aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2013-11-26 15:05:40 -0500
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2014-01-03 14:54:18 -0500
commit51c71a3bbaca868043cc45b3ad3786dd48a90235 (patch)
tree65cef69a3d3434393f1c063b8cf138d9a06e3154
parent802eee95bde72fd0cd0f3a5b2098375a487d1eda (diff)
xen/pvhvm: If xen_platform_pci=0 is set don't blow up (v4).
The user has the option of disabling the platform driver: 00:02.0 Unassigned class [ff80]: XenSource, Inc. Xen Platform Device (rev 01) which is used to unplug the emulated drivers (IDE, Realtek 8169, etc) and allow the PV drivers to take over. If the user wishes to disable that they can set: xen_platform_pci=0 (in the guest config file) or xen_emul_unplug=never (on the Linux command line) except it does not work properly. The PV drivers still try to load and since the Xen platform driver is not run - and it has not initialized the grant tables, most of the PV drivers stumble upon: input: Xen Virtual Keyboard as /devices/virtual/input/input5 input: Xen Virtual Pointer as /devices/virtual/input/input6M ------------[ cut here ]------------ kernel BUG at /home/konrad/ssd/konrad/linux/drivers/xen/grant-table.c:1206! invalid opcode: 0000 [#1] SMP Modules linked in: xen_kbdfront(+) xenfs xen_privcmd CPU: 6 PID: 1389 Comm: modprobe Not tainted 3.13.0-rc1upstream-00021-ga6c892b-dirty #1 Hardware name: Xen HVM domU, BIOS 4.4-unstable 11/26/2013 RIP: 0010:[<ffffffff813ddc40>] [<ffffffff813ddc40>] get_free_entries+0x2e0/0x300 Call Trace: [<ffffffff8150d9a3>] ? evdev_connect+0x1e3/0x240 [<ffffffff813ddd0e>] gnttab_grant_foreign_access+0x2e/0x70 [<ffffffffa0010081>] xenkbd_connect_backend+0x41/0x290 [xen_kbdfront] [<ffffffffa0010a12>] xenkbd_probe+0x2f2/0x324 [xen_kbdfront] [<ffffffff813e5757>] xenbus_dev_probe+0x77/0x130 [<ffffffff813e7217>] xenbus_frontend_dev_probe+0x47/0x50 [<ffffffff8145e9a9>] driver_probe_device+0x89/0x230 [<ffffffff8145ebeb>] __driver_attach+0x9b/0xa0 [<ffffffff8145eb50>] ? driver_probe_device+0x230/0x230 [<ffffffff8145eb50>] ? driver_probe_device+0x230/0x230 [<ffffffff8145cf1c>] bus_for_each_dev+0x8c/0xb0 [<ffffffff8145e7d9>] driver_attach+0x19/0x20 [<ffffffff8145e260>] bus_add_driver+0x1a0/0x220 [<ffffffff8145f1ff>] driver_register+0x5f/0xf0 [<ffffffff813e55c5>] xenbus_register_driver_common+0x15/0x20 [<ffffffff813e76b3>] xenbus_register_frontend+0x23/0x40 [<ffffffffa0015000>] ? 0xffffffffa0014fff [<ffffffffa001502b>] xenkbd_init+0x2b/0x1000 [xen_kbdfront] [<ffffffff81002049>] do_one_initcall+0x49/0x170 .. snip.. which is hardly nice. This patch fixes this by having each PV driver check for: - if running in PV, then it is fine to execute (as that is their native environment). - if running in HVM, check if user wanted 'xen_emul_unplug=never', in which case bail out and don't load any PV drivers. - if running in HVM, and if PCI device 5853:0001 (xen_platform_pci) does not exist, then bail out and not load PV drivers. - (v2) if running in HVM, and if the user wanted 'xen_emul_unplug=ide-disks', then bail out for all PV devices _except_ the block one. Ditto for the network one ('nics'). - (v2) if running in HVM, and if the user wanted 'xen_emul_unplug=unnecessary' then load block PV driver, and also setup the legacy IDE paths. In (v3) make it actually load PV drivers. Reported-by: Sander Eikelenboom <linux@eikelenboom.it Reported-by: Anthony PERARD <anthony.perard@citrix.com> Reported-and-Tested-by: Fabio Fantoni <fabio.fantoni@m2r.biz> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> [v2: Add extra logic to handle the myrid ways 'xen_emul_unplug' can be used per Ian and Stefano suggestion] [v3: Make the unnecessary case work properly] [v4: s/disks/ide-disks/ spotted by Fabio] Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Acked-by: Bjorn Helgaas <bhelgaas@google.com> [for PCI parts] CC: stable@vger.kernel.org
-rw-r--r--arch/x86/xen/platform-pci-unplug.c74
-rw-r--r--drivers/block/xen-blkfront.c4
-rw-r--r--drivers/char/tpm/xen-tpmfront.c4
-rw-r--r--drivers/input/misc/xen-kbdfront.c4
-rw-r--r--drivers/net/xen-netfront.c2
-rw-r--r--drivers/pci/xen-pcifront.c4
-rw-r--r--drivers/video/xen-fbfront.c4
-rw-r--r--drivers/xen/xenbus/xenbus_probe_frontend.c2
-rw-r--r--include/xen/platform_pci.h23
9 files changed, 117 insertions, 4 deletions
diff --git a/arch/x86/xen/platform-pci-unplug.c b/arch/x86/xen/platform-pci-unplug.c
index 0a7852483ffe..ab84ac198a9a 100644
--- a/arch/x86/xen/platform-pci-unplug.c
+++ b/arch/x86/xen/platform-pci-unplug.c
@@ -69,6 +69,80 @@ static int check_platform_magic(void)
69 return 0; 69 return 0;
70} 70}
71 71
72bool xen_has_pv_devices()
73{
74 if (!xen_domain())
75 return false;
76
77 /* PV domains always have them. */
78 if (xen_pv_domain())
79 return true;
80
81 /* And user has xen_platform_pci=0 set in guest config as
82 * driver did not modify the value. */
83 if (xen_platform_pci_unplug == 0)
84 return false;
85
86 if (xen_platform_pci_unplug & XEN_UNPLUG_NEVER)
87 return false;
88
89 if (xen_platform_pci_unplug & XEN_UNPLUG_ALL)
90 return true;
91
92 /* This is an odd one - we are going to run legacy
93 * and PV drivers at the same time. */
94 if (xen_platform_pci_unplug & XEN_UNPLUG_UNNECESSARY)
95 return true;
96
97 /* And the caller has to follow with xen_pv_{disk,nic}_devices
98 * to be certain which driver can load. */
99 return false;
100}
101EXPORT_SYMBOL_GPL(xen_has_pv_devices);
102
103static bool __xen_has_pv_device(int state)
104{
105 /* HVM domains might or might not */
106 if (xen_hvm_domain() && (xen_platform_pci_unplug & state))
107 return true;
108
109 return xen_has_pv_devices();
110}
111
112bool xen_has_pv_nic_devices(void)
113{
114 return __xen_has_pv_device(XEN_UNPLUG_ALL_NICS | XEN_UNPLUG_ALL);
115}
116EXPORT_SYMBOL_GPL(xen_has_pv_nic_devices);
117
118bool xen_has_pv_disk_devices(void)
119{
120 return __xen_has_pv_device(XEN_UNPLUG_ALL_IDE_DISKS |
121 XEN_UNPLUG_AUX_IDE_DISKS | XEN_UNPLUG_ALL);
122}
123EXPORT_SYMBOL_GPL(xen_has_pv_disk_devices);
124
125/*
126 * This one is odd - it determines whether you want to run PV _and_
127 * legacy (IDE) drivers together. This combination is only possible
128 * under HVM.
129 */
130bool xen_has_pv_and_legacy_disk_devices(void)
131{
132 if (!xen_domain())
133 return false;
134
135 /* N.B. This is only ever used in HVM mode */
136 if (xen_pv_domain())
137 return false;
138
139 if (xen_platform_pci_unplug & XEN_UNPLUG_UNNECESSARY)
140 return true;
141
142 return false;
143}
144EXPORT_SYMBOL_GPL(xen_has_pv_and_legacy_disk_devices);
145
72void xen_unplug_emulated_devices(void) 146void xen_unplug_emulated_devices(void)
73{ 147{
74 int r; 148 int r;
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index c4a4c9006288..f9c43f91f03e 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -1356,7 +1356,7 @@ static int blkfront_probe(struct xenbus_device *dev,
1356 char *type; 1356 char *type;
1357 int len; 1357 int len;
1358 /* no unplug has been done: do not hook devices != xen vbds */ 1358 /* no unplug has been done: do not hook devices != xen vbds */
1359 if (xen_platform_pci_unplug & XEN_UNPLUG_UNNECESSARY) { 1359 if (xen_has_pv_and_legacy_disk_devices()) {
1360 int major; 1360 int major;
1361 1361
1362 if (!VDEV_IS_EXTENDED(vdevice)) 1362 if (!VDEV_IS_EXTENDED(vdevice))
@@ -2079,7 +2079,7 @@ static int __init xlblk_init(void)
2079 if (!xen_domain()) 2079 if (!xen_domain())
2080 return -ENODEV; 2080 return -ENODEV;
2081 2081
2082 if (xen_hvm_domain() && !xen_platform_pci_unplug) 2082 if (!xen_has_pv_disk_devices())
2083 return -ENODEV; 2083 return -ENODEV;
2084 2084
2085 if (register_blkdev(XENVBD_MAJOR, DEV_NAME)) { 2085 if (register_blkdev(XENVBD_MAJOR, DEV_NAME)) {
diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c
index c8ff4df81779..62e7d383fa64 100644
--- a/drivers/char/tpm/xen-tpmfront.c
+++ b/drivers/char/tpm/xen-tpmfront.c
@@ -17,6 +17,7 @@
17#include <xen/xenbus.h> 17#include <xen/xenbus.h>
18#include <xen/page.h> 18#include <xen/page.h>
19#include "tpm.h" 19#include "tpm.h"
20#include <xen/platform_pci.h>
20 21
21struct tpm_private { 22struct tpm_private {
22 struct tpm_chip *chip; 23 struct tpm_chip *chip;
@@ -421,6 +422,9 @@ static int __init xen_tpmfront_init(void)
421 if (!xen_domain()) 422 if (!xen_domain())
422 return -ENODEV; 423 return -ENODEV;
423 424
425 if (!xen_has_pv_devices())
426 return -ENODEV;
427
424 return xenbus_register_frontend(&tpmfront_driver); 428 return xenbus_register_frontend(&tpmfront_driver);
425} 429}
426module_init(xen_tpmfront_init); 430module_init(xen_tpmfront_init);
diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
index e21c1816a8f9..fbfdc10573be 100644
--- a/drivers/input/misc/xen-kbdfront.c
+++ b/drivers/input/misc/xen-kbdfront.c
@@ -29,6 +29,7 @@
29#include <xen/interface/io/fbif.h> 29#include <xen/interface/io/fbif.h>
30#include <xen/interface/io/kbdif.h> 30#include <xen/interface/io/kbdif.h>
31#include <xen/xenbus.h> 31#include <xen/xenbus.h>
32#include <xen/platform_pci.h>
32 33
33struct xenkbd_info { 34struct xenkbd_info {
34 struct input_dev *kbd; 35 struct input_dev *kbd;
@@ -380,6 +381,9 @@ static int __init xenkbd_init(void)
380 if (xen_initial_domain()) 381 if (xen_initial_domain())
381 return -ENODEV; 382 return -ENODEV;
382 383
384 if (!xen_has_pv_devices())
385 return -ENODEV;
386
383 return xenbus_register_frontend(&xenkbd_driver); 387 return xenbus_register_frontend(&xenkbd_driver);
384} 388}
385 389
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index e59acb1daa23..2ab82fe75ede 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -2115,7 +2115,7 @@ static int __init netif_init(void)
2115 if (!xen_domain()) 2115 if (!xen_domain())
2116 return -ENODEV; 2116 return -ENODEV;
2117 2117
2118 if (xen_hvm_domain() && !xen_platform_pci_unplug) 2118 if (!xen_has_pv_nic_devices())
2119 return -ENODEV; 2119 return -ENODEV;
2120 2120
2121 pr_info("Initialising Xen virtual ethernet driver\n"); 2121 pr_info("Initialising Xen virtual ethernet driver\n");
diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index f7197a790341..eae7cd9fde7b 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -20,6 +20,7 @@
20#include <linux/workqueue.h> 20#include <linux/workqueue.h>
21#include <linux/bitops.h> 21#include <linux/bitops.h>
22#include <linux/time.h> 22#include <linux/time.h>
23#include <xen/platform_pci.h>
23 24
24#include <asm/xen/swiotlb-xen.h> 25#include <asm/xen/swiotlb-xen.h>
25#define INVALID_GRANT_REF (0) 26#define INVALID_GRANT_REF (0)
@@ -1138,6 +1139,9 @@ static int __init pcifront_init(void)
1138 if (!xen_pv_domain() || xen_initial_domain()) 1139 if (!xen_pv_domain() || xen_initial_domain())
1139 return -ENODEV; 1140 return -ENODEV;
1140 1141
1142 if (!xen_has_pv_devices())
1143 return -ENODEV;
1144
1141 pci_frontend_registrar(1 /* enable */); 1145 pci_frontend_registrar(1 /* enable */);
1142 1146
1143 return xenbus_register_frontend(&xenpci_driver); 1147 return xenbus_register_frontend(&xenpci_driver);
diff --git a/drivers/video/xen-fbfront.c b/drivers/video/xen-fbfront.c
index cd005c227a23..4b2d3ab870f3 100644
--- a/drivers/video/xen-fbfront.c
+++ b/drivers/video/xen-fbfront.c
@@ -35,6 +35,7 @@
35#include <xen/interface/io/fbif.h> 35#include <xen/interface/io/fbif.h>
36#include <xen/interface/io/protocols.h> 36#include <xen/interface/io/protocols.h>
37#include <xen/xenbus.h> 37#include <xen/xenbus.h>
38#include <xen/platform_pci.h>
38 39
39struct xenfb_info { 40struct xenfb_info {
40 unsigned char *fb; 41 unsigned char *fb;
@@ -699,6 +700,9 @@ static int __init xenfb_init(void)
699 if (xen_initial_domain()) 700 if (xen_initial_domain())
700 return -ENODEV; 701 return -ENODEV;
701 702
703 if (!xen_has_pv_devices())
704 return -ENODEV;
705
702 return xenbus_register_frontend(&xenfb_driver); 706 return xenbus_register_frontend(&xenfb_driver);
703} 707}
704 708
diff --git a/drivers/xen/xenbus/xenbus_probe_frontend.c b/drivers/xen/xenbus/xenbus_probe_frontend.c
index 129bf84c19ec..cb385c10d2b1 100644
--- a/drivers/xen/xenbus/xenbus_probe_frontend.c
+++ b/drivers/xen/xenbus/xenbus_probe_frontend.c
@@ -496,7 +496,7 @@ subsys_initcall(xenbus_probe_frontend_init);
496#ifndef MODULE 496#ifndef MODULE
497static int __init boot_wait_for_devices(void) 497static int __init boot_wait_for_devices(void)
498{ 498{
499 if (xen_hvm_domain() && !xen_platform_pci_unplug) 499 if (!xen_has_pv_devices())
500 return -ENODEV; 500 return -ENODEV;
501 501
502 ready_to_wait_for_devices = 1; 502 ready_to_wait_for_devices = 1;
diff --git a/include/xen/platform_pci.h b/include/xen/platform_pci.h
index 438c256c274b..b49eeab0262e 100644
--- a/include/xen/platform_pci.h
+++ b/include/xen/platform_pci.h
@@ -48,4 +48,27 @@ static inline int xen_must_unplug_disks(void) {
48 48
49extern int xen_platform_pci_unplug; 49extern int xen_platform_pci_unplug;
50 50
51#if defined(CONFIG_XEN_PVHVM)
52extern bool xen_has_pv_devices(void);
53extern bool xen_has_pv_disk_devices(void);
54extern bool xen_has_pv_nic_devices(void);
55extern bool xen_has_pv_and_legacy_disk_devices(void);
56#else
57static inline bool xen_has_pv_devices(void)
58{
59 return IS_ENABLED(CONFIG_XEN);
60}
61static inline bool xen_has_pv_disk_devices(void)
62{
63 return IS_ENABLED(CONFIG_XEN);
64}
65static inline bool xen_has_pv_nic_devices(void)
66{
67 return IS_ENABLED(CONFIG_XEN);
68}
69static inline bool xen_has_pv_and_legacy_disk_devices(void)
70{
71 return false;
72}
73#endif
51#endif /* _XEN_PLATFORM_PCI_H */ 74#endif /* _XEN_PLATFORM_PCI_H */