Skip to contentSkip to conversation

[PATCH PV_OPS]

PATCH In review Konrad Rzeszutek Wilk 2 participants 10 messages Dec 9, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 [PATCH PV_OPS]

Jeremy,

Attached are couple of patches for pciback to remove the xenbus_walk usage and replace it with a registration list type mechanism as discussed in previous e-mail correspondence.

Also the last two remove functions that are not currently used.

#1 lore raw

PATCH 1/6 Revert "In xen_create_msi_irq, extract the domain id of the MSI device."

This reverts commit 661692690f8cf5a5ceccec1f4d221ec2381974

I did not remove the domid attribute from the structs as they are going to be used in the subsequent patches.

---
 drivers/xen/events.c |   44 --------------------------------------------
 1 files changed, 0 insertions(+), 44 deletions(-)
drivers/xen/events.c +0 -44
index 9c56d60..f8bbf4c 100644
@@ -45,7 +45,6 @@
 #include <xen/interface/xen.h>
 #include <xen/interface/event_channel.h>
 
-#include <xen/xenbus.h>
 #include "../pci/msi.h"
 
 /*
@@ -627,43 +626,6 @@ out:
 	spin_unlock(&irq_mapping_update_lock);
 	return rc;
 }
-#define XS_PCI_SEARCH "/local/domain/0/backend/pci/"
-#define XS_PCI_SEARCH_LEN 28
-
-static int get_domid_for_dev(char *nodename, char *path, char *val, void *data)
-{
-	struct pci_dev *dev = (struct pci_dev *)data;
-
-	/* We are looking for:
-	 * CB inv[/local/domain/0/backend/pci/3/0/dev-1]=0000:00:14.5 */
-
-	if (!dev || !pci_name(dev))
-		return -ENODEV;
-
-	if (strncmp(nodename, XS_PCI_SEARCH, XS_PCI_SEARCH_LEN) == 0)
-	{
-		if (strncmp(path, "dev", 3) == 0) {
-			char *name = NULL;
-			unsigned int domid;
-
-			/* The val contains: 0000:00:14.5 */
-			if (strcmp(val, pci_name(dev)) != 0)
-				return 0;
-
-			/* From here on, extract the Domain ID */
- 			name = strstr(nodename, "pci/");
-			if (!name)
-				return 0;
-
-			if (sscanf(name, "pci/%u", &domid) != 1)
-				return 0;
-
-			dev_dbg(&dev->dev,"Assigned to domain %u.\n", domid);
-			return domid;
-		}
-	}
-	return 0;
-}
 
 int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc,
 		       int type, int pirq_override)
@@ -675,12 +637,6 @@ int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc,
 	int pos;
 	u32 table_offset, bir;
 
-	/* Walk the XenStore keys to see if the device is assigned to any
-	 * domain. If so, extract the domain id. */
-	domid = rc = xenbus_walk( "/local/domain/0", get_domid_for_dev, dev);
-	if (rc <= 0)
-		domid = DOMID_SELF;
-
 	memset(&map_irq, 0, sizeof(map_irq));
 	map_irq.domid = domid;
 	map_irq.type = MAP_PIRQ_TYPE_MSI;
Signature · 1 line
1.6.2.5
#2 lore raw

PATCH 2/6 Provide a mechanism to register domain owner of a PCI device.

. and also to find the domain owner based on the PCI device and to unregister a domain owner of a PCI device.

---
 arch/x86/include/asm/xen/pci.h |   16 +++++++++
 arch/x86/xen/pci.c             |   73 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+), 0 deletions(-)
arch/x86/include/asm/xen/pci.h +16 -0
index 6c022c8..6e9e9f2 100644
@@ -8,6 +8,11 @@ int xen_create_msi_irq(struct pci_dev *dev,
 			int type, int pirq_override);
 int xen_destroy_irq(int irq);
 void xen_teardown_msi_dev(struct pci_dev *dev);
+
+int find_device_owner(struct pci_dev *dev);
+int register_device_owner(struct pci_dev *dev, domid_t domain);
+int unregister_device_owner(struct pci_dev *dev);
+
 #else
 static inline int xen_register_gsi(u32 gsi, int triggering, int polarity)
 {
@@ -25,6 +30,17 @@ static inline int xen_destroy_irq(int irq)
 	return -1;
 }
 static inline void xen_teardown_msi_dev(struct pci_dev *dev) { }
+
+static inline int find_device_owner(struct pci_dev *dev) { return -1; }
+static inline int register_device_owner(struct pci_dev *dev, domid_t domain)
+{
+	return -1;
+}
+static inline int unregister_device_owner(struct pci_dev *dev)
+{
+	return -1;
+}
+
 #endif
 
 #if defined(CONFIG_PCI_MSI) && defined(CONFIG_XEN_DOM0_PCI)
arch/x86/xen/pci.c +73 -0

82 lines not on this page · raw message

Signature · 1 line
1.6.2.5
#3 lore raw

PATCH 3/6 Check if the PCI device is owner by a domain different than DOMID_SELF.

We check if there is a domain owner for the PCI device. In case of failure (meaning no domain has registered for this device) we make DOMID_SELF the owner.

---
 drivers/xen/events.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
drivers/xen/events.c +6 -1
index f8bbf4c..d122022 100644
@@ -39,6 +39,7 @@
 #include <asm/sync_bitops.h>
 #include <asm/xen/hypercall.h>
 #include <asm/xen/hypervisor.h>
+#include <asm/xen/pci.h>
 
 #include <xen/xen-ops.h>
 #include <xen/events.h>
@@ -633,10 +634,14 @@ int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc,
 	int irq = 0;
 	struct physdev_map_pirq map_irq;
 	int rc;
-	domid_t domid = DOMID_SELF;
+	domid_t domid;
 	int pos;
 	u32 table_offset, bir;
 
+	domid = rc = find_device_owner(dev);
+	if (rc < 0)
+		domid = DOMID_SELF;
+	
 	memset(&map_irq, 0, sizeof(map_irq));
 	map_irq.domid = domid;
 	map_irq.type = MAP_PIRQ_TYPE_MSI;
Signature · 1 line
1.6.2.5
#4 lore raw

PATCH 4/6 Register the owner (domain) of the PCI device.

When the front-end and back-end start negotiating we register the domain that will use the PCI device. Furthermore during shutdown of guest or unbinding of the PCI device (and unloading of module) from pciback we unregister the domain owner.

---
 drivers/xen/pciback/pci_stub.c |    3 +++
 drivers/xen/pciback/xenbus.c   |   12 ++++++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)
drivers/xen/pciback/pci_stub.c +3 -0
index c65c7c1..00018c1 100644
@@ -14,6 +14,7 @@
 #include <linux/wait.h>
 #include <asm/atomic.h>
 #include <xen/events.h>
+#include <asm/xen/pci.h>
 #include "pciback.h"
 #include "conf_space.h"
 #include "conf_space_quirks.h"
@@ -87,6 +88,8 @@ static void pcistub_device_release(struct kref *kref)
 
 	dev_dbg(&psdev->dev->dev, "pcistub_device_release\n");
 
+	unregister_device_owner(psdev->dev);
+
 	/* Clean-up the device */
 	pciback_reset_device(psdev->dev);
 	pciback_config_free_dyn_fields(psdev->dev);
drivers/xen/pciback/xenbus.c +12 -0
index efec585..86acae3 100644
@@ -10,6 +10,7 @@
 #include <linux/workqueue.h>
 #include <xen/xenbus.h>
 #include <xen/events.h>
+#include <asm/xen/pci.h>
 #include <linux/workqueue.h>
 #include "pciback.h"
 
@@ -221,6 +222,14 @@ static int pciback_export_device(struct pciback_device *pdev,
 	if (err)
 		goto out;
 
+	dev_info(&dev->dev, "registering for %d\n", pdev->xdev->otherend_id);
+	if (register_device_owner(dev, pdev->xdev->otherend_id) != 0) {
+		dev_err(&dev->dev, "device has been assigned to another " \
+			"domain! Over-writting the ownership, but beware.\n");
+		unregister(dev);
+		register_device_owner(dev, pdev->xdev->otherend_id);
+	}
+
 	/* TODO: It'd be nice to export a bridge and have all of its children
 	 * get exported with it. This may be best done in xend (which will
 	 * have to calculate resource usage anyway) but we probably want to
@@ -251,6 +260,9 @@ static int pciback_remove_device(struct pciback_device *pdev,
 		goto out;
 	}
 
+	dev_db(&dev->dev, "unregistering for %d\n", pdev->xdev->otherend_id);
+	unregister_device_owner(dev);
+
 	pciback_release_pci_dev(pdev, dev);
 
 out:
Signature · 1 line
1.6.2.5
#5 lore raw

PATCH 5/6 Remove the vestiges of CONFIG_PCI_GUESTDEV.

The code 'pci_is_guestdev' is not yet back-ported. Will revisit this once that has been completed.

---
 drivers/xen/pciback/pci_stub.c |   10 ----------
 1 files changed, 0 insertions(+), 10 deletions(-)
drivers/xen/pciback/pci_stub.c +0 -10
index 00018c1..e9e8e68 100644
@@ -430,16 +430,6 @@ static int __devinit pcistub_probe(struct pci_dev *dev,
 
 		dev_info(&dev->dev, "seizing device\n");
 		err = pcistub_seize(dev);
-#ifdef CONFIG_PCI_GUESTDEV
-	} else if (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) {
-		if (!pci_is_guestdev(dev)) {
-			err = -ENODEV;
-			goto out;
-		}
-
-		dev_info(&dev->dev, "seizing device\n");
-		err = pcistub_seize(dev);
-#endif /* CONFIG_PCI_GUESTDEV */
 	} else
 		/* Didn't find the device */
 		err = -ENODEV;
