From: George Spelvin <lkml@SDF.ORG>
To: Alexander Duyck <alexander.duyck@gmail.com>
Cc: Kees Cook <keescook@chromium.org>,
Dan Williams <dan.j.williams@intel.com>,
linux-mm <linux-mm@kvack.org>,
Andrew Morton <akpm@linux-foundation.org>,
lkml@sdf.org
Subject: Re: [PATCH v2] mm/shuffle.c: Fix races in add_to_free_area_random()
Date: Wed, 18 Mar 2020 20:06:09 +0000 [thread overview]
Message-ID: <20200318200609.GE2281@SDF.ORG> (raw)
In-Reply-To: <CAKgT0UeZqKfvbbxv6sWROZkWWt6jcVxZgP7YG_M=9mMKD5+oow@mail.gmail.com>
On Wed, Mar 18, 2020 at 12:17:14PM -0700, Alexander Duyck wrote:
> I was just putting it out there as a possibility. What I have seen in
> the past is that under some circumstances gcc can be smart enough to
> interpret that as a "branch on carry". My thought was you are likely
> having to test the value against itself and then you might be able to
> make use of shift and carry flag to avoid that. In addition you could
> get away from having to recast a unsigned value as a signed one in
> order to perform the bit test.
Ah, yes, it would be nice if gcc could use the carry bit for r
rather than having to devote a whole register to it. But it has
to do two unrelated flag tests (zero and carry), and it's generally
pretty bad at taking advantage of preserved flag bits like that.
My ideal x86-64 object code would be:
shlq rand(%rip)
jz fixup
fixed:
jnc tail
jmp add_to_free_area
tail:
jmp add_to_free_area_tail
fixup:
pushq %rdx
pushq %rsi
pushq %rdi
call get_random_u64
popq %rdi
popq %rsi
popq %rdx
stc
adcq %rax,%rax
movq %rax, rand(%rip)
jmp fixed
... but I don't know how to induce GCC to generate that, and
the function doesn't seem worthy of platform-specific asm.
(Note that I have to use add add on the slow path because lea doesn't
set the carry bit.)
next prev parent reply other threads:[~2020-03-18 20:06 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-17 13:50 [PATCH] mm/shuffle.c: optimize add_to_free_area_random() George Spelvin
2020-03-17 21:44 ` Kees Cook
2020-03-17 23:06 ` George Spelvin
2020-03-17 23:38 ` Kees Cook
2020-03-18 1:44 ` [PATCH v2] mm/shuffle.c: Fix races in add_to_free_area_random() George Spelvin
2020-03-18 1:49 ` Randy Dunlap
2020-03-18 3:53 ` Dan Williams
2020-03-18 8:20 ` George Spelvin
2020-03-18 17:36 ` Dan Williams
2020-03-18 19:29 ` George Spelvin
2020-03-18 19:40 ` Dan Williams
2020-03-18 21:02 ` George Spelvin
2020-03-18 3:58 ` Kees Cook
2020-03-18 15:26 ` Alexander Duyck
2020-03-18 18:35 ` George Spelvin
2020-03-18 19:17 ` Alexander Duyck
2020-03-18 20:06 ` George Spelvin [this message]
2020-03-18 20:39 ` [PATCH v3] " George Spelvin
2020-03-18 21:34 ` Alexander Duyck
2020-03-18 22:49 ` George Spelvin
2020-03-18 22:57 ` Dan Williams
2020-03-18 23:18 ` George Spelvin
2020-03-19 12:05 ` [PATCH v4] " George Spelvin
2020-03-19 17:49 ` Alexander Duyck
2020-03-20 17:58 ` Kees Cook
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=20200318200609.GE2281@SDF.ORG \
--to=lkml@sdf.org \
--cc=akpm@linux-foundation.org \
--cc=alexander.duyck@gmail.com \
--cc=dan.j.williams@intel.com \
--cc=keescook@chromium.org \
--cc=linux-mm@kvack.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).