From f8f1bb83f78e8a2b7f4f10432882c39bbd7952fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Fri, 21 Aug 2015 15:53:08 +0000 Subject: [PATCH] xen: allow disabling PV disks and nics Introduce two new loader tunnables that can be used to disable PV disks and PV nics at boot time. They default to 0 and should be set to 1 (or any number different than 0) in order to disable the PV devices: hw.xen.disable_pv_disks=1 hw.xen.disable_pv_nics=1 In /boot/loader.conf will disable both PV disks and nics. Sponsored by: Citrix Systems R&D Tested by: Karl Pielorz MFC after: 1 week --- sys/dev/xen/blkfront/blkfront.c | 3 +++ sys/dev/xen/netfront/netfront.c | 3 +++ sys/x86/xen/hvm.c | 28 ++++++++++++++++++++++++---- sys/xen/xen-os.h | 3 +++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/sys/dev/xen/blkfront/blkfront.c b/sys/dev/xen/blkfront/blkfront.c index 5ff9d38a68dc..1416c28192ee 100644 --- a/sys/dev/xen/blkfront/blkfront.c +++ b/sys/dev/xen/blkfront/blkfront.c @@ -1366,6 +1366,9 @@ xbd_probe(device_t dev) if (strcmp(xenbus_get_type(dev), "vbd") != 0) return (ENXIO); + if (xen_hvm_domain() && xen_disable_pv_disks != 0) + return (ENXIO); + if (xen_hvm_domain()) { int error; char *type; diff --git a/sys/dev/xen/netfront/netfront.c b/sys/dev/xen/netfront/netfront.c index 302c0179e80c..703b44fedbb7 100644 --- a/sys/dev/xen/netfront/netfront.c +++ b/sys/dev/xen/netfront/netfront.c @@ -445,6 +445,9 @@ static int netfront_probe(device_t dev) { + if (xen_hvm_domain() && xen_disable_pv_nics != 0) + return (ENXIO); + if (!strcmp(xenbus_get_type(dev), "vif")) { device_set_desc(dev, "Virtual Network Interface"); return (0); diff --git a/sys/x86/xen/hvm.c b/sys/x86/xen/hvm.c index 9ad196a83f4f..c969e262b956 100644 --- a/sys/x86/xen/hvm.c +++ b/sys/x86/xen/hvm.c @@ -100,8 +100,15 @@ DPCPU_DEFINE(struct vcpu_info *, vcpu_info); shared_info_t *HYPERVISOR_shared_info; start_info_t *HYPERVISOR_start_info; + +/*------------------------------ Sysctl tunables -----------------------------*/ +int xen_disable_pv_disks = 0; +int xen_disable_pv_nics = 0; +TUNABLE_INT("hw.xen.disable_pv_disks", &xen_disable_pv_disks); +TUNABLE_INT("hw.xen.disable_pv_nics", &xen_disable_pv_nics); + #ifdef SMP -/* XEN diverged cpu operations */ +/*---------------------- XEN diverged cpu operations -------------------------*/ static void xen_hvm_cpu_resume(void) { @@ -256,21 +263,34 @@ enum { static void xen_hvm_disable_emulated_devices(void) { + u_short disable_devs = 0; if (xen_pv_domain()) { /* * No emulated devices in the PV case, so no need to unplug * anything. */ + if (xen_disable_pv_disks != 0 || xen_disable_pv_nics != 0) + printf("PV devices cannot be disabled in PV guests\n"); return; } if (inw(XEN_MAGIC_IOPORT) != XMI_MAGIC) return; - if (bootverbose) - printf("XEN: Disabling emulated block and network devices\n"); - outw(XEN_MAGIC_IOPORT, XMI_UNPLUG_IDE_DISKS|XMI_UNPLUG_NICS); + if (xen_disable_pv_disks == 0) { + if (bootverbose) + printf("XEN: disabling emulated disks\n"); + disable_devs |= XMI_UNPLUG_IDE_DISKS; + } + if (xen_disable_pv_nics == 0) { + if (bootverbose) + printf("XEN: disabling emulated nics\n"); + disable_devs |= XMI_UNPLUG_NICS; + } + + if (disable_devs != 0) + outw(XEN_MAGIC_IOPORT, disable_devs); } static void diff --git a/sys/xen/xen-os.h b/sys/xen/xen-os.h index 7ceef4f1c5ae..ab594d437058 100644 --- a/sys/xen/xen-os.h +++ b/sys/xen/xen-os.h @@ -56,6 +56,9 @@ extern start_info_t *HYPERVISOR_start_info; /* XXX: we need to get rid of this and use HYPERVISOR_start_info directly */ extern char *console_page; +extern int xen_disable_pv_disks; +extern int xen_disable_pv_nics; + enum xen_domain_type { XEN_NATIVE, /* running on bare hardware */ XEN_PV_DOMAIN, /* running in a PV domain */