Signature · 1 line
1.6.2.5
#6 lore raw

PATCH 6/6 Remove deprecated routine to find domain owner of PCI device.

In linux-2.6.18.hg tree the mechanism to find the domain owner was for the MSI driver (msi-xen.c) to call in this function to retrieve the domain number. This is not the way anymore.

---
 drivers/xen/pciback/pci_stub.c |   16 ----------------
 1 files changed, 0 insertions(+), 16 deletions(-)
drivers/xen/pciback/pci_stub.c +0 -16
index e9e8e68..a94d350 100644
@@ -1157,22 +1157,6 @@ static ssize_t permissive_show(struct device_driver *drv, char *buf)
 
 DRIVER_ATTR(permissive, S_IRUSR | S_IWUSR, permissive_show, permissive_add);
 
-#ifdef CONFIG_PCI_MSI
-
-int pciback_get_owner(struct pci_dev *dev)
-{
-	struct pcistub_device *psdev;
-
-	psdev = pcistub_device_find(pci_domain_nr(dev->bus), dev->bus->number,
-			PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
-
-	if (!psdev || !psdev->pdev)
-		return -1;
-
-	return psdev->pdev->xdev->otherend_id;
-}
-#endif
-
 static void pcistub_exit(void)
 {
 	driver_remove_file(&pciback_pci_driver.driver, &driver_attr_new_slot);
Signature · 1 line
1.6.2.5
#7 lore raw

PATCH 1/1 Fix build issues.

In reply to Konrad Rzeszutek Wilk

<sigh>

---
 drivers/xen/pciback/xenbus.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/xen/pciback/xenbus.c +2 -2
index 86acae3..e33a688 100644
@@ -226,7 +226,7 @@ static int pciback_export_device(struct pciback_device *pdev,
 	if (register_device_owner(dev, pdev->xdev->otherend_id) != 0) {
 		dev_err(&dev->dev, "device has been assigned to another " \
 			"domain! Over-writting the ownership, but beware.\n");
-		unregister(dev);
+		unregister_device_owner(dev);
 		register_device_owner(dev, pdev->xdev->otherend_id);
 	}
 
@@ -260,7 +260,7 @@ static int pciback_remove_device(struct pciback_device *pdev,
 		goto out;
 	}
 
-	dev_db(&dev->dev, "unregistering for %d\n", pdev->xdev->otherend_id);
+	dev_dbg(&dev->dev, "unregistering for %d\n", pdev->xdev->otherend_id);
 	unregister_device_owner(dev);
 
 	pciback_release_pci_dev(pdev, dev);
Signature · 1 line
1.6.2.5
#8 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 6 lines · Konrad Rzeszutek Wilk

Attached are couple of patches for pciback to remove the xenbus_walk usage and replace it with a registration list type mechanism as discussed in previous e-mail correspondence.

Also the last two remove functions that are not currently used.

What changeset are they against?

J

#9 lore raw
Quoted 9 lines · Jeremy Fitzhardinge
Quoted 6 lines · Konrad Rzeszutek Wilk

Attached are couple of patches for pciback to remove the xenbus_walk usage and replace it with a registration list type mechanism as discussed in previous e-mail correspondence.

Also the last two remove functions that are not currently used.

What changeset are they against?

This is on top of the latest (origin/xen/master). Let me rebase is on top of the xen/dom0/pciback and re-send the patches.