From nobody Thu May 2 23:31:40 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 1490636892419569.8120574058203; Mon, 27 Mar 2017 10:48:12 -0700 (PDT) Received: from localhost ([::1]:48255 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csYkS-0003yK-1E for importer@patchew.org; Mon, 27 Mar 2017 13:48:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csYia-0002gF-Bg for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csYiX-0000et-9z for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:12 -0400 Received: from 6.mo2.mail-out.ovh.net ([87.98.165.38]:57502) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csYiX-0000eP-3B for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:09 -0400 Received: from player796.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id A20A2782B2 for ; Mon, 27 Mar 2017 19:46:07 +0200 (CEST) Received: from bahia.lan (huguette.tetaneutral.net [91.224.149.27]) (Authenticated sender: groug@kaod.org) by player796.ha.ovh.net (Postfix) with ESMTPA id E31F25C008A; Mon, 27 Mar 2017 19:46:03 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 19:46:03 +0200 Message-ID: <149063676337.4447.2095575576822297032.stgit@bahia.lan> In-Reply-To: <149063674781.4447.14258971700726134711.stgit@bahia.lan> References: <149063674781.4447.14258971700726134711.stgit@bahia.lan> 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: 5755318849281825201 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelhedrkedugdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 87.98.165.38 Subject: [Qemu-devel] [PATCH 1/5] virtio: Error object based virtio_error() 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: Stefano Stabellini , Greg Kurz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This introduces an Error object based implementation of virtio_error(). It allows to implement virtio_error() wrappers in device-specific code. Signed-off-by: Greg Kurz --- hw/virtio/virtio.c | 21 ++++++++++++++++----- include/hw/virtio/virtio.h | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 03592c542a55..4036f4816038 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2443,6 +2443,16 @@ void virtio_device_set_child_bus_name(VirtIODevice *= vdev, char *bus_name) vdev->bus_name =3D g_strdup(bus_name); } =20 +static void virtio_device_set_broken(VirtIODevice *vdev) +{ + vdev->broken =3D true; + + if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { + virtio_set_status(vdev, vdev->status | VIRTIO_CONFIG_S_NEEDS_RESET= ); + virtio_notify_config(vdev); + } +} + void GCC_FMT_ATTR(2, 3) virtio_error(VirtIODevice *vdev, const char *fmt, = ...) { va_list ap; @@ -2451,12 +2461,13 @@ void GCC_FMT_ATTR(2, 3) virtio_error(VirtIODevice *= vdev, const char *fmt, ...) error_vreport(fmt, ap); va_end(ap); =20 - vdev->broken =3D true; + virtio_device_set_broken(vdev); +} =20 - if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { - virtio_set_status(vdev, vdev->status | VIRTIO_CONFIG_S_NEEDS_RESET= ); - virtio_notify_config(vdev); - } +void virtio_error_err(VirtIODevice *vdev, Error *err) +{ + error_report_err(err); + virtio_device_set_broken(vdev); } =20 static void virtio_memory_listener_commit(MemoryListener *listener) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 15efcf205711..5b13c5f67b63 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -150,6 +150,7 @@ void virtio_init(VirtIODevice *vdev, const char *name, void virtio_cleanup(VirtIODevice *vdev); =20 void virtio_error(VirtIODevice *vdev, const char *fmt, ...) GCC_FMT_ATTR(2= , 3); +void virtio_error_err(VirtIODevice *vdev, Error *err); =20 /* Set the child bus name. */ void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name); From nobody Thu May 2 23:31:40 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 1490637023214711.3633633238393; Mon, 27 Mar 2017 10:50:23 -0700 (PDT) Received: from localhost ([::1]:48261 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csYmc-0005Uh-4E for importer@patchew.org; Mon, 27 Mar 2017 13:50:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csYik-0002n2-8c for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csYih-0000hS-6S for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:22 -0400 Received: from 2.mo2.mail-out.ovh.net ([188.165.53.149]:54565) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csYig-0000h3-VD for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:19 -0400 Received: from player796.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 9DDCA76A05 for ; Mon, 27 Mar 2017 19:46:17 +0200 (CEST) Received: from bahia.lan (huguette.tetaneutral.net [91.224.149.27]) (Authenticated sender: groug@kaod.org) by player796.ha.ovh.net (Postfix) with ESMTPA id BC6465C008A; Mon, 27 Mar 2017 19:46:13 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 19:46:12 +0200 Message-ID: <149063677290.4447.3976316489902712200.stgit@bahia.lan> In-Reply-To: <149063674781.4447.14258971700726134711.stgit@bahia.lan> References: <149063674781.4447.14258971700726134711.stgit@bahia.lan> 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: 5758133599871015345 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelhedrkedugdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 188.165.53.149 Subject: [Qemu-devel] [PATCH 2/5] virtio-9p: factor out virtio_9p_error_err() 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: Stefano Stabellini , Greg Kurz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 When an unrecoverable is hit, we need to set the broken flag of the virtio device, detach the queue element and free it. This is currently open coded in handle_9p_output(). It is fine since this is the only function that can set the broken flag. But if we want to be able to do this from other places, we must consolidate the logic in a helper. Signed-off-by: Greg Kurz --- hw/9pfs/virtio-9p-device.c | 45 +++++++++++++++++++++++++++++-----------= ---- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index 27a4a32f5c4c..873b22baf0f9 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -22,21 +22,42 @@ =20 static const struct V9fsTransport virtio_9p_transport; =20 +static void virtio_9p_free_element(V9fsVirtioState *v, unsigned int idx) +{ + VirtQueueElement **pelem =3D &v->elems[idx]; + g_free(*pelem); + *pelem =3D NULL; +} + static void virtio_9p_push_and_notify(V9fsPDU *pdu) { V9fsState *s =3D pdu->s; V9fsVirtioState *v =3D container_of(s, V9fsVirtioState, state); - VirtQueueElement *elem =3D v->elems[pdu->idx]; =20 /* push onto queue and notify */ - virtqueue_push(v->vq, elem, pdu->size); - g_free(elem); - v->elems[pdu->idx] =3D NULL; + virtqueue_push(v->vq, v->elems[pdu->idx], pdu->size); + virtio_9p_free_element(v, pdu->idx); =20 /* FIXME: we should batch these completions */ virtio_notify(VIRTIO_DEVICE(v), v->vq); } =20 +static void virtio_9p_error_err(V9fsVirtioState *v, unsigned int idx, + Error *err) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(v); + + virtio_error_err(vdev, err); + virtqueue_detach_element(v->vq, v->elems[idx], 0); + virtio_9p_free_element(v, idx); +} + +#define virtio_9p_error(v, idx, ...) { \ + Error *err =3D NULL; \ + error_setg(&err, ## __VA_ARGS__); \ + virtio_9p_error_err(v, idx, err); \ +} + static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq) { V9fsVirtioState *v =3D (V9fsVirtioState *)vdev; @@ -56,22 +77,19 @@ static void handle_9p_output(VirtIODevice *vdev, VirtQu= eue *vq) if (!elem) { goto out_free_pdu; } + v->elems[pdu->idx] =3D elem; =20 if (elem->in_num =3D=3D 0) { - virtio_error(vdev, - "The guest sent a VirtFS request without space fo= r " - "the reply"); - goto out_free_req; + virtio_9p_error(v, pdu->idx, "The guest sent a VirtFS request = without space for the reply"); + goto out_free_pdu; } QEMU_BUILD_BUG_ON(sizeof(out) !=3D 7); =20 - v->elems[pdu->idx] =3D elem; len =3D iov_to_buf(elem->out_sg, elem->out_num, 0, &out, sizeof(out)); if (len !=3D sizeof(out)) { - virtio_error(vdev, "The guest sent a malformed VirtFS request:= " - "header size is %zd, should be 7", len); - goto out_free_req; + virtio_9p_error(v, pdu->idx, "The guest sent a malformed VirtF= S request: header size is %zd, should be 7", len); + goto out_free_pdu; } =20 pdu->size =3D le32_to_cpu(out.size_le); @@ -85,9 +103,6 @@ static void handle_9p_output(VirtIODevice *vdev, VirtQue= ue *vq) =20 return; =20 -out_free_req: - virtqueue_detach_element(vq, elem, 0); - g_free(elem); out_free_pdu: pdu_free(pdu); } From nobody Thu May 2 23:31:40 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 1490637106799348.76040630313184; Mon, 27 Mar 2017 10:51:46 -0700 (PDT) Received: from localhost ([::1]:48274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csYnx-0006aH-Cl for importer@patchew.org; Mon, 27 Mar 2017 13:51:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csYiw-0002yc-5J for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csYit-0000rY-3H for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:34 -0400 Received: from 8.mo2.mail-out.ovh.net ([188.165.52.147]:43883) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csYis-0000o6-Sw for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:31 -0400 Received: from player796.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 7EC5676687 for ; Mon, 27 Mar 2017 19:46:27 +0200 (CEST) Received: from bahia.lan (huguette.tetaneutral.net [91.224.149.27]) (Authenticated sender: groug@kaod.org) by player796.ha.ovh.net (Postfix) with ESMTPA id 85FB55C008A; Mon, 27 Mar 2017 19:46:23 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 19:46:22 +0200 Message-ID: <149063678269.4447.4512988258114498161.stgit@bahia.lan> In-Reply-To: <149063674781.4447.14258971700726134711.stgit@bahia.lan> References: <149063674781.4447.14258971700726134711.stgit@bahia.lan> 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: 5760948352270899633 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelhedrkedugdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 188.165.52.147 Subject: [Qemu-devel] [PATCH 3/5] fsdev: don't allow unknown format in marshal/unmarshal 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: Stefano Stabellini , Greg Kurz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 The code only uses well known format strings. An unknown format token is a bug. Signed-off-by: Greg Kurz --- fsdev/9p-iov-marshal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fsdev/9p-iov-marshal.c b/fsdev/9p-iov-marshal.c index 1d16f8df4bd4..a1c9beddd2e7 100644 --- a/fsdev/9p-iov-marshal.c +++ b/fsdev/9p-iov-marshal.c @@ -168,7 +168,7 @@ ssize_t v9fs_iov_vunmarshal(struct iovec *out_sg, int o= ut_num, size_t offset, break; } default: - break; + g_assert_not_reached(); } if (copied < 0) { return copied; @@ -281,7 +281,7 @@ ssize_t v9fs_iov_vmarshal(struct iovec *in_sg, int in_n= um, size_t offset, break; } default: - break; + g_assert_not_reached(); } if (copied < 0) { return copied; From nobody Thu May 2 23:31:40 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 1490637192611484.8539350559096; Mon, 27 Mar 2017 10:53:12 -0700 (PDT) Received: from localhost ([::1]:48281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csYpL-0007XS-AM for importer@patchew.org; Mon, 27 Mar 2017 13:53:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csYj3-00033n-Eq for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csYj0-0000y8-Cn for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:41 -0400 Received: from 4.mo2.mail-out.ovh.net ([87.98.172.75]:49722) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csYj0-0000xQ-6e for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:38 -0400 Received: from player796.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 195BD769BD for ; Mon, 27 Mar 2017 19:46:37 +0200 (CEST) Received: from bahia.lan (huguette.tetaneutral.net [91.224.149.27]) (Authenticated sender: groug@kaod.org) by player796.ha.ovh.net (Postfix) with ESMTPA id 717E85C0093; Mon, 27 Mar 2017 19:46:33 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 19:46:32 +0200 Message-ID: <149063679263.4447.610228515162504763.stgit@bahia.lan> In-Reply-To: <149063674781.4447.14258971700726134711.stgit@bahia.lan> References: <149063674781.4447.14258971700726134711.stgit@bahia.lan> 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: 5763763102111406513 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelhedrkedugdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 87.98.172.75 Subject: [Qemu-devel] [PATCH 4/5] 9pfs: drop pdu_push_and_notify() 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: Stefano Stabellini , Greg Kurz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Only pdu_complete() needs to notify the client that a request has completed. Signed-off-by: Greg Kurz --- hw/9pfs/9p.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 48babce836b6..09a8c79cf781 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -65,11 +65,6 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const= char *fmt, ...) return ret; } =20 -static void pdu_push_and_notify(V9fsPDU *pdu) -{ - pdu->s->transport->push_and_notify(pdu); -} - static int omode_to_uflags(int8_t mode) { int ret =3D 0; @@ -667,7 +662,7 @@ static void coroutine_fn pdu_complete(V9fsPDU *pdu, ssi= ze_t len) pdu->size =3D len; pdu->id =3D id; =20 - pdu_push_and_notify(pdu); + pdu->s->transport->push_and_notify(pdu); =20 /* Now wakeup anybody waiting in flush for this request */ if (!qemu_co_queue_next(&pdu->complete)) { From nobody Thu May 2 23:31:40 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 1490637024906844.6824834121542; Mon, 27 Mar 2017 10:50:24 -0700 (PDT) Received: from localhost ([::1]:48262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csYmc-0005VO-QJ for importer@patchew.org; Mon, 27 Mar 2017 13:50:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csYjE-0003AK-2K for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csYjA-00014b-Vo for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:52 -0400 Received: from 7.mo2.mail-out.ovh.net ([188.165.48.182]:34695) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csYjA-00014I-N6 for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:46:48 -0400 Received: from player796.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 9EE6577307 for ; Mon, 27 Mar 2017 19:46:46 +0200 (CEST) Received: from bahia.lan (huguette.tetaneutral.net [91.224.149.27]) (Authenticated sender: groug@kaod.org) by player796.ha.ovh.net (Postfix) with ESMTPA id E4A845C0086; Mon, 27 Mar 2017 19:46:42 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 19:46:42 +0200 Message-ID: <149063680216.4447.10660696756972719425.stgit@bahia.lan> In-Reply-To: <149063674781.4447.14258971700726134711.stgit@bahia.lan> References: <149063674781.4447.14258971700726134711.stgit@bahia.lan> 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: 5766296376487614897 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelhedrkedugdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 188.165.48.182 Subject: [Qemu-devel] [PATCH 5/5] 9pfs: handle broken transport 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: Stefano Stabellini , Greg Kurz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 The 9p protocol is transport agnostic: if an error occurs when copying data to/from the client, this should be handled by the transport layer [1] and the 9p server should simply stop processing requests [2]. [1] can be implemented in the transport marshal/unmarshal handlers. In the case of virtio, this means calling virtio_error() to inform the guest that the device isn't functional anymore. [2] means that the pdu_complete() function shouldn't send a reply back to the client if the transport had a failure. This cannot be decided using the current error path though, since we cannot discriminate if the error comes from the transport or the backend. This patch hence introduces a flag in the 9pfs state to record that the transport is broken. The device needs to be reset for the flag to be unset. This fixes Coverity issue CID 1348518. Signed-off-by: Greg Kurz --- hw/9pfs/9p.c | 36 ++++++++++++++++++++++++++++-------- hw/9pfs/9p.h | 1 + hw/9pfs/virtio-9p-device.c | 16 ++++++++++++++-- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 09a8c79cf781..79d8292e9a7a 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -50,6 +50,9 @@ ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const ch= ar *fmt, ...) ret =3D pdu->s->transport->pdu_vmarshal(pdu, offset, fmt, ap); va_end(ap); =20 + if (ret < 0) { + pdu->s->transport_broken =3D true; + } return ret; } =20 @@ -62,6 +65,9 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const = char *fmt, ...) ret =3D pdu->s->transport->pdu_vunmarshal(pdu, offset, fmt, ap); va_end(ap); =20 + if (ret < 0) { + pdu->s->transport_broken =3D true; + } return ret; } =20 @@ -623,15 +629,15 @@ void pdu_free(V9fsPDU *pdu) QLIST_INSERT_HEAD(&s->free_list, pdu, next); } =20 -/* - * We don't do error checking for pdu_marshal/unmarshal here - * because we always expect to have enough space to encode - * error details - */ static void coroutine_fn pdu_complete(V9fsPDU *pdu, ssize_t len) { int8_t id =3D pdu->id + 1; /* Response */ V9fsState *s =3D pdu->s; + int ret; + + if (s->transport_broken) { + goto out_complete; + } =20 if (len < 0) { int err =3D -len; @@ -643,11 +649,19 @@ static void coroutine_fn pdu_complete(V9fsPDU *pdu, s= size_t len) str.data =3D strerror(err); str.size =3D strlen(str.data); =20 - len +=3D pdu_marshal(pdu, len, "s", &str); + ret =3D pdu_marshal(pdu, len, "s", &str); + if (ret < 0) { + goto out_complete; + } + len +=3D ret; id =3D P9_RERROR; } =20 - len +=3D pdu_marshal(pdu, len, "d", err); + ret =3D pdu_marshal(pdu, len, "d", err); + if (ret < 0) { + goto out_complete; + } + len +=3D ret; =20 if (s->proto_version =3D=3D V9FS_PROTO_2000L) { id =3D P9_RLERROR; @@ -656,7 +670,10 @@ static void coroutine_fn pdu_complete(V9fsPDU *pdu, ss= ize_t len) } =20 /* fill out the header */ - pdu_marshal(pdu, 0, "dbw", (int32_t)len, id, pdu->tag); + ret =3D pdu_marshal(pdu, 0, "dbw", (int32_t)len, id, pdu->tag); + if (ret < 0) { + goto out_complete; + } =20 /* keep these in sync */ pdu->size =3D len; @@ -664,6 +681,7 @@ static void coroutine_fn pdu_complete(V9fsPDU *pdu, ssi= ze_t len) =20 pdu->s->transport->push_and_notify(pdu); =20 +out_complete: /* Now wakeup anybody waiting in flush for this request */ if (!qemu_co_queue_next(&pdu->complete)) { pdu_free(pdu); @@ -3593,6 +3611,8 @@ void v9fs_reset(V9fsState *s) while (!data.done) { aio_poll(qemu_get_aio_context(), true); } + + s->transport_broken =3D false; } =20 static void __attribute__((__constructor__)) v9fs_set_fd_limit(void) diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index b7e836251e13..523abdb0a582 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -240,6 +240,7 @@ typedef struct V9fsState Error *migration_blocker; V9fsConf fsconf; V9fsQID root_qid; + bool transport_broken; } V9fsState; =20 /* 9p2000.L open flags */ diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index 873b22baf0f9..6ea9acfc28a9 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -172,8 +172,14 @@ static ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_= t offset, V9fsState *s =3D pdu->s; V9fsVirtioState *v =3D container_of(s, V9fsVirtioState, state); VirtQueueElement *elem =3D v->elems[pdu->idx]; + int ret; =20 - return v9fs_iov_vmarshal(elem->in_sg, elem->in_num, offset, 1, fmt, ap= ); + ret =3D v9fs_iov_vmarshal(elem->in_sg, elem->in_num, offset, 1, fmt, a= p); + if (ret < 0) { + virtio_9p_error(v, pdu->idx, + "Failed to marshal VirtFS reply type %d", pdu->id); + } + return ret; } =20 static ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset, @@ -182,8 +188,14 @@ static ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, siz= e_t offset, V9fsState *s =3D pdu->s; V9fsVirtioState *v =3D container_of(s, V9fsVirtioState, state); VirtQueueElement *elem =3D v->elems[pdu->idx]; + int ret; =20 - return v9fs_iov_vunmarshal(elem->out_sg, elem->out_num, offset, 1, fmt= , ap); + ret =3D v9fs_iov_vunmarshal(elem->out_sg, elem->out_num, offset, 1, fm= t, ap); + if (ret < 0) { + virtio_9p_error(v, pdu->idx, + "Failed to unmarshal VirtFS request type %d", pdu-= >id); + } + return ret; } =20 /* The size parameter is used by other transports. Do not drop it. */