diff mbox series

[5/6] rcuscale: Do a proper cleanup if kfree_scale_init() fails

Message ID 20241106160223.42119-6-frederic@kernel.org (mailing list archive)
State New
Headers show
Series RCU torture for v6.13 | expand

Commit Message

Frederic Weisbecker Nov. 6, 2024, 4:02 p.m. UTC
From: "Uladzislau Rezki (Sony)" <urezki@gmail.com>

A static analyzer for C, Smatch, reports and triggers below
warnings:

   kernel/rcu/rcuscale.c:1215 rcu_scale_init()
   warn: inconsistent returns 'global &fullstop_mutex'.

The checker complains about, we do not unlock the "fullstop_mutex"
mutex, in case of hitting below error path:

<snip>
...
    if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
        pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
        WARN_ON_ONCE(1);
        return -1;
        ^^^^^^^^^^
...
<snip>

it happens because "-1" is returned right away instead of
doing a proper unwinding.

Fix it by jumping to "unwind" label instead of returning -1.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/rcu/ZxfTrHuEGtgnOYWp@pc636/T/
Fixes: 084e04fff160 ("rcuscale: Add laziness and kfree tests")
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
---
 kernel/rcu/rcuscale.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Neeraj Upadhyay Nov. 11, 2024, 9:54 a.m. UTC | #1
> diff --git a/kernel/rcu/rcuscale.c b/kernel/rcu/rcuscale.c
> index 6d37596deb1f..de7d511e6be4 100644
> --- a/kernel/rcu/rcuscale.c
> +++ b/kernel/rcu/rcuscale.c
> @@ -890,13 +890,13 @@ kfree_scale_init(void)
>  		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
>  			pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
>  			WARN_ON_ONCE(1);
> -			return -1;
> +			goto unwind;

Do we need to set firsterr = -1 here before "goto unwind"? Otherwise, 0
is returned from kfree_scale_init().

>  		}
>  
>  		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start > 3 * HZ)) {
>  			pr_alert("ERROR: call_rcu() CBs are being too lazy!\n");
>  			WARN_ON_ONCE(1);
> -			return -1;
> +			goto unwind;

Ditto


- Neeraj

>  		}
>  	}
>
Uladzislau Rezki Nov. 11, 2024, 10:53 a.m. UTC | #2
On Mon, Nov 11, 2024 at 03:24:38PM +0530, Neeraj Upadhyay wrote:
> 
> > diff --git a/kernel/rcu/rcuscale.c b/kernel/rcu/rcuscale.c
> > index 6d37596deb1f..de7d511e6be4 100644
> > --- a/kernel/rcu/rcuscale.c
> > +++ b/kernel/rcu/rcuscale.c
> > @@ -890,13 +890,13 @@ kfree_scale_init(void)
> >  		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
> >  			pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
> >  			WARN_ON_ONCE(1);
> > -			return -1;
> > +			goto unwind;
> 
> Do we need to set firsterr = -1 here before "goto unwind"? Otherwise, 0
> is returned from kfree_scale_init().
> 
> >  		}
> >  
> >  		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start > 3 * HZ)) {
> >  			pr_alert("ERROR: call_rcu() CBs are being too lazy!\n");
> >  			WARN_ON_ONCE(1);
> > -			return -1;
> > +			goto unwind;
> 
> Ditto
> 
Let me check it!

--
Uladzislau Rezki
Uladzislau Rezki Nov. 11, 2024, 11:22 a.m. UTC | #3
On Mon, Nov 11, 2024 at 11:53:45AM +0100, Uladzislau Rezki wrote:
> On Mon, Nov 11, 2024 at 03:24:38PM +0530, Neeraj Upadhyay wrote:
> > 
> > > diff --git a/kernel/rcu/rcuscale.c b/kernel/rcu/rcuscale.c
> > > index 6d37596deb1f..de7d511e6be4 100644
> > > --- a/kernel/rcu/rcuscale.c
> > > +++ b/kernel/rcu/rcuscale.c
> > > @@ -890,13 +890,13 @@ kfree_scale_init(void)
> > >  		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
> > >  			pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
> > >  			WARN_ON_ONCE(1);
> > > -			return -1;
> > > +			goto unwind;
> > 
> > Do we need to set firsterr = -1 here before "goto unwind"? Otherwise, 0
> > is returned from kfree_scale_init().
> > 
> > >  		}
> > >  
> > >  		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start > 3 * HZ)) {
> > >  			pr_alert("ERROR: call_rcu() CBs are being too lazy!\n");
> > >  			WARN_ON_ONCE(1);
> > > -			return -1;
> > > +			goto unwind;
> > 
> > Ditto
> > 
> Let me check it!
> 
Right you are. I will repost the patch to be align with a previous behaviour.

Thanks!

--
Uladzislau Rezki
diff mbox series

Patch

diff --git a/kernel/rcu/rcuscale.c b/kernel/rcu/rcuscale.c
index 6d37596deb1f..de7d511e6be4 100644
--- a/kernel/rcu/rcuscale.c
+++ b/kernel/rcu/rcuscale.c
@@ -890,13 +890,13 @@  kfree_scale_init(void)
 		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
 			pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
 			WARN_ON_ONCE(1);
-			return -1;
+			goto unwind;
 		}
 
 		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start > 3 * HZ)) {
 			pr_alert("ERROR: call_rcu() CBs are being too lazy!\n");
 			WARN_ON_ONCE(1);
-			return -1;
+			goto unwind;
 		}
 	}