Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5441506imm; Tue, 16 Oct 2018 10:16:16 -0700 (PDT) X-Google-Smtp-Source: ACcGV637Tx9wga6lazG/60N7Cs+ZFyIUk3N3t4GWpmuw6jeF50g27Qe5ZCkHout4lONVb6m88i7q X-Received: by 2002:a63:4904:: with SMTP id w4-v6mr20937026pga.303.1539710176749; Tue, 16 Oct 2018 10:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539710176; cv=none; d=google.com; s=arc-20160816; b=FRml/SSUsuXo9Ufvw89Xd3lM5x3z1VTvMgiskxvsN50FDuol+w+7i0mojZCjbgpJGA Yiw+KUNB0htmfOc87YEy0mBm4iFcOS83utuuI+sQ+PXc+fgzdeYjy/CPVtZ45+tMnY6m sov6yn1l2103P7LWrGpGar1Jpp2Wpb3rj9J1F81MDVBhafFGcLezsjZRa4x9LGHhZklT nLltiv+UkiWb3/PxZSOSl5RJ/63/srtwg+Qfx+thdooZCJc9v+JfPWFj6ih6VcnkdCdx zSny3WcohyEkgIwq5FGwuRgx6cedZrfGQqhu8y+IYpnnG9ZfhS2U/uAUNXfJrD9cShYD f28A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=U8FE+sYozMeVuKkw9mildWVh6EbBqL4QQZP70EFNWRg=; b=GbgHJp1pJcRGx1oEElFO3OdUdWcWLFdDVPUkS076VQOFhxIMwe57tdXl5+Smb/FdE/ OcZwPCgwmmpYrKge+Xdce5wEio1Aq3xc2bkC6UI0zCH+pOSS2UkDSqApmX9VgVxHOQMP Uf29I4dJu9CVc2o+3Km3aLlhQGuEyLQxX7gcZcsPwBHZMbR0dA2bxjzTGnpKNEVzczmI FSyiPxsamNP68NWByY9kLt1r7v+oZogeWCpMZzytrCcLGrZ25tw0gNnD3AWDOVQ10ciG lmcUjEkv/p+axsgvEoyTuX3dExF5qo3gR1lV3/JRF+VTfYo0wz84i+MCe7WI94fZ/pHC Xisg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2JKH0tGt; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b1-v6si14806709pgc.319.2018.10.16.10.16.00; Tue, 16 Oct 2018 10:16:16 -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=@kernel.org header.s=default header.b=2JKH0tGt; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729264AbeJQBGV (ORCPT + 99 others); Tue, 16 Oct 2018 21:06:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:50234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727007AbeJQBGU (ORCPT ); Tue, 16 Oct 2018 21:06:20 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4A60C2089E; Tue, 16 Oct 2018 17:14:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539710096; bh=moQYg2qVn14bWam7GWXu497IpuRk2h23vEFweTOI3uQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2JKH0tGt+qSHADp8aZwVqNahI0+5LjdvivbH4jbZTklIn+aafPBvJPKB9xfx+JvRb Yiz14XFMgvRCeLrN5fE1hWSicyiujhiMrQMzWDKrO8+THGgxOWotZumViVsOv1HiTg INEaAdbSkvzogQC5gPzc0XbUF5rmcXcb6psO63c4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephen Hemminger , "David S. Miller" , Sasha Levin Subject: [PATCH 4.18 101/135] hv_netvsc: pair VF based on serial number Date: Tue, 16 Oct 2018 19:05:31 +0200 Message-Id: <20181016170522.303317746@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181016170515.447235311@linuxfoundation.org> References: <20181016170515.447235311@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stephen Hemminger [ Upstream commit 00d7ddba1143623b31bc2c15d18216e2da031b14 ] Matching network device based on MAC address is problematic since a non VF network device can be creted with a duplicate MAC address causing confusion and problems. The VMBus API does provide a serial number that is a better matching method. Signed-off-by: Stephen Hemminger Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/net/hyperv/netvsc.c | 3 ++ drivers/net/hyperv/netvsc_drv.c | 58 ++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 25 deletions(-) --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -1203,6 +1203,9 @@ static void netvsc_send_vf(struct net_de net_device_ctx->vf_alloc = nvmsg->msg.v4_msg.vf_assoc.allocated; net_device_ctx->vf_serial = nvmsg->msg.v4_msg.vf_assoc.serial; + netdev_info(ndev, "VF slot %u %s\n", + net_device_ctx->vf_serial, + net_device_ctx->vf_alloc ? "added" : "removed"); } static void netvsc_receive_inband(struct net_device *ndev, --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -1794,20 +1794,6 @@ out_unlock: rtnl_unlock(); } -static struct net_device *get_netvsc_bymac(const u8 *mac) -{ - struct net_device_context *ndev_ctx; - - list_for_each_entry(ndev_ctx, &netvsc_dev_list, list) { - struct net_device *dev = hv_get_drvdata(ndev_ctx->device_ctx); - - if (ether_addr_equal(mac, dev->perm_addr)) - return dev; - } - - return NULL; -} - static struct net_device *get_netvsc_byref(struct net_device *vf_netdev) { struct net_device_context *net_device_ctx; @@ -1936,26 +1922,48 @@ static void netvsc_vf_setup(struct work_ rtnl_unlock(); } +/* Find netvsc by VMBus serial number. + * The PCI hyperv controller records the serial number as the slot. + */ +static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev) +{ + struct device *parent = vf_netdev->dev.parent; + struct net_device_context *ndev_ctx; + struct pci_dev *pdev; + + if (!parent || !dev_is_pci(parent)) + return NULL; /* not a PCI device */ + + pdev = to_pci_dev(parent); + if (!pdev->slot) { + netdev_notice(vf_netdev, "no PCI slot information\n"); + return NULL; + } + + list_for_each_entry(ndev_ctx, &netvsc_dev_list, list) { + if (!ndev_ctx->vf_alloc) + continue; + + if (ndev_ctx->vf_serial == pdev->slot->number) + return hv_get_drvdata(ndev_ctx->device_ctx); + } + + netdev_notice(vf_netdev, + "no netdev found for slot %u\n", pdev->slot->number); + return NULL; +} + static int netvsc_register_vf(struct net_device *vf_netdev) { - struct net_device *ndev; struct net_device_context *net_device_ctx; - struct device *pdev = vf_netdev->dev.parent; struct netvsc_device *netvsc_dev; + struct net_device *ndev; int ret; if (vf_netdev->addr_len != ETH_ALEN) return NOTIFY_DONE; - if (!pdev || !dev_is_pci(pdev) || dev_is_pf(pdev)) - return NOTIFY_DONE; - - /* - * We will use the MAC address to locate the synthetic interface to - * associate with the VF interface. If we don't find a matching - * synthetic interface, move on. - */ - ndev = get_netvsc_bymac(vf_netdev->perm_addr); + ndev = get_netvsc_byslot(vf_netdev); if (!ndev) return NOTIFY_DONE;