Re: [PATCH V3 4/5] iommu/hyperv: Only call pviommu init on non-root VMs

From
sashiko-bot@kernel.org
Date
2026-11-03 02:57:53
Reply to
Mukesh R, 2026-11-03
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] iommu/hyperv: always-false NULL check on iommu_init in hyperv_init()
--

commit 4f2b2cb5f11d745054ce781b3dfdb1a7f85d3560
Author: Mukesh R [off-list ref]

iommu/hyperv: Only call pviommu init on non-root VMs

This commit renames hv_iommu_init() to hv_pviommu_init() and updates
hyperv_init() so that x86_init.iommu.iommu_init is only assigned on non-root
Hyper-V VMs when x86_init.iommu.iommu_init is not already set.
quoted hunk ↗ jump to hunk
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index b90e6f4875335..18651c38dba3e 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -580,7 +580,8 @@ void __init hyperv_init(void)
 	x86_init.timers.setup_percpu_clockev = hv_stimer_setup_percpu_clockev;
 
 #ifdef CONFIG_HYPERV_PVIOMMU
-	x86_init.iommu.iommu_init = hv_iommu_init;
+	if (!hv_root_partition() && x86_init.iommu.iommu_init == NULL)
+		x86_init.iommu.iommu_init = hv_pviommu_init;
[Severity: High]
Can x86_init.iommu.iommu_init == NULL ever evaluate to true here?

In arch/x86/kernel/x86_init.c, x86_init.iommu.iommu_init is statically
initialized to iommu_init_noop rather than NULL:

    static int __init iommu_init_noop(void) { return 0; }
    ...
    struct x86_init_ops x86_init __initdata = {
        ...
        .iommu = {
            .iommu_init		= iommu_init_noop,
        },
        ...
    };

And in arch/x86/kernel/pci-dma.c, pci_iommu_init() invokes
x86_init.iommu.iommu_init() unconditionally without a NULL check.

Because x86_init.iommu.iommu_init defaults to iommu_init_noop (or is
overwritten by an earlier hardware IOMMU detector in pci_iommu_alloc()) and
is never set to NULL, doesn't checking x86_init.iommu.iommu_init == NULL in
hyperv_init() prevent hv_pviommu_init from ever being registered on non-root
guest VMs?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261103025150.3192119-1-mrathor@linux.microsoft.com?part=4
Thread (9 messages) 9 messages, 3 authors, last reply 13d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help