The XEN_ELFNOTE_L1_MFN_VALID is an arrray of two values, but it is
printed as:
(XEN) ELF: note: L1_MFN_VALID = 0
Expand the printing to handle an array.
(XEN) ELF: note: L1_MFN_VALID = mask: 0x1 val: 0x1
ELFNOTE_OTHER prints the name and " = ", but not the value.
Implementing a switch case is needed to show the value, which should
include a newline.
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
---
xen/common/libelf/libelf-dominfo.c | 59 +++++++++++++++++++-----------
1 file changed, 38 insertions(+), 21 deletions(-)
diff --git a/xen/common/libelf/libelf-dominfo.c b/xen/common/libelf/libelf-dominfo.c
index a13a5e4db6..7cc7b18a51 100644
--- a/xen/common/libelf/libelf-dominfo.c
+++ b/xen/common/libelf/libelf-dominfo.c
@@ -101,26 +101,30 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf,
/* *INDENT-OFF* */
static const struct {
const char *name;
- bool str;
+ enum {
+ ELFNOTE_INT,
+ ELFNOTE_STRING,
+ ELFNOTE_OTHER
+ } type;
} note_desc[] = {
- [XEN_ELFNOTE_ENTRY] = { "ENTRY", 0},
- [XEN_ELFNOTE_HYPERCALL_PAGE] = { "HYPERCALL_PAGE", 0},
- [XEN_ELFNOTE_VIRT_BASE] = { "VIRT_BASE", 0},
- [XEN_ELFNOTE_INIT_P2M] = { "INIT_P2M", 0},
- [XEN_ELFNOTE_PADDR_OFFSET] = { "PADDR_OFFSET", 0},
- [XEN_ELFNOTE_HV_START_LOW] = { "HV_START_LOW", 0},
- [XEN_ELFNOTE_XEN_VERSION] = { "XEN_VERSION", 1},
- [XEN_ELFNOTE_GUEST_OS] = { "GUEST_OS", 1},
- [XEN_ELFNOTE_GUEST_VERSION] = { "GUEST_VERSION", 1},
- [XEN_ELFNOTE_LOADER] = { "LOADER", 1},
- [XEN_ELFNOTE_PAE_MODE] = { "PAE_MODE", 1},
- [XEN_ELFNOTE_FEATURES] = { "FEATURES", 1},
- [XEN_ELFNOTE_SUPPORTED_FEATURES] = { "SUPPORTED_FEATURES", 0},
- [XEN_ELFNOTE_BSD_SYMTAB] = { "BSD_SYMTAB", 1},
- [XEN_ELFNOTE_L1_MFN_VALID] = { "L1_MFN_VALID", false },
- [XEN_ELFNOTE_SUSPEND_CANCEL] = { "SUSPEND_CANCEL", 0 },
- [XEN_ELFNOTE_MOD_START_PFN] = { "MOD_START_PFN", 0 },
- [XEN_ELFNOTE_PHYS32_ENTRY] = { "PHYS32_ENTRY", 0 },
+ [XEN_ELFNOTE_ENTRY] = { "ENTRY", ELFNOTE_INT },
+ [XEN_ELFNOTE_HYPERCALL_PAGE] = { "HYPERCALL_PAGE", ELFNOTE_INT },
+ [XEN_ELFNOTE_VIRT_BASE] = { "VIRT_BASE", ELFNOTE_INT },
+ [XEN_ELFNOTE_INIT_P2M] = { "INIT_P2M", ELFNOTE_INT },
+ [XEN_ELFNOTE_PADDR_OFFSET] = { "PADDR_OFFSET", ELFNOTE_INT },
+ [XEN_ELFNOTE_HV_START_LOW] = { "HV_START_LOW", ELFNOTE_INT },
+ [XEN_ELFNOTE_XEN_VERSION] = { "XEN_VERSION", ELFNOTE_STRING },
+ [XEN_ELFNOTE_GUEST_OS] = { "GUEST_OS", ELFNOTE_STRING },
+ [XEN_ELFNOTE_GUEST_VERSION] = { "GUEST_VERSION", ELFNOTE_STRING },
+ [XEN_ELFNOTE_LOADER] = { "LOADER", ELFNOTE_STRING },
+ [XEN_ELFNOTE_PAE_MODE] = { "PAE_MODE", ELFNOTE_STRING },
+ [XEN_ELFNOTE_FEATURES] = { "FEATURES", ELFNOTE_STRING },
+ [XEN_ELFNOTE_SUPPORTED_FEATURES] = { "SUPPORTED_FEATURES", ELFNOTE_INT },
+ [XEN_ELFNOTE_BSD_SYMTAB] = { "BSD_SYMTAB", ELFNOTE_STRING },
+ [XEN_ELFNOTE_L1_MFN_VALID] = { "L1_MFN_VALID", ELFNOTE_OTHER },
+ [XEN_ELFNOTE_SUSPEND_CANCEL] = { "SUSPEND_CANCEL", ELFNOTE_INT },
+ [XEN_ELFNOTE_MOD_START_PFN] = { "MOD_START_PFN", ELFNOTE_INT },
+ [XEN_ELFNOTE_PHYS32_ENTRY] = { "PHYS32_ENTRY", ELFNOTE_INT },
};
/* *INDENT-ON* */
@@ -136,7 +140,7 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf,
return 0;
}
- if ( note_desc[type].str )
+ if ( note_desc[type].type == ELFNOTE_STRING )
{
str = elf_strval(elf, elf_note_desc(elf, note));
if (str == NULL)
@@ -146,13 +150,17 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf,
parms->elf_notes[type].type = XEN_ENT_STR;
parms->elf_notes[type].data.str = str;
}
- else
+ else if ( note_desc[type].type == ELFNOTE_INT )
{
val = elf_note_numeric(elf, note);
elf_msg(elf, "ELF: note: %s = %#" PRIx64 "\n", note_desc[type].name, val);
parms->elf_notes[type].type = XEN_ENT_LONG;
parms->elf_notes[type].data.num = val;
}
+ else
+ {
+ elf_msg(elf, "ELF: note: %s = ", note_desc[type].name);
+ }
parms->elf_notes[type].name = note_desc[type].name;
switch ( type )
@@ -217,6 +225,15 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf,
case XEN_ELFNOTE_PHYS32_ENTRY:
parms->phys_entry = val;
break;
+
+ case XEN_ELFNOTE_L1_MFN_VALID:
+ if ( elf_uval(elf, note, descsz) != 2 * sizeof(uint64_t) )
+ return -1;
+
+ elf_msg(elf, "mask: %#"PRIx64" val: %#"PRIx64"\n",
+ elf_note_numeric_array(elf, note, 8, 0),
+ elf_note_numeric_array(elf, note, 8, 1));
+ break;
}
return 0;
}
--
2.44.0
On 13.03.2024 20:30, Jason Andryuk wrote: > @@ -217,6 +225,15 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf, > case XEN_ELFNOTE_PHYS32_ENTRY: > parms->phys_entry = val; > break; > + > + case XEN_ELFNOTE_L1_MFN_VALID: > + if ( elf_uval(elf, note, descsz) != 2 * sizeof(uint64_t) ) > + return -1; elf_note_numeric() use sites don't have such a check. Why would we need one here, and even more so causing a error to be raised when in reality the supplied values (still) aren't consumed? Furthermore the documentation says "pairs" (plural) for a reason. Finally maddr_t-sized only happens to mean uint64_t on all architectures we presently support. Jan > + elf_msg(elf, "mask: %#"PRIx64" val: %#"PRIx64"\n", > + elf_note_numeric_array(elf, note, 8, 0), > + elf_note_numeric_array(elf, note, 8, 1)); > + break; > } > return 0; > }
On 2024-03-14 09:16, Jan Beulich wrote: > On 13.03.2024 20:30, Jason Andryuk wrote: >> @@ -217,6 +225,15 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf, >> case XEN_ELFNOTE_PHYS32_ENTRY: >> parms->phys_entry = val; >> break; >> + >> + case XEN_ELFNOTE_L1_MFN_VALID: >> + if ( elf_uval(elf, note, descsz) != 2 * sizeof(uint64_t) ) >> + return -1; > > elf_note_numeric() use sites don't have such a check. Why would we need > one here, and even more so causing a error to be raised when in reality > the supplied values (still) aren't consumed? Furthermore the documentation > says "pairs" (plural) for a reason. Finally maddr_t-sized only happens to > mean uint64_t on all architectures we presently support. I failed to pay attention to the definition stating plural pairs. I saw Linux stored two 64bit values and printed them. I added the size check to avoid going out of bounds. elf_note_numeric() handles 1, 2, 4 or 8 bytes and returns 0 otherwise, so it won't overrun boundaries. That's why it was getting printed as "ELF: note: L1_MFN_VALID = 0" What motivated this was seeing "PVH_RELOCATION = 0". That confusingly looks like relocation is disabled. I'm fine dropping this attempt at printing the L1_MFN_VALID note. maddr_t is not defined, and it looks the note values were 32bit in non-PAE kernels. It could just be printed as "ELF: note: L1_MFN_VALID" with no details. Regards, Jason >> + elf_msg(elf, "mask: %#"PRIx64" val: %#"PRIx64"\n", >> + elf_note_numeric_array(elf, note, 8, 0), >> + elf_note_numeric_array(elf, note, 8, 1)); >> + break; >> } >> return 0; >> } >
© 2016 - 2026 Red Hat, Inc.