Commit 9348b73c authored by Linus Torvalds's avatar Linus Torvalds

mm: don't play games with pinned pages in clear_page_refs

Turning a pinned page read-only breaks the pinning after COW.  Don't do it.

The whole "track page soft dirty" state doesn't work with pinned pages
anyway, since the page might be dirtied by the pinning entity without
ever being noticed in the page tables.
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 29a951df
...@@ -1035,6 +1035,25 @@ struct clear_refs_private { ...@@ -1035,6 +1035,25 @@ struct clear_refs_private {
}; };
#ifdef CONFIG_MEM_SOFT_DIRTY #ifdef CONFIG_MEM_SOFT_DIRTY
#define is_cow_mapping(flags) (((flags) & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE)
static inline bool pte_is_pinned(struct vm_area_struct *vma, unsigned long addr, pte_t pte)
{
struct page *page;
if (!pte_write(pte))
return false;
if (!is_cow_mapping(vma->vm_flags))
return false;
if (likely(!atomic_read(&vma->vm_mm->has_pinned)))
return false;
page = vm_normal_page(vma, addr, pte);
if (!page)
return false;
return page_maybe_dma_pinned(page);
}
static inline void clear_soft_dirty(struct vm_area_struct *vma, static inline void clear_soft_dirty(struct vm_area_struct *vma,
unsigned long addr, pte_t *pte) unsigned long addr, pte_t *pte)
{ {
...@@ -1049,6 +1068,8 @@ static inline void clear_soft_dirty(struct vm_area_struct *vma, ...@@ -1049,6 +1068,8 @@ static inline void clear_soft_dirty(struct vm_area_struct *vma,
if (pte_present(ptent)) { if (pte_present(ptent)) {
pte_t old_pte; pte_t old_pte;
if (pte_is_pinned(vma, addr, ptent))
return;
old_pte = ptep_modify_prot_start(vma, addr, pte); old_pte = ptep_modify_prot_start(vma, addr, pte);
ptent = pte_wrprotect(old_pte); ptent = pte_wrprotect(old_pte);
ptent = pte_clear_soft_dirty(ptent); ptent = pte_clear_soft_dirty(ptent);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment