From patchwork Thu Aug 25 19:03:51 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: 12955147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E266EECAA24 for ; Thu, 25 Aug 2022 19:09:46 +0000 (UTC) Received: from localhost ([::1]:57150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oRIEb-00035X-Q9 for qemu-devel@archiver.kernel.org; Thu, 25 Aug 2022 15:09:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRI9R-00005w-37 for qemu-devel@nongnu.org; Thu, 25 Aug 2022 15:04:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52496) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRI9F-0006Qh-1P for qemu-devel@nongnu.org; Thu, 25 Aug 2022 15:04:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661454249; 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=DDWpdsL5OU9Ybva9CnjAjGSBsvyRnTO2bo8Ew4VpQPs=; b=HKmLdp/JQy7Z1QiddNFYaFFKYs/+3EwPmjPEaVZuyMT3ZL/9ZySm32JANTYXn9hXLhczQt QJ+0SBUY3Lvx4pKx2kHP+NeYj92AEBdLmsaPAh3/HiaAazKJADts5Ph9z80SL6LZW2x1uL tbV+Vi+cDhejX8nYIJG+Pr0shPBQMbo= 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-662-8zSRxrbxN3-z47EOid47EA-1; Thu, 25 Aug 2022 15:04:05 -0400 X-MC-Unique: 8zSRxrbxN3-z47EOid47EA-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 652991C01B43; Thu, 25 Aug 2022 19:04:05 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B92B492C3B; Thu, 25 Aug 2022 19:04:02 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Si-Wei Liu , Parav Pandit , Jason Wang , "Michael S. Tsirkin" , Harpreet Singh Anand , Stefan Hajnoczi , Zhu Lingshan , Cindy Lu , Gautam Dawar , Paolo Bonzini , Eli Cohen , "Gonglei (Arei)" , Liuxiangdong , Laurent Vivier , Stefano Garzarella Subject: [PATCH v3 1/6] vdpa: Make VhostVDPAState cvq_cmd_in_buffer control ack type Date: Thu, 25 Aug 2022 21:03:51 +0200 Message-Id: <20220825190356.317527-2-eperezma@redhat.com> In-Reply-To: <20220825190356.317527-1-eperezma@redhat.com> References: <20220825190356.317527-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This allows to simplify the code. Rename to status while we're at it. Signed-off-by: Eugenio Pérez --- v3: Rename it to status. --- net/vhost-vdpa.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 6ce68fcd3f..535315c1d0 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -35,7 +35,9 @@ typedef struct VhostVDPAState { VHostNetState *vhost_net; /* Control commands shadow buffers */ - void *cvq_cmd_out_buffer, *cvq_cmd_in_buffer; + void *cvq_cmd_out_buffer; + virtio_net_ctrl_ack *status; + bool started; } VhostVDPAState; @@ -158,7 +160,7 @@ static void vhost_vdpa_cleanup(NetClientState *nc) struct vhost_dev *dev = &s->vhost_net->dev; qemu_vfree(s->cvq_cmd_out_buffer); - qemu_vfree(s->cvq_cmd_in_buffer); + qemu_vfree(s->status); if (dev->vq_index + dev->nvqs == dev->vq_index_end) { g_clear_pointer(&s->vhost_vdpa.iova_tree, vhost_iova_tree_delete); } @@ -310,7 +312,7 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) return r; } - r = vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, s->cvq_cmd_in_buffer, + r = vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, s->status, vhost_vdpa_net_cvq_cmd_page_len(), true); if (unlikely(r < 0)) { vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer); @@ -327,7 +329,7 @@ static void vhost_vdpa_net_cvq_stop(NetClientState *nc) if (s->vhost_vdpa.shadow_vqs_enabled) { vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer); - vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_in_buffer); + vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->status); } } @@ -340,7 +342,7 @@ static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s, size_t out_len, .iov_len = out_len, }; const struct iovec in = { - .iov_base = s->cvq_cmd_in_buffer, + .iov_base = s->status, .iov_len = sizeof(virtio_net_ctrl_ack), }; VhostShadowVirtqueue *svq = g_ptr_array_index(s->vhost_vdpa.shadow_vqs, 0); @@ -396,7 +398,7 @@ static int vhost_vdpa_net_load(NetClientState *nc) return dev_written; } - return *((virtio_net_ctrl_ack *)s->cvq_cmd_in_buffer) != VIRTIO_NET_OK; + return *s->status != VIRTIO_NET_OK; } return 0; @@ -491,8 +493,7 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq, goto out; } - memcpy(&status, s->cvq_cmd_in_buffer, sizeof(status)); - if (status != VIRTIO_NET_OK) { + if (*s->status != VIRTIO_NET_OK) { return VIRTIO_NET_ERR; } @@ -549,9 +550,9 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->cvq_cmd_out_buffer = qemu_memalign(qemu_real_host_page_size(), vhost_vdpa_net_cvq_cmd_page_len()); memset(s->cvq_cmd_out_buffer, 0, vhost_vdpa_net_cvq_cmd_page_len()); - s->cvq_cmd_in_buffer = qemu_memalign(qemu_real_host_page_size(), - vhost_vdpa_net_cvq_cmd_page_len()); - memset(s->cvq_cmd_in_buffer, 0, vhost_vdpa_net_cvq_cmd_page_len()); + s->status = qemu_memalign(qemu_real_host_page_size(), + vhost_vdpa_net_cvq_cmd_page_len()); + memset(s->status, 0, vhost_vdpa_net_cvq_cmd_page_len()); s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque = s; From patchwork Thu Aug 25 19:03:52 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: 12955151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C6E11ECAA25 for ; Thu, 25 Aug 2022 19:18:31 +0000 (UTC) Received: from localhost ([::1]:36628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oRIN4-0006KN-M2 for qemu-devel@archiver.kernel.org; Thu, 25 Aug 2022 15:18:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRI9S-00006B-Ez for qemu-devel@nongnu.org; Thu, 25 Aug 2022 15:04:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45209) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRI9E-0006Qo-Uu for qemu-devel@nongnu.org; Thu, 25 Aug 2022 15:04:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661454250; 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=947XT4qKSHAoxN6t9wuk7kVV5CX4QvokhO/FmmUQDNI=; b=dl6ZXGArOClgSYuY2e7tYBgfyavKS6xsOD5FiogdMcrpC2eZ1tVdf6ZBLX6OgkROKWMjLl Sm1rlvfxjyxo5DB3cvWcob/kRujbOFjjI5fLxbVFADZSZ/rkfp3xq/IT7BTD/HJal+8SqB 7MvAiFZKvoQHjPjQYOE2amt5e0DjQcY= 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-96-s6DUDxdnMaGHyXvnvVaQSA-1; Thu, 25 Aug 2022 15:04:09 -0400 X-MC-Unique: s6DUDxdnMaGHyXvnvVaQSA-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 73756101A58E; Thu, 25 Aug 2022 19:04:08 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id A926D492CA2; Thu, 25 Aug 2022 19:04:05 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Si-Wei Liu , Parav Pandit , Jason Wang , "Michael S. Tsirkin" , Harpreet Singh Anand , Stefan Hajnoczi , Zhu Lingshan , Cindy Lu , Gautam Dawar , Paolo Bonzini , Eli Cohen , "Gonglei (Arei)" , Liuxiangdong , Laurent Vivier , Stefano Garzarella Subject: [PATCH v3 2/6] vdpa: extract vhost_vdpa_net_load_mac from vhost_vdpa_net_load Date: Thu, 25 Aug 2022 21:03:52 +0200 Message-Id: <20220825190356.317527-3-eperezma@redhat.com> In-Reply-To: <20220825190356.317527-1-eperezma@redhat.com> References: <20220825190356.317527-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Since there may be many commands we need to issue to load the NIC state, let's split them in individual functions Signed-off-by: Eugenio Pérez --- v2: Add vhost_vdpa_net_load_cmd helper v3: Move ctrl header definition to vhost_vdpa_net_load_cmd --- net/vhost-vdpa.c | 62 +++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 535315c1d0..e799e744cd 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -365,12 +365,47 @@ static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s, size_t out_len, return vhost_svq_poll(svq); } +static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *s, uint8_t class, + uint8_t cmd, const void *data, + size_t data_size) +{ + const struct virtio_net_ctrl_hdr ctrl = { + .class = class, + .cmd = cmd, + }; + + assert(data_size < vhost_vdpa_net_cvq_cmd_page_len() - sizeof(ctrl)); + + memcpy(s->cvq_cmd_out_buffer, &ctrl, sizeof(ctrl)); + memcpy(s->cvq_cmd_out_buffer + sizeof(ctrl), data, data_size); + + return vhost_vdpa_net_cvq_add(s, sizeof(ctrl) + data_size, + sizeof(virtio_net_ctrl_ack)); +} + +static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n) +{ + uint64_t features = n->parent_obj.guest_features; + if (features & BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR)) { + ssize_t dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_MAC, + VIRTIO_NET_CTRL_MAC_ADDR_SET, + n->mac, sizeof(n->mac)); + if (unlikely(dev_written < 0)) { + return dev_written; + } + + return *s->status != VIRTIO_NET_OK; + } + + return 0; +} + static int vhost_vdpa_net_load(NetClientState *nc) { VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); - const struct vhost_vdpa *v = &s->vhost_vdpa; + struct vhost_vdpa *v = &s->vhost_vdpa; const VirtIONet *n; - uint64_t features; + int r; assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); @@ -379,26 +414,9 @@ static int vhost_vdpa_net_load(NetClientState *nc) } n = VIRTIO_NET(v->dev->vdev); - features = n->parent_obj.guest_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, - }; - char *cursor = s->cvq_cmd_out_buffer; - ssize_t dev_written; - - memcpy(cursor, &ctrl, sizeof(ctrl)); - cursor += sizeof(ctrl); - memcpy(cursor, n->mac, sizeof(n->mac)); - - dev_written = vhost_vdpa_net_cvq_add(s, sizeof(ctrl) + sizeof(n->mac), - sizeof(virtio_net_ctrl_ack)); - if (unlikely(dev_written < 0)) { - return dev_written; - } - - return *s->status != VIRTIO_NET_OK; + r = vhost_vdpa_net_load_mac(s, n); + if (unlikely(r < 0)) { + return r; } return 0; From patchwork Thu Aug 25 19:03:53 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: 12955145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id DFAAFECAA24 for ; Thu, 25 Aug 2022 19:09:43 +0000 (UTC) Received: from localhost ([::1]:57152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oRIEY-00035k-L8 for qemu-devel@archiver.kernel.org; Thu, 25 Aug 2022 15:09:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRI9Q-00005v-Up for qemu-devel@nongnu.org; Thu, 25 Aug 2022 15:04:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRI9H-0006RG-N7 for qemu-devel@nongnu.org; Thu, 25 Aug 2022 15:04:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661454255; 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=1bseDS+wOobKWNpI52Cr9QlPEX2vQfsnWTkOXDELPEw=; b=XhaqQr2xA5/7NccJZnDCiK7/SvBJnUoKxiRFJ82EmeDHzgoQzWZkV5jM3chiX/MBTdM4IR gHGFe8QFxVqOFT5Vyqw1XRT8nUzKoKt3JyRmtQfe1V6cFVM45riAAZ8WFKnm4nGdxk2Gmc SYRGq9BEv+QuhulKgOuAeGK4HagdJh4= 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-322-_2RrZVYpOkyjMfGcDAYHow-1; Thu, 25 Aug 2022 15:04:12 -0400 X-MC-Unique: _2RrZVYpOkyjMfGcDAYHow-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 8001E811E76; Thu, 25 Aug 2022 19:04:11 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8CD5492CA2; Thu, 25 Aug 2022 19:04:08 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Si-Wei Liu , Parav Pandit , Jason Wang , "Michael S. Tsirkin" , Harpreet Singh Anand , Stefan Hajnoczi , Zhu Lingshan , Cindy Lu , Gautam Dawar , Paolo Bonzini , Eli Cohen , "Gonglei (Arei)" , Liuxiangdong , Laurent Vivier , Stefano Garzarella Subject: [PATCH v3 3/6] vdpa: Add vhost_vdpa_net_load_mq Date: Thu, 25 Aug 2022 21:03:53 +0200 Message-Id: <20220825190356.317527-4-eperezma@redhat.com> In-Reply-To: <20220825190356.317527-1-eperezma@redhat.com> References: <20220825190356.317527-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Same way as with the MAC, restore the expected number of queues at device's start. Signed-off-by: Eugenio Pérez --- net/vhost-vdpa.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index e799e744cd..3950e4f25d 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -400,6 +400,28 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n) return 0; } +static int vhost_vdpa_net_load_mq(VhostVDPAState *s, + const VirtIONet *n) +{ + struct virtio_net_ctrl_mq mq; + uint64_t features = n->parent_obj.guest_features; + ssize_t dev_written; + + if (!(features & BIT_ULL(VIRTIO_NET_F_MQ))) { + return 0; + } + + mq.virtqueue_pairs = cpu_to_le16(n->curr_queue_pairs); + dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_MQ, + VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET, &mq, + sizeof(mq)); + if (unlikely(dev_written < 0)) { + return dev_written; + } + + return *s->status != VIRTIO_NET_OK; +} + static int vhost_vdpa_net_load(NetClientState *nc) { VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); @@ -418,6 +440,10 @@ static int vhost_vdpa_net_load(NetClientState *nc) if (unlikely(r < 0)) { return r; } + r = vhost_vdpa_net_load_mq(s, n); + if (unlikely(r)) { + return r; + } return 0; } From patchwork Thu Aug 25 19:03:54 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: 12955146 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 4272CECAA25 for ; Thu, 25 Aug 2022 19:09:45 +0000 (UTC) Received: from localhost ([::1]:57148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oRIEY-00034C-Rm for qemu-devel@archiver.kernel.org; Thu, 25 Aug 2022 15:09:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRI9R-00005y-OX for qemu-devel@nongnu.org; Thu, 25 Aug 2022 15:04:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42745) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRI9N-0006RU-H0 for qemu-devel@nongnu.org; Thu, 25 Aug 2022 15:04:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661454258; 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=ssNtCJXhbLSC8S4I9ANaar9bo1LEaJNUSGxPwa2T81w=; b=Xrn/Lkhrz9E728Kcha7Gqj7hHrvRbeZDGy+IPWiODD0Yh8uhfonxTqGY9ko1HlyrYXbzw2 zN1WveaJ7kflzmmVQ+gcnto65J+8GFmP5AUzv/fwXEqcKHdZOW6KLBPC70FxRbTNK5Jhip W2O90jfUW5l+2kfp2sR8YxNuyOUBf6g= 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-540-RW7uFwhIO42GsxrEsXzvbA-1; Thu, 25 Aug 2022 15:04:15 -0400 X-MC-Unique: RW7uFwhIO42GsxrEsXzvbA-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 8C305804191; Thu, 25 Aug 2022 19:04:14 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id C60FD492C3B; Thu, 25 Aug 2022 19:04:11 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Si-Wei Liu , Parav Pandit , Jason Wang , "Michael S. Tsirkin" , Harpreet Singh Anand , Stefan Hajnoczi , Zhu Lingshan , Cindy Lu , Gautam Dawar , Paolo Bonzini , Eli Cohen , "Gonglei (Arei)" , Liuxiangdong , Laurent Vivier , Stefano Garzarella Subject: [PATCH v3 4/6] vdpa: validate MQ CVQ commands Date: Thu, 25 Aug 2022 21:03:54 +0200 Message-Id: <20220825190356.317527-5-eperezma@redhat.com> In-Reply-To: <20220825190356.317527-1-eperezma@redhat.com> References: <20220825190356.317527-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" So we are sure we can update the device model properly before sending to the device. Signed-off-by: Eugenio Pérez --- net/vhost-vdpa.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 3950e4f25d..c6cbe2fb5c 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -486,6 +486,15 @@ static bool vhost_vdpa_net_cvq_validate_cmd(const void *out_buf, size_t len) __func__, ctrl.cmd); }; break; + case VIRTIO_NET_CTRL_MQ: + switch (ctrl.cmd) { + case VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET: + return true; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid mq cmd %u\n", + __func__, ctrl.cmd); + }; + break; default: qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid control class %u\n", __func__, ctrl.class); From patchwork Thu Aug 25 19:03:55 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: 12955150 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B1493ECAA25 for ; Thu, 25 Aug 2022 19:13:28 +0000 (UTC) Received: from localhost ([::1]:52154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oRIIB-0000RM-KP for qemu-devel@archiver.kernel.org; Thu, 25 Aug 2022 15:13:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRI9R-00005z-Qg for qemu-devel@nongnu.org; Thu, 25 Aug 2022 15:04:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:39569) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRI9Q-0006Rb-9J for qemu-devel@nongnu.org; Thu, 25 Aug 2022 15:04:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661454259; 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=xoutYqkapS/nIMsepScl0jd/aod9k3GRqbKF46hCZW0=; b=Pr6LbfevWVtVqshcANWs+4TAZg4L0VFjdmwnFQJrYxs+laiOAsVfUXt7PMOF04jK8RJVRt 4fUgFkfgehZ8ncnjWwrEkMVekXIxHw0EKwX/Qlgja5xKL7JN9+kFuB6cvRJCownMo0FWh7 2ByRf1S7MAWL2S2hO6dKvfaaskOnl3g= 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-453-IEk8g8MFM7W2t7dXG8LUlA-1; Thu, 25 Aug 2022 15:04:18 -0400 X-MC-Unique: IEk8g8MFM7W2t7dXG8LUlA-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 95DE33C025D2; Thu, 25 Aug 2022 19:04:17 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0228492C3B; Thu, 25 Aug 2022 19:04:14 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Si-Wei Liu , Parav Pandit , Jason Wang , "Michael S. Tsirkin" , Harpreet Singh Anand , Stefan Hajnoczi , Zhu Lingshan , Cindy Lu , Gautam Dawar , Paolo Bonzini , Eli Cohen , "Gonglei (Arei)" , Liuxiangdong , Laurent Vivier , Stefano Garzarella Subject: [PATCH v3 5/6] virtio-net: Update virtio-net curr_queue_pairs in vdpa backends Date: Thu, 25 Aug 2022 21:03:55 +0200 Message-Id: <20220825190356.317527-6-eperezma@redhat.com> In-Reply-To: <20220825190356.317527-1-eperezma@redhat.com> References: <20220825190356.317527-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It was returned as error before. Instead of it, simply update the corresponding field so qemu can send it in the migration data. Signed-off-by: Eugenio Pérez --- hw/net/virtio-net.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index dd0d056fde..63a8332cd0 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1412,19 +1412,14 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd, return VIRTIO_NET_ERR; } - /* Avoid changing the number of queue_pairs for vdpa device in - * userspace handler. A future fix is needed to handle the mq - * change in userspace handler with vhost-vdpa. Let's disable - * the mq handling from userspace for now and only allow get - * done through the kernel. Ripples may be seen when falling - * back to userspace, but without doing it qemu process would - * crash on a recursive entry to virtio_net_set_status(). - */ + n->curr_queue_pairs = queue_pairs; if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) { - return VIRTIO_NET_ERR; + /* + * Avoid updating the backend for a vdpa device: We're only interested + * in updating the device model queues. + */ + return VIRTIO_NET_OK; } - - n->curr_queue_pairs = queue_pairs; /* stop the backend before changing the number of queue_pairs to avoid handling a * disabled queue */ virtio_net_set_status(vdev, vdev->status); From patchwork Thu Aug 25 19:03:56 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: 12955144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 0359BECAA25 for ; Thu, 25 Aug 2022 19:09:39 +0000 (UTC) Received: from localhost ([::1]:57146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oRIEU-0002wF-H1 for qemu-devel@archiver.kernel.org; Thu, 25 Aug 2022 15:09:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRI9X-00006j-DX for qemu-devel@nongnu.org; Thu, 25 Aug 2022 15:04:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:40938) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRI9S-0006Rx-13 for qemu-devel@nongnu.org; Thu, 25 Aug 2022 15:04:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661454265; 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=0EiC9qsa92qPMgZCmBJglnW5RyionM1aBUgNqKB3yf0=; b=eXT6YK3vAMDTilL7A6T75PHexLqqqZr73Mq2AeourPxzfacxT5wUiejX0q1TsPt5z5qsx7 /ceLG+pJ+Pq3zeDoTjYbj4CC/nQ/5GMG7G8KXZl9F6g0eDuiO6tfzniT5PHEYvVIzUdxyb 41Nm8o/ca3/wQP+VN6Nfnq7RnrWoMnE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-629-2PUCCOzKOx2Iq0F55r7kmw-1; Thu, 25 Aug 2022 15:04:21 -0400 X-MC-Unique: 2PUCCOzKOx2Iq0F55r7kmw-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 A327E85A589; Thu, 25 Aug 2022 19:04:20 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id D9597492C3B; Thu, 25 Aug 2022 19:04:17 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cornelia Huck , Si-Wei Liu , Parav Pandit , Jason Wang , "Michael S. Tsirkin" , Harpreet Singh Anand , Stefan Hajnoczi , Zhu Lingshan , Cindy Lu , Gautam Dawar , Paolo Bonzini , Eli Cohen , "Gonglei (Arei)" , Liuxiangdong , Laurent Vivier , Stefano Garzarella Subject: [PATCH v3 6/6] vdpa: Allow MQ feature in SVQ Date: Thu, 25 Aug 2022 21:03:56 +0200 Message-Id: <20220825190356.317527-7-eperezma@redhat.com> In-Reply-To: <20220825190356.317527-1-eperezma@redhat.com> References: <20220825190356.317527-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Finally enable SVQ with MQ feature. Signed-off-by: Eugenio Pérez --- net/vhost-vdpa.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index c6cbe2fb5c..4bc3fd01a8 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -94,6 +94,7 @@ static const uint64_t vdpa_svq_device_features = BIT_ULL(VIRTIO_NET_F_MRG_RXBUF) | BIT_ULL(VIRTIO_NET_F_STATUS) | BIT_ULL(VIRTIO_NET_F_CTRL_VQ) | + BIT_ULL(VIRTIO_NET_F_MQ) | BIT_ULL(VIRTIO_F_ANY_LAYOUT) | BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR) | BIT_ULL(VIRTIO_NET_F_RSC_EXT) |