x86: Don't pass bootstrap_map() by function pointer
cover x86: Don't pass bootstrap_map() by function pointer
This series is presented on its code-hygene argument alone.
However, it should be noted that compiler-based mitigations for SP2 do increase the overhead of indirect branches, and even just on the boot path, its wasteful to needlessly take the overhead.
It should be noted that this series texturally collides with both the PV-shim and Vixen series, because of the changes in contstruct_dom*() prototypes.
Andrew Cooper (3):
x86/boot: Export bootstrap_map() for use in other translation units x86/xsm: Use the exported bootstrap_map() function x86/microcode: Use the exported bootstrap_map() function
xen/arch/x86/dom0_build.c | 3 +-- xen/arch/x86/hvm/dom0_build.c | 1 - xen/arch/x86/microcode.c | 20 ++++++++------------ xen/arch/x86/pv/dom0_build.c | 1 - xen/arch/x86/setup.c | 9 ++++----- xen/include/asm-x86/dom0_build.h | 2 -- xen/include/asm-x86/setup.h | 4 ++-- xen/include/xsm/xsm.h | 7 ++----- xen/xsm/xsm_core.c | 9 ++++++--- xen/xsm/xsm_policy.c | 2 +- 10 files changed, 24 insertions(+), 34 deletions(-)
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/3 x86/boot: Export bootstrap_map() for use in other translation units
There is one static bootstrap_map() function which is passed via function pointer to all of its users. This is wasteful.
Export bootstrap_map() for all x86 users, and drop the function pointer parameter from the construct_dom0*() infrastructure.
---
CC: Jan Beulich <[email protected]>
--- xen/arch/x86/dom0_build.c | 3 +-- xen/arch/x86/hvm/dom0_build.c | 1 - xen/arch/x86/pv/dom0_build.c | 1 - xen/arch/x86/setup.c | 5 ++--- xen/include/asm-x86/dom0_build.h | 2 -- xen/include/asm-x86/setup.h | 2 +- 6 files changed, 4 insertions(+), 10 deletions(-)
xen/arch/x86/dom0_build.c +1 -2
@@ -463,7 +463,6 @@ int __init dom0_setup_permissions(struct domain *d)int __init construct_dom0 (struct domain *d,const module_t *image,unsigned long image_headroom,module_t *initrd, -void *(*bootstrap_map)(const module_t *),char *cmdline) {int rc;
@@ -484,7 +483,7 @@ int __init construct_dom0(struct domain *d, const module_t *image,#endif rc = (is_hvm_domain (d) ? dom0_construct_pvh : dom0_construct_pv) - (d, image, image_headroom, initrd, bootstrap_map, cmdline); + (d, image, image_headroom, initrd, cmdline);if ( rc )return rc;
xen/arch/x86/hvm/dom0_build.c +0 -1
@@ -1063,7 +1063,6 @@ static int __init pvh_setup_acpi(struct domain *d, paddr_t start_info)int __init dom0_construct_pvh (struct domain *d,const module_t *image,unsigned long image_headroom,module_t *initrd, -void *(*bootstrap_map)(const module_t *),char *cmdline) {paddr_t entry, start_info;
xen/arch/x86/pv/dom0_build.c +0 -1
@@ -275,7 +275,6 @@ int __init dom0_construct_pv(struct domain *d,const module_t *image, unsigned long image_headroom, module_t *initrd, - void *(*bootstrap_map)(const module_t *), char *cmdline) { int i, cpu, rc, compatible, compat32, order, machine;
xen/arch/x86/setup.c +2 -3
@@ -319,7 +319,7 @@ static void __init normalise_cpu_order(void)* Ensure a given physical memory range is present in the bootstrap mappings. * Use superpage mappings to ensure that pagetable memory needn't be allocated. */ -static void *__init bootstrap_map (const module_t *mod) +void *__init bootstrap_map (const module_t *mod) {static unsigned long __initdata map_cur =BOOTSTRAP_MAP_BASE ;uint64_t start, end, mask = (1L <<L2_PAGETABLE_SHIFT ) -1 ;
@@ -1654,8 +1654,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)*/ if (construct_dom0 (dom0, mod, modules_headroom, (initrdidx >0 ) && (initrdidx < mbi->mods_count) - ? mod + initrdidx :NULL , - bootstrap_map, cmdline) !=0 ) + ? mod + initrdidx :NULL , cmdline) !=0 )panic ("Could not set up DOM0 guest OS" );if ( cpu_has_smap )
xen/include/asm-x86/dom0_build.h +0 -2
@@ -17,13 +17,11 @@ int dom0_setup_permissions(struct domain *d);int dom0_construct_pv (struct domain *d,const module_t *image,unsigned long image_headroom,module_t *initrd, -void *(*bootstrap_map)(const module_t *),char *cmdline);int dom0_construct_pvh (struct domain *d,const module_t *image,unsigned long image_headroom,module_t *initrd, -void *(*bootstrap_map)(const module_t *),char *cmdline); unsigned long dom0_paging_pages(const struct domain *d,
xen/include/asm-x86/setup.h +1 -1
@@ -38,12 +38,12 @@ int construct_dom0(struct domain *d, const module_t *kernel, unsigned long kernel_headroom, module_t *initrd, - void *(*bootstrap_map)(const module_t *), char *cmdline);void setup_io_bitmap (struct domain *d);unsigned long initial_images_nrpages (nodeid_t node);void discard_initial_images (void ); +void *bootstrap_map (const module_t *mod);unsigned int dom0_max_vcpus (void );
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/3] x86/boot: Export bootstrap_map() for use in other translation units
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 08.01.18 at 12:56, <[email protected]> wrote:
There is one static
bootstrap_map()function which is passed via function pointer to all of its users. This is wasteful.Export
bootstrap_map()for all x86 users, and drop the function pointer parameter from the construct_dom0*() infrastructure.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/3 x86/xsm: Use the exported bootstrap_map() function
In reply to Andrew Cooper... rather than obtaining it via function pointer.
---
CC: Jan Beulich <[email protected]>
CC: Daniel De Graaf <[email protected]>
--- xen/arch/x86/setup.c | 2 +- xen/include/xsm/xsm.h | 7 ++----- xen/xsm/xsm_core.c | 9 ++++++--- xen/xsm/xsm_policy.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-)
xen/arch/x86/setup.c +1 -1
@@ -1471,7 +1471,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)bitmap_fill (module_map, mbi->mods_count);__clear_bit (0 , module_map);/* Dom0 kernel is always first */ -xsm_multiboot_init (module_map, mbi, bootstrap_map); +xsm_multiboot_init (module_map, mbi);microcode_grab_module (module_map, mbi, bootstrap_map);
xen/include/xsm/xsm.h +2 -5
@@ -696,11 +696,9 @@ static inline int xsm_xen_version (xsm_default_t def, uint32_t op)#ifdef CONFIG_MULTIBOOT extern int xsm_multiboot_init (unsigned long *module_map, -const multiboot_info_t *mbi, -void *(*bootstrap_map)(const module_t *)); +const multiboot_info_t *mbi);extern int xsm_multiboot_policy_init (unsigned long *module_map,const multiboot_info_t *mbi, -void *(*bootstrap_map)(const module_t *),void **policy_buffer,size_t *policy_size);#endif
@@ -735,8 +733,7 @@ extern const unsigned int xsm_init_policy_size;#ifdef CONFIG_MULTIBOOT static inline int xsm_multiboot_init (unsigned long *module_map, -const multiboot_info_t *mbi, -void *(*bootstrap_map)(const module_t *)) +const multiboot_info_t *mbi) {return 0 ; }
xen/xsm/xsm_core.c +6 -3
@@ -19,6 +19,10 @@#ifdef CONFIG_XSM +#ifdef CONFIG_MULTIBOOT +#include <asm/setup.h> +#endif +#ifdef CONFIG_HAS_DEVICE_TREE #include <asm/setup.h> #endif
@@ -60,8 +64,7 @@ static int __init xsm_core_init(const void *policy_buffer, size_t policy_size)#ifdef CONFIG_MULTIBOOT int __init xsm_multiboot_init (unsigned long *module_map, -const multiboot_info_t *mbi, -void *(*bootstrap_map)(const module_t *)) +const multiboot_info_t *mbi) {int ret =0 ;void *policy_buffer =NULL ;
@@ -71,7 +74,7 @@ int __init xsm_multiboot_init(unsigned long *module_map,if (XSM_MAGIC ) { - ret =xsm_multiboot_policy_init (module_map, mbi, bootstrap_map, + ret =xsm_multiboot_policy_init (module_map, mbi, &policy_buffer, &policy_size);if ( ret ) {
xen/xsm/xsm_policy.c +1 -1
@@ -21,6 +21,7 @@#include <xsm/xsm.h> #ifdef CONFIG_MULTIBOOT #include <xen/multiboot.h> +#include <asm/setup.h> #endif #include <xen/bitops.h> #ifdef CONFIG_HAS_DEVICE_TREE
@@ -31,7 +32,6 @@#ifdef CONFIG_MULTIBOOT int __init xsm_multiboot_policy_init (unsigned long *module_map,const multiboot_info_t *mbi, -void *(*bootstrap_map)(const module_t *),void **policy_buffer,size_t *policy_size) {
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/3] x86/xsm: Use the exported bootstrap_map() function
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 08.01.18 at 12:56, <[email protected]> wrote:
... rather than obtaining it via function pointer.
Signed-off-by Andrew Cooper <[email protected]>
Assuming this doesn't break ARM
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/3] x86/xsm: Use the exported bootstrap_map() function
In reply to Andrew CooperQuoted 3 lines · Andrew Cooper
... rather than obtaining it via function pointer.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/3 x86/microcode: Use the exported bootstrap_map() function
In reply to Andrew Cooper... rather than obtaining it via function pointer. The internal ucode_mod_map function pointer can also be dropped.
---
CC: Jan Beulich <[email protected]>
I'm not entirely convinced of the correctness of the uses of bootstrap_map(NULL) here especially as it is used over an extended period of booting, but only behavioural change I've introduced is to remove the risk of accidentially calling a NULL ucode_mod_map pointer. I'll see about revisiting this when I've got a bit more time and brainpower to spare.
--- xen/arch/x86/microcode.c | 20 ++++++++------------ xen/arch/x86/setup.c | 2 +- xen/include/asm-x86/setup.h | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-)
xen/arch/x86/microcode.c +8 -12
@@ -40,7 +40,6 @@#include <asm/microcode.h> static module_t __initdata ucode_mod; -static void *(*__initdata ucode_mod_map)(const module_t *);static signed int __initdata ucode_mod_idx;static bool_t __initdata ucode_mod_forced;
@@ -96,8 +95,7 @@ custom_param("ucode", parse_ucode);void __init microcode_scan_module (unsigned long *module_map, -const multiboot_info_t *mbi, -void *(*bootmap)(const module_t *)) +const multiboot_info_t *mbi) {module_t *mod = (module_t *)__va (mbi->mods_addr);uint64_t *_blob_start;
@@ -126,7 +124,7 @@ void __init microcode_scan_module(if ( !test_bit (i, module_map) )continue ; - _blob_start =bootmap (&mod[i]); + _blob_start =bootstrap_map (&mod[i]); _blob_size = mod[i].mod_end;if ( !_blob_start ) {
@@ -157,18 +155,17 @@ void __init microcode_scan_module(else memcpy (ucode_blob.data, cd.data, cd.size); } -bootmap (NULL ); +bootstrap_map (NULL );if ( cd.data )break ; }return ; err: -bootmap (NULL ); +bootstrap_map (NULL ); }void __init microcode_grab_module (unsigned long *module_map, -const multiboot_info_t *mbi, -void *(*map)(const module_t *)) +const multiboot_info_t *mbi) {module_t *mod = (module_t *)__va (mbi->mods_addr);
@@ -178,10 +175,9 @@ void __init microcode_grab_module( !__test_and_clear_bit(ucode_mod_idx, module_map) ) goto scan; ucode_mod = mod[ucode_mod_idx]; - ucode_mod_map = map; scan:if ( ucode_scan ) -microcode_scan_module (module_map, mbi, map); +microcode_scan_module (module_map, mbi); }const struct microcode_ops *microcode_ops;
@@ -358,7 +354,7 @@ static int __init microcode_init(void) }else if ( ucode_mod.mod_end ) { -ucode_mod_map (NULL ); +bootstrap_map (NULL ); ucode_mod.mod_end =0 ; }
@@ -399,7 +395,7 @@ int __init early_microcode_update_cpu(bool start_update)else if ( ucode_mod.mod_end ) { len = ucode_mod.mod_end; - data =ucode_mod_map (&ucode_mod); + data =bootstrap_map (&ucode_mod); }if ( data ) {
xen/arch/x86/setup.c +1 -1
@@ -1473,7 +1473,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)xsm_multiboot_init (module_map, mbi); -microcode_grab_module (module_map, mbi, bootstrap_map); +microcode_grab_module (module_map, mbi);timer_init ();
xen/include/asm-x86/setup.h +1 -1
@@ -50,7 +50,7 @@ unsigned int dom0_max_vcpus(void);int xen_in_range (unsigned long mfn);void microcode_grab_module ( -unsigned long *,const multiboot_info_t *,void *(*)(const module_t *)); +unsigned long *,const multiboot_info_t *);extern uint8_t kbd_shift_flags;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/3] x86/microcode: Use the exported bootstrap_map() function
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 08.01.18 at 12:56, <[email protected]> wrote:
... rather than obtaining it via function pointer. The internal
ucode_mod_mapfunction pointer can also be dropped.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel