From patchwork Fri Oct 28 15:19: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: 13023830 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 3CC97C38A02 for ; Fri, 28 Oct 2022 15:21:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooR8u-0003l6-JX; Fri, 28 Oct 2022 11:19:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooR8t-0003kr-82 for qemu-devel@nongnu.org; Fri, 28 Oct 2022 11:19:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooR8r-0003r4-Fg for qemu-devel@nongnu.org; Fri, 28 Oct 2022 11:19:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666970368; 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=pJWfwax7YNhnZW1GKWA5XmDSDsYcoKbWEEwQ6CZiLUA=; b=cxumqir69detqu4YaXJXaNHpFlnM/Vz8Ij9NYHGkOwzLB+OJXrZo0VLEjxwjjHuCaDvriM FGXPnQ7MjdtGfLdla+cdoDsgqQFiI16OQc5YJmRaeBAygMbYfQ6jXto88XaMDJdF8LP+4X xdytlC37ro9Baopk+Or90XfqHEEKrRI= 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-62-vsUYLMDDMxKIg5qZXHMn5g-1; Fri, 28 Oct 2022 11:19:26 -0400 X-MC-Unique: vsUYLMDDMxKIg5qZXHMn5g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E935C3C1023F; Fri, 28 Oct 2022 15:19:25 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id B87D52024CBF; Fri, 28 Oct 2022 15:19:23 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Harpreet Singh Anand , Zhu Lingshan , Stefano Garzarella , Gautam Dawar , Eli Cohen , Parav Pandit , Jason Wang , Si-Wei Liu , "Michael S. Tsirkin" , Liuxiangdong , Laurent Vivier Subject: [PATCH v2 1/3] virtio_net: Modify virtio_net_get_config to early return Date: Fri, 28 Oct 2022 17:19:15 +0200 Message-Id: <20221028151917.260038-2-eperezma@redhat.com> In-Reply-To: <20221028151917.260038-1-eperezma@redhat.com> References: <20221028151917.260038-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.516, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Next patches introduce more code on vhost-vdpa branch, with already have too much indentation. Signed-off-by: Eugenio Pérez Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Michael S. Tsirkin --- hw/net/virtio-net.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index e9f696b4cf..56ff219196 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -158,20 +158,22 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) { ret = vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg, n->config_size); - if (ret != -1) { - /* - * Some NIC/kernel combinations present 0 as the mac address. As - * that is not a legal address, try to proceed with the - * address from the QEMU command line in the hope that the - * address has been configured correctly elsewhere - just not - * reported by the device. - */ - if (memcmp(&netcfg.mac, &zero, sizeof(zero)) == 0) { - info_report("Zero hardware mac address detected. Ignoring."); - memcpy(netcfg.mac, n->mac, ETH_ALEN); - } - memcpy(config, &netcfg, n->config_size); + if (ret == -1) { + return; } + + /* + * Some NIC/kernel combinations present 0 as the mac address. As that + * is not a legal address, try to proceed with the address from the + * QEMU command line in the hope that the address has been configured + * correctly elsewhere - just not reported by the device. + */ + if (memcmp(&netcfg.mac, &zero, sizeof(zero)) == 0) { + info_report("Zero hardware mac address detected. Ignoring."); + memcpy(netcfg.mac, n->mac, ETH_ALEN); + } + + memcpy(config, &netcfg, n->config_size); } } From patchwork Fri Oct 28 15:19: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: 13023828 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 86D76C38A02 for ; Fri, 28 Oct 2022 15:20:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooR8y-0003m7-Ph; Fri, 28 Oct 2022 11:19:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooR8w-0003le-V2 for qemu-devel@nongnu.org; Fri, 28 Oct 2022 11:19:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooR8v-0003tk-Fj for qemu-devel@nongnu.org; Fri, 28 Oct 2022 11:19:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666970373; 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=x3c0NH+cwMHbx78oOj/9GAlwf5kvmomFCCYkkshSQzk=; b=XCI8t0mBL6pWAltKZ9jNX3ymaCDyZpybJCL9jWilB49Fq5t1WAZjrChsherzyB79cygvRR EvNcT46PFvhDmzK62EVJ2LyUx099rwybB4zWssBUSB2IfkAjGZA0NVjQrBN/gG/Zp8a8NM PFV8sE6cWa8SA/yVUh/ouLjgGIhIH18= 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-402-l5PhqeLoOIO1q2c9nRT_4w-1; Fri, 28 Oct 2022 11:19:29 -0400 X-MC-Unique: l5PhqeLoOIO1q2c9nRT_4w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 91B2438145A3; Fri, 28 Oct 2022 15:19:28 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A06220290A5; Fri, 28 Oct 2022 15:19:26 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Harpreet Singh Anand , Zhu Lingshan , Stefano Garzarella , Gautam Dawar , Eli Cohen , Parav Pandit , Jason Wang , Si-Wei Liu , "Michael S. Tsirkin" , Liuxiangdong , Laurent Vivier Subject: [PATCH v2 2/3] virtio_net: Handle _F_STATUS emulation in virtio_net_get_config Date: Fri, 28 Oct 2022 17:19:16 +0200 Message-Id: <20221028151917.260038-3-eperezma@redhat.com> In-Reply-To: <20221028151917.260038-1-eperezma@redhat.com> References: <20221028151917.260038-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.516, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org At this moment this code path is not reached, but vdpa devices can offer VIRTIO_NET_F_STATUS unconditionally. While the guest must assume that link is always up by the standard, qemu will set the status bit to 1 always in this case. This makes little use by itself, but VIRTIO_NET_F_STATUS is needed for the guest to read status bit VIRTIO_NET_F_GUEST_ANNOUNCE, used by feature VIRTIO_NET_F_GUEST_ANNOUNCE. So qemu must emulate status feature in case it needs to emulate the guest announce feature. Signed-off-by: Eugenio Pérez Reviewed-by: Michael S. Tsirkin --- hw/net/virtio-net.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 56ff219196..6d4d75615b 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -156,8 +156,9 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) * disconnect/reconnect a VDPA peer. */ if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) { - ret = vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg, - n->config_size); + struct vhost_net *net = get_vhost_net(nc->peer); + + ret = vhost_net_get_config(net, (uint8_t *)&netcfg, n->config_size); if (ret == -1) { return; } @@ -173,6 +174,12 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) memcpy(netcfg.mac, n->mac, ETH_ALEN); } + if (vdev->guest_features & BIT_ULL(VIRTIO_NET_F_STATUS) && + !(net->dev.features & BIT_ULL(VIRTIO_NET_F_STATUS))) { + /* Emulating link up in qemu */ + netcfg.status |= virtio_tswap16(vdev, VIRTIO_NET_S_LINK_UP); + } + memcpy(config, &netcfg, n->config_size); } } From patchwork Fri Oct 28 15:19:17 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: 13023829 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 F285FECAAA1 for ; Fri, 28 Oct 2022 15:20:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooR90-0003mU-DN; Fri, 28 Oct 2022 11:19:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooR8z-0003mM-HP for qemu-devel@nongnu.org; Fri, 28 Oct 2022 11:19:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooR8y-0003uL-77 for qemu-devel@nongnu.org; Fri, 28 Oct 2022 11:19:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666970375; 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=8XFpQgy7hEPyzc0f/MlRMqPAoore8UmDwJSQHnHIKBk=; b=ZgPCStDpqxchEbhFiYSko/rh2ktvI7J9LmHwKztDYqb4ZFd7Q6o3V4LyZ9knNcFOx6xmjG GpZypZBxHbDEITG4cpwwrNDkZpAZ11yqvPuiOgdbDOjVDLCR4Jo8NunLiXvWejDQks4FLz LMGN513qnryZMWuhTXwBc5HdaQQ2Z7Y= 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-451-Qh_pUAB5PQy2_G7nDPWSWw-1; Fri, 28 Oct 2022 11:19:31 -0400 X-MC-Unique: Qh_pUAB5PQy2_G7nDPWSWw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1128638145A0; Fri, 28 Oct 2022 15:19:31 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id D59622022EA2; Fri, 28 Oct 2022 15:19:28 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Cindy Lu , Harpreet Singh Anand , Zhu Lingshan , Stefano Garzarella , Gautam Dawar , Eli Cohen , Parav Pandit , Jason Wang , Si-Wei Liu , "Michael S. Tsirkin" , Liuxiangdong , Laurent Vivier Subject: [PATCH v2 3/3] vhost_vdpa: move VIRTIO_NET_F_STATUS handling to vhost_net Date: Fri, 28 Oct 2022 17:19:17 +0200 Message-Id: <20221028151917.260038-4-eperezma@redhat.com> In-Reply-To: <20221028151917.260038-1-eperezma@redhat.com> References: <20221028151917.260038-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.516, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Since it is emulated on all vhost backends it makes sense to move it. Although this feature can be emulated by qemu it benefits from information from the device. Ack it as long as the guest ack it. Signed-off-by: Eugenio Pérez Reviewed-by: Michael S. Tsirkin --- hw/net/vhost_net.c | 13 +++++++++++++ net/vhost-vdpa.c | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index d28f8b974b..b533744211 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -127,8 +127,21 @@ int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, void vhost_net_ack_features(struct vhost_net *net, uint64_t features) { + static const int status_feature_bit[] = { + VIRTIO_NET_F_STATUS, + VHOST_INVALID_FEATURE_BIT, + }; + net->dev.acked_features = net->dev.backend_features; vhost_ack_features(&net->dev, vhost_net_get_feature_bits(net), features); + if (net->dev.features & BIT_ULL(VIRTIO_NET_F_STATUS)) { + /* + * If device support _F_STATUS qemu should ack it so it reports link + * status changes. If not supported qemu emulates it reporting an + * always up link. + */ + vhost_ack_features(&net->dev, status_feature_bit, features); + } } uint64_t vhost_net_get_max_queues(VHostNetState *net) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 6d64000202..854b27186c 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -72,7 +72,6 @@ const int vdpa_feature_bits[] = { VIRTIO_NET_F_RSS, VIRTIO_NET_F_HASH_REPORT, VIRTIO_NET_F_GUEST_ANNOUNCE, - VIRTIO_NET_F_STATUS, VHOST_INVALID_FEATURE_BIT };