xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [Xen-devel] [PATCH v2 1/2] xen-bus: Fix backend state transition on device reset
       [not found] <20190823101534.465-1-anthony.perard@citrix.com>
@ 2019-08-23 10:15 ` Anthony PERARD
  2019-08-27  9:44   ` Paul Durrant
  2019-08-23 10:15 ` [Xen-devel] [PATCH v2 2/2] xen-bus: Avoid rewriting identical values to xenstore Anthony PERARD
  1 sibling, 1 reply; 4+ messages in thread
From: Anthony PERARD @ 2019-08-23 10:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: Anthony PERARD, xen-devel, Stefano Stabellini, qemu-stable, Paul Durrant

When a frontend wants to reset its state and the backend one, it
starts with setting "Closing", then waits for the backend (QEMU) to do
the same.

But when QEMU is setting "Closing" to its state, it triggers an event
(xenstore watch) that re-execute xen_device_backend_changed() and set
the backend state to "Closed". QEMU should wait for the frontend to
set "Closed" before doing the same.

Before setting "Closed" to the backend_state, we are also going to
check if there is a frontend. If that the case, when the backend state
is set to "Closing" the frontend should react and sets its state to
"Closing" then "Closed". The backend should wait for that to happen.

Fixes: b6af8926fb858c4f1426e5acb2cfc1f0580ec98a
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
Cc: qemu-stable@nongnu.org
---

Notes:
    v2:
    - use a helper
    - Add InitWait and Initialised to the list of active state

 hw/xen/xen-bus.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c
index e40500242d..62c127b926 100644
--- a/hw/xen/xen-bus.c
+++ b/hw/xen/xen-bus.c
@@ -516,6 +516,23 @@ static void xen_device_backend_set_online(XenDevice *xendev, bool online)
     xen_device_backend_printf(xendev, "online", "%u", online);
 }
 
+/*
+ * Tell from the state whether the frontend is likely alive,
+ * i.e. it will react to a change of state of the backend.
+ */
+static bool xen_device_state_is_active(enum xenbus_state state)
+{
+    switch (state) {
+    case XenbusStateInitWait:
+    case XenbusStateInitialised:
+    case XenbusStateConnected:
+    case XenbusStateClosing:
+        return true;
+    default:
+        return false;
+    }
+}
+
 static void xen_device_backend_changed(void *opaque)
 {
     XenDevice *xendev = opaque;
@@ -539,11 +556,11 @@ static void xen_device_backend_changed(void *opaque)
 
     /*
      * If the toolstack (or unplug request callback) has set the backend
-     * state to Closing, but there is no active frontend (i.e. the
-     * state is not Connected) then set the backend state to Closed.
+     * state to Closing, but there is no active frontend then set the
+     * backend state to Closed.
      */
     if (xendev->backend_state == XenbusStateClosing &&
-        xendev->frontend_state != XenbusStateConnected) {
+        !xen_device_state_is_active(state)) {
         xen_device_backend_set_state(xendev, XenbusStateClosed);
     }
 
-- 
Anthony PERARD


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

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

* [Xen-devel] [PATCH v2 2/2] xen-bus: Avoid rewriting identical values to xenstore
       [not found] <20190823101534.465-1-anthony.perard@citrix.com>
  2019-08-23 10:15 ` [Xen-devel] [PATCH v2 1/2] xen-bus: Fix backend state transition on device reset Anthony PERARD
@ 2019-08-23 10:15 ` Anthony PERARD
  2019-08-27  9:46   ` Paul Durrant
  1 sibling, 1 reply; 4+ messages in thread
From: Anthony PERARD @ 2019-08-23 10:15 UTC (permalink / raw)
  To: qemu-devel; +Cc: Anthony PERARD, xen-devel, Stefano Stabellini, Paul Durrant

When QEMU receives a xenstore watch event suggesting that the "state"
of the frontend changed, it records this in its own state but it also
re-write the value back into xenstore even so there were no change.
This triggers an unnecessary xenstore watch event which QEMU will
process again (and maybe the frontend as well). Also QEMU could
potentially write an already old value.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---

Notes:
    v2:
    - fix coding style
    - only change frontend_set_state() and use 'publish' instead of 'export'.

 hw/xen/xen-bus.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c
index 62c127b926..a04478ad4f 100644
--- a/hw/xen/xen-bus.c
+++ b/hw/xen/xen-bus.c
@@ -698,7 +698,8 @@ int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
 }
 
 static void xen_device_frontend_set_state(XenDevice *xendev,
-                                          enum xenbus_state state)
+                                          enum xenbus_state state,
+                                          bool publish)
 {
     const char *type = object_get_typename(OBJECT(xendev));
 
@@ -710,7 +711,9 @@ static void xen_device_frontend_set_state(XenDevice *xendev,
                                     xs_strstate(state));
 
     xendev->frontend_state = state;
-    xen_device_frontend_printf(xendev, "state", "%u", state);
+    if (publish) {
+        xen_device_frontend_printf(xendev, "state", "%u", state);
+    }
 }
 
 static void xen_device_frontend_changed(void *opaque)
@@ -726,7 +729,7 @@ static void xen_device_frontend_changed(void *opaque)
         state = XenbusStateUnknown;
     }
 
-    xen_device_frontend_set_state(xendev, state);
+    xen_device_frontend_set_state(xendev, state, false);
 
     if (state == XenbusStateInitialising &&
         xendev->backend_state == XenbusStateClosed &&
@@ -1169,7 +1172,7 @@ static void xen_device_realize(DeviceState *dev, Error **errp)
     xen_device_frontend_printf(xendev, "backend-id", "%u",
                                xenbus->backend_id);
 
-    xen_device_frontend_set_state(xendev, XenbusStateInitialising);
+    xen_device_frontend_set_state(xendev, XenbusStateInitialising, true);
 
     xendev->exit.notify = xen_device_exit;
     qemu_add_exit_notifier(&xendev->exit);
-- 
Anthony PERARD


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

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

* Re: [Xen-devel] [PATCH v2 1/2] xen-bus: Fix backend state transition on device reset
  2019-08-23 10:15 ` [Xen-devel] [PATCH v2 1/2] xen-bus: Fix backend state transition on device reset Anthony PERARD
@ 2019-08-27  9:44   ` Paul Durrant
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Durrant @ 2019-08-27  9:44 UTC (permalink / raw)
  To: Anthony Perard, qemu-devel
  Cc: Anthony Perard, xen-devel, Stefano Stabellini, qemu-stable

> -----Original Message-----
> From: Anthony PERARD <anthony.perard@citrix.com>
> Sent: 23 August 2019 11:16
> To: qemu-devel@nongnu.org
> Cc: Anthony Perard <anthony.perard@citrix.com>; qemu-stable@nongnu.org; Stefano Stabellini
> <sstabellini@kernel.org>; Paul Durrant <Paul.Durrant@citrix.com>; xen-devel@lists.xenproject.org
> Subject: [PATCH v2 1/2] xen-bus: Fix backend state transition on device reset
> 
> When a frontend wants to reset its state and the backend one, it
> starts with setting "Closing", then waits for the backend (QEMU) to do
> the same.
> 
> But when QEMU is setting "Closing" to its state, it triggers an event
> (xenstore watch) that re-execute xen_device_backend_changed() and set
> the backend state to "Closed". QEMU should wait for the frontend to
> set "Closed" before doing the same.
> 
> Before setting "Closed" to the backend_state, we are also going to
> check if there is a frontend. If that the case, when the backend state
> is set to "Closing" the frontend should react and sets its state to
> "Closing" then "Closed". The backend should wait for that to happen.
> 
> Fixes: b6af8926fb858c4f1426e5acb2cfc1f0580ec98a
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>

Reviewed-by: Paul Durrant <paul.durrant@citrix.com>

> ---
> Cc: qemu-stable@nongnu.org
> ---
> 
> Notes:
>     v2:
>     - use a helper
>     - Add InitWait and Initialised to the list of active state
> 
>  hw/xen/xen-bus.c | 23 ++++++++++++++++++++---
>  1 file changed, 20 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c
> index e40500242d..62c127b926 100644
> --- a/hw/xen/xen-bus.c
> +++ b/hw/xen/xen-bus.c
> @@ -516,6 +516,23 @@ static void xen_device_backend_set_online(XenDevice *xendev, bool online)
>      xen_device_backend_printf(xendev, "online", "%u", online);
>  }
> 
> +/*
> + * Tell from the state whether the frontend is likely alive,
> + * i.e. it will react to a change of state of the backend.
> + */
> +static bool xen_device_state_is_active(enum xenbus_state state)
> +{
> +    switch (state) {
> +    case XenbusStateInitWait:
> +    case XenbusStateInitialised:
> +    case XenbusStateConnected:
> +    case XenbusStateClosing:
> +        return true;
> +    default:
> +        return false;
> +    }
> +}
> +
>  static void xen_device_backend_changed(void *opaque)
>  {
>      XenDevice *xendev = opaque;
> @@ -539,11 +556,11 @@ static void xen_device_backend_changed(void *opaque)
> 
>      /*
>       * If the toolstack (or unplug request callback) has set the backend
> -     * state to Closing, but there is no active frontend (i.e. the
> -     * state is not Connected) then set the backend state to Closed.
> +     * state to Closing, but there is no active frontend then set the
> +     * backend state to Closed.
>       */
>      if (xendev->backend_state == XenbusStateClosing &&
> -        xendev->frontend_state != XenbusStateConnected) {
> +        !xen_device_state_is_active(state)) {
>          xen_device_backend_set_state(xendev, XenbusStateClosed);
>      }
> 
> --
> Anthony PERARD


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

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

* Re: [Xen-devel] [PATCH v2 2/2] xen-bus: Avoid rewriting identical values to xenstore
  2019-08-23 10:15 ` [Xen-devel] [PATCH v2 2/2] xen-bus: Avoid rewriting identical values to xenstore Anthony PERARD
@ 2019-08-27  9:46   ` Paul Durrant
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Durrant @ 2019-08-27  9:46 UTC (permalink / raw)
  To: Anthony Perard, qemu-devel; +Cc: Anthony Perard, xen-devel, Stefano Stabellini

> -----Original Message-----
> From: Anthony PERARD <anthony.perard@citrix.com>
> Sent: 23 August 2019 11:16
> To: qemu-devel@nongnu.org
> Cc: Anthony Perard <anthony.perard@citrix.com>; Stefano Stabellini <sstabellini@kernel.org>; Paul
> Durrant <Paul.Durrant@citrix.com>; xen-devel@lists.xenproject.org
> Subject: [PATCH v2 2/2] xen-bus: Avoid rewriting identical values to xenstore
> 
> When QEMU receives a xenstore watch event suggesting that the "state"
> of the frontend changed, it records this in its own state but it also
> re-write the value back into xenstore even so there were no change.
> This triggers an unnecessary xenstore watch event which QEMU will
> process again (and maybe the frontend as well). Also QEMU could
> potentially write an already old value.
> 
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>

Reviewed-by: Paul Durrant <paul.durrant@citrix.com>

> ---
> 
> Notes:
>     v2:
>     - fix coding style
>     - only change frontend_set_state() and use 'publish' instead of 'export'.
> 
>  hw/xen/xen-bus.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c
> index 62c127b926..a04478ad4f 100644
> --- a/hw/xen/xen-bus.c
> +++ b/hw/xen/xen-bus.c
> @@ -698,7 +698,8 @@ int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
>  }
> 
>  static void xen_device_frontend_set_state(XenDevice *xendev,
> -                                          enum xenbus_state state)
> +                                          enum xenbus_state state,
> +                                          bool publish)
>  {
>      const char *type = object_get_typename(OBJECT(xendev));
> 
> @@ -710,7 +711,9 @@ static void xen_device_frontend_set_state(XenDevice *xendev,
>                                      xs_strstate(state));
> 
>      xendev->frontend_state = state;
> -    xen_device_frontend_printf(xendev, "state", "%u", state);
> +    if (publish) {
> +        xen_device_frontend_printf(xendev, "state", "%u", state);
> +    }
>  }
> 
>  static void xen_device_frontend_changed(void *opaque)
> @@ -726,7 +729,7 @@ static void xen_device_frontend_changed(void *opaque)
>          state = XenbusStateUnknown;
>      }
> 
> -    xen_device_frontend_set_state(xendev, state);
> +    xen_device_frontend_set_state(xendev, state, false);
> 
>      if (state == XenbusStateInitialising &&
>          xendev->backend_state == XenbusStateClosed &&
> @@ -1169,7 +1172,7 @@ static void xen_device_realize(DeviceState *dev, Error **errp)
>      xen_device_frontend_printf(xendev, "backend-id", "%u",
>                                 xenbus->backend_id);
> 
> -    xen_device_frontend_set_state(xendev, XenbusStateInitialising);
> +    xen_device_frontend_set_state(xendev, XenbusStateInitialising, true);
> 
>      xendev->exit.notify = xen_device_exit;
>      qemu_add_exit_notifier(&xendev->exit);
> --
> Anthony PERARD


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

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

end of thread, other threads:[~2019-08-27  9:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20190823101534.465-1-anthony.perard@citrix.com>
2019-08-23 10:15 ` [Xen-devel] [PATCH v2 1/2] xen-bus: Fix backend state transition on device reset Anthony PERARD
2019-08-27  9:44   ` Paul Durrant
2019-08-23 10:15 ` [Xen-devel] [PATCH v2 2/2] xen-bus: Avoid rewriting identical values to xenstore Anthony PERARD
2019-08-27  9:46   ` Paul Durrant

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).