xen/version: Remove xen_build_id() and export the variable instead

The 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.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Ross Lagerwall <Ross.lagerwall@citrix.com>
This commit is contained in:
Andrew Cooper committed 2025-08-05 22:09:35 +01:00
1 parent bfb57fecdc
commit a8dc4ec942
4 files changed
+24 -42

No files matched your search

+4 -10
View File
@@ -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();
+10 -13
View File
@@ -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) )
{
+7 -18
View File
@@ -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;
}
}
+3 -1
View File
@@ -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,
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.