Skip to content

Commit ec2e0cc

Browse files
apopple-nvidiaakpm00
authored andcommitted
mm/memory: add vmf_insert_page_mkwrite()
Currently to map a DAX page the DAX driver calls vmf_insert_pfn. This creates a special devmap PTE entry for the pfn but does not take a reference on the underlying struct page for the mapping. This is because DAX page refcounts are treated specially, as indicated by the presence of a devmap entry. To allow DAX page refcounts to be managed the same as normal page refcounts introduce vmf_insert_page_mkwrite(). This will take a reference on the underlying page much the same as vmf_insert_page, except it also permits upgrading an existing mapping to be writable if requested/possible. Link: https://lkml.kernel.org/r/4ce3aa984c060f370105e0bfef1035869578be47.1740713401.git-series.apopple@nvidia.com Signed-off-by: Alistair Popple <apopple@nvidia.com> Acked-by: David Hildenbrand <david@redhat.com> Tested-by: Alison Schofield <alison.schofield@intel.com> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Asahi Lina <lina@asahilina.net> Cc: Balbir Singh <balbirs@nvidia.com> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christian Borntraeger <borntraeger@linux.ibm.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Chunyan Zhang <zhang.lyra@gmail.com> Cc: Dan Wiliams <dan.j.williams@intel.com> Cc: "Darrick J. Wong" <djwong@kernel.org> Cc: Dave Chinner <david@fromorbit.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Dave Jiang <dave.jiang@intel.com> Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ira Weiny <ira.weiny@intel.com> Cc: Jan Kara <jack@suse.cz> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: John Hubbard <jhubbard@nvidia.com> Cc: linmiaohe <linmiaohe@huawei.com> Cc: Logan Gunthorpe <logang@deltatee.com> Cc: Matthew Wilcow (Oracle) <willy@infradead.org> Cc: Michael "Camp Drill Sergeant" Ellerman <mpe@ellerman.id.au> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Peter Xu <peterx@redhat.com> Cc: Sven Schnelle <svens@linux.ibm.com> Cc: Ted Ts'o <tytso@mit.edu> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Vishal Verma <vishal.l.verma@intel.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: WANG Xuerui <kernel@xen0n.name> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 15a6431 commit ec2e0cc

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/linux/mm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3644,6 +3644,8 @@ int vm_map_pages(struct vm_area_struct *vma, struct page **pages,
36443644
unsigned long num);
36453645
int vm_map_pages_zero(struct vm_area_struct *vma, struct page **pages,
36463646
unsigned long num);
3647+
vm_fault_t vmf_insert_page_mkwrite(struct vm_fault *vmf, struct page *page,
3648+
bool write);
36473649
vm_fault_t vmf_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
36483650
unsigned long pfn);
36493651
vm_fault_t vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr,

mm/memory.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,6 +2643,26 @@ static vm_fault_t __vm_insert_mixed(struct vm_area_struct *vma,
26432643
return VM_FAULT_NOPAGE;
26442644
}
26452645

2646+
vm_fault_t vmf_insert_page_mkwrite(struct vm_fault *vmf, struct page *page,
2647+
bool write)
2648+
{
2649+
pgprot_t pgprot = vmf->vma->vm_page_prot;
2650+
unsigned long addr = vmf->address;
2651+
int err;
2652+
2653+
if (addr < vmf->vma->vm_start || addr >= vmf->vma->vm_end)
2654+
return VM_FAULT_SIGBUS;
2655+
2656+
err = insert_page(vmf->vma, addr, page, pgprot, write);
2657+
if (err == -ENOMEM)
2658+
return VM_FAULT_OOM;
2659+
if (err < 0 && err != -EBUSY)
2660+
return VM_FAULT_SIGBUS;
2661+
2662+
return VM_FAULT_NOPAGE;
2663+
}
2664+
EXPORT_SYMBOL_GPL(vmf_insert_page_mkwrite);
2665+
26462666
vm_fault_t vmf_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
26472667
pfn_t pfn)
26482668
{

0 commit comments

Comments
 (0)