From: Brendan Jackman <jackmanb@google.com>
To: Pedro Falcato <pfalcato@suse.de>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>, Jann Horn <jannh@google.com>,
<linux-kernel@vger.kernel.org>, <maple-tree@lists.infradead.org>,
<linux-mm@kvack.org>
Subject: Re: [PATCH 2/3] tools: testing: Use existing atomic.h for vma/radix-tree tests
Date: Wed, 27 Aug 2025 15:19:12 +0000 [thread overview]
Message-ID: <DCDB7IYZS73V.2KL54A53D1O1L@google.com> (raw)
In-Reply-To: <xz2m4q24kgig36wu3enk6qlsxo5xywsaffgivyubadsps5topi@6yupqs7b7cze>
On Wed Aug 27, 2025 at 12:56 PM UTC, Pedro Falcato wrote:
> On Wed, Aug 27, 2025 at 11:04:42AM +0000, Brendan Jackman wrote:
>> The shared userspace logic used for unit-testing radix-tree and VMA code
>> currently has its own replacements for atomics helpers. This is not
>> needed as the necessary APIs already have userspace implementations in
>> the tools tree. Switching over to that allows deleting a bit of code.
>>
>> Note that the implementation is different; while the version being
>> deleted here is implemented using liburcu, the existing version in tools
>> uses either x86 asm or compiler builtins. It's assumed that both are
>> equally likely to be correct.
>>
>> The tools tree's version of atomic_t is a struct type while the version
>> being deleted was just a typedef of an integer. This means it's no
>> longer valid to call __sync_bool_compare_and_swap() directly on it. One
>> option would be to just peek into the struct and call it on the field,
>> but it seems a little cleaner to just use the corresponding atomic.h
>> API. On non-x86 archs this is implemented using
>> __sync_val_compare_and_swap(). It's not clear why the old version uses
>> the bool variant instead of the generic "val" one, for now it's assumed
>> that this was a mistake.
>>
>
> I don't think it's a mistake. Namely we're checking if the cmpxchg occured.
> So in the new version you'll have trouble incrementing i_mmap_writeable from
> 0 to 1, where in practice you should (AIUI) see 0 -> 1 (old val = 0, retry) -> 2,
> which is obviously not correct here.
>
> At the very least you'll need some:
>
> do {
> } while(atomic_cmpxchg(&mapping->i_mmap_writeable, c, c+1) != c);
Oops, yeah my code is total nonsense here - thanks for paying attention.
I guess I "got away with it" because there's probably no actual races
going on when I run the tests...
Anyway I'll apply my brain properly next time I get the chance and send
a v2.
Thanks for the review!
next prev parent reply other threads:[~2025-08-27 15:19 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-27 11:04 [PATCH 0/3] tools: testing: Use existing atomic.h for vma/radix-tree tests Brendan Jackman
2025-08-27 11:04 ` [PATCH 1/3] tools: testing: Allow importing arch headers in shared.mk Brendan Jackman
2025-08-27 12:50 ` Pedro Falcato
2025-08-27 15:07 ` Brendan Jackman
2025-08-27 18:43 ` Liam R. Howlett
2025-08-28 1:00 ` Liam R. Howlett
2025-08-28 10:23 ` Lorenzo Stoakes
2025-08-28 11:59 ` Brendan Jackman
2025-08-27 11:04 ` [PATCH 2/3] tools: testing: Use existing atomic.h for vma/radix-tree tests Brendan Jackman
2025-08-27 12:56 ` Pedro Falcato
2025-08-27 15:19 ` Brendan Jackman [this message]
2025-08-28 1:05 ` Liam R. Howlett
2025-08-28 9:20 ` Brendan Jackman
2025-08-28 10:26 ` Lorenzo Stoakes
2025-08-27 11:04 ` [PATCH 3/3] tools: testing: Support EXTRA_CFLAGS in shared.mk Brendan Jackman
2025-08-27 12:57 ` Pedro Falcato
2025-08-28 1:04 ` Liam R. Howlett
2025-08-28 10:27 ` Lorenzo Stoakes
2025-08-28 10:28 ` [PATCH 0/3] tools: testing: Use existing atomic.h for vma/radix-tree tests Lorenzo Stoakes
2025-08-28 12:09 ` Brendan Jackman
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=DCDB7IYZS73V.2KL54A53D1O1L@google.com \
--to=jackmanb@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=maple-tree@lists.infradead.org \
--cc=pfalcato@suse.de \
--cc=vbabka@suse.cz \
/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).