linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Uros Bizjak <ubizjak@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] llist: Use try_cmpxchg in llist_add_batch and llist_del_first
Date: Mon, 15 Aug 2022 21:28:29 +0200	[thread overview]
Message-ID: <CAFULd4Ydo2BR3-kvHPeabzyHExW2GM3pfLiWa2uStrLDW52buA@mail.gmail.com> (raw)
In-Reply-To: <CAFULd4YuYhNmhx3tBwBeR=ascfy=BZfZKk4e7vMq6gy06zk41Q@mail.gmail.com>

On Mon, Aug 15, 2022 at 9:20 PM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> On Mon, Aug 15, 2022 at 3:48 AM Andrew Morton <akpm@linux-foundation.org> wrote:
> >
> > On Tue, 12 Jul 2022 16:49:17 +0200 Uros Bizjak <ubizjak@gmail.com> wrote:
> >
> > > Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in
> > > llist_add_batch and llist_del_first. x86 CMPXCHG instruction returns
> > > success in ZF flag, so this change saves a compare after cmpxchg.
> > >
> > > Also, try_cmpxchg implicitly assigns old *ptr value to "old" when
> > > cmpxchg fails, enabling further code simplifications.
> > >
> > > No functional change intended.
> >
> > Well this is strange.  Your innocuous little patch:
>
> [...]
>
> > Does this:
> >
> > x1:/usr/src/25> size lib/llist.o-before lib/llist.o-after
> >    text    data     bss     dec     hex filename
> >     541      24       0     565     235 lib/llist.o-before
> >     940      24       0     964     3c4 lib/llist.o-after
> >
> > with x86_64 allmodconfig, gcc-11.1.0.
> >
> > No change with allnoconfig, some bloat with defconfig.
> >
> > I was too lazy to figure out why this happened, but it'd be great if
> > someone could investigate.  Something has gone wrong somewhere.
>
> Sanitizer is detecting a comparison with a constant and emits:
>
>  132:    f0 48 0f b1 2b           lock cmpxchg %rbp,(%rbx)
>  137:    41 0f 94 c6              sete   %r14b
>  13b:    31 ff                    xor    %edi,%edi
>  13d:    44 89 f6                 mov    %r14d,%esi
>  140:    e8 00 00 00 00           call   145 <llist_add_batch+0xc5>
>             141: R_X86_64_PLT32    __sanitizer_cov_trace_const_cmp1-0x4
>
> Since a new call is inserted, the compiler has to save all
> call-clobbered variables around the call, this triggers another call
> to __kasan_check_write. Finally, stack checking is emitted for patched

Actually, this second __kasan_check_write is for the write in case of
cmpxchg failure.

Uros.

      reply	other threads:[~2022-08-15 21:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12 14:49 [PATCH] llist: Use try_cmpxchg in llist_add_batch and llist_del_first Uros Bizjak
2022-08-15  1:48 ` Andrew Morton
2022-08-15 19:20   ` Uros Bizjak
2022-08-15 19:28     ` Uros Bizjak [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=CAFULd4Ydo2BR3-kvHPeabzyHExW2GM3pfLiWa2uStrLDW52buA@mail.gmail.com \
    --to=ubizjak@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.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 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).