All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [Qemu-devel] [Xen-devel] [PATCH 01/19] xen: Create a new file xen_pvdev.c
@ 2016-07-17  7:41 ` Quan Xu
  0 siblings, 0 replies; 15+ messages in thread
From: Quan Xu @ 2016-07-17  7:41 UTC (permalink / raw)
  To: rea, Stefano Stabellini, anthony.perard
  Cc: qemu-devel, stefanb, xen-devel, dgdegra, wei.liu2, eblake, quan.xu2


[Quan:]: comment starts with [Quan:]


The purpose of the new file is to store generic functions shared by frontendand backends such as xenstore operations, xendevs.

Signed-off-by: Quan Xu <quan.xu@xxxxxxxxx>
Signed-off-by: Emil Condrea <emilcondrea@xxxxxxxxx>
---
 hw/xen/Makefile.objs         |   2 +-
 hw/xen/xen_backend.c         | 125 +-----------------------------------
 hw/xen/xen_pvdev.c           | 149 +++++++++++++++++++++++++++++++++++++++++++
 include/hw/xen/xen_backend.h |  63 +-----------------
 include/hw/xen/xen_pvdev.h   |  71 +++++++++++++++++++++
 5 files changed, 223 insertions(+), 187 deletions(-)
 create mode 100644 hw/xen/xen_pvdev.c
 create mode 100644 include/hw/xen/xen_pvdev.h

diff --git a/hw/xen/Makefile.objs b/hw/xen/Makefile.objs
index d367094..591cdc2 100644
--- a/hw/xen/Makefile.objs
+++ b/hw/xen/Makefile.objs
@@ -1,5 +1,5 @@
 # xen backend driver support
-common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o
+common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o xen_pvdev.o
 
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o 
xen_pt_graphics.o xen_pt_msi.o
diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
index bab79b1..a251a4a 100644
--- a/hw/xen/xen_backend.c
+++ b/hw/xen/xen_backend.c
@@ -30,6 +30,7 @@
 #include "sysemu/char.h"
 #include "qemu/log.h"
 #include "hw/xen/xen_backend.h"
+#include "hw/xen/xen_pvdev.h"
 
 #include <xen/grant_table.h>
 
@@ -56,8 +57,6 @@ static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup =
 static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = 
QTAILQ_HEAD_INITIALIZER(xendevs);
 static int debug = 0;
 
-/* ------------------------------------------------------------- */
-
 static void xenstore_cleanup_dir(char *dir)
 {
     struct xs_dirs *d;
@@ -76,34 +75,6 @@ void xen_config_cleanup(void)
     }
 }
 
-int xenstore_write_str(const char *base, const char *node, const char *val)
-{
-    char abspath[XEN_BUFSIZE];
-
-    snprintf(abspath, sizeof(abspath), "%s/%s", base, node);
-    if (!xs_write(xenstore, 0, abspath, val, strlen(val))) {
-        return -1;
-    }
-    return 0;
-}
-
-char *xenstore_read_str(const char *base, const char *node)
-{
-    char abspath[XEN_BUFSIZE];
-    unsigned int len;
-    char *str, *ret = NULL;
-
-    snprintf(abspath, sizeof(abspath), "%s/%s", base, node);
-    str = xs_read(xenstore, 0, abspath, &len);
-    if (str != NULL) {
-        /* move to qemu-allocated memory to make sure
-         * callers can savely g_free() stuff. */
-        ret = g_strdup(str);
-        free(str);
-    }
-    return ret;
-}
-
 int xenstore_mkdir(char *path, int p)
 {
     struct xs_permissions perms[2] = {
@@ -128,48 +99,6 @@ int xenstore_mkdir(char *path, int p)
     return 0;
 }
 
-int xenstore_write_int(const char *base, const char *node, int ival)
-{
-    char val[12];
-
[Quan:]: why 12 ? what about XEN_BUFSIZE? 
-    snprintf(val, sizeof(val), "%d", ival);
-    return xenstore_write_str(base, node, val);
-}
-
-int xenstore_write_int64(const char *base, const char *node, int64_t ival)
-{
-    char val[21];
-
[Quan:]: why 21 ? what about XEN_BUFSIZE?

-    snprintf(val, sizeof(val), "%"PRId64, ival);
-    return xenstore_write_str(base, node, val);
-}
-
-int xenstore_read_int(const char *base, const char *node, int *ival)
-{
-    char *val;
-    int rc = -1;
-
-    val = xenstore_read_str(base, node);
[Quan:]:  IMO, it is better to initialize val when declares.  the same comment for the other 'val'
-    if (val && 1 == sscanf(val, "%d", ival)) {
-        rc = 0;
-    }
-    g_free(val);
-    return rc;
-}
-
-int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval)
-{
-    char *val;
-    int rc = -1;
-
-    val = xenstore_read_str(base, node);-    if (val && 1 == sscanf(val, "%"SCNu64, uval)) {
-        rc = 0;
-    }
-    g_free(val);
-    return rc;
-}
-
 int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const 
char *val)
 {
     return xenstore_write_str(xendev->be, node, val);
@@ -212,20 +141,6 @@ int xenstore_read_fe_uint64(struct XenDevice *xendev, 
const char *node, uint64_t
 
 /* ------------------------------------------------------------- */
 
-const char *xenbus_strstate(enum xenbus_state state)
-{
-    static const char *const name[] = {
-        [ XenbusStateUnknown      ] = "Unknown",
-        [ XenbusStateInitialising ] = "Initialising",
-        [ XenbusStateInitWait     ] = "InitWait",
-        [ XenbusStateInitialised  ] = "Initialised",
-        [ XenbusStateConnected    ] = "Connected",
-        [ XenbusStateClosing      ] = "Closing",
-        [ XenbusStateClosed       ] = "Closed",
-    };
-    return (state < ARRAY_SIZE(name)) ? name[state] : "INVALID";
-}
-
 int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state)
 {
     int rc;
@@ -833,44 +748,6 @@ int xen_be_send_notify(struct XenDevice *xendev)
     return xenevtchn_notify(xendev->evtchndev, xendev->local_port);
 }
 
-/*
- * msg_level:
- *  0 == errors (stderr + logfile).
- *  1 == informative debug messages (logfile only).
- *  2 == noisy debug messages (logfile only).
- *  3 == will flood your log (logfile only).
- */
-void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, 
...)
-{
-    va_list args;
-
-    if (xendev) {
-        if (msg_level > xendev->debug) {
-            return;
-        }
-        qemu_log("xen be: %s: ", xendev->name);
-        if (msg_level == 0) {
-            fprintf(stderr, "xen be: %s: ", xendev->name);
-        }
-    } else {
-        if (msg_level > debug) {
-            return;
-        }
-        qemu_log("xen be core: ");
-        if (msg_level == 0) {
-            fprintf(stderr, "xen be core: ");
-        }
-    }
-    va_start(args, fmt);
-    qemu_log_vprintf(fmt, args);
-    va_end(args);
-    if (msg_level == 0) {
-        va_start(args, fmt);
-        vfprintf(stderr, fmt, args);
-        va_end(args);
-    }
-    qemu_log_flush();
-}
 
 static int xen_sysdev_init(SysBusDevice *dev)
 {
diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c
new file mode 100644
index 0000000..a444855
--- /dev/null
+++ b/hw/xen/xen_pvdev.c
@@ -0,0 +1,149 @@
+/*
+ * Xen para-virtualization device
+ *
+ *  (c) 2008 Gerd Hoffmann <kraxel@xxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>
+ */
+
+#include "qemu/osdep.h"
+
+#include "hw/xen/xen_backend.h"
+#include "hw/xen/xen_pvdev.h"
+
+static int debug = 0;
+/* ------------------------------------------------------------- */
+
+int xenstore_write_str(const char *base, const char *node, const char *val)
+{
+    char abspath[XEN_BUFSIZE];
+
+    snprintf(abspath, sizeof(abspath), "%s/%s", base, node);
+    if (!xs_write(xenstore, 0, abspath, val, strlen(val))) {
+        return -1;
+    }
+    return 0;
+}
+
+char *xenstore_read_str(const char *base, const char *node)
+{
+    char abspath[XEN_BUFSIZE];
+    unsigned int len;
+    char *str, *ret = NULL;
+
+    snprintf(abspath, sizeof(abspath), "%s/%s", base, node);
+    str = xs_read(xenstore, 0, abspath, &len);
+    if (str != NULL) {
+        /* move to qemu-allocated memory to make sure
+         * callers can savely g_free() stuff. */
+        ret = g_strdup(str);
+        free(str);
+    }
+    return ret;
+}
+
+int xenstore_write_int(const char *base, const char *node, int ival)
+{
+    char val[12];
+
+    snprintf(val, sizeof(val), "%d", ival);
+    return xenstore_write_str(base, node, val);
+}
+
+int xenstore_write_int64(const char *base, const char *node, int64_t ival)
+{
+    char val[21];
+
+    snprintf(val, sizeof(val), "%"PRId64, ival);
+    return xenstore_write_str(base, node, val);
+}
+
+int xenstore_read_int(const char *base, const char *node, int *ival)
+{
+    char *val;
+    int rc = -1;
+
+    val = xenstore_read_str(base, node);+    if (val && 1 == sscanf(val, "%d", ival)) {
+        rc = 0;
+    }
+    g_free(val);
+    return rc;
+}
+
+int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval)
+{
+    char *val;
+    int rc = -1;
+
+    val = xenstore_read_str(base, node);
+    if (val && 1 == sscanf(val, "%"SCNu64, uval)) {
+        rc = 0;
+    }
+    g_free(val);
+    return rc;
+}
+
+const char *xenbus_strstate(enum xenbus_state state)
+{
+    static const char *const name[] = {
+        [ XenbusStateUnknown      ] = "Unknown",
+        [ XenbusStateInitialising ] = "Initialising",
+        [ XenbusStateInitWait     ] = "InitWait",
+        [ XenbusStateInitialised  ] = "Initialised",
+        [ XenbusStateConnected    ] = "Connected",
+        [ XenbusStateClosing      ] = "Closing",
+        [ XenbusStateClosed       ] = "Closed",
+    };
+    return (state < ARRAY_SIZE(name)) ? name[state] : "INVALID";
+}
+
+/*
+ * msg_level:
+ *  0 == errors (stderr + logfile).
+ *  1 == informative debug messages (logfile only).
+ *  2 == noisy debug messages (logfile only).
+ *  3 == will flood your log (logfile only).
+ */
+void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, 
...)
+{
+    va_list args;
+
+    if (xendev) {
+        if (msg_level > xendev->debug) {
+            return;
+        }
+        qemu_log("xen be: %s: ", xendev->name);
+        if (msg_level == 0) {
+            fprintf(stderr, "xen be: %s: ", xendev->name);
+        }
+    } else {
+        if (msg_level > debug) {
+            return;
+        }
+        qemu_log("xen be core: ");
+        if (msg_level == 0) {
+            fprintf(stderr, "xen be core: ");
+        }
+    }
+    va_start(args, fmt);
+    qemu_log_vprintf(fmt, args);
+    va_end(args);
+    if (msg_level == 0) {
+        va_start(args, fmt);
+        vfprintf(stderr, fmt, args);
+        va_end(args);
+    }
+    qemu_log_flush();
+}
diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h
index 6e18a46..0f009e3 100644
--- a/include/hw/xen/xen_backend.h
+++ b/include/hw/xen/xen_backend.h
@@ -2,60 +2,10 @@
 #define QEMU_HW_XEN_BACKEND_H 1
 
 #include "hw/xen/xen_common.h"
+#include "hw/xen/xen_pvdev.h"
 #include "sysemu/sysemu.h"
 #include "net/net.h"
 
-/* ------------------------------------------------------------- */
-
-#define XEN_BUFSIZE 1024
-
-struct XenDevice;
-
-/* driver uses grant tables  ->  open gntdev device (xendev->gnttabdev) */
-#define DEVOPS_FLAG_NEED_GNTDEV   1
-/* don't expect frontend doing correct state transitions (aka console quirk) */
-#define DEVOPS_FLAG_IGNORE_STATE  2
-
-struct XenDevOps {
-    size_t    size;
-    uint32_t  flags;
-    void      (*alloc)(struct XenDevice *xendev);
-    int       (*init)(struct XenDevice *xendev);
-    int       (*initialise)(struct XenDevice *xendev);
-    void      (*connected)(struct XenDevice *xendev);
-    void      (*event)(struct XenDevice *xendev);
-    void      (*disconnect)(struct XenDevice *xendev);
-    int       (*free)(struct XenDevice *xendev);
-    void      (*backend_changed)(struct XenDevice *xendev, const char *node);
-    void      (*frontend_changed)(struct XenDevice *xendev, const char *node);
-    int       (*backend_register)(void);
-};
-
-struct XenDevice {
-    const char         *type;
-    int                dom;
-    int                dev;
-    char               name[64];
-    int                debug;
-
-    enum xenbus_state  be_state;
-    enum xenbus_state  fe_state;
-    int                online;
-    char               be[XEN_BUFSIZE];
-    char               *fe;
-    char               *protocol;
-    int                remote_port;
-    int                local_port;
-
-    xenevtchn_handle   *evtchndev;
-    xengnttab_handle   *gnttabdev;
-
-    struct XenDevOps   *ops;
-    QTAILQ_ENTRY(XenDevice) next;
-};
-
-/* ------------------------------------------------------------- */
-
 /* variables */
 extern xc_interface *xen_xc;
 extern xenforeignmemory_handle *xen_fmem;
@@ -63,14 +13,7 @@ extern struct xs_handle *xenstore;
 extern const char *xen_protocol;
 extern DeviceState *xen_sysdev;
 
-/* xenstore helper functions */
 int xenstore_mkdir(char *path, int p);
-int xenstore_write_str(const char *base, const char *node, const char *val);
-int xenstore_write_int(const char *base, const char *node, int ival);
-int xenstore_write_int64(const char *base, const char *node, int64_t ival);
-char *xenstore_read_str(const char *base, const char *node);
-int xenstore_read_int(const char *base, const char *node, int *ival);
-
 int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const 
char *val);
 int xenstore_write_be_int(struct XenDevice *xendev, const char *node, int 
ival);
 int xenstore_write_be_int64(struct XenDevice *xendev, const char *node, 
int64_t ival);
@@ -78,10 +21,8 @@ char *xenstore_read_be_str(struct XenDevice *xendev, const 
char *node);
 int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int 
*ival);
 char *xenstore_read_fe_str(struct XenDevice *xendev, const char *node);
 int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int 
*ival);
-int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval);
 int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, 
uint64_t *uval);
 
-const char *xenbus_strstate(enum xenbus_state state);
 struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev);
 void xen_be_check_state(struct XenDevice *xendev);
 
@@ -92,8 +33,6 @@ int xen_be_set_state(struct XenDevice *xendev, enum 
xenbus_state state);
 int xen_be_bind_evtchn(struct XenDevice *xendev);
 void xen_be_unbind_evtchn(struct XenDevice *xendev);
 int xen_be_send_notify(struct XenDevice *xendev);
-void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, 
...)
-    GCC_FMT_ATTR(3, 4);
 
 /* actual backend drivers */
 extern struct XenDevOps xen_console_ops;      /* xen_console.c     */
diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h
new file mode 100644
index 0000000..f60bfae
--- /dev/null
+++ b/include/hw/xen/xen_pvdev.h
@@ -0,0 +1,71 @@
+#ifndef QEMU_HW_XEN_PVDEV_H
+#define QEMU_HW_XEN_PVDEV_H 1
+
+#include "hw/xen/xen_common.h"
+#include <inttypes.h>
+
+/* ------------------------------------------------------------- */
+
+#define XEN_BUFSIZE 1024
+
+struct XenDevice;
+
+/* driver uses grant tables  ->  open gntdev device (xendev->gnttabdev) */
+#define DEVOPS_FLAG_NEED_GNTDEV   1
+/* don't expect frontend doing correct state transitions (aka console quirk) */
+#define DEVOPS_FLAG_IGNORE_STATE  2
+
+struct XenDevOps {
+    size_t    size;
+    uint32_t  flags;
+    void      (*alloc)(struct XenDevice *xendev);
+    int       (*init)(struct XenDevice *xendev);
+    int       (*initialise)(struct XenDevice *xendev);
+    void      (*connected)(struct XenDevice *xendev);
+    void      (*event)(struct XenDevice *xendev);
+    void      (*disconnect)(struct XenDevice *xendev);
+    int       (*free)(struct XenDevice *xendev);
+    void      (*backend_changed)(struct XenDevice *xendev, const char *node);
+    void      (*frontend_changed)(struct XenDevice *xendev, const char *node);
+    int       (*backend_register)(void);
+};
+
+struct XenDevice {
+    const char         *type;
+    int                dom;
+    int                dev;
+    char               name[64];
+    int                debug;
+
+    enum xenbus_state  be_state;
+    enum xenbus_state  fe_state;
+    int                online;
+    char               be[XEN_BUFSIZE];
+    char               *fe;
+    char               *protocol;
+    int                remote_port;
+    int                local_port;
+
+    xenevtchn_handle   *evtchndev;
+    xengnttab_handle   *gnttabdev;
+
+    struct XenDevOps   *ops;
+    QTAILQ_ENTRY(XenDevice) next;
+};
+
+/* ------------------------------------------------------------- */
+
+/* xenstore helper functions */
+int xenstore_write_str(const char *base, const char *node, const char *val);
+int xenstore_write_int(const char *base, const char *node, int ival);
+int xenstore_write_int64(const char *base, const char *node, int64_t ival);
+char *xenstore_read_str(const char *base, const char *node);
+int xenstore_read_int(const char *base, const char *node, int *ival);
+int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval);
+
+const char *xenbus_strstate(enum xenbus_state state);
+
+void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, 
...)
+    GCC_FMT_ATTR(3, 4);
+
+#endif /* QEMU_HW_XEN_PVDEV_H */
-- 
1.9.1

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: [PATCH 01/19] xen: Create a new file xen_pvdev.c
@ 2016-07-22 14:24 Quan Xu
  0 siblings, 0 replies; 15+ messages in thread
From: Quan Xu @ 2016-07-22 14:24 UTC (permalink / raw)
  To: anthony.perard, Emil Condrea
  Cc: Stefano Stabellini, wei.liu2, stefanb, qemu-devel, xen-devel,
	Daniel De Graaf, Eric Blake


[-- Attachment #1.1: Type: text/plain, Size: 1664 bytes --]

Anthony, thanks for your explaination.IMO, patch 1  and patch 2 need your detailed review.. IMO the reset patches are good in general..Emil, if patch 1 / patch 2 are reviewed from anthony, could you send out v10? :) i know it's not an easy task, thanks in advence!!
Quan

On Mon, 18 Jul 2016 15:50:27 +0100, anthony.perard<anthony.perard@citrix.com> wrote:> On Sun, Jul 17, 2016 at 03:41:26PM +0800, Quan Xu wrote:
> -int xenstore_write_int(const char *base, const char *node, int ival)
> -{
> -    char val[12];
> -
> [Quan:]: why 12 ? what about XEN_BUFSIZE? 

That is the number of digit in INT_MAX (10) + 1 for the sign + 1 for '\0'.

> -    snprintf(val, sizeof(val), "%d", ival);
> -    return xenstore_write_str(base, node, val);
> -}
> -
> -int xenstore_write_int64(const char *base, const char *node, int64_t ival)
> -{
> -    char val[21];
> -
> [Quan:]: why 21 ? what about XEN_BUFSIZE?

Same with INT64_MAX (19 digits).

> 
> -    snprintf(val, sizeof(val), "%"PRId64, ival);
> -    return xenstore_write_str(base, node, val);
> -}
> -
> -int xenstore_read_int(const char *base, const char *node, int *ival)
> -{
> -    char *val;
> -    int rc = -1;
> -
> -    val = xenstore_read_str(base, node);
> [Quan:]:  IMO, it is better to initialize val when declares.

I think I prefer it this way.

> -    if (val && 1 == sscanf(val, "%d", ival)) {
> -        rc = 0;
> -    }
> -    g_free(val);
> -    return rc;
> -}

-- 
Anthony PERARD

[-- Attachment #1.2: Type: text/html, Size: 3828 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [Xen-devel] [PATCH 01/19] xen: Create a new file xen_pvdev.c
@ 2016-07-22 14:24 Quan Xu
  2016-07-22 14:28 ` Emil Condrea
  0 siblings, 1 reply; 15+ messages in thread
