From 091febc04a5d5065fe633fe29c11f008dc392ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Fri, 17 Jun 2022 15:29:05 +0200 Subject: [PATCH] xen/blkback: do not use x86 CPUID in generic code Move checker for whether Xen creates IOMMU mappings for foreign pages into a helper that's defined in arch-specific code. Reported by: Elliott Mitchell Fixes: 1d528f95e8ce ('xen/blkback: remove bounce buffering mode') Sponsored by: Citrix Systems R&D --- sys/dev/xen/blkback/blkback.c | 7 +------ sys/x86/include/xen/xen-os.h | 2 ++ sys/x86/xen/hvm.c | 11 +++++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/sys/dev/xen/blkback/blkback.c b/sys/dev/xen/blkback/blkback.c index b15dbb1e9155..bd550695e719 100644 --- a/sys/dev/xen/blkback/blkback.c +++ b/sys/dev/xen/blkback/blkback.c @@ -80,7 +80,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include #include @@ -3318,16 +3317,12 @@ xbb_attach_failed(struct xbb_softc *xbb, int err, const char *fmt, ...) static int xbb_probe(device_t dev) { - uint32_t regs[4]; if (strcmp(xenbus_get_type(dev), "vbd")) return (ENXIO); - KASSERT(xen_cpuid_base != 0, ("Invalid base Xen CPUID leaf")); - cpuid_count(xen_cpuid_base + 4, 0, regs); - /* Only attach if Xen creates IOMMU entries for grant mapped pages. */ - if (!(regs[0] & XEN_HVM_CPUID_IOMMU_MAPPINGS)) { + if (!xen_has_iommu_maps()) { static bool warned; if (!warned) { diff --git a/sys/x86/include/xen/xen-os.h b/sys/x86/include/xen/xen-os.h index 4d4aa64955ba..861ad10e3d78 100644 --- a/sys/x86/include/xen/xen-os.h +++ b/sys/x86/include/xen/xen-os.h @@ -72,6 +72,8 @@ xen_pv_nics_disabled(void) return (xen_hvm_domain() && xen_disable_pv_nics != 0); } +bool xen_has_iommu_maps(void); + #endif /* !__ASSEMBLY__ */ #endif /* _MACHINE_X86_XEN_XEN_OS_H_ */ diff --git a/sys/x86/xen/hvm.c b/sys/x86/xen/hvm.c index 544b6e6439e8..8d25e35e5151 100644 --- a/sys/x86/xen/hvm.c +++ b/sys/x86/xen/hvm.c @@ -489,3 +489,14 @@ xen_hvm_cpu_init(void) DPCPU_SET(vcpu_info, vcpu_info); } SYSINIT(xen_hvm_cpu_init, SI_SUB_INTR, SI_ORDER_FIRST, xen_hvm_cpu_init, NULL); + +bool +xen_has_iommu_maps(void) +{ + uint32_t regs[4]; + + KASSERT(xen_cpuid_base != 0, ("Invalid base Xen CPUID leaf")); + cpuid_count(xen_cpuid_base + 4, 0, regs); + + return (regs[0] & XEN_HVM_CPUID_IOMMU_MAPPINGS); +}