From: Alan Huang <mmpgouride@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Christoph Hellwig <hch@infradead.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
Peter Zijlstra <peterz@infradead.org>, RCU <rcu@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
kernel-team@meta.com, Steven Rostedt <rostedt@goodmis.org>,
andrii@kernel.org
Subject: Re: [PATCH rcu] srcu: Guarantee non-negative return value from srcu_read_lock()
Date: Thu, 24 Oct 2024 00:46:32 +0800 [thread overview]
Message-ID: <09DF4DE0-1694-4B06-84A9-A0E1DA1B3109@gmail.com> (raw)
In-Reply-To: <CAEf4BzaqXhq3q5kXSAgH7H3tibC3wFU7R9zr5fcwcddT-r6wUw@mail.gmail.com>
On Oct 24, 2024, at 00:34, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
>
> On Tue, Oct 22, 2024 at 11:40 PM Christoph Hellwig <hch@infradead.org> wrote:
>>
>> On Tue, Oct 22, 2024 at 10:29:13AM -0700, Andrii Nakryiko wrote:
>>>>
>>>> Would this work?
>>>>
>>>> #define SRCU_INVALID_INDEX -1
>>>>
>>>
>>> But why?
>>
>> Becaue it very clearly documents what is going on.
>
> So does saying "returned value is going to be non-negative, always".
> It's not some weird and unusual thing in C by any means.
>
>>
>>> It's a nice property to have an int-returning API where valid
>>> values are only >= 0, so callers are free to use the entire negative
>>> range (not just -1) for whatever they need to store in case there is
>>> no srcu_idx value.
>>
>> Well, if you have a concrete use case for that we can probably live
>> with it, but I'd rather have that use case extremely well documented,
>> as it will be very puzzling to the reader.
>>
>
> See [0] for what Peter is proposing. Note hprobe_init() and its use of
> `srcu_idx < 0` as a mark that there is no SRCU "session" associated
> with the uprobe. Now, if we say that SRCU_INVALID_INDEX is the only
> invalid value, it leaves a question: what to do with other negative
> srcu_idx values? Are they valid? Should I now WARN() on "unknown
> invalid" values? Why all these complications? I'd rather just not have
> a unified hprobe_init() at that point, TBH.
>
> But anyways, taking a step back. Take idr_alloc()/idr_alloc_cyclic()
> APIs as an example. They return int, but valid IDs are documented to
> be positive. This leaves users of this API free to use int to store ID
> in their data structures, knowing that <= 0 is "no ID", and if
> necessary, they can have multiple possible "no ID" situations.
>
> Same principle here. Why prescribing a randomly picked -1 as the only
> "valid" invalid value, if anything negative is clearly impossible.
>
A IS_INVALID_SRCU_INDEX macro would suffice, you need the condition anyway.
>
> [0] https://lore.kernel.org/linux-trace-kernel/20241018101647.GA36494@noisy.programming.kicks-ass.net/
next prev parent reply other threads:[~2024-10-23 16:46 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-21 22:13 Paul E. McKenney
2024-10-21 23:50 ` Andrii Nakryiko
2024-10-22 0:21 ` Paul E. McKenney
2024-10-22 2:01 ` Andrii Nakryiko
2024-10-22 3:30 ` Paul E. McKenney
2024-10-22 3:40 ` Andrii Nakryiko
2024-10-22 7:07 ` Peter Zijlstra
2024-10-22 14:27 ` Paul E. McKenney
2024-10-22 6:51 ` Christoph Hellwig
2024-10-22 7:06 ` Peter Zijlstra
2024-10-22 7:07 ` Christoph Hellwig
2024-10-22 7:10 ` Peter Zijlstra
2024-10-22 7:13 ` Christoph Hellwig
2024-10-22 14:26 ` Paul E. McKenney
2024-10-22 17:29 ` Andrii Nakryiko
2024-10-23 6:40 ` Christoph Hellwig
2024-10-23 16:34 ` Andrii Nakryiko
2024-10-23 16:46 ` Alan Huang [this message]
2024-10-23 16:59 ` Andrii Nakryiko
2024-10-23 6:58 ` Alan Huang
2024-10-23 16:40 ` Paul E. McKenney
2024-10-23 16:56 ` Alan Huang
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=09DF4DE0-1694-4B06-84A9-A0E1DA1B3109@gmail.com \
--to=mmpgouride@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=hch@infradead.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.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
all inboxes | Powered by JetHome®