From patchwork Thu Apr 17 10:24:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 14055251 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 4AA22C369C2 for ; Thu, 17 Apr 2025 10:26:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u5MRF-00065c-A4; Thu, 17 Apr 2025 06:25:45 -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 1u5MRB-00064l-AJ for qemu-devel@nongnu.org; Thu, 17 Apr 2025 06:25:41 -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 1u5MR8-000751-4E for qemu-devel@nongnu.org; Thu, 17 Apr 2025 06:25:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744885534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bQTfnMByU8MnkTwicEltHqnzuHODFDc3zPKI3tdjsME=; b=bXNtHm/TBu7Vr6yr8NQdV82+Of3fFFyfyP0Q3sLZS/2zb7+KDZsbFOQZ6x0Odl1hbOrxEN Ce7kYJlhMpk/02EA8VVtZS59GPXN6mFuFpEfn3hoNLmRPEJ2oE3BSjO+OtTfKynBN0fNl5 UZ7XzQ5RMvfUmUE1zuDXL8q7m2r+k1g= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-278-R1egKHK2M2StLf-5ebdLIg-1; Thu, 17 Apr 2025 06:25:33 -0400 X-MC-Unique: R1egKHK2M2StLf-5ebdLIg-1 X-Mimecast-MFC-AGG-ID: R1egKHK2M2StLf-5ebdLIg_1744885532 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BC0C018004A7 for ; Thu, 17 Apr 2025 10:25:32 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.10]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3D9161800965; Thu, 17 Apr 2025 10:25:29 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v7 1/4] vhost_vdpa : Add a new parameter to enable check mac address Date: Thu, 17 Apr 2025 18:24:15 +0800 Message-ID: <20250417102522.4125379-2-lulu@redhat.com> In-Reply-To: <20250417102522.4125379-1-lulu@redhat.com> References: <20250417102522.4125379-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass client-ip=170.10.133.124; envelope-from=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org When using a VDPA device, it's important to ensure that the MAC address is correctly set. This patch adds a new QEMU command line parameter to enable MAC address verification, which is enabled by default. Usage example: .... -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-0,id=vhost-vdpa0,check-mac=true\ -device virtio-net-pci,netdev=vhost-vdpa0\ .... To disable this check: .... -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-0,id=vhost-vdpa0,check-mac=false\ -device virtio-net-pci,netdev=vhost-vdpa0\ .... Signed-off-by: Cindy Lu Tested-by: Lei Yang --- include/net/net.h | 1 + net/vhost-vdpa.c | 5 +++++ qapi/net.json | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index cdd5b109b0..fac1951b6e 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -112,6 +112,7 @@ struct NetClientState { bool is_netdev; bool do_not_pad; /* do not pad to the minimum ethernet frame length */ bool is_datapath; + bool check_mac; QTAILQ_HEAD(, NetFilterState) filters; }; diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 7ca8b46eee..7dbe6cf65c 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -1871,6 +1871,11 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, if (!ncs[i]) goto err; } + /* Enable the mac check by default */ + if (opts->has_check_mac) + ncs[0]->check_mac = opts->check_mac; + else + ncs[0]->check_mac = true; if (has_cvq) { VhostVDPAState *s0 = DO_UPCAST(VhostVDPAState, nc, ncs[0]); diff --git a/qapi/net.json b/qapi/net.json index 310cc4fd19..0607c83833 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -510,6 +510,10 @@ # @queues: number of queues to be created for multiqueue vhost-vdpa # (default: 1) # +# @check-mac: Enable the check for whether the device's MAC address +# and the MAC in QEMU command line are acceptable for booting. +# (default: true) +# # @x-svq: Start device with (experimental) shadow virtqueue. (Since # 7.1) (default: false) # @@ -524,6 +528,7 @@ '*vhostdev': 'str', '*vhostfd': 'str', '*queues': 'int', + '*check-mac': 'bool', '*x-svq': {'type': 'bool', 'features' : [ 'unstable'] } } } ## From patchwork Thu Apr 17 10:24:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 14055249 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 E3DFDC369B2 for ; Thu, 17 Apr 2025 10:26:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u5MRF-00065x-PM; Thu, 17 Apr 2025 06:25:45 -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 1u5MRE-00065N-4S for qemu-devel@nongnu.org; Thu, 17 Apr 2025 06:25:44 -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 1u5MRB-00075i-Tn for qemu-devel@nongnu.org; Thu, 17 Apr 2025 06:25:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744885539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EPvdBPxtUAgTddV1yewBvjESBsX9d9esW3wgEE0sHAI=; b=BcHKdIPr51eN4F7ulOQDJ1w+yuR42hmMrqUJDPSPwZlkiRGmM2Y/Z6fnqtnnhzif57HJaV oBotz6vt81lLHLhvXKnMHYU1maPYs7AspsFgiKRqlcCMuDEZh4GyBc0+AMJTJ/Z2Xoyz4Q C3KsbW3QufeoWqnd/H40zhqJ4lgKjxk= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-TJwIr8l1Pj-ycZgw3pzDvQ-1; Thu, 17 Apr 2025 06:25:38 -0400 X-MC-Unique: TJwIr8l1Pj-ycZgw3pzDvQ-1 X-Mimecast-MFC-AGG-ID: TJwIr8l1Pj-ycZgw3pzDvQ_1744885537 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 86F591800876 for ; Thu, 17 Apr 2025 10:25:37 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.10]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5C2D9180045B; Thu, 17 Apr 2025 10:25:33 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v7 2/4] virtio_net: Add the check for vdpa's mac address Date: Thu, 17 Apr 2025 18:24:16 +0800 Message-ID: <20250417102522.4125379-3-lulu@redhat.com> In-Reply-To: <20250417102522.4125379-1-lulu@redhat.com> References: <20250417102522.4125379-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass client-ip=170.10.129.124; envelope-from=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org When using a VDPA device, it is important to ensure that the MAC address is correctly set. The MAC address in the hardware should match the MAC address from the QEMU command line. This is a recommended configuration and will allow the system to boot. Signed-off-by: Cindy Lu --- hw/net/virtio-net.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index bd37651dab..0b6a4e5634 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3744,12 +3744,29 @@ static bool failover_hide_primary_device(DeviceListener *listener, /* failover_primary_hidden is set during feature negotiation */ return qatomic_read(&n->failover_primary_hidden); } +static bool virtio_net_check_vdpa_mac(VirtIONet *n, uint8_t *hwmac, + MACAddr *cmdline_mac, Error **errp) +{ + static const MACAddr zero = { .a = { 0, 0, 0, 0, 0, 0 } }; + + if (memcmp(hwmac, &zero, sizeof(MACAddr)) != 0) { + /* + * 1. The hardware MAC address is the same as the QEMU command line MAC + * address, and both of them are not 0. + */ + if ((memcmp(hwmac, cmdline_mac, sizeof(MACAddr)) == 0)) { + return true; + } + } + return false; +} static void virtio_net_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIONet *n = VIRTIO_NET(dev); NetClientState *nc; + MACAddr macaddr_cmdline; int i; if (n->net_conf.mtu) { @@ -3857,6 +3874,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) virtio_net_add_queue(n, 0); n->ctrl_vq = virtio_add_queue(vdev, 64, virtio_net_handle_ctrl); + memcpy(&macaddr_cmdline, &n->nic_conf.macaddr, sizeof(n->mac)); qemu_macaddr_default_if_unset(&n->nic_conf.macaddr); memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac)); n->status = VIRTIO_NET_S_LINK_UP; @@ -3903,8 +3921,28 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) nc = qemu_get_queue(n->nic); nc->rxfilter_notify_enabled = 1; - if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) { + if (nc->peer && (nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA)) { + struct virtio_net_config netcfg = {}; + if (nc->peer->check_mac) { + vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg, + ETH_ALEN); + if (!virtio_net_check_vdpa_mac(n, (uint8_t *)&netcfg.mac, + &macaddr_cmdline, errp)) { + error_setg(errp, "vDPA device's MAC address " + "%02x:%02x:%02x:%02x:%02x:%02x " + "is not same as the QEMU command line MAC address" + "%02x:%02x:%02x:%02x:%02x:%02x," + "Initialization failed.", + netcfg.mac[0], netcfg.mac[1], netcfg.mac[2], + netcfg.mac[3], netcfg.mac[4], netcfg.mac[5], + macaddr_cmdline.a[0], macaddr_cmdline.a[1], + macaddr_cmdline.a[2], macaddr_cmdline.a[3], + macaddr_cmdline.a[4], macaddr_cmdline.a[5]); + virtio_cleanup(vdev); + return; + } + } memcpy(&netcfg.mac, &n->nic_conf.macaddr, ETH_ALEN); vhost_net_set_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg, 0, ETH_ALEN, VHOST_SET_CONFIG_TYPE_FRONTEND); From patchwork Thu Apr 17 10:24:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 14055250 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 23F51C369B2 for ; Thu, 17 Apr 2025 10:26:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u5MRI-00066j-4c; Thu, 17 Apr 2025 06:25:48 -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 1u5MRF-00065v-Jx for qemu-devel@nongnu.org; Thu, 17 Apr 2025 06:25:45 -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 1u5MRD-00076V-Qj for qemu-devel@nongnu.org; Thu, 17 Apr 2025 06:25:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744885542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x0ABQxPb+sin1yUjY1rlXFm6+xfXpzGjs6uHJFTaCKM=; b=KbcQmLgy5Gqb0+TOY4VeVT2+JOs92Qivx137zeqnOpmsXUvERIn8DGIZlckWfw7jFEwt7A CS/UdK2IoWvnULFI9o7v+94w1j8NSa96iZqLw+8VHCjUa8oeX16ARJu6RDOx2zPmRgeYD4 dpOyUsAPu1vBRVbN52xfMQFGL+9CbXk= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-N4q65OtTPFGcNXiRmCsy0Q-1; Thu, 17 Apr 2025 06:25:41 -0400 X-MC-Unique: N4q65OtTPFGcNXiRmCsy0Q-1 X-Mimecast-MFC-AGG-ID: N4q65OtTPFGcNXiRmCsy0Q_1744885540 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C3DBC19560BB for ; Thu, 17 Apr 2025 10:25:40 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.10]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 46255180045B; Thu, 17 Apr 2025 10:25:37 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v7 3/4] virtio_net: Add second acceptable configuration for MAC setup Date: Thu, 17 Apr 2025 18:24:17 +0800 Message-ID: <20250417102522.4125379-4-lulu@redhat.com> In-Reply-To: <20250417102522.4125379-1-lulu@redhat.com> References: <20250417102522.4125379-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass client-ip=170.10.129.124; envelope-from=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org For VDPA devices, Allow configurations where the hardware MAC address is non-zero while the MAC address in the QEMU command line is zero. In this case, QEMU will use the hardware MAC address from the device. Signed-off-by: Cindy Lu --- hw/net/virtio-net.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 0b6a4e5634..808a2fe4d4 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3757,6 +3757,20 @@ static bool virtio_net_check_vdpa_mac(VirtIONet *n, uint8_t *hwmac, if ((memcmp(hwmac, cmdline_mac, sizeof(MACAddr)) == 0)) { return true; } + /* + * 2. The hardware MAC address is NOT 0 and the MAC address in + * the QEMU command line is 0. + * In this case,qemu will use the hardware MAC address overwrite + * the QEMU command line MAC address saved in VirtIONet->mac[0]. + * In the following process, QEMU will use this MAC address + * to complete the initialization. + */ + if (memcmp(cmdline_mac, &zero, sizeof(MACAddr)) == 0) { + /* overwrite the mac address with hardware address */ + memcpy(&n->mac[0], hwmac, sizeof(n->mac)); + memcpy(&n->nic_conf.macaddr, hwmac, sizeof(n->mac)); + return true; + } } return false; From patchwork Thu Apr 17 10:24:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 14055248 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 331BAC369C2 for ; Thu, 17 Apr 2025 10:26:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u5MRk-0006EU-66; Thu, 17 Apr 2025 06:26:16 -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 1u5MRi-00069e-Rb for qemu-devel@nongnu.org; Thu, 17 Apr 2025 06:26:14 -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 1u5MRc-0007A4-LT for qemu-devel@nongnu.org; Thu, 17 Apr 2025 06:26:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744885567; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s/9g1gTYzUp0WwIT1QPguWr2mKg87EJXHIh8QUSRRtg=; b=SEn1xqg+7JTkYaEddRmjy7Mf58FIeRPj9dzH0T8wP1X7ww4vpFG34uP8Xtbq7wmycCYW/u MobRuh/AU5J6QzGepCyagJRxA19vlDrsIi+0FFpW93omKIoa+ReamLj2lz/mZaXsQiEeBz ZMHm58t/O0BzH3I3TuscdTJnn5zOc4Q= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-126-0-ZtXvF-PCCJFX8zWLHxVw-1; Thu, 17 Apr 2025 06:26:06 -0400 X-MC-Unique: 0-ZtXvF-PCCJFX8zWLHxVw-1 X-Mimecast-MFC-AGG-ID: 0-ZtXvF-PCCJFX8zWLHxVw_1744885565 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C90E7180034A for ; Thu, 17 Apr 2025 10:26:05 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.10]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 40263180045B; Thu, 17 Apr 2025 10:26:02 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v7 4/4] virtio_net: Add third acceptable configuration for MAC setup. Date: Thu, 17 Apr 2025 18:24:18 +0800 Message-ID: <20250417102522.4125379-5-lulu@redhat.com> In-Reply-To: <20250417102522.4125379-1-lulu@redhat.com> References: <20250417102522.4125379-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass client-ip=170.10.133.124; envelope-from=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org For VDPA devices, Allow configurations where both the hardware MAC address and QEMU command line MAC address are zero. In this case, QEMU will automatically generate a random MAC address and assign it to the hardware, and the VM will use this random MAC address as its MAC address. Signed-off-by: Cindy Lu --- hw/net/virtio-net.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 808a2fe4d4..2d4ac20ee0 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3772,7 +3772,18 @@ static bool virtio_net_check_vdpa_mac(VirtIONet *n, uint8_t *hwmac, return true; } } + /* + * 3. The hardware MAC address is 0, + * and the MAC address in the QEMU command line is also 0. + * In this situation, QEMU generates a random MAC address and + * uses CVQ/set_config to assign it to the device. + */ + if ((memcmp(hwmac, &zero, sizeof(MACAddr)) == 0) && + (memcmp(cmdline_mac, &zero, sizeof(MACAddr)) == 0)) { + memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac)); + return true; + } return false; } static void virtio_net_device_realize(DeviceState *dev, Error **errp)