Skip to contentSkip to conversation

paravirt: helper to disable all IO space

PATCH In review Jeremy Fitzhardinge 1 participant 2 messages Jun 6, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 paravirt: helper to disable all IO space

In a virtual environment, device drivers such as legacy IDE will waste quite a lot of time probing for their devices which will never appear. This helper function allows a paravirt implementation to lay claim to the whole iomem and ioport space, thereby disabling all device drivers trying to claim IO resources.

arch/i386/kernel/paravirt.c +33 -0
diff -r 83c67f9402b5 arch/i386/kernel/paravirt.c
@@ -227,6 +227,39 @@ static int __init print_banner(void)
 	return 0;
 }
 core_initcall(print_banner);
+
+static struct resource reserve_ioports = {
+	.start = 0,
+	.end = IO_SPACE_LIMIT,
+	.name = "paravirt-ioport",
+	.flags = IORESOURCE_IO | IORESOURCE_BUSY,
+};
+
+static struct resource reserve_iomem = {
+	.start = 0,
+	.end = -1,
+	.name = "paravirt-iomem",
+	.flags = IORESOURCE_MEM | IORESOURCE_BUSY,
+};
+
+/*
+ * Reserve the whole legacy IO space to prevent any legacy drivers
+ * from wasting time probing for their hardware.  This is a fairly
+ * brute-force approach to disabling all non-virtual drivers.
+ * 
+ * Note that this must be called very early to have any effect.
+ */
+int paravirt_disable_iospace(void)
+{
+	int ret = 0;
+
+	ret = request_resource(&ioport_resource, &reserve_ioports);
+	if (ret == 0)
+		ret = request_resource(&iomem_resource, &reserve_iomem);
+
+	return ret;
+}
+
 
 struct paravirt_ops paravirt_ops = {
 	.name = "bare hardware",
arch/i386/xen/setup.c +2 -0
diff -r 83c67f9402b5 arch/i386/xen/setup.c
@@ -8,12 +8,14 @@
 #include <linux/mm.h>
 #include <linux/sched.h>
 #include <linux/pm.h>
+#include <linux/ioport.h>
 
 #include <asm/elf.h>
 #include <asm/e820.h>
 #include <asm/setup.h>
 #include <asm/xen/hypervisor.h>
 #include <asm/xen/hypercall.h>
+#include <asm/io.h>
 
 #include <xen/interface/physdev.h>
 #include <xen/features.h>
include/asm-i386/paravirt.h +1 -0
diff -r 83c67f9402b5 include/asm-i386/paravirt.h
@@ -262,6 +262,7 @@ unsigned paravirt_patch_insns(void *site
 unsigned paravirt_patch_insns(void *site, unsigned len,
 			      const char *start, const char *end);
 
+int paravirt_disable_iospace(void);
 
 /*
  * This generates an indirect call based on the operation type number.
#1 lore raw

arch/i386/xen/setup.c

Quoted 56 lines · Jeremy Fitzhardinge

In a virtual environment, device drivers such as legacy IDE will waste quite a lot of time probing for their devices which will never appear. This helper function allows a paravirt implementation to lay claim to the whole iomem and ioport space, thereby disabling all device drivers trying to claim IO resources.

diff -r 83c67f9402b5 arch/i386/kernel/paravirt.c

arch/i386/kernel/paravirt.c +33 -0
@@ -227,6 +227,39 @@ static int __init print_banner(void)
 	return 0;
 }
 core_initcall(print_banner);
+
+static struct resource reserve_ioports = {
+	.start = 0,
+	.end = IO_SPACE_LIMIT,
+	.name = "paravirt-ioport",
+	.flags = IORESOURCE_IO | IORESOURCE_BUSY,
+};
+
+static struct resource reserve_iomem = {
+	.start = 0,
+	.end = -1,
+	.name = "paravirt-iomem",
+	.flags = IORESOURCE_MEM | IORESOURCE_BUSY,
+};
+
+/*
+ * Reserve the whole legacy IO space to prevent any legacy drivers
+ * from wasting time probing for their hardware.  This is a fairly
+ * brute-force approach to disabling all non-virtual drivers.
+ * 
+ * Note that this must be called very early to have any effect.
+ */
+int paravirt_disable_iospace(void)
+{
+	int ret = 0;
+
+	ret = request_resource(&ioport_resource, &reserve_ioports);
+	if (ret == 0)
+		ret = request_resource(&iomem_resource, &reserve_iomem);
+
+	return ret;
+}
+
 
 struct paravirt_ops paravirt_ops = {
 	.name = "bare hardware",

diff -r 83c67f9402b5 arch/i386/xen/setup.c

arch/i386/xen/setup.c +0 -0

Oops. This was supposed to be in the corresponding Xen patch.

J