[PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation

Joel Fernandes posted 1 patch 1 month, 2 weeks ago
kernel/rcu/rcutorture.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation
Posted by Joel Fernandes 1 month, 2 weeks ago
Fix incorrect operator precedence in the conditional that determines
when to call exp_current() during torture testing. The modulo
by 0xff appears to do nothing.

Fix by adding parentheses:

    !(torture_random(&rand) % 0xff)

Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
---
 kernel/rcu/rcutorture.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 82588ceed9da..9873a1d54c46 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -1749,7 +1749,7 @@ rcu_torture_writer(void *arg)
 					ulo[i] = cur_ops->get_comp_state();
 				gp_snap = cur_ops->start_gp_poll();
 				rcu_torture_writer_state = RTWS_POLL_WAIT;
-				if (cur_ops->exp_current && !torture_random(&rand) % 0xff)
+				if (cur_ops->exp_current && !(torture_random(&rand) % 0xff))
 					cur_ops->exp_current();
 				while (!cur_ops->poll_gp_state(gp_snap)) {
 					gp_snap1 = cur_ops->get_gp_state();
@@ -1771,7 +1771,7 @@ rcu_torture_writer(void *arg)
 					cur_ops->get_comp_state_full(&rgo[i]);
 				cur_ops->start_gp_poll_full(&gp_snap_full);
 				rcu_torture_writer_state = RTWS_POLL_WAIT_FULL;
-				if (cur_ops->exp_current && !torture_random(&rand) % 0xff)
+				if (cur_ops->exp_current && !(torture_random(&rand) % 0xff))
 					cur_ops->exp_current();
 				while (!cur_ops->poll_gp_state_full(&gp_snap_full)) {
 					cur_ops->get_gp_state_full(&gp_snap1_full);
-- 
2.34.1
Re: [PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation
Posted by Paul E. McKenney 1 month, 2 weeks ago
On Mon, Dec 22, 2025 at 07:44:07PM -0500, Joel Fernandes wrote:
> Fix incorrect operator precedence in the conditional that determines
> when to call exp_current() during torture testing. The modulo
> by 0xff appears to do nothing.
> 
> Fix by adding parentheses:
> 
>     !(torture_random(&rand) % 0xff)
> 
> Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>

Good eyes, thank you!

Unfortunately, Chris Mason beat you to it:

50d8a5d2a94c ("rcutorture: Correctly compute probability to invoke ->exp_current()")

I will add your Reported-by to that commit on my next rebase.

							Thanx, Paul

> ---
>  kernel/rcu/rcutorture.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
> index 82588ceed9da..9873a1d54c46 100644
> --- a/kernel/rcu/rcutorture.c
> +++ b/kernel/rcu/rcutorture.c
> @@ -1749,7 +1749,7 @@ rcu_torture_writer(void *arg)
>  					ulo[i] = cur_ops->get_comp_state();
>  				gp_snap = cur_ops->start_gp_poll();
>  				rcu_torture_writer_state = RTWS_POLL_WAIT;
> -				if (cur_ops->exp_current && !torture_random(&rand) % 0xff)
> +				if (cur_ops->exp_current && !(torture_random(&rand) % 0xff))
>  					cur_ops->exp_current();
>  				while (!cur_ops->poll_gp_state(gp_snap)) {
>  					gp_snap1 = cur_ops->get_gp_state();
> @@ -1771,7 +1771,7 @@ rcu_torture_writer(void *arg)
>  					cur_ops->get_comp_state_full(&rgo[i]);
>  				cur_ops->start_gp_poll_full(&gp_snap_full);
>  				rcu_torture_writer_state = RTWS_POLL_WAIT_FULL;
> -				if (cur_ops->exp_current && !torture_random(&rand) % 0xff)
> +				if (cur_ops->exp_current && !(torture_random(&rand) % 0xff))
>  					cur_ops->exp_current();
>  				while (!cur_ops->poll_gp_state_full(&gp_snap_full)) {
>  					cur_ops->get_gp_state_full(&gp_snap1_full);
> -- 
> 2.34.1
>
Re: [PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation
Posted by Steven Rostedt 1 month, 2 weeks ago
On Mon, 22 Dec 2025 17:12:18 -0800
"Paul E. McKenney" <paulmck@kernel.org> wrote:

> Good eyes, thank you!
> 
> Unfortunately, Chris Mason beat you to it:

Was it Chris or his AI? ;-)

-- Steve
Re: [PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation
Posted by Joel Fernandes 1 month, 2 weeks ago
On 12/23/2025 11:37 AM, Steven Rostedt wrote:
> On Mon, 22 Dec 2025 17:12:18 -0800
> "Paul E. McKenney" <paulmck@kernel.org> wrote:
> 
>> Good eyes, thank you!
>>
>> Unfortunately, Chris Mason beat you to it:
> 
> Was it Chris or his AI? ;-)

Does it matter? It is like saying, was it "Chris or his text editor". ;-)

 - Joel
Re: [PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation
Posted by Paul E. McKenney 1 month, 2 weeks ago
On Tue, Dec 23, 2025 at 12:22:51PM -0500, Joel Fernandes wrote:
> On 12/23/2025 11:37 AM, Steven Rostedt wrote:
> > On Mon, 22 Dec 2025 17:12:18 -0800
> > "Paul E. McKenney" <paulmck@kernel.org> wrote:
> > 
> >> Good eyes, thank you!
> >>
> >> Unfortunately, Chris Mason beat you to it:
> > 
> > Was it Chris or his AI? ;-)
> 
> Does it matter? It is like saying, was it "Chris or his text editor". ;-)

Adding Chris on CC for his thoughts on whether it was him or his AI and
whether or not this matters.  Should he choose to share any thoughts on
either topic.  ;-)

							Thanx, Paul
Re: [PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation
Posted by Joel Fernandes 1 month, 2 weeks ago

On 12/23/2025 12:28 PM, Paul E. McKenney wrote:
> On Tue, Dec 23, 2025 at 12:22:51PM -0500, Joel Fernandes wrote:
>> On 12/23/2025 11:37 AM, Steven Rostedt wrote:
>>> On Mon, 22 Dec 2025 17:12:18 -0800
>>> "Paul E. McKenney" <paulmck@kernel.org> wrote:
>>>
>>>> Good eyes, thank you!
>>>>
>>>> Unfortunately, Chris Mason beat you to it:
>>>
>>> Was it Chris or his AI? ;-)
>>
>> Does it matter? It is like saying, was it "Chris or his text editor". ;-)
> 
> Adding Chris on CC for his thoughts on whether it was him or his AI and
> whether or not this matters.  Should he choose to share any thoughts on
> either topic.  ;-)

"Was it Paul replying here, or was it his email client?" ;-)

