Skip to contentSkip to conversation

PV drivers product number registration (v2)

PATCH In review Paul Durrant 3 participants 10 messages Oct 1, 2012 – Oct 2, 2012

lore
Share & tools
lore
#0 lore raw

cover PV drivers product number registration (v2)

PV drivers in HVM guests typically make use off an 'unplug' protocol in QEMU to prevent co-existence of emulated devices.
See docs/misc/hvm-emulated-unplug.markdown for details.

The register of product numbers used by the blacklisting feature of this protocol is currently directly in the xenstore.c source moduleof traditional QEMU. It should really be in a Xen header file to prevent duplication/conflict between QEMU versions.

Moreover the linux PV-on-HVM drivers make use of product number 3 seemingly without ever registering that number.

This patch series introduces a new header and registers product number 3 for Linux's use. A subsequent patch to qemu-xen-unstable wll be created to make use of the new header.

Version 2:

I have re-coded at Ian Jackson's request in the form of macros that allow a switch statement or array to be easily generated from the product list.

#1 lore raw

PATCH 1/2 Add a new pvdrivers header to serve as the register of product numbers.

These product numbers are used by the QEMU blacklisting protocol in traditional QEMU and are currently coded directly into the xenstore.c source module. Since there are now multiple QEMUs this information should be pulled into a public header to avoid duplication/conflict. hvm-emulated-unplug.markdown has also been adjusted to reference the new header.

---
 docs/misc/hvm-emulated-unplug.markdown |    2 +-
 xen/include/public/hvm/pvdrivers.h     |   47 ++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletions(-)
 create mode 100644 xen/include/public/hvm/pvdrivers.h
docs/misc/hvm-emulated-unplug.markdown +1 -1
index 707fbab..ec9ce83 100644
@@ -65,4 +65,4 @@ decimal number.  `{product_name}` is a string corresponding to the
 product number in step 3.
 
 The master registry of product names and numbers is in
-qemu-xen-unstable's xenstore.c.
+xen/include/public/hvm/pvdrivers.h
xen/include/public/hvm/pvdrivers.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
1.7.2.5
#5 lore raw

PATCH 2/2 Register Linux PV-on-HVM drivers product number.

In reply to Paul Durrant

This is already in use despite never being registereed. See XEN_IOPORT_LINUX_PRODNUM in include/xen/platform_pci.h

---
 xen/include/public/hvm/pvdrivers.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
xen/include/public/hvm/pvdrivers.h +1 -0
index 13bf57b..d117e5c 100644
@@ -41,6 +41,7 @@
 #define	PVDRIVERS_PRODUCT_LIST(EACH)                         \
         EACH("xensource-windows", 0x0001) /* Citrix */       \
         EACH("gplpv-windows",     0x0002) /* James Harper */ \
+        EACH("linux",             0x0003)                    \
         EACH("experimental",      0xffff)                    \
         EACH(NULL,                0x0000) /* terminator */
 
Signature · 1 line
1.7.2.5
#6 lore raw

PATCH 1/1 Use new Xen public header for product numbers and names

xen/include/public/hvm/pvdrivers.h has been added as the register of product numbers used by the blacklisting protocol. Use the definitions therein rather then locally coded values.

---
 xenstore.c |   23 +++++++----------------
 1 files changed, 7 insertions(+), 16 deletions(-)
xenstore.c +7 -16
index 1857160..4382674 100644
@@ -23,6 +23,8 @@
 #include "qemu-timer.h"
 #include "qemu-xen.h"
 
+#include <xen/hvm/pvdrivers.h>
+
 struct xs_handle *xsh = NULL;
 static char *media_filename[MAX_DRIVES+1];
 static QEMUTimer *insert_timer = NULL;
@@ -960,28 +962,17 @@ xenstore_pv_driver_build_blacklisted(uint16_t product_nr,
     char *tmp;
     const char *product;
 
+#define PRODUCT(_name, _nr) case _nr: product = _name; break;
     switch (product_nr) {
-    /*
-     * In qemu-xen-unstable, this is the master registry of product
-     * numbers.  If you need a new product number allocating, please
-     * post to [email protected].  You should NOT use
-     * an existing product number without allocating one.
-     *
-     * If you maintain a seaparate versioning and distribution path
-     * for PV drivers you should have a separate product number so
-     * that your drivers can be separated from others'.
-     *
-     * During development, you may use the product ID 0xffff to
-     * indicate a driver which is yet to be released.
-     */
-    case 1: product = "xensource-windows";  break; /* Citrix */
-    case 2: product = "gplpv-windows";      break; /* James Harper */
-    case 0xffff: product = "experimental";  break;
+    PVDRIVERS_PRODUCT_LIST(PRODUCT)
     default:
         /* Don't know what product this is -> we can't blacklist
          * it. */
         return 0;
     }
+
+#undef  PRODUCT
+
     if (asprintf(&buf, "/mh/driver-blacklist/%s/%d", product, build_nr) < 0)
         return 0;
     tmp = xs_read(xsh, XBT_NULL, buf, NULL);
Signature · 1 line
1.7.2.5
#2 lore raw

Re: [PATCH 1/2] Add a new pvdrivers header to serve as the register of product numbers.

In reply to Paul Durrant

Paul Durrant writes ("[Xen-devel] [PATCH 1/2] Add a new pvdrivers header to serve as the register of product numbers."):

xen/include/public/hvm/pvdrivers.h line 45

Quoted 5 lines
xen/include/public/hvm/pvdrivers.h new file +5 -0
+#define PVDRIVERS_PRODUCT_LIST(EACH)                         \
+        EACH("xensource-windows", 0x0001) /* Citrix */       \
+        EACH("gplpv-windows",     0x0002) /* James Harper */ \
+        EACH("experimental",      0xffff)                    \
+        EACH(NULL,                0x0000) /* terminator */

When you said a terminator, I thought you meant macro parameters to PVDRIVERS_PRODUCT_LIST which were invoked only between elements.

This invocation of EACH is harmful. If the user wants to make an array out of this, they can add it themselves. But if they want to make a switch statement out of it, they can't.

Ian.

#7 lore raw

Re: [PATCH] Use new Xen public header for product numbers and names

In reply to Paul Durrant

Paul Durrant writes ("[Xen-devel] [PATCH] Use new Xen public header for product numbers and names"):

Quoted 3 lines

xen/include/public/hvm/pvdrivers.h has been added as the register of product numbers used by the blacklisting protocol. Use the definitions therein rather then locally coded values.

...

Quoted 9 lines
xenstore.c +1 -7
+#define PRODUCT(_name, _nr) case _nr: product = _name; break;
     switch (product_nr) {
-    /*
-     * In qemu-xen-unstable, this is the master registry of product
-     * numbers.  If you need a new product number allocating, please
-     * post to [email protected].  You should NOT use
-     * an existing product number without allocating one.
-     *
-     * If you maintain a seaparate versioning and distribution path

xenstore.c xenstore_pv_driver_build_blacklisted(uint16_t product_nr, · line 967

Quoted 10 lines
xenstore.c +1 -9
-     * for PV drivers you should have a separate product number so
-     * that your drivers can be separated from others'.
-     *
-     * During development, you may use the product ID 0xffff to
-     * indicate a driver which is yet to be released.
-     */
-    case 1: product = "xensource-windows";  break; /* Citrix */
-    case 2: product = "gplpv-windows";      break; /* James Harper */
-    case 0xffff: product = "experimental";  break;
+    PVDRIVERS_PRODUCT_LIST(PRODUCT)

As a case in point, this generates:

       case 0: product = NULL; break;

and then passes the NULL to asprintf.

Ian.

#8 lore raw

Re: [PATCH] Use new Xen public header for product numbers and names

Quoted 34 lines

-----Original Message-----
From: Ian Jackson [mailto:[email protected]]
Sent: 01 October 2012 16:14
To: Paul Durrant
Cc: [email protected]
Subject: Re: [Xen-devel] [PATCH] Use new Xen public header for product numbers and names

Paul Durrant writes ("[Xen-devel] [PATCH] Use new Xen public header for product numbers and names"):

Quoted 3 lines

xen/include/public/hvm/pvdrivers.h has been added as the register of product numbers used by the blacklisting protocol.
Use the definitions therein rather then locally coded values.

...

Quoted 9 lines
xenstore.c +1 -7
+#define PRODUCT(_name, _nr) case _nr: product = _name; break;
     switch (product_nr) {
-    /*
-     * In qemu-xen-unstable, this is the master registry of product
-     * numbers.  If you need a new product number allocating, please
-     * post to [email protected].  You should NOT use
-     * an existing product number without allocating one.
-     *
-     * If you maintain a seaparate versioning and distribution path

xenstore.c xenstore_pv_driver_build_blacklisted(uint16_t product_nr, · line 967

Quoted 10 lines
xenstore.c +1 -9
-     * for PV drivers you should have a separate product number so
-     * that your drivers can be separated from others'.
-     *
-     * During development, you may use the product ID 0xffff to
-     * indicate a driver which is yet to be released.
-     */
-    case 1: product = "xensource-windows";  break; /* Citrix */
-    case 2: product = "gplpv-windows";      break; /* James Harper */
-    case 0xffff: product = "experimental";  break;
+    PVDRIVERS_PRODUCT_LIST(PRODUCT)
Quoted 4 lines

As a case in point, this generates:

       case 0: product = NULL; break;

and then passes the NULL to asprintf.

Nothing should be using product number 0, so is this a problem?

Paul

#3 lore raw

Re: [PATCH 1/2] Add a new pvdrivers header to serve as the register of product numbers.

In reply to Ian Jackson
Quoted 17 lines

-----Original Message-----
From: Ian Jackson [mailto:[email protected]]
Sent: 01 October 2012 16:12
To: Paul Durrant
Cc: [email protected]
Subject: Re: [Xen-devel] [PATCH 1/2] Add a new pvdrivers header to serve as the register of product numbers.

Paul Durrant writes ("[Xen-devel] [PATCH 1/2] Add a new pvdrivers header to serve as the register of product numbers."):

xen/include/public/hvm/pvdrivers.h line 45

Quoted 5 lines
xen/include/public/hvm/pvdrivers.h new file +5 -0
+#define PVDRIVERS_PRODUCT_LIST(EACH)                         \
+        EACH("xensource-windows", 0x0001) /* Citrix */       \
+        EACH("gplpv-windows",     0x0002) /* James Harper */ \
+        EACH("experimental",      0xffff)                    \
+        EACH(NULL,                0x0000) /* terminator */
Quoted 7 lines

When you said a terminator, I thought you meant macro parameters to PVDRIVERS_PRODUCT_LIST which were invoked only between elements.

This invocation of EACH is harmful. If the user wants to make an array out of this, they can add it themselves. But if they want to make a switch statement out of it, they can't.

Ok. I thought it was helpful to reserve product number 0 for this purpose, but I'll ditch it.

Paul

#4 lore raw

Re: [PATCH 1/2] Add a new pvdrivers header to serve as the register of product numbers. [and 1 more messages]

Paul Durrant writes ("RE: [Xen-devel] [PATCH 1/2] Add a new pvdrivers header to serve as the register of product numbers."):

Quoted 1 line

Ok. I thought it was helpful to reserve product number 0 for this purpose, but I'll ditch it.

Well if you want to reserve it you could put a comment in the list saying "0 is reserved, do not use".

Paul Durrant writes ("Re: [Xen-devel] [PATCH] Use new Xen public header for product numbers and names"):

Quoted 6 lines

Ian Jackson [mailto:[email protected]]:

Quoted 3 lines

As a case in point, this generates:

       case 0: product = NULL; break;

and then passes the NULL to asprintf.

Nothing should be using product number 0, so is this a problem?

You're joking, right ?

The guest can send any value it likes here and the result is that qemu might dereference NULL. (Although in practice asprintf doesn't crash on NULL strings in any implementation I'm aware of.)

Ian.

#9 lore raw

Re: [PATCH] Use new Xen public header for product numbers and names

In reply to Paul Durrant
Quoted 34 lines · Paul Durrant
Quoted 34 lines

-----Original Message-----
From: Ian Jackson [mailto:[email protected]]
Sent: 01 October 2012 16:14
To: Paul Durrant
Cc: [email protected]
Subject: Re: [Xen-devel] [PATCH] Use new Xen public header for product numbers and names

Paul Durrant writes ("[Xen-devel] [PATCH] Use new Xen public header for product numbers and names"):

Quoted 3 lines

xen/include/public/hvm/pvdrivers.h has been added as the register of product numbers used by the blacklisting protocol.
Use the definitions therein rather then locally coded values.

...

Quoted 19 lines
xenstore.c +2 -16
+#define PRODUCT(_name, _nr) case _nr: product = _name; break;
     switch (product_nr) {
-    /*
-     * In qemu-xen-unstable, this is the master registry of product
-     * numbers.  If you need a new product number allocating, please
-     * post to [email protected].  You should NOT use
-     * an existing product number without allocating one.
-     *
-     * If you maintain a seaparate versioning and distribution path
-     * for PV drivers you should have a separate product number so
-     * that your drivers can be separated from others'.
-     *
-     * During development, you may use the product ID 0xffff to
-     * indicate a driver which is yet to be released.
-     */
-    case 1: product = "xensource-windows";  break; /* Citrix */
-    case 2: product = "gplpv-windows";      break; /* James Harper */
-    case 0xffff: product = "experimental";  break;
+    PVDRIVERS_PRODUCT_LIST(PRODUCT)
Quoted 6 lines
Quoted 4 lines

As a case in point, this generates:

       case 0: product = NULL; break;

and then passes the NULL to asprintf.

Nothing should be using product number 0, so is this a problem?

In some circumstances (I think) the product number may come from the guest, which may be malicious.

Ian.