From: Quan Xu @ 2016-07-22 14:24 UTC (permalink / raw)
  To: anthony.perard, Emil Condrea
  Cc: qemu-devel, Daniel De Graaf, xen-devel, Stefano Stabellini,
	wei.liu2, stefanb, Eric Blake

Anthony, thanks for your explaination.IMO, patch 1  and patch 2 need your detailed review.. IMO the reset patches are good in general..Emil, if patch 1 / patch 2 are reviewed from anthony, could you send out v10? :) i know it's not an easy task, thanks in advence!!
Quan

On Mon, 18 Jul 2016 15:50:27 +0100, anthony.perard<anthony.perard@citrix.com> wrote:> On Sun, Jul 17, 2016 at 03:41:26PM +0800, Quan Xu wrote:
> -int xenstore_write_int(const char *base, const char *node, int ival)
> -{
> -    char val[12];
> -
> [Quan:]: why 12 ? what about XEN_BUFSIZE? 

That is the number of digit in INT_MAX (10) + 1 for the sign + 1 for '\0'.

> -    snprintf(val, sizeof(val), "%d", ival);
> -    return xenstore_write_str(base, node, val);
> -}
> -
> -int xenstore_write_int64(const char *base, const char *node, int64_t ival)
> -{
> -    char val[21];
> -
> [Quan:]: why 21 ? what about XEN_BUFSIZE?

Same with INT64_MAX (19 digits).

> 
> -    snprintf(val, sizeof(val), "%"PRId64, ival);
> -    return xenstore_write_str(base, node, val);
> -}
> -
> -int xenstore_read_int(const char *base, const char *node, int *ival)
> -{
> -    char *val;
> -    int rc = -1;
> -
> -    val = xenstore_read_str(base, node);
> [Quan:]:  IMO, it is better to initialize val when declares.

I think I prefer it this way.

> -    if (val && 1 == sscanf(val, "%d", ival)) {
> -        rc = 0;
> -    }
> -    g_free(val);
> -    return rc;
> -}

