Received: by 10.213.65.68 with SMTP id h4csp2151193imn; Sun, 8 Apr 2018 21:02:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+hby/sfqxOXm9P8VZO2eh70h8A5dkDGxLd2kMDIFWYYczOIPpPe7nmvDHZUkW4RWtZaIMd X-Received: by 2002:a17:902:b786:: with SMTP id e6-v6mr2384168pls.246.1523246527680; Sun, 08 Apr 2018 21:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523246527; cv=none; d=google.com; s=arc-20160816; b=jdbrDqPmZwwGaRJqcbdU0CsX5QQtoQ9I20czB154A18cG7LijI25x1lqKa9/DNWbb2 dTmivMKydV6kdatQ4y0oEjkhh0yAvpZ6uaIvJuVxspzX5Ce4f3Ivln6iHBxUfyi75nv/ Q/WhLLFO/S6bLAYwDiNB5O0LBXC7zpSVpRu8jyjRgRd94Gv7qYyQbLTTNPbJosBKd4DW L1ngXGkm0RW2auLm/2A2zBkOv/e2jYG4UUSRQFuWI02J9xxq8ZDSgO/ouXZJh1UMIsm9 j9m++c0HacqByeMfsWhomIRi3SqDh7NMJEODbddMt6uMFFn/sC0rihK7Z8DCs4lyrf61 6fbw== 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=IvyQm4+lXV2qFY9KOOWwhu3BcfIySIk+TC4BZwMQ0vo=; b=xlvqOmnkWqitnoyBKv4O7U6mPmlyvGz8gaVyJNfPX0wnX5O86/irvmt/PJx2etk2mD nha1GGXhHekbZ0R25Q7Swoc2AGslBHpD0sQ2ywDFXC1XAPFEj4zf67rD3/4ZYSaBDPzt 7cabH2o8YUXQHKVZxPNMcI3RjynGilcajHfwl88Q6EKv7+XU7Kuq9Mca4G6UgautpIub EibOTlHof1W0s2Naiiar1qLwiarArhO3oygu6nBEgHxeasfBB0Rwv3kqelaPan3TeMYv qLp4F9LTm95d3nHMIzlkndFO4JN1EkdJP11QvajDV1AkBwRvomQiUrf8llx2yw/VTDiU BJsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=d5BrOOJO; 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 l8-v6si13978645pln.484.2018.04.08.21.01.30; Sun, 08 Apr 2018 21:02:07 -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=d5BrOOJO; 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 S1754445AbeDID4P (ORCPT + 99 others); Sun, 8 Apr 2018 23:56:15 -0400 Received: from mail-bn3nam01on0092.outbound.protection.outlook.com ([104.47.33.92]:62923 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753651AbeDIASt (ORCPT ); Sun, 8 Apr 2018 20:18:49 -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=IvyQm4+lXV2qFY9KOOWwhu3BcfIySIk+TC4BZwMQ0vo=; b=d5BrOOJObNStfLmaTevVYjDCu4f7tS/zIZ/TBasf16E1BADyHrmgl6cBCpaUHEds86cbfX/grFwQ+606Qeg1hNpftdHnCZqeTU6yIWZAhqjXPKodKpS/EQixdxoSotE7kJrHIxsT/R4HzAZueTWsxASE3WqkytN0CA/XOi0nKv4= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1128.namprd21.prod.outlook.com (52.132.133.20) 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:18:41 +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:18:41 +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.15 086/189] igb: Allow to remove administratively set MAC on VFs Thread-Topic: [PATCH AUTOSEL for 4.15 086/189] igb: Allow to remove administratively set MAC on VFs Thread-Index: AQHTz5gz+Oyql4m4KUyysA6r22OHHA== Date: Mon, 9 Apr 2018 00:17:53 +0000 Message-ID: <20180409001637.162453-86-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-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;DM5PR2101MB1128;7:uqfyf2e3SMrQckUFfUKsuJSsbqjLhP5D/YQMysB90HY9eOIThKpKRte1oNybubnPmAPIcOQ/Kb33ilzq+wbszBtFMNZu+ui/i84RkglZjVyetH98D8B3B0qUvT/BHglhCT4xo2KSG+zXLd+6ferCHIs0778C8vEYqD+Y/zG5FipstfmRRWpGwSTG6Hh/QyxETZKLv8lbG0z0JivyNiNyo/be4g8yB7oL7mCGwOPLzw9b5YxetP89kAvI3MnAxe5q;20:1DwAs+m85A3QLU0uj3w1gv/iwPGsbSoNYJee95LJIdtmHfrmkmNuvs2awL/2Xm1evELunMiZeDrisvANe38SrdTHuwQff8rTP2cNvOR6/wyulDfDNBPdcWjmEcMXfmDXWupc76w429Qh81lwchqGpkFzUK4jjI9hgr5YuvCqrK0= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 4a7698f4-495d-4937-0b8e-08d59daf72fc x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1128; x-ms-traffictypediagnostic: DM5PR2101MB1128: 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)(3231221)(944501327)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1128;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1128; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(396003)(376002)(366004)(39380400002)(199004)(189003)(66066001)(86362001)(59450400001)(3660700001)(3280700002)(2900100001)(25786009)(36756003)(6506007)(76176011)(2906002)(6486002)(86612001)(99286004)(102836004)(1076002)(7736002)(97736004)(2616005)(446003)(486006)(11346002)(476003)(26005)(305945005)(6666003)(6512007)(4326008)(107886003)(478600001)(6436002)(5660300001)(10290500003)(5250100002)(22452003)(316002)(105586002)(186003)(8676002)(110136005)(54906003)(72206003)(53936002)(2501003)(68736007)(14454004)(6116002)(8936002)(3846002)(81156014)(10090500001)(106356001)(81166006)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1128;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: vYW/smTqAiRYb6gE/03tpa306k4oVzmLzT+L0lEbK8zuPNaY6CwOdvFRGnzhCmVUpbCHWC1h2ifRuCdh6XHBaPdnBKEJtGHYXk9oenHO6s9030T5kDPlLIe9PHXJNoB252WoA/DNfR0jAeaavzcmepWvowj0lo4Jn0HbIt4j7rZg8vApo4sXuVLdON0SpPqRR4kgzOpZ+FUzPBfl66X9jBtq4e3pejQ4RSPw4v6FnUVla/tmqMBNfoUsYPUhhidOr+KaDfLPCrpZ+H7s3pCpm1iW2IsBOwwxWxdoQorScFICzAeKYrfjTIJZ7CS+HpB00XEIzsQl1r3hY+jrYCUC/jTUXRxXCFnplhNCxTl6NEX6QinSSdcKviyc6+74W33H8H70hx5Vh4Z6Jca7Mlhz+/MVVTxgPK/g5E+6tjsRDqg= 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: 4a7698f4-495d-4937-0b8e-08d59daf72fc X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:17:53.5699 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1128 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 c69a5b3ae8c8..13dd7d2d90fe 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -8718,7 +8718,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 * @@ -8756,17 +8757,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