From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425094434640.765138050024; Fri, 8 Apr 2022 06:38:14 -0700 (PDT) Received: from localhost ([::1]:44842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncooW-0005bR-Ca for importer@patchew.org; Fri, 08 Apr 2022 09:38:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60056) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncokv-0002mx-8g for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48626) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncokt-0003bZ-Po for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:29 -0400 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-108-09rvt7KIOk60ffISDzUL2Q-1; Fri, 08 Apr 2022 09:34:24 -0400 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 A48B285A5BC; Fri, 8 Apr 2022 13:34:23 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2998145B97F; Fri, 8 Apr 2022 13:34:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424867; 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=hKgKZlgYC04pIvK3YPR2QspNXKMOSQacNc53HmmqnRU=; b=hfSs8XLOENaa4e3HBaTgp+sQGOzgFx5/BbYbONVN8eamY0WyHZqpkstQzLG8NYFc+/6F+q A3p5IzgeCoqamv2mivypQv1VyAg3oKQxfqQ1GvCoAZDZ3k2kwecul5FmrN+YyKNtnyHHkT 0st/wprTkOJA8ClVBxqGg7IS1Udlong= X-MC-Unique: 09rvt7KIOk60ffISDzUL2Q-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 01/23] vdpa: Add missing tracing to batch mapping functions Date: Fri, 8 Apr 2022 15:33:53 +0200 Message-Id: <20220408133415.1371760-2-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425094891100001 These functions were not traced properly. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 2 ++ hw/virtio/trace-events | 2 ++ 2 files changed, 4 insertions(+) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 8adf7c0b92..9e5fe15d03 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -129,6 +129,7 @@ static void vhost_vdpa_listener_begin_batch(struct vhos= t_vdpa *v) .iotlb.type =3D VHOST_IOTLB_BATCH_BEGIN, }; =20 + trace_vhost_vdpa_listener_begin_batch(v, fd, msg.type, msg.iotlb.type); if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { error_report("failed to write, fd=3D%d, errno=3D%d (%s)", fd, errno, strerror(errno)); @@ -163,6 +164,7 @@ static void vhost_vdpa_listener_commit(MemoryListener *= listener) msg.type =3D v->msg_type; msg.iotlb.type =3D VHOST_IOTLB_BATCH_END; =20 + trace_vhost_vdpa_listener_commit(v, fd, msg.type, msg.iotlb.type); if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { error_report("failed to write, fd=3D%d, errno=3D%d (%s)", fd, errno, strerror(errno)); diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index a5102eac9e..333348d9d5 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -25,6 +25,8 @@ vhost_user_postcopy_waker_nomatch(const char *rb, uint64_= t rb_offset) "%s + 0x%" # 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_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" vhost_vdpa_listener_region_del(void *vdpa, uint64_t iova, uint64_t llend) = "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64 vhost_vdpa_add_status(void *dev, uint8_t status) "dev: %p status: 0x%"PRIx8 --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425259807218.22609528239138; Fri, 8 Apr 2022 06:40:59 -0700 (PDT) Received: from localhost ([::1]:53404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncorB-0002vH-36 for importer@patchew.org; Fri, 08 Apr 2022 09:40:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncokz-0002nF-Rv for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58978) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncokw-0003c1-Qc for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:31 -0400 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-428-Sm_lUlNRNVCM0cxBEkENJg-1; Fri, 08 Apr 2022 09:34:27 -0400 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 BF66886B8A4; Fri, 8 Apr 2022 13:34:26 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAB1E145B97F; Fri, 8 Apr 2022 13:34:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424870; 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=NY0yjFl4kansC5VeJh7l4mujK97Y5LhTofKmeL7JHAM=; b=dLteW8ZdzUAzrBQq+8YBuNyNdwqsGsrMM24z0it0p4p5Bpet6hbshINlOb31RHua56ZHdH F4J7iIHdhFN+uoytuedDc8Td27nJ6SsW9MKWKZRtkomqaIrOx9oxNBMjobexjbVeMbf2PS 3RLxwSmqi5dcJpBas3b2KvQEf9S38EI= X-MC-Unique: Sm_lUlNRNVCM0cxBEkENJg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 02/23] vdpa: Fix bad index calculus at vhost_vdpa_get_vring_base Date: Fri, 8 Apr 2022 15:33:54 +0200 Message-Id: <20220408133415.1371760-3-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425262033100001 Fixes: 6d0b222666 ("vdpa: Adapt vhost_vdpa_get_vring_base to SVQ") 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 9e5fe15d03..1f229ff4cb 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1172,11 +1172,11 @@ static int vhost_vdpa_get_vring_base(struct vhost_d= ev *dev, struct vhost_vring_state *ring) { struct vhost_vdpa *v =3D dev->opaque; + int vdpa_idx =3D ring->index - dev->vq_index; int ret; =20 if (v->shadow_vqs_enabled) { - VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, - ring->index); + VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, vdp= a_idx); =20 /* * Setting base as last used idx, so destination will see as avail= able --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164942525985023.86071762890697; Fri, 8 Apr 2022 06:40:59 -0700 (PDT) Received: from localhost ([::1]:53508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncorC-0002z0-TU for importer@patchew.org; Fri, 08 Apr 2022 09:40:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncol1-0002nM-F2 for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32403) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncol0-0003cG-0Q for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:35 -0400 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-wGHg2wyUNFKcYYQpH6s3Hg-1; Fri, 08 Apr 2022 09:34:30 -0400 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 DC4D285A5A8; Fri, 8 Apr 2022 13:34:29 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F059145B97F; Fri, 8 Apr 2022 13:34:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424873; 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=4hRd/1JFpc+TVhaJIVv0c3bcCXb/Sz/bn/9yvm/rPhA=; b=KQuVMVOMi7K9bkWJy6jd/43/yAqaWbTxWIUeOJ2BOyrHQPgrkhNfLjsPqPbJCKXDiWKcXH 2Vz0cucemQMGPF8xGSW4+c33UBnF6Fgkj7beo79IiyPGKCEb4mumFQHp+VeCdG4EJoKlzJ wyru2eaJnqB0BJDXm9V0KtiZRGHt+vw= X-MC-Unique: wGHg2wyUNFKcYYQpH6s3Hg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 03/23] util: Return void on iova_tree_remove Date: Fri, 8 Apr 2022 15:33:55 +0200 Message-Id: <20220408133415.1371760-4-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425262035100002 It always returns IOVA_OK so nobody uses it. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- include/qemu/iova-tree.h | 4 +--- util/iova-tree.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/include/qemu/iova-tree.h b/include/qemu/iova-tree.h index c938fb0793..16bbfdf5f8 100644 --- a/include/qemu/iova-tree.h +++ b/include/qemu/iova-tree.h @@ -72,10 +72,8 @@ int iova_tree_insert(IOVATree *tree, const DMAMap *map); * provided. The range does not need to be exactly what has inserted, * all the mappings that are included in the provided range will be * removed from the tree. Here map->translated_addr is meaningless. - * - * Return: 0 if succeeded, or <0 if error. */ -int iova_tree_remove(IOVATree *tree, const DMAMap *map); +void iova_tree_remove(IOVATree *tree, const DMAMap *map); =20 /** * iova_tree_find: diff --git a/util/iova-tree.c b/util/iova-tree.c index 6dff29c1f6..fee530a579 100644 --- a/util/iova-tree.c +++ b/util/iova-tree.c @@ -164,15 +164,13 @@ void iova_tree_foreach(IOVATree *tree, iova_tree_iter= ator iterator) g_tree_foreach(tree->tree, iova_tree_traverse, iterator); } =20 -int iova_tree_remove(IOVATree *tree, const DMAMap *map) +void iova_tree_remove(IOVATree *tree, const DMAMap *map) { const DMAMap *overlap; =20 while ((overlap =3D iova_tree_find(tree, map))) { g_tree_remove(tree->tree, overlap); } - - return IOVA_OK; } =20 /** --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164942509627017.284694428368425; Fri, 8 Apr 2022 06:38:16 -0700 (PDT) Received: from localhost ([::1]:45054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncooZ-0005kN-7J for importer@patchew.org; Fri, 08 Apr 2022 09:38:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncol4-0002rJ-Pq for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21240) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncol3-0003cX-0G for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:38 -0400 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-646-6J2yBloDMsalyLn6S5cbAA-1; Fri, 08 Apr 2022 09:34:33 -0400 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 0BA3D28EA705; Fri, 8 Apr 2022 13:34:33 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D9F614583E7; Fri, 8 Apr 2022 13:34:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424876; 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=n9vkaECCZXkAflzlL3P30ZPEXvMKzVcAl99HEU/aA4A=; b=C/nokY+jC3lE343X+MGlhsePDuxLbpn0NKbyDPEYHCfBj6OT5YNDAu2JuPQhWtwSGcIQYs dMHev0CREhSLfrVO+yeFkA7k4ec56riLXs5IwRSdDFUqUU1YNWTUM2sfqJGUFh3FsS1Q6y 2Ushe+xXMs0t1nNdkU1lLFkwFrah6M0= X-MC-Unique: 6J2yBloDMsalyLn6S5cbAA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 04/23] hw/virtio: Replace g_memdup() by g_memdup2() Date: Fri, 8 Apr 2022 15:33:56 +0200 Message-Id: <20220408133415.1371760-5-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425096762100003 From: Philippe Mathieu-Daud=C3=A9 Per https://discourse.gnome.org/t/port-your-module-from-g-memdup-to-g-memdu= p2-now/5538 The old API took the size of the memory to duplicate as a guint, whereas most memory functions take memory sizes as a gsize. This made it easy to accidentally pass a gsize to g_memdup(). For large values, that would lead to a silent truncation of the size from 64 to 32 bits, and result in a heap area being returned which is significantly smaller than what the caller expects. This can likely be exploited in various modules to cause a heap buffer overflow. Replace g_memdup() by the safer g_memdup2() wrapper. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Jason Wang --- hw/net/virtio-net.c | 3 ++- hw/virtio/virtio-crypto.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 1067e72b39..e4748a7e6c 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1443,7 +1443,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev= , VirtQueue *vq) } =20 iov_cnt =3D elem->out_num; - iov2 =3D iov =3D g_memdup(elem->out_sg, sizeof(struct iovec) * ele= m->out_num); + iov2 =3D iov =3D g_memdup2(elem->out_sg, + sizeof(struct iovec) * elem->out_num); s =3D iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl)); iov_discard_front(&iov, &iov_cnt, sizeof(ctrl)); if (s !=3D sizeof(ctrl)) { diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index dcd80b904d..0e31e3cc04 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -242,7 +242,7 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vde= v, VirtQueue *vq) } =20 out_num =3D elem->out_num; - out_iov_copy =3D g_memdup(elem->out_sg, sizeof(out_iov[0]) * out_n= um); + out_iov_copy =3D g_memdup2(elem->out_sg, sizeof(out_iov[0]) * out_= num); out_iov =3D out_iov_copy; =20 in_num =3D elem->in_num; @@ -605,11 +605,11 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) } =20 out_num =3D elem->out_num; - out_iov_copy =3D g_memdup(elem->out_sg, sizeof(out_iov[0]) * out_num); + out_iov_copy =3D g_memdup2(elem->out_sg, sizeof(out_iov[0]) * out_num); out_iov =3D out_iov_copy; =20 in_num =3D elem->in_num; - in_iov_copy =3D g_memdup(elem->in_sg, sizeof(in_iov[0]) * in_num); + in_iov_copy =3D g_memdup2(elem->in_sg, sizeof(in_iov[0]) * in_num); in_iov =3D in_iov_copy; =20 if (unlikely(iov_to_buf(out_iov, out_num, 0, &req, sizeof(req)) --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425278977579.2649302548397; Fri, 8 Apr 2022 06:41:18 -0700 (PDT) Received: from localhost ([::1]:53678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncorV-000364-6o for importer@patchew.org; Fri, 08 Apr 2022 09:41:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncol7-0002tL-Qj for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58428) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncol6-0003cs-8i for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:41 -0400 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-620-m7cUwEWzN72dRx1IyXc63w-1; Fri, 08 Apr 2022 09:34:36 -0400 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 4F7F63C33B27; Fri, 8 Apr 2022 13:34:36 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6ECCC145B989; Fri, 8 Apr 2022 13:34:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424879; 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=1geVC60KOCBqYcV0yzBh5c9nGhEBBky47+bYEoJUFqQ=; b=R6jEUX7/IPXOBKcAgUsbn1MxNyxk/Rgd02n7pEw0MYS/uGdKnPRs9NfGsRlpQyH+mcr7y7 SJD+0Kx/qLzt3aov56dd9NwEeVt/d3lZHdkfP4KZ/EJLLRkJy/j5qBFnAE28WbcurnsX3M 4PxBXLDHP0jhwTSGdT3kpg67I4TiHpw= X-MC-Unique: m7cUwEWzN72dRx1IyXc63w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 05/23] vhost: Fix bad return of descriptors to SVQ Date: Fri, 8 Apr 2022 15:33:57 +0200 Message-Id: <20220408133415.1371760-6-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425279807100001 Only the first one of them were properly enqueued back. Fixes: 100890f7ca ("vhost: Shadow virtqueue buffers forwarding") Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-shadow-virtqueue.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index b232803d1b..c17506df20 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -333,13 +333,25 @@ static void vhost_svq_disable_notification(VhostShado= wVirtqueue *svq) svq->vring.avail->flags |=3D cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT); } =20 +static uint16_t vhost_svq_last_desc_of_chain(VhostShadowVirtqueue *svq, + uint16_t i) +{ + vring_desc_t *descs =3D svq->vring.desc; + + while (le16_to_cpu(descs[i].flags) & VRING_DESC_F_NEXT) { + i =3D le16_to_cpu(descs[i].next); + } + + return i; +} + static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, uint32_t *len) { vring_desc_t *descs =3D svq->vring.desc; const vring_used_t *used =3D svq->vring.used; vring_used_elem_t used_elem; - uint16_t last_used; + uint16_t last_used, last_used_chain; =20 if (!vhost_svq_more_used(svq)) { return NULL; @@ -365,7 +377,8 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowV= irtqueue *svq, return NULL; } =20 - descs[used_elem.id].next =3D svq->free_head; + last_used_chain =3D vhost_svq_last_desc_of_chain(svq, used_elem.id); + descs[last_used_chain].next =3D svq->free_head; svq->free_head =3D used_elem.id; =20 *len =3D used_elem.len; --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425098685452.1840615579275; Fri, 8 Apr 2022 06:38:18 -0700 (PDT) Received: from localhost ([::1]:45252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncoob-0005sA-4F for importer@patchew.org; Fri, 08 Apr 2022 09:38:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolC-0002vh-AJ for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:40129) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolA-0003dM-LX for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:46 -0400 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-561-XscAYUUsOv-PAHL5pHJveA-1; Fri, 08 Apr 2022 09:34:40 -0400 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 861C21C12DE1; Fri, 8 Apr 2022 13:34:39 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EDEA14583E7; Fri, 8 Apr 2022 13:34:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424884; 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=MjaUdmRv71AomMAF1I+JCfjhng0mfwKSvkU2ZhRqfD0=; b=LN07eFq/hOLtlbZpIcyHMnR6gNHkq/HzljZm3Ahliv4tXdko56Dyr+/cvuMAmlvTWY4Ljh Ez/b1f4j7470XzJ/5NuNJAeeBff2OOGp+swwHbohxvnfSahR+ORbIIEgivfT0+c3IaboMF 8nKCu5Zhbq7wpRtXOpA0voO1e/+jLR8= X-MC-Unique: XscAYUUsOv-PAHL5pHJveA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 06/23] vdpa: Add x-svq to NetdevVhostVDPAOptions Date: Fri, 8 Apr 2022 15:33:58 +0200 Message-Id: <20220408133415.1371760-7-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425100708100001 Finally offering the possibility to enable SVQ from the command line. Signed-off-by: Eugenio P=C3=A9rez --- qapi/net.json | 9 ++++++++- net/vhost-vdpa.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/qapi/net.json b/qapi/net.json index b92f3f5fb4..92848e4362 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -445,12 +445,19 @@ # @queues: number of queues to be created for multiqueue vhost-vdpa # (default: 1) # +# @x-svq: Start device with (experimental) shadow virtqueue. (Since 7.1) +# (default: false) +# +# Features: +# @unstable: Member @x-svq is experimental. +# # Since: 5.1 ## { 'struct': 'NetdevVhostVDPAOptions', 'data': { '*vhostdev': 'str', - '*queues': 'int' } } + '*queues': 'int', + '*x-svq': {'type': 'bool', 'features' : [ 'unstable'] } } } =20 ## # @NetClientDriver: diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 1e9fe47c03..def738998b 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -127,7 +127,11 @@ err_init: static void vhost_vdpa_cleanup(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + struct vhost_dev *dev =3D s->vhost_vdpa.dev; =20 + if (dev && dev->vq_index + dev->nvqs =3D=3D dev->vq_index_end) { + g_clear_pointer(&s->vhost_vdpa.iova_tree, vhost_iova_tree_delete); + } if (s->vhost_net) { vhost_net_cleanup(s->vhost_net); g_free(s->vhost_net); @@ -187,13 +191,23 @@ 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 NetClientState *net_vhost_vdpa_init(NetClientState *peer, - const char *device, - const char *name, - int vdpa_device_fd, - int queue_pair_index, - int nvqs, - bool is_datapath) + const char *device, + const char *name, + int vdpa_device_fd, + int queue_pair_index, + int nvqs, + bool is_datapath, + bool svq, + VhostIOVATree *iova_tree) { NetClientState *nc =3D NULL; VhostVDPAState *s; @@ -211,6 +225,8 @@ 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->vhost_vdpa.shadow_vqs_enabled =3D svq; + s->vhost_vdpa.iova_tree =3D iova_tree; ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, n= vqs); if (ret) { qemu_del_net_client(nc); @@ -266,6 +282,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, g_autofree NetClientState **ncs =3D NULL; NetClientState *nc; int queue_pairs, i, has_cvq =3D 0; + g_autoptr(VhostIOVATree) iova_tree =3D NULL; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); opts =3D &netdev->u.vhost_vdpa; @@ -285,29 +302,44 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, qemu_close(vdpa_device_fd); return queue_pairs; } + if (opts->x_svq) { + struct vhost_vdpa_iova_range iova_range; + + if (has_cvq) { + error_setg(errp, "vdpa svq does not work with cvq"); + goto err_svq; + } + 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 ncs =3D g_malloc0(sizeof(*ncs) * queue_pairs); =20 for (i =3D 0; i < queue_pairs; i++) { ncs[i] =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 2, true); + vdpa_device_fd, i, 2, true, opts->x_s= vq, + iova_tree); if (!ncs[i]) goto err; } =20 if (has_cvq) { nc =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 1, false); + vdpa_device_fd, i, 1, false, opts->x_svq, + iova_tree); if (!nc) goto err; } =20 + iova_tree =3D NULL; return 0; =20 err: if (i) { qemu_del_net_client(ncs[0]); } + +err_svq: qemu_close(vdpa_device_fd); =20 return -1; --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425282007100.53709369557987; Fri, 8 Apr 2022 06:41:22 -0700 (PDT) Received: from localhost ([::1]:53882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncorZ-0003E5-1j for importer@patchew.org; Fri, 08 Apr 2022 09:41:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolG-0002yY-G1 for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolE-0003dg-8a for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:49 -0400 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-388-qv1CmmJZOx67jT6ABpEJNA-1; Fri, 08 Apr 2022 09:34:43 -0400 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 A4004811E80; Fri, 8 Apr 2022 13:34:42 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBBFE145B97F; Fri, 8 Apr 2022 13:34:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424886; 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=wu1vsUndWOLvb3RTGasVPJU6G3DYWl3fVIUxjaYHcOU=; b=Qcema8/XM9PL6Ch4m37vt0HuPCF1BolbGpEONczsYZGcQvEQxYcMlt93/nOwYePMi8B1Bq dmOTXot083RBIlRVXsV1TFYZeGcNK1NBcaLLxHuDEQWYCHMDmZWf5EsCWjl988krh1pfRa 74YcLM56+0Re4QjmX/72V3fOpnDG3Ew= X-MC-Unique: qv1CmmJZOx67jT6ABpEJNA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 07/23] vhost: move descriptor translation to vhost_svq_vring_write_descs Date: Fri, 8 Apr 2022 15:33:59 +0200 Message-Id: <20220408133415.1371760-8-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425283863100001 It's done for both in and out descriptors so it's better placed here. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index c17506df20..bcb5f3aae9 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -122,17 +122,23 @@ static bool vhost_svq_translate_addr(const VhostShado= wVirtqueue *svq, return true; } =20 -static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, - const struct iovec *iovec, size_t num, - bool more_descs, bool write) +static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr = *sg, + const struct iovec *iovec, size_t = num, + bool more_descs, bool write) { uint16_t i =3D svq->free_head, last =3D svq->free_head; unsigned n; uint16_t flags =3D write ? cpu_to_le16(VRING_DESC_F_WRITE) : 0; vring_desc_t *descs =3D svq->vring.desc; + bool ok; =20 if (num =3D=3D 0) { - return; + return true; + } + + ok =3D vhost_svq_translate_addr(svq, sg, iovec, num); + if (unlikely(!ok)) { + return false; } =20 for (n =3D 0; n < num; n++) { @@ -149,6 +155,7 @@ static void vhost_vring_write_descs(VhostShadowVirtqueu= e *svq, hwaddr *sg, } =20 svq->free_head =3D le16_to_cpu(descs[last].next); + return true; } =20 static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, @@ -168,21 +175,18 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue = *svq, return false; } =20 - ok =3D vhost_svq_translate_addr(svq, sgs, elem->out_sg, elem->out_num); + ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->out_sg, elem->out_n= um, + elem->in_num > 0, false); if (unlikely(!ok)) { return false; } - vhost_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num, - elem->in_num > 0, false); =20 - - ok =3D vhost_svq_translate_addr(svq, sgs, elem->in_sg, elem->in_num); + ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num= , false, + true); if (unlikely(!ok)) { return false; } =20 - vhost_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false, tr= ue); - /* * Put the entry in the available array (but don't update avail->idx u= ntil * they do sync). --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425435297491.9803567265312; Fri, 8 Apr 2022 06:43:55 -0700 (PDT) Received: from localhost ([::1]:34260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncotz-0000cC-PA for importer@patchew.org; Fri, 08 Apr 2022 09:43:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolG-0002yb-Fa for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48908) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolE-0003dm-9A for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:49 -0400 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-280-X-bW3qxoMO2BibGPRN3_fQ-1; Fri, 08 Apr 2022 09:34:46 -0400 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 CF847185A7A4; Fri, 8 Apr 2022 13:34:45 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8B0A145B97F; Fri, 8 Apr 2022 13:34:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424887; 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=JcAG0EcP2UeeXAB13Uxux33r2xiCGG/un4uQKOxzZ/g=; b=WG/JE3bfSLwu1Vzd/Xpnw3vwdnUiynnP0pbMaMnhdgxvhwouajhEQEhFtzksVS9hUawtlR QvE8gwbqHCynqS18gtTM1wTQd2AT0g+9h+4oUONiYfmO2F/B/wjpj61hnNzDP+ZwcUPTtI A/zcJNSmgdt9WDOrkkF5Y0EmVCSFnkM= X-MC-Unique: X-bW3qxoMO2BibGPRN3_fQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 08/23] vdpa: Fix index calculus at vhost_vdpa_svqs_start Date: Fri, 8 Apr 2022 15:34:00 +0200 Message-Id: <20220408133415.1371760-9-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425436657100001 Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 1f229ff4cb..3f8fa66e8e 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1018,7 +1018,7 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *d= ev) VirtQueue *vq =3D virtio_get_queue(dev->vdev, dev->vq_index + i); VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, i); struct vhost_vring_addr addr =3D { - .index =3D i, + .index =3D dev->vq_index + i, }; int r; bool ok =3D vhost_vdpa_svq_setup(dev, svq, i, &err); --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425871551598.9827441903361; Fri, 8 Apr 2022 06:51:11 -0700 (PDT) Received: from localhost ([::1]:43870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncp14-0007Ie-I1 for importer@patchew.org; Fri, 08 Apr 2022 09:51:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolU-000341-FB for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21312) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolH-0003e7-2v for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:34:52 -0400 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-12-Q0XtpzhWNYuRId1o4GbTSQ-1; Fri, 08 Apr 2022 09:34:49 -0400 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 E684C1014A62; Fri, 8 Apr 2022 13:34:48 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FF0D14583E7; Fri, 8 Apr 2022 13:34:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424890; 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=65vilO4C7QXbaCNdrrFiA01K50S0z9rLxmu2iLaO/aI=; b=iMIA41/GnSNROoYSeIeINamfa5nEjnkN8OjDvmsgXzEHxudth6z6cXhM+obwqXZwZjCFj3 JQ6DlwwffmGJhxzS9tsby1n57JUT840ljby2rGeJ5+yPIeMkkAs+O9csJi4lPkdYC5aKEZ W97gVIfgoGFvD1/HsThqzsH8XkYJs1k= X-MC-Unique: Q0XtpzhWNYuRId1o4GbTSQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 09/23] virtio-net: Expose ctrl virtqueue logic Date: Fri, 8 Apr 2022 15:34:01 +0200 Message-Id: <20220408133415.1371760-10-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425873479100001 This allows external vhost-net devices to modify the state of the VirtIO device model once vhost-vdpa device has acknowledge the control commands. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/virtio-net.h | 3 ++ hw/net/virtio-net.c | 83 ++++++++++++++++++++-------------- 2 files changed, 51 insertions(+), 35 deletions(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index eb87032627..e62f9e227f 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -218,6 +218,9 @@ struct VirtIONet { struct EBPFRSSContext ebpf_rss; }; =20 +unsigned virtio_net_handle_ctrl_iov(VirtIODevice *vdev, + const struct iovec *in_sg, size_t in_n= um, + struct iovec *out_sg, unsigned out_num= ); void virtio_net_set_netclient_name(VirtIONet *n, const char *name, const char *type); =20 diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index e4748a7e6c..5905a9285c 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1419,57 +1419,70 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8= _t cmd, return VIRTIO_NET_OK; } =20 -static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) +unsigned virtio_net_handle_ctrl_iov(VirtIODevice *vdev, + const struct iovec *in_sg, size_t in_n= um, + struct iovec *out_sg, unsigned out_num) { VirtIONet *n =3D VIRTIO_NET(vdev); struct virtio_net_ctrl_hdr ctrl; virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; - VirtQueueElement *elem; size_t s; struct iovec *iov, *iov2; - unsigned int iov_cnt; + + if (iov_size(in_sg, in_num) < sizeof(status) || + iov_size(out_sg, out_num) < sizeof(ctrl)) { + virtio_error(vdev, "virtio-net ctrl missing headers"); + return 0; + } + + iov2 =3D iov =3D g_memdup2(out_sg, sizeof(struct iovec) * out_num); + s =3D iov_to_buf(iov, out_num, 0, &ctrl, sizeof(ctrl)); + iov_discard_front(&iov, &out_num, sizeof(ctrl)); + if (s !=3D sizeof(ctrl)) { + status =3D VIRTIO_NET_ERR; + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_RX) { + status =3D virtio_net_handle_rx_mode(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MAC) { + status =3D virtio_net_handle_mac(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_VLAN) { + status =3D virtio_net_handle_vlan_table(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_ANNOUNCE) { + status =3D virtio_net_handle_announce(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MQ) { + status =3D virtio_net_handle_mq(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_GUEST_OFFLOADS) { + status =3D virtio_net_handle_offloads(n, ctrl.cmd, iov, out_num); + } + + s =3D iov_from_buf(in_sg, in_num, 0, &status, sizeof(status)); + assert(s =3D=3D sizeof(status)); + + g_free(iov2); + return sizeof(status); +} + +static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtQueueElement *elem; =20 for (;;) { + unsigned written; elem =3D virtqueue_pop(vq, sizeof(VirtQueueElement)); if (!elem) { break; } - if (iov_size(elem->in_sg, elem->in_num) < sizeof(status) || - iov_size(elem->out_sg, elem->out_num) < sizeof(ctrl)) { - virtio_error(vdev, "virtio-net ctrl missing headers"); + + written =3D virtio_net_handle_ctrl_iov(vdev, elem->in_sg, elem->in= _num, + elem->out_sg, elem->out_num); + if (written > 0) { + virtqueue_push(vq, elem, written); + virtio_notify(vdev, vq); + g_free(elem); + } else { virtqueue_detach_element(vq, elem, 0); g_free(elem); break; } - - iov_cnt =3D elem->out_num; - iov2 =3D iov =3D g_memdup2(elem->out_sg, - sizeof(struct iovec) * elem->out_num); - s =3D iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl)); - iov_discard_front(&iov, &iov_cnt, sizeof(ctrl)); - if (s !=3D sizeof(ctrl)) { - status =3D VIRTIO_NET_ERR; - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_RX) { - status =3D virtio_net_handle_rx_mode(n, ctrl.cmd, iov, iov_cnt= ); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MAC) { - status =3D virtio_net_handle_mac(n, ctrl.cmd, iov, iov_cnt); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_VLAN) { - status =3D virtio_net_handle_vlan_table(n, ctrl.cmd, iov, iov_= cnt); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_ANNOUNCE) { - status =3D virtio_net_handle_announce(n, ctrl.cmd, iov, iov_cn= t); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_MQ) { - status =3D virtio_net_handle_mq(n, ctrl.cmd, iov, iov_cnt); - } else if (ctrl.class =3D=3D VIRTIO_NET_CTRL_GUEST_OFFLOADS) { - status =3D virtio_net_handle_offloads(n, ctrl.cmd, iov, iov_cn= t); - } - - s =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &status, sizeof(s= tatus)); - assert(s =3D=3D sizeof(status)); - - virtqueue_push(vq, elem, sizeof(status)); - virtio_notify(vdev, vq); - g_free(iov2); - g_free(elem); } } =20 --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425788379207.04050396562013; Fri, 8 Apr 2022 06:49:48 -0700 (PDT) Received: from localhost ([::1]:42528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncozi-0006Mi-NJ for importer@patchew.org; Fri, 08 Apr 2022 09:49:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolY-00035S-Fm for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:42084) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolU-0003eT-5b for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:06 -0400 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-91-1645fya2PSKGNv_EY7Bf2Q-1; Fri, 08 Apr 2022 09:34:52 -0400 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 0AF5C80159B; Fri, 8 Apr 2022 13:34:52 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37A33145B97F; Fri, 8 Apr 2022 13:34:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424894; 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=Cp+pLK6qQUIS+VZf9K6pYU4iR+sCDEsaxpbkxBhnqMI=; b=Q4qeKkfXd+RCWFUnNcyq1G0ehd5Gd3FOk8cGJqpKCAEC1ejEsomR5Z3GY6jMygErMY4jzn Dc+b0qqaJji0uEHlZjjrM3uPsH8GIw6GMpfwuHryvyd655WJIHU1zUer3fOSceZ9jykucl FczPZ7d3kIS6MowC/ATlQqjIm2zwUks= X-MC-Unique: 1645fya2PSKGNv_EY7Bf2Q-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 10/23] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs Date: Fri, 8 Apr 2022 15:34:02 +0200 Message-Id: <20220408133415.1371760-11-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425790927100001 To know the device features is also needed for CVQ SVQ. Extract from vhost_vdpa_get_max_queue_pairs so we can reuse it. Report errno in case of failure getting them while we're at it. Signed-off-by: Eugenio P=C3=A9rez --- net/vhost-vdpa.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index def738998b..290aa01e13 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -235,20 +235,24 @@ static NetClientState *net_vhost_vdpa_init(NetClientS= tate *peer, return nc; } =20 -static int vhost_vdpa_get_max_queue_pairs(int fd, int *has_cvq, Error **er= rp) +static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **err= p) +{ + int ret =3D ioctl(fd, VHOST_GET_FEATURES, features); + if (ret) { + error_setg_errno(errp, errno, + "Fail to query features from vhost-vDPA device"); + } + return ret; +} + +static int vhost_vdpa_get_max_queue_pairs(int fd, uint64_t features, + int *has_cvq, Error **errp) { unsigned long config_size =3D offsetof(struct vhost_vdpa_config, buf); g_autofree struct vhost_vdpa_config *config =3D NULL; __virtio16 *max_queue_pairs; - uint64_t features; int ret; =20 - ret =3D ioctl(fd, VHOST_GET_FEATURES, &features); - if (ret) { - error_setg(errp, "Fail to query features from vhost-vDPA device"); - return ret; - } - if (features & (1 << VIRTIO_NET_F_CTRL_VQ)) { *has_cvq =3D 1; } else { @@ -278,10 +282,11 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, NetClientState *peer, Error **errp) { const NetdevVhostVDPAOptions *opts; + uint64_t features; int vdpa_device_fd; g_autofree NetClientState **ncs =3D NULL; NetClientState *nc; - int queue_pairs, i, has_cvq =3D 0; + int queue_pairs, r, i, has_cvq =3D 0; g_autoptr(VhostIOVATree) iova_tree =3D NULL; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); @@ -296,7 +301,12 @@ int net_init_vhost_vdpa(const Netdev *netdev, const ch= ar *name, return -errno; } =20 - queue_pairs =3D vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, + r =3D vhost_vdpa_get_features(vdpa_device_fd, &features, errp); + if (r) { + return r; + } + + queue_pairs =3D vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, feature= s, &has_cvq, errp); if (queue_pairs < 0) { qemu_close(vdpa_device_fd); --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425426597939.4939934988971; Fri, 8 Apr 2022 06:43:46 -0700 (PDT) Received: from localhost ([::1]:33984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncott-0000Qy-FN for importer@patchew.org; Fri, 08 Apr 2022 09:43:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolW-00034A-Jx for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:25976) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolU-0003ee-6B for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:05 -0400 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-587-ljghHgVGM06-QL8t2LzD-w-1; Fri, 08 Apr 2022 09:34:55 -0400 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 264DB381D8AE; Fri, 8 Apr 2022 13:34:55 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F524145B97F; Fri, 8 Apr 2022 13:34:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424897; 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=H+ZKd6KUcLTqI9r8rju+MObNDFWLHKaMjymBGI90yBQ=; b=KWH5l4mcsXoY/UYilJdtdOWI9UGR4WL/tgN+RpWeK4fGSxyxw9fgKRZhtYyc2IsKzMfJZD 6t13WXb3buGEyTuf5hvNBYw7Hyr76EPG5w4ifl3wV513buFJx8BNe59zVF+KlPcaz0rIW1 FtsyuJEAn1krpBtyh7iql9SS+qM57JU= X-MC-Unique: ljghHgVGM06-QL8t2LzD-w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 11/23] virtio: Make virtqueue_alloc_element non-static Date: Fri, 8 Apr 2022 15:34:03 +0200 Message-Id: <20220408133415.1371760-12-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425428562100001 So SVQ can allocate elements using it Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/virtio.h | 1 + hw/virtio/virtio.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b31c4507f5..1e85833897 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -195,6 +195,7 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueEleme= nt *elem, unsigned int len, unsigned int idx); =20 void virtqueue_map(VirtIODevice *vdev, VirtQueueElement *elem); +void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num= ); void *virtqueue_pop(VirtQueue *vq, size_t sz); unsigned int virtqueue_drop_all(VirtQueue *vq); void *qemu_get_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, size_t s= z); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 9d637e043e..17cbbb5fca 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1376,7 +1376,7 @@ void virtqueue_map(VirtIODevice *vdev, VirtQueueEleme= nt *elem) fa= lse); } =20 -static void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned= in_num) +void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num) { VirtQueueElement *elem; size_t in_addr_ofs =3D QEMU_ALIGN_UP(sz, __alignof__(elem->in_addr[0])= ); --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425419992357.54122050882984; Fri, 8 Apr 2022 06:43:39 -0700 (PDT) Received: from localhost ([::1]:33804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncotm-0000Iw-FI for importer@patchew.org; Fri, 08 Apr 2022 09:43:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolY-00035P-EI for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48163) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolU-0003ey-BT for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:07 -0400 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-626-TRovmIazPZ2DNB0WRqAXbQ-1; Fri, 08 Apr 2022 09:34:59 -0400 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 834A0185A79C; Fri, 8 Apr 2022 13:34:58 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BFC014583E7; Fri, 8 Apr 2022 13:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424901; 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=y6sMK5av6SgTfEBF+xWQTA3ffG7GV1ORuW8fC48+Uy0=; b=E/07Tsr4jZZoUgo/qafWsqcd2DtisUXe8NNNSYYUyyUH4hbzt4uKV13tbdoZS0yQQSDGo+ CotZAW2UnOpsU+eAFjSM/CEtXhnT0ktlIDElzHxKUY3qt1wqupJoAo1Ef8DC4TtHCwsSvD ullqOaJ1hD6dTHqvFWgzfEQrMyd+/gw= X-MC-Unique: TRovmIazPZ2DNB0WRqAXbQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 12/23] vhost: Add SVQElement Date: Fri, 8 Apr 2022 15:34:04 +0200 Message-Id: <20220408133415.1371760-13-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425421027100001 This allows SVQ to add metadata to the different queue elements Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 8 ++++-- hw/virtio/vhost-shadow-virtqueue.c | 42 ++++++++++++++++-------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index e5e24c536d..72aadb0aec 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -15,6 +15,10 @@ #include "standard-headers/linux/vhost_types.h" #include "hw/virtio/vhost-iova-tree.h" =20 +typedef struct SVQElement { + VirtQueueElement elem; +} SVQElement; + /* Shadow virtqueue to relay notifications */ typedef struct VhostShadowVirtqueue { /* Shadow vring */ @@ -48,10 +52,10 @@ typedef struct VhostShadowVirtqueue { VhostIOVATree *iova_tree; =20 /* Map for use the guest's descriptors */ - VirtQueueElement **ring_id_maps; + SVQElement **ring_id_maps; =20 /* Next VirtQueue element that guest made available */ - VirtQueueElement *next_guest_avail_elem; + SVQElement *next_guest_avail_elem; =20 /* Next head to expose to the device */ uint16_t shadow_avail_idx; diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index bcb5f3aae9..cf701576d1 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -158,9 +158,10 @@ static bool vhost_svq_vring_write_descs(VhostShadowVir= tqueue *svq, hwaddr *sg, return true; } =20 -static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, - VirtQueueElement *elem, unsigned *head) +static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, SVQElement *svq= _elem, + unsigned *head) { + const VirtQueueElement *elem =3D &svq_elem->elem; unsigned avail_idx; vring_avail_t *avail =3D svq->vring.avail; bool ok; @@ -202,7 +203,7 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *s= vq, return true; } =20 -static bool vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *ele= m) +static bool vhost_svq_add(VhostShadowVirtqueue *svq, SVQElement *elem) { unsigned qemu_head; bool ok =3D vhost_svq_add_split(svq, elem, &qemu_head); @@ -251,19 +252,21 @@ static void vhost_handle_guest_kick(VhostShadowVirtqu= eue *svq) virtio_queue_set_notification(svq->vq, false); =20 while (true) { + SVQElement *svq_elem; VirtQueueElement *elem; bool ok; =20 if (svq->next_guest_avail_elem) { - elem =3D g_steal_pointer(&svq->next_guest_avail_elem); + svq_elem =3D g_steal_pointer(&svq->next_guest_avail_elem); } else { - elem =3D virtqueue_pop(svq->vq, sizeof(*elem)); + svq_elem =3D virtqueue_pop(svq->vq, sizeof(*svq_elem)); } =20 - if (!elem) { + if (!svq_elem) { break; } =20 + elem =3D &svq_elem->elem; if (elem->out_num + elem->in_num > vhost_svq_available_slots(s= vq)) { /* * This condition is possible since a contiguous buffer in= GPA @@ -276,11 +279,11 @@ static void vhost_handle_guest_kick(VhostShadowVirtqu= eue *svq) * queue the current guest descriptor and ignore further k= icks * until some elements are used. */ - svq->next_guest_avail_elem =3D elem; + svq->next_guest_avail_elem =3D svq_elem; return; } =20 - ok =3D vhost_svq_add(svq, elem); + ok =3D vhost_svq_add(svq, svq_elem); if (unlikely(!ok)) { /* VQ is broken, just return and ignore any other kicks */ return; @@ -349,8 +352,7 @@ static uint16_t vhost_svq_last_desc_of_chain(VhostShado= wVirtqueue *svq, return i; } =20 -static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, - uint32_t *len) +static SVQElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, uint32_t *= len) { vring_desc_t *descs =3D svq->vring.desc; const vring_used_t *used =3D svq->vring.used; @@ -401,11 +403,13 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, vhost_svq_disable_notification(svq); while (true) { uint32_t len; - g_autofree VirtQueueElement *elem =3D vhost_svq_get_buf(svq, &= len); - if (!elem) { + g_autofree SVQElement *svq_elem =3D vhost_svq_get_buf(svq, &le= n); + VirtQueueElement *elem; + if (!svq_elem) { break; } =20 + elem =3D &svq_elem->elem; if (unlikely(i >=3D svq->vring.num)) { qemu_log_mask(LOG_GUEST_ERROR, "More than %u used buffers obtained in a %u size = SVQ", @@ -556,7 +560,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, memset(svq->vring.desc, 0, driver_size); svq->vring.used =3D qemu_memalign(qemu_real_host_page_size, device_siz= e); memset(svq->vring.used, 0, device_size); - svq->ring_id_maps =3D g_new0(VirtQueueElement *, svq->vring.num); + svq->ring_id_maps =3D g_new0(SVQElement *, svq->vring.num); for (unsigned i =3D 0; i < svq->vring.num - 1; i++) { svq->vring.desc[i].next =3D cpu_to_le16(i + 1); } @@ -569,7 +573,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, void vhost_svq_stop(VhostShadowVirtqueue *svq) { event_notifier_set_handler(&svq->svq_kick, NULL); - g_autofree VirtQueueElement *next_avail_elem =3D NULL; + g_autofree SVQElement *next_avail_elem =3D NULL; =20 if (!svq->vq) { return; @@ -579,16 +583,16 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) vhost_svq_flush(svq, false); =20 for (unsigned i =3D 0; i < svq->vring.num; ++i) { - g_autofree VirtQueueElement *elem =3D NULL; - elem =3D g_steal_pointer(&svq->ring_id_maps[i]); - if (elem) { - virtqueue_detach_element(svq->vq, elem, 0); + g_autofree SVQElement *svq_elem =3D NULL; + svq_elem =3D g_steal_pointer(&svq->ring_id_maps[i]); + if (svq_elem) { + virtqueue_detach_element(svq->vq, &svq_elem->elem, 0); } } =20 next_avail_elem =3D g_steal_pointer(&svq->next_guest_avail_elem); if (next_avail_elem) { - virtqueue_detach_element(svq->vq, next_avail_elem, 0); + virtqueue_detach_element(svq->vq, &next_avail_elem->elem, 0); } svq->vq =3D NULL; g_free(svq->ring_id_maps); --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425980004196.79725970063907; Fri, 8 Apr 2022 06:53:00 -0700 (PDT) Received: from localhost ([::1]:51178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncp2o-0003r1-W7 for importer@patchew.org; Fri, 08 Apr 2022 09:52:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolZ-00035U-Rs for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48896) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolY-0003po-5N for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:09 -0400 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-265-zZeGzKjqMKW5tTR_urGGfw-1; Fri, 08 Apr 2022 09:35:02 -0400 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 D698428EA705; Fri, 8 Apr 2022 13:35:01 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id D028514583E7; Fri, 8 Apr 2022 13:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424906; 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=ObqKJN5OUF/rCbSuNkxUYEffGZRq876oDQSMibVxKx8=; b=aoKsMTDH7LIps68xliKAKdFWHbF5TZ7IU5YuyBItClRcNkstUPYqLWE0cBXsBl3PQF+Xhw Dg94FFtYJgezHqHvBVkt/OsNFywLfrjYcoQq5GwUMg+vDFg9OeludL09caOCnRpSSezVRX JbrTrQuULacnA8eRsMQeGwqkMIGAYq0= X-MC-Unique: zZeGzKjqMKW5tTR_urGGfw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 13/23] vhost: Add custom used buffer callback Date: Fri, 8 Apr 2022 15:34:05 +0200 Message-Id: <20220408133415.1371760-14-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425981747100001 The callback allows SVQ users to know the VirtQueue requests and responses. QEMU can use this to synchronize virtio device model state, allowing to migrate it with minimum changes to the migration code. In the case of networking, this will be used to inspect control virtqueue messages. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 16 +++++++++++++++- include/hw/virtio/vhost-vdpa.h | 2 ++ hw/virtio/vhost-shadow-virtqueue.c | 9 ++++++++- hw/virtio/vhost-vdpa.c | 3 ++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 72aadb0aec..4ff6a0cda0 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -19,6 +19,13 @@ typedef struct SVQElement { VirtQueueElement elem; } SVQElement; =20 +typedef void (*VirtQueueElementCallback)(VirtIODevice *vdev, + const VirtQueueElement *elem); + +typedef struct VhostShadowVirtqueueOps { + VirtQueueElementCallback used_elem_handler; +} VhostShadowVirtqueueOps; + /* Shadow virtqueue to relay notifications */ typedef struct VhostShadowVirtqueue { /* Shadow vring */ @@ -57,6 +64,12 @@ typedef struct VhostShadowVirtqueue { /* Next VirtQueue element that guest made available */ SVQElement *next_guest_avail_elem; =20 + /* Optional callbacks */ + const VhostShadowVirtqueueOps *ops; + + /* Optional custom used virtqueue element handler */ + VirtQueueElementCallback used_elem_cb; + /* Next head to expose to the device */ uint16_t shadow_avail_idx; =20 @@ -83,7 +96,8 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODev= ice *vdev, VirtQueue *vq); void vhost_svq_stop(VhostShadowVirtqueue *svq); =20 -VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree); +VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, + const VhostShadowVirtqueueOps *ops); =20 void vhost_svq_free(gpointer vq); G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostShadowVirtqueue, vhost_svq_free); diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index a29dbb3f53..f1ba46a860 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -17,6 +17,7 @@ #include "hw/virtio/vhost-iova-tree.h" #include "hw/virtio/virtio.h" #include "standard-headers/linux/vhost_types.h" +#include "hw/virtio/vhost-shadow-virtqueue.h" =20 typedef struct VhostVDPAHostNotifier { MemoryRegion mr; @@ -35,6 +36,7 @@ typedef struct vhost_vdpa { /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; GPtrArray *shadow_vqs; + const VhostShadowVirtqueueOps *shadow_vq_ops; struct vhost_dev *dev; VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index cf701576d1..208832a698 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -419,6 +419,10 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, return; } virtqueue_fill(vq, elem, len, i++); + + if (svq->ops && svq->ops->used_elem_handler) { + svq->ops->used_elem_handler(svq->vdev, elem); + } } =20 virtqueue_flush(vq, i); @@ -605,12 +609,14 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) * shadow methods and file descriptors. * * @iova_tree: Tree to perform descriptors translations + * @ops: SVQ operations hooks * * Returns the new virtqueue or NULL. * * In case of error, reason is reported through error_report. */ -VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree) +VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, + const VhostShadowVirtqueueOps *ops) { g_autofree VhostShadowVirtqueue *svq =3D g_new0(VhostShadowVirtqueue, = 1); int r; @@ -632,6 +638,7 @@ VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova= _tree) 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; return g_steal_pointer(&svq); =20 err_init_hdev_call: diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 3f8fa66e8e..421eddf8ca 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -411,7 +411,8 @@ 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 =3D vhost_svq_new(v->iova_tree= ); + g_autoptr(VhostShadowVirtqueue) svq =3D vhost_svq_new(v->iova_tree, + v->shadow_vq_o= ps); =20 if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649426185476641.9210361936588; Fri, 8 Apr 2022 06:56:25 -0700 (PDT) Received: from localhost ([::1]:59854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncp67-0001GD-70 for importer@patchew.org; Fri, 08 Apr 2022 09:56:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncoli-0003G9-V9 for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:25876) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolg-0003rG-IL for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:18 -0400 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-177-uRM7ux9kOYunA6u1TKGBrA-1; Fri, 08 Apr 2022 09:35:05 -0400 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 0C00C28EA711; Fri, 8 Apr 2022 13:35:05 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2980E1410F3B; Fri, 8 Apr 2022 13:35:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424916; 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=Da3BHGyAUkkYsbHgyZwVeZEaa40hKI/NVlYgdlhFTDU=; b=eUaAnFn6pO8cyVVq02Hx1wSpWshuxActkfXJ7BOqZW8ty0MCKsvoAkL+KEjDhEL75rAgUT qx1yhYQU2NBqIWj6tidACsoh6X7l9Q2t55VI6t0ZQtImHrtTYVxDfelTSSqXRYc2zTU5ef 1u0+0GmY7aAbZZ5JeqpZmo303ShT9Xg= X-MC-Unique: uRM7ux9kOYunA6u1TKGBrA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 14/23] vdpa: control virtqueue support on shadow virtqueue Date: Fri, 8 Apr 2022 15:34:06 +0200 Message-Id: <20220408133415.1371760-15-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649426187120100001 Introduce the control virtqueue support for vDPA shadow virtqueue. This is needed for advanced networking features like multiqueue. To demonstrate command handling, VIRTIO_NET_F_CTRL_MACADDR and VIRTIO_NET_CTRL_MQ are implemented. If vDPA device is started with SVQ support and virtio-net driver changes MAC or the number of queues virtio-net device model will be updated with the new one. Others cvq commands could be added here straightforwardly but they have been not tested. Signed-off-by: Eugenio P=C3=A9rez --- net/vhost-vdpa.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 290aa01e13..a83da4616c 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -11,6 +11,7 @@ =20 #include "qemu/osdep.h" #include "clients.h" +#include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "net/vhost-vdpa.h" #include "hw/virtio/vhost-vdpa.h" @@ -69,6 +70,30 @@ const int vdpa_feature_bits[] =3D { VHOST_INVALID_FEATURE_BIT }; =20 +/** Supported device specific feature bits with SVQ */ +static const uint64_t vdpa_svq_device_features =3D + BIT_ULL(VIRTIO_NET_F_CSUM) | + BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) | + BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) | + BIT_ULL(VIRTIO_NET_F_MTU) | + BIT_ULL(VIRTIO_NET_F_MAC) | + BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) | + BIT_ULL(VIRTIO_NET_F_GUEST_TSO6) | + BIT_ULL(VIRTIO_NET_F_GUEST_ECN) | + BIT_ULL(VIRTIO_NET_F_GUEST_UFO) | + BIT_ULL(VIRTIO_NET_F_HOST_TSO4) | + BIT_ULL(VIRTIO_NET_F_HOST_TSO6) | + BIT_ULL(VIRTIO_NET_F_HOST_ECN) | + BIT_ULL(VIRTIO_NET_F_HOST_UFO) | + BIT_ULL(VIRTIO_NET_F_MRG_RXBUF) | + BIT_ULL(VIRTIO_NET_F_STATUS) | + BIT_ULL(VIRTIO_NET_F_CTRL_VQ) | + BIT_ULL(VIRTIO_NET_F_MQ) | + BIT_ULL(VIRTIO_F_ANY_LAYOUT) | + BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR) | + BIT_ULL(VIRTIO_NET_F_RSC_EXT) | + BIT_ULL(VIRTIO_NET_F_STANDBY); + VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); @@ -199,6 +224,46 @@ static int vhost_vdpa_get_iova_range(int fd, return ret < 0 ? -errno : 0; } =20 +static void vhost_vdpa_net_handle_ctrl(VirtIODevice *vdev, + const VirtQueueElement *elem) +{ + struct virtio_net_ctrl_hdr ctrl; + virtio_net_ctrl_ack status =3D VIRTIO_NET_ERR; + size_t s; + struct iovec in =3D { + .iov_base =3D &status, + .iov_len =3D sizeof(status), + }; + + s =3D iov_to_buf(elem->out_sg, elem->out_num, 0, &ctrl, sizeof(ctrl.cl= ass)); + if (s !=3D sizeof(ctrl.class)) { + return; + } + + switch (ctrl.class) { + case VIRTIO_NET_CTRL_MAC_ADDR_SET: + case VIRTIO_NET_CTRL_MQ: + break; + default: + return; + }; + + s =3D iov_to_buf(elem->in_sg, elem->in_num, 0, &status, sizeof(status)= ); + if (s !=3D sizeof(status) || status !=3D VIRTIO_NET_OK) { + return; + } + + status =3D VIRTIO_NET_ERR; + virtio_net_handle_ctrl_iov(vdev, &in, 1, elem->out_sg, elem->out_num); + if (status !=3D VIRTIO_NET_OK) { + error_report("Bad CVQ processing in model"); + } +} + +static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops =3D { + .used_elem_handler =3D vhost_vdpa_net_handle_ctrl, +}; + static NetClientState *net_vhost_vdpa_init(NetClientState *peer, const char *device, const char *name, @@ -226,6 +291,9 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; s->vhost_vdpa.shadow_vqs_enabled =3D svq; + if (!is_datapath) { + s->vhost_vdpa.shadow_vq_ops =3D &vhost_vdpa_net_svq_ops; + } s->vhost_vdpa.iova_tree =3D iova_tree; ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, n= vqs); if (ret) { @@ -314,9 +382,15 @@ int net_init_vhost_vdpa(const Netdev *netdev, const ch= ar *name, } if (opts->x_svq) { struct vhost_vdpa_iova_range iova_range; - - if (has_cvq) { - error_setg(errp, "vdpa svq does not work with cvq"); + 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); goto err_svq; } vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425796903968.1327511853539; Fri, 8 Apr 2022 06:49:56 -0700 (PDT) Received: from localhost ([::1]:42690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncozr-0006Tz-Ci for importer@patchew.org; Fri, 08 Apr 2022 09:49:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolg-0003Aq-BO for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23572) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncole-0003r0-Oq for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:15 -0400 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-468-rfTM3gwbPFyngQ6lnx8n8A-1; Fri, 08 Apr 2022 09:35:09 -0400 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 8D11F811E76; Fri, 8 Apr 2022 13:35:08 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 514FD145B989; Fri, 8 Apr 2022 13:35:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424914; 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=hHzOVhbuDAldunZ9QcAku48EC7FHmGMGuqGVYEMagSk=; b=cwp+h0Ntq4pG+M354JpwSiVw/J2W87RXePackUCD9Ka56LW9dGgo/JwM7dXTYqMVW0XHL1 UOMMy6egLNgFvANr/q/jACzyE7N++EZq4y0Fz+WJ4cIzYyHws5V3/Pyuw+OhIxF1EMAbUt 7IEWkCUDXbeSNzlulho9Otwt/S2/orU= X-MC-Unique: rfTM3gwbPFyngQ6lnx8n8A-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 15/23] vhost: Add vhost_iova_tree_find Date: Fri, 8 Apr 2022 15:34:07 +0200 Message-Id: <20220408133415.1371760-16-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425798651100001 Just a simple wrapper so we can find DMAMap entries based on iova Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-iova-tree.h | 2 ++ hw/virtio/vhost-iova-tree.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/hw/virtio/vhost-iova-tree.h b/hw/virtio/vhost-iova-tree.h index 6a4f24e0f9..1ffcdc5b57 100644 --- a/hw/virtio/vhost-iova-tree.h +++ b/hw/virtio/vhost-iova-tree.h @@ -19,6 +19,8 @@ VhostIOVATree *vhost_iova_tree_new(uint64_t iova_first, u= int64_t iova_last); void vhost_iova_tree_delete(VhostIOVATree *iova_tree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostIOVATree, vhost_iova_tree_delete); =20 +const DMAMap *vhost_iova_tree_find(const VhostIOVATree *iova_tree, + const DMAMap *map); const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *iova_tree, const DMAMap *map); int vhost_iova_tree_map_alloc(VhostIOVATree *iova_tree, DMAMap *map); diff --git a/hw/virtio/vhost-iova-tree.c b/hw/virtio/vhost-iova-tree.c index 55fed1fefb..7d4e8ac499 100644 --- a/hw/virtio/vhost-iova-tree.c +++ b/hw/virtio/vhost-iova-tree.c @@ -56,6 +56,20 @@ void vhost_iova_tree_delete(VhostIOVATree *iova_tree) g_free(iova_tree); } =20 +/** + * Find a mapping in the tree that matches map + * + * @iova_tree The iova tree + * @map The map + * + * Return a matching map that contains argument map or NULL + */ +const DMAMap *vhost_iova_tree_find(const VhostIOVATree *iova_tree, + const DMAMap *map) +{ + return iova_tree_find(iova_tree->iova_taddr_map, map); +} + /** * Find the IOVA address stored from a memory address * --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425426629745.4792188879264; Fri, 8 Apr 2022 06:43:46 -0700 (PDT) Received: from localhost ([::1]:34010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncotr-0000Rj-Or for importer@patchew.org; Fri, 08 Apr 2022 09:43:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolh-0003Ei-Vk for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60226) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolf-0003r9-VF for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:17 -0400 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-278-FrO4L0vVOQKc2XhrKuJ9Dw-1; Fri, 08 Apr 2022 09:35:12 -0400 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 A8426185A7A4; Fri, 8 Apr 2022 13:35:11 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id D21E8145B989; Fri, 8 Apr 2022 13:35:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424915; 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=Wi9FawyPi4L6fRdHrLUNb9P/AF8WHvZY93cQmd8wvBk=; b=cdp8L8aF5SDncqsAdtkTpK4fao+COVQ/UmJQ7k2XnSVfGj6w3PLXbthcfd1E59O8C7YPTS bhDXkBzy1Ge2j/4CFfind/J9SOLJTEP2sqtN7W3bF6GCTP1wdu/cSL654IjPBe3xRBNvFV pFtShcQ54DQZOSUZwK5+/IYoSB4L4s4= X-MC-Unique: FrO4L0vVOQKc2XhrKuJ9Dw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 16/23] vdpa: Add map/unmap operation callback to SVQ Date: Fri, 8 Apr 2022 15:34:08 +0200 Message-Id: <20220408133415.1371760-17-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425428588100003 Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 21 +++++++++++++++++++-- hw/virtio/vhost-shadow-virtqueue.c | 8 +++++++- hw/virtio/vhost-vdpa.c | 20 +++++++++++++++++++- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 4ff6a0cda0..6e61d9bfef 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -26,6 +26,15 @@ typedef struct VhostShadowVirtqueueOps { VirtQueueElementCallback used_elem_handler; } VhostShadowVirtqueueOps; =20 +typedef int (*vhost_svq_map_op)(hwaddr iova, hwaddr size, void *vaddr, + bool readonly, void *opaque); +typedef int (*vhost_svq_unmap_op)(hwaddr iova, hwaddr size, void *opaque); + +typedef struct VhostShadowVirtqueueMapOps { + vhost_svq_map_op map; + vhost_svq_unmap_op unmap; +} VhostShadowVirtqueueMapOps; + /* Shadow virtqueue to relay notifications */ typedef struct VhostShadowVirtqueue { /* Shadow vring */ @@ -67,6 +76,12 @@ typedef struct VhostShadowVirtqueue { /* Optional callbacks */ const VhostShadowVirtqueueOps *ops; =20 + /* Device memory mapping callbacks */ + const VhostShadowVirtqueueMapOps *map_ops; + + /* Device memory mapping callbacks opaque */ + void *map_ops_opaque; + /* Optional custom used virtqueue element handler */ VirtQueueElementCallback used_elem_cb; =20 @@ -96,8 +111,10 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, VirtQueue *vq); void vhost_svq_stop(VhostShadowVirtqueue *svq); =20 -VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, - const VhostShadowVirtqueueOps *ops); +VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_map, + const VhostShadowVirtqueueOps *ops, + const VhostShadowVirtqueueMapOps *map_= ops, + void *map_ops_opaque); =20 void vhost_svq_free(gpointer vq); G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostShadowVirtqueue, vhost_svq_free); diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 208832a698..15e6cbc5cb 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -610,13 +610,17 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) * * @iova_tree: Tree to perform descriptors translations * @ops: SVQ operations hooks + * @map_ops: SVQ mapping operation hooks + * @map_ops_opaque: Opaque data to pass to mapping operations * * 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) + const VhostShadowVirtqueueOps *ops, + const VhostShadowVirtqueueMapOps *map_= ops, + void *map_ops_opaque) { g_autofree VhostShadowVirtqueue *svq =3D g_new0(VhostShadowVirtqueue, = 1); int r; @@ -639,6 +643,8 @@ VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova= _tree, event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); svq->iova_tree =3D iova_tree; svq->ops =3D ops; + svq->map_ops =3D map_ops; + svq->map_ops_opaque =3D map_ops_opaque; return g_steal_pointer(&svq); =20 err_init_hdev_call: diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 421eddf8ca..d09e06d212 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -385,6 +385,22 @@ static int vhost_vdpa_get_dev_features(struct vhost_de= v *dev, return ret; } =20 +static int vhost_vdpa_svq_map(hwaddr iova, hwaddr size, void *vaddr, + bool readonly, void *opaque) +{ + return vhost_vdpa_dma_map(opaque, iova, size, vaddr, readonly); +} + +static int vhost_vdpa_svq_unmap(hwaddr iova, hwaddr size, void *opaque) +{ + return vhost_vdpa_dma_unmap(opaque, iova, size); +} + +static const VhostShadowVirtqueueMapOps vhost_vdpa_svq_map_ops =3D { + .map =3D vhost_vdpa_svq_map, + .unmap =3D vhost_vdpa_svq_unmap, +}; + static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *= v, Error **errp) { @@ -412,7 +428,9 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, = struct vhost_vdpa *v, 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 =3D vhost_svq_new(v->iova_tree, - v->shadow_vq_o= ps); + v->shadow_vq_ops, + &vhost_vdpa_svq_map= _ops, + v); =20 if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649426365425243.46003896019738; Fri, 8 Apr 2022 06:59:25 -0700 (PDT) Received: from localhost ([::1]:40492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncp91-0007IZ-U6 for importer@patchew.org; Fri, 08 Apr 2022 09:59:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncoll-0003OH-T3 for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23128) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolj-0003rj-MJ for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:21 -0400 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-76-jJm_mpYfNzKDb-kGOEqy2A-1; Fri, 08 Apr 2022 09:35:15 -0400 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 39A4E811E75; Fri, 8 Apr 2022 13:35:15 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED17B145B97F; Fri, 8 Apr 2022 13:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424918; 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=enYYW2JCSlMr4WqUdZnHPpB6wl/SgsQ0b07XNxMSKw8=; b=fxnJVJmI7PkPv0Z47Sb9K29v+30ygARcn1PrpS44Uogv5+0q7d7e30WJt/PwvUQ6cwmRbO KsqW7kt7LGoKSumMwAscvI1/IOWbi4ui1ce5iLQAXXjBeN7Qg3jWzneSe+LT6/q+LEVApx yRz/HS/ZYLmWAa/EtiJ81QABHXKkZWo= X-MC-Unique: jJm_mpYfNzKDb-kGOEqy2A-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 17/23] vhost: Add vhost_svq_inject Date: Fri, 8 Apr 2022 15:34:09 +0200 Message-Id: <20220408133415.1371760-18-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649426366311100001 This allows qemu to inject packets to the device without guest's notice. This will be use to inject net CVQ messages to restore status in the destin= ation Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 5 + hw/virtio/vhost-shadow-virtqueue.c | 179 +++++++++++++++++++++++++---- 2 files changed, 160 insertions(+), 24 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 6e61d9bfef..d82a64d566 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -17,6 +17,9 @@ =20 typedef struct SVQElement { VirtQueueElement elem; + hwaddr in_iova; + hwaddr out_iova; + bool not_from_guest; } SVQElement; =20 typedef void (*VirtQueueElementCallback)(VirtIODevice *vdev, @@ -100,6 +103,8 @@ typedef struct VhostShadowVirtqueue { =20 bool vhost_svq_valid_features(uint64_t features, Error **errp); =20 +bool vhost_svq_inject(VhostShadowVirtqueue *svq, const struct iovec *iov, + size_t out_num, size_t in_num); void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 15e6cbc5cb..26f40dda9e 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -16,6 +16,7 @@ #include "qemu/log.h" #include "qemu/memalign.h" #include "linux-headers/linux/vhost.h" +#include "qemu/iov.h" =20 /** * Validate the transport device features that both guests can use with th= e SVQ @@ -122,7 +123,8 @@ static bool vhost_svq_translate_addr(const VhostShadowV= irtqueue *svq, return true; } =20 -static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr = *sg, +static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, + SVQElement *svq_elem, hwaddr *sg, const struct iovec *iovec, size_t = num, bool more_descs, bool write) { @@ -130,15 +132,39 @@ static bool vhost_svq_vring_write_descs(VhostShadowVi= rtqueue *svq, hwaddr *sg, unsigned n; uint16_t flags =3D write ? cpu_to_le16(VRING_DESC_F_WRITE) : 0; vring_desc_t *descs =3D svq->vring.desc; - bool ok; =20 if (num =3D=3D 0) { return true; } =20 - ok =3D vhost_svq_translate_addr(svq, sg, iovec, num); - if (unlikely(!ok)) { - return false; + if (svq_elem->not_from_guest) { + DMAMap map =3D { + .translated_addr =3D (hwaddr)iovec->iov_base, + .size =3D ROUND_UP(iovec->iov_len, 4096) - 1, + .perm =3D write ? IOMMU_RW : IOMMU_RO, + }; + int r; + + if (unlikely(num !=3D 1)) { + error_report("Unexpected chain of element injected"); + return false; + } + r =3D vhost_iova_tree_map_alloc(svq->iova_tree, &map); + if (unlikely(r !=3D IOVA_OK)) { + error_report("Cannot map injected element"); + return false; + } + + r =3D svq->map_ops->map(map.iova, map.size + 1, + (void *)map.translated_addr, !write, + svq->map_ops_opaque); + assert(r =3D=3D 0); + sg[0] =3D map.iova; + } else { + bool ok =3D vhost_svq_translate_addr(svq, sg, iovec, num); + if (unlikely(!ok)) { + return false; + } } =20 for (n =3D 0; n < num; n++) { @@ -165,7 +191,8 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *s= vq, SVQElement *svq_elem, unsigned avail_idx; vring_avail_t *avail =3D svq->vring.avail; bool ok; - g_autofree hwaddr *sgs =3D g_new(hwaddr, MAX(elem->out_num, elem->in_n= um)); + g_autofree hwaddr *sgs =3D NULL; + hwaddr *in_sgs, *out_sgs; =20 *head =3D svq->free_head; =20 @@ -176,15 +203,23 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue = *svq, SVQElement *svq_elem, return false; } =20 - ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->out_sg, elem->out_n= um, - elem->in_num > 0, false); + if (!svq_elem->not_from_guest) { + sgs =3D g_new(hwaddr, MAX(elem->out_num, elem->in_num)); + in_sgs =3D out_sgs =3D sgs; + } else { + in_sgs =3D &svq_elem->in_iova; + out_sgs =3D &svq_elem->out_iova; + } + ok =3D vhost_svq_vring_write_descs(svq, svq_elem, out_sgs, elem->out_s= g, + elem->out_num, elem->in_num > 0, fals= e); if (unlikely(!ok)) { return false; } =20 - ok =3D vhost_svq_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num= , false, - true); + ok =3D vhost_svq_vring_write_descs(svq, svq_elem, in_sgs, elem->in_sg, + elem->in_num, false, true); if (unlikely(!ok)) { + /* TODO unwind out_sg */ return false; } =20 @@ -229,6 +264,43 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) event_notifier_set(&svq->hdev_kick); } =20 +bool vhost_svq_inject(VhostShadowVirtqueue *svq, const struct iovec *iov, + size_t out_num, size_t in_num) +{ + size_t out_size =3D iov_size(iov, out_num); + size_t out_buf_size =3D ROUND_UP(out_size, 4096); + size_t in_size =3D iov_size(iov + out_num, in_num); + size_t in_buf_size =3D ROUND_UP(in_size, 4096); + SVQElement *svq_elem; + uint16_t num_slots =3D (in_num ? 1 : 0) + (out_num ? 1 : 0); + + if (unlikely(num_slots =3D=3D 0 || svq->next_guest_avail_elem || + vhost_svq_available_slots(svq) < num_slots)) { + return false; + } + + svq_elem =3D virtqueue_alloc_element(sizeof(SVQElement), 1, 1); + if (out_num) { + void *out =3D qemu_memalign(4096, out_buf_size); + svq_elem->elem.out_sg[0].iov_base =3D out; + svq_elem->elem.out_sg[0].iov_len =3D out_size; + iov_to_buf(iov, out_num, 0, out, out_size); + memset(out + out_size, 0, out_buf_size - out_size); + } + if (in_num) { + void *in =3D qemu_memalign(4096, in_buf_size); + svq_elem->elem.in_sg[0].iov_base =3D in; + svq_elem->elem.in_sg[0].iov_len =3D in_size; + memset(in, 0, in_buf_size); + } + + svq_elem->not_from_guest =3D true; + vhost_svq_add(svq, svq_elem); + vhost_svq_kick(svq); + + return true; +} + /** * Forward available buffers. * @@ -266,6 +338,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueu= e *svq) break; } =20 + svq_elem->not_from_guest =3D false; elem =3D &svq_elem->elem; if (elem->out_num + elem->in_num > vhost_svq_available_slots(s= vq)) { /* @@ -391,6 +464,31 @@ static SVQElement *vhost_svq_get_buf(VhostShadowVirtqu= eue *svq, uint32_t *len) return g_steal_pointer(&svq->ring_id_maps[used_elem.id]); } =20 +static int vhost_svq_unmap(VhostShadowVirtqueue *svq, hwaddr iova, size_t = size) +{ + DMAMap needle =3D { + .iova =3D iova, + .size =3D size, + }; + const DMAMap *overlap; + + while ((overlap =3D vhost_iova_tree_find(svq->iova_tree, &needle))) { + DMAMap needle =3D *overlap; + + if (svq->map_ops->unmap) { + int r =3D svq->map_ops->unmap(overlap->iova, overlap->size + 1, + svq->map_ops_opaque); + if (unlikely(r !=3D 0)) { + return r; + } + } + qemu_vfree((void *)overlap->translated_addr); + vhost_iova_tree_remove(svq->iova_tree, &needle); + } + + return 0; +} + static void vhost_svq_flush(VhostShadowVirtqueue *svq, bool check_for_avail_queue) { @@ -410,23 +508,56 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, } =20 elem =3D &svq_elem->elem; - if (unlikely(i >=3D svq->vring.num)) { - qemu_log_mask(LOG_GUEST_ERROR, - "More than %u used buffers obtained in a %u size = SVQ", - i, svq->vring.num); - virtqueue_fill(vq, elem, len, i); - virtqueue_flush(vq, i); - return; - } - virtqueue_fill(vq, elem, len, i++); - if (svq->ops && svq->ops->used_elem_handler) { svq->ops->used_elem_handler(svq->vdev, elem); } + + if (svq_elem->not_from_guest) { + if (unlikely(!elem->out_num && elem->out_num !=3D 1)) { + error_report("Unexpected out_num > 1"); + return; + } + + if (elem->out_num) { + int r =3D vhost_svq_unmap(svq, svq_elem->out_iova, + elem->out_sg[0].iov_len); + if (unlikely(r !=3D 0)) { + error_report("Cannot unmap out buffer"); + return; + } + } + + if (unlikely(!elem->in_num && elem->in_num !=3D 1)) { + error_report("Unexpected in_num > 1"); + return; + } + + if (elem->in_num) { + int r =3D vhost_svq_unmap(svq, svq_elem->in_iova, + elem->in_sg[0].iov_len); + if (unlikely(r !=3D 0)) { + error_report("Cannot unmap out buffer"); + return; + } + } + } else { + if (unlikely(i >=3D svq->vring.num)) { + qemu_log_mask( + LOG_GUEST_ERROR, + "More than %u used buffers obtained in a %u size S= VQ", + i, svq->vring.num); + virtqueue_fill(vq, elem, len, i); + virtqueue_flush(vq, i); + return; + } + virtqueue_fill(vq, elem, len, i++); + } } =20 - virtqueue_flush(vq, i); - event_notifier_set(&svq->svq_call); + if (i > 0) { + virtqueue_flush(vq, i); + event_notifier_set(&svq->svq_call); + } =20 if (check_for_avail_queue && svq->next_guest_avail_elem) { /* @@ -589,13 +720,13 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) for (unsigned i =3D 0; i < svq->vring.num; ++i) { g_autofree SVQElement *svq_elem =3D NULL; svq_elem =3D g_steal_pointer(&svq->ring_id_maps[i]); - if (svq_elem) { + if (svq_elem && !svq_elem->not_from_guest) { virtqueue_detach_element(svq->vq, &svq_elem->elem, 0); } } =20 next_avail_elem =3D g_steal_pointer(&svq->next_guest_avail_elem); - if (next_avail_elem) { + if (next_avail_elem && !next_avail_elem->not_from_guest) { virtqueue_detach_element(svq->vq, &next_avail_elem->elem, 0); } svq->vq =3D NULL; --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425809945545.9412871615602; Fri, 8 Apr 2022 06:50:09 -0700 (PDT) Received: from localhost ([::1]:42912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncp04-0006e2-MI for importer@patchew.org; Fri, 08 Apr 2022 09:50:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncomD-0003aJ-Dl for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52336) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncolm-0003uH-DV for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:23 -0400 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-202-G4MpPNemNaakxm2E3sBV4w-1; Fri, 08 Apr 2022 09:35:18 -0400 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 5994518AE941; Fri, 8 Apr 2022 13:35:18 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DACA145B97F; Fri, 8 Apr 2022 13:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424921; 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=uUR6TjwCWYCo3LuSdLeQzS9X+JAPaHgWLCnfsrZtvRs=; b=BIuXTxhhEPr64inPaQNyCmhsUYdOEtz3F5vVPPYUb4tmYD/5re3A5i4BGUHnQRPWFrbhvc D/vi/GNOebaPwvvZfX9LvzVx9Upa3cHeqHv95kyYqaSUKjFnLe8TeJoCU3vGlfDolZZ5Bo E32ENnkq5bWiFKD6fwaORVrboxUaQrA= X-MC-Unique: G4MpPNemNaakxm2E3sBV4w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 18/23] vdpa: add NetClientState->start() callback Date: Fri, 8 Apr 2022 15:34:10 +0200 Message-Id: <20220408133415.1371760-19-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425810803100001 It allows to inject custom code on device success start, right before release lock. Signed-off-by: Eugenio P=C3=A9rez --- include/net/net.h | 2 ++ hw/net/vhost_net.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 523136c7ac..2fc3002ab4 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -44,6 +44,7 @@ typedef struct NICConf { =20 typedef void (NetPoll)(NetClientState *, bool enable); typedef bool (NetCanReceive)(NetClientState *); +typedef void (NetStart)(NetClientState *); typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, in= t); typedef void (NetCleanup) (NetClientState *); @@ -71,6 +72,7 @@ typedef struct NetClientInfo { NetReceive *receive_raw; NetReceiveIOV *receive_iov; NetCanReceive *can_receive; + NetStart *start; NetCleanup *cleanup; LinkStatusChanged *link_status_changed; QueryRxFilter *query_rx_filter; diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 30379d2ca4..44a105ec29 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -274,6 +274,10 @@ static int vhost_net_start_one(struct vhost_net *net, } } } + + if (net->nc->info->start) { + net->nc->info->start(net->nc); + } return 0; fail: file.fd =3D -1; --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425982088278.66487705523593; Fri, 8 Apr 2022 06:53:02 -0700 (PDT) Received: from localhost ([::1]:51450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncp2r-00041u-1Y for importer@patchew.org; Fri, 08 Apr 2022 09:53:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60638) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncomG-0003bd-2O for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:27804) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncoly-0003xY-Qb for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:50 -0400 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-375-73yhLVxBN_CBWxSK2BmSBg-1; Fri, 08 Apr 2022 09:35:22 -0400 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 81B05381D8A9; Fri, 8 Apr 2022 13:35:21 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0F941410F3B; Fri, 8 Apr 2022 13:35:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424926; 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=yfN2adIZit7o76ipLAOd0d/MR2JWCbn5Tn/hHrRcIZ8=; b=C2hUrLy3/9OhEDNoNGvDM4umi1QTSBDp5qixy3YCDU4hUIxUCulVN4mzUC3RvoNaNXhu5V d+1AP7h2vXTsKNxZNhlI17FpsL9IXrFRrwMXAQhWMLliagsQf2ybEAApn65Xfesn3/DrDE 36Nc+3N6jqik60znVOGhpQ8NKJ4LWNM= X-MC-Unique: 73yhLVxBN_CBWxSK2BmSBg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 19/23] vdpa: Add vhost_vdpa_start_control_svq Date: Fri, 8 Apr 2022 15:34:11 +0200 Message-Id: <20220408133415.1371760-20-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425983639100003 This will send CVQ commands in the destination machine, seting up everything o there is no guest-visible change. Signed-off-by: Eugenio P=C3=A9rez --- net/vhost-vdpa.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index a83da4616c..09fcc4a88e 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -206,10 +206,73 @@ static ssize_t vhost_vdpa_receive(NetClientState *nc,= const uint8_t *buf, return 0; } =20 +static bool vhost_vdpa_start_control_svq(VhostShadowVirtqueue *svq, + VirtIODevice *vdev) +{ + VirtIONet *n =3D VIRTIO_NET(vdev); + uint64_t features =3D vdev->host_features; + + if (features & BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR)) { + const struct virtio_net_ctrl_hdr ctrl =3D { + .class =3D VIRTIO_NET_CTRL_MAC, + .cmd =3D VIRTIO_NET_CTRL_MAC_ADDR_SET, + }; + uint8_t mac[6]; + const struct iovec data[] =3D { + { + .iov_base =3D (void *)&ctrl, + .iov_len =3D sizeof(ctrl), + },{ + .iov_base =3D mac, + .iov_len =3D sizeof(mac), + },{ + .iov_base =3D NULL, + .iov_len =3D sizeof(virtio_net_ctrl_ack), + } + }; + bool ret; + + /* TODO: Only best effort? */ + memcpy(mac, n->mac, sizeof(mac)); + ret =3D vhost_svq_inject(svq, data, 2, 1); + if (!ret) { + return false; + } + } + + return true; +} + +static void vhost_vdpa_start(NetClientState *nc) +{ + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); + VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + struct vhost_vdpa *v =3D &s->vhost_vdpa; + struct vhost_dev *dev =3D &s->vhost_net->dev; + VhostShadowVirtqueue *svq; + + if (nc->is_datapath) { + /* This is not the cvq dev */ + return; + } + + if (dev->vq_index + dev->nvqs !=3D dev->vq_index_end) { + return; + } + + if (!v->shadow_vqs_enabled) { + return; + } + + svq =3D g_ptr_array_index(v->shadow_vqs, 0); + vhost_vdpa_start_control_svq(svq, dev->vdev); +} + static NetClientInfo net_vhost_vdpa_info =3D { .type =3D NET_CLIENT_DRIVER_VHOST_VDPA, .size =3D sizeof(VhostVDPAState), .receive =3D vhost_vdpa_receive, + .start =3D vhost_vdpa_start, .cleanup =3D vhost_vdpa_cleanup, .has_vnet_hdr =3D vhost_vdpa_has_vnet_hdr, .has_ufo =3D vhost_vdpa_has_ufo, --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649425981851686.4658669705508; Fri, 8 Apr 2022 06:53:01 -0700 (PDT) Received: from localhost ([::1]:51254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncp2p-0003uM-Rc for importer@patchew.org; Fri, 08 Apr 2022 09:52:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncomG-0003be-3N for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41671) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncom7-0003y0-64 for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:51 -0400 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-444-kyoA1f5SNlCDuMqI6Z2tLQ-1; Fri, 08 Apr 2022 09:35:25 -0400 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 DE81F381D8B2; Fri, 8 Apr 2022 13:35:24 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA314145B97F; Fri, 8 Apr 2022 13:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424926; 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=at74jLvfPBplnvuRaQUgguMyDaRAte8OVbgQmgvjYoc=; b=ezAzAtiCT2DFKYAt9clbYB3pU79YHqwvI58zL7xUSXzSa/yb0xUpffByAwEtwY5BqF3Ze6 Hr5kPjIfkQGef8bLiuINpgwWFPn+Y9p73xKJjnjwPD23LIjA4V+JgWYomQi8st+dmf8SR5 OzLw/f0gdZgZanpkTav6p0ZSDqBNenI= X-MC-Unique: kyoA1f5SNlCDuMqI6Z2tLQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 20/23] vhost: Update kernel headers Date: Fri, 8 Apr 2022 15:34:12 +0200 Message-Id: <20220408133415.1371760-21-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649425983640100004 Signed-off-by: Eugenio P=C3=A9rez --- include/standard-headers/linux/vhost_types.h | 11 ++++++++- linux-headers/linux/vhost.h | 25 ++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/standard-headers/linux/vhost_types.h b/include/standar= d-headers/linux/vhost_types.h index 0bd2684a2a..ce78551b0f 100644 --- a/include/standard-headers/linux/vhost_types.h +++ b/include/standard-headers/linux/vhost_types.h @@ -87,7 +87,7 @@ struct vhost_msg { =20 struct vhost_msg_v2 { uint32_t type; - uint32_t reserved; + uint32_t asid; union { struct vhost_iotlb_msg iotlb; uint8_t padding[64]; @@ -153,4 +153,13 @@ struct vhost_vdpa_iova_range { /* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */ #define VHOST_NET_F_VIRTIO_NET_HDR 27 =20 +/* Use message type V2 */ +#define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1 +/* IOTLB can accept batching hints */ +#define VHOST_BACKEND_F_IOTLB_BATCH 0x2 +/* IOTLB can accept address space identifier through V2 type of IOTLB + * message + */ +#define VHOST_BACKEND_F_IOTLB_ASID 0x3 + #endif diff --git a/linux-headers/linux/vhost.h b/linux-headers/linux/vhost.h index c998860d7b..5e083490f1 100644 --- a/linux-headers/linux/vhost.h +++ b/linux-headers/linux/vhost.h @@ -89,11 +89,6 @@ =20 /* Set or get vhost backend capability */ =20 -/* Use message type V2 */ -#define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1 -/* IOTLB can accept batching hints */ -#define VHOST_BACKEND_F_IOTLB_BATCH 0x2 - #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64) #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64) =20 @@ -150,4 +145,24 @@ /* Get the valid iova range */ #define VHOST_VDPA_GET_IOVA_RANGE _IOR(VHOST_VIRTIO, 0x78, \ struct vhost_vdpa_iova_range) +/* Get the number of virtqueue groups. */ +#define VHOST_VDPA_GET_GROUP_NUM _IOR(VHOST_VIRTIO, 0x79, unsigned int) + +/* Get the number of address spaces. */ +#define VHOST_VDPA_GET_AS_NUM _IOR(VHOST_VIRTIO, 0x7A, unsigned int) + +/* Get the group for a virtqueue: read index, write group in num, + * The virtqueue index is stored in the index field of + * vhost_vring_state. The group for this specific virtqueue is + * returned via num field of vhost_vring_state. + */ +#define VHOST_VDPA_GET_VRING_GROUP _IOWR(VHOST_VIRTIO, 0x7B, \ + struct vhost_vring_state) +/* Set the ASID for a virtqueue group. The group index is stored in + * the index field of vhost_vring_state, the ASID associated with this + * group is stored at num field of vhost_vring_state. + */ +#define VHOST_VDPA_SET_GROUP_ASID _IOW(VHOST_VIRTIO, 0x7C, \ + struct vhost_vring_state) + #endif --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649426079297281.5956218097525; Fri, 8 Apr 2022 06:54:39 -0700 (PDT) Received: from localhost ([::1]:55664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncp4Q-0006q9-AB for importer@patchew.org; Fri, 08 Apr 2022 09:54:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60666) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncomG-0003bg-E6 for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40336) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncomD-0003z5-9Z for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:52 -0400 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-412-Wn3auCeCPpW7qTj8SlGHmg-1; Fri, 08 Apr 2022 09:35:28 -0400 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 5B9B63C33B23; Fri, 8 Apr 2022 13:35:28 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4994B1402642; Fri, 8 Apr 2022 13:35:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424932; 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=TSNmlTlHwOXjPRivKwmySsoLJZ6FYEIksDk0qAJFNLI=; b=aEg67u5BERid8MeKo3e3eqSM8yvIrQ2KvQLtlH9vshP9F4g88htRiRaBNHFe7qaSCzS0D2 +QragkVfLa5xnqWE+06cJ0zmM/wYgCm5nGc3Yu/vicuXW2HKhrXl2jZxUd7vAtgKyA7H6j OIP97TUlng/B8QY7dr4K5kXidGpx29g= X-MC-Unique: Wn3auCeCPpW7qTj8SlGHmg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 21/23] vhost: Make possible to check for device exclusive vq group Date: Fri, 8 Apr 2022 15:34:13 +0200 Message-Id: <20220408133415.1371760-22-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649426080186100001 CVQ needs to be in its own group, not shared with any data vq. Enable the checking of it here, before introducing address space id concepts. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/vhost.h | 2 + hw/net/vhost_net.c | 4 +- hw/virtio/vhost-vdpa.c | 79 ++++++++++++++++++++++++++++++++++++++- hw/virtio/trace-events | 1 + 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 58a73e7b7a..034868fa9e 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -78,6 +78,8 @@ struct vhost_dev { int vq_index_end; /* if non-zero, minimum required value for max_queues */ int num_queues; + /* Must be a vq group different than any other vhost dev */ + bool independent_vq_group; uint64_t features; uint64_t acked_features; uint64_t backend_features; diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 44a105ec29..10480e19e5 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -343,14 +343,16 @@ int vhost_net_start(VirtIODevice *dev, NetClientState= *ncs, } =20 for (i =3D 0; i < nvhosts; i++) { + bool cvq_idx =3D i >=3D data_queue_pairs; =20 - if (i < data_queue_pairs) { + if (!cvq_idx) { peer =3D qemu_get_peer(ncs, i); } else { /* Control Virtqueue */ peer =3D qemu_get_peer(ncs, n->max_queue_pairs); } =20 net =3D get_vhost_net(peer); + net->dev.independent_vq_group =3D !!cvq_idx; vhost_net_set_vq_index(net, i * 2, index_end); =20 /* Suppress the masking guest notifiers on vhost user diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index d09e06d212..dfff94d46f 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -677,7 +677,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)) { @@ -1097,6 +1098,78 @@ static bool vhost_vdpa_svqs_stop(struct vhost_dev *d= ev) return true; } =20 +static int vhost_vdpa_get_vring_group(struct vhost_dev *dev, + struct vhost_vring_state *state) +{ + int ret =3D vhost_vdpa_call(dev, VHOST_VDPA_GET_VRING_GROUP, state); + trace_vhost_vdpa_get_vring_group(dev, state->index, state->num); + return ret; +} + +static bool vhost_dev_is_independent_group(struct vhost_dev *dev) +{ + struct vhost_vdpa *v =3D dev->opaque; + struct vhost_vring_state this_vq_group =3D { + .index =3D dev->vq_index, + }; + int ret; + + if (!(dev->backend_cap & VHOST_BACKEND_F_IOTLB_ASID)) { + return true; + } + + if (!v->shadow_vqs_enabled) { + return true; + } + + ret =3D vhost_vdpa_get_vring_group(dev, &this_vq_group); + if (unlikely(ret)) { + goto call_err; + } + + for (int i =3D 1; i < dev->nvqs; ++i) { + struct vhost_vring_state vq_group =3D { + .index =3D dev->vq_index + i, + }; + + ret =3D vhost_vdpa_get_vring_group(dev, &vq_group); + if (unlikely(ret)) { + goto call_err; + } + if (unlikely(vq_group.num !=3D this_vq_group.num)) { + error_report("VQ %d group is different than VQ %d one", + this_vq_group.index, vq_group.index); + return false; + } + } + + for (int i =3D 0; i < dev->vq_index_end; ++i) { + struct vhost_vring_state vq_group =3D { + .index =3D i, + }; + + if (dev->vq_index <=3D i && i < dev->vq_index + dev->nvqs) { + continue; + } + + ret =3D vhost_vdpa_get_vring_group(dev, &vq_group); + if (unlikely(ret)) { + goto call_err; + } + if (unlikely(vq_group.num =3D=3D this_vq_group.num)) { + error_report("VQ %d group is the same as VQ %d one", + this_vq_group.index, vq_group.index); + return false; + } + } + + return true; + +call_err: + error_report("Can't read vq group, errno=3D%d (%s)", ret, g_strerror(-= ret)); + return false; +} + static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) { struct vhost_vdpa *v =3D dev->opaque; @@ -1105,6 +1178,10 @@ static int vhost_vdpa_dev_start(struct vhost_dev *de= v, bool started) =20 if (started) { vhost_vdpa_host_notifiers_init(dev); + if (dev->independent_vq_group && + !vhost_dev_is_independent_group(dev)) { + return -1; + } ok =3D vhost_vdpa_svqs_start(dev); if (unlikely(!ok)) { return -1; diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 333348d9d5..e6fdc03514 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -43,6 +43,7 @@ vhost_vdpa_set_vring_ready(void *dev) "dev: %p" vhost_vdpa_dump_config(void *dev, const char *line) "dev: %p %s" vhost_vdpa_set_config(void *dev, uint32_t offset, uint32_t size, uint32_t = flags) "dev: %p offset: %"PRIu32" size: %"PRIu32" flags: 0x%"PRIx32 vhost_vdpa_get_config(void *dev, void *config, uint32_t config_len) "dev: = %p config: %p config_len: %"PRIu32 +vhost_vdpa_get_vring_group(void *dev, unsigned int index, unsigned int num= ) "dev: %p index: %u num: %u" vhost_vdpa_dev_start(void *dev, bool started) "dev: %p started: %d" vhost_vdpa_set_log_base(void *dev, uint64_t base, unsigned long long size,= int refcnt, int fd, void *log) "dev: %p base: 0x%"PRIx64" size: %llu refcn= t: %d fd: %d log: %p" vhost_vdpa_set_vring_addr(void *dev, unsigned int index, unsigned int flag= s, uint64_t desc_user_addr, uint64_t used_user_addr, uint64_t avail_user_ad= dr, uint64_t log_guest_addr) "dev: %p index: %u flags: 0x%x desc_user_addr:= 0x%"PRIx64" used_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" log_g= uest_addr: 0x%"PRIx64 --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649426195426186.0185124475189; Fri, 8 Apr 2022 06:56:35 -0700 (PDT) Received: from localhost ([::1]:60190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncp6H-0001Td-Sx for importer@patchew.org; Fri, 08 Apr 2022 09:56:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncomG-0003bj-No for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:30256) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncomD-0003zG-9K for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:52 -0400 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-665-RgiK3JFrPO2oUpgo-TovfQ-1; Fri, 08 Apr 2022 09:35:32 -0400 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 777691C12DE1; Fri, 8 Apr 2022 13:35:31 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id A74731402642; Fri, 8 Apr 2022 13:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424935; 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=wbglap7skzvtvKKEdfvl/EVgf/YdR4E36WaLogczy+4=; b=W6VFtdI7aFbmfiPnc9IXgIuUNcskPCclDj1C+K7F1yz19F8ZjmGe3cFS0jjRi3faPvP0QN cy+0IHJBW6anCvPR3AjriYrvynrcN/4+uoQkxq5sLsAX6iwfIIYY3NxhBvnAT+rPaD+rzp WG9ulgsSXYzQLtTYko3wdlzMHo1RqAo= X-MC-Unique: RgiK3JFrPO2oUpgo-TovfQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 22/23] vdpa: Add asid attribute to vdpa device Date: Fri, 8 Apr 2022 15:34:14 +0200 Message-Id: <20220408133415.1371760-23-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649426197960100001 We can configure ASID per group, but we still use asid 0 for every vdpa device. Multiple asid support for cvq will be introduced in next patches Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/vhost-vdpa.h | 2 + include/hw/virtio/vhost.h | 2 + hw/net/vhost_net.c | 1 + hw/virtio/vhost-vdpa.c | 97 ++++++++++++++++++++++++++++------ net/vhost-vdpa.c | 15 +++--- hw/virtio/trace-events | 9 ++-- 6 files changed, 99 insertions(+), 27 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index f1ba46a860..aa572d1acc 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -32,6 +32,8 @@ typedef struct vhost_vdpa { MemoryListener listener; struct vhost_vdpa_iova_range iova_range; uint64_t acked_features; + /* one past the last vq index of this virtqueue group */ + int vq_group_index_end; bool shadow_vqs_enabled; /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 034868fa9e..2a6819dc2e 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -78,6 +78,8 @@ struct vhost_dev { int vq_index_end; /* if non-zero, minimum required value for max_queues */ int num_queues; + /* address space id */ + uint32_t address_space_id; /* Must be a vq group different than any other vhost dev */ bool independent_vq_group; uint64_t features; diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 10480e19e5..e8a99c8605 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -352,6 +352,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *= ncs, } =20 net =3D get_vhost_net(peer); + net->dev.address_space_id =3D !!cvq_idx; net->dev.independent_vq_group =3D !!cvq_idx; vhost_net_set_vq_index(net, i * 2, index_end); =20 diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index dfff94d46f..1b4e03c658 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -79,14 +79,18 @@ static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwa= ddr iova, hwaddr size, int ret =3D 0; =20 msg.type =3D v->msg_type; + if (v->dev->backend_cap & BIT_ULL(VHOST_BACKEND_F_IOTLB_ASID)) { + msg.asid =3D v->dev->address_space_id; + } 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)", @@ -104,12 +108,15 @@ static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v,= hwaddr iova, int fd =3D v->device_fd; int ret =3D 0; =20 + if (v->dev->backend_cap & BIT_ULL(VHOST_BACKEND_F_IOTLB_ASID)) { + msg.asid =3D v->dev->address_space_id; + } msg.type =3D v->msg_type; 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)) { @@ -129,7 +136,12 @@ static void vhost_vdpa_listener_begin_batch(struct vho= st_vdpa *v) .iotlb.type =3D VHOST_IOTLB_BATCH_BEGIN, }; =20 - trace_vhost_vdpa_listener_begin_batch(v, fd, msg.type, msg.iotlb.type); + if (v->dev->backend_cap & BIT_ULL(VHOST_BACKEND_F_IOTLB_ASID)) { + msg.asid =3D v->dev->address_space_id; + } + + trace_vhost_vdpa_listener_begin_batch(v, fd, msg.type, msg.asid, + msg.iotlb.type); if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { error_report("failed to write, fd=3D%d, errno=3D%d (%s)", fd, errno, strerror(errno)); @@ -162,9 +174,13 @@ static void vhost_vdpa_listener_commit(MemoryListener = *listener) } =20 msg.type =3D v->msg_type; + if (dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_ASID)) { + msg.asid =3D v->dev->address_space_id; + } msg.iotlb.type =3D VHOST_IOTLB_BATCH_END; =20 - trace_vhost_vdpa_listener_commit(v, fd, msg.type, msg.iotlb.type); + trace_vhost_vdpa_listener_commit(v, fd, msg.type, msg.asid, + msg.iotlb.type); if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { error_report("failed to write, fd=3D%d, errno=3D%d (%s)", fd, errno, strerror(errno)); @@ -1170,10 +1186,48 @@ call_err: return false; } =20 +static int vhost_vdpa_set_vq_group_address_space_id(struct vhost_dev *dev, + struct vhost_vring_state *= asid) +{ + trace_vhost_vdpa_set_vq_group_address_space_id(dev, asid->index, asid-= >num); + return vhost_vdpa_call(dev, VHOST_VDPA_SET_GROUP_ASID, asid); +} + +static int vhost_vdpa_set_address_space_id(struct vhost_dev *dev) +{ + struct vhost_vring_state vq_group =3D { + .index =3D dev->vq_index, + }; + struct vhost_vring_state asid; + int ret; + + if (!dev->address_space_id) { + return 0; + } + + ret =3D vhost_vdpa_get_vring_group(dev, &vq_group); + if (unlikely(ret)) { + error_report("Can't read vq group, errno=3D%d (%s)", ret, + g_strerror(-ret)); + return ret; + } + + asid.index =3D vq_group.num; + asid.num =3D dev->address_space_id; + ret =3D vhost_vdpa_set_vq_group_address_space_id(dev, &asid); + if (unlikely(ret)) { + error_report("Can't set vq group %u asid %u, errno=3D%d (%s)", + asid.index, asid.num, ret, g_strerror(-ret)); + } + return ret; +} + static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) { struct vhost_vdpa *v =3D dev->opaque; - bool ok; + bool vq_group_end, ok; + int r =3D 0; + trace_vhost_vdpa_dev_start(dev, started); =20 if (started) { @@ -1182,6 +1236,10 @@ static int vhost_vdpa_dev_start(struct vhost_dev *de= v, bool started) !vhost_dev_is_independent_group(dev)) { return -1; } + r =3D vhost_vdpa_set_address_space_id(dev); + if (unlikely(r)) { + return r; + } ok =3D vhost_vdpa_svqs_start(dev); if (unlikely(!ok)) { return -1; @@ -1195,21 +1253,26 @@ static int vhost_vdpa_dev_start(struct vhost_dev *d= ev, bool started) vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); } =20 - if (dev->vq_index + dev->nvqs !=3D dev->vq_index_end) { - return 0; + vq_group_end =3D dev->vq_index + dev->nvqs =3D=3D v->vq_group_index_en= d; + if (vq_group_end && started) { + memory_listener_register(&v->listener, &address_space_memory); } =20 - if (started) { - memory_listener_register(&v->listener, &address_space_memory); - return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); - } else { - vhost_vdpa_reset_device(dev); - vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | - VIRTIO_CONFIG_S_DRIVER); - memory_listener_unregister(&v->listener); + if (dev->vq_index + dev->nvqs =3D=3D dev->vq_index_end) { + if (started) { + r =3D vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); + } else { + vhost_vdpa_reset_device(dev); + vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER); + } + } =20 - return 0; + if (vq_group_end && !started) { + memory_listener_unregister(&v->listener); } + + return r; } =20 static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 09fcc4a88e..6207ead884 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -152,9 +152,10 @@ err_init: static void vhost_vdpa_cleanup(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); - struct vhost_dev *dev =3D s->vhost_vdpa.dev; + struct vhost_vdpa *v =3D &s->vhost_vdpa; + struct vhost_dev *dev =3D v->dev; =20 - if (dev && dev->vq_index + dev->nvqs =3D=3D dev->vq_index_end) { + if (dev && dev->vq_index + dev->nvqs =3D=3D v->vq_group_index_end) { g_clear_pointer(&s->vhost_vdpa.iova_tree, vhost_iova_tree_delete); } if (s->vhost_net) { @@ -333,6 +334,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, int vdpa_device_fd, int queue_pair_index, int nvqs, + int vq_group_end, bool is_datapath, bool svq, VhostIOVATree *iova_tree) @@ -354,6 +356,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; s->vhost_vdpa.shadow_vqs_enabled =3D svq; + s->vhost_vdpa.vq_group_index_end =3D vq_group_end; if (!is_datapath) { s->vhost_vdpa.shadow_vq_ops =3D &vhost_vdpa_net_svq_ops; } @@ -464,16 +467,16 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, =20 for (i =3D 0; i < queue_pairs; i++) { ncs[i] =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 2, true, opts->x_s= vq, - iova_tree); + vdpa_device_fd, i, 2, 2 * queue_pairs, + true, opts->x_svq, iova_tree); if (!ncs[i]) goto err; } =20 if (has_cvq) { nc =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 1, false, opts->x_svq, - iova_tree); + vdpa_device_fd, i, 1, 2 * queue_pairs + 1, + false, opts->x_svq, iova_tree); if (!nc) goto err; } diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index e6fdc03514..2858deac60 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -23,10 +23,10 @@ vhost_user_postcopy_waker_found(uint64_t client_addr) "= 0x%"PRIx64 vhost_user_postcopy_waker_nomatch(const char *rb, uint64_t rb_offset) "%s = + 0x%"PRIx64 =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_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_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, uint32= _t asid, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32"= type: %"PRIu8 +vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint32_t as= id, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"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" vhost_vdpa_listener_region_del(void *vdpa, uint64_t iova, uint64_t llend) = "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64 vhost_vdpa_add_status(void *dev, uint8_t status) "dev: %p status: 0x%"PRIx8 @@ -44,6 +44,7 @@ vhost_vdpa_dump_config(void *dev, const char *line) "dev:= %p %s" vhost_vdpa_set_config(void *dev, uint32_t offset, uint32_t size, uint32_t = flags) "dev: %p offset: %"PRIu32" size: %"PRIu32" flags: 0x%"PRIx32 vhost_vdpa_get_config(void *dev, void *config, uint32_t config_len) "dev: = %p config: %p config_len: %"PRIu32 vhost_vdpa_get_vring_group(void *dev, unsigned int index, unsigned int num= ) "dev: %p index: %u num: %u" +vhost_vdpa_set_vq_group_address_space_id(void *dev, unsigned int index, un= signed int num) "dev: %p index: %u num: %u" vhost_vdpa_dev_start(void *dev, bool started) "dev: %p started: %d" vhost_vdpa_set_log_base(void *dev, uint64_t base, unsigned long long size,= int refcnt, int fd, void *log) "dev: %p base: 0x%"PRIx64" size: %llu refcn= t: %d fd: %d log: %p" vhost_vdpa_set_vring_addr(void *dev, unsigned int index, unsigned int flag= s, uint64_t desc_user_addr, uint64_t used_user_addr, uint64_t avail_user_ad= dr, uint64_t log_guest_addr) "dev: %p index: %u flags: 0x%x desc_user_addr:= 0x%"PRIx64" used_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" log_g= uest_addr: 0x%"PRIx64 --=20 2.27.0 From nobody Sat Feb 7 07:30:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649426618705430.9435307864402; Fri, 8 Apr 2022 07:03:38 -0700 (PDT) Received: from localhost ([::1]:45830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncpD7-0002fR-4w for importer@patchew.org; Fri, 08 Apr 2022 10:03:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncomG-0003bf-5Y for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:23712) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncomD-0003zd-64 for qemu-devel@nongnu.org; Fri, 08 Apr 2022 09:35:51 -0400 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-643-90pKGxu_O5GThSpHGnXz2w-1; Fri, 08 Apr 2022 09:35:35 -0400 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 C7428811E75; Fri, 8 Apr 2022 13:35:34 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC502145B97F; Fri, 8 Apr 2022 13:35:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649424941; 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=cH9E/dTXKUuGHNHy1ApLn5GkFyZXXwbKKhO7IpP6waU=; b=Cw1TjIC1brAhda0A1Ii/071eSB9uhHeLYgB/L11rYWDPIuz0oqhW2khY4XBVpkfjowGvye PR74ErQF4/h8/PJxc+cdKQ4M9pKnu+VEtkhMOWr0ZIlVnOnQ7y502TtdFMKnEJ4thnY8BN kpwSdeToKyVBVGQaLzpsoDUtJFe8QFs= X-MC-Unique: 90pKGxu_O5GThSpHGnXz2w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v5 23/23] vdpa: Add x-cvq-svq Date: Fri, 8 Apr 2022 15:34:15 +0200 Message-Id: <20220408133415.1371760-24-eperezma@redhat.com> In-Reply-To: <20220408133415.1371760-1-eperezma@redhat.com> References: <20220408133415.1371760-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , "Gonglei \(Arei\)" , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1649426621052100001 This isolates shadow cvq in its own group. Signed-off-by: Eugenio P=C3=A9rez --- qapi/net.json | 8 +++- net/vhost-vdpa.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 100 insertions(+), 6 deletions(-) diff --git a/qapi/net.json b/qapi/net.json index 92848e4362..39c245e6cd 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -447,9 +447,12 @@ # # @x-svq: Start device with (experimental) shadow virtqueue. (Since 7.1) # (default: false) +# @x-cvq-svq: Start device with (experimental) shadow virtqueue in its own +# virtqueue group. (Since 7.1) +# (default: false) # # Features: -# @unstable: Member @x-svq is experimental. +# @unstable: Members @x-svq and x-cvq-svq are experimental. # # Since: 5.1 ## @@ -457,7 +460,8 @@ 'data': { '*vhostdev': 'str', '*queues': 'int', - '*x-svq': {'type': 'bool', 'features' : [ 'unstable'] } } } + '*x-svq': {'type': 'bool', 'features' : [ 'unstable'] }, + '*x-cvq-svq': {'type': 'bool', 'features' : [ 'unstable'] } } } =20 ## # @NetClientDriver: diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 6207ead884..e907ef1618 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -379,6 +379,17 @@ static int vhost_vdpa_get_features(int fd, uint64_t *f= eatures, Error **errp) return ret; } =20 +static int vhost_vdpa_get_backend_features(int fd, uint64_t *features, + Error **errp) +{ + int ret =3D ioctl(fd, VHOST_GET_BACKEND_FEATURES, features); + if (ret) { + error_setg_errno(errp, errno, + "Fail to query backend features from vhost-vDPA device"); + } + return ret; +} + static int vhost_vdpa_get_max_queue_pairs(int fd, uint64_t features, int *has_cvq, Error **errp) { @@ -412,16 +423,56 @@ static int vhost_vdpa_get_max_queue_pairs(int fd, uin= t64_t features, return 1; } =20 +/** + * Check vdpa device to support CVQ group asid 1 + * + * @vdpa_device_fd: Vdpa device fd + * @queue_pairs: Queue pairs + * @errp: Error + */ +static int vhost_vdpa_check_cvq_svq(int vdpa_device_fd, int queue_pairs, + Error **errp) +{ + uint64_t backend_features; + unsigned num_as; + int r; + + r =3D vhost_vdpa_get_backend_features(vdpa_device_fd, &backend_feature= s, + errp); + if (unlikely(r)) { + return -1; + } + + if (unlikely(!(backend_features & VHOST_BACKEND_F_IOTLB_ASID))) { + error_setg(errp, "Device without IOTLB_ASID feature"); + return -1; + } + + r =3D ioctl(vdpa_device_fd, VHOST_VDPA_GET_AS_NUM, &num_as); + if (unlikely(r)) { + error_setg_errno(errp, errno, + "Cannot retrieve number of supported ASs"); + return -1; + } + if (unlikely(num_as < 2)) { + error_setg(errp, "Insufficient number of ASs (%u, min: 2)", num_as= ); + } + + return 0; +} + int net_init_vhost_vdpa(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { const NetdevVhostVDPAOptions *opts; + struct vhost_vdpa_iova_range iova_range; uint64_t features; int vdpa_device_fd; g_autofree NetClientState **ncs =3D NULL; NetClientState *nc; int queue_pairs, r, i, has_cvq =3D 0; g_autoptr(VhostIOVATree) iova_tree =3D NULL; + ERRP_GUARD(); =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); opts =3D &netdev->u.vhost_vdpa; @@ -446,8 +497,9 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, qemu_close(vdpa_device_fd); return queue_pairs; } - if (opts->x_svq) { - struct vhost_vdpa_iova_range iova_range; + if (opts->x_cvq_svq || opts->x_svq) { + vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); + uint64_t invalid_dev_features =3D features & ~vdpa_svq_device_features & /* Transport are all accepted at this point */ @@ -459,7 +511,21 @@ int net_init_vhost_vdpa(const Netdev *netdev, const ch= ar *name, invalid_dev_features); goto err_svq; } - vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); + } + + if (opts->x_cvq_svq) { + if (!has_cvq) { + error_setg(errp, "Cannot use x-cvq-svq with a device without c= vq"); + goto err_svq; + } + + r =3D vhost_vdpa_check_cvq_svq(vdpa_device_fd, queue_pairs, errp); + if (unlikely(r)) { + error_prepend(errp, "Cannot configure CVQ SVQ: "); + goto err_svq; + } + } + if (opts->x_svq) { iova_tree =3D vhost_iova_tree_new(iova_range.first, iova_range.las= t); } =20 @@ -474,11 +540,35 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, } =20 if (has_cvq) { + g_autoptr(VhostIOVATree) cvq_iova_tree =3D NULL; + + if (opts->x_cvq_svq) { + cvq_iova_tree =3D vhost_iova_tree_new(iova_range.first, + iova_range.last); + } + nc =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd, i, 1, 2 * queue_pairs + 1, - false, opts->x_svq, iova_tree); + false, opts->x_cvq_svq || opts->x_svq, + opts->x_cvq_svq ? cvq_iova_tree : iova_tr= ee); if (!nc) goto err; + + if (opts->x_cvq_svq) { + struct vhost_vring_state asid =3D { + .index =3D 1, + .num =3D 1, + }; + + r =3D ioctl(vdpa_device_fd, VHOST_VDPA_SET_GROUP_ASID, &asid); + if (unlikely(r)) { + error_setg_errno(errp, errno, + "Cannot set cvq group independent asid"); + goto err; + } + } + + cvq_iova_tree =3D NULL; } =20 iova_tree =3D NULL; --=20 2.27.0