From nobody Mon May 6 19:16:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490959803763364.732507208141; Fri, 31 Mar 2017 04:30:03 -0700 (PDT) Received: from localhost ([::1]:40151 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctukk-0004Pj-JA for importer@patchew.org; Fri, 31 Mar 2017 07:30:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctui4-0002UC-Ct for qemu-devel@nongnu.org; Fri, 31 Mar 2017 07:27:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ctuhz-0006yi-Fg for qemu-devel@nongnu.org; Fri, 31 Mar 2017 07:27:16 -0400 Received: from 4.mo179.mail-out.ovh.net ([46.105.36.149]:51956) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ctuhz-0006yF-92 for qemu-devel@nongnu.org; Fri, 31 Mar 2017 07:27:11 -0400 Received: from player755.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id 0402E341A6 for ; Fri, 31 Mar 2017 13:27:10 +0200 (CEST) Received: from bahia.lan (huguette.tetaneutral.net [91.224.149.27]) (Authenticated sender: groug@kaod.org) by player755.ha.ovh.net (Postfix) with ESMTPA id 2654926009A; Fri, 31 Mar 2017 13:27:02 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Fri, 31 Mar 2017 13:27:00 +0200 Message-ID: <149095962044.26233.2156597686399438923.stgit@bahia.lan> In-Reply-To: <149095959109.26233.3201018420228514740.stgit@bahia> References: <149095959109.26233.3201018420228514740.stgit@bahia> User-Agent: StGit/0.17.1-20-gc0b1b-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 4399172412388448627 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelhedrledugdeflecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.36.149 Subject: [Qemu-devel] [for-2.9 PATCH 1/3] 9pfs: clear migration blocker at session reset 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: Li Qiang , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 The migration blocker survives a device reset: if the guest mounts a 9p share and then gets rebooted with system_reset, it will be unmigratable until it remounts and umounts the 9p share again. This happens because the migration blocker is supposed to be cleared when we put the last reference on the root fid, but virtfs_reset() wrongly calls free_fid() instead of put_fid(). This patch fixes virtfs_reset() so that it honor the way fids are supposed to be manipulated: first get a reference and later put it back when you're done. Signed-off-by: Greg Kurz Reviewed-by: Li Qiang --- hw/9pfs/9p.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 48babce836b6..cc109367b030 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -539,14 +539,15 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu) =20 /* Free all fids */ while (s->fid_list) { + /* Get fid */ fidp =3D s->fid_list; + fidp->ref++; + + /* Clunk fid */ s->fid_list =3D fidp->next; + fidp->clunked =3D 1; =20 - if (fidp->ref) { - fidp->clunked =3D 1; - } else { - free_fid(pdu, fidp); - } + put_fid(pdu, fidp); } } =20 From nobody Mon May 6 19:16:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490959771797592.826251769742; Fri, 31 Mar 2017 04:29:31 -0700 (PDT) Received: from localhost ([::1]:40150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctukE-0003wp-D2 for importer@patchew.org; Fri, 31 Mar 2017 07:29:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38888) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctuiJ-0002do-TH for qemu-devel@nongnu.org; Fri, 31 Mar 2017 07:27:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ctuiF-00078j-1I for qemu-devel@nongnu.org; Fri, 31 Mar 2017 07:27:31 -0400 Received: from 3.mo179.mail-out.ovh.net ([178.33.251.175]:54129) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ctuiE-00077o-Qn for qemu-devel@nongnu.org; Fri, 31 Mar 2017 07:27:26 -0400 Received: from player755.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id 8579E34148 for ; Fri, 31 Mar 2017 13:27:25 +0200 (CEST) Received: from bahia.lan (huguette.tetaneutral.net [91.224.149.27]) (Authenticated sender: groug@kaod.org) by player755.ha.ovh.net (Postfix) with ESMTPA id 15E92260087; Fri, 31 Mar 2017 13:27:18 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Fri, 31 Mar 2017 13:27:15 +0200 Message-ID: <149095963571.26233.9370507789591510204.stgit@bahia.lan> In-Reply-To: <149095959109.26233.3201018420228514740.stgit@bahia> References: <149095959109.26233.3201018420228514740.stgit@bahia> User-Agent: StGit/0.17.1-20-gc0b1b-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 4403676011537471859 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelhedrledugdeflecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.33.251.175 Subject: [Qemu-devel] [for-2.9 PATCH 2/3] 9pfs: cancel active PDUs in virtfs_reset() 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: Li Qiang , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 According to the 9P spec [1], the version operation should abort any outstanding I/O and clunk all fids, so that a new session may be started in a clean state. The current code tries to clunk and free fids, but it doesn't wait for active PDUs to complete. This can cause an I/O to actually complete after the new session has begun, and confuse the client. This patch modifies virtfs_reset() so that it explicitely cancels and waits for inflight requests to terminate. All fids should thus be unreferenced and ready to be freed. Let's make it clear with a an assertion. [1] http://man.cat-v.org/plan_9/5/version Signed-off-by: Greg Kurz Reviewed-by: Li Qiang --- hw/9pfs/9p.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index cc109367b030..86ed9065c4e2 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -536,9 +536,29 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu) { V9fsState *s =3D pdu->s; V9fsFidState *fidp; + bool done =3D false; + + /* Drain any outstanding I/O */ + while (!done) { + V9fsPDU *cancel_pdu; + + done =3D true; + QLIST_FOREACH(cancel_pdu, &s->active_list, next) { + if (cancel_pdu !=3D pdu) { + done =3D false; + cancel_pdu->cancelled =3D 1; + qemu_co_queue_wait(&cancel_pdu->complete, NULL); + cancel_pdu->cancelled =3D 0; + pdu_free(cancel_pdu); + break; + } + } + } =20 /* Free all fids */ while (s->fid_list) { + assert(!fidp->ref); + /* Get fid */ fidp =3D s->fid_list; fidp->ref++; @@ -670,7 +690,7 @@ static void coroutine_fn pdu_complete(V9fsPDU *pdu, ssi= ze_t len) =20 pdu_push_and_notify(pdu); =20 - /* Now wakeup anybody waiting in flush for this request */ + /* Now wakeup anybody waiting in flush or reset for this request */ if (!qemu_co_queue_next(&pdu->complete)) { pdu_free(pdu); } From nobody Mon May 6 19:16:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490959746444763.5095543326502; Fri, 31 Mar 2017 04:29:06 -0700 (PDT) Received: from localhost ([::1]:40149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctujp-0003e3-22 for importer@patchew.org; Fri, 31 Mar 2017 07:29:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39075) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctuiX-0002oJ-EA for qemu-devel@nongnu.org; Fri, 31 Mar 2017 07:27:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ctuiS-0007KN-Hs for qemu-devel@nongnu.org; Fri, 31 Mar 2017 07:27:45 -0400 Received: from 7.mo179.mail-out.ovh.net ([46.105.61.94]:55726) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ctuiS-0007JS-Bl for qemu-devel@nongnu.org; Fri, 31 Mar 2017 07:27:40 -0400 Received: from player755.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id 266873420C for ; Fri, 31 Mar 2017 13:27:39 +0200 (CEST) Received: from bahia.lan (huguette.tetaneutral.net [91.224.149.27]) (Authenticated sender: groug@kaod.org) by player755.ha.ovh.net (Postfix) with ESMTPA id 54FF42600AF; Fri, 31 Mar 2017 13:27:33 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Fri, 31 Mar 2017 13:27:31 +0200 Message-ID: <149095965106.26233.18168802196576430962.stgit@bahia.lan> In-Reply-To: <149095959109.26233.3201018420228514740.stgit@bahia> References: <149095959109.26233.3201018420228514740.stgit@bahia> User-Agent: StGit/0.17.1-20-gc0b1b-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 4407616661432801651 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelhedrledugdeflecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.61.94 Subject: [Qemu-devel] [for-2.9 PATCH 3/3] 9pfs: drop useless loop in v9fs_reset() 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: Li Qiang , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 We don't need to wait for the PDU active list to be empty: virtfs_reset() already takes care of that. Signed-off-by: Greg Kurz Reviewed-by: Li Qiang --- hw/9pfs/9p.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 86ed9065c4e2..16ef6bd5bd8c 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -3601,6 +3601,7 @@ static void coroutine_fn virtfs_co_reset(void *opaque) VirtfsCoResetData *data =3D opaque; =20 virtfs_reset(&data->pdu); + assert(QLIST_EMPTY(&data->pdu.s->active_list)); data->done =3D true; } =20 @@ -3609,10 +3610,6 @@ void v9fs_reset(V9fsState *s) VirtfsCoResetData data =3D { .pdu =3D { .s =3D s }, .done =3D false }; Coroutine *co; =20 - while (!QLIST_EMPTY(&s->active_list)) { - aio_poll(qemu_get_aio_context(), true); - } - co =3D qemu_coroutine_create(virtfs_co_reset, &data); qemu_coroutine_enter(co); =20