From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@suse.cz>,
Vineet Gupta <vgupta@synopsys.com>,
Russell King <linux@armlinux.org.uk>,
Will Deacon <will.deacon@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Ralf Baechle <ralf@linux-mips.org>,
"David S. Miller" <davem@davemloft.net>,
"Aneesh Kumar K . V" <aneesh.kumar@linux.vnet.ibm.com>,
Martin Schwidefsky <schwidefsky@de.ibm.com>,
Heiko Carstens <heiko.carstens@de.ibm.com>,
Andrea Arcangeli <aarcange@redhat.com>
Cc: linux-arch@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Subject: [PATCHv2 2/3] mm: Do not loose dirty and access bits in pmdp_invalidate()
Date: Thu, 15 Jun 2017 17:52:23 +0300 [thread overview]
Message-ID: <20170615145224.66200-3-kirill.shutemov@linux.intel.com> (raw)
In-Reply-To: <20170615145224.66200-1-kirill.shutemov@linux.intel.com>
Vlastimil noted that pmdp_invalidate() is not atomic and we can loose
dirty and access bits if CPU sets them after pmdp dereference, but
before set_pmd_at().
The bug doesn't lead to user-visible misbehaviour in current kernel.
Loosing access bit can lead to sub-optimal reclaim behaviour for THP,
but nothing destructive.
Loosing dirty bit is not a big deal too: we would make page dirty
unconditionally on splitting huge page.
The fix is critical for future work on THP: both huge-ext4 and THP swap
out rely on proper dirty tracking.
The patch change pmdp_invalidate() to make the entry non-present atomically and
return previous value of the entry. This value can be used to check if
CPU set dirty/accessed bits under us.
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reported-by: Vlastimil Babka <vbabka@suse.cz>
---
include/asm-generic/pgtable.h | 2 +-
mm/pgtable-generic.c | 9 +++++----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
index 7dfa767dc680..ece5e399567a 100644
--- a/include/asm-generic/pgtable.h
+++ b/include/asm-generic/pgtable.h
@@ -309,7 +309,7 @@ extern pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
#endif
#ifndef __HAVE_ARCH_PMDP_INVALIDATE
-extern void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
+extern pmd_t pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
pmd_t *pmdp);
#endif
diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c
index c99d9512a45b..148fe36f61a7 100644
--- a/mm/pgtable-generic.c
+++ b/mm/pgtable-generic.c
@@ -179,12 +179,13 @@ pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
#endif
#ifndef __HAVE_ARCH_PMDP_INVALIDATE
-void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
+pmd_t pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
pmd_t *pmdp)
{
- pmd_t entry = *pmdp;
- set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(entry));
- flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
+ pmd_t old = pmdp_establish(pmdp, pmd_mknotpresent(*pmdp));
+ if (pmd_present(old))
+ flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
+ return old;
}
#endif
--
2.11.0
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-06-15 14:52 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-15 14:52 [HELP-NEEDED, PATCHv2 0/3] Do not loose dirty bit on THP pages Kirill A. Shutemov
2017-06-15 14:52 ` [PATCHv2 1/3] x86/mm: Provide pmdp_establish() helper Kirill A. Shutemov
2017-06-16 13:36 ` Andrea Arcangeli
2017-06-19 12:46 ` Kirill A. Shutemov
2017-06-19 5:48 ` Martin Schwidefsky
2017-06-19 12:48 ` Kirill A. Shutemov
2017-06-19 13:04 ` Martin Schwidefsky
2017-06-19 15:22 ` Catalin Marinas
2017-06-19 16:00 ` Kirill A. Shutemov
2017-06-19 17:09 ` Catalin Marinas
2017-06-19 21:52 ` Kirill A. Shutemov
2017-06-20 15:54 ` Catalin Marinas
2017-06-21 9:53 ` Kirill A. Shutemov
2017-06-21 10:40 ` Catalin Marinas
2017-06-21 11:27 ` Catalin Marinas
2017-06-21 12:04 ` Kirill A. Shutemov
2017-06-21 15:49 ` Vineet Gupta
2017-06-21 17:15 ` Kirill A. Shutemov
2017-06-21 17:20 ` Vineet Gupta
2017-06-21 17:52 ` Kirill A. Shutemov
2017-06-19 17:11 ` Nadav Amit
2017-06-19 21:57 ` Kirill A. Shutemov
2017-06-15 14:52 ` Kirill A. Shutemov [this message]
2017-06-15 22:44 ` [PATCHv2 2/3] mm: Do not loose dirty and access bits in pmdp_invalidate() kbuild test robot
2017-06-16 13:40 ` Andrea Arcangeli
2017-06-19 13:29 ` Kirill A. Shutemov
2017-06-15 14:52 ` [PATCHv2 3/3] mm: Use updated pmdp_invalidate() inteface to track dirty/accessed bits Kirill A. Shutemov
2017-06-15 21:54 ` kbuild test robot
2017-06-15 23:02 ` kbuild test robot
2017-06-16 3:02 ` Minchan Kim
2017-06-16 13:19 ` Kirill A. Shutemov
2017-06-16 13:52 ` Minchan Kim
2017-06-16 14:27 ` Andrea Arcangeli
2017-06-16 14:53 ` Minchan Kim
2017-06-19 14:03 ` Kirill A. Shutemov
2017-06-20 2:52 ` Minchan Kim
2017-06-20 9:57 ` Minchan Kim
2017-06-16 11:31 ` Aneesh Kumar K.V
2017-06-16 13:21 ` Kirill A. Shutemov
2017-06-16 15:57 ` Aneesh Kumar K.V
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170615145224.66200-3-kirill.shutemov@linux.intel.com \
--to=kirill.shutemov@linux.intel.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=catalin.marinas@arm.com \
--cc=davem@davemloft.net \
--cc=heiko.carstens@de.ibm.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@armlinux.org.uk \
--cc=ralf@linux-mips.org \
--cc=schwidefsky@de.ibm.com \
--cc=vbabka@suse.cz \
--cc=vgupta@synopsys.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox