From nobody Sun May 19 01:42:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1589939366; cv=none; d=zohomail.com; s=zohoarc; b=ExPaPY9WKSFH5gRQUN4mTXZ+hb1dz9gmfk4Bovsm+KB5jbll3zUzSXXpJ97OOzEA3BxTOkYoqxXAXRxI+ienAfou3zSrtv9qXV7ZxMwnToHA88bsSfctIy6mUDpaR2zIz2yScz+O2Y6zG1CyONvYiTWQhFJJ1OCXP3M5OKy0g3g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589939365; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=qNK8HOfOERYDGCC0ji1l54rjaCBIg9JJO4A8Cz38als=; b=VEx07rEduFbW0uAMlzrh1ot4PpgRBBM0LzRKTASh1Ri5ZKMJ/iyA4iXnEl7F3hrFs9JEP+IhRZs2N5bLrKIuP5wqw1qsHe47q7+q6ri44S+u9NCSDi/taI9og20EEwv1qgp4zFUlC0wyTdH3hio3UBa+S0LLY75/ClyqV1W7cJM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158993936599669.64789884604147; Tue, 19 May 2020 18:49:25 -0700 (PDT) Received: from localhost ([::1]:38322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbDrI-0000g9-RS for importer@patchew.org; Tue, 19 May 2020 21:49:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbDpE-0006HW-7L for qemu-devel@nongnu.org; Tue, 19 May 2020 21:47:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:33536) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbDpD-0000cQ-4B for qemu-devel@nongnu.org; Tue, 19 May 2020 21:47:15 -0400 Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9D619207D8; Wed, 20 May 2020 01:47:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589939233; bh=4/W/Pzh2gymBGgKA7KnPmOduUQtI3QITX4oFPL4mDos=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xb7uZcNbQptT0Ye8VBvou5KfUxII6ADHU0mOX4eWKxDSH9s1EICUvscW4hxxF5A23 LuprqIXka8K/g76G7iFeJMf0IdoemS1jMcQNG48NdyWhhhiA6sEqIz8GyfRn9Xv1Yi 4LqN5mnpM4VW8ZFYcWNFCnbDwHg+NAU0fwSjQUoo= From: Stefano Stabellini To: groug@kaod.org, qemu_oss@crudebyte.com Subject: [PATCH 1/2] Revert "9p: init_in_iov_from_pdu can truncate the size" Date: Tue, 19 May 2020 18:47:11 -0700 Message-Id: <20200520014712.24213-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.145.29.99; envelope-from=sstabellini@kernel.org; helo=mail.kernel.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/19 21:47:04 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: anthony.perard@citrix.com, sstabellini@kernel.org, qemu-devel@nongnu.org, Stefano Stabellini , paul@xen.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini This reverts commit 16724a173049ac29c7b5ade741da93a0f46edff7. It causes https://bugs.launchpad.net/bugs/1877688. Signed-off-by: Stefano Stabellini Reviewed-by: Christian Schoenebeck --- hw/9pfs/9p.c | 33 +++++++++++---------------------- hw/9pfs/9p.h | 2 +- hw/9pfs/virtio-9p-device.c | 11 ++++------- hw/9pfs/xen-9p-backend.c | 15 ++++++--------- 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index a2a14b5979..d39bfee462 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -2102,29 +2102,22 @@ out_nofid: * with qemu_iovec_destroy(). */ static void v9fs_init_qiov_from_pdu(QEMUIOVector *qiov, V9fsPDU *pdu, - size_t skip, size_t *size, + size_t skip, size_t size, bool is_write) { QEMUIOVector elem; struct iovec *iov; unsigned int niov; - size_t alloc_size =3D *size + skip; =20 if (is_write) { - pdu->s->transport->init_out_iov_from_pdu(pdu, &iov, &niov, alloc_s= ize); + pdu->s->transport->init_out_iov_from_pdu(pdu, &iov, &niov, size + = skip); } else { - pdu->s->transport->init_in_iov_from_pdu(pdu, &iov, &niov, &alloc_s= ize); - } - - if (alloc_size < skip) { - *size =3D 0; - } else { - *size =3D alloc_size - skip; + pdu->s->transport->init_in_iov_from_pdu(pdu, &iov, &niov, size + s= kip); } =20 qemu_iovec_init_external(&elem, iov, niov); qemu_iovec_init(qiov, niov); - qemu_iovec_concat(qiov, &elem, skip, *size); + qemu_iovec_concat(qiov, &elem, skip, size); } =20 static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, @@ -2132,14 +2125,15 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *p= du, V9fsFidState *fidp, { ssize_t err; size_t offset =3D 7; - size_t read_count; + uint64_t read_count; QEMUIOVector qiov_full; =20 if (fidp->fs.xattr.len < off) { read_count =3D 0; - } else if (fidp->fs.xattr.len - off < max_count) { - read_count =3D fidp->fs.xattr.len - off; } else { + read_count =3D fidp->fs.xattr.len - off; + } + if (read_count > max_count) { read_count =3D max_count; } err =3D pdu_marshal(pdu, offset, "d", read_count); @@ -2148,7 +2142,7 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu= , V9fsFidState *fidp, } offset +=3D err; =20 - v9fs_init_qiov_from_pdu(&qiov_full, pdu, offset, &read_count, false); + v9fs_init_qiov_from_pdu(&qiov_full, pdu, offset, read_count, false); err =3D v9fs_pack(qiov_full.iov, qiov_full.niov, 0, ((char *)fidp->fs.xattr.value) + off, read_count); @@ -2277,11 +2271,9 @@ static void coroutine_fn v9fs_read(void *opaque) QEMUIOVector qiov_full; QEMUIOVector qiov; int32_t len; - size_t size =3D max_count; =20 - v9fs_init_qiov_from_pdu(&qiov_full, pdu, offset + 4, &size, false); + v9fs_init_qiov_from_pdu(&qiov_full, pdu, offset + 4, max_count, fa= lse); qemu_iovec_init(&qiov, qiov_full.niov); - max_count =3D size; do { qemu_iovec_reset(&qiov); qemu_iovec_concat(&qiov, &qiov_full, count, qiov_full.size - c= ount); @@ -2532,7 +2524,6 @@ static void coroutine_fn v9fs_write(void *opaque) int32_t len =3D 0; int32_t total =3D 0; size_t offset =3D 7; - size_t size; V9fsFidState *fidp; V9fsPDU *pdu =3D opaque; V9fsState *s =3D pdu->s; @@ -2545,9 +2536,7 @@ static void coroutine_fn v9fs_write(void *opaque) return; } offset +=3D err; - size =3D count; - v9fs_init_qiov_from_pdu(&qiov_full, pdu, offset, &size, true); - count =3D size; + v9fs_init_qiov_from_pdu(&qiov_full, pdu, offset, count, true); trace_v9fs_write(pdu->tag, pdu->id, fid, off, count, qiov_full.niov); =20 fidp =3D get_fid(pdu, fid); diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index dd1c6cb8d2..1b9e110605 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -436,7 +436,7 @@ struct V9fsTransport { ssize_t (*pdu_vunmarshal)(V9fsPDU *pdu, size_t offset, const char = *fmt, va_list ap); void (*init_in_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov, - unsigned int *pniov, size_t *size); + unsigned int *pniov, size_t size); void (*init_out_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov, unsigned int *pniov, size_t size); void (*push_and_notify)(V9fsPDU *pdu); diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index e5b44977c7..36f3aa9352 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -147,22 +147,19 @@ static ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, si= ze_t offset, } =20 static void virtio_init_in_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov, - unsigned int *pniov, size_t *size) + unsigned int *pniov, size_t size) { V9fsState *s =3D pdu->s; V9fsVirtioState *v =3D container_of(s, V9fsVirtioState, state); VirtQueueElement *elem =3D v->elems[pdu->idx]; size_t buf_size =3D iov_size(elem->in_sg, elem->in_num); =20 - if (buf_size < P9_IOHDRSZ) { + if (buf_size < size) { VirtIODevice *vdev =3D VIRTIO_DEVICE(v); =20 virtio_error(vdev, - "VirtFS reply type %d needs %zu bytes, buffer has %zu= , less than minimum", - pdu->id + 1, *size, buf_size); - } - if (buf_size < *size) { - *size =3D buf_size; + "VirtFS reply type %d needs %zu bytes, buffer has %zu= ", + pdu->id + 1, size, buf_size); } =20 *piov =3D elem->in_sg; diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c index f04caabfe5..fc197f6c8a 100644 --- a/hw/9pfs/xen-9p-backend.c +++ b/hw/9pfs/xen-9p-backend.c @@ -188,7 +188,7 @@ static void xen_9pfs_init_out_iov_from_pdu(V9fsPDU *pdu, static void xen_9pfs_init_in_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov, unsigned int *pniov, - size_t *size) + size_t size) { Xen9pfsDev *xen_9pfs =3D container_of(pdu->s, Xen9pfsDev, state); Xen9pfsRing *ring =3D &xen_9pfs->rings[pdu->tag % xen_9pfs->num_rings]; @@ -198,19 +198,16 @@ static void xen_9pfs_init_in_iov_from_pdu(V9fsPDU *pd= u, g_free(ring->sg); =20 ring->sg =3D g_new0(struct iovec, 2); - xen_9pfs_in_sg(ring, ring->sg, &num, pdu->idx, *size); + xen_9pfs_in_sg(ring, ring->sg, &num, pdu->idx, size); =20 buf_size =3D iov_size(ring->sg, num); - if (buf_size < P9_IOHDRSZ) { - xen_pv_printf(&xen_9pfs->xendev, 0, "Xen 9pfs reply type %d needs " - "%zu bytes, buffer has %zu, less than minimum\n", - pdu->id + 1, *size, buf_size); + if (buf_size < size) { + xen_pv_printf(&xen_9pfs->xendev, 0, "Xen 9pfs request type %d" + "needs %zu bytes, buffer has %zu\n", pdu->id, size, + buf_size); xen_be_set_state(&xen_9pfs->xendev, XenbusStateClosing); xen_9pfs_disconnect(&xen_9pfs->xendev); } - if (buf_size < *size) { - *size =3D buf_size; - } =20 *piov =3D ring->sg; *pniov =3D num; --=20 2.17.1 From nobody Sun May 19 01:42:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1589939324; cv=none; d=zohomail.com; s=zohoarc; b=RoWAYli5wqWx8H3uzci/nbhtIRxrLYn6pNySpWdRLD7vVD8mpA1Q8S6Icny0ML6dNoCs4QLS4TjESV/i+qNFbzGW7kMeIBif81BILNwJ2qUqYgXZNwmxcV/LsXhwi6lN2XqAYWIfEqu6ywuo47eCk7OXekAukFLdgyBg1Jo7xPc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589939324; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=jVeLu46UDaOD+YKlxIGYlxzYlRYHoC0eApZsjX2MMqc=; b=WWeKryrEZW5z5B3+eAwXaNLpPSkdhWPEpABFF/eQN6mAeZ8z4m7qwH6sZLOoqtqGmTwKlek7l9v1TY/MsmSzaHp3RWPfFv95TDqUcnrKGNbiK44WzVy+0O0NgJOARj1guFQ0jdtiaoYrOMSbbuM4hADOMp1OVv4r0iqeS3RbBAs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158993932458098.95315079978661; Tue, 19 May 2020 18:48:44 -0700 (PDT) Received: from localhost ([::1]:35844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbDqd-0007fi-6X for importer@patchew.org; Tue, 19 May 2020 21:48:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbDpE-0006Ie-Uu for qemu-devel@nongnu.org; Tue, 19 May 2020 21:47:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:33554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbDpD-0000cW-HA for qemu-devel@nongnu.org; Tue, 19 May 2020 21:47:16 -0400 Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3514420835; Wed, 20 May 2020 01:47:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589939234; bh=sE88ONPOkNRCEvBA7tC0Bdt5FgoDGYj91tBBiFVTE1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GQ5sn/4B3xBZgyUZMqD8NA4ytMRfiXDbREuS/qzfqPjQ5eVqeMcoaNBlBQ0FT3TCI SMCce/na1Upz6ZXO5Wi50hyRtI/6FXqMtvBTVdGT5gYDY9et3IrQEeyMXJEJlo/CUS NMQMw/mkDLVBzE5+DrcnY62KNehvya4Adt32GtWE= From: Stefano Stabellini To: groug@kaod.org, qemu_oss@crudebyte.com Subject: [PATCH 2/2] xen/9pfs: yield when there isn't enough room on the ring Date: Tue, 19 May 2020 18:47:12 -0700 Message-Id: <20200520014712.24213-2-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.145.29.99; envelope-from=sstabellini@kernel.org; helo=mail.kernel.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/19 21:47:04 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: anthony.perard@citrix.com, sstabellini@kernel.org, qemu-devel@nongnu.org, Stefano Stabellini , paul@xen.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini Instead of truncating replies, which is problematic, wait until the client reads more data and frees bytes on the reply ring. Do that by calling qemu_coroutine_yield(). The corresponding qemu_coroutine_enter_if_inactive() is called from xen_9pfs_bh upon receiving the next notification from the client. We need to be careful to avoid races in case xen_9pfs_bh and the coroutine are both active at the same time. In xen_9pfs_bh, wait until either the critical section is over (ring->co =3D=3D NULL) or until the coroutine becomes inactive (qemu_coroutine_yield() was called) before continuing. Then, simply wake up the coroutine if it is inactive. Signed-off-by: Stefano Stabellini Reviewed-by: Christian Schoenebeck --- hw/9pfs/xen-9p-backend.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c index fc197f6c8a..3939539028 100644 --- a/hw/9pfs/xen-9p-backend.c +++ b/hw/9pfs/xen-9p-backend.c @@ -37,6 +37,7 @@ typedef struct Xen9pfsRing { =20 struct iovec *sg; QEMUBH *bh; + Coroutine *co; =20 /* local copies, so that we can read/write PDU data directly from * the ring */ @@ -198,16 +199,18 @@ static void xen_9pfs_init_in_iov_from_pdu(V9fsPDU *pd= u, g_free(ring->sg); =20 ring->sg =3D g_new0(struct iovec, 2); - xen_9pfs_in_sg(ring, ring->sg, &num, pdu->idx, size); + ring->co =3D qemu_coroutine_self(); + smp_wmb(); =20 +again: + xen_9pfs_in_sg(ring, ring->sg, &num, pdu->idx, size); buf_size =3D iov_size(ring->sg, num); if (buf_size < size) { - xen_pv_printf(&xen_9pfs->xendev, 0, "Xen 9pfs request type %d" - "needs %zu bytes, buffer has %zu\n", pdu->id, size, - buf_size); - xen_be_set_state(&xen_9pfs->xendev, XenbusStateClosing); - xen_9pfs_disconnect(&xen_9pfs->xendev); + qemu_coroutine_yield(); + goto again; } + ring->co =3D NULL; + smp_wmb(); =20 *piov =3D ring->sg; *pniov =3D num; @@ -292,6 +295,19 @@ static int xen_9pfs_receive(Xen9pfsRing *ring) static void xen_9pfs_bh(void *opaque) { Xen9pfsRing *ring =3D opaque; + bool wait; + +again: + wait =3D ring->co !=3D NULL && qemu_coroutine_entered(ring->co); + smp_rmb(); + if (wait) { + cpu_relax(); + goto again; + } + + if (ring->co !=3D NULL) { + qemu_coroutine_enter_if_inactive(ring->co); + } xen_9pfs_receive(ring); } =20 --=20 2.17.1