lib/alloc_tag: fix RCU imbalance in pgalloc_tag_get()
authorSuren Baghdasaryan <surenb@google.com>
Sat, 1 Jun 2024 23:38:40 +0000 (16:38 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 15 Jun 2024 17:43:05 +0000 (10:43 -0700)
commita273559e9eb68cb58c57803d76a1622b8324a878
tree8336be723cd6f1c07c471cb26857e912d7667cb4
parentc944bf60c16a65ae812a59fd1b66f6c9e18c91c9
lib/alloc_tag: fix RCU imbalance in pgalloc_tag_get()

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.

Link: https://lkml.kernel.org/r/20240601233840.617458-1-surenb@google.com
Fixes: cc92eba1c88b ("mm: fix non-compound multi-order memory accounting in __free_pages")
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202405271029.6d2f9c4c-lkp@intel.com
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Kees Cook <keescook@chromium.org>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/pgalloc_tag.h