diff options
author | Stefano Stabellini <stefano.stabellini@eu.citrix.com> | 2010-05-14 07:44:30 -0400 |
---|---|---|
committer | Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com> | 2010-07-27 02:13:25 -0400 |
commit | c1c5413ad58cb73267d328e6020268aa2e50d8ca (patch) | |
tree | f2c66141ab8d9fdb7b16a13d4d510ad09b2430ed | |
parent | 409771d258e9dd71c30f3c9520fd2b796ffc40f0 (diff) |
x86: Unplug emulated disks and nics.
Add a xen_emul_unplug command line option to the kernel to unplug
xen emulated disks and nics.
Set the default value of xen_emul_unplug depending on whether or
not the Xen PV frontends and the Xen platform PCI driver have
been compiled for this kernel (modules or built-in are both OK).
The user can specify xen_emul_unplug=ignore to enable PV drivers on HVM
even if the host platform doesn't support unplug.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
-rw-r--r-- | Documentation/kernel-parameters.txt | 11 | ||||
-rw-r--r-- | arch/x86/xen/Makefile | 2 | ||||
-rw-r--r-- | arch/x86/xen/enlighten.c | 1 | ||||
-rw-r--r-- | arch/x86/xen/platform-pci-unplug.c | 135 | ||||
-rw-r--r-- | arch/x86/xen/xen-ops.h | 1 | ||||
-rw-r--r-- | drivers/block/xen-blkfront.c | 17 | ||||
-rw-r--r-- | drivers/xen/platform-pci.c | 6 | ||||
-rw-r--r-- | drivers/xen/xenbus/xenbus_probe.c | 4 | ||||
-rw-r--r-- | include/xen/platform_pci.h | 49 |
9 files changed, 225 insertions, 1 deletions
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 82d6aeb5228f..eefcd805102e 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt | |||
@@ -115,6 +115,7 @@ parameter is applicable: | |||
115 | More X86-64 boot options can be found in | 115 | More X86-64 boot options can be found in |
116 | Documentation/x86/x86_64/boot-options.txt . | 116 | Documentation/x86/x86_64/boot-options.txt . |
117 | X86 Either 32bit or 64bit x86 (same as X86-32+X86-64) | 117 | X86 Either 32bit or 64bit x86 (same as X86-32+X86-64) |
118 | XEN Xen support is enabled | ||
118 | 119 | ||
119 | In addition, the following text indicates that the option: | 120 | In addition, the following text indicates that the option: |
120 | 121 | ||
@@ -2879,6 +2880,16 @@ and is between 256 and 4096 characters. It is defined in the file | |||
2879 | xd= [HW,XT] Original XT pre-IDE (RLL encoded) disks. | 2880 | xd= [HW,XT] Original XT pre-IDE (RLL encoded) disks. |
2880 | xd_geo= See header of drivers/block/xd.c. | 2881 | xd_geo= See header of drivers/block/xd.c. |
2881 | 2882 | ||
2883 | xen_emul_unplug= [HW,X86,XEN] | ||
2884 | Unplug Xen emulated devices | ||
2885 | Format: [unplug0,][unplug1] | ||
2886 | ide-disks -- unplug primary master IDE devices | ||
2887 | aux-ide-disks -- unplug non-primary-master IDE devices | ||
2888 | nics -- unplug network devices | ||
2889 | all -- unplug all emulated devices (NICs and IDE disks) | ||
2890 | ignore -- continue loading the Xen platform PCI driver even | ||
2891 | if the version check failed | ||
2892 | |||
2882 | xirc2ps_cs= [NET,PCMCIA] | 2893 | xirc2ps_cs= [NET,PCMCIA] |
2883 | Format: | 2894 | Format: |
2884 | <irq>,<irq_mask>,<io>,<full_duplex>,<do_sound>,<lockup_hack>[,<irq2>[,<irq3>[,<irq4>]]] | 2895 | <irq>,<irq_mask>,<io>,<full_duplex>,<do_sound>,<lockup_hack>[,<irq2>[,<irq3>[,<irq4>]]] |
diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile index 3bb4fc21f4f2..930954685980 100644 --- a/arch/x86/xen/Makefile +++ b/arch/x86/xen/Makefile | |||
@@ -12,7 +12,7 @@ CFLAGS_mmu.o := $(nostackp) | |||
12 | 12 | ||
13 | obj-y := enlighten.o setup.o multicalls.o mmu.o irq.o \ | 13 | obj-y := enlighten.o setup.o multicalls.o mmu.o irq.o \ |
14 | time.o xen-asm.o xen-asm_$(BITS).o \ | 14 | time.o xen-asm.o xen-asm_$(BITS).o \ |
15 | grant-table.o suspend.o | 15 | grant-table.o suspend.o platform-pci-unplug.o |
16 | 16 | ||
17 | obj-$(CONFIG_SMP) += smp.o | 17 | obj-$(CONFIG_SMP) += smp.o |
18 | obj-$(CONFIG_PARAVIRT_SPINLOCKS)+= spinlock.o | 18 | obj-$(CONFIG_PARAVIRT_SPINLOCKS)+= spinlock.o |
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index a90172963884..157c93b62dd4 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c | |||
@@ -1314,6 +1314,7 @@ static void __init xen_hvm_guest_init(void) | |||
1314 | if (xen_feature(XENFEAT_hvm_callback_vector)) | 1314 | if (xen_feature(XENFEAT_hvm_callback_vector)) |
1315 | xen_have_vector_callback = 1; | 1315 | xen_have_vector_callback = 1; |
1316 | register_cpu_notifier(&xen_hvm_cpu_notifier); | 1316 | register_cpu_notifier(&xen_hvm_cpu_notifier); |
1317 | xen_unplug_emulated_devices(); | ||
1317 | have_vcpu_info_placement = 0; | 1318 | have_vcpu_info_placement = 0; |
1318 | x86_init.irqs.intr_init = xen_init_IRQ; | 1319 | x86_init.irqs.intr_init = xen_init_IRQ; |
1319 | xen_hvm_init_time_ops(); | 1320 | xen_hvm_init_time_ops(); |
diff --git a/arch/x86/xen/platform-pci-unplug.c b/arch/x86/xen/platform-pci-unplug.c new file mode 100644 index 000000000000..2f7f3fb34777 --- /dev/null +++ b/arch/x86/xen/platform-pci-unplug.c | |||
@@ -0,0 +1,135 @@ | |||
1 | /****************************************************************************** | ||
2 | * platform-pci-unplug.c | ||
3 | * | ||
4 | * Xen platform PCI device driver | ||
5 | * Copyright (c) 2010, Citrix | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms and conditions of the GNU General Public License, | ||
9 | * version 2, as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
14 | * more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along with | ||
17 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
18 | * Place - Suite 330, Boston, MA 02111-1307 USA. | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include <linux/init.h> | ||
23 | #include <linux/io.h> | ||
24 | #include <linux/module.h> | ||
25 | |||
26 | #include <xen/platform_pci.h> | ||
27 | |||
28 | #define XEN_PLATFORM_ERR_MAGIC -1 | ||
29 | #define XEN_PLATFORM_ERR_PROTOCOL -2 | ||
30 | #define XEN_PLATFORM_ERR_BLACKLIST -3 | ||
31 | |||
32 | /* store the value of xen_emul_unplug after the unplug is done */ | ||
33 | int xen_platform_pci_unplug; | ||
34 | EXPORT_SYMBOL_GPL(xen_platform_pci_unplug); | ||
35 | static int xen_emul_unplug; | ||
36 | |||
37 | static int __init check_platform_magic(void) | ||
38 | { | ||
39 | short magic; | ||
40 | char protocol; | ||
41 | |||
42 | magic = inw(XEN_IOPORT_MAGIC); | ||
43 | if (magic != XEN_IOPORT_MAGIC_VAL) { | ||
44 | printk(KERN_ERR "Xen Platform PCI: unrecognised magic value\n"); | ||
45 | return XEN_PLATFORM_ERR_MAGIC; | ||
46 | } | ||
47 | |||
48 | protocol = inb(XEN_IOPORT_PROTOVER); | ||
49 | |||
50 | printk(KERN_DEBUG "Xen Platform PCI: I/O protocol version %d\n", | ||
51 | protocol); | ||
52 | |||
53 | switch (protocol) { | ||
54 | case 1: | ||
55 | outw(XEN_IOPORT_LINUX_PRODNUM, XEN_IOPORT_PRODNUM); | ||
56 | outl(XEN_IOPORT_LINUX_DRVVER, XEN_IOPORT_DRVVER); | ||
57 | if (inw(XEN_IOPORT_MAGIC) != XEN_IOPORT_MAGIC_VAL) { | ||
58 | printk(KERN_ERR "Xen Platform: blacklisted by host\n"); | ||
59 | return XEN_PLATFORM_ERR_BLACKLIST; | ||
60 | } | ||
61 | break; | ||
62 | default: | ||
63 | printk(KERN_WARNING "Xen Platform PCI: unknown I/O protocol version"); | ||
64 | return XEN_PLATFORM_ERR_PROTOCOL; | ||
65 | } | ||
66 | |||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | void __init xen_unplug_emulated_devices(void) | ||
71 | { | ||
72 | int r; | ||
73 | |||
74 | /* check the version of the xen platform PCI device */ | ||
75 | r = check_platform_magic(); | ||
76 | /* If the version matches enable the Xen platform PCI driver. | ||
77 | * Also enable the Xen platform PCI driver if the version is really old | ||
78 | * and the user told us to ignore it. */ | ||
79 | if (r && !(r == XEN_PLATFORM_ERR_MAGIC && | ||
80 | (xen_emul_unplug & XEN_UNPLUG_IGNORE))) | ||
81 | return; | ||
82 | /* Set the default value of xen_emul_unplug depending on whether or | ||
83 | * not the Xen PV frontends and the Xen platform PCI driver have | ||
84 | * been compiled for this kernel (modules or built-in are both OK). */ | ||
85 | if (!xen_emul_unplug) { | ||
86 | if (xen_must_unplug_nics()) { | ||
87 | printk(KERN_INFO "Netfront and the Xen platform PCI driver have " | ||
88 | "been compiled for this kernel: unplug emulated NICs.\n"); | ||
89 | xen_emul_unplug |= XEN_UNPLUG_ALL_NICS; | ||
90 | } | ||
91 | if (xen_must_unplug_disks()) { | ||
92 | printk(KERN_INFO "Blkfront and the Xen platform PCI driver have " | ||
93 | "been compiled for this kernel: unplug emulated disks.\n" | ||
94 | "You might have to change the root device\n" | ||
95 | "from /dev/hd[a-d] to /dev/xvd[a-d]\n" | ||
96 | "in your root= kernel command line option\n"); | ||
97 | xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS; | ||
98 | } | ||
99 | } | ||
100 | /* Now unplug the emulated devices */ | ||
101 | if (!(xen_emul_unplug & XEN_UNPLUG_IGNORE)) | ||
102 | outw(xen_emul_unplug, XEN_IOPORT_UNPLUG); | ||
103 | xen_platform_pci_unplug = xen_emul_unplug; | ||
104 | } | ||
105 | |||
106 | static int __init parse_xen_emul_unplug(char *arg) | ||
107 | { | ||
108 | char *p, *q; | ||
109 | int l; | ||
110 | |||
111 | for (p = arg; p; p = q) { | ||
112 | q = strchr(p, ','); | ||
113 | if (q) { | ||
114 | l = q - p; | ||
115 | q++; | ||
116 | } else { | ||
117 | l = strlen(p); | ||
118 | } | ||
119 | if (!strncmp(p, "all", l)) | ||
120 | xen_emul_unplug |= XEN_UNPLUG_ALL; | ||
121 | else if (!strncmp(p, "ide-disks", l)) | ||
122 | xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS; | ||
123 | else if (!strncmp(p, "aux-ide-disks", l)) | ||
124 | xen_emul_unplug |= XEN_UNPLUG_AUX_IDE_DISKS; | ||
125 | else if (!strncmp(p, "nics", l)) | ||
126 | xen_emul_unplug |= XEN_UNPLUG_ALL_NICS; | ||
127 | else if (!strncmp(p, "ignore", l)) | ||
128 | xen_emul_unplug |= XEN_UNPLUG_IGNORE; | ||
129 | else | ||
130 | printk(KERN_WARNING "unrecognised option '%s' " | ||
131 | "in parameter 'xen_emul_unplug'\n", p); | ||
132 | } | ||
133 | return 0; | ||
134 | } | ||
135 | early_param("xen_emul_unplug", parse_xen_emul_unplug); | ||
diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h index 089d18923d2b..ed776949024c 100644 --- a/arch/x86/xen/xen-ops.h +++ b/arch/x86/xen/xen-ops.h | |||
@@ -40,6 +40,7 @@ void xen_vcpu_restore(void); | |||
40 | 40 | ||
41 | void xen_callback_vector(void); | 41 | void xen_callback_vector(void); |
42 | void xen_hvm_init_shared_info(void); | 42 | void xen_hvm_init_shared_info(void); |
43 | void __init xen_unplug_emulated_devices(void); | ||
43 | 44 | ||
44 | void __init xen_build_dynamic_phys_to_machine(void); | 45 | void __init xen_build_dynamic_phys_to_machine(void); |
45 | 46 | ||
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 82ed403147c0..6eb2989a9d0a 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c | |||
@@ -48,6 +48,7 @@ | |||
48 | #include <xen/grant_table.h> | 48 | #include <xen/grant_table.h> |
49 | #include <xen/events.h> | 49 | #include <xen/events.h> |
50 | #include <xen/page.h> | 50 | #include <xen/page.h> |
51 | #include <xen/platform_pci.h> | ||
51 | 52 | ||
52 | #include <xen/interface/grant_table.h> | 53 | #include <xen/interface/grant_table.h> |
53 | #include <xen/interface/io/blkif.h> | 54 | #include <xen/interface/io/blkif.h> |
@@ -737,6 +738,22 @@ static int blkfront_probe(struct xenbus_device *dev, | |||
737 | } | 738 | } |
738 | } | 739 | } |
739 | 740 | ||
741 | /* no unplug has been done: do not hook devices != xen vbds */ | ||
742 | if (xen_hvm_domain() && (xen_platform_pci_unplug & XEN_UNPLUG_IGNORE)) { | ||
743 | int major; | ||
744 | |||
745 | if (!VDEV_IS_EXTENDED(vdevice)) | ||
746 | major = BLKIF_MAJOR(vdevice); | ||
747 | else | ||
748 | major = XENVBD_MAJOR; | ||
749 | |||
750 | if (major != XENVBD_MAJOR) { | ||
751 | printk(KERN_INFO | ||
752 | "%s: HVM does not support vbd %d as xen block device\n", | ||
753 | __FUNCTION__, vdevice); | ||
754 | return -ENODEV; | ||
755 | } | ||
756 | } | ||
740 | info = kzalloc(sizeof(*info), GFP_KERNEL); | 757 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
741 | if (!info) { | 758 | if (!info) { |
742 | xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure"); | 759 | xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure"); |
diff --git a/drivers/xen/platform-pci.c b/drivers/xen/platform-pci.c index bdb44f2473e8..c01b5ddce529 100644 --- a/drivers/xen/platform-pci.c +++ b/drivers/xen/platform-pci.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/module.h> | 27 | #include <linux/module.h> |
28 | #include <linux/pci.h> | 28 | #include <linux/pci.h> |
29 | 29 | ||
30 | #include <xen/platform_pci.h> | ||
30 | #include <xen/grant_table.h> | 31 | #include <xen/grant_table.h> |
31 | #include <xen/xenbus.h> | 32 | #include <xen/xenbus.h> |
32 | #include <xen/events.h> | 33 | #include <xen/events.h> |
@@ -195,6 +196,11 @@ static struct pci_driver platform_driver = { | |||
195 | 196 | ||
196 | static int __init platform_pci_module_init(void) | 197 | static int __init platform_pci_module_init(void) |
197 | { | 198 | { |
199 | /* no unplug has been done, IGNORE hasn't been specified: just | ||
200 | * return now */ | ||
201 | if (!xen_platform_pci_unplug) | ||
202 | return -ENODEV; | ||
203 | |||
198 | return pci_register_driver(&platform_driver); | 204 | return pci_register_driver(&platform_driver); |
199 | } | 205 | } |
200 | 206 | ||
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c index a9e83c438cbb..37e8894b50d6 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c | |||
@@ -56,6 +56,7 @@ | |||
56 | #include <xen/events.h> | 56 | #include <xen/events.h> |
57 | #include <xen/page.h> | 57 | #include <xen/page.h> |
58 | 58 | ||
59 | #include <xen/platform_pci.h> | ||
59 | #include <xen/hvm.h> | 60 | #include <xen/hvm.h> |
60 | 61 | ||
61 | #include "xenbus_comms.h" | 62 | #include "xenbus_comms.h" |
@@ -977,6 +978,9 @@ static void wait_for_devices(struct xenbus_driver *xendrv) | |||
977 | #ifndef MODULE | 978 | #ifndef MODULE |
978 | static int __init boot_wait_for_devices(void) | 979 | static int __init boot_wait_for_devices(void) |
979 | { | 980 | { |
981 | if (xen_hvm_domain() && !xen_platform_pci_unplug) | ||
982 | return -ENODEV; | ||
983 | |||
980 | ready_to_wait_for_devices = 1; | 984 | ready_to_wait_for_devices = 1; |
981 | wait_for_devices(NULL); | 985 | wait_for_devices(NULL); |
982 | return 0; | 986 | return 0; |
diff --git a/include/xen/platform_pci.h b/include/xen/platform_pci.h new file mode 100644 index 000000000000..ce9d671c636c --- /dev/null +++ b/include/xen/platform_pci.h | |||
@@ -0,0 +1,49 @@ | |||
1 | #ifndef _XEN_PLATFORM_PCI_H | ||
2 | #define _XEN_PLATFORM_PCI_H | ||
3 | |||
4 | #define XEN_IOPORT_MAGIC_VAL 0x49d2 | ||
5 | #define XEN_IOPORT_LINUX_PRODNUM 0x0003 | ||
6 | #define XEN_IOPORT_LINUX_DRVVER 0x0001 | ||
7 | |||
8 | #define XEN_IOPORT_BASE 0x10 | ||
9 | |||
10 | #define XEN_IOPORT_PLATFLAGS (XEN_IOPORT_BASE + 0) /* 1 byte access (R/W) */ | ||
11 | #define XEN_IOPORT_MAGIC (XEN_IOPORT_BASE + 0) /* 2 byte access (R) */ | ||
12 | #define XEN_IOPORT_UNPLUG (XEN_IOPORT_BASE + 0) /* 2 byte access (W) */ | ||
13 | #define XEN_IOPORT_DRVVER (XEN_IOPORT_BASE + 0) /* 4 byte access (W) */ | ||
14 | |||
15 | #define XEN_IOPORT_SYSLOG (XEN_IOPORT_BASE + 2) /* 1 byte access (W) */ | ||
16 | #define XEN_IOPORT_PROTOVER (XEN_IOPORT_BASE + 2) /* 1 byte access (R) */ | ||
17 | #define XEN_IOPORT_PRODNUM (XEN_IOPORT_BASE + 2) /* 2 byte access (W) */ | ||
18 | |||
19 | #define XEN_UNPLUG_ALL_IDE_DISKS 1 | ||
20 | #define XEN_UNPLUG_ALL_NICS 2 | ||
21 | #define XEN_UNPLUG_AUX_IDE_DISKS 4 | ||
22 | #define XEN_UNPLUG_ALL 7 | ||
23 | #define XEN_UNPLUG_IGNORE 8 | ||
24 | |||
25 | static inline int xen_must_unplug_nics(void) { | ||
26 | #if (defined(CONFIG_XEN_NETDEV_FRONTEND) || \ | ||
27 | defined(CONFIG_XEN_NETDEV_FRONTEND_MODULE)) && \ | ||
28 | (defined(CONFIG_XEN_PLATFORM_PCI) || \ | ||
29 | defined(CONFIG_XEN_PLATFORM_PCI_MODULE)) | ||
30 | return 1; | ||
31 | #else | ||
32 | return 0; | ||
33 | #endif | ||
34 | } | ||
35 | |||
36 | static inline int xen_must_unplug_disks(void) { | ||
37 | #if (defined(CONFIG_XEN_BLKDEV_FRONTEND) || \ | ||
38 | defined(CONFIG_XEN_BLKDEV_FRONTEND_MODULE)) && \ | ||
39 | (defined(CONFIG_XEN_PLATFORM_PCI) || \ | ||
40 | defined(CONFIG_XEN_PLATFORM_PCI_MODULE)) | ||
41 | return 1; | ||
42 | #else | ||
43 | return 0; | ||
44 | #endif | ||
45 | } | ||
46 | |||
47 | extern int xen_platform_pci_unplug; | ||
48 | |||
49 | #endif /* _XEN_PLATFORM_PCI_H */ | ||