From nobody Tue Nov 26 17:35:37 2024 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11020082.outbound.protection.outlook.com [52.101.56.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86CC42040B2; Fri, 18 Oct 2024 18:25:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.56.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275939; cv=fail; b=YGUEW9z5U/Iotw8UoFmPKwV+767XdfOUetuzPxuXtjyf846M1g4WR6r0xVMd5umICvkpvQTjy+ykKH+HFoGFxuFeuOTQCYJJ5Pop/Dc0drC12RKBfipSAcygzPtAYhMTfwWEUt1RGDqtZhbKUMzTx6YW09HX4BgrPGtt/sfqo5o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275939; c=relaxed/simple; bh=c6DB9xS7MRcLqZIxINVRaAbmf/GxDb/O6l8n5lOkfvs=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=QIm7xlb8zhlSvYFkfECHoVdwEtkuk/WE3hVUOpyG0S8upcDrabYusYHgBJrT6UPk3nTa08cwzrI9vCn29opaejZTH/SFvh4dd8Xoj3qhoswF3HwNwO6pbp7kMpXyVOk1nvIGRQOtsEYo3FQQ4KVEYSgZx79HmvANXj2TYwT7Cws= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=microsoft.com; dkim=pass (1024-bit key) header.d=microsoft.com header.i=@microsoft.com header.b=WsDnDGek; arc=fail smtp.client-ip=52.101.56.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=microsoft.com header.i=@microsoft.com header.b="WsDnDGek" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wsGag66tGwIXGB286rLt0roU58QOXagXAd5RrC182FiFqV0T4MFu/DFM68hQ4XwLueGjgKs89ScVMtQHPoj0abESNxco0VEBkkCzLBXQ2Bbvsm+/CJ0FBsJGfA8fLfN/ieGcgD0OjUwVj6oUw5Z7cEaevLEGSeQGFgXLkgUu2wUUfuBX2JzuOV1pNaQZor2XAf9/JozmBX6omPzebG+Ls4uhD88WuHKjg2udXomWfxjNremHodPaYHQRYXaEE2clc8pO9uaR55JNszSs6EfOtTrfB0iJgZxcqPZFK8T9IyyLCWBzzkvF/ckDZHTTqBHJBF+EYMFWhYvSgOCk4c0Lmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=il99dkPd0kNT29Ru6xUAHWsS81Z3wRoyekGNbgkUCWc=; b=u8zzQ7n40ZWOhB9nLLvYWC/ooNeNi1/NIE7FjPnDhsJGPZI4DR7Mp91n944fA41yoBLZS0+3+2ttGNgMtWb86kwwjBHQ+svaXMjfX3tAG4mHWIGDlIeJfcR4fLXbdHwdTQfA+kZPW9kR4YY2xxE+k8tB29jbtq9aCKgMUHzVMpVX7bOuh9q4j65U+m3MXGG4harz4z6LSmtKdpZys8vg0NB7ZxjUWWdFToMoSwp8R9Bp2Urf2Gq2ABq9tulgDAPUtKaar+35FpGR+ti+ufQFa+hzekC2DPRNW/DWjCY7MlxrkY9x8FM82bu1OTVSV/TDUdpHJXGno0D6mGeVuMJGTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=il99dkPd0kNT29Ru6xUAHWsS81Z3wRoyekGNbgkUCWc=; b=WsDnDGekYYjrFMIxi9baWx04X0YjlQf+pg0vLbqSSRWrk6lTmQsUR1PyFKzKFcukhSTHB579NGmtbw88nvIZzIawtjIWusS099c03af8SIGbSLk7MXlgNqqRbhG6KFwNorNCgW3MJGAV0pgz9GVtNZfLOwsWp9etluFxszfbU5o= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BY5PR21MB1443.namprd21.prod.outlook.com (2603:10b6:a03:21f::18) by BY1PR21MB3893.namprd21.prod.outlook.com (2603:10b6:a03:52d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.11; Fri, 18 Oct 2024 18:25:35 +0000 Received: from BY5PR21MB1443.namprd21.prod.outlook.com ([fe80::2c5a:1a34:2c8d:48ef]) by BY5PR21MB1443.namprd21.prod.outlook.com ([fe80::2c5a:1a34:2c8d:48ef%7]) with mapi id 15.20.8093.011; Fri, 18 Oct 2024 18:25:35 +0000 From: Haiyang Zhang To: linux-hyperv@vger.kernel.org, netdev@vger.kernel.org Cc: haiyangz@microsoft.com, kys@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, stephen@networkplumber.org, davem@davemloft.net, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH net,v3] hv_netvsc: Fix VF namespace also in synthetic NIC NETDEV_REGISTER event Date: Fri, 18 Oct 2024 11:25:22 -0700 Message-Id: <1729275922-17595-1-git-send-email-haiyangz@microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-ClientProxiedBy: MW4P223CA0022.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::27) To BY5PR21MB1443.namprd21.prod.outlook.com (2603:10b6:a03:21f::18) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Sender: LKML haiyangz X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR21MB1443:EE_|BY1PR21MB3893:EE_ X-MS-Office365-Filtering-Correlation-Id: 2b31f0b3-9d6a-4a26-92e9-08dcefa241ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|52116014|7416014|376014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?T8ZoJBogi0YT4pkDrQmgxdebHVgXw5E72Y42jO4adUDWWizAFIBuEMyVKmmX?= =?us-ascii?Q?+JmFQ9WcNsm3OVieS9qsQTapT0FANYjmxUo1yXge7JqYjpB9KWobCxTk/I76?= =?us-ascii?Q?QgygDlCLPGHhcN2Eaoi/uYQNPNnuNi8ZfJ2Skg0wUWqwJ15Wox0OANdCwL07?= =?us-ascii?Q?VX/pIuUsReiArsU7lOibZd3hS4JwZfCRkVZJeT0s9q8NKeQuQlCx/Z1F/1Pq?= =?us-ascii?Q?XqUgi1v1jVLjuh8BMoWmul7iO0Sn1ZsfYJbv2DQ7/vgR4PWTPnno/0MBWLRu?= =?us-ascii?Q?/5Ql6bd5BBVED3+CgPSW5E2IykGbhX9cYy6Rbt3ABX71uFNgSv7CDmA7GG9q?= =?us-ascii?Q?W7TQFaZ2D1YCPbvQQNrqr2v1mzuDs2S2JDjTdXNtQ+1vmHqDC6Z3frVVN7Ks?= =?us-ascii?Q?we8niXC8b8Zg6UZxghFsfygpMJ0JQeLqtLwDFrk2vG6fP9G7pN7eV1u6SjdY?= =?us-ascii?Q?ds0RJAolYGpcO9eq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?us-ascii?Q?U6zkzuk=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR21MB1443.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(52116014)(7416014)(376014)(1800799024)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?43BPD4eORsNx6/e/C9acdBOX0nEqxwn7RaJfuMfUeiI5SDcnUD9yWECoNFH1?= =?us-ascii?Q?kpMn+mN45PDxZ12nD+RvUa7OCodiUEYOcmWvmbpW6ZVXaQQr1e+WIm0olHRz?= =?us-ascii?Q?CXaAmT471LvLZvN+Z9mO37LdD/5NmUlor9NijP/Pon7OucbId3pj8pkXzqHh?= =?us-ascii?Q?IRMfitdbOaktKeFVAMIYmRCC0UBerKeQi1PhIFCV4igjRj1tNMuCwenIc4dr?= =?us-ascii?Q?etdLUViTPWAH7YzEnnX3B04aK5y3QzLOhoch3Cf69PmFzsR1NZCrm/rBzeW1?= =?us-ascii?Q?fnZDpYlHG5NqZlnSw9EFXScZZLrevXuvkn9y5u6nOlfQHHCMB/Ffo37khV1P?= =?us-ascii?Q?csY/evUv2o04QmF6qNkOKO7629CDKgaf6POu3Ucn58isKVvbnI3oeh2fw0Wn?= =?us-ascii?Q?llOFCHa1U57LpDAR04YzRFDiYeeyw6kKdL3Ic/8LGIfnfqy/ElY1HCyKvUcr?= =?us-ascii?Q?V0+3Urx+muIEw3WNSFNby/kVjp+OQ1sETjY13wglupqt/346qcqkkXjx7KCD?= =?us-ascii?Q?d9h7g0gbVvHJBqAQavGdgpU1tbcgIjdsczp2U3WFRjIIeuES7CcKvMNRd2+3?= =?us-ascii?Q?rDxkoNkPBiPKeOeyRH7ZCZu4d9729iFNAXCTo15Iyl+/rhxqTgM01Owz1SXz?= =?us-ascii?Q?lwSM5hF4vXMjbPF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2wiX+N43v?= =?us-ascii?Q?GvyoCGsGRV0lh5DAJuVKMBvtBTtJuRT894dsuOpo?= X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b31f0b3-9d6a-4a26-92e9-08dcefa241ce X-MS-Exchange-CrossTenant-AuthSource: BY5PR21MB1443.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2024 18:25:35.0270 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eSYngAH+iEb54bJoN6FAtVJgKvntaNtWkPRsiDHVZfB13l88y2JB9q6iU2o2jjs1DsE1TUGVaaQMOCwk0vjZfQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR21MB3893 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The existing code moves VF to the same namespace as the synthetic NIC during netvsc_register_vf(). But, if the synthetic device is moved to a new namespace after the VF registration, the VF won't be moved together. To make the behavior more consistent, add a namespace check for synthetic NIC's NETDEV_REGISTER event (generated during its move), and move the VF if it is not in the same namespace. Cc: stable@vger.kernel.org Fixes: c0a41b887ce6 ("hv_netvsc: move VF to same namespace as netvsc device= ") Suggested-by: Stephen Hemminger Signed-off-by: Haiyang Zhang Reviewed-by: Simon Horman --- v3: Use RCT order as suggested by Simon. v2: Move my fix to synthetic NIC's NETDEV_REGISTER event as suggested by St= ephen. --- drivers/net/hyperv/netvsc_drv.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_dr= v.c index 153b97f8ec0d..23180f7b67b6 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -2798,6 +2798,31 @@ static struct hv_driver netvsc_drv =3D { }, }; =20 +/* Set VF's namespace same as the synthetic NIC */ +static void netvsc_event_set_vf_ns(struct net_device *ndev) +{ + struct net_device_context *ndev_ctx =3D netdev_priv(ndev); + struct net_device *vf_netdev; + int ret; + + vf_netdev =3D rtnl_dereference(ndev_ctx->vf_netdev); + if (!vf_netdev) + return; + + if (!net_eq(dev_net(ndev), dev_net(vf_netdev))) { + ret =3D dev_change_net_namespace(vf_netdev, dev_net(ndev), + "eth%d"); + if (ret) + netdev_err(vf_netdev, + "Cannot move to same namespace as %s: %d\n", + ndev->name, ret); + else + netdev_info(vf_netdev, + "Moved VF to namespace with: %s\n", + ndev->name); + } +} + /* * On Hyper-V, every VF interface is matched with a corresponding * synthetic interface. The synthetic interface is presented first @@ -2810,6 +2835,11 @@ static int netvsc_netdev_event(struct notifier_block= *this, struct net_device *event_dev =3D netdev_notifier_info_to_dev(ptr); int ret =3D 0; =20 + if (event_dev->netdev_ops =3D=3D &device_ops && event =3D=3D NETDEV_REGIS= TER) { + netvsc_event_set_vf_ns(event_dev); + return NOTIFY_DONE; + } + ret =3D check_dev_is_matching_vf(event_dev); if (ret !=3D 0) return NOTIFY_DONE; --=20 2.34.1