Skip to content

Commit 402e262

Browse files
committed
Merge tag 'efi-next-for-v6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi
Pull EFI updates from Ard Biesheuvel: - Expose the OVMF firmware debug log via sysfs - Lower the default log level for the EFI stub to avoid corrupting any splash screens with unimportant diagnostic output * tag 'efi-next-for-v6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi: efi: add API doc entry for ovmf_debug_log efistub: Lower default log level efi: add ovmf debug log driver
2 parents c30a135 + 02eb7a8 commit 402e262

File tree

7 files changed

+141
-2
lines changed

7 files changed

+141
-2
lines changed

Documentation/ABI/testing/sysfs-firmware-efi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ Description: Displays the content of the Runtime Configuration Interface
3636
Table version 2 on Dell EMC PowerEdge systems in binary format
3737
Users: It is used by Dell EMC OpenManage Server Administrator tool to
3838
populate BIOS setup page.
39+
40+
What: /sys/firmware/efi/ovmf_debug_log
41+
Date: July 2025
42+
Contact: Gerd Hoffmann <[email protected]>, [email protected]
43+
Description: Displays the content of the OVMF debug log buffer. The file is
44+
only present in case the firmware supports logging to a memory
45+
buffer.

drivers/firmware/efi/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ config EFI_COCO_SECRET
263263
virt/coco/efi_secret module to access the secrets, which in turn
264264
allows userspace programs to access the injected secrets.
265265

266+
config OVMF_DEBUG_LOG
267+
bool "Expose OVMF firmware debug log via sysfs"
268+
depends on EFI
269+
help
270+
Recent OVMF versions (edk2-stable202508 + newer) can write
271+
their debug log to a memory buffer. This driver exposes the
272+
log content via sysfs (/sys/firmware/efi/ovmf_debug_log).
273+
266274
config UNACCEPTED_MEMORY
267275
bool
268276
depends on EFI_STUB

drivers/firmware/efi/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ obj-$(CONFIG_APPLE_PROPERTIES) += apple-properties.o
2929
obj-$(CONFIG_EFI_RCI2_TABLE) += rci2-table.o
3030
obj-$(CONFIG_EFI_EMBEDDED_FIRMWARE) += embedded-firmware.o
3131
obj-$(CONFIG_LOAD_UEFI_KEYS) += mokvar-table.o
32+
obj-$(CONFIG_OVMF_DEBUG_LOG) += ovmf-debug-log.o
3233

3334
obj-$(CONFIG_SYSFB) += sysfb_efi.o
3435

drivers/firmware/efi/efi.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct efi __read_mostly efi = {
4545
.esrt = EFI_INVALID_TABLE_ADDR,
4646
.tpm_log = EFI_INVALID_TABLE_ADDR,
4747
.tpm_final_log = EFI_INVALID_TABLE_ADDR,
48+
.ovmf_debug_log = EFI_INVALID_TABLE_ADDR,
4849
#ifdef CONFIG_LOAD_UEFI_KEYS
4950
.mokvar_table = EFI_INVALID_TABLE_ADDR,
5051
#endif
@@ -473,6 +474,10 @@ static int __init efisubsys_init(void)
473474
platform_device_register_simple("efi_secret", 0, NULL, 0);
474475
#endif
475476

477+
if (IS_ENABLED(CONFIG_OVMF_DEBUG_LOG) &&
478+
efi.ovmf_debug_log != EFI_INVALID_TABLE_ADDR)
479+
ovmf_log_probe(efi.ovmf_debug_log);
480+
476481
return 0;
477482

478483
err_remove_group:
@@ -617,6 +622,9 @@ static const efi_config_table_type_t common_tables[] __initconst = {
617622
{LINUX_EFI_MEMRESERVE_TABLE_GUID, &mem_reserve, "MEMRESERVE" },
618623
{LINUX_EFI_INITRD_MEDIA_GUID, &initrd, "INITRD" },
619624
{EFI_RT_PROPERTIES_TABLE_GUID, &rt_prop, "RTPROP" },
625+
#ifdef CONFIG_OVMF_DEBUG_LOG
626+
{OVMF_MEMORY_LOG_TABLE_GUID, &efi.ovmf_debug_log, "OvmfDebugLog" },
627+
#endif
620628
#ifdef CONFIG_EFI_RCI2_TABLE
621629
{DELLEMC_EFI_RCI2_TABLE_GUID, &rci2_table_phys },
622630
#endif

drivers/firmware/efi/libstub/printk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
#include <linux/ctype.h>
66
#include <linux/efi.h>
77
#include <linux/kernel.h>
8-
#include <linux/printk.h> /* For CONSOLE_LOGLEVEL_* */
8+
#include <linux/kern_levels.h>
99
#include <asm/efi.h>
1010
#include <asm/setup.h>
1111

1212
#include "efistub.h"
1313

14-
int efi_loglevel = CONSOLE_LOGLEVEL_DEFAULT;
14+
int efi_loglevel = LOGLEVEL_NOTICE;
1515

1616
/**
1717
* efi_char16_puts() - Write a UCS-2 encoded string to the console

drivers/firmware/efi/ovmf-debug-log.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/efi.h>
4+
#include <linux/init.h>
5+
#include <linux/io.h>
6+
#include <linux/kernel.h>
7+
#include <linux/kobject.h>
8+
#include <linux/module.h>
9+
#include <linux/platform_device.h>
10+
#include <linux/sysfs.h>
11+
12+
#define OVMF_DEBUG_LOG_MAGIC1 0x3167646d666d766f // "ovmfmdg1"
13+
#define OVMF_DEBUG_LOG_MAGIC2 0x3267646d666d766f // "ovmfmdg2"
14+
15+
struct ovmf_debug_log_header {
16+
u64 magic1;
17+
u64 magic2;
18+
u64 hdr_size;
19+
u64 log_size;
20+
u64 lock; // edk2 spinlock
21+
u64 head_off;
22+
u64 tail_off;
23+
u64 truncated;
24+
u8 fw_version[128];
25+
};
26+
27+
static struct ovmf_debug_log_header *hdr;
28+
static u8 *logbuf;
29+
static u64 logbufsize;
30+
31+
static ssize_t ovmf_log_read(struct file *filp, struct kobject *kobj,
32+
const struct bin_attribute *attr, char *buf,
33+
loff_t offset, size_t count)
34+
{
35+
u64 start, end;
36+
37+
start = hdr->head_off + offset;
38+
if (hdr->head_off > hdr->tail_off && start >= hdr->log_size)
39+
start -= hdr->log_size;
40+
41+
end = start + count;
42+
if (start > hdr->tail_off) {
43+
if (end > hdr->log_size)
44+
end = hdr->log_size;
45+
} else {
46+
if (end > hdr->tail_off)
47+
end = hdr->tail_off;
48+
}
49+
50+
if (start > logbufsize || end > logbufsize)
51+
return 0;
52+
if (start >= end)
53+
return 0;
54+
55+
memcpy(buf, logbuf + start, end - start);
56+
return end - start;
57+
}
58+
59+
static struct bin_attribute ovmf_log_bin_attr = {
60+
.attr = {
61+
.name = "ovmf_debug_log",
62+
.mode = 0444,
63+
},
64+
.read = ovmf_log_read,
65+
};
66+
67+
int __init ovmf_log_probe(unsigned long ovmf_debug_log_table)
68+
{
69+
int ret = -EINVAL;
70+
u64 size;
71+
72+
/* map + verify header */
73+
hdr = memremap(ovmf_debug_log_table, sizeof(*hdr), MEMREMAP_WB);
74+
if (!hdr) {
75+
pr_err("OVMF debug log: header map failed\n");
76+
return -EINVAL;
77+
}
78+
79+
if (hdr->magic1 != OVMF_DEBUG_LOG_MAGIC1 ||
80+
hdr->magic2 != OVMF_DEBUG_LOG_MAGIC2) {
81+
printk(KERN_ERR "OVMF debug log: magic mismatch\n");
82+
goto err_unmap;
83+
}
84+
85+
size = hdr->hdr_size + hdr->log_size;
86+
pr_info("OVMF debug log: firmware version: \"%s\"\n", hdr->fw_version);
87+
pr_info("OVMF debug log: buffer size: %lluk\n", size / 1024);
88+
89+
/* map complete log buffer */
90+
memunmap(hdr);
91+
hdr = memremap(ovmf_debug_log_table, size, MEMREMAP_WB);
92+
if (!hdr) {
93+
pr_err("OVMF debug log: buffer map failed\n");
94+
return -EINVAL;
95+
}
96+
logbuf = (void *)hdr + hdr->hdr_size;
97+
logbufsize = hdr->log_size;
98+
99+
ovmf_log_bin_attr.size = size;
100+
ret = sysfs_create_bin_file(efi_kobj, &ovmf_log_bin_attr);
101+
if (ret != 0) {
102+
pr_err("OVMF debug log: sysfs register failed\n");
103+
goto err_unmap;
104+
}
105+
106+
return 0;
107+
108+
err_unmap:
109+
memunmap(hdr);
110+
return ret;
111+
}

include/linux/efi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ void efi_native_runtime_setup(void);
439439

440440
/* OVMF protocol GUIDs */
441441
#define OVMF_SEV_MEMORY_ACCEPTANCE_PROTOCOL_GUID EFI_GUID(0xc5a010fe, 0x38a7, 0x4531, 0x8a, 0x4a, 0x05, 0x00, 0xd2, 0xfd, 0x16, 0x49)
442+
#define OVMF_MEMORY_LOG_TABLE_GUID EFI_GUID(0x95305139, 0xb20f, 0x4723, 0x84, 0x25, 0x62, 0x7c, 0x88, 0x8f, 0xf1, 0x21)
442443

443444
typedef struct {
444445
efi_guid_t guid;
@@ -642,6 +643,7 @@ extern struct efi {
642643
unsigned long esrt; /* ESRT table */
643644
unsigned long tpm_log; /* TPM2 Event Log table */
644645
unsigned long tpm_final_log; /* TPM2 Final Events Log table */
646+
unsigned long ovmf_debug_log;
645647
unsigned long mokvar_table; /* MOK variable config table */
646648
unsigned long coco_secret; /* Confidential computing secret table */
647649
unsigned long unaccepted; /* Unaccepted memory table */
@@ -1344,6 +1346,8 @@ bool efi_config_table_is_usable(const efi_guid_t *guid, unsigned long table)
13441346

13451347
umode_t efi_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n);
13461348

1349+
int ovmf_log_probe(unsigned long ovmf_debug_log_table);
1350+
13471351
/*
13481352
* efivar ops event type
13491353
*/

0 commit comments

Comments
 (0)