[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/4] xen: make stop_machine_run() take const void *


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Tue, 3 Nov 2026 10:29:17 +0000
  • Accept-language: en-US, uk-UA, ru-RU
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=EsXl/aeo0boVRCT0OB9Zheu0UgODdNyiCYv7d8Cc3q0=; b=nkvLm4M2uaZHJ/F3OSrF3UwdkQ74JpfPf+8pkLIzabARSVppVrDFv2On+PW7Kxc2FdSuIE1sXLWiZyMeMdOqBGuKFblUwR7BU/x06xYzNX7ubjXOXY3Dp2imod4eRer0DzfcQGEGYMWy1/JggxFZ/inr5wkNIRd2JoaJL1vUOCWmZd/cmXGWSwOoceVtDPixOoabP5GAvaZbYrJFo0TXb1eDo+39Pnqv8tyhade2T74Opklk8iRe0o7UxUy/0sk0s91+dQhhnDgwtfGN+1Xss9IzW3YkZ+L3kiMUu+0mkoSVYgMRxCmXTBaHTYt7qKeZq7vr1NVusOcSqw/Bm4jdng==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xPpa6g66JBP/h715Quk7X0EIFkPH7InETV0f/0Dxwe8PYmYSrlFLM64xYLIMOPFc2+FOFQSxkzz6Oz6dEGO/06M2obmK4O3fjyA7Uh0Cd2jdOXSRdkaZLc5jdMpMRM3pfe/j6kgY01CJt9pOoC5XkYqsqIrLuof+m4RHoOEUk6akLWIIMeCL+6kXRRJMhiCBWLcy4EZK6dM7LYDP/eCExKcKDlnEerY7suiqp/BzdgTe24pjWOvFt1h2O5HQODkndwTrNih/4t4Id6D1HxX0Pfn54FAsPI3IiHa35IOS75kexy+f9Nk3LYy5O53Y6zXGIwhpetmV2wYGEABLKQuGkg==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>
  • Delivery-date: Tue, 03 Nov 2026 10:29:24 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHda34uLj3vzse0MkyTNG2xjUiWVg==
  • Thread-topic: [PATCH 1/4] xen: make stop_machine_run() take const void *

MISRA C Rule 11.8 forbids casts that remove the const qualifier from
the pointed-to type. On Arm, enable_cpu_capabilities() and
enable_nonboot_cpu_caps() cast a const struct arm_cpu_capabilities
pointer to void * so that it can be passed to the capability enable
callback, either directly or through stop_machine_run().

None of the stop_machine_run() callbacks modify the data they are
given. Make stop_machine_run() and its callback type take const void *,
and update the callbacks to match:

 - the Arm capability enable hook and its implementations
   (enable_smccc_arch_workaround_1(), enable_spectre_bhb_workaround(),
   enable_bp_inv_hardening() and enable_ic_inv_hardening()),
 - __apply_alternatives_multi_stop() on Arm,
 - do_microcode_update() on x86,
 - take_cpu_down() in common code.

This allows the casts in cpufeature.c to be dropped.

take_cpu_down() is always invoked with NULL, so it now passes NULL to
_take_cpu_down() explicitly. _take_cpu_down() keeps its void * argument
because it is also used as an on_selected_cpus() callback.

No functional changes.

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
---
 xen/arch/arm/alternative.c            | 4 ++--
 xen/arch/arm/cpuerrata.c              | 8 ++++----
 xen/arch/arm/cpufeature.c             | 4 ++--
 xen/arch/arm/include/asm/cpufeature.h | 2 +-
 xen/arch/x86/cpu/microcode/core.c     | 4 ++--
 xen/common/cpu.c                      | 4 ++--
 xen/common/stop_machine.c             | 7 ++++---
 xen/include/xen/stop_machine.h        | 5 +++--
 8 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c
