Re: [Xen-devel] [PATCH 04/19] xen: Move evtchn functions to xen_pvdev.c
On Mon, Jul 25, 2016 at 4:53 PM, Anthony PERARD wrote: > On Sun, Jul 10, 2016 at 02:47:35PM +0300, Emil Condrea wrote: > > The name of the functions moved: > > * xen_be_evtchn_event > > * xen_be_unbind_evtchn > > * xen_be_send_notify > > > > Signed-off-by: Emil Condrea > > --- > > hw/xen/xen_backend.c | 37 + > > hw/xen/xen_pvdev.c | 35 +++ > > include/hw/xen/xen_backend.h | 2 -- > > include/hw/xen/xen_pvdev.h | 4 > > 4 files changed, 40 insertions(+), 38 deletions(-) > > > > diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c > > index 0a9f9bb..5f2821a 100644 > > --- a/hw/xen/xen_backend.c > > +++ b/hw/xen/xen_backend.c > > @@ -693,4 +658,4 @@ static void xenbe_register_types(void) > > type_register_static(&xensysdev_info); > > } > > > > -type_init(xenbe_register_types); > > +type_init(xenbe_register_types); > > \ No newline at end of file > > Looks like this change does not belong to this patch. > Will fix this in v10. > > -- > Anthony PERARD > ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
Re: [Xen-devel] [Qemu-devel] [v9 00/19] QEMU:Xen stubdom vTPM for HVM virtual machine(QEMU Part)
Thanks Anthony for the feedback. I will send v10 containing fixes for patches 1 to 12 + additional patches for fixing code style issues for moved code. On Mon, Jul 25, 2016 at 5:09 PM, Anthony PERARD wrote: > On Sun, Jul 10, 2016 at 02:47:31PM +0300, Emil Condrea wrote: > > 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 > > Patches from 1 to 12 looks fine but ./script/checkpatch.pl reveal some > coding style issue in the code that is moved. Could you fix those issues > in separate patches? (Having separate patches for code movement and for > coding style fix makes it easier to review.) > > I'll start reviewing the more complicated patches now. > > Thanks, > > -- > Anthony PERARD > ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH 15/19] Qemu-Xen-vTPM: Xen frontend driver infrastructure
On Mon, Jul 25, 2016 at 7:01 PM, Anthony PERARD wrote: > > On Sun, Jul 10, 2016 at 02:47:46PM +0300, Emil Condrea wrote: > > This patch adds infrastructure for xen front drivers living in qemu, > > so drivers don't need to implement common stuff on their own. It's > > mostly xenbus management stuff: some functions to access XenStore, > > setting up XenStore watches, callbacks on device discovery and state > > changes, and handle event channel between the virtual machines. > > > > Call xen_fe_register() function to register XenDevOps, and make sure, > > XenDevOps's flags is DEVOPS_FLAG_FE, which is flag bit to point out > > the XenDevOps is Xen frontend. > > > > Signed-off-by: Quan Xu > > Signed-off-by: Emil Condrea > > > > --- > > Changes in v9: > > * xenstore_dev should not be global, it will not work correctly with > > multiple xen frontends living in qemu > > * reuse some common functions: > > - xen_fe_printf -> xen_pv_printf > > - xen_fe_evtchn_event -> xen_pv_evtchn_event > > * use libxenevtchn stable API instead of xc_* calls: > > - xc_evtchn_fd -> xenevtchn_fd > > - xc_evtchn_close -> xenevtchn_close > > - xc_evtchn_bind_unbound_port -> xenevtchn_bind_unbound_port > > --- > > hw/xen/xen_frontend.c | 308 > > ++ > > hw/xen/xen_pvdev.c| 15 ++ > > include/hw/xen/xen_frontend.h | 6 + > > include/hw/xen/xen_pvdev.h| 1 + > > 4 files changed, 330 insertions(+) > > > > diff --git a/hw/xen/xen_frontend.c b/hw/xen/xen_frontend.c > > index 6b92cf1..7b305ce 100644 > > --- a/hw/xen/xen_frontend.c > > +++ b/hw/xen/xen_frontend.c > > @@ -3,6 +3,10 @@ > > * > > * (c) 2008 Gerd Hoffmann > > * > > + * Copyright (c) 2015 Intel Corporation > > + * Authors: > > + *Quan Xu > > + * > > * 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 > > @@ -23,6 +27,8 @@ > > #include "hw/xen/xen_frontend.h" > > #include "hw/xen/xen_backend.h" > > > > +static int debug = 0; > > + > > char *xenstore_read_fe_str(struct XenDevice *xendev, const char *node) > > { > > return xenstore_read_str(xendev->fe, node); > > @@ -86,3 +92,305 @@ void xenstore_update_fe(char *watch, struct XenDevice > > *xendev) > > xen_fe_frontend_changed(xendev, node); > > xen_be_check_state(xendev); > > } > > + > > +struct XenDevice *xen_fe_get_xendev(const char *type, int dom, int dev, > > +char *backend, struct XenDevOps *ops) > > This function looks similare to xen_be_get_xendev(), could they be > shared? > > In any case, there is a few issue with this implementation. There is some special initialization in each function but we can group common behavior in xen_pv_get_xendev which will be called by xen_be_get_xendev and xen_fe_get_xendev > > > +{ > > +struct XenDevice *xendev; > > + > > +xendev = xen_pv_find_xendev(type, dom, dev); > > +if (xendev) { > > +return xendev; > > +} > > + > > +/* init new xendev */ > > +xendev = g_malloc0(ops->size); > > +xendev->type = type; > > +xendev->dom = dom; > > +xendev->dev = dev; > > +xendev->ops = ops; > > + > > +/*return if the ops->flags is not DEVOPS_FLAG_FE*/ > > +if (!(ops->flags & DEVOPS_FLAG_FE)) { > > Here, xendev is leaked. Will fix in v10 > > > > +return NULL; > > +} > > + > > +snprintf(xendev->be, sizeof(xendev->be), "%s", backend); > > +snprintf(xendev->name, sizeof(xendev->name), "%s-%d", > > + xendev->type, xendev->dev); > > + > > +xendev->debug = debug; > > +xendev->local_port = -1; > > + > > +xendev->evtchndev = xenevtchn_open(NULL, 0); > > +if (xendev->evtchndev == NULL) { > > +xen_pv_printf(NULL, 0, "can't open evtchn device\n"); > > +g_free(xendev); > > We could use goto here, so there would be only one cleanup path. Will fix in v10 > > > > +return NULL; > > +} > > +fcntl(xenevtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC); > > + > > +i
[Xen-devel] [PATCH 02/15] xen: Fix coding style warnings
Fixes: * WARNING: line over 80 characters Signed-off-by: Emil Condrea --- hw/block/xen_disk.c | 3 ++- hw/char/xen_console.c| 6 -- hw/display/xenfb.c | 30 -- hw/net/xen_nic.c | 12 hw/xen/xen_backend.c | 15 ++- include/hw/xen/xen_backend.h | 8 +--- 6 files changed, 49 insertions(+), 25 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 5aa350a..24edeb2 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -1068,7 +1068,8 @@ static int blk_connect(struct XenDevice *xendev) blk_set_enable_write_cache(blkdev->blk, !writethrough); } else { /* setup via qemu cmdline -> already setup for us */ -xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n"); +xen_be_printf(&blkdev->xendev, 2, + "get configured bdrv (cmdline setup)\n"); blkdev->blk = blk_by_legacy_dinfo(blkdev->dinfo); if (blk_is_read_only(blkdev->blk) && !readonly) { xen_be_printf(&blkdev->xendev, 0, "Unexpected read-only drive"); diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 4e35c82..399bb5d 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -156,7 +156,8 @@ static void xencons_send(struct XenConsole *con) if (len < 1) { if (!con->backlog) { con->backlog = 1; -xen_be_printf(&con->xendev, 1, "backlog piling up, nobody listening?\n"); +xen_be_printf(&con->xendev, 1, + "backlog piling up, nobody listening?\n"); } } else { buffer_advance(&con->buffer, len); @@ -247,7 +248,8 @@ static int con_initialise(struct XenDevice *xendev) } } -xen_be_printf(xendev, 1, "ring mfn %d, remote port %d, local port %d, limit %zd\n", +xen_be_printf(xendev, 1, + "ring mfn %d, remote port %d, local port %d, limit %zd\n", con->ring_ref, con->xendev.remote_port, con->xendev.local_port, diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index a9a93f9..9bcf60b 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -511,38 +511,45 @@ static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, int max_width, max_height; if (fb_len_lim > fb_len_max) { -xen_be_printf(&xenfb->c.xendev, 0, "fb size limit %zu exceeds %zu, corrected\n", +xen_be_printf(&xenfb->c.xendev, 0, + "fb size limit %zu exceeds %zu, corrected\n", fb_len_lim, fb_len_max); fb_len_lim = fb_len_max; } if (fb_len_lim && fb_len > fb_len_lim) { -xen_be_printf(&xenfb->c.xendev, 0, "frontend fb size %zu limited to %zu\n", +xen_be_printf(&xenfb->c.xendev, 0, + "frontend fb size %zu limited to %zu\n", fb_len, fb_len_lim); fb_len = fb_len_lim; } if (depth != 8 && depth != 16 && depth != 24 && depth != 32) { -xen_be_printf(&xenfb->c.xendev, 0, "can't handle frontend fb depth %d\n", +xen_be_printf(&xenfb->c.xendev, 0, + "can't handle frontend fb depth %d\n", depth); return -1; } if (row_stride <= 0 || row_stride > fb_len) { -xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend stride %d\n", row_stride); +xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend stride %d\n", + row_stride); return -1; } max_width = row_stride / (depth / 8); if (width < 0 || width > max_width) { -xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend width %d limited to %d\n", +xen_be_printf(&xenfb->c.xendev, 0, + "invalid frontend width %d limited to %d\n", width, max_width); width = max_width; } if (offset < 0 || offset >= fb_len) { -xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend offset %d (max %zu)\n", +xen_be_printf(&xenfb->c.xendev, 0, + "invalid frontend offset %d (max %zu)\n", offset, fb_len - 1); return -1; } max_height = (fb_len - offset) / row_stride; if (height < 0 || height > max_height) { -xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend height %d limited to %d\n", +xen_be_printf(&xenfb->c.xendev, 0,
[Xen-devel] [PATCH 04/15] xen: Create a new file xen_frontend.c
Its purpose is to store frontend related functions. Signed-off-by: Quan Xu Signed-off-by: Emil Condrea --- hw/block/xen_disk.c | 1 + hw/display/xenfb.c| 1 + hw/net/xen_nic.c | 1 + hw/usb/xen-usb.c | 1 + hw/xen/Makefile.objs | 2 +- hw/xen/xen_backend.c | 49 + hw/xen/xen_frontend.c | 72 +++ include/hw/xen/xen_backend.h | 4 --- include/hw/xen/xen_frontend.h | 11 +++ 9 files changed, 89 insertions(+), 53 deletions(-) create mode 100644 hw/xen/xen_frontend.c create mode 100644 include/hw/xen/xen_frontend.h diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 24edeb2..0b2db3b 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -25,6 +25,7 @@ #include "hw/hw.h" #include "hw/xen/xen_backend.h" +#include "hw/xen/xen_frontend.h" #include "xen_blkif.h" #include "sysemu/blockdev.h" #include "sysemu/block-backend.h" diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 9bcf60b..9b10b35 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -30,6 +30,7 @@ #include "ui/console.h" #include "sysemu/char.h" #include "hw/xen/xen_backend.h" +#include "hw/xen/xen_frontend.h" #include #include diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 30efe47..8db3448 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -29,6 +29,7 @@ #include "net/checksum.h" #include "net/util.h" #include "hw/xen/xen_backend.h" +#include "hw/xen/xen_frontend.h" #include diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c index 174d715..10773f2 100644 --- a/hw/usb/xen-usb.c +++ b/hw/usb/xen-usb.c @@ -28,6 +28,7 @@ #include "hw/sysbus.h" #include "hw/usb.h" #include "hw/xen/xen_backend.h" +#include "hw/xen/xen_frontend.h" #include "monitor/qdev.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qint.h" diff --git a/hw/xen/Makefile.objs b/hw/xen/Makefile.objs index 591cdc2..1000294 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 xen_pvdev.o +common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_frontend.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 84142d8..d4880e1 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_frontend.h" #include "hw/xen/xen_pvdev.h" #include @@ -125,22 +126,6 @@ int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int *ival) return xenstore_read_int(xendev->be, node, ival); } -char *xenstore_read_fe_str(struct XenDevice *xendev, const char *node) -{ -return xenstore_read_str(xendev->fe, node); -} - -int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival) -{ -return xenstore_read_int(xendev->fe, node, ival); -} - -int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, -uint64_t *uval) -{ -return xenstore_read_uint64(xendev->fe, node, uval); -} - /* - */ int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state) @@ -283,38 +268,6 @@ static void xen_be_backend_changed(struct XenDevice *xendev, const char *node) } } -static void xen_be_frontend_changed(struct XenDevice *xendev, const char *node) -{ -int fe_state; - -if (node == NULL || strcmp(node, "state") == 0) { -if (xenstore_read_fe_int(xendev, "state", &fe_state) == -1) { -fe_state = XenbusStateUnknown; -} -if (xendev->fe_state != fe_state) { -xen_be_printf(xendev, 1, "frontend state: %s -> %s\n", - xenbus_strstate(xendev->fe_state), - xenbus_strstate(fe_state)); -} -xendev->fe_state = fe_state; -} -if (node == NULL || strcmp(node, "protocol") == 0) { -g_free(xendev->protocol); -xendev->protocol = xenstore_read_fe_str(xendev, "protocol"); -if (xendev->protocol) { -xen_be_printf(xendev, 1, "frontend protocol: %s\n", -xendev->protocol); -} -} - -if (node) { -xen_be_printf(xendev,
[Xen-devel] [PATCH 07/15] xen: Prepare xendev qtail to be shared with frontends
* move xendevs qtail to xen_pvdev.c * change xen_be_get_xendev to use a new function: xen_pv_insert_xendev Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 51 +- hw/xen/xen_pvdev.c| 57 +++ include/hw/xen/xen_backend.h | 1 - include/hw/xen/xen_frontend.h | 2 ++ include/hw/xen/xen_pvdev.h| 4 +++ 5 files changed, 64 insertions(+), 51 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index c7db068..d572cd0 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -55,8 +55,6 @@ struct xs_dirs { static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = QTAILQ_HEAD_INITIALIZER(xs_cleanup); -static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = -QTAILQ_HEAD_INITIALIZER(xendevs); static int debug; static void xenstore_cleanup_dir(char *dir) @@ -142,27 +140,6 @@ int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state) return 0; } -/* - */ - -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) -{ -struct XenDevice *xendev; - -QTAILQ_FOREACH(xendev, &xendevs, next) { -if (xendev->dom != dom) { -continue; -} -if (xendev->dev != dev) { -continue; -} -if (strcmp(xendev->type, type) != 0) { -continue; -} -return xendev; -} -return NULL; -} - /* * get xen backend device, allocate a new one if it doesn't exist. */ @@ -211,7 +188,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, xendev->gnttabdev = NULL; } -QTAILQ_INSERT_TAIL(&xendevs, xendev, next); +xen_pv_insert_xendev(xendev); if (xendev->ops->alloc) { xendev->ops->alloc(xendev); @@ -220,32 +197,6 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, return xendev; } -/* - * release xen backend device. - */ -static void xen_be_del_xendev(struct XenDevice *xendev) -{ -if (xendev->ops->free) { -xendev->ops->free(xendev); -} - -if (xendev->fe) { -char token[XEN_BUFSIZE]; -snprintf(token, sizeof(token), "fe:%p", xendev); -xs_unwatch(xenstore, xendev->fe, token); -g_free(xendev->fe); -} - -if (xendev->evtchndev != NULL) { -xenevtchn_close(xendev->evtchndev); -} -if (xendev->gnttabdev != NULL) { -xengnttab_close(xendev->gnttabdev); -} - -QTAILQ_REMOVE(&xendevs, xendev, next); -g_free(xendev); -} /* * Sync internal data structures on xenstore updates. diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 91101fd..72e2e79 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -23,7 +23,11 @@ #include "hw/xen/xen_frontend.h" #include "hw/xen/xen_pvdev.h" +/* private */ static int debug; +static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = +QTAILQ_HEAD_INITIALIZER(xendevs); + /* - */ int xenstore_write_str(const char *base, const char *node, const char *val) @@ -207,3 +211,56 @@ int xen_be_send_notify(struct XenDevice *xendev) { return xenevtchn_notify(xendev->evtchndev, xendev->local_port); } + +/* - */ + +struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) +{ +struct XenDevice *xendev; + +QTAILQ_FOREACH(xendev, &xendevs, next) { +if (xendev->dom != dom) { +continue; +} +if (xendev->dev != dev) { +continue; +} +if (strcmp(xendev->type, type) != 0) { +continue; +} +return xendev; +} +return NULL; +} + +/* + * release xen backend device. + */ +void xen_be_del_xendev(struct XenDevice *xendev) +{ +if (xendev->ops->free) { +xendev->ops->free(xendev); +} + +if (xendev->fe) { +char token[XEN_BUFSIZE]; +snprintf(token, sizeof(token), "fe:%p", xendev); +xs_unwatch(xenstore, xendev->fe, token); +g_free(xendev->fe); +} + +if (xendev->evtchndev != NULL) { +xenevtchn_close(xendev->evtchndev); +} +if (xendev->gnttabdev != NULL) { +xengnttab_close(xendev->gnttabdev); +} + +QTAILQ_REMOVE(&xendevs, xendev, next); +g_free(xendev); +} + +void xen_pv_insert_xendev(struct XenDevice *xendev) +{ +QTAILQ_INSERT_TAIL(&xendevs, xendev, next); +} diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index d0dbee5..64d4fe3 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -22,7 +22,6 @@ int xenstore_read_be_int(struct XenDevice
[Xen-devel] [PATCH 06/15] xen: Move evtchn functions to xen_pvdev.c
The name of the functions moved: * xen_be_evtchn_event * xen_be_unbind_evtchn * xen_be_send_notify Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 35 --- hw/xen/xen_pvdev.c | 35 +++ include/hw/xen/xen_backend.h | 2 -- include/hw/xen/xen_pvdev.h | 4 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 6b03c50..c7db068 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -543,25 +543,6 @@ void xenstore_update_be(char *watch, char *type, int dom, } } -static void xen_be_evtchn_event(void *opaque) -{ -struct XenDevice *xendev = opaque; -evtchn_port_t port; - -port = xenevtchn_pending(xendev->evtchndev); -if (port != xendev->local_port) { -xen_be_printf(xendev, 0, - "xenevtchn_pending returned %d (expected %d)\n", - port, xendev->local_port); -return; -} -xenevtchn_unmask(xendev->evtchndev, port); - -if (xendev->ops->event) { -xendev->ops->event(xendev); -} -} - /* */ int xen_be_init(void) @@ -638,22 +619,6 @@ int xen_be_bind_evtchn(struct XenDevice *xendev) return 0; } -void xen_be_unbind_evtchn(struct XenDevice *xendev) -{ -if (xendev->local_port == -1) { -return; -} -qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), NULL, NULL, NULL); -xenevtchn_unbind(xendev->evtchndev, xendev->local_port); -xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port); -xendev->local_port = -1; -} - -int xen_be_send_notify(struct XenDevice *xendev) -{ -return xenevtchn_notify(xendev->evtchndev, xendev->local_port); -} - static int xen_sysdev_init(SysBusDevice *dev) { diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 35d3be6..91101fd 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -172,3 +172,38 @@ void xen_be_printf(struct XenDevice *xendev, int msg_level, } qemu_log_flush(); } + +void xen_be_evtchn_event(void *opaque) +{ +struct XenDevice *xendev = opaque; +evtchn_port_t port; + +port = xenevtchn_pending(xendev->evtchndev); +if (port != xendev->local_port) { +xen_be_printf(xendev, 0, + "xenevtchn_pending returned %d (expected %d)\n", + port, xendev->local_port); +return; +} +xenevtchn_unmask(xendev->evtchndev, port); + +if (xendev->ops->event) { +xendev->ops->event(xendev); +} +} + +void xen_be_unbind_evtchn(struct XenDevice *xendev) +{ +if (xendev->local_port == -1) { +return; +} +qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), NULL, NULL, NULL); +xenevtchn_unbind(xendev->evtchndev, xendev->local_port); +xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port); +xendev->local_port = -1; +} + +int xen_be_send_notify(struct XenDevice *xendev) +{ +return xenevtchn_notify(xendev->evtchndev, xendev->local_port); +} diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 965a39a..d0dbee5 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -31,8 +31,6 @@ void xen_be_register_common(void); int xen_be_register(const char *type, struct XenDevOps *ops); 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); /* 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 index 3a9a4a4..cf44a87 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -64,6 +64,10 @@ void xenstore_update(void *unused); const char *xenbus_strstate(enum xenbus_state state); +void xen_be_evtchn_event(void *opaque); +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); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 01/15] xen: Fix coding style errors
Fixes the following errors: * ERROR: line over 90 characters * ERROR: code indent should never use tabs * ERROR: space prohibited after that open square bracket '[' * ERROR: do not initialise statics to 0 or NULL * ERROR: "(foo*)" should be "(foo *)" Signed-off-by: Emil Condrea --- hw/char/xen_console.c | 20 ++--- hw/display/xenfb.c| 83 ++- hw/net/xen_nic.c | 8 +++-- hw/xen/xen_backend.c | 20 ++--- 4 files changed, 67 insertions(+), 64 deletions(-) diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 83108b0..4e35c82 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -154,16 +154,16 @@ static void xencons_send(struct XenConsole *con) else len = size; if (len < 1) { - if (!con->backlog) { - con->backlog = 1; - xen_be_printf(&con->xendev, 1, "backlog piling up, nobody listening?\n"); - } +if (!con->backlog) { +con->backlog = 1; +xen_be_printf(&con->xendev, 1, "backlog piling up, nobody listening?\n"); +} } else { - buffer_advance(&con->buffer, len); - if (con->backlog && len == size) { - con->backlog = 0; - xen_be_printf(&con->xendev, 1, "backlog is gone\n"); - } +buffer_advance(&con->buffer, len); +if (con->backlog && len == size) { +con->backlog = 0; +xen_be_printf(&con->xendev, 1, "backlog is gone\n"); +} } } @@ -187,7 +187,7 @@ static int con_init(struct XenDevice *xendev) type = xenstore_read_str(con->console, "type"); if (!type || strcmp(type, "ioemu") != 0) { - xen_be_printf(xendev, 1, "not for me (type=%s)\n", type); +xen_be_printf(xendev, 1, "not for me (type=%s)\n", type); ret = -1; goto out; } diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 46b7d5e..a9a93f9 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -90,21 +90,22 @@ static int common_bind(struct common *c) xen_pfn_t mfn; if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &val) == -1) - return -1; +return -1; mfn = (xen_pfn_t)val; assert(val == mfn); if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1) - return -1; +return -1; c->page = xenforeignmemory_map(xen_fmem, c->xendev.dom, PROT_READ | PROT_WRITE, 1, &mfn, NULL); if (c->page == NULL) - return -1; +return -1; xen_be_bind_evtchn(&c->xendev); -xen_be_printf(&c->xendev, 1, "ring mfn %"PRI_xen_pfn", remote-port %d, local-port %d\n", - mfn, c->xendev.remote_port, c->xendev.local_port); +xen_be_printf(&c->xendev, 1, + "ring mfn %"PRI_xen_pfn", remote-port %d, local-port %d\n", + mfn, c->xendev.remote_port, c->xendev.local_port); return 0; } @@ -500,8 +501,8 @@ out: } static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, - int width, int height, int depth, - size_t fb_len, int offset, int row_stride) + int width, int height, int depth, + size_t fb_len, int offset, int row_stride) { size_t mfn_sz = sizeof(*((struct xenfb_page *)0)->pd); size_t pd_len = sizeof(((struct xenfb_page *)0)->pd) / mfn_sz; @@ -510,40 +511,40 @@ static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, int max_width, max_height; if (fb_len_lim > fb_len_max) { - xen_be_printf(&xenfb->c.xendev, 0, "fb size limit %zu exceeds %zu, corrected\n", - fb_len_lim, fb_len_max); - fb_len_lim = fb_len_max; +xen_be_printf(&xenfb->c.xendev, 0, "fb size limit %zu exceeds %zu, corrected\n", + fb_len_lim, fb_len_max); +fb_len_lim = fb_len_max; } if (fb_len_lim && fb_len > fb_len_lim) { - xen_be_printf(&xenfb->c.xendev, 0, "frontend fb size %zu limited to %zu\n", - fb_len, fb_len_lim); - fb_len = fb_len_lim; +xen_be_printf(&xenfb->c.xendev, 0, "frontend fb size %zu limited to %zu\n", + fb_len, fb_len_lim); +fb_len = fb_len_lim; } if (depth != 8 && depth != 16 && depth != 24 && depth != 32) { - xen_be_printf(&xenfb->c.xendev, 0, "can't handle front
[Xen-devel] [PATCH 00/15] Refactor common part of xen backend and frontend
This patch series was splitted from QEMU:Xen stubdom vTPM for HVM virtual machine http://markmail.org/message/fkix7g3a5zdj7lvr It contains a reorganization of xen backend and frontend functions together with code style fixes. Common functions shared by backends and frontends are moved to xen_pvdev file. Emil Condrea (15): xen: Fix coding style errors xen: Fix coding style warnings 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: Move xenstore cleanup and mkdir functions 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 hw/block/xen_disk.c | 66 +++ hw/char/xen_console.c | 32 ++-- hw/display/xenfb.c| 128 -- hw/net/xen_nic.c | 37 ++-- hw/usb/xen-usb.c | 47 ++--- hw/xen/Makefile.objs | 2 +- hw/xen/xen_backend.c | 400 -- hw/xen/xen_devconfig.c| 4 +- hw/xen/xen_frontend.c | 90 ++ hw/xen/xen_pvdev.c| 317 + include/hw/xen/xen_backend.h | 71 +--- include/hw/xen/xen_frontend.h | 14 ++ include/hw/xen/xen_pvdev.h| 78 xen-common.c | 4 +- 14 files changed, 704 insertions(+), 586 deletions(-) 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 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 11/15] xen: Rename xen_be_send_notify
Prepare xen_be_send_notify to be shared with frontends: * xen_be_send_notify -> xen_pv_send_notify Signed-off-by: Emil Condrea --- hw/block/xen_disk.c| 4 ++-- hw/char/xen_console.c | 4 ++-- hw/display/xenfb.c | 8 hw/net/xen_nic.c | 4 ++-- hw/usb/xen-usb.c | 6 +++--- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 3688a4b..799ee25 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -797,7 +797,7 @@ static void blk_send_response_all(struct XenBlkDev *blkdev) ioreq_release(ioreq, true); } if (send_notify) { -xen_be_send_notify(&blkdev->xendev); +xen_pv_send_notify(&blkdev->xendev); } } @@ -867,7 +867,7 @@ static void blk_handle_requests(struct XenBlkDev *blkdev) }; if (blk_send_response_one(ioreq)) { -xen_be_send_notify(&blkdev->xendev); +xen_pv_send_notify(&blkdev->xendev); } ioreq_release(ioreq, false); continue; diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 6dc2d81..dbe4755 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -72,7 +72,7 @@ static void buffer_append(struct XenConsole *con) xen_mb(); intf->out_cons = cons; -xen_be_send_notify(&con->xendev); +xen_pv_send_notify(&con->xendev); if (buffer->max_capacity && buffer->size > buffer->max_capacity) { @@ -140,7 +140,7 @@ static void xencons_receive(void *opaque, const uint8_t *buf, int len) } xen_wmb(); intf->in_prod = prod; -xen_be_send_notify(&con->xendev); +xen_pv_send_notify(&con->xendev); } static void xencons_send(struct XenConsole *con) diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index a86d990..9a7b298 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -216,7 +216,7 @@ static int xenfb_kbd_event(struct XenInput *xenfb, XENKBD_IN_RING_REF(page, prod) = *event; xen_wmb(); /* ensure ring contents visible */ page->in_prod = prod + 1; -return xen_be_send_notify(&xenfb->c.xendev); +return xen_pv_send_notify(&xenfb->c.xendev); } /* Send a keyboard (or mouse button) event */ @@ -398,7 +398,7 @@ static void input_event(struct XenDevice *xendev) if (page->out_prod == page->out_cons) return; page->out_cons = page->out_prod; -xen_be_send_notify(&xenfb->c.xendev); +xen_pv_send_notify(&xenfb->c.xendev); } /* */ @@ -673,7 +673,7 @@ static void xenfb_send_event(struct XenFB *xenfb, union xenfb_in_event *event) xen_wmb(); /* ensure ring contents visible */ page->in_prod = prod + 1; -xen_be_send_notify(&xenfb->c.xendev); +xen_pv_send_notify(&xenfb->c.xendev); } static void xenfb_send_refresh_period(struct XenFB *xenfb, int period) @@ -946,7 +946,7 @@ static void fb_event(struct XenDevice *xendev) struct XenFB *xenfb = container_of(xendev, struct XenFB, c.xendev); xenfb_handle_events(xenfb); -xen_be_send_notify(&xenfb->c.xendev); +xen_pv_send_notify(&xenfb->c.xendev); } /* */ diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index c6af5dc..89a2f43 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -70,7 +70,7 @@ static void net_tx_response(struct XenNetDev *netdev, netif_tx_request_t *txp, i netdev->tx_ring.rsp_prod_pvt = ++i; RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netdev->tx_ring, notify); if (notify) { -xen_be_send_notify(&netdev->xendev); +xen_pv_send_notify(&netdev->xendev); } if (i == netdev->tx_ring.req_cons) { @@ -222,7 +222,7 @@ static void net_rx_response(struct XenNetDev *netdev, netdev->rx_ring.rsp_prod_pvt = ++i; RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netdev->rx_ring, notify); if (notify) { -xen_be_send_notify(&netdev->xendev); +xen_pv_send_notify(&netdev->xendev); } } diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c index f93c73d..7b0abf4 100644 --- a/hw/usb/xen-usb.c +++ b/hw/usb/xen-usb.c @@ -315,7 +315,7 @@ static void usbback_do_response(struct usbback_req *usbback_req, int32_t status, RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&usbif->urb_ring, notify); if (notify) { -xen_be_send_notify(xendev); +xen_pv_send_notify(xendev); } } @@ -591,7 +591,7 @@ static void usbback_hotplug_notify(struct usbback_info *usbif) /* Check for full ring. */ if ((RING_SIZE(ring) - ring-
[Xen-devel] [PATCH 03/15] xen: Create a new file xen_pvdev.c
The purpose of the new file is to store generic functions shared by frontend and backends such as xenstore operations, xendevs. Signed-off-by: Quan Xu Signed-off-by: Emil Condrea --- hw/xen/Makefile.objs | 2 +- hw/xen/xen_backend.c | 126 +--- hw/xen/xen_pvdev.c | 150 +++ include/hw/xen/xen_backend.h | 64 +- include/hw/xen/xen_pvdev.h | 69 5 files changed, 222 insertions(+), 189 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 0aca6ae..84142d8 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 @@ -57,8 +58,6 @@ static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs); static int debug; -/* - */ - static void xenstore_cleanup_dir(char *dir) { struct xs_dirs *d; @@ -77,34 +76,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] = { @@ -129,48 +100,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]; - -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; -} - int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val) { return xenstore_write_str(xendev->be, node, val); @@ -214,20 +143,6 @@ int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, /* - */ -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; @@ -827,45 +742,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)
[Xen-devel] [PATCH 13/15] xen: Rename xen_be_find_xendev
Prepare xen_be_find_xendev to be shared with frontends: * xen_be_find_xendev -> xen_pv_find_xendev Signed-off-by: Emil Condrea --- hw/display/xenfb.c | 4 ++-- hw/xen/xen_backend.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 9a7b298..52020b3 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -989,8 +989,8 @@ void xen_init_display(int domid) wait_more: i++; main_loop_wait(true); -xfb = xen_be_find_xendev("vfb", domid, 0); -xin = xen_be_find_xendev("vkbd", domid, 0); +xfb = xen_pv_find_xendev("vfb", domid, 0); +xin = xen_pv_find_xendev("vkbd", domid, 0); if (!xfb || !xin) { if (i < 256) { usleep(1); diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index b6c11a1..5c41524 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -99,7 +99,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, { struct XenDevice *xendev; -xendev = xen_be_find_xendev(type, dom, dev); +xendev = xen_pv_find_xendev(type, dom, dev); if (xendev) { return xendev; } diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 1c2cb98..69cf7af 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -265,7 +265,7 @@ int xen_pv_send_notify(struct XenDevice *xendev) /* - */ -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) +struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev) { struct XenDevice *xendev; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index 46560a1..550bf69 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -67,7 +67,7 @@ const char *xenbus_strstate(enum xenbus_state state); void xen_pv_evtchn_event(void *opaque); void xen_pv_insert_xendev(struct XenDevice *xendev); void xen_be_del_xendev(struct XenDevice *xendev); -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); +struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev); void xen_pv_unbind_evtchn(struct XenDevice *xendev); int xen_pv_send_notify(struct XenDevice *xendev); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 09/15] xen: Rename xen_be_printf to xen_pv_printf
Prepare xen_be_printf to be used by both backend and frontends: * xen_be_printf -> xen_pv_printf Signed-off-by: Emil Condrea --- hw/block/xen_disk.c| 58 +++--- hw/char/xen_console.c | 10 hw/display/xenfb.c | 42 - hw/net/xen_nic.c | 22 +- hw/usb/xen-usb.c | 38 +++--- hw/xen/xen_backend.c | 40 hw/xen/xen_devconfig.c | 4 ++-- hw/xen/xen_frontend.c | 6 ++--- hw/xen/xen_pvdev.c | 10 include/hw/xen/xen_pvdev.h | 2 +- xen-common.c | 4 ++-- 11 files changed, 118 insertions(+), 118 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 0b2db3b..425efba 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -168,12 +168,12 @@ static void destroy_grant(gpointer pgnt) xengnttab_handle *gnt = grant->blkdev->xendev.gnttabdev; if (xengnttab_unmap(gnt, grant->page, 1) != 0) { -xen_be_printf(&grant->blkdev->xendev, 0, +xen_pv_printf(&grant->blkdev->xendev, 0, "xengnttab_unmap failed: %s\n", strerror(errno)); } grant->blkdev->persistent_gnt_count--; -xen_be_printf(&grant->blkdev->xendev, 3, +xen_pv_printf(&grant->blkdev->xendev, 3, "unmapped grant %p\n", grant->page); g_free(grant); } @@ -185,11 +185,11 @@ static void remove_persistent_region(gpointer data, gpointer dev) xengnttab_handle *gnt = blkdev->xendev.gnttabdev; if (xengnttab_unmap(gnt, region->addr, region->num) != 0) { -xen_be_printf(&blkdev->xendev, 0, +xen_pv_printf(&blkdev->xendev, 0, "xengnttab_unmap region %p failed: %s\n", region->addr, strerror(errno)); } -xen_be_printf(&blkdev->xendev, 3, +xen_pv_printf(&blkdev->xendev, 3, "unmapped grant region %p with %d pages\n", region->addr, region->num); g_free(region); @@ -256,7 +256,7 @@ static int ioreq_parse(struct ioreq *ioreq) size_t len; int i; -xen_be_printf(&blkdev->xendev, 3, +xen_pv_printf(&blkdev->xendev, 3, "op %d, nr %d, handle %d, id %" PRId64 ", sector %" PRId64 "\n", ioreq->req.operation, ioreq->req.nr_segments, ioreq->req.handle, ioreq->req.id, ioreq->req.sector_number); @@ -276,28 +276,28 @@ static int ioreq_parse(struct ioreq *ioreq) case BLKIF_OP_DISCARD: return 0; default: -xen_be_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n", +xen_pv_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n", ioreq->req.operation); goto err; }; if (ioreq->req.operation != BLKIF_OP_READ && blkdev->mode[0] != 'w') { -xen_be_printf(&blkdev->xendev, 0, "error: write req for ro device\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: write req for ro device\n"); goto err; } ioreq->start = ioreq->req.sector_number * blkdev->file_blk; for (i = 0; i < ioreq->req.nr_segments; i++) { if (i == BLKIF_MAX_SEGMENTS_PER_REQUEST) { -xen_be_printf(&blkdev->xendev, 0, "error: nr_segments too big\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: nr_segments too big\n"); goto err; } if (ioreq->req.seg[i].first_sect > ioreq->req.seg[i].last_sect) { -xen_be_printf(&blkdev->xendev, 0, "error: first > last sector\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: first > last sector\n"); goto err; } if (ioreq->req.seg[i].last_sect * BLOCK_SIZE >= XC_PAGE_SIZE) { -xen_be_printf(&blkdev->xendev, 0, "error: page crossing\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: page crossing\n"); goto err; } @@ -309,7 +309,7 @@ static int ioreq_parse(struct ioreq *ioreq) qemu_iovec_add(&ioreq->v, (void*)mem, len); } if (ioreq->start + ioreq->v.size > blkdev->file_size) { -xen_be_printf(&blkdev->xendev, 0, "error: access beyond end of file\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: access beyond end of file\n"); goto err; } return 0; @@ -332,7 +332,7 @@ static void ioreq_unmap(struct ioreq *ioreq)
[Xen-devel] [PATCH 14/15] xen: Rename xen_be_del_xendev
Prepare xen_be_del_xendev to be shared with frontends: * xen_be_del_xendev -> xen_pv_del_xendev Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 5c41524..30d3aaa 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -436,7 +436,7 @@ void xenstore_update_be(char *watch, char *type, int dom, if (xendev != NULL) { bepath = xs_read(xenstore, 0, xendev->be, &len); if (bepath == NULL) { -xen_be_del_xendev(xendev); +xen_pv_del_xendev(xendev); } else { free(bepath); xen_be_backend_changed(xendev, path); diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 69cf7af..9bc4b38 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -287,7 +287,7 @@ struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev) /* * release xen backend device. */ -void xen_be_del_xendev(struct XenDevice *xendev) +void xen_pv_del_xendev(struct XenDevice *xendev) { if (xendev->ops->free) { xendev->ops->free(xendev); diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index 550bf69..dfe91c1 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -66,7 +66,7 @@ const char *xenbus_strstate(enum xenbus_state state); void xen_pv_evtchn_event(void *opaque); void xen_pv_insert_xendev(struct XenDevice *xendev); -void xen_be_del_xendev(struct XenDevice *xendev); +void xen_pv_del_xendev(struct XenDevice *xendev); struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev); void xen_pv_unbind_evtchn(struct XenDevice *xendev); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 10/15] xen: Rename xen_be_unbind_evtchn
Prepare xen_be_unbind_evtchn to be shared with frontends: * xen_be_unbind_evtchn -> xen_pv_unbind_evtchn Signed-off-by: Emil Condrea --- hw/block/xen_disk.c| 2 +- hw/char/xen_console.c | 2 +- hw/display/xenfb.c | 2 +- hw/net/xen_nic.c | 2 +- hw/usb/xen-usb.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 425efba..3688a4b 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -1195,7 +1195,7 @@ static void blk_disconnect(struct XenDevice *xendev) blk_unref(blkdev->blk); blkdev->blk = NULL; } -xen_be_unbind_evtchn(&blkdev->xendev); +xen_pv_unbind_evtchn(&blkdev->xendev); if (blkdev->sring) { xengnttab_unmap(blkdev->xendev.gnttabdev, blkdev->sring, 1); diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index b705a06..6dc2d81 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -265,7 +265,7 @@ static void con_disconnect(struct XenDevice *xendev) qemu_chr_add_handlers(con->chr, NULL, NULL, NULL, NULL); qemu_chr_fe_release(con->chr); } -xen_be_unbind_evtchn(&con->xendev); +xen_pv_unbind_evtchn(&con->xendev); if (con->sring) { if (!xendev->dev) { diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 55aca85..a86d990 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -113,7 +113,7 @@ static int common_bind(struct common *c) static void common_unbind(struct common *c) { -xen_be_unbind_evtchn(&c->xendev); +xen_pv_unbind_evtchn(&c->xendev); if (c->page) { xenforeignmemory_unmap(xen_fmem, c->page, 1); c->page = NULL; diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 7418a7b..c6af5dc 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -373,7 +373,7 @@ static void net_disconnect(struct XenDevice *xendev) { struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev); -xen_be_unbind_evtchn(&netdev->xendev); +xen_pv_unbind_evtchn(&netdev->xendev); if (netdev->txs) { xengnttab_unmap(netdev->xendev.gnttabdev, netdev->txs, 1); diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c index a245355..f93c73d 100644 --- a/hw/usb/xen-usb.c +++ b/hw/usb/xen-usb.c @@ -835,7 +835,7 @@ static void usbback_disconnect(struct XenDevice *xendev) usbif = container_of(xendev, struct usbback_info, xendev); -xen_be_unbind_evtchn(xendev); +xen_pv_unbind_evtchn(xendev); if (usbif->urb_sring) { xengnttab_unmap(xendev->gnttabdev, usbif->urb_sring, 1); diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 15bf95c..85f7430 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -247,7 +247,7 @@ void xen_be_evtchn_event(void *opaque) } } -void xen_be_unbind_evtchn(struct XenDevice *xendev) +void xen_pv_unbind_evtchn(struct XenDevice *xendev) { if (xendev->local_port == -1) { return; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index cf26ce5..bc8a3ea 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -69,7 +69,7 @@ void xen_pv_insert_xendev(struct XenDevice *xendev); void xen_be_del_xendev(struct XenDevice *xendev); struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); -void xen_be_unbind_evtchn(struct XenDevice *xendev); +void xen_pv_unbind_evtchn(struct XenDevice *xendev); int xen_be_send_notify(struct XenDevice *xendev); void xen_pv_printf(struct XenDevice *xendev, int msg_level, -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 15/15] xen: Rename xen_be_frontend_changed
xen_be_frontend_changed -> xen_fe_frontend_changed Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 2 +- hw/xen/xen_frontend.c | 4 ++-- include/hw/xen/xen_frontend.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 30d3aaa..b79e83e 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -213,7 +213,7 @@ static int xen_be_try_setup(struct XenDevice *xendev) xen_be_set_state(xendev, XenbusStateInitialising); xen_be_backend_changed(xendev, NULL); -xen_be_frontend_changed(xendev, NULL); +xen_fe_frontend_changed(xendev, NULL); return 0; } diff --git a/hw/xen/xen_frontend.c b/hw/xen/xen_frontend.c index 1407f5f..761688b 100644 --- a/hw/xen/xen_frontend.c +++ b/hw/xen/xen_frontend.c @@ -39,7 +39,7 @@ int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, return xenstore_read_uint64(xendev->fe, node, uval); } -void xen_be_frontend_changed(struct XenDevice *xendev, const char *node) +void xen_fe_frontend_changed(struct XenDevice *xendev, const char *node) { int fe_state; @@ -85,6 +85,6 @@ void xenstore_update_fe(char *watch, struct XenDevice *xendev) } node = watch + len + 1; -xen_be_frontend_changed(xendev, node); +xen_fe_frontend_changed(xendev, node); xen_be_check_state(xendev); } diff --git a/include/hw/xen/xen_frontend.h b/include/hw/xen/xen_frontend.h index bb0bc23..2a5f03f 100644 --- a/include/hw/xen/xen_frontend.h +++ b/include/hw/xen/xen_frontend.h @@ -9,6 +9,6 @@ int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, uint64_t *uval); void xenstore_update_fe(char *watch, struct XenDevice *xendev); -void xen_be_frontend_changed(struct XenDevice *xendev, const char *node); +void xen_fe_frontend_changed(struct XenDevice *xendev, const char *node); #endif /* QEMU_HW_XEN_FRONTEND_H */ -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 12/15] xen: Rename xen_be_evtchn_event
Prepare xen_be_evtchn_event to be shared with frontends: * xen_be_evtchn_event -> xen_pv_evtchn_event Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 97869cf..b6c11a1 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -517,7 +517,7 @@ int xen_be_bind_evtchn(struct XenDevice *xendev) } xen_pv_printf(xendev, 2, "bind evtchn port %d\n", xendev->local_port); qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), -xen_be_evtchn_event, NULL, xendev); +xen_pv_evtchn_event, NULL, xendev); return 0; } diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 61e40c9..1c2cb98 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -228,7 +228,7 @@ void xen_pv_printf(struct XenDevice *xendev, int msg_level, qemu_log_flush(); } -void xen_be_evtchn_event(void *opaque) +void xen_pv_evtchn_event(void *opaque) { struct XenDevice *xendev = opaque; evtchn_port_t port; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index 0ebcda7..46560a1 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -64,7 +64,7 @@ void xenstore_update(void *unused); const char *xenbus_strstate(enum xenbus_state state); -void xen_be_evtchn_event(void *opaque); +void xen_pv_evtchn_event(void *opaque); void xen_pv_insert_xendev(struct XenDevice *xendev); void xen_be_del_xendev(struct XenDevice *xendev); struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 08/15] xen: Move xenstore cleanup and mkdir functions
The name of the functions moved to xen_pvdev.c: * xenstore_cleanup_dir * xen_config_cleanup * xenstore_mkdir Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 49 - hw/xen/xen_pvdev.c | 51 +++ 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index d572cd0..3518aac 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -48,57 +48,8 @@ struct xs_handle *xenstore = NULL; const char *xen_protocol; /* private */ -struct xs_dirs { -char *xs_dir; -QTAILQ_ENTRY(xs_dirs) list; -}; -static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = -QTAILQ_HEAD_INITIALIZER(xs_cleanup); - static int debug; -static void xenstore_cleanup_dir(char *dir) -{ -struct xs_dirs *d; - -d = g_malloc(sizeof(*d)); -d->xs_dir = dir; -QTAILQ_INSERT_TAIL(&xs_cleanup, d, list); -} - -void xen_config_cleanup(void) -{ -struct xs_dirs *d; - -QTAILQ_FOREACH(d, &xs_cleanup, list) { -xs_rm(xenstore, 0, d->xs_dir); -} -} - -int xenstore_mkdir(char *path, int p) -{ -struct xs_permissions perms[2] = { -{ -.id= 0, /* set owner: dom0 */ -}, { -.id= xen_domid, -.perms = p, -} -}; - -if (!xs_mkdir(xenstore, 0, path)) { -xen_be_printf(NULL, 0, "xs_mkdir %s: failed\n", path); -return -1; -} -xenstore_cleanup_dir(g_strdup(path)); - -if (!xs_set_permissions(xenstore, 0, path, perms, 2)) { -xen_be_printf(NULL, 0, "xs_set_permissions %s: failed\n", path); -return -1; -} -return 0; -} - int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val) { return xenstore_write_str(xendev->be, node, val); diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 72e2e79..6c92624 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -25,11 +25,62 @@ /* private */ static int debug; + +struct xs_dirs { +char *xs_dir; +QTAILQ_ENTRY(xs_dirs) list; +}; + +static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = +QTAILQ_HEAD_INITIALIZER(xs_cleanup); + static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs); /* - */ +static void xenstore_cleanup_dir(char *dir) +{ +struct xs_dirs *d; + +d = g_malloc(sizeof(*d)); +d->xs_dir = dir; +QTAILQ_INSERT_TAIL(&xs_cleanup, d, list); +} + +void xen_config_cleanup(void) +{ +struct xs_dirs *d; + +QTAILQ_FOREACH(d, &xs_cleanup, list) { +xs_rm(xenstore, 0, d->xs_dir); +} +} + +int xenstore_mkdir(char *path, int p) +{ +struct xs_permissions perms[2] = { +{ +.id= 0, /* set owner: dom0 */ +}, { +.id= xen_domid, +.perms = p, +} +}; + +if (!xs_mkdir(xenstore, 0, path)) { +xen_be_printf(NULL, 0, "xs_mkdir %s: failed\n", path); +return -1; +} +xenstore_cleanup_dir(g_strdup(path)); + +if (!xs_set_permissions(xenstore, 0, path, perms, 2)) { +xen_be_printf(NULL, 0, "xs_set_permissions %s: failed\n", path); +return -1; +} +return 0; +} + int xenstore_write_str(const char *base, const char *node, const char *val) { char abspath[XEN_BUFSIZE]; -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 05/15] xen: Move xenstore_update to xen_pvdev.c
* xenstore_update -> xen_pvdev.c * xenstore_update_fe -> xen_frontend.c Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 43 +-- hw/xen/xen_frontend.c | 18 ++ hw/xen/xen_pvdev.c| 24 include/hw/xen/xen_backend.h | 2 ++ include/hw/xen/xen_frontend.h | 1 + include/hw/xen/xen_pvdev.h| 1 + 6 files changed, 47 insertions(+), 42 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index d4880e1..6b03c50 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -509,7 +509,7 @@ static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops) return 0; } -static void xenstore_update_be(char *watch, char *type, int dom, +void xenstore_update_be(char *watch, char *type, int dom, struct XenDevOps *ops) { struct XenDevice *xendev; @@ -543,47 +543,6 @@ static void xenstore_update_be(char *watch, char *type, int dom, } } -static void xenstore_update_fe(char *watch, struct XenDevice *xendev) -{ -char *node; -unsigned int len; - -len = strlen(xendev->fe); -if (strncmp(xendev->fe, watch, len) != 0) { -return; -} -if (watch[len] != '/') { -return; -} -node = watch + len + 1; - -xen_be_frontend_changed(xendev, node); -xen_be_check_state(xendev); -} - -static void xenstore_update(void *unused) -{ -char **vec = NULL; -intptr_t type, ops, ptr; -unsigned int dom, count; - -vec = xs_read_watch(xenstore, &count); -if (vec == NULL) { -goto cleanup; -} - -if (sscanf(vec[XS_WATCH_TOKEN], "be:%" PRIxPTR ":%d:%" PRIxPTR, - &type, &dom, &ops) == 3) { -xenstore_update_be(vec[XS_WATCH_PATH], (void *)type, dom, (void*)ops); -} -if (sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr) == 1) { -xenstore_update_fe(vec[XS_WATCH_PATH], (void *)ptr); -} - -cleanup: -free(vec); -} - static void xen_be_evtchn_event(void *opaque) { struct XenDevice *xendev = opaque; diff --git a/hw/xen/xen_frontend.c b/hw/xen/xen_frontend.c index c8ff9ae..d42e57b 100644 --- a/hw/xen/xen_frontend.c +++ b/hw/xen/xen_frontend.c @@ -70,3 +70,21 @@ void xen_be_frontend_changed(struct XenDevice *xendev, const char *node) } } } + +void xenstore_update_fe(char *watch, struct XenDevice *xendev) +{ +char *node; +unsigned int len; + +len = strlen(xendev->fe); +if (strncmp(xendev->fe, watch, len) != 0) { +return; +} +if (watch[len] != '/') { +return; +} +node = watch + len + 1; + +xen_be_frontend_changed(xendev, node); +xen_be_check_state(xendev); +} diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 78960a9..35d3be6 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "hw/xen/xen_backend.h" +#include "hw/xen/xen_frontend.h" #include "hw/xen/xen_pvdev.h" static int debug; @@ -95,6 +96,29 @@ int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval) return rc; } +void xenstore_update(void *unused) +{ +char **vec = NULL; +intptr_t type, ops, ptr; +unsigned int dom, count; + +vec = xs_read_watch(xenstore, &count); +if (vec == NULL) { +goto cleanup; +} + +if (sscanf(vec[XS_WATCH_TOKEN], "be:%" PRIxPTR ":%d:%" PRIxPTR, + &type, &dom, &ops) == 3) { +xenstore_update_be(vec[XS_WATCH_PATH], (void *)type, dom, (void*)ops); +} +if (sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr) == 1) { +xenstore_update_fe(vec[XS_WATCH_PATH], (void *)ptr); +} + +cleanup: +free(vec); +} + const char *xenbus_strstate(enum xenbus_state state) { static const char *const name[] = { diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index ffd8772..965a39a 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -19,6 +19,8 @@ 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); char *xenstore_read_be_str(struct XenDevice *xendev, const char *node); int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int *ival); +void xenstore_update_be(char *watch, char *type, int dom, + struct XenDevOps *ops); struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); void xen_be_check_state(struct XenDevice *xendev); diff --git a/include/hw/xen/xen_frontend.h b/include/hw/xen/xen_frontend.h index 86243b9..69a7694 100644 --- a/include/hw/xen/xen_frontend.h +++ b/include/hw/xen/xen_frontend.
Re: [Xen-devel] [Qemu-devel] [v9 00/19] QEMU:Xen stubdom vTPM for HVM virtual machine(QEMU Part)
Anthony, I've split the reorganization and code style issues in a separate patch series which I've posted today: http://markmail.org/message/feu6u3f7py5vt77v Thanks On Mon, Jul 25, 2016 at 5:09 PM, Anthony PERARD wrote: > On Sun, Jul 10, 2016 at 02:47:31PM +0300, Emil Condrea wrote: >> 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 > > Patches from 1 to 12 looks fine but ./script/checkpatch.pl reveal some > coding style issue in the code that is moved. Could you fix those issues > in separate patches? (Having separate patches for code movement and for > coding style fix makes it easier to review.) > > I'll start reviewing the more complicated patches now. > > Thanks, > > -- > Anthony PERARD ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH 15/15] xen: Rename xen_be_frontend_changed
On Tue, Oct 4, 2016 at 11:06 AM, Paolo Bonzini wrote: > > > On 04/10/2016 08:43, Emil Condrea wrote: >> xen_be_frontend_changed -> xen_fe_frontend_changed > > This is not correct. The front-end is implemented in the guest domain, > while the back-end is implemented in the dom0 or stubdom. > You are right, thanks for the feedback! I will drop this patch together with the hunk from 04/15 patch which moves this function to xen_frontend.c > This function processes *in the backed* a notification that the frontend > state changed, hence the name should be xen_be_frontend_changed. > > Paolo > >> Signed-off-by: Emil Condrea >> --- >> hw/xen/xen_backend.c | 2 +- >> hw/xen/xen_frontend.c | 4 ++-- >> include/hw/xen/xen_frontend.h | 2 +- >> 3 files changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c >> index 30d3aaa..b79e83e 100644 >> --- a/hw/xen/xen_backend.c >> +++ b/hw/xen/xen_backend.c >> @@ -213,7 +213,7 @@ static int xen_be_try_setup(struct XenDevice *xendev) >> xen_be_set_state(xendev, XenbusStateInitialising); >> >> xen_be_backend_changed(xendev, NULL); >> -xen_be_frontend_changed(xendev, NULL); >> +xen_fe_frontend_changed(xendev, NULL); >> return 0; >> } >> >> diff --git a/hw/xen/xen_frontend.c b/hw/xen/xen_frontend.c >> index 1407f5f..761688b 100644 >> --- a/hw/xen/xen_frontend.c >> +++ b/hw/xen/xen_frontend.c >> @@ -39,7 +39,7 @@ int xenstore_read_fe_uint64(struct XenDevice *xendev, >> const char *node, >> return xenstore_read_uint64(xendev->fe, node, uval); >> } >> >> -void xen_be_frontend_changed(struct XenDevice *xendev, const char *node) >> +void xen_fe_frontend_changed(struct XenDevice *xendev, const char *node) >> { >> int fe_state; >> >> @@ -85,6 +85,6 @@ void xenstore_update_fe(char *watch, struct XenDevice >> *xendev) >> } >> node = watch + len + 1; >> >> -xen_be_frontend_changed(xendev, node); >> +xen_fe_frontend_changed(xendev, node); >> xen_be_check_state(xendev); >> } >> diff --git a/include/hw/xen/xen_frontend.h b/include/hw/xen/xen_frontend.h >> index bb0bc23..2a5f03f 100644 >> --- a/include/hw/xen/xen_frontend.h >> +++ b/include/hw/xen/xen_frontend.h >> @@ -9,6 +9,6 @@ int xenstore_read_fe_uint64(struct XenDevice *xendev, const >> char *node, >> uint64_t *uval); >> void xenstore_update_fe(char *watch, struct XenDevice *xendev); >> >> -void xen_be_frontend_changed(struct XenDevice *xendev, const char *node); >> +void xen_fe_frontend_changed(struct XenDevice *xendev, const char *node); >> >> #endif /* QEMU_HW_XEN_FRONTEND_H */ >> ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH 01/15] xen: Fix coding style errors
Actually I've split fixing coding style in 2 patches: one for errors and one for warnings. In this patch some resolve the error "code indent should never use tabs" but if on the same line there is a warning about line exceeding 80 characters, it will be fixed in "Fix coding style warnings" patch. On Tue, Oct 11, 2016 at 4:56 PM, Anthony PERARD wrote: > On Tue, Oct 04, 2016 at 09:43:30AM +0300, Emil Condrea wrote: >> Fixes the following errors: >> * ERROR: line over 90 characters > > It's 80 ;), and there are a few more left in this patch. > >> * ERROR: code indent should never use tabs >> * ERROR: space prohibited after that open square bracket '[' >> * ERROR: do not initialise statics to 0 or NULL >> * ERROR: "(foo*)" should be "(foo *)" >> >> Signed-off-by: Emil Condrea > > -- > Anthony PERARD ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH 02/15] xen: Fix coding style warnings
On Tue, Oct 11, 2016 at 5:20 PM, Anthony PERARD wrote: > On Tue, Oct 04, 2016 at 09:43:31AM +0300, Emil Condrea wrote: >> Fixes: >> * WARNING: line over 80 characters >> >> Signed-off-by: Emil Condrea >> --- >> hw/block/xen_disk.c | 3 ++- >> hw/char/xen_console.c| 6 -- >> hw/display/xenfb.c | 30 -- >> hw/net/xen_nic.c | 12 >> hw/xen/xen_backend.c | 15 ++- >> include/hw/xen/xen_backend.h | 8 +--- >> 6 files changed, 49 insertions(+), 25 deletions(-) >> >> diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c >> index 5aa350a..24edeb2 100644 >> --- a/hw/block/xen_disk.c >> +++ b/hw/block/xen_disk.c >> @@ -1068,7 +1068,8 @@ static int blk_connect(struct XenDevice *xendev) >> blk_set_enable_write_cache(blkdev->blk, !writethrough); >> } else { >> /* setup via qemu cmdline -> already setup for us */ >> -xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline >> setup)\n"); >> +xen_be_printf(&blkdev->xendev, 2, >> + "get configured bdrv (cmdline setup)\n"); > > Arguments are usually aligned with the first one, so there is one > missing space. I guess this is displayed wrongly in the email client as in mine but the source of the email contains this patch http://pastebin.com/Sbk23h6m, which shows that this line is aligned to the first parameter. > >> blkdev->blk = blk_by_legacy_dinfo(blkdev->dinfo); >> if (blk_is_read_only(blkdev->blk) && !readonly) { >> xen_be_printf(&blkdev->xendev, 0, "Unexpected read-only drive"); >> diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c >> index 4e35c82..399bb5d 100644 >> --- a/hw/char/xen_console.c >> +++ b/hw/char/xen_console.c >> @@ -156,7 +156,8 @@ static void xencons_send(struct XenConsole *con) >> if (len < 1) { >> if (!con->backlog) { >> con->backlog = 1; >> -xen_be_printf(&con->xendev, 1, "backlog piling up, nobody >> listening?\n"); >> +xen_be_printf(&con->xendev, 1, >> + "backlog piling up, nobody listening?\n"); > > same here and other places. same as above > >> } >> } else { >> buffer_advance(&con->buffer, len); >> @@ -247,7 +248,8 @@ static int con_initialise(struct XenDevice *xendev) >> } >> } >> >> -xen_be_printf(xendev, 1, "ring mfn %d, remote port %d, local port %d, >> limit %zd\n", >> +xen_be_printf(xendev, 1, >> + "ring mfn %d, remote port %d, local port %d, limit %zd\n", >> con->ring_ref, >> con->xendev.remote_port, >> con->xendev.local_port, >> diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c >> index 545ee47..0aca6ae 100644 >> --- a/hw/xen/xen_backend.c >> +++ b/hw/xen/xen_backend.c >> @@ -205,7 +206,8 @@ int xenstore_read_fe_int(struct XenDevice *xendev, const >> char *node, int *ival) >> return xenstore_read_int(xendev->fe, node, ival); >> } >> >> -int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, >> uint64_t *uval) >> +int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, >> +uint64_t *uval) > > Same here, it would be better to align the second line with the first > parameter. This indeed should be fixed. I will send a new patch for it. > >> { >> return xenstore_read_uint64(xendev->fe, node, uval); >> } > > -- > Anthony PERARD ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v2 00/13] Refactor common part of xen backend and frontend
This patch series was splitted from QEMU:Xen stubdom vTPM for HVM virtual machine http://markmail.org/message/fkix7g3a5zdj7lvr It contains a reorganization of xen backend and frontend functions together with code style fixes. Common functions shared by backends and frontends are moved to xen_pvdev file. --- Changes in v2: * fixed parameter alignment when spliting long lines * removed patches for creating xen_frontend Emil Condrea (13): xen: Fix coding style errors xen: Fix coding style warnings xen: Create a new file xen_pvdev.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: Move xenstore cleanup and mkdir functions 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 hw/block/xen_disk.c | 65 hw/char/xen_console.c| 32 ++-- hw/display/xenfb.c | 127 hw/net/xen_nic.c | 36 +++-- hw/usb/xen-usb.c | 46 +++--- hw/xen/Makefile.objs | 2 +- hw/xen/xen_backend.c | 348 +-- hw/xen/xen_devconfig.c | 4 +- hw/xen/xen_pvdev.c | 316 +++ include/hw/xen/xen_backend.h | 72 + include/hw/xen/xen_pvdev.h | 78 ++ xen-common.c | 4 +- 12 files changed, 604 insertions(+), 526 deletions(-) create mode 100644 hw/xen/xen_pvdev.c create mode 100644 include/hw/xen/xen_pvdev.h -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v2 03/13] xen: Create a new file xen_pvdev.c
The purpose of the new file is to store generic functions shared by frontend and backends such as xenstore operations, xendevs. Signed-off-by: Quan Xu Signed-off-by: Emil Condrea --- hw/xen/Makefile.objs | 2 +- hw/xen/xen_backend.c | 126 +--- hw/xen/xen_pvdev.c | 150 +++ include/hw/xen/xen_backend.h | 64 +- include/hw/xen/xen_pvdev.h | 69 5 files changed, 222 insertions(+), 189 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 0e95880..b32b0dd 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 @@ -57,8 +58,6 @@ static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs); static int debug; -/* - */ - static void xenstore_cleanup_dir(char *dir) { struct xs_dirs *d; @@ -77,34 +76,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] = { @@ -129,48 +100,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]; - -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; -} - int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val) { return xenstore_write_str(xendev->be, node, val); @@ -214,20 +143,6 @@ int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, /* - */ -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; @@ -827,45 +742,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 message
[Xen-devel] [PATCH v2 05/13] xen: Move evtchn functions to xen_pvdev.c
The name of the functions moved: * xen_be_evtchn_event * xen_be_unbind_evtchn * xen_be_send_notify Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 35 --- hw/xen/xen_pvdev.c | 35 +++ include/hw/xen/xen_backend.h | 2 -- include/hw/xen/xen_pvdev.h | 4 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index e3a7d95..1487db2 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -607,25 +607,6 @@ void xenstore_update_fe(char *watch, struct XenDevice *xendev) xen_be_frontend_changed(xendev, node); xen_be_check_state(xendev); } -static void xen_be_evtchn_event(void *opaque) -{ -struct XenDevice *xendev = opaque; -evtchn_port_t port; - -port = xenevtchn_pending(xendev->evtchndev); -if (port != xendev->local_port) { -xen_be_printf(xendev, 0, - "xenevtchn_pending returned %d (expected %d)\n", - port, xendev->local_port); -return; -} -xenevtchn_unmask(xendev->evtchndev, port); - -if (xendev->ops->event) { -xendev->ops->event(xendev); -} -} - /* */ int xen_be_init(void) @@ -702,22 +683,6 @@ int xen_be_bind_evtchn(struct XenDevice *xendev) return 0; } -void xen_be_unbind_evtchn(struct XenDevice *xendev) -{ -if (xendev->local_port == -1) { -return; -} -qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), NULL, NULL, NULL); -xenevtchn_unbind(xendev->evtchndev, xendev->local_port); -xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port); -xendev->local_port = -1; -} - -int xen_be_send_notify(struct XenDevice *xendev) -{ -return xenevtchn_notify(xendev->evtchndev, xendev->local_port); -} - static int xen_sysdev_init(SysBusDevice *dev) { diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 22a1abe..7607e44 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -171,3 +171,38 @@ void xen_be_printf(struct XenDevice *xendev, int msg_level, } qemu_log_flush(); } + +void xen_be_evtchn_event(void *opaque) +{ +struct XenDevice *xendev = opaque; +evtchn_port_t port; + +port = xenevtchn_pending(xendev->evtchndev); +if (port != xendev->local_port) { +xen_be_printf(xendev, 0, + "xenevtchn_pending returned %d (expected %d)\n", + port, xendev->local_port); +return; +} +xenevtchn_unmask(xendev->evtchndev, port); + +if (xendev->ops->event) { +xendev->ops->event(xendev); +} +} + +void xen_be_unbind_evtchn(struct XenDevice *xendev) +{ +if (xendev->local_port == -1) { +return; +} +qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), NULL, NULL, NULL); +xenevtchn_unbind(xendev->evtchndev, xendev->local_port); +xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port); +xendev->local_port = -1; +} + +int xen_be_send_notify(struct XenDevice *xendev) +{ +return xenevtchn_notify(xendev->evtchndev, xendev->local_port); +} diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 2e54150..6c617d9 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -36,8 +36,6 @@ void xen_be_register_common(void); int xen_be_register(const char *type, struct XenDevOps *ops); 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); /* 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 index 3c4cc01..a8da3da 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -64,6 +64,10 @@ void xenstore_update(void *unused); const char *xenbus_strstate(enum xenbus_state state); +void xen_be_evtchn_event(void *opaque); +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); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v2 10/13] xen: Rename xen_be_send_notify
Prepare xen_be_send_notify to be shared with frontends: * xen_be_send_notify -> xen_pv_send_notify Signed-off-by: Emil Condrea Acked-by: Anthony PERARD Reviewed-by: Quan Xu --- hw/block/xen_disk.c| 4 ++-- hw/char/xen_console.c | 4 ++-- hw/display/xenfb.c | 8 hw/net/xen_nic.c | 4 ++-- hw/usb/xen-usb.c | 6 +++--- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 981dd0e..d676c9e 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -796,7 +796,7 @@ static void blk_send_response_all(struct XenBlkDev *blkdev) ioreq_release(ioreq, true); } if (send_notify) { -xen_be_send_notify(&blkdev->xendev); +xen_pv_send_notify(&blkdev->xendev); } } @@ -866,7 +866,7 @@ static void blk_handle_requests(struct XenBlkDev *blkdev) }; if (blk_send_response_one(ioreq)) { -xen_be_send_notify(&blkdev->xendev); +xen_pv_send_notify(&blkdev->xendev); } ioreq_release(ioreq, false); continue; diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 6dc2d81..dbe4755 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -72,7 +72,7 @@ static void buffer_append(struct XenConsole *con) xen_mb(); intf->out_cons = cons; -xen_be_send_notify(&con->xendev); +xen_pv_send_notify(&con->xendev); if (buffer->max_capacity && buffer->size > buffer->max_capacity) { @@ -140,7 +140,7 @@ static void xencons_receive(void *opaque, const uint8_t *buf, int len) } xen_wmb(); intf->in_prod = prod; -xen_be_send_notify(&con->xendev); +xen_pv_send_notify(&con->xendev); } static void xencons_send(struct XenConsole *con) diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index d9e5514..7d26bdb 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -215,7 +215,7 @@ static int xenfb_kbd_event(struct XenInput *xenfb, XENKBD_IN_RING_REF(page, prod) = *event; xen_wmb(); /* ensure ring contents visible */ page->in_prod = prod + 1; -return xen_be_send_notify(&xenfb->c.xendev); +return xen_pv_send_notify(&xenfb->c.xendev); } /* Send a keyboard (or mouse button) event */ @@ -397,7 +397,7 @@ static void input_event(struct XenDevice *xendev) if (page->out_prod == page->out_cons) return; page->out_cons = page->out_prod; -xen_be_send_notify(&xenfb->c.xendev); +xen_pv_send_notify(&xenfb->c.xendev); } /* */ @@ -672,7 +672,7 @@ static void xenfb_send_event(struct XenFB *xenfb, union xenfb_in_event *event) xen_wmb(); /* ensure ring contents visible */ page->in_prod = prod + 1; -xen_be_send_notify(&xenfb->c.xendev); +xen_pv_send_notify(&xenfb->c.xendev); } static void xenfb_send_refresh_period(struct XenFB *xenfb, int period) @@ -945,7 +945,7 @@ static void fb_event(struct XenDevice *xendev) struct XenFB *xenfb = container_of(xendev, struct XenFB, c.xendev); xenfb_handle_events(xenfb); -xen_be_send_notify(&xenfb->c.xendev); +xen_pv_send_notify(&xenfb->c.xendev); } /* */ diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 9003737..6d6909d 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -69,7 +69,7 @@ static void net_tx_response(struct XenNetDev *netdev, netif_tx_request_t *txp, i netdev->tx_ring.rsp_prod_pvt = ++i; RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netdev->tx_ring, notify); if (notify) { -xen_be_send_notify(&netdev->xendev); +xen_pv_send_notify(&netdev->xendev); } if (i == netdev->tx_ring.req_cons) { @@ -221,7 +221,7 @@ static void net_rx_response(struct XenNetDev *netdev, netdev->rx_ring.rsp_prod_pvt = ++i; RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netdev->rx_ring, notify); if (notify) { -xen_be_send_notify(&netdev->xendev); +xen_pv_send_notify(&netdev->xendev); } } diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c index f13bbe1..258fa0b 100644 --- a/hw/usb/xen-usb.c +++ b/hw/usb/xen-usb.c @@ -314,7 +314,7 @@ static void usbback_do_response(struct usbback_req *usbback_req, int32_t status, RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&usbif->urb_ring, notify); if (notify) { -xen_be_send_notify(xendev); +xen_pv_send_notify(xendev); } } @@ -590,7 +590,7 @@ static void usbback_hotplug_notify(struct usbback_info *usbif) /* Check for fu
[Xen-devel] [PATCH v2 09/13] xen: Rename xen_be_unbind_evtchn
Prepare xen_be_unbind_evtchn to be shared with frontends: * xen_be_unbind_evtchn -> xen_pv_unbind_evtchn Signed-off-by: Emil Condrea Acked-by: Anthony PERARD Reviewed-by: Quan Xu --- hw/block/xen_disk.c| 2 +- hw/char/xen_console.c | 2 +- hw/display/xenfb.c | 2 +- hw/net/xen_nic.c | 2 +- hw/usb/xen-usb.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index bcfd36a..981dd0e 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -1194,7 +1194,7 @@ static void blk_disconnect(struct XenDevice *xendev) blk_unref(blkdev->blk); blkdev->blk = NULL; } -xen_be_unbind_evtchn(&blkdev->xendev); +xen_pv_unbind_evtchn(&blkdev->xendev); if (blkdev->sring) { xengnttab_unmap(blkdev->xendev.gnttabdev, blkdev->sring, 1); diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index b705a06..6dc2d81 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -265,7 +265,7 @@ static void con_disconnect(struct XenDevice *xendev) qemu_chr_add_handlers(con->chr, NULL, NULL, NULL, NULL); qemu_chr_fe_release(con->chr); } -xen_be_unbind_evtchn(&con->xendev); +xen_pv_unbind_evtchn(&con->xendev); if (con->sring) { if (!xendev->dev) { diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 34108ab..d9e5514 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -112,7 +112,7 @@ static int common_bind(struct common *c) static void common_unbind(struct common *c) { -xen_be_unbind_evtchn(&c->xendev); +xen_pv_unbind_evtchn(&c->xendev); if (c->page) { xenforeignmemory_unmap(xen_fmem, c->page, 1); c->page = NULL; diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index a5e57d6..9003737 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -372,7 +372,7 @@ static void net_disconnect(struct XenDevice *xendev) { struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev); -xen_be_unbind_evtchn(&netdev->xendev); +xen_pv_unbind_evtchn(&netdev->xendev); if (netdev->txs) { xengnttab_unmap(netdev->xendev.gnttabdev, netdev->txs, 1); diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c index a43f3fa..f13bbe1 100644 --- a/hw/usb/xen-usb.c +++ b/hw/usb/xen-usb.c @@ -834,7 +834,7 @@ static void usbback_disconnect(struct XenDevice *xendev) usbif = container_of(xendev, struct usbback_info, xendev); -xen_be_unbind_evtchn(xendev); +xen_pv_unbind_evtchn(xendev); if (usbif->urb_sring) { xengnttab_unmap(xendev->gnttabdev, usbif->urb_sring, 1); diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 6938c09..b362eb7 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -246,7 +246,7 @@ void xen_be_evtchn_event(void *opaque) } } -void xen_be_unbind_evtchn(struct XenDevice *xendev) +void xen_pv_unbind_evtchn(struct XenDevice *xendev) { if (xendev->local_port == -1) { return; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index 7aedc91..1aff68c 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -69,7 +69,7 @@ void xen_pv_insert_xendev(struct XenDevice *xendev); void xen_be_del_xendev(struct XenDevice *xendev); struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); -void xen_be_unbind_evtchn(struct XenDevice *xendev); +void xen_pv_unbind_evtchn(struct XenDevice *xendev); int xen_be_send_notify(struct XenDevice *xendev); void xen_pv_printf(struct XenDevice *xendev, int msg_level, -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v2 12/13] xen: Rename xen_be_find_xendev
Prepare xen_be_find_xendev to be shared with frontends: * xen_be_find_xendev -> xen_pv_find_xendev Signed-off-by: Emil Condrea Acked-by: Anthony PERARD Reviewed-by: Quan Xu --- hw/display/xenfb.c | 4 ++-- hw/xen/xen_backend.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 7d26bdb..15aa088 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -988,8 +988,8 @@ void xen_init_display(int domid) wait_more: i++; main_loop_wait(true); -xfb = xen_be_find_xendev("vfb", domid, 0); -xin = xen_be_find_xendev("vkbd", domid, 0); +xfb = xen_pv_find_xendev("vfb", domid, 0); +xin = xen_pv_find_xendev("vkbd", domid, 0); if (!xfb || !xin) { if (i < 256) { usleep(1); diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index f594dba..98fcb77 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -114,7 +114,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, { struct XenDevice *xendev; -xendev = xen_be_find_xendev(type, dom, dev); +xendev = xen_pv_find_xendev(type, dom, dev); if (xendev) { return xendev; } diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 28acf61..af29150 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -264,7 +264,7 @@ int xen_pv_send_notify(struct XenDevice *xendev) /* - */ -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) +struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev) { struct XenDevice *xendev; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index caf1edc..4b1cc60 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -67,7 +67,7 @@ const char *xenbus_strstate(enum xenbus_state state); void xen_pv_evtchn_event(void *opaque); void xen_pv_insert_xendev(struct XenDevice *xendev); void xen_be_del_xendev(struct XenDevice *xendev); -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); +struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev); void xen_pv_unbind_evtchn(struct XenDevice *xendev); int xen_pv_send_notify(struct XenDevice *xendev); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v2 13/13] xen: Rename xen_be_del_xendev
Prepare xen_be_del_xendev to be shared with frontends: * xen_be_del_xendev -> xen_pv_del_xendev Signed-off-by: Emil Condrea Acked-by: Anthony PERARD Reviewed-by: Quan Xu --- hw/xen/xen_backend.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 98fcb77..41ba5c5 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -483,7 +483,7 @@ void xenstore_update_be(char *watch, char *type, int dom, if (xendev != NULL) { bepath = xs_read(xenstore, 0, xendev->be, &len); if (bepath == NULL) { -xen_be_del_xendev(xendev); +xen_pv_del_xendev(xendev); } else { free(bepath); xen_be_backend_changed(xendev, path); diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index af29150..405e154 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -286,7 +286,7 @@ struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev) /* * release xen backend device. */ -void xen_be_del_xendev(struct XenDevice *xendev) +void xen_pv_del_xendev(struct XenDevice *xendev) { if (xendev->ops->free) { xendev->ops->free(xendev); diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index 4b1cc60..083f0a9 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -66,7 +66,7 @@ const char *xenbus_strstate(enum xenbus_state state); void xen_pv_evtchn_event(void *opaque); void xen_pv_insert_xendev(struct XenDevice *xendev); -void xen_be_del_xendev(struct XenDevice *xendev); +void xen_pv_del_xendev(struct XenDevice *xendev); struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev); void xen_pv_unbind_evtchn(struct XenDevice *xendev); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v2 02/13] xen: Fix coding style warnings
Fixes: * WARNING: line over 80 characters Signed-off-by: Emil Condrea --- hw/block/xen_disk.c | 3 ++- hw/char/xen_console.c| 6 -- hw/display/xenfb.c | 30 -- hw/net/xen_nic.c | 12 hw/xen/xen_backend.c | 15 ++- include/hw/xen/xen_backend.h | 8 +--- 6 files changed, 49 insertions(+), 25 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 1292a4b..d04f3aa 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -1068,7 +1068,8 @@ static int blk_connect(struct XenDevice *xendev) blk_set_enable_write_cache(blkdev->blk, !writethrough); } else { /* setup via qemu cmdline -> already setup for us */ -xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n"); +xen_be_printf(&blkdev->xendev, 2, + "get configured bdrv (cmdline setup)\n"); blkdev->blk = blk_by_legacy_dinfo(blkdev->dinfo); if (blk_is_read_only(blkdev->blk) && !readonly) { xen_be_printf(&blkdev->xendev, 0, "Unexpected read-only drive"); diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 4e35c82..399bb5d 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -156,7 +156,8 @@ static void xencons_send(struct XenConsole *con) if (len < 1) { if (!con->backlog) { con->backlog = 1; -xen_be_printf(&con->xendev, 1, "backlog piling up, nobody listening?\n"); +xen_be_printf(&con->xendev, 1, + "backlog piling up, nobody listening?\n"); } } else { buffer_advance(&con->buffer, len); @@ -247,7 +248,8 @@ static int con_initialise(struct XenDevice *xendev) } } -xen_be_printf(xendev, 1, "ring mfn %d, remote port %d, local port %d, limit %zd\n", +xen_be_printf(xendev, 1, + "ring mfn %d, remote port %d, local port %d, limit %zd\n", con->ring_ref, con->xendev.remote_port, con->xendev.local_port, diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index a9a93f9..9bcf60b 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -511,38 +511,45 @@ static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, int max_width, max_height; if (fb_len_lim > fb_len_max) { -xen_be_printf(&xenfb->c.xendev, 0, "fb size limit %zu exceeds %zu, corrected\n", +xen_be_printf(&xenfb->c.xendev, 0, + "fb size limit %zu exceeds %zu, corrected\n", fb_len_lim, fb_len_max); fb_len_lim = fb_len_max; } if (fb_len_lim && fb_len > fb_len_lim) { -xen_be_printf(&xenfb->c.xendev, 0, "frontend fb size %zu limited to %zu\n", +xen_be_printf(&xenfb->c.xendev, 0, + "frontend fb size %zu limited to %zu\n", fb_len, fb_len_lim); fb_len = fb_len_lim; } if (depth != 8 && depth != 16 && depth != 24 && depth != 32) { -xen_be_printf(&xenfb->c.xendev, 0, "can't handle frontend fb depth %d\n", +xen_be_printf(&xenfb->c.xendev, 0, + "can't handle frontend fb depth %d\n", depth); return -1; } if (row_stride <= 0 || row_stride > fb_len) { -xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend stride %d\n", row_stride); +xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend stride %d\n", + row_stride); return -1; } max_width = row_stride / (depth / 8); if (width < 0 || width > max_width) { -xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend width %d limited to %d\n", +xen_be_printf(&xenfb->c.xendev, 0, + "invalid frontend width %d limited to %d\n", width, max_width); width = max_width; } if (offset < 0 || offset >= fb_len) { -xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend offset %d (max %zu)\n", +xen_be_printf(&xenfb->c.xendev, 0, + "invalid frontend offset %d (max %zu)\n", offset, fb_len - 1); return -1; } max_height = (fb_len - offset) / row_stride; if (height < 0 || height > max_height) { -xen_be_printf(&xenfb->c.xendev, 0, "invalid frontend height %d limited to %d\n", +xen_be_printf(&xenfb->c.xendev, 0,
[Xen-devel] [PATCH v2 06/13] xen: Prepare xendev qtail to be shared with frontends
* move xendevs qtail to xen_pvdev.c * change xen_be_get_xendev to use a new function: xen_pv_insert_xendev Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 51 +-- hw/xen/xen_pvdev.c | 57 include/hw/xen/xen_backend.h | 1 - include/hw/xen/xen_pvdev.h | 4 4 files changed, 62 insertions(+), 51 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 1487db2..2875e7c 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -54,8 +54,6 @@ struct xs_dirs { static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = QTAILQ_HEAD_INITIALIZER(xs_cleanup); -static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = -QTAILQ_HEAD_INITIALIZER(xendevs); static int debug; static void xenstore_cleanup_dir(char *dir) @@ -157,27 +155,6 @@ int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state) return 0; } -/* - */ - -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) -{ -struct XenDevice *xendev; - -QTAILQ_FOREACH(xendev, &xendevs, next) { -if (xendev->dom != dom) { -continue; -} -if (xendev->dev != dev) { -continue; -} -if (strcmp(xendev->type, type) != 0) { -continue; -} -return xendev; -} -return NULL; -} - /* * get xen backend device, allocate a new one if it doesn't exist. */ @@ -226,7 +203,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, xendev->gnttabdev = NULL; } -QTAILQ_INSERT_TAIL(&xendevs, xendev, next); +xen_pv_insert_xendev(xendev); if (xendev->ops->alloc) { xendev->ops->alloc(xendev); @@ -235,32 +212,6 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, return xendev; } -/* - * release xen backend device. - */ -static void xen_be_del_xendev(struct XenDevice *xendev) -{ -if (xendev->ops->free) { -xendev->ops->free(xendev); -} - -if (xendev->fe) { -char token[XEN_BUFSIZE]; -snprintf(token, sizeof(token), "fe:%p", xendev); -xs_unwatch(xenstore, xendev->fe, token); -g_free(xendev->fe); -} - -if (xendev->evtchndev != NULL) { -xenevtchn_close(xendev->evtchndev); -} -if (xendev->gnttabdev != NULL) { -xengnttab_close(xendev->gnttabdev); -} - -QTAILQ_REMOVE(&xendevs, xendev, next); -g_free(xendev); -} /* * Sync internal data structures on xenstore updates. diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 7607e44..96ed2a3 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -22,7 +22,11 @@ #include "hw/xen/xen_backend.h" #include "hw/xen/xen_pvdev.h" +/* private */ static int debug; +static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = +QTAILQ_HEAD_INITIALIZER(xendevs); + /* - */ int xenstore_write_str(const char *base, const char *node, const char *val) @@ -206,3 +210,56 @@ int xen_be_send_notify(struct XenDevice *xendev) { return xenevtchn_notify(xendev->evtchndev, xendev->local_port); } + +/* - */ + +struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) +{ +struct XenDevice *xendev; + +QTAILQ_FOREACH(xendev, &xendevs, next) { +if (xendev->dom != dom) { +continue; +} +if (xendev->dev != dev) { +continue; +} +if (strcmp(xendev->type, type) != 0) { +continue; +} +return xendev; +} +return NULL; +} + +/* + * release xen backend device. + */ +void xen_be_del_xendev(struct XenDevice *xendev) +{ +if (xendev->ops->free) { +xendev->ops->free(xendev); +} + +if (xendev->fe) { +char token[XEN_BUFSIZE]; +snprintf(token, sizeof(token), "fe:%p", xendev); +xs_unwatch(xenstore, xendev->fe, token); +g_free(xendev->fe); +} + +if (xendev->evtchndev != NULL) { +xenevtchn_close(xendev->evtchndev); +} +if (xendev->gnttabdev != NULL) { +xengnttab_close(xendev->gnttabdev); +} + +QTAILQ_REMOVE(&xendevs, xendev, next); +g_free(xendev); +} + +void xen_pv_insert_xendev(struct XenDevice *xendev) +{ +QTAILQ_INSERT_TAIL(&xendevs, xendev, next); +} diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 6c617d9..cbda40e 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -27,7 +27,6 @@ int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival);
[Xen-devel] [PATCH v2 01/13] xen: Fix coding style errors
Fixes the following errors: * ERROR: line over 90 characters * ERROR: code indent should never use tabs * ERROR: space prohibited after that open square bracket '[' * ERROR: do not initialise statics to 0 or NULL * ERROR: "(foo*)" should be "(foo *)" Signed-off-by: Emil Condrea --- hw/char/xen_console.c | 20 ++--- hw/display/xenfb.c| 83 ++- hw/net/xen_nic.c | 8 +++-- hw/xen/xen_backend.c | 20 ++--- 4 files changed, 67 insertions(+), 64 deletions(-) diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 83108b0..4e35c82 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -154,16 +154,16 @@ static void xencons_send(struct XenConsole *con) else len = size; if (len < 1) { - if (!con->backlog) { - con->backlog = 1; - xen_be_printf(&con->xendev, 1, "backlog piling up, nobody listening?\n"); - } +if (!con->backlog) { +con->backlog = 1; +xen_be_printf(&con->xendev, 1, "backlog piling up, nobody listening?\n"); +} } else { - buffer_advance(&con->buffer, len); - if (con->backlog && len == size) { - con->backlog = 0; - xen_be_printf(&con->xendev, 1, "backlog is gone\n"); - } +buffer_advance(&con->buffer, len); +if (con->backlog && len == size) { +con->backlog = 0; +xen_be_printf(&con->xendev, 1, "backlog is gone\n"); +} } } @@ -187,7 +187,7 @@ static int con_init(struct XenDevice *xendev) type = xenstore_read_str(con->console, "type"); if (!type || strcmp(type, "ioemu") != 0) { - xen_be_printf(xendev, 1, "not for me (type=%s)\n", type); +xen_be_printf(xendev, 1, "not for me (type=%s)\n", type); ret = -1; goto out; } diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 46b7d5e..a9a93f9 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -90,21 +90,22 @@ static int common_bind(struct common *c) xen_pfn_t mfn; if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &val) == -1) - return -1; +return -1; mfn = (xen_pfn_t)val; assert(val == mfn); if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1) - return -1; +return -1; c->page = xenforeignmemory_map(xen_fmem, c->xendev.dom, PROT_READ | PROT_WRITE, 1, &mfn, NULL); if (c->page == NULL) - return -1; +return -1; xen_be_bind_evtchn(&c->xendev); -xen_be_printf(&c->xendev, 1, "ring mfn %"PRI_xen_pfn", remote-port %d, local-port %d\n", - mfn, c->xendev.remote_port, c->xendev.local_port); +xen_be_printf(&c->xendev, 1, + "ring mfn %"PRI_xen_pfn", remote-port %d, local-port %d\n", + mfn, c->xendev.remote_port, c->xendev.local_port); return 0; } @@ -500,8 +501,8 @@ out: } static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, - int width, int height, int depth, - size_t fb_len, int offset, int row_stride) + int width, int height, int depth, + size_t fb_len, int offset, int row_stride) { size_t mfn_sz = sizeof(*((struct xenfb_page *)0)->pd); size_t pd_len = sizeof(((struct xenfb_page *)0)->pd) / mfn_sz; @@ -510,40 +511,40 @@ static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, int max_width, max_height; if (fb_len_lim > fb_len_max) { - xen_be_printf(&xenfb->c.xendev, 0, "fb size limit %zu exceeds %zu, corrected\n", - fb_len_lim, fb_len_max); - fb_len_lim = fb_len_max; +xen_be_printf(&xenfb->c.xendev, 0, "fb size limit %zu exceeds %zu, corrected\n", + fb_len_lim, fb_len_max); +fb_len_lim = fb_len_max; } if (fb_len_lim && fb_len > fb_len_lim) { - xen_be_printf(&xenfb->c.xendev, 0, "frontend fb size %zu limited to %zu\n", - fb_len, fb_len_lim); - fb_len = fb_len_lim; +xen_be_printf(&xenfb->c.xendev, 0, "frontend fb size %zu limited to %zu\n", + fb_len, fb_len_lim); +fb_len = fb_len_lim; } if (depth != 8 && depth != 16 && depth != 24 && depth != 32) { - xen_be_printf(&xenfb->c.xendev, 0, "can't handle front
[Xen-devel] [PATCH v2 04/13] xen: Move xenstore_update to xen_pvdev.c
* xenstore_update -> xen_pvdev.c Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 30 +++--- hw/xen/xen_pvdev.c | 23 +++ include/hw/xen/xen_backend.h | 3 +++ include/hw/xen/xen_pvdev.h | 1 + 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index b32b0dd..e3a7d95 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -556,8 +556,8 @@ static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops) return 0; } -static void xenstore_update_be(char *watch, char *type, int dom, - struct XenDevOps *ops) +void xenstore_update_be(char *watch, char *type, int dom, +struct XenDevOps *ops) { struct XenDevice *xendev; char path[XEN_BUFSIZE], *bepath; @@ -590,7 +590,7 @@ static void xenstore_update_be(char *watch, char *type, int dom, } } -static void xenstore_update_fe(char *watch, struct XenDevice *xendev) +void xenstore_update_fe(char *watch, struct XenDevice *xendev) { char *node; unsigned int len; @@ -607,30 +607,6 @@ static void xenstore_update_fe(char *watch, struct XenDevice *xendev) xen_be_frontend_changed(xendev, node); xen_be_check_state(xendev); } - -static void xenstore_update(void *unused) -{ -char **vec = NULL; -intptr_t type, ops, ptr; -unsigned int dom, count; - -vec = xs_read_watch(xenstore, &count); -if (vec == NULL) { -goto cleanup; -} - -if (sscanf(vec[XS_WATCH_TOKEN], "be:%" PRIxPTR ":%d:%" PRIxPTR, - &type, &dom, &ops) == 3) { -xenstore_update_be(vec[XS_WATCH_PATH], (void *)type, dom, (void*)ops); -} -if (sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr) == 1) { -xenstore_update_fe(vec[XS_WATCH_PATH], (void *)ptr); -} - -cleanup: -free(vec); -} - static void xen_be_evtchn_event(void *opaque) { struct XenDevice *xendev = opaque; diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index a1dc2be..22a1abe 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -95,6 +95,29 @@ int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval) return rc; } +void xenstore_update(void *unused) +{ +char **vec = NULL; +intptr_t type, ops, ptr; +unsigned int dom, count; + +vec = xs_read_watch(xenstore, &count); +if (vec == NULL) { +goto cleanup; +} + +if (sscanf(vec[XS_WATCH_TOKEN], "be:%" PRIxPTR ":%d:%" PRIxPTR, + &type, &dom, &ops) == 3) { +xenstore_update_be(vec[XS_WATCH_PATH], (void *)type, dom, (void*)ops); +} +if (sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr) == 1) { +xenstore_update_fe(vec[XS_WATCH_PATH], (void *)ptr); +} + +cleanup: +free(vec); +} + const char *xenbus_strstate(enum xenbus_state state) { static const char *const name[] = { diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 973cb4b..2e54150 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -19,6 +19,9 @@ 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); char *xenstore_read_be_str(struct XenDevice *xendev, const char *node); int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int *ival); +void xenstore_update_fe(char *watch, struct XenDevice *xendev); +void xenstore_update_be(char *watch, char *type, int dom, +struct XenDevOps *ops); 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_fe_uint64(struct XenDevice *xendev, const char *node, diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index cd3d6bc..3c4cc01 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -60,6 +60,7 @@ 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); +void xenstore_update(void *unused); const char *xenbus_strstate(enum xenbus_state state); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v2 08/13] xen: Rename xen_be_printf to xen_pv_printf
Prepare xen_be_printf to be used by both backend and frontends: * xen_be_printf -> xen_pv_printf Signed-off-by: Emil Condrea Acked-by: Anthony PERARD --- hw/block/xen_disk.c| 58 +++--- hw/char/xen_console.c | 10 hw/display/xenfb.c | 42 - hw/net/xen_nic.c | 22 +- hw/usb/xen-usb.c | 38 +++--- hw/xen/xen_backend.c | 46 ++-- hw/xen/xen_devconfig.c | 4 ++-- hw/xen/xen_pvdev.c | 10 include/hw/xen/xen_pvdev.h | 2 +- xen-common.c | 4 ++-- 10 files changed, 118 insertions(+), 118 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index d04f3aa..bcfd36a 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -167,12 +167,12 @@ static void destroy_grant(gpointer pgnt) xengnttab_handle *gnt = grant->blkdev->xendev.gnttabdev; if (xengnttab_unmap(gnt, grant->page, 1) != 0) { -xen_be_printf(&grant->blkdev->xendev, 0, +xen_pv_printf(&grant->blkdev->xendev, 0, "xengnttab_unmap failed: %s\n", strerror(errno)); } grant->blkdev->persistent_gnt_count--; -xen_be_printf(&grant->blkdev->xendev, 3, +xen_pv_printf(&grant->blkdev->xendev, 3, "unmapped grant %p\n", grant->page); g_free(grant); } @@ -184,11 +184,11 @@ static void remove_persistent_region(gpointer data, gpointer dev) xengnttab_handle *gnt = blkdev->xendev.gnttabdev; if (xengnttab_unmap(gnt, region->addr, region->num) != 0) { -xen_be_printf(&blkdev->xendev, 0, +xen_pv_printf(&blkdev->xendev, 0, "xengnttab_unmap region %p failed: %s\n", region->addr, strerror(errno)); } -xen_be_printf(&blkdev->xendev, 3, +xen_pv_printf(&blkdev->xendev, 3, "unmapped grant region %p with %d pages\n", region->addr, region->num); g_free(region); @@ -255,7 +255,7 @@ static int ioreq_parse(struct ioreq *ioreq) size_t len; int i; -xen_be_printf(&blkdev->xendev, 3, +xen_pv_printf(&blkdev->xendev, 3, "op %d, nr %d, handle %d, id %" PRId64 ", sector %" PRId64 "\n", ioreq->req.operation, ioreq->req.nr_segments, ioreq->req.handle, ioreq->req.id, ioreq->req.sector_number); @@ -275,28 +275,28 @@ static int ioreq_parse(struct ioreq *ioreq) case BLKIF_OP_DISCARD: return 0; default: -xen_be_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n", +xen_pv_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n", ioreq->req.operation); goto err; }; if (ioreq->req.operation != BLKIF_OP_READ && blkdev->mode[0] != 'w') { -xen_be_printf(&blkdev->xendev, 0, "error: write req for ro device\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: write req for ro device\n"); goto err; } ioreq->start = ioreq->req.sector_number * blkdev->file_blk; for (i = 0; i < ioreq->req.nr_segments; i++) { if (i == BLKIF_MAX_SEGMENTS_PER_REQUEST) { -xen_be_printf(&blkdev->xendev, 0, "error: nr_segments too big\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: nr_segments too big\n"); goto err; } if (ioreq->req.seg[i].first_sect > ioreq->req.seg[i].last_sect) { -xen_be_printf(&blkdev->xendev, 0, "error: first > last sector\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: first > last sector\n"); goto err; } if (ioreq->req.seg[i].last_sect * BLOCK_SIZE >= XC_PAGE_SIZE) { -xen_be_printf(&blkdev->xendev, 0, "error: page crossing\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: page crossing\n"); goto err; } @@ -308,7 +308,7 @@ static int ioreq_parse(struct ioreq *ioreq) qemu_iovec_add(&ioreq->v, (void*)mem, len); } if (ioreq->start + ioreq->v.size > blkdev->file_size) { -xen_be_printf(&blkdev->xendev, 0, "error: access beyond end of file\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: access beyond end of file\n"); goto err; } return 0; @@ -331,7 +331,7 @@ static void ioreq_unmap(struct ioreq *ioreq)
[Xen-devel] [PATCH v2 11/13] xen: Rename xen_be_evtchn_event
Prepare xen_be_evtchn_event to be shared with frontends: * xen_be_evtchn_event -> xen_pv_evtchn_event Signed-off-by: Emil Condrea Acked-by: Anthony PERARD Reviewed-by: Quan Xu --- hw/xen/xen_backend.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index e960dad..f594dba 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -581,7 +581,7 @@ int xen_be_bind_evtchn(struct XenDevice *xendev) } xen_pv_printf(xendev, 2, "bind evtchn port %d\n", xendev->local_port); qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), -xen_be_evtchn_event, NULL, xendev); +xen_pv_evtchn_event, NULL, xendev); return 0; } diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 8c7e3f5..28acf61 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -227,7 +227,7 @@ void xen_pv_printf(struct XenDevice *xendev, int msg_level, qemu_log_flush(); } -void xen_be_evtchn_event(void *opaque) +void xen_pv_evtchn_event(void *opaque) { struct XenDevice *xendev = opaque; evtchn_port_t port; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index 2e5d6e1..caf1edc 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -64,7 +64,7 @@ void xenstore_update(void *unused); const char *xenbus_strstate(enum xenbus_state state); -void xen_be_evtchn_event(void *opaque); +void xen_pv_evtchn_event(void *opaque); void xen_pv_insert_xendev(struct XenDevice *xendev); void xen_be_del_xendev(struct XenDevice *xendev); struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v2 07/13] xen: Move xenstore cleanup and mkdir functions
The name of the functions moved to xen_pvdev.c: * xenstore_cleanup_dir * xen_config_cleanup * xenstore_mkdir Signed-off-by: Emil Condrea Acked-by: Anthony PERARD --- hw/xen/xen_backend.c | 49 - hw/xen/xen_pvdev.c | 51 +++ 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 2875e7c..216072d 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -47,57 +47,8 @@ struct xs_handle *xenstore = NULL; const char *xen_protocol; /* private */ -struct xs_dirs { -char *xs_dir; -QTAILQ_ENTRY(xs_dirs) list; -}; -static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = -QTAILQ_HEAD_INITIALIZER(xs_cleanup); - static int debug; -static void xenstore_cleanup_dir(char *dir) -{ -struct xs_dirs *d; - -d = g_malloc(sizeof(*d)); -d->xs_dir = dir; -QTAILQ_INSERT_TAIL(&xs_cleanup, d, list); -} - -void xen_config_cleanup(void) -{ -struct xs_dirs *d; - -QTAILQ_FOREACH(d, &xs_cleanup, list) { -xs_rm(xenstore, 0, d->xs_dir); -} -} - -int xenstore_mkdir(char *path, int p) -{ -struct xs_permissions perms[2] = { -{ -.id= 0, /* set owner: dom0 */ -}, { -.id= xen_domid, -.perms = p, -} -}; - -if (!xs_mkdir(xenstore, 0, path)) { -xen_be_printf(NULL, 0, "xs_mkdir %s: failed\n", path); -return -1; -} -xenstore_cleanup_dir(g_strdup(path)); - -if (!xs_set_permissions(xenstore, 0, path, perms, 2)) { -xen_be_printf(NULL, 0, "xs_set_permissions %s: failed\n", path); -return -1; -} -return 0; -} - int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val) { return xenstore_write_str(xendev->be, node, val); diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 96ed2a3..e432d30 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -24,11 +24,62 @@ /* private */ static int debug; + +struct xs_dirs { +char *xs_dir; +QTAILQ_ENTRY(xs_dirs) list; +}; + +static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = +QTAILQ_HEAD_INITIALIZER(xs_cleanup); + static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs); /* - */ +static void xenstore_cleanup_dir(char *dir) +{ +struct xs_dirs *d; + +d = g_malloc(sizeof(*d)); +d->xs_dir = dir; +QTAILQ_INSERT_TAIL(&xs_cleanup, d, list); +} + +void xen_config_cleanup(void) +{ +struct xs_dirs *d; + +QTAILQ_FOREACH(d, &xs_cleanup, list) { +xs_rm(xenstore, 0, d->xs_dir); +} +} + +int xenstore_mkdir(char *path, int p) +{ +struct xs_permissions perms[2] = { +{ +.id= 0, /* set owner: dom0 */ +}, { +.id= xen_domid, +.perms = p, +} +}; + +if (!xs_mkdir(xenstore, 0, path)) { +xen_be_printf(NULL, 0, "xs_mkdir %s: failed\n", path); +return -1; +} +xenstore_cleanup_dir(g_strdup(path)); + +if (!xs_set_permissions(xenstore, 0, path, perms, 2)) { +xen_be_printf(NULL, 0, "xs_set_permissions %s: failed\n", path); +return -1; +} +return 0; +} + int xenstore_write_str(const char *base, const char *node, const char *val) { char abspath[XEN_BUFSIZE]; -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH v2 00/13] Refactor common part of xen backend and frontend
+ cc Paolo Bonzini On Thu, Oct 13, 2016 at 9:01 AM, Emil Condrea wrote: > This patch series was splitted from QEMU:Xen stubdom vTPM for HVM virtual > machine > http://markmail.org/message/fkix7g3a5zdj7lvr > > It contains a reorganization of xen backend and frontend functions together > with code style fixes. > Common functions shared by backends and frontends are moved to xen_pvdev file. > > --- > Changes in v2: > * fixed parameter alignment when spliting long lines > * removed patches for creating xen_frontend > > > Emil Condrea (13): > xen: Fix coding style errors > xen: Fix coding style warnings > xen: Create a new file xen_pvdev.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: Move xenstore cleanup and mkdir functions > 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 > > hw/block/xen_disk.c | 65 > hw/char/xen_console.c| 32 ++-- > hw/display/xenfb.c | 127 > hw/net/xen_nic.c | 36 +++-- > hw/usb/xen-usb.c | 46 +++--- > hw/xen/Makefile.objs | 2 +- > hw/xen/xen_backend.c | 348 > +-- > hw/xen/xen_devconfig.c | 4 +- > hw/xen/xen_pvdev.c | 316 +++ > include/hw/xen/xen_backend.h | 72 + > include/hw/xen/xen_pvdev.h | 78 ++ > xen-common.c | 4 +- > 12 files changed, 604 insertions(+), 526 deletions(-) > create mode 100644 hw/xen/xen_pvdev.c > create mode 100644 include/hw/xen/xen_pvdev.h > > -- > 1.9.1 > ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH 15/15] xen: Rename xen_be_frontend_changed
As you suggested, I've dropped the all patches for xen_frontend. Emil On Wed, Oct 12, 2016 at 2:00 PM, Paolo Bonzini wrote: > > > On 09/10/2016 21:50, Emil Condrea wrote: >> On Tue, Oct 4, 2016 at 11:06 AM, Paolo Bonzini wrote: >>> >>> >>> On 04/10/2016 08:43, Emil Condrea wrote: >>>> xen_be_frontend_changed -> xen_fe_frontend_changed >>> >>> This is not correct. The front-end is implemented in the guest domain, >>> while the back-end is implemented in the dom0 or stubdom. >>> >> >> You are right, thanks for the feedback! I will drop this patch >> together with the hunk >> from 04/15 patch which moves this function to xen_frontend.c > > Actually all of your new xen_frontend.c seems to be reading frontend > information from XenStore, which is typically something that the backend > does. So I suggest dropping the patch altogether. > > Thanks, > > Paolo > >>> This function processes *in the backed* a notification that the frontend >>> state changed, hence the name should be xen_be_frontend_changed. >>> >>> Paolo >>> >>>> Signed-off-by: Emil Condrea >>>> --- >>>> hw/xen/xen_backend.c | 2 +- >>>> hw/xen/xen_frontend.c | 4 ++-- >>>> include/hw/xen/xen_frontend.h | 2 +- >>>> 3 files changed, 4 insertions(+), 4 deletions(-) >>>> >>>> diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c >>>> index 30d3aaa..b79e83e 100644 >>>> --- a/hw/xen/xen_backend.c >>>> +++ b/hw/xen/xen_backend.c >>>> @@ -213,7 +213,7 @@ static int xen_be_try_setup(struct XenDevice *xendev) >>>> xen_be_set_state(xendev, XenbusStateInitialising); >>>> >>>> xen_be_backend_changed(xendev, NULL); >>>> -xen_be_frontend_changed(xendev, NULL); >>>> +xen_fe_frontend_changed(xendev, NULL); >>>> return 0; >>>> } >>>> >>>> diff --git a/hw/xen/xen_frontend.c b/hw/xen/xen_frontend.c >>>> index 1407f5f..761688b 100644 >>>> --- a/hw/xen/xen_frontend.c >>>> +++ b/hw/xen/xen_frontend.c >>>> @@ -39,7 +39,7 @@ int xenstore_read_fe_uint64(struct XenDevice *xendev, >>>> const char *node, >>>> return xenstore_read_uint64(xendev->fe, node, uval); >>>> } >>>> >>>> -void xen_be_frontend_changed(struct XenDevice *xendev, const char *node) >>>> +void xen_fe_frontend_changed(struct XenDevice *xendev, const char *node) >>>> { >>>> int fe_state; >>>> >>>> @@ -85,6 +85,6 @@ void xenstore_update_fe(char *watch, struct XenDevice >>>> *xendev) >>>> } >>>> node = watch + len + 1; >>>> >>>> -xen_be_frontend_changed(xendev, node); >>>> +xen_fe_frontend_changed(xendev, node); >>>> xen_be_check_state(xendev); >>>> } >>>> diff --git a/include/hw/xen/xen_frontend.h b/include/hw/xen/xen_frontend.h >>>> index bb0bc23..2a5f03f 100644 >>>> --- a/include/hw/xen/xen_frontend.h >>>> +++ b/include/hw/xen/xen_frontend.h >>>> @@ -9,6 +9,6 @@ int xenstore_read_fe_uint64(struct XenDevice *xendev, >>>> const char *node, >>>> uint64_t *uval); >>>> void xenstore_update_fe(char *watch, struct XenDevice *xendev); >>>> >>>> -void xen_be_frontend_changed(struct XenDevice *xendev, const char *node); >>>> +void xen_fe_frontend_changed(struct XenDevice *xendev, const char *node); >>>> >>>> #endif /* QEMU_HW_XEN_FRONTEND_H */ >>>> >> >> ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH 02/15] xen: Fix coding style warnings
Oh, I see. Because gmail messes up the alignment but raw diff looked fine I thought that you were seeing the same issue as I see on email client. I will align the quoted strings properly with the first parameter and I will send another series. Thanks, Emil On Thu, Oct 13, 2016 at 2:35 PM, Anthony PERARD wrote: > On Thu, Oct 13, 2016 at 07:04:56AM +0300, Emil Condrea wrote: >> On Tue, Oct 11, 2016 at 5:20 PM, Anthony PERARD >> wrote: >> > On Tue, Oct 04, 2016 at 09:43:31AM +0300, Emil Condrea wrote: >> >> Fixes: >> >> * WARNING: line over 80 characters >> >> >> >> Signed-off-by: Emil Condrea >> >> --- >> >> hw/block/xen_disk.c | 3 ++- >> >> hw/char/xen_console.c| 6 -- >> >> hw/display/xenfb.c | 30 -- >> >> hw/net/xen_nic.c | 12 >> >> hw/xen/xen_backend.c | 15 ++- >> >> include/hw/xen/xen_backend.h | 8 +--- >> >> 6 files changed, 49 insertions(+), 25 deletions(-) >> >> >> >> diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c >> >> index 5aa350a..24edeb2 100644 >> >> --- a/hw/block/xen_disk.c >> >> +++ b/hw/block/xen_disk.c >> >> @@ -1068,7 +1068,8 @@ static int blk_connect(struct XenDevice *xendev) >> >> blk_set_enable_write_cache(blkdev->blk, !writethrough); >> >> } else { >> >> /* setup via qemu cmdline -> already setup for us */ >> >> -xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline >> >> setup)\n"); >> >> +xen_be_printf(&blkdev->xendev, 2, >> >> + "get configured bdrv (cmdline setup)\n"); >> > >> > Arguments are usually aligned with the first one, so there is one >> > missing space. >> >> I guess this is displayed wrongly in the email client as in mine but the >> source >> of the email contains this patch http://pastebin.com/Sbk23h6m, which shows >> that >> this line is aligned to the first parameter. > > My mail client runs in a terminal, also I've apply the patches to a > local tree, so no display issue. > > Here, the quote is just below the open parentheses, but it's normally > one space futher. > > If I ask Vim to realign it, I end up with this: > xen_be_printf(&blkdev->xendev, 2, > - "get configured bdrv (cmdline setup)\n"); > + "get configured bdrv (cmdline setup)\n"); > > You can also have a look at other call of xen_be_printf() in this > function (blk_connect) to get an idea ;). > > -- > Anthony PERARD ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v3 12/13] xen: Rename xen_be_find_xendev
Prepare xen_be_find_xendev to be shared with frontends: * xen_be_find_xendev -> xen_pv_find_xendev Signed-off-by: Emil Condrea Acked-by: Anthony PERARD Reviewed-by: Quan Xu --- hw/display/xenfb.c | 4 ++-- hw/xen/xen_backend.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 184e735..7a8727a 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -988,8 +988,8 @@ void xen_init_display(int domid) wait_more: i++; main_loop_wait(true); -xfb = xen_be_find_xendev("vfb", domid, 0); -xin = xen_be_find_xendev("vkbd", domid, 0); +xfb = xen_pv_find_xendev("vfb", domid, 0); +xin = xen_pv_find_xendev("vkbd", domid, 0); if (!xfb || !xin) { if (i < 256) { usleep(1); diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index f594dba..98fcb77 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -114,7 +114,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, { struct XenDevice *xendev; -xendev = xen_be_find_xendev(type, dom, dev); +xendev = xen_pv_find_xendev(type, dom, dev); if (xendev) { return xendev; } diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 28acf61..af29150 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -264,7 +264,7 @@ int xen_pv_send_notify(struct XenDevice *xendev) /* - */ -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) +struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev) { struct XenDevice *xendev; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index caf1edc..4b1cc60 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -67,7 +67,7 @@ const char *xenbus_strstate(enum xenbus_state state); void xen_pv_evtchn_event(void *opaque); void xen_pv_insert_xendev(struct XenDevice *xendev); void xen_be_del_xendev(struct XenDevice *xendev); -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); +struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev); void xen_pv_unbind_evtchn(struct XenDevice *xendev); int xen_pv_send_notify(struct XenDevice *xendev); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v3 02/13] xen: Fix coding style warnings
Fixes: * WARNING: line over 80 characters Signed-off-by: Emil Condrea --- hw/block/xen_disk.c | 3 ++- hw/char/xen_console.c| 3 ++- hw/display/xenfb.c | 6 -- hw/net/xen_nic.c | 12 hw/xen/xen_backend.c | 15 ++- include/hw/xen/xen_backend.h | 8 +--- 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 1292a4b..5b037e7 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -1068,7 +1068,8 @@ static int blk_connect(struct XenDevice *xendev) blk_set_enable_write_cache(blkdev->blk, !writethrough); } else { /* setup via qemu cmdline -> already setup for us */ -xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n"); +xen_be_printf(&blkdev->xendev, 2, + "get configured bdrv (cmdline setup)\n"); blkdev->blk = blk_by_legacy_dinfo(blkdev->dinfo); if (blk_is_read_only(blkdev->blk) && !readonly) { xen_be_printf(&blkdev->xendev, 0, "Unexpected read-only drive"); diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index d236a46..9ae9558 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -248,7 +248,8 @@ static int con_initialise(struct XenDevice *xendev) qemu_chr_fe_set_handlers(&con->chr, xencons_can_receive, xencons_receive, NULL, con, NULL, true); -xen_be_printf(xendev, 1, "ring mfn %d, remote port %d, local port %d, limit %zd\n", +xen_be_printf(xendev, 1, + "ring mfn %d, remote port %d, local port %d, limit %zd\n", con->ring_ref, con->xendev.remote_port, con->xendev.local_port, diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index eaa1fce..d458fc1 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -561,7 +561,8 @@ static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, xenfb->offset = offset; xenfb->up_fullscreen = 1; xenfb->do_resize = 1; -xen_be_printf(&xenfb->c.xendev, 1, "framebuffer %dx%dx%d offset %d stride %d\n", +xen_be_printf(&xenfb->c.xendev, 1, + "framebuffer %dx%dx%d offset %d stride %d\n", width, height, depth, offset, row_stride); return 0; } @@ -729,7 +730,8 @@ static void xenfb_update(void *opaque) break; } dpy_gfx_replace_surface(xenfb->c.con, surface); -xen_be_printf(&xenfb->c.xendev, 1, "update: resizing: %dx%d @ %d bpp%s\n", +xen_be_printf(&xenfb->c.xendev, 1, + "update: resizing: %dx%d @ %d bpp%s\n", xenfb->width, xenfb->height, xenfb->depth, is_buffer_shared(surface) ? " (shared)" : ""); xenfb->up_fullscreen = 1; diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 9d93466..dbf3a89 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -140,7 +140,8 @@ static void net_tx_packets(struct XenNetDev *netdev) #endif if (txreq.size < 14) { -xen_be_printf(&netdev->xendev, 0, "bad packet size: %d\n", txreq.size); +xen_be_printf(&netdev->xendev, 0, "bad packet size: %d\n", + txreq.size); net_tx_error(netdev, &txreq, rc); continue; } @@ -213,7 +214,8 @@ static void net_rx_response(struct XenNetDev *netdev, resp->status = (int16_t)st; } -xen_be_printf(&netdev->xendev, 3, "rx response: idx %d, status %d, flags 0x%x\n", +xen_be_printf(&netdev->xendev, 3, + "rx response: idx %d, status %d, flags 0x%x\n", i, resp->status, resp->flags); netdev->rx_ring.rsp_prod_pvt = ++i; @@ -256,7 +258,8 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t size netdev->xendev.dom, rxreq.gref, PROT_WRITE); if (page == NULL) { -xen_be_printf(&netdev->xendev, 0, "error: rx gref dereference failed (%d)\n", +xen_be_printf(&netdev->xendev, 0, + "error: rx gref dereference failed (%d)\n", rxreq.gref); net_rx_response(netdev, &rxreq, NETIF_RSP_ERROR, 0, 0, 0); return -1; @@ -330,7 +333,8 @@ static int net_connect(struct XenDevice *xendev) rx_copy = 0; } if (rx_copy == 0) { -xen_be_printf(&netdev->xendev, 0, "frontend doesn't support rx-copy.\n&
[Xen-devel] [PATCH v3 03/13] xen: Create a new file xen_pvdev.c
The purpose of the new file is to store generic functions shared by frontend and backends such as xenstore operations, xendevs. Signed-off-by: Quan Xu Signed-off-by: Emil Condrea --- hw/xen/Makefile.objs | 2 +- hw/xen/xen_backend.c | 126 +--- hw/xen/xen_pvdev.c | 150 +++ include/hw/xen/xen_backend.h | 64 +- include/hw/xen/xen_pvdev.h | 69 5 files changed, 222 insertions(+), 189 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 0e95880..b32b0dd 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 @@ -57,8 +58,6 @@ static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs); static int debug; -/* - */ - static void xenstore_cleanup_dir(char *dir) { struct xs_dirs *d; @@ -77,34 +76,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] = { @@ -129,48 +100,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]; - -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; -} - int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val) { return xenstore_write_str(xendev->be, node, val); @@ -214,20 +143,6 @@ int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, /* - */ -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; @@ -827,45 +742,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 message
[Xen-devel] [PATCH v3 04/13] xen: Move xenstore_update to xen_pvdev.c
* xenstore_update -> xen_pvdev.c Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 30 +++--- hw/xen/xen_pvdev.c | 23 +++ include/hw/xen/xen_backend.h | 3 +++ include/hw/xen/xen_pvdev.h | 1 + 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index b32b0dd..e3a7d95 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -556,8 +556,8 @@ static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops) return 0; } -static void xenstore_update_be(char *watch, char *type, int dom, - struct XenDevOps *ops) +void xenstore_update_be(char *watch, char *type, int dom, +struct XenDevOps *ops) { struct XenDevice *xendev; char path[XEN_BUFSIZE], *bepath; @@ -590,7 +590,7 @@ static void xenstore_update_be(char *watch, char *type, int dom, } } -static void xenstore_update_fe(char *watch, struct XenDevice *xendev) +void xenstore_update_fe(char *watch, struct XenDevice *xendev) { char *node; unsigned int len; @@ -607,30 +607,6 @@ static void xenstore_update_fe(char *watch, struct XenDevice *xendev) xen_be_frontend_changed(xendev, node); xen_be_check_state(xendev); } - -static void xenstore_update(void *unused) -{ -char **vec = NULL; -intptr_t type, ops, ptr; -unsigned int dom, count; - -vec = xs_read_watch(xenstore, &count); -if (vec == NULL) { -goto cleanup; -} - -if (sscanf(vec[XS_WATCH_TOKEN], "be:%" PRIxPTR ":%d:%" PRIxPTR, - &type, &dom, &ops) == 3) { -xenstore_update_be(vec[XS_WATCH_PATH], (void *)type, dom, (void*)ops); -} -if (sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr) == 1) { -xenstore_update_fe(vec[XS_WATCH_PATH], (void *)ptr); -} - -cleanup: -free(vec); -} - static void xen_be_evtchn_event(void *opaque) { struct XenDevice *xendev = opaque; diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index a1dc2be..22a1abe 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -95,6 +95,29 @@ int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval) return rc; } +void xenstore_update(void *unused) +{ +char **vec = NULL; +intptr_t type, ops, ptr; +unsigned int dom, count; + +vec = xs_read_watch(xenstore, &count); +if (vec == NULL) { +goto cleanup; +} + +if (sscanf(vec[XS_WATCH_TOKEN], "be:%" PRIxPTR ":%d:%" PRIxPTR, + &type, &dom, &ops) == 3) { +xenstore_update_be(vec[XS_WATCH_PATH], (void *)type, dom, (void*)ops); +} +if (sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr) == 1) { +xenstore_update_fe(vec[XS_WATCH_PATH], (void *)ptr); +} + +cleanup: +free(vec); +} + const char *xenbus_strstate(enum xenbus_state state) { static const char *const name[] = { diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 973cb4b..2e54150 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -19,6 +19,9 @@ 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); char *xenstore_read_be_str(struct XenDevice *xendev, const char *node); int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int *ival); +void xenstore_update_fe(char *watch, struct XenDevice *xendev); +void xenstore_update_be(char *watch, char *type, int dom, +struct XenDevOps *ops); 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_fe_uint64(struct XenDevice *xendev, const char *node, diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index cd3d6bc..3c4cc01 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -60,6 +60,7 @@ 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); +void xenstore_update(void *unused); const char *xenbus_strstate(enum xenbus_state state); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v3 13/13] xen: Rename xen_be_del_xendev
Prepare xen_be_del_xendev to be shared with frontends: * xen_be_del_xendev -> xen_pv_del_xendev Signed-off-by: Emil Condrea Acked-by: Anthony PERARD Reviewed-by: Quan Xu --- hw/xen/xen_backend.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 98fcb77..41ba5c5 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -483,7 +483,7 @@ void xenstore_update_be(char *watch, char *type, int dom, if (xendev != NULL) { bepath = xs_read(xenstore, 0, xendev->be, &len); if (bepath == NULL) { -xen_be_del_xendev(xendev); +xen_pv_del_xendev(xendev); } else { free(bepath); xen_be_backend_changed(xendev, path); diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index af29150..405e154 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -286,7 +286,7 @@ struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev) /* * release xen backend device. */ -void xen_be_del_xendev(struct XenDevice *xendev) +void xen_pv_del_xendev(struct XenDevice *xendev) { if (xendev->ops->free) { xendev->ops->free(xendev); diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index 4b1cc60..083f0a9 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -66,7 +66,7 @@ const char *xenbus_strstate(enum xenbus_state state); void xen_pv_evtchn_event(void *opaque); void xen_pv_insert_xendev(struct XenDevice *xendev); -void xen_be_del_xendev(struct XenDevice *xendev); +void xen_pv_del_xendev(struct XenDevice *xendev); struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev); void xen_pv_unbind_evtchn(struct XenDevice *xendev); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v3 05/13] xen: Move evtchn functions to xen_pvdev.c
The name of the functions moved: * xen_be_evtchn_event * xen_be_unbind_evtchn * xen_be_send_notify Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 35 --- hw/xen/xen_pvdev.c | 35 +++ include/hw/xen/xen_backend.h | 2 -- include/hw/xen/xen_pvdev.h | 4 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index e3a7d95..1487db2 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -607,25 +607,6 @@ void xenstore_update_fe(char *watch, struct XenDevice *xendev) xen_be_frontend_changed(xendev, node); xen_be_check_state(xendev); } -static void xen_be_evtchn_event(void *opaque) -{ -struct XenDevice *xendev = opaque; -evtchn_port_t port; - -port = xenevtchn_pending(xendev->evtchndev); -if (port != xendev->local_port) { -xen_be_printf(xendev, 0, - "xenevtchn_pending returned %d (expected %d)\n", - port, xendev->local_port); -return; -} -xenevtchn_unmask(xendev->evtchndev, port); - -if (xendev->ops->event) { -xendev->ops->event(xendev); -} -} - /* */ int xen_be_init(void) @@ -702,22 +683,6 @@ int xen_be_bind_evtchn(struct XenDevice *xendev) return 0; } -void xen_be_unbind_evtchn(struct XenDevice *xendev) -{ -if (xendev->local_port == -1) { -return; -} -qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), NULL, NULL, NULL); -xenevtchn_unbind(xendev->evtchndev, xendev->local_port); -xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port); -xendev->local_port = -1; -} - -int xen_be_send_notify(struct XenDevice *xendev) -{ -return xenevtchn_notify(xendev->evtchndev, xendev->local_port); -} - static int xen_sysdev_init(SysBusDevice *dev) { diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 22a1abe..7607e44 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -171,3 +171,38 @@ void xen_be_printf(struct XenDevice *xendev, int msg_level, } qemu_log_flush(); } + +void xen_be_evtchn_event(void *opaque) +{ +struct XenDevice *xendev = opaque; +evtchn_port_t port; + +port = xenevtchn_pending(xendev->evtchndev); +if (port != xendev->local_port) { +xen_be_printf(xendev, 0, + "xenevtchn_pending returned %d (expected %d)\n", + port, xendev->local_port); +return; +} +xenevtchn_unmask(xendev->evtchndev, port); + +if (xendev->ops->event) { +xendev->ops->event(xendev); +} +} + +void xen_be_unbind_evtchn(struct XenDevice *xendev) +{ +if (xendev->local_port == -1) { +return; +} +qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), NULL, NULL, NULL); +xenevtchn_unbind(xendev->evtchndev, xendev->local_port); +xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port); +xendev->local_port = -1; +} + +int xen_be_send_notify(struct XenDevice *xendev) +{ +return xenevtchn_notify(xendev->evtchndev, xendev->local_port); +} diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 2e54150..6c617d9 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -36,8 +36,6 @@ void xen_be_register_common(void); int xen_be_register(const char *type, struct XenDevOps *ops); 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); /* 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 index 3c4cc01..a8da3da 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -64,6 +64,10 @@ void xenstore_update(void *unused); const char *xenbus_strstate(enum xenbus_state state); +void xen_be_evtchn_event(void *opaque); +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); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v3 00/13] Refactor common part of xen backend and frontend
This patch series was splitted from QEMU:Xen stubdom vTPM for HVM virtual machine http://markmail.org/message/fkix7g3a5zdj7lvr It contains a reorganization of xen backend and frontend functions together with code style fixes. Common functions shared by backends and frontends are moved to xen_pvdev file. --- Changes in v3: * align second line with first parameter Changes in v2: * fixed parameter alignment when spliting long lines * removed patches for creating xen_frontend Emil Condrea (13): xen: Fix coding style errors xen: Fix coding style warnings xen: Create a new file xen_pvdev.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: Move xenstore cleanup and mkdir functions 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 hw/block/xen_disk.c | 65 hw/char/xen_console.c| 30 ++-- hw/display/xenfb.c | 127 hw/net/xen_nic.c | 36 +++-- hw/usb/xen-usb.c | 46 +++--- hw/xen/Makefile.objs | 2 +- hw/xen/xen_backend.c | 348 +-- hw/xen/xen_devconfig.c | 4 +- hw/xen/xen_pvdev.c | 316 +++ include/hw/xen/xen_backend.h | 72 + include/hw/xen/xen_pvdev.h | 78 ++ xen-common.c | 4 +- 12 files changed, 603 insertions(+), 525 deletions(-) create mode 100644 hw/xen/xen_pvdev.c create mode 100644 include/hw/xen/xen_pvdev.h -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v3 10/13] xen: Rename xen_be_send_notify
Prepare xen_be_send_notify to be shared with frontends: * xen_be_send_notify -> xen_pv_send_notify Signed-off-by: Emil Condrea Acked-by: Anthony PERARD Reviewed-by: Quan Xu --- hw/block/xen_disk.c| 4 ++-- hw/char/xen_console.c | 4 ++-- hw/display/xenfb.c | 8 hw/net/xen_nic.c | 4 ++-- hw/usb/xen-usb.c | 6 +++--- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 8f7fe41..3a7dc19 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -796,7 +796,7 @@ static void blk_send_response_all(struct XenBlkDev *blkdev) ioreq_release(ioreq, true); } if (send_notify) { -xen_be_send_notify(&blkdev->xendev); +xen_pv_send_notify(&blkdev->xendev); } } @@ -866,7 +866,7 @@ static void blk_handle_requests(struct XenBlkDev *blkdev) }; if (blk_send_response_one(ioreq)) { -xen_be_send_notify(&blkdev->xendev); +xen_pv_send_notify(&blkdev->xendev); } ioreq_release(ioreq, false); continue; diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 15463dc..c01f410 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -74,7 +74,7 @@ static void buffer_append(struct XenConsole *con) xen_mb(); intf->out_cons = cons; -xen_be_send_notify(&con->xendev); +xen_pv_send_notify(&con->xendev); if (buffer->max_capacity && buffer->size > buffer->max_capacity) { @@ -142,7 +142,7 @@ static void xencons_receive(void *opaque, const uint8_t *buf, int len) } xen_wmb(); intf->in_prod = prod; -xen_be_send_notify(&con->xendev); +xen_pv_send_notify(&con->xendev); } static void xencons_send(struct XenConsole *con) diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 1077575..184e735 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -215,7 +215,7 @@ static int xenfb_kbd_event(struct XenInput *xenfb, XENKBD_IN_RING_REF(page, prod) = *event; xen_wmb(); /* ensure ring contents visible */ page->in_prod = prod + 1; -return xen_be_send_notify(&xenfb->c.xendev); +return xen_pv_send_notify(&xenfb->c.xendev); } /* Send a keyboard (or mouse button) event */ @@ -397,7 +397,7 @@ static void input_event(struct XenDevice *xendev) if (page->out_prod == page->out_cons) return; page->out_cons = page->out_prod; -xen_be_send_notify(&xenfb->c.xendev); +xen_pv_send_notify(&xenfb->c.xendev); } /* */ @@ -672,7 +672,7 @@ static void xenfb_send_event(struct XenFB *xenfb, union xenfb_in_event *event) xen_wmb(); /* ensure ring contents visible */ page->in_prod = prod + 1; -xen_be_send_notify(&xenfb->c.xendev); +xen_pv_send_notify(&xenfb->c.xendev); } static void xenfb_send_refresh_period(struct XenFB *xenfb, int period) @@ -945,7 +945,7 @@ static void fb_event(struct XenDevice *xendev) struct XenFB *xenfb = container_of(xendev, struct XenFB, c.xendev); xenfb_handle_events(xenfb); -xen_be_send_notify(&xenfb->c.xendev); +xen_pv_send_notify(&xenfb->c.xendev); } /* */ diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index c996684..20c43a6 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -69,7 +69,7 @@ static void net_tx_response(struct XenNetDev *netdev, netif_tx_request_t *txp, i netdev->tx_ring.rsp_prod_pvt = ++i; RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netdev->tx_ring, notify); if (notify) { -xen_be_send_notify(&netdev->xendev); +xen_pv_send_notify(&netdev->xendev); } if (i == netdev->tx_ring.req_cons) { @@ -221,7 +221,7 @@ static void net_rx_response(struct XenNetDev *netdev, netdev->rx_ring.rsp_prod_pvt = ++i; RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netdev->rx_ring, notify); if (notify) { -xen_be_send_notify(&netdev->xendev); +xen_pv_send_notify(&netdev->xendev); } } diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c index 4ae9b6a..1b3c2fb 100644 --- a/hw/usb/xen-usb.c +++ b/hw/usb/xen-usb.c @@ -314,7 +314,7 @@ static void usbback_do_response(struct usbback_req *usbback_req, int32_t status, RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&usbif->urb_ring, notify); if (notify) { -xen_be_send_notify(xendev); +xen_pv_send_notify(xendev); } } @@ -590,7 +590,7 @@ static void usbback_hotplug_notify(struct usbback_info *usbif) /* Check for fu
[Xen-devel] [PATCH v3 09/13] xen: Rename xen_be_unbind_evtchn
Prepare xen_be_unbind_evtchn to be shared with frontends: * xen_be_unbind_evtchn -> xen_pv_unbind_evtchn Signed-off-by: Emil Condrea Acked-by: Anthony PERARD Reviewed-by: Quan Xu --- hw/block/xen_disk.c| 2 +- hw/char/xen_console.c | 2 +- hw/display/xenfb.c | 2 +- hw/net/xen_nic.c | 2 +- hw/usb/xen-usb.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 6145567..8f7fe41 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -1194,7 +1194,7 @@ static void blk_disconnect(struct XenDevice *xendev) blk_unref(blkdev->blk); blkdev->blk = NULL; } -xen_be_unbind_evtchn(&blkdev->xendev); +xen_pv_unbind_evtchn(&blkdev->xendev); if (blkdev->sring) { xengnttab_unmap(blkdev->xendev.gnttabdev, blkdev->sring, 1); diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index aa7a27e..15463dc 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -262,7 +262,7 @@ static void con_disconnect(struct XenDevice *xendev) struct XenConsole *con = container_of(xendev, struct XenConsole, xendev); qemu_chr_fe_deinit(&con->chr); -xen_be_unbind_evtchn(&con->xendev); +xen_pv_unbind_evtchn(&con->xendev); if (con->sring) { if (!xendev->dev) { diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index d7b94b0..1077575 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -112,7 +112,7 @@ static int common_bind(struct common *c) static void common_unbind(struct common *c) { -xen_be_unbind_evtchn(&c->xendev); +xen_pv_unbind_evtchn(&c->xendev); if (c->page) { xenforeignmemory_unmap(xen_fmem, c->page, 1); c->page = NULL; diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 2d6e033..c996684 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -372,7 +372,7 @@ static void net_disconnect(struct XenDevice *xendev) { struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev); -xen_be_unbind_evtchn(&netdev->xendev); +xen_pv_unbind_evtchn(&netdev->xendev); if (netdev->txs) { xengnttab_unmap(netdev->xendev.gnttabdev, netdev->txs, 1); diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c index 6b06fd8..4ae9b6a 100644 --- a/hw/usb/xen-usb.c +++ b/hw/usb/xen-usb.c @@ -834,7 +834,7 @@ static void usbback_disconnect(struct XenDevice *xendev) usbif = container_of(xendev, struct usbback_info, xendev); -xen_be_unbind_evtchn(xendev); +xen_pv_unbind_evtchn(xendev); if (usbif->urb_sring) { xengnttab_unmap(xendev->gnttabdev, usbif->urb_sring, 1); diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 6938c09..b362eb7 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -246,7 +246,7 @@ void xen_be_evtchn_event(void *opaque) } } -void xen_be_unbind_evtchn(struct XenDevice *xendev) +void xen_pv_unbind_evtchn(struct XenDevice *xendev) { if (xendev->local_port == -1) { return; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index 7aedc91..1aff68c 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -69,7 +69,7 @@ void xen_pv_insert_xendev(struct XenDevice *xendev); void xen_be_del_xendev(struct XenDevice *xendev); struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); -void xen_be_unbind_evtchn(struct XenDevice *xendev); +void xen_pv_unbind_evtchn(struct XenDevice *xendev); int xen_be_send_notify(struct XenDevice *xendev); void xen_pv_printf(struct XenDevice *xendev, int msg_level, -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v3 07/13] xen: Move xenstore cleanup and mkdir functions
The name of the functions moved to xen_pvdev.c: * xenstore_cleanup_dir * xen_config_cleanup * xenstore_mkdir Signed-off-by: Emil Condrea Acked-by: Anthony PERARD --- hw/xen/xen_backend.c | 49 - hw/xen/xen_pvdev.c | 51 +++ 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 2875e7c..216072d 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -47,57 +47,8 @@ struct xs_handle *xenstore = NULL; const char *xen_protocol; /* private */ -struct xs_dirs { -char *xs_dir; -QTAILQ_ENTRY(xs_dirs) list; -}; -static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = -QTAILQ_HEAD_INITIALIZER(xs_cleanup); - static int debug; -static void xenstore_cleanup_dir(char *dir) -{ -struct xs_dirs *d; - -d = g_malloc(sizeof(*d)); -d->xs_dir = dir; -QTAILQ_INSERT_TAIL(&xs_cleanup, d, list); -} - -void xen_config_cleanup(void) -{ -struct xs_dirs *d; - -QTAILQ_FOREACH(d, &xs_cleanup, list) { -xs_rm(xenstore, 0, d->xs_dir); -} -} - -int xenstore_mkdir(char *path, int p) -{ -struct xs_permissions perms[2] = { -{ -.id= 0, /* set owner: dom0 */ -}, { -.id= xen_domid, -.perms = p, -} -}; - -if (!xs_mkdir(xenstore, 0, path)) { -xen_be_printf(NULL, 0, "xs_mkdir %s: failed\n", path); -return -1; -} -xenstore_cleanup_dir(g_strdup(path)); - -if (!xs_set_permissions(xenstore, 0, path, perms, 2)) { -xen_be_printf(NULL, 0, "xs_set_permissions %s: failed\n", path); -return -1; -} -return 0; -} - int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val) { return xenstore_write_str(xendev->be, node, val); diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 96ed2a3..e432d30 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -24,11 +24,62 @@ /* private */ static int debug; + +struct xs_dirs { +char *xs_dir; +QTAILQ_ENTRY(xs_dirs) list; +}; + +static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = +QTAILQ_HEAD_INITIALIZER(xs_cleanup); + static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs); /* - */ +static void xenstore_cleanup_dir(char *dir) +{ +struct xs_dirs *d; + +d = g_malloc(sizeof(*d)); +d->xs_dir = dir; +QTAILQ_INSERT_TAIL(&xs_cleanup, d, list); +} + +void xen_config_cleanup(void) +{ +struct xs_dirs *d; + +QTAILQ_FOREACH(d, &xs_cleanup, list) { +xs_rm(xenstore, 0, d->xs_dir); +} +} + +int xenstore_mkdir(char *path, int p) +{ +struct xs_permissions perms[2] = { +{ +.id= 0, /* set owner: dom0 */ +}, { +.id= xen_domid, +.perms = p, +} +}; + +if (!xs_mkdir(xenstore, 0, path)) { +xen_be_printf(NULL, 0, "xs_mkdir %s: failed\n", path); +return -1; +} +xenstore_cleanup_dir(g_strdup(path)); + +if (!xs_set_permissions(xenstore, 0, path, perms, 2)) { +xen_be_printf(NULL, 0, "xs_set_permissions %s: failed\n", path); +return -1; +} +return 0; +} + int xenstore_write_str(const char *base, const char *node, const char *val) { char abspath[XEN_BUFSIZE]; -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH v3 06/13] xen: Prepare xendev qtail to be shared with frontends
* move xendevs qtail to xen_pvdev.c * change xen_be_get_xendev to use a new function: xen_pv_insert_xendev Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 51 +-- hw/xen/xen_pvdev.c | 57 include/hw/xen/xen_backend.h | 1 - include/hw/xen/xen_pvdev.h | 4 4 files changed, 62 insertions(+), 51 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 1487db2..2875e7c 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -54,8 +54,6 @@ struct xs_dirs { static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = QTAILQ_HEAD_INITIALIZER(xs_cleanup); -static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = -QTAILQ_HEAD_INITIALIZER(xendevs); static int debug; static void xenstore_cleanup_dir(char *dir) @@ -157,27 +155,6 @@ int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state) return 0; } -/* - */ - -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) -{ -struct XenDevice *xendev; - -QTAILQ_FOREACH(xendev, &xendevs, next) { -if (xendev->dom != dom) { -continue; -} -if (xendev->dev != dev) { -continue; -} -if (strcmp(xendev->type, type) != 0) { -continue; -} -return xendev; -} -return NULL; -} - /* * get xen backend device, allocate a new one if it doesn't exist. */ @@ -226,7 +203,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, xendev->gnttabdev = NULL; } -QTAILQ_INSERT_TAIL(&xendevs, xendev, next); +xen_pv_insert_xendev(xendev); if (xendev->ops->alloc) { xendev->ops->alloc(xendev); @@ -235,32 +212,6 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, return xendev; } -/* - * release xen backend device. - */ -static void xen_be_del_xendev(struct XenDevice *xendev) -{ -if (xendev->ops->free) { -xendev->ops->free(xendev); -} - -if (xendev->fe) { -char token[XEN_BUFSIZE]; -snprintf(token, sizeof(token), "fe:%p", xendev); -xs_unwatch(xenstore, xendev->fe, token); -g_free(xendev->fe); -} - -if (xendev->evtchndev != NULL) { -xenevtchn_close(xendev->evtchndev); -} -if (xendev->gnttabdev != NULL) { -xengnttab_close(xendev->gnttabdev); -} - -QTAILQ_REMOVE(&xendevs, xendev, next); -g_free(xendev); -} /* * Sync internal data structures on xenstore updates. diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 7607e44..96ed2a3 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -22,7 +22,11 @@ #include "hw/xen/xen_backend.h" #include "hw/xen/xen_pvdev.h" +/* private */ static int debug; +static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = +QTAILQ_HEAD_INITIALIZER(xendevs); + /* - */ int xenstore_write_str(const char *base, const char *node, const char *val) @@ -206,3 +210,56 @@ int xen_be_send_notify(struct XenDevice *xendev) { return xenevtchn_notify(xendev->evtchndev, xendev->local_port); } + +/* - */ + +struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) +{ +struct XenDevice *xendev; + +QTAILQ_FOREACH(xendev, &xendevs, next) { +if (xendev->dom != dom) { +continue; +} +if (xendev->dev != dev) { +continue; +} +if (strcmp(xendev->type, type) != 0) { +continue; +} +return xendev; +} +return NULL; +} + +/* + * release xen backend device. + */ +void xen_be_del_xendev(struct XenDevice *xendev) +{ +if (xendev->ops->free) { +xendev->ops->free(xendev); +} + +if (xendev->fe) { +char token[XEN_BUFSIZE]; +snprintf(token, sizeof(token), "fe:%p", xendev); +xs_unwatch(xenstore, xendev->fe, token); +g_free(xendev->fe); +} + +if (xendev->evtchndev != NULL) { +xenevtchn_close(xendev->evtchndev); +} +if (xendev->gnttabdev != NULL) { +xengnttab_close(xendev->gnttabdev); +} + +QTAILQ_REMOVE(&xendevs, xendev, next); +g_free(xendev); +} + +void xen_pv_insert_xendev(struct XenDevice *xendev) +{ +QTAILQ_INSERT_TAIL(&xendevs, xendev, next); +} diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 6c617d9..cbda40e 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -27,7 +27,6 @@ int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival);
[Xen-devel] [PATCH v3 08/13] xen: Rename xen_be_printf to xen_pv_printf
Prepare xen_be_printf to be used by both backend and frontends: * xen_be_printf -> xen_pv_printf Signed-off-by: Emil Condrea Acked-by: Anthony PERARD --- hw/block/xen_disk.c| 58 +++--- hw/char/xen_console.c | 8 +++ hw/display/xenfb.c | 42 - hw/net/xen_nic.c | 22 +- hw/usb/xen-usb.c | 38 +++--- hw/xen/xen_backend.c | 46 ++-- hw/xen/xen_devconfig.c | 4 ++-- hw/xen/xen_pvdev.c | 10 include/hw/xen/xen_pvdev.h | 2 +- xen-common.c | 4 ++-- 10 files changed, 117 insertions(+), 117 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 5b037e7..6145567 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -167,12 +167,12 @@ static void destroy_grant(gpointer pgnt) xengnttab_handle *gnt = grant->blkdev->xendev.gnttabdev; if (xengnttab_unmap(gnt, grant->page, 1) != 0) { -xen_be_printf(&grant->blkdev->xendev, 0, +xen_pv_printf(&grant->blkdev->xendev, 0, "xengnttab_unmap failed: %s\n", strerror(errno)); } grant->blkdev->persistent_gnt_count--; -xen_be_printf(&grant->blkdev->xendev, 3, +xen_pv_printf(&grant->blkdev->xendev, 3, "unmapped grant %p\n", grant->page); g_free(grant); } @@ -184,11 +184,11 @@ static void remove_persistent_region(gpointer data, gpointer dev) xengnttab_handle *gnt = blkdev->xendev.gnttabdev; if (xengnttab_unmap(gnt, region->addr, region->num) != 0) { -xen_be_printf(&blkdev->xendev, 0, +xen_pv_printf(&blkdev->xendev, 0, "xengnttab_unmap region %p failed: %s\n", region->addr, strerror(errno)); } -xen_be_printf(&blkdev->xendev, 3, +xen_pv_printf(&blkdev->xendev, 3, "unmapped grant region %p with %d pages\n", region->addr, region->num); g_free(region); @@ -255,7 +255,7 @@ static int ioreq_parse(struct ioreq *ioreq) size_t len; int i; -xen_be_printf(&blkdev->xendev, 3, +xen_pv_printf(&blkdev->xendev, 3, "op %d, nr %d, handle %d, id %" PRId64 ", sector %" PRId64 "\n", ioreq->req.operation, ioreq->req.nr_segments, ioreq->req.handle, ioreq->req.id, ioreq->req.sector_number); @@ -275,28 +275,28 @@ static int ioreq_parse(struct ioreq *ioreq) case BLKIF_OP_DISCARD: return 0; default: -xen_be_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n", +xen_pv_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n", ioreq->req.operation); goto err; }; if (ioreq->req.operation != BLKIF_OP_READ && blkdev->mode[0] != 'w') { -xen_be_printf(&blkdev->xendev, 0, "error: write req for ro device\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: write req for ro device\n"); goto err; } ioreq->start = ioreq->req.sector_number * blkdev->file_blk; for (i = 0; i < ioreq->req.nr_segments; i++) { if (i == BLKIF_MAX_SEGMENTS_PER_REQUEST) { -xen_be_printf(&blkdev->xendev, 0, "error: nr_segments too big\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: nr_segments too big\n"); goto err; } if (ioreq->req.seg[i].first_sect > ioreq->req.seg[i].last_sect) { -xen_be_printf(&blkdev->xendev, 0, "error: first > last sector\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: first > last sector\n"); goto err; } if (ioreq->req.seg[i].last_sect * BLOCK_SIZE >= XC_PAGE_SIZE) { -xen_be_printf(&blkdev->xendev, 0, "error: page crossing\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: page crossing\n"); goto err; } @@ -308,7 +308,7 @@ static int ioreq_parse(struct ioreq *ioreq) qemu_iovec_add(&ioreq->v, (void*)mem, len); } if (ioreq->start + ioreq->v.size > blkdev->file_size) { -xen_be_printf(&blkdev->xendev, 0, "error: access beyond end of file\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: access beyond end of file\n"); goto err; } return 0; @@ -331,7 +331,7 @@ static void ioreq_unmap(struct ioreq *ioreq)
[Xen-devel] [PATCH v3 01/13] xen: Fix coding style errors
Fixes the following errors: * ERROR: line over 90 characters * ERROR: code indent should never use tabs * ERROR: space prohibited after that open square bracket '[' * ERROR: do not initialise statics to 0 or NULL * ERROR: "(foo*)" should be "(foo *)" Signed-off-by: Emil Condrea --- hw/char/xen_console.c | 21 ++-- hw/display/xenfb.c| 91 --- hw/net/xen_nic.c | 8 +++-- hw/xen/xen_backend.c | 20 +-- 4 files changed, 76 insertions(+), 64 deletions(-) diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 86cdc52..d236a46 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -158,16 +158,17 @@ static void xencons_send(struct XenConsole *con) len = size; } if (len < 1) { - if (!con->backlog) { - con->backlog = 1; - xen_be_printf(&con->xendev, 1, "backlog piling up, nobody listening?\n"); - } +if (!con->backlog) { +con->backlog = 1; +xen_be_printf(&con->xendev, 1, + "backlog piling up, nobody listening?\n"); +} } else { - buffer_advance(&con->buffer, len); - if (con->backlog && len == size) { - con->backlog = 0; - xen_be_printf(&con->xendev, 1, "backlog is gone\n"); - } +buffer_advance(&con->buffer, len); +if (con->backlog && len == size) { +con->backlog = 0; +xen_be_printf(&con->xendev, 1, "backlog is gone\n"); +} } } @@ -191,7 +192,7 @@ static int con_init(struct XenDevice *xendev) type = xenstore_read_str(con->console, "type"); if (!type || strcmp(type, "ioemu") != 0) { - xen_be_printf(xendev, 1, "not for me (type=%s)\n", type); +xen_be_printf(xendev, 1, "not for me (type=%s)\n", type); ret = -1; goto out; } diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 46b7d5e..eaa1fce 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -90,21 +90,22 @@ static int common_bind(struct common *c) xen_pfn_t mfn; if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &val) == -1) - return -1; +return -1; mfn = (xen_pfn_t)val; assert(val == mfn); if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1) - return -1; +return -1; c->page = xenforeignmemory_map(xen_fmem, c->xendev.dom, PROT_READ | PROT_WRITE, 1, &mfn, NULL); if (c->page == NULL) - return -1; +return -1; xen_be_bind_evtchn(&c->xendev); -xen_be_printf(&c->xendev, 1, "ring mfn %"PRI_xen_pfn", remote-port %d, local-port %d\n", - mfn, c->xendev.remote_port, c->xendev.local_port); +xen_be_printf(&c->xendev, 1, + "ring mfn %"PRI_xen_pfn", remote-port %d, local-port %d\n", + mfn, c->xendev.remote_port, c->xendev.local_port); return 0; } @@ -500,8 +501,8 @@ out: } static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, - int width, int height, int depth, - size_t fb_len, int offset, int row_stride) + int width, int height, int depth, + size_t fb_len, int offset, int row_stride) { size_t mfn_sz = sizeof(*((struct xenfb_page *)0)->pd); size_t pd_len = sizeof(((struct xenfb_page *)0)->pd) / mfn_sz; @@ -510,40 +511,47 @@ static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, int max_width, max_height; if (fb_len_lim > fb_len_max) { - xen_be_printf(&xenfb->c.xendev, 0, "fb size limit %zu exceeds %zu, corrected\n", - fb_len_lim, fb_len_max); - fb_len_lim = fb_len_max; +xen_be_printf(&xenfb->c.xendev, 0, + "fb size limit %zu exceeds %zu, corrected\n", + fb_len_lim, fb_len_max); +fb_len_lim = fb_len_max; } if (fb_len_lim && fb_len > fb_len_lim) { - xen_be_printf(&xenfb->c.xendev, 0, "frontend fb size %zu limited to %zu\n", - fb_len, fb_len_lim); - fb_len = fb_len_lim; +xen_be_printf(&xenfb->c.xendev, 0, + "frontend fb size %zu limited to %zu\n", + fb_len, fb_len_lim); +fb_len = fb_len_lim; } if (depth != 8 && depth != 16 && depth != 24 && depth != 32) { - xen_
[Xen-devel] [PATCH v3 11/13] xen: Rename xen_be_evtchn_event
Prepare xen_be_evtchn_event to be shared with frontends: * xen_be_evtchn_event -> xen_pv_evtchn_event Signed-off-by: Emil Condrea Acked-by: Anthony PERARD Reviewed-by: Quan Xu --- hw/xen/xen_backend.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index e960dad..f594dba 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -581,7 +581,7 @@ int xen_be_bind_evtchn(struct XenDevice *xendev) } xen_pv_printf(xendev, 2, "bind evtchn port %d\n", xendev->local_port); qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), -xen_be_evtchn_event, NULL, xendev); +xen_pv_evtchn_event, NULL, xendev); return 0; } diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 8c7e3f5..28acf61 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -227,7 +227,7 @@ void xen_pv_printf(struct XenDevice *xendev, int msg_level, qemu_log_flush(); } -void xen_be_evtchn_event(void *opaque) +void xen_pv_evtchn_event(void *opaque) { struct XenDevice *xendev = opaque; evtchn_port_t port; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index 2e5d6e1..caf1edc 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -64,7 +64,7 @@ void xenstore_update(void *unused); const char *xenbus_strstate(enum xenbus_state state); -void xen_be_evtchn_event(void *opaque); +void xen_pv_evtchn_event(void *opaque); void xen_pv_insert_xendev(struct XenDevice *xendev); void xen_be_del_xendev(struct XenDevice *xendev); struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
Re: [Xen-devel] vTPM issues
I guess you are using pv guests, I don't know exactly if Quan finished development for hvm. I suggest to take a look at tcsd log: pkill tcsd tcsd -f & tpm_takeownership -z -y -l debug Also can you see if /sys/devices/vtpm-0 and /dev/tpm0 are present? On Wed, Jun 24, 2015 at 6:16 PM, Marcos Simó Picó wrote: > Hello everyone, > > > I would like to try the vTPM feature, but I'm having some issues. > Basically, I followed the steps explained in > https://mhsamsal.wordpress.com/2013/12/05/configuring-virtual-tpm-vtpm-for-xen-4-3-guest-virtual-machines/ > > > I'm running Ubuntu 14.04 as Dom0 on a Dell optiplex-9020. I compiled Xen > 4.5.0 from source. After creating vtpmmgr and vtpm stubdoms, and DomU, I > can invoke tpm_version from DomU: > > > root@DomU:/home/xen# tpm_version > TPM 1.2 Version Info: > Chip Version:1.2.0.7 > Spec Level: 2 > Errata Revision: 1 > TPM Vendor ID: ETHZ > TPM Version: 0101 > Manufacturer Info: 4554485a > > > I can also see the PCRs status by invoking cat > /sys/class/misc/tpm0/device/pcrs, however, most of the commands return an > error. When I invoke takeownership I get the following error: > > > root@DomU:/home/xen# tpm_takeownership -y -z -l debug > Tspi_Context_Create success > Tspi_Context_Connect success > Tspi_Context_GetTpmObject success > Tspi_GetPolicyObject success > Tspi_Policy_SetSecret success > Tspi_Context_CreateObject success > Tspi_GetPolicyObject success > Tspi_Policy_SetSecret success > Tspi_TPM_TakeOwnership failed: 0x2004 - layer=tcs, code=0004 (4), > Internal software error > Tspi_Context_CloseObject success > Tspi_Context_FreeMemory success > Tspi_Context_Close success > > > The same error is given when invoking tpm_getpubkey. I have already > tried after clearing the TPM from BIOS, after having taken ownership and > with ownership no taken with the same result when using the vTPM. I have > also installed Xen 4.3.4, with the same result too. > > > In the end, I would like to use the vTPM to generate and use RSA keys > for TLS session establishing (using the API provided with GnuTLS). Since I > cannot take ownership of the vTPM, the GnuTLS' tpmtool complains it doesn't > find any SRK. > > > I really appreciate any help you can provide. > > > Best regards, > > Marcos > > ___ > Xen-devel mailing list > Xen-devel@lists.xen.org > http://lists.xen.org/xen-devel > > ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Re: [Xen-devel] vTPM issues
Sorry, I misspelled, I meant /dev/tpm0 not /etc/tpm0 I remember that once I had this problem when almost all trousers commands were returning internal software error in domU. Can you check what are the timeout values? cat /sys/devices/vtpm-0/timeouts I remember that there was a bug in ubuntu 14.04 regarding tpm driver. You could try 14.04.2. I am using Ubuntu 15.04 as domU guest and tpm comands run succesfully. On Thu, Jun 25, 2015 at 12:10 PM, Marcos Simó Picó wrote: > Yes, I'm indeed using pv guests. After running #tcsd -f & I get: > > TCSD TDDL ioctl: (25) Inappropriate ioctl for device > TCSD TDDL Falling back to Read/Write device support. > TCSD trousers 0.3.5git: TCSD up and running. > > > I don't know if the problem might be there. When I invoke > tpm_takeownership -z -y -l debug it returns exactly the same messages I > sent in my previous email. > > > On the other hand, /sys/devices/vtpm-0 is present, but /etc/tpm0 is not. > > > Thanks for your reply. > > > -- > *De:* Emil Condrea > *Enviado:* jueves, 25 de junio de 2015 10:21 > *Para:* Marcos Simó Picó > *Cc:* xen-devel@lists.xen.org; Xu, Quan > *Asunto:* Re: [Xen-devel] vTPM issues > > I guess you are using pv guests, I don't know exactly if Quan finished > development for hvm. > I suggest to take a look at tcsd log: > pkill tcsd > tcsd -f & > tpm_takeownership -z -y -l debug > Also can you see if /sys/devices/vtpm-0 and /dev/tpm0 are present? > > On Wed, Jun 24, 2015 at 6:16 PM, Marcos Simó Picó wrote: > >> Hello everyone, >> >> >> I would like to try the vTPM feature, but I'm having some issues. >> Basically, I followed the steps explained in >> https://mhsamsal.wordpress.com/2013/12/05/configuring-virtual-tpm-vtpm-for-xen-4-3-guest-virtual-machines/ >> >> >> I'm running Ubuntu 14.04 as Dom0 on a Dell optiplex-9020. I compiled >> Xen 4.5.0 from source. After creating vtpmmgr and vtpm stubdoms, and DomU, >> I can invoke tpm_version from DomU: >> >> >> root@DomU:/home/xen# tpm_version >> TPM 1.2 Version Info: >> Chip Version:1.2.0.7 >> Spec Level: 2 >> Errata Revision: 1 >> TPM Vendor ID: ETHZ >> TPM Version: 0101 >> Manufacturer Info: 4554485a >> >> >> I can also see the PCRs status by invoking cat >> /sys/class/misc/tpm0/device/pcrs, however, most of the commands return an >> error. When I invoke takeownership I get the following error: >> >> >> root@DomU:/home/xen# tpm_takeownership -y -z -l debug >> Tspi_Context_Create success >> Tspi_Context_Connect success >> Tspi_Context_GetTpmObject success >> Tspi_GetPolicyObject success >> Tspi_Policy_SetSecret success >> Tspi_Context_CreateObject success >> Tspi_GetPolicyObject success >> Tspi_Policy_SetSecret success >> Tspi_TPM_TakeOwnership failed: 0x2004 - layer=tcs, code=0004 (4), >> Internal software error >> Tspi_Context_CloseObject success >> Tspi_Context_FreeMemory success >> Tspi_Context_Close success >> >> >> The same error is given when invoking tpm_getpubkey. I have already >> tried after clearing the TPM from BIOS, after having taken ownership and >> with ownership no taken with the same result when using the vTPM. I have >> also installed Xen 4.3.4, with the same result too. >> >> >> In the end, I would like to use the vTPM to generate and use RSA keys >> for TLS session establishing (using the API provided with GnuTLS). Since I >> cannot take ownership of the vTPM, the GnuTLS' tpmtool complains it doesn't >> find any SRK. >> >> >> I really appreciate any help you can provide. >> >> >> Best regards, >> >> Marcos >> >> ___ >> Xen-devel mailing list >> Xen-devel@lists.xen.org >> http://lists.xen.org/xen-devel >> >> > ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Re: [Xen-devel] vTPM issues
Timeouts have the standard values. Good luck with installing 15.04. On Thu, Jun 25, 2015 at 12:34 PM, Marcos Simó Picó wrote: > Okay, /etc/tpm0 is present. > > The timeout values are: > > 752000 200 752000 752000 [adjusted] > > > I have no problem actually upgrading to Ubuntu 15.04 if that might solve > the problem. > > > Thanks a lot for your reply again. > ------ > *De:* Emil Condrea > *Enviado:* jueves, 25 de junio de 2015 11:22 > *Para:* Marcos Simó Picó > *Cc:* xen-devel@lists.xen.org > *Asunto:* Re: [Xen-devel] vTPM issues > > Sorry, I misspelled, I meant /dev/tpm0 not /etc/tpm0 > I remember that once I had this problem when almost all trousers commands > were returning internal software error in domU. > Can you check what are the timeout values? > cat /sys/devices/vtpm-0/timeouts > > I remember that there was a bug in ubuntu 14.04 regarding tpm driver. > You could try 14.04.2. I am using Ubuntu 15.04 as domU guest and tpm > comands > run succesfully. > > On Thu, Jun 25, 2015 at 12:10 PM, Marcos Simó Picó > wrote: > >> Yes, I'm indeed using pv guests. After running #tcsd -f & I get: >> >> TCSD TDDL ioctl: (25) Inappropriate ioctl for device >> TCSD TDDL Falling back to Read/Write device support. >> TCSD trousers 0.3.5git: TCSD up and running. >> >> >> I don't know if the problem might be there. When I invoke >> tpm_takeownership -z -y -l debug it returns exactly the same messages I >> sent in my previous email. >> >> >> On the other hand, /sys/devices/vtpm-0 is present, but /etc/tpm0 is not. >> >> >> Thanks for your reply. >> >> >> -- >> *De:* Emil Condrea >> *Enviado:* jueves, 25 de junio de 2015 10:21 >> *Para:* Marcos Simó Picó >> *Cc:* xen-devel@lists.xen.org; Xu, Quan >> *Asunto:* Re: [Xen-devel] vTPM issues >> >> I guess you are using pv guests, I don't know exactly if Quan finished >> development for hvm. >> I suggest to take a look at tcsd log: >> pkill tcsd >> tcsd -f & >> tpm_takeownership -z -y -l debug >> Also can you see if /sys/devices/vtpm-0 and /dev/tpm0 are present? >> >> On Wed, Jun 24, 2015 at 6:16 PM, Marcos Simó Picó >> wrote: >> >>> Hello everyone, >>> >>> >>> I would like to try the vTPM feature, but I'm having some issues. >>> Basically, I followed the steps explained in >>> https://mhsamsal.wordpress.com/2013/12/05/configuring-virtual-tpm-vtpm-for-xen-4-3-guest-virtual-machines/ >>> >>> >>> I'm running Ubuntu 14.04 as Dom0 on a Dell optiplex-9020. I compiled >>> Xen 4.5.0 from source. After creating vtpmmgr and vtpm stubdoms, and DomU, >>> I can invoke tpm_version from DomU: >>> >>> >>> root@DomU:/home/xen# tpm_version >>> TPM 1.2 Version Info: >>> Chip Version:1.2.0.7 >>> Spec Level: 2 >>> Errata Revision: 1 >>> TPM Vendor ID: ETHZ >>> TPM Version: 0101 >>> Manufacturer Info: 4554485a >>> >>> >>> I can also see the PCRs status by invoking cat >>> /sys/class/misc/tpm0/device/pcrs, however, most of the commands return an >>> error. When I invoke takeownership I get the following error: >>> >>> >>> root@DomU:/home/xen# tpm_takeownership -y -z -l debug >>> Tspi_Context_Create success >>> Tspi_Context_Connect success >>> Tspi_Context_GetTpmObject success >>> Tspi_GetPolicyObject success >>> Tspi_Policy_SetSecret success >>> Tspi_Context_CreateObject success >>> Tspi_GetPolicyObject success >>> Tspi_Policy_SetSecret success >>> Tspi_TPM_TakeOwnership failed: 0x2004 - layer=tcs, code=0004 (4), >>> Internal software error >>> Tspi_Context_CloseObject success >>> Tspi_Context_FreeMemory success >>> Tspi_Context_Close success >>> >>> >>> The same error is given when invoking tpm_getpubkey. I have already >>> tried after clearing the TPM from BIOS, after having taken ownership and >>> with ownership no taken with the same result when using the vTPM. I have >>> also installed Xen 4.3.4, with the same result too. >>> >>> >>> In the end, I would like to use the vTPM to generate and use RSA keys >>> for TLS session establishing (using the API provided with GnuTLS). Since I >>> cannot take ownership of the vTPM, the GnuTLS' tpmtool complains it doesn't >>> find any SRK. >>> >>> >>> I really appreciate any help you can provide. >>> >>> >>> Best regards, >>> >>> Marcos >>> >>> ___ >>> Xen-devel mailing list >>> Xen-devel@lists.xen.org >>> http://lists.xen.org/xen-devel >>> >>> >> > ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
[Xen-devel] [PATCH 19/19] Qemu-Xen-vTPM: QEMU machine class is initialized before tpm_init()
make sure QEMU machine class is initialized and QEMU has registered Xen stubdom vTPM driver when call tpm_init() Signed-off-by: Quan Xu Signed-off-by: Emil Condrea Reviewed-by: Stefan Berger --- vl.c | 17 +++-- 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/vl.c b/vl.c index 5cd0f2a..a22b0c9 100644 --- a/vl.c +++ b/vl.c @@ -4353,12 +4353,6 @@ int main(int argc, char **argv, char **envp) exit(1); } -#ifdef CONFIG_TPM -if (tpm_init() < 0) { -exit(1); -} -#endif - /* init the bluetooth world */ if (foreach_device_config(DEV_BT, bt_parse)) exit(1); @@ -4477,6 +4471,17 @@ int main(int argc, char **argv, char **envp) exit(1); } +/* + * For compatible with Xen stubdom vTPM driver, make + * sure QEMU machine class is initialized and QEMU has + * registered Xen stubdom vTPM driver. + */ +#ifdef CONFIG_TPM +if (tpm_init() < 0) { +exit(1); +} +#endif + /* Check if IGD GFX passthrough. */ igd_gfx_passthru(); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 15/19] Qemu-Xen-vTPM: Xen frontend driver infrastructure
This patch adds infrastructure for xen front drivers living in qemu, so drivers don't need to implement common stuff on their own. It's mostly xenbus management stuff: some functions to access XenStore, setting up XenStore watches, callbacks on device discovery and state changes, and handle event channel between the virtual machines. Call xen_fe_register() function to register XenDevOps, and make sure, XenDevOps's flags is DEVOPS_FLAG_FE, which is flag bit to point out the XenDevOps is Xen frontend. Signed-off-by: Quan Xu Signed-off-by: Emil Condrea --- Changes in v9: * xenstore_dev should not be global, it will not work correctly with multiple xen frontends living in qemu * reuse some common functions: - xen_fe_printf -> xen_pv_printf - xen_fe_evtchn_event -> xen_pv_evtchn_event * use libxenevtchn stable API instead of xc_* calls: - xc_evtchn_fd -> xenevtchn_fd - xc_evtchn_close -> xenevtchn_close - xc_evtchn_bind_unbound_port -> xenevtchn_bind_unbound_port --- hw/xen/xen_frontend.c | 308 ++ hw/xen/xen_pvdev.c| 15 ++ include/hw/xen/xen_frontend.h | 6 + include/hw/xen/xen_pvdev.h| 1 + 4 files changed, 330 insertions(+) diff --git a/hw/xen/xen_frontend.c b/hw/xen/xen_frontend.c index 6b92cf1..7b305ce 100644 --- a/hw/xen/xen_frontend.c +++ b/hw/xen/xen_frontend.c @@ -3,6 +3,10 @@ * * (c) 2008 Gerd Hoffmann * + * Copyright (c) 2015 Intel Corporation + * Authors: + *Quan Xu + * * 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 @@ -23,6 +27,8 @@ #include "hw/xen/xen_frontend.h" #include "hw/xen/xen_backend.h" +static int debug = 0; + char *xenstore_read_fe_str(struct XenDevice *xendev, const char *node) { return xenstore_read_str(xendev->fe, node); @@ -86,3 +92,305 @@ void xenstore_update_fe(char *watch, struct XenDevice *xendev) xen_fe_frontend_changed(xendev, node); xen_be_check_state(xendev); } + +struct XenDevice *xen_fe_get_xendev(const char *type, int dom, int dev, +char *backend, struct XenDevOps *ops) +{ +struct XenDevice *xendev; + +xendev = xen_pv_find_xendev(type, dom, dev); +if (xendev) { +return xendev; +} + +/* init new xendev */ +xendev = g_malloc0(ops->size); +xendev->type = type; +xendev->dom = dom; +xendev->dev = dev; +xendev->ops = ops; + +/*return if the ops->flags is not DEVOPS_FLAG_FE*/ +if (!(ops->flags & DEVOPS_FLAG_FE)) { +return NULL; +} + +snprintf(xendev->be, sizeof(xendev->be), "%s", backend); +snprintf(xendev->name, sizeof(xendev->name), "%s-%d", + xendev->type, xendev->dev); + +xendev->debug = debug; +xendev->local_port = -1; + +xendev->evtchndev = xenevtchn_open(NULL, 0); +if (xendev->evtchndev == NULL) { +xen_pv_printf(NULL, 0, "can't open evtchn device\n"); +g_free(xendev); +return NULL; +} +fcntl(xenevtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC); + +if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) { +xendev->gnttabdev = xengnttab_open(NULL, 0); +if (xendev->gnttabdev == NULL) { +xen_pv_printf(NULL, 0, "can't open gnttab device\n"); +xenevtchn_close(xendev->evtchndev); +g_free(xendev); +return NULL; +} +} else { +xendev->gnttabdev = NULL; +} + +xen_pv_insert_xendev(xendev); + +if (xendev->ops->alloc) { +xendev->ops->alloc(xendev); +} + +return xendev; +} + +int xen_fe_alloc_unbound(struct XenDevice *xendev, int dom, int remote_dom){ +xendev->local_port = xenevtchn_bind_unbound_port(xendev->evtchndev, + remote_dom); +if (xendev->local_port == -1) { +xen_pv_printf(xendev, 0, "xenevtchn_bind_unbound_port failed\n"); +return -1; +} +xen_pv_printf(xendev, 2, "bind evtchn port %d\n", xendev->local_port); +qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), +xen_pv_evtchn_event, NULL, xendev); +return 0; +} + +/* + * Make sure, initialize the 'xendev->fe' in xendev->ops->init() or + * xendev->ops->initialize() + */ +int xenbus_switch_state(struct XenDevice *xendev, enum xenbus_state xbus) +{ +xs_transaction_t xbt = XBT_NULL; + +if (xendev->fe_state == xbus) { +return 0; +} + +xendev->fe_state = xbus; +if (xendev->fe == NULL) { +xen_pv_printf(NULL, 0, "xendev->fe is NULL\n"); +return
[Xen-devel] [PATCH 07/19] xen: Rename xen_be_unbind_evtchn
Prepare xen_be_unbind_evtchn to be shared with frontends: * xen_be_unbind_evtchn -> xen_pv_unbind_evtchn Signed-off-by: Emil Condrea --- hw/block/xen_disk.c| 2 +- hw/char/xen_console.c | 2 +- hw/display/xenfb.c | 2 +- hw/net/xen_nic.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index ad3f519..0716ca2 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -1048,7 +1048,7 @@ static void blk_disconnect(struct XenDevice *xendev) blk_unref(blkdev->blk); blkdev->blk = NULL; } -xen_be_unbind_evtchn(&blkdev->xendev); +xen_pv_unbind_evtchn(&blkdev->xendev); if (blkdev->sring) { xengnttab_unmap(blkdev->xendev.gnttabdev, blkdev->sring, 1); diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index e6bae67..889f7b2 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -263,7 +263,7 @@ static void con_disconnect(struct XenDevice *xendev) qemu_chr_add_handlers(con->chr, NULL, NULL, NULL, NULL); qemu_chr_fe_release(con->chr); } -xen_be_unbind_evtchn(&con->xendev); +xen_pv_unbind_evtchn(&con->xendev); if (con->sring) { if (!xendev->dev) { diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index b1e8b3b..250dbc2 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -112,7 +112,7 @@ static int common_bind(struct common *c) static void common_unbind(struct common *c) { -xen_be_unbind_evtchn(&c->xendev); +xen_pv_unbind_evtchn(&c->xendev); if (c->page) { xenforeignmemory_unmap(xen_fmem, c->page, 1); c->page = NULL; diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 91126b5..1fc6a22 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -367,7 +367,7 @@ static void net_disconnect(struct XenDevice *xendev) { struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev); -xen_be_unbind_evtchn(&netdev->xendev); +xen_pv_unbind_evtchn(&netdev->xendev); if (netdev->txs) { xengnttab_unmap(netdev->xendev.gnttabdev, netdev->txs, 1); diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 7375b43..6bf1ae4 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -193,7 +193,7 @@ void xen_be_evtchn_event(void *opaque) } } -void xen_be_unbind_evtchn(struct XenDevice *xendev) +void xen_pv_unbind_evtchn(struct XenDevice *xendev) { if (xendev->local_port == -1) { return; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index 3e2dfd8..5c27184 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -71,7 +71,7 @@ void xen_pv_insert_xendev(struct XenDevice *xendev); struct XenDevice *xen_be_del_xendev(int dom, int dev); struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); -void xen_be_unbind_evtchn(struct XenDevice *xendev); +void xen_pv_unbind_evtchn(struct XenDevice *xendev); int xen_be_send_notify(struct XenDevice *xendev); void xen_pv_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...) -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 04/19] xen: Move evtchn functions to xen_pvdev.c
The name of the functions moved: * xen_be_evtchn_event * xen_be_unbind_evtchn * xen_be_send_notify Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 37 + hw/xen/xen_pvdev.c | 35 +++ include/hw/xen/xen_backend.h | 2 -- include/hw/xen/xen_pvdev.h | 4 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 0a9f9bb..5f2821a 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -561,25 +561,6 @@ void xenstore_update_be(char *watch, char *type, int dom, } } -static void xen_be_evtchn_event(void *opaque) -{ -struct XenDevice *xendev = opaque; -evtchn_port_t port; - -port = xenevtchn_pending(xendev->evtchndev); -if (port != xendev->local_port) { -xen_be_printf(xendev, 0, - "xenevtchn_pending returned %d (expected %d)\n", - port, xendev->local_port); -return; -} -xenevtchn_unmask(xendev->evtchndev, port); - -if (xendev->ops->event) { -xendev->ops->event(xendev); -} -} - /* */ int xen_be_init(void) @@ -646,22 +627,6 @@ int xen_be_bind_evtchn(struct XenDevice *xendev) return 0; } -void xen_be_unbind_evtchn(struct XenDevice *xendev) -{ -if (xendev->local_port == -1) { -return; -} -qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), NULL, NULL, NULL); -xenevtchn_unbind(xendev->evtchndev, xendev->local_port); -xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port); -xendev->local_port = -1; -} - -int xen_be_send_notify(struct XenDevice *xendev) -{ -return xenevtchn_notify(xendev->evtchndev, xendev->local_port); -} - static int xen_sysdev_init(SysBusDevice *dev) { @@ -693,4 +658,4 @@ static void xenbe_register_types(void) type_register_static(&xensysdev_info); } -type_init(xenbe_register_types); +type_init(xenbe_register_types); \ No newline at end of file diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 001fda2..7876724 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -171,3 +171,38 @@ void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ... } qemu_log_flush(); } + +void xen_be_evtchn_event(void *opaque) +{ +struct XenDevice *xendev = opaque; +evtchn_port_t port; + +port = xenevtchn_pending(xendev->evtchndev); +if (port != xendev->local_port) { +xen_be_printf(xendev, 0, + "xenevtchn_pending returned %d (expected %d)\n", + port, xendev->local_port); +return; +} +xenevtchn_unmask(xendev->evtchndev, port); + +if (xendev->ops->event) { +xendev->ops->event(xendev); +} +} + +void xen_be_unbind_evtchn(struct XenDevice *xendev) +{ +if (xendev->local_port == -1) { +return; +} +qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), NULL, NULL, NULL); +xenevtchn_unbind(xendev->evtchndev, xendev->local_port); +xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port); +xendev->local_port = -1; +} + +int xen_be_send_notify(struct XenDevice *xendev) +{ +return xenevtchn_notify(xendev->evtchndev, xendev->local_port); +} diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 4832f79..60b634e 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -29,8 +29,6 @@ int xen_be_init(void); int xen_be_register(const char *type, struct XenDevOps *ops); 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); /* 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 index cc49636..f269b04 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -66,6 +66,10 @@ void xenstore_update(void *unused); const char *xenbus_strstate(enum xenbus_state state); +void xen_be_evtchn_event(void *opaque); +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); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 09/19] xen: Rename xen_be_evtchn_event
Prepare xen_be_evtchn_event to be shared with frontends: * xen_be_evtchn_event -> xen_pv_evtchn_event Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 46e1944..d6c04c7 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -555,7 +555,7 @@ int xen_be_bind_evtchn(struct XenDevice *xendev) } xen_pv_printf(xendev, 2, "bind evtchn port %d\n", xendev->local_port); qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), -xen_be_evtchn_event, NULL, xendev); +xen_pv_evtchn_event, NULL, xendev); return 0; } diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 3d8b2c2..5482ab0 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -174,7 +174,7 @@ void xen_pv_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ... qemu_log_flush(); } -void xen_be_evtchn_event(void *opaque) +void xen_pv_evtchn_event(void *opaque) { struct XenDevice *xendev = opaque; evtchn_port_t port; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index 80e242f..a06afb6 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -66,7 +66,7 @@ void xenstore_update(void *unused); const char *xenbus_strstate(enum xenbus_state state); -void xen_be_evtchn_event(void *opaque); +void xen_pv_evtchn_event(void *opaque); void xen_pv_insert_xendev(struct XenDevice *xendev); struct XenDevice *xen_be_del_xendev(int dom, int dev); struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 18/19] Qemu-Xen-vTPM: Qemu vTPM xenstubdoms backend
This Patch provides the glue for the TPM_TIS(Qemu frontend) to Xen stubdom vTPM domain that provides the actual TPM functionality. It sends data and TPM commends with xen_vtpm_frontend. It is similar as another two vTPM backends: *vTPM passthrough backend Since QEMU 1.5. *vTPM libtpms-based backend. Some details: This part of the patch provides support for the spawning of a thread that will interact with stubdom vTPM domain by the xen_vtpm_frontend. It expects a signal from the frontend to wake and pick up the TPM command that is supposed to be processed and delivers the response packet using a callback function provided by the frontend. The backend connects itself to the frontend by filling out an interface structure with pointers to the function implementing support for various operations. (QEMU) vTPM XenStubdoms backend is initialized by Qemu command line options, "-tpmdev xenstubdoms,id=xenvtpm0 -device tpm-tis,tpmdev=xenvtpm0" Signed-off-by: Quan Xu Signed-off-by: Emil Condrea Reviewed-by: Stefan Berger --- Changes in v9: * added reset_tpm_established_flag and get_tpm_version for TPMDriverOps * readded tpm_backend_thread_tpm_reset which was removed because it was not used * tpm_xenstubdoms_unix_transfer use xenstore_vtpm_dev instead of xenstore_dev --- backends/tpm.c | 11 ++ hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_xenstubdoms.c | 284 +++ include/sysemu/tpm_backend_int.h | 2 + 4 files changed, 298 insertions(+), 1 deletion(-) create mode 100644 hw/tpm/tpm_xenstubdoms.c diff --git a/backends/tpm.c b/backends/tpm.c index 536f262..9e0dfaa 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -181,6 +181,17 @@ void tpm_backend_thread_end(TPMBackendThread *tbt) } } +void tpm_backend_thread_tpm_reset(TPMBackendThread *tbt, + GFunc func, gpointer user_data) +{ +if (!tbt->pool) { +tpm_backend_thread_create(tbt, func, user_data); +} else { +g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_TPM_RESET, + NULL); +} +} + static const TypeInfo tpm_backend_info = { .name = TYPE_TPM_BACKEND, .parent = TYPE_OBJECT, diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs index 16b1447..5e1e282 100644 --- a/hw/tpm/Makefile.objs +++ b/hw/tpm/Makefile.objs @@ -1,3 +1,3 @@ common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o tpm_util.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o tpm_util.o -common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.o +common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.o tpm_xenstubdoms.o diff --git a/hw/tpm/tpm_xenstubdoms.c b/hw/tpm/tpm_xenstubdoms.c new file mode 100644 index 000..55223bf --- /dev/null +++ b/hw/tpm/tpm_xenstubdoms.c @@ -0,0 +1,284 @@ +/* + * Xen Stubdom vTPM driver + * + * Copyright (c) 2015 Intel Corporation + * Authors: + *Quan Xu + * + * 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 "sysemu/tpm_backend.h" +#include "tpm_int.h" +#include "tpm_util.h" +#include "hw/xen/xen_pvdev.h" +#include "sysemu/tpm_backend_int.h" +#include "hw/tpm/xen_vtpm_frontend.h" + +#define DEBUG_TPM 0 +#define DPRINTF(fmt, ...) do { \ +if (DEBUG_TPM) { \ +fprintf(stderr, fmt, ## __VA_ARGS__); \ +} \ +} while (0) + +#define TYPE_TPM_XENSTUBDOMS "tpm-xenstubdoms" +#define TPM_XENSTUBDOMS(obj) \ +OBJECT_CHECK(TPMXenstubdomsState, (obj), TYPE_TPM_XENSTUBDOMS) + +static const TPMDriverOps tpm_xenstubdoms_driver; + +/* Data structures */ +typedef struct TPMXenstubdomsThreadParams { +TPMState *tpm_state; +TPMRecvDataCB *recv_data_callback; +TPMBackend *tb; +} TPMXenstubdomsThreadParams; + +struct TPMXenstubdomsState { +TPMBackend parent; +TPMBackendThread tbt; +TPMXenstubdomsThreadParams tpm_thread_params; +bool had_startup_error; +}; + +typedef struct TPMXenstubdomsState TPMXenstubdomsState; + +/* Functions */ +static void tpm_xenstubdoms_cancel_cmd(TPMBackend *tb); + +static int tpm_xenstubdoms_unix_transfer(const TPMLocality *locty_data, + bool *selftest_done) +{ +size_t rlen; +struct XenDevice
[Xen-devel] [PATCH 13/19] xen: Distinguish between frontend and backend devops
xen_be_check_state should not be called for frontends Use DEVOPS_FLAG_FE flag to distinguish a frontend. Signed-off-by: Emil Condrea Signed-off-by: Quan Xu --- Changes in v9: * Removed not needed strstr from xenstore_update_be It was left over from first patch series when domu was included in xenstore schema: "%s/backend/%s/%d/%d" --- hw/xen/xen_backend.c | 4 +++- include/hw/xen/xen_pvdev.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index d0e3f50..3931128 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -488,7 +488,9 @@ void xenstore_update_be(char *watch, char *type, int dom, } else { free(bepath); xen_be_backend_changed(xendev, path); -xen_be_check_state(xendev); +if (!(ops->flags & DEVOPS_FLAG_FE)) { +xen_be_check_state(xendev); +} } } } diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index c19e1df..c985a9d 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -14,6 +14,8 @@ struct XenDevice; #define DEVOPS_FLAG_NEED_GNTDEV 1 /* don't expect frontend doing correct state transitions (aka console quirk) */ #define DEVOPS_FLAG_IGNORE_STATE 2 +/*dev is frontend device*/ +#define DEVOPS_FLAG_FE4 struct XenDevOps { size_tsize; -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 02/19] xen: Create a new file xen_frontend.c
Its purpose is to store frontend related functions. Signed-off-by: Quan Xu Signed-off-by: Emil Condrea --- hw/block/xen_disk.c | 1 + hw/display/xenfb.c| 1 + hw/net/xen_nic.c | 1 + hw/xen/Makefile.objs | 2 +- hw/xen/xen_backend.c | 47 + hw/xen/xen_frontend.c | 70 +++ include/hw/xen/xen_backend.h | 3 -- include/hw/xen/xen_frontend.h | 10 +++ 8 files changed, 85 insertions(+), 50 deletions(-) create mode 100644 hw/xen/xen_frontend.c create mode 100644 include/hw/xen/xen_frontend.h diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 90aca73..28fbf24 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -25,6 +25,7 @@ #include "hw/hw.h" #include "hw/xen/xen_backend.h" +#include "hw/xen/xen_frontend.h" #include "xen_blkif.h" #include "sysemu/blockdev.h" #include "sysemu/block-backend.h" diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 46b7d5e..5751113 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -30,6 +30,7 @@ #include "ui/console.h" #include "sysemu/char.h" #include "hw/xen/xen_backend.h" +#include "hw/xen/xen_frontend.h" #include #include diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 0b4ddae..bdfa789 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -29,6 +29,7 @@ #include "net/checksum.h" #include "net/util.h" #include "hw/xen/xen_backend.h" +#include "hw/xen/xen_frontend.h" #include diff --git a/hw/xen/Makefile.objs b/hw/xen/Makefile.objs index 591cdc2..1000294 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 xen_pvdev.o +common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_frontend.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 a251a4a..7a83a7d 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_frontend.h" #include "hw/xen/xen_pvdev.h" #include @@ -124,21 +125,6 @@ int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int *ival) return xenstore_read_int(xendev->be, node, ival); } -char *xenstore_read_fe_str(struct XenDevice *xendev, const char *node) -{ -return xenstore_read_str(xendev->fe, node); -} - -int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival) -{ -return xenstore_read_int(xendev->fe, node, ival); -} - -int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, uint64_t *uval) -{ -return xenstore_read_uint64(xendev->fe, node, uval); -} - /* - */ int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state) @@ -301,37 +287,6 @@ static void xen_be_backend_changed(struct XenDevice *xendev, const char *node) } } -static void xen_be_frontend_changed(struct XenDevice *xendev, const char *node) -{ -int fe_state; - -if (node == NULL || strcmp(node, "state") == 0) { -if (xenstore_read_fe_int(xendev, "state", &fe_state) == -1) { -fe_state = XenbusStateUnknown; -} -if (xendev->fe_state != fe_state) { -xen_be_printf(xendev, 1, "frontend state: %s -> %s\n", - xenbus_strstate(xendev->fe_state), - xenbus_strstate(fe_state)); -} -xendev->fe_state = fe_state; -} -if (node == NULL || strcmp(node, "protocol") == 0) { -g_free(xendev->protocol); -xendev->protocol = xenstore_read_fe_str(xendev, "protocol"); -if (xendev->protocol) { -xen_be_printf(xendev, 1, "frontend protocol: %s\n", xendev->protocol); -} -} - -if (node) { -xen_be_printf(xendev, 2, "frontend update: %s\n", node); -if (xendev->ops->frontend_changed) { -xendev->ops->frontend_changed(xendev, node); -} -} -} - /* - */ /* Check for possible state transitions and perform them.*/ diff --git a/hw/xen/xen_frontend.c b/hw/xen/xen_frontend.c new file mode 100644 index 000..b4bf8da --- /dev/null +++ b/hw/xen/xen_frontend.c @@ -0,0 +1,70 @@ +/* + * Xen frontend driver infrastructure + * + * (c) 2008 Gerd Hof
[Xen-devel] [PATCH 08/19] xen: Rename xen_be_send_notify
Prepare xen_be_send_notify to be shared with frontends: * xen_be_send_notify -> xen_pv_send_notify Signed-off-by: Emil Condrea --- hw/block/xen_disk.c| 4 ++-- hw/char/xen_console.c | 4 ++-- hw/display/xenfb.c | 8 hw/net/xen_nic.c | 4 ++-- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 0716ca2..c36b08b 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -659,7 +659,7 @@ static void blk_send_response_all(struct XenBlkDev *blkdev) ioreq_release(ioreq, true); } if (send_notify) { -xen_be_send_notify(&blkdev->xendev); +xen_pv_send_notify(&blkdev->xendev); } } @@ -729,7 +729,7 @@ static void blk_handle_requests(struct XenBlkDev *blkdev) }; if (blk_send_response_one(ioreq)) { -xen_be_send_notify(&blkdev->xendev); +xen_pv_send_notify(&blkdev->xendev); } ioreq_release(ioreq, false); continue; diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 889f7b2..94e6ab0 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -72,7 +72,7 @@ static void buffer_append(struct XenConsole *con) xen_mb(); intf->out_cons = cons; -xen_be_send_notify(&con->xendev); +xen_pv_send_notify(&con->xendev); if (buffer->max_capacity && buffer->size > buffer->max_capacity) { @@ -140,7 +140,7 @@ static void xencons_receive(void *opaque, const uint8_t *buf, int len) } xen_wmb(); intf->in_prod = prod; -xen_be_send_notify(&con->xendev); +xen_pv_send_notify(&con->xendev); } static void xencons_send(struct XenConsole *con) diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 250dbc2..01ae00f 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -215,7 +215,7 @@ static int xenfb_kbd_event(struct XenInput *xenfb, XENKBD_IN_RING_REF(page, prod) = *event; xen_wmb(); /* ensure ring contents visible */ page->in_prod = prod + 1; -return xen_be_send_notify(&xenfb->c.xendev); +return xen_pv_send_notify(&xenfb->c.xendev); } /* Send a keyboard (or mouse button) event */ @@ -397,7 +397,7 @@ static void input_event(struct XenDevice *xendev) if (page->out_prod == page->out_cons) return; page->out_cons = page->out_prod; -xen_be_send_notify(&xenfb->c.xendev); +xen_pv_send_notify(&xenfb->c.xendev); } /* */ @@ -664,7 +664,7 @@ static void xenfb_send_event(struct XenFB *xenfb, union xenfb_in_event *event) xen_wmb(); /* ensure ring contents visible */ page->in_prod = prod + 1; -xen_be_send_notify(&xenfb->c.xendev); +xen_pv_send_notify(&xenfb->c.xendev); } static void xenfb_send_refresh_period(struct XenFB *xenfb, int period) @@ -935,7 +935,7 @@ static void fb_event(struct XenDevice *xendev) struct XenFB *xenfb = container_of(xendev, struct XenFB, c.xendev); xenfb_handle_events(xenfb); -xen_be_send_notify(&xenfb->c.xendev); +xen_pv_send_notify(&xenfb->c.xendev); } /* */ diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 1fc6a22..f46c745 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -70,7 +70,7 @@ static void net_tx_response(struct XenNetDev *netdev, netif_tx_request_t *txp, i netdev->tx_ring.rsp_prod_pvt = ++i; RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netdev->tx_ring, notify); if (notify) { -xen_be_send_notify(&netdev->xendev); +xen_pv_send_notify(&netdev->xendev); } if (i == netdev->tx_ring.req_cons) { @@ -218,7 +218,7 @@ static void net_rx_response(struct XenNetDev *netdev, netdev->rx_ring.rsp_prod_pvt = ++i; RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netdev->rx_ring, notify); if (notify) { -xen_be_send_notify(&netdev->xendev); +xen_pv_send_notify(&netdev->xendev); } } diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 6bf1ae4..3d8b2c2 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -204,7 +204,7 @@ void xen_pv_unbind_evtchn(struct XenDevice *xendev) xendev->local_port = -1; } -int xen_be_send_notify(struct XenDevice *xendev) +int xen_pv_send_notify(struct XenDevice *xendev) { return xenevtchn_notify(xendev->evtchndev, xendev->local_port); } diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index 5c27184..80e242f 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -72,7 +72,7 @@ struct XenDevic
[Xen-devel] [PATCH 12/19] xen: Rename xen_be_frontend_changed
xen_be_frontend_changed -> xen_fe_frontend_changed Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 2 +- hw/xen/xen_frontend.c | 4 ++-- include/hw/xen/xen_frontend.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 9efe4b9..d0e3f50 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -262,7 +262,7 @@ static int xen_be_try_setup(struct XenDevice *xendev) xen_be_set_state(xendev, XenbusStateInitialising); xen_be_backend_changed(xendev, NULL); -xen_be_frontend_changed(xendev, NULL); +xen_fe_frontend_changed(xendev, NULL); return 0; } diff --git a/hw/xen/xen_frontend.c b/hw/xen/xen_frontend.c index 474c74a..6b92cf1 100644 --- a/hw/xen/xen_frontend.c +++ b/hw/xen/xen_frontend.c @@ -38,7 +38,7 @@ int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, uint64_t return xenstore_read_uint64(xendev->fe, node, uval); } -void xen_be_frontend_changed(struct XenDevice *xendev, const char *node) +void xen_fe_frontend_changed(struct XenDevice *xendev, const char *node) { int fe_state; @@ -83,6 +83,6 @@ void xenstore_update_fe(char *watch, struct XenDevice *xendev) } node = watch + len + 1; -xen_be_frontend_changed(xendev, node); +xen_fe_frontend_changed(xendev, node); xen_be_check_state(xendev); } diff --git a/include/hw/xen/xen_frontend.h b/include/hw/xen/xen_frontend.h index ae587e1..5d03f4e 100644 --- a/include/hw/xen/xen_frontend.h +++ b/include/hw/xen/xen_frontend.h @@ -8,6 +8,6 @@ int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival); int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, uint64_t *uval); void xenstore_update_fe(char *watch, struct XenDevice *xendev); -void xen_be_frontend_changed(struct XenDevice *xendev, const char *node); +void xen_fe_frontend_changed(struct XenDevice *xendev, const char *node); #endif /* QEMU_HW_XEN_FRONTEND_H */ -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 10/19] xen: Rename xen_be_find_xendev
Prepare xen_be_find_xendev to be shared with frontends: * xen_be_find_xendev -> xen_pv_find_xendev Signed-off-by: Emil Condrea --- hw/display/xenfb.c | 4 ++-- hw/xen/xen_backend.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index 01ae00f..df13912 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -978,8 +978,8 @@ void xen_init_display(int domid) wait_more: i++; main_loop_wait(true); -xfb = xen_be_find_xendev("vfb", domid, 0); -xin = xen_be_find_xendev("vkbd", domid, 0); +xfb = xen_pv_find_xendev("vfb", domid, 0); +xin = xen_pv_find_xendev("vkbd", domid, 0); if (!xfb || !xin) { if (i < 256) { usleep(1); diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index d6c04c7..51afb1c 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -148,7 +148,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, { struct XenDevice *xendev; -xendev = xen_be_find_xendev(type, dom, dev); +xendev = xen_pv_find_xendev(type, dom, dev); if (xendev) { return xendev; } diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 5482ab0..24266fa 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -211,7 +211,7 @@ int xen_pv_send_notify(struct XenDevice *xendev) /* - */ -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) +struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev) { struct XenDevice *xendev; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index a06afb6..f26d82a 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -69,7 +69,7 @@ const char *xenbus_strstate(enum xenbus_state state); void xen_pv_evtchn_event(void *opaque); void xen_pv_insert_xendev(struct XenDevice *xendev); struct XenDevice *xen_be_del_xendev(int dom, int dev); -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); +struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev); void xen_pv_unbind_evtchn(struct XenDevice *xendev); int xen_pv_send_notify(struct XenDevice *xendev); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 11/19] xen: Rename xen_be_del_xendev
Prepare xen_be_del_xendev to be shared with frontends: * xen_be_del_xendev -> xen_pv_del_xendev Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 2 +- hw/xen/xen_pvdev.c | 2 +- include/hw/xen/xen_pvdev.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 51afb1c..9efe4b9 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -484,7 +484,7 @@ void xenstore_update_be(char *watch, char *type, int dom, if (xendev != NULL) { bepath = xs_read(xenstore, 0, xendev->be, &len); if (bepath == NULL) { -xen_be_del_xendev(dom, dev); +xen_pv_del_xendev(dom, dev); } else { free(bepath); xen_be_backend_changed(xendev, path); diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 24266fa..394ddc1 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -233,7 +233,7 @@ struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev) /* * release xen backend device. */ -struct XenDevice *xen_be_del_xendev(int dom, int dev) +struct XenDevice *xen_pv_del_xendev(int dom, int dev) { struct XenDevice *xendev, *xnext; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index f26d82a..c19e1df 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -68,7 +68,7 @@ const char *xenbus_strstate(enum xenbus_state state); void xen_pv_evtchn_event(void *opaque); void xen_pv_insert_xendev(struct XenDevice *xendev); -struct XenDevice *xen_be_del_xendev(int dom, int dev); +struct XenDevice *xen_pv_del_xendev(int dom, int dev); struct XenDevice *xen_pv_find_xendev(const char *type, int dom, int dev); void xen_pv_unbind_evtchn(struct XenDevice *xendev); -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 05/19] xen: Prepare xendev qtail to be shared with frontends
* move xendevs qtail to xen_pvdev.c * change xen_be_get_xendev to use a new function: xen_pv_insert_xendev Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 70 +--- hw/xen/xen_pvdev.c| 75 +++ include/hw/xen/xen_backend.h | 1 - include/hw/xen/xen_frontend.h | 2 ++ include/hw/xen/xen_pvdev.h| 4 +++ 5 files changed, 82 insertions(+), 70 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 5f2821a..2f7f1a6 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -55,7 +55,6 @@ struct xs_dirs { static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = QTAILQ_HEAD_INITIALIZER(xs_cleanup); -static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs); static int debug = 0; static void xenstore_cleanup_dir(char *dir) @@ -141,27 +140,6 @@ int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state) return 0; } -/* - */ - -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) -{ -struct XenDevice *xendev; - -QTAILQ_FOREACH(xendev, &xendevs, next) { -if (xendev->dom != dom) { -continue; -} -if (xendev->dev != dev) { -continue; -} -if (strcmp(xendev->type, type) != 0) { -continue; -} -return xendev; -} -return NULL; -} - /* * get xen backend device, allocate a new one if it doesn't exist. */ @@ -210,7 +188,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, xendev->gnttabdev = NULL; } -QTAILQ_INSERT_TAIL(&xendevs, xendev, next); +xen_pv_insert_xendev(xendev); if (xendev->ops->alloc) { xendev->ops->alloc(xendev); @@ -219,52 +197,6 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, return xendev; } -/* - * release xen backend device. - */ -static struct XenDevice *xen_be_del_xendev(int dom, int dev) -{ -struct XenDevice *xendev, *xnext; - -/* - * This is pretty much like QTAILQ_FOREACH(xendev, &xendevs, next) but - * we save the next pointer in xnext because we might free xendev. - */ -xnext = xendevs.tqh_first; -while (xnext) { -xendev = xnext; -xnext = xendev->next.tqe_next; - -if (xendev->dom != dom) { -continue; -} -if (xendev->dev != dev && dev != -1) { -continue; -} - -if (xendev->ops->free) { -xendev->ops->free(xendev); -} - -if (xendev->fe) { -char token[XEN_BUFSIZE]; -snprintf(token, sizeof(token), "fe:%p", xendev); -xs_unwatch(xenstore, xendev->fe, token); -g_free(xendev->fe); -} - -if (xendev->evtchndev != NULL) { -xenevtchn_close(xendev->evtchndev); -} -if (xendev->gnttabdev != NULL) { -xengnttab_close(xendev->gnttabdev); -} - -QTAILQ_REMOVE(&xendevs, xendev, next); -g_free(xendev); -} -return NULL; -} /* * Sync internal data structures on xenstore updates. diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 7876724..042adeb 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -23,7 +23,9 @@ #include "hw/xen/xen_frontend.h" #include "hw/xen/xen_pvdev.h" +/* private */ static int debug = 0; +static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs); /* - */ int xenstore_write_str(const char *base, const char *node, const char *val) @@ -206,3 +208,76 @@ int xen_be_send_notify(struct XenDevice *xendev) { return xenevtchn_notify(xendev->evtchndev, xendev->local_port); } + +/* - */ + +struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) +{ +struct XenDevice *xendev; + +QTAILQ_FOREACH(xendev, &xendevs, next) { +if (xendev->dom != dom) { +continue; +} +if (xendev->dev != dev) { +continue; +} +if (strcmp(xendev->type, type) != 0) { +continue; +} +return xendev; +} +return NULL; +} + +/* + * release xen backend device. + */ +struct XenDevice *xen_be_del_xendev(int dom, int dev) +{ +struct XenDevice *xendev, *xnext; + +/* + * This is pretty much like QTAILQ_FOREACH(xendev, &xendevs, next) but + * we save the next pointer in xnext because we might free xendev. + */ +xnext = xendevs.tqh_first; +while (xnext) { +xendev = xnext; +xnext = xendev->next
[Xen-devel] [PATCH 03/19] xen: Move xenstore_update to xen_pvdev.c
* xenstore_update -> xen_pvdev.c * xenstore_update_fe -> xen_frontend.c Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 43 +-- hw/xen/xen_frontend.c | 18 ++ hw/xen/xen_pvdev.c| 24 include/hw/xen/xen_backend.h | 1 + include/hw/xen/xen_frontend.h | 1 + include/hw/xen/xen_pvdev.h| 1 + 6 files changed, 46 insertions(+), 42 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 7a83a7d..0a9f9bb 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -527,7 +527,7 @@ static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops) return 0; } -static void xenstore_update_be(char *watch, char *type, int dom, +void xenstore_update_be(char *watch, char *type, int dom, struct XenDevOps *ops) { struct XenDevice *xendev; @@ -561,47 +561,6 @@ static void xenstore_update_be(char *watch, char *type, int dom, } } -static void xenstore_update_fe(char *watch, struct XenDevice *xendev) -{ -char *node; -unsigned int len; - -len = strlen(xendev->fe); -if (strncmp(xendev->fe, watch, len) != 0) { -return; -} -if (watch[len] != '/') { -return; -} -node = watch + len + 1; - -xen_be_frontend_changed(xendev, node); -xen_be_check_state(xendev); -} - -static void xenstore_update(void *unused) -{ -char **vec = NULL; -intptr_t type, ops, ptr; -unsigned int dom, count; - -vec = xs_read_watch(xenstore, &count); -if (vec == NULL) { -goto cleanup; -} - -if (sscanf(vec[XS_WATCH_TOKEN], "be:%" PRIxPTR ":%d:%" PRIxPTR, - &type, &dom, &ops) == 3) { -xenstore_update_be(vec[XS_WATCH_PATH], (void*)type, dom, (void*)ops); -} -if (sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr) == 1) { -xenstore_update_fe(vec[XS_WATCH_PATH], (void*)ptr); -} - -cleanup: -free(vec); -} - static void xen_be_evtchn_event(void *opaque) { struct XenDevice *xendev = opaque; diff --git a/hw/xen/xen_frontend.c b/hw/xen/xen_frontend.c index b4bf8da..4e01169 100644 --- a/hw/xen/xen_frontend.c +++ b/hw/xen/xen_frontend.c @@ -68,3 +68,21 @@ void xen_be_frontend_changed(struct XenDevice *xendev, const char *node) } } } + +void xenstore_update_fe(char *watch, struct XenDevice *xendev) +{ +char *node; +unsigned int len; + +len = strlen(xendev->fe); +if (strncmp(xendev->fe, watch, len) != 0) { +return; +} +if (watch[len] != '/') { +return; +} +node = watch + len + 1; + +xen_be_frontend_changed(xendev, node); +xen_be_check_state(xendev); +} diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index a444855..001fda2 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "hw/xen/xen_backend.h" +#include "hw/xen/xen_frontend.h" #include "hw/xen/xen_pvdev.h" static int debug = 0; @@ -95,6 +96,29 @@ int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval) return rc; } +void xenstore_update(void *unused) +{ +char **vec = NULL; +intptr_t type, ops, ptr; +unsigned int dom, count; + +vec = xs_read_watch(xenstore, &count); +if (vec == NULL) { +goto cleanup; +} + +if (sscanf(vec[XS_WATCH_TOKEN], "be:%" PRIxPTR ":%d:%" PRIxPTR, + &type, &dom, &ops) == 3) { +xenstore_update_be(vec[XS_WATCH_PATH], (void*)type, dom, (void*)ops); +} +if (sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr) == 1) { +xenstore_update_fe(vec[XS_WATCH_PATH], (void*)ptr); +} + +cleanup: +free(vec); +} + const char *xenbus_strstate(enum xenbus_state state) { static const char *const name[] = { diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 0daaf7c..4832f79 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -19,6 +19,7 @@ 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); char *xenstore_read_be_str(struct XenDevice *xendev, const char *node); int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int *ival); +void xenstore_update_be(char *watch, char *type, int dom, struct XenDevOps *ops); struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); void xen_be_check_state(struct XenDevice *xendev); diff --git a/include/hw/xen/xen_frontend.h b/include/hw/xen/xen_frontend.h index 46485b9..7d87da4 100644 --- a/include/hw/xen/xen_frontend.h +++ b/include/hw/xen/xen_frontend.h @@ -4,6 +4,7 @@ char *xenstore_read_fe_str(str
[Xen-devel] [PATCH 16/19] Qemu-Xen-vTPM: Register Xen stubdom vTPM frontend driver
This driver transfers any request/repond between TPM xenstubdoms driver and Xen vTPM stubdom, and facilitates communications between Xen vTPM stubdom domain and vTPM xenstubdoms driver. It is a glue for the TPM xenstubdoms driver and Xen stubdom vTPM domain that provides the actual TPM functionality. (Xen) Xen backend driver should run before running this frontend, and initialize XenStore as the following for communication. [XenStore] for example: Domain 0: runs QEMU for guest A Domain 1: vtpmmgr Domain 2: vTPM for guest A Domain 3: HVM guest A [...] local = "" domain = "" 0 = "" frontend = "" vtpm = "" 2 = "" 0 = "" backend = "/local/domain/2/backend/vtpm/0/0" backend-id = "2" state = "*" handle = "0" domain = "Domain3's name" ring-ref = "*" event-channel = "*" feature-protocol-v2 = "1" backend = "" qdisk = "" [...] console = "" vif = "" [...] 2 = "" [...] backend = "" vtpm = "" 0 = "" 0 = "" frontend = "/local/domain/0/frontend/vtpm/2/0" frontend-id = "0" ('0', frontend is running in Domain-0) [...] 3 = "" [...] device = "" (frontend device, the backend is running in QEMU/.etc) vkbd = "" [...] vif = "" [...] .. (QEMU) xen_vtpmdev_ops is initialized with the following process: xen_hvm_init() [...] -->xen_fe_register("vtpm", ...) -->xenstore_fe_scan() -->xen_fe_try_init(ops) --> XenDevOps.init() -->xen_fe_get_xendev() --> XenDevOps.alloc() -->xen_fe_check() -->xen_fe_try_initialise() --> XenDevOps.initialise() -->xen_fe_try_connected() --> XenDevOps.connected() -->xs_watch() [...] Signed-off-by: Quan Xu Signed-off-by: Emil Condrea Reviewed-by: Stefan Berger --- Changed in v9: * 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) * added xen_vtpm_frontend.h * move vtpm_backend_changed -> xen_fe_backend_changed to xen_frontend.c * use libxengnttab, libxenevtchn stable API instead of xc_* calls: - xc_gntshr_share_pages -> xengntshr_share_pages - xc_gntshr_munmap -> xengntshr_unshare - xc_interface_close -> xengntshr_close - xc_evtchn_unmask -> xenevtchn_unmask --- hw/tpm/Makefile.objs | 1 + hw/tpm/xen_vtpm_frontend.c| 303 ++ hw/tpm/xen_vtpm_frontend.h| 10 ++ hw/xen/xen_frontend.c | 20 +++ include/hw/xen/xen_backend.h | 1 + include/hw/xen/xen_frontend.h | 1 + xen-hvm.c | 6 + 7 files changed, 342 insertions(+) create mode 100644 hw/tpm/xen_vtpm_frontend.c create mode 100644 hw/tpm/xen_vtpm_frontend.h diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs index 64cecc3..b0a821c 100644 --- a/hw/tpm/Makefile.objs +++ b/hw/tpm/Makefile.objs @@ -1,2 +1,3 @@ common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o tpm_util.o +common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.o diff --git a/hw/tpm/xen_vtpm_frontend.c b/hw/tpm/xen_vtpm_frontend.c new file mode 100644 index 000..cf3eb5e --- /dev/null +++ b/hw/tpm/xen_vtpm_frontend.c @@ -0,0 +1,303 @@ +/* + * Connect to Xen vTPM stubdom domain + * + * Copyright (c) 2015 Intel Corporation + * Authors: + *Quan Xu + * + * 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 "xen_vtpm_frontend.h" +#include "hw/xen/xen_frontend.h" +#include "hw/xen/xen_backend.h" + +int xenstore_vtpm_dev; +#ifndef XS_STUBDOM_VTPM_ENABLE +#define XS_STUBDOM_VTPM_ENABLE"1" +#endif + +#ifndef VTPM_PAGE_SIZE +#define VTPM_PAGE_SIZE 40
[Xen-devel] [PATCH 17/19] Qemu-Xen-vTPM: Move tpm_passthrough_is_selftest() into tpm_util.c
Also rename it to tpm_util_is_selftest(). Signed-off-by: Quan Xu Signed-off-by: Emil Condrea Reviewed-by: Stefan Berger --- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_passthrough.c | 13 + hw/tpm/tpm_util.c| 11 +++ hw/tpm/tpm_util.h| 1 + 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs index b0a821c..16b1447 100644 --- a/hw/tpm/Makefile.objs +++ b/hw/tpm/Makefile.objs @@ -1,3 +1,3 @@ -common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o +common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o tpm_util.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o tpm_util.o common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.o diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index e88c0d2..dba408b 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -137,17 +137,6 @@ static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len) } } -static bool tpm_passthrough_is_selftest(const uint8_t *in, uint32_t in_len) -{ -struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; - -if (in_len >= sizeof(*hdr)) { -return (be32_to_cpu(hdr->ordinal) == TPM_ORD_ContinueSelfTest); -} - -return false; -} - static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, const uint8_t *in, uint32_t in_len, uint8_t *out, uint32_t out_len, @@ -161,7 +150,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, tpm_pt->tpm_executing = true; *selftest_done = false; -is_selftest = tpm_passthrough_is_selftest(in, in_len); +is_selftest = tpm_util_is_selftest(in, in_len); ret = tpm_passthrough_unix_write(tpm_pt->tpm_fd, in, in_len); if (ret != in_len) { diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c index 7b35429..323f4ae 100644 --- a/hw/tpm/tpm_util.c +++ b/hw/tpm/tpm_util.c @@ -125,3 +125,14 @@ int tpm_util_test_tpmdev(int tpm_fd, TPMVersion *tpm_version) return 1; } + +bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len) +{ +struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; + +if (in_len >= sizeof(*hdr)) { +return (be32_to_cpu(hdr->ordinal) == TPM_ORD_ContinueSelfTest); +} + +return false; +} diff --git a/hw/tpm/tpm_util.h b/hw/tpm/tpm_util.h index e7f354a..b629663 100644 --- a/hw/tpm/tpm_util.h +++ b/hw/tpm/tpm_util.h @@ -24,5 +24,6 @@ #include "sysemu/tpm_backend.h" int tpm_util_test_tpmdev(int tpm_fd, TPMVersion *tpm_version); +bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len); #endif /* TPM_TPM_UTILS_H */ -- 1.9.1 ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
[Xen-devel] [PATCH 14/19] Qemu-Xen-vTPM: Support for Xen stubdom vTPM command line options
Signed-off-by: Quan Xu Signed-off-by: Emil Condrea Reviewed-by: Eric Blake --- Changes in v9: * Replace `type` with `struct` as required by 895a2a80e * Change `qpm_query_tpm_inst` as required by ce21131a0 --- configure| 14 ++ hmp.c| 2 ++ qapi-schema.json | 16 ++-- qemu-options.hx | 13 +++-- tpm.c| 7 ++- 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/configure b/configure index e9090a0..29e982e 100755 --- a/configure +++ b/configure @@ -3242,6 +3242,16 @@ else fi ## +# TPM xenstubdoms is only on x86 Linux + +if test "$targetos" = Linux && test "$cpu" = i386 -o "$cpu" = x86_64 && \ + test "$xen" = "yes"; then + tpm_xenstubdoms=$tpm +else + tpm_xenstubdoms=no +fi + +## # attr probe if test "$attr" != "no" ; then @@ -4891,6 +4901,7 @@ echo "gcov $gcov_tool" echo "gcov enabled $gcov" echo "TPM support $tpm" echo "libssh2 support $libssh2" +echo "TPM xenstubdoms $tpm_xenstubdoms" echo "TPM passthrough $tpm_passthrough" echo "QOM debugging $qom_cast_debug" echo "vhdx $vhdx" @@ -5431,6 +5442,9 @@ if test "$tpm" = "yes"; then if test "$tpm_passthrough" = "yes"; then echo "CONFIG_TPM_PASSTHROUGH=y" >> $config_host_mak fi + if test "$tpm_xenstubdoms" = "yes"; then +echo "CONFIG_TPM_XENSTUBDOMS=y" >> $config_host_mak + fi fi echo "TRACE_BACKENDS=$trace_backends" >> $config_host_mak diff --git a/hmp.c b/hmp.c index 0cf5baa..1ed7a28 100644 --- a/hmp.c +++ b/hmp.c @@ -883,6 +883,8 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) tpo->has_cancel_path ? ",cancel-path=" : "", tpo->has_cancel_path ? tpo->cancel_path : ""); break; +case TPM_TYPE_OPTIONS_KIND_XENSTUBDOMS: +break; case TPM_TYPE_OPTIONS_KIND__MAX: break; } diff --git a/qapi-schema.json b/qapi-schema.json index d2d6506..12efb23 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3502,9 +3502,11 @@ # # @passthrough: TPM passthrough type # +# @xenstubdoms: TPM xenstubdoms type (since 2.7) +# # Since: 1.5 ## -{ 'enum': 'TpmType', 'data': [ 'passthrough' ] } +{ 'enum': 'TpmType', 'data': [ 'passthrough', 'xenstubdoms' ] } ## # @query-tpm-types: @@ -3533,6 +3535,15 @@ '*cancel-path' : 'str'} } ## +# @TPMXenstubdomsOptions: +# +# Information about the TPM xenstubdoms type +# +# Since: 2.7 +## +{ 'struct': 'TPMXenstubdomsOptions', 'data': { } } + +## # @TpmTypeOptions: # # A union referencing different TPM backend types' configuration options @@ -3542,7 +3553,8 @@ # Since: 1.5 ## { 'union': 'TpmTypeOptions', - 'data': { 'passthrough' : 'TPMPassthroughOptions' } } + 'data': { 'passthrough' : 'TPMPassthroughOptions', +'xenstubdoms' : 'TPMXenstubdomsOptions' } } ## # @TpmInfo: diff --git a/qemu-options.hx b/qemu-options.hx index 8e0d9a5..748fb62 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2748,7 +2748,8 @@ DEF("tpmdev", HAS_ARG, QEMU_OPTION_tpmdev, \ "-tpmdev passthrough,id=id[,path=path][,cancel-path=path]\n" "use path to provide path to a character device; default is /dev/tpm0\n" "use cancel-path to provide path to TPM's cancel sysfs entry; if\n" -"not provided it will be searched for in /sys/class/misc/tpm?/device\n", +"not provided it will be searched for in /sys/class/misc/tpm?/device\n" +"-tpmdev xenstubdoms,id=id\n", QEMU_ARCH_ALL) STEXI @@ -2758,7 +2759,8 @@ The general form of a TPM device option is: @item -tpmdev @var{backend} ,id=@var{id} [,@var{options}] @findex -tpmdev Backend type must be: -@option{passthrough}. +@option{passthrough}, or +@option{xenstubdoms}. The specific backend type will determine the applicable options. The @code{-tpmdev} option creates the TPM backend and requires a @@ -2808,6 +2810,13 @@ To create a passthrough TPM use the following two options: Note that the @code{-tpmdev} id is @code{tpm0} and is referenced by @code{tpmdev=tpm0} in the device option. +To create a xenstubdoms TPM use the following two options: +@examp
[Xen-devel] [v9 00/19] QEMU:Xen stubdom vTPM for HVM virtual machine(QEMU Part)
*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
[Xen-devel] [PATCH 01/19] xen: Create a new file xen_pvdev.c
The purpose of the new file is to store generic functions shared by frontend and backends such as xenstore operations, xendevs. Signed-off-by: Quan Xu Signed-off-by: Emil Condrea --- 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 @@ -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]; - -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; -} - 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 == er
[Xen-devel] [PATCH 06/19] xen: Rename xen_be_printf to xen_pv_printf
Prepare xen_be_printf to be used by both backend and frontends: * xen_be_printf -> xen_pv_printf Signed-off-by: Emil Condrea --- hw/block/xen_disk.c| 52 +++--- hw/char/xen_console.c | 10 - hw/display/xenfb.c | 42 ++--- hw/net/xen_nic.c | 22 ++-- hw/usb/xen-usb.c | 38 - hw/xen/xen_backend.c | 44 +++ hw/xen/xen_devconfig.c | 4 ++-- hw/xen/xen_frontend.c | 6 +++--- hw/xen/xen_pvdev.c | 6 +++--- include/hw/xen/xen_pvdev.h | 2 +- xen-common.c | 4 ++-- 11 files changed, 115 insertions(+), 115 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 28fbf24..ad3f519 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -165,12 +165,12 @@ static void destroy_grant(gpointer pgnt) xengnttab_handle *gnt = grant->blkdev->xendev.gnttabdev; if (xengnttab_unmap(gnt, grant->page, 1) != 0) { -xen_be_printf(&grant->blkdev->xendev, 0, +xen_pv_printf(&grant->blkdev->xendev, 0, "xengnttab_unmap failed: %s\n", strerror(errno)); } grant->blkdev->persistent_gnt_count--; -xen_be_printf(&grant->blkdev->xendev, 3, +xen_pv_printf(&grant->blkdev->xendev, 3, "unmapped grant %p\n", grant->page); g_free(grant); } @@ -182,11 +182,11 @@ static void remove_persistent_region(gpointer data, gpointer dev) xengnttab_handle *gnt = blkdev->xendev.gnttabdev; if (xengnttab_unmap(gnt, region->addr, region->num) != 0) { -xen_be_printf(&blkdev->xendev, 0, +xen_pv_printf(&blkdev->xendev, 0, "xengnttab_unmap region %p failed: %s\n", region->addr, strerror(errno)); } -xen_be_printf(&blkdev->xendev, 3, +xen_pv_printf(&blkdev->xendev, 3, "unmapped grant region %p with %d pages\n", region->addr, region->num); g_free(region); @@ -253,7 +253,7 @@ static int ioreq_parse(struct ioreq *ioreq) size_t len; int i; -xen_be_printf(&blkdev->xendev, 3, +xen_pv_printf(&blkdev->xendev, 3, "op %d, nr %d, handle %d, id %" PRId64 ", sector %" PRId64 "\n", ioreq->req.operation, ioreq->req.nr_segments, ioreq->req.handle, ioreq->req.id, ioreq->req.sector_number); @@ -273,28 +273,28 @@ static int ioreq_parse(struct ioreq *ioreq) case BLKIF_OP_DISCARD: return 0; default: -xen_be_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n", +xen_pv_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n", ioreq->req.operation); goto err; }; if (ioreq->req.operation != BLKIF_OP_READ && blkdev->mode[0] != 'w') { -xen_be_printf(&blkdev->xendev, 0, "error: write req for ro device\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: write req for ro device\n"); goto err; } ioreq->start = ioreq->req.sector_number * blkdev->file_blk; for (i = 0; i < ioreq->req.nr_segments; i++) { if (i == BLKIF_MAX_SEGMENTS_PER_REQUEST) { -xen_be_printf(&blkdev->xendev, 0, "error: nr_segments too big\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: nr_segments too big\n"); goto err; } if (ioreq->req.seg[i].first_sect > ioreq->req.seg[i].last_sect) { -xen_be_printf(&blkdev->xendev, 0, "error: first > last sector\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: first > last sector\n"); goto err; } if (ioreq->req.seg[i].last_sect * BLOCK_SIZE >= XC_PAGE_SIZE) { -xen_be_printf(&blkdev->xendev, 0, "error: page crossing\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: page crossing\n"); goto err; } @@ -306,7 +306,7 @@ static int ioreq_parse(struct ioreq *ioreq) qemu_iovec_add(&ioreq->v, (void*)mem, len); } if (ioreq->start + ioreq->v.size > blkdev->file_size) { -xen_be_printf(&blkdev->xendev, 0, "error: access beyond end of file\n"); +xen_pv_printf(&blkdev->xendev, 0, "error: access beyond end of file\n"); goto err; } return 0; @@ -329,7 +329,7 @@ static void ioreq_unmap(struct ioreq *io
Re: [Xen-devel] [PATCH 01/19] xen: Create a new file xen_pvdev.c
On Jul 17, 2016 10:41, "Quan Xu" wrote: > > > [Quan:]: comment starts with [Quan:] > Thanks, Quan for your comments. The first patches from this series just move some code from xen_backend to xen_pvdev file. I would not group the reorg from xen_backend with refactoring in the same patch. Eventually this can be done in another patch later. > > > The purpose of the new file is to store generic functions shared by frontend > and backends such as xenstore operations, xendevs. > > Signed-off-by: Quan Xu > Signed-off-by: Emil Condrea > --- > 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 > > @@ -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); >
Re: [Xen-devel] [PATCH 01/19] xen: Create a new file xen_pvdev.c
Eric, this is the link to the original patch which is well formatted: http://marc.info/?l=xen-devel&m=146815138831762&w=2 I think that the formatting and s-o-b was broken in the reply from Quan. On Jul 18, 2016 17:57, "Eric Blake" wrote: > On 07/17/2016 01:41 AM, Quan Xu wrote: > > > > [Quan:]: comment starts with [Quan:] > > > > This line doesn't belong in a commit message; it's fine to put it after > the --- separator though, if it aids mailing list reviewers. > > > > > The purpose of the new file is to store generic functions shared by > frontendand backends such as xenstore operations, xendevs. > > > > s/frontendand/front end and/ > > Please wrap your commit message lines. Since 'git log' displays logs > with indentation, wrapping around 72 characters is ideal. > > > Signed-off-by: Quan Xu > > Signed-off-by: Emil Condrea > > These are not valid S-o-b, therefore this patch cannot be applied as-is. > > > > -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)) { > > This is not a valid patch. Are you replying to a patch that someone > else posted? If so, your quoting style is VERY difficult to read. > Please consider using a leading > before every line that you are quoting > (rather than pasting it verbatim as if you had written it), and include > a blank line both before and after every line that you insert, to call > visual attention to what is your reply vs. what you are quoting. > > > -- > Eric Blake eblake redhat com+1-919-301-3266 > Libvirt virtualization library http://libvirt.org > > ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH 01/19] xen: Create a new file xen_pvdev.c
Sure, I will continue to send revisions until it is approved upstream. On Jul 22, 2016 5:24 PM, "Quan Xu" wrote: > 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.per...@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 > ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
Re: [Xen-devel] vTPM Deep Quote validation
I think it is fair to read the PCRs before performing Deep Quote and after and to retry if something changed. It is an interesting suggestion to extend the tpm character device driver in order to obtain atomicity. I will think about it. Thanks for clarifying. On Mon, Mar 9, 2015 at 7:26 PM, Daniel De Graaf wrote: > On 03/09/2015 11:58 AM, Emil Condrea wrote: > >> On Mon, Mar 9, 2015 at 4:40 PM, Daniel De Graaf >> wrote: >> >> On 03/08/2015 07:41 AM, Emil Condrea wrote: >>> >>> I am trying to validate a Deep Quote request made by domU but I feel >>>> that >>>> something is missing. Right now when a domU requests TPM_ORD_DeepQuote: >>>> 1. vTPM: >>>> - unpacks the params: nonce, vTPM PCR selection and physical PCR >>>> selection >>>> - packs PCR_INFO_SHORT structure into buf that contains the selected >>>> vTPM >>>> PCRs >>>> - computes nonce as a SHA1 of: dquot_hdr, nonce, and previous packed buf >>>> - packs: nonce, physical PCR selection >>>> - receives physical pcr data and signature from manager and returns them >>>> to >>>> DomU >>>> 2. vTPM Manager >>>> - unpacks the params: nonce, PCR selection >>>> - execute TPM_Quote with: externalData = nonce >>>> - returns pcr data and signature to vTPM >>>> >>>> If domU user wants to validate the signature it has to do the exact >>>> process >>>> that the vtpm and manager did but the virtual PCR values are not >>>> included >>>> in response, just physical ones. >>>> >>>> >>> The virtual machine can use TPM_PCRRead to get the value of the vTPM >>> PCRs. >>> This is the same method that is used by the TPM_Quote2 command. >>> >> >> >> I thought of using TPM_PCRRead from virtual machine but it was not clear >> for me if it is safe. >> Is it possible for the selected vTPM PCRs values to be different when >> performing >> composite hash on vTPM from the values read with TPM_PCRRead after >> executing DeepQuote? >> > > One way to detect this is by reading the PCRs before and after asking > for a quote. If the values match, then the quote used those values; if > not, try the quote operation again. In either case, you should have a > log or other information on what values have been extended into the PCRs > so that a verifier can make sense of them: there is little reason to > include the PCRs in a quote if you can't reconstruct them. > As an alternative to retrying, you could try to reconstruct the PCRs > used in the quote by hashing the various possibilities drawn from the > logs. If the number of extend operations between the pre- and post-read > operations is reasonable, this could end up being faster than asking for > another quote from the (rather slow) hardware TPM. > > The TPM has context management for each application? (eg: when one >> application extends something >> into a PCR and another application extends other thing in the same PCR(at >> the same time moment), >> are they hashed together?) >> > > This depends on the TPM multiplexing daemon (usually trousers in Linux). > I believe it just processes the requests in the order it receives them, > so without external synchronization they would be in an arbitrary order. > > I am unsure if this is implemented (and would guess it is currently > not), but it would be possible for trousers to queue up several commands > (such as PCR reads and quote requests) from a single source and > guarantee that they are executed without intervening commands. In order > to avoid interactions with IMA, this would need an extension to the > Linux TPM character device interface to submit multiple commands for > processing without unlocking the TPM device. > > > When I read the standard I understood that the PCRs can never be >> overwritten, >> just reset and extended. >> >> Thanks. >> >> >>> >>> We can include the vTPM PCRS in response or the manager must perform >>> >>>> TPM_Quote using the nonce received from domU in order to be able to >>>> have a >>>> successful validation on the client side. >>>> >>>> >>> If you want a quote without any vTPM PCRs, you can specify an empty PCR >>> mask >>> to get something fairly close to this behavior - the nonce will be >>> combined >>> with an empty deep quote structure instead of passed directly. >>> >>> What do you think? Is there something that I am missing ? >>> >>>> >>>> >>> It is useful to be able to ask for the current value of both physical and >>> virtual PCRs in a single atomic operation. Including the value of all >>> PCRs >>> in the response could make the reply packet too large (which is part of >>> the >>> reason why TPM_Quote2 removed them). >>> >>> -- >>> Daniel De Graaf >>> National Security Agency >>> >>> >> > > -- > Daniel De Graaf > National Security Agency > ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
[Xen-devel] vTPM Deep Quote validation
I am trying to validate a Deep Quote request made by domU but I feel that something is missing. Right now when a domU requests TPM_ORD_DeepQuote: 1. vTPM: - unpacks the params: nonce, vTPM PCR selection and physical PCR selection - packs PCR_INFO_SHORT structure into buf that contains the selected vTPM PCRs - computes nonce as a SHA1 of: dquot_hdr, nonce, and previous packed buf - packs: nonce, physical PCR selection - receives physical pcr data and signature from manager and returns them to DomU 2. vTPM Manager - unpacks the params: nonce, PCR selection - execute TPM_Quote with: externalData = nonce - returns pcr data and signature to vTPM If domU user wants to validate the signature it has to do the exact process that the vtpm and manager did but the virtual PCR values are not included in response, just physical ones. We can include the vTPM PCRS in response or the manager must perform TPM_Quote using the nonce received from domU in order to be able to have a successful validation on the client side. What do you think? Is there something that I am missing ? ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Re: [Xen-devel] vTPM Deep Quote validation
TPM_ORD_DeepQuote is a custom command used just with vTPMs so a domU user can get a quote signed with vTPM PCRs and also physical PCRs. It is not included in 1.2 specification. On Mon, Mar 9, 2015 at 4:51 PM, Xu, Quan wrote: > For ‘TPM_ORD_DeepQuote’cmd, it looks like a specific TPM 1.2 emulator > command, instead of TPM physic cmd. I can’t find it in TPM 1.2 spec. > > (my TPM Main Part2 TPM Structures is *Specification version 1.2/ Level 2 > Revision 116 / 1 March 2011*) > > > > > > -Quan > > > > *From:* xen-devel-boun...@lists.xen.org [mailto: > xen-devel-boun...@lists.xen.org] *On Behalf Of *Emil Condrea > *Sent:* Sunday, March 08, 2015 7:41 PM > *To:* xen-devel@lists.xen.org > *Cc:* Daniel De Graaf > *Subject:* [Xen-devel] vTPM Deep Quote validation > > > > I am trying to validate a Deep Quote request made by domU but I feel that > something is missing. Right now when a domU requests TPM_ORD_DeepQuote: > > 1. vTPM: > > - unpacks the params: nonce, vTPM PCR selection and physical PCR selection > > - packs PCR_INFO_SHORT structure into buf that contains the selected vTPM > PCRs > > - computes nonce as a SHA1 of: dquot_hdr, nonce, and previous packed buf > > - packs: nonce, physical PCR selection > > - receives physical pcr data and signature from manager and returns them > to DomU > > 2. vTPM Manager > > - unpacks the params: nonce, PCR selection > > - execute TPM_Quote with: externalData = nonce > > - returns pcr data and signature to vTPM > > > If domU user wants to validate the signature it has to do the exact > process that the vtpm and manager did but the virtual PCR values are not > included in response, just physical ones. > > We can include the vTPM PCRS in response or the manager must perform > TPM_Quote using the nonce received from domU in order to be able to have a > successful validation on the client side. > > What do you think? Is there something that I am missing ? > ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Re: [Xen-devel] vTPM Deep Quote validation
On Mon, Mar 9, 2015 at 4:40 PM, Daniel De Graaf wrote: > On 03/08/2015 07:41 AM, Emil Condrea wrote: > >> I am trying to validate a Deep Quote request made by domU but I feel that >> something is missing. Right now when a domU requests TPM_ORD_DeepQuote: >> 1. vTPM: >> - unpacks the params: nonce, vTPM PCR selection and physical PCR selection >> - packs PCR_INFO_SHORT structure into buf that contains the selected vTPM >> PCRs >> - computes nonce as a SHA1 of: dquot_hdr, nonce, and previous packed buf >> - packs: nonce, physical PCR selection >> - receives physical pcr data and signature from manager and returns them >> to >> DomU >> 2. vTPM Manager >> - unpacks the params: nonce, PCR selection >> - execute TPM_Quote with: externalData = nonce >> - returns pcr data and signature to vTPM >> >> If domU user wants to validate the signature it has to do the exact >> process >> that the vtpm and manager did but the virtual PCR values are not included >> in response, just physical ones. >> > > The virtual machine can use TPM_PCRRead to get the value of the vTPM PCRs. > This is the same method that is used by the TPM_Quote2 command. I thought of using TPM_PCRRead from virtual machine but it was not clear for me if it is safe. Is it possible for the selected vTPM PCRs values to be different when performing composite hash on vTPM from the values read with TPM_PCRRead after executing DeepQuote? The TPM has context management for each application? (eg: when one application extends something into a PCR and another application extends other thing in the same PCR(at the same time moment), are they hashed together?) When I read the standard I understood that the PCRs can never be overwritten, just reset and extended. Thanks. > > > We can include the vTPM PCRS in response or the manager must perform >> TPM_Quote using the nonce received from domU in order to be able to have a >> successful validation on the client side. >> > > If you want a quote without any vTPM PCRs, you can specify an empty PCR > mask > to get something fairly close to this behavior - the nonce will be combined > with an empty deep quote structure instead of passed directly. > > What do you think? Is there something that I am missing ? >> > > It is useful to be able to ask for the current value of both physical and > virtual PCRs in a single atomic operation. Including the value of all PCRs > in the response could make the reply packet too large (which is part of the > reason why TPM_Quote2 removed them). > > -- > Daniel De Graaf > National Security Agency > ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
[Xen-devel] [PATCH 0/2] vtpm deep quote in locality 0
Right now, deep quote functionality is enabled just when vtpm manager is started with locality=2. This requirement is enforced by the current implementation which uses PCRs that can be reset in locality 2: 20,21,22,23. Since some TPM chips do not enable access to other locality than 0 this patch enables the deep quote functionality for vtpm manager started with locality=0. The patches are based on a suggestion given by Daniel De Graaf in another thread on the list: - Add a field to the request - extraInfoFlags - Compute externData = SHA1 ( extraInfoFlags requestData [UUIDs if requested] [vTPM measurements if requested] [vTPM group update policy if requested] ) - Perform deep quotes using the above externData value instead of the value provided by the vTPM. Embedding additional data in externData is equivalently secure as extending it into PCRs. This change also has the benefit of increasing the flexibility of the request. It is simple to define additional flags and add data to the hash if needed. Emil Condrea (2): vtpm: deep quote flags vtpmmgr: execute deep quote in locality 0 stubdom/Makefile| 1 + stubdom/vtpm-deepquote-anyloc.patch | 127 stubdom/vtpm/vtpm_cmd.c | 13 ++-- stubdom/vtpmmgr/marshal.h | 1 + stubdom/vtpmmgr/mgmt_authority.c| 89 ++--- stubdom/vtpmmgr/mgmt_authority.h| 2 +- stubdom/vtpmmgr/vtpm_cmd_handler.c | 7 +- stubdom/vtpmmgr/vtpm_manager.h | 16 + 8 files changed, 238 insertions(+), 18 deletions(-) create mode 100644 stubdom/vtpm-deepquote-anyloc.patch -- 2.1.0 ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
[Xen-devel] [PATCH 2/2] vtpmmgr: execute deep quote in locality 0
Enables deep quote execution for vtpmmgr which can not be started using locality 2. The VTPM_ORD_GET_QUOTE command is backwards compatible. When receives flags=0 from vTPM it extends additional information into the PCRs as it did before. Flags are interpreted as a bitmask of: * VTPM_QUOTE_FLAGS_HASH_UUID * VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS * VTPM_QUOTE_FLAGS_GROUP_INFO When using flags!=0, vtpmmgr ignores quoteSelect and TPM_Quote is executed with: externData = SHA1( flags, requestData, [UUIDs if requested], [vTPM measurements if requested], [vTPM group update policy if requested] ) Signed-off-by: Emil Condrea --- stubdom/vtpmmgr/marshal.h | 1 + stubdom/vtpmmgr/mgmt_authority.c | 89 ++ stubdom/vtpmmgr/mgmt_authority.h | 2 +- stubdom/vtpmmgr/vtpm_cmd_handler.c | 7 ++- stubdom/vtpmmgr/vtpm_manager.h | 16 +++ 5 files changed, 103 insertions(+), 12 deletions(-) diff --git a/stubdom/vtpmmgr/marshal.h b/stubdom/vtpmmgr/marshal.h index bcc7c46..d826f19 100644 --- a/stubdom/vtpmmgr/marshal.h +++ b/stubdom/vtpmmgr/marshal.h @@ -195,6 +195,7 @@ inline int unpack3_UINT32(BYTE* ptr, UINT32* pos, UINT32 max, UINT32 *t) #define unpack3_TPM_PHYSICAL_PRESENCE(p, l, m, t) unpack3_UINT16(p, l, m, t) #define unpack3_TPM_KEY_FLAGS(p, l, m, t) unpack3_UINT32(p, l, m, t) #define unpack3_TPM_LOCALITY_SELECTION(p, l, m, t) unpack3_BYTE(p, l, m, t) +#define unpack3_TPM_DEEP_QUOTE_INFO(p, l, m, t) unpack3_UINT32(p, l, m, t) #define sizeof_TPM_RESULT(t) sizeof_UINT32(t) #define sizeof_TPM_PCRINDEX(t) sizeof_UINT32(t) diff --git a/stubdom/vtpmmgr/mgmt_authority.c b/stubdom/vtpmmgr/mgmt_authority.c index 0526a12..0e4aac7 100644 --- a/stubdom/vtpmmgr/mgmt_authority.c +++ b/stubdom/vtpmmgr/mgmt_authority.c @@ -128,6 +128,49 @@ static int do_load_aik(struct mem_group *group, TPM_HANDLE *handle) return TPM_LoadKey(TPM_SRK_KEYHANDLE, &key, handle, (void*)&vtpm_globals.srk_auth, &vtpm_globals.oiap); } +static void do_vtpminfo_hash(uint32_t extra_info_flags,struct mem_group *group, + const void* uuid, const uint8_t* kern_hash,unsigned char** calc_hashes) +{ + int i; + sha1_context ctx; + if(extra_info_flags & VTPM_QUOTE_FLAGS_HASH_UUID){ + printk("hashing for FLAGS_HASH_UUID: "); + if(uuid){ + printk("true"); + sha1_starts(&ctx); + sha1_update(&ctx, (void*)uuid, 16); + sha1_finish(&ctx, *calc_hashes); + *calc_hashes = *calc_hashes + 20; + } + printk("\n"); + } + if(extra_info_flags & VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS){ + printk("hashing for VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS: "); + if(kern_hash){ + printk("true"); + sha1_starts(&ctx); + sha1_update(&ctx, (void*)kern_hash, 20); + sha1_finish(&ctx, *calc_hashes); + *calc_hashes = *calc_hashes + 20; + } + printk("\n"); + } + if(extra_info_flags & VTPM_QUOTE_FLAGS_GROUP_INFO){ + printk("hashing for VTPM_QUOTE_FLAGS_GROUP_INFO: true"); + sha1_starts(&ctx); + sha1_update(&ctx, (void*)&group->id_data.saa_pubkey, sizeof(group->id_data.saa_pubkey)); + sha1_update(&ctx, (void*)&group->details.cfg_seq, 8); + sha1_update(&ctx, (void*)&group->seal_bits.nr_cfgs, 4); + for(i=0; i < group->nr_seals; i++) + sha1_update(&ctx, (void*)&group->seals[i].digest_release, 20); + sha1_update(&ctx, (void*)&group->seal_bits.nr_kerns, 4); + sha1_update(&ctx, (void*)&group->seal_bits.kernels, 20 * be32_native(group->seal_bits.nr_kerns)); + sha1_finish(&ctx, *calc_hashes); + *calc_hashes = *calc_hashes + 20; + printk("\n"); + } +} + /* * Sets up resettable PCRs for a vTPM deep quote request */ @@ -273,18 +316,44 @@ int group_do_activate(struct mem_group *group, void* blob, int blobSize, int vtpm_do_quote(struct mem_group *group, const uuid_t uuid, const uint8_t* kern_hash, const struct tpm_authdata *data, TPM_PCR_SELECTION *sel, - void* pcr_out, uint32_t *pcr_size, void* sig_out) + uint32_t extra_info_flags, void* pcr_out, uint32_t *pcr_size, void* sig_out) { TPM_HANDLE handle; TPM_AUTH_SESSION oiap = TPM_AUTH_SESSION_INIT; TPM_PCR_COMPOSITE pcrs; BYTE* sig; UINT32 size; - int rc; + sha1_context ctx; + TPM_DIGEST externData; + const void* data_to_qu
[Xen-devel] [PATCH 1/2] vtpm: deep quote flags
Currently, the flags are not interpreted by vTPM. They are just packed and sent to vtpmmgr. The new implementation is backward compatible, if it receives a request without flags, it continues the request to vtpmmgr with extraInfoFlags=0. Signed-off-by: Emil Condrea --- stubdom/Makefile| 1 + stubdom/vtpm-deepquote-anyloc.patch | 127 stubdom/vtpm/vtpm_cmd.c | 13 ++-- 3 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 stubdom/vtpm-deepquote-anyloc.patch diff --git a/stubdom/Makefile b/stubdom/Makefile index 8fb885a..c135334 100644 --- a/stubdom/Makefile +++ b/stubdom/Makefile @@ -211,6 +211,7 @@ tpm_emulator-$(XEN_TARGET_ARCH): tpm_emulator-$(TPMEMU_VERSION).tar.gz patch -d $@ -p1 < vtpm-locality.patch patch -d $@ -p1 < vtpm-parent-sign-ek.patch patch -d $@ -p1 < vtpm-deepquote.patch + patch -d $@ -p1 < vtpm-deepquote-anyloc.patch patch -d $@ -p1 < vtpm-cmake-Wextra.patch mkdir $@/build cd $@/build; CC=${CC} $(CMAKE) .. -DCMAKE_C_FLAGS:STRING="-std=c99 -DTPM_NO_EXTERN $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-declaration-after-statement" diff --git a/stubdom/vtpm-deepquote-anyloc.patch b/stubdom/vtpm-deepquote-anyloc.patch new file mode 100644 index 000..ae7df9c --- /dev/null +++ b/stubdom/vtpm-deepquote-anyloc.patch @@ -0,0 +1,127 @@ +diff --git a/tpm/tpm_cmd_handler.c b/tpm/tpm_cmd_handler.c +index 69511d1..cf441bb 100644 +--- a/tpm/tpm_cmd_handler.c b/tpm/tpm_cmd_handler.c +@@ -3347,12 +3347,13 @@ static TPM_RESULT execute_TPM_DeepQuote(TPM_REQUEST *req, TPM_RESPONSE *rsp) + { + TPM_NONCE nonce; + TPM_RESULT res; +- UINT32 sigSize; +- BYTE *sig; ++ UINT32 quote_blob_size; ++ BYTE *quote_blob; + BYTE *ptr; + UINT32 len; + TPM_PCR_SELECTION myPCR; + TPM_PCR_SELECTION ptPCR; ++ UINT32 extraInfoFlags = 0; + + tpm_compute_in_param_digest(req); + +@@ -3361,17 +3362,19 @@ static TPM_RESULT execute_TPM_DeepQuote(TPM_REQUEST *req, TPM_RESPONSE *rsp) + if (tpm_unmarshal_TPM_NONCE(&ptr, &len, &nonce) + || tpm_unmarshal_TPM_PCR_SELECTION(&ptr, &len, &myPCR) + || tpm_unmarshal_TPM_PCR_SELECTION(&ptr, &len, &ptPCR) ++ || (len>0 && tpm_unmarshal_TPM_DEEP_QUOTE_INFO(&ptr, &len, &extraInfoFlags)!=0) + || len != 0) return TPM_BAD_PARAMETER; + +- res = TPM_DeepQuote(&nonce, &myPCR, &ptPCR, &req->auth1, &sigSize, &sig); ++ res = TPM_DeepQuote(&nonce, &myPCR, &ptPCR, &req->auth1, extraInfoFlags, ++ "e_blob_size, "e_blob); + if (res != TPM_SUCCESS) return res; +- rsp->paramSize = len = sigSize; ++ rsp->paramSize = len = quote_blob_size; + rsp->param = ptr = tpm_malloc(len); +- if (ptr == NULL || tpm_marshal_BLOB(&ptr, &len, sig, sigSize)) { ++ if (ptr == NULL || tpm_marshal_BLOB(&ptr, &len, quote_blob, quote_blob_size)) { + tpm_free(rsp->param); + res = TPM_FAIL; + } +- tpm_free(sig); ++ tpm_free(quote_blob); + + return res; + } +diff --git a/tpm/tpm_commands.h b/tpm/tpm_commands.h +index 328d1be..a56dd5f 100644 +--- a/tpm/tpm_commands.h b/tpm/tpm_commands.h +@@ -3077,6 +3077,7 @@ TPM_RESULT TPM_ParentSignEK( + * @myPCR: [in] PCR selection for the virtual TPM + * @ptPCR: [in] PCR selection for the hardware TPM + * @auth1: [in, out] Authorization protocol parameters ++ * @extraInfoFlags [in] Flags for including, kernel hash, group info, etc + * @sigSize: [out] The length of the returned digital signature + * @sig: [out] The resulting digital signature and PCR values + * Returns: TPM_SUCCESS on success, a TPM error code otherwise. +@@ -3086,6 +3087,7 @@ TPM_RESULT TPM_DeepQuote( + TPM_PCR_SELECTION *myPCR, + TPM_PCR_SELECTION *ptPCR, + TPM_AUTH *auth1, ++ UINT32 extraInfoFlags, + UINT32 *sigSize, + BYTE **sig + ); +diff --git a/tpm/tpm_credentials.c b/tpm/tpm_credentials.c +index c0d62e7..6586c22 100644 +--- a/tpm/tpm_credentials.c b/tpm/tpm_credentials.c +@@ -183,7 +183,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_KEY_HANDLE keyHandle, TPM_AUTH *auth1, + + int endorsementKeyFresh = 0; + +-TPM_RESULT VTPM_GetParentQuote(TPM_DIGEST* data, TPM_PCR_SELECTION *sel, UINT32 *sigSize, BYTE **sig); ++TPM_RESULT VTPM_GetParentQuote(TPM_NONCE *data, TPM_PCR_SELECTION *sel, ++ UINT32 extraInfoFlags, UINT32 *sigSize, BYTE **sig); + + TPM_RESULT TPM_ParentSignEK(TPM_NONCE *externalData, TPM_PCR_SELECTION *sel, + TPM_AUTH *auth1, UINT32 *sigSize, BYTE **sig) +@@ -191,7 +192,7 @@ TPM_RESULT TPM_ParentSignEK(TPM_NONCE *externalData, TPM_PCR_SELECTION *sel, + TPM_PUBKEY p
Re: [Xen-devel] [PATCH 2/2] vtpmmgr: execute deep quote in locality 0
On Mon, Apr 6, 2015 at 6:49 PM, Daniel De Graaf wrote: > On 04/05/2015 07:09 AM, Emil Condrea wrote: > >> Enables deep quote execution for vtpmmgr which can not be started >> using locality 2. The VTPM_ORD_GET_QUOTE command is backwards >> compatible. When receives flags=0 from vTPM it extends additional >> information into the PCRs as it did before. >> > > Even without extending values into the resettable PCRs, the PCR > selection for the quote should not be ignored: otherwise, the > measurement of the hypervisor (stored in either PCR 4-5 or PCR 18-19) > cannot be included in a deep quote. Allowing a guest to attest to the > measurement of its hypervisor is one of the major reasons for allowing a > deep quote and is likely to be mandatory in a vTPM provisioning quote. > very good point, I missed that someone would include additional PCRs in the request. > > The backwards compatibility added here has some caveats that need to be > treated carefully. In the current version, it is not possible to > distinguish between a request that has the new externData structure and > a request that uses flags=0 where the vTPM itself has constructed a > requestData value that looks like a valid externData. > > The simplest solution is to always use the structure prepared by the > vTPM manager for externData and remove backwards compatibility from the > series. Since the new quote format would be introduced with a new > version of the vTPM Manager and (likely) a new hypervisor, any support > software that makes use of the quotes can be updated at the same time. > > If backwards compatibility is needed, then there must be a way to > distinguish a new-format quote from an old-format quote. If the reset > of the modified PCRs is moved to the end of the quote operation (instead > of the beginning, as is currently done), the value of PCR 20 will be > at its reset value (either 00..00 or ff..ff) when the new-format quote > is requested. Including the value of PCR 20 in all new-format quotes > would then be sufficient evidence that the externData value in the quote > was generated by the vTPM Manager. > > In addition, it would be useful to add a command-line switch to the vTPM > manager that disables this backwards compatibility mode if a given > system will not be using it: this would avoid issues if the users of > that system have not read this discussion and decide to use quotes that > do not include PCR 20-23 (which is normally a sensible thing to do). > > I think it is reasonable to specify in the documentation the changes and include only the new version. > Flags are interpreted as a bitmask of: >> * VTPM_QUOTE_FLAGS_HASH_UUID >> * VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS >> * VTPM_QUOTE_FLAGS_GROUP_INFO >> When using flags!=0, vtpmmgr ignores quoteSelect and TPM_Quote is >> executed with: >>externData = SHA1( >> flags, >> requestData, >> [UUIDs if requested], >> [vTPM measurements if requested], >> [vTPM group update policy if requested] >>) >> > > This specification does not match what you actually do below. There are > some advantages to doing it the way you have coded, but the method for > calculating the hash needs to be fully documented. > > I will update the documentation: sha1(UUIDs) instead of UUIDs and so on. > Signed-off-by: Emil Condrea >> --- >> > [...] > > diff --git a/stubdom/vtpmmgr/mgmt_authority.c >> b/stubdom/vtpmmgr/mgmt_authority.c >> index 0526a12..0e4aac7 100644 >> --- a/stubdom/vtpmmgr/mgmt_authority.c >> +++ b/stubdom/vtpmmgr/mgmt_authority.c >> @@ -128,6 +128,49 @@ static int do_load_aik(struct mem_group *group, >> TPM_HANDLE *handle) >> return TPM_LoadKey(TPM_SRK_KEYHANDLE, &key, handle, >> (void*)&vtpm_globals.srk_auth, &vtpm_globals.oiap); >> } >> >> +static void do_vtpminfo_hash(uint32_t extra_info_flags,struct mem_group >> *group, >> + const void* uuid, const uint8_t* kern_hash,unsigned char** >> calc_hashes) >> +{ >> + int i; >> + sha1_context ctx; >> + if(extra_info_flags & VTPM_QUOTE_FLAGS_HASH_UUID){ >> + printk("hashing for FLAGS_HASH_UUID: "); >> + if(uuid){ >> + printk("true"); >> + sha1_starts(&ctx); >> + sha1_update(&ctx, (void*)uuid, 16); >> + sha1_finish(&ctx, *calc_hashes); >> + *calc_hashes = *calc_hashes + 20; >> + } >> + printk(&q
[Xen-devel] [PATCH v2 0/2] vtpm deep quote in locality 0
Changes from v1, suggested by Daniel: - flags parameter is now mandatory - updated documentation about externData calculation - constant size for externData structure, perform SHA1 on empty string if requested parameter is NULL - return error if invalid bit is set in flags - added VTPM_QUOTE_FLAGS_GROUP_PUBKEY flag Right now, deep quote functionality is enabled just when vtpm manager is started with locality=2. This requirement is enforced by the current implementation which uses PCRs that can be reset in locality 2: 20,21,22,23. Since some TPM chips do not enable access to other locality than 0 this patch enables the deep quote functionality for vtpm manager started with locality=0. The patches are based on a suggestion given by Daniel De Graaf in another thread on the list: - Add a field to the request - extraInfoFlags - Compute externData = SHA1 ( extraInfoFlags requestData [SHA1 ( [SHA1 (UUIDs if requested)] [SHA1 (vTPM measurements if requested)] [SHA1 (vTPM group update policy if requested)] [SHA1 (vTPM group public key if requested)] ) if flags !=0 ] ) - Perform deep quotes using the above externData value instead of the value provided by the vTPM. Embedding additional data in externData is equivalently secure as extending it into PCRs. This change also has the benefit of increasing the flexibility of the request. It is simple to define additional flags and add data to the hash if needed. Emil Condrea (2): vtpm: deep quote flags vtpmmgr: execute deep quote in locality 0 stubdom/Makefile| 1 + stubdom/vtpm-deepquote-anyloc.patch | 127 stubdom/vtpm/vtpm_cmd.c | 13 ++-- stubdom/vtpmmgr/marshal.h | 1 + stubdom/vtpmmgr/mgmt_authority.c| 91 +++--- stubdom/vtpmmgr/mgmt_authority.h| 2 +- stubdom/vtpmmgr/vtpm_cmd_handler.c | 7 +- stubdom/vtpmmgr/vtpm_manager.h | 27 +++- 8 files changed, 250 insertions(+), 19 deletions(-) create mode 100644 stubdom/vtpm-deepquote-anyloc.patch -- 2.1.0 ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
[Xen-devel] [PATCH v2 1/2] vtpm: deep quote flags
Currently, the flags are not interpreted by vTPM. They are just packed and sent to vtpmmgr. Signed-off-by: Emil Condrea --- stubdom/Makefile| 1 + stubdom/vtpm-deepquote-anyloc.patch | 127 stubdom/vtpm/vtpm_cmd.c | 13 ++-- 3 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 stubdom/vtpm-deepquote-anyloc.patch diff --git a/stubdom/Makefile b/stubdom/Makefile index 8fb885a..c135334 100644 --- a/stubdom/Makefile +++ b/stubdom/Makefile @@ -211,6 +211,7 @@ tpm_emulator-$(XEN_TARGET_ARCH): tpm_emulator-$(TPMEMU_VERSION).tar.gz patch -d $@ -p1 < vtpm-locality.patch patch -d $@ -p1 < vtpm-parent-sign-ek.patch patch -d $@ -p1 < vtpm-deepquote.patch + patch -d $@ -p1 < vtpm-deepquote-anyloc.patch patch -d $@ -p1 < vtpm-cmake-Wextra.patch mkdir $@/build cd $@/build; CC=${CC} $(CMAKE) .. -DCMAKE_C_FLAGS:STRING="-std=c99 -DTPM_NO_EXTERN $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-declaration-after-statement" diff --git a/stubdom/vtpm-deepquote-anyloc.patch b/stubdom/vtpm-deepquote-anyloc.patch new file mode 100644 index 000..13b00d8 --- /dev/null +++ b/stubdom/vtpm-deepquote-anyloc.patch @@ -0,0 +1,127 @@ +diff --git a/tpm/tpm_cmd_handler.c b/tpm/tpm_cmd_handler.c +index 69511d1..7545d51 100644 +--- a/tpm/tpm_cmd_handler.c b/tpm/tpm_cmd_handler.c +@@ -3347,12 +3347,13 @@ static TPM_RESULT execute_TPM_DeepQuote(TPM_REQUEST *req, TPM_RESPONSE *rsp) + { + TPM_NONCE nonce; + TPM_RESULT res; +- UINT32 sigSize; +- BYTE *sig; ++ UINT32 quote_blob_size; ++ BYTE *quote_blob; + BYTE *ptr; + UINT32 len; + TPM_PCR_SELECTION myPCR; + TPM_PCR_SELECTION ptPCR; ++ UINT32 extraInfoFlags = 0; + + tpm_compute_in_param_digest(req); + +@@ -3361,17 +3362,19 @@ static TPM_RESULT execute_TPM_DeepQuote(TPM_REQUEST *req, TPM_RESPONSE *rsp) + if (tpm_unmarshal_TPM_NONCE(&ptr, &len, &nonce) + || tpm_unmarshal_TPM_PCR_SELECTION(&ptr, &len, &myPCR) + || tpm_unmarshal_TPM_PCR_SELECTION(&ptr, &len, &ptPCR) ++ || tpm_unmarshal_TPM_DEEP_QUOTE_INFO(&ptr, &len, &extraInfoFlags)) + || len != 0) return TPM_BAD_PARAMETER; + +- res = TPM_DeepQuote(&nonce, &myPCR, &ptPCR, &req->auth1, &sigSize, &sig); ++ res = TPM_DeepQuote(&nonce, &myPCR, &ptPCR, &req->auth1, extraInfoFlags, ++ "e_blob_size, "e_blob); + if (res != TPM_SUCCESS) return res; +- rsp->paramSize = len = sigSize; ++ rsp->paramSize = len = quote_blob_size; + rsp->param = ptr = tpm_malloc(len); +- if (ptr == NULL || tpm_marshal_BLOB(&ptr, &len, sig, sigSize)) { ++ if (ptr == NULL || tpm_marshal_BLOB(&ptr, &len, quote_blob, quote_blob_size)) { + tpm_free(rsp->param); + res = TPM_FAIL; + } +- tpm_free(sig); ++ tpm_free(quote_blob); + + return res; + } +diff --git a/tpm/tpm_commands.h b/tpm/tpm_commands.h +index 328d1be..a56dd5f 100644 +--- a/tpm/tpm_commands.h b/tpm/tpm_commands.h +@@ -3077,6 +3077,7 @@ TPM_RESULT TPM_ParentSignEK( + * @myPCR: [in] PCR selection for the virtual TPM + * @ptPCR: [in] PCR selection for the hardware TPM + * @auth1: [in, out] Authorization protocol parameters ++ * @extraInfoFlags [in] Flags for including, kernel hash, group info, etc + * @sigSize: [out] The length of the returned digital signature + * @sig: [out] The resulting digital signature and PCR values + * Returns: TPM_SUCCESS on success, a TPM error code otherwise. +@@ -3086,6 +3087,7 @@ TPM_RESULT TPM_DeepQuote( + TPM_PCR_SELECTION *myPCR, + TPM_PCR_SELECTION *ptPCR, + TPM_AUTH *auth1, ++ UINT32 extraInfoFlags, + UINT32 *sigSize, + BYTE **sig + ); +diff --git a/tpm/tpm_credentials.c b/tpm/tpm_credentials.c +index c0d62e7..6586c22 100644 +--- a/tpm/tpm_credentials.c b/tpm/tpm_credentials.c +@@ -183,7 +183,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_KEY_HANDLE keyHandle, TPM_AUTH *auth1, + + int endorsementKeyFresh = 0; + +-TPM_RESULT VTPM_GetParentQuote(TPM_DIGEST* data, TPM_PCR_SELECTION *sel, UINT32 *sigSize, BYTE **sig); ++TPM_RESULT VTPM_GetParentQuote(TPM_NONCE *data, TPM_PCR_SELECTION *sel, ++ UINT32 extraInfoFlags, UINT32 *sigSize, BYTE **sig); + + TPM_RESULT TPM_ParentSignEK(TPM_NONCE *externalData, TPM_PCR_SELECTION *sel, + TPM_AUTH *auth1, UINT32 *sigSize, BYTE **sig) +@@ -191,7 +192,7 @@ TPM_RESULT TPM_ParentSignEK(TPM_NONCE *externalData, TPM_PCR_SELECTION *sel, + TPM_PUBKEY pubKey; + TPM_RESULT res; + TPM_DIGEST hres; +- ++ UINT32 extraInfoFlags = 0; + info("TPM_ParentSignEK()"); + + res = tpm
[Xen-devel] [PATCH v2 2/2] vtpmmgr: execute deep quote in locality 0
Enables deep quote execution for vtpmmgr which can not be started using locality 2. Flags are used to request additional data to be present when executing quote. They are interpreted as a bitmask of: * VTPM_QUOTE_FLAGS_HASH_UUID * VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS * VTPM_QUOTE_FLAGS_GROUP_INFO * VTPM_QUOTE_FLAGS_GROUP_PUBKEY The externData param for TPM_Quote is calculated as: externData = SHA1 ( extraInfoFlags requestData [SHA1 ( [SHA1 (UUIDs if requested)] [SHA1 (vTPM measurements if requested)] [SHA1 (vTPM group update policy if requested)] [SHA1 (vTPM group public key if requested)] ) if flags !=0 ] ) The response param pcrValues is an array containing requested hashes used for externData calculation : UUIDs, vTPM measurements, vTPM group update policy, group public key. At the end of these hashes the PCR values are appended. Signed-off-by: Emil Condrea --- stubdom/vtpmmgr/marshal.h | 1 + stubdom/vtpmmgr/mgmt_authority.c | 91 ++ stubdom/vtpmmgr/mgmt_authority.h | 2 +- stubdom/vtpmmgr/vtpm_cmd_handler.c | 7 ++- stubdom/vtpmmgr/vtpm_manager.h | 27 ++- 5 files changed, 115 insertions(+), 13 deletions(-) diff --git a/stubdom/vtpmmgr/marshal.h b/stubdom/vtpmmgr/marshal.h index bcc7c46..d826f19 100644 --- a/stubdom/vtpmmgr/marshal.h +++ b/stubdom/vtpmmgr/marshal.h @@ -195,6 +195,7 @@ inline int unpack3_UINT32(BYTE* ptr, UINT32* pos, UINT32 max, UINT32 *t) #define unpack3_TPM_PHYSICAL_PRESENCE(p, l, m, t) unpack3_UINT16(p, l, m, t) #define unpack3_TPM_KEY_FLAGS(p, l, m, t) unpack3_UINT32(p, l, m, t) #define unpack3_TPM_LOCALITY_SELECTION(p, l, m, t) unpack3_BYTE(p, l, m, t) +#define unpack3_TPM_DEEP_QUOTE_INFO(p, l, m, t) unpack3_UINT32(p, l, m, t) #define sizeof_TPM_RESULT(t) sizeof_UINT32(t) #define sizeof_TPM_PCRINDEX(t) sizeof_UINT32(t) diff --git a/stubdom/vtpmmgr/mgmt_authority.c b/stubdom/vtpmmgr/mgmt_authority.c index 0526a12..b839a20 100644 --- a/stubdom/vtpmmgr/mgmt_authority.c +++ b/stubdom/vtpmmgr/mgmt_authority.c @@ -128,6 +128,55 @@ static int do_load_aik(struct mem_group *group, TPM_HANDLE *handle) return TPM_LoadKey(TPM_SRK_KEYHANDLE, &key, handle, (void*)&vtpm_globals.srk_auth, &vtpm_globals.oiap); } +static void do_vtpminfo_hash(uint32_t extra_info_flags,struct mem_group *group, + const void* uuid, const uint8_t* kern_hash,unsigned char** calc_hashes) +{ + int i; + sha1_context ctx; + if(extra_info_flags & VTPM_QUOTE_FLAGS_HASH_UUID){ + printk("hashing for FLAGS_HASH_UUID: "); + sha1_starts(&ctx); + if(uuid){ + printk("true"); + sha1_update(&ctx, (void*)uuid, 16); + } + sha1_finish(&ctx, *calc_hashes); + *calc_hashes = *calc_hashes + 20; + printk("\n"); + } + if(extra_info_flags & VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS){ + printk("hashing for VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS: "); + sha1_starts(&ctx); + if(kern_hash){ + printk("true"); + sha1_update(&ctx, (void*)kern_hash, 20); + } + sha1_finish(&ctx, *calc_hashes); + *calc_hashes = *calc_hashes + 20; + printk("\n"); + } + if(extra_info_flags & VTPM_QUOTE_FLAGS_GROUP_INFO){ + printk("hashing for VTPM_QUOTE_FLAGS_GROUP_INFO: true\n"); + sha1_starts(&ctx); + sha1_update(&ctx, (void*)&group->id_data.saa_pubkey, sizeof(group->id_data.saa_pubkey)); + sha1_update(&ctx, (void*)&group->details.cfg_seq, 8); + sha1_update(&ctx, (void*)&group->seal_bits.nr_cfgs, 4); + for(i=0; i < group->nr_seals; i++) + sha1_update(&ctx, (void*)&group->seals[i].digest_release, 20); + sha1_update(&ctx, (void*)&group->seal_bits.nr_kerns, 4); + sha1_update(&ctx, (void*)&group->seal_bits.kernels, 20 * be32_native(group->seal_bits.nr_kerns)); + sha1_finish(&ctx, *calc_hashes); + *calc_hashes = *calc_hashes + 20; + } + if(extra_info_flags & VTPM_QUOTE_FLAGS_GROUP_PUBKEY){ + printk("hashing for VTPM_QUOTE_FLAGS_GROUP_PUBKEY: true\n"); + sha1_starts(&ctx); + sha1_update(&ctx, (void*)&group->id_data.saa_pubkey, sizeof(group->id_data.saa_pubkey)); + sha1_finish(&ctx, *calc_hashes); + *calc_hashes = *calc_hashes + 20; + } +} + /* * Sets up resettable PCRs for a vTPM deep quote request */ @@ -273,18
Re: [Xen-devel] [PATCH v2 1/2] vtpm: deep quote flags
Thanks! Should it remove it and resend the patches ? On Wed, Apr 15, 2015 at 6:07 PM, Daniel De Graaf wrote: > On 04/14/2015 05:08 AM, Emil Condrea wrote: > >> Currently, the flags are not interpreted by vTPM. They are just >> packed and sent to vtpmmgr. >> >> Signed-off-by: Emil Condrea >> > > Acked-by: Daniel De Graaf > > [...] > >> +- res = TPM_DeepQuote(&nonce, &myPCR, &ptPCR, &req->auth1, >> &sigSize, &sig); >> ++ res = TPM_DeepQuote(&nonce, &myPCR, &ptPCR, &req->auth1, >> extraInfoFlags, >> ++ "e_blob_size, "e_blob); >> + if (res != TPM_SUCCESS) return res; >> +- rsp->paramSize = len = sigSize; >> ++ rsp->paramSize = len = quote_blob_size; >> > > There's an extra tab at the start of this line. > > -- > Daniel De Graaf > National Security Agency > ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH v2 1/2] vtpm: deep quote flags
Strangely! Of course that I compiled it but it seems that a rebuild was needed in order to reapply the patch for the tpm emulator. I will do both changes. After rebuilding vtpmmgr and vtpm I will resend the patches. On Wed, Apr 15, 2015 at 6:50 PM, Ian Campbell wrote: > On Wed, 2015-04-15 at 16:34 +0100, Ian Campbell wrote: > > On Wed, 2015-04-15 at 18:09 +0300, Emil Condrea wrote: > > > Thanks! Should it remove it and resend the patches ? > > > > I'll do it on commit (which I'm about to do). > > Except: > stubdom/tpm_emulator-x86_64/tpm/tpm_cmd_handler.c: In function > ‘execute_TPM_DeepQuote’: > stubdom/tpm_emulator-x86_64/tpm/tpm_cmd_handler.c:3366:3: error: expected > expression before ‘||’ token > stubdom/tpm_emulator-x86_64/tpm/tpm_cmd_handler.c:3366:14: error: expected > statement before ‘)’ token > > Same on i386. I think there is an extra ) On the previous line. Did you > compile test this? > > In any case I will now await v3. > > Ian. > > ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
[Xen-devel] [PATCH v3 0/2] vtpm deep quote in locality 0
Changes from v2: - removed useless whitespace - fixed compiling issues for tpm emulator Changes from v1, suggested by Daniel: - flags parameter is now mandatory - updated documentation about externData calculation - constant size for externData structure, perform SHA1 on empty string if requested parameter is NULL - return error if invalid bit is set in flags - added VTPM_QUOTE_FLAGS_GROUP_PUBKEY flag Right now, deep quote functionality is enabled just when vtpm manager is started with locality=2. This requirement is enforced by the current implementation which uses PCRs that can be reset in locality 2: 20,21,22,23. Since some TPM chips do not enable access to other locality than 0 this patch enables the deep quote functionality for vtpm manager started with locality=0. The patches are based on a suggestion given by Daniel De Graaf in another thread on the list: - Add a field to the request - extraInfoFlags - Compute externData = SHA1 ( extraInfoFlags requestData [SHA1 ( [SHA1 (UUIDs if requested)] [SHA1 (vTPM measurements if requested)] [SHA1 (vTPM group update policy if requested)] [SHA1 (vTPM group public key if requested)] ) if flags !=0 ] ) - Perform deep quotes using the above externData value instead of the value provided by the vTPM. Embedding additional data in externData is equivalently secure as extending it into PCRs. This change also has the benefit of increasing the flexibility of the request. It is simple to define additional flags and add data to the hash if needed. Emil Condrea (2): vtpm: deep quote flags vtpmmgr: execute deep quote in locality 0 stubdom/Makefile| 1 + stubdom/vtpm-deepquote-anyloc.patch | 127 stubdom/vtpm/vtpm_cmd.c | 13 ++-- stubdom/vtpmmgr/marshal.h | 1 + stubdom/vtpmmgr/mgmt_authority.c| 91 +++--- stubdom/vtpmmgr/mgmt_authority.h| 2 +- stubdom/vtpmmgr/vtpm_cmd_handler.c | 7 +- stubdom/vtpmmgr/vtpm_manager.h | 27 +++- 8 files changed, 250 insertions(+), 19 deletions(-) create mode 100644 stubdom/vtpm-deepquote-anyloc.patch -- 2.1.0 ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
[Xen-devel] [PATCH v3 1/2] vtpm: deep quote flags
Currently, the flags are not interpreted by vTPM. They are just packed and sent to vtpmmgr. Signed-off-by: Emil Condrea Acked-by: Daniel De Graaf --- stubdom/Makefile| 1 + stubdom/vtpm-deepquote-anyloc.patch | 127 stubdom/vtpm/vtpm_cmd.c | 13 ++-- 3 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 stubdom/vtpm-deepquote-anyloc.patch diff --git a/stubdom/Makefile b/stubdom/Makefile index 8fb885a..c135334 100644 --- a/stubdom/Makefile +++ b/stubdom/Makefile @@ -211,6 +211,7 @@ tpm_emulator-$(XEN_TARGET_ARCH): tpm_emulator-$(TPMEMU_VERSION).tar.gz patch -d $@ -p1 < vtpm-locality.patch patch -d $@ -p1 < vtpm-parent-sign-ek.patch patch -d $@ -p1 < vtpm-deepquote.patch + patch -d $@ -p1 < vtpm-deepquote-anyloc.patch patch -d $@ -p1 < vtpm-cmake-Wextra.patch mkdir $@/build cd $@/build; CC=${CC} $(CMAKE) .. -DCMAKE_C_FLAGS:STRING="-std=c99 -DTPM_NO_EXTERN $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-declaration-after-statement" diff --git a/stubdom/vtpm-deepquote-anyloc.patch b/stubdom/vtpm-deepquote-anyloc.patch new file mode 100644 index 000..13b00d8 --- /dev/null +++ b/stubdom/vtpm-deepquote-anyloc.patch @@ -0,0 +1,127 @@ +diff --git a/tpm/tpm_cmd_handler.c b/tpm/tpm_cmd_handler.c +index 69511d1..7545d51 100644 +--- a/tpm/tpm_cmd_handler.c b/tpm/tpm_cmd_handler.c +@@ -3347,12 +3347,13 @@ static TPM_RESULT execute_TPM_DeepQuote(TPM_REQUEST *req, TPM_RESPONSE *rsp) + { + TPM_NONCE nonce; + TPM_RESULT res; +- UINT32 sigSize; +- BYTE *sig; ++ UINT32 quote_blob_size; ++ BYTE *quote_blob; + BYTE *ptr; + UINT32 len; + TPM_PCR_SELECTION myPCR; + TPM_PCR_SELECTION ptPCR; ++ UINT32 extraInfoFlags = 0; + + tpm_compute_in_param_digest(req); + +@@ -3361,17 +3362,19 @@ static TPM_RESULT execute_TPM_DeepQuote(TPM_REQUEST *req, TPM_RESPONSE *rsp) + if (tpm_unmarshal_TPM_NONCE(&ptr, &len, &nonce) + || tpm_unmarshal_TPM_PCR_SELECTION(&ptr, &len, &myPCR) + || tpm_unmarshal_TPM_PCR_SELECTION(&ptr, &len, &ptPCR) ++ || tpm_unmarshal_TPM_DEEP_QUOTE_INFO(&ptr, &len, &extraInfoFlags) + || len != 0) return TPM_BAD_PARAMETER; + +- res = TPM_DeepQuote(&nonce, &myPCR, &ptPCR, &req->auth1, &sigSize, &sig); ++ res = TPM_DeepQuote(&nonce, &myPCR, &ptPCR, &req->auth1, extraInfoFlags, ++ "e_blob_size, "e_blob); + if (res != TPM_SUCCESS) return res; +- rsp->paramSize = len = sigSize; ++ rsp->paramSize = len = quote_blob_size; + rsp->param = ptr = tpm_malloc(len); +- if (ptr == NULL || tpm_marshal_BLOB(&ptr, &len, sig, sigSize)) { ++ if (ptr == NULL || tpm_marshal_BLOB(&ptr, &len, quote_blob, quote_blob_size)) { + tpm_free(rsp->param); + res = TPM_FAIL; + } +- tpm_free(sig); ++ tpm_free(quote_blob); + + return res; + } +diff --git a/tpm/tpm_commands.h b/tpm/tpm_commands.h +index 328d1be..a56dd5f 100644 +--- a/tpm/tpm_commands.h b/tpm/tpm_commands.h +@@ -3077,6 +3077,7 @@ TPM_RESULT TPM_ParentSignEK( + * @myPCR: [in] PCR selection for the virtual TPM + * @ptPCR: [in] PCR selection for the hardware TPM + * @auth1: [in, out] Authorization protocol parameters ++ * @extraInfoFlags [in] Flags for including, kernel hash, group info, etc + * @sigSize: [out] The length of the returned digital signature + * @sig: [out] The resulting digital signature and PCR values + * Returns: TPM_SUCCESS on success, a TPM error code otherwise. +@@ -3086,6 +3087,7 @@ TPM_RESULT TPM_DeepQuote( + TPM_PCR_SELECTION *myPCR, + TPM_PCR_SELECTION *ptPCR, + TPM_AUTH *auth1, ++ UINT32 extraInfoFlags, + UINT32 *sigSize, + BYTE **sig + ); +diff --git a/tpm/tpm_credentials.c b/tpm/tpm_credentials.c +index c0d62e7..6586c22 100644 +--- a/tpm/tpm_credentials.c b/tpm/tpm_credentials.c +@@ -183,7 +183,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_KEY_HANDLE keyHandle, TPM_AUTH *auth1, + + int endorsementKeyFresh = 0; + +-TPM_RESULT VTPM_GetParentQuote(TPM_DIGEST* data, TPM_PCR_SELECTION *sel, UINT32 *sigSize, BYTE **sig); ++TPM_RESULT VTPM_GetParentQuote(TPM_NONCE *data, TPM_PCR_SELECTION *sel, ++ UINT32 extraInfoFlags, UINT32 *sigSize, BYTE **sig); + + TPM_RESULT TPM_ParentSignEK(TPM_NONCE *externalData, TPM_PCR_SELECTION *sel, + TPM_AUTH *auth1, UINT32 *sigSize, BYTE **sig) +@@ -191,7 +192,7 @@ TPM_RESULT TPM_ParentSignEK(TPM_NONCE *externalData, TPM_PCR_SELECTION *sel, + TPM_PUBKEY pubKey; + TPM_RESULT res; + TPM_DIGEST hres; +- ++ UINT32 extraInfoFlags = 0; + info("TPM_ParentSignEK()"); + + res
[Xen-devel] [PATCH v3 2/2] vtpmmgr: execute deep quote in locality 0
Enables deep quote execution for vtpmmgr which can not be started using locality 2. Flags are used to request additional data to be present when executing quote. They are interpreted as a bitmask of: * VTPM_QUOTE_FLAGS_HASH_UUID * VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS * VTPM_QUOTE_FLAGS_GROUP_INFO * VTPM_QUOTE_FLAGS_GROUP_PUBKEY The externData param for TPM_Quote is calculated as: externData = SHA1 ( extraInfoFlags requestData [SHA1 ( [SHA1 (UUIDs if requested)] [SHA1 (vTPM measurements if requested)] [SHA1 (vTPM group update policy if requested)] [SHA1 (vTPM group public key if requested)] ) if flags !=0 ] ) The response param pcrValues is an array containing requested hashes used for externData calculation : UUIDs, vTPM measurements, vTPM group update policy, group public key. At the end of these hashes the PCR values are appended. Signed-off-by: Emil Condrea Acked-by: Daniel De Graaf --- stubdom/vtpmmgr/marshal.h | 1 + stubdom/vtpmmgr/mgmt_authority.c | 91 ++ stubdom/vtpmmgr/mgmt_authority.h | 2 +- stubdom/vtpmmgr/vtpm_cmd_handler.c | 7 ++- stubdom/vtpmmgr/vtpm_manager.h | 27 ++- 5 files changed, 115 insertions(+), 13 deletions(-) diff --git a/stubdom/vtpmmgr/marshal.h b/stubdom/vtpmmgr/marshal.h index bcc7c46..d826f19 100644 --- a/stubdom/vtpmmgr/marshal.h +++ b/stubdom/vtpmmgr/marshal.h @@ -195,6 +195,7 @@ inline int unpack3_UINT32(BYTE* ptr, UINT32* pos, UINT32 max, UINT32 *t) #define unpack3_TPM_PHYSICAL_PRESENCE(p, l, m, t) unpack3_UINT16(p, l, m, t) #define unpack3_TPM_KEY_FLAGS(p, l, m, t) unpack3_UINT32(p, l, m, t) #define unpack3_TPM_LOCALITY_SELECTION(p, l, m, t) unpack3_BYTE(p, l, m, t) +#define unpack3_TPM_DEEP_QUOTE_INFO(p, l, m, t) unpack3_UINT32(p, l, m, t) #define sizeof_TPM_RESULT(t) sizeof_UINT32(t) #define sizeof_TPM_PCRINDEX(t) sizeof_UINT32(t) diff --git a/stubdom/vtpmmgr/mgmt_authority.c b/stubdom/vtpmmgr/mgmt_authority.c index 0526a12..b839a20 100644 --- a/stubdom/vtpmmgr/mgmt_authority.c +++ b/stubdom/vtpmmgr/mgmt_authority.c @@ -128,6 +128,55 @@ static int do_load_aik(struct mem_group *group, TPM_HANDLE *handle) return TPM_LoadKey(TPM_SRK_KEYHANDLE, &key, handle, (void*)&vtpm_globals.srk_auth, &vtpm_globals.oiap); } +static void do_vtpminfo_hash(uint32_t extra_info_flags,struct mem_group *group, + const void* uuid, const uint8_t* kern_hash,unsigned char** calc_hashes) +{ + int i; + sha1_context ctx; + if(extra_info_flags & VTPM_QUOTE_FLAGS_HASH_UUID){ + printk("hashing for FLAGS_HASH_UUID: "); + sha1_starts(&ctx); + if(uuid){ + printk("true"); + sha1_update(&ctx, (void*)uuid, 16); + } + sha1_finish(&ctx, *calc_hashes); + *calc_hashes = *calc_hashes + 20; + printk("\n"); + } + if(extra_info_flags & VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS){ + printk("hashing for VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS: "); + sha1_starts(&ctx); + if(kern_hash){ + printk("true"); + sha1_update(&ctx, (void*)kern_hash, 20); + } + sha1_finish(&ctx, *calc_hashes); + *calc_hashes = *calc_hashes + 20; + printk("\n"); + } + if(extra_info_flags & VTPM_QUOTE_FLAGS_GROUP_INFO){ + printk("hashing for VTPM_QUOTE_FLAGS_GROUP_INFO: true\n"); + sha1_starts(&ctx); + sha1_update(&ctx, (void*)&group->id_data.saa_pubkey, sizeof(group->id_data.saa_pubkey)); + sha1_update(&ctx, (void*)&group->details.cfg_seq, 8); + sha1_update(&ctx, (void*)&group->seal_bits.nr_cfgs, 4); + for(i=0; i < group->nr_seals; i++) + sha1_update(&ctx, (void*)&group->seals[i].digest_release, 20); + sha1_update(&ctx, (void*)&group->seal_bits.nr_kerns, 4); + sha1_update(&ctx, (void*)&group->seal_bits.kernels, 20 * be32_native(group->seal_bits.nr_kerns)); + sha1_finish(&ctx, *calc_hashes); + *calc_hashes = *calc_hashes + 20; + } + if(extra_info_flags & VTPM_QUOTE_FLAGS_GROUP_PUBKEY){ + printk("hashing for VTPM_QUOTE_FLAGS_GROUP_PUBKEY: true\n"); + sha1_starts(&ctx); + sha1_update(&ctx, (void*)&group->id_data.saa_pubkey, sizeof(group->id_data.saa_pubkey)); + sha1_finish(&ctx, *calc_hashes); + *calc_hashes = *calc_hashes + 20; + } +} + /* * Sets up resettable PCRs for a vTPM deep
Re: [Xen-devel] [PATCH v3 0/2] vtpm deep quote in locality 0
Thank you! On Thu, Apr 16, 2015 at 5:10 PM, Ian Campbell wrote: > On Wed, 2015-04-15 at 21:00 +0300, Emil Condrea wrote: > > Changes from v2: > > - removed useless whitespace > > - fixed compiling issues for tpm emulator > > Applied, thanks. > > > ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Re: [Xen-devel] vtpmmgr bug: fails to start if locality!=0
I modified linux kernel tpm_tis driver to try to start with locality 2. I did some logging and after taking a look with dmesg it seems that the IO pages for other localities are full with 1. in tpm_tis_init: for(i=0;i<5;i++){ release_locality(chip,i,1); } ... wait_startup(chip,2); request_locality(chip,2) ... TPM_RID(2);//FF TPM_RID(0);//64 Would this mean that Atmel disabled other localities after manufacturing? I tried to define a NVRAM index at F200 but I have the same results. I see what you mean about changing the DeepQuote behaviour in order to provide evidence of the VM launch but I am not sure that I understand what is the type of extraInfoFlags and what should it contain. Will the UUIDs and vTPM measurements be stored in extraInfoFlags? If we take this as a solution for systems that do not support DRTM lanch, they will still be forced to use locality 0 if any other is disabled and the TPM might return busy if other commands are currently running. Thanks. Emil Condrea On Sat, Nov 8, 2014 at 1:31 AM, Daniel De Graaf wrote: > On 11/07/2014 05:40 AM, Emil Condrea wrote: > >> My system does not support DRTM so I can not test this. I am interested in >> contributing to vtpm and making this to work without DRTM, can you give me >> more details about PCRs that need to be implemented using an alternate >> manner? When someone wants to use other locality than 0 it will run all >> commands with PCRs disabled? Since the vtpmmgr is tying domU to hardware >> TPM, deactivating PCRs will result that all commands issued by domU will >> not use PCRs anymore, right? >> > > The PCRs seen by the domU are emulated by the vTPM, and the vTPM Manager > has no information on any of their values or updates. Deep quotes may > include a hash of the vTPM's PCR values, but the vTPM Manager is only > asserting that the hash was given by the vTPM. > > Where should the new layer of PCR values stored? NVRAM ? >> > > They will be stored in the vtpmmgr domain's RAM; in fact, they are already > stored there (they just need to be used more directly). > > The PCRs in question are PCR 20-23, used by the vTPM Manager to store > information about the vTPM making a deep quote request. In order to > support more than one vTPM, the values of these PCRs need to be reset when > a different client connects. However, the reset operation for PCR 20-22 is > limited to locality 2. > > An alternative to this is to embed this information in the externData > field that is signed by the quote operation. This requires a bit more work > to provide the same flexibility that the PCRs provided, but it can be made > equivalently secure. > > A deep quote request currently contains a PCR mask and a requestData value > (20 bytes) from the vTPM. On a deep quote request, the vTPM Manager: > 1. Reset PCR 20-23 > 2. Extend information about the requesting vTPM to PCR 20-23 >- Different information is extended into each PCR >- Some clients want all information, some only want selected PCRs > 3. Perform a Quote with externData=requestData on the requested PCRs > 4. Return the result to the requesting vTPM > > The change I am suggesting requires: > - Add a field to the request - extraInfoFlags > - Compute externData = SHA1 ( > requestData > extraInfoFlags > [UUIDs if requested] > [vTPM measurements if requested] > [vTPM group update policy if requested] > ) > - Perform deep quotes using the above externData value instead of the > value provided by the vTPM. > > This change also has the benefit of increasing the flexibility of the > request - it is simple to define additional flags and add data to the hash > if needed. > > > On Thu, Nov 6, 2014 at 11:55 PM, Daniel De Graaf >> wrote: >> >> On 11/05/2014 05:00 AM, Ian Campbell wrote: >>> >>> CCing Daniel. >>>> >>>> On Fri, 2014-10-31 at 17:37 +0200, Emil Condrea wrote: >>>> >>>> >>>>> I am wondering if this is known issue that when I set locality!=0 to >>>>> vtpmmgr it does not start. It is a bit strange that every call to >>>>> tpm_tis_status returns 255 and device-id is also : >>>>> 1.2 TPM (device-id=0x vendor-id = rev-id = FF). >>>>> TPM interface capabilities (0x): >>>>> >>>>> I am configuring vtpmmgr using: >>>>> >>>>> kernel="/usr/local/lib/xen/boot/vtpmmgr-stubdom.gz" >>>>> memory=8 >>>>> disk=["file:/var/vtpmmgr-stubdom.img,hda,w"] >>>>> name="vtpmmgr" >>>>> iomem=["fed40,5"] >>&g
Re: [Xen-devel] vtpmmgr bug: fails to start if locality!=0
It seems that tpm_tis_request_locality did not manage to wait enough for locality change. I suspect that if timeout_a does not have correct value it will not wait enough in that loop and it will exit too soon. Can you do this test again replacing timeout_a value from tpm_tis_request_locality =>(stop = NOW() + tpm->timeout_a;) with something much bigger? I sent a patch that was committed this week, that fixes timeout problems that could appear and resets them to the standard value if they are incorrect. At least it seems that the locality 2 on your chip is enabled since you got here. Thanks. Emil Condrea On Sun, Nov 16, 2014 at 9:15 AM, Xu, Quan wrote: > Emil / Graaf, > I have verified it, it is still not working when tboot is enabled. > The attach file is txt-stat log. > [...] > > *** > TXT measured launch: TRUE > secrets flag set: TRUE > *** > [...] > > > Below is error when I boot vtpmmgr: > > > ** > [...] > IOMEM Machine Base Address: FED4 > Enabled Localities: 2 > REQ LOCALITY FAILURE > Unable to request locality 2?? > Shutting down tpm_tis device > Page fault at linear address 0xfed40008, rip 0x2f918, regs 0x10fc78, sp > 0x10fd20, our_sp 0x10fc40, code 2 > Thread: main > RIP: e030:[<0002f918>] > RSP: e02b:0010fd20 EFLAGS: 00010202 > RAX: RBX: 002000804c60 RCX: 072c > RDX: 001e RSI: 7fff RDI: fed40008 > RBP: 0010fd20 R08: 000a R09: 000af000 > R10: 070e R11: 06d8 R12: 002000804c60 > R13: fed42000 R14: R15: 0002 > base is 0x10fd20 caller is 0x24977 > base is 0x10fd40 caller is 0x24e32 > base is 0x10fd80 caller is 0x5b4b > base is 0x10ff30 caller is 0x3510 > base is 0x10ff50 caller is 0x287a2 > base is 0x10ffe0 caller is 0x343b > > 10fd10: 20 fd 10 00 00 00 00 00 2b e0 00 00 00 00 00 00 > 10fd20: 40 fd 10 00 00 00 00 00 77 49 02 00 00 00 00 00 > 10fd30: 60 4c 80 00 20 00 00 00 02 00 00 00 00 00 00 00 > 10fd40: 80 fd 10 00 00 00 00 00 32 4e 02 00 00 00 00 00 > > 10fd10: 20 fd 10 00 00 00 00 00 2b e0 00 00 00 00 00 00 > 10fd20: 40 fd 10 00 00 00 00 00 77 49 02 00 00 00 00 00 > 10fd30: 60 4c 80 00 20 00 00 00 02 00 00 00 00 00 00 00 > 10fd40: 80 fd 10 00 00 00 00 00 32 4e 02 00 00 00 00 00 > > 2f900: 5d c3 55 48 89 e5 40 88 37 5d c3 55 48 89 e5 66 > 2f910: 89 37 5d c3 55 48 89 e5 89 37 5d c3 55 48 89 e5 > 2f920: 48 89 37 5d c3 55 48 89 e5 0f b6 07 5d c3 55 48 > 2f930: 89 e5 0f b7 07 5d c3 55 48 89 e5 8b 07 5d c3 55 > Pagetable walk from virt fed40008, base b: > L4 = 000127033067 (0xb1000) [offset = 0] > L3 = (0xf000) [offset = 3] > Page fault in pagetable walk (access to invalid memory?). > > > > Thanks > Quan Xu > > > > -Original Message- > > From: xen-devel-boun...@lists.xen.org > > [mailto:xen-devel-boun...@lists.xen.org] On Behalf Of Xu, Quan > > Sent: Sunday, November 09, 2014 4:30 PM > > To: Emil Condrea > > Cc: Daniel De Graaf; Ian Campbell; xen-devel@lists.xen.org > > Subject: Re: [Xen-devel] vtpmmgr bug: fails to start if locality!=0 > > > > Okay, I will test it in next week. > > > > Thanks > > Quan Xu > > > > > > From: xen-devel-boun...@lists.xen.org > > [mailto:xen-devel-boun...@lists.xen.org] On Behalf Of Emil Condrea > > Sent: Friday, November 07, 2014 6:42 PM > > To: Xu, Quan > > Cc: Daniel De Graaf; Ian Campbell; xen-devel@lists.xen.org > > Subject: Re: [Xen-devel] vtpmmgr bug: fails to start if locality!=0 > > > > Xu, my system does not support DRTM launch so if you can test it next > week > > it would be great. > > Thanks > > > > On Fri, Nov 7, 2014 at 3:46 AM, Xu, Quan wrote: > > > > > > > -Original Message- > > > From: xen-devel-boun...@lists.xen.org > > > [mailto:xen-devel-boun...@lists.xen.org] On Behalf Of Daniel De Graaf > > > Sent: Friday, November 07, 2014 5:55 AM > > > To: Emil Condrea > > > Cc: Ian Campbell; xen-devel@lists.xen.org > > > Subject: Re: [Xen-devel] vtpmmgr bug: fails to start if locality!=0 > > > > > > On 11/05/2014 05:00 AM, Ian Campbell wrote: > > > > CCing Daniel. > > > > > > > > On Fri, 2014-10-31 at 17:37 +0200, Emil Condrea wrote: > > > >> > > > >> I am wondering i
[Xen-devel] Fwd: vTPM should be detached after being destroyed
I see that when the vTPM domain is destroyed using xl destroy the advertised info is not removed from xenstore. I don't see a reason for which it should remain there. If something crashes the vTPM it must be destroyed, started again and attached to domU using xl vtpm-attach. The problem is that because the previous vTPM was not removed from xenstore, the new one will be seen different in domU, instead of vtpm0 it will see both vtpm0(unusable) and vtpm1(working). For the moment, doing a vtpm-detach before attaching the new vtpm allows the guest to see the correct vtpm but since vtpm0 will not be usable anymore why not cleaning stuff on destroy? Is there something that I miss? Also, I have some errors while running xl destroy vtpm and maybe this affects correct cleaning: xl -vvv destroy vtpm also warns that backend /local/domain/...vtpm/../state wanted state 6 but it was removed. I see from devstate_watch_callback that this error happens when it could not find some info in the xenstore. It is there a synchronization problem and some xenstore info is deleted too soon and then the destroy operation fails? After this step, the error is sent to the calling functions: libxl_device.c:device_backend_callback: unable to remove device with path /local/domain/...vtpm/58/0 libxl.c:devices_destroy_cb:libxl__devices_destroy failed for 58 What do you think? Is it a good ideea to detach vtpm on destroy? Should I send a patch with the changes? Thanks. Emil Condrea ___ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel