Skip to contentSkip to conversation

xen: stop_machine: fill fn_result only in case of error.

PATCH Superseded [email protected] 2 participants 3 messages May 30, 2017 – May 31, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: stop_machine: fill fn_result only in case of error.

From: Gregory Herrero <[email protected]>

Since fn_result member is shared across all cpus, it must be filled only if an error happens. Assume CPU1 detects an error and set fn_result to -1, then CPU2 doesn't detect an error and set fn_result to 0. The error detected by CPU1 will be ignored.

---
 xen/common/stop_machine.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
xen/common/stop_machine.c +11 -3
index 304b783aae..22d246c7a4 100644
@@ -94,6 +94,7 @@ int stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu)
     stopmachine_data.fn_data = data;
     stopmachine_data.nr_cpus = nr_cpus;
     stopmachine_data.fn_cpu = cpu;
+    stopmachine_data.fn_result = 0;
     atomic_set(&stopmachine_data.done, 0);
     stopmachine_data.state = STOPMACHINE_START;
 
@@ -112,7 +113,11 @@ int stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu)
 
     stopmachine_set_state(STOPMACHINE_INVOKE);
     if ( (cpu == smp_processor_id()) || (cpu == NR_CPUS) )
-        stopmachine_data.fn_result = (*fn)(data);
+    {
+        ret = (*fn)(data);
+        if (ret)
+            stopmachine_data.fn_result = ret;
+    }
     stopmachine_wait_state();
     ret = stopmachine_data.fn_result;
 
@@ -150,8 +155,11 @@ static void stopmachine_action(unsigned long cpu)
         case STOPMACHINE_INVOKE:
             if ( (stopmachine_data.fn_cpu == smp_processor_id()) ||
                  (stopmachine_data.fn_cpu == NR_CPUS) )
-                stopmachine_data.fn_result =
-                    stopmachine_data.fn(stopmachine_data.fn_data);
+	    {
+                int ret = stopmachine_data.fn(stopmachine_data.fn_data);
+                if (ret)
+                    stopmachine_data.fn_result = ret;
+	    }
             break;
         default:
             break;
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 30.05.17 at 18:19, <[email protected]> wrote:

Since fn_result member is shared across all cpus, it must be filled only if an error happens. Assume CPU1 detects an error and set fn_result to -1, then CPU2 doesn't detect an error and set fn_result to 0. The error detected by CPU1 will be ignored.

First of all there's a difference between stop_machine_run()'s last argument being a valid CPU number or NR_CPUS - what you say above applies to the latter case only, so you should also state that.

And then even after your fix it'll remain ambiguous which error is being returned on case multiple failures occur (which isn't all that unlikely). This (almost unavoidable) effect should also be spelled out imo, and I think you want to use write_atomic() to actually store the error code.

Finally there a various coding style violations in the code you add.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
Quoted 10 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 30.05.17 at 18:19, <[email protected]> wrote:

Since fn_result member is shared across all cpus, it must be filled only if an error happens. Assume CPU1 detects an error and set fn_result to -1, then CPU2 doesn't detect an error and set fn_result to 0. The error detected by CPU1 will be ignored.

First of all there's a difference between stop_machine_run()'s last argument being a valid CPU number or NR_CPUS - what you say above applies to the latter case only, so you should also state that.

Make sense, I will mention that.

Quoted 6 lines

And then even after your fix it'll remain ambiguous which error is being returned on case multiple failures occur (which isn't all that unlikely). This (almost unavoidable) effect should also be spelled out imo, and I think you want to use write_atomic() to actually store the error code.

I agree, that's indeed ambiguous which error happens on which cpu. I will mention it in v2. And I will also use write_atomic().

Quoted 2 lines

Finally there a various coding style violations in the code you add.

Sorry for that, I will fix it.

Thanks,
Gregory

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel