From patchwork Mon Feb 4 11:28:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 10795463 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5BBB922 for ; Mon, 4 Feb 2019 11:42:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 948942B092 for ; Mon, 4 Feb 2019 11:42:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 878792B117; Mon, 4 Feb 2019 11:42:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 200F02B092 for ; Mon, 4 Feb 2019 11:42:03 +0000 (UTC) Received: from localhost ([127.0.0.1]:41107 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqcdW-0006Ju-BE for patchwork-qemu-devel@patchwork.kernel.org; Mon, 04 Feb 2019 06:42:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52256) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqcQh-0006Ax-KL for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqcQf-0007MS-VV for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:47 -0500 Received: from smtp03.citrix.com ([162.221.156.55]:14941) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqcQb-00078u-UB for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:45 -0500 X-IronPort-AV: E=Sophos;i="5.56,560,1539648000"; d="scan'208";a="77210718" From: Anthony PERARD To: Date: Mon, 4 Feb 2019 11:28:02 +0000 Message-ID: <20190204112803.11645-4-anthony.perard@citrix.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204112803.11645-1-anthony.perard@citrix.com> References: <20190204112803.11645-1-anthony.perard@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PULL 3/4] xen: fix xen-bus state model to allow frontend re-connection X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , xen-devel@lists.xenproject.org, Peter Maydell Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Paul Durrant There is a flaw in the xen-bus state model. To allow a frontend to re- connect the backend state of an online XenDevice is transitioned from Closed to InitWait, but this is currently done unilaterally which is incorrect. The backend state should remain Closed until the frontend state transitions to Initialising. This patch removes the automatic backend state transition from xen_device_backend_state_changed() and, instead, adds an extra check in xen_device_frontend_state_changed() to determine whether a frontend is trying to re-connect to a previously Closed XenDevice. Only if this is found to be the case is the backend state transitioned from Closed to InitWait. Note that this transition will be common amongst all XenDevice classes and hence xen_device_frontend_state_changed() returns immediately afterwards without calling into the XenDeviceClass frontend_changed() method. Signed-off-by: Paul Durrant Acked-by: Anthony PERARD Signed-off-by: Anthony PERARD --- hw/xen/xen-bus.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index 3aeccec69c..49a725e8c7 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -547,20 +547,15 @@ static void xen_device_backend_changed(void *opaque) } /* - * If a backend is still 'online' then its state should be cycled - * back round to InitWait in order for a new frontend instance to - * connect. This may happen when, for example, a frontend driver is - * re-installed or updated. - * If a backend is not 'online' then the device should be destroyed. + * If a backend is still 'online' then we should leave it alone but, + * if a backend is not 'online', then the device should be destroyed + * once the state is Closed. */ - if (xendev->backend_online && - xendev->backend_state == XenbusStateClosed) { - xen_device_backend_set_state(xendev, XenbusStateInitWait); - } else if (!xendev->backend_online && - (xendev->backend_state == XenbusStateClosed || - xendev->backend_state == XenbusStateInitialising || - xendev->backend_state == XenbusStateInitWait || - xendev->backend_state == XenbusStateUnknown)) { + if (!xendev->backend_online && + (xendev->backend_state == XenbusStateClosed || + xendev->backend_state == XenbusStateInitialising || + xendev->backend_state == XenbusStateInitWait || + xendev->backend_state == XenbusStateUnknown)) { Error *local_err = NULL; if (!xen_backend_try_device_destroy(xendev, &local_err)) { @@ -715,6 +710,17 @@ static void xen_device_frontend_changed(void *opaque) xen_device_frontend_set_state(xendev, state); + if (state == XenbusStateInitialising && + xendev->backend_state == XenbusStateClosed && + xendev->backend_online) { + /* + * The frontend is re-initializing so switch back to + * InitWait. + */ + xen_device_backend_set_state(xendev, XenbusStateInitWait); + return; + } + if (xendev_class->frontend_changed) { Error *local_err = NULL;