On Mon, Jun 29, 2026 at 03:56:33PM +0200, Thomas Zimmermann wrote:
> Hi
>
> Am 29.06.26 um 14:23 schrieb Lorenzo Stoakes:
> > There are a number of places where we open code what linear_page_index()
> > and linear_page_delta() calculate.
> >
> > Replace this code with the appropriate functions for consistency.
> >
> > No functional change intended.
> >
> > Signed-off-by: Lorenzo Stoakes <[email protected]>
>
> For the DRM changes:
>
> Reviewed-by: Thomas Zimmermann <[email protected]>

Thanks!

>
> See below for two additional comments.
>
>
> > ---
> >   arch/arm/mm/fault-armv.c              | 2 +-
> >   arch/x86/kernel/cpu/sgx/virt.c        | 3 ++-
> >   drivers/comedi/comedi_fops.c          | 3 ++-
> >   drivers/gpu/drm/etnaviv/etnaviv_gem.c | 3 ++-
> >   drivers/gpu/drm/gma500/gem.c          | 2 +-
> >   drivers/gpu/drm/msm/msm_gem.c         | 3 ++-
> >   drivers/gpu/drm/omapdrm/omap_gem.c    | 5 +++--
> >   drivers/gpu/drm/tegra/gem.c           | 3 ++-
> >   drivers/gpu/drm/ttm/ttm_bo_vm.c       | 7 ++++---
> >   drivers/vfio/pci/nvgrace-gpu/main.c   | 3 ++-
> >   drivers/vfio/pci/vfio_pci_core.c      | 3 ++-
> >   mm/nommu.c                            | 2 +-
> >   mm/vma.c                              | 2 +-
> >   virt/kvm/guest_memfd.c                | 2 +-
> >   14 files changed, 26 insertions(+), 17 deletions(-)
> >
>
> [...]
>
> >   #include <linux/io.h>
> >   #include <linux/uaccess.h>
> > @@ -2462,7 +2463,7 @@ static int comedi_vm_access(struct vm_area_struct 
> > *vma, unsigned long addr,
> >   {
> >     struct comedi_buf_map *bm = vma->vm_private_data;
> >     unsigned long offset =
> > -       addr - vma->vm_start + (vma->vm_pgoff << PAGE_SHIFT);
> > +       addr - vma->vm_start + (vma_start_pgoff(vma) << PAGE_SHIFT);
>
> This doesn't seem to belong here.

Ah yeah, I'll move that on a respin thanks!

>
> >     if (len < 0)
> >             return -EINVAL;
> > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c 
> > b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
> > index b0436a1e103f..2e4d6d117ee2 100644
> > --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c
> > +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
> > @@ -6,6 +6,7 @@
> >   #include <drm/drm_prime.h>
> >   #include <drm/drm_print.h>
> >   #include <linux/dma-mapping.h>
> > +#include <linux/pagemap.h>
> >   #include <linux/shmem_fs.h>
> >   #include <linux/spinlock.h>
> >   #include <linux/vmalloc.h>
> > @@ -188,7 +189,7 @@ static vm_fault_t etnaviv_gem_fault(struct vm_fault 
> > *vmf)
> >     }
> >     /* We don't use vmf->pgoff since that has the fake offset: */
> > -   pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
> > +   pgoff = linear_page_delta(vma, vmf->address);
> >     pfn = page_to_pfn(pages[pgoff]);
> > diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
> > index 88f1e86c8903..2708e8c68f4c 100644
> > --- a/drivers/gpu/drm/gma500/gem.c
> > +++ b/drivers/gpu/drm/gma500/gem.c
> > @@ -288,7 +288,7 @@ static vm_fault_t psb_gem_fault(struct vm_fault *vmf)
> >     /* Page relative to the VMA start - we must calculate this ourselves
> >        because vmf->pgoff is the fake GEM offset */
> > -   page_offset = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
> > +   page_offset = linear_page_delta(vma, vmf->address);
> >     /* CPU view of the page, don't go via the GART for CPU writes */
> >     if (pobj->stolen)
> > diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> > index efd3d3c9a449..cbf723a5d86f 100644
> > --- a/drivers/gpu/drm/msm/msm_gem.c
> > +++ b/drivers/gpu/drm/msm/msm_gem.c
> > @@ -9,6 +9,7 @@
> >   #include <linux/spinlock.h>
> >   #include <linux/shmem_fs.h>
> >   #include <linux/dma-buf.h>
> > +#include <linux/pagemap.h>
> >   #include <drm/drm_dumb_buffers.h>
> >   #include <drm/drm_prime.h>
> > @@ -360,7 +361,7 @@ static vm_fault_t msm_gem_fault(struct vm_fault *vmf)
> >     }
> >     /* We don't use vmf->pgoff since that has the fake offset: */
> > -   pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
> > +   pgoff = linear_page_delta(vma, vmf->address);
> >     pfn = page_to_pfn(pages[pgoff]);
> > diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c 
> > b/drivers/gpu/drm/omapdrm/omap_gem.c
> > index 8e013e4f2c6b..00404fb6c29a 100644
> > --- a/drivers/gpu/drm/omapdrm/omap_gem.c
> > +++ b/drivers/gpu/drm/omapdrm/omap_gem.c
> > @@ -5,6 +5,7 @@
> >    */
> >   #include <linux/dma-mapping.h>
> > +#include <linux/pagemap.h>
> >   #include <linux/seq_file.h>
> >   #include <linux/shmem_fs.h>
> >   #include <linux/spinlock.h>
> > @@ -359,7 +360,7 @@ static vm_fault_t omap_gem_fault_1d(struct 
> > drm_gem_object *obj,
> >     pgoff_t pgoff;
> >     /* We don't use vmf->pgoff since that has the fake offset: */
> > -   pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
> > +   pgoff = linear_page_delta(vma, vmf->address);
> >     if (omap_obj->pages) {
> >             omap_gem_cpu_sync_page(obj, pgoff);
> > @@ -407,7 +408,7 @@ static vm_fault_t omap_gem_fault_2d(struct 
> > drm_gem_object *obj,
> >     const int m = DIV_ROUND_UP(omap_obj->width << fmt, PAGE_SIZE);
> >     /* We don't use vmf->pgoff since that has the fake offset: */
> > -   pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
> > +   pgoff = linear_page_delta(vma, vmf->address);
> >     /*
> >      * Actual address we start mapping at is rounded down to previous slot
> > diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c
> > index 436394e04812..1d8d27a5ea89 100644
> > --- a/drivers/gpu/drm/tegra/gem.c
> > +++ b/drivers/gpu/drm/tegra/gem.c
> > @@ -13,6 +13,7 @@
> >   #include <linux/dma-buf.h>
> >   #include <linux/iommu.h>
> >   #include <linux/module.h>
> > +#include <linux/pagemap.h>
> >   #include <linux/vmalloc.h>
> >   #include <drm/drm_drv.h>
> > @@ -564,7 +565,7 @@ static vm_fault_t tegra_bo_fault(struct vm_fault *vmf)
> >     if (!bo->pages)
> >             return VM_FAULT_SIGBUS;
> > -   offset = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
> > +   offset = linear_page_delta(vma, vmf->address);
> >     page = bo->pages[offset];
> >     return vmf_insert_page(vma, vmf->address, page);
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c 
> > b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > index a80510489c45..88babf435ac2 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > @@ -32,6 +32,7 @@
> >   #define pr_fmt(fmt) "[TTM] " fmt
> >   #include <linux/export.h>
> > +#include <linux/pagemap.h>
> >   #include <drm/ttm/ttm_bo.h>
> >   #include <drm/ttm/ttm_placement.h>
> > @@ -208,9 +209,9 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault 
> > *vmf,
> >     if (unlikely(err != 0))
> >             return VM_FAULT_SIGBUS;
> > -   page_offset = ((address - vma->vm_start) >> PAGE_SHIFT) +
> > -           vma->vm_pgoff - drm_vma_node_start(&bo->base.vma_node);
> > -   page_last = vma_pages(vma) + vma->vm_pgoff -
> > +   page_offset = linear_page_index(vma, address) -
> > +           drm_vma_node_start(&bo->base.vma_node);
> > +   page_last = vma_end_pgoff(vma) -
> >             drm_vma_node_start(&bo->base.vma_node);
>
> Not your fault, but page_last seems misnamed here.

Yeah :)

>
> Best regards
> Thomas
>
> >     if (unlikely(page_offset >= PFN_UP(bo->base.size)))
> > diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c 
> > b/drivers/vfio/pci/nvgrace-gpu/main.c
> > index d07dcacb76bd..963fd8ded20d 100644
> > --- a/drivers/vfio/pci/nvgrace-gpu/main.c
> > +++ b/drivers/vfio/pci/nvgrace-gpu/main.c
> > @@ -11,6 +11,7 @@
> >   #include <linux/jiffies.h>
> >   #include <linux/sched.h>
> >   #include <linux/pci-p2pdma.h>
> > +#include <linux/pagemap.h>
> >   #include <linux/pm_runtime.h>
> >   #include <linux/memory-failure.h>
> > @@ -385,7 +386,7 @@ static unsigned long addr_to_pgoff(struct 
> > vm_area_struct *vma,
> >     u64 pgoff = vma->vm_pgoff &
> >             ((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
> > -   return ((addr - vma->vm_start) >> PAGE_SHIFT) + pgoff;
> > +   return linear_page_delta(vma, addr) + pgoff;
> >   }
> >   static vm_fault_t nvgrace_gpu_vfio_pci_huge_fault(struct vm_fault *vmf,
> > diff --git a/drivers/vfio/pci/vfio_pci_core.c 
> > b/drivers/vfio/pci/vfio_pci_core.c
> > index a28f1e99362c..55d4937d495a 100644
> > --- a/drivers/vfio/pci/vfio_pci_core.c
> > +++ b/drivers/vfio/pci/vfio_pci_core.c
> > @@ -19,6 +19,7 @@
> >   #include <linux/module.h>
> >   #include <linux/mutex.h>
> >   #include <linux/notifier.h>
> > +#include <linux/pagemap.h>
> >   #include <linux/pci.h>
> >   #include <linux/pm_runtime.h>
> >   #include <linux/slab.h>
> > @@ -1727,7 +1728,7 @@ static vm_fault_t vfio_pci_mmap_huge_fault(struct 
> > vm_fault *vmf,
> >     struct vm_area_struct *vma = vmf->vma;
> >     struct vfio_pci_core_device *vdev = vma->vm_private_data;
> >     unsigned long addr = vmf->address & ~((PAGE_SIZE << order) - 1);
> > -   unsigned long pgoff = (addr - vma->vm_start) >> PAGE_SHIFT;
> > +   unsigned long pgoff = linear_page_delta(vma, addr);
> >     unsigned long pfn = vma_to_pfn(vma) + pgoff;
> >     vm_fault_t ret = VM_FAULT_FALLBACK;
> > diff --git a/mm/nommu.c b/mm/nommu.c
> > index 60560b2c457e..7333d855e974 100644
> > --- a/mm/nommu.c
> > +++ b/mm/nommu.c
> > @@ -1332,7 +1332,7 @@ static int split_vma(struct vma_iterator *vmi, struct 
> > vm_area_struct *vma,
> >     *region = *vma->vm_region;
> >     new->vm_region = region;
> > -   npages = (addr - vma->vm_start) >> PAGE_SHIFT;
> > +   npages = linear_page_delta(vma, addr);
> >     if (new_below) {
> >             region->vm_top = region->vm_end = new->vm_end = addr;
> > diff --git a/mm/vma.c b/mm/vma.c
> > index ee3a8ca13d07..185d07397ca6 100644
> > --- a/mm/vma.c
> > +++ b/mm/vma.c
> > @@ -517,7 +517,7 @@ __split_vma(struct vma_iterator *vmi, struct 
> > vm_area_struct *vma,
> >             new->vm_end = addr;
> >     } else {
> >             new->vm_start = addr;
> > -           new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
> > +           new->vm_pgoff += linear_page_delta(vma, addr);
> >     }
> >     err = -ENOMEM;
> > diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> > index db57c5766ab6..f0e5da490866 100644
> > --- a/virt/kvm/guest_memfd.c
> > +++ b/virt/kvm/guest_memfd.c
> > @@ -440,7 +440,7 @@ static int kvm_gmem_set_policy(struct vm_area_struct 
> > *vma, struct mempolicy *mpo
> >   static struct mempolicy *kvm_gmem_get_policy(struct vm_area_struct *vma,
> >                                          unsigned long addr, pgoff_t *ilx)
> >   {
> > -   pgoff_t pgoff = vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT);
> > +   pgoff_t pgoff = linear_page_index(vma, addr);
> >     struct inode *inode = file_inode(vma->vm_file);
> >     *ilx = inode->i_ino;
>
> --
> --
> Thomas Zimmermann
> Graphics Driver Developer
> SUSE Software Solutions Germany GmbH
> Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
> GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
>
>

Cheers, Lorenzo

Reply via email to