* [PATCH AUTOSEL 4.14 18/32] slab: fix a crash by reading /proc/slab_allocators
[not found] <20190427014224.8274-1-sashal@kernel.org>
@ 2019-04-27 1:42 ` Sasha Levin
2019-04-27 1:42 ` [PATCH AUTOSEL 4.14 31/32] mm: make page ref count overflow check tighter and more explicit Sasha Levin
2019-04-27 1:42 ` [PATCH AUTOSEL 4.14 32/32] mm: add 'try_get_page()' helper function Sasha Levin
2 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2019-04-27 1:42 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Qian Cai, Tejun Heo, Andrew Morton, Linus Torvalds, Sasha Levin,
linux-mm
From: Qian Cai <cai@lca.pw>
[ Upstream commit fcf88917dd435c6a4cb2830cb086ee58605a1d85 ]
The commit 510ded33e075 ("slab: implement slab_root_caches list")
changes the name of the list node within "struct kmem_cache" from "list"
to "root_caches_node", but leaks_show() still use the "list" which
causes a crash when reading /proc/slab_allocators.
You need to have CONFIG_SLAB=y and CONFIG_MEMCG=y to see the problem,
because without MEMCG all slab caches are root caches, and the "list"
node happens to be the right one.
Fixes: 510ded33e075 ("slab: implement slab_root_caches list")
Signed-off-by: Qian Cai <cai@lca.pw>
Reviewed-by: Tobin C. Harding <tobin@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
mm/slab.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/slab.c b/mm/slab.c
index f4658468b23e..843ecea9e336 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -4299,7 +4299,8 @@ static void show_symbol(struct seq_file *m, unsigned long address)
static int leaks_show(struct seq_file *m, void *p)
{
- struct kmem_cache *cachep = list_entry(p, struct kmem_cache, list);
+ struct kmem_cache *cachep = list_entry(p, struct kmem_cache,
+ root_caches_node);
struct page *page;
struct kmem_cache_node *n;
const char *name;
--
2.19.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH AUTOSEL 4.14 31/32] mm: make page ref count overflow check tighter and more explicit
[not found] <20190427014224.8274-1-sashal@kernel.org>
2019-04-27 1:42 ` [PATCH AUTOSEL 4.14 18/32] slab: fix a crash by reading /proc/slab_allocators Sasha Levin
@ 2019-04-27 1:42 ` Sasha Levin
2019-04-27 1:42 ` [PATCH AUTOSEL 4.14 32/32] mm: add 'try_get_page()' helper function Sasha Levin
2 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2019-04-27 1:42 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Linus Torvalds, Jann Horn, stable, Sasha Levin, linux-mm
From: Linus Torvalds <torvalds@linux-foundation.org>
[ Upstream commit f958d7b528b1b40c44cfda5eabe2d82760d868c3 ]
We have a VM_BUG_ON() to check that the page reference count doesn't
underflow (or get close to overflow) by checking the sign of the count.
That's all fine, but we actually want to allow people to use a "get page
ref unless it's already very high" helper function, and we want that one
to use the sign of the page ref (without triggering this VM_BUG_ON).
Change the VM_BUG_ON to only check for small underflows (or _very_ close
to overflowing), and ignore overflows which have strayed into negative
territory.
Acked-by: Matthew Wilcox <willy@infradead.org>
Cc: Jann Horn <jannh@google.com>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/linux/mm.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 58f2263de4de..4023819837a6 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -824,6 +824,10 @@ static inline bool is_device_public_page(const struct page *page)
#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */
+/* 127: arbitrary random number, small enough to assemble well */
+#define page_ref_zero_or_close_to_overflow(page) \
+ ((unsigned int) page_ref_count(page) + 127u <= 127u)
+
static inline void get_page(struct page *page)
{
page = compound_head(page);
@@ -831,7 +835,7 @@ static inline void get_page(struct page *page)
* Getting a normal page or the head of a compound page
* requires to already have an elevated page->_refcount.
*/
- VM_BUG_ON_PAGE(page_ref_count(page) <= 0, page);
+ VM_BUG_ON_PAGE(page_ref_zero_or_close_to_overflow(page), page);
page_ref_inc(page);
}
--
2.19.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH AUTOSEL 4.14 32/32] mm: add 'try_get_page()' helper function
[not found] <20190427014224.8274-1-sashal@kernel.org>
2019-04-27 1:42 ` [PATCH AUTOSEL 4.14 18/32] slab: fix a crash by reading /proc/slab_allocators Sasha Levin
2019-04-27 1:42 ` [PATCH AUTOSEL 4.14 31/32] mm: make page ref count overflow check tighter and more explicit Sasha Levin
@ 2019-04-27 1:42 ` Sasha Levin
2 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2019-04-27 1:42 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Linus Torvalds, Jann Horn, stable, Sasha Levin, linux-mm
From: Linus Torvalds <torvalds@linux-foundation.org>
[ Upstream commit 88b1a17dfc3ed7728316478fae0f5ad508f50397 ]
This is the same as the traditional 'get_page()' function, but instead
of unconditionally incrementing the reference count of the page, it only
does so if the count was "safe". It returns whether the reference count
was incremented (and is marked __must_check, since the caller obviously
has to be aware of it).
Also like 'get_page()', you can't use this function unless you already
had a reference to the page. The intent is that you can use this
exactly like get_page(), but in situations where you want to limit the
maximum reference count.
The code currently does an unconditional WARN_ON_ONCE() if we ever hit
the reference count issues (either zero or negative), as a notification
that the conditional non-increment actually happened.
NOTE! The count access for the "safety" check is inherently racy, but
that doesn't matter since the buffer we use is basically half the range
of the reference count (ie we look at the sign of the count).
Acked-by: Matthew Wilcox <willy@infradead.org>
Cc: Jann Horn <jannh@google.com>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/linux/mm.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 4023819837a6..ee0eae215210 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -839,6 +839,15 @@ static inline void get_page(struct page *page)
page_ref_inc(page);
}
+static inline __must_check bool try_get_page(struct page *page)
+{
+ page = compound_head(page);
+ if (WARN_ON_ONCE(page_ref_count(page) <= 0))
+ return false;
+ page_ref_inc(page);
+ return true;
+}
+
static inline void put_page(struct page *page)
{
page = compound_head(page);
--
2.19.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-27 1:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20190427014224.8274-1-sashal@kernel.org>
2019-04-27 1:42 ` [PATCH AUTOSEL 4.14 18/32] slab: fix a crash by reading /proc/slab_allocators Sasha Levin
2019-04-27 1:42 ` [PATCH AUTOSEL 4.14 31/32] mm: make page ref count overflow check tighter and more explicit Sasha Levin
2019-04-27 1:42 ` [PATCH AUTOSEL 4.14 32/32] mm: add 'try_get_page()' helper function Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).