From patchwork Tue Apr 8 06:12:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 14042213 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 7F60BC369A4 for ; Tue, 8 Apr 2025 06:14:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u22Da-0007Cu-FB; Tue, 08 Apr 2025 02:13:54 -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 1u22DX-0007BZ-Ip for qemu-devel@nongnu.org; Tue, 08 Apr 2025 02:13:51 -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 1u22DV-0001wE-7g for qemu-devel@nongnu.org; Tue, 08 Apr 2025 02:13:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744092827; 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=CDklKuC5L3JF0nZoxxdQAyPqUBGCqrBeyCpp179htLk=; b=g3hF7zMusJ5DmOfiR3fuTVsD3yEZT8qaNtNCTFCQgIEQ8GUyT5k7dUuQRAtkuz/93OwmVX ua4t1VDJ5dHThJ5X+39eiVNofV2fVrpBJNi+vm4DKD8g3b7ipBjCTOHg/fLqckarfS+oKt g56KgnFkZj7LzlL53kNqfeSdRhf6wNE= Received: from mx-prod-mc-01.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-653-ZrCQxjzUODG19RUkM-lmTg-1; Tue, 08 Apr 2025 02:13:41 -0400 X-MC-Unique: ZrCQxjzUODG19RUkM-lmTg-1 X-Mimecast-MFC-AGG-ID: ZrCQxjzUODG19RUkM-lmTg_1744092820 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CFF4E19560B8 for ; Tue, 8 Apr 2025 06:13:39 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.41]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E104C180AF7C; Tue, 8 Apr 2025 06:13:35 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v6 1/4] vhost_vdpa : Add a new parameter to enable check mac address Date: Tue, 8 Apr 2025 14:12:43 +0800 Message-ID: <20250408061327.2590372-2-lulu@redhat.com> In-Reply-To: <20250408061327.2590372-1-lulu@redhat.com> References: <20250408061327.2590372-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.32, 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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. Add a new parameter in qemu cmdline to enable this check, default value is false The usage is: .... -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-0,id=vhost-vdpa0,check-mac=true\ -device virtio-net-pci,netdev=vhost-vdpa0\ .... Signed-off-by: Cindy Lu --- include/net/net.h | 1 + net/vhost-vdpa.c | 4 ++++ qapi/net.json | 5 +++++ 3 files changed, 10 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..ba1da31741 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -1870,6 +1870,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, iova_range, features, shared, errp); if (!ncs[i]) goto err; + + ncs[i]->check_mac = opts->check_mac; } if (has_cvq) { @@ -1882,6 +1884,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, errp); if (!nc) goto err; + + nc->check_mac = opts->check_mac; } return 0; diff --git a/qapi/net.json b/qapi/net.json index 310cc4fd19..a5c70d1df8 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: false) +# # @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 Tue Apr 8 06:12:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 14042210 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 B46A0C3600C for ; Tue, 8 Apr 2025 06:14:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u22Db-0007Di-F4; Tue, 08 Apr 2025 02:13:56 -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 1u22DX-0007BY-IE for qemu-devel@nongnu.org; Tue, 08 Apr 2025 02:13:51 -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 1u22DT-0001vv-FS for qemu-devel@nongnu.org; Tue, 08 Apr 2025 02:13:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744092825; 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=NLjF1iN1UpW3TqnujNqRsnMeCWMXGCyRQljHuUDZUKI=; b=hV/YOTHYq58MXT/KAnhQlOEiuSgZC+CN4nR/7GkBxOzkrQM5rgdIPy5OmTMPWmrundvnXX tbT5FiGyrDDIvJfebHlsGFAABvY9sgj14NNeIuSiiiQ6GHu/9hrt2VjOZ7zySVFybKMMGC 5sab461EYr5/RXhnonxZdC/UDbx8Bwo= 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-616-PCATy8tDN_myHsMTmCKhlg-1; Tue, 08 Apr 2025 02:13:43 -0400 X-MC-Unique: PCATy8tDN_myHsMTmCKhlg-1 X-Mimecast-MFC-AGG-ID: PCATy8tDN_myHsMTmCKhlg_1744092823 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 DD5CC1800361 for ; Tue, 8 Apr 2025 06:13:42 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.41]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6E5D2180B486; Tue, 8 Apr 2025 06:13:40 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v6 2/4] virtio_net: Add the check for vdpa's mac address Date: Tue, 8 Apr 2025 14:12:44 +0800 Message-ID: <20250408061327.2590372-3-lulu@redhat.com> In-Reply-To: <20250408061327.2590372-1-lulu@redhat.com> References: <20250408061327.2590372-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.32, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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 340c6b6422..94ee21d1fc 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3751,12 +3751,43 @@ 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(NetClientState *nc, VirtIONet *n, + MACAddr *cmdline_mac, Error **errp) +{ + struct virtio_net_config hwcfg = {}; + static const MACAddr zero = { .a = { 0, 0, 0, 0, 0, 0 } }; + + vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&hwcfg, ETH_ALEN); + + /* For VDPA device following situations are acceptable: */ + if (memcmp(&hwcfg.mac, &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(&hwcfg.mac, cmdline_mac, sizeof(MACAddr)) == 0)) { + return true; + } + } + error_setg(errp, + "vDPA device's MAC address %02x:%02x:%02x:%02x:%02x:%02x " + "is not the same as the QEMU command line MAC address " + "%02x:%02x:%02x:%02x:%02x:%02x," + "Initialization failed.", + hwcfg.mac[0], hwcfg.mac[1], hwcfg.mac[2], hwcfg.mac[3], + hwcfg.mac[4], hwcfg.mac[5], cmdline_mac->a[0], cmdline_mac->a[1], + cmdline_mac->a[2], cmdline_mac->a[3], cmdline_mac->a[4], + cmdline_mac->a[5]); + + 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) { @@ -3864,6 +3895,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; @@ -3910,7 +3942,13 @@ 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)) { + if (nc->peer->check_mac) { + if (!virtio_net_check_vdpa_mac(nc, n, &macaddr_cmdline, errp)) { + virtio_cleanup(vdev); + return; + } + } struct virtio_net_config netcfg = {}; memcpy(&netcfg.mac, &n->nic_conf.macaddr, ETH_ALEN); vhost_net_set_config(get_vhost_net(nc->peer), From patchwork Tue Apr 8 06:12:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 14042211 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 DB5E7C3DA4A for ; Tue, 8 Apr 2025 06:14:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u22Df-0007Ew-A4; Tue, 08 Apr 2025 02:13:59 -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 1u22DY-0007CG-R4 for qemu-devel@nongnu.org; Tue, 08 Apr 2025 02:13:52 -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 1u22DX-0001wa-As for qemu-devel@nongnu.org; Tue, 08 Apr 2025 02:13:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744092829; 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=rfxzveTaXJtWwFKEeVvLZ0x0ccZfdKdEW4mEoLLWsSA=; b=Tmb8tn/mHTinfoZd/uHVZTe0PuEeaKm9kFjgEjMZjj4095OdC0QmJF+EP3tGViiUDeqHCM 2h7IAc3Y2Zsr0QR/4+GCCmQ5jP/JZTmn5gGoUU7/W+C8esv9Pmac0cWCUc3rOHgQN8aEZ3 pi1jzB/2zBRcLyxt6Uc6USFsQXQ1I0s= 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-669-KFaZtCBIOtSX9-zSRxHXSw-1; Tue, 08 Apr 2025 02:13:47 -0400 X-MC-Unique: KFaZtCBIOtSX9-zSRxHXSw-1 X-Mimecast-MFC-AGG-ID: KFaZtCBIOtSX9-zSRxHXSw_1744092827 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 19A57180025A for ; Tue, 8 Apr 2025 06:13:47 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.41]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4FC75180B486; Tue, 8 Apr 2025 06:13:43 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v6 3/4] virtio_net: Add second acceptable configuration for MAC setup Date: Tue, 8 Apr 2025 14:12:45 +0800 Message-ID: <20250408061327.2590372-4-lulu@redhat.com> In-Reply-To: <20250408061327.2590372-1-lulu@redhat.com> References: <20250408061327.2590372-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.32, 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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. 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 94ee21d1fc..45b63eb9de 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3769,6 +3769,20 @@ static bool virtio_net_check_vdpa_mac(NetClientState *nc, VirtIONet *n, if ((memcmp(&hwcfg.mac, 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 situation, we use the hardware MAC address overwrite + * the QEMU command line address saved in VirtIONet->mac[0]. + * In the following process, QEMU will use this MAC address + * in VirtIONet to complete the initialization. + */ + if (memcmp(cmdline_mac, &zero, sizeof(MACAddr)) == 0) { + /* overwrite the mac address with hardware address */ + memcpy(&n->mac[0], &hwcfg.mac, sizeof(n->mac)); + memcpy(&n->nic_conf.macaddr, &hwcfg.mac, sizeof(n->mac)); + return true; + } } error_setg(errp, "vDPA device's MAC address %02x:%02x:%02x:%02x:%02x:%02x " From patchwork Tue Apr 8 06:12:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 14042212 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 7DE99C3600C for ; Tue, 8 Apr 2025 06:14:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u22EE-0007kt-UL; Tue, 08 Apr 2025 02:14:34 -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 1u22Dy-0007WV-QE for qemu-devel@nongnu.org; Tue, 08 Apr 2025 02:14:23 -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 1u22Dx-0001yV-4N for qemu-devel@nongnu.org; Tue, 08 Apr 2025 02:14:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744092854; 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=cPR42kA0dDxhaaC2cfyBVWCZvGqQEyUACJjLYf9+oxA=; b=QNROP2lGHHyTzBinel9zcBQATxYVwXnyPtINMhFOlzej8ayUfUByFCKIFObU3cMaOfxxBk yKtHr/HhcTm98IHi9o8JdqLcHbZpX1jBmoNFvFAjygaYUHhjCjoI3wZu+iSTTTth9qfhcr pTbrO66wZCfrRxBFWF19+i7TaJ72GtY= 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-626-JIc2fgVPMB2AMgcHB-U2DQ-1; Tue, 08 Apr 2025 02:14:13 -0400 X-MC-Unique: JIc2fgVPMB2AMgcHB-U2DQ-1 X-Mimecast-MFC-AGG-ID: JIc2fgVPMB2AMgcHB-U2DQ_1744092852 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 A4112180035E for ; Tue, 8 Apr 2025 06:14:12 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.41]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BAA0A180AF7C; Tue, 8 Apr 2025 06:14:09 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v6 4/4] virtio_net: Add third acceptable configuration for MAC setup. Date: Tue, 8 Apr 2025 14:12:46 +0800 Message-ID: <20250408061327.2590372-5-lulu@redhat.com> In-Reply-To: <20250408061327.2590372-1-lulu@redhat.com> References: <20250408061327.2590372-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.32, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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. Signed-off-by: Cindy Lu --- hw/net/virtio-net.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 45b63eb9de..6c6bd116f7 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3784,6 +3784,18 @@ static bool virtio_net_check_vdpa_mac(NetClientState *nc, VirtIONet *n, 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(&hwcfg.mac, &zero, sizeof(MACAddr)) == 0) && + (memcmp(cmdline_mac, &zero, sizeof(MACAddr)) == 0)) { + memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac)); + + return true; + } error_setg(errp, "vDPA device's MAC address %02x:%02x:%02x:%02x:%02x:%02x " "is not the same as the QEMU command line MAC address "