Received: by 10.213.65.68 with SMTP id h4csp2204288imn; Sun, 8 Apr 2018 22:26:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx49qE9IwhHAYAud1B3q1K/CTVb1KYfZscDXCXiYbkebNKCq2+44nNZ0kn43aRZVRT9SuMe1p X-Received: by 10.98.60.146 with SMTP id b18mr28249637pfk.36.1523251615156; Sun, 08 Apr 2018 22:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523251615; cv=none; d=google.com; s=arc-20160816; b=kIldtnOc2VnFzpz2WgFKR3v9PcHbifDz7OuyDcWdx7PYixpWXDW+Uw/Ax13NZXXLZH S7L9llqsUHj96Wwk2bjZTGRJR59nRTfGFmRWxdiNw6ckWdUxcGrpnoUatAKc+AYit/KA SG5MUA2sv+4v2fUF5/AmLzvR61L7P7t7PlZYNyFmAOC5GD6nEDxLF5RuAWEkVNCVKvdM IF9aAM+jjnWsmoGlOuzrfLqtj5jSpsHlj0+M7f4Zgc2AtYdWJKmruq/mC6BjrxNLNHVu Nl/PLX3FFpOk/75jPQf96c48xfZKSvdhqOIDB44wBP7wcYd3GyD6eo3pW8/+QMSAHoM7 xUvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=S1Gl8mo3By5CAc7C5aQ8/Y5CKpI5g9aSRKp7S6uU5L0=; b=jA4RwyMmDf1mZ6E/eGkUKTGQzbWu73x/jTkicLr/ckoDnli+B7PDLV/7/otETG02PI ejIDYP6YJ2RBnVDUH/R7tApe2ftEFTJRySzxeJ8XigxC0Q8i8bJKxTwJVoeTjwZTpGek Ocm1jiB9uYap1413c7CLwdY5ZhvCe9HxzQqCeLfYYwOzBJAZBeDMGfEHdiYJiwH1CJPl azmtU7blUUMa2Broc4dfFXTLKUhWw0/pQqYNnQNdnIzzmZKAXnbjyFgRbJIEUA/pGsMt JWOc5s76+7dDVcvCLhXfI5Sak1xidPqZP7064CN4fkNY4v6dQHKyckYMxJjMV1/x79Bx v37A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=ieta2MCe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k4-v6si10580478pll.176.2018.04.08.22.26.18; Sun, 08 Apr 2018 22:26:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=ieta2MCe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754979AbeDIAX4 (ORCPT + 99 others); Sun, 8 Apr 2018 20:23:56 -0400 Received: from mail-by2nam03on0115.outbound.protection.outlook.com ([104.47.42.115]:29467 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754916AbeDIAXv (ORCPT ); Sun, 8 Apr 2018 20:23:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=S1Gl8mo3By5CAc7C5aQ8/Y5CKpI5g9aSRKp7S6uU5L0=; b=ieta2MCeIA9nrQ7RLOBmaw103tgooEMaWnyyChuo//AuY3Rf0Ve9rBMMOF071HjsTcVjiOuGMzp5606a4+oB4kD0AlHmUqWHmc74GsEXhWJcE7pdszpN8GhQy8Fvl3UQsADPX8IcmdcmxzZqDldL5W+niztizy68b1Hrih87nzg= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1080.namprd21.prod.outlook.com (52.132.130.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:23:47 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:23:47 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Corinna Vinschen , Jeff Kirsher , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 072/161] igb: Allow to remove administratively set MAC on VFs Thread-Topic: [PATCH AUTOSEL for 4.14 072/161] igb: Allow to remove administratively set MAC on VFs Thread-Index: AQHTz5iZpEykyJyNfUuSfkDg+kmUZQ== Date: Mon, 9 Apr 2018 00:20:44 +0000 Message-ID: <20180409001936.162706-72-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1080;7:KwwSP5QZarbNRXF2IrhdYwslkvAYnsR0lp4YFvb32ybrdBaOBildny+WVT02HyWXP4Ab11xWNha0x17Vux6vLtsa+jdLM34eqc5lskkhvfGdnMImfQ4yDc06jYK2ECZcVUE4D8bHU7rbRiLTkbQ/LTZ4IgQw+PXazZi+bF4txdjSspLxIWv3EbMFI1BPpEqYX/uEKDnfdIL2NkA3URU5kBVnrj3yJwAt2BBY5jy4t91ROfo1OaE9uKa3Xl3FbL7p;20:t9zi9XjKGkDhjfJrnzWxEVZmJ3+PrEChxp7Sn3UlfiegndSrgzaTS5bIFF9XlUUYvR4lC0FMoTB7SysDI+xemsm4LZMJjE1G1LxexfLzBH4gt8TycoODcLCHbpu9UXaeiAFj2CFKAoJPDnH48bVTuAKsj8JGYi1NLNiVg7HxkwI= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: b73e3f96-9e21-40ac-49c0-08d59db02981 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1080; x-ms-traffictypediagnostic: DM5PR2101MB1080: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(20558992708506)(89211679590171)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(3231221)(944501327)(52105095)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB1080;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1080; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(346002)(396003)(39380400002)(366004)(39860400002)(199004)(189003)(2501003)(5250100002)(8936002)(10090500001)(5660300001)(3660700001)(446003)(107886003)(14454004)(36756003)(6436002)(476003)(3280700002)(2616005)(11346002)(4326008)(6666003)(53936002)(6512007)(22452003)(305945005)(10290500003)(316002)(102836004)(2906002)(6116002)(66066001)(6506007)(3846002)(7736002)(486006)(54906003)(110136005)(186003)(72206003)(26005)(1076002)(105586002)(2900100001)(6486002)(97736004)(478600001)(81156014)(81166006)(86612001)(8676002)(106356001)(99286004)(86362001)(76176011)(59450400001)(68736007)(25786009)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1080;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: JmgINEEoWPxIHmWbxTzahkv5E3U8jMA9fNsb1MmpRSX06So3IoFaOyXwBG/2109qG3qX2DIXSA97Ab9jrqRocT4CmScHb7EJIaH63iavjoxfVduko6ucPgMGvMY1y+9GIeeXTfr7Qi3lpXjC3tWZeg3h8MJBcQ7jsoXYNek8LZZf3THYxoEuVj1wUU/dnc1ee5vW5wySEWemPn11o+TtIz8locrW/DjnOjj6YcFF1b7VW5cGWbKT/GHJNQm5nBUAEYzRSbKsbrsBFGHptcHo4hy2v2jBmyHD2ZEcGsdtqKjlfk967o0GkD4LpUENk1kA9ItW8efAQGuMTlwI6JZfMgXuY7QSK1v8BwdDIkwCziXnP00tMEZycuiaqXUzXB6DT2kiuIR7MKBwVBwhjWjK8MdLi4dqmumaVmcdX4Yfmf8= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: b73e3f96-9e21-40ac-49c0-08d59db02981 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:20:44.8784 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1080 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Corinna Vinschen [ Upstream commit 177132df5e45b134c147f419f567a3b56aafaf2b ] Before libvirt modifies the MAC address and vlan tag for an SRIOV VF for use by a virtual machine (either using vfio device assignment or macvtap passthru mode), it saves the current MAC address and vlan tag so that it can reset them to their original value when the guest is done. Libvirt can't leave the VF MAC set to the value used by the now-defunct guest since it may be started again later using a different VF, but it certainly shouldn't just pick any random value, either. So it saves the state of everything prior to using the VF, and resets it to that. The igb driver initializes the MAC addresses of all VFs to 00:00:00:00:00:00, and reports that when asked (via an RTM_GETLINK netlink message, also visible in the list of VFs in the output of "ip link show"). But when libvirt attempts to restore the MAC address back to 00:00:00:00:00:00 (using an RTM_SETLINK netlink message) the kernel responds with "Invalid argument". Forbidding a reset back to the original value leaves the VF MAC at the value set for the now-defunct virtual machine. Especially on a system with NetworkManager enabled, this has very bad consequences, since NetworkManager forces all interfacess to be IFF_UP all the time - if the same virtual machine is restarted using a different VF (or even on a different host), there will be multiple interfaces watching for traffic with the same MAC address. To allow libvirt to revert to the original state, we need a way to remove the administrative set MAC on a VF, to allow normal host operation again, and to reset/overwrite the VF MAC via VF netdev. This patch implements the outlined scenario by allowing to set the VF MAC to 00:00:00:00:00:00 via RTM_SETLINK on the PF. igb_ndo_set_vf_mac resets the IGB_VF_FLAG_PF_SET_MAC flag to 0, so it's possible to reset the VF MAC back to the original value via the VF netdev. Note: Recent patches to libvirt allow for a workaround if the NIC isn't capable of resetting the administrative MAC back to all 0, but in theory the NIC should allow resetting the MAC in the first place. Signed-off-by: Corinna Vinschen Tested-by: Aaron Brown Signed-off-by: Jeff Kirsher Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/igb/igb_main.c | 42 +++++++++++++++++++++++----= ---- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethern= et/intel/igb/igb_main.c index d1a44a84c97e..6ca580cdfd84 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -8373,7 +8373,8 @@ static void igb_rar_set_index(struct igb_adapter *ada= pter, u32 index) =20 /* Indicate to hardware the Address is Valid. */ if (adapter->mac_table[index].state & IGB_MAC_STATE_IN_USE) { - rar_high |=3D E1000_RAH_AV; + if (is_valid_ether_addr(addr)) + rar_high |=3D E1000_RAH_AV; =20 if (hw->mac.type =3D=3D e1000_82575) rar_high |=3D E1000_RAH_POOL_1 * @@ -8411,17 +8412,36 @@ static int igb_set_vf_mac(struct igb_adapter *adapt= er, static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) { struct igb_adapter *adapter =3D netdev_priv(netdev); - if (!is_valid_ether_addr(mac) || (vf >=3D adapter->vfs_allocated_count)) + + if (vf >=3D adapter->vfs_allocated_count) + return -EINVAL; + + /* Setting the VF MAC to 0 reverts the IGB_VF_FLAG_PF_SET_MAC + * flag and allows to overwrite the MAC via VF netdev. This + * is necessary to allow libvirt a way to restore the original + * MAC after unbinding vfio-pci and reloading igbvf after shutting + * down a VM. + */ + if (is_zero_ether_addr(mac)) { + adapter->vf_data[vf].flags &=3D ~IGB_VF_FLAG_PF_SET_MAC; + dev_info(&adapter->pdev->dev, + "remove administratively set MAC on VF %d\n", + vf); + } else if (is_valid_ether_addr(mac)) { + adapter->vf_data[vf].flags |=3D IGB_VF_FLAG_PF_SET_MAC; + dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", + mac, vf); + dev_info(&adapter->pdev->dev, + "Reload the VF driver to make this change effective."); + /* Generate additional warning if PF is down */ + if (test_bit(__IGB_DOWN, &adapter->state)) { + dev_warn(&adapter->pdev->dev, + "The VF MAC address has been set, but the PF device is not up.\n"); + dev_warn(&adapter->pdev->dev, + "Bring the PF device up before attempting to use the VF device.\n"); + } + } else { return -EINVAL; - adapter->vf_data[vf].flags |=3D IGB_VF_FLAG_PF_SET_MAC; - dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf); - dev_info(&adapter->pdev->dev, - "Reload the VF driver to make this change effective."); - if (test_bit(__IGB_DOWN, &adapter->state)) { - dev_warn(&adapter->pdev->dev, - "The VF MAC address has been set, but the PF device is not up.\n"); - dev_warn(&adapter->pdev->dev, - "Bring the PF device up before attempting to use the VF device.\n"); } return igb_set_vf_mac(adapter, vf, mac); } --=20 2.15.1