Skip to contentSkip to conversation

userspace: fix module load errors with kernel 2.6.27 and DMAR enabled

PATCH In review Joerg Roedel 1 participant 3 messages Dec 15, 2008 – Jan 21, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 userspace: fix module load errors with kernel 2.6.27 and DMAR enabled

---
 configure                           |    7 +++++++
 kernel/x86/Kbuild                   |    2 ++
 kernel/x86/external-module-compat.h |    8 ++++++++
 kernel/x86/hack-module.awk          |    2 ++
 4 files changed, 19 insertions(+), 0 deletions(-)
configure +7 -0
index 4e88961..f7c0534 100755
@@ -15,6 +15,7 @@ qemu_opts=()
 cross_prefix=
 arch=`uname -m`
 target_exec=
+kvm_vtd_iommu="n"
 # don't use uname if kerneldir is set
 no_uname=
 depmod_version=
@@ -111,6 +112,11 @@ case $arch in
         ;;
 esac
 
+# test for IOMMU support in the kernel we build for
+if [ -f "$kernelsourcedir/virt/kvm/vtd.c" ]; then
+	kvm_vtd_iommu="y"
+fi
+
 processor=${arch#*-}
 arch=${arch%%-*}
 
@@ -170,4 +176,5 @@ EOF
 
 cat <<EOF > kernel/config.kbuild
 EXT_CONFIG_KVM_TRACE=$kvm_trace
+KVM_USE_VTD_IOMMU=$kvm_vtd_iommu
 EOF
kernel/x86/Kbuild +2 -0
index c4723b1..faee1e7 100644
@@ -10,8 +10,10 @@ ifeq ($(EXT_CONFIG_KVM_TRACE),y)
 kvm-objs += kvm_trace.o
 endif
 ifeq ($(CONFIG_DMAR),y)
+ifeq ($(KVM_USE_VTD_IOMMU),y)
 kvm-objs += vtd.o
 endif
+endif
 kvm-intel-objs := vmx.o vmx-debug.o ../external-module-compat.o
 kvm-amd-objs := svm.o ../external-module-compat.o
 
kernel/x86/external-module-compat.h +8 -0
index b5e11e2..ac78b81 100644
@@ -335,6 +335,14 @@ struct kvm_desc_ptr {
 #define FEATURE_CONTROL_VMXON_ENABLED	(1<<2)
 #endif
 
+#if defined(CONFIG_DMAR) || defined(CONFIG_IOMMU_API)
+#define KVM_IOMMU_SUPPORT 1
+#endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
+#undef KVM_IOMMU_SUPPORT
+#endif
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
 
 struct mtrr_var_range {
kernel/x86/hack-module.awk +2 -0
index 2ad0951..8d2806f 100644
@@ -75,6 +75,8 @@ BEGIN { split("INIT_WORK tsc_khz desc_struct ldttss_desc64 desc_ptr " \
 
 /\kvm_.*_fops\.owner = module;/ { $0 = "IF_ANON_INODES_DOES_REFCOUNTS(" $0 ")" }
 
+{sub(/CONFIG_DMAR/, "KVM_IOMMU_SUPPORT");}
+
 { print }
 
 /kvm_x86_ops->run/ {
Signature · 1 line
1.5.6.4
#1 lore raw

PATCH 2/2 userspace: enable build with IOMMU_API enabled

---
 kernel/x86/Kbuild |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
kernel/x86/Kbuild +3 -1
index faee1e7..c0776f5 100644
@@ -9,7 +9,9 @@ kvm-objs := kvm_main.o x86.o mmu.o x86_emulate.o ../anon_inodes.o irq.o i8259.o
 ifeq ($(EXT_CONFIG_KVM_TRACE),y)
 kvm-objs += kvm_trace.o
 endif
-ifeq ($(CONFIG_DMAR),y)
+ifeq ($(CONFIG_IOMMU_API),y)
+kvm-objs += iommu.o
+else ifeq ($(CONFIG_DMAR),y)
 ifeq ($(KVM_USE_VTD_IOMMU),y)
 kvm-objs += vtd.o
 endif
Signature · 1 line
1.5.6.4
#2 lore raw
In reply to Joerg Roedel

Hi Avi,

what about these patches?

Quoted 88 lines · Joerg Roedel
---
 configure                           |    7 +++++++
 kernel/x86/Kbuild                   |    2 ++
 kernel/x86/external-module-compat.h |    8 ++++++++
 kernel/x86/hack-module.awk          |    2 ++
 4 files changed, 19 insertions(+), 0 deletions(-)
configure +7 -0
index 4e88961..f7c0534 100755
@@ -15,6 +15,7 @@ qemu_opts=()
 cross_prefix=
 arch=`uname -m`
 target_exec=
+kvm_vtd_iommu="n"
 # don't use uname if kerneldir is set
 no_uname=
 depmod_version=
@@ -111,6 +112,11 @@ case $arch in
         ;;
 esac
 
+# test for IOMMU support in the kernel we build for
+if [ -f "$kernelsourcedir/virt/kvm/vtd.c" ]; then
+	kvm_vtd_iommu="y"
+fi
+
 processor=${arch#*-}
 arch=${arch%%-*}
 
@@ -170,4 +176,5 @@ EOF
 
 cat <<EOF > kernel/config.kbuild
 EXT_CONFIG_KVM_TRACE=$kvm_trace
+KVM_USE_VTD_IOMMU=$kvm_vtd_iommu
 EOF
kernel/x86/Kbuild +2 -0
index c4723b1..faee1e7 100644
@@ -10,8 +10,10 @@ ifeq ($(EXT_CONFIG_KVM_TRACE),y)
 kvm-objs += kvm_trace.o
 endif
 ifeq ($(CONFIG_DMAR),y)
+ifeq ($(KVM_USE_VTD_IOMMU),y)
 kvm-objs += vtd.o
 endif
+endif
 kvm-intel-objs := vmx.o vmx-debug.o ../external-module-compat.o
 kvm-amd-objs := svm.o ../external-module-compat.o
 
kernel/x86/external-module-compat.h +8 -0
index b5e11e2..ac78b81 100644
@@ -335,6 +335,14 @@ struct kvm_desc_ptr {
 #define FEATURE_CONTROL_VMXON_ENABLED	(1<<2)
 #endif
 
+#if defined(CONFIG_DMAR) || defined(CONFIG_IOMMU_API)
+#define KVM_IOMMU_SUPPORT 1
+#endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
+#undef KVM_IOMMU_SUPPORT
+#endif
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
 
 struct mtrr_var_range {
kernel/x86/hack-module.awk +2 -0
index 2ad0951..8d2806f 100644
@@ -75,6 +75,8 @@ BEGIN { split("INIT_WORK tsc_khz desc_struct ldttss_desc64 desc_ptr " \
 
 /\kvm_.*_fops\.owner = module;/ { $0 = "IF_ANON_INODES_DOES_REFCOUNTS(" $0 ")" }
 
+{sub(/CONFIG_DMAR/, "KVM_IOMMU_SUPPORT");}
+
 { print }
 
 /kvm_x86_ops->run/ {
Signature · 1 line
1.5.6.4
Signature · 6 lines
           | Advanced Micro Devices GmbH
 Operating | Karl-Hammerschmidt-Str. 34, 85609 Dornach bei München
 System    | 
 Research  | Geschäftsführer: Jochen Polster, Thomas M. McCoy, Giuliano Meroni
 Center    | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
           | Registergericht München, HRB Nr. 43632