From nobody Fri May 10 00:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671104016; cv=none; d=zohomail.com; s=zohoarc; b=elB0J4cgcIEctbUVJ3qg0EOVTuarqQkVDrp6RZZuPhLiMed0y+zd5pZREJ++RROnmakeAInf+Irx9tMhhwANsk5cCP+FWTK6zbwk9pMHJRO8fQCfsdHxfGDV6KcHHEYsDzB2eTTt08RRSKM+ymSnDrC+L9PSAsk4pOP23Vmh4ew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671104016; 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=F+8Ig73/fLUeRTg3onTKDE4DpjNQE7LZwNbUPhE0FNg=; b=G8JPnw2767QQmx9DxUEGig+pjL2eXxstE8L64iMhYnyXKqPC+XLE6+0MrmL+l/BU25GEWo1XSjUZGwMCtHzS0HHWCo5/nS4zK8QMKSVTgV6w8sB3XSJeBQMC77EZbKqXQvaM3QBPugO30plXvLLVFRtJSpcdmdUcfo/GtKDgIgs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671104016518384.9360687007985; Thu, 15 Dec 2022 03:33:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5mT8-0002Wc-Q5; Thu, 15 Dec 2022 06:32:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mT4-0002W0-7E for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mT2-0006iJ-Bm for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:01 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-653--72wctfgMv6qNDfHg0Fkbg-1; Thu, 15 Dec 2022 06:31:56 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DE5E51C09B70; Thu, 15 Dec 2022 11:31:55 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id B69502166B26; Thu, 15 Dec 2022 11:31:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671103919; 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=F+8Ig73/fLUeRTg3onTKDE4DpjNQE7LZwNbUPhE0FNg=; b=W1J4vilILSJykEZAoLN0+o+yKteXj3JLwgWobzPgdSGOmkxyX8VHxVN0dR3vwJQrtpc8zP Lv+RMt9puQuJskK/mRGaFk978RZt5nadCoKSvu+wZ2wH38xVXp8b3JElu5GdsYd4PjpbSr ibaphc/jL5j8O7/21UDKkVSDuGuJH4Y= X-MC-Unique: -72wctfgMv6qNDfHg0Fkbg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Stefano Garzarella , Zhu Lingshan , Si-Wei Liu , Laurent Vivier , "Gonglei (Arei)" , Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Cindy Lu , Gautam Dawar , Eli Cohen , Cornelia Huck , Paolo Bonzini , Longpeng , Harpreet Singh Anand , Parav Pandit , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v9 01/12] vdpa: use v->shadow_vqs_enabled in vhost_vdpa_svqs_start & stop Date: Thu, 15 Dec 2022 12:31:33 +0100 Message-Id: <20221215113144.322011-2-eperezma@redhat.com> In-Reply-To: <20221215113144.322011-1-eperezma@redhat.com> References: <20221215113144.322011-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671104018321100003 This function used to trust in v->shadow_vqs !=3D NULL to know if it must start svq or not. This is not going to be valid anymore, as qemu is going to allocate svq array unconditionally (but it will only start them conditionally). Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 7468e44b87..7f0ff4df5b 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1029,7 +1029,7 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *d= ev) Error *err =3D NULL; unsigned i; =20 - if (!v->shadow_vqs) { + if (!v->shadow_vqs_enabled) { return true; } =20 @@ -1082,7 +1082,7 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *de= v) { struct vhost_vdpa *v =3D dev->opaque; =20 - if (!v->shadow_vqs) { + if (!v->shadow_vqs_enabled) { return; } =20 --=20 2.31.1 From nobody Fri May 10 00:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671104238; cv=none; d=zohomail.com; s=zohoarc; b=OxvLIqj16S7NKzcybH2PdpcURqwhMX+VT7pXuI5uc/AnQXFma5Imv3itaL1vtsKsfyOlWrSlkj94xv2eD7bLQlSY9JpDxOb0sTjd+w7N2ti3Ag2oEW5B/8Umea2kvEUYwkpyJqAvPs0nxYDHP7w337u2kcjGgkOm0dwe9godDfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671104238; 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=TSjVQAN1hGLhWwbJytaWeNULUe7TeqdaxnpYJGUlvrs=; b=ayJIiUmK+2arYJdyHx7RKIe4M7PX+L+CEn0mwbKxx1pmUBrgTTlMMju+GxT+fztAd/IIjvyvrRNNqYrhiiG8HTa09Wmrxy9S8Z/CydyQg/mc3ugVAQx89ASMM/aRJMv7wUh9AyFRMwyqzTXrFcQUxioQs0qCKN6VHnAGkfZOEiE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671104238497138.52573941974833; Thu, 15 Dec 2022 03:37:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5mTN-0002b1-0i; Thu, 15 Dec 2022 06:32:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mT8-0002Wx-Qx for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mT6-0006jD-UM for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:06 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-252-glKMjI7uNGaKgpcO6G2I1A-1; Thu, 15 Dec 2022 06:31:59 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 553C73C11045; Thu, 15 Dec 2022 11:31:59 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CDD02166B26; Thu, 15 Dec 2022 11:31:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671103923; 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=TSjVQAN1hGLhWwbJytaWeNULUe7TeqdaxnpYJGUlvrs=; b=JH/BA8UWkZ86Qa0xD6Gfe3eSuIklM7MAi8uzCjhKWYnl2gxCUq7kLyoM0c5zui5jscG+7v Hhq7qRwJWWolWmEzusx4to4sles0x3WUOxTmAuMYvtPacr+eXxi5RmBMayqUEeIFCpnSM3 iyucTYvfdzHTr03qVspsWIhxSDX4UA0= X-MC-Unique: glKMjI7uNGaKgpcO6G2I1A-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Stefano Garzarella , Zhu Lingshan , Si-Wei Liu , Laurent Vivier , "Gonglei (Arei)" , Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Cindy Lu , Gautam Dawar , Eli Cohen , Cornelia Huck , Paolo Bonzini , Longpeng , Harpreet Singh Anand , Parav Pandit , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v9 02/12] vhost: set SVQ device call handler at SVQ start Date: Thu, 15 Dec 2022 12:31:34 +0100 Message-Id: <20221215113144.322011-3-eperezma@redhat.com> In-Reply-To: <20221215113144.322011-1-eperezma@redhat.com> References: <20221215113144.322011-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671104238728100003 By the end of this series CVQ is shadowed as long as the features support it. Since we don't know at the beginning of qemu running if this is supported, move the event notifier handler setting to the start of the SVQ, instead of the start of qemu run. This will avoid to create them if the device does not support SVQ. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 5bd14cad96..264ddc166d 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -648,6 +648,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, { size_t desc_size, driver_size, device_size; =20 + event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); svq->next_guest_avail_elem =3D NULL; svq->shadow_avail_idx =3D 0; svq->shadow_used_idx =3D 0; @@ -704,6 +705,7 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) g_free(svq->desc_state); qemu_vfree(svq->vring.desc); qemu_vfree(svq->vring.used); + event_notifier_set_handler(&svq->hdev_call, NULL); } =20 /** @@ -740,7 +742,6 @@ VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova= _tree, } =20 event_notifier_init_fd(&svq->svq_kick, VHOST_FILE_UNBIND); - event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); svq->iova_tree =3D iova_tree; svq->ops =3D ops; svq->ops_opaque =3D ops_opaque; @@ -763,7 +764,6 @@ void vhost_svq_free(gpointer pvq) VhostShadowVirtqueue *vq =3D pvq; vhost_svq_stop(vq); event_notifier_cleanup(&vq->hdev_kick); - event_notifier_set_handler(&vq->hdev_call, NULL); event_notifier_cleanup(&vq->hdev_call); g_free(vq); } --=20 2.31.1 From nobody Fri May 10 00:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671104199; cv=none; d=zohomail.com; s=zohoarc; b=nShg3fv2n+4ieqERcuScBGwZqAKJBwXKCJEaRPnnqu7QfzHkLHQFk+xaw7CMkBUeVzXN1L2oayMrxGtGsFvTjcnEko7sgxsKPC8Th2UG+xkifPKN+eNpkPMJtk8md9Xb7cwIqloGpQF8Y+LSIoduXAiOvkXXqiwSjGhDIfQwUjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671104199; 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=wLU39RtuBP+GapQRx/xyrSR9LCcfBeflobv1obIr0ZE=; b=gEiEukVddC9+vVhklj/kI9TfMTKWOQE1A2BPlBKgLNicRpyZGI4UdkHYTuuJonom4FHdRp8Zc+imh/CLXa01U54L8DasPFop6iqxxhb6vk8+PfPiOG9B89OTfxQmxNtoVJcONr283U6O5UZMrnvDFIV6UsdttSs3AvimGxmPzuk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167110419973545.61807718649493; Thu, 15 Dec 2022 03:36:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5mTN-0002b4-EN; Thu, 15 Dec 2022 06:32:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTE-0002XY-0N for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTB-0006jd-Mo for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:11 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-205-rGcCx_BZOlKswPpBjks7PA-1; Thu, 15 Dec 2022 06:32:03 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CFDA229AA2D0; Thu, 15 Dec 2022 11:32:02 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9925A2166B26; Thu, 15 Dec 2022 11:31:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671103928; 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=wLU39RtuBP+GapQRx/xyrSR9LCcfBeflobv1obIr0ZE=; b=LSpRoVknRueGLioNhhvfQK25xtz7m2Epo0m+dUnkiAeZ/6Hy6RIS4LE/OiP55Yd6Y82e/y qCUyrdtGPNFLBChzCm8J9DtnjtP2PVDcxD4BG3oGPtPeStnXX2wUqVPoczs1Y1b9W9ClVa o5ypq/ig/BK4qUdMd/0bbJyLoeIUw/A= X-MC-Unique: rGcCx_BZOlKswPpBjks7PA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Stefano Garzarella , Zhu Lingshan , Si-Wei Liu , Laurent Vivier , "Gonglei (Arei)" , Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Cindy Lu , Gautam Dawar , Eli Cohen , Cornelia Huck , Paolo Bonzini , Longpeng , Harpreet Singh Anand , Parav Pandit , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v9 03/12] vhost: allocate SVQ device file descriptors at device start Date: Thu, 15 Dec 2022 12:31:35 +0100 Message-Id: <20221215113144.322011-4-eperezma@redhat.com> In-Reply-To: <20221215113144.322011-1-eperezma@redhat.com> References: <20221215113144.322011-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671104200501100002 The next patches will start control SVQ if possible. However, we don't know if that will be possible at qemu boot anymore. Delay device file descriptors until we know it at device start. This will avoid to create them if the device does not support SVQ. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 31 ++------------------------ hw/virtio/vhost-vdpa.c | 35 ++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 264ddc166d..3b05bab44d 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -715,43 +715,18 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) * @iova_tree: Tree to perform descriptors translations * @ops: SVQ owner callbacks * @ops_opaque: ops opaque pointer - * - * Returns the new virtqueue or NULL. - * - * In case of error, reason is reported through error_report. */ VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, const VhostShadowVirtqueueOps *ops, void *ops_opaque) { - g_autofree VhostShadowVirtqueue *svq =3D g_new0(VhostShadowVirtqueue, = 1); - int r; - - r =3D event_notifier_init(&svq->hdev_kick, 0); - if (r !=3D 0) { - error_report("Couldn't create kick event notifier: %s (%d)", - g_strerror(errno), errno); - goto err_init_hdev_kick; - } - - r =3D event_notifier_init(&svq->hdev_call, 0); - if (r !=3D 0) { - error_report("Couldn't create call event notifier: %s (%d)", - g_strerror(errno), errno); - goto err_init_hdev_call; - } + VhostShadowVirtqueue *svq =3D g_new0(VhostShadowVirtqueue, 1); =20 event_notifier_init_fd(&svq->svq_kick, VHOST_FILE_UNBIND); svq->iova_tree =3D iova_tree; svq->ops =3D ops; svq->ops_opaque =3D ops_opaque; - return g_steal_pointer(&svq); - -err_init_hdev_call: - event_notifier_cleanup(&svq->hdev_kick); - -err_init_hdev_kick: - return NULL; + return svq; } =20 /** @@ -763,7 +738,5 @@ void vhost_svq_free(gpointer pvq) { VhostShadowVirtqueue *vq =3D pvq; vhost_svq_stop(vq); - event_notifier_cleanup(&vq->hdev_kick); - event_notifier_cleanup(&vq->hdev_call); g_free(vq); } diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 7f0ff4df5b..3df2775760 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -428,15 +428,11 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev= , struct vhost_vdpa *v, =20 shadow_vqs =3D g_ptr_array_new_full(hdev->nvqs, vhost_svq_free); for (unsigned n =3D 0; n < hdev->nvqs; ++n) { - g_autoptr(VhostShadowVirtqueue) svq; + VhostShadowVirtqueue *svq; =20 svq =3D vhost_svq_new(v->iova_tree, v->shadow_vq_ops, v->shadow_vq_ops_opaque); - if (unlikely(!svq)) { - error_setg(errp, "Cannot create svq %u", n); - return -1; - } - g_ptr_array_add(shadow_vqs, g_steal_pointer(&svq)); + g_ptr_array_add(shadow_vqs, svq); } =20 v->shadow_vqs =3D g_steal_pointer(&shadow_vqs); @@ -864,11 +860,23 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *d= ev, const EventNotifier *event_notifier =3D &svq->hdev_kick; int r; =20 + r =3D event_notifier_init(&svq->hdev_kick, 0); + if (r !=3D 0) { + error_setg_errno(errp, -r, "Couldn't create kick event notifier"); + goto err_init_hdev_kick; + } + + r =3D event_notifier_init(&svq->hdev_call, 0); + if (r !=3D 0) { + error_setg_errno(errp, -r, "Couldn't create call event notifier"); + goto err_init_hdev_call; + } + file.fd =3D event_notifier_get_fd(event_notifier); r =3D vhost_vdpa_set_vring_dev_kick(dev, &file); if (unlikely(r !=3D 0)) { error_setg_errno(errp, -r, "Can't set device kick fd"); - return r; + goto err_init_set_dev_fd; } =20 event_notifier =3D &svq->hdev_call; @@ -876,8 +884,18 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *de= v, r =3D vhost_vdpa_set_vring_dev_call(dev, &file); if (unlikely(r !=3D 0)) { error_setg_errno(errp, -r, "Can't set device call fd"); + goto err_init_set_dev_fd; } =20 + return 0; + +err_init_set_dev_fd: + event_notifier_set_handler(&svq->hdev_call, NULL); + +err_init_hdev_call: + event_notifier_cleanup(&svq->hdev_kick); + +err_init_hdev_kick: return r; } =20 @@ -1089,6 +1107,9 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *de= v) for (unsigned i =3D 0; i < v->shadow_vqs->len; ++i) { VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, i); vhost_vdpa_svq_unmap_rings(dev, svq); + + event_notifier_cleanup(&svq->hdev_kick); + event_notifier_cleanup(&svq->hdev_call); } } =20 --=20 2.31.1 From nobody Fri May 10 00:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671104016; cv=none; d=zohomail.com; s=zohoarc; b=gRpPR47yQRFpGBed+EJTNDNZ23MspI0hYMWkb8LOKP6+NGd3J6c8ztdWsoemzAjmjhWsP7O9Btk05C9+vyyAqcFOtSaHrsE+7loyXOaufFDHuYOx3PH6/oECuOWZnW4uMWs4jd1q6HVPIM0wq05ncBz2+JuJ5p3+cnKUTasG4Ks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671104016; 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=gReR1hVJf9xBAZ4Dw92F4r0+VgwswRVcL7qHrzE1ZSo=; b=R+ilubD/KpeEFjKV9zyL3bnpASO4pYPKNu9ZpeKsqS+7ADIABPmx1ZSH+DgkYhmqaaVBNKD7JGsauzCSNDG18Aibbz65D7InsXYQBwD6lA07To5meMtlI0xzllOu4K2cvA8iWwnhDnXej5Ow0FY2PE+OQDWk4rkSviIvMAGuvVA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671104016628285.8313950802652; Thu, 15 Dec 2022 03:33:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5mTO-0002bI-BG; Thu, 15 Dec 2022 06:32:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTI-0002YD-SX for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTG-0006k4-4t for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:16 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-515--G33fKGmPU2LDUkGZFb7-g-1; Thu, 15 Dec 2022 06:32:07 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 81747858F09; Thu, 15 Dec 2022 11:32:06 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E1812166B26; Thu, 15 Dec 2022 11:32:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671103933; 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=gReR1hVJf9xBAZ4Dw92F4r0+VgwswRVcL7qHrzE1ZSo=; b=Em0REwSjCZYGWcCvhf7K9oepOmBuOA7LmDeyKgmf6O9dgCUcAxCtimF24+XzJiUfV9qnAA MfhEhj4Lcdx2eeZog5KxJJtcAnTifx/hYXzi1IktYlESeTFOhMF02bSQjzTkr+tnBL72SA w4OMeSapQoC9AHU7PN4Fdjr/i3N6tfw= X-MC-Unique: -G33fKGmPU2LDUkGZFb7-g-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Stefano Garzarella , Zhu Lingshan , Si-Wei Liu , Laurent Vivier , "Gonglei (Arei)" , Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Cindy Lu , Gautam Dawar , Eli Cohen , Cornelia Huck , Paolo Bonzini , Longpeng , Harpreet Singh Anand , Parav Pandit , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v9 04/12] vhost: move iova_tree set to vhost_svq_start Date: Thu, 15 Dec 2022 12:31:36 +0100 Message-Id: <20221215113144.322011-5-eperezma@redhat.com> In-Reply-To: <20221215113144.322011-1-eperezma@redhat.com> References: <20221215113144.322011-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671104018344100004 Since we don't know if we will use SVQ at qemu initialization, let's allocate iova_tree only if needed. To do so, accept it at SVQ start, not at initialization. This will avoid to create it if the device does not support SVQ. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.h | 5 ++--- hw/virtio/vhost-shadow-virtqueue.c | 9 ++++----- hw/virtio/vhost-vdpa.c | 5 ++--- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index d04c34a589..926a4897b1 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -126,11 +126,10 @@ size_t vhost_svq_driver_area_size(const VhostShadowVi= rtqueue *svq); size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq); =20 void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, - VirtQueue *vq); + VirtQueue *vq, VhostIOVATree *iova_tree); void vhost_svq_stop(VhostShadowVirtqueue *svq); =20 -VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, - const VhostShadowVirtqueueOps *ops, +VhostShadowVirtqueue *vhost_svq_new(const VhostShadowVirtqueueOps *ops, void *ops_opaque); =20 void vhost_svq_free(gpointer vq); diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 3b05bab44d..4307296358 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -642,9 +642,10 @@ void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *s= vq, int svq_kick_fd) * @svq: Shadow Virtqueue * @vdev: VirtIO device * @vq: Virtqueue to shadow + * @iova_tree: Tree to perform descriptors translations */ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, - VirtQueue *vq) + VirtQueue *vq, VhostIOVATree *iova_tree) { size_t desc_size, driver_size, device_size; =20 @@ -655,6 +656,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, svq->last_used_idx =3D 0; svq->vdev =3D vdev; svq->vq =3D vq; + svq->iova_tree =3D iova_tree; =20 svq->vring.num =3D virtio_queue_get_num(vdev, virtio_get_queue_index(v= q)); driver_size =3D vhost_svq_driver_area_size(svq); @@ -712,18 +714,15 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) * Creates vhost shadow virtqueue, and instructs the vhost device to use t= he * shadow methods and file descriptors. * - * @iova_tree: Tree to perform descriptors translations * @ops: SVQ owner callbacks * @ops_opaque: ops opaque pointer */ -VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, - const VhostShadowVirtqueueOps *ops, +VhostShadowVirtqueue *vhost_svq_new(const VhostShadowVirtqueueOps *ops, void *ops_opaque) { VhostShadowVirtqueue *svq =3D g_new0(VhostShadowVirtqueue, 1); =20 event_notifier_init_fd(&svq->svq_kick, VHOST_FILE_UNBIND); - svq->iova_tree =3D iova_tree; svq->ops =3D ops; svq->ops_opaque =3D ops_opaque; return svq; diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 3df2775760..691bcc811a 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -430,8 +430,7 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, = struct vhost_vdpa *v, for (unsigned n =3D 0; n < hdev->nvqs; ++n) { VhostShadowVirtqueue *svq; =20 - svq =3D vhost_svq_new(v->iova_tree, v->shadow_vq_ops, - v->shadow_vq_ops_opaque); + svq =3D vhost_svq_new(v->shadow_vq_ops, v->shadow_vq_ops_opaque); g_ptr_array_add(shadow_vqs, svq); } =20 @@ -1063,7 +1062,7 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *d= ev) goto err; } =20 - vhost_svq_start(svq, dev->vdev, vq); + vhost_svq_start(svq, dev->vdev, vq, v->iova_tree); ok =3D vhost_vdpa_svq_map_rings(dev, svq, &addr, &err); if (unlikely(!ok)) { goto err_map; --=20 2.31.1 From nobody Fri May 10 00:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671104220; cv=none; d=zohomail.com; s=zohoarc; b=n2agjUN8gG8TztwkCpt1ZMRa+ZKxb1ZSXYFKs966ocuYFkWYW7yVAffQaBqEEoUEJkAJakqmrTgWb3K9rLrxi+iuR/PNIimT2zyI0KF/xqQU4wnkUiwjkVVt/nbD/jOicLoPPaNRORSum7HK1Fx3K6Yhky4+Oyp9HbTfHX0qozM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671104220; 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=qh9IFx0k8h0cmNyHPydWbPOxeOqSM/5ev2W0OwNyZ2c=; b=h2QkdcT7WO+LAJdOSp4fmcjafyH3OAuvJlWaSpbQutG7UWunFA61UTdYWfmmBwM4l9L5y56RGdci/MutZ3lCgnRRYEJWHhY/bg76S0tOUriyRgh0+M3BxZ+ucBLET9Gjoj0xwvoTJpc4eUPquihdfhI79AKhNrPfScIxJVSPXEE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671104220357226.6684809421489; Thu, 15 Dec 2022 03:37:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5mTN-0002b3-DS; Thu, 15 Dec 2022 06:32:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTK-0002YE-6S for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTI-0006kD-Kg for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:17 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-91-2rSAVxALPyuwjl16BpoheQ-1; Thu, 15 Dec 2022 06:32:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9E8C51C09B67; Thu, 15 Dec 2022 11:32:11 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id D39382166B29; Thu, 15 Dec 2022 11:32:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671103935; 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=qh9IFx0k8h0cmNyHPydWbPOxeOqSM/5ev2W0OwNyZ2c=; b=bwuYmBHG5bOhZ92Gek5DVzUX9xEqaXCKl3xRv5Zh/6A41pOyOWGtD0q1uqb6Pj7ha0tzxV KcRyvb5TDvgNdyFO8N3jdxGjRphqhEfkDLM+G5vVFjzQbLQ5GA0Sg7n5y30yFHqEDBE9Y1 cMj37A8Td1lT390NW5nJ7CKdPiT04sg= X-MC-Unique: 2rSAVxALPyuwjl16BpoheQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Stefano Garzarella , Zhu Lingshan , Si-Wei Liu , Laurent Vivier , "Gonglei (Arei)" , Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Cindy Lu , Gautam Dawar , Eli Cohen , Cornelia Huck , Paolo Bonzini , Longpeng , Harpreet Singh Anand , Parav Pandit , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v9 05/12] vdpa: add vhost_vdpa_net_valid_svq_features Date: Thu, 15 Dec 2022 12:31:37 +0100 Message-Id: <20221215113144.322011-6-eperezma@redhat.com> In-Reply-To: <20221215113144.322011-1-eperezma@redhat.com> References: <20221215113144.322011-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671104220726100003 It will be reused at vdpa device start so let's extract in its own function. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- net/vhost-vdpa.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 260e474863..2c0ff6d7b0 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -107,6 +107,22 @@ VHostNetState *vhost_vdpa_get_vhost_net(NetClientState= *nc) return s->vhost_net; } =20 +static bool vhost_vdpa_net_valid_svq_features(uint64_t features, Error **e= rrp) +{ + uint64_t invalid_dev_features =3D + features & ~vdpa_svq_device_features & + /* Transport are all accepted at this point */ + ~MAKE_64BIT_MASK(VIRTIO_TRANSPORT_F_START, + VIRTIO_TRANSPORT_F_END - VIRTIO_TRANSPORT_F_START= ); + + if (invalid_dev_features) { + error_setg(errp, "vdpa svq does not work with features 0x%" PRIx64, + invalid_dev_features); + } + + return !invalid_dev_features; +} + static int vhost_vdpa_net_check_device_id(struct vhost_net *net) { uint32_t device_id; @@ -676,15 +692,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const ch= ar *name, if (opts->x_svq) { struct vhost_vdpa_iova_range iova_range; =20 - uint64_t invalid_dev_features =3D - features & ~vdpa_svq_device_features & - /* Transport are all accepted at this point */ - ~MAKE_64BIT_MASK(VIRTIO_TRANSPORT_F_START, - VIRTIO_TRANSPORT_F_END - VIRTIO_TRANSPORT_F_S= TART); - - if (invalid_dev_features) { - error_setg(errp, "vdpa svq does not work with features 0x%" PR= Ix64, - invalid_dev_features); + if (!vhost_vdpa_net_valid_svq_features(features, errp)) { goto err_svq; } =20 --=20 2.31.1 From nobody Fri May 10 00:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671104080; cv=none; d=zohomail.com; s=zohoarc; b=KreLenXamsw0S9woki4YfkChwDOeREyWGX/pbr1eFBB6NSfqF2gqtS9CEAkuvFLp/P/8PXefDHyeJe1tY11BLVBHfnlYbcWu/vqekM4xQ14SXQMCDrKpocmQqBsFsmg3I60JtLYs1Y9XPuEEHzKYBh23H3zg3fSHmyRawhBVV2M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671104080; 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=/Rfuwpr+kShoJMYQJoTJHzLoWWsJJtsbRxz+cbi+3HQ=; b=Gb6wpMcTsKIZYfxUNUEsOjMbN4Hnfdp4VHt0ldnCRUCR11zGHW7UvyUbARER+V0vxrYrdLusCWVhMQB/3P2W6Ct/WS0UF/z12EhbWC3wNdrt5fH4fCBouimpGNCi9eCE7jt4o9Ksvff7fkQyOUM5+u466gp1CNrg7Gfaqj0X4cA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671104080811358.37182147751616; Thu, 15 Dec 2022 03:34:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5mTP-0002cP-Ii; Thu, 15 Dec 2022 06:32:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTN-0002b7-PL for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTM-0006lF-4r for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:21 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-615-ByS1VDxMM7208FTfBg8kGw-1; Thu, 15 Dec 2022 06:32:16 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9168F3C11046; Thu, 15 Dec 2022 11:32:15 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id E469F2166B26; Thu, 15 Dec 2022 11:32:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671103939; 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=/Rfuwpr+kShoJMYQJoTJHzLoWWsJJtsbRxz+cbi+3HQ=; b=TVHWcOqQgF9/fZpfdyjXz7v0m51s8ga5jQpMLHdktwJlPxpXH5TuBgsDyTa7kvT1pV+Bp7 6EWvjJnjkbrF9vHphYXmaAxOOiH9J2LR+NnupJFDs5JkrxCb2Hpk1ae1YuYamMnHNe372g E3Z+/7B6yhNVTQNhy1KQCP/A8EWVBDg= X-MC-Unique: ByS1VDxMM7208FTfBg8kGw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Stefano Garzarella , Zhu Lingshan , Si-Wei Liu , Laurent Vivier , "Gonglei (Arei)" , Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Cindy Lu , Gautam Dawar , Eli Cohen , Cornelia Huck , Paolo Bonzini , Longpeng , Harpreet Singh Anand , Parav Pandit , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v9 06/12] vdpa: request iova_range only once Date: Thu, 15 Dec 2022 12:31:38 +0100 Message-Id: <20221215113144.322011-7-eperezma@redhat.com> In-Reply-To: <20221215113144.322011-1-eperezma@redhat.com> References: <20221215113144.322011-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671104081289100001 Currently iova range is requested once per queue pair in the case of net. Reduce the number of ioctls asking it once at initialization and reusing that value for each vhost_vdpa. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 15 --------------- net/vhost-vdpa.c | 27 ++++++++++++++------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 691bcc811a..9b7f4ef083 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -365,19 +365,6 @@ static int vhost_vdpa_add_status(struct vhost_dev *dev= , uint8_t status) return 0; } =20 -static void vhost_vdpa_get_iova_range(struct vhost_vdpa *v) -{ - int ret =3D vhost_vdpa_call(v->dev, VHOST_VDPA_GET_IOVA_RANGE, - &v->iova_range); - if (ret !=3D 0) { - v->iova_range.first =3D 0; - v->iova_range.last =3D UINT64_MAX; - } - - trace_vhost_vdpa_get_iova_range(v->dev, v->iova_range.first, - v->iova_range.last); -} - /* * The use of this function is for requests that only need to be * applied once. Typically such request occurs at the beginning @@ -465,8 +452,6 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void = *opaque, Error **errp) goto err; } =20 - vhost_vdpa_get_iova_range(v); - if (!vhost_vdpa_first_dev(dev)) { return 0; } diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 2c0ff6d7b0..b6462f0192 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -541,14 +541,15 @@ static const VhostShadowVirtqueueOps vhost_vdpa_net_s= vq_ops =3D { }; =20 static NetClientState *net_vhost_vdpa_init(NetClientState *peer, - const char *device, - const char *name, - int vdpa_device_fd, - int queue_pair_index, - int nvqs, - bool is_datapath, - bool svq, - VhostIOVATree *iova_tree) + const char *device, + const char *name, + int vdpa_device_fd, + int queue_pair_index, + int nvqs, + bool is_datapath, + bool svq, + struct vhost_vdpa_iova_range iova_r= ange, + VhostIOVATree *iova_tree) { NetClientState *nc =3D NULL; VhostVDPAState *s; @@ -567,6 +568,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; s->vhost_vdpa.shadow_vqs_enabled =3D svq; + s->vhost_vdpa.iova_range =3D iova_range; s->vhost_vdpa.iova_tree =3D iova_tree; if (!is_datapath) { s->cvq_cmd_out_buffer =3D qemu_memalign(qemu_real_host_page_size(), @@ -646,6 +648,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, int vdpa_device_fd; g_autofree NetClientState **ncs =3D NULL; g_autoptr(VhostIOVATree) iova_tree =3D NULL; + struct vhost_vdpa_iova_range iova_range; NetClientState *nc; int queue_pairs, r, i =3D 0, has_cvq =3D 0; =20 @@ -689,14 +692,12 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, return queue_pairs; } =20 + vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); if (opts->x_svq) { - struct vhost_vdpa_iova_range iova_range; - if (!vhost_vdpa_net_valid_svq_features(features, errp)) { goto err_svq; } =20 - vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); iova_tree =3D vhost_iova_tree_new(iova_range.first, iova_range.las= t); } =20 @@ -705,7 +706,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, for (i =3D 0; i < queue_pairs; i++) { ncs[i] =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd, i, 2, true, opts->x_s= vq, - iova_tree); + iova_range, iova_tree); if (!ncs[i]) goto err; } @@ -713,7 +714,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, if (has_cvq) { nc =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd, i, 1, false, - opts->x_svq, iova_tree); + opts->x_svq, iova_range, iova_tree); if (!nc) goto err; } --=20 2.31.1 From nobody Fri May 10 00:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671103999; cv=none; d=zohomail.com; s=zohoarc; b=YkKTppGDlBhn+oUZnK4H2QZZhrzSsT83Gw9g93sJH3Zu4HhAUidvViegdtua7o6nriFJ2SJkz15H1AtzsBerOU2hH5WCl+6vtmTUYSw0ouJInIet0dZTNJqrxdmYUcDo0VOTEGxbhChLF8y4SeminLt87E989EDg2ltpyhe20DM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671103999; 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=EJM5bMQK66LBjQHzGpr59PzU4BEc4YKDsnGoL7YGzBU=; b=PCcpMHHuigsDtafpth0SNQJOO92oXVJinvBshmuwgJdNUtQ+sdaS4qTQj1OS8t+1gMvGQbNUpHCS+XQpoUx9+WkbzAzezhYQ1oG0qwITR6nco4QWOLLzY0W0XqHavmsM4dL3Y/NU74eaBwCeRoanzMWgHQ8LXChG3REnDSjS/Ac= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671103999633532.4843109684904; Thu, 15 Dec 2022 03:33:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5mTW-0002dD-9k; Thu, 15 Dec 2022 06:32:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTV-0002d4-Gy for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTU-0006n7-0B for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:29 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-22-hgG2_VNUMgmMREg0BDfy2g-1; Thu, 15 Dec 2022 06:32:21 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D3B91811E9C; Thu, 15 Dec 2022 11:32:19 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id E29BC2166B26; Thu, 15 Dec 2022 11:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671103947; 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=EJM5bMQK66LBjQHzGpr59PzU4BEc4YKDsnGoL7YGzBU=; b=Z6CsIaehMdBmEzDuJ6KUpoJAAIJtWoqfBIAV9LXZJ35mowEYpe5NDz80idK+b2pa4igBgf p+lDNhZrjYGoFrv4UfuwkfkSLchkvnOkYsZemX/TulZhvOMB8S/obMsKWd/RIzpVeiqlNY qBfddra11P1O6zTaYIUGtk8m/xdxs7Q= X-MC-Unique: hgG2_VNUMgmMREg0BDfy2g-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Stefano Garzarella , Zhu Lingshan , Si-Wei Liu , Laurent Vivier , "Gonglei (Arei)" , Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Cindy Lu , Gautam Dawar , Eli Cohen , Cornelia Huck , Paolo Bonzini , Longpeng , Harpreet Singh Anand , Parav Pandit , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v9 07/12] vdpa: move SVQ vring features check to net/ Date: Thu, 15 Dec 2022 12:31:39 +0100 Message-Id: <20221215113144.322011-8-eperezma@redhat.com> In-Reply-To: <20221215113144.322011-1-eperezma@redhat.com> References: <20221215113144.322011-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671104000447100002 The next patches will start control SVQ if possible. However, we don't know if that will be possible at qemu boot anymore. Since the moved checks will be already evaluated at net/ to know if it is ok to shadow CVQ, move them. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 32 ++------------------------------ net/vhost-vdpa.c | 3 ++- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 9b7f4ef083..5039d9bb2f 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -389,29 +389,9 @@ static int vhost_vdpa_get_dev_features(struct vhost_de= v *dev, return ret; } =20 -static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *= v, - Error **errp) +static void vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa = *v) { g_autoptr(GPtrArray) shadow_vqs =3D NULL; - uint64_t dev_features, svq_features; - int r; - bool ok; - - if (!v->shadow_vqs_enabled) { - return 0; - } - - r =3D vhost_vdpa_get_dev_features(hdev, &dev_features); - if (r !=3D 0) { - error_setg_errno(errp, -r, "Can't get vdpa device features"); - return r; - } - - svq_features =3D dev_features; - ok =3D vhost_svq_valid_features(svq_features, errp); - if (unlikely(!ok)) { - return -1; - } =20 shadow_vqs =3D g_ptr_array_new_full(hdev->nvqs, vhost_svq_free); for (unsigned n =3D 0; n < hdev->nvqs; ++n) { @@ -422,7 +402,6 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, = struct vhost_vdpa *v, } =20 v->shadow_vqs =3D g_steal_pointer(&shadow_vqs); - return 0; } =20 static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **er= rp) @@ -447,10 +426,7 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void= *opaque, Error **errp) dev->opaque =3D opaque ; v->listener =3D vhost_vdpa_memory_listener; v->msg_type =3D VHOST_IOTLB_MSG_V2; - ret =3D vhost_vdpa_init_svq(dev, v, errp); - if (ret) { - goto err; - } + vhost_vdpa_init_svq(dev, v); =20 if (!vhost_vdpa_first_dev(dev)) { return 0; @@ -460,10 +436,6 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void= *opaque, Error **errp) VIRTIO_CONFIG_S_DRIVER); =20 return 0; - -err: - ram_block_discard_disable(false); - return ret; } =20 static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev, diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index b6462f0192..e829ef1f43 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -118,9 +118,10 @@ static bool vhost_vdpa_net_valid_svq_features(uint64_t= features, Error **errp) if (invalid_dev_features) { error_setg(errp, "vdpa svq does not work with features 0x%" PRIx64, invalid_dev_features); + return false; } =20 - return !invalid_dev_features; + return vhost_svq_valid_features(features, errp); } =20 static int vhost_vdpa_net_check_device_id(struct vhost_net *net) --=20 2.31.1 From nobody Fri May 10 00:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671104026; cv=none; d=zohomail.com; s=zohoarc; b=CKedf7XO1L19ogtXPAZEAz+/+qXjWUoB9LN5FsEMXO9f2+CN1G7qDXzLOyC67gQYVl5TEoSRvxsnr2OCxuoLiYRJi4ynH8KE1h5v1MiQylhzq2l6ofmaubfzPD8GxWVAgOtq+g1upQTUJvDLuGXCZtUll/jIlCOIMLU7VdIDkxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671104026; 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=Xgz+q+nkh20Rxi7Ya77r3f1WK5Zz4XbA/xuiyyNphGI=; b=gFbLqXcZV5M96ubuHc430HkOwgT4KMycNqHq3N0gH1t817yH6kKG2kP2dmYBUm9b65FsqLtdYzUpHulkJDPb8Al+GeQxwXb3XbZw3jjRB49bP+ZUbbW/f3WMXX050peTTQtj2lL6Y2WUCOXPY9/9tcuCJezJKP6TBjZXJZvbvTQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167110402619071.85343156171132; Thu, 15 Dec 2022 03:33:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5mTY-0002do-4A; Thu, 15 Dec 2022 06:32:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTW-0002dC-6b for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTU-0006nD-SK for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:29 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-618-3DVIKixCND-7Fahk1cNZDA-1; Thu, 15 Dec 2022 06:32:25 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 81C3E80234E; Thu, 15 Dec 2022 11:32:24 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31AF12166B26; Thu, 15 Dec 2022 11:32:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671103948; 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=Xgz+q+nkh20Rxi7Ya77r3f1WK5Zz4XbA/xuiyyNphGI=; b=cDQGo9o5tHDz20PQ3MPBj9CxwmV+OnHtrEkGGo1oI6vA6cLeDXiJ1wi0RY0BaBaLgYa5Jh HfSW1BQay06UOcHp4Xl9CKnS3zJCtfcN8Ltq2bQVMCu/4geMS5mkLOnjlxvasneLvEpDBi g8WH31L3Oo5S+DCfVAcLpb7tcf54J9k= X-MC-Unique: 3DVIKixCND-7Fahk1cNZDA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Stefano Garzarella , Zhu Lingshan , Si-Wei Liu , Laurent Vivier , "Gonglei (Arei)" , Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Cindy Lu , Gautam Dawar , Eli Cohen , Cornelia Huck , Paolo Bonzini , Longpeng , Harpreet Singh Anand , Parav Pandit , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v9 08/12] vdpa: allocate SVQ array unconditionally Date: Thu, 15 Dec 2022 12:31:40 +0100 Message-Id: <20221215113144.322011-9-eperezma@redhat.com> In-Reply-To: <20221215113144.322011-1-eperezma@redhat.com> References: <20221215113144.322011-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671104028411100003 SVQ may run or not in a device depending on runtime conditions (for example, if the device can move CVQ to its own group or not). Allocate the SVQ array unconditionally at startup, since its hard to move this allocation elsewhere. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 5039d9bb2f..86e1fa8e9e 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -532,10 +532,6 @@ static void vhost_vdpa_svq_cleanup(struct vhost_dev *d= ev) struct vhost_vdpa *v =3D dev->opaque; size_t idx; =20 - if (!v->shadow_vqs) { - return; - } - for (idx =3D 0; idx < v->shadow_vqs->len; ++idx) { vhost_svq_stop(g_ptr_array_index(v->shadow_vqs, idx)); } --=20 2.31.1 From nobody Fri May 10 00:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671104237; cv=none; d=zohomail.com; s=zohoarc; b=k5dBBRDHDbShWCaugkwJAjkOMUAF2UoijoZUoPrQAKGGiUTvPmGbav3z8JeChxW6197IOvMuJTQHZ1/Sx7b3KGoqHp0N5ITSZNrJ9CDodD1Rqdkoeac4JrBRSW1QO6kDJ86ifNQuGDUbsWCK4CmK8MS3j2hwaNmfnjT3EGeS0d0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671104237; 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=2MfiRtTFamLMgHlUz7mclmxu7zXNnIyauq4FC3uxYWE=; b=I5gmsEZd0lMN+8npaS7gYyOd/h6V2Y6pBgp6Uz0bnpJakzLoKXXjBBVckw0skfhvoUP8ML6qFa3K782vLKdU9V7gi9hgTD7sNUG3Y15rYkI8csjt6z+xa1yy4OYpLQTOGDm81DIa2W1u2grvYmwcaQrmc/N0Yt1VdP2WzPVP90A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671104237357774.0455664436845; Thu, 15 Dec 2022 03:37:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5mTm-0002g1-9y; Thu, 15 Dec 2022 06:32:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTc-0002e4-2j for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTa-0006nq-3I for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:35 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-63-fZ0xZL_DOxuVUvxzLj1rcQ-1; Thu, 15 Dec 2022 06:32:29 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 64C9E185A794; Thu, 15 Dec 2022 11:32:28 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBC592166B26; Thu, 15 Dec 2022 11:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671103953; 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=2MfiRtTFamLMgHlUz7mclmxu7zXNnIyauq4FC3uxYWE=; b=HTUUb9dZFiGacqCEa/1CGpwIKBQ9xsQEckY6kWxAThPtHTj8EioWRGs1EYp4hx9ViC6GkM Yequ/3pQbGFOGTJqxzrFYo2SwPO+iJHr1t+hlBivipvnBQaLxCkuq2SbMRH9nWnN3cOQ7s ioMqLgWNpcLYXqx8KQ0jTvD0+lVed3Y= X-MC-Unique: fZ0xZL_DOxuVUvxzLj1rcQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Stefano Garzarella , Zhu Lingshan , Si-Wei Liu , Laurent Vivier , "Gonglei (Arei)" , Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Cindy Lu , Gautam Dawar , Eli Cohen , Cornelia Huck , Paolo Bonzini , Longpeng , Harpreet Singh Anand , Parav Pandit , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v9 09/12] vdpa: add asid parameter to vhost_vdpa_dma_map/unmap Date: Thu, 15 Dec 2022 12:31:41 +0100 Message-Id: <20221215113144.322011-10-eperezma@redhat.com> In-Reply-To: <20221215113144.322011-1-eperezma@redhat.com> References: <20221215113144.322011-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671104238780100004 So the caller can choose which ASID is destined. No need to update the batch functions as they will always be called from memory listener updates at the moment. Memory listener updates will always update ASID 0, as it's the passthrough ASID. All vhost devices's ASID are 0 at this moment. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- v7: * Move comment on zero initailization of vhost_vdpa_dma_map above the functions. * Add VHOST_VDPA_GUEST_PA_ASID macro. v5: * Solve conflict, now vhost_vdpa_svq_unmap_ring returns void * Change comment on zero initialization. v4: Add comment specifying behavior if device does not support _F_ASID v3: Deleted unneeded space --- include/hw/virtio/vhost-vdpa.h | 14 ++++++++++--- hw/virtio/vhost-vdpa.c | 36 +++++++++++++++++++++++----------- net/vhost-vdpa.c | 6 +++--- hw/virtio/trace-events | 4 ++-- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 1111d85643..e57dfa1fd1 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -19,6 +19,12 @@ #include "hw/virtio/virtio.h" #include "standard-headers/linux/vhost_types.h" =20 +/* + * ASID dedicated to map guest's addresses. If SVQ is disabled it maps GP= A to + * qemu's IOVA. If SVQ is enabled it maps also the SVQ vring here + */ +#define VHOST_VDPA_GUEST_PA_ASID 0 + typedef struct VhostVDPAHostNotifier { MemoryRegion mr; void *addr; @@ -29,6 +35,7 @@ typedef struct vhost_vdpa { int index; uint32_t msg_type; bool iotlb_batch_begin_sent; + uint32_t address_space_id; MemoryListener listener; struct vhost_vdpa_iova_range iova_range; uint64_t acked_features; @@ -42,8 +49,9 @@ typedef struct vhost_vdpa { VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; =20 -int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size, - void *vaddr, bool readonly); -int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, hwaddr size); +int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, + hwaddr size, void *vaddr, bool readonly); +int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, + hwaddr size); =20 #endif diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 86e1fa8e9e..5e591a8fda 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -72,22 +72,28 @@ static bool vhost_vdpa_listener_skipped_section(MemoryR= egionSection *section, return false; } =20 -int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size, - void *vaddr, bool readonly) +/* + * The caller must set asid =3D 0 if the device does not support asid. + * This is not an ABI break since it is set to 0 by the initializer anyway. + */ +int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, + hwaddr size, void *vaddr, bool readonly) { struct vhost_msg_v2 msg =3D {}; int fd =3D v->device_fd; int ret =3D 0; =20 msg.type =3D v->msg_type; + msg.asid =3D asid; msg.iotlb.iova =3D iova; msg.iotlb.size =3D size; msg.iotlb.uaddr =3D (uint64_t)(uintptr_t)vaddr; msg.iotlb.perm =3D readonly ? VHOST_ACCESS_RO : VHOST_ACCESS_RW; msg.iotlb.type =3D VHOST_IOTLB_UPDATE; =20 - trace_vhost_vdpa_dma_map(v, fd, msg.type, msg.iotlb.iova, msg.iotlb.siz= e, - msg.iotlb.uaddr, msg.iotlb.perm, msg.iotlb.typ= e); + trace_vhost_vdpa_dma_map(v, fd, msg.type, msg.asid, msg.iotlb.iova, + msg.iotlb.size, msg.iotlb.uaddr, msg.iotlb.pe= rm, + msg.iotlb.type); =20 if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { error_report("failed to write, fd=3D%d, errno=3D%d (%s)", @@ -98,18 +104,24 @@ int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr io= va, hwaddr size, return ret; } =20 -int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, hwaddr size) +/* + * The caller must set asid =3D 0 if the device does not support asid. + * This is not an ABI break since it is set to 0 by the initializer anyway. + */ +int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, + hwaddr size) { struct vhost_msg_v2 msg =3D {}; int fd =3D v->device_fd; int ret =3D 0; =20 msg.type =3D v->msg_type; + msg.asid =3D asid; msg.iotlb.iova =3D iova; msg.iotlb.size =3D size; msg.iotlb.type =3D VHOST_IOTLB_INVALIDATE; =20 - trace_vhost_vdpa_dma_unmap(v, fd, msg.type, msg.iotlb.iova, + trace_vhost_vdpa_dma_unmap(v, fd, msg.type, msg.asid, msg.iotlb.iova, msg.iotlb.size, msg.iotlb.type); =20 if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { @@ -229,8 +241,8 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, } =20 vhost_vdpa_iotlb_batch_begin_once(v); - ret =3D vhost_vdpa_dma_map(v, iova, int128_get64(llsize), - vaddr, section->readonly); + ret =3D vhost_vdpa_dma_map(v, VHOST_VDPA_GUEST_PA_ASID, iova, + int128_get64(llsize), vaddr, section->readonl= y); if (ret) { error_report("vhost vdpa map fail!"); goto fail_map; @@ -303,7 +315,8 @@ static void vhost_vdpa_listener_region_del(MemoryListen= er *listener, vhost_iova_tree_remove(v->iova_tree, *result); } vhost_vdpa_iotlb_batch_begin_once(v); - ret =3D vhost_vdpa_dma_unmap(v, iova, int128_get64(llsize)); + ret =3D vhost_vdpa_dma_unmap(v, VHOST_VDPA_GUEST_PA_ASID, iova, + int128_get64(llsize)); if (ret) { error_report("vhost_vdpa dma unmap error!"); } @@ -869,7 +882,7 @@ static void vhost_vdpa_svq_unmap_ring(struct vhost_vdpa= *v, hwaddr addr) } =20 size =3D ROUND_UP(result->size, qemu_real_host_page_size()); - r =3D vhost_vdpa_dma_unmap(v, result->iova, size); + r =3D vhost_vdpa_dma_unmap(v, v->address_space_id, result->iova, size); if (unlikely(r < 0)) { error_report("Unable to unmap SVQ vring: %s (%d)", g_strerror(-r),= -r); return; @@ -909,7 +922,8 @@ static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa *= v, DMAMap *needle, return false; } =20 - r =3D vhost_vdpa_dma_map(v, needle->iova, needle->size + 1, + r =3D vhost_vdpa_dma_map(v, v->address_space_id, needle->iova, + needle->size + 1, (void *)(uintptr_t)needle->translated_addr, needle->perm =3D=3D IOMMU_RO); if (unlikely(r !=3D 0)) { diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index e829ef1f43..a592ee07ec 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -259,7 +259,7 @@ static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa = *v, void *addr) return; } =20 - r =3D vhost_vdpa_dma_unmap(v, map->iova, map->size + 1); + r =3D vhost_vdpa_dma_unmap(v, v->address_space_id, map->iova, map->siz= e + 1); if (unlikely(r !=3D 0)) { error_report("Device cannot unmap: %s(%d)", g_strerror(r), r); } @@ -299,8 +299,8 @@ static int vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v,= void *buf, size_t size, return r; } =20 - r =3D vhost_vdpa_dma_map(v, map.iova, vhost_vdpa_net_cvq_cmd_page_len(= ), buf, - !write); + r =3D vhost_vdpa_dma_map(v, v->address_space_id, map.iova, + vhost_vdpa_net_cvq_cmd_page_len(), buf, !write); if (unlikely(r < 0)) { goto dma_map_err; } diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 14fc5b9bb2..96da58a41f 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -30,8 +30,8 @@ vhost_user_write(uint32_t req, uint32_t flags) "req:%d fl= ags:0x%"PRIx32"" vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" =20 # vhost-vdpa.c -vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint64_t iova, u= int64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d m= sg_type: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" p= erm: 0x%"PRIx8" type: %"PRIu8 -vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint64_t iova,= uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" iova: 0x%= "PRIx64" size: 0x%"PRIx64" type: %"PRIu8 +vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, u= int64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "v= dpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0= x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 +vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid,= uint64_t iova, uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PR= Iu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 vhost_vdpa_listener_begin_batch(void *v, int fd, uint32_t msg_type, uint8_= t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t typ= e) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, = void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" va= ddr: %p read-only: %d" --=20 2.31.1 From nobody Fri May 10 00:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671104205; cv=none; d=zohomail.com; s=zohoarc; b=XqNwSSwg99wB7txbdvtceeM99AVNeOYYctjhgxSk+3uxb+zyc0I5YdWd5HC3R7uCytIG82I7h3Cp2IsfBnfZ3+JVn2CuWmXAgbomtAKVlmTUHrL3Cd4bUz9OFmx+K2Wgym6++sJeQs4qK5os0THzSl2IBVUTY+ogBHlPh1hZuPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671104205; 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=3XrKtgy7SKfYb4zM2Z5iKSfvbYsX8frhW78q2PCn1DA=; b=VUIBw6iQOyacQ3gyXoFwE3V0Lhf8ZbNPwCDJzV9IKxDyePFO4ZJVr+PhPLaXoQB6qW3tDb9ZhvM/EdN9uJ0nVWnaLFybZ4cEPTkoAg5B3zdmVfvPu7qf5Z+5ZeWrRtbdZszhyezV8KdCteVsv6o2BgC/Yev0rszG7AeihvfOufo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671104205600981.1279328586644; Thu, 15 Dec 2022 03:36:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5mTl-0002fz-V0; Thu, 15 Dec 2022 06:32:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTe-0002eF-Lr for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTd-0006oD-91 for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:38 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-57-jjKgYOtjOKK7VB0JV0BraQ-1; Thu, 15 Dec 2022 06:32:32 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D687B3C11043; Thu, 15 Dec 2022 11:32:31 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9E612166B26; Thu, 15 Dec 2022 11:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671103956; 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=3XrKtgy7SKfYb4zM2Z5iKSfvbYsX8frhW78q2PCn1DA=; b=ceR5oO1IqIIks7I08rr5iXNwrRD+5MecseTsfjbSDwgyJTGFj8RLJPKW7QEiZA+daqM9i4 pmKLBjg0tsPm66BQ0Nf+J/il4yWWknMXBLgqEcfPusS8Z90PxrTy3R4M90LP0Fr9CUZDtm 3Qfm4oSBpq+0Lv28b/tmXIb7ixiCMws= X-MC-Unique: jjKgYOtjOKK7VB0JV0BraQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Stefano Garzarella , Zhu Lingshan , Si-Wei Liu , Laurent Vivier , "Gonglei (Arei)" , Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Cindy Lu , Gautam Dawar , Eli Cohen , Cornelia Huck , Paolo Bonzini , Longpeng , Harpreet Singh Anand , Parav Pandit , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v9 10/12] vdpa: store x-svq parameter in VhostVDPAState Date: Thu, 15 Dec 2022 12:31:42 +0100 Message-Id: <20221215113144.322011-11-eperezma@redhat.com> In-Reply-To: <20221215113144.322011-1-eperezma@redhat.com> References: <20221215113144.322011-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671104206489100003 CVQ can be shadowed two ways: - Device has x-svq=3Don parameter (current way) - The device can isolate CVQ in its own vq group QEMU needs to check for the second condition dynamically, because CVQ index is not known before the driver ack the features. Since this is dynamic, the CVQ isolation could vary with different conditions, making it possible to go from "not isolated group" to "isolated". Saving the cmdline parameter in an extra field so we never disable CVQ SVQ in case the device was started with x-svq cmdline. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- net/vhost-vdpa.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index a592ee07ec..bff72717d0 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -38,6 +38,8 @@ typedef struct VhostVDPAState { void *cvq_cmd_out_buffer; virtio_net_ctrl_ack *status; =20 + /* The device always have SVQ enabled */ + bool always_svq; bool started; } VhostVDPAState; =20 @@ -568,6 +570,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, =20 s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; + s->always_svq =3D svq; s->vhost_vdpa.shadow_vqs_enabled =3D svq; s->vhost_vdpa.iova_range =3D iova_range; s->vhost_vdpa.iova_tree =3D iova_tree; --=20 2.31.1 From nobody Fri May 10 00:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671104200; cv=none; d=zohomail.com; s=zohoarc; b=hQXvs0FqD5CQUNhsi6XP3rv42GFHzoMtCHn+mXI/+Xh1NRy4/wSRgRh6lca8hdcnG7ATaeLJCGsFzrt6QgvrTGBfh42EfppIkoLU3SkeWyc9/X9F72PJhIjLpxDsT3+cjezunMREHaVDUZD1vSa+4rBCr5Bgc9UXEABWJp3xzbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671104200; 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=dXGuhwfeZjBxFZikNv60tkGbMJIoXpvVQ00BB1y2Yk8=; b=KeamGih7sVhdpVtEW3LthFGlwK6BoFP0GTlTQOo+bVRAfBB18R9mZpiOBwIMzNOC0tgY2kzTc30wSSacaJ1ogiOjB6dNuYrvu0GhbOmBvSeso5A92Kd6NBYqqaaUvEoQesBrKwlvWdmcf8fo0DhnrGk0zRhctB9wnvzkOUYZ69I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671104200046758.089715320302; Thu, 15 Dec 2022 03:36:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5mTl-0002fV-9I; Thu, 15 Dec 2022 06:32:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTh-0002eT-IU for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTf-0006oO-QN for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:41 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-302-vKKsX5eoP3KDbGp0Okt8eQ-1; Thu, 15 Dec 2022 06:32:35 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4D713802C1B; Thu, 15 Dec 2022 11:32:35 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2686D2166B26; Thu, 15 Dec 2022 11:32:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671103959; 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=dXGuhwfeZjBxFZikNv60tkGbMJIoXpvVQ00BB1y2Yk8=; b=bs0gpOsMjv2BFFpGNPpLi15HkvTxLjVYu219GRgXCNzhGy5qccivsSDXisLCrHVbkpAS9+ rL/h8738T9Bbuan3spQz9AB9oKrdGBV5uzoAFlsIA6hO5yHB7S5SZAhz+HA9PmkzQhrX4J FuATu5gfb2NAczl+oHhEB1T9fTiJhDs= X-MC-Unique: vKKsX5eoP3KDbGp0Okt8eQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Stefano Garzarella , Zhu Lingshan , Si-Wei Liu , Laurent Vivier , "Gonglei (Arei)" , Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Cindy Lu , Gautam Dawar , Eli Cohen , Cornelia Huck , Paolo Bonzini , Longpeng , Harpreet Singh Anand , Parav Pandit , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v9 11/12] vdpa: add shadow_data to vhost_vdpa Date: Thu, 15 Dec 2022 12:31:43 +0100 Message-Id: <20221215113144.322011-12-eperezma@redhat.com> In-Reply-To: <20221215113144.322011-1-eperezma@redhat.com> References: <20221215113144.322011-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671104200487100001 The memory listener that thells the device how to convert GPA to qemu's va is registered against CVQ vhost_vdpa. memory listener translations are always ASID 0, CVQ ones are ASID 1 if supported. Let's tell the listener if it needs to register them on iova tree or not. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- v7: Rename listener_shadow_vq to shadow_data v5: Solve conflict about vhost_iova_tree_remove accepting mem_region by value. --- include/hw/virtio/vhost-vdpa.h | 2 ++ hw/virtio/vhost-vdpa.c | 6 +++--- net/vhost-vdpa.c | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index e57dfa1fd1..45b969a311 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -40,6 +40,8 @@ typedef struct vhost_vdpa { struct vhost_vdpa_iova_range iova_range; uint64_t acked_features; bool shadow_vqs_enabled; + /* Vdpa must send shadow addresses as IOTLB key for data queues, not G= PA */ + bool shadow_data; /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; GPtrArray *shadow_vqs; diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 5e591a8fda..48d8c60e76 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -224,7 +224,7 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, vaddr, section->readonly); =20 llsize =3D int128_sub(llend, int128_make64(iova)); - if (v->shadow_vqs_enabled) { + if (v->shadow_data) { int r; =20 mem_region.translated_addr =3D (hwaddr)(uintptr_t)vaddr, @@ -251,7 +251,7 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, return; =20 fail_map: - if (v->shadow_vqs_enabled) { + if (v->shadow_data) { vhost_iova_tree_remove(v->iova_tree, mem_region); } =20 @@ -296,7 +296,7 @@ static void vhost_vdpa_listener_region_del(MemoryListen= er *listener, =20 llsize =3D int128_sub(llend, int128_make64(iova)); =20 - if (v->shadow_vqs_enabled) { + if (v->shadow_data) { const DMAMap *result; const void *vaddr =3D memory_region_get_ram_ptr(section->mr) + section->offset_within_region + diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index bff72717d0..710c5efe96 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -573,6 +573,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, s->always_svq =3D svq; s->vhost_vdpa.shadow_vqs_enabled =3D svq; s->vhost_vdpa.iova_range =3D iova_range; + s->vhost_vdpa.shadow_data =3D svq; s->vhost_vdpa.iova_tree =3D iova_tree; if (!is_datapath) { s->cvq_cmd_out_buffer =3D qemu_memalign(qemu_real_host_page_size(), --=20 2.31.1 From nobody Fri May 10 00:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671104096; cv=none; d=zohomail.com; s=zohoarc; b=SQihxGBGjgKpkuoka5ieCngMjvxw/21xzDkRC2SyhcW2C02yel17mKHkzVAG7wVJyZUMm0GAitQiqeMlrrmFcFLI0ugAu+7RgneH9O9F6Js6TEOanVOALunaVIId+JwBJfd5ZxgyjMqXaiE+e49xh7VCcOaHTPtk0Rl5vw2UyYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671104096; 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=bgm13BxT3w9/bf/Q3/tjjDwn3ewco6Sm6e47Y2FWYg4=; b=PCi7qfG6qVHEF3lm1CNsE+TrTmE2F3GFeBeDNXvwTJJMXrS3PqcnkBjhPNXAi8o+QxK9erxk/EYOhtPEkUhYqeCfWvgA8jWsB2Wot2/5Et+11936fwcQhW7fh+3UssoP6MEUOuXFa0LSUwNAD0dzDzqu/dSfVrZWcRv+z0K4OiE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671104096299497.81015800880823; Thu, 15 Dec 2022 03:34:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5mTo-0002gf-NQ; Thu, 15 Dec 2022 06:32:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTm-0002gI-W7 for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5mTl-0006p0-5K for qemu-devel@nongnu.org; Thu, 15 Dec 2022 06:32:46 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-384-zqpl_RVmMraUk_Kl-3M2Sg-1; Thu, 15 Dec 2022 06:32:39 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B8A02382C96F; Thu, 15 Dec 2022 11:32:38 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 903002166B26; Thu, 15 Dec 2022 11:32:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671103964; 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=bgm13BxT3w9/bf/Q3/tjjDwn3ewco6Sm6e47Y2FWYg4=; b=CQVYwOS2VRy8YdISBoNnuxD5OeFVrxw0SUP0l1osXYGCiIHn0UxzRgltMPtT5AlHrDWHFy rAkH6ZphWlIDN2R7J6Dk1BoWurMlddOMeyY/1XkAr7osU/oO/8Y/pQt6slhiPyF3jScrUK EDqgCoMfdwYKpJIF/ZPYHoLghjgsCjY= X-MC-Unique: zqpl_RVmMraUk_Kl-3M2Sg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Liuxiangdong , Stefano Garzarella , Zhu Lingshan , Si-Wei Liu , Laurent Vivier , "Gonglei (Arei)" , Stefan Hajnoczi , Jason Wang , "Michael S. Tsirkin" , Cindy Lu , Gautam Dawar , Eli Cohen , Cornelia Huck , Paolo Bonzini , Longpeng , Harpreet Singh Anand , Parav Pandit , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v9 12/12] vdpa: always start CVQ in SVQ mode if possible Date: Thu, 15 Dec 2022 12:31:44 +0100 Message-Id: <20221215113144.322011-13-eperezma@redhat.com> In-Reply-To: <20221215113144.322011-1-eperezma@redhat.com> References: <20221215113144.322011-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671104097493100003 Isolate control virtqueue in its own group, allowing to intercept control commands but letting dataplane run totally passthrough to the guest. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- v9: * Reuse iova_range fetched from the device at initialization, instead of fetch it again at vhost_vdpa_net_cvq_start. * Add comment about how migration is blocked in case ASID does not met our expectations. * Delete warning about CVQ group not being independent. v8: * Do not allocate iova_tree on net_init_vhost_vdpa if only CVQ is shadowed. Move the iova_tree handling in this case to vhost_vdpa_net_cvq_start and vhost_vdpa_net_cvq_stop. v7: * Never ask for number of address spaces, just react if isolation is not possible. * Return ASID ioctl errors instead of masking them as if the device has no asid. * Simplify net_init_vhost_vdpa logic * Add "if possible" suffix v6: * Disable control SVQ if the device does not support it because of features. v5: * Fixing the not adding cvq buffers when x-svq=3Don is specified. * Move vring state in vhost_vdpa_get_vring_group instead of using a parameter. * Rename VHOST_VDPA_NET_CVQ_PASSTHROUGH to VHOST_VDPA_NET_DATA_ASID v4: * Squash vhost_vdpa_cvq_group_is_independent. * Rebased on last CVQ start series, that allocated CVQ cmd bufs at load * Do not check for cvq index on vhost_vdpa_net_prepare, we only have one that callback registered in that NetClientInfo. v3: * Make asid related queries print a warning instead of returning an error and stop the start of qemu. --- hw/virtio/vhost-vdpa.c | 3 +- net/vhost-vdpa.c | 110 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 48d8c60e76..8cd00f5a96 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -638,7 +638,8 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev = *dev) { uint64_t features; uint64_t f =3D 0x1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2 | - 0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH; + 0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH | + 0x1ULL << VHOST_BACKEND_F_IOTLB_ASID; int r; =20 if (vhost_vdpa_call(dev, VHOST_GET_BACKEND_FEATURES, &features)) { diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 710c5efe96..d36664f33a 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -102,6 +102,8 @@ static const uint64_t vdpa_svq_device_features =3D BIT_ULL(VIRTIO_NET_F_RSC_EXT) | BIT_ULL(VIRTIO_NET_F_STANDBY); =20 +#define VHOST_VDPA_NET_CVQ_ASID 1 + VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); @@ -243,6 +245,40 @@ static NetClientInfo net_vhost_vdpa_info =3D { .check_peer_type =3D vhost_vdpa_check_peer_type, }; =20 +static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index) +{ + struct vhost_vring_state state =3D { + .index =3D vq_index, + }; + int r =3D ioctl(device_fd, VHOST_VDPA_GET_VRING_GROUP, &state); + + if (unlikely(r < 0)) { + error_report("Cannot get VQ %u group: %s", vq_index, + g_strerror(errno)); + return r; + } + + return state.num; +} + +static int vhost_vdpa_set_address_space_id(struct vhost_vdpa *v, + unsigned vq_group, + unsigned asid_num) +{ + struct vhost_vring_state asid =3D { + .index =3D vq_group, + .num =3D asid_num, + }; + int r; + + r =3D ioctl(v->device_fd, VHOST_VDPA_SET_GROUP_ASID, &asid); + if (unlikely(r < 0)) { + error_report("Can't set vq group %u asid %u, errno=3D%d (%s)", + asid.index, asid.num, errno, g_strerror(errno)); + } + return r; +} + static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa *v, void *addr) { VhostIOVATree *tree =3D v->iova_tree; @@ -317,11 +353,75 @@ dma_map_err: static int vhost_vdpa_net_cvq_start(NetClientState *nc) { VhostVDPAState *s; - int r; + struct vhost_vdpa *v; + uint64_t backend_features; + int64_t cvq_group; + int cvq_index, r; =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); =20 s =3D DO_UPCAST(VhostVDPAState, nc, nc); + v =3D &s->vhost_vdpa; + + v->shadow_data =3D s->always_svq; + v->shadow_vqs_enabled =3D s->always_svq; + s->vhost_vdpa.address_space_id =3D VHOST_VDPA_GUEST_PA_ASID; + + if (s->always_svq) { + /* SVQ is already configured for all virtqueues */ + goto out; + } + + /* + * If we early return in these cases SVQ will not be enabled. The migr= ation + * will be blocked as long as vhost-vdpa backends will not offer _F_LO= G. + * + * Calling VHOST_GET_BACKEND_FEATURES as they are not available in v->= dev + * yet. + */ + r =3D ioctl(v->device_fd, VHOST_GET_BACKEND_FEATURES, &backend_feature= s); + if (unlikely(r < 0)) { + error_report("Cannot get vdpa backend_features: %s(%d)", + g_strerror(errno), errno); + return -1; + } + if (!(backend_features & VHOST_BACKEND_F_IOTLB_ASID) || + !vhost_vdpa_net_valid_svq_features(v->dev->features, NULL)) { + return 0; + } + + /* + * Check if all the virtqueues of the virtio device are in a different= vq + * than the last vq. VQ group of last group passed in cvq_group. + */ + cvq_index =3D v->dev->vq_index_end - 1; + cvq_group =3D vhost_vdpa_get_vring_group(v->device_fd, cvq_index); + if (unlikely(cvq_group < 0)) { + return cvq_group; + } + for (int i =3D 0; i < cvq_index; ++i) { + int64_t group =3D vhost_vdpa_get_vring_group(v->device_fd, i); + + if (unlikely(group < 0)) { + return group; + } + + if (group =3D=3D cvq_group) { + return 0; + } + } + + r =3D vhost_vdpa_set_address_space_id(v, cvq_group, VHOST_VDPA_NET_CVQ= _ASID); + if (unlikely(r < 0)) { + return r; + } + + v->iova_tree =3D vhost_iova_tree_new(v->iova_range.first, + v->iova_range.last); + v->shadow_vqs_enabled =3D true; + s->vhost_vdpa.address_space_id =3D VHOST_VDPA_NET_CVQ_ASID; + +out: if (!s->vhost_vdpa.shadow_vqs_enabled) { return 0; } @@ -350,6 +450,14 @@ static void vhost_vdpa_net_cvq_stop(NetClientState *nc) if (s->vhost_vdpa.shadow_vqs_enabled) { vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer); vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->status); + if (!s->always_svq) { + /* + * If only the CVQ is shadowed we can delete this safely. + * If all the VQs are shadows this will be needed by the time = the + * device is started again to register SVQ vrings and similar. + */ + g_clear_pointer(&s->vhost_vdpa.iova_tree, vhost_iova_tree_dele= te); + } } } =20 --=20 2.31.1