Skip to contentSkip to conversation

xen pci platform device driver

PATCH In review Stefano Stabellini 3 participants 5 messages May 10, 2010 – May 11, 2010 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 5/11 xen pci platform device driver

Add the xen pci platform device driver that is responsible for initializing the grant table and xenbus in PV on HVM mode. Few changes to xenbus and grant table are necessary to allow the delayed initialization in HVM mode.
Grant table needs few additional modifications to work in HVM mode.

When running on HVM the event channel upcall is never called while in progress because it is a normal Linux irq handler, therefore we cannot be sure that evtchn_upcall_pending is 0 when returning.
For this reason if evtchn_upcall_pending is set by Xen we need to loop again on the event channels set pending otherwise we might loose some event channel deliveries.

---
 drivers/xen/Kconfig                  |   11 ++-
 drivers/xen/Makefile                 |    3 +-
 drivers/xen/events.c                 |    5 +-
 drivers/xen/grant-table.c            |   70 +++++++++-
 drivers/xen/platform-pci.c           |  236 ++++++++++++++++++++++++++++++++++
 drivers/xen/xenbus/xenbus_probe.c    |   20 ++-
 include/xen/grant_table.h            |    1 +
 include/xen/interface/grant_table.h  |    1 +
 include/xen/interface/platform_pci.h |   45 +++++++
 include/xen/platform_pci.h           |   41 ++++++
 include/xen/xenbus.h                 |    1 +
 11 files changed, 417 insertions(+), 17 deletions(-)
 create mode 100644 drivers/xen/platform-pci.c
 create mode 100644 include/xen/interface/platform_pci.h
 create mode 100644 include/xen/platform_pci.h
drivers/xen/Kconfig +10 -1
index cab100a..3e02457 100644
@@ -60,4 +60,13 @@ config XEN_SYS_HYPERVISOR
          Create entries under /sys/hypervisor describing the Xen
 	 hypervisor environment.  When running native or in another
 	 virtual environment, /sys/hypervisor will still be present,
-	 but will have no xen contents.
\ No newline at end of file
+	 but will have no xen contents.
+
+config XEN_PLATFORM_PCI
+	tristate "xen platform pci device driver"
+	depends on XEN
+	help
+	  Driver for the Xen PCI Platform device: it is responsible for
+	  initializing xenbus and grant_table when running in a Xen HVM
+	  domain. As a consequence this driver is required to run any Xen PV
+	  frontend on Xen HVM.
drivers/xen/Makefile +2 -1
index 7c28434..2a502d2 100644
@@ -9,4 +9,5 @@ obj-$(CONFIG_XEN_XENCOMM)	+= xencomm.o
 obj-$(CONFIG_XEN_BALLOON)	+= balloon.o
 obj-$(CONFIG_XEN_DEV_EVTCHN)	+= evtchn.o
 obj-$(CONFIG_XENFS)		+= xenfs/
-obj-$(CONFIG_XEN_SYS_HYPERVISOR)	+= sys-hypervisor.o
\ No newline at end of file
+obj-$(CONFIG_XEN_SYS_HYPERVISOR)	+= sys-hypervisor.o
+obj-$(CONFIG_XEN_PLATFORM_PCI)		+= platform-pci.o
drivers/xen/events.c +3 -2
index cd609f4..197ccbc 100644
@@ -662,7 +662,7 @@ void __xen_evtchn_do_upcall(struct pt_regs *regs)
 
 		count = __get_cpu_var(xed_nesting_count);
 		__get_cpu_var(xed_nesting_count) = 0;
-	} while(count != 1);
+	} while(count != 1 || vcpu_info->evtchn_upcall_pending);
 
 out:
 
@@ -722,7 +722,8 @@ static int rebind_irq_to_cpu(unsigned irq, unsigned tcpu)
 	struct evtchn_bind_vcpu bind_vcpu;
 	int evtchn = evtchn_from_irq(irq);
 
-	if (!VALID_EVTCHN(evtchn))
+	if (!VALID_EVTCHN(evtchn) ||
+			(xen_hvm_domain() && !xen_have_vector_callback))
 		return -1;
 
 	/* Send future instances of this interrupt to other vcpu. */
drivers/xen/grant-table.c +63 -7

113 lines not on this page · raw message

drivers/xen/platform-pci.c new file +236 -0

236 lines not on this page · raw message

drivers/xen/xenbus/xenbus_probe.c +14 -6
index 0fa7ccf..9057f8d 100644
@@ -779,16 +779,24 @@ void xenbus_probe(struct work_struct *unused)
 	blocking_notifier_call_chain(&xenstore_chain, 0, NULL);
 }
 
-static int __init xenbus_probe_init(void)
+static int __init __xenbus_probe_init(void)
+{
+	/* Delay initialization in the PV on HVM case */
+	if (xen_hvm_domain())
+		return 0;
+
+	if (!xen_pv_domain())
+		return -ENODEV;
+
+	return xenbus_probe_init();
+}
+
+int xenbus_probe_init(void)
 {
 	int err = 0;
 
 	DPRINTK("");
 
-	err = -ENODEV;
-	if (!xen_domain())
-		goto out_error;
-
 	/* Register ourselves with the kernel bus subsystem */
 	err = bus_register(&xenbus_frontend.bus);
 	if (err)
@@ -847,7 +855,7 @@ static int __init xenbus_probe_init(void)
 	return err;
 }
 
-postcore_initcall(xenbus_probe_init);
+postcore_initcall(__xenbus_probe_init);
 
 MODULE_LICENSE("GPL");
 
include/xen/grant_table.h +1 -0
index a40f1cd..811cda5 100644
@@ -51,6 +51,7 @@ struct gnttab_free_callback {
 	u16 count;
 };
 
+int gnttab_init(void);
 int gnttab_suspend(void);
 int gnttab_resume(void);
 
include/xen/interface/grant_table.h +1 -0
index 39da93c..39e5717 100644
@@ -28,6 +28,7 @@
 #ifndef __XEN_PUBLIC_GRANT_TABLE_H__
 #define __XEN_PUBLIC_GRANT_TABLE_H__
 
+#include <xen/interface/xen.h>
 
 /***********************************
  * GRANT TABLE REPRESENTATION
include/xen/interface/platform_pci.h new file +45 -0

45 lines not on this page · raw message

include/xen/platform_pci.h new file +41 -0

41 lines not on this page · raw message

include/xen/xenbus.h +1 -0
index b9763ba..7fa0c22 100644
@@ -173,6 +173,7 @@ void unregister_xenbus_watch(struct xenbus_watch *watch);
 void xs_suspend(void);
 void xs_resume(void);
 void xs_suspend_cancel(void);
+int xenbus_probe_init(void);
 
 /* Used by xenbus_dev to borrow kernel's store connection. */
 void *xenbus_dev_request_and_reply(struct xsd_sockmsg *msg);
Signature · 1 line
1.5.4.3
#1 lore raw
Quoted 37 lines · Stefano Stabellini

Add the xen pci platform device driver that is responsible for initializing the grant table and xenbus in PV on HVM mode. Few changes to xenbus and grant table are necessary to allow the delayed initialization in HVM mode.
Grant table needs few additional modifications to work in HVM mode.

When running on HVM the event channel upcall is never called while in progress because it is a normal Linux irq handler, therefore we cannot be sure that evtchn_upcall_pending is 0 when returning.
For this reason if evtchn_upcall_pending is set by Xen we need to loop again on the event channels set pending otherwise we might loose some event channel deliveries.

---
 drivers/xen/Kconfig                  |   11 ++-
 drivers/xen/Makefile                 |    3 +-
 drivers/xen/events.c                 |    5 +-
 drivers/xen/grant-table.c            |   70 +++++++++-
 drivers/xen/platform-pci.c           |  236 ++++++++++++++++++++++++++++++++++
 drivers/xen/xenbus/xenbus_probe.c    |   20 ++-
 include/xen/grant_table.h            |    1 +
 include/xen/interface/grant_table.h  |    1 +
 include/xen/interface/platform_pci.h |   45 +++++++
 include/xen/platform_pci.h           |   41 ++++++
 include/xen/xenbus.h                 |    1 +
 11 files changed, 417 insertions(+), 17 deletions(-)
 create mode 100644 drivers/xen/platform-pci.c
 create mode 100644 include/xen/interface/platform_pci.h
 create mode 100644 include/xen/platform_pci.h
drivers/xen/Kconfig +0 -0
index cab100a..3e02457 100644

drivers/xen/Kconfig config XEN_SYS_HYPERVISOR · line 67

Quoted 10 lines
drivers/xen/Kconfig +5 -1
@@ -60,4 +60,13 @@ config XEN_SYS_HYPERVISOR
          Create entries under /sys/hypervisor describing the Xen
 	 hypervisor environment.  When running native or in another
 	 virtual environment, /sys/hypervisor will still be present,
-	 but will have no xen contents.
\ No newline at end of file
+	 but will have no xen contents.
+
+config XEN_PLATFORM_PCI
+	tristate "xen platform pci device driver"
+	depends on XEN

Wasn't there some XENBUS frontend depency needed here?

#2 lore raw
Quoted 9 lines · Konrad Rzeszutek Wilk
Quoted 9 lines
drivers/xen/Kconfig +0 -1
index cab100a..3e02457 100644
@@ -60,4 +60,13 @@ config XEN_SYS_HYPERVISOR
          Create entries under /sys/hypervisor describing the Xen
 	 hypervisor environment.  When running native or in another
 	 virtual environment, /sys/hypervisor will still be present,
-	 but will have no xen contents.
Quoted 9 lines

drivers/xen/Kconfig config XEN_SYS_HYPERVISOR · line 67

Quoted 6 lines

\ No newline at end of file

drivers/xen/Kconfig +5 -0
+	 but will have no xen contents.
+
+config XEN_PLATFORM_PCI
+	tristate "xen platform pci device driver"
+	depends on XEN

Wasn't there some XENBUS frontend depency needed here?

On 2.6.32 there is no XENBUS module, all the xenbus stuff is compiled in when CONFIG_XEN is selected (see the hooks and function pointers I had to add in patch 8 to allow XEN_PLATFORM_PCI to be compiled as a module).

#3 lore raw
In reply to Stefano Stabellini
Quoted 10 lines · Stefano Stabellini

Add the xen pci platform device driver that is responsible for initializing the grant table and xenbus in PV on HVM mode. Few changes to xenbus and grant table are necessary to allow the delayed initialization in HVM mode.
Grant table needs few additional modifications to work in HVM mode.

When running on HVM the event channel upcall is never called while in progress because it is a normal Linux irq handler, therefore we cannot be sure that evtchn_upcall_pending is 0 when returning.

Won't the event (and the interrupt it raises) still be pending when the handler returns?

Quoted 4 lines

For this reason if evtchn_upcall_pending is set by Xen we need to loop again on the event channels set pending otherwise we might loose some event channel deliveries.

See below...

Quoted 56 lines
---
 drivers/xen/Kconfig                  |   11 ++-
 drivers/xen/Makefile                 |    3 +-
 drivers/xen/events.c                 |    5 +-
 drivers/xen/grant-table.c            |   70 +++++++++-
 drivers/xen/platform-pci.c           |  236 ++++++++++++++++++++++++++++++++++
 drivers/xen/xenbus/xenbus_probe.c    |   20 ++-
 include/xen/grant_table.h            |    1 +
 include/xen/interface/grant_table.h  |    1 +
 include/xen/interface/platform_pci.h |   45 +++++++
 include/xen/platform_pci.h           |   41 ++++++
 include/xen/xenbus.h                 |    1 +
 11 files changed, 417 insertions(+), 17 deletions(-)
 create mode 100644 drivers/xen/platform-pci.c
 create mode 100644 include/xen/interface/platform_pci.h
 create mode 100644 include/xen/platform_pci.h
drivers/xen/Kconfig +10 -1
index cab100a..3e02457 100644
@@ -60,4 +60,13 @@ config XEN_SYS_HYPERVISOR
          Create entries under /sys/hypervisor describing the Xen
 	 hypervisor environment.  When running native or in another
 	 virtual environment, /sys/hypervisor will still be present,
-	 but will have no xen contents.
\ No newline at end of file
+	 but will have no xen contents.
+
+config XEN_PLATFORM_PCI
+	tristate "xen platform pci device driver"
+	depends on XEN
+	help
+	  Driver for the Xen PCI Platform device: it is responsible for
+	  initializing xenbus and grant_table when running in a Xen HVM
+	  domain. As a consequence this driver is required to run any Xen PV
+	  frontend on Xen HVM.
drivers/xen/Makefile +2 -1
index 7c28434..2a502d2 100644
@@ -9,4 +9,5 @@ obj-$(CONFIG_XEN_XENCOMM)	+= xencomm.o
 obj-$(CONFIG_XEN_BALLOON)	+= balloon.o
 obj-$(CONFIG_XEN_DEV_EVTCHN)	+= evtchn.o
 obj-$(CONFIG_XENFS)		+= xenfs/
-obj-$(CONFIG_XEN_SYS_HYPERVISOR)	+= sys-hypervisor.o
\ No newline at end of file
+obj-$(CONFIG_XEN_SYS_HYPERVISOR)	+= sys-hypervisor.o
+obj-$(CONFIG_XEN_PLATFORM_PCI)		+= platform-pci.o
drivers/xen/events.c +0 -0
index cd609f4..197ccbc 100644

drivers/xen/events.c void __xen_evtchn_do_upcall(struct pt_regs *regs) · line 666

Quoted 6 lines
drivers/xen/events.c +1 -1
@@ -662,7 +662,7 @@ void __xen_evtchn_do_upcall(struct pt_regs *regs)
 
 		count = __get_cpu_var(xed_nesting_count);
 		__get_cpu_var(xed_nesting_count) = 0;
-	} while(count != 1);
+	} while(count != 1 || vcpu_info->evtchn_upcall_pending);
 

So the intention here is to pick up newly posted events while the event processing loop is running? But if this is necessary it won't work, because it is still racy. For example, what happens if a new event is posted right here, just after the loop has exited? Will it get ignored? Or if it does need to be processed, why is the test in the loop necessary?

J

#4 lore raw
Quoted 7 lines · Jeremy Fitzhardinge
Quoted 6 lines · Stefano Stabellini

Add the xen pci platform device driver that is responsible for initializing the grant table and xenbus in PV on HVM mode. Few changes to xenbus and grant table are necessary to allow the delayed initialization in HVM mode.
Grant table needs few additional modifications to work in HVM mode.

Quoted 8 lines
Quoted 4 lines

When running on HVM the event channel upcall is never called while in progress because it is a normal Linux irq handler, therefore we cannot be sure that evtchn_upcall_pending is 0 when returning.

Won't the event (and the interrupt it raises) still be pending when the handler returns?

Reading handle_fasteoi_irq it doesn't seem like it.

Quoted 64 lines
Quoted 4 lines

For this reason if evtchn_upcall_pending is set by Xen we need to loop again on the event channels set pending otherwise we might loose some event channel deliveries.

See below...

Quoted 57 lines
---
 drivers/xen/Kconfig                  |   11 ++-
 drivers/xen/Makefile                 |    3 +-
 drivers/xen/events.c                 |    5 +-
 drivers/xen/grant-table.c            |   70 +++++++++-
 drivers/xen/platform-pci.c           |  236 ++++++++++++++++++++++++++++++++++
 drivers/xen/xenbus/xenbus_probe.c    |   20 ++-
 include/xen/grant_table.h            |    1 +
 include/xen/interface/grant_table.h  |    1 +
 include/xen/interface/platform_pci.h |   45 +++++++
 include/xen/platform_pci.h           |   41 ++++++
 include/xen/xenbus.h                 |    1 +
 11 files changed, 417 insertions(+), 17 deletions(-)
 create mode 100644 drivers/xen/platform-pci.c
 create mode 100644 include/xen/interface/platform_pci.h
 create mode 100644 include/xen/platform_pci.h
drivers/xen/Kconfig +10 -1
index cab100a..3e02457 100644
@@ -60,4 +60,13 @@ config XEN_SYS_HYPERVISOR
          Create entries under /sys/hypervisor describing the Xen
 	 hypervisor environment.  When running native or in another
 	 virtual environment, /sys/hypervisor will still be present,
-	 but will have no xen contents.
\ No newline at end of file
+	 but will have no xen contents.
+
+config XEN_PLATFORM_PCI
+	tristate "xen platform pci device driver"
+	depends on XEN
+	help
+	  Driver for the Xen PCI Platform device: it is responsible for
+	  initializing xenbus and grant_table when running in a Xen HVM
+	  domain. As a consequence this driver is required to run any Xen PV
+	  frontend on Xen HVM.
drivers/xen/Makefile +2 -1
index 7c28434..2a502d2 100644
@@ -9,4 +9,5 @@ obj-$(CONFIG_XEN_XENCOMM)	+= xencomm.o
 obj-$(CONFIG_XEN_BALLOON)	+= balloon.o
 obj-$(CONFIG_XEN_DEV_EVTCHN)	+= evtchn.o
 obj-$(CONFIG_XENFS)		+= xenfs/
-obj-$(CONFIG_XEN_SYS_HYPERVISOR)	+= sys-hypervisor.o
\ No newline at end of file
+obj-$(CONFIG_XEN_SYS_HYPERVISOR)	+= sys-hypervisor.o
+obj-$(CONFIG_XEN_PLATFORM_PCI)		+= platform-pci.o
drivers/xen/events.c +0 -0
index cd609f4..197ccbc 100644
@@ -662,7 +662,7 @@ void __xen_evtchn_do_upcall(struct pt_regs *regs)
 
Quoted 13 lines

drivers/xen/events.c void __xen_evtchn_do_upcall(struct pt_regs *regs) · line 666

Quoted 5 lines
drivers/xen/events.c +1 -1
 		count = __get_cpu_var(xed_nesting_count);
 		__get_cpu_var(xed_nesting_count) = 0;
-	} while(count != 1);
+	} while(count != 1 || vcpu_info->evtchn_upcall_pending);
 

So the intention here is to pick up newly posted events while the event processing loop is running? But if this is necessary it won't work, because it is still racy. For example, what happens if a new event is posted right here, just after the loop has exited? Will it get ignored? Or if it does need to be processed, why is the test in the loop necessary?

Your example is not going to cause any trouble because in that case Xen will also send an interrupt to the guest that is going to have local irq disable at the time.
When the first interrupt handling routing is finished, local irq will be enabled and the second interrupt will be served, therefore no event channels will be lost.

The problem that I am trying to solve is making sure that when evtchn_upcall_pending is set by Xen and an interrupt is sent by Xen to the guest, we (the guest) handle the event channel.
In particular the problem was that during event channel handling we re-enable irqs so a second irq may be served but the second handler wouldn't go as far as resetting evtchn_upcall_pending because as soon as it realizes that another one is in progress the fasteoi handler will exits. Therefore we have to reset evtchn_upcall_pending and handle the event channel directly in the first handler. Since this only happens when we re-enable irqs we can make sure that we'll be able to handle the new event channel in the same loop.