KEXEC: disconnect all PCI devices from the PCI bus on crash
PATCH 1/1 KEXEC: disconnect all PCI devices from the PCI bus on crash
In the case of a crash, IOMMU DMA remapping gets turned off so that the kdump kernel may boot. However, this is warned as being dangerous in the VTD specification if a DMA transaction is in progress.
Also, in the case of a crash, DMA transactions and interrupts from peripheral devices such as network cards are likely to keep coming in. Without DMA remapping enabled, the transactions will be writing over low memory, corrupting the crash state, and perhaps even the kdump reserved memory.
Therefore, on the crash path, we can disconnect all PCI devices from their respective buses so that they are no longer able to be DMA busmasters. This reduces the risk of DMA transactions corrupting state (and will also reduce spurious interrupts arriving to the kdump kernel) until the kdump kernel and properly reset the PCI devices.
xen/arch/x86/crash.c +3 -0
@@ -28,6 +28,7 @@#include <asm/apic.h> #include <asm/io_apic.h> #include <xen/iommu.h> +#include <xen/pci.h> static atomic_t waiting_for_crash_ipi;static unsigned int crashing_cpu;
@@ -78,6 +79,8 @@ static void nmi_shootdown_cpus(void) msecs--; } +disconnect_pci_devices (); +/* Crash shutdown any IOMMU functionality as the crashdump kernel is not * happy when booting if interrupt/dma remapping is still enabled */ iommu_crash_shutdown ();
xen/drivers/passthrough/pci.c +26 -0
@@ -462,6 +462,32 @@ int __init scan_pci_devices(void)return 0 ; } +/* Disconnect a PCI device from the PCI bus. From the PCI spec: +* "When a 0 is written to [the COMMAND] register, the device is +* logically disconnected from the PCI bus for all accesses except +* configuration accesses. All devices are required to support +* this base level of functionality." +*/ +void disconnect_pci_device (struct pci_dev *pdev) +{ +pci_conf_write16 (pdev->bus,PCI_SLOT (pdev->devfn), +PCI_FUNC (pdev->devfn),PCI_COMMAND ,0 ); +} + +/* Diconnect all PCI devices from the PCI buses. +*/ +void disconnect_pci_devices (void ) +{ +struct pci_dev *pdev; + +spin_lock (&pcidevs_lock); + + list_for_each_entry ( pdev, &alldevs_list, alldevs_list ) +disconnect_pci_device (pdev); + +spin_unlock (&pcidevs_lock); +} +#ifdef SUPPORT_MSI_REMAPPING static void dump_pci_devices (unsigned char ch) {
xen/include/xen/pci.h +3 -0
@@ -92,6 +92,9 @@ int pci_add_device_ext(u8 bus, u8 devfn,struct pci_dev *pci_get_pdev (int bus,int devfn);struct pci_dev *pci_get_pdev_by_domain (struct domain *d,int bus,int devfn); +void disconnect_pci_device (struct pci_dev * pdev); +void disconnect_pci_devices (void ); +uint8_t pci_conf_read8 (unsigned int bus,unsigned int dev,unsigned int func,unsigned int reg); uint16_t pci_conf_read16(
Quoted 44 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
In the case of a crash, IOMMU DMA remapping gets turned off so that the kdump kernel may boot. However, this is warned as being dangerous in the VTD specification if a DMA transaction is in progress.
Also, in the case of a crash, DMA transactions and interrupts from peripheral devices such as network cards are likely to keep coming in. Without DMA remapping enabled, the transactions will be writing over low memory, corrupting the crash state, and perhaps even the kdump reserved memory.
Therefore, on the crash path, we can disconnect all PCI devices from their respective buses so that they are no longer able to be DMA busmasters. This reduces the risk of DMA transactions corrupting state (and will also reduce spurious interrupts arriving to the kdump kernel) until the kdump kernel and properly reset the PCI devices.
Signed-off-by Andrew Cooper <[email protected]>diff -r
2f63562df1c4-r7ea606c5ce8cxen/arch/x86/crash.cxen/arch/x86/crash.c +3
-0@@ -28,6 +28,7 @@#include <asm/apic.h> #include <asm/io_apic.h> #include <xen/iommu.h> +#include <xen/pci.h> static atomic_t waiting_for_crash_ipi;static unsigned int crashing_cpu;@@ -78,6 +79,8 @@ static void nmi_shootdown_cpus(void) msecs--; } +disconnect_pci_devices (); +/* Crash shutdown any IOMMU functionality as the crashdump kernel is not
* happy when booting if interrupt/dma remapping is still enabled */
iommu_crash_shutdown();
diff -r2f63562df1c4-r7ea606c5ce8cxen/drivers/passthrough/pci.c
xen/drivers/passthrough/pci.c int __init scan_pci_devices(void) · line 471
Quoted 10 lines
xen/drivers/passthrough/pci.c +7
-0@@ -462,6 +462,32 @@ int __init scan_pci_devices(void)return 0 ; } +/* Disconnect a PCI device from the PCI bus. From the PCI spec: +* "When a 0 is written to [the COMMAND] register, the device is +* logically disconnected from the PCI bus for all accesses except +* configuration accesses. All devices are required to support +* this base level of functionality." +*/ +void disconnect_pci_device (struct pci_dev *pdev)
Any reason this cannot be static? Or even be integrated into the single caller?
Jan
Quoted 42 lines
xen/drivers/passthrough/pci.c +19
-0+{ +pci_conf_write16 (pdev->bus,PCI_SLOT (pdev->devfn), +PCI_FUNC (pdev->devfn),PCI_COMMAND ,0 ); +} + +/* Diconnect all PCI devices from the PCI buses. +*/ +void disconnect_pci_devices (void ) +{ +struct pci_dev *pdev; + +spin_lock (&pcidevs_lock); + + list_for_each_entry ( pdev, &alldevs_list, alldevs_list ) +disconnect_pci_device (pdev); + +spin_unlock (&pcidevs_lock); +} +#ifdef SUPPORT_MSI_REMAPPING static void dump_pci_devices (unsigned char ch) {diff -r
2f63562df1c4-r7ea606c5ce8cxen/include/xen/pci.hxen/include/xen/pci.h +3
-0@@ -92,6 +92,9 @@ int pci_add_device_ext(u8 bus, u8 devfn,struct pci_dev *pci_get_pdev (int bus,int devfn);struct pci_dev *pci_get_pdev_by_domain (struct domain *d,int bus,int devfn); +void disconnect_pci_device (struct pci_dev * pdev); +void disconnect_pci_devices (void ); +uint8_t pci_conf_read8 ( unsigned int bus, unsigned int dev, unsigned int func, unsigned intreg);
uint16_tpci_conf_read16(_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 57 lines · Jan Beulich
Quoted 44 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
In the case of a crash, IOMMU DMA remapping gets turned off so that the kdump kernel may boot. However, this is warned as being dangerous in the VTD specification if a DMA transaction is in progress.
Also, in the case of a crash, DMA transactions and interrupts from peripheral devices such as network cards are likely to keep coming in. Without DMA remapping enabled, the transactions will be writing over low memory, corrupting the crash state, and perhaps even the kdump reserved memory.
Therefore, on the crash path, we can disconnect all PCI devices from their respective buses so that they are no longer able to be DMA busmasters. This reduces the risk of DMA transactions corrupting state (and will also reduce spurious interrupts arriving to the kdump kernel) until the kdump kernel and properly reset the PCI devices.
Signed-off-by Andrew Cooper <[email protected]>diff -r
2f63562df1c4-r7ea606c5ce8cxen/arch/x86/crash.cxen/arch/x86/crash.c +3
-0@@ -28,6 +28,7 @@#include <asm/apic.h> #include <asm/io_apic.h> #include <xen/iommu.h> +#include <xen/pci.h> static atomic_t waiting_for_crash_ipi;static unsigned int crashing_cpu;@@ -78,6 +79,8 @@ static void nmi_shootdown_cpus(void) msecs--; } +disconnect_pci_devices (); +/* Crash shutdown any IOMMU functionality as the crashdump kernel is not
* happy when booting if interrupt/dma remapping is still enabled */
iommu_crash_shutdown();
diff -r2f63562df1c4-r7ea606c5ce8cxen/drivers/passthrough/pci.cxen/drivers/passthrough/pci.c int __init scan_pci_devices(void) · line 471
Quoted 10 lines
xen/drivers/passthrough/pci.c +7
-0@@ -462,6 +462,32 @@ int __init scan_pci_devices(void)return 0 ; } +/* Disconnect a PCI device from the PCI bus. From the PCI spec: +* "When a 0 is written to [the COMMAND] register, the device is +* logically disconnected from the PCI bus for all accesses except +* configuration accesses. All devices are required to support +* this base level of functionality." +*/ +void disconnect_pci_device (struct pci_dev *pdev)Any reason this cannot be static? Or even be integrated into the single caller?
Quoted 1 line
Jan
Not specifically - I can fold them together if you think that would be better
~Andrew
Quoted 44 lines
Quoted 42 lines
xen/drivers/passthrough/pci.c +19
-0+{ +pci_conf_write16 (pdev->bus,PCI_SLOT (pdev->devfn), +PCI_FUNC (pdev->devfn),PCI_COMMAND ,0 ); +} + +/* Diconnect all PCI devices from the PCI buses. +*/ +void disconnect_pci_devices (void ) +{ +struct pci_dev *pdev; + +spin_lock (&pcidevs_lock); + + list_for_each_entry ( pdev, &alldevs_list, alldevs_list ) +disconnect_pci_device (pdev); + +spin_unlock (&pcidevs_lock); +} +#ifdef SUPPORT_MSI_REMAPPING static void dump_pci_devices (unsigned char ch) {diff -r
2f63562df1c4-r7ea606c5ce8cxen/include/xen/pci.hxen/include/xen/pci.h +3
-0@@ -92,6 +92,9 @@ int pci_add_device_ext(u8 bus, u8 devfn,struct pci_dev *pci_get_pdev (int bus,int devfn);struct pci_dev *pci_get_pdev_by_domain (struct domain *d,int bus,int devfn); +void disconnect_pci_device (struct pci_dev * pdev); +void disconnect_pci_devices (void ); +uint8_t pci_conf_read8 ( unsigned int bus, unsigned int dev, unsigned int func, unsigned intreg);
uint16_tpci_conf_read16(_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Signature · 2 lines
Andrew Cooper - Dom0 Kernel Engineer, Citrix XenServer T: +44 (0)1223 225 900, http://www.citrix.com
Quoted 45 lines · Andrew Cooper
In the case of a crash, IOMMU DMA remapping gets turned off so that the kdump kernel may boot. However, this is warned as being dangerous in the VTD specification if a DMA transaction is in progress.
Also, in the case of a crash, DMA transactions and interrupts from peripheral devices such as network cards are likely to keep coming in. Without DMA remapping enabled, the transactions will be writing over low memory, corrupting the crash state, and perhaps even the kdump reserved memory.
Therefore, on the crash path, we can disconnect all PCI devices from their respective buses so that they are no longer able to be DMA busmasters. This reduces the risk of DMA transactions corrupting state (and will also reduce spurious interrupts arriving to the kdump kernel) until the kdump kernel and properly reset the PCI devices.
Signed-off-by Andrew Cooper <[email protected]>diff -r
2f63562df1c4-r7ea606c5ce8cxen/arch/x86/crash.cxen/arch/x86/crash.c +3
-0@@ -28,6 +28,7 @@#include <asm/apic.h> #include <asm/io_apic.h> #include <xen/iommu.h> +#include <xen/pci.h> static atomic_t waiting_for_crash_ipi;static unsigned int crashing_cpu;@@ -78,6 +79,8 @@ static void nmi_shootdown_cpus(void) msecs--; } +disconnect_pci_devices (); +/* Crash shutdown any IOMMU functionality as the crashdump kernel is not * happy when booting if interrupt/dma remapping is still enabled */ iommu_crash_shutdown ();diff -r
2f63562df1c4-r7ea606c5ce8cxen/drivers/passthrough/pci.cxen/drivers/passthrough/pci.c +0
-0@@ -462,6 +462,32 @@ int __init scan_pci_devices(void)return 0 ; }
xen/drivers/passthrough/pci.c int __init scan_pci_devices(void) · line 474
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+/* Disconnect a PCI device from the PCI bus. From the PCI spec: +* "When a 0 is written to [the COMMAND] register, the device is +* logically disconnected from the PCI bus for all accesses except +* configuration accesses. All devices are required to support +* this base level of functionality." +*/ +void disconnect_pci_device (struct pci_dev *pdev) +{ +pci_conf_write16 (pdev->bus,PCI_SLOT (pdev->devfn), +PCI_FUNC (pdev->devfn),PCI_COMMAND ,0 );
So if you have a PCI serial card (or Intel AMT) and you are using that for serial output on the hypervisor line, this will turn it off. There should be some whitelist capability to not do it for PCI serial devices that are owned (used) by the hypervisor.
Quoted 4 lines · Konrad Rzeszutek Wilk
So if you have a PCI serial card (or Intel AMT) and you are using that for serial output on the hypervisor line, this will turn it off. There should be some whitelist capability to not do it for PCI serial devices that are owned (used) by the hypervisor.
Good catch, Konrad. Andrew, I have a box with such a configuration, if you want to test it.
-George
Quoted 46 lines · Konrad Rzeszutek Wilk
Quoted 45 lines · Andrew Cooper
In the case of a crash, IOMMU DMA remapping gets turned off so that the kdump kernel may boot. However, this is warned as being dangerous in the VTD specification if a DMA transaction is in progress.
Also, in the case of a crash, DMA transactions and interrupts from peripheral devices such as network cards are likely to keep coming in. Without DMA remapping enabled, the transactions will be writing over low memory, corrupting the crash state, and perhaps even the kdump reserved memory.
Therefore, on the crash path, we can disconnect all PCI devices from their respective buses so that they are no longer able to be DMA busmasters. This reduces the risk of DMA transactions corrupting state (and will also reduce spurious interrupts arriving to the kdump kernel) until the kdump kernel and properly reset the PCI devices.
Signed-off-by Andrew Cooper <[email protected]>diff -r
2f63562df1c4-r7ea606c5ce8cxen/arch/x86/crash.cxen/arch/x86/crash.c +3
-0@@ -28,6 +28,7 @@#include <asm/apic.h> #include <asm/io_apic.h> #include <xen/iommu.h> +#include <xen/pci.h> static atomic_t waiting_for_crash_ipi;static unsigned int crashing_cpu;@@ -78,6 +79,8 @@ static void nmi_shootdown_cpus(void) msecs--; } +disconnect_pci_devices (); +/* Crash shutdown any IOMMU functionality as the crashdump kernel is not * happy when booting if interrupt/dma remapping is still enabled */ iommu_crash_shutdown ();diff -r
2f63562df1c4-r7ea606c5ce8cxen/drivers/passthrough/pci.cxen/drivers/passthrough/pci.c +0
-0@@ -462,6 +462,32 @@ int __init scan_pci_devices(void)return 0 ; }
Quoted 15 lines
xen/drivers/passthrough/pci.c int __init scan_pci_devices(void) · line 474
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+/* Disconnect a PCI device from the PCI bus. From the PCI spec: +* "When a 0 is written to [the COMMAND] register, the device is +* logically disconnected from the PCI bus for all accesses except +* configuration accesses. All devices are required to support +* this base level of functionality." +*/ +void disconnect_pci_device (struct pci_dev *pdev) +{ +pci_conf_write16 (pdev->bus,PCI_SLOT (pdev->devfn), +PCI_FUNC (pdev->devfn),PCI_COMMAND ,0 );So if you have a PCI serial card (or Intel AMT) and you are using that for serial output on the hypervisor line, this will turn it off. There should be some whitelist capability to not do it for PCI serial devices that are owned (used) by the hypervisor.
That would be useful for debugging the kexec process itself but in the general case there won't be any further output from the hypervisor and if the kexec'd kernel wants to use the device it is going to have to set it up again anyways.
On the other hand if the hypervisor is driving a device it presumably knows (or could know) how to turn of interrupts and switch to polled mode so we might as well do that?
Ian.
Quoted 19 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 16 lines · Konrad Rzeszutek Wilk
xen/drivers/passthrough/pci.c int __init scan_pci_devices(void) · line 474
Quoted 10 lines · Andrew Cooper
xen/drivers/passthrough/pci.c +10
-0+/* Disconnect a PCI device from the PCI bus. From the PCI spec: +* "When a 0 is written to [the COMMAND] register, the device is +* logically disconnected from the PCI bus for all accesses except +* configuration accesses. All devices are required to support +* this base level of functionality." +*/ +void disconnect_pci_device (struct pci_dev *pdev) +{ +pci_conf_write16 (pdev->bus,PCI_SLOT (pdev->devfn), +PCI_FUNC (pdev->devfn),PCI_COMMAND ,0 );So if you have a PCI serial card (or Intel AMT) and you are using that for serial output on the hypervisor line, this will turn it off. There should be some whitelist capability to not do it for PCI serial devices that are owned (used) by the hypervisor.
Quoted 4 lines
That would be useful for debugging the kexec process itself but in the general case there won't be any further output from the hypervisor and if the kexec'd kernel wants to use the device it is going to have to set it up again anyways.
No, not generally. Just look at Linux' early-printk code: The device is assumed to be enabled (by the BIOS), as the PCI subsystem can't possibly be initialized at this point already.
This also means that white-listing just devices Xen uses may not be
enough: If Xen doesn't use a serial console (or the secondary kernel wants to use some other device Xen doesn't care about - VGA or other kind of console devices come to mind), it must not find it fully disconnected from the bus. Consequently I would think that while interrupt and DMA activity should be forced off, decoding I/O and memory addresses by the devices shouldn't be.
Jan
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 16 lines · Konrad Rzeszutek Wilk
xen/drivers/passthrough/pci.c int __init scan_pci_devices(void) · line 474
Quoted 10 lines · Andrew Cooper
xen/drivers/passthrough/pci.c +10
-0+/* Disconnect a PCI device from the PCI bus. From the PCI spec: +* "When a 0 is written to [the COMMAND] register, the device is +* logically disconnected from the PCI bus for all accesses except +* configuration accesses. All devices are required to support +* this base level of functionality." +*/ +void disconnect_pci_device (struct pci_dev *pdev) +{ +pci_conf_write16 (pdev->bus,PCI_SLOT (pdev->devfn), +PCI_FUNC (pdev->devfn),PCI_COMMAND ,0 );So if you have a PCI serial card (or Intel AMT) and you are using that for serial output on the hypervisor line, this will turn it off. There should be some whitelist capability to not do it for PCI serial devices that are owned (used) by the hypervisor.
Quoted 8 lines
Quoted 4 lines
That would be useful for debugging the kexec process itself but in the general case there won't be any further output from the hypervisor and if the kexec'd kernel wants to use the device it is going to have to set it up again anyways.
No, not generally. Just look at Linux' early-printk code: The device is assumed to be enabled (by the BIOS), as the PCI subsystem can't possibly be initialized at this point already.
That's arguably a debugging facility as well though.
Quoted 7 lines
This also means that white-listing just devices Xen uses may not be
enough: If Xen doesn't use a serial console (or the secondary kernel wants to use some other device Xen doesn't care about - VGA or other kind of console devices come to mind), it must not find it fully disconnected from the bus. Consequently I would think that while interrupt and DMA activity should be forced off, decoding I/O and memory addresses by the devices shouldn't be.
The problem is that this can't be done without device specific knowledge, which the hypervisor generally doesn't have and we can't get the device's owning domain to do anything because we are crashing.
Ian.
Quoted 40 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 16 lines · Konrad Rzeszutek Wilk
xen/drivers/passthrough/pci.c int __init scan_pci_devices(void) · line 474
Quoted 10 lines · Andrew Cooper
xen/drivers/passthrough/pci.c +10
-0+/* Disconnect a PCI device from the PCI bus. From the PCI spec: +* "When a 0 is written to [the COMMAND] register, the device is +* logically disconnected from the PCI bus for all accesses except +* configuration accesses. All devices are required to support +* this base level of functionality." +*/ +void disconnect_pci_device (struct pci_dev *pdev) +{ +pci_conf_write16 (pdev->bus,PCI_SLOT (pdev->devfn), +PCI_FUNC (pdev->devfn),PCI_COMMAND ,0 );So if you have a PCI serial card (or Intel AMT) and you are using that for serial output on the hypervisor line, this will turn it off. There should be some whitelist capability to not do it for PCI serial devices that are owned (used) by the hypervisor.
Quoted 8 lines
Quoted 4 lines
That would be useful for debugging the kexec process itself but in the general case there won't be any further output from the hypervisor and if the kexec'd kernel wants to use the device it is going to have to set it up again anyways.
No, not generally. Just look at Linux' early-printk code: The device is assumed to be enabled (by the BIOS), as the PCI subsystem can't possibly be initialized at this point already.
That's arguably a debugging facility as well though.
Quoted 7 lines
This also means that white-listing just devices Xen uses may not be
enough: If Xen doesn't use a serial console (or the secondary kernel wants to use some other device Xen doesn't care about - VGA or other kind of console devices come to mind), it must not find it fully disconnected from the bus. Consequently I would think that while interrupt and DMA activity should be forced off, decoding I/O and memory addresses by the devices shouldn't be.
Quoted 3 lines
The problem is that this can't be done without device specific knowledge, which the hypervisor generally doesn't have and we can't get the device's owning domain to do anything because we are crashing.
Why would there be any device specific knowledge needed? It's all done through the command word, just that writing zero isn't really appropriate.
Jan
Quoted 40 lines · Jan Beulich
Quoted 40 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 16 lines · Konrad Rzeszutek Wilk
xen/drivers/passthrough/pci.c int __init scan_pci_devices(void) · line 474
Quoted 10 lines · Andrew Cooper
xen/drivers/passthrough/pci.c +10
-0+/* Disconnect a PCI device from the PCI bus. From the PCI spec: +* "When a 0 is written to [the COMMAND] register, the device is +* logically disconnected from the PCI bus for all accesses except +* configuration accesses. All devices are required to support +* this base level of functionality." +*/ +void disconnect_pci_device (struct pci_dev *pdev) +{ +pci_conf_write16 (pdev->bus,PCI_SLOT (pdev->devfn), +PCI_FUNC (pdev->devfn),PCI_COMMAND ,0 );So if you have a PCI serial card (or Intel AMT) and you are using that for serial output on the hypervisor line, this will turn it off. There should be some whitelist capability to not do it for PCI serial devices that are owned (used) by the hypervisor.
Quoted 8 lines
Quoted 4 lines
That would be useful for debugging the kexec process itself but in the general case there won't be any further output from the hypervisor and if the kexec'd kernel wants to use the device it is going to have to set it up again anyways.
No, not generally. Just look at Linux' early-printk code: The device is assumed to be enabled (by the BIOS), as the PCI subsystem can't possibly be initialized at this point already.
That's arguably a debugging facility as well though.
Quoted 7 lines
This also means that white-listing just devices Xen uses may not be
enough: If Xen doesn't use a serial console (or the secondary kernel wants to use some other device Xen doesn't care about - VGA or other kind of console devices come to mind), it must not find it fully disconnected from the bus. Consequently I would think that while interrupt and DMA activity should be forced off, decoding I/O and memory addresses by the devices shouldn't be.
Quoted 7 lines
Quoted 3 lines
The problem is that this can't be done without device specific knowledge, which the hypervisor generally doesn't have and we can't get the device's owning domain to do anything because we are crashing.
Why would there be any device specific knowledge needed? It's all done through the command word, just that writing zero isn't really appropriate.
So presumably if you disable bus mastering you've effectively disabled DMA but how do you disable interrupts via the command word?
Ian.
Quoted 39 lines · Ian Campbell
Quoted 38 lines · Jan Beulich
Quoted 38 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 15 lines · Konrad Rzeszutek Wilk
Review
Quoted 10 lines · Andrew Cooper
(quoted diff) +10
-0+/* Disconnect a PCI device from the PCI bus. From the PCI spec: + * "When a 0 is written to [the COMMAND] register, the device is + * logically disconnected from the PCI bus for all accesses except + * configuration accesses. All devices are required to support + * this base level of functionality." + */ +void disconnect_pci_device(struct pci_dev *pdev) +{ + pci_conf_write16(pdev->bus, PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), PCI_COMMAND, 0);So if you have a PCI serial card (or Intel AMT) and you are using that for serial output on the hypervisor line, this will turn it off. There should be some whitelist capability to not do it for PCI serial devices that are owned (used) by the hypervisor.
Quoted 7 lines
Quoted 4 lines
That would be useful for debugging the kexec process itself but in the general case there won't be any further output from the hypervisor and if the kexec'd kernel wants to use the device it is going to have to set it up again anyways.
No, not generally. Just look at Linux' early-printk code: The device is assumed to be enabled (by the BIOS), as the PCI subsystem can't possibly be initialized at this point already.
That's arguably a debugging facility as well though.
Quoted 7 lines
This also means that white-listing just devices Xen uses may not be
enough: If Xen doesn't use a serial console (or the secondary kernel wants to use some other device Xen doesn't care about - VGA or other kind of console devices come to mind), it must not find it fully disconnected from the bus. Consequently I would think that while interrupt and DMA activity should be forced off, decoding I/O and memory addresses by the devices shouldn't be.The problem is that this can't be done without device specific knowledge, which the hypervisor generally doesn't have and we can't get the device's owning domain to do anything because we are crashing.
Quoted 8 lines
Quoted 3 lines
Why would there be any device specific knowledge needed? It's all done through the command word, just that writing zero isn't really appropriate.
So presumably if you disable bus mastering you've effectively disabled DMA but how do you disable interrupts via the command word?
Ian.
Bit 10 of the control word is "disable assertion of INTx# pins" (so set bit to 1 to disable interrupts). That should cover legacy interrupts. For MSI and above, disabling DMA should prevent the bus writing to the magic local APIC addresses.
Signature · 2 lines
Andrew Cooper - Dom0 Kernel Engineer, Citrix XenServer T: +44 (0)1223 225 900, http://www.citrix.com
Quoted 45 lines · Andrew Cooper
Quoted 42 lines · Ian Campbell
Quoted 41 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 15 lines · Konrad Rzeszutek Wilk
Review
Quoted 10 lines · Andrew Cooper
(quoted diff) +10
-0+/* Disconnect a PCI device from the PCI bus. From the PCI spec: + * "When a 0 is written to [the COMMAND] register, the device is + * logically disconnected from the PCI bus for all accesses except + * configuration accesses. All devices are required to support + * this base level of functionality." + */ +void disconnect_pci_device(struct pci_dev *pdev) +{ + pci_conf_write16(pdev->bus, PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), PCI_COMMAND, 0);So if you have a PCI serial card (or Intel AMT) and you are using that for serial output on the hypervisor line, this will turn it off. There should be some whitelist capability to not do it for PCI serial devices that are owned (used) by the hypervisor.
Quoted 7 lines
Quoted 4 lines
That would be useful for debugging the kexec process itself but in the general case there won't be any further output from the hypervisor and if the kexec'd kernel wants to use the device it is going to have to set it up again anyways.
No, not generally. Just look at Linux' early-printk code: The device is assumed to be enabled (by the BIOS), as the PCI subsystem can't possibly be initialized at this point already.
That's arguably a debugging facility as well though.
Quoted 7 lines
This also means that white-listing just devices Xen uses may not be
enough: If Xen doesn't use a serial console (or the secondary kernel wants to use some other device Xen doesn't care about - VGA or other kind of console devices come to mind), it must not find it fully disconnected from the bus. Consequently I would think that while interrupt and DMA activity should be forced off, decoding I/O and memory addresses by the devices shouldn't be.Quoted 3 lines
The problem is that this can't be done without device specific knowledge, which the hypervisor generally doesn't have and we can't get the device's owning domain to do anything because we are crashing.
Why would there be any device specific knowledge needed? It's all done through the command word, just that writing zero isn't really appropriate.
Quoted 7 lines
Quoted 5 lines
So presumably if you disable bus mastering you've effectively disabled DMA but how do you disable interrupts via the command word?
Ian.
Bit 10 of the control word is "disable assertion of INTx# pins" (so set bit to 1 to disable interrupts). That should cover legacy interrupts.
In older specs that's a reserved bit; I suspect on real PCI devices it will have no effect.
Quoted 2 lines
For MSI and above, disabling DMA should prevent the bus writing to the magic local APIC addresses.
Are MSI cycles always the same as DMA cycles? I though that MSI-X changed that (but might be quite wrong).
Tim.
Signature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, Xen Platform Team Citrix Systems UK Ltd. (Company #02937203, SL9 0BG)
Quoted 44 lines · Andrew Cooper
Quoted 42 lines · Ian Campbell
Quoted 41 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 15 lines · Konrad Rzeszutek Wilk
Review
Quoted 10 lines · Andrew Cooper
(quoted diff) +10
-0+/* Disconnect a PCI device from the PCI bus. From the PCI spec: + * "When a 0 is written to [the COMMAND] register, the device is + * logically disconnected from the PCI bus for all accesses except + * configuration accesses. All devices are required to support + * this base level of functionality." + */ +void disconnect_pci_device(struct pci_dev *pdev) +{ + pci_conf_write16(pdev->bus, PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), PCI_COMMAND, 0);So if you have a PCI serial card (or Intel AMT) and you are using that for serial output on the hypervisor line, this will turn it off. There should be some whitelist capability to not do it for PCI serial devices that are owned (used) by the hypervisor.
Quoted 7 lines
Quoted 4 lines
That would be useful for debugging the kexec process itself but in the general case there won't be any further output from the hypervisor and if the kexec'd kernel wants to use the device it is going to have to set it up again anyways.
No, not generally. Just look at Linux' early-printk code: The device is assumed to be enabled (by the BIOS), as the PCI subsystem can't possibly be initialized at this point already.
That's arguably a debugging facility as well though.
Quoted 7 lines
This also means that white-listing just devices Xen uses may not be
enough: If Xen doesn't use a serial console (or the secondary kernel wants to use some other device Xen doesn't care about - VGA or other kind of console devices come to mind), it must not find it fully disconnected from the bus. Consequently I would think that while interrupt and DMA activity should be forced off, decoding I/O and memory addresses by the devices shouldn't be.Quoted 3 lines
The problem is that this can't be done without device specific knowledge, which the hypervisor generally doesn't have and we can't get the device's owning domain to do anything because we are crashing.
Why would there be any device specific knowledge needed? It's all done through the command word, just that writing zero isn't really appropriate.
Quoted 7 lines
Quoted 5 lines
So presumably if you disable bus mastering you've effectively disabled DMA but how do you disable interrupts via the command word?
Ian.
Bit 10 of the control word is "disable assertion of INTx# pins" (so set bit to 1 to disable interrupts).
My copy of the spec isn't new enough to cover that particular bit but the Linux headers describe it as disabling INTx "emulation" so I wasn't sure if it actually did anything in all cases, especially on older hardware.
Quoted 4 lines
That should cover legacy interrupts.
For MSI and above, disabling DMA should prevent the bus writing to the magic local APIC addresses.
Quoted 49 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Quoted 45 lines · Ian Campbell
Quoted 35 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 15 lines · Konrad Rzeszutek Wilk
Review
Quoted 10 lines · Andrew Cooper
(quoted diff) +10
-0+/* Disconnect a PCI device from the PCI bus. From the PCI spec: + * "When a 0 is written to [the COMMAND] register, the device is + * logically disconnected from the PCI bus for all accesses except + * configuration accesses. All devices are required to support + * this base level of functionality." + */ +void disconnect_pci_device(struct pci_dev *pdev) +{ + pci_conf_write16(pdev->bus, PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), PCI_COMMAND, 0);So if you have a PCI serial card (or Intel AMT) and you are using that for serial output on the hypervisor line, this will turn it off. There should be some whitelist capability to not do it for PCI serial devices that are owned (used) by the hypervisor.
Quoted 7 lines
Quoted 4 lines
That would be useful for debugging the kexec process itself but in the general case there won't be any further output from the hypervisor and if the kexec'd kernel wants to use the device it is going to have to set it up again anyways.
No, not generally. Just look at Linux' early-printk code: The device is assumed to be enabled (by the BIOS), as the PCI subsystem can't possibly be initialized at this point already.
That's arguably a debugging facility as well though.
Quoted 7 lines
This also means that white-listing just devices Xen uses may not be
enough: If Xen doesn't use a serial console (or the secondary kernel wants to use some other device Xen doesn't care about - VGA or other kind of console devices come to mind), it must not find it fully disconnected from the bus. Consequently I would think that while interrupt and DMA activity should be forced off, decoding I/O and memory addresses by the devices shouldn't be.Quoted 6 lines
Quoted 3 lines
The problem is that this can't be done without device specific knowledge, which the hypervisor generally doesn't have and we can't get the device's owning domain to do anything because we are crashing.
Why would there be any device specific knowledge needed? It's all done through the command word, just that writing zero isn't really appropriate.
So presumably if you disable bus mastering you've effectively disabled DMA but how do you disable interrupts via the command word?
Quoted 6 lines
Quoted 2 lines
Ian.
Bit 10 of the control word is "disable assertion of INTx# pins" (so set bit to 1 to disable interrupts). That should cover legacy interrupts. For MSI and above, disabling DMA should prevent the bus writing to the magic local APIC addresses.
No, I don't thing the bus mastering bit disables MSI accesses (and even if officially it did, I wouldn't trust it). But disabling MSI itself isn't device specific either, so should be an option here (with the caveat that there are a few buggy devices that can't get back into MSI mode if it was once disabled, so perhaps masking MSI when possible should be preferred over disabling it).
Jan
Quoted 46 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 44 lines · Jan Beulich
Quoted 43 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 16 lines · Konrad Rzeszutek Wilk
Review
Quoted 10 lines · Andrew Cooper
(quoted diff) +10
-0+/* Disconnect a PCI device from the PCI bus. From the PCI spec: + * "When a 0 is written to [the COMMAND] register, the device is + * logically disconnected from the PCI bus for all accesses except + * configuration accesses. All devices are required to support + * this base level of functionality." + */ +void disconnect_pci_device(struct pci_dev *pdev) +{ + pci_conf_write16(pdev->bus, PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), PCI_COMMAND, 0);So if you have a PCI serial card (or Intel AMT) and you are using that for serial output on the hypervisor line, this will turn it off. There should be some whitelist capability to not do it for PCI serial devices that are owned (used) by the hypervisor.
Quoted 8 lines
Quoted 4 lines
That would be useful for debugging the kexec process itself but in the general case there won't be any further output from the hypervisor and if the kexec'd kernel wants to use the device it is going to have to set it up again anyways.
No, not generally. Just look at Linux' early-printk code: The device is assumed to be enabled (by the BIOS), as the PCI subsystem can't possibly be initialized at this point already.
That's arguably a debugging facility as well though.
Quoted 7 lines
This also means that white-listing just devices Xen uses may not be
enough: If Xen doesn't use a serial console (or the secondary kernel wants to use some other device Xen doesn't care about - VGA or other kind of console devices come to mind), it must not find it fully disconnected from the bus. Consequently I would think that while interrupt and DMA activity should be forced off, decoding I/O and memory addresses by the devices shouldn't be.The problem is that this can't be done without device specific knowledge, which the hypervisor generally doesn't have and we can't get the device's owning domain to do anything because we are crashing.
Quoted 6 lines
Quoted 3 lines
Why would there be any device specific knowledge needed? It's all done through the command word, just that writing zero isn't really appropriate.
So presumably if you disable bus mastering you've effectively disabled DMA but how do you disable interrupts via the command word?
Interrupts can be disabled equally well in the IO-APIC and by disabling MSI for all devices.
Jan
Quoted 50 lines · Jan Beulich
Quoted 50 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 47 lines · Jan Beulich
Quoted 40 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 16 lines · Konrad Rzeszutek Wilk
Review
Quoted 10 lines · Andrew Cooper
(quoted diff) +10
-0+/* Disconnect a PCI device from the PCI bus. From the PCI spec: + * "When a 0 is written to [the COMMAND] register, the device is + * logically disconnected from the PCI bus for all accesses except + * configuration accesses. All devices are required to support + * this base level of functionality." + */ +void disconnect_pci_device(struct pci_dev *pdev) +{ + pci_conf_write16(pdev->bus, PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), PCI_COMMAND, 0);So if you have a PCI serial card (or Intel AMT) and you are using that for serial output on the hypervisor line, this will turn it off. There should be some whitelist capability to not do it for PCI serial devices that are owned (used) by the hypervisor.
Quoted 8 lines
Quoted 4 lines
That would be useful for debugging the kexec process itself but in the general case there won't be any further output from the hypervisor and if the kexec'd kernel wants to use the device it is going to have to set it up again anyways.
No, not generally. Just look at Linux' early-printk code: The device is assumed to be enabled (by the BIOS), as the PCI subsystem can't possibly be initialized at this point already.
That's arguably a debugging facility as well though.
Quoted 7 lines
This also means that white-listing just devices Xen uses may not be
enough: If Xen doesn't use a serial console (or the secondary kernel wants to use some other device Xen doesn't care about - VGA or other kind of console devices come to mind), it must not find it fully disconnected from the bus. Consequently I would think that while interrupt and DMA activity should be forced off, decoding I/O and memory addresses by the devices shouldn't be.Quoted 3 lines
The problem is that this can't be done without device specific knowledge, which the hypervisor generally doesn't have and we can't get the device's owning domain to do anything because we are crashing.
Why would there be any device specific knowledge needed? It's all done through the command word, just that writing zero isn't really appropriate.
Quoted 5 lines
Quoted 2 lines
So presumably if you disable bus mastering you've effectively disabled DMA but how do you disable interrupts via the command word?
Interrupts can be disabled equally well in the IO-APIC and by disabling MSI for all devices.
Considering that it would be nice to have PCI device reset capabilities in the hypervisor anyway, in case a device is malfunctioning, and considering that we all know that PCI devices don't always follow PCI specs, wouldn't it be safer to just reset all the devices in this case? At least the reset code is well tested and known to work (or known to work with some particular devices, and for this reasons there are quirks). Also resetting devices would better cover the case when a device is misbehaving.
Of course we still need a whitelist for serial consoles and maybe other devices.
Quoted 4 lines
quirks). Also resetting devices would better cover the case when a device is misbehaving.
Of course we still need a whitelist for serial consoles and maybe other devices.
It sounds like I should post some of the patches I've that deal with various serial console now. They actually save the BDF of the PCI serial device so that the "whitelist" data can be easily extracted.