xen/CET: Fix __initconst_cf_clobber
PATCH 1/1 xen/CET: Fix __initconst_cf_clobber
The linker script collecting .init.rodata.* ahead of .init.rodata.cf_clobber accidentally causes __initconst_cf_clobber to be a no-op.
Rearrange the linker script to unbreak this.
The IOMMU adjust_irq_affinities() hooks currently violate the safety requirement for being cf_clobber, by also being __initcall().
Consolidate to a single initcall using iommu_call() (satisfying the cf_clobber safety requirement), and also removes the dubious property that we'd call into both vendors IOMMU drivers on boot, relying on the for_each_*() loops to be empty for safety.
With this fixed, an all-enabled build of Xen has 1681 endbr64's (1918 including .init.text) with 382 (23%) being clobbered during boot.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
I was unsure whether to go common or x86 spefific IOMMU code, so went with the conservative option. The final hunk can trivially move if preferred.
--- xen/arch/x86/xen.lds.S | 12 ++++++------ xen/drivers/passthrough/amd/iommu_init.c | 1 - xen/drivers/passthrough/vtd/iommu.c | 1 - xen/drivers/passthrough/x86/iommu.c | 6 ++++++ 4 files changed, 12 insertions(+), 8 deletions(-)
xen/arch/x86/xen.lds.S +6 -6
@@ -210,6 +210,12 @@ SECTIONS DECL_SECTION(.init.data) { #endif + . = ALIGN(POINTER_ALIGN); + __initdata_cf_clobber_start = .; + *(.init.data.cf_clobber) + *(.init.rodata.cf_clobber) + __initdata_cf_clobber_end = .; + *(.init.rodata) *(.init.rodata.*)
@@ -224,12 +230,6 @@ SECTIONS *(.initcall1.init) __initcall_end = .; - . = ALIGN(POINTER_ALIGN); - __initdata_cf_clobber_start = .; - *(.init.data.cf_clobber) - *(.init.rodata.cf_clobber) - __initdata_cf_clobber_end = .; - *(.init.data) *(.init.data.rel) *(.init.data.rel.*)
xen/drivers/passthrough/amd/iommu_init.c +0 -1
@@ -831,7 +831,6 @@ int cf_check iov_adjust_irq_affinities(void)return 0 ; } -__initcall (iov_adjust_irq_affinities);/* * Family15h Model 10h-1fh erratum 746 (IOMMU Logging May Stall Translations)
xen/drivers/passthrough/vtd/iommu.c +0 -1
@@ -2119,7 +2119,6 @@ static int cf_check adjust_vtd_irq_affinities(void)return 0 ; } -__initcall (adjust_vtd_irq_affinities);static int __must_check init_vtd_hw (bool resume) {
xen/drivers/passthrough/x86/iommu.c +6 -0
@@ -462,6 +462,12 @@ bool arch_iommu_use_permitted(const struct domain *d) likely(!p2m_get_hostp2m(d)->global_logdirty)); } +static int cf_check __init adjust_irq_affinities(void) +{ +return iommu_call (&iommu_ops, adjust_irq_affinities); +} +__initcall (adjust_irq_affinities); +/* * Local variables: * mode: C
Signature · 1 line
2.11.0
Quoted 13 lines · Andrew Cooper
The linker script collecting .init.rodata.* ahead of .init.rodata.cf_clobber accidentally causes
__initconst_cf_clobberto be a no-op.Rearrange the linker script to unbreak this.
The IOMMU
adjust_irq_affinities()hooks currently violate the safety requirement for beingcf_clobber, by also being__initcall().Consolidate to a single initcall using
iommu_call()(satisfying thecf_clobbersafety requirement), and also removes the dubious property that we'd call into both vendors IOMMU drivers on boot, relying on the for_each_*() loops to be empty for safety.
Quoted 4 lines
With this fixed, an all-enabled build of Xen has 1681 endbr64's (1918 including .init.text) with 382 (23%) being clobbered during boot.
Signed-off-by Andrew Cooper <[email protected]>
This will do for the immediate purpose, so:
Quoted 2 lines
I was unsure whether to go common or x86 spefific IOMMU code, so went with the conservative option. The final hunk can trivially move if preferred.
The hook is x86-specific, so the wrapper should be too (and the existing inline wrapper also is).
Quoted 4 lines
xen/arch/x86/xen.lds.S +0
-0@@ -210,6 +210,12 @@ SECTIONS DECL_SECTION(.init.data) {
xen/arch/x86/xen.lds.S SECTIONS · line 220
Quoted 10 lines
xen/arch/x86/xen.lds.S +6
-0#endif + . = ALIGN(POINTER_ALIGN); + __initdata_cf_clobber_start = .; + *(.init.data.cf_clobber) + *(.init.rodata.cf_clobber) + __initdata_cf_clobber_end = .; + *(.init.rodata) *(.init.rodata.*)
I wonder if this shouldn't really be two sections. Live-patching will need to supply two ranges to apply_alternatives() anyway (one for each section, unless you want to start requiring to pass a linker script to "$(LD) -r" when generating live patches, just to fold the two sections), so in the core hypervisor we may want to follow suit.
xen/drivers/passthrough/x86/iommu.c bool arch_iommu_use_permitted(const struct domain *d) · line 469
Quoted 11 lines
xen/drivers/passthrough/x86/iommu.c +5
-0@@ -462,6 +462,12 @@ bool arch_iommu_use_permitted(const struct domain *d) likely(!p2m_get_hostp2m(d)->global_logdirty)); } +static int cf_check __init adjust_irq_affinities(void) +{ +return iommu_call (&iommu_ops, adjust_irq_affinities); +} +__initcall (adjust_irq_affinities);
I assume it is intentional that you didn't re-use the inline wrapper, to avoid its (then non-__init) instantiation to stay with an ENDBR. Yet then you could at least _call_ that wrapper here, instead of open- coding it. And I further think the iommu_enabled checks should move out of the vendor functions, plus the hook also has no need anymore to have a return type of int. I guess I'll make a follow-on patch if you don't want to fold this in here.
Jan
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Andrew Cooper
The linker script collecting .init.rodata.* ahead of .init.rodata.cf_clobber accidentally causes
__initconst_cf_clobberto be a no-op.Rearrange the linker script to unbreak this.
The IOMMU
adjust_irq_affinities()hooks currently violate the safety requirement for beingcf_clobber, by also being__initcall().Consolidate to a single initcall using
iommu_call()(satisfying thecf_clobbersafety requirement), and also removes the dubious property that we'd call into both vendors IOMMU drivers on boot, relying on the for_each_*() loops to be empty for safety.
Quoted 6 lines
Quoted 4 lines
With this fixed, an all-enabled build of Xen has 1681 endbr64's (1918 including .init.text) with 382 (23%) being clobbered during boot.
Signed-off-by Andrew Cooper <[email protected]>This will do for the immediate purpose, so:
Reviewed-by Jan Beulich <[email protected]>
Thanks.
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/xen.lds.S +0
-0@@ -210,6 +210,12 @@ SECTIONS DECL_SECTION(.init.data) { #endif
Quoted 13 lines
xen/arch/x86/xen.lds.S SECTIONS · line 220
Quoted 8 lines
xen/arch/x86/xen.lds.S +6
-0+ . = ALIGN(POINTER_ALIGN); + __initdata_cf_clobber_start = .; + *(.init.data.cf_clobber) + *(.init.rodata.cf_clobber) + __initdata_cf_clobber_end = .; + *(.init.rodata) *(.init.rodata.*)I wonder if this shouldn't really be two sections. Live-patching will need to supply two ranges to
apply_alternatives()anyway (one for each section, unless you want to start requiring to pass a linker script to "$(LD) -r" when generating live patches, just to fold the two sections), so in the core hypervisor we may want to follow suit.
I don't see why livepatches would need two sections - they're linked in a similar way to Xen IIRC. Either way, if changes are needed, they should be part of the livepatch work.
Quoted 6 lines
Quoted 6 lines
xen/drivers/passthrough/x86/iommu.c +0
-0@@ -462,6 +462,12 @@ bool arch_iommu_use_permitted(const struct domain *d) likely(!p2m_get_hostp2m(d)->global_logdirty)); }
Quoted 9 lines
xen/drivers/passthrough/x86/iommu.c bool arch_iommu_use_permitted(const struct domain *d) · line 469
Quoted 5 lines
xen/drivers/passthrough/x86/iommu.c +5
-0+static int cf_check __init adjust_irq_affinities(void) +{ +return iommu_call (&iommu_ops, adjust_irq_affinities); +} +__initcall (adjust_irq_affinities);I assume it is intentional that you didn't re-use the inline wrapper, to avoid its (then non-__init) instantiation to stay with an ENDBR. Yet then you could at least _call_ that wrapper here, instead of open- coding it.
No - that was unintentional. I only merged the initcalls late during development and forgot the wrapper.
I've adjusted to:
- return iommu_call(&iommu_ops, adjust_irq_affinities); + return iommu_adjust_irq_affinities();
Quoted 4 lines
And I further think the
iommu_enabledchecks should move out of the vendor functions, plus the hook also has no need anymore to have a return type of int. I guess I'll make a follow-on patch if you don't want to fold this in here.
Yeah, I'd prefer not to fold cleanup into this bugfix, but there are certainly improvements to be done.
~Andrew
Quoted 22 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
xen/arch/x86/xen.lds.S +0
-0@@ -210,6 +210,12 @@ SECTIONS DECL_SECTION(.init.data) { #endifQuoted 13 lines
xen/arch/x86/xen.lds.S SECTIONS · line 220
Quoted 8 lines
xen/arch/x86/xen.lds.S +6
-0+ . = ALIGN(POINTER_ALIGN); + __initdata_cf_clobber_start = .; + *(.init.data.cf_clobber) + *(.init.rodata.cf_clobber) + __initdata_cf_clobber_end = .; + *(.init.rodata) *(.init.rodata.*)I wonder if this shouldn't really be two sections. Live-patching will need to supply two ranges to
apply_alternatives()anyway (one for each section, unless you want to start requiring to pass a linker script to "$(LD) -r" when generating live patches, just to fold the two sections), so in the core hypervisor we may want to follow suit.
Quoted 3 lines
I don't see why livepatches would need two sections - they're linked in a similar way to Xen IIRC. Either way, if changes are needed, they should be part of the livepatch work.
Live patch objects being relocatable ones, their loading logic works with section boundaries. Hence there'll be two sections of interest, the boundaries of which are independent and hence need passing as separate values.
Jan