From nobody Sun May 5 12:53:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550498741369352.2516121512331; Mon, 18 Feb 2019 06:05:41 -0800 (PST) Received: from localhost ([127.0.0.1]:59050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjY3-0000gK-UQ for importer@patchew.org; Mon, 18 Feb 2019 09:05:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjWA-00084L-CQ for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:03:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvjW9-0003nG-KO for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:03:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35452) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gvjW4-0003fp-VK; Mon, 18 Feb 2019 09:03:30 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E71EC718A; Mon, 18 Feb 2019 14:03:22 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-116-155.ams2.redhat.com [10.36.116.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 681801024948; Mon, 18 Feb 2019 14:03:16 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Mon, 18 Feb 2019 15:02:52 +0100 Message-Id: <20190218140301.197408-2-sgarzare@redhat.com> In-Reply-To: <20190218140301.197408-1-sgarzare@redhat.com> References: <20190218140301.197408-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 18 Feb 2019 14:03:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 01/10] virtio-blk: add acct_failed param to virtio_blk_handle_rw_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: Kevin Wolf , Laurent Vivier , Thomas Huth , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , "Dr . David Alan Gilbert" , Max Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We add acct_failed param in order to use virtio_blk_handle_rw_error() also when is not required to call block_acct_failed(). (eg. a discard operation is failed) Reviewed-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- hw/block/virtio-blk.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index cf7f47eaba..afedf48ca6 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -65,7 +65,7 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, = unsigned char status) } =20 static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, - bool is_read) + bool is_read, bool acct_failed) { VirtIOBlock *s =3D req->dev; BlockErrorAction action =3D blk_get_error_action(s->blk, is_read, erro= r); @@ -78,7 +78,9 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req= , int error, s->rq =3D req; } else if (action =3D=3D BLOCK_ERROR_ACTION_REPORT) { virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR); - block_acct_failed(blk_get_stats(s->blk), &req->acct); + if (acct_failed) { + block_acct_failed(blk_get_stats(s->blk), &req->acct); + } virtio_blk_free_request(req); } =20 @@ -116,7 +118,7 @@ static void virtio_blk_rw_complete(void *opaque, int re= t) * the memory until the request is completed (which will * happen on the other side of the migration). */ - if (virtio_blk_handle_rw_error(req, -ret, is_read)) { + if (virtio_blk_handle_rw_error(req, -ret, is_read, true)) { continue; } } @@ -135,7 +137,7 @@ static void virtio_blk_flush_complete(void *opaque, int= ret) =20 aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); if (ret) { - if (virtio_blk_handle_rw_error(req, -ret, 0)) { + if (virtio_blk_handle_rw_error(req, -ret, 0, true)) { goto out; } } --=20 2.20.1 From nobody Sun May 5 12:53:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550498754968795.4158625286949; Mon, 18 Feb 2019 06:05:54 -0800 (PST) Received: from localhost ([127.0.0.1]:59066 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjYN-00013u-UW for importer@patchew.org; Mon, 18 Feb 2019 09:05:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjWZ-0008G2-Ep for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:04:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvjWR-0004Ca-JX for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:03:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47802) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gvjW9-0003me-0w; Mon, 18 Feb 2019 09:03:33 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 41E0810F90; Mon, 18 Feb 2019 14:03:32 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-116-155.ams2.redhat.com [10.36.116.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 355F11024948; Mon, 18 Feb 2019 14:03:22 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Mon, 18 Feb 2019 15:02:53 +0100 Message-Id: <20190218140301.197408-3-sgarzare@redhat.com> In-Reply-To: <20190218140301.197408-1-sgarzare@redhat.com> References: <20190218140301.197408-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 18 Feb 2019 14:03:32 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 02/10] virtio-blk: add host_features field in VirtIOBlock 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: Kevin Wolf , Laurent Vivier , Thomas Huth , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , "Dr . David Alan Gilbert" , Max Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Since configurable features for virtio-blk are growing, this patch adds host_features field in the struct VirtIOBlock. (as in virtio-net) In this way, we can avoid to add new fields for new properties and we can directly set VIRTIO_BLK_F* flags in the host_features. We update "config-wce" and "scsi" property definition to use the new host_features field without change the behaviour. Suggested-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi Reviewed-by: Michael S. Tsirkin Signed-off-by: Stefano Garzarella --- hw/block/virtio-blk.c | 16 +++++++++------- include/hw/virtio/virtio-blk.h | 3 +-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index afedf48ca6..7813237756 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -245,7 +245,7 @@ static int virtio_blk_handle_scsi_req(VirtIOBlockReq *r= eq) */ scsi =3D (void *)elem->in_sg[elem->in_num - 2].iov_base; =20 - if (!blk->conf.scsi) { + if (!virtio_has_feature(blk->host_features, VIRTIO_BLK_F_SCSI)) { status =3D VIRTIO_BLK_S_UNSUPP; goto fail; } @@ -785,12 +785,15 @@ static uint64_t virtio_blk_get_features(VirtIODevice = *vdev, uint64_t features, { VirtIOBlock *s =3D VIRTIO_BLK(vdev); =20 + /* Firstly sync all virtio-blk possible supported features */ + features |=3D s->host_features; + virtio_add_feature(&features, VIRTIO_BLK_F_SEG_MAX); virtio_add_feature(&features, VIRTIO_BLK_F_GEOMETRY); virtio_add_feature(&features, VIRTIO_BLK_F_TOPOLOGY); virtio_add_feature(&features, VIRTIO_BLK_F_BLK_SIZE); if (virtio_has_feature(features, VIRTIO_F_VERSION_1)) { - if (s->conf.scsi) { + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_SCSI)) { error_setg(errp, "Please set scsi=3Doff for virtio-blk devices= in order to use virtio 1.0"); return 0; } @@ -799,9 +802,6 @@ static uint64_t virtio_blk_get_features(VirtIODevice *v= dev, uint64_t features, virtio_add_feature(&features, VIRTIO_BLK_F_SCSI); } =20 - if (s->conf.config_wce) { - virtio_add_feature(&features, VIRTIO_BLK_F_CONFIG_WCE); - } if (blk_enable_write_cache(s->blk)) { virtio_add_feature(&features, VIRTIO_BLK_F_WCE); } @@ -1015,9 +1015,11 @@ static Property virtio_blk_properties[] =3D { DEFINE_BLOCK_ERROR_PROPERTIES(VirtIOBlock, conf.conf), DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, conf.conf), DEFINE_PROP_STRING("serial", VirtIOBlock, conf.serial), - DEFINE_PROP_BIT("config-wce", VirtIOBlock, conf.config_wce, 0, true), + DEFINE_PROP_BIT64("config-wce", VirtIOBlock, host_features, + VIRTIO_BLK_F_CONFIG_WCE, true), #ifdef __linux__ - DEFINE_PROP_BIT("scsi", VirtIOBlock, conf.scsi, 0, false), + DEFINE_PROP_BIT64("scsi", VirtIOBlock, host_features, + VIRTIO_BLK_F_SCSI, false), #endif DEFINE_PROP_BIT("request-merging", VirtIOBlock, conf.request_merging, = 0, true), diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 5117431d96..f7345b0511 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -35,8 +35,6 @@ struct VirtIOBlkConf BlockConf conf; IOThread *iothread; char *serial; - uint32_t scsi; - uint32_t config_wce; uint32_t request_merging; uint16_t num_queues; uint16_t queue_size; @@ -57,6 +55,7 @@ typedef struct VirtIOBlock { bool dataplane_disabled; bool dataplane_started; struct VirtIOBlockDataPlane *dataplane; + uint64_t host_features; } VirtIOBlock; =20 typedef struct VirtIOBlockReq { --=20 2.20.1 From nobody Sun May 5 12:53:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155049891457139.44860893582245; Mon, 18 Feb 2019 06:08:34 -0800 (PST) Received: from localhost ([127.0.0.1]:59117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjaw-0003As-Ew for importer@patchew.org; Mon, 18 Feb 2019 09:08:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjWr-0000Ah-Vy for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:04:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvjWq-0004Un-23 for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:04:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60026) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gvjWi-0004QU-U7; Mon, 18 Feb 2019 09:04:09 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E35F213269C; Mon, 18 Feb 2019 14:04:07 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-116-155.ams2.redhat.com [10.36.116.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDBCD1024948; Mon, 18 Feb 2019 14:03:32 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Mon, 18 Feb 2019 15:02:54 +0100 Message-Id: <20190218140301.197408-4-sgarzare@redhat.com> In-Reply-To: <20190218140301.197408-1-sgarzare@redhat.com> References: <20190218140301.197408-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 18 Feb 2019 14:04:07 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 03/10] virtio-blk: add "discard" and "write-zeroes" properties 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: Kevin Wolf , Laurent Vivier , Thomas Huth , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , "Dr . David Alan Gilbert" , Max Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In order to avoid migration issues, we enable DISCARD and WRITE_ZEROES features only for machine type >=3D 4.0 As discussed with Michael S. Tsirkin and Stefan Hajnoczi on the list [1], DISCARD operation should not have security implications (eg. page cache attacks), so we can enable it by default. [1] https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg00504.html Suggested-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- hw/block/virtio-blk.c | 4 ++++ hw/core/machine.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 7813237756..f7cd322811 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1027,6 +1027,10 @@ static Property virtio_blk_properties[] =3D { DEFINE_PROP_UINT16("queue-size", VirtIOBlock, conf.queue_size, 128), DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD, IOThread *), + DEFINE_PROP_BIT64("discard", VirtIOBlock, host_features, + VIRTIO_BLK_F_DISCARD, true), + DEFINE_PROP_BIT64("write-zeroes", VirtIOBlock, host_features, + VIRTIO_BLK_F_WRITE_ZEROES, true), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/core/machine.c b/hw/core/machine.c index 077fbd182a..766ca5899d 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -33,6 +33,8 @@ GlobalProperty hw_compat_3_1[] =3D { { "usb-kbd", "serial", "42" }, { "usb-mouse", "serial", "42" }, { "usb-kbd", "serial", "42" }, + { "virtio-blk-device", "discard", "false" }, + { "virtio-blk-device", "write-zeroes", "false" }, }; const size_t hw_compat_3_1_len =3D G_N_ELEMENTS(hw_compat_3_1); =20 --=20 2.20.1 From nobody Sun May 5 12:53:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550498934277838.7157777027277; Mon, 18 Feb 2019 06:08:54 -0800 (PST) Received: from localhost ([127.0.0.1]:59119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjbH-0003Ul-8H for importer@patchew.org; Mon, 18 Feb 2019 09:08:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59434) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjXM-0000Yg-PY for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:04:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvjXF-0004ec-Pg for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:04:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36636) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gvjX3-0004ZK-3r; Mon, 18 Feb 2019 09:04:30 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B1FBAC7C0F; Mon, 18 Feb 2019 14:04:26 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-116-155.ams2.redhat.com [10.36.116.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A47D1001F52; Mon, 18 Feb 2019 14:04:08 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Mon, 18 Feb 2019 15:02:55 +0100 Message-Id: <20190218140301.197408-5-sgarzare@redhat.com> In-Reply-To: <20190218140301.197408-1-sgarzare@redhat.com> References: <20190218140301.197408-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 18 Feb 2019 14:04:26 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 04/10] virtio-net: make VirtIOFeature usable for other virtio devices 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: Kevin Wolf , Laurent Vivier , Thomas Huth , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , "Dr . David Alan Gilbert" , Max Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In order to use VirtIOFeature also in other virtio devices, we move its declaration and the endof() macro (renamed in virtio_endof()) in virtio.h. We add virtio_feature_get_config_size() function to iterate the array of VirtIOFeature and to return the config size depending on the features enabled. (as virtio_net_set_config_size() did) Suggested-by: Michael S. Tsirkin Signed-off-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi --- hw/net/virtio-net.c | 31 +++++++------------------------ hw/virtio/virtio.c | 15 +++++++++++++++ include/hw/virtio/virtio.h | 15 +++++++++++++++ 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 3f319ef723..6e6b146022 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -82,29 +82,17 @@ static inline __virtio16 *virtio_net_rsc_ext_num_dupack= s( =20 #endif =20 -/* - * Calculate the number of bytes up to and including the given 'field' of - * 'container'. - */ -#define endof(container, field) \ - (offsetof(container, field) + sizeof_field(container, field)) - -typedef struct VirtIOFeature { - uint64_t flags; - size_t end; -} VirtIOFeature; - static VirtIOFeature feature_sizes[] =3D { {.flags =3D 1ULL << VIRTIO_NET_F_MAC, - .end =3D endof(struct virtio_net_config, mac)}, + .end =3D virtio_endof(struct virtio_net_config, mac)}, {.flags =3D 1ULL << VIRTIO_NET_F_STATUS, - .end =3D endof(struct virtio_net_config, status)}, + .end =3D virtio_endof(struct virtio_net_config, status)}, {.flags =3D 1ULL << VIRTIO_NET_F_MQ, - .end =3D endof(struct virtio_net_config, max_virtqueue_pairs)}, + .end =3D virtio_endof(struct virtio_net_config, max_virtqueue_pairs)}, {.flags =3D 1ULL << VIRTIO_NET_F_MTU, - .end =3D endof(struct virtio_net_config, mtu)}, + .end =3D virtio_endof(struct virtio_net_config, mtu)}, {.flags =3D 1ULL << VIRTIO_NET_F_SPEED_DUPLEX, - .end =3D endof(struct virtio_net_config, duplex)}, + .end =3D virtio_endof(struct virtio_net_config, duplex)}, {} }; =20 @@ -2580,15 +2568,10 @@ static void virtio_net_guest_notifier_mask(VirtIODe= vice *vdev, int idx, =20 static void virtio_net_set_config_size(VirtIONet *n, uint64_t host_feature= s) { - int i, config_size =3D 0; virtio_add_feature(&host_features, VIRTIO_NET_F_MAC); =20 - for (i =3D 0; feature_sizes[i].flags !=3D 0; i++) { - if (host_features & feature_sizes[i].flags) { - config_size =3D MAX(feature_sizes[i].end, config_size); - } - } - n->config_size =3D config_size; + n->config_size =3D virtio_feature_get_config_size(feature_sizes, + host_features); } =20 void virtio_net_set_netclient_name(VirtIONet *n, const char *name, diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index a1ff647a66..2626a895cb 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2036,6 +2036,21 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t= val) return ret; } =20 +size_t virtio_feature_get_config_size(VirtIOFeature *feature_sizes, + uint64_t host_features) +{ + size_t config_size =3D 0; + int i; + + for (i =3D 0; feature_sizes[i].flags !=3D 0; i++) { + if (host_features & feature_sizes[i].flags) { + config_size =3D MAX(feature_sizes[i].end, config_size); + } + } + + return config_size; +} + int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) { int i, ret; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 9c1fa07d6d..ce9516236a 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -37,6 +37,21 @@ static inline hwaddr vring_align(hwaddr addr, return QEMU_ALIGN_UP(addr, align); } =20 +/* + * Calculate the number of bytes up to and including the given 'field' of + * 'container'. + */ +#define virtio_endof(container, field) \ + (offsetof(container, field) + sizeof_field(container, field)) + +typedef struct VirtIOFeature { + uint64_t flags; + size_t end; +} VirtIOFeature; + +size_t virtio_feature_get_config_size(VirtIOFeature *features, + uint64_t host_features); + typedef struct VirtQueue VirtQueue; =20 #define VIRTQUEUE_MAX_SIZE 1024 --=20 2.20.1 From nobody Sun May 5 12:53:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550499120666293.05155445393405; Mon, 18 Feb 2019 06:12:00 -0800 (PST) Received: from localhost ([127.0.0.1]:59178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjeD-0006IO-Ig for importer@patchew.org; Mon, 18 Feb 2019 09:11:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59651) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjXz-00019P-1A for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:05:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvjXy-00055N-0X for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:05:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44656) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gvjXv-00052t-JD; Mon, 18 Feb 2019 09:05:23 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BFA18A77F; Mon, 18 Feb 2019 14:05:22 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-116-155.ams2.redhat.com [10.36.116.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E4321001F52; Mon, 18 Feb 2019 14:04:26 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Mon, 18 Feb 2019 15:02:56 +0100 Message-Id: <20190218140301.197408-6-sgarzare@redhat.com> In-Reply-To: <20190218140301.197408-1-sgarzare@redhat.com> References: <20190218140301.197408-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 18 Feb 2019 14:05:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 05/10] virtio-blk: set config size depending on the features enabled 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: Kevin Wolf , Laurent Vivier , Thomas Huth , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , "Dr . David Alan Gilbert" , Max Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Starting from DISABLE and WRITE_ZEROES features, we use an array of VirtIOFeature (as virtio-net) to properly set the config size depending on the features enabled. Signed-off-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi --- hw/block/virtio-blk.c | 31 +++++++++++++++++++++++++------ include/hw/virtio/virtio-blk.h | 1 + 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index f7cd322811..8798d13bc4 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -28,9 +28,28 @@ #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" =20 -/* We don't support discard yet, hide associated config fields. */ +/* Config size before the discard support (hide associated config fields) = */ #define VIRTIO_BLK_CFG_SIZE offsetof(struct virtio_blk_config, \ max_discard_sectors) +/* + * Starting from the discard feature, we can use this array to properly + * set the config size depending on the features enabled. + */ +static VirtIOFeature feature_sizes[] =3D { + {.flags =3D 1ULL << VIRTIO_BLK_F_DISCARD, + .end =3D virtio_endof(struct virtio_blk_config, discard_sector_alignm= ent)}, + {.flags =3D 1ULL << VIRTIO_BLK_F_WRITE_ZEROES, + .end =3D virtio_endof(struct virtio_blk_config, write_zeroes_may_unma= p)}, + {} +}; + +static void virtio_blk_set_config_size(VirtIOBlock *s, uint64_t host_featu= res) +{ + s->config_size =3D MAX(VIRTIO_BLK_CFG_SIZE, + virtio_feature_get_config_size(feature_sizes, host_features)); + + assert(s->config_size <=3D sizeof(struct virtio_blk_config)); +} =20 static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq, VirtIOBlockReq *req) @@ -763,8 +782,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev= , uint8_t *config) blkcfg.alignment_offset =3D 0; blkcfg.wce =3D blk_enable_write_cache(s->blk); virtio_stw_p(vdev, &blkcfg.num_queues, s->conf.num_queues); - memcpy(config, &blkcfg, VIRTIO_BLK_CFG_SIZE); - QEMU_BUILD_BUG_ON(VIRTIO_BLK_CFG_SIZE > sizeof(blkcfg)); + memcpy(config, &blkcfg, s->config_size); } =20 static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *confi= g) @@ -772,8 +790,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev, c= onst uint8_t *config) VirtIOBlock *s =3D VIRTIO_BLK(vdev); struct virtio_blk_config blkcfg; =20 - memcpy(&blkcfg, config, VIRTIO_BLK_CFG_SIZE); - QEMU_BUILD_BUG_ON(VIRTIO_BLK_CFG_SIZE > sizeof(blkcfg)); + memcpy(&blkcfg, config, s->config_size); =20 aio_context_acquire(blk_get_aio_context(s->blk)); blk_set_enable_write_cache(s->blk, blkcfg.wce !=3D 0); @@ -956,7 +973,9 @@ static void virtio_blk_device_realize(DeviceState *dev,= Error **errp) return; } =20 - virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, VIRTIO_BLK_CFG_SIZE); + virtio_blk_set_config_size(s, s->host_features); + + virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, s->config_size); =20 s->blk =3D conf->conf.blk; s->rq =3D NULL; diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index f7345b0511..7877ae67ae 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -56,6 +56,7 @@ typedef struct VirtIOBlock { bool dataplane_started; struct VirtIOBlockDataPlane *dataplane; uint64_t host_features; + size_t config_size; } VirtIOBlock; =20 typedef struct VirtIOBlockReq { --=20 2.20.1 From nobody Sun May 5 12:53:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550498965007615.2102156693516; Mon, 18 Feb 2019 06:09:25 -0800 (PST) Received: from localhost ([127.0.0.1]:59121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjbk-0003qu-P9 for importer@patchew.org; Mon, 18 Feb 2019 09:09:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjYY-0001cB-A5 for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:06:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvjYV-0005KH-UI for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:06:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60820) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gvjYL-0005Ay-Bu; Mon, 18 Feb 2019 09:05:49 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 476D87A481; Mon, 18 Feb 2019 14:05:40 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-116-155.ams2.redhat.com [10.36.116.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 012431001F52; Mon, 18 Feb 2019 14:05:22 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Mon, 18 Feb 2019 15:02:57 +0100 Message-Id: <20190218140301.197408-7-sgarzare@redhat.com> In-Reply-To: <20190218140301.197408-1-sgarzare@redhat.com> References: <20190218140301.197408-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 18 Feb 2019 14:05:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 06/10] virtio-blk: add DISCARD and WRITE_ZEROES features 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: Kevin Wolf , Laurent Vivier , Thomas Huth , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , "Dr . David Alan Gilbert" , Max Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This patch adds the support of DISCARD and WRITE_ZEROES commands, that have been introduced in the virtio-blk protocol to have better performance when using SSD backend. We support only one segment per request since multiple segments are not widely used and there are no userspace APIs that allow applications to submit multiple segments in a single call. Reviewed-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- hw/block/virtio-blk.c | 184 +++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-blk.h | 2 + 2 files changed, 186 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 8798d13bc4..c159a3d5f7 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -169,6 +169,30 @@ out: aio_context_release(blk_get_aio_context(s->conf.conf.blk)); } =20 +static void virtio_blk_discard_write_zeroes_complete(void *opaque, int ret) +{ + VirtIOBlockReq *req =3D opaque; + VirtIOBlock *s =3D req->dev; + bool is_write_zeroes =3D (virtio_ldl_p(VIRTIO_DEVICE(s), &req->out.typ= e) & + ~VIRTIO_BLK_T_BARRIER) =3D=3D VIRTIO_BLK_T_WRI= TE_ZEROES; + + aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); + if (ret) { + if (virtio_blk_handle_rw_error(req, -ret, false, is_write_zeroes))= { + goto out; + } + } + + virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); + if (is_write_zeroes) { + block_acct_done(blk_get_stats(s->blk), &req->acct); + } + virtio_blk_free_request(req); + +out: + aio_context_release(blk_get_aio_context(s->conf.conf.blk)); +} + #ifdef __linux__ =20 typedef struct { @@ -502,6 +526,84 @@ static bool virtio_blk_sect_range_ok(VirtIOBlock *dev, return true; } =20 +static uint8_t virtio_blk_handle_discard_write_zeroes(VirtIOBlockReq *req, + struct virtio_blk_discard_write_zeroes *dwz_hdr, bool is_write_zeroes) +{ + VirtIOBlock *s =3D req->dev; + VirtIODevice *vdev =3D VIRTIO_DEVICE(s); + uint64_t sector; + uint32_t num_sectors, flags, max_sectors; + uint8_t err_status; + int bytes; + + sector =3D virtio_ldq_p(vdev, &dwz_hdr->sector); + num_sectors =3D virtio_ldl_p(vdev, &dwz_hdr->num_sectors); + flags =3D virtio_ldl_p(vdev, &dwz_hdr->flags); + max_sectors =3D is_write_zeroes ? s->conf.max_write_zeroes_sectors : + s->conf.max_discard_sectors; + + /* + * max_sectors is at most BDRV_REQUEST_MAX_SECTORS, this check + * make us sure that "num_sectors << BDRV_SECTOR_BITS" can fit in + * the integer variable. + */ + if (unlikely(num_sectors > max_sectors)) { + err_status =3D VIRTIO_BLK_S_IOERR; + goto err; + } + + bytes =3D num_sectors << BDRV_SECTOR_BITS; + + if (unlikely(!virtio_blk_sect_range_ok(s, sector, bytes))) { + err_status =3D VIRTIO_BLK_S_IOERR; + goto err; + } + + /* + * The device MUST set the status byte to VIRTIO_BLK_S_UNSUPP for disc= ard + * and write zeroes commands if any unknown flag is set. + */ + if (unlikely(flags & ~VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP)) { + err_status =3D VIRTIO_BLK_S_UNSUPP; + goto err; + } + + if (is_write_zeroes) { /* VIRTIO_BLK_T_WRITE_ZEROES */ + int blk_aio_flags =3D 0; + + if (flags & VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP) { + blk_aio_flags |=3D BDRV_REQ_MAY_UNMAP; + } + + block_acct_start(blk_get_stats(s->blk), &req->acct, bytes, + BLOCK_ACCT_WRITE); + + blk_aio_pwrite_zeroes(s->blk, sector << BDRV_SECTOR_BITS, + bytes, blk_aio_flags, + virtio_blk_discard_write_zeroes_complete, re= q); + } else { /* VIRTIO_BLK_T_DISCARD */ + /* + * The device MUST set the status byte to VIRTIO_BLK_S_UNSUPP for + * discard commands if the unmap flag is set. + */ + if (unlikely(flags & VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP)) { + err_status =3D VIRTIO_BLK_S_UNSUPP; + goto err; + } + + blk_aio_pdiscard(s->blk, sector << BDRV_SECTOR_BITS, bytes, + virtio_blk_discard_write_zeroes_complete, req); + } + + return VIRTIO_BLK_S_OK; + +err: + if (is_write_zeroes) { + block_acct_invalid(blk_get_stats(s->blk), BLOCK_ACCT_WRITE); + } + return err_status; +} + static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *= mrb) { uint32_t type; @@ -603,6 +705,47 @@ static int virtio_blk_handle_request(VirtIOBlockReq *r= eq, MultiReqBuffer *mrb) virtio_blk_free_request(req); break; } + /* + * VIRTIO_BLK_T_DISCARD and VIRTIO_BLK_T_WRITE_ZEROES are defined with + * VIRTIO_BLK_T_OUT flag set. We masked this flag in the switch statem= ent, + * so we must mask it for these requests, then we will check if it is = set. + */ + case VIRTIO_BLK_T_DISCARD & ~VIRTIO_BLK_T_OUT: + case VIRTIO_BLK_T_WRITE_ZEROES & ~VIRTIO_BLK_T_OUT: + { + struct virtio_blk_discard_write_zeroes dwz_hdr; + size_t out_len =3D iov_size(out_iov, out_num); + bool is_write_zeroes =3D (type & ~VIRTIO_BLK_T_BARRIER) =3D=3D + VIRTIO_BLK_T_WRITE_ZEROES; + uint8_t err_status; + + /* + * Unsupported if VIRTIO_BLK_T_OUT is not set or the request conta= ins + * more than one segment. + */ + if (unlikely(!(type & VIRTIO_BLK_T_OUT) || + out_len > sizeof(dwz_hdr))) { + virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP); + virtio_blk_free_request(req); + return 0; + } + + if (unlikely(iov_to_buf(out_iov, out_num, 0, &dwz_hdr, + sizeof(dwz_hdr)) !=3D sizeof(dwz_hdr))) { + virtio_error(vdev, "virtio-blk discard/write_zeroes header" + " too short"); + return -1; + } + + err_status =3D virtio_blk_handle_discard_write_zeroes(req, &dwz_hd= r, + is_write_zeroe= s); + if (err_status !=3D VIRTIO_BLK_S_OK) { + virtio_blk_req_complete(req, err_status); + virtio_blk_free_request(req); + } + + break; + } default: virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP); virtio_blk_free_request(req); @@ -782,6 +925,24 @@ static void virtio_blk_update_config(VirtIODevice *vde= v, uint8_t *config) blkcfg.alignment_offset =3D 0; blkcfg.wce =3D blk_enable_write_cache(s->blk); virtio_stw_p(vdev, &blkcfg.num_queues, s->conf.num_queues); + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_DISCARD)) { + virtio_stl_p(vdev, &blkcfg.max_discard_sectors, + s->conf.max_discard_sectors); + virtio_stl_p(vdev, &blkcfg.discard_sector_alignment, + blk_size >> BDRV_SECTOR_BITS); + /* + * We support only one segment per request since multiple segments + * are not widely used and there are no userspace APIs that allow + * applications to submit multiple segments in a single call. + */ + virtio_stl_p(vdev, &blkcfg.max_discard_seg, 1); + } + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_WRITE_ZEROES)) { + virtio_stl_p(vdev, &blkcfg.max_write_zeroes_sectors, + s->conf.max_write_zeroes_sectors); + blkcfg.write_zeroes_may_unmap =3D 1; + virtio_stl_p(vdev, &blkcfg.max_write_zeroes_seg, 1); + } memcpy(config, &blkcfg, s->config_size); } =20 @@ -973,6 +1134,25 @@ static void virtio_blk_device_realize(DeviceState *de= v, Error **errp) return; } =20 + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_DISCARD) && + (!conf->max_discard_sectors || + conf->max_discard_sectors > BDRV_REQUEST_MAX_SECTORS)) { + error_setg(errp, "invalid max-discard-sectors property (%" PRIu32 = ")" + ", must be between 1 and %d", + conf->max_discard_sectors, (int)BDRV_REQUEST_MAX_SECTOR= S); + return; + } + + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_WRITE_ZEROES) && + (!conf->max_write_zeroes_sectors || + conf->max_write_zeroes_sectors > BDRV_REQUEST_MAX_SECTORS)) { + error_setg(errp, "invalid max-write-zeroes-sectors property (%" PR= Iu32 + "), must be between 1 and %d", + conf->max_write_zeroes_sectors, + (int)BDRV_REQUEST_MAX_SECTORS); + return; + } + virtio_blk_set_config_size(s, s->host_features); =20 virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, s->config_size); @@ -1050,6 +1230,10 @@ static Property virtio_blk_properties[] =3D { VIRTIO_BLK_F_DISCARD, true), DEFINE_PROP_BIT64("write-zeroes", VirtIOBlock, host_features, VIRTIO_BLK_F_WRITE_ZEROES, true), + DEFINE_PROP_UINT32("max-discard-sectors", VirtIOBlock, + conf.max_discard_sectors, BDRV_REQUEST_MAX_SECTORS), + DEFINE_PROP_UINT32("max-write-zeroes-sectors", VirtIOBlock, + conf.max_write_zeroes_sectors, BDRV_REQUEST_MAX_SEC= TORS), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 7877ae67ae..cddcfbebe9 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -38,6 +38,8 @@ struct VirtIOBlkConf uint32_t request_merging; uint16_t num_queues; uint16_t queue_size; + uint32_t max_discard_sectors; + uint32_t max_write_zeroes_sectors; }; =20 struct VirtIOBlockDataPlane; --=20 2.20.1 From nobody Sun May 5 12:53:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550498898709778.6922841275006; Mon, 18 Feb 2019 06:08:18 -0800 (PST) Received: from localhost ([127.0.0.1]:59115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjag-0002zY-IQ for importer@patchew.org; Mon, 18 Feb 2019 09:08:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjYT-0001Xa-U8 for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:05:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvjYS-0005I3-0q for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:05:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55504) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gvjYP-0005FP-HE; Mon, 18 Feb 2019 09:05:53 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B6FA57AEBB; Mon, 18 Feb 2019 14:05:52 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-116-155.ams2.redhat.com [10.36.116.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE6501001F52; Mon, 18 Feb 2019 14:05:40 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Mon, 18 Feb 2019 15:02:58 +0100 Message-Id: <20190218140301.197408-8-sgarzare@redhat.com> In-Reply-To: <20190218140301.197408-1-sgarzare@redhat.com> References: <20190218140301.197408-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 18 Feb 2019 14:05:52 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 07/10] tests/virtio-blk: change assert on data_size in virtio_blk_request() 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: Kevin Wolf , Laurent Vivier , Thomas Huth , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , "Dr . David Alan Gilbert" , Max Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The size of data in the virtio_blk_request must be a multiple of 512 bytes for IN and OUT requests, or a multiple of the size of struct virtio_blk_discard_write_zeroes for DISCARD and WRITE_ZEROES requests. Reviewed-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi Reviewed-by: Thomas Huth Signed-off-by: Stefano Garzarella --- tests/virtio-blk-test.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 04c608764b..0739498da7 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -144,7 +144,20 @@ static uint64_t virtio_blk_request(QGuestAllocator *al= loc, QVirtioDevice *d, uint64_t addr; uint8_t status =3D 0xFF; =20 - g_assert_cmpuint(data_size % 512, =3D=3D, 0); + switch (req->type) { + case VIRTIO_BLK_T_IN: + case VIRTIO_BLK_T_OUT: + g_assert_cmpuint(data_size % 512, =3D=3D, 0); + break; + case VIRTIO_BLK_T_DISCARD: + case VIRTIO_BLK_T_WRITE_ZEROES: + g_assert_cmpuint(data_size % + sizeof(struct virtio_blk_discard_write_zeroes), = =3D=3D, 0); + break; + default: + g_assert_cmpuint(data_size, =3D=3D, 0); + } + addr =3D guest_alloc(alloc, sizeof(*req) + data_size); =20 virtio_blk_fix_request(d, req); --=20 2.20.1 From nobody Sun May 5 12:53:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550499130990716.0475365661014; Mon, 18 Feb 2019 06:12:10 -0800 (PST) Received: from localhost ([127.0.0.1]:59182 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjeR-0006VQ-Sm for importer@patchew.org; Mon, 18 Feb 2019 09:12:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjYk-0001o4-6b for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:06:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvjYj-0005Pc-04 for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:06:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51486) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gvjYW-0005Jw-3I; Mon, 18 Feb 2019 09:06:00 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A0CCC0C0546; Mon, 18 Feb 2019 14:05:59 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-116-155.ams2.redhat.com [10.36.116.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51FF71001F52; Mon, 18 Feb 2019 14:05:52 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Mon, 18 Feb 2019 15:02:59 +0100 Message-Id: <20190218140301.197408-9-sgarzare@redhat.com> In-Reply-To: <20190218140301.197408-1-sgarzare@redhat.com> References: <20190218140301.197408-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 18 Feb 2019 14:05:59 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 08/10] tests/virtio-blk: add virtio_blk_fix_dwz_hdr() function 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: Kevin Wolf , Laurent Vivier , Thomas Huth , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , "Dr . David Alan Gilbert" , Max Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This function is useful to fix the endianness of struct virtio_blk_discard_write_zeroes headers. Signed-off-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi --- tests/virtio-blk-test.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 0739498da7..b51c4f2697 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -46,6 +46,12 @@ typedef struct QVirtioBlkReq { uint8_t status; } QVirtioBlkReq; =20 +#ifdef HOST_WORDS_BIGENDIAN +const bool host_is_big_endian =3D true; +#else +const bool host_is_big_endian =3D false; +#endif + static char *drive_create(void) { int fd, ret; @@ -125,12 +131,6 @@ static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *= bus, int slot) =20 static inline void virtio_blk_fix_request(QVirtioDevice *d, QVirtioBlkReq = *req) { -#ifdef HOST_WORDS_BIGENDIAN - const bool host_is_big_endian =3D true; -#else - const bool host_is_big_endian =3D false; -#endif - if (qvirtio_is_big_endian(d) !=3D host_is_big_endian) { req->type =3D bswap32(req->type); req->ioprio =3D bswap32(req->ioprio); @@ -138,6 +138,17 @@ static inline void virtio_blk_fix_request(QVirtioDevic= e *d, QVirtioBlkReq *req) } } =20 + +static inline void virtio_blk_fix_dwz_hdr(QVirtioDevice *d, + struct virtio_blk_discard_write_zeroes *dwz_hdr) +{ + if (qvirtio_is_big_endian(d) !=3D host_is_big_endian) { + dwz_hdr->sector =3D bswap64(dwz_hdr->sector); + dwz_hdr->num_sectors =3D bswap32(dwz_hdr->num_sectors); + dwz_hdr->flags =3D bswap32(dwz_hdr->flags); + } +} + static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice *= d, QVirtioBlkReq *req, uint64_t data_size) { --=20 2.20.1 From nobody Sun May 5 12:53:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550500200073432.3828444875696; Mon, 18 Feb 2019 06:30:00 -0800 (PST) Received: from localhost ([127.0.0.1]:59434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjvh-00045l-22 for importer@patchew.org; Mon, 18 Feb 2019 09:29:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjZ0-00024L-Aw for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:06:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvjYu-0005Wd-PS for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:06:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37906) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gvjYk-0005N6-6a; Mon, 18 Feb 2019 09:06:16 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3882356C4; Mon, 18 Feb 2019 14:06:05 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-116-155.ams2.redhat.com [10.36.116.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD8601024948; Mon, 18 Feb 2019 14:05:59 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Mon, 18 Feb 2019 15:03:00 +0100 Message-Id: <20190218140301.197408-10-sgarzare@redhat.com> In-Reply-To: <20190218140301.197408-1-sgarzare@redhat.com> References: <20190218140301.197408-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 18 Feb 2019 14:06:05 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 09/10] tests/virtio-blk: add test for WRITE_ZEROES command 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: Kevin Wolf , Laurent Vivier , Thomas Huth , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , "Dr . David Alan Gilbert" , Max Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If the WRITE_ZEROES feature is enabled, we check this command in the test_basic(). Reviewed-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi Acked-by: Thomas Huth Signed-off-by: Stefano Garzarella --- tests/virtio-blk-test.c | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index b51c4f2697..cfc560be46 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -255,6 +255,68 @@ static void test_basic(QVirtioDevice *dev, QGuestAlloc= ator *alloc, =20 guest_free(alloc, req_addr); =20 + if (features & (1u << VIRTIO_BLK_F_WRITE_ZEROES)) { + struct virtio_blk_discard_write_zeroes dwz_hdr; + void *expected; + + /* + * WRITE_ZEROES request on the same sector of previous test where + * we wrote "TEST". + */ + req.type =3D VIRTIO_BLK_T_WRITE_ZEROES; + req.data =3D (char *) &dwz_hdr; + dwz_hdr.sector =3D 0; + dwz_hdr.num_sectors =3D 1; + dwz_hdr.flags =3D 0; + + virtio_blk_fix_dwz_hdr(dev, &dwz_hdr); + + req_addr =3D virtio_blk_request(alloc, dev, &req, sizeof(dwz_hdr)); + + free_head =3D qvirtqueue_add(vq, req_addr, 16, false, true); + qvirtqueue_add(vq, req_addr + 16, sizeof(dwz_hdr), false, true); + qvirtqueue_add(vq, req_addr + 16 + sizeof(dwz_hdr), 1, true, false= ); + + qvirtqueue_kick(dev, vq, free_head); + + qvirtio_wait_used_elem(dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status =3D readb(req_addr + 16 + sizeof(dwz_hdr)); + g_assert_cmpint(status, =3D=3D, 0); + + guest_free(alloc, req_addr); + + /* Read request to check if the sector contains all zeroes */ + req.type =3D VIRTIO_BLK_T_IN; + req.ioprio =3D 1; + req.sector =3D 0; + req.data =3D g_malloc0(512); + + req_addr =3D virtio_blk_request(alloc, dev, &req, 512); + + g_free(req.data); + + free_head =3D qvirtqueue_add(vq, req_addr, 16, false, true); + qvirtqueue_add(vq, req_addr + 16, 512, true, true); + qvirtqueue_add(vq, req_addr + 528, 1, true, false); + + qvirtqueue_kick(dev, vq, free_head); + + qvirtio_wait_used_elem(dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status =3D readb(req_addr + 528); + g_assert_cmpint(status, =3D=3D, 0); + + data =3D g_malloc(512); + expected =3D g_malloc0(512); + memread(req_addr + 16, data, 512); + g_assert_cmpmem(data, 512, expected, 512); + g_free(expected); + g_free(data); + + guest_free(alloc, req_addr); + } + if (features & (1u << VIRTIO_F_ANY_LAYOUT)) { /* Write and read with 2 descriptor layout */ /* Write request */ --=20 2.20.1 From nobody Sun May 5 12:53:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550499798975781.0372808129831; Mon, 18 Feb 2019 06:23:18 -0800 (PST) Received: from localhost ([127.0.0.1]:59340 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjp4-0006pR-9B for importer@patchew.org; Mon, 18 Feb 2019 09:23:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjZ2-00026T-AG for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:06:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvjZ0-0005am-AF for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:06:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45580) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gvjYm-0005Oc-LH; Mon, 18 Feb 2019 09:06:16 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3243C315D3F; Mon, 18 Feb 2019 14:06:10 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-116-155.ams2.redhat.com [10.36.116.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 415651001F52; Mon, 18 Feb 2019 14:06:06 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Mon, 18 Feb 2019 15:03:01 +0100 Message-Id: <20190218140301.197408-11-sgarzare@redhat.com> In-Reply-To: <20190218140301.197408-1-sgarzare@redhat.com> References: <20190218140301.197408-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 18 Feb 2019 14:06:10 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 10/10] tests/virtio-blk: add test for DISCARD command 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: Kevin Wolf , Laurent Vivier , Thomas Huth , Eduardo Habkost , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , "Dr . David Alan Gilbert" , Max Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If the DISCARD feature is enabled, we try this command in the test_basic(), checking only the status returned by the request. Signed-off-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi --- tests/virtio-blk-test.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index cfc560be46..0bdbee32ba 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -317,6 +317,33 @@ static void test_basic(QVirtioDevice *dev, QGuestAlloc= ator *alloc, guest_free(alloc, req_addr); } =20 + if (features & (1u << VIRTIO_BLK_F_DISCARD)) { + struct virtio_blk_discard_write_zeroes dwz_hdr; + + req.type =3D VIRTIO_BLK_T_DISCARD; + req.data =3D (char *) &dwz_hdr; + dwz_hdr.sector =3D 0; + dwz_hdr.num_sectors =3D 1; + dwz_hdr.flags =3D 0; + + virtio_blk_fix_dwz_hdr(dev, &dwz_hdr); + + req_addr =3D virtio_blk_request(alloc, dev, &req, sizeof(dwz_hdr)); + + free_head =3D qvirtqueue_add(vq, req_addr, 16, false, true); + qvirtqueue_add(vq, req_addr + 16, sizeof(dwz_hdr), false, true); + qvirtqueue_add(vq, req_addr + 16 + sizeof(dwz_hdr), 1, true, false= ); + + qvirtqueue_kick(dev, vq, free_head); + + qvirtio_wait_used_elem(dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status =3D readb(req_addr + 16 + sizeof(dwz_hdr)); + g_assert_cmpint(status, =3D=3D, 0); + + guest_free(alloc, req_addr); + } + if (features & (1u << VIRTIO_F_ANY_LAYOUT)) { /* Write and read with 2 descriptor layout */ /* Write request */ --=20 2.20.1