Skip to contentSkip to conversation

rcuscale: Do a proper cleanup if kfree_scale_init() fails

PATCH In review Uladzislau Rezki (Sony) 2 participants 4 messages Nov 13, 2024

Subsystems (2)
lore
Share & tools
lore

Uladzislau Rezki (Sony)

author maintainer
#0 lore raw

PATCH v2 1/2 rcuscale: Do a proper cleanup if kfree_scale_init() fails

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.

---
 kernel/rcu/rcuscale.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/rcu/rcuscale.c +4 -2
index 6d37596deb1f..d360fa44b234 100644
@@ -890,13 +890,15 @@ 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;
+			firsterr = -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;
+			firsterr = -1;
+			goto unwind;
 		}
 	}
 
Signature · 1 line
2.39.5
author maintainer
#1 lore raw

PATCH v2 2/2 rcuscale: Remove redundant WARN_ON_ONCE() splat

There are two places where WARN_ON_ONCE() is called two times in the error paths. One which is encapsulated into if() condition and another one, which is unnecessary, is placed in the brackets.

Remove an extra WARN_ON_ONCE() splat which is in brackets.

---
 kernel/rcu/rcuscale.c | 2 --
 1 file changed, 2 deletions(-)
kernel/rcu/rcuscale.c +0 -2
index d360fa44b234..0f3059b1b80d 100644
@@ -889,14 +889,12 @@ 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);
 			firsterr = -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);
 			firsterr = -1;
 			goto unwind;
 		}
Signature · 1 line
2.39.5
Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] rcuscale: Remove redundant WARN_ON_ONCE() splat

Quoted 9 lines · Uladzislau Rezki (Sony)

There are two places where WARN_ON_ONCE() is called two times in the error paths. One which is encapsulated into if() condition and another one, which is unnecessary, is placed in the brackets.

Remove an extra WARN_ON_ONCE() splat which is in brackets.

---

- Neeraj

Reviewed-by on v2 1/2
#3 lore raw
In reply to Uladzislau Rezki (Sony)
Quoted 22 lines · Uladzislau Rezki (Sony)

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.

Quoted 8 lines

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

---

- Neeraj