PCI: vmd: Only assign _OSC features in bare metal OS.
Subsystems (3)
Nirmal Patel
maintainerPATCH 1/1 PCI: vmd: Only assign _OSC features in bare metal OS.
From: Nirmal Patel <[email protected]>
Copy valid _OSC flags from root bridge only when OS can provide correct values. In virtual machine, all of the control features are disabled as hypervisor will not passthrough root bridge information to VM.
--- drivers/pci/controller/vmd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/pci/controller/vmd.c +4 -2
@@ -910,8 +910,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)return -ENODEV ; } -vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus), -to_pci_host_bridge (vmd->bus->bridge)); +/* Don't copy _OSC control flags in VM, it disables features.*/ +if (!offset[0 ] || !offset[1 ]) +vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus), +to_pci_host_bridge (vmd->bus->bridge));vmd_attach_resources (vmd);if (vmd->irq_domain)
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Incorrect boolean logic for detecting virtual machine environments due to a De Morgan's Law…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Incorrect boolean logic for detecting virtual machine environments due to a De Morgan's Law violation, leading to erroneous _OSC flag copying in VMs.
- [High] The VM detection heuristic used for skipping _OSC flags fails to account for Xen domains and older VMD hardware lacking shadow registers. --
commit 51d3c2c481556010415fe2cd5fa77be881005b5c
Author: Nirmal Patel <[email protected]>
PCI: vmd: Only assign _OSC features in bare metal OS.
Copy valid _OSC flags from root bridge only when OS can provide correct values. In virtual machine, all of the control features are disabled as hypervisor will not passthrough root bridge information to VM.
drivers/pci/controller/vmd.c static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) · line 914
Quoted 12 lines
drivers/pci/controller/vmd.c +2
-2@@ -910,8 +910,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)return -ENODEV ; } -vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus), -to_pci_host_bridge (vmd->bus->bridge)); +/* Don't copy _OSC control flags in VM, it disables features.*/ +if (!offset[0 ] || !offset[1 ])
[Severity: High]
Does this logical condition correctly identify bare-metal environments?
The patch uses !offset[0] || !offset[1] to execute bare-metal logic. However, if a hypervisor identity-maps exactly one MEMBAR (offset is 0) while translating the other (offset is non-zero), this condition will evaluate to true.
Since earlier in the function offset[0] || offset[1] is used to indicate a VM for MSI remapping, should the inverse (bare metal) be
!offset[0] && !offset[1]?
[Severity: High]
Does this VM detection heuristic also cover Xen domains and older VMD hardware?
If running in a Xen domain or a VM with older VMD hardware lacking the VMD_FEAT_HAS_MEMBAR_SHADOW capability, both offset variables remain 0.
This causes the condition to evaluate to true, meaning the driver will still copy the _OSC flags in these VM environments, potentially breaking PCIe features. Could this be avoided by checking for xen_domain() or hardware capability constraints alongside the offsets?
Quoted 5 lines
drivers/pci/controller/vmd.c +2
-0+vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus), +to_pci_host_bridge (vmd->bus->bridge));vmd_attach_resources (vmd);if (vmd->irq_domain)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 5 lines · Nirmal Patel
Copy valid
_OSCflags from root bridge only when OS can provide correct values. In virtual machine, all of the control features are disabled as hypervisor will not passthrough root bridge information to VM.Reviewed-by Andy Shevchenko <[email protected]>
I confirm that I reviewed this internally and agree on the main approach and the implementation. I think it's a redundant period in the Subject slipped, but it maybe tweaked whilst applying I think.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 17 lines · Nirmal Patel
From: Nirmal Patel <[email protected]>
Copy valid
_OSCflags from root bridge only when OS can provide correct values. In virtual machine, all of the control features are disabled as hypervisor will not passthrough root bridge information to VM.Signed-off-by Nirmal Patel <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- drivers/pci/controller/vmd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/pci/controller/vmd.c +0
-0
drivers/pci/controller/vmd.c static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) · line 914
Quoted 7 lines
drivers/pci/controller/vmd.c +2
-2@@ -910,8 +910,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)return -ENODEV ; } -vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus), -to_pci_host_bridge (vmd->bus->bridge)); +/* Don't copy _OSC control flags in VM, it disables features.*/ +if (!offset[0 ] || !offset[1 ])
Drop period in subject line.
Replace period in comment with space.
Kind of a weird way to check for VM. I see it's already done this way earlier in the function, but maybe it's time to add a descriptive boolean based on offset[0] and offset[1].
Quoted 8 lines
drivers/pci/controller/vmd.c +2
-0+vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus), +to_pci_host_bridge (vmd->bus->bridge));vmd_attach_resources (vmd);if (vmd->irq_domain)Signature · 1 line
2.43.0
Nirmal Patel
maintainerQuoted 32 lines · On Tue, 30 Jun 2026 12:10:03 -0500 Bjorn Helgaas <[email protected]> wrote:
Quoted 27 lines · Nirmal Patel
From: Nirmal Patel <[email protected]>
Copy valid
_OSCflags from root bridge only when OS can provide correct values. In virtual machine, all of the control features are disabled as hypervisor will not passthrough root bridge information to VM.Signed-off-by Nirmal Patel <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- drivers/pci/controller/vmd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/pci/controller/vmd.cindexd4ae250d4bc6..f9e38f2f926a100644 ---a/drivers/pci/controller/vmd.c
+++b/drivers/pci/controller/vmd.c(quoted diff) +1
-2@@ -910,8 +910,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) return -ENODEV; } - vmd_copy_host_bridge_flags(pci_find_host_bridge(vmd->dev->bus), - to_pci_host_bridge(vmd->bus->bridge)); + /* Don't copy _OSC control flags in VM, it disablesfeatures.*/
drivers/pci/controller/vmd.c static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) · line 914
Quoted 1 line
drivers/pci/controller/vmd.c +1
-0+if (!offset[0 ] || !offset[1 ])Drop period in subject line.
Quoted 5 lines
Replace period in comment with space.
Kind of a weird way to check for VM. I see it's already done this way earlier in the function, but maybe it's time to add a descriptive boolean based on offset[0] and offset[1].
Thanks for the response, I will add a boolean implementation.
Quoted 10 lines
Quoted 10 lines
+ vmd_copy_host_bridge_flags(pci_find_host_bridge(vmd->dev->bus), +
to_pci_host_bridge(vmd->bus->bridge));drivers/pci/controller/vmd.c +0
-0vmd_attach_resources (vmd);if (vmd->irq_domain)Signature · 1 line
2.43.0
Manivannan Sadhasivam
maintainerQuoted 28 lines · Bjorn Helgaas
Quoted 17 lines · Nirmal Patel
From: Nirmal Patel <[email protected]>
Copy valid
_OSCflags from root bridge only when OS can provide correct values. In virtual machine, all of the control features are disabled as hypervisor will not passthrough root bridge information to VM.Signed-off-by Nirmal Patel <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- drivers/pci/controller/vmd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/pci/controller/vmd.c +0
-0drivers/pci/controller/vmd.c static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) · line 914
Quoted 7 lines
drivers/pci/controller/vmd.c +2
-2@@ -910,8 +910,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)return -ENODEV ; } -vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus), -to_pci_host_bridge (vmd->bus->bridge)); +/* Don't copy _OSC control flags in VM, it disables features.*/ +if (!offset[0 ] || !offset[1 ])Drop period in subject line.
Quoted 3 lines
Replace period in comment with space.
Kind of a weird way to check for VM.
It is indeed very weird. I see a few x86 driver using
'if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR))' check to test whether the driver is running inside a VM or not. Can this driver use a similar check?
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்