From patchwork Wed Mar 30 18:30:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611308 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UKCcTCvn; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTFcx3n64z9sFq for ; Thu, 31 Mar 2022 05:41:05 +1100 (AEDT) Received: from localhost ([::1]:51318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdFf-00012c-Gd for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 14:41:03 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49356) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6R-00062p-I8 for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30736) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6P-0006VY-TY for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665088; 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=UKCcTCvnNd7sWn0yM8cm1qprBDA9oQEo8cMle0gLXxqv/jugOv48dmWOILuSzxyVH9LhpH 4akK8Ce0SUmc5hl/pJmF1qu7Z11yfUAi2YN2GU6afENICZDMU479Ldgu2XQGppqt04fHyo oAdYozOOGbEQNlt+p7BbtA1mcmUse8U= 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-672-gnPYKkJSNDqPzP3ZoH8XGw-1; Wed, 30 Mar 2022 14:31:26 -0400 X-MC-Unique: gnPYKkJSNDqPzP3ZoH8XGw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 675B33802AD4; Wed, 30 Mar 2022 18:31:26 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B3BB57ECEF; Wed, 30 Mar 2022 18:31:23 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 01/19] util: Return void on iova_tree_remove Date: Wed, 30 Mar 2022 20:30:58 +0200 Message-Id: <20220330183116.358598-2-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It always returns IOVA_OK so nobody uses it. Signed-off-by: Eugenio Pérez --- 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); /** * 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_iterator iterator) g_tree_foreach(tree->tree, iova_tree_traverse, iterator); } -int iova_tree_remove(IOVATree *tree, const DMAMap *map) +void iova_tree_remove(IOVATree *tree, const DMAMap *map) { const DMAMap *overlap; while ((overlap = iova_tree_find(tree, map))) { g_tree_remove(tree->tree, overlap); } - - return IOVA_OK; } /** From patchwork Wed Mar 30 18:30:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611302 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ikRLCKNu; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTFRs5tBvz9sFq for ; Thu, 31 Mar 2022 05:33:13 +1100 (AEDT) Received: from localhost ([::1]:34386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZd83-00067q-SG for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 14:33:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49390) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6X-000668-0M for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30546) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6V-0006Vv-Dj for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665094; 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=vHBhJsAvU/DLc0t/VHHqN3DMv8GdSaRVtAL+alhF320=; b=ikRLCKNuSPBBlsNL+3WgsVlaRQlReZAySO5NCZCVvu3vCjQufrFrP4HX8+UhSFJh8fRs3v NqMlxAWZhnCk9BHIzfCdNeJOvlcTnTKG0qrRvNkJTR2+xqqfF7mTGGoXs4AbBUxVZ9vLYZ 277hK5YrZVQYcF+4MkatpIhpNlFrVC4= 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-652-pRx0A_vCOZiNZv3a35aBQw-1; Wed, 30 Mar 2022 14:31:31 -0400 X-MC-Unique: pRx0A_vCOZiNZv3a35aBQw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 134C8811E81; Wed, 30 Mar 2022 18:31:31 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0B0057ECED; Wed, 30 Mar 2022 18:31:26 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 02/19] vdpa: Add x-svq to NetdevVhostVDPAOptions Date: Wed, 30 Mar 2022 20:30:59 +0200 Message-Id: <20220330183116.358598-3-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Finally offering the possibility to enable SVQ from the command line. Signed-off-by: Eugenio Pérez --- 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 7fab2e7cd8..6a5460ce56 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'] } } } ## # @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 = DO_UPCAST(VhostVDPAState, nc, nc); + struct vhost_dev *dev = s->vhost_vdpa.dev; + if (dev && dev->vq_index + dev->nvqs == 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 = { .check_peer_type = vhost_vdpa_check_peer_type, }; +static int vhost_vdpa_get_iova_range(int fd, + struct vhost_vdpa_iova_range *iova_range) +{ + int ret = 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 = NULL; VhostVDPAState *s; @@ -211,6 +225,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.device_fd = vdpa_device_fd; s->vhost_vdpa.index = queue_pair_index; + s->vhost_vdpa.shadow_vqs_enabled = svq; + s->vhost_vdpa.iova_tree = iova_tree; ret = vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs); if (ret) { qemu_del_net_client(nc); @@ -266,6 +282,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, g_autofree NetClientState **ncs = NULL; NetClientState *nc; int queue_pairs, i, has_cvq = 0; + g_autoptr(VhostIOVATree) iova_tree = NULL; assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA); opts = &netdev->u.vhost_vdpa; @@ -285,29 +302,44 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *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 = vhost_iova_tree_new(iova_range.first, iova_range.last); + } ncs = g_malloc0(sizeof(*ncs) * queue_pairs); for (i = 0; i < queue_pairs; i++) { ncs[i] = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 2, true); + vdpa_device_fd, i, 2, true, opts->x_svq, + iova_tree); if (!ncs[i]) goto err; } if (has_cvq) { nc = 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; } + iova_tree = NULL; return 0; err: if (i) { qemu_del_net_client(ncs[0]); } + +err_svq: qemu_close(vdpa_device_fd); return -1; From patchwork Wed Mar 30 18:31:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611327 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GngRUsku; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTG5P6W4xz9sFt for ; Thu, 31 Mar 2022 06:02:17 +1100 (AEDT) Received: from localhost ([::1]:42554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdaB-0001NH-MU for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 15:02:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6b-00066k-3x for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:23385) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6Z-0006WJ-3Q for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665098; 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=zck6c8oTpToAbaL+eBIMP52brUzAbPTu3DbdpX7x8FU=; b=GngRUskuqWk+xThTRhi+gBe8atOefVIBOvu+tbSeN+2J6XOEHO0OiqzPHhd0bvzLJdDGUP 9xybdmf7hL4dNMwZhS+2SUQ2de4It2ztExGMWplXAVas3XuI3w6oKP3BOesmNfPZOvtSwy 4CNmRJjTA1Y75wWtMd/+x102EkqahlM= 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-111-swfhJ3iBOP-QfRmo-wQoqg-1; Wed, 30 Mar 2022 14:31:35 -0400 X-MC-Unique: swfhJ3iBOP-QfRmo-wQoqg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AAAA31C168EC; Wed, 30 Mar 2022 18:31:34 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EE9E57ECED; Wed, 30 Mar 2022 18:31:31 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 03/19] vhost: move descriptor translation to vhost_svq_vring_write_descs Date: Wed, 30 Mar 2022 20:31:00 +0200 Message-Id: <20220330183116.358598-4-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It's done for both in and out descriptors so it's better placed here. Signed-off-by: Eugenio Pérez --- 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-virtqueue.c index b232803d1b..349255525f 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 VhostShadowVirtqueue *svq, return true; } -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 = svq->free_head, last = svq->free_head; unsigned n; uint16_t flags = write ? cpu_to_le16(VRING_DESC_F_WRITE) : 0; vring_desc_t *descs = svq->vring.desc; + bool ok; if (num == 0) { - return; + return true; + } + + ok = vhost_svq_translate_addr(svq, sg, iovec, num); + if (unlikely(!ok)) { + return false; } for (n = 0; n < num; n++) { @@ -149,6 +155,7 @@ static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg, } svq->free_head = le16_to_cpu(descs[last].next); + return true; } static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, @@ -168,21 +175,18 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, return false; } - ok = vhost_svq_translate_addr(svq, sgs, elem->out_sg, elem->out_num); + ok = vhost_svq_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num, + 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); - - ok = vhost_svq_translate_addr(svq, sgs, elem->in_sg, elem->in_num); + ok = vhost_svq_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false, + true); if (unlikely(!ok)) { return false; } - vhost_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false, true); - /* * Put the entry in the available array (but don't update avail->idx until * they do sync). From patchwork Wed Mar 30 18:31:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611311 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UxpjfHa3; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTFgp6fnpz9sFq for ; Thu, 31 Mar 2022 05:43:34 +1100 (AEDT) Received: from localhost ([::1]:57948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdHz-0005dY-Ld for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 14:43:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6e-000676-9p for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57719) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6c-0006WY-V3 for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665101; 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=9IDz/9W93pVKAcRcZydDC03uu8yVY/Dr0TINJi9riQA=; b=UxpjfHa3LmzIBJgOaSL+g18bEm2sIDWFX31H93sI4NwMLOJBXReZbOj4S4adhU67AuJt2t 4vtJ9bk6wCyGTk4xLh/CfPbrzBFsdk3VIxGoxd9yJCB+AwiAykmzqR1tLvSA76xENM4EAh fiD+Z4hxfoWeZcpT4LA9M+2ZiG3GN74= 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-416-NotUbYJmNUCbLxVpHNh5aQ-1; Wed, 30 Mar 2022 14:31:38 -0400 X-MC-Unique: NotUbYJmNUCbLxVpHNh5aQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BB72F811E80; Wed, 30 Mar 2022 18:31:37 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id F013457ECF1; Wed, 30 Mar 2022 18:31:34 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 04/19] vdpa: Fix index calculus at vhost_vdpa_svqs_start Date: Wed, 30 Mar 2022 20:31:01 +0200 Message-Id: <20220330183116.358598-5-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- 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 c5ed7a3779..9eeac8fa8e 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1016,7 +1016,7 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev) VirtQueue *vq = virtio_get_queue(dev->vdev, dev->vq_index + i); VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i); struct vhost_vring_addr addr = { - .index = i, + .index = dev->vq_index + i, }; int r; bool ok = vhost_vdpa_svq_setup(dev, svq, i, &err); From patchwork Wed Mar 30 18:31:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611314 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=K6Km6IR+; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTFmQ1t10z9sFq for ; Thu, 31 Mar 2022 05:47:34 +1100 (AEDT) Received: from localhost ([::1]:36294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdLw-0001mk-8g for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 14:47:32 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6k-00067r-F7 for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59509) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6i-0006Wt-1X for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665106; 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=PGQ1gG94uiWh6IiJD6PlVFqPqWSjTn/uu14BwVv38jU=; b=K6Km6IR+NmP6Y4pc3B8c6PywApBBHbZ4vmceLv+F7PVvJshB7CbT0I+vdPNGtgXjN0syp2 NuECyB94Zx9tI6WSXzrL7MopPRuVPrB+IIkyFhGP0SZTyHrB1IghC52IsKsuI7LS0zjh7U UE8DYq9aLlUXb2ux/PJ9/s/E9sk81cI= 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-262-YBkLZy_1MHiJK780p5N-Vg-1; Wed, 30 Mar 2022 14:31:41 -0400 X-MC-Unique: YBkLZy_1MHiJK780p5N-Vg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D1EDE8F0541; Wed, 30 Mar 2022 18:31:40 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D21357ECE5; Wed, 30 Mar 2022 18:31:37 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 05/19] virtio-net: use g_memdup2() instead of unsafe g_memdup() Date: Wed, 30 Mar 2022 20:31:02 +0200 Message-Id: <20220330183116.358598-6-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Fixing that literal checkpatch.pl because it will complain when we modify the file Signed-off-by: Eugenio Pérez --- hw/net/virtio-net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 1067e72b39..da05516a99 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1443,7 +1443,7 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) } iov_cnt = elem->out_num; - iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) * elem->out_num); + iov2 = iov = g_memdup2(elem->out_sg, sizeof(struct iovec) * elem->out_num); s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl)); iov_discard_front(&iov, &iov_cnt, sizeof(ctrl)); if (s != sizeof(ctrl)) { From patchwork Wed Mar 30 18:31:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611328 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OeDSldgt; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTG7R4Hwsz9sFt for ; Thu, 31 Mar 2022 06:04:01 +1100 (AEDT) Received: from localhost ([::1]:48804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdbq-0005nT-Uw for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 15:03:58 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6l-000686-Ur for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52618) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6k-0006X0-5m for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665107; 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=4GmbUo6O0Dba+4XirVQ6543nPqsNcknVw3Af+9XtNC0=; b=OeDSldgtj3xDv0I1PeJpI047JcGbc8IVLvl5I1WU7i8Qw3LMxEz6Q5i1y3s6AZnit0BWr8 cREUGKC2N0I4UgwQx22K7xThlqVjIXbl79OFrWoG3ZlvdQpuTTgpMtkSv9cZFI+11dIun8 VITckXVmmD3urRADRIhhq4Q0odqe4Vk= 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-554-Cx5T8E5pN0KZ5j8IFXN9lg-1; Wed, 30 Mar 2022 14:31:44 -0400 X-MC-Unique: Cx5T8E5pN0KZ5j8IFXN9lg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EF5AB2803580; Wed, 30 Mar 2022 18:31:43 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 265D557ECE5; Wed, 30 Mar 2022 18:31:41 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 06/19] virtio-net: Expose ctrl virtqueue logic Date: Wed, 30 Mar 2022 20:31:03 +0200 Message-Id: <20220330183116.358598-7-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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érez --- include/hw/virtio/virtio-net.h | 3 ++ hw/net/virtio-net.c | 82 ++++++++++++++++++++-------------- 2 files changed, 51 insertions(+), 34 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; }; +unsigned virtio_net_handle_ctrl_iov(VirtIODevice *vdev, + const struct iovec *in_sg, size_t in_num, + struct iovec *out_sg, unsigned out_num); void virtio_net_set_netclient_name(VirtIONet *n, const char *name, const char *type); diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index da05516a99..5905a9285c 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1419,56 +1419,70 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd, return VIRTIO_NET_OK; } -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_num, + struct iovec *out_sg, unsigned out_num) { VirtIONet *n = VIRTIO_NET(vdev); struct virtio_net_ctrl_hdr ctrl; virtio_net_ctrl_ack status = 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 = iov = g_memdup2(out_sg, sizeof(struct iovec) * out_num); + s = iov_to_buf(iov, out_num, 0, &ctrl, sizeof(ctrl)); + iov_discard_front(&iov, &out_num, sizeof(ctrl)); + if (s != sizeof(ctrl)) { + status = VIRTIO_NET_ERR; + } else if (ctrl.class == VIRTIO_NET_CTRL_RX) { + status = virtio_net_handle_rx_mode(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class == VIRTIO_NET_CTRL_MAC) { + status = virtio_net_handle_mac(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class == VIRTIO_NET_CTRL_VLAN) { + status = virtio_net_handle_vlan_table(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class == VIRTIO_NET_CTRL_ANNOUNCE) { + status = virtio_net_handle_announce(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class == VIRTIO_NET_CTRL_MQ) { + status = virtio_net_handle_mq(n, ctrl.cmd, iov, out_num); + } else if (ctrl.class == VIRTIO_NET_CTRL_GUEST_OFFLOADS) { + status = virtio_net_handle_offloads(n, ctrl.cmd, iov, out_num); + } + + s = iov_from_buf(in_sg, in_num, 0, &status, sizeof(status)); + assert(s == sizeof(status)); + + g_free(iov2); + return sizeof(status); +} + +static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtQueueElement *elem; for (;;) { + unsigned written; elem = 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 = 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 = elem->out_num; - iov2 = iov = g_memdup2(elem->out_sg, sizeof(struct iovec) * elem->out_num); - s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl)); - iov_discard_front(&iov, &iov_cnt, sizeof(ctrl)); - if (s != sizeof(ctrl)) { - status = VIRTIO_NET_ERR; - } else if (ctrl.class == VIRTIO_NET_CTRL_RX) { - status = virtio_net_handle_rx_mode(n, ctrl.cmd, iov, iov_cnt); - } else if (ctrl.class == VIRTIO_NET_CTRL_MAC) { - status = virtio_net_handle_mac(n, ctrl.cmd, iov, iov_cnt); - } else if (ctrl.class == VIRTIO_NET_CTRL_VLAN) { - status = virtio_net_handle_vlan_table(n, ctrl.cmd, iov, iov_cnt); - } else if (ctrl.class == VIRTIO_NET_CTRL_ANNOUNCE) { - status = virtio_net_handle_announce(n, ctrl.cmd, iov, iov_cnt); - } else if (ctrl.class == VIRTIO_NET_CTRL_MQ) { - status = virtio_net_handle_mq(n, ctrl.cmd, iov, iov_cnt); - } else if (ctrl.class == VIRTIO_NET_CTRL_GUEST_OFFLOADS) { - status = virtio_net_handle_offloads(n, ctrl.cmd, iov, iov_cnt); - } - - s = iov_from_buf(elem->in_sg, elem->in_num, 0, &status, sizeof(status)); - assert(s == sizeof(status)); - - virtqueue_push(vq, elem, sizeof(status)); - virtio_notify(vdev, vq); - g_free(iov2); - g_free(elem); } } From patchwork Wed Mar 30 18:31:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611313 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Gph83te0; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTFkV6nthz9sG8 for ; Thu, 31 Mar 2022 05:45:54 +1100 (AEDT) Received: from localhost ([::1]:33126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdKK-0007tk-Ha for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 14:45:52 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6m-00068B-VN for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:55775) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6l-0006Xb-GU for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665111; 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=Gph83te0pjs9EBD30I288qQ4+es3l/omKyNnIksZl8v4y7tJsuh7F6ItNUEmulsgBwotvR +2AegoBkmn56pURvC6mVWkij1Yfzs/+TTqtDw9w9bnLTGA6bONIyxMFZBoE4IxpJNPWQIk KVzr9EDagfZ0l/R3sp9WTAbK1zLIzHs= 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-JIJtIIu9ONWL3IzWom0PvA-1; Wed, 30 Mar 2022 14:31:47 -0400 X-MC-Unique: JIJtIIu9ONWL3IzWom0PvA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 288832803581; Wed, 30 Mar 2022 18:31:47 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44D8C57ECE5; Wed, 30 Mar 2022 18:31:44 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 07/19] vdpa: Extract get geatures part from vhost_vdpa_get_max_queue_pairs Date: Wed, 30 Mar 2022 20:31:04 +0200 Message-Id: <20220330183116.358598-8-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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érez --- 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(NetClientState *peer, return nc; } -static int vhost_vdpa_get_max_queue_pairs(int fd, int *has_cvq, Error **errp) +static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **errp) +{ + int ret = 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 = offsetof(struct vhost_vdpa_config, buf); g_autofree struct vhost_vdpa_config *config = NULL; __virtio16 *max_queue_pairs; - uint64_t features; int ret; - ret = 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 = 1; } else { @@ -278,10 +282,11 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { const NetdevVhostVDPAOptions *opts; + uint64_t features; int vdpa_device_fd; g_autofree NetClientState **ncs = NULL; NetClientState *nc; - int queue_pairs, i, has_cvq = 0; + int queue_pairs, r, i, has_cvq = 0; g_autoptr(VhostIOVATree) iova_tree = NULL; assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA); @@ -296,7 +301,12 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, return -errno; } - queue_pairs = vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, + r = vhost_vdpa_get_features(vdpa_device_fd, &features, errp); + if (r) { + return r; + } + + queue_pairs = vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, features, &has_cvq, errp); if (queue_pairs < 0) { qemu_close(vdpa_device_fd); From patchwork Wed Mar 30 18:31:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611315 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MO7bgfXx; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTFnr5Y1sz9sFq for ; Thu, 31 Mar 2022 05:48:48 +1100 (AEDT) Received: from localhost ([::1]:40482 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdN8-0004b7-Pd for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 14:48:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6p-00069I-D2 for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38686) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6n-0006Xu-VN for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:31:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665112; 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=MO7bgfXximOf1znJmFL0ek3N1sBL2XXfd99s075dvR2xNohkLtDdOfARpO3ZHEKB6ouL/9 MatsuObc9I3yWLmKSMlVMhDUw2bHZ7j1EEAyS/afaFvXLW7reVc4SWTD/a8rSZ9U9hpJBO FK33W/Z1SSclcmBEsNvPDHc+JbcXmyM= 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-284-U-sNdCrgNbOPVAiL_NMJaw-1; Wed, 30 Mar 2022 14:31:51 -0400 X-MC-Unique: U-sNdCrgNbOPVAiL_NMJaw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E8D40811E81; Wed, 30 Mar 2022 18:31:50 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79A0757ECE5; Wed, 30 Mar 2022 18:31:47 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 08/19] virtio: Make virtqueue_alloc_element non-static Date: Wed, 30 Mar 2022 20:31:05 +0200 Message-Id: <20220330183116.358598-9-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" So SVQ can allocate elements using it Signed-off-by: Eugenio Pérez --- 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 VirtQueueElement *elem, unsigned int len, unsigned int idx); 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 sz); 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, VirtQueueElement *elem) false); } -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 = QEMU_ALIGN_UP(sz, __alignof__(elem->in_addr[0])); From patchwork Wed Mar 30 18:31:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611317 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Vzura6Tg; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTFpy4DHSz9sFq for ; Thu, 31 Mar 2022 05:49:46 +1100 (AEDT) Received: from localhost ([::1]:44372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdO4-0007CA-0W for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 14:49:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6w-0006NV-P9 for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:24517) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6u-0006YG-Ud for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665120; 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=JbKC6ERcKV0FbOQbzSNjo7X8WZRas/UXAQJ3U4pdLPg=; b=Vzura6Tgj5tMw2GipPjtsfUuh2PaZnORlse+SeWXptG2bmBGA4qtCvlRk7quONpKFB21sG MGIZGnGGQn9cQ5b0jJ/hNG8QynMMBnCAGVDAGTXyYjKSx3zIlKcWsMNNe8gSym8Sj3cc0/ 2O68OVXkrt/GR5dvhwKP39DxCbGPSgQ= 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-375-2_jpdDZ8P9CGyjfLRLuKcQ-1; Wed, 30 Mar 2022 14:31:57 -0400 X-MC-Unique: 2_jpdDZ8P9CGyjfLRLuKcQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 43ACC8001EA; Wed, 30 Mar 2022 18:31:55 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A4AC43271F; Wed, 30 Mar 2022 18:31:51 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 09/19] vhost: Add SVQElement Date: Wed, 30 Mar 2022 20:31:06 +0200 Message-Id: <20220330183116.358598-10-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This allows SVQ to add metadata to the different queue elements Signed-off-by: Eugenio Pérez --- 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-virtqueue.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" +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; /* Map for use the guest's descriptors */ - VirtQueueElement **ring_id_maps; + SVQElement **ring_id_maps; /* Next VirtQueue element that guest made available */ - VirtQueueElement *next_guest_avail_elem; + SVQElement *next_guest_avail_elem; /* 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-virtqueue.c index 349255525f..37e80c5ee0 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(VhostShadowVirtqueue *svq, hwaddr *sg, return true; } -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 = &svq_elem->elem; unsigned avail_idx; vring_avail_t *avail = svq->vring.avail; bool ok; @@ -202,7 +203,7 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, return true; } -static bool vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *elem) +static bool vhost_svq_add(VhostShadowVirtqueue *svq, SVQElement *elem) { unsigned qemu_head; bool ok = vhost_svq_add_split(svq, elem, &qemu_head); @@ -251,19 +252,21 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq) virtio_queue_set_notification(svq->vq, false); while (true) { + SVQElement *svq_elem; VirtQueueElement *elem; bool ok; if (svq->next_guest_avail_elem) { - elem = g_steal_pointer(&svq->next_guest_avail_elem); + svq_elem = g_steal_pointer(&svq->next_guest_avail_elem); } else { - elem = virtqueue_pop(svq->vq, sizeof(*elem)); + svq_elem = virtqueue_pop(svq->vq, sizeof(*svq_elem)); } - if (!elem) { + if (!svq_elem) { break; } + elem = &svq_elem->elem; if (elem->out_num + elem->in_num > vhost_svq_available_slots(svq)) { /* * This condition is possible since a contiguous buffer in GPA @@ -276,11 +279,11 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq) * queue the current guest descriptor and ignore further kicks * until some elements are used. */ - svq->next_guest_avail_elem = elem; + svq->next_guest_avail_elem = svq_elem; return; } - ok = vhost_svq_add(svq, elem); + ok = vhost_svq_add(svq, svq_elem); if (unlikely(!ok)) { /* VQ is broken, just return and ignore any other kicks */ return; @@ -337,8 +340,7 @@ static void vhost_svq_disable_notification(VhostShadowVirtqueue *svq) svq->vring.avail->flags |= cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT); } -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 = svq->vring.desc; const vring_used_t *used = svq->vring.used; @@ -388,11 +390,13 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, vhost_svq_disable_notification(svq); while (true) { uint32_t len; - g_autofree VirtQueueElement *elem = vhost_svq_get_buf(svq, &len); - if (!elem) { + g_autofree SVQElement *svq_elem = vhost_svq_get_buf(svq, &len); + VirtQueueElement *elem; + if (!svq_elem) { break; } + elem = &svq_elem->elem; if (unlikely(i >= svq->vring.num)) { qemu_log_mask(LOG_GUEST_ERROR, "More than %u used buffers obtained in a %u size SVQ", @@ -543,7 +547,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, memset(svq->vring.desc, 0, driver_size); svq->vring.used = qemu_memalign(qemu_real_host_page_size, device_size); memset(svq->vring.used, 0, device_size); - svq->ring_id_maps = g_new0(VirtQueueElement *, svq->vring.num); + svq->ring_id_maps = g_new0(SVQElement *, svq->vring.num); for (unsigned i = 0; i < svq->vring.num - 1; i++) { svq->vring.desc[i].next = cpu_to_le16(i + 1); } @@ -556,7 +560,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, void vhost_svq_stop(VhostShadowVirtqueue *svq) { event_notifier_set_handler(&svq->svq_kick, NULL); - g_autofree VirtQueueElement *next_avail_elem = NULL; + g_autofree SVQElement *next_avail_elem = NULL; if (!svq->vq) { return; @@ -566,16 +570,16 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) vhost_svq_flush(svq, false); for (unsigned i = 0; i < svq->vring.num; ++i) { - g_autofree VirtQueueElement *elem = NULL; - elem = g_steal_pointer(&svq->ring_id_maps[i]); - if (elem) { - virtqueue_detach_element(svq->vq, elem, 0); + g_autofree SVQElement *svq_elem = NULL; + svq_elem = g_steal_pointer(&svq->ring_id_maps[i]); + if (svq_elem) { + virtqueue_detach_element(svq->vq, &svq_elem->elem, 0); } } next_avail_elem = 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 = NULL; g_free(svq->ring_id_maps); From patchwork Wed Mar 30 18:31:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611318 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=b87FDW9k; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTFsN4LNpz9sFq for ; Thu, 31 Mar 2022 05:51:51 +1100 (AEDT) Received: from localhost ([::1]:48168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdQ3-0001L2-VR for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 14:51:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6y-0006Uw-Rq for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:39398) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd6x-0006YO-2W for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665122; 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=qGKpkvn5rZEcwzypIWsqaT7xtdkTsNPUiam0rbueScc=; b=b87FDW9ki9VPl8whHsMbMcl9oKo8shq4NLBCznDztSoY9rp7Dra9Teagw/GXLm30Zow8Ct EvwQngCwYKx/fUQuH4NwrE5pAlkCoHVPIC2W27cKTXFbIET7+LfA1+yOnJaw4XkcmJXyHz seL003KwpstoZFtdQgP4gQ0/uyO14do= 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-117-HtUMjkPiNqOGqAnmdI-jOA-1; Wed, 30 Mar 2022 14:31:59 -0400 X-MC-Unique: HtUMjkPiNqOGqAnmdI-jOA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 953D5100BAB0; Wed, 30 Mar 2022 18:31:58 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CF9B57ECE5; Wed, 30 Mar 2022 18:31:55 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 10/19] vhost: Add custom used buffer callback Date: Wed, 30 Mar 2022 20:31:07 +0200 Message-Id: <20220330183116.358598-11-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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érez --- 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-virtqueue.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; +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; + /* 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; @@ -83,7 +96,8 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, VirtQueue *vq); void vhost_svq_stop(VhostShadowVirtqueue *svq); -VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree); +VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, + const VhostShadowVirtqueueOps *ops); 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" 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-virtqueue.c index 37e80c5ee0..112d0daf20 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -406,6 +406,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); + } } virtqueue_flush(vq, i); @@ -592,12 +596,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 = g_new0(VhostShadowVirtqueue, 1); int r; @@ -619,6 +625,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 = iova_tree; + svq->ops = ops; return g_steal_pointer(&svq); err_init_hdev_call: diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 9eeac8fa8e..ebd17b6185 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -409,7 +409,8 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, shadow_vqs = g_ptr_array_new_full(hdev->nvqs, vhost_svq_free); for (unsigned n = 0; n < hdev->nvqs; ++n) { - g_autoptr(VhostShadowVirtqueue) svq = vhost_svq_new(v->iova_tree); + g_autoptr(VhostShadowVirtqueue) svq = vhost_svq_new(v->iova_tree, + v->shadow_vq_ops); if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); From patchwork Wed Mar 30 18:31:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611329 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=CiHs7t+/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTGBB5DwRz9sG8 for ; Thu, 31 Mar 2022 06:06:26 +1100 (AEDT) Received: from localhost ([::1]:52724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdeC-0000J9-HS for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 15:06:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd72-0006dk-6D for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd70-0006Yy-FX for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665125; 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=qqXoJqj9OA7Sqf3YvkIuIL7r3l4Sr5HSovq3lKNXtoM=; b=CiHs7t+/pGgBHchUrCgAiac0HwXX5c31NmU6Z2OpkS8qTg5M4ioHmryzFz6Frb9OWte3u1 CdzU9V1GRV6U3RorMmttrSrpsGtossGxI8IvEWQ/BzUZoTUDKNyZgdE4sCaQmoaSazgWrF H0z7H8US5Xy0segiQR0PdOPmTudJ3ko= 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-642-FKtWtrJYMoWElK8MbPZGIg-1; Wed, 30 Mar 2022 14:32:02 -0400 X-MC-Unique: FKtWtrJYMoWElK8MbPZGIg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D3AA53C01D89; Wed, 30 Mar 2022 18:32:01 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4C1B43271F; Wed, 30 Mar 2022 18:31:58 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 11/19] vdpa: control virtqueue support on shadow virtqueue Date: Wed, 30 Mar 2022 20:31:08 +0200 Message-Id: <20220330183116.358598-12-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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_CTROL_MACADDR is implemented. If vDPA device is started with SVQ support and virtio-net driver changes MAC, virtio-net device model will be updated with the new one. Signed-off-by: Eugenio Pérez --- net/vhost-vdpa.c | 70 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 290aa01e13..585d2f60f8 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -11,6 +11,7 @@ #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,29 @@ const int vdpa_feature_bits[] = { VHOST_INVALID_FEATURE_BIT }; +/** Supported device specific feature bits with SVQ */ +static const uint64_t vdpa_svq_device_features = + 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_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 = DO_UPCAST(VhostVDPAState, nc, nc); @@ -199,6 +223,37 @@ static int vhost_vdpa_get_iova_range(int fd, return ret < 0 ? -errno : 0; } +static void vhost_vdpa_net_handle_ctrl(VirtIODevice *vdev, + const VirtQueueElement *elem) +{ + struct virtio_net_ctrl_hdr ctrl; + virtio_net_ctrl_ack status = VIRTIO_NET_ERR; + size_t s; + struct iovec in = { + .iov_base = &status, + .iov_len = sizeof(status), + }; + + s = iov_to_buf(elem->out_sg, elem->out_num, 0, &ctrl, sizeof(ctrl.class)); + if (s != sizeof(ctrl.class) || ctrl.class != VIRTIO_NET_CTRL_MAC_ADDR_SET) { + return; + } + s = iov_to_buf(elem->in_sg, elem->in_num, 0, &status, sizeof(status)); + if (s != sizeof(status) || status != VIRTIO_NET_OK) { + return; + } + + status = VIRTIO_NET_ERR; + virtio_net_handle_ctrl_iov(vdev, &in, 1, elem->out_sg, elem->out_num); + if (status != VIRTIO_NET_OK) { + error_report("Bad CVQ processing in model"); + } +} + +static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = { + .used_elem_handler = vhost_vdpa_net_handle_ctrl, +}; + static NetClientState *net_vhost_vdpa_init(NetClientState *peer, const char *device, const char *name, @@ -226,6 +281,9 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.device_fd = vdpa_device_fd; s->vhost_vdpa.index = queue_pair_index; s->vhost_vdpa.shadow_vqs_enabled = svq; + if (!is_datapath) { + s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops; + } s->vhost_vdpa.iova_tree = iova_tree; ret = vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs); if (ret) { @@ -314,9 +372,15 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *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 = + features & ~vdpa_svq_device_features & + /* Transport are all accepted at this point */ + ~MAKE_64BIT_MASK(VIRTIO_TRANSPORT_F_START, + VIRTIO_TRANSPORT_F_END - VIRTIO_TRANSPORT_F_START); + + if (invalid_dev_features) { + error_setg(errp, "vdpa svq does not work with features 0x%" PRIx64, + invalid_dev_features); goto err_svq; } vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); From patchwork Wed Mar 30 18:31:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611330 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Yz6fYtmq; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTGDC4LYSz9sG9 for ; Thu, 31 Mar 2022 06:08:11 +1100 (AEDT) Received: from localhost ([::1]:56680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdft-00034w-8q for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 15:08:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd74-0006lU-T4 for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22217) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd73-0006ZN-8O for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665128; 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=Yz6fYtmqL0MPMDjM4FyruNl561OpXtzpA9NHRLjHLo1XtSo4VYOREtPekyo/gQ8w/foilm fodjfOozIC9pu8gQwK8bpysa217migHKPkfrZ6D2AlCC4AMVp45Lxdd5oN83SoU4jp+e6X 8bq65VsPyJIqRbnl1xj0V89+Uz/GGp4= 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-672-ICGdRUjJMfOK0x3TmpICSg-1; Wed, 30 Mar 2022 14:32:05 -0400 X-MC-Unique: ICGdRUjJMfOK0x3TmpICSg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E4255811E90; Wed, 30 Mar 2022 18:32:04 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26ED957ECED; Wed, 30 Mar 2022 18:32:02 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 12/19] vhost: Add vhost_iova_tree_find Date: Wed, 30 Mar 2022 20:31:09 +0200 Message-Id: <20220330183116.358598-13-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Just a simple wrapper so we can find DMAMap entries based on iova Signed-off-by: Eugenio Pérez --- 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, uint64_t iova_last); void vhost_iova_tree_delete(VhostIOVATree *iova_tree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostIOVATree, vhost_iova_tree_delete); +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); } +/** + * 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 * From patchwork Wed Mar 30 18:31:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611334 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=U3pYzJWy; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTGG73DC4z9sG9 for ; Thu, 31 Mar 2022 06:09:49 +1100 (AEDT) Received: from localhost ([::1]:59382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdhS-0004vJ-B4 for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 15:09:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49584) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd76-0006mb-DY for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41585) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd74-0006ZS-Px for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665130; 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=ziKG7NMrQUDfpN7hHEJ3ldSTZN61IqMf/1SSEIHh+7U=; b=U3pYzJWyD7o9/ZoWBChsKHS0HPKx0piUuOZcuJpBa9Mpv0VcQOuSKJcXBa1DiVG9RjGSKl tayKlt1sAMXRhwT7/nGv7iFnvpAunrCe7h5GKC5TzZeuh1WKM311ij1lPejTWeiqe3JJFu fvbsJaBf6pHI8jKimU6lmFEb6Dv6xE4= 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-146-PzzEB0v3P3CXyQ-7e3smBg-1; Wed, 30 Mar 2022 14:32:08 -0400 X-MC-Unique: PzzEB0v3P3CXyQ-7e3smBg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 554F12803587; Wed, 30 Mar 2022 18:32:08 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3692F57ECE5; Wed, 30 Mar 2022 18:32:05 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 13/19] vdpa: Add map/unmap operation callback to SVQ Date: Wed, 30 Mar 2022 20:31:10 +0200 Message-Id: <20220330183116.358598-14-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- 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-virtqueue.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; +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; + /* 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; @@ -96,8 +111,10 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, VirtQueue *vq); void vhost_svq_stop(VhostShadowVirtqueue *svq); -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); 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-virtqueue.c index 112d0daf20..714c820698 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -597,13 +597,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 = g_new0(VhostShadowVirtqueue, 1); int r; @@ -626,6 +630,8 @@ VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree, event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); svq->iova_tree = iova_tree; svq->ops = ops; + svq->map_ops = map_ops; + svq->map_ops_opaque = map_ops_opaque; return g_steal_pointer(&svq); err_init_hdev_call: diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index ebd17b6185..600d006d6e 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -383,6 +383,22 @@ static int vhost_vdpa_get_dev_features(struct vhost_dev *dev, return ret; } +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 = { + .map = vhost_vdpa_svq_map, + .unmap = vhost_vdpa_svq_unmap, +}; + static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, Error **errp) { @@ -410,7 +426,9 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, shadow_vqs = g_ptr_array_new_full(hdev->nvqs, vhost_svq_free); for (unsigned n = 0; n < hdev->nvqs; ++n) { g_autoptr(VhostShadowVirtqueue) svq = vhost_svq_new(v->iova_tree, - v->shadow_vq_ops); + v->shadow_vq_ops, + &vhost_vdpa_svq_map_ops, + v); if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); From patchwork Wed Mar 30 18:31:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611323 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ToIzKdvw; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTFzr3Blyz9sFt for ; Thu, 31 Mar 2022 05:57:26 +1100 (AEDT) Received: from localhost ([::1]:60600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdVT-0001jk-RM for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 14:57:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd7F-0006nY-Nm for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:56525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd7A-0006ca-34 for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665135; 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=9A+sHtG8pHBJO54T8z69caFIuWr/WFYIUUCcELZ6RAU=; b=ToIzKdvwZJQW3M+FN1juWyzZRqHAC2lvaSTOokLFfQVXczhA79i6PfXKE3/gJbWM5HzbbG vnGVRb80K5AXLL/eU713ziFLaSs7GaKbSHme0xdlvI+qyDR3ftteuDv/HPBQYzk3VUGpg5 VP+S9Lybl8rRsHgbWOzSrIhKkOR5bn4= 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-633-ROZshcqENRiOJYaQAIMwOw-1; Wed, 30 Mar 2022 14:32:11 -0400 X-MC-Unique: ROZshcqENRiOJYaQAIMwOw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 60A68185A7BA; Wed, 30 Mar 2022 18:32:11 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CC3257ECF2; Wed, 30 Mar 2022 18:32:08 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 14/19] vhost: Add vhost_svq_inject Date: Wed, 30 Mar 2022 20:31:11 +0200 Message-Id: <20220330183116.358598-15-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 destination Signed-off-by: Eugenio Pérez --- 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-virtqueue.h index 6e61d9bfef..d82a64d566 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -17,6 +17,9 @@ typedef struct SVQElement { VirtQueueElement elem; + hwaddr in_iova; + hwaddr out_iova; + bool not_from_guest; } SVQElement; typedef void (*VirtQueueElementCallback)(VirtIODevice *vdev, @@ -100,6 +103,8 @@ typedef struct VhostShadowVirtqueue { bool vhost_svq_valid_features(uint64_t features, Error **errp); +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-virtqueue.c index 714c820698..dc2f194e24 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" /** * Validate the transport device features that both guests can use with the SVQ @@ -122,7 +123,8 @@ static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq, return true; } -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(VhostShadowVirtqueue *svq, hwaddr *sg, unsigned n; uint16_t flags = write ? cpu_to_le16(VRING_DESC_F_WRITE) : 0; vring_desc_t *descs = svq->vring.desc; - bool ok; if (num == 0) { return true; } - ok = vhost_svq_translate_addr(svq, sg, iovec, num); - if (unlikely(!ok)) { - return false; + if (svq_elem->not_from_guest) { + DMAMap map = { + .translated_addr = (hwaddr)iovec->iov_base, + .size = ROUND_UP(iovec->iov_len, 4096) - 1, + .perm = write ? IOMMU_RW : IOMMU_RO, + }; + int r; + + if (unlikely(num != 1)) { + error_report("Unexpected chain of element injected"); + return false; + } + r = vhost_iova_tree_map_alloc(svq->iova_tree, &map); + if (unlikely(r != IOVA_OK)) { + error_report("Cannot map injected element"); + return false; + } + + r = svq->map_ops->map(map.iova, map.size + 1, + (void *)map.translated_addr, !write, + svq->map_ops_opaque); + assert(r == 0); + sg[0] = map.iova; + } else { + bool ok = vhost_svq_translate_addr(svq, sg, iovec, num); + if (unlikely(!ok)) { + return false; + } } for (n = 0; n < num; n++) { @@ -165,7 +191,8 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, SVQElement *svq_elem, unsigned avail_idx; vring_avail_t *avail = svq->vring.avail; bool ok; - g_autofree hwaddr *sgs = g_new(hwaddr, MAX(elem->out_num, elem->in_num)); + g_autofree hwaddr *sgs = NULL; + hwaddr *in_sgs, *out_sgs; *head = svq->free_head; @@ -176,15 +203,23 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, SVQElement *svq_elem, return false; } - ok = vhost_svq_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num, - elem->in_num > 0, false); + if (!svq_elem->not_from_guest) { + sgs = g_new(hwaddr, MAX(elem->out_num, elem->in_num)); + in_sgs = out_sgs = sgs; + } else { + in_sgs = &svq_elem->in_iova; + out_sgs = &svq_elem->out_iova; + } + ok = vhost_svq_vring_write_descs(svq, svq_elem, out_sgs, elem->out_sg, + elem->out_num, elem->in_num > 0, false); if (unlikely(!ok)) { return false; } - ok = vhost_svq_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false, - true); + ok = 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; } @@ -229,6 +264,43 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) event_notifier_set(&svq->hdev_kick); } +bool vhost_svq_inject(VhostShadowVirtqueue *svq, const struct iovec *iov, + size_t out_num, size_t in_num) +{ + size_t out_size = iov_size(iov, out_num); + size_t out_buf_size = ROUND_UP(out_size, 4096); + size_t in_size = iov_size(iov + out_num, in_num); + size_t in_buf_size = ROUND_UP(in_size, 4096); + SVQElement *svq_elem; + uint16_t num_slots = (in_num ? 1 : 0) + (out_num ? 1 : 0); + + if (unlikely(num_slots == 0 || svq->next_guest_avail_elem || + vhost_svq_available_slots(svq) < num_slots)) { + return false; + } + + svq_elem = virtqueue_alloc_element(sizeof(SVQElement), 1, 1); + if (out_num) { + void *out = qemu_memalign(4096, out_buf_size); + svq_elem->elem.out_sg[0].iov_base = out; + svq_elem->elem.out_sg[0].iov_len = 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 = qemu_memalign(4096, in_buf_size); + svq_elem->elem.in_sg[0].iov_base = in; + svq_elem->elem.in_sg[0].iov_len = in_size; + memset(in, 0, in_buf_size); + } + + svq_elem->not_from_guest = 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(VhostShadowVirtqueue *svq) break; } + svq_elem->not_from_guest = false; elem = &svq_elem->elem; if (elem->out_num + elem->in_num > vhost_svq_available_slots(svq)) { /* @@ -378,6 +451,31 @@ static SVQElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, uint32_t *len) return g_steal_pointer(&svq->ring_id_maps[used_elem.id]); } +static int vhost_svq_unmap(VhostShadowVirtqueue *svq, hwaddr iova, size_t size) +{ + DMAMap needle = { + .iova = iova, + .size = size, + }; + const DMAMap *overlap; + + while ((overlap = vhost_iova_tree_find(svq->iova_tree, &needle))) { + DMAMap needle = *overlap; + + if (svq->map_ops->unmap) { + int r = svq->map_ops->unmap(overlap->iova, overlap->size + 1, + svq->map_ops_opaque); + if (unlikely(r != 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) { @@ -397,23 +495,56 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, } elem = &svq_elem->elem; - if (unlikely(i >= 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 != 1)) { + error_report("Unexpected out_num > 1"); + return; + } + + if (elem->out_num) { + int r = vhost_svq_unmap(svq, svq_elem->out_iova, + elem->out_sg[0].iov_len); + if (unlikely(r != 0)) { + error_report("Cannot unmap out buffer"); + return; + } + } + + if (unlikely(!elem->in_num && elem->in_num != 1)) { + error_report("Unexpected in_num > 1"); + return; + } + + if (elem->in_num) { + int r = vhost_svq_unmap(svq, svq_elem->in_iova, + elem->in_sg[0].iov_len); + if (unlikely(r != 0)) { + error_report("Cannot unmap out buffer"); + return; + } + } + } else { + if (unlikely(i >= 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++); + } } - virtqueue_flush(vq, i); - event_notifier_set(&svq->svq_call); + if (i > 0) { + virtqueue_flush(vq, i); + event_notifier_set(&svq->svq_call); + } if (check_for_avail_queue && svq->next_guest_avail_elem) { /* @@ -576,13 +707,13 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) for (unsigned i = 0; i < svq->vring.num; ++i) { g_autofree SVQElement *svq_elem = NULL; svq_elem = 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); } } next_avail_elem = 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 = NULL; From patchwork Wed Mar 30 18:31:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611321 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UjJ41BeT; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTFw412n0z9sFq for ; Thu, 31 Mar 2022 05:54:12 +1100 (AEDT) Received: from localhost ([::1]:53562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdSM-0005CC-7J for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 14:54:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd7F-0006nX-NZ for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53060) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd7B-0006dE-HS for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665136; 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=UjJ41BeTmB+2pQxYvX/ca/j2gcgPdLTtsLFCXRga8cH555As9BAgjowq7/ECfIUj19Il8p WryUEylhnabHC6sbKhj0kE+v0DdvxJlS8nI6A37WGGATJd0ZyNLjnkqGO92vb1O2kCOIuM /BUoXX9A4enPyVBmag0dC/aF6YZUuuk= 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-636-BVtpAxVFO5K4KRi2zMwoEA-1; Wed, 30 Mar 2022 14:32:14 -0400 X-MC-Unique: BVtpAxVFO5K4KRi2zMwoEA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 62968811E9B; Wed, 30 Mar 2022 18:32:14 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id A695F57ECED; Wed, 30 Mar 2022 18:32:11 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 15/19] vdpa: add NetClientState->start() callback Date: Wed, 30 Mar 2022 20:31:12 +0200 Message-Id: <20220330183116.358598-16-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It allows to inject custom code on device success start, right before release lock. Signed-off-by: Eugenio Pérez --- 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 { 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 *, int); 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 = -1; From patchwork Wed Mar 30 18:31:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611322 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MP1Au3Fb; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTFwp5hg2z9sFq for ; Thu, 31 Mar 2022 05:54:50 +1100 (AEDT) Received: from localhost ([::1]:54684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdSy-0005yd-SA for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 14:54:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd7J-0006nz-Ev for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:32050) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd7F-0006fV-QR for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665141; 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=mwMJrXbjBoQvBEMEY7wL0UMJ13pv00ab4vGSzMsAE6A=; b=MP1Au3FbrqK0Onfvx+FY6GkC7RwYZA9bRMwa7BGR5bQNpLeqx4QITExrZDJDibYNfMTlTh 0cgnx5PC7i9HIlq3n6GA7+ORoRGM54oL/9ZrzA/+3AME8ra/z1awXhhbQkoXKh2uPJUSyU Ep+DEosAoJXmoOPZcb/V1j+xKsWQLNM= 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-523-c8P2XyQ-Nn2PiEyOTPB8kg-1; Wed, 30 Mar 2022 14:32:17 -0400 X-MC-Unique: c8P2XyQ-Nn2PiEyOTPB8kg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5DB54811E75; Wed, 30 Mar 2022 18:32:17 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id A934C57ECE5; Wed, 30 Mar 2022 18:32:14 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 16/19] vdpa: Add vhost_vdpa_start_control_svq Date: Wed, 30 Mar 2022 20:31:13 +0200 Message-Id: <20220330183116.358598-17-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This will send CVQ commands in the destination machine, seting up everything o there is no guest-visible change. Signed-off-by: Eugenio Pérez --- net/vhost-vdpa.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 585d2f60f8..6dc0ae8614 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -205,10 +205,73 @@ static ssize_t vhost_vdpa_receive(NetClientState *nc, const uint8_t *buf, return 0; } +static bool vhost_vdpa_start_control_svq(VhostShadowVirtqueue *svq, + VirtIODevice *vdev) +{ + VirtIONet *n = VIRTIO_NET(vdev); + uint64_t features = vdev->host_features; + + if (features & BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR)) { + const struct virtio_net_ctrl_hdr ctrl = { + .class = VIRTIO_NET_CTRL_MAC, + .cmd = VIRTIO_NET_CTRL_MAC_ADDR_SET, + }; + uint8_t mac[6]; + const struct iovec data[] = { + { + .iov_base = (void *)&ctrl, + .iov_len = sizeof(ctrl), + },{ + .iov_base = mac, + .iov_len = sizeof(mac), + },{ + .iov_base = NULL, + .iov_len = sizeof(virtio_net_ctrl_ack), + } + }; + bool ret; + + /* TODO: Only best effort? */ + memcpy(mac, n->mac, sizeof(mac)); + ret = vhost_svq_inject(svq, data, 2, 1); + if (!ret) { + return false; + } + } + + return true; +} + +static void vhost_vdpa_start(NetClientState *nc) +{ + assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); + VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); + struct vhost_vdpa *v = &s->vhost_vdpa; + struct vhost_dev *dev = &s->vhost_net->dev; + VhostShadowVirtqueue *svq; + + if (nc->is_datapath) { + /* This is not the cvq dev */ + return; + } + + if (dev->vq_index + dev->nvqs != dev->vq_index_end) { + return; + } + + if (!v->shadow_vqs_enabled) { + return; + } + + svq = g_ptr_array_index(v->shadow_vqs, 0); + vhost_vdpa_start_control_svq(svq, dev->vdev); +} + static NetClientInfo net_vhost_vdpa_info = { .type = NET_CLIENT_DRIVER_VHOST_VDPA, .size = sizeof(VhostVDPAState), .receive = vhost_vdpa_receive, + .start = vhost_vdpa_start, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr, .has_ufo = vhost_vdpa_has_ufo, From patchwork Wed Mar 30 18:31:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611324 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XOgaEqpW; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTG0r59m3z9sFt for ; Thu, 31 Mar 2022 05:58:20 +1100 (AEDT) Received: from localhost ([::1]:33552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdWM-0002YN-NZ for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 14:58:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd7N-0006qQ-8n for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:26549) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd7J-0006fs-7r for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665144; 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=XOgaEqpWKssB0f+p54ILpmOcU/4z7rNMs1kRw/boZMeZ9GDoPgJ/6YIMLo2OYu7r/+P9Fr JPagesKPX+bvCEPP8UGpoVh0AI7ASJ8JNhQBGoMVo35XNZtPULDQSVR/my/OBxgwGZcIwT oNHq4FIn4/sdPck/FT+NnkoUqqrCcA0= 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-663-b9MlvANcN1a0zeimvc__FQ-1; Wed, 30 Mar 2022 14:32:21 -0400 X-MC-Unique: b9MlvANcN1a0zeimvc__FQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5EE6C185A79C; Wed, 30 Mar 2022 18:32:20 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3B1D57ECED; Wed, 30 Mar 2022 18:32:17 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 17/19] vhost: Update kernel headers Date: Wed, 30 Mar 2022 20:31:14 +0200 Message-Id: <20220330183116.358598-18-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Eugenio Pérez --- 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/standard-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 { 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 +/* 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 @@ /* Set or get vhost backend capability */ -/* 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) @@ -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 From patchwork Wed Mar 30 18:31:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611305 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JcjkoPKI; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTFXr2HjJz9sFq for ; Thu, 31 Mar 2022 05:37:32 +1100 (AEDT) Received: from localhost ([::1]:43024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdCE-0003dz-Be for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 14:37:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd7P-0006ru-8t for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47493) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd7M-0006hM-R1 for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665147; 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=jm9CSuoNBVFc0RS5uG9jeyenGVAdiuZSmP7TrosYivs=; b=JcjkoPKI2JPsNW7pp7K5RvueAvIMakrwMf+OeGnHjxbjMz9v6jUDZLgk2wLztajrUKbq3j 8SLM1e+J1Q4Y3YhWo+UJtJqNyVNlbcztjfV6EYU/pW3j/g7M8iekl39qYFqhMxgueOsc7D nIGY1QL7ddg6ne5EUV6wsfVzOb6DM8c= 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-498-KuP-vQR9NuuPdQ4SpLDD7A-1; Wed, 30 Mar 2022 14:32:23 -0400 X-MC-Unique: KuP-vQR9NuuPdQ4SpLDD7A-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5F23B3C01D9A; Wed, 30 Mar 2022 18:32:23 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id A479E57ECE5; Wed, 30 Mar 2022 18:32:20 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 18/19] vdpa: Add asid attribute to vdpa device Date: Wed, 30 Mar 2022 20:31:15 +0200 Message-Id: <20220330183116.358598-19-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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érez --- include/hw/virtio/vhost-vdpa.h | 3 +++ hw/virtio/vhost-vdpa.c | 47 ++++++++++++++++++++++++---------- net/vhost-vdpa.c | 10 ++++++-- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index f1ba46a860..921edbf77b 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -28,10 +28,13 @@ typedef struct vhost_vdpa { int device_fd; int index; uint32_t msg_type; + uint32_t asid; bool iotlb_batch_begin_sent; 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/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 600d006d6e..bd06662cee 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -79,6 +79,9 @@ static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size, int ret = 0; msg.type = v->msg_type; + if (v->dev->backend_cap & BIT_ULL(VHOST_BACKEND_F_IOTLB_ASID)) { + msg.asid = v->asid; + } msg.iotlb.iova = iova; msg.iotlb.size = size; msg.iotlb.uaddr = (uint64_t)(uintptr_t)vaddr; @@ -104,6 +107,9 @@ static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, int fd = v->device_fd; int ret = 0; + if (v->dev->backend_cap & BIT_ULL(VHOST_BACKEND_F_IOTLB_ASID)) { + msg.asid = v->asid; + } msg.type = v->msg_type; msg.iotlb.iova = iova; msg.iotlb.size = size; @@ -129,6 +135,10 @@ static void vhost_vdpa_listener_begin_batch(struct vhost_vdpa *v) .iotlb.type = VHOST_IOTLB_BATCH_BEGIN, }; + if (v->dev->backend_cap & BIT_ULL(VHOST_BACKEND_F_IOTLB_ASID)) { + msg.asid = v->asid; + } + if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) { error_report("failed to write, fd=%d, errno=%d (%s)", fd, errno, strerror(errno)); @@ -161,6 +171,9 @@ static void vhost_vdpa_listener_commit(MemoryListener *listener) } msg.type = v->msg_type; + if (dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_ASID)) { + msg.asid = v->asid; + } msg.iotlb.type = VHOST_IOTLB_BATCH_END; if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) { @@ -675,7 +688,8 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) { uint64_t features; uint64_t f = 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; if (vhost_vdpa_call(dev, VHOST_GET_BACKEND_FEATURES, &features)) { @@ -1098,7 +1112,9 @@ static bool vhost_vdpa_svqs_stop(struct vhost_dev *dev) static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) { struct vhost_vdpa *v = dev->opaque; - bool ok; + bool vq_group_end, ok; + int r = 0; + trace_vhost_vdpa_dev_start(dev, started); if (started) { @@ -1116,21 +1132,26 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); } - if (dev->vq_index + dev->nvqs != dev->vq_index_end) { - return 0; + vq_group_end = dev->vq_index + dev->nvqs == v->vq_group_index_end; + if (vq_group_end && started) { + memory_listener_register(&v->listener, &address_space_memory); } - 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 == dev->vq_index_end) { + if (started) { + r = 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); + } + } - return 0; + if (vq_group_end && !started) { + memory_listener_unregister(&v->listener); } + + return r; } 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 6dc0ae8614..fae9a43b86 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -323,6 +323,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, int vdpa_device_fd, int queue_pair_index, int nvqs, + uint32_t asid, + int vq_group_end, bool is_datapath, bool svq, VhostIOVATree *iova_tree) @@ -344,6 +346,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.device_fd = vdpa_device_fd; s->vhost_vdpa.index = queue_pair_index; s->vhost_vdpa.shadow_vqs_enabled = svq; + s->vhost_vdpa.vq_group_index_end = vq_group_end; + s->vhost_vdpa.asid = asid; if (!is_datapath) { s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops; } @@ -454,7 +458,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, for (i = 0; i < queue_pairs; i++) { ncs[i] = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 2, true, opts->x_svq, + vdpa_device_fd, i, 2, 0, + queue_pairs + has_cvq, true, opts->x_svq, iova_tree); if (!ncs[i]) goto err; @@ -462,7 +467,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, if (has_cvq) { nc = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 1, false, opts->x_svq, + vdpa_device_fd, i, 1, 0, + queue_pairs + has_cvq, false, opts->x_svq, iova_tree); if (!nc) goto err; From patchwork Wed Mar 30 18:31:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 1611326 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RB3xWvwK; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTG4Q5Zg2z9sFt for ; Thu, 31 Mar 2022 06:01:26 +1100 (AEDT) Received: from localhost ([::1]:40046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZdZM-0007C0-Ce for incoming@patchwork.ozlabs.org; Wed, 30 Mar 2022 15:01:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49730) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd7Q-0006xQ-To for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49562) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZd7O-0006i0-Vs for qemu-devel@nongnu.org; Wed, 30 Mar 2022 14:32:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648665150; 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=ezYTcu/aPLPMjWfufw2S8H5qEgyKxJbAT4R0X+HbWVs=; b=RB3xWvwKhVtLvU9IA/vwLOhfKHoSeGXipVd+oqZOLoxHTucN9iyq+VK8kMmgTs2OunmkGB nsCTXa9vAHUBkrJdvvBbmypuqwrjFz9N0DjULeAyxz+drjh5tg6bAQAl7Ia/75AVYdnOhX ZFr2UCiL/1LbLq/RYrii4OPTbSmCdGM= 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-54-Qk_xcfhDNmG45wCXZyiqtA-1; Wed, 30 Mar 2022 14:32:26 -0400 X-MC-Unique: Qk_xcfhDNmG45wCXZyiqtA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5C34D185A794; Wed, 30 Mar 2022 18:32:26 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id A42AD57ECF2; Wed, 30 Mar 2022 18:32:23 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 19/19] vdpa: Add x-cvq-svq Date: Wed, 30 Mar 2022 20:31:16 +0200 Message-Id: <20220330183116.358598-20-eperezma@redhat.com> In-Reply-To: <20220330183116.358598-1-eperezma@redhat.com> References: <20220330183116.358598-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 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 , Peter Xu , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Liuxiangdong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This isolates shadow cvq in its own group. Signed-off-by: Eugenio Pérez --- qapi/net.json | 8 ++- net/vhost-vdpa.c | 179 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 171 insertions(+), 16 deletions(-) diff --git a/qapi/net.json b/qapi/net.json index 6a5460ce56..d54a137581 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'] } } } ## # @NetClientDriver: diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index fae9a43b86..13767e6d3c 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -354,10 +354,13 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.iova_tree = iova_tree; ret = vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs); if (ret) { - qemu_del_net_client(nc); - return NULL; + goto err; } return nc; + +err: + qemu_del_net_client(nc); + return NULL; } static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **errp) @@ -370,6 +373,17 @@ static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **errp) return ret; } +static int vhost_vdpa_get_backend_features(int fd, uint64_t *features, + Error **errp) +{ + int ret = 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) { @@ -403,16 +417,112 @@ static int vhost_vdpa_get_max_queue_pairs(int fd, uint64_t features, return 1; } +/** + * 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 = vhost_vdpa_get_backend_features(vdpa_device_fd, &backend_features, + 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 = 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; +} + +/** + * Check if CVQ lives in an isolated group. + * + * Note that vdpa QEMU needs to be the owner of vdpa device (in other words, to + * have called VHOST_SET_OWNER) for this to succeed. + * + * @vdpa_device_fd: vdpa device fd + * @vq_index: vq index to start asking for group + * @nvq: Number of vqs to check + * @cvq_device_index: cvq device index + * @cvq_group: cvq group + * @errp: Error + */ +static bool vhost_vdpa_is_cvq_isolated_group(int vdpa_device_fd, + unsigned vq_index, + unsigned nvq, + unsigned cvq_device_index, + struct vhost_vring_state *cvq_group, + Error **errp) +{ + int r; + + if (cvq_group->index == 0) { + cvq_group->index = cvq_device_index; + r = ioctl(vdpa_device_fd, VHOST_VDPA_GET_VRING_GROUP, cvq_group); + if (unlikely(r)) { + error_setg_errno(errp, errno, + "Cannot get control vq index %d group", + cvq_group->index); + false; + } + } + + for (int k = vq_index; k < vq_index + nvq; ++k) { + struct vhost_vring_state s = { + .index = k, + }; + + r = ioctl(vdpa_device_fd, VHOST_VDPA_GET_VRING_GROUP, &s); + if (unlikely(r)) { + error_setg_errno(errp, errno, "Cannot get vq %d group", k); + return false; + } + + if (unlikely(s.num == cvq_group->num)) { + error_setg(errp, "Data virtqueue %d has the same group as cvq (%d)", + k, s.num); + return false; + } + } + + return true; +} + 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; + struct vhost_vring_state cvq_group = {}; uint64_t features; int vdpa_device_fd; g_autofree NetClientState **ncs = NULL; NetClientState *nc; int queue_pairs, r, i, has_cvq = 0; g_autoptr(VhostIOVATree) iova_tree = NULL; + g_autoptr(VhostIOVATree) cvq_iova_tree = NULL; + ERRP_GUARD(); assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA); opts = &netdev->u.vhost_vdpa; @@ -437,8 +547,9 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *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 = features & ~vdpa_svq_device_features & /* Transport are all accepted at this point */ @@ -448,9 +559,25 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, if (invalid_dev_features) { error_setg(errp, "vdpa svq does not work with features 0x%" PRIx64, invalid_dev_features); - goto err_svq; + goto err_svq_features; } - 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 cvq"); + goto err_cvq_svq; + } + + r = vhost_vdpa_check_cvq_svq(vdpa_device_fd, queue_pairs, errp); + if (unlikely(r)) { + error_prepend(errp, "Cannot configure CVQ SVQ: "); + goto err_cvq_svq; + } + + cvq_iova_tree = vhost_iova_tree_new(iova_range.first, iova_range.last); + } + if (opts->x_svq) { iova_tree = vhost_iova_tree_new(iova_range.first, iova_range.last); } @@ -458,31 +585,55 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, for (i = 0; i < queue_pairs; i++) { ncs[i] = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 2, 0, - queue_pairs + has_cvq, true, opts->x_svq, - iova_tree); + vdpa_device_fd, i, 2, 0, 2 * queue_pairs, + true, opts->x_svq, iova_tree); if (!ncs[i]) goto err; + + if (opts->x_cvq_svq && + !vhost_vdpa_is_cvq_isolated_group(vdpa_device_fd, i * 2, 2, + queue_pairs * 2, &cvq_group, + errp)) { + goto err_cvq_svq; + } } if (has_cvq) { - nc = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 1, 0, - queue_pairs + has_cvq, false, opts->x_svq, - iova_tree); + nc = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd, + i, 1, !!opts->x_cvq_svq, + 2 * queue_pairs + 1, false, + opts->x_cvq_svq || opts->x_svq, + cvq_iova_tree); if (!nc) goto err; + + if (opts->x_cvq_svq) { + struct vhost_vring_state asid = { + .index = 1, + .num = 1, + }; + + r = 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 = NULL; } iova_tree = NULL; return 0; err: +err_cvq_svq: if (i) { qemu_del_net_client(ncs[0]); } -err_svq: +err_svq_features: qemu_close(vdpa_device_fd); return -1;