Skip to contentSkip to conversation

x86/mm: compile out __set_fixmap_x() when not needed

PATCH In review Jan Beulich 1 participant 7 messages Nov 3 – Nov 12 4 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mm: compile out __set_fixmap_x() when not needed

Only HYPERV_GUEST has a need for an executable fixmap, so with that option unset __set_fixmap_x() (and l1_fixmap_x[] in turn) is unreachable. Address this Misra rule 2.1 violation by introduction ofa new FIXMAP_X Kconfig setting.

---
Why is __set_fixmap_x() not found by Eclair as a rule 2.1 violation in the x86_64-amd job?

xen/arch/x86/Kconfig +4 -0
@@ -269,6 +269,9 @@ config MCE_NONFATAL
 config GUEST
 	bool
 
+config FIXMAP_X
+	bool
+
 config XEN_GUEST
 	bool "Xen Guest"
 	select GUEST
@@ -309,6 +312,7 @@ config PV_SHIM_EXCLUSIVE
 
 config HYPERV_GUEST
 	bool "Hyper-V Guest"
+	select FIXMAP_X
 	select GUEST
 	help
 	  Support for Xen detecting when it is running under Hyper-V.
xen/arch/x86/boot/x86_64.S +2 -2
@@ -142,13 +142,13 @@ END(l2_directmap)
 
 /*
  * L2 mapping the Xen text/data/bss region, constructed dynamically.
- * Executable fixmap is hooked up statically.
+ * Executable fixmap, when in use, is hooked up statically.
  * Uses 1x 4k page.
  */
 DATA(l2_xenmap, PAGE_SIZE)
         idx = 0
         .rept L2_PAGETABLE_ENTRIES
-        .if idx == l2_table_offset(FIXADDR_X_TOP - 1)
+        .if IS_ENABLED(CONFIG_FIXMAP_X) && idx == l2_table_offset(FIXADDR_X_TOP - 1)
         .quad sym_offs(l1_fixmap_x) + __PAGE_HYPERVISOR
         .else
         .quad 0
xen/arch/x86/include/asm/fixmap.h +8 -0
@@ -95,6 +95,8 @@ static inline unsigned long virt_to_fix(
     return __virt_to_fix(vaddr);
 }
 
+#ifdef CONFIG_FIXMAP_X
+
 enum fixed_addresses_x {
     /* Index 0 is reserved since fix_x_to_virt(0) == FIXADDR_X_TOP. */
     FIX_X_RESERVED,
@@ -118,6 +120,12 @@ extern void __set_fixmap_x(
 #define __fix_x_to_virt(x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT))
 #define fix_x_to_virt(x)   ((void *)__fix_x_to_virt(x))
 
+#else /* !CONFIG_FIXMAP_X */
+
+#define FIXADDR_X_SIZE  0
+
+#endif /* CONFIG_FIXMAP_X */
+
 #endif /* __ASSEMBLER__ */
 
 #endif
xen/arch/x86/mm.c +7 -2
@@ -147,8 +147,6 @@
 /* Mapping of the fixmap space needed early. */
 l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE)
     l1_fixmap[L1_PAGETABLE_ENTRIES];
-l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE)
-    l1_fixmap_x[L1_PAGETABLE_ENTRIES]; /* SAF-1-safe */
 
 bool __read_mostly machine_to_phys_mapping_valid;
 
@@ -6180,6 +6178,11 @@ void __set_fixmap(
     map_pages_to_xen(__fix_to_virt(idx), _mfn(mfn), 1, flags);
 }
 
+#ifdef CONFIG_FIXMAP_X
+
+l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE)
+    l1_fixmap_x[L1_PAGETABLE_ENTRIES]; /* SAF-1-safe */
+
 void __set_fixmap_x(
     enum fixed_addresses_x idx, unsigned long mfn, unsigned long flags)
 {
@@ -6187,6 +6190,8 @@ void __set_fixmap_x(
     map_pages_to_xen(__fix_x_to_virt(idx), _mfn(mfn), 1, flags);
 }
 
+#endif /* CONFIG_FIXMAP_X */
+
 void *__init arch_vmap_virt_end(void)
 {
     return fix_to_virt(__end_of_fixed_addresses);
#1 lore raw
Quoted 9 lines · Jan Beulich

Only HYPERV_GUEST has a need for an executable fixmap, so with that option unset __set_fixmap_x() (and l1_fixmap_x[] in turn) is unreachable. Address this Misra rule 2.1 violation by introduction ofa new FIXMAP_X Kconfig setting.

---
Why is __set_fixmap_x() not found by Eclair as a rule 2.1 violation in the x86_64-amd job?

Same question actually for both functions converted to static by [1]. This apparently being a wider problem, are we (again / still) having an issue with the scanning of the linking steps?

Jan

[1] https://lists.xen.org/archives/html/xen-devel/2026-10/msg01537.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 32 lines · Nicola Vetrini
Quoted 20 lines · Jan Beulich
Quoted 7 lines · Jan Beulich

Only HYPERV_GUEST has a need for an executable fixmap, so with that option
unset __set_fixmap_x() (and l1_fixmap_x[] in turn) is unreachable. Address
this Misra rule 2.1 violation by introduction ofa new FIXMAP_X Kconfig setting.

Quoted 5 lines

---
Why is __set_fixmap_x() not found by Eclair as a rule 2.1 violation in the
x86_64-amd job?

Same question actually for both functions converted to static by [1]. This
apparently being a wider problem, are we (again / still) having an issue
with the scanning of the linking steps?

Quoted 3 lines

Jan

[1] https://lists.xen.org/archives/html/xen-devel/2026-10/msg01537.html

It was a Xen project decision not to consider for R2.1 functions that are never referenced: you can see in "automation/eclair_analysis/ECLAIR/deviations.ecl". Of course that is reversible and I am in favour of not hiding those violations, but the rationale for the justification that was given is that the compiler will indeed DCE those:

Quoted 7 lines

* - R2.1
- The compiler implementation guarantees that the unreachable code
is
removed. Constant expressions and unreachable branches of if and
switch
statements are expected.
- Tagged as safe for ECLAIR.

For the cases at hand (and then likely many more) the compiler doesn't DCE anything. Imo the wording here is completely bogus. It may say "If the compiler implementation guarantees ..." Which it might do for static functions, but aiui without LTO it never will for non-static ones.

Then I'm also puzzled by the deviations.ecl entry:

-doc_begin="The compiler implementation guarantees that the unreachable code is removed. Constant expressions and unreachable branches of if and switch statements are expected." -config=MC3A2.R2.1,+reports={safe,"first_area(^.*has an invariantly.*$)"} -config=MC3A2.R2.1,+reports={safe,"first_area(^.*incompatible with labeled statement$)"} -doc_end

First - these are two different deviations, and hence imo should be two separate entries. More important here though is that I can't connect the two config= lines to the deviation of unreferenced non-static functions. There's nothing "... has an invariantly ..." or "... incompatible with labeled statement ..." there? How would the full diagnostic for an unreferenced global function (or data item) look like?

Jan

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 71 lines · Nicola Vetrini
Quoted 47 lines · Jan Beulich
Quoted 36 lines · Nicola Vetrini
Quoted 22 lines · Jan Beulich
Quoted 8 lines · Jan Beulich

Only HYPERV_GUEST has a need for an executable fixmap, so with that option
unset __set_fixmap_x() (and l1_fixmap_x[] in turn) is unreachable. Address
this Misra rule 2.1 violation by introduction ofa new FIXMAP_X Kconfig
setting.

Quoted 6 lines

---
Why is __set_fixmap_x() not found by Eclair as a rule 2.1 violation in
the
x86_64-amd job?

Same question actually for both functions converted to static by [1]. This
apparently being a wider problem, are we (again / still) having an issue
with the scanning of the linking steps?

Quoted 4 lines

Jan

[1]
https://lists.xen.org/archives/html/xen-devel/2026-10/msg01537.html

It was a Xen project decision not to consider for R2.1 functions that are never referenced: you can see in "automation/eclair_analysis/ECLAIR/deviations.ecl". Of course that is reversible and I am in favour of not hiding those violations, but the rationale for the justification that was given is that the compiler will
indeed DCE those:

Quoted 9 lines

* - R2.1
- The compiler implementation guarantees that the unreachable
code
is
removed. Constant expressions and unreachable branches of if
and
switch
statements are expected.
- Tagged as safe for ECLAIR.

Quoted 6 lines

For the cases at hand (and then likely many more) the compiler doesn't DCE
anything. Imo the wording here is completely bogus. It may say "If the compiler implementation guarantees ..." Which it might do for static functions, but aiui without LTO it never will for non-static ones.

I'm not saying the configuration is good as is. Ideally that should be removed or restricted to static functions and the likely newly present violations triaged.

Quoted 12 lines

Then I'm also puzzled by the deviations.ecl entry:

-doc_begin="The compiler implementation guarantees that the unreachable code is removed.
Constant expressions and unreachable branches of if and switch statements are expected." -config=MC3A2.R2.1,+reports={safe,"first_area(^.*has an invariantly.*$)"} -config=MC3A2.R2.1,+reports={safe,"first_area(^.*incompatible with labeled statement$)"}
-doc_end

Quoted 12 lines
Quoted 8 lines

First - these are two different deviations, and hence imo should be two separate entries. More important here though is that I can't connect the
two config= lines to the deviation of unreferenced non-static functions.
There's nothing "... has an invariantly ..." or "... incompatible with labeled statement ..." there? How would the full diagnostic for an unreferenced global function (or data item) look like?

These two have nothing do do with functions never referenced indeed: the rule is about unreachable code in general, of which functions that are never called is just a subcase.

Yet then in your earlier mail which part of deviations.ecl did you refer to?

Jan

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw
Quoted 110 lines · Nicola Vetrini
Quoted 97 lines · Jan Beulich
Quoted 80 lines · Nicola Vetrini
Quoted 53 lines · Jan Beulich
Quoted 42 lines · Nicola Vetrini
Quoted 25 lines · Jan Beulich
Quoted 9 lines · Jan Beulich

Only HYPERV_GUEST has a need for an executable fixmap, so with that
option
unset __set_fixmap_x() (and l1_fixmap_x[] in turn) is unreachable. Address
this Misra rule 2.1 violation by introduction ofa new FIXMAP_X Kconfig
setting.

Quoted 7 lines

---
Why is __set_fixmap_x() not found by Eclair as a rule 2.1 violation
in
the
x86_64-amd job?

Same question actually for both functions converted to static by [1].
This
apparently being a wider problem, are we (again / still) having an issue
with the scanning of the linking steps?

Quoted 4 lines

Jan

[1]
https://lists.xen.org/archives/html/xen-devel/2026-10/msg01537.html

It was a Xen project decision not to consider for R2.1 functions that
are never referenced: you can see in "automation/eclair_analysis/ECLAIR/deviations.ecl". Of course that is
reversible and I am in favour of not hiding those violations, but the
rationale for the justification that was given is that the compiler will
indeed DCE those:

Quoted 9 lines

* - R2.1
- The compiler implementation guarantees that the unreachable
code
is
removed. Constant expressions and unreachable branches of if
and
switch
statements are expected.
- Tagged as safe for ECLAIR.

Quoted 8 lines

For the cases at hand (and then likely many more) the compiler doesn't
DCE
anything. Imo the wording here is completely bogus. It may say "If the
compiler implementation guarantees ..." Which it might do for static functions, but aiui without LTO it never will for non-static ones.

I'm not saying the configuration is good as is. Ideally that should be removed or restricted to static functions and the likely newly present violations triaged.

Quoted 13 lines

Then I'm also puzzled by the deviations.ecl entry:

-doc_begin="The compiler implementation guarantees that the unreachable
code is removed.
Constant expressions and unreachable branches of if and switch statements are expected." -config=MC3A2.R2.1,+reports={safe,"first_area(^.*has an invariantly.*$)"} -config=MC3A2.R2.1,+reports={safe,"first_area(^.*incompatible with labeled statement$)"}
-doc_end

Quoted 15 lines
Quoted 10 lines

First - these are two different deviations, and hence imo should be two
separate entries. More important here though is that I can't connect the
two config= lines to the deviation of unreferenced non-static functions.
There's nothing "... has an invariantly ..." or "... incompatible with
labeled statement ..." there? How would the full diagnostic for an unreferenced global function (or data item) look like?

These two have nothing do do with functions never referenced indeed:
the
rule is about unreachable code in general, of which functions that are never called is just a subcase.

Quoted 4 lines

Yet then in your earlier mail which part of deviations.ecl did you refer
to?

Sorry, I assumed I had pasted it [1], but forgot:

(quoted diff) +0 -2
-doc_begin="Some functions are intended to be not referenced."
-config=MC3A2.R2.1,+reports={deliberate,"first_area(^.*is never 

referenced$)"}
-doc_end

Quoted 1 line

this bit specifically is about both static and non-static functions

Oh, I see. Since this deviation is unspecific as to static / non-static, I didn't think it was the one relevant here.

Jan

#8 lore raw
Quoted 110 lines · Jan Beulich
Quoted 109 lines · Nicola Vetrini
Quoted 97 lines · Jan Beulich
Quoted 80 lines · Nicola Vetrini
Quoted 53 lines · Jan Beulich
Quoted 42 lines · Nicola Vetrini
Quoted 25 lines · Jan Beulich
Quoted 9 lines · Jan Beulich

Only HYPERV_GUEST has a need for an executable fixmap, so with that
option
unset __set_fixmap_x() (and l1_fixmap_x[] in turn) is unreachable. Address
this Misra rule 2.1 violation by introduction ofa new FIXMAP_X Kconfig
setting.

Quoted 7 lines

---
Why is __set_fixmap_x() not found by Eclair as a rule 2.1 violation
in
the
x86_64-amd job?

Same question actually for both functions converted to static by [1].
This
apparently being a wider problem, are we (again / still) having an issue
with the scanning of the linking steps?

Quoted 4 lines

Jan

[1]
https://lists.xen.org/archives/html/xen-devel/2026-10/msg01537.html

It was a Xen project decision not to consider for R2.1 functions that
are never referenced: you can see in "automation/eclair_analysis/ECLAIR/deviations.ecl". Of course that is
reversible and I am in favour of not hiding those violations, but the
rationale for the justification that was given is that the compiler will
indeed DCE those:

Quoted 9 lines

* - R2.1
- The compiler implementation guarantees that the unreachable
code
is
removed. Constant expressions and unreachable branches of if
and
switch
statements are expected.
- Tagged as safe for ECLAIR.

Quoted 8 lines

For the cases at hand (and then likely many more) the compiler doesn't
DCE
anything. Imo the wording here is completely bogus. It may say "If the
compiler implementation guarantees ..." Which it might do for static functions, but aiui without LTO it never will for non-static ones.

I'm not saying the configuration is good as is. Ideally that should be removed or restricted to static functions and the likely newly present violations triaged.

Quoted 13 lines

Then I'm also puzzled by the deviations.ecl entry:

-doc_begin="The compiler implementation guarantees that the unreachable
code is removed.
Constant expressions and unreachable branches of if and switch statements are expected." -config=MC3A2.R2.1,+reports={safe,"first_area(^.*has an invariantly.*$)"} -config=MC3A2.R2.1,+reports={safe,"first_area(^.*incompatible with labeled statement$)"}
-doc_end

Quoted 15 lines
Quoted 10 lines

First - these are two different deviations, and hence imo should be two
separate entries. More important here though is that I can't connect the
two config= lines to the deviation of unreferenced non-static functions.
There's nothing "... has an invariantly ..." or "... incompatible with
labeled statement ..." there? How would the full diagnostic for an unreferenced global function (or data item) look like?

These two have nothing do do with functions never referenced indeed:
the
rule is about unreachable code in general, of which functions that are never called is just a subcase.

Quoted 3 lines

Yet then in your earlier mail which part of deviations.ecl did you refer
to?

Sorry, I assumed I had pasted it [1], but forgot:

(quoted diff) +0 -2
-doc_begin="Some functions are intended to be not referenced."
-config=MC3A2.R2.1,+reports={deliberate,"first_area(^.*is never 

referenced$)"}
-doc_end

Quoted 4 lines
Quoted 1 line

this bit specifically is about both static and non-static functions

Oh, I see. Since this deviation is unspecific as to static / non-static, I didn't think it was the one relevant here.

What's possibly worse (and what may have added to me not spotting it):
This does not look to have a representation in docs/misra/deviations.txt. Such an inconsistency imo needs addressing.

How would the above configuration setting look like when limiting things to static functions?

Jan

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw
Quoted 136 lines · Nicola Vetrini
Quoted 135 lines · Jan Beulich
Quoted 123 lines · Jan Beulich
Quoted 122 lines · Nicola Vetrini
Quoted 110 lines · Jan Beulich
Quoted 100 lines · Nicola Vetrini
Quoted 59 lines · Jan Beulich
Quoted 46 lines · Nicola Vetrini
Quoted 27 lines · Jan Beulich
Quoted 10 lines · Jan Beulich

Only HYPERV_GUEST has a need for an executable fixmap, so with that
option
unset __set_fixmap_x() (and l1_fixmap_x[] in turn) is unreachable.
Address
this Misra rule 2.1 violation by introduction ofa new FIXMAP_X Kconfig
setting.

Quoted 7 lines

---
Why is __set_fixmap_x() not found by Eclair as a rule 2.1 violation
in
the
x86_64-amd job?

Same question actually for both functions converted to static by [1].
This
apparently being a wider problem, are we (again / still) having an
issue
with the scanning of the linking steps?

Quoted 4 lines

Jan

[1]
https://lists.xen.org/archives/html/xen-devel/2026-10/msg01537.html

It was a Xen project decision not to consider for R2.1 functions that
are never referenced: you can see in "automation/eclair_analysis/ECLAIR/deviations.ecl". Of course that
is
reversible and I am in favour of not hiding those violations, but the
rationale for the justification that was given is that the compiler
will
indeed DCE those:

Quoted 11 lines

* - R2.1
- The compiler implementation guarantees that the
unreachable
code
is
removed. Constant expressions and unreachable branches of
if
and
switch
statements are expected.
- Tagged as safe for ECLAIR.

Quoted 9 lines

For the cases at hand (and then likely many more) the compiler doesn't
DCE
anything. Imo the wording here is completely bogus. It may say "If the
compiler implementation guarantees ..." Which it might do for static
functions, but aiui without LTO it never will for non-static ones.

I'm not saying the configuration is good as is. Ideally that should be
removed or restricted to static functions and the likely newly present
violations triaged.

Quoted 24 lines

Then I'm also puzzled by the deviations.ecl entry:

-doc_begin="The compiler implementation guarantees that the unreachable
code is removed.
Constant expressions and unreachable branches of if and switch statements are expected." -config=MC3A2.R2.1,+reports={safe,"first_area(^.*has an invariantly.*$)"} -config=MC3A2.R2.1,+reports={safe,"first_area(^.*incompatible with labeled statement$)"}
-doc_end

First - these are two different deviations, and hence imo should be
two
separate entries. More important here though is that I can't connect
the
two config= lines to the deviation of unreferenced non-static functions.
There's nothing "... has an invariantly ..." or "... incompatible with
labeled statement ..." there? How would the full diagnostic for an

Quoted 8 lines
Quoted 1 line

unreferenced global function (or data item) look like?

These two have nothing do do with functions never referenced indeed:
the
rule is about unreachable code in general, of which functions that are
never called is just a subcase.

Quoted 3 lines

Yet then in your earlier mail which part of deviations.ecl did you refer
to?

Sorry, I assumed I had pasted it [1], but forgot:

(quoted diff) +0 -2
-doc_begin="Some functions are intended to be not referenced."
-config=MC3A2.R2.1,+reports={deliberate,"first_area(^.*is never

referenced$)"}
-doc_end

Quoted 5 lines
Quoted 1 line

this bit specifically is about both static and non-static functions

Oh, I see. Since this deviation is unspecific as to static / non-static,
I didn't think it was the one relevant here.

What's possibly worse (and what may have added to me not spotting it):
This does not look to have a representation in docs/misra/deviations.txt.
Such an inconsistency imo needs addressing.

Quoted 8 lines
Quoted 3 lines

How would the above configuration setting look like when limiting things
to static functions?

Probably something like:

-config=MC3A2.R2.1,+reports={deliberate,"first_area(^.*is never referenced$&&decl(kind(function)&&storage_duration(static))"}

Using that (with the missing parenthesis added) I get (pipeline [1]) no change in numbers for Arm64 and a drop by 4 for x86-64, compared to the results with [2]). With that I'm not sure whether it's worth keeping the rule in this modified form vs deleting it altogether.

Jan

[1] https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/3059613055
[2] https://lists.xen.org/archives/html/xen-devel/2026-11/msg01007.html