Skip to content

Commit 4f526e8

Browse files
authored
kmsg: Log the raw buffer if we fail to parse (#1704) (#1709)
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. Cherry-pick of #1704
1 parent ad86b05 commit 4f526e8

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
@@ -486,9 +486,8 @@ impl VmInner {
486486

487487
while let Some(data) = kmsg.next().await {
488488
match data {
489-
Ok(data) => {
490-
let message = kmsg::KmsgParsedEntry::new(&data)?;
491-
match &mut target {
489+
Ok(data) => match kmsg::KmsgParsedEntry::new(&data) {
490+
Ok(message) => match &mut target {
492491
IoTarget::Printer => {
493492
writeln!(
494493
self.printer.out(),
@@ -501,8 +500,18 @@ impl VmInner {
501500
let line = format!("{}\r\n", message.display(true));
502501
console.write_all(line.as_bytes()).await?;
503502
}
504-
}
505-
}
503+
},
504+
Err(e) => match &mut target {
505+
IoTarget::Printer => {
506+
writeln!(self.printer.out(), "[kmsg]: invalid entry: {:?}", e)
507+
.ok();
508+
}
509+
IoTarget::Console(console) => {
510+
let line = format!("invalid kmsg entry: {:?}\r\n", e);
511+
console.write_all(line.as_bytes()).await?;
512+
}
513+
},
514+
},
506515
Err(err) if err.kind() == std::io::ErrorKind::ConnectionReset => {
507516
break;
508517
}

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
@@ -332,7 +332,7 @@ pub async fn kmsg_log_task(
332332
while let Some(data) = file_stream.next().await {
333333
match data {
334334
Ok(data) => {
335-
let message = kmsg::KmsgParsedEntry::new(&data)?;
335+
let message = kmsg::KmsgParsedEntry::new(&data).unwrap();
336336
log_file.write_entry(message.display(false));
337337
}
338338
Err(err) => {

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
@@ -105,7 +105,7 @@ async fn efi_diagnostics_no_boot(config: PetriVmConfigOpenVmm) -> anyhow::Result
105105
// Search for the message
106106
while let Some(data) = kmsg.next().await {
107107
let data = data.context("reading kmsg")?;
108-
let msg = kmsg::KmsgParsedEntry::new(&data)?;
108+
let msg = kmsg::KmsgParsedEntry::new(&data).unwrap();
109109
let raw = msg.message.as_raw();
110110
if raw.contains(NO_BOOT_MSG) {
111111
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
@@ -149,7 +149,7 @@ async fn no_numa_errors(config: PetriVmConfigOpenVmm) -> Result<(), anyhow::Erro
149149
// Search kmsg and make sure we didn't see any errors from the kernel
150150
while let Some(data) = kmsg.next().await {
151151
let data = data.context("reading kmsg")?;
152-
let msg = kmsg::KmsgParsedEntry::new(&data)?;
152+
let msg = kmsg::KmsgParsedEntry::new(&data).unwrap();
153153
let raw = msg.message.as_raw();
154154
if raw.contains(BAD_PROP) {
155155
anyhow::bail!("found bad prop in kmsg");

0 commit comments

Comments
 (0)