Skip to content

Commit f24168c

Browse files
authored
kmsg: Log the raw buffer if we fail to parse (#1704)
We've seen a crash here in the wild, but haven't yet figured out what exactly is failing to parse. Add some more logging so we can hopefully get this if it happens again.
1 parent 736445b commit f24168c

File tree

6 files changed

+25
-16
lines changed

6 files changed

+25
-16
lines changed

hyperv/tools/hypestv/src/windows/vm.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,8 @@ impl VmInner {
507507

508508
while let Some(data) = kmsg.next().await {
509509
match data {
510-
Ok(data) => {
511-
let message = kmsg::KmsgParsedEntry::new(&data)?;
512-
match &mut target {
510+
Ok(data) => match kmsg::KmsgParsedEntry::new(&data) {
511+
Ok(message) => match &mut target {
513512
IoTarget::Printer => {
514513
writeln!(
515514
self.printer.out(),
@@ -522,8 +521,18 @@ impl VmInner {
522521
let line = format!("{}\r\n", message.display(true));
523522
console.write_all(line.as_bytes()).await?;
524523
}
525-
}
526-
}
524+
},
525+
Err(e) => match &mut target {
526+
IoTarget::Printer => {
527+
writeln!(self.printer.out(), "[kmsg]: invalid entry: {:?}", e)
528+
.ok();
529+
}
530+
IoTarget::Console(console) => {
531+
let line = format!("invalid kmsg entry: {:?}\r\n", e);
532+
console.write_all(line.as_bytes()).await?;
533+
}
534+
},
535+
},
527536
Err(err) if err.kind() == std::io::ErrorKind::ConnectionReset => {
528537
break;
529538
}

openhcl/ohcldiag-dev/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,10 @@ pub fn main() -> anyhow::Result<()> {
629629

630630
while let Some(data) = file_stream.next().await {
631631
match data {
632-
Ok(data) => {
633-
let message = kmsg::KmsgParsedEntry::new(&data)?;
634-
println!("{}", message.display(is_terminal));
635-
}
632+
Ok(data) => match kmsg::KmsgParsedEntry::new(&data) {
633+
Ok(message) => println!("{}", message.display(is_terminal)),
634+
Err(e) => println!("Invalid kmsg entry: {e:?}"),
635+
},
636636
Err(err) if reconnect && err.kind() == ErrorKind::ConnectionReset => {
637637
if verbose {
638638
eprintln!(

petri/src/tracing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub async fn kmsg_log_task(
344344
while let Some(data) = file_stream.next().await {
345345
match data {
346346
Ok(data) => {
347-
let message = KmsgParsedEntry::new(&data)?;
347+
let message = KmsgParsedEntry::new(&data).unwrap();
348348
let level = kernel_level_to_tracing_level(message.level);
349349
log_file.write_entry_fmt(None, level, format_args!("{}", message.display(false)));
350350
}

support/kmsg/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ impl Display for EncodedMessage<'_> {
6969

7070
/// An error indicating the kmsg entry could not be parsed because it is invalid.
7171
#[derive(Debug, Error)]
72-
#[error("invalid kmsg entry")]
73-
pub struct InvalidKmsgEntry;
72+
#[error("invalid kmsg entry: {0:?}")]
73+
pub struct InvalidKmsgEntry<'a>(&'a [u8]);
7474

7575
impl<'a> KmsgParsedEntry<'a> {
76-
pub fn new(data: &'a [u8]) -> Result<Self, InvalidKmsgEntry> {
77-
Self::new_inner(data).ok_or(InvalidKmsgEntry)
76+
pub fn new(data: &'a [u8]) -> Result<Self, InvalidKmsgEntry<'a>> {
77+
Self::new_inner(data).ok_or(InvalidKmsgEntry(data))
7878
}
7979

8080
fn new_inner(data: &'a [u8]) -> Option<Self> {

vmm_tests/vmm_tests/tests/tests/multiarch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ async fn efi_diagnostics_no_boot(
181181
// Search for the message
182182
while let Some(data) = kmsg.next().await {
183183
let data = data.context("reading kmsg")?;
184-
let msg = kmsg::KmsgParsedEntry::new(&data)?;
184+
let msg = kmsg::KmsgParsedEntry::new(&data).unwrap();
185185
let raw = msg.message.as_raw();
186186
if raw.contains(NO_BOOT_MSG) {
187187
return Ok(());

vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_uefi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ async fn no_numa_errors(config: PetriVmBuilder<OpenVmmPetriBackend>) -> Result<(
157157
// Search kmsg and make sure we didn't see any errors from the kernel
158158
while let Some(data) = kmsg.next().await {
159159
let data = data.context("reading kmsg")?;
160-
let msg = kmsg::KmsgParsedEntry::new(&data)?;
160+
let msg = kmsg::KmsgParsedEntry::new(&data).unwrap();
161161
let raw = msg.message.as_raw();
162162
if raw.contains(BAD_PROP) {
163163
anyhow::bail!("found bad prop in kmsg");

0 commit comments

Comments
 (0)