Skip to contentSkip to conversation

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

PATCH In review [email protected] 2 participants 2 messages May 31, 2017

lore
Share & tools
lore
#0 lore raw

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

From: Gregory Herrero <[email protected]>

When stop_machine_run() is called with NR_CPUS as last argument, fn_result member must be filled only if an error happens since it is shared across all cpus.

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.

Note that in case multiple failures occur on different CPUs, only the last error will be reported.

---
V3:
- Correct indentation. (Wei Liu)
V2:
- Add more details in commit description. (Jan Beulich)
- Use write_atomic() when writing fn_result. (Jan Beulich)

---
 xen/common/stop_machine.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
xen/common/stop_machine.c +11 -3
index 304b783aae..1f4af0e9f1 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 )
+            write_atomic(&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 )
+                    write_atomic(&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
Reviewed-by on v3 1/1
#1 lore raw
Quoted 6 lines · On Wed, May 31, 2017 at 03:06:15PM +0200, [email protected] wrote:

From: Gregory Herrero <[email protected]>

When stop_machine_run() is called with NR_CPUS as last argument, fn_result member must be filled only if an error happens since it is shared across all cpus.

Quoted 8 lines

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.

Note that in case multiple failures occur on different CPUs, only the last error will be reported.

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