Sorry I couldn't help. :-) What is a Christmas holiday if not for poking some fun?

 - Joel
Re: [PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation
Posted by Paul E. McKenney 1 month, 2 weeks ago
On Tue, Dec 23, 2025 at 12:30:01PM -0500, Joel Fernandes wrote:
> 
> 
> On 12/23/2025 12:28 PM, Paul E. McKenney wrote:
> > On Tue, Dec 23, 2025 at 12:22:51PM -0500, Joel Fernandes wrote:
> >> On 12/23/2025 11:37 AM, Steven Rostedt wrote:
> >>> On Mon, 22 Dec 2025 17:12:18 -0800
> >>> "Paul E. McKenney" <paulmck@kernel.org> wrote:
> >>>
> >>>> Good eyes, thank you!
> >>>>
> >>>> Unfortunately, Chris Mason beat you to it:
> >>>
> >>> Was it Chris or his AI? ;-)
> >>
> >> Does it matter? It is like saying, was it "Chris or his text editor". ;-)
> > 
> > Adding Chris on CC for his thoughts on whether it was him or his AI and
> > whether or not this matters.  Should he choose to share any thoughts on
> > either topic.  ;-)
> 
> "Was it Paul replying here, or was it his email client?" ;-)

"Yes!!!"  ;-)

> Sorry I couldn't help. :-) What is a Christmas holiday if not for poking some fun?

No problem!

I was half expecting something along the lines of "Is Paul an AI?" ;-)

							Thanx, Paul
Re: [PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation
Posted by Steven Rostedt 1 month, 2 weeks ago
On Tue, 23 Dec 2025 09:51:19 -0800
"Paul E. McKenney" <paulmck@kernel.org> wrote:

> On Tue, Dec 23, 2025 at 12:30:01PM -0500, Joel Fernandes wrote:
> > 
> > 
> > On 12/23/2025 12:28 PM, Paul E. McKenney wrote:  
> > > On Tue, Dec 23, 2025 at 12:22:51PM -0500, Joel Fernandes wrote:  
> > >> On 12/23/2025 11:37 AM, Steven Rostedt wrote:  
> > >>> On Mon, 22 Dec 2025 17:12:18 -0800
> > >>> "Paul E. McKenney" <paulmck@kernel.org> wrote:
> > >>>  
> > >>>> Good eyes, thank you!
> > >>>>
> > >>>> Unfortunately, Chris Mason beat you to it:  
> > >>>
> > >>> Was it Chris or his AI? ;-)  
> > >>
> > >> Does it matter? It is like saying, was it "Chris or his text editor". ;-)  

I think AI is a bit more powerful than a text editor. Unless you think
Chris is using emacs?

> > > 
> > > Adding Chris on CC for his thoughts on whether it was him or his AI and
> > > whether or not this matters.  Should he choose to share any thoughts on
> > > either topic.  ;-)  
> > 
> > "Was it Paul replying here, or was it his email client?" ;-)  
> 
> "Yes!!!"  ;-)
> 
> > Sorry I couldn't help. :-) What is a Christmas holiday if not for poking some fun?  
> 
> No problem!
> 
> I was half expecting something along the lines of "Is Paul an AI?" ;-)

I guess that begs the question. Is your intelligence artificial? ;-)

-- Steve
Re: [PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation
Posted by Chris Mason 1 month, 2 weeks ago
On 12/23/25 3:54 PM, Steven Rostedt wrote:
> On Tue, 23 Dec 2025 09:51:19 -0800
> "Paul E. McKenney" <paulmck@kernel.org> wrote:
> 
>> On Tue, Dec 23, 2025 at 12:30:01PM -0500, Joel Fernandes wrote:
>>>
>>>
>>> On 12/23/2025 12:28 PM, Paul E. McKenney wrote:  
>>>> On Tue, Dec 23, 2025 at 12:22:51PM -0500, Joel Fernandes wrote:  
>>>>> On 12/23/2025 11:37 AM, Steven Rostedt wrote:  
>>>>>> On Mon, 22 Dec 2025 17:12:18 -0800
>>>>>> "Paul E. McKenney" <paulmck@kernel.org> wrote:
>>>>>>  
>>>>>>> Good eyes, thank you!
>>>>>>>
>>>>>>> Unfortunately, Chris Mason beat you to it:  
>>>>>>
>>>>>> Was it Chris or his AI? ;-)  
>>>>>
>>>>> Does it matter? It is like saying, was it "Chris or his text editor". ;-)  
> 
> I think AI is a bit more powerful than a text editor. Unless you think
> Chris is using emacs?

In the interest of full disclosure, this review came from a local
version of my prompts that told AI to review as though it was a kernel
developer who preferred vi over emacs.

-chris
Re: [PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation
Posted by Paul E. McKenney 1 month, 2 weeks ago
On Tue, Dec 23, 2025 at 03:54:43PM -0500, Steven Rostedt wrote:
> On Tue, 23 Dec 2025 09:51:19 -0800
> "Paul E. McKenney" <paulmck@kernel.org> wrote:
> > On Tue, Dec 23, 2025 at 12:30:01PM -0500, Joel Fernandes wrote:
> > > On 12/23/2025 12:28 PM, Paul E. McKenney wrote:  
> > > > On Tue, Dec 23, 2025 at 12:22:51PM -0500, Joel Fernandes wrote:  
> > > >> On 12/23/2025 11:37 AM, Steven Rostedt wrote:  
> > > >>> On Mon, 22 Dec 2025 17:12:18 -0800
> > > >>> "Paul E. McKenney" <paulmck@kernel.org> wrote:

[ . . . ]

> > > > Adding Chris on CC for his thoughts on whether it was him or his AI and
> > > > whether or not this matters.  Should he choose to share any thoughts on
> > > > either topic.  ;-)  
> > > 
> > > "Was it Paul replying here, or was it his email client?" ;-)  
> > 
> > "Yes!!!"  ;-)
> > 
> > > Sorry I couldn't help. :-) What is a Christmas holiday if not for poking some fun?  
> > 
> > No problem!
> > 
> > I was half expecting something along the lines of "Is Paul an AI?" ;-)
> 
> I guess that begs the question. Is your intelligence artificial? ;-)

My many teachers and mentors along the way would likely argue that
they made a difference.  That would suggest that at least some of my
intelligence is created by the efforts of human beings.

Does that mean that my intelligence is artificial?

Choose your answer carefully.  But don't worry about my reaction to it.
After all, more than six decades of being incessantly targeted by
advertising has made me quite good at ignoring things.  ;-)

							Thanx, Paul
Re: [PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation
Posted by Steven Rostedt 1 month, 2 weeks ago
On Tue, 23 Dec 2025 15:50:18 -0800
"Paul E. McKenney" <paulmck@kernel.org> wrote:

> Does that mean that my intelligence is artificial?
> 
> Choose your answer carefully.  But don't worry about my reaction to it.
> After all, more than six decades of being incessantly targeted by
> advertising has made me quite good at ignoring things.  ;-)

Paul, I don't think your intelligence is artificial. Heck I usually tell
people the two most intelligent kernel developers are you and Al Viro.

Although, maybe all intelligence is artificial? Who knows?

-- Steve
Re: [PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation
Posted by Paul E. McKenney 1 month, 2 weeks ago
On Wed, Dec 24, 2025 at 09:14:50AM -0500, Steven Rostedt wrote:
> On Tue, 23 Dec 2025 15:50:18 -0800
> "Paul E. McKenney" <paulmck@kernel.org> wrote:
> 
> > Does that mean that my intelligence is artificial?
> > 
> > Choose your answer carefully.  But don't worry about my reaction to it.
> > After all, more than six decades of being incessantly targeted by
> > advertising has made me quite good at ignoring things.  ;-)
> 
> Paul, I don't think your intelligence is artificial. Heck I usually tell
> people the two most intelligent kernel developers are you and Al Viro.

Thank you for that high praise, but I fear that you might be selling
Al short.  His ability to dive into random code and find issues is
truly impressive.  Maybe we need him to teach the LLMs a thing or two?

> Although, maybe all intelligence is artificial? Who knows?

We each can choose our definitions to get whatever answer we want.
What could go wrong?  ;-)

							Thanx, Paul
Re: [PATCH] rcutorture: Fix operator precedence bug in exp_current() invocation
Posted by Joel Fernandes 1 month, 2 weeks ago

> On Dec 22, 2025, at 8:12 PM, Paul E. McKenney <paulmck@kernel.org> wrote:
> 
> On Mon, Dec 22, 2025 at 07:44:07PM -0500, Joel Fernandes wrote:
>> Fix incorrect operator precedence in the conditional that determines
>> when to call exp_current() during torture testing. The modulo
>> by 0xff appears to do nothing.
>> 
>> Fix by adding parentheses:
>> 
>>    !(torture_random(&rand) % 0xff)
>> 
>> Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
> 
> Good eyes, thank you!
> 
> Unfortunately, Chris Mason beat you to it:
> 
> 50d8a5d2a94c ("rcutorture: Correctly compute probability to invoke ->exp_current()")
> 
> I will add your Reported-by to that commit on my next rebase.

Ah, nice thanks.

 - Joel

> 
>                            Thanx, Paul
> 
>> ---
>> kernel/rcu/rcutorture.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
>> index 82588ceed9da..9873a1d54c46 100644
>> --- a/kernel/rcu/rcutorture.c
>> +++ b/kernel/rcu/rcutorture.c
>> @@ -1749,7 +1749,7 @@ rcu_torture_writer(void *arg)
>>                    ulo[i] = cur_ops->get_comp_state();
>>                gp_snap = cur_ops->start_gp_poll();
>>                rcu_torture_writer_state = RTWS_POLL_WAIT;
>> -                if (cur_ops->exp_current && !torture_random(&rand) % 0xff)
>> +                if (cur_ops->exp_current && !(torture_random(&rand) % 0xff))
>>                    cur_ops->exp_current();
>>                while (!cur_ops->poll_gp_state(gp_snap)) {
>>                    gp_snap1 = cur_ops->get_gp_state();
>> @@ -1771,7 +1771,7 @@ rcu_torture_writer(void *arg)
>>                    cur_ops->get_comp_state_full(&rgo[i]);
>>                cur_ops->start_gp_poll_full(&gp_snap_full);
>>                rcu_torture_writer_state = RTWS_POLL_WAIT_FULL;
>> -                if (cur_ops->exp_current && !torture_random(&rand) % 0xff)
>> +                if (cur_ops->exp_current && !(torture_random(&rand) % 0xff))
>>                    cur_ops->exp_current();
>>                while (!cur_ops->poll_gp_state_full(&gp_snap_full)) {
>>                    cur_ops->get_gp_state_full(&gp_snap1_full);
>> --
>> 2.34.1
>>