Skip to contentSkip to conversation

pciback: user-space quirks policy

PATCH In review Chris 2 participants 4 messages Jul 17, 2006 – Jul 27, 2006

lore
Share & tools
lore

Chris

author
#0 lore raw

PATCH 4/5 pciback: user-space quirks policy

The attached patch contains two policy files written in what is intended to be human-readable SXP.

1. xend-pci-quirks.sxp:

Specifies which PCI device(s) may write to a set of PCI configuration space registers. A quirky PCI device is identified by its vendor ID, device ID, subvendor ID, and subdevice ID. If a matching entry is found, the corresponding fields will be sent to the PCI bus manager. Fields are composed of a register, size, and mask -- although the mask field is currently unused.

The included policy file is for a range of tg3 devices, which is the only type of quirky device I know about. Users with other quirky devices are invited to either add entries to this policy file or add an entry in the permissive file, described next. In either case, send an email to the xen-devel list to make the device known.

2. xend-pci-permissive.sxp

Lists PCI devices that pciback should not prevent from writing to their configuration space. This can be necessary if, for example, a new Tigon3 devices is released with different PCI vendor/device values such that no entry in xend-pci-quirks.sxp is triggered.

tools/examples/Makefile +2 -0
diff -r b20580cf7fc1 -r 94a0a82c91d1 tools/examples/Makefile
@@ -18,6 +18,8 @@ XEN_CONFIGS += xmexample2
 XEN_CONFIGS += xmexample2
 XEN_CONFIGS += xmexample.hvm
 XEN_CONFIGS += xmexample.vti
+XEN_CONFIGS += xend-pci-quirks.sxp
+XEN_CONFIGS += xend-pci-permissive.sxp
 
 # Xen script dir and scripts to go there.
 XEN_SCRIPT_DIR = /etc/xen/scripts
tools/examples/xend-pci-permissive.sxp new file +33 -0
diff -r b20580cf7fc1 -r 94a0a82c91d1 tools/examples/xend-pci-permissive.sxp
@@ -0,0 +1,33 @@
+###############################################################################
+# Configuration file for granting quiry PCI devices full write access to their 
+# configuration space.  This file should only be used when you are unable to 
+# determine the exact registers required by your device.  Even so, it should 
+# be used only temporarily.
+# 
+# SEND A MESSAGE TO [email protected] IF YOU USE THIS FILE.
+# 
+# Using this file should NOT be necessary.  If you must use it to make some
+# device work, send a message to the above list with as much information about 
+# your device as possible so the developers can make accomodations for it.  
+# Once developers make the necessary updates you can remove the corresponding
+# entry for your device. 
+###############################################################################
+# This is a bogus entry to show how a new device would be added to the list.
+# Entries are formated like the following:  'domain:bus:slot:function'
+#  
+# Case 1: The file is originally empty.  Add the following lines, adapted with
+#         your device's domain, bus, slot, and function.
+#
+#  (unconstrained_dev_ids
+#    ('0000:02:00.0') 	# first entry
+#  )
+#
+# 
+# Case 2: Appending to an existing list.  Entries are comma delimited.
+#  
+#  (unconstrained_dev_ids
+#    ('XXXX:XX:XX.X', 	# existing entry
+#     '0000:02:00.0')   # new entry
+#  )
+#
+###############################################################################
tools/examples/xend-pci-quirks.sxp new file +96 -0

96 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 2 lines · Chris

The attached patch contains two policy files written in what is intended to be human-readable SXP.

A few comments on the format:

1. Instead of having xend-pci-permissive.sxp empty, could you:
(unconstrained_dev_ids
(

        # 'XXXX:XX:XX.X'

)
)
This would simplify the header comment as no need to have separate
explanation for empty file.

2. It's a bit weird that xend-pci-quirks.sxp identifies devices by
vendor/device ids, but xend-pci-permissive.sxp identifies by slot. Could the latter also identify by vendor/device ids -- after all, the need to be in the list is a property of the device, not its position on the PCI bus. This would also allow us to add devices to this list in a way that's portable across systems (an idea I'm sure you hate ;-).

3. Can we define the identifier format as
<vendor>:<device>[:<subvendor>:<subdevice>]. The sub-details ffff:ffff crop up rather a lot and it'd be neater to be able to make that a default if that section of the identifier string isn't present.

Apart from that, as far as I can tell you parse the config files whenever a PCI device is bound to a domain. You pick out matching entries and poke them down to pciback via sysfs. All seems sensibel to me. Is there a way of reading out from sysfs the quirks and 'permissive status' for a particular device (or all devices)? That could be handy.

Thanks!
Keir

author
#2 lore raw
Quoted 8 lines · Keir Fraser

1. Instead of having xend-pci-permissive.sxp empty, could you:
(unconstrained_dev_ids
(

        # 'XXXX:XX:XX.X'

)
)
This would simplify the header comment as no need to have separate
explanation for empty file.

Agreed; done.

Quoted 6 lines

2. It's a bit weird that xend-pci-quirks.sxp identifies devices by
vendor/device ids, but xend-pci-permissive.sxp identifies by slot. Could the latter also identify by vendor/device ids -- after all, the need to be in the list is a property of the device, not its position on the PCI bus. This would also allow us to add devices to this list in a way that's portable across systems (an idea I'm sure you hate ;-).

There was a method to my madness. The goal was to make using devices that require permissive mode possible, but to discourage its use as a long-term solution, thereby encouraging admins to feed their quirky device info back to xen-devel for a proper fix in xend-pci-permissive.sxp.

However, since my argument against your suggestion is more philosophical than technical I'm willing to compromise; done

Quoted 4 lines

3. Can we define the identifier format as
<vendor>:<device>[:<subvendor>:<subdevice>]. The sub-details ffff:ffff crop up rather a lot and it'd be neater to be able to make that a default if that section of the identifier string isn't present.

Seems reasonable; done.

Quoted 2 lines

Is there a way of reading out from sysfs the quirks and 'permissive status' for a particular device (or all devices)? That could be handy.

The documentation was lacking in this area, but this feature was already there. Doing a cat on /sys/bus/pci/drivers/pciback/permissive will list devices currently in permissive mode. Similarly, cat'ing /sys/bus/pci/drivers/pciback/quirks will show each device bound to the PCI backend and any quirks it is afforded. Relevant sections have been added to the users guide to document these features.

A note of interest: a standard set of 17 quirks is applied to all PCI devices when they are bound to pciback. The rest of the device-specific quirks get added by xend via sysfs when a device is bound to a domain.

See attached patches that include the requested changes.

Three are changed from the original submission:
- pciback-uspace-quirks-xend.patch
- pciback-uspace-quirks-policy.patch
- pciback-uspace-quirks-doc.patch

The other two are the same as before:
- pciback-uspace-quirks-linux.patch
- pciback-per-device-permissive-flags.patch

The order of patch application remains the same.

-Chris

linux-2.6-xen-sparse/drivers/xen/pciback/conf_space.c +1 -4
diff -r 46eb52cd64e3 linux-2.6-xen-sparse/drivers/xen/pciback/conf_space.c
@@ -14,9 +14,6 @@
 #include "pciback.h"
 #include "conf_space.h"
 #include "conf_space_quirks.h"
-
-static int permissive = 0;
-module_param(permissive, bool, 0644);
 
 #define DEFINE_PCI_CONFIG(op,size,type) 			\
 int pciback_##op##_config_##size 				\
@@ -258,7 +255,7 @@ int pciback_config_write(struct pci_dev 
 		 * This means that some fields may still be read-only because
 		 * they have entries in the config_field list that intercept
 		 * the write and do nothing. */
-		if (permissive) {
+		if (dev_data->permissive) {
 			switch (size) {
 			case 1:
 				err = pci_write_config_byte(dev, offset,
linux-2.6-xen-sparse/drivers/xen/pciback/pci_stub.c +68 -0

86 lines not on this page · raw message

linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h +1 -0
diff -r 46eb52cd64e3 linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h
@@ -44,6 +44,7 @@ struct pciback_device {
 
 struct pciback_dev_data {
 	struct list_head config_fields;
+	int permissive;
 	int warned_on_write;
 };
 
docs/src/user.tex +46 -2

60 lines not on this page · raw message

linux-2.6-xen-sparse/drivers/xen/pciback/Makefile +2 -1
diff -r b20580cf7fc1 -r 94a0a82c91d1 linux-2.6-xen-sparse/drivers/xen/pciback/Makefile
@@ -4,7 +4,8 @@ pciback-y += conf_space.o conf_space_hea
 pciback-y += conf_space.o conf_space_header.o \
 	     conf_space_capability.o \
 	     conf_space_capability_vpd.o \
-	     conf_space_capability_pm.o
+	     conf_space_capability_pm.o \
+             conf_space_quirks.o
 pciback-$(CONFIG_XEN_PCIDEV_BACKEND_VPCI) += vpci.o
 pciback-$(CONFIG_XEN_PCIDEV_BACKEND_PASS) += passthrough.o
 
linux-2.6-xen-sparse/drivers/xen/pciback/conf_space.c +48 -23

118 lines not on this page · raw message

linux-2.6-xen-sparse/drivers/xen/pciback/conf_space.h +7 -4
diff -r b20580cf7fc1 -r 94a0a82c91d1 linux-2.6-xen-sparse/drivers/xen/pciback/conf_space.h
@@ -33,11 +33,13 @@ typedef int (*conf_byte_read) (struct pc
  * values.
  */
 struct config_field {
-	unsigned int     offset;
-	unsigned int     size;
-	conf_field_init  init;
+	unsigned int offset;
+	unsigned int size;
+	unsigned int mask;
+	conf_field_init init;
 	conf_field_reset reset;
-	conf_field_free  release;
+	conf_field_free release;
+	void (*clean) (struct config_field * field);
 	union {
 		struct {
 			conf_dword_write write;
@@ -52,6 +54,7 @@ struct config_field {
 			conf_byte_read read;
 		} b;
 	} u;
+	struct list_head list;
 };
 
 struct config_field_entry {
linux-2.6-xen-sparse/drivers/xen/pciback/pci_stub.c +155 -1

228 lines not on this page · raw message

linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h +1 -0
diff -r b20580cf7fc1 -r 94a0a82c91d1 linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h
@@ -61,6 +61,7 @@ void pciback_reset_device(struct pci_dev
 /* Access a virtual configuration space for a PCI device */
 int pciback_config_init(void);
 int pciback_config_init_dev(struct pci_dev *dev);
+void pciback_config_free_dyn_fields(struct pci_dev *dev);
 void pciback_config_reset_dev(struct pci_dev *dev);
 void pciback_config_free_dev(struct pci_dev *dev);
 int pciback_config_read(struct pci_dev *dev, int offset, int size,
linux-2.6-xen-sparse/drivers/xen/pciback/conf_space_quirks.c new file +128 -0

128 lines not on this page · raw message

linux-2.6-xen-sparse/drivers/xen/pciback/conf_space_quirks.h new file +35 -0
diff -r b20580cf7fc1 -r 94a0a82c91d1 linux-2.6-xen-sparse/drivers/xen/pciback/conf_space_quirks.h
@@ -0,0 +1,35 @@
+/*
+ * PCI Backend - Data structures for special overlays for broken devices.
+ *
+ * Ryan Wilson <[email protected]>
+ * Chris Bookholt <[email protected]>
+ */
+
+#ifndef __XEN_PCIBACK_CONF_SPACE_QUIRKS_H__
+#define __XEN_PCIBACK_CONF_SPACE_QUIRKS_H__
+
+#include <linux/pci.h>
+#include <linux/list.h>
+
+struct pciback_config_quirk {
+	struct list_head quirks_list;
+	struct pci_device_id devid;
+	struct pci_dev *pdev;
+};
+
+struct pciback_config_quirk *pciback_find_quirk(struct pci_dev *dev);
+
+int pciback_config_quirks_add_field(struct pci_dev *dev, struct config_field
+				    *field);
+
+int pciback_config_quirks_remove_field(struct pci_dev *dev, int reg);
+
+int pciback_config_quirks_init(struct pci_dev *dev);
+
+void pciback_config_field_free(struct config_field *field);
+
+int pciback_config_quirk_release(struct pci_dev *dev);
+
+int pciback_field_is_dup(struct pci_dev *dev, int reg);
+
+#endif
tools/examples/Makefile +2 -0
diff -r 37f206c7405a tools/examples/Makefile
@@ -18,6 +18,8 @@ XEN_CONFIGS += xmexample2
 XEN_CONFIGS += xmexample2
 XEN_CONFIGS += xmexample.hvm
 XEN_CONFIGS += xmexample.vti
+XEN_CONFIGS += xend-pci-quirks.sxp
+XEN_CONFIGS += xend-pci-permissive.sxp
 
 # Xen script dir and scripts to go there.
 XEN_SCRIPT_DIR = /etc/xen/scripts
tools/examples/xend-pci-permissive.sxp new file +27 -0
diff -r 37f206c7405a tools/examples/xend-pci-permissive.sxp
@@ -0,0 +1,27 @@
+###############################################################################
+# Configuration file for granting quiry PCI devices full write access to their 
+# configuration space.  This file should only be used when you are unable to 
+# determine the exact registers required by your device.  Even so, it should 
+# be used only temporarily.
+# 
+# SEND A MESSAGE TO [email protected] IF YOU USE THIS FILE.
+# 
+# Using this file should NOT be necessary.  If you must use it to make some
+# device work, send a message to the above list with as much information about 
+# your device as possible so the developers can make accomodations for it.  
+# Once developers make the necessary updates you can remove the corresponding
+# entry for your device. 
+###############################################################################
+# Entries are formated as follows:  <vendor>:<device>[:<subvendor>:<subdevice>]
+# 
+# Example: Appending to an existing list
+#  
+# (unconstrained_dev_ids
+#     ('XXXX:XXXX:XXXX:XXXX'	# existing entry
+#      'YYYY:YYYY:YYYY:YYYY' 	# new entry 1
+#      'ZZZZ:ZZZZ')		# new entry 2
+# )
+###############################################################################
+(unconstrained_dev_ids
+     #('0123:4567:89AB:CDEF')
+)
tools/examples/xend-pci-quirks.sxp new file +96 -0

96 lines not on this page · raw message

tools/python/xen/util/pci.py +47 -50

129 lines not on this page · raw message

tools/python/xen/xend/server/pciif.py +6 -1
diff -r 37f206c7405a tools/python/xen/xend/server/pciif.py
@@ -32,6 +32,8 @@ from xen.util.pci import PciDevice
 from xen.util.pci import PciDevice
 import resource
 import re
+
+from xen.xend.server.pciquirk import *
 
 xc = xen.lowlevel.xc.xc()
 
@@ -150,7 +152,10 @@ class PciController(DevController):
                     "bind your slot/device to the PCI backend using sysfs" \
                     )%(dev.name))
 
-        for (start, size) in dev.ioports:
+        PCIQuirk(dev.vendor, dev.device, dev.subvendor, dev.subdevice, domain, 
+                bus, slot, func)
+
+	for (start, size) in dev.ioports:
             log.debug('pci: enabling ioport 0x%x/0x%x'%(start,size))
             rc = xc.domain_ioport_permission(dom = fe_domid, first_port = start,
                     nr_ports = size, allow_access = True)
tools/python/xen/xend/server/pciquirk.py new file +145 -0

145 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 11 lines · Chris
Quoted 6 lines

2. It's a bit weird that xend-pci-quirks.sxp identifies devices by
vendor/device ids, but xend-pci-permissive.sxp identifies by slot. Could the latter also identify by vendor/device ids -- after all, the need to be in the list is a property of the device, not its position on the PCI bus. This would also allow us to add devices to this list in a way that's portable across systems (an idea I'm sure you hate ;-).

There was a method to my madness. The goal was to make using devices that require permissive mode possible, but to discourage its use as a long-term solution, thereby encouraging admins to feed their quirky device info back to xen-devel for a proper fix in xend-pci-permissive.sxp.

Yes, that was my suspicion. :-) Not unreasonable really as it shouldn't be hard to work out a quirks list for any given device, but I'd rather keep the same method of device identification across both config files.

By the way, your email didn't contain attachments but had a humungous blob of patch appended instead. Could you resend (all in one email is fine, but separate attachments) and remind me of the order in which to apply them? Thanks!

-- Keir