index 44b5e09732..e17b5d6e8a 100644
--- a/xen/arch/arm/alternative.c
+++ b/xen/arch/arm/alternative.c
@@ -160,7 +160,7 @@ static int __apply_alternatives(const struct alt_region 
*region,
  * We might be patching the stop_machine state machine, so implement a
  * really simple polling protocol here.
  */
-static int __apply_alternatives_multi_stop(void *xenmap)
+static int __apply_alternatives_multi_stop(const void *xenmap)
 {
     static int patched = 0;
 
@@ -181,7 +181,7 @@ static int __apply_alternatives_multi_stop(void *xenmap)
         region.begin = __alt_instructions;
         region.end = __alt_instructions_end;
 
-        ret = __apply_alternatives(&region, xenmap - (void *)_start);
+        ret = __apply_alternatives(&region, xenmap - (const void *)_start);
         /* The patching is not expected to fail during boot. */
         BUG_ON(ret != 0);
 
diff --git a/xen/arch/arm/cpuerrata.c b/xen/arch/arm/cpuerrata.c
index 35ad98d29d..030304fbd8 100644
--- a/xen/arch/arm/cpuerrata.c
+++ b/xen/arch/arm/cpuerrata.c
@@ -156,7 +156,7 @@ extern char __mitigate_spectre_bhb_loop_start_24[],
 extern char __mitigate_spectre_bhb_loop_start_32[],
             __mitigate_spectre_bhb_loop_end_32[];
 
-static int enable_smccc_arch_workaround_1(void *data)
+static int enable_smccc_arch_workaround_1(const void *data)
 {
     struct arm_smccc_res res;
     const struct arm_cpu_capabilities *entry = data;
@@ -207,7 +207,7 @@ warn:
  *   the CPU).
  * - Mitigating using the firmware.
  */
-static int enable_spectre_bhb_workaround(void *data)
+static int enable_spectre_bhb_workaround(const void *data)
 {
     const struct arm_cpu_capabilities *entry = data;
 
@@ -314,14 +314,14 @@ install_bp_hardening_vecs(const struct 
arm_cpu_capabilities *entry,
     this_cpu(bp_harden_vecs) = hyp_vecs;
 }
 
-static int enable_bp_inv_hardening(void *data)
+static int enable_bp_inv_hardening(const void *data)
 {
     install_bp_hardening_vecs(data, hyp_traps_vector_bp_inv,
                               "execute BPIALL");
     return 0;
 }
 
-static int enable_ic_inv_hardening(void *data)
+static int enable_ic_inv_hardening(const void *data)
 {
     install_bp_hardening_vecs(data, hyp_traps_vector_ic_inv,
                               "execute ICIALLU");
diff --git a/xen/arch/arm/cpufeature.c b/xen/arch/arm/cpufeature.c
index 8d8cd19a96..701232fe01 100644
--- a/xen/arch/arm/cpufeature.c
+++ b/xen/arch/arm/cpufeature.c
@@ -72,7 +72,7 @@ void __init enable_cpu_capabilities(const struct 
arm_cpu_capabilities *caps)
              * an IPI, giving us a PSTATE that disappears when we
              * return.
              */
-            ret = stop_machine_run(caps->enable, (void *)caps, NR_CPUS);
+            ret = stop_machine_run(caps->enable, caps, NR_CPUS);
             /* stop_machine_run should never fail at this stage of the boot. */
             BUG_ON(ret);
         }
@@ -108,7 +108,7 @@ int enable_nonboot_cpu_caps(const struct 
arm_cpu_capabilities *caps)
 
         if ( caps->enable )
         {
-            int ret = caps->enable((void *)caps);
+            int ret = caps->enable(caps);
 
             if ( ret )
                 rc = ret;
diff --git a/xen/arch/arm/include/asm/cpufeature.h 
b/xen/arch/arm/include/asm/cpufeature.h
index c554686415..53afd1ca5c 100644
--- a/xen/arch/arm/include/asm/cpufeature.h
+++ b/xen/arch/arm/include/asm/cpufeature.h
@@ -123,7 +123,7 @@ struct arm_cpu_capabilities {
     const char *desc;
     u16 capability;
     bool (*matches)(const struct arm_cpu_capabilities *entry);
-    int (*enable)(void *data); /* Called on every active CPUs */
+    int (*enable)(const void *data); /* Called on every active CPUs */
     union {
         struct {    /* To be used for eratum handling only */
             u32 midr_model;
diff --git a/xen/arch/x86/cpu/microcode/core.c 
b/xen/arch/x86/cpu/microcode/core.c
index 9b8d1e09cb..dd984fc923 100644
--- a/xen/arch/x86/cpu/microcode/core.c
+++ b/xen/arch/x86/cpu/microcode/core.c
@@ -457,11 +457,11 @@ static int control_thread_fn(const struct microcode_patch 
*patch,
     return ret;
 }
 
-static int cf_check do_microcode_update(void *_patch_with_flags)
+static int cf_check do_microcode_update(const void *_patch_with_flags)
 {
     unsigned int cpu = smp_processor_id();
     int ret;
-    struct patch_with_flags *patch_with_flags = _patch_with_flags;
+    const struct patch_with_flags *patch_with_flags = _patch_with_flags;
 
     /*
      * The control thread set state to coordinate ucode loading. Primary
diff --git a/xen/common/cpu.c b/xen/common/cpu.c
index f09af0444b..c86899b4c0 100644
--- a/xen/common/cpu.c
+++ b/xen/common/cpu.c
@@ -101,9 +101,9 @@ static void cf_check _take_cpu_down(void *unused)
     __cpu_disable();
 }
 
-static int cf_check take_cpu_down(void *arg)
+static int cf_check take_cpu_down(const void *unused)
 {
-    _take_cpu_down(arg);
+    _take_cpu_down(NULL);
     return 0;
 }
 
diff --git a/xen/common/stop_machine.c b/xen/common/stop_machine.c
index 398cfd507c..38091eff50 100644
--- a/xen/common/stop_machine.c
+++ b/xen/common/stop_machine.c
@@ -46,8 +46,8 @@ struct stopmachine_data {
 
     unsigned int fn_cpu;
     int fn_result;
-    int (*fn)(void *data);
-    void *fn_data;
+    int (*fn)(const void *data);
+    const void *fn_data;
 };
 
 static DEFINE_PER_CPU(struct tasklet, stopmachine_tasklet);
@@ -73,7 +73,8 @@ static void stopmachine_wait_state(void)
  * mandatory to be called only on an idle vcpu, as otherwise active core
  * scheduling might hang.
  */
-int stop_machine_run(int (*fn)(void *data), void *data, unsigned int cpu)
+int stop_machine_run(int (*fn)(const void *data), const void *data,
+                     unsigned int cpu)
 {
     unsigned int i, nr_cpus;
     unsigned int this = smp_processor_id();
diff --git a/xen/include/xen/stop_machine.h b/xen/include/xen/stop_machine.h
index 0bbf71f112..905b9af0f5 100644
--- a/xen/include/xen/stop_machine.h
+++ b/xen/include/xen/stop_machine.h
@@ -4,7 +4,7 @@
 /**
  * stop_machine_run: freeze the machine on all CPUs and run this function
  * @fn: the function to run
- * @data: the data ptr for the @fn()
+ * @data: read-only argument passed to @fn()
  * @cpu: the cpu to run @fn() on (or all, if @cpu == NR_CPUS).
  *
  * Description: This causes every other cpu to enter a safe point, with
@@ -14,6 +14,7 @@
  *
  * This can be thought of as a very heavy write lock, equivalent to
  * grabbing every spinlock in the kernel. */
-int stop_machine_run(int (*fn)(void *data), void *data, unsigned int cpu);
+int stop_machine_run(int (*fn)(const void *data), const void *data,
+                     unsigned int cpu);
 
 #endif /* __XEN_STOP_MACHINE_H__ */
-- 
2.43.0

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.