xen/version: Improvements to buildid handling
cover xen/version: Improvements to buildid handling
Mostly for patch 2.
Andrew Cooper (2):
xen/version: Fold print_build_id() into print_version() xen/version: Remove xen_build_id() and export the variable instead
xen/common/kernel.c | 14 ++++---------- xen/common/keyhandler.c | 1 - xen/common/livepatch.c | 23 ++++++++++------------- xen/common/version.c | 34 ++++++++-------------------------- xen/drivers/char/console.c | 7 +++---- xen/include/xen/lib.h | 1 - xen/include/xen/version.h | 4 +++- 7 files changed, 28 insertions(+), 56 deletions(-)
Signature · 1 line
2.39.5
PATCH 1/2 xen/version: Fold print_build_id() into print_version()
Both callsites call them as a pair, and the buildid really is as much a part of the version as the changeset.
This involves rearranging console_init_preirq() to ensure xen_build_init() is ahead of print_version().
No functional change.
---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Ross Lagerwall <[email protected]>
--- xen/common/keyhandler.c | 1 - xen/common/version.c | 19 ++++++------------- xen/drivers/char/console.c | 7 +++---- xen/include/xen/lib.h | 1 - 4 files changed, 9 insertions(+), 19 deletions(-)
xen/common/keyhandler.c +0 -1
@@ -131,7 +131,6 @@ static void cf_check show_handlers(unsigned char key)printk ("'%c' pressed -> showing installed handlers\n" , key);print_version (); -print_build_id ();for ( i =0 ; i <ARRAY_SIZE (key_table); i++ )if ( key_table[i].fn )
xen/common/version.c +6 -13
@@ -94,6 +94,9 @@ const char *xen_build_info(void)return build_info; } +static const void *build_id_p__read_mostly ; +static unsigned int build_id_len__read_mostly ; +void print_version (void ) { printk("Xen version %d.%d%s (%s@%s) (%s) %s %s\n",
@@ -102,10 +105,10 @@ void print_version(void) xen_build_info(), xen_compile_date());printk ("Latest ChangeSet: %s\n" ,xen_changeset ()); -} -static const void *build_id_p__read_mostly ; -static unsigned int build_id_len__read_mostly ; +if ( build_id_len ) +printk ("build-id: %*phN\n" , build_id_len, build_id_p); +}int xen_build_id (const void **p,unsigned int *len) {
@@ -118,16 +121,6 @@ int xen_build_id(const void **p, unsigned int *len)return 0 ; } -void print_build_id (void ) -{ -/* -* NB: build_id_len may be 0 if XEN_HAS_BUILD_ID=n. -* Do not print empty build-id. -*/ -if ( build_id_len ) -printk ("build-id: %*phN\n" , build_id_len, build_id_p); -} -#ifdef BUILD_ID /* Defined in linker script. */ extern const Elf_Note __note_gnu_build_id_start[], __note_gnu_build_id_end[];
xen/drivers/char/console.c +3 -4
@@ -1105,11 +1105,10 @@ void __init console_init_preirq(void)__putstr (xen_banner ());nrspin_unlock (&console_lock); -print_version (); - -/* Locate and print the buildid, if applicable. */ +/* Locate the buildid, if possible. */ xen_build_init (); -print_build_id (); + +print_version ();if ( opt_sync_console ) {
xen/include/xen/lib.h +0 -1
@@ -48,7 +48,6 @@ int parse_signed_integer(const char *name, const char *s, const char *e,int cmdline_strcmp (const char *frag,const char *name);void print_version (void ); -void print_build_id (void );#ifdef CONFIG_DEBUG_TRACE extern void debugtrace_dump (void );
Signature · 1 line
2.39.5
Re: [PATCH 1/2] xen/version: Fold print_build_id() into print_version()
Quoted 2 lines · Andrew Cooper
Both callsites call them as a pair, and the buildid really is as much a part of the version as the changeset.
I wouldn't view it as strongly, but then I also don't mind making the connection, so ...
Quoted 6 lines
This involves rearranging
console_init_preirq()to ensurexen_build_init()is ahead ofprint_version().No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Jan
PATCH 2/2 xen/version: Remove xen_build_id() and export the variable instead
In reply to Andrew CooperThe API is unergonomic to use, and leads to poor code generation because of unnecessary forcing of data to the stack.
Rename build_id_p to xen_build_id, and build_id_len to xen_build_id_len, make them __ro_after_init, and export the variables directly.
No functional change.
---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Ross Lagerwall <[email protected]>
Both the code diffstat, and the binary on x86 speaks for themselves:
add/remove: 1/2 grow/shrink: 0/6 up/down: 4/-348 (-344)
Function old new delta
xen_build_id_len - 4 +4 build_id_len 4 - -4 build_id_p 8 - -8 xen_build_id 42 8 -34 livepatch_printall 470 432 -38 build_id_dep 152 113 -39 livepatch_op 7930 7866 -64 do_xen_version 2436 2363 -73 livepatch_op.cold 1420 1332 -88 --- xen/common/kernel.c | 14 ++++---------- xen/common/livepatch.c | 23 ++++++++++------------- xen/common/version.c | 25 +++++++------------------ xen/include/xen/version.h | 4 +++- 4 files changed, 24 insertions(+), 42 deletions(-)
xen/common/kernel.c +4 -10
@@ -510,21 +510,15 @@ static long xenver_varbuf_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)struct xen_varbuf user_str;const char *str =NULL ;size_t sz; -int rc;switch ( cmd ) {case XENVER_build_id: - { -unsigned int local_sz; - - rc =xen_build_id ((const void **)&str, &local_sz); -if ( rc ) -return rc; - - sz = local_sz; + str = xen_build_id; + sz = xen_build_id_len; +if ( !sz ) +return -ENODATA ; goto have_len; - }case XENVER_extraversion2: str =xen_extra_version ();
xen/common/livepatch.c +10 -13
@@ -475,8 +475,8 @@ static int parse_buildid(const struct livepatch_elf_sec *sec,static int check_xen_buildid (const struct livepatch_elf *elf) { -const void *id; -unsigned int len; +const void *id = xen_build_id; +unsigned int len = xen_build_id_len;struct livepatch_build_id lp_id;const struct livepatch_elf_sec *sec =livepatch_elf_sec_by_name (elf,ELF_LIVEPATCH_XEN_DEPENDS );
@@ -498,13 +498,12 @@ static int check_xen_buildid(const struct livepatch_elf *elf)return -EINVAL ; } - rc =xen_build_id (&id, &len); -if ( rc ) +if ( !len ) { printk(XENLOG_ERR LIVEPATCH"%s: unable to get running Xen build-id: %d\n" , elf->name, rc); -return rc; +return -ENODATA ; }if ( lp_id.len != len ||memcmp (id, lp_id.p, len) )
@@ -1984,7 +1983,6 @@ static int build_id_dep(struct payload *payload, bool internal) {const void *id =NULL ;unsigned int len =0 ; -int rc;const char *name ="hypervisor" ;ASSERT (payload->dep.len && payload->dep.p);
@@ -1992,9 +1990,10 @@ static int build_id_dep(struct payload *payload, bool internal)/* First time user is against hypervisor. */ if ( internal ) { - rc =xen_build_id (&id, &len); -if ( rc ) -return rc; + id = xen_build_id; + len = xen_build_id_len; +if ( !len ) +return -ENODATA ; }else {
@@ -2249,14 +2248,12 @@ static const char *state2str(unsigned int state) static void cf_check livepatch_printall(unsigned char key) {struct payload *data; -const void *binary_id =NULL ; -unsigned int len =0 ;unsigned int i;printk ("'%c' pressed - Dumping all livepatch patches\n" , key); -if ( !xen_build_id (&binary_id, &len) ) -printk ("build-id: %*phN\n" , len, binary_id); +if ( xen_build_id_len ) +printk ("build-id: %*phN\n" , xen_build_id_len, xen_build_id);if ( !spin_trylock (&payload_lock) ) {
xen/common/version.c +7 -18
@@ -94,8 +94,8 @@ const char *xen_build_info(void)return build_info; } -static const void *build_id_p__read_mostly ; -static unsigned int build_id_len__read_mostly ; +const void *__ro_after_init xen_build_id; +unsigned int __ro_after_init xen_build_id_len;void print_version (void ) {
@@ -106,19 +106,8 @@ void print_version(void)printk ("Latest ChangeSet: %s\n" ,xen_changeset ()); -if ( build_id_len ) -printk ("build-id: %*phN\n" , build_id_len, build_id_p); -} - -int xen_build_id (const void **p,unsigned int *len) -{ -if ( !build_id_len ) -return -ENODATA ; - - *len = build_id_len; - *p = build_id_p; - -return 0 ; +if ( xen_build_id_len ) +printk ("build-id: %*phN\n" , xen_build_id_len, xen_build_id); }#ifdef BUILD_ID
@@ -193,7 +182,7 @@ void __init xen_build_init(void) sz = (uintptr_t )__note_gnu_build_id_end - (uintptr_t )n; - rc =xen_build_id_check (n, sz, &build_id_p, &build_id_len); + rc =xen_build_id_check (n, sz, &xen_build_id, &xen_build_id_len);#ifdef CONFIG_X86 /*
@@ -219,8 +208,8 @@ void __init xen_build_init(void)if ( info->cv_signature ==CVINFO_PDB70_CVSIGNATURE ) { - build_id_p = info->signature; - build_id_len =sizeof (info->signature); + xen_build_id = info->signature; + xen_build_id_len =sizeof (info->signature); rc =0 ; } }
xen/include/xen/version.h +3 -1
@@ -17,10 +17,12 @@ const char *xen_changeset(void);const char *xen_banner (void );const char *xen_deny (void );const char *xen_build_info (void ); -int xen_build_id (const void **p,unsigned int *len);extern char xen_cap_info[128 ]; +extern const void *xen_build_id; +extern unsigned int xen_build_id_len;/* 0 -> No build id. */ +#ifdef BUILD_ID void xen_build_init (void ); int xen_build_id_check(const Elf_Note *n, unsigned int n_sz,
Signature · 1 line
2.39.5
Re: [PATCH 2/2] xen/version: Remove xen_build_id() and export the variable instead
Quoted 9 lines · Andrew Cooper
The API is unergonomic to use, and leads to poor code generation because of unnecessary forcing of data to the stack.
Rename
build_id_ptoxen_build_id, andbuild_id_lentoxen_build_id_len, make them__ro_after_init, and export the variables directly.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Re: [PATCH 2/2] xen/version: Remove xen_build_id() and export the variable instead
In reply to Andrew CooperQuoted 74 lines · Andrew Cooper
The API is unergonomic to use, and leads to poor code generation because of unnecessary forcing of data to the stack.
Rename
build_id_ptoxen_build_id, andbuild_id_lentoxen_build_id_len, make them__ro_after_init, and export the variables directly.No functional change.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Ross Lagerwall <[email protected]>Both the code diffstat, and the binary on x86 speaks for themselves:
add/remove: 1/2 grow/shrink: 0/6 up/down: 4/-348 (-344)
Function old new deltaxen_build_id_len - 4 +4 build_id_len 4 - -4 build_id_p 8 - -8 xen_build_id 42 8 -34 livepatch_printall 470 432 -38 build_id_dep 152 113 -39 livepatch_op 7930 7866 -64 do_xen_version 2436 2363 -73 livepatch_op.cold 1420 1332 -88 --- xen/common/kernel.c | 14 ++++---------- xen/common/livepatch.c | 23 ++++++++++------------- xen/common/version.c | 25 +++++++------------------ xen/include/xen/version.h | 4 +++- 4 files changed, 24 insertions(+), 42 deletions(-)xen/common/kernel.c +4
-10@@ -510,21 +510,15 @@ static long xenver_varbuf_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)struct xen_varbuf user_str;const char *str =NULL ;size_t sz; -int rc;switch ( cmd ) {case XENVER_build_id: - { -unsigned int local_sz; - - rc =xen_build_id ((const void **)&str, &local_sz); -if ( rc ) -return rc; - - sz = local_sz; + str = xen_build_id; + sz = xen_build_id_len; +if ( !sz ) +return -ENODATA ; goto have_len; - }case XENVER_extraversion2: str =xen_extra_version ();xen/common/livepatch.c +0
-0
xen/common/livepatch.c static int parse_buildid(const struct livepatch_elf_sec *sec, · line 479
Quoted 7 lines
xen/common/livepatch.c +2
-2@@ -475,8 +475,8 @@ static int parse_buildid(const struct livepatch_elf_sec *sec,static int check_xen_buildid (const struct livepatch_elf *elf) { -const void *id; -unsigned int len; +const void *id = xen_build_id; +unsigned int len = xen_build_id_len;
Is it worth making this const? Or you could just remove these variables entirely and use xen_build_id / xen_build_id_len directly in the rest of the function.
In any case,