From nobody Sat May 11 20:06:50 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=1668611227; cv=none; d=zohomail.com; s=zohoarc; b=ZrH8HTSaQgC5+QGgEykArelpERZK9LySTObnOoGgw9dcGXru6VF6IqiBR5g4E7z/2NKYHfwgtx3TVaAzCLAH3F3Bllc5se7TQZKkT5wJaX3NbZJ/HjWjBk89EP02buK/Z/3oPY+R8hxm7SOkC40lYiZv0OZ9xEAo4nRLorvTM4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668611227; 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=3DZzVaTb8ZcE2rexgrMNXJqh3vRsjkFL61vNK5okDmI=; b=llwpjhX0OdHsKJrbZ+oHjKLs2lbrTJvQOezC4bCWfJCjYAXGCA/VKvooOTZWHKzJ3aN2ZrCKH7P4z3vy4cegYOuCo4FYvdHR0AA0p/1LFeG0i1STAevZiwonFemuhpqFTy9HyAZR1oLSFh6H+ljmpMr+ktI38cRab/gcSxl5bJs= 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 1668611227356680.4051295175177; Wed, 16 Nov 2022 07:07:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovJzh-00079N-Vd; Wed, 16 Nov 2022 10:06:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ovJzU-00075l-KA for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06: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 1ovJzS-0005xT-PT for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:16 -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-448-IsAJoLBDOEuBOdE2k6_H0Q-1; Wed, 16 Nov 2022 10:06:10 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF47A29AB411; Wed, 16 Nov 2022 15:06:09 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFD48140EBF3; Wed, 16 Nov 2022 15:06:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668611174; 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=3DZzVaTb8ZcE2rexgrMNXJqh3vRsjkFL61vNK5okDmI=; b=KShGif6cG03YGg7lzC6+1aV9uFXTCMA67FZQSsR35uKT9FFoGyN/tqNszOyvedQL1ZCabl iIXDY9xTk/jPJhDh98FK/voyevJn4p/fiLCAU93Wg6s/+SOOTV/KXLlH4m8wy088P8PT8e EVCBz6ztQxSbDZgnj5myYBA7vmpGSMw= X-MC-Unique: IsAJoLBDOEuBOdE2k6_H0Q-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Gautam Dawar , Eli Cohen , Stefano Garzarella , Harpreet Singh Anand , Paolo Bonzini , Stefan Hajnoczi , Cindy Lu , Liuxiangdong , "Gonglei (Arei)" , Jason Wang , Parav Pandit , Si-Wei Liu , Zhu Lingshan , Laurent Vivier , "Michael S. Tsirkin" , kvm@vger.kernel.org Subject: [PATCH for 8.0 v7 01/10] vdpa: Use v->shadow_vqs_enabled in vhost_vdpa_svqs_start & stop Date: Wed, 16 Nov 2022 16:05:47 +0100 Message-Id: <20221116150556.1294049-2-eperezma@redhat.com> In-Reply-To: <20221116150556.1294049-1-eperezma@redhat.com> References: <20221116150556.1294049-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.7 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: 1668611229220100003 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 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 Sat May 11 20:06:50 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=1668611205; cv=none; d=zohomail.com; s=zohoarc; b=LbLSZKjiydud//SzQEuSrqcuqHecQtfbcWfHmhKmIV12eqOfh4ONuB8GREqfHstz1H6PpMoKjqLVEUDoidkZP+mYEsUekvFLyKpFGvmZdrJPVcUn5l5bpJ+4rqmpBLoVTxnCgRnm0/+Q+tGM+ijlQbmk64+UdZc96u6hVl8cTHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668611205; 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=sIC9X3hY8kpTDzvY0hqjASgJT0kr6duy1l0lnuqOZcw=; b=Xr9hSj/6cujWcc69nXFLUBNuT+YIHidHBkXQ6mt9vkinpy92PzZ7+7WBjAUkOzC7cJ8ZUuRATY+LMwMldqxGMtTT+LsrPLyDmDueeigFGM2Gx9DIwz9g4qmeBSGIHLNsXKTMF1WgszcPPvoifymHx5QjUaP1nuJ4ZRgT73CRWEM= 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 1668611205697957.6092522147333; Wed, 16 Nov 2022 07:06:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovJzk-0007B8-1m; Wed, 16 Nov 2022 10:06:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ovJzZ-00076a-IL for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:28 -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 1ovJzX-0005yW-IH for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:21 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-324-9xGeWKCQPWSids9oTRwreQ-1; Wed, 16 Nov 2022 10:06:13 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 18E2C3C0F7EB; Wed, 16 Nov 2022 15:06:13 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 184AA140EBF3; Wed, 16 Nov 2022 15:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668611179; 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=sIC9X3hY8kpTDzvY0hqjASgJT0kr6duy1l0lnuqOZcw=; b=i9vdEUz7brUMNW+hejcRk77oHojd6jGl4p/pwYc8bnEOcA16lemAN1F29SK3q5e9b4cLmm zezK8Xxr+Dn9nmsfwQKyuVTI5tne3A7R7V5jynwCsY0fz0GtDbUfpm4G93iid+vU1bH6WR b3I44CauX9rVln6vGTmG/3hva4U0wRo= X-MC-Unique: 9xGeWKCQPWSids9oTRwreQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Gautam Dawar , Eli Cohen , Stefano Garzarella , Harpreet Singh Anand , Paolo Bonzini , Stefan Hajnoczi , Cindy Lu , Liuxiangdong , "Gonglei (Arei)" , Jason Wang , Parav Pandit , Si-Wei Liu , Zhu Lingshan , Laurent Vivier , "Michael S. Tsirkin" , kvm@vger.kernel.org Subject: [PATCH for 8.0 v7 02/10] vhost: set SVQ device call handler at SVQ start Date: Wed, 16 Nov 2022 16:05:48 +0100 Message-Id: <20221116150556.1294049-3-eperezma@redhat.com> In-Reply-To: <20221116150556.1294049-1-eperezma@redhat.com> References: <20221116150556.1294049-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.7 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: 1668611207232100003 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. 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 Sat May 11 20:06:50 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=1668611330; cv=none; d=zohomail.com; s=zohoarc; b=GRyubjmH1h9+jUOl3vhBMQXAEKmsLKCu+QCiCxsxeJMYqxc94VY4Tl933qBlWBVIRvPneQwstlyE7jJ1gDxTKYvZmSNhGQv+aDYODiV3cpG6gHzRREw5EjRpzwQtJ0UfuRlfkyxyL/sBLcjNpL5fV23/2g5VZbc3PsOMjtmFxLE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668611330; 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=TuVSmmtk6tStl4tlJ6zRf9QVt9d6pPui6elY2DjbyVY=; b=PsI66wJiRbPdG5uCW1ED4Aw8YcE3Gsjib++NqAaxS3W8Kwf0YrWUOlvXztqRy8V4Ga+7QjRPAaJ21H/M9AzDZe2A/nTykc8fmsjQRyaL22wbkjq9vsbzBMQwcxZZpp1eX/7hDwNNEPMFX49hpGpODCPFiaPgy4cwYihgYGC7yk8= 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 1668611330783991.8941676796345; Wed, 16 Nov 2022 07:08:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovJzk-0007BB-1t; Wed, 16 Nov 2022 10:06:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ovJzc-00076p-4q for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:28 -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 1ovJza-0005yr-DV for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:23 -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-651-9Lin8lTmPBqNakiiklHMAw-1; Wed, 16 Nov 2022 10:06:17 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0EB21185A7A8; Wed, 16 Nov 2022 15:06:17 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60E80140EBF3; Wed, 16 Nov 2022 15:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668611181; 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=TuVSmmtk6tStl4tlJ6zRf9QVt9d6pPui6elY2DjbyVY=; b=MdzlqCccba/J/en9jAsAloOb2DIriAWA9ZS2voCrLNTDsBhZWfiR0bmjFfAQDZ/7eQhTGE PXDK72IAA+b1+RYgiAWnM5aBUQF4lbvUA6pOOgg/ulotDntQNHdVCb5AlLVV/8jLY1ZEdc gvRAq1fceL591trjdj5V0tU+ieXOq1c= X-MC-Unique: 9Lin8lTmPBqNakiiklHMAw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Gautam Dawar , Eli Cohen , Stefano Garzarella , Harpreet Singh Anand , Paolo Bonzini , Stefan Hajnoczi , Cindy Lu , Liuxiangdong , "Gonglei (Arei)" , Jason Wang , Parav Pandit , Si-Wei Liu , Zhu Lingshan , Laurent Vivier , "Michael S. Tsirkin" , kvm@vger.kernel.org Subject: [PATCH for 8.0 v7 03/10] vhost: Allocate SVQ device file descriptors at device start Date: Wed, 16 Nov 2022 16:05:49 +0100 Message-Id: <20221116150556.1294049-4-eperezma@redhat.com> In-Reply-To: <20221116150556.1294049-1-eperezma@redhat.com> References: <20221116150556.1294049-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.7 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: 1668611332405100003 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. 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 Sat May 11 20:06:50 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=1668611251; cv=none; d=zohomail.com; s=zohoarc; b=d5J4NGKHE4wf7JprtFXiq+7nh/goueb9PlO6U1c7M6S/jwqjaknB08FIdBJXVGkwOJm9vmu2aTkw2OdNTgJXIR3+5zq7+VWnQUj2NE0vD8HRzE774bQ+SxThXHT3VNEWBnMPuCJlMGn0t2cfF5+KSlyGb7+QiOXDoM1MIwEqQDU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668611251; 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=ZKhQraieiyCC6iuUOOfNki3arvZTQD/5FkxsiUk8g4s=; b=eN8bN3PTzPigvrERhwV1iaa6r8ywp8C3K3DC81rpQiCjTGoLIeE3L7OQiVZbIf1iO7Imip/Q+Gb5KmLgEzoltv9mWjjj3HNWi34iDq9dXuE0Oi6xRBlqN8iUGoHu9hWiEdKCZCx2HG1vBHFGlmMoKMADKyhKa8PyS6omWyp+8kg= 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 166861125152032.49055227795884; Wed, 16 Nov 2022 07:07:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovJzk-0007Gk-So; Wed, 16 Nov 2022 10:06:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ovJzg-00076z-5l for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:28 -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 1ovJze-0005zY-Js for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:27 -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-622-DuQdWBqaOtmwI4B6HlfZsw-1; Wed, 16 Nov 2022 10:06:21 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 58B62858282; Wed, 16 Nov 2022 15:06:20 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CABE140EBF3; Wed, 16 Nov 2022 15:06:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668611186; 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=ZKhQraieiyCC6iuUOOfNki3arvZTQD/5FkxsiUk8g4s=; b=RXmA592Z7YWCs2dNNqU8ZAUjLi3SWQRbFFbqN168p/KTZ8K85Zmaw6Sld1dRDNhW1OrTP3 bDtiOxnRcxzkYkUXhaiD0989/BzBVY5lsWMDBpp5eIz0CMfU6853mj2d7TyyNy6HQvBU7B 0LlwTG1lFrdaqW9jFEXIUDMPwmTwfVs= X-MC-Unique: DuQdWBqaOtmwI4B6HlfZsw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Gautam Dawar , Eli Cohen , Stefano Garzarella , Harpreet Singh Anand , Paolo Bonzini , Stefan Hajnoczi , Cindy Lu , Liuxiangdong , "Gonglei (Arei)" , Jason Wang , Parav Pandit , Si-Wei Liu , Zhu Lingshan , Laurent Vivier , "Michael S. Tsirkin" , kvm@vger.kernel.org Subject: [PATCH for 8.0 v7 04/10] vdpa: add vhost_vdpa_net_valid_svq_features Date: Wed, 16 Nov 2022 16:05:50 +0100 Message-Id: <20221116150556.1294049-5-eperezma@redhat.com> In-Reply-To: <20221116150556.1294049-1-eperezma@redhat.com> References: <20221116150556.1294049-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.7 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: 1668611253463100005 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 6811089231..e98d5f5eac 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -106,6 +106,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; @@ -675,15 +691,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 Sat May 11 20:06:50 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=1668611350; cv=none; d=zohomail.com; s=zohoarc; b=ii4OjGQtRL27Rcvg0vV7vIfbCMZSXemz3W3WFkAaQtLYccS11nQNdgJzNkD8/NUQQE6ZjLt54q4HWLytwcQmFFgGgnP//VM3Hr1WIJNnMNxfIp3SlmRVZc4wOuNUWCdKAM4Vuak9k48mZTN8+pCkCSGhSrwW2Ai1iE80ud0lfAA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668611350; 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=0+au/UM9VIHTmPOqBDQ2vQGnj810Su87nJuzkIxq8kA=; b=LFrVW/JBc1w1rhXF+jO10nO30oLSNFFAFYLLE6id+nGWauOa8VJl/Dpz7/yIa3HSrZkDjnyjUm448Km+XocFbq0piv8DkcPeyDn6HAocRetJzNevE8VpL91tiJbX8csbkoAJO+oqEXkBIoiDcybInDsCCzmQHuA+LnJUNHgwCZw= 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 1668611350549969.8913765044913; Wed, 16 Nov 2022 07:09:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovK0B-0007lN-AF; Wed, 16 Nov 2022 10:06:59 -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 1ovJzr-0007MV-T1 for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:39 -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 1ovJzo-00065V-Pl for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:39 -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-389-9Gm-IvmuNJy1Q4ZfMHUb3w-1; Wed, 16 Nov 2022 10:06:24 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A5827803D49; Wed, 16 Nov 2022 15:06:23 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E5C8140EBF3; Wed, 16 Nov 2022 15:06:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668611194; 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=0+au/UM9VIHTmPOqBDQ2vQGnj810Su87nJuzkIxq8kA=; b=HDxlgE+Q1c3t6ps+7270esQNMiPmS8OaldKlNL8s0pUTvogXfP/QH0f4QU739z5+HwpynH cCZyMFQqgTbF1QmmFJGLbixp+fgOko/HGO3mvrpjn6s6tRuOI/M5vmxO/Bu+VAzIq1ds35 Gm5Brdmo3PQPTUrVI/eliFzXp6+DjYk= X-MC-Unique: 9Gm-IvmuNJy1Q4ZfMHUb3w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Gautam Dawar , Eli Cohen , Stefano Garzarella , Harpreet Singh Anand , Paolo Bonzini , Stefan Hajnoczi , Cindy Lu , Liuxiangdong , "Gonglei (Arei)" , Jason Wang , Parav Pandit , Si-Wei Liu , Zhu Lingshan , Laurent Vivier , "Michael S. Tsirkin" , kvm@vger.kernel.org Subject: [PATCH for 8.0 v7 05/10] vdpa: move SVQ vring features check to net/ Date: Wed, 16 Nov 2022 16:05:51 +0100 Message-Id: <20221116150556.1294049-6-eperezma@redhat.com> In-Reply-To: <20221116150556.1294049-1-eperezma@redhat.com> References: <20221116150556.1294049-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.7 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: 1668611352404100006 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 3df2775760..146f0dcb40 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) { @@ -436,7 +416,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) @@ -461,11 +440,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)) { @@ -476,10 +451,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 e98d5f5eac..dd9cea42d0 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -117,9 +117,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 Sat May 11 20:06:50 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=1668611220; cv=none; d=zohomail.com; s=zohoarc; b=Z5VknzAPG8klXLgEQ7IDJ5hNI3UCwOBe8G2nAYLo9XC4DRIW9RXF7Mu3qzuCWLO7ct2tsuK1UeKA+vtxLxurvFUCS/wcnVc8LYIUkoYbNoA3dr3ttJd3URamvVwDHwmU1sed/NOmZxsxZ83PQoLJP0LDEtz/m5HYCeCvqHprK2A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668611220; 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=UBhJmZa5i1MuF5puQfZjzc9b3Lj3N6FQWq5txtTVLw4=; b=n6KN9hLsoIAJdcCYenQSlRRagCy9Wa/9HuSiErOUDlPje3zJI+O3zU/fGK/s7q82oXbNk0dM8Gr30oJc4Vkb9+AYSLiUnWwHebqi6Y6W01dTdBIzbvGAKKBW/l3o937I7jmUJAfQv2wgiDQObxV3jW8B1O+63g6tc24cT3/BX6A= 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 1668611220843816.3673422522431; Wed, 16 Nov 2022 07:07:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovJzv-0007Sm-Kw; Wed, 16 Nov 2022 10:06: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 1ovJzq-0007LD-3u for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:39 -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 1ovJzn-00064i-Bc for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06: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-193-znWEZFXFOKGB586PhMgNqQ-1; Wed, 16 Nov 2022 10:06:28 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 02F613C0F7E6; Wed, 16 Nov 2022 15:06:27 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED1111401C26; Wed, 16 Nov 2022 15:06:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668611193; 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=UBhJmZa5i1MuF5puQfZjzc9b3Lj3N6FQWq5txtTVLw4=; b=R1Q3LvZ/xyMOnjH5rzcVDatYOGcovHKa+blvdpQcuJH5Jh5N0UoKDcD+aDXbmN+82ErwZE cFyeA2J8US3IjyZy61LkKNoSmqr08Mdkl8Dy0jawLXz6CiRP10a1kQRtNVbZiUvMG/0btd Z/fxG9j2fiyVKVR+EdTcCd3tpmhV7gI= X-MC-Unique: znWEZFXFOKGB586PhMgNqQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Gautam Dawar , Eli Cohen , Stefano Garzarella , Harpreet Singh Anand , Paolo Bonzini , Stefan Hajnoczi , Cindy Lu , Liuxiangdong , "Gonglei (Arei)" , Jason Wang , Parav Pandit , Si-Wei Liu , Zhu Lingshan , Laurent Vivier , "Michael S. Tsirkin" , kvm@vger.kernel.org Subject: [PATCH for 8.0 v7 06/10] vdpa: Allocate SVQ unconditionally Date: Wed, 16 Nov 2022 16:05:52 +0100 Message-Id: <20221116150556.1294049-7-eperezma@redhat.com> In-Reply-To: <20221116150556.1294049-1-eperezma@redhat.com> References: <20221116150556.1294049-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.7 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: 1668611221393100001 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 146f0dcb40..23efb8f49d 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -547,10 +547,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 Sat May 11 20:06:50 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=1668611341; cv=none; d=zohomail.com; s=zohoarc; b=SPZkgxrVZ8GH4s35J9oXQk0ANTnMmXhwufaEZkcARMqIdSErVHRuoTWJ/Y43z9PNC+tdiM5WVIjdj85PGz1G4OLqGNYGlrizbytQgONH+nM0GdlrTr/Xl7Ja6ProclYMV1fFWqGsnx6Aej59aHZ7cbFxbqGu4n/A+I+e/4uoP3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668611341; 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=SV1pSXz8HO2Vze1ti2+PRql1wRH/uHwDewqdJDyPzso=; b=Nlu14Ctz3n9IEpdIlu2EzixGBvqduZr9wL8xEyFiZ6Pg2DmIdA+GCrmyYh6hxEEZKtAZiKyWOmb5/p0RfJJCf4qnOH9rIH9dMRyfailj7meboK4V9IzV4Ilv3QF8yT9FZ6uKXp2OfhETq3vaCexFKLh8vsTlNidT7n+jFazrmpA= 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 1668611341242267.4051868021004; Wed, 16 Nov 2022 07:09:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovK05-0007bx-Vh; Wed, 16 Nov 2022 10:06: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 1ovJzr-0007Lo-P4 for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:39 -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 1ovJzo-00065m-HP for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06: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-198-JZo5modeMse3TgkJWjc8ZQ-1; Wed, 16 Nov 2022 10:06:31 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 55B083C0F7E7; Wed, 16 Nov 2022 15:06:30 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C1A2140EBF3; Wed, 16 Nov 2022 15:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668611195; 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=SV1pSXz8HO2Vze1ti2+PRql1wRH/uHwDewqdJDyPzso=; b=G0xOXEv4zffdWo8cOfKjjbWfK8j3Ax+93NFt+SwZ80z/tP29r1n3sKnCZpQZFy8G4d35f2 o8iUexXv1NNJ2MDcuBA0+Ngta+8rhoDGFS5kVGuiGGq16FB86oEV5cHp1AtRvaiLqjcwBU bExAXmSWIk7Ad0Z3oWVyVnrHiR4xSzs= X-MC-Unique: JZo5modeMse3TgkJWjc8ZQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Gautam Dawar , Eli Cohen , Stefano Garzarella , Harpreet Singh Anand , Paolo Bonzini , Stefan Hajnoczi , Cindy Lu , Liuxiangdong , "Gonglei (Arei)" , Jason Wang , Parav Pandit , Si-Wei Liu , Zhu Lingshan , Laurent Vivier , "Michael S. Tsirkin" , kvm@vger.kernel.org Subject: [PATCH for 8.0 v7 07/10] vdpa: Add asid parameter to vhost_vdpa_dma_map/unmap Date: Wed, 16 Nov 2022 16:05:53 +0100 Message-Id: <20221116150556.1294049-8-eperezma@redhat.com> In-Reply-To: <20221116150556.1294049-1-eperezma@redhat.com> References: <20221116150556.1294049-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.7 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: 1668611342330100003 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 23efb8f49d..1e4e1cb523 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!"); } @@ -884,7 +897,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; @@ -924,7 +937,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 dd9cea42d0..89b01fcaec 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -258,7 +258,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); } @@ -298,8 +298,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 Sat May 11 20:06:50 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=1668611350; cv=none; d=zohomail.com; s=zohoarc; b=fWk77/qnGvUEFZGP8RajrQKcKACZrZq7poaKE+z+kTVbVclwCCVHCdA7bjq+ZAGqKTQkgp5atMroJseuvbtxud/o5fYNdcD64przfCzfu/KEh56BBwZCzwZUnQclRHVfnt6fZcd4X/rdN29+eJKHQj/oPuFyOtImxop9/v35Tls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668611350; 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=KkEFc+fbOcKId5NgCA9Uao5tsVxIoOCfeJE3AaAaezk=; b=f3s5r3+tHbkFh/Nn8/QBBSlaC29r6zlDdtii29YFRUP+j1AT0H4tpoXZRQnN2+EhDnO3iX8Y81PyHXjsoLEJQuP1D95aOhZDvpoWU6lp1L5o8ABTW/W4DNS6poIT2dPfOpHenrODSSj92crm2f8/Qf15X8dp5omGq+AXen73u9A= 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 1668611350215689.0502877712098; Wed, 16 Nov 2022 07:09:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovK08-0007co-Mh; Wed, 16 Nov 2022 10:06:56 -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 1ovJzu-0007PM-0Z for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:42 -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 1ovJzs-00066r-GV for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:41 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-563-MIIakxijPG-eKYNRgCI4ug-1; Wed, 16 Nov 2022 10:06:34 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B3732185A78B; Wed, 16 Nov 2022 15:06:33 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D870140EBF3; Wed, 16 Nov 2022 15:06:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668611199; 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=KkEFc+fbOcKId5NgCA9Uao5tsVxIoOCfeJE3AaAaezk=; b=bCrsL/XFlDkcVNGFiHzO+pv51mPYiWYgUb7Svop/Z7lhu0LG/8DxMV6YlPJyw95g6tDu/x IaHFKDiaeJ25mhQRfuTWZkiCiLuhH22TdqBGr3DW686W1AGwQafyUW/Di+k1t6LR9BhvE2 udhXi0CxVOiEGT3+sVna4iQ1BBxLr7w= X-MC-Unique: MIIakxijPG-eKYNRgCI4ug-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Gautam Dawar , Eli Cohen , Stefano Garzarella , Harpreet Singh Anand , Paolo Bonzini , Stefan Hajnoczi , Cindy Lu , Liuxiangdong , "Gonglei (Arei)" , Jason Wang , Parav Pandit , Si-Wei Liu , Zhu Lingshan , Laurent Vivier , "Michael S. Tsirkin" , kvm@vger.kernel.org Subject: [PATCH for 8.0 v7 08/10] vdpa: Store x-svq parameter in VhostVDPAState Date: Wed, 16 Nov 2022 16:05:54 +0100 Message-Id: <20221116150556.1294049-9-eperezma@redhat.com> In-Reply-To: <20221116150556.1294049-1-eperezma@redhat.com> References: <20221116150556.1294049-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.7 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: 1668611352378100005 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 at initialization time. 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 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 89b01fcaec..5185ac7042 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 @@ -566,6 +568,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 Sat May 11 20:06:50 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=1668611258; cv=none; d=zohomail.com; s=zohoarc; b=XsGULrTFtnct+/FWlpyItKDe5777JcDYKkz6X4DdjW+j649PWJa5p+J5tHAbLBLiqkFzMFMRkG7zapHt+IkFpTWZGQ/qOHWhmgE8OZSCmJIvqmP+sszCyQHEmqQzcYqwVnAjkutThTL29lyvG8C0S97h4ZgYqUbYEHrKWKbQo8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668611258; 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=FdqwhFCGFX4yvYXKI0vJfEUIP0lNQsnSRb8Ow14L8T4=; b=gI5kni6wsT271Y1WcgTyA4nr1ega5mKJeBZ6NGB7/2lAg0YcNDzVOVL/C5KK+0flL9pN/w7s6+gRzR9sytyEbPVPTcynuU47dazLt2SXNZKGxsYxY5SvNnQT17DDm/gg3dQ03Tc5evowpe+hTf41BaScA5XHTl6o1rew9WxihhE= 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 1668611258664538.7182401066024; Wed, 16 Nov 2022 07:07:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovK09-0007ev-HD; Wed, 16 Nov 2022 10:06:57 -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 1ovK04-0007by-5u for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:52 -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 1ovJzu-000676-2v for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:51 -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-631-oNcDVPfBOy6VWB09AIFNdA-1; Wed, 16 Nov 2022 10:06:38 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4E582803520; Wed, 16 Nov 2022 15:06:37 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C961140EBF3; Wed, 16 Nov 2022 15:06:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668611201; 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=FdqwhFCGFX4yvYXKI0vJfEUIP0lNQsnSRb8Ow14L8T4=; b=Rw79uZ9EW/jJep+LDaWQ/QlGSBmuYnLfbYoxLt4GJXbgsqDuRtacICEzG7+bJb8LXq1vxc u0IEkecqlIW3I3IsjQI2cCkCxHKrHUaoK855EOyH/lp7Lchu5WIy6fBLWDnE2WfiPLlw/v t/nQEGPW59lEcEyJyzaLJTblO1ZwQw8= X-MC-Unique: oNcDVPfBOy6VWB09AIFNdA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Gautam Dawar , Eli Cohen , Stefano Garzarella , Harpreet Singh Anand , Paolo Bonzini , Stefan Hajnoczi , Cindy Lu , Liuxiangdong , "Gonglei (Arei)" , Jason Wang , Parav Pandit , Si-Wei Liu , Zhu Lingshan , Laurent Vivier , "Michael S. Tsirkin" , kvm@vger.kernel.org Subject: [PATCH for 8.0 v7 09/10] vdpa: Add shadow_data to vhost_vdpa Date: Wed, 16 Nov 2022 16:05:55 +0100 Message-Id: <20221116150556.1294049-10-eperezma@redhat.com> In-Reply-To: <20221116150556.1294049-1-eperezma@redhat.com> References: <20221116150556.1294049-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.7 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: 1668611259498100003 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 1e4e1cb523..852baf8b2c 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 5185ac7042..a9c864741a 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -570,6 +570,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 Sat May 11 20:06:50 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=1668611368; cv=none; d=zohomail.com; s=zohoarc; b=A8SZyZeALq7Gvlkdq6THXnHMTeMY2ixSbqkMJceca73Rsgwn/okF0QbOcKYhboXBMjm8goLEr+kDnwT8ybihPAHh7DYskkevL0/IkSz0L/ZEU+m/Nynt+eMaqDtG+RuVdSMbKDXA6p7gPZsH2+bEFquLE+urMSYM/Trrv7NYpC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668611368; 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=nG9yzz83gQ5M2uNRxZwrKtK54pcLyuqOza9Uz1EHlTE=; b=aX6zYcBMd/XAMzbl6w/t0LeYKMC52gsU8XewvNAgh6WBXueA/iMuQo52udFKRa2F5SOUXhrS4nm61DXOV5/dZzBjiYwutCfMf0bOx66K/DDeOmVve2LU372SNee/zleJvRQI7EHhk0gd8InectZ9IyfFt2jPsq55x0oM78ger0k= 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 1668611368044457.3144715307553; Wed, 16 Nov 2022 07:09:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovK0A-0007gQ-Br; Wed, 16 Nov 2022 10:06:58 -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 1ovK05-0007cW-Iq for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06:55 -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 1ovK00-000693-Lf for qemu-devel@nongnu.org; Wed, 16 Nov 2022 10:06: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-620-L6xm2OMMOXyxA4KtA3Y_Lg-1; Wed, 16 Nov 2022 10:06:42 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 97E6E1019C88; Wed, 16 Nov 2022 15:06:41 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1728140EBF3; Wed, 16 Nov 2022 15:06:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668611207; 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=nG9yzz83gQ5M2uNRxZwrKtK54pcLyuqOza9Uz1EHlTE=; b=OdYzEpW3s/w/zn0zHvgr8PVc8JnFXx/yQoyrTzhOn2peAZGU7xU4xflQXiA2OX4kGeONn1 wrRx3ClpFWThFP5Kp4l/HUjmHDklEqI9rtnbBRL3lsURWKOrtuzty857jTSaQb7oCAGiAj 282EtVj5rt9nYn6KiCUyrZ4HOTSb8NM= X-MC-Unique: L6xm2OMMOXyxA4KtA3Y_Lg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Gautam Dawar , Eli Cohen , Stefano Garzarella , Harpreet Singh Anand , Paolo Bonzini , Stefan Hajnoczi , Cindy Lu , Liuxiangdong , "Gonglei (Arei)" , Jason Wang , Parav Pandit , Si-Wei Liu , Zhu Lingshan , Laurent Vivier , "Michael S. Tsirkin" , kvm@vger.kernel.org Subject: [PATCH for 8.0 v7 10/10] vdpa: Always start CVQ in SVQ mode if possible Date: Wed, 16 Nov 2022 16:05:56 +0100 Message-Id: <20221116150556.1294049-11-eperezma@redhat.com> In-Reply-To: <20221116150556.1294049-1-eperezma@redhat.com> References: <20221116150556.1294049-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.7 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: 1668611368496100003 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 --- 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 | 117 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 114 insertions(+), 6 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 852baf8b2c..a29a18a6a9 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -653,7 +653,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 a9c864741a..dc13a49311 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -101,6 +101,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); @@ -242,6 +244,40 @@ static NetClientInfo net_vhost_vdpa_info =3D { .check_peer_type =3D vhost_vdpa_check_peer_type, }; =20 +static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index) +{ + struct vhost_vring_state state =3D { + .index =3D vq_index, + }; + int r =3D ioctl(device_fd, VHOST_VDPA_GET_VRING_GROUP, &state); + + if (unlikely(r < 0)) { + error_report("Cannot get VQ %u group: %s", vq_index, + g_strerror(errno)); + return r; + } + + return state.num; +} + +static int vhost_vdpa_set_address_space_id(struct vhost_vdpa *v, + unsigned vq_group, + unsigned asid_num) +{ + struct vhost_vring_state asid =3D { + .index =3D vq_group, + .num =3D asid_num, + }; + int r; + + r =3D ioctl(v->device_fd, VHOST_VDPA_SET_GROUP_ASID, &asid); + if (unlikely(r < 0)) { + error_report("Can't set vq group %u asid %u, errno=3D%d (%s)", + asid.index, asid.num, errno, g_strerror(errno)); + } + return r; +} + static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa *v, void *addr) { VhostIOVATree *tree =3D v->iova_tree; @@ -316,11 +352,69 @@ 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) { + 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; + } else { + 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; } @@ -652,6 +746,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, g_autoptr(VhostIOVATree) iova_tree =3D NULL; NetClientState *nc; int queue_pairs, r, i =3D 0, has_cvq =3D 0; + bool svq_cvq; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); opts =3D &netdev->u.vhost_vdpa; @@ -693,12 +788,24 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, return queue_pairs; } =20 - if (opts->x_svq) { - struct vhost_vdpa_iova_range iova_range; + svq_cvq =3D opts->x_svq || has_cvq; + if (svq_cvq) { + Error *warn =3D NULL; =20 - if (!vhost_vdpa_net_valid_svq_features(features, errp)) { - goto err_svq; + svq_cvq =3D vhost_vdpa_net_valid_svq_features(features, + opts->x_svq ? errp : &w= arn); + if (!svq_cvq) { + if (opts->x_svq) { + goto err_svq; + } else { + warn_reportf_err(warn, "Cannot shadow CVQ: "); + } } + } + + if (svq_cvq) { + /* Allocate a common iova tree if there is a possibility of SVQ */ + struct vhost_vdpa_iova_range iova_range; =20 vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); iova_tree =3D vhost_iova_tree_new(iova_range.first, iova_range.las= t); --=20 2.31.1