-- 
Anthony PERARD

^ permalink raw reply	[flat|nested] 15+ messages in thread
* [Qemu-devel] [v9 00/19] QEMU:Xen stubdom vTPM for HVM virtual machine(QEMU Part)
@ 2016-07-10 11:47 Emil Condrea
  2016-07-10 11:47 ` [PATCH 01/19] xen: Create a new file xen_pvdev.c Emil Condrea
  0 siblings, 1 reply; 15+ messages in thread
From: Emil Condrea @ 2016-07-10 11:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: xen-devel, quan.xu, dgdegra, stefano.stabellini, wei.liu2,
	stefanb, eblake, emilcondrea

*INTRODUCTION*
The goal of virtual Trusted Platform Module (vTPM) is to provide a TPM
functionality to virtual machines (Fedora, Ubuntu, Redhat, Windows .etc).
This allows programs to interact with a TPM in a virtual machine the same
way they interact with a TPM on the physical system. Each virtual machine
gets its own unique, emulated, software TPM. Each major component of vTPM
is implemented as a stubdom, providing secure separation guaranteed by the
hypervisor.

The vTPM stubdom is a Xen mini-OS domain that emulates a TPM for the virtual
machine to use. It is a small wrapper around the Berlios TPM emulator. TPM
commands are passed from mini-os TPM backend driver.

*ARCHITECTURE*
The architecture of stubdom vTPM for HVM virtual machine:

            +--------------------+
            | Windows/Linux DomU | ...
            |        |  ^        |
            |        v  |        |
            |  Qemu tpm1.2 Tis   |
            |        |  ^        |
            |        v  |        |
            | XenStubdoms backend|
            +--------------------+
                     |  ^
                     v  |
            +--------------------+
            |      XenDevOps     |
            +--------------------+
                     |  ^
                     v  |
            +--------------------+
            |  mini-os/tpmback   |
            |        |  ^        |
            |        v  |        |
            |   vtpm-stubdom     | ...
            |        |  ^        |
            |        v  |        |
            |  mini-os/tpmfront  |
            +--------------------+
                     |  ^
                     v  |
            +--------------------+
            |  mini-os/tpmback   |
            |        |  ^        |
            |        v  |        |
            |  vtpmmgr-stubdom   |
            |        |  ^        |
            |        v  |        |
            |  mini-os/tpm_tis   |
            +--------------------+
                     |  ^
                     v  |
            +--------------------+
            |    Hardware TPM    |
            +--------------------+

 * Windows/Linux DomU:
    The HVM based guest that wants to use a vTPM. There may be
    more than one of these.

 * Qemu tpm1.2 Tis:
    Implementation of the tpm1.2 Tis interface for HVM virtual
    machines. It is Qemu emulation device.

 * vTPM xenstubdoms driver:
    Qemu vTPM driver. This driver provides vtpm initialization
    and sending data and commends to a para-virtualized vtpm
    stubdom.

 * XenDevOps:
    Register Xen stubdom vTPM frontend driver, and transfer any
    request/repond between TPM xenstubdoms driver and Xen vTPM
    stubdom. Facilitate communications between Xen vTPM stubdom
    and vTPM xenstubdoms driver.

 * mini-os/tpmback:
    Mini-os TPM backend driver. The Linux frontend driver connects
    to this backend driver to facilitate communications between the
    Linux DomU and its vTPM. This driver is also used by vtpmmgr
    stubdom to communicate with vtpm-stubdom.

 * vtpm-stubdom:
    A mini-os stub domain that implements a vTPM. There is a
    one to one mapping between running vtpm-stubdom instances and
    logical vtpms on the system. The vTPM Platform Configuration
    Registers (PCRs) are all initialized to zero.

 * mini-os/tpmfront:
    Mini-os TPM frontend driver. The vTPM mini-os domain vtpm
    stubdom uses this driver to communicate with vtpmmgr-stubdom.
    This driver could also be used separately to implement a mini-os
    domain that wishes to use a vTPM of its own.

 * vtpmmgr-stubdom:
    A mini-os domain that implements the vTPM manager. There is only
    one vTPM manager and it should be running during the entire lifetime
    of the machine. vtpmmgr domain securely stores encryption keys for
    each of the vtpms and accesses to the hardware TPM to get the root of
    trust for the entire system.

 * mini-os/tpm_tis:
    Mini-os TPM version 1.2 TPM Interface Specification (TIS) driver.
    This driver used by vtpmmgr-stubdom to talk directly to the hardware
    TPM. Communication is facilitated by mapping hardware memory pages
    into vtpmmgr stubdom.

 * Hardware TPM: The physical TPM 1.2 that is soldered onto the motherboard.

---
Changes in v9
High level changes: (each patch has a detailed history versioning)
 * rebase on upstream qemu
 * refactor qemu xendevs, xenstore functions in order to be shared with both backend and frontends
 * convert tpm stubdoms to new qapi layout
 * use libxengnttab, libxenevtchn stable API instead of xc_* calls
 * added reset_tpm_established_flag and get_tpm_version for TPMDriverOps
 * instead of xen_frontend.c global variable xenstore_dev, use vtpm specific
xenstore_vtpm_dev (since it will be needed just for tpm_xenstubdoms qemu driver)


Emil Condrea (19):
  xen: Create a new file xen_pvdev.c
  xen: Create a new file xen_frontend.c
  xen: Move xenstore_update to xen_pvdev.c
  xen: Move evtchn functions to xen_pvdev.c
  xen: Prepare xendev qtail to be shared with frontends
  xen: Rename xen_be_printf to xen_pv_printf
  xen: Rename xen_be_unbind_evtchn
  xen: Rename xen_be_send_notify
  xen: Rename xen_be_evtchn_event
  xen: Rename xen_be_find_xendev
  xen: Rename xen_be_del_xendev
  xen: Rename xen_be_frontend_changed
  xen: Distinguish between frontend and backend devops
  Qemu-Xen-vTPM: Support for Xen stubdom vTPM command line options
  Qemu-Xen-vTPM: Xen frontend driver infrastructure
  Qemu-Xen-vTPM: Register Xen stubdom vTPM frontend driver
  Qemu-Xen-vTPM: Move tpm_passthrough_is_selftest() into tpm_util.c
  Qemu-Xen-vTPM: Qemu vTPM xenstubdoms backend
  Qemu-Xen-vTPM: QEMU machine class is initialized before tpm_init()

 backends/tpm.c                   |  11 ++
 configure                        |  14 ++
 hmp.c                            |   2 +
 hw/block/xen_disk.c              |  59 +++---
 hw/char/xen_console.c            |  16 +-
 hw/display/xenfb.c               |  57 +++---
 hw/net/xen_nic.c                 |  29 +--
 hw/tpm/Makefile.objs             |   3 +-
 hw/tpm/tpm_passthrough.c         |  13 +-
 hw/tpm/tpm_util.c                |  11 ++
 hw/tpm/tpm_util.h                |   1 +
 hw/tpm/tpm_xenstubdoms.c         | 284 ++++++++++++++++++++++++++
 hw/tpm/xen_vtpm_frontend.c       | 303 ++++++++++++++++++++++++++++
 hw/tpm/xen_vtpm_frontend.h       |  10 +
 hw/usb/xen-usb.c                 |  38 ++--
 hw/xen/Makefile.objs             |   2 +-
 hw/xen/xen_backend.c             | 378 ++++-------------------------------
 hw/xen/xen_devconfig.c           |   4 +-
 hw/xen/xen_frontend.c            | 416 +++++++++++++++++++++++++++++++++++++++
 hw/xen/xen_pvdev.c               | 298 ++++++++++++++++++++++++++++
 include/hw/xen/xen_backend.h     |  71 +------
 include/hw/xen/xen_frontend.h    |  20 ++
 include/hw/xen/xen_pvdev.h       |  83 ++++++++
 include/sysemu/tpm_backend_int.h |   2 +
 qapi-schema.json                 |  16 +-
 qemu-options.hx                  |  13 +-
 tpm.c                            |   7 +-
 vl.c                             |  17 +-
 xen-common.c                     |   4 +-
 xen-hvm.c                        |   6 +
 30 files changed, 1649 insertions(+), 539 deletions(-)
 create mode 100644 hw/tpm/tpm_xenstubdoms.c
 create mode 100644 hw/tpm/xen_vtpm_frontend.c
 create mode 100644 hw/tpm/xen_vtpm_frontend.h
 create mode 100644 hw/xen/xen_frontend.c
 create mode 100644 hw/xen/xen_pvdev.c
 create mode 100644 include/hw/xen/xen_frontend.h
 create mode 100644 include/hw/xen/xen_pvdev.h

-- 
1.9.1

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2016-07-22 14:28 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-17  7:41 [Qemu-devel] [Xen-devel] [PATCH 01/19] xen: Create a new file xen_pvdev.c Quan Xu
2016-07-17  7:41 ` Quan Xu
2016-07-17 17:02 ` Emil Condrea
2016-07-17 17:02 ` [Qemu-devel] [Xen-devel] " Emil Condrea
2016-07-18 14:50 ` Anthony PERARD
2016-07-18 14:50 ` [Qemu-devel] [Xen-devel] " Anthony PERARD
2016-07-18 14:57 ` Eric Blake
2016-07-18 14:57   ` Eric Blake
2016-07-18 16:54   ` Emil Condrea
2016-07-18 16:54   ` [Qemu-devel] [Xen-devel] " Emil Condrea
2016-07-22 14:00   ` Quan Xu
2016-07-22 14:00     ` Quan Xu
  -- strict thread matches above, loose matches on Subject: below --
2016-07-22 14:24 Quan Xu
2016-07-22 14:24 [Qemu-devel] [Xen-devel] " Quan Xu
2016-07-22 14:28 ` Emil Condrea
2016-07-10 11:47 [Qemu-devel] [v9 00/19] QEMU:Xen stubdom vTPM for HVM virtual machine(QEMU Part) Emil Condrea
2016-07-10 11:47 ` [PATCH 01/19] xen: Create a new file xen_pvdev.c Emil Condrea

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.