* [PATCH 1/1] lib/alloc_tag: fix RCU imbalance in pgalloc_tag_get()
@ 2024-06-01 23:38 Suren Baghdasaryan
2024-06-03 9:31 ` Vlastimil Babka
0 siblings, 1 reply; 2+ messages in thread
From: Suren Baghdasaryan @ 2024-06-01 23:38 UTC (permalink / raw)
To: akpm
Cc: kent.overstreet, pasha.tatashin, vbabka, keescook, linux-mm,
linux-kernel, Suren Baghdasaryan, kernel test robot
put_page_tag_ref() should be called only when get_page_tag_ref() returns
a valid reference because only in that case get_page_tag_ref() enters RCU
read section while put_page_tag_ref() will call rcu_read_unlock() even if
the provided reference is NULL. Fix pgalloc_tag_get() which does not
follow this rule causing RCU imbalance. Add a warning in put_page_tag_ref()
to catch any future mistakes.
Fixes: cc92eba1c88b ("mm: fix non-compound multi-order memory accounting in __free_pages")
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202405271029.6d2f9c4c-lkp@intel.com
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
---
include/linux/pgalloc_tag.h | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/include/linux/pgalloc_tag.h b/include/linux/pgalloc_tag.h
index 86ba5d33e43b..9cacadbd61f8 100644
--- a/include/linux/pgalloc_tag.h
+++ b/include/linux/pgalloc_tag.h
@@ -37,6 +37,9 @@ static inline union codetag_ref *get_page_tag_ref(struct page *page)
static inline void put_page_tag_ref(union codetag_ref *ref)
{
+ if (WARN_ON(!ref))
+ return;
+
page_ext_put(page_ext_from_codetag_ref(ref));
}
@@ -102,9 +105,11 @@ static inline struct alloc_tag *pgalloc_tag_get(struct page *page)
union codetag_ref *ref = get_page_tag_ref(page);
alloc_tag_sub_check(ref);
- if (ref && ref->ct)
- tag = ct_to_alloc_tag(ref->ct);
- put_page_tag_ref(ref);
+ if (ref) {
+ if (ref->ct)
+ tag = ct_to_alloc_tag(ref->ct);
+ put_page_tag_ref(ref);
+ }
}
return tag;
base-commit: 065d3634d60843b8e338d405b844cc7f2e5e1c66
--
2.45.1.288.g0e0cd299f1-goog
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] lib/alloc_tag: fix RCU imbalance in pgalloc_tag_get()
2024-06-01 23:38 [PATCH 1/1] lib/alloc_tag: fix RCU imbalance in pgalloc_tag_get() Suren Baghdasaryan
@ 2024-06-03 9:31 ` Vlastimil Babka
0 siblings, 0 replies; 2+ messages in thread
From: Vlastimil Babka @ 2024-06-03 9:31 UTC (permalink / raw)
To: Suren Baghdasaryan, akpm
Cc: kent.overstreet, pasha.tatashin, keescook, linux-mm,
linux-kernel, kernel test robot
On 6/2/24 1:38 AM, Suren Baghdasaryan wrote:
> put_page_tag_ref() should be called only when get_page_tag_ref() returns
> a valid reference because only in that case get_page_tag_ref() enters RCU
> read section while put_page_tag_ref() will call rcu_read_unlock() even if
> the provided reference is NULL. Fix pgalloc_tag_get() which does not
> follow this rule causing RCU imbalance. Add a warning in put_page_tag_ref()
> to catch any future mistakes.
>
> Fixes: cc92eba1c88b ("mm: fix non-compound multi-order memory accounting in __free_pages")
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202405271029.6d2f9c4c-lkp@intel.com
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> Cc: Kent Overstreet <kent.overstreet@linux.dev>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> include/linux/pgalloc_tag.h | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/pgalloc_tag.h b/include/linux/pgalloc_tag.h
> index 86ba5d33e43b..9cacadbd61f8 100644
> --- a/include/linux/pgalloc_tag.h
> +++ b/include/linux/pgalloc_tag.h
> @@ -37,6 +37,9 @@ static inline union codetag_ref *get_page_tag_ref(struct page *page)
>
> static inline void put_page_tag_ref(union codetag_ref *ref)
> {
> + if (WARN_ON(!ref))
> + return;
> +
> page_ext_put(page_ext_from_codetag_ref(ref));
> }
>
> @@ -102,9 +105,11 @@ static inline struct alloc_tag *pgalloc_tag_get(struct page *page)
> union codetag_ref *ref = get_page_tag_ref(page);
>
> alloc_tag_sub_check(ref);
> - if (ref && ref->ct)
> - tag = ct_to_alloc_tag(ref->ct);
> - put_page_tag_ref(ref);
> + if (ref) {
> + if (ref->ct)
> + tag = ct_to_alloc_tag(ref->ct);
> + put_page_tag_ref(ref);
> + }
> }
>
> return tag;
>
> base-commit: 065d3634d60843b8e338d405b844cc7f2e5e1c66
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-03 9:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-01 23:38 [PATCH 1/1] lib/alloc_tag: fix RCU imbalance in pgalloc_tag_get() Suren Baghdasaryan
2024-06-03 9:31 ` Vlastimil Babka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox