From: Suren Baghdasaryan <surenb@google.com>
To: David Wang <00107082@163.com>
Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev,
linux-kernel@vger.kernel.org, linux-mm@kvack.org, lkp@intel.com,
oe-lkp@lists.linux.dev, oliver.sang@intel.com,
yuzhao@google.com
Subject: Re: [PATCH v2] mm/codetag: clear tags before swap
Date: Thu, 12 Dec 2024 15:18:01 -0800 [thread overview]
Message-ID: <CAJuCfpF2e7niEbR=nX2u0HZHq-7tjRGB=xV397pFpjdzBqUGfQ@mail.gmail.com> (raw)
In-Reply-To: <20241212082910.30826-1-00107082@163.com>
On Thu, Dec 12, 2024 at 12:29 AM David Wang <00107082@163.com> wrote:
>
> When CONFIG_MEM_ALLOC_PROFILING_DEBUG is set, kernel WARN would be
> triggered when calling __alloc_tag_ref_set() during swap:
>
> alloc_tag was not cleared (got tag for mm/filemap.c:1951)
> WARNING: CPU: 0 PID: 816 at ./include/linux/alloc_tag.h...
>
> Clear code tags before swap can fix the warning. And this patch also fix
> a potential invalid address dereference in alloc_tag_add_check() when
> CONFIG_MEM_ALLOC_PROFILING_DEBUG is set and ref->ct is CODETAG_EMPTY,
> which is defined as ((void *)1).
>
> Signed-off-by: David Wang <00107082@163.com>
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202412112227.df61ebb-lkp@intel.com
> Suggested-by: Suren Baghdasaryan <surenb@google.com>
I didn't really suggest much in this patch, so please replace above
Suggested-by with:
Acked-by: Suren Baghdasaryan <surenb@google.com>
Thanks for fixing this!
> ---
> include/linux/alloc_tag.h | 2 +-
> lib/alloc_tag.c | 7 +++++++
> 2 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h
> index 7c0786bdf9af..cba024bf2db3 100644
> --- a/include/linux/alloc_tag.h
> +++ b/include/linux/alloc_tag.h
> @@ -135,7 +135,7 @@ static inline struct alloc_tag_counters alloc_tag_read(struct alloc_tag *tag)
> #ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG
> static inline void alloc_tag_add_check(union codetag_ref *ref, struct alloc_tag *tag)
> {
> - WARN_ONCE(ref && ref->ct,
> + WARN_ONCE(ref && ref->ct && !is_codetag_empty(ref),
> "alloc_tag was not cleared (got tag for %s:%u)\n",
> ref->ct->filename, ref->ct->lineno);
>
> diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c
> index 35f7560a309a..3a0413462e9f 100644
> --- a/lib/alloc_tag.c
> +++ b/lib/alloc_tag.c
> @@ -209,6 +209,13 @@ void pgalloc_tag_swap(struct folio *new, struct folio *old)
> return;
> }
>
> + /*
> + * Clear tag references to avoid debug warning when using
> + * __alloc_tag_ref_set() with non-empty reference.
> + */
> + set_codetag_empty(&ref_old);
> + set_codetag_empty(&ref_new);
> +
> /* swap tags */
> __alloc_tag_ref_set(&ref_old, tag_new);
> update_page_tag_ref(handle_old, &ref_old);
> --
> 2.39.2
>
next prev parent reply other threads:[~2024-12-12 23:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-11 15:08 [linus:master] [mm/codetag] 51f43d5d82: WARNING:at_include/linux/alloc_tag.h:#__alloc_tag_ref_set kernel test robot
2024-12-12 2:12 ` David Wang
2024-12-12 4:01 ` [PATCH] mm/codetag: clear tags before swap David Wang
2024-12-12 7:09 ` Suren Baghdasaryan
2024-12-12 8:17 ` David Wang
2024-12-12 8:29 ` [PATCH v2] " David Wang
2024-12-12 23:18 ` Suren Baghdasaryan [this message]
2024-12-13 1:33 ` [PATCH v3] " David Wang
2024-12-13 4:12 ` Andrew Morton
2024-12-13 4:22 ` Suren Baghdasaryan
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='CAJuCfpF2e7niEbR=nX2u0HZHq-7tjRGB=xV397pFpjdzBqUGfQ@mail.gmail.com' \
--to=surenb@google.com \
--cc=00107082@163.com \
--cc=akpm@linux-foundation.org \
--cc=kent.overstreet@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lkp@intel.com \
--cc=oe-lkp@lists.linux.dev \
--cc=oliver.sang@intel.com \
--cc=yuzhao@google.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