[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1401155e1db8221b892fb935204ad2d358c2808f.1607332046.git.yuleixzhang@tencent.com>
Date: Mon, 7 Dec 2020 19:31:11 +0800
From: yulei.kernel@...il.com
To: linux-mm@...ck.org, akpm@...ux-foundation.org,
linux-fsdevel@...r.kernel.org, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, naoya.horiguchi@....com,
viro@...iv.linux.org.uk, pbonzini@...hat.com
Cc: joao.m.martins@...cle.com, rdunlap@...radead.org,
sean.j.christopherson@...el.com, xiaoguangrong.eric@...il.com,
kernellwp@...il.com, lihaiwei.kernel@...il.com,
Yulei Zhang <yuleixzhang@...cent.com>,
Chen Zhuo <sagazchen@...cent.com>
Subject: [RFC V2 18/37] mm: follow_pmd_mask() for dmem huge pmd
From: Yulei Zhang <yuleixzhang@...cent.com>
While follow_pmd_mask(), dmem huge pmd should be recognized and return
error pointer of '-EEXIST' to indicate that proper page table entry exists
in pmd special but no corresponding struct page, because dmem page means
non struct page backend. We update pmd if foll_flags takes FOLL_TOUCH.
Signed-off-by: Chen Zhuo <sagazchen@...cent.com>
Signed-off-by: Yulei Zhang <yuleixzhang@...cent.com>
---
mm/gup.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/mm/gup.c b/mm/gup.c
index 98eb8e6..ad1aede 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -387,6 +387,42 @@ static int follow_pfn_pte(struct vm_area_struct *vma, unsigned long address,
return -EEXIST;
}
+static struct page *
+follow_special_pmd(struct vm_area_struct *vma, unsigned long address,
+ pmd_t *pmd, unsigned int flags)
+{
+ spinlock_t *ptl;
+
+ if ((flags & FOLL_DUMP) && is_huge_zero_pmd(*pmd))
+ /* Avoid special (like zero) pages in core dumps */
+ return ERR_PTR(-EFAULT);
+
+ /* No page to get reference */
+ if (flags & FOLL_GET)
+ return ERR_PTR(-EFAULT);
+
+ if (flags & FOLL_TOUCH) {
+ pmd_t _pmd;
+
+ ptl = pmd_lock(vma->vm_mm, pmd);
+ if (!pmd_special(*pmd)) {
+ spin_unlock(ptl);
+ return NULL;
+ }
+ _pmd = pmd_mkyoung(*pmd);
+ if (flags & FOLL_WRITE)
+ _pmd = pmd_mkdirty(_pmd);
+ if (pmdp_set_access_flags(vma, address & HPAGE_PMD_MASK,
+ pmd, _pmd,
+ flags & FOLL_WRITE))
+ update_mmu_cache_pmd(vma, address, pmd);
+ spin_unlock(ptl);
+ }
+
+ /* Proper page table entry exists, but no corresponding struct page */
+ return ERR_PTR(-EEXIST);
+}
+
/*
* FOLL_FORCE can write to even unwritable pte's, but only
* after we've gone through a COW cycle and they are dirty.
@@ -571,6 +607,12 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma,
return page;
return no_page_table(vma, flags);
}
+ if (pmd_special(*pmd)) {
+ page = follow_special_pmd(vma, address, pmd, flags);
+ if (page)
+ return page;
+ return no_page_table(vma, flags);
+ }
if (is_hugepd(__hugepd(pmd_val(pmdval)))) {
page = follow_huge_pd(vma, address,
__hugepd(pmd_val(pmdval)), flags,
--
1.8.3.1
Powered by blists - more mailing lists