docs/misra/safe.json | 8 ++++++++ xen/arch/arm/cpufeature.c | 2 ++ 2 files changed, 10 insertions(+)
MISRA C Rule 11.8 forbids casts that remove the const qualifier from
the pointed-to type. 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().
The callback type takes void * by convention. Existing enable
implementations treat the pointer as const and do not modify the
object. Document both casts with SAF-15-safe comment.
No functional changes.
Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
---
Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/3081209229
---
docs/misra/safe.json | 8 ++++++++
xen/arch/arm/cpufeature.c | 2 ++
2 files changed, 10 insertions(+)
diff --git a/docs/misra/safe.json b/docs/misra/safe.json
index 3584cb90c6..67f8ed9869 100644
--- a/docs/misra/safe.json
+++ b/docs/misra/safe.json
@@ -124,6 +124,14 @@
},
{
"id": "SAF-15-safe",
+ "analyser": {
+ "eclair": "MC3A2.R11.8"
+ },
+ "name": "Rule 11.8: cast const capabilities to void * for enable callback",
+ "text": "The Arm CPU capability enable callback takes void * to match the generic callback convention. The cast removes const only to pass a const struct arm_cpu_capabilities * into that signature. Existing enable implementations treat the pointer as const and do not modify the object."
+ },
+ {
+ "id": "SAF-16-safe",
"analyser": {},
"name": "Sentinel",
"text": "Next ID to be used"
diff --git a/xen/arch/arm/cpufeature.c b/xen/arch/arm/cpufeature.c
index 8d8cd19a96..4d2b183a62 100644
--- a/xen/arch/arm/cpufeature.c
+++ b/xen/arch/arm/cpufeature.c
@@ -72,6 +72,7 @@ void __init enable_cpu_capabilities(const struct arm_cpu_capabilities *caps)
* an IPI, giving us a PSTATE that disappears when we
* return.
*/
+ /* SAF-15-safe R11.8 cast const caps to void * for enable callback */
ret = stop_machine_run(caps->enable, (void *)caps, NR_CPUS);
/* stop_machine_run should never fail at this stage of the boot. */
BUG_ON(ret);
@@ -108,6 +109,7 @@ int enable_nonboot_cpu_caps(const struct arm_cpu_capabilities *caps)
if ( caps->enable )
{
+ /* SAF-15-safe R11.8 cast const caps to void * for enable callback */
int ret = caps->enable((void *)caps);
if ( ret )
--
2.43.0
On 17.11.2026 22:31, Dmytro Prokopchuk1 wrote:
> --- a/docs/misra/safe.json
> +++ b/docs/misra/safe.json
> @@ -124,6 +124,14 @@
> },
> {
> "id": "SAF-15-safe",
> + "analyser": {
> + "eclair": "MC3A2.R11.8"
> + },
> + "name": "Rule 11.8: cast const capabilities to void * for enable callback",
> + "text": "The Arm CPU capability enable callback takes void * to match the generic callback convention. The cast removes const only to pass a const struct arm_cpu_capabilities * into that signature. Existing enable implementations treat the pointer as const and do not modify the object."
> + },
Do we really want to restrict this to Arm CPU cap handling? The same pattern
could easily arise elsewhere.
Jan
On 11/18/26 09:41, Jan Beulich wrote:
> On 17.11.2026 22:31, Dmytro Prokopchuk1 wrote:
>> --- a/docs/misra/safe.json
>> +++ b/docs/misra/safe.json
>> @@ -124,6 +124,14 @@
>> },
>> {
>> "id": "SAF-15-safe",
>> + "analyser": {
>> + "eclair": "MC3A2.R11.8"
>> + },
>> + "name": "Rule 11.8: cast const capabilities to void * for enable callback",
>> + "text": "The Arm CPU capability enable callback takes void * to match the generic callback convention. The cast removes const only to pass a const struct arm_cpu_capabilities * into that signature. Existing enable implementations treat the pointer as const and do not modify the object."
>> + },
>
> Do we really want to restrict this to Arm CPU cap handling? The same pattern
> could easily arise elsewhere.
Hmm, good point.
Well, the deviation could be generalized to this:
name: Rule 11.8: cast const pointer to void * for a callback
text: Generic callbacks take void * by convention. Casting a
const-qualified pointer to void * only to pass it into such a signature
is safe when the callback implementation treat the pointer as const and
do not modify the object.
If such wording is OK for maintainers, I can prepare v2.
>
> Jan
BR, Dmytro.
On 18.11.2026 21:28, Dmytro Prokopchuk wrote:
>
>
> On 11/18/26 09:41, Jan Beulich wrote:
>> On 17.11.2026 22:31, Dmytro Prokopchuk1 wrote:
>>> --- a/docs/misra/safe.json
>>> +++ b/docs/misra/safe.json
>>> @@ -124,6 +124,14 @@
>>> },
>>> {
>>> "id": "SAF-15-safe",
>>> + "analyser": {
>>> + "eclair": "MC3A2.R11.8"
>>> + },
>>> + "name": "Rule 11.8: cast const capabilities to void * for enable callback",
>>> + "text": "The Arm CPU capability enable callback takes void * to match the generic callback convention. The cast removes const only to pass a const struct arm_cpu_capabilities * into that signature. Existing enable implementations treat the pointer as const and do not modify the object."
>>> + },
>>
>> Do we really want to restrict this to Arm CPU cap handling? The same pattern
>> could easily arise elsewhere.
>
> Hmm, good point.
>
> Well, the deviation could be generalized to this:
>
> name: Rule 11.8: cast const pointer to void * for a callback
>
> text: Generic callbacks take void * by convention. Casting a
> const-qualified pointer to void * only to pass it into such a signature
> is safe when the callback implementation treat the pointer as const and
> do not modify the object.
>
> If such wording is OK for maintainers, I can prepare v2.
Sounds largely okay to me. (I'm not quite sure whether "generic" is an
appropriate description here. I'd likely use "Callbacks often have void *
parameters, to be type-generic.")
Jan
On 17/11/2026 9:31 pm, Dmytro Prokopchuk1 wrote:
> MISRA C Rule 11.8 forbids casts that remove the const qualifier from
> the pointed-to type. 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().
>
> The callback type takes void * by convention. Existing enable
> implementations treat the pointer as const and do not modify the
> object. Document both casts with SAF-15-safe comment.
>
> No functional changes.
>
> Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
> ---
> Test CI pipeline:
> https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/3081209229
> ---
> docs/misra/safe.json | 8 ++++++++
> xen/arch/arm/cpufeature.c | 2 ++
> 2 files changed, 10 insertions(+)
>
> diff --git a/docs/misra/safe.json b/docs/misra/safe.json
> index 3584cb90c6..67f8ed9869 100644
> --- a/docs/misra/safe.json
> +++ b/docs/misra/safe.json
> @@ -124,6 +124,14 @@
> },
> {
> "id": "SAF-15-safe",
> + "analyser": {
> + "eclair": "MC3A2.R11.8"
> + },
> + "name": "Rule 11.8: cast const capabilities to void * for enable callback",
> + "text": "The Arm CPU capability enable callback takes void * to match the generic callback convention. The cast removes const only to pass a const struct arm_cpu_capabilities * into that signature. Existing enable implementations treat the pointer as const and do not modify the object."
> + },
> + {
> + "id": "SAF-16-safe",
> "analyser": {},
> "name": "Sentinel",
> "text": "Next ID to be used"
> diff --git a/xen/arch/arm/cpufeature.c b/xen/arch/arm/cpufeature.c
> index 8d8cd19a96..4d2b183a62 100644
> --- a/xen/arch/arm/cpufeature.c
> +++ b/xen/arch/arm/cpufeature.c
> @@ -72,6 +72,7 @@ void __init enable_cpu_capabilities(const struct arm_cpu_capabilities *caps)
> * an IPI, giving us a PSTATE that disappears when we
> * return.
> */
> + /* SAF-15-safe R11.8 cast const caps to void * for enable callback */
> ret = stop_machine_run(caps->enable, (void *)caps, NR_CPUS);
> /* stop_machine_run should never fail at this stage of the boot. */
> BUG_ON(ret);
> @@ -108,6 +109,7 @@ int enable_nonboot_cpu_caps(const struct arm_cpu_capabilities *caps)
>
> if ( caps->enable )
> {
> + /* SAF-15-safe R11.8 cast const caps to void * for enable callback */
> int ret = caps->enable((void *)caps);
>
> if ( ret )
Thankyou.
FWIW, Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>, although
you'll need an ARM maintainer for the patch to be accepted.
~Andrew
© 2016 - 2026 Red Hat, Inc.