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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F47CC636CC for ; Tue, 31 Jan 2023 09:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231157AbjAaJdo (ORCPT ); Tue, 31 Jan 2023 04:33:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231126AbjAaJdm (ORCPT ); Tue, 31 Jan 2023 04:33:42 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5FF34695 for ; Tue, 31 Jan 2023 01:32:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675157578; 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=DBQzfQxX4tLE3XglxaxRBTAUCUwV8ydRvRoWUBFiIAU=; b=DGSnsjpF8+hAxK9Dp6jp1WVDbiuROwtSAN/W8bvMZhT5RZ82wX12ixVJVS+BNFV2XV1PqQ ikizPHVgho8ASpxYpQfkzGoS11s3yLXccRyNZiD8Qwzx4RaBuvC8oJJY36x00LvTqbLaBE +TEYNUtsKG2LAt5DIWLeXjmyYS7/rXM= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-590-9H32PN2xMOiWHqmD-OwTYg-1; Tue, 31 Jan 2023 04:32:57 -0500 X-MC-Unique: 9H32PN2xMOiWHqmD-OwTYg-1 Received: by mail-qv1-f71.google.com with SMTP id j12-20020a056214032c00b0053782e42278so7511504qvu.5 for ; Tue, 31 Jan 2023 01:32:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DBQzfQxX4tLE3XglxaxRBTAUCUwV8ydRvRoWUBFiIAU=; b=mFw68YEvj/9a7A5kpq1t9dUEOdhrvVr9Ijye8OKFxn/nkmNGGu7vPBD8PtrXAworfL 3dhzym6rh5f58E38nEpboyzn3UbNjwOvG/bxUNFhndavbInnqeKbv5UrZBHT1RdClOS9 zFJzBEAHGFKj6PE5ZBCw8PYFNPqQbkH/FAjyTGscI+60SyHbLXS/n3RXXwhU4b1iM341 thyKdFIMKECNlfqxij7OfYiQHCcI7EmH1+QOz+SYJZlLHCi6Si6KaFD3Y2dYscwkuzLT DzT1RDWm960+Yt83Qx7wauTdym4VaDjj8CYoszGWLuNucKlSHN+JvYPXo9/IfCI7jtYX 1w6w== X-Gm-Message-State: AFqh2kqUZIzcO1A20X0cngH/uupdZcbiTdGM8MyVXHBCfvonh6YShbRm 0kyQBEjkqlId3Lv5WdEO4SRAbBqdUJwXWtFDIhsgfXbuR8WoD/SrnogIYpxUtZEDFJY8TWZobei 3JoY4l4pV77vUSHVQPOIhTNZH X-Received: by 2002:ac8:454e:0:b0:3a8:fdf:8ff8 with SMTP id z14-20020ac8454e000000b003a80fdf8ff8mr71681303qtn.36.1675157576800; Tue, 31 Jan 2023 01:32:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXuFcusn7/Z9gSKN7OA3kQNo5zOuRPcVs4oJi5oHw2k5cV6S5N4fhP31zSpvJcDZwlm/3V5sOg== X-Received: by 2002:ac8:454e:0:b0:3a8:fdf:8ff8 with SMTP id z14-20020ac8454e000000b003a80fdf8ff8mr71681284qtn.36.1675157576463; Tue, 31 Jan 2023 01:32:56 -0800 (PST) Received: from [192.168.100.30] ([82.142.8.70]) by smtp.gmail.com with ESMTPSA id j4-20020a37c244000000b00706a452c074sm6737880qkm.104.2023.01.31.01.32.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 Jan 2023 01:32:55 -0800 (PST) Message-ID: <8bb17aed-d643-2e33-472a-9f237e26e4d1@redhat.com> Date: Tue, 31 Jan 2023 10:32:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH v3 2/2] virtio_net: notify MAC address change on device initialization Content-Language: en-US To: Paolo Abeni , linux-kernel@vger.kernel.org Cc: "David S. Miller" , virtualization@lists.linux-foundation.org, Cindy Lu , "Michael S. Tsirkin" , Eli Cohen , Gautam Dawar , =?UTF-8?Q?Eugenio_P=c3=a9rez?= , Jason Wang , netdev@vger.kernel.org, Parav Pandit References: <20230127204500.51930-1-lvivier@redhat.com> <20230127204500.51930-3-lvivier@redhat.com> <949500bd10077989eb21bd41d6bb1a0de296f9d8.camel@redhat.com> From: Laurent Vivier In-Reply-To: <949500bd10077989eb21bd41d6bb1a0de296f9d8.camel@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/31/23 10:01, Paolo Abeni wrote: > On Fri, 2023-01-27 at 21:45 +0100, Laurent Vivier wrote: >> In virtnet_probe(), if the device doesn't provide a MAC address the >> driver assigns a random one. >> As we modify the MAC address we need to notify the device to allow it >> to update all the related information. >> >> The problem can be seen with vDPA and mlx5_vdpa driver as it doesn't >> assign a MAC address by default. The virtio_net device uses a random >> MAC address (we can see it with "ip link"), but we can't ping a net >> namespace from another one using the virtio-vdpa device because the >> new MAC address has not been provided to the hardware: >> RX packets are dropped since they don't go through the receive filters, >> TX packets go through unaffected. >> >> Signed-off-by: Laurent Vivier >> --- >> drivers/net/virtio_net.c | 20 ++++++++++++++++++++ >> 1 file changed, 20 insertions(+) >> >> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c >> index 7d700f8e545a..704a05f1c279 100644 >> --- a/drivers/net/virtio_net.c >> +++ b/drivers/net/virtio_net.c >> @@ -3806,6 +3806,8 @@ static int virtnet_probe(struct virtio_device *vdev) >> eth_hw_addr_set(dev, addr); >> } else { >> eth_hw_addr_random(dev); >> + dev_info(&vdev->dev, "Assigned random MAC address %pM\n", >> + dev->dev_addr); >> } >> >> /* Set up our device-specific information */ >> @@ -3933,6 +3935,24 @@ static int virtnet_probe(struct virtio_device *vdev) >> >> virtio_device_ready(vdev); >> >> + /* a random MAC address has been assigned, notify the device. >> + * We don't fail probe if VIRTIO_NET_F_CTRL_MAC_ADDR is not there >> + * because many devices work fine without getting MAC explicitly >> + */ >> + if (!virtio_has_feature(vdev, VIRTIO_NET_F_MAC) && >> + virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_MAC_ADDR)) { >> + struct scatterlist sg; >> + >> + sg_init_one(&sg, dev->dev_addr, dev->addr_len); >> + if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC, >> + VIRTIO_NET_CTRL_MAC_ADDR_SET, &sg)) { >> + pr_debug("virtio_net: setting MAC address failed\n"); >> + rtnl_unlock(); >> + err = -EINVAL; >> + goto free_unregister_netdev; > > Since the above is still dealing with device initialization, would it > make sense moving such init step before registering the netdevice? It depends if we can send the command using the control command queue or not. I don't think we can use a vq before virtio_device_ready(). Thanks, Laurent