From nobody Thu Apr 25 19:35:43 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=1669305280; cv=none; d=zohomail.com; s=zohoarc; b=SvDNwvOWS9tGU7w4CG5SywmURDEhsyl0tGljwdSgzLBZoT+BjVr6JqHYFOHoQUYJTgX6OfwBj41t9h2JXmzwOwr7ppaV/d43Igj7D9Gi5bZDD2LL0aEtBKsEKIpogHRzjkfXMyuZTAWjhr9sRt1tVVXw6qKHPFg5CEQqxGWpO+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669305280; 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=n44OonAUWrrZZb/4zX0awJACxWCjNeW2K6XtvhQ5xO8RE9sOdYg+rItkc9w5wMztCeraW9er7y9FWzvUO5OQJNEYeCNgscKSf5j2y/ShUXjF/bg0/oOpD9tldJtcioCOOAoeUswMVFKCjRH3dqvwVLRime67QOjK92ZOzxYEv4Q= 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 1669305280655565.5858364616075; Thu, 24 Nov 2022 07:54:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyEWP-0002XP-U1; Thu, 24 Nov 2022 10:52:17 -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 1oyEWO-0002XG-7d for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:16 -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 1oyEWM-0004Ea-RV for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:15 -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-658-eNLmhS8vPZ-5GEI775XNGQ-1; Thu, 24 Nov 2022 10:52:10 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8C54E800B23; Thu, 24 Nov 2022 15:52:09 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A0F2111DCE6; Thu, 24 Nov 2022 15:52:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669305133; 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=M4YZ/lgka2uoPWsOJPKrWSgNSPeJfBAVWNRk5wUFTm/2j25FklvxpdyjfnoO0F+nfgVO+s z0qYnyVnBrUEqACpnHjwI49zWLcAHqivh7ptUdv3MTLjLtDpJTl3uZxOTafBDdYT42FQDg g7k2QWJ2k/pvFRlW8o4wzHmiTz0nnc8= X-MC-Unique: eNLmhS8vPZ-5GEI775XNGQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Cornelia Huck , Eli Cohen , Jason Wang , Cindy Lu , Parav Pandit , Laurent Vivier , "Michael S. Tsirkin" , Si-Wei Liu , Zhu Lingshan , Paolo Bonzini , Stefan Hajnoczi , Gautam Dawar , Liuxiangdong , "Gonglei (Arei)" , Harpreet Singh Anand , Stefano Garzarella Subject: [PATCH for 8.0 v8 01/12] vdpa: use v->shadow_vqs_enabled in vhost_vdpa_svqs_start & stop Date: Thu, 24 Nov 2022 16:51:47 +0100 Message-Id: <20221124155158.2109884-2-eperezma@redhat.com> In-Reply-To: <20221124155158.2109884-1-eperezma@redhat.com> References: <20221124155158.2109884-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.3 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: 1669305281959100001 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 Thu Apr 25 19:35:43 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=1669305340; cv=none; d=zohomail.com; s=zohoarc; b=fW1UAt8Vb2dRaCJSj7XglZbHHWdZO4YLbjRAYqfdCkyys7hzHnGxdTzLwZAidSd/lEo/QpNu2ivQpr7+Zx5uS31J7HKBwQULaLpxrgc7/fDGLnywlPdISmQegGYffEOIh3KYq5w5NSSwnb92MJ5sjFoyELPNwAvRve6hslTAJQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669305340; 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=lx76l/DUW/abARENRVUsT3JeSj0ZZ1KzDzUTp5ysGNGvEvM0BjT+VsXkr/QkluDQBdG5mcEJptE6DH9gGCHAmUu9gh8YtfQF2fpdb7MnaVXltn6E1wQf0rgtFLk8MVdiCw4ctF468eklOvaWUmaLaaLEeGwl5rF7EBCs87pG0VM= 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 1669305340809436.962697562662; Thu, 24 Nov 2022 07:55:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyEWT-0002YH-Hs; Thu, 24 Nov 2022 10:52: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 1oyEWS-0002Y3-61 for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52: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 1oyEWQ-0004F2-Nf for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:19 -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-65-JM78j4smMnO63DX_IuidHQ-1; Thu, 24 Nov 2022 10:52:13 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EB533833A06; Thu, 24 Nov 2022 15:52:12 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3FE7111DCE6; Thu, 24 Nov 2022 15:52:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669305138; 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=cxtMbH23YShAmlqryEycRj5Ey3y3aqc8hJohR+cY8q94l0CUTw5dqIP9nySr0CpBZdOx80 P+866erMxOXzAKHqxWlPXb911/nabmc/5Cwg6pHCXgsvRy6YaqFMPVERECEq0ZCWnih31i 05Dv8OM+toT86vL6ONEWAscY9ztp+9g= X-MC-Unique: JM78j4smMnO63DX_IuidHQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Cornelia Huck , Eli Cohen , Jason Wang , Cindy Lu , Parav Pandit , Laurent Vivier , "Michael S. Tsirkin" , Si-Wei Liu , Zhu Lingshan , Paolo Bonzini , Stefan Hajnoczi , Gautam Dawar , Liuxiangdong , "Gonglei (Arei)" , Harpreet Singh Anand , Stefano Garzarella Subject: [PATCH for 8.0 v8 02/12] vhost: set SVQ device call handler at SVQ start Date: Thu, 24 Nov 2022 16:51:48 +0100 Message-Id: <20221124155158.2109884-3-eperezma@redhat.com> In-Reply-To: <20221124155158.2109884-1-eperezma@redhat.com> References: <20221124155158.2109884-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.3 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: 1669305342134100001 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 Thu Apr 25 19:35:43 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=1669305400; cv=none; d=zohomail.com; s=zohoarc; b=Z3FlTu2oIWi9KZARIpstJqYckdR6juVRo2CwEp77MvNlpVHqLwhhlKTxIKvzWLdh7qoPolcKanypIPQXUH4M6ZeGWUrgQeRPgcY8sLUI8MFJJ7hD12rYOm8b+3vduaDoOm/gTRNLDzQT52vyltay5W3bJIZsMP0p4zCVHJr/YfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669305400; 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=FZalBHA34DV8uWL9E2cjxaCj4CKQfLouDX8Dyvc2AZ+0PATjVe3TfJ/pSVQF5kPocYyR3j5pY2AC9ce9TlW5np+t9G0vE0+Fp2NFJF5EvCLlRibPgQqZAI/5M45Z06w1h5h2N3KT3gr41SVVP8nxf6JUVNsaZlfdrWIuaZc+KGY= 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 1669305400421614.276549904739; Thu, 24 Nov 2022 07:56:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyEWV-0002Ye-FE; Thu, 24 Nov 2022 10:52: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 1oyEWU-0002YU-Iq for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:22 -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 1oyEWS-0004F7-Vh for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:22 -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-319-CopEi7jLNsaV5SEWHQEFuA-1; Thu, 24 Nov 2022 10:52:17 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 674341C05B0C; Thu, 24 Nov 2022 15:52:16 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E2A1111DCE8; Thu, 24 Nov 2022 15:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669305139; 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=RS9pPlwueunf27w35W7D/9OHe0+gXXgIkE+EkeQ9AiFpfib9g+ak3NNKSXdFhvj3L181Nw GrDLtL0W5/Vk1WTtofyjBH0zeZ5uxalIvOpe6bYS8dT2vLYtnVebWCgDeHmhFMepuGSA7Y MchHNPpROS/QsY0hRl40PH/nmzdN3jg= X-MC-Unique: CopEi7jLNsaV5SEWHQEFuA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Cornelia Huck , Eli Cohen , Jason Wang , Cindy Lu , Parav Pandit , Laurent Vivier , "Michael S. Tsirkin" , Si-Wei Liu , Zhu Lingshan , Paolo Bonzini , Stefan Hajnoczi , Gautam Dawar , Liuxiangdong , "Gonglei (Arei)" , Harpreet Singh Anand , Stefano Garzarella Subject: [PATCH for 8.0 v8 03/12] vhost: allocate SVQ device file descriptors at device start Date: Thu, 24 Nov 2022 16:51:49 +0100 Message-Id: <20221124155158.2109884-4-eperezma@redhat.com> In-Reply-To: <20221124155158.2109884-1-eperezma@redhat.com> References: <20221124155158.2109884-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.3 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: 1669305402461100007 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 Thu Apr 25 19:35:43 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=1669305212; cv=none; d=zohomail.com; s=zohoarc; b=TsE1QfLfYYD7pnLq1swLNvcfl6y7n5Q38nb3RCS3PtfCdqAOYzuk6U2VPYpJEgaeLSPDJnv/4Q2qua2D+Ts1kD0l2lyO9bBLIsw9Y0lMt7meQoteKehn9KTkD0hnWXDw2BZ5cp7QZEkQ+Luio7KSVOWW7IA0zMJBd0PyEkYlNEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669305212; 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=4FrNEK9BW9vrejue8PJ2vXmvbvlWh0jBFggXf0s4JdU=; b=kmBHQLhk5HFPJ7CGW1ao9p3BuAHg7o5uiGpG0UiD5HWL2Mf+Nmg783h1HawE9YEeM75wblUxDIZHA8mZlQKkp2GY2c36L/VrpX4Fk1M86aQNuWiHtKP7S0QUoZZjg5Gzpw/2NGWHeUB4YyuF+Ydr7t5mGnZg1hkT1hK2MqBLBMY= 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 1669305212441524.760459760934; Thu, 24 Nov 2022 07:53:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyEWb-0002ZE-JC; Thu, 24 Nov 2022 10:52:29 -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 1oyEWZ-0002Z3-O4 for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:27 -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 1oyEWY-0004Fd-5y for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:27 -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-154-FPglt4DFOp2_Nqm4mCBFmg-1; Thu, 24 Nov 2022 10:52:20 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BEBCE1C05B0F; Thu, 24 Nov 2022 15:52:19 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE661111DCE6; Thu, 24 Nov 2022 15:52:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669305145; 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=4FrNEK9BW9vrejue8PJ2vXmvbvlWh0jBFggXf0s4JdU=; b=PU5q3Iwe3LVWRx6tol7UE78zKopq+QGwzTk0InUIhUr9JEI4A6V/5iJFqI06Sp1Tdfhmnc x8dRsEoBTOLKxkpGqS03EGRydMNiSS7195r0/GKBCnjouKUF7tRIiaKwuPTh1q+OuDDds2 k/i+iN4lPleQHa6439+z+y0pmsAQN7k= X-MC-Unique: FPglt4DFOp2_Nqm4mCBFmg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Cornelia Huck , Eli Cohen , Jason Wang , Cindy Lu , Parav Pandit , Laurent Vivier , "Michael S. Tsirkin" , Si-Wei Liu , Zhu Lingshan , Paolo Bonzini , Stefan Hajnoczi , Gautam Dawar , Liuxiangdong , "Gonglei (Arei)" , Harpreet Singh Anand , Stefano Garzarella Subject: [PATCH for 8.0 v8 04/12] vhost: move iova_tree set to vhost_svq_start Date: Thu, 24 Nov 2022 16:51:50 +0100 Message-Id: <20221124155158.2109884-5-eperezma@redhat.com> In-Reply-To: <20221124155158.2109884-1-eperezma@redhat.com> References: <20221124155158.2109884-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.3 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: 1669305213640100017 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 Thu Apr 25 19:35:43 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=1669305211; cv=none; d=zohomail.com; s=zohoarc; b=KNGJZ/pERXub7OghTNgTldM8A55RFeUmlMhkILeH/shpwXkbvJesyuD6dczJkv7+QqGbbYWqdrzbthU10GDA9XsQYirCzMw5hAJL6Km1e/vUTJirI+qt1gcCIhew6nCl2J6Hpq1bXigcEPH/FoypYXskzx8jzxxdPUjeT4QcMkQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669305211; 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=t+qR/RbRnzTmnM7TqHoM4ncCb2+5woArLJeALcMnuIs=; b=C+oUU1NRZlPGaAY7Lsz5o/Jb+UXn1/cWI+zVgnMOSFvKbSvsaamuNuiF8/lKKTTksjSYiadvdMPGT7+UkuTYpG/igAPE5C1/gluS4qsXFsQFthAFn04mIX38eyQRc0KTuBukQVUqtW5Szw93Yb6tEuKSkYDodr5jF/TwzdC+cBI= 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 1669305211628145.43079056479428; Thu, 24 Nov 2022 07:53:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyEWi-0002bC-CF; Thu, 24 Nov 2022 10:52:36 -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 1oyEWd-0002Zb-F2 for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:31 -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 1oyEWb-0004Fx-Op for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:30 -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-207-SCsHdSB7Nx-vINcTA543gw-1; Thu, 24 Nov 2022 10:52:23 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2FFCB101A528; Thu, 24 Nov 2022 15:52:23 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 12585111E3F8; Thu, 24 Nov 2022 15:52:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669305148; 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=t+qR/RbRnzTmnM7TqHoM4ncCb2+5woArLJeALcMnuIs=; b=IIiWumtQO68a0nfxWkaJvBdppHBT9QhcGBgqXFEbDNbOQA/+BfdO8TFreQ3OXfrIi0O+Rx YeS7DgPlE+9FbJdZ1uo05K2VKBE2WUHMso5mP+oRQnb6buF6rL7ErS6xKVpMVag1BZHieO U5Mz5u9dpULpOgeBBOcDmoDi+0lbUMI= X-MC-Unique: SCsHdSB7Nx-vINcTA543gw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Cornelia Huck , Eli Cohen , Jason Wang , Cindy Lu , Parav Pandit , Laurent Vivier , "Michael S. Tsirkin" , Si-Wei Liu , Zhu Lingshan , Paolo Bonzini , Stefan Hajnoczi , Gautam Dawar , Liuxiangdong , "Gonglei (Arei)" , Harpreet Singh Anand , Stefano Garzarella Subject: [PATCH for 8.0 v8 05/12] vdpa: add vhost_vdpa_net_valid_svq_features Date: Thu, 24 Nov 2022 16:51:51 +0100 Message-Id: <20221124155158.2109884-6-eperezma@redhat.com> In-Reply-To: <20221124155158.2109884-1-eperezma@redhat.com> References: <20221124155158.2109884-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.3 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: 1669305213631100015 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 2b4b85d8f8..88e0eec5fa 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 Thu Apr 25 19:35:43 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=1669305211; cv=none; d=zohomail.com; s=zohoarc; b=HPjwsF3hZx0lR83I0Z0m2c70/t75yLTqcMjrb+vCEWMmD/DSPpZFw3ocKW0gl9ayU8ecrVLLmHbBSfJyeb3cGRcFwCbQQ1rfpJ2/Fv9r6Bvl6vYZknggSdk4wQt9iyLzvfns67gw2Wky5Iw93ZWe3ul9Zu9jpgdXw+tohHKFCYI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669305211; 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=WhSLPDhzhFxcNenczXsbaDgqHh/5TPD4sy5gJvmX1zw=; b=BpjLceyMjBT5vv/KUl+9idAFcpN67+ZBX6ztT/SmtmP5SbzLJ9XQOdcNjRVfddY09+lqq0caFjrY2utNKAlblCzyyBpZOopUyRJdH5XXBCl6DovSNu6l6ZYWFBOY6ojqnZbeR4tjs3bzgcXGdqT/lWapJRTFPLI1pkUurnEz2dQ= 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 1669305211028970.0113923574903; Thu, 24 Nov 2022 07:53:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyEWm-0002bd-HH; Thu, 24 Nov 2022 10:52:40 -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 1oyEWe-0002b1-LR for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:34 -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 1oyEWd-0004G6-4o for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:32 -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-450-EUNe_WFbMRmg49YabOmcBw-1; Thu, 24 Nov 2022 10:52:27 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 86A9B811E75; Thu, 24 Nov 2022 15:52:26 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7706F111E3F8; Thu, 24 Nov 2022 15:52:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669305150; 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=WhSLPDhzhFxcNenczXsbaDgqHh/5TPD4sy5gJvmX1zw=; b=A/bbnGKCJzjJ1Vk+vTlHQ7udDMyCVWoO8pTvZ+oZZNTtGaE7XFfSc6AojgJS9OFCsTahiM 8PAcMaIDQ5OWh3bSjQAsgqgg4t3+sJeKt9fXPNLAM6d8Xw4+ylMzfNyrf7BHfLUkOQNXs9 cPuRkH4cOpeDlAnZKut/pefGqugxfXU= X-MC-Unique: EUNe_WFbMRmg49YabOmcBw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Cornelia Huck , Eli Cohen , Jason Wang , Cindy Lu , Parav Pandit , Laurent Vivier , "Michael S. Tsirkin" , Si-Wei Liu , Zhu Lingshan , Paolo Bonzini , Stefan Hajnoczi , Gautam Dawar , Liuxiangdong , "Gonglei (Arei)" , Harpreet Singh Anand , Stefano Garzarella Subject: [PATCH for 8.0 v8 06/12] vdpa: extract vhost_vdpa_svq_allocate_iova_tree Date: Thu, 24 Nov 2022 16:51:52 +0100 Message-Id: <20221124155158.2109884-7-eperezma@redhat.com> In-Reply-To: <20221124155158.2109884-1-eperezma@redhat.com> References: <20221124155158.2109884-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.3 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: 1669305211722100001 It can be allocated either if all virtqueues must be shadowed or if vdpa-net detects it can shadow only cvq. Extract in its own function so we can reuse it. Signed-off-by: Eugenio P=C3=A9rez --- net/vhost-vdpa.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 88e0eec5fa..9ee3bc4cd3 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -240,6 +240,22 @@ static NetClientInfo net_vhost_vdpa_info =3D { .check_peer_type =3D vhost_vdpa_check_peer_type, }; =20 +static int vhost_vdpa_get_iova_range(int fd, + struct vhost_vdpa_iova_range *iova_ra= nge) +{ + int ret =3D ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range); + + return ret < 0 ? -errno : 0; +} + +static VhostIOVATree *vhost_vdpa_svq_allocate_iova_tree(int vdpa_device_fd) +{ + struct vhost_vdpa_iova_range iova_range; + + vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); + return vhost_iova_tree_new(iova_range.first, iova_range.last); +} + static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa *v, void *addr) { VhostIOVATree *tree =3D v->iova_tree; @@ -587,14 +603,6 @@ static NetClientState *net_vhost_vdpa_init(NetClientSt= ate *peer, return nc; } =20 -static int vhost_vdpa_get_iova_range(int fd, - struct vhost_vdpa_iova_range *iova_ra= nge) -{ - int ret =3D ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range); - - return ret < 0 ? -errno : 0; -} - static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **err= p) { int ret =3D ioctl(fd, VHOST_GET_FEATURES, features); @@ -690,14 +698,11 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, } =20 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); + iova_tree =3D vhost_vdpa_svq_allocate_iova_tree(vdpa_device_fd); } =20 ncs =3D g_malloc0(sizeof(*ncs) * queue_pairs); --=20 2.31.1 From nobody Thu Apr 25 19:35:43 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=1669305324; cv=none; d=zohomail.com; s=zohoarc; b=NvQ+maDeZynp2Ui3pbcpJYx59JUA0/Q5VoOO8yg6+7HM+IdneloU09E49szlbwKffGma42pHsM+/JjKSApn7tNCiK9/LbhtH+B2PhbWg606WbqkHLyHE1Bcsz3kpG1H7KSYSwX7sbXo2iYUsdoaUgTcu5P+m/jYJUwSLYqGWhJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669305324; 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=xfr4y8K+ipo09Wo9rlQQiQ9rlXW0vTMWU5HjYZ33inE=; b=Zp4RUEkDPlQjvaOylVwtcQVPGdfBNFBHa+XSRGan8wQ+QmjsfW2puTtKomfSCbJ5WGodqPmGxo3ga8ofQnwowme712GVEQI3u7loFbGUEU2TuBXLUlCkPa+D72qfOIZIBYWXCmq7JstUs/LK5cJNry/M2y2TduWW9IRNgCcEWiM= 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 166930532411426.615668722703163; Thu, 24 Nov 2022 07:55:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyEWv-0002dq-1A; Thu, 24 Nov 2022 10:52:49 -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 1oyEWl-0002bp-Ha for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:40 -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 1oyEWj-0004Gk-Un for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:39 -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-426-WmSAaO1lMqm6oUEvoR0aAg-1; Thu, 24 Nov 2022 10:52:30 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E0F4A381A727; Thu, 24 Nov 2022 15:52:29 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE615111E3F8; Thu, 24 Nov 2022 15:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669305156; 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=xfr4y8K+ipo09Wo9rlQQiQ9rlXW0vTMWU5HjYZ33inE=; b=WyBJQS6ypNhUaficbM9X/ECGBl0GsXCnFeDWrnRzh43I2GrGaLIl4CqiMbGUgmLAwZVH3W vwgufqo4jxD9EMYL3Hy7utmQkOS/WI35MD9hOu4It+1jv2FXFwZWvsMmBPMKM7nvhHWof/ D0BkhOPSlJ4rivchjsUhKuMlR/K50fY= X-MC-Unique: WmSAaO1lMqm6oUEvoR0aAg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Cornelia Huck , Eli Cohen , Jason Wang , Cindy Lu , Parav Pandit , Laurent Vivier , "Michael S. Tsirkin" , Si-Wei Liu , Zhu Lingshan , Paolo Bonzini , Stefan Hajnoczi , Gautam Dawar , Liuxiangdong , "Gonglei (Arei)" , Harpreet Singh Anand , Stefano Garzarella Subject: [PATCH for 8.0 v8 07/12] vdpa: move SVQ vring features check to net/ Date: Thu, 24 Nov 2022 16:51:53 +0100 Message-Id: <20221124155158.2109884-8-eperezma@redhat.com> In-Reply-To: <20221124155158.2109884-1-eperezma@redhat.com> References: <20221124155158.2109884-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.3 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: 1669305326098100003 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 | 33 ++------------------------------- net/vhost-vdpa.c | 3 ++- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 691bcc811a..6f2dabd0bf 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -402,29 +402,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) { @@ -435,7 +415,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) @@ -460,11 +439,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); vhost_vdpa_get_iova_range(v); =20 if (!vhost_vdpa_first_dev(dev)) { @@ -475,10 +450,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 9ee3bc4cd3..b47acf5a2d 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 Thu Apr 25 19:35:43 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=1669305276; cv=none; d=zohomail.com; s=zohoarc; b=ZptCmNe94vlinVdFZw+HG+kq8/02P09BFqA1FaYKg2eVdF5hdm4AUNsXRHKcq31Uj9BjoemMVzKaMpji8wsLR7JaqztZ060wJsw4FocLfwQonwIAcJ+nkvRVEHjCCRgelU2vaZvSGn5RDc60NUTKAKKM9VlutVz09zcFShTPm2k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669305276; 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=vUhr69+TgZmndftT7btVTmABb13n2gplbiYWMXh4Xjw=; b=gHi5hS6Bd1pdV8osFID88QYCApNWb5mXz2BtFhskoGg45wG8JamAuDEzWN6zp5XOek/uEi4EExY973NPf3G31l9bHVxwWakJscrpNdra/HyYQIVqUGYIUAOOUK4MOZ1bNGRkN4XDMStmNl7zH0JMh1MoZ+uB82oEQIRy0MCcbdA= 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 16693052767681018.7167906627382; Thu, 24 Nov 2022 07:54:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyEWs-0002cu-FE; Thu, 24 Nov 2022 10:52: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 1oyEWk-0002bW-5n for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:38 -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 1oyEWh-0004Gf-Ug for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:36 -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-43-8pIWLS0SPW2xxUKQUZ5Lrg-1; Thu, 24 Nov 2022 10:52:33 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4654C1C05EC0; Thu, 24 Nov 2022 15:52:33 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3450B111F3B6; Thu, 24 Nov 2022 15:52:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669305155; 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=vUhr69+TgZmndftT7btVTmABb13n2gplbiYWMXh4Xjw=; b=CvC1JSRDd2lfV8IbEXOy0JCWjz0G3QN+D3lWz0pwCkaNluvsa7CM2BySYIWQ16aifZKMYp ZBtm5jS/v1jLCTm6/3vbD3Xw5KMSz5VdKmuhLogY3V/Aw3syqqgZzLgfn4C4729nsS148G TOFz9n5LjtOvoVg94bXv8Gi8/difzsk= X-MC-Unique: 8pIWLS0SPW2xxUKQUZ5Lrg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Cornelia Huck , Eli Cohen , Jason Wang , Cindy Lu , Parav Pandit , Laurent Vivier , "Michael S. Tsirkin" , Si-Wei Liu , Zhu Lingshan , Paolo Bonzini , Stefan Hajnoczi , Gautam Dawar , Liuxiangdong , "Gonglei (Arei)" , Harpreet Singh Anand , Stefano Garzarella Subject: [PATCH for 8.0 v8 08/12] vdpa: allocate SVQ array unconditionally Date: Thu, 24 Nov 2022 16:51:54 +0100 Message-Id: <20221124155158.2109884-9-eperezma@redhat.com> In-Reply-To: <20221124155158.2109884-1-eperezma@redhat.com> References: <20221124155158.2109884-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.3 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: 1669305277910100001 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 6f2dabd0bf..ed360b7fdf 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -546,10 +546,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 Thu Apr 25 19:35:43 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=1669305210; cv=none; d=zohomail.com; s=zohoarc; b=KvJEjwRblQyL+MbpkC02O5+ptqQEh3F0xyQSJF3nB45NV811s3FJebMlipWam1C7GfpS29mjLgthfucleozF/qNUJHHsqjaYk5JdAyjouBgPeoBW583ROJwyydyZSIRs2AfZNciNXyJcmfAMF++qhLOifUZAw5LV7xXfA0kL51s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669305210; 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=xwqiEr5SlgEI/MINJPyBvBK8+yHdIggDrwdzZzipAcU=; b=fOSsFqviGDjxG6Q8VaaI4gPKVkMSg/xilIWNuN8/UtERwc9MYmAPYTVN88zip6x+IycokDRXtVCJjNel1p8Rjilsp8Wax8iyCHMS8DQw6zVRncZoeBpPwDZE0uL9ma7TU65B7at7gjvmi54ucLlg67YfCKqhYCml3ZUWw7pSYjU= 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 1669305210912112.02452523734883; Thu, 24 Nov 2022 07:53:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyEWw-0002eL-OP; Thu, 24 Nov 2022 10:52:50 -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 1oyEWr-0002d8-3m for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:46 -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 1oyEWo-0004HW-7h for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:44 -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-613-3YYXfx8XOPaoxwBM90dYBQ-1; Thu, 24 Nov 2022 10:52:37 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9E98F380671D; Thu, 24 Nov 2022 15:52:36 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D735111E403; Thu, 24 Nov 2022 15:52:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669305161; 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=xwqiEr5SlgEI/MINJPyBvBK8+yHdIggDrwdzZzipAcU=; b=jHWmzr46wNZ7/4GwKTXMjBl4AO4yYsqQocrcrm2wPG6d0hJK4dyP3DZk77/JLoYCgEm131 weoifMeZpGYsFocsgAn85itpJOLIY8mofxZcIONmpuNRIQ03qS0umwj/6dwur1Aq3COGDc rYx/b76YjiMRmE7YFKnzYQDnEd/+cyg= X-MC-Unique: 3YYXfx8XOPaoxwBM90dYBQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Cornelia Huck , Eli Cohen , Jason Wang , Cindy Lu , Parav Pandit , Laurent Vivier , "Michael S. Tsirkin" , Si-Wei Liu , Zhu Lingshan , Paolo Bonzini , Stefan Hajnoczi , Gautam Dawar , Liuxiangdong , "Gonglei (Arei)" , Harpreet Singh Anand , Stefano Garzarella Subject: [PATCH for 8.0 v8 09/12] vdpa: add asid parameter to vhost_vdpa_dma_map/unmap Date: Thu, 24 Nov 2022 16:51:55 +0100 Message-Id: <20221124155158.2109884-10-eperezma@redhat.com> In-Reply-To: <20221124155158.2109884-1-eperezma@redhat.com> References: <20221124155158.2109884-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.3 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: 1669305211942100005 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 ed360b7fdf..1100cde29e 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!"); } @@ -883,7 +896,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; @@ -923,7 +936,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 b47acf5a2d..b40b1ddf0d 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -275,7 +275,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); } @@ -315,8 +315,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 820dadc26c..0ad9390307 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 Thu Apr 25 19:35:43 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=1669305318; cv=none; d=zohomail.com; s=zohoarc; b=coe5+uX9DG3Fchfhm4aaE1kQOVtFgmS81wXkLwnopvq//wlo+nCNC2NmGaEU7xE/0eZ2ZTi73UwzhGBWxLfnMdeUGNmNFHaoDrL0hvOjCDDrvU3WcLB2Tu4kBx5xGq2CV7F1cxIKC0GH+MrmPlfzAMc6SZugNY2wedK9lVhwvxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669305318; 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=ySh46XbYk9VIs4uLkfJkTIjcH+z9Qv25PLQCXJV9doc=; b=oGbR2c5dl0BD7AGid62i5Vy597CjgWc8be85L241cob6HztgXmmSsLKu1lFOlS8Gm6wg8DSXIONL5KyGAYlmNETowy6aVD3bU+oftjm8pi6wCx9+A3pDrjG6w2YBLlXQlbRu2xqgOLXNf4dcbfAcwrQ6VTOicTGpgC3B7RyAwMM= 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 1669305318410795.3812845639709; Thu, 24 Nov 2022 07:55:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyEWu-0002dp-U0; Thu, 24 Nov 2022 10:52: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 1oyEWr-0002d9-VU for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:46 -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 1oyEWq-0004Ha-Ki for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:45 -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-213-LBxWdrbqMHiyDE2LEqTnng-1; Thu, 24 Nov 2022 10:52:40 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0CDC3800B23; Thu, 24 Nov 2022 15:52:40 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6E5B111E3F8; Thu, 24 Nov 2022 15:52:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669305164; 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=ySh46XbYk9VIs4uLkfJkTIjcH+z9Qv25PLQCXJV9doc=; b=IgasK/G8UqI6UcgM43a857oCMtwr68qMi0+kXOagdcKw83CGCZ7GU3FipzXyV/cYsvFJF0 910rFQ6edebaWYbg8zkyIcVXKQbPm7vkJ8n8vo8nHA7YUiY1QE23QEBWNxUsUkB8GeJkqO 1PY1FDcq0eZsir9Cl36ekhA6tQ2fCjw= X-MC-Unique: LBxWdrbqMHiyDE2LEqTnng-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Cornelia Huck , Eli Cohen , Jason Wang , Cindy Lu , Parav Pandit , Laurent Vivier , "Michael S. Tsirkin" , Si-Wei Liu , Zhu Lingshan , Paolo Bonzini , Stefan Hajnoczi , Gautam Dawar , Liuxiangdong , "Gonglei (Arei)" , Harpreet Singh Anand , Stefano Garzarella Subject: [PATCH for 8.0 v8 10/12] vdpa: store x-svq parameter in VhostVDPAState Date: Thu, 24 Nov 2022 16:51:56 +0100 Message-Id: <20221124155158.2109884-11-eperezma@redhat.com> In-Reply-To: <20221124155158.2109884-1-eperezma@redhat.com> References: <20221124155158.2109884-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.3 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: 1669305320069100001 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 b40b1ddf0d..3ff149dfd9 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 @@ -583,6 +585,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_tree =3D iova_tree; if (!is_datapath) { --=20 2.31.1 From nobody Thu Apr 25 19:35:43 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=1669305399; cv=none; d=zohomail.com; s=zohoarc; b=NYRZIHziQyb8ZImV1Htp8IUwREtZ1S1nnSAbaIJ4SIHrZn+X0YXgDjj0b37jiaY7wM8GfWIO2q/HGkmOPCIW8g+x3aHf3OkpSWW/q6Gdz15DbShjpyYEvUg5nS5AsYwyuUQNewD4i26s4wk4svdQV0id+FuXiOcZwdAYg18X10I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669305399; 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=0QDAmttFt0/uzyyfXC+uWtyx2ufyevmD2rR2wGnwGck=; b=LGukUO1MUEyj9HppIur4Tq/XHpAkcTnulBJPQYmgspQ/Oj3EJ9/jhqckHTQr9BFpbEh0FQsPxCPtuBRkDV+DJ2H70ahBJK0t8mOpjBkhmnDSpDxoZ3jtyumOFS68QntUIitWJpWcYpqO9n78hITM0x91Z9ns+2yKIN4ojosk7f4= 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 1669305399813400.3139102446182; Thu, 24 Nov 2022 07:56:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyEWy-0002f8-0J; Thu, 24 Nov 2022 10:52:52 -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 1oyEWv-0002e5-Q3 for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:49 -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 1oyEWu-0004Hs-9V for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:49 -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-629-KOa_z0INP--O0gfHRnMKsA-1; Thu, 24 Nov 2022 10:52:44 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 69A8485A5A6; Thu, 24 Nov 2022 15:52:43 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54489111E3F8; Thu, 24 Nov 2022 15:52:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669305167; 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=0QDAmttFt0/uzyyfXC+uWtyx2ufyevmD2rR2wGnwGck=; b=EJUEiix1mIDh2wkiT2KfnZHtro4nCInHxObM6A3Qqhis9FWcwyLVP9gEZFrWXQwi38wwn0 FUAY3MDrT/b/JPH3+aWS0pXcXY9YBhtV0Iqg2oL7HbTeFmdFLH9yaNUyhxyz1COtQekDZA BDf9CBdgp/2vFX6j1s9VQbnBzBJos4Q= X-MC-Unique: KOa_z0INP--O0gfHRnMKsA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Cornelia Huck , Eli Cohen , Jason Wang , Cindy Lu , Parav Pandit , Laurent Vivier , "Michael S. Tsirkin" , Si-Wei Liu , Zhu Lingshan , Paolo Bonzini , Stefan Hajnoczi , Gautam Dawar , Liuxiangdong , "Gonglei (Arei)" , Harpreet Singh Anand , Stefano Garzarella Subject: [PATCH for 8.0 v8 11/12] vdpa: add shadow_data to vhost_vdpa Date: Thu, 24 Nov 2022 16:51:57 +0100 Message-Id: <20221124155158.2109884-12-eperezma@redhat.com> In-Reply-To: <20221124155158.2109884-1-eperezma@redhat.com> References: <20221124155158.2109884-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.3 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: 1669305400430100001 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 1100cde29e..8e54c5c0fc 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 3ff149dfd9..a1f1e29b7c 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -587,6 +587,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, s->vhost_vdpa.index =3D queue_pair_index; s->always_svq =3D svq; s->vhost_vdpa.shadow_vqs_enabled =3D svq; + 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 Thu Apr 25 19:35:43 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=1669305307; cv=none; d=zohomail.com; s=zohoarc; b=LTcKs0PtHgFvuLg/4P6LFkEDX3kIPTIu/NA6yiXWEVFkb7VJtCL/soL53Irdid6O6JSvnQOJk0Ocbn/sgmZdIN1XGbyNs6Q7KA4SJfi7ZH1R0b2k2TlQTbcS1GpOAoecbL6hcdHkNZCLeJi3fQBzUHi8qh1rK32xbW55anSdU6I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669305307; 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=2skwpC+eVA6yYC2x/mr1Nxhuj4mB+d6nCE7s2zzx13A=; b=VxmX46xUhLDTTw7/q7ztC+rLb5mkeS9r4Sm58/QEjT2M9K73mFmxL64ibdGmWJsotf8DYS1S2nBrqcrzVAfXhkk5qMBwPw/yO8MLCHTGa+p+zb/l3/tfbhMDzH4LZPlgBVEFtVHgihiSDI9fI9eqgsqxq+OgUBuXYIwFAkpeWUM= 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 1669305307221510.3558043645646; Thu, 24 Nov 2022 07:55:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyEX1-0002fj-If; Thu, 24 Nov 2022 10:52:55 -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 1oyEWz-0002fF-Sh for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:53 -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 1oyEWx-0004I4-62 for qemu-devel@nongnu.org; Thu, 24 Nov 2022 10:52:53 -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-532-pv3OueikMXSiQWcWzl7bxw-1; Thu, 24 Nov 2022 10:52:47 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C4C2A800186; Thu, 24 Nov 2022 15:52:46 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id B136F111E3F8; Thu, 24 Nov 2022 15:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669305170; 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=2skwpC+eVA6yYC2x/mr1Nxhuj4mB+d6nCE7s2zzx13A=; b=WMzvzGOEPlN4gmAg/DClRtq4Px86+8vJ9x4WSwupCravOaNeoscsQ0YiNxMuyU5rWpHbLb kOJCek+qdDDaj8hBXYkqivrgEoSZIu6W6KmMwlx3on4+seYkcUf1lhQ8KVidek3SC0QR+e 8RO32f/8myn2R/O9iSvoYjK0kNHi/lE= X-MC-Unique: pv3OueikMXSiQWcWzl7bxw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Cornelia Huck , Eli Cohen , Jason Wang , Cindy Lu , Parav Pandit , Laurent Vivier , "Michael S. Tsirkin" , Si-Wei Liu , Zhu Lingshan , Paolo Bonzini , Stefan Hajnoczi , Gautam Dawar , Liuxiangdong , "Gonglei (Arei)" , Harpreet Singh Anand , Stefano Garzarella Subject: [PATCH for 8.0 v8 12/12] vdpa: always start CVQ in SVQ mode if possible Date: Thu, 24 Nov 2022 16:51:58 +0100 Message-Id: <20221124155158.2109884-13-eperezma@redhat.com> In-Reply-To: <20221124155158.2109884-1-eperezma@redhat.com> References: <20221124155158.2109884-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.3 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: 1669305308040100001 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 --- 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 | 106 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 107 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 8e54c5c0fc..45bb72d359 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -652,7 +652,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 a1f1e29b7c..bce57fa724 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); @@ -259,6 +261,40 @@ static VhostIOVATree *vhost_vdpa_svq_allocate_iova_tre= e(int vdpa_device_fd) return vhost_iova_tree_new(iova_range.first, iova_range.last); } =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; @@ -333,11 +369,71 @@ 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; + } + + /* Backend features 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 (unlikely(group =3D=3D cvq_group)) { + warn_report( + "CVQ %"PRId64" group is the same as VQ %d one (%"PRId64")", + cvq_group, i, 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_vdpa_svq_allocate_iova_tree(v->device_fd); + 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; } @@ -366,6 +462,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