linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: linux-mm@kvack.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	kirill.shutemov@linux.intel.com, pasha.tatashin@soleen.com
Subject: [PATCH 5/5] mm: Check page poison before finding a head page
Date: Wed,  8 Apr 2020 08:01:48 -0700	[thread overview]
Message-ID: <20200408150148.25290-6-willy@infradead.org> (raw)
In-Reply-To: <20200408150148.25290-1-willy@infradead.org>

From: "Matthew Wilcox (Oracle)" <willy@infradead.org>

If a page is poisoned, the page->compound_head will be set to -1.
Since it has bit zero set, we will think it is a tail page, and the head
page is at 0xff..fe.  Checking said head page for being poisoned will
not have good results.  Therefore we need to check for poison in each
of compound_head(), PageTail() and PageCompound() (and can remove the
checks which are now redundant from the PF_ macros).

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/page-flags.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index 331aef35f3e0..340ceeeda8ed 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -190,6 +190,7 @@ static inline int PagePoisoned(const struct page *page)
 #define compound_head(page) ({						\
 	__typeof__(page) _page = page;					\
 	unsigned long head = READ_ONCE(_page->compound_head);		\
+	VM_BUG_ON_PAGE(head == PAGE_POISON_PATTERN, page);		\
 	if (unlikely(head & 1))						\
 		_page = (void *)(head - 1);				\
 	_page;								\
@@ -197,11 +198,13 @@ static inline int PagePoisoned(const struct page *page)
 
 static __always_inline int PageTail(const struct page *page)
 {
+	page_poison_check(page);
 	return READ_ONCE(page->compound_head) & 1;
 }
 
 static __always_inline int PageCompound(const struct page *page)
 {
+	page_poison_check(page);
 	return test_bit(PG_head, &page->flags) || PageTail(page);
 }
 
@@ -234,13 +237,13 @@ static inline void page_init_poison(struct page *page, size_t size)
  *     the page flag is not relevant for compound pages.
  */
 #define PF_ANY(page, enforce)	page_poison_check(page)
-#define PF_HEAD(page, enforce)	page_poison_check(compound_head(page))
+#define PF_HEAD(page, enforce)	compound_head(page)
 #define PF_ONLY_HEAD(page, enforce) ({					\
 		VM_BUG_ON_PGFLAGS(PageTail(page), page);		\
-		page_poison_check(page); })
+		page; })
 #define PF_NO_TAIL(page, enforce) ({					\
 		VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page);	\
-		page_poison_check(compound_head(page)); })
+		compound_head(page); })
 #define PF_NO_COMPOUND(page, enforce) ({				\
 		VM_BUG_ON_PGFLAGS(enforce && PageCompound(page), page);	\
 		page_poison_check(page); })
-- 
2.25.1



  parent reply	other threads:[~2020-04-08 15:01 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-08 15:01 [PATCH 0/5] Improve page poisoning implementation Matthew Wilcox
2020-04-08 15:01 ` [PATCH 1/5] mm: Constify a lot of struct page arguments Matthew Wilcox
2020-04-08 15:14   ` Pavel Tatashin
2020-04-09 14:09   ` Kirill A. Shutemov
2020-04-09 14:15     ` Matthew Wilcox
2020-04-09 14:28       ` Kirill A. Shutemov
2020-04-09 14:32         ` Matthew Wilcox
2020-04-09 14:47           ` Kirill A. Shutemov
2020-04-09 15:00             ` Kirill A. Shutemov
2020-04-09 17:12             ` Jason Gunthorpe
2020-04-09 20:47               ` John Hubbard
2020-04-08 15:01 ` [PATCH 2/5] mm: Rename PF_POISONED_PAGE to page_poison_check Matthew Wilcox
2020-04-08 15:21   ` Pavel Tatashin
2020-04-09 14:14   ` Kirill A. Shutemov
2020-04-08 15:01 ` [PATCH 3/5] mm: Remove casting away of constness Matthew Wilcox
2020-04-08 15:23   ` Pavel Tatashin
2020-04-09 14:19   ` Kirill A. Shutemov
2020-04-08 15:01 ` [PATCH 4/5] mm: Check for page poison in both page_to_nid implementations Matthew Wilcox
2020-04-08 15:24   ` Pavel Tatashin
2020-04-09 14:21   ` Kirill A. Shutemov
2020-04-08 15:01 ` Matthew Wilcox [this message]
2020-04-08 15:32   ` [PATCH 5/5] mm: Check page poison before finding a head page Pavel Tatashin
2020-04-09 14:25   ` Kirill A. Shutemov
2020-04-08 15:11 ` [PATCH 0/5] Improve page poisoning implementation Pavel Tatashin
2020-04-09 20:55   ` John Hubbard

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=20200408150148.25290-6-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.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