]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-4.9/mm-make-page-ref-count-overflow-check-tighter-and-more-explicit.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.9 / mm-make-page-ref-count-overflow-check-tighter-and-more-explicit.patch
CommitLineData
25085850
GKH
1From foo@baz Tue 04 Jun 2019 04:44:10 PM CEST
2From: Linus Torvalds <torvalds@linux-foundation.org>
3Date: Thu, 11 Apr 2019 10:06:20 -0700
4Subject: mm: make page ref count overflow check tighter and more explicit
5
6From: Linus Torvalds <torvalds@linux-foundation.org>
7
8commit f958d7b528b1b40c44cfda5eabe2d82760d868c3 upstream.
9
10We have a VM_BUG_ON() to check that the page reference count doesn't
11underflow (or get close to overflow) by checking the sign of the count.
12
13That's all fine, but we actually want to allow people to use a "get page
14ref unless it's already very high" helper function, and we want that one
15to use the sign of the page ref (without triggering this VM_BUG_ON).
16
17Change the VM_BUG_ON to only check for small underflows (or _very_ close
18to overflowing), and ignore overflows which have strayed into negative
19territory.
20
21Acked-by: Matthew Wilcox <willy@infradead.org>
22Cc: Jann Horn <jannh@google.com>
23Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
24Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
25Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26---
27 include/linux/mm.h | 6 +++++-
28 1 file changed, 5 insertions(+), 1 deletion(-)
29
30--- a/include/linux/mm.h
31+++ b/include/linux/mm.h
32@@ -763,6 +763,10 @@ static inline bool is_zone_device_page(c
33 }
34 #endif
35
36+/* 127: arbitrary random number, small enough to assemble well */
37+#define page_ref_zero_or_close_to_overflow(page) \
38+ ((unsigned int) page_ref_count(page) + 127u <= 127u)
39+
40 static inline void get_page(struct page *page)
41 {
42 page = compound_head(page);
43@@ -770,7 +774,7 @@ static inline void get_page(struct page
44 * Getting a normal page or the head of a compound page
45 * requires to already have an elevated page->_refcount.
46 */
47- VM_BUG_ON_PAGE(page_ref_count(page) <= 0, page);
48+ VM_BUG_ON_PAGE(page_ref_zero_or_close_to_overflow(page), page);
49 page_ref_inc(page);
50
51 if (unlikely(is_zone_device_page(page)))