Skip to content

Commit 7f10fca

Browse files
firmware_uefi: suppress known warning logs backport (#1558)
This is a backport PR for EfiDiagnostics to suppress known logs that spam kmsg. Original PR is here: #1551 Co-authored-by: Trevor Jones <trevor@thjmedia.net>
1 parent 0aafe8e commit 7f10fca

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

vm/devices/firmware/firmware_uefi/src/service/diagnostics.rs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use guestmem::GuestMemory;
1818
use guestmem::GuestMemoryError;
1919
use inspect::Inspect;
2020
use std::borrow::Cow;
21+
use std::collections::BTreeMap;
2122
use std::fmt::Debug;
2223
use std::mem::size_of;
2324
use thiserror::Error;
@@ -43,6 +44,16 @@ pub const MAX_LOG_BUFFER_SIZE: u32 = 0x400000; // 4MB
4344
/// Maximum allowed size of a single message
4445
pub const MAX_MESSAGE_LENGTH: u16 = 0x1000; // 4KB
4546

47+
// Suppress logs that contain these known error/warning messages.
48+
// These messages are the result of known issues with our UEFI firmware that do
49+
// not seem to affect the guest.
50+
// TODO: Fix UEFI to resolve this errors/warnings
51+
const SUPPRESS_LOGS: [&str; 3] = [
52+
"WARNING: There is mismatch of supported HashMask (0x2 - 0x7) between modules",
53+
"that are linking different HashInstanceLib instances!",
54+
"ConvertPages: failed to find range",
55+
];
56+
4657
/// Represents a processed log entry from the EFI diagnostics buffer
4758
#[derive(Debug, Clone)]
4859
pub struct EfiDiagnosticsLog<'a> {
@@ -320,11 +331,7 @@ impl DiagnosticsServices {
320331
let mut bytes_read: usize = 0;
321332
let mut entries_processed: usize = 0;
322333

323-
// Defines how to handle completed messages
324-
let mut process_complete_log = |log: EfiDiagnosticsLog<'_>| {
325-
log_handler(log);
326-
entries_processed += 1;
327-
};
334+
let mut suppressed_logs = BTreeMap::new();
328335

329336
// Process the buffer slice until all entries are processed
330337
while !buffer_slice.is_empty() {
@@ -349,13 +356,26 @@ impl DiagnosticsServices {
349356

350357
// Handle completed messages (ending with '\n')
351358
if !entry.message.is_empty() && entry.message.ends_with('\n') {
352-
process_complete_log(EfiDiagnosticsLog {
353-
debug_level,
354-
ticks: time_stamp,
355-
phase,
356-
message: accumulated_message.trim_end_matches(&['\r', '\n'][..]),
357-
});
359+
let mut suppress = false;
360+
for log in SUPPRESS_LOGS {
361+
if accumulated_message.contains(log) {
362+
suppressed_logs
363+
.entry(log)
364+
.and_modify(|c| *c += 1)
365+
.or_insert(1);
366+
suppress = true;
367+
}
368+
}
369+
if !suppress {
370+
log_handler(EfiDiagnosticsLog {
371+
debug_level,
372+
ticks: time_stamp,
373+
phase,
374+
message: accumulated_message.trim_end_matches(&['\r', '\n'][..]),
375+
});
376+
}
358377
is_accumulating = false;
378+
entries_processed += 1;
359379
}
360380

361381
// Update bytes read and move to the next entry
@@ -372,12 +392,17 @@ impl DiagnosticsServices {
372392

373393
// Process any remaining accumulated message
374394
if is_accumulating && !accumulated_message.is_empty() {
375-
process_complete_log(EfiDiagnosticsLog {
395+
log_handler(EfiDiagnosticsLog {
376396
debug_level,
377397
ticks: time_stamp,
378398
phase,
379399
message: accumulated_message.trim_end_matches(&['\r', '\n'][..]),
380400
});
401+
entries_processed += 1;
402+
}
403+
404+
for (substring, count) in suppressed_logs {
405+
tracelimit::warn_ratelimited!(substring, count, "suppressed logs")
381406
}
382407

383408
// Print summary statistics

0 commit comments

Comments
 (0)