All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev, "kernelci.org bot" <bot@kernelci.org>
Subject: Re: [PATCH] mm/page_alloc: Mark pagesets as __maybe_unused
Date: Wed, 16 Feb 2022 08:50:51 -0700	[thread overview]
Message-ID: <Yg0dWwfpGyGC/q40@dev-arch.archlinux-ax161> (raw)
In-Reply-To: <YgyvCTiIWAFKq6G4@linutronix.de>

On Wed, Feb 16, 2022 at 09:00:09AM +0100, Sebastian Andrzej Siewior wrote:
> On 2022-02-15 11:43:22 [-0700], Nathan Chancellor wrote:
> > Commit 9983a9d577db ("locking/local_lock: Make the empty local_lock_*()
> > function a macro.") in the -tip tree converted the local_lock_*()
> > functions into macros, which causes a warning with clang with
> > CONFIG_PREEMPT_RT=n + CONFIG_DEBUG_LOCK_ALLOC=n:
> > 
> >   mm/page_alloc.c:131:40: error: variable 'pagesets' is not needed and will not be emitted [-Werror,-Wunneeded-internal-declaration]
> >   static DEFINE_PER_CPU(struct pagesets, pagesets) = {
> >                                          ^
> >   1 error generated.
> > 
> > Prior to that change, clang was not able to tell that pagesets was
> > unused in this configuration because it does not perform cross function
> > analysis in the frontend. After that change, it sees that the macros
> > just do a typecheck on the lock member of pagesets, which is evaluated
> > at compile time (so the variable is technically "used"), meaning the
> > variable is not needed in the final assembly, as the warning states.
> > 
> > Mark the variable as __maybe_unused to make it clear to clang that this
> > is expected in this configuration so there is no more warning.
> > 
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1593
> > Reported-by: "kernelci.org bot" <bot@kernelci.org>
> > Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> > Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> > ---
> >  mm/page_alloc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> > index 7ff1efc84205..406f5d0c610f 100644
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -128,7 +128,7 @@ static DEFINE_MUTEX(pcp_batch_high_lock);
> >  struct pagesets {
> >  	local_lock_t lock;
> >  };
> > -static DEFINE_PER_CPU(struct pagesets, pagesets) = {
> > +static DEFINE_PER_CPU(struct pagesets, pagesets) __maybe_unused = {
> 
> No, I need to think of something else then for the local_lock thing.  I
> haven't seen it with gcc. There is probably more than just this one.

As far as I am aware, this is a clang only warning.

From my brief audit of uses of local_lock_t, I believe this is the only
one that will trigger this warning because every other structure that
has a local_lock_t also has another member that is unconditionally used,
meaning an instance of that structure will not just be used at compile
time. In this case, 'struct pagesets' ONLY contains a local_lock_t,
which is only used at compile time in this configuration, hence the
warning.

Of course, if you can think of something that works for your use case
and doesn't make clang warn, that would be ideal but I don't see this
patch as the worst solution. I'll run through my full set of builds
tonight and see if there are any other instances of this warning; this
particular instance was visible in several defconfigs so I fixed it
first.

Cheers,
Nathan

      reply	other threads:[~2022-02-16 15:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-15 18:43 [PATCH] mm/page_alloc: Mark pagesets as __maybe_unused Nathan Chancellor
2022-02-16  8:00 ` Sebastian Andrzej Siewior
2022-02-16 15:50   ` Nathan Chancellor [this message]

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=Yg0dWwfpGyGC/q40@dev-arch.archlinux-ax161 \
    --to=nathan@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=bot@kernelci.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=llvm@lists.linux.dev \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.