mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-27 09:23:17 -04:00
mm: use linear_page_[index, delta]() consistently
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. Link: https://lore.kernel.org/20260710-b4-pre-scalable-cow-v2-21-2a5aa403d977@kernel.org Signed-off-by: Lorenzo Stoakes <ljs@kernel.org> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de> [DRM] Acked-by: Kai Huang <kai.huang@intel.com> # for sgx Reviewed-by: Gregory Price <gourry@gourry.net> Reviewed-by: Pedro Falcato <pfalcato@suse.de> # for mm Reviewed-by: Ackerley Tng <ackerleytng@google.com> [guest_memfd] Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org> Cc: David Hildenbrand (Arm) <david@kernel.org> Cc: Marek Szyprowski <m.szyprowski@samsung.com> Cc: SJ Park <sj@kernel.org> Cc: Liam R. Howlett (Oracle) <liam@infradead.org> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
ff8fbc9e08
commit
93d23dff8e
@@ -132,7 +132,7 @@ make_coherent(struct address_space *mapping, struct vm_area_struct *vma,
|
||||
pgoff_t pgoff;
|
||||
int aliases = 0;
|
||||
|
||||
pgoff = vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT);
|
||||
pgoff = linear_page_index(vma, addr);
|
||||
|
||||
/*
|
||||
* If we have any shared mappings that are in the same mm
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/mman.h>
|
||||
#include <linux/pagemap.h>
|
||||
#include <linux/sched/mm.h>
|
||||
#include <linux/sched/signal.h>
|
||||
#include <linux/slab.h>
|
||||
@@ -41,7 +42,7 @@ static int __sgx_vepc_fault(struct sgx_vepc *vepc,
|
||||
WARN_ON(!mutex_is_locked(&vepc->lock));
|
||||
|
||||
/* Calculate index of EPC page in virtual EPC's page_array */
|
||||
index = vma->vm_pgoff + PFN_DOWN(addr - vma->vm_start);
|
||||
index = linear_page_index(vma, addr);
|
||||
|
||||
epc_page = xa_load(&vepc->page_array, index);
|
||||
if (epc_page)
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
if (unlikely(page_offset >= PFN_UP(bo->base.size)))
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -20,6 +20,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>
|
||||
@@ -1780,7 +1781,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;
|
||||
|
||||
|
||||
@@ -1355,7 +1355,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;
|
||||
|
||||
2
mm/vma.c
2
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user