From: Lukas Wunner <lukas@wunner.de>
To: Tomita Moeko <tomitamoeko@gmail.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND] x86/pci: Check signature before assigning shadow ROM
Date: Sun, 17 Aug 2025 11:45:17 +0200 [thread overview]
Message-ID: <aKGkrSWUA8BTYniZ@wunner.de> (raw)
In-Reply-To: <20250815162041.14826-1-tomitamoeko@gmail.com>
On Sat, Aug 16, 2025 at 12:20:41AM +0800, Tomita Moeko wrote:
> Modern platforms without VBIOS or UEFI CSM support do not contain
> VGA ROM at 0xC0000, this is observed on Intel Ice Lake and later
> systems. Check whether the VGA ROM region is a valid PCI option ROM
> with 0xAA55 signature before assigning the shadow ROM to device.
Which spec is the 0xAA55 magic number coming from?
Could you add a spec reference for it in a code comment and the
commit message?
I note that arch/x86/kernel/probe_roms.c contains ...
#define ROMSIGNATURE 0xaa55
... and a function romsignature() to check the signature.
I'm wondering why that existing check isn't sufficient?
Why is it necessary to check again elsewhere?
> +++ b/arch/x86/pci/fixup.c
> @@ -317,6 +317,7 @@ static void pci_fixup_video(struct pci_dev *pdev)
> struct pci_bus *bus;
> u16 config;
> struct resource *res;
> + void __iomem *rom;
>
> /* Is VGA routed to us? */
> bus = pdev->bus;
> @@ -338,9 +339,12 @@ static void pci_fixup_video(struct pci_dev *pdev)
> }
> bus = bus->parent;
> }
> - if (!vga_default_device() || pdev == vga_default_device()) {
> +
> + rom = ioremap(0xC0000, 0x20000);
There's a code comment preceding pci_fixup_video() which says that
"BIOS [is] copied to 0xC0000 in system RAM". So this isn't MMIO,
it's system memory and you can use memremap() instead if ioremap().
Since you're only interested in the first two bytes, you don't need
to map the whole 0x20000 bytes.
Instead of amending the if-condition ...
> + if (rom && (!vga_default_device() || pdev == vga_default_device())) {
> pci_read_config_word(pdev, PCI_COMMAND, &config);
> - if (config & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) {
> + if ((config & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) &&
> + (readw(rom) == 0xAA55)) {
> res = &pdev->resource[PCI_ROM_RESOURCE];
... you could just return on failure to find a valid signature, i.e.:
+ rom = memremap(0xC0000, sizeof(sig), MEMREMAP_WB);
+ if (!rom)
+ return;
+
+ memcpy(&sig, rom, sizeof(sig));
+ memunmap(rom);
+ if (sig != 0xAA55)
+ return;
May want to emit an error on failure to memremap().
Amending the if-condition makes it messier to find an offending commit
with "git blame" (more iterations needed). And returning early reduces
indentation levels per section 1 of Documentation/process/coding-style.rst.
Thanks,
Lukas
next prev parent reply other threads:[~2025-08-17 9:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-15 16:20 [PATCH RESEND] x86/pci: Check signature before assigning shadow ROM Tomita Moeko
2025-08-17 9:45 ` Lukas Wunner [this message]
2025-10-08 6:15 ` Tomita Moeko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aKGkrSWUA8BTYniZ@wunner.de \
--to=lukas@wunner.de \
--cc=bhelgaas@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=tomitamoeko@gmail.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox