From nobody Sat May 18 07:31:20 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619717194; cv=none; d=zohomail.com; s=zohoarc; b=QTwmTdbcui8j3bCeBeYn3vqrRR1yM9HKyyU4E8pfpYr8LLykLyquiLjyfdZ3PsFbyzxWaaaYBz2rnQ+byW9TNkOUjT8tJ3jtL7vNUBRI6HG9WE2o1MZmvmg7zlsVRbm/GcTPzjJByafBSCZccrWnPyCCa003MLjZIUPkc6qc2Vw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619717194; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JRCZ+OkAL0MNi9+mor7gUuEI2CMuTLhxg1pXiS/3Ik4=; b=MkQIBT3fObn4lVFxvJlcRAvi+gL8GLPzoLNsfNdDCw/fyZHqc93sF3NTVQXw4qOluonCkfE0+KdAGt+O4qmfYArezDcfyJdm9WGpRc4hmU0+6PMxTFZUqEReY6Grg5UbV+uItcnFlDoF/f952insy4ViUTaz841k+acFqhgvcIM= 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 1619717194720484.99070402639506; Thu, 29 Apr 2021 10:26:34 -0700 (PDT) Received: from localhost ([::1]:34066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcAQr-0001kL-CL for importer@patchew.org; Thu, 29 Apr 2021 13:26:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59980) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcAEP-0000z5-Vt for qemu-devel@nongnu.org; Thu, 29 Apr 2021 13:13:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60196) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcAEA-0001HI-LO for qemu-devel@nongnu.org; Thu, 29 Apr 2021 13:13:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-601-GzmMDsADPXuk3z5WdKWLSQ-1; Thu, 29 Apr 2021 13:13:22 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 07B471006C83; Thu, 29 Apr 2021 17:13:21 +0000 (UTC) Received: from merkur.redhat.com (ovpn-114-217.ams2.redhat.com [10.36.114.217]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC1E5100164C; Thu, 29 Apr 2021 17:13:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619716405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JRCZ+OkAL0MNi9+mor7gUuEI2CMuTLhxg1pXiS/3Ik4=; b=bS4ETIe8qjlTd3oLO0s5+squoKqUMo8fKN8yuKqVrA0rgWemQYr4nmQX7MQ0gxQoITejzd uzFy36OsrcrLQMMrvPzGa2lMTWq354gPKJiKtWzYbfZvxXjvKUbE/YSVEQINiB1E8XZyVG 6gAhdF7shqCyHywpx+RHfAUMCBezBn4= X-MC-Unique: GzmMDsADPXuk3z5WdKWLSQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 1/6] vhost-user-blk: Make sure to set Error on realize failure Date: Thu, 29 Apr 2021 19:13:11 +0200 Message-Id: <20210429171316.162022-2-kwolf@redhat.com> In-Reply-To: <20210429171316.162022-1-kwolf@redhat.com> References: <20210429171316.162022-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: kwolf@redhat.com, den-plotnikov@yandex-team.ru, mst@redhat.com, qemu-devel@nongnu.org, raphael.norwitz@nutanix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We have to set errp before jumping to virtio_err, otherwise the caller (virtio_device_realize()) will take this as success and crash when it later tries to access things that we've already freed in the error path. Fixes: 77542d431491788d1e8e79d93ce10172ef207775 Signed-off-by: Kevin Wolf Acked-by: Raphael Norwitz Reviewed-by: Eric Blake Reviewed-by: Michael S. Tsirkin --- hw/block/vhost-user-blk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index f5e9682703..7c85248a7b 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -447,7 +447,6 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserBlk *s =3D VHOST_USER_BLK(vdev); - Error *err =3D NULL; int i, ret; =20 if (!s->chardev.chr) { @@ -495,8 +494,7 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) NULL, true); =20 reconnect: - if (qemu_chr_fe_wait_connected(&s->chardev, &err) < 0) { - error_report_err(err); + if (qemu_chr_fe_wait_connected(&s->chardev, errp) < 0) { goto virtio_err; } =20 --=20 2.30.2 From nobody Sat May 18 07:31:20 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619717042; cv=none; d=zohomail.com; s=zohoarc; b=Pl/V8RAxje4amIh9StZKgNxOdEOyTBWmP9psAIj8gj1eYxkNxq4EzW0bNqD06mGFhbhv1749hEeG4Q/weI7PubdpxxU95Ah6ReYyVZfdqLWVXZHWLVsIUPtzlNrNFooi21sN5Ytt0TePLLzsj/i/LllNw/nyyEWb/M0XqxmfanQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619717042; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=s7yPffZPDNbb+3hA2vDQLYKmtn+ChMX0L/tBZxf+i5E=; b=Csx2zc86f4+cOevthgN+IvTEBIoaxURUS4J4ocTdr/HX4xsamBVY0qcS16f0FvgbzvowVpg0rwk7K5BMQB7nLfPFUvlkPV/V2nL+9nymxHbVTjM6hQwq8/xQS6lH8E0ziF1LpLR5Okdvh4z2YutIxtfRld0pUmNL3m2kgs2nYSs= 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 1619717042967162.31210952690276; Thu, 29 Apr 2021 10:24:02 -0700 (PDT) Received: from localhost ([::1]:55838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcAOP-0007Sj-P3 for importer@patchew.org; Thu, 29 Apr 2021 13:24:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcAEK-0000xy-HU for qemu-devel@nongnu.org; Thu, 29 Apr 2021 13:13:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48229) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcAEA-0001Ha-8m for qemu-devel@nongnu.org; Thu, 29 Apr 2021 13:13:30 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-290-A4QN2FKCNZCMA6aFh6HlKA-1; Thu, 29 Apr 2021 13:13:23 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8ED5B8BB8A1; Thu, 29 Apr 2021 17:13:22 +0000 (UTC) Received: from merkur.redhat.com (ovpn-114-217.ams2.redhat.com [10.36.114.217]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F22E100763B; Thu, 29 Apr 2021 17:13:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619716405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s7yPffZPDNbb+3hA2vDQLYKmtn+ChMX0L/tBZxf+i5E=; b=OeHWe19yywBJc58q0/5xJaz8OwjdcT8fH3jeJQ/XLE5KybBXbde5rV8clTzLcZ4cePX1ZC bLUGJHe9tVmUsIw4/dxD/6475hb/LzaQUnyfjU37cXL1+5jIKf9vSyu72dOjV4UdkJH9Dm M/eAuvCAmehjXeAf1T4JTIG1I2r9VGc= X-MC-Unique: A4QN2FKCNZCMA6aFh6HlKA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 2/6] vhost-user-blk: Don't reconnect during initialisation Date: Thu, 29 Apr 2021 19:13:12 +0200 Message-Id: <20210429171316.162022-3-kwolf@redhat.com> In-Reply-To: <20210429171316.162022-1-kwolf@redhat.com> References: <20210429171316.162022-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: kwolf@redhat.com, den-plotnikov@yandex-team.ru, mst@redhat.com, qemu-devel@nongnu.org, raphael.norwitz@nutanix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is a partial revert of commits 77542d43149 and bc79c87bcde. Usually, an error during initialisation means that the configuration was wrong. Reconnecting won't make the error go away, but just turn the error condition into an endless loop. Avoid this and return errors again. Additionally, calling vhost_user_blk_disconnect() from the chardev event handler could result in use-after-free because none of the initialisation code expects that the device could just go away in the middle. So removing the call fixes crashes in several places. For example, using a num-queues setting that is incompatible with the backend would result in a crash like this (dereferencing dev->opaque, which is already NULL): #0 0x0000555555d0a4bd in vhost_user_read_cb (source=3D0x5555568f4690, con= dition=3D(G_IO_IN | G_IO_HUP), opaque=3D0x7fffffffcbf0) at ../hw/virtio/vho= st-user.c:313 #1 0x0000555555d950d3 in qio_channel_fd_source_dispatch (source=3D0x55555= 7c3f750, callback=3D0x555555d0a478 , user_data=3D0x7fff= ffffcbf0) at ../io/channel-watch.c:84 #2 0x00007ffff7b32a9f in g_main_context_dispatch () at /lib64/libglib-2.0= .so.0 #3 0x00007ffff7b84a98 in g_main_context_iterate.constprop () at /lib64/li= bglib-2.0.so.0 #4 0x00007ffff7b32163 in g_main_loop_run () at /lib64/libglib-2.0.so.0 #5 0x0000555555d0a724 in vhost_user_read (dev=3D0x555557bc62f8, msg=3D0x7= fffffffcc50) at ../hw/virtio/vhost-user.c:402 #6 0x0000555555d0ee6b in vhost_user_get_config (dev=3D0x555557bc62f8, con= fig=3D0x555557bc62ac "", config_len=3D60) at ../hw/virtio/vhost-user.c:2133 #7 0x0000555555d56d46 in vhost_dev_get_config (hdev=3D0x555557bc62f8, con= fig=3D0x555557bc62ac "", config_len=3D60) at ../hw/virtio/vhost.c:1566 #8 0x0000555555cdd150 in vhost_user_blk_device_realize (dev=3D0x555557bc6= 0b0, errp=3D0x7fffffffcf90) at ../hw/block/vhost-user-blk.c:510 #9 0x0000555555d08f6d in virtio_device_realize (dev=3D0x555557bc60b0, err= p=3D0x7fffffffcff0) at ../hw/virtio/virtio.c:3660 Signed-off-by: Kevin Wolf Reviewed-by: Michael S. Tsirkin --- hw/block/vhost-user-blk.c | 59 +++++++++++---------------------------- 1 file changed, 17 insertions(+), 42 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 7c85248a7b..c0b9958da1 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -50,6 +50,8 @@ static const int user_feature_bits[] =3D { VHOST_INVALID_FEATURE_BIT }; =20 +static void vhost_user_blk_event(void *opaque, QEMUChrEvent event); + static void vhost_user_blk_update_config(VirtIODevice *vdev, uint8_t *conf= ig) { VHostUserBlk *s =3D VHOST_USER_BLK(vdev); @@ -362,19 +364,6 @@ static void vhost_user_blk_disconnect(DeviceState *dev) vhost_dev_cleanup(&s->dev); } =20 -static void vhost_user_blk_event(void *opaque, QEMUChrEvent event, - bool realized); - -static void vhost_user_blk_event_realize(void *opaque, QEMUChrEvent event) -{ - vhost_user_blk_event(opaque, event, false); -} - -static void vhost_user_blk_event_oper(void *opaque, QEMUChrEvent event) -{ - vhost_user_blk_event(opaque, event, true); -} - static void vhost_user_blk_chr_closed_bh(void *opaque) { DeviceState *dev =3D opaque; @@ -382,12 +371,11 @@ static void vhost_user_blk_chr_closed_bh(void *opaque) VHostUserBlk *s =3D VHOST_USER_BLK(vdev); =20 vhost_user_blk_disconnect(dev); - qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, - vhost_user_blk_event_oper, NULL, opaque, NULL, true); + qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_event, + NULL, opaque, NULL, true); } =20 -static void vhost_user_blk_event(void *opaque, QEMUChrEvent event, - bool realized) +static void vhost_user_blk_event(void *opaque, QEMUChrEvent event) { DeviceState *dev =3D opaque; VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -401,17 +389,7 @@ static void vhost_user_blk_event(void *opaque, QEMUChr= Event event, } break; case CHR_EVENT_CLOSED: - /* - * Closing the connection should happen differently on device - * initialization and operation stages. - * On initalization, we want to re-start vhost_dev initialization - * from the very beginning right away when the connection is close= d, - * so we clean up vhost_dev on each connection closing. - * On operation, we want to postpone vhost_dev cleanup to let the - * other code perform its own cleanup sequence using vhost_dev data - * (e.g. vhost_dev_set_log). - */ - if (realized && !runstate_check(RUN_STATE_SHUTDOWN)) { + if (!runstate_check(RUN_STATE_SHUTDOWN)) { /* * A close event may happen during a read/write, but vhost * code assumes the vhost_dev remains setup, so delay the @@ -431,8 +409,6 @@ static void vhost_user_blk_event(void *opaque, QEMUChrE= vent event, * knowing its type (in this case vhost-user). */ s->dev.started =3D false; - } else { - vhost_user_blk_disconnect(dev); } break; case CHR_EVENT_BREAK: @@ -489,33 +465,32 @@ static void vhost_user_blk_device_realize(DeviceState= *dev, Error **errp) s->vhost_vqs =3D g_new0(struct vhost_virtqueue, s->num_queues); s->connected =3D false; =20 - qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, - vhost_user_blk_event_realize, NULL, (void *)d= ev, - NULL, true); - -reconnect: if (qemu_chr_fe_wait_connected(&s->chardev, errp) < 0) { goto virtio_err; } =20 - /* check whether vhost_user_blk_connect() failed or not */ - if (!s->connected) { - goto reconnect; + if (vhost_user_blk_connect(dev) < 0) { + error_setg(errp, "vhost-user-blk: could not connect"); + qemu_chr_fe_disconnect(&s->chardev); + goto virtio_err; } + assert(s->connected); =20 ret =3D vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, sizeof(struct virtio_blk_config)); if (ret < 0) { - error_report("vhost-user-blk: get block config failed"); - goto reconnect; + error_setg(errp, "vhost-user-blk: get block config failed"); + goto vhost_err; } =20 - /* we're fully initialized, now we can operate, so change the handler = */ + /* we're fully initialized, now we can operate, so add the handler */ qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, - vhost_user_blk_event_oper, NULL, (void *)dev, + vhost_user_blk_event, NULL, (void *)dev, NULL, true); return; =20 +vhost_err: + vhost_dev_cleanup(&s->dev); virtio_err: g_free(s->vhost_vqs); s->vhost_vqs =3D NULL; --=20 2.30.2 From nobody Sat May 18 07:31:20 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619717010; cv=none; d=zohomail.com; s=zohoarc; b=WTJUbjGz3GA9Mxwb7aVEp4UBFE2Qrqe8Jpvn0iyX7qbq2WT5GbO9q0uV9D/qB0pL40ePCFIpY/2TycsX7+Aj6FRaD5RnOhst0FSau/F/d697WWn+4fRo6tq48oLPpS5v+g3HfPDKL0ROSHZK6edpvcn3N4ioKLgwN7zsBQwS8jo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619717010; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yPAL4bj2qLmgPg/sQw5yszXqNR/eF0I71QFTopDUz+Y=; b=hDJbopk7kJrdSGEf7HfSgh0A1LfS7/AvCGi+yVFyszwv/0IB9+dX4+H74VfgyM+uF74d08MG7KYLhRSjzvBtF/tIpIwRE6TR6hNRnlqIzKikxJR3U7GcUu+koz79GOSE6gqZ259VawR4K5qefwUft501oWQ3EwsRePJRbCk3+vs= 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 1619717010347310.0708434774514; Thu, 29 Apr 2021 10:23:30 -0700 (PDT) Received: from localhost ([::1]:53822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcANs-0006cm-Qo for importer@patchew.org; Thu, 29 Apr 2021 13:23:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcAEP-0000z7-Vc for qemu-devel@nongnu.org; Thu, 29 Apr 2021 13:13:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45694) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcAEC-0001Iy-M1 for qemu-devel@nongnu.org; Thu, 29 Apr 2021 13:13:41 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-258-_3j7lp9TNVGqLBJ0u8o9Sg-1; Thu, 29 Apr 2021 13:13:25 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22AEA107ACE6; Thu, 29 Apr 2021 17:13:24 +0000 (UTC) Received: from merkur.redhat.com (ovpn-114-217.ams2.redhat.com [10.36.114.217]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4C4C100164C; Thu, 29 Apr 2021 17:13:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619716407; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yPAL4bj2qLmgPg/sQw5yszXqNR/eF0I71QFTopDUz+Y=; b=Pvcr9kGdLAskQbfWFxnZlscwunZ5WVVtESqrSBF6DOgdf26yVygDtSSyaNBU06Kj0ToiQz 3/Y9Hr1QvYY6t+hG9ppxL5ym4vqROGIsYqd7l/dFDmtGYK1ofIVn7TVwW3ZbzDup1q1PX9 Gnua2KTImDFNq1Hi9USMoz2Vi1G4GqE= X-MC-Unique: _3j7lp9TNVGqLBJ0u8o9Sg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 3/6] vhost-user-blk: Improve error reporting in realize Date: Thu, 29 Apr 2021 19:13:13 +0200 Message-Id: <20210429171316.162022-4-kwolf@redhat.com> In-Reply-To: <20210429171316.162022-1-kwolf@redhat.com> References: <20210429171316.162022-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no 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: kwolf@redhat.com, den-plotnikov@yandex-team.ru, mst@redhat.com, qemu-devel@nongnu.org, raphael.norwitz@nutanix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Now that vhost_user_blk_connect() is not called from an event handler any more, but directly from vhost_user_blk_device_realize(), we can actually make use of Error again instead of calling error_report() in the inner function and setting a more generic and therefore less useful error message in realize() itself. With Error, the callers are responsible for adding context if necessary (such as the "-device" option the error refers to). Additional prefixes are redundant and better omitted. Signed-off-by: Kevin Wolf Acked-by: Raphael Norwitz Reviewed-by: Michael S. Tsirkin --- hw/block/vhost-user-blk.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index c0b9958da1..f3a45af97c 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -311,7 +311,7 @@ static void vhost_user_blk_reset(VirtIODevice *vdev) vhost_dev_free_inflight(s->inflight); } =20 -static int vhost_user_blk_connect(DeviceState *dev) +static int vhost_user_blk_connect(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserBlk *s =3D VHOST_USER_BLK(vdev); @@ -331,8 +331,7 @@ static int vhost_user_blk_connect(DeviceState *dev) =20 ret =3D vhost_dev_init(&s->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USE= R, 0); if (ret < 0) { - error_report("vhost-user-blk: vhost initialization failed: %s", - strerror(-ret)); + error_setg_errno(errp, -ret, "vhost initialization failed"); return ret; } =20 @@ -340,8 +339,7 @@ static int vhost_user_blk_connect(DeviceState *dev) if (virtio_device_started(vdev, vdev->status)) { ret =3D vhost_user_blk_start(vdev); if (ret < 0) { - error_report("vhost-user-blk: vhost start failed: %s", - strerror(-ret)); + error_setg_errno(errp, -ret, "vhost start failed"); return ret; } } @@ -380,10 +378,12 @@ static void vhost_user_blk_event(void *opaque, QEMUCh= rEvent event) DeviceState *dev =3D opaque; VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserBlk *s =3D VHOST_USER_BLK(vdev); + Error *local_err =3D NULL; =20 switch (event) { case CHR_EVENT_OPENED: - if (vhost_user_blk_connect(dev) < 0) { + if (vhost_user_blk_connect(dev, &local_err) < 0) { + error_report_err(local_err); qemu_chr_fe_disconnect(&s->chardev); return; } @@ -426,7 +426,7 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) int i, ret; =20 if (!s->chardev.chr) { - error_setg(errp, "vhost-user-blk: chardev is mandatory"); + error_setg(errp, "chardev is mandatory"); return; } =20 @@ -434,16 +434,16 @@ static void vhost_user_blk_device_realize(DeviceState= *dev, Error **errp) s->num_queues =3D 1; } if (!s->num_queues || s->num_queues > VIRTIO_QUEUE_MAX) { - error_setg(errp, "vhost-user-blk: invalid number of IO queues"); + error_setg(errp, "invalid number of IO queues"); return; } =20 if (!s->queue_size) { - error_setg(errp, "vhost-user-blk: queue size must be non-zero"); + error_setg(errp, "queue size must be non-zero"); return; } if (s->queue_size > VIRTQUEUE_MAX_SIZE) { - error_setg(errp, "vhost-user-blk: queue size must not exceed %d", + error_setg(errp, "queue size must not exceed %d", VIRTQUEUE_MAX_SIZE); return; } @@ -469,8 +469,7 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) goto virtio_err; } =20 - if (vhost_user_blk_connect(dev) < 0) { - error_setg(errp, "vhost-user-blk: could not connect"); + if (vhost_user_blk_connect(dev, errp) < 0) { qemu_chr_fe_disconnect(&s->chardev); goto virtio_err; } --=20 2.30.2 From nobody Sat May 18 07:31:20 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619718183; cv=none; d=zohomail.com; s=zohoarc; b=OSdHIxZnzVxniEMh72NYNBW2C0DzJYKMYiwZVZXsIKlE6wsnYsT8bkv6d5fGhSBNP+C9ahPjVN6/IGyycRKSdTEiy2CwKEoiY6GGYH9WEajhy/TNVBUyxlMRrNEKWFO6Z4D08VA+NnZZFak3t31ol3+Hv0lTOfIR1f6DlJG9hL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619718183; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZvIGOKzjvo2npC8jOwDxGZsL8448/SjlGICXbsfeBzE=; b=KpVhw49B3mD/Hm0gwHbIwAs2HlZBcixFyWEtyCtIrX+1EtgWz0dhUHJFX+bVq7X8z/eTzMZZqb5xJK/S9qrzTLCpUUkY4FHubcS/0Rw2fNIn8q43LkBgyMadT8yoAG/A3x1om7lB5iYqX6vMYQ3fh/DSQzVvj3rfSyqpC/VHXsQ= 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 161971818381445.70030999070775; Thu, 29 Apr 2021 10:43:03 -0700 (PDT) Received: from localhost ([::1]:33434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcAgo-0005Dn-7d for importer@patchew.org; Thu, 29 Apr 2021 13:43:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcAEV-00011S-Cw for qemu-devel@nongnu.org; Thu, 29 Apr 2021 13:13:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26357) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcAEL-0001K7-AK for qemu-devel@nongnu.org; Thu, 29 Apr 2021 13:13:47 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-405-I6EnhHNBNTmUq374RnojDg-1; Thu, 29 Apr 2021 13:13:26 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id AA9F18BB8A5; Thu, 29 Apr 2021 17:13:25 +0000 (UTC) Received: from merkur.redhat.com (ovpn-114-217.ams2.redhat.com [10.36.114.217]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69464100164C; Thu, 29 Apr 2021 17:13:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619716411; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZvIGOKzjvo2npC8jOwDxGZsL8448/SjlGICXbsfeBzE=; b=gSgHdyPMqu4hJxOpLI7sP9Fes/qUkoZsag1WhSxf+RjvMDVk5HyzwaJfUjjCkhU79zOtX4 usZ4+Y1qMnIT7Gx8floWf/m4ILW6UnJcFOwHvnOyhebIjBFSg0qXBcFHg6ClGBT5q9yXqN u7BPzfUMpq6Tos1xO9DYfxb8SfCimw4= X-MC-Unique: I6EnhHNBNTmUq374RnojDg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 4/6] vhost-user-blk: Get more feature flags from vhost device Date: Thu, 29 Apr 2021 19:13:14 +0200 Message-Id: <20210429171316.162022-5-kwolf@redhat.com> In-Reply-To: <20210429171316.162022-1-kwolf@redhat.com> References: <20210429171316.162022-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no 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: kwolf@redhat.com, den-plotnikov@yandex-team.ru, mst@redhat.com, qemu-devel@nongnu.org, raphael.norwitz@nutanix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" VIRTIO_F_RING_PACKED and VIRTIO_F_IOMMU_PLATFORM need to be supported by the vhost device, otherwise advertising it to the guest doesn't result in a working configuration. They are currently not supported by the vhost-user-blk export in QEMU. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1935020 Signed-off-by: Kevin Wolf Acked-by: Raphael Norwitz Reviewed-by: Michael S. Tsirkin --- hw/block/vhost-user-blk.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index f3a45af97c..c7e502f4c7 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -47,6 +47,8 @@ static const int user_feature_bits[] =3D { VIRTIO_RING_F_INDIRECT_DESC, VIRTIO_RING_F_EVENT_IDX, VIRTIO_F_NOTIFY_ON_EMPTY, + VIRTIO_F_RING_PACKED, + VIRTIO_F_IOMMU_PLATFORM, VHOST_INVALID_FEATURE_BIT }; =20 --=20 2.30.2 From nobody Sat May 18 07:31:20 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619717348; cv=none; d=zohomail.com; s=zohoarc; b=AEWPMyaOM2+ACz9lu6/E1b9L1CY1F4pcnNo9U0FLNomEfnt//ZTUOXafgHlZZJdOwJ07mwEx5CKtjAFC4NRjjOUUaxnSCJ+3B4iF+KM2rRMfHE6EXRd9HZ53g284VGRxYYv4Nq6rppclfhTbg36sSDCsysTyJYpCkx7PDRjX7hY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619717348; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zMPbUoTnjJF+iETtlzM4yrkXa5/HPn+fqfzaqas06sU=; b=I0LEqQUjIxFPOYhMH7bJcPj3Uz/fEvWuIhKpxPw63iMTTmttqMwPeqfsQ/VWFTj2cXT+Dq2DZVK4sHtJygdkohFzlVVPmBhklLQuIWikFJ5+qTZMcox4dIajXb2D6r7aUDXhyLwZD3s1eZ/1AfEBpZ8SYlJ1zc6H4v4PuZx+r40= 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 1619717348491813.3406635159398; Thu, 29 Apr 2021 10:29:08 -0700 (PDT) Received: from localhost ([::1]:41864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcATL-00050B-9x for importer@patchew.org; Thu, 29 Apr 2021 13:29:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60058) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcAEX-00012e-9H for qemu-devel@nongnu.org; Thu, 29 Apr 2021 13:13:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40242) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcAEI-0001Jz-6V for qemu-devel@nongnu.org; Thu, 29 Apr 2021 13:13:47 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-501-i3MKKOKBNPWrOxLjiIbc6w-1; Thu, 29 Apr 2021 13:13:28 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C7F218982A2; Thu, 29 Apr 2021 17:13:27 +0000 (UTC) Received: from merkur.redhat.com (ovpn-114-217.ams2.redhat.com [10.36.114.217]) by smtp.corp.redhat.com (Postfix) with ESMTP id F139E100763B; Thu, 29 Apr 2021 17:13:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619716410; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zMPbUoTnjJF+iETtlzM4yrkXa5/HPn+fqfzaqas06sU=; b=ZlNOhiXWzSA8Rmzu2XXw3ZbQKsm2CoTghWHi16CJmtd/WeIyzSZi3rnaNAXwFSkFke+quS WQ6btaxEhH3DFul1dYUF0fVyekGkC2J76fMpOBVeFpZMOo+QWQats5VkvMPY89+zIxdvsA PYOm3wSAuW5XlKiP/saQfyyZIUGHr8M= X-MC-Unique: i3MKKOKBNPWrOxLjiIbc6w-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 5/6] virtio: Fail if iommu_platform is requested, but unsupported Date: Thu, 29 Apr 2021 19:13:15 +0200 Message-Id: <20210429171316.162022-6-kwolf@redhat.com> In-Reply-To: <20210429171316.162022-1-kwolf@redhat.com> References: <20210429171316.162022-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no 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: kwolf@redhat.com, den-plotnikov@yandex-team.ru, mst@redhat.com, qemu-devel@nongnu.org, raphael.norwitz@nutanix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Commit 2943b53f6 (' virtio: force VIRTIO_F_IOMMU_PLATFORM') made sure that vhost can't just reject VIRTIO_F_IOMMU_PLATFORM when it was requested. However, just adding it back to the negotiated flags isn't right either because it promises support to the guest that the device actually doesn't support. One example of a vhost-user device that doesn't have support for the flag is the vhost-user-blk export of QEMU. Instead of successfully creating a device that doesn't work, just fail to plug the device when it doesn't support the feature, but it was requested. This results in much clearer error messages. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1935019 Signed-off-by: Kevin Wolf Reviewed-by: Raphael Norwitz Reviewed-by: Michael S. Tsirkin --- hw/virtio/virtio-bus.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index d6332d45c3..859978d248 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -69,6 +69,11 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error= **errp) return; } =20 + if (has_iommu && !virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFOR= M)) { + error_setg(errp, "iommu_platform=3Dtrue is not supported by the de= vice"); + return; + } + if (klass->device_plugged !=3D NULL) { klass->device_plugged(qbus->parent, &local_err); } --=20 2.30.2 From nobody Sat May 18 07:31:20 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619716673; cv=none; d=zohomail.com; s=zohoarc; b=Ub36wB6p3Ctx6ZHkagZ3pQIt5e6nvW0+m2wJi1f2zq5PwQWOwLErTigq7q/4LwhSgoH7c8BbygogYtCz0Zkz7vXUSLCwYP5ZliW6rollSnNr3AI3rv0DB/N4ctuQs43hie0KJtwohGcIfnvNpAOUWyu5o4Papl5ZPhRZaazxh58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619716673; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iTF805gQyPbAOYxQZa1iU/505AMVspiWfaW8wvd1fpc=; b=manmGX9VXVKiZX03oE82MzouKa7l8EMxTBsh9gEwNcBq4X2yBMzxGwzConHmAK2THhWYY8Vr2pOhfHWUyoJ0ZsAzUKffQ5ylIpdfDD3FRoDUZhjrwJHOv0SdPMFq5ed2CrumyNFL1W1EwSnT+Vbn47UIA+uf3oiCOZcz0yL7eKg= 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 1619716673083538.2241908963191; Thu, 29 Apr 2021 10:17:53 -0700 (PDT) Received: from localhost ([::1]:46176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcAIR-00039V-U9 for importer@patchew.org; Thu, 29 Apr 2021 13:17:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60070) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcAEY-00015L-8c for qemu-devel@nongnu.org; Thu, 29 Apr 2021 13:13:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52291) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcAEP-0001KE-O3 for qemu-devel@nongnu.org; Thu, 29 Apr 2021 13:13:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-562-fgtgrMO8MbGemIZh2L3qew-1; Thu, 29 Apr 2021 13:13:29 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C801681871A; Thu, 29 Apr 2021 17:13:28 +0000 (UTC) Received: from merkur.redhat.com (ovpn-114-217.ams2.redhat.com [10.36.114.217]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85BCB100763C; Thu, 29 Apr 2021 17:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619716411; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iTF805gQyPbAOYxQZa1iU/505AMVspiWfaW8wvd1fpc=; b=O8UW1tPIc/orh6z2sz70eVVAKykgXD0Le7oLedePx22wo1dSiRKtaa83Br2CUiv7qvrk8T mbHUZcDb8eeHNbzvrsF4Kqmof0Cgd3CNZALz2hFhb/ODAuL+2q/AelxBxWGMzPKUHP4ibI 6lgblp8dHLhs9IlQMW7ED1tfD2m3gWg= X-MC-Unique: fgtgrMO8MbGemIZh2L3qew-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 6/6] vhost-user-blk: Check that num-queues is supported by backend Date: Thu, 29 Apr 2021 19:13:16 +0200 Message-Id: <20210429171316.162022-7-kwolf@redhat.com> In-Reply-To: <20210429171316.162022-1-kwolf@redhat.com> References: <20210429171316.162022-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no 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: kwolf@redhat.com, den-plotnikov@yandex-team.ru, mst@redhat.com, qemu-devel@nongnu.org, raphael.norwitz@nutanix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Creating a device with a number of queues that isn't supported by the backend is pointless, the device won't work properly and the error messages are rather confusing. Just fail to create the device if num-queues is higher than what the backend supports. Since the relationship between num-queues and the number of virtqueues depends on the specific device, this is an additional value that needs to be initialised by the device. For convenience, allow leaving it 0 if the check should be skipped. This makes sense for vhost-user-net where separate vhost devices are used for the queues and custom initialisation code is needed to perform the check. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1935031 Signed-off-by: Kevin Wolf Reviewed-by: Raphael Norwitz Reviewed-by: Michael S. Tsirkin --- include/hw/virtio/vhost.h | 2 ++ hw/block/vhost-user-blk.c | 1 + hw/virtio/vhost-user.c | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 4a8bc75415..21a9a52088 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -74,6 +74,8 @@ struct vhost_dev { int nvqs; /* the first virtqueue which would be used by this vhost dev */ int vq_index; + /* if non-zero, minimum required value for max_queues */ + int num_queues; uint64_t features; uint64_t acked_features; uint64_t backend_features; diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index c7e502f4c7..c6210fad0c 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -324,6 +324,7 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) } s->connected =3D true; =20 + s->dev.num_queues =3D s->num_queues; s->dev.nvqs =3D s->num_queues; s->dev.vqs =3D s->vhost_vqs; s->dev.vq_index =3D 0; diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index ded0c10453..ee57abe045 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1909,6 +1909,11 @@ static int vhost_user_backend_init(struct vhost_dev = *dev, void *opaque) return err; } } + if (dev->num_queues && dev->max_queues < dev->num_queues) { + error_report("The maximum number of queues supported by the " + "backend is %" PRIu64, dev->max_queues); + return -EINVAL; + } =20 if (virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM) && !(virtio_has_feature(dev->protocol_features, --=20 2.30.2