Re: URCU feature request?

Thobias Knudsen via lttng-dev <[email protected]> Tue, 2 Sep 2025 23:06:08 +0200
Newsgroups org.lttng.lists.lttng-dev
Message-ID <CAKGpciq+ixOVGN7TXYaF336ZEL_mOejzic5BvaKbexwwn_aqOQ@mail.gmail.com>
--0000000000001577db063dd7dc69
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

> We usually rely on the debugging code in rcu_dereference() to check this
> sort of thing.  Or are you worried about the user leaking RCU-protected
> pointers out past the rcu_read_unlock()?

Yes, that is what I'm worried about. For my case when using URCU that is my
biggest concern, as the debug macro "library" I made checks everything
else, if I haven't overlooked anything.

Thanks
Thobias

tir. 2. sep. 2025 kl. 22:33 skrev Paul E. McKenney <[email protected]>:

> On Tue, Sep 02, 2025 at 04:24:16PM +0200, Thobias Knudsen wrote:
> > Figured out what rcu_read_ongoing does. It just returns true if it's
> called
> > within a read section and false otherwise. The problem for catching
> whether
> > reads are done outside read sections is that you can not make macros fo=
r
> > read and write operations. e.g. ptr->a =3D 4;.
>
> We usually rely on the debugging code in rcu_dereference() to check this
> sort of thing.  Or are you worried about the user leaking RCU-protected
> pointers out past the rcu_read_unlock()?
>
>                                                         Thanx, Paul
>
> > tir. 2. sep. 2025 kl. 16:17 skrev Thobias Knudsen <[email protected]>:
> >
> > > > I suspect that what you are trying to achieve is validation that
> > > > calls to functions that require to be within a RCU read-side critic=
al
> > > > section such as cds_lfht_lookup are indeed invoked from within a
> > > > critical section.
> > >
> > > Yes exactly, but not only for read sections. It could also be to
> validate
> > > that rcu_barrier isnt called within a callback function or that
> > > rcu_quiescent_state isnt called when thread is offline
> > >
> > > > We've added a "rcu_read_ongoing()" API for that purpose to liburcu
> > > > RCU flavors, but AFAIK it's not used for any kind of validation
> > > > within cds_lfht. This could indeed become a feature request that
> > > > would apply to all liburcu data structure APIs.
> > >
> > > I can't find any documentation on rcu_read_ongoing. Btw the
> documentation
> > > for urcu in general is scattered all around the repo it seems. It
> should
> > > have been all at one place imo. Should I make a feature request for
> it? I
> > > don't know how stuff works inside this repo though.
> > >
> > >
> > >
> > > man. 1. sep. 2025 kl. 17:09 skrev Mathieu Desnoyers <
> > > [email protected]>:
> > >
> > >> On 2025-08-31 16:48, Thobias Knudsen wrote:
> > >> > BTW i've made a macro library which overrides the
> > >> > urcu and lfht functions. It checks that you call the functions in
> the
> > >> > correct order. This has been really useful for debugging and I
> think it
> > >> > would be useful to have it integrated into urcu to make the it mor=
e
> > >> user
> > >> > friendly. you could have it integrated with the macro DEBUG_RCU or
> make
> > >> > a new one, maybe DEBUG_FUNCTION_CALL_ORDER. The only thing it
> doesn't
> > >> > catch is if you continue to use data from cds_lfht_lookup() after
> > >> > rcu_read_unlock()
> > >>
> > >> I suspect that what you are trying to achieve is validation that
> > >> calls to functions that require to be within a RCU read-side critica=
l
> > >> section such as cds_lfht_lookup are indeed invoked from within a
> > >> critical section.
> > >>
> > >> We've added a "rcu_read_ongoing()" API for that purpose to liburcu
> > >> RCU flavors, but AFAIK it's not used for any kind of validation
> > >> within cds_lfht. This could indeed become a feature request that
> > >> would apply to all liburcu data structure APIs.
> > >>
> > >> Thanks,
> > >>
> > >> Mathieu
> > >>
> > >> >
> > >> > s=C3=B8n. 31. aug. 2025 kl. 22:42 skrev Thobias Knudsen <
> [email protected]
> > >> > <mailto:[email protected]>>:
> > >> >
> > >> >     First question: why isn't Userspace RCU more popular?
> > >> >     Second question: Why isn't it possible to create issues in the
> urcu
> > >> >     repo? Im asking for a feature here:
> > >> >     Is it possible to make a function which checks if there are mo=
re
> > >> >     callbacks queued by call_rcu? I need that because there are so=
me
> > >> >     callbacks which call call_rcu, and then calling rcu_barrier on=
ce
> > >> >     isn't enough and I therefore need a way to check if there are
> still
> > >> >     callbacks to wait on before terminating the program. No worrie=
s
> if
> > >> >     this is too much to ask for or if it isn't possible. This
> > >> >     functionality is only needed in termination because otherwise
> > >> >     isn't needed to call rcu_barrier multiple times (at least so
> far)
> > >> >
> > >> >     Best regards
> > >> >     Thobias
> > >> >
> > >> >
> > >>
> > >>
> > >> --
> > >> Mathieu Desnoyers
> > >> EfficiOS Inc.
> > >> https://www.efficios.com
> > >>
> > >
>

--0000000000001577db063dd7dc69
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">&gt; We usually rely on the debugging code in rcu_derefere=
nce() to check this<br>&gt; sort of thing.=C2=A0 Or are you worried about t=
he user leaking RCU-protected<br>&gt; pointers out past the rcu_read_unlock=
()?<div><br></div><div>Yes, that is what I&#39;m worried about. For my case=
 when using URCU that is my biggest concern, as the debug macro &quot;libra=
ry&quot; I made checks everything else, if I haven&#39;t overlooked anythin=
g.</div><div><br></div><div>Thanks</div><div>Thobias</div></div><br><div cl=
ass=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_a=
ttr">tir. 2. sep. 2025 kl. 22:33 skrev Paul E. McKenney &lt;<a href=3D"mail=
to:[email protected]">[email protected]</a>&gt;:<br></div><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid =
rgb(204,204,204);padding-left:1ex">On Tue, Sep 02, 2025 at 04:24:16PM +0200=
, Thobias Knudsen wrote:<br>
&gt; Figured out what rcu_read_ongoing does. It just returns true if it&#39=
;s called<br>
&gt; within a read section and false otherwise. The problem for catching wh=
ether<br>
&gt; reads are done outside read sections is that you can not make macros f=
or<br>
&gt; read and write operations. e.g. ptr-&gt;a =3D 4;.<br>
<br>
We usually rely on the debugging code in rcu_dereference() to check this<br=
>
sort of thing.=C2=A0 Or are you worried about the user leaking RCU-protecte=
d<br>
pointers out past the rcu_read_unlock()?<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Thanx, Paul<br>
<br>
&gt; tir. 2. sep. 2025 kl. 16:17 skrev Thobias Knudsen &lt;<a href=3D"mailt=
o:[email protected]" target=3D"_blank">[email protected]</a>&gt;:<br>
&gt; <br>
&gt; &gt; &gt; I suspect that what you are trying to achieve is validation =
that<br>
&gt; &gt; &gt; calls to functions that require to be within a RCU read-side=
 critical<br>
&gt; &gt; &gt; section such as cds_lfht_lookup are indeed invoked from with=
in a<br>
&gt; &gt; &gt; critical section.<br>
&gt; &gt;<br>
&gt; &gt; Yes exactly, but not only for read sections. It could also be to =
validate<br>
&gt; &gt; that rcu_barrier isnt called within a callback function or that<b=
r>
&gt; &gt; rcu_quiescent_state isnt called when thread is offline<br>
&gt; &gt;<br>
&gt; &gt; &gt; We&#39;ve added a &quot;rcu_read_ongoing()&quot; API for tha=
t purpose to liburcu<br>
&gt; &gt; &gt; RCU flavors, but AFAIK it&#39;s not used for any kind of val=
idation<br>
&gt; &gt; &gt; within cds_lfht. This could indeed become a feature request =
that<br>
&gt; &gt; &gt; would apply to all liburcu data structure APIs.<br>
&gt; &gt;<br>
&gt; &gt; I can&#39;t find any documentation on rcu_read_ongoing. Btw the d=
ocumentation<br>
&gt; &gt; for urcu in general is scattered all around the repo it seems. It=
 should<br>
&gt; &gt; have been all at one place imo. Should I make a feature request f=
or it? I<br>
&gt; &gt; don&#39;t know how stuff works inside this repo though.<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; man. 1. sep. 2025 kl. 17:09 skrev Mathieu Desnoyers &lt;<br>
&gt; &gt; <a href=3D"mailto:[email protected]" target=3D"_blan=
k">[email protected]</a>&gt;:<br>
&gt; &gt;<br>
&gt; &gt;&gt; On 2025-08-31 16:48, Thobias Knudsen wrote:<br>
&gt; &gt;&gt; &gt; BTW i&#39;ve made a macro library which overrides the<br=
>
&gt; &gt;&gt; &gt; urcu and lfht functions. It checks that you call the fun=
ctions in the<br>
&gt; &gt;&gt; &gt; correct order. This has been really useful for debugging=
 and I think it<br>
&gt; &gt;&gt; &gt; would be useful to have it integrated into urcu to make =
the it more<br>
&gt; &gt;&gt; user<br>
&gt; &gt;&gt; &gt; friendly. you could have it integrated with the macro DE=
BUG_RCU or make<br>
&gt; &gt;&gt; &gt; a new one, maybe DEBUG_FUNCTION_CALL_ORDER. The only thi=
ng it doesn&#39;t<br>
&gt; &gt;&gt; &gt; catch is if you continue to use data from cds_lfht_looku=
p() after<br>
&gt; &gt;&gt; &gt; rcu_read_unlock()<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; I suspect that what you are trying to achieve is validation t=
hat<br>
&gt; &gt;&gt; calls to functions that require to be within a RCU read-side =
critical<br>
&gt; &gt;&gt; section such as cds_lfht_lookup are indeed invoked from withi=
n a<br>
&gt; &gt;&gt; critical section.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; We&#39;ve added a &quot;rcu_read_ongoing()&quot; API for that=
 purpose to liburcu<br>
&gt; &gt;&gt; RCU flavors, but AFAIK it&#39;s not used for any kind of vali=
dation<br>
&gt; &gt;&gt; within cds_lfht. This could indeed become a feature request t=
hat<br>
&gt; &gt;&gt; would apply to all liburcu data structure APIs.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Thanks,<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Mathieu<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; s=C3=B8n. 31. aug. 2025 kl. 22:42 skrev Thobias Knudsen =
&lt;<a href=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
m</a><br>
&gt; &gt;&gt; &gt; &lt;mailto:<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>&gt;&gt;:<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt;=C2=A0 =C2=A0 =C2=A0First question: why isn&#39;t Userspa=
ce RCU more popular?<br>
&gt; &gt;&gt; &gt;=C2=A0 =C2=A0 =C2=A0Second question: Why isn&#39;t it pos=
sible to create issues in the urcu<br>
&gt; &gt;&gt; &gt;=C2=A0 =C2=A0 =C2=A0repo? Im asking for a feature here:<b=
r>
&gt; &gt;&gt; &gt;=C2=A0 =C2=A0 =C2=A0Is it possible to make a function whi=
ch checks if there are more<br>
&gt; &gt;&gt; &gt;=C2=A0 =C2=A0 =C2=A0callbacks queued by call_rcu? I need =
that because there are some<br>
&gt; &gt;&gt; &gt;=C2=A0 =C2=A0 =C2=A0callbacks which call call_rcu, and th=
en calling rcu_barrier once<br>
&gt; &gt;&gt; &gt;=C2=A0 =C2=A0 =C2=A0isn&#39;t enough and I therefore need=
 a way to check if there are still<br>
&gt; &gt;&gt; &gt;=C2=A0 =C2=A0 =C2=A0callbacks to wait on before terminati=
ng the program. No worries if<br>
&gt; &gt;&gt; &gt;=C2=A0 =C2=A0 =C2=A0this is too much to ask for or if it =
isn&#39;t possible. This<br>
&gt; &gt;&gt; &gt;=C2=A0 =C2=A0 =C2=A0functionality is only needed in termi=
nation because otherwise<br>
&gt; &gt;&gt; &gt;=C2=A0 =C2=A0 =C2=A0isn&#39;t needed to call rcu_barrier =
multiple times (at least so far)<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt;=C2=A0 =C2=A0 =C2=A0Best regards<br>
&gt; &gt;&gt; &gt;=C2=A0 =C2=A0 =C2=A0Thobias<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; --<br>
&gt; &gt;&gt; Mathieu Desnoyers<br>
&gt; &gt;&gt; EfficiOS Inc.<br>
&gt; &gt;&gt; <a href=3D"https://www.efficios.com" rel=3D"noreferrer" targe=
t=3D"_blank">https://www.efficios.com</a><br>
&gt; &gt;&gt;<br>
&gt; &gt;<br>
</blockquote></div>

--0000000000001577db063dd7dc69--