Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/shmem-helper: Simplify page offset calculation in fault handler

For a fault at address addr, the page offset is
page_offset = (vmf->address - vma->vm_start) >> PAGE_SHIFT
= ((addr & PAGE_MASK) - vma->vm_start) >> PAGE_SHIFT
= (addr - vma->vm_start) >> PAGE_SHIFT

Since the faulty logical page offset based on VMA is
vmf->pgoff = vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT)

We can slightly simplify the calculation using
page_offset = vmf->pgoff - vma->vm_pgoff

v11:
- remove misleading comment
- add Boris R-b

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Link: https://patch.msgid.link/20251205182231.194072-2-loic.molinari@collabora.com
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>

authored by

Loïc Molinari and committed by
Boris Brezillon
9d2d4902 d8f94cb0

+2 -2
+2 -2
drivers/gpu/drm/drm_gem_shmem_helper.c
··· 577 577 struct page *page; 578 578 pgoff_t page_offset; 579 579 580 - /* We don't use vmf->pgoff since that has the fake offset */ 581 - page_offset = (vmf->address - vma->vm_start) >> PAGE_SHIFT; 580 + /* Offset to faulty address in the VMA. */ 581 + page_offset = vmf->pgoff - vma->vm_pgoff; 582 582 583 583 dma_resv_lock(shmem->base.resv, NULL); 584 584