From patchwork Sat Jan 25 11:17:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 1229202 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=GeMiqrLl; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 484YPr4b7Cz9sRs for ; Sat, 25 Jan 2020 22:17:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727534AbgAYLRQ (ORCPT ); Sat, 25 Jan 2020 06:17:16 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:44398 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725767AbgAYLRP (ORCPT ); Sat, 25 Jan 2020 06:17:15 -0500 Received: by mail-wr1-f68.google.com with SMTP id q10so5148090wrm.11 for ; Sat, 25 Jan 2020 03:17:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/7VYyQSo6PVi3ys5VLzxKBaK389wAKDc5hKCvmhZ5FI=; b=GeMiqrLlNZwlS9HwB44Q9jFo3wdE9me5mqtVWhkdRhY4csjtYy7YZLyN7LFxYnFdV7 7L4NoPoHXz3AP+113VHc5lLA9moCvzFe7JXhpOugd6g6+h/bdIYJQo+nrDJ5oCKcZMI4 AwGCgEe2EOiYbWDGr83RyrlobtcoPAtV/1sSEHXXHrAi3CCLfl5M5qkFJ0NpVA2RvZNg uwy9BnXCgsrJeo3t6e9zvzh1GAOeVtFSYFi2ZAIr43IL72SbdaUcnse5eNY02PIyfbfL EtDYM71shAEq4KlkRLgW6LshV3rrPnOfUed11504AKOUynfTJtA3DKQj3NO27SdnEob1 9Vtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/7VYyQSo6PVi3ys5VLzxKBaK389wAKDc5hKCvmhZ5FI=; b=nRw7MKPrTQnZ/xquom3HUcPgZJhDGREYEjJRo+Vxrsw4mXkGbVT6BNzdbWaM00LOMo DsjEb/kOrnRQJn+rBqSDvhQIFGvPgU4INJAgx5OFqLIrNPxcq2RU/BHKJM7M0FuHtkBm toczC1oLGrVnRpKYqeaH/rCiL9glpgqKRSj8cqLMYjry5T1PDecM1YzZ4ywSlCBLRBPW AF/q9AqZ72EJ4cPNnPuoOK2sDR4dVwD3YaP2G0aBzvrcuqjTe0tEVHldN9SUL535hWWo VaH2gTVh6WAaOlTQgoo0jUdZINt5Hi8SSs4PWVuoaxUEyKuqp0caRCTjoknbL+mVRrEM jn3w== X-Gm-Message-State: APjAAAXJQuGrXk65eqisWKC2dHJ0k07BbfRl7nmt3Vy+fEYKLfiynbuW a2CVpLSbecPoFuhAt94V/pf2GwLiTwM= X-Google-Smtp-Source: APXvYqyWZtzsSTKaeNa8idIYxtPVgBT+ErdFQijL5ckCNE75eNahSeu1Dxkwnijm2OEHhS5qx6u+Ag== X-Received: by 2002:adf:f18b:: with SMTP id h11mr10797065wro.56.1579951033760; Sat, 25 Jan 2020 03:17:13 -0800 (PST) Received: from localhost (jirka.pirko.cz. [84.16.102.26]) by smtp.gmail.com with ESMTPSA id h2sm12510494wrt.45.2020.01.25.03.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2020 03:17:13 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, jakub.kicinski@netronome.com, saeedm@mellanox.com, leon@kernel.org, tariqt@mellanox.com, ayal@mellanox.com, vladbu@mellanox.com, michaelgur@mellanox.com, moshe@mellanox.com, mlxsw@mellanox.com, dsahern@gmail.com Subject: [patch net-next v2 2/4] net: push code from net notifier reg/unreg into helpers Date: Sat, 25 Jan 2020 12:17:07 +0100 Message-Id: <20200125111709.14566-3-jiri@resnulli.us> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200125111709.14566-1-jiri@resnulli.us> References: <20200125111709.14566-1-jiri@resnulli.us> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Push the code which is done under rtnl lock in net notifier register and unregister function into separate helpers. Signed-off-by: Jiri Pirko --- v1->v2: - fixed error path of __register_netdevice_notifier_net() --- net/core/dev.c | 60 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 3cacfb7184e8..7e5aa58ce1ea 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1784,6 +1784,42 @@ int unregister_netdevice_notifier(struct notifier_block *nb) } EXPORT_SYMBOL(unregister_netdevice_notifier); +static int __register_netdevice_notifier_net(struct net *net, + struct notifier_block *nb, + bool ignore_call_fail) +{ + int err; + + err = raw_notifier_chain_register(&net->netdev_chain, nb); + if (err) + return err; + if (dev_boot_phase) + return 0; + + err = call_netdevice_register_net_notifiers(nb, net); + if (err && !ignore_call_fail) + goto chain_unregister; + + return 0; + +chain_unregister: + raw_notifier_chain_unregister(&net->netdev_chain, nb); + return err; +} + +static int __unregister_netdevice_notifier_net(struct net *net, + struct notifier_block *nb) +{ + int err; + + err = raw_notifier_chain_unregister(&net->netdev_chain, nb); + if (err) + return err; + + call_netdevice_unregister_net_notifiers(nb, net); + return 0; +} + /** * register_netdevice_notifier_net - register a per-netns network notifier block * @net: network namespace @@ -1804,23 +1840,9 @@ int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb) int err; rtnl_lock(); - err = raw_notifier_chain_register(&net->netdev_chain, nb); - if (err) - goto unlock; - if (dev_boot_phase) - goto unlock; - - err = call_netdevice_register_net_notifiers(nb, net); - if (err) - goto chain_unregister; - -unlock: + err = __register_netdevice_notifier_net(net, nb, false); rtnl_unlock(); return err; - -chain_unregister: - raw_notifier_chain_unregister(&netdev_chain, nb); - goto unlock; } EXPORT_SYMBOL(register_netdevice_notifier_net); @@ -1846,13 +1868,7 @@ int unregister_netdevice_notifier_net(struct net *net, int err; rtnl_lock(); - err = raw_notifier_chain_unregister(&net->netdev_chain, nb); - if (err) - goto unlock; - - call_netdevice_unregister_net_notifiers(nb, net); - -unlock: + err = __unregister_netdevice_notifier_net(net, nb); rtnl_unlock(); return err; } From patchwork Sat Jan 25 11:17:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 1229204 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=EviEP0bm; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 484YPw00Htz9sSG for ; Sat, 25 Jan 2020 22:17:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727964AbgAYLRU (ORCPT ); Sat, 25 Jan 2020 06:17:20 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35471 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726436AbgAYLRS (ORCPT ); Sat, 25 Jan 2020 06:17:18 -0500 Received: by mail-wm1-f68.google.com with SMTP id p17so2059941wmb.0 for ; Sat, 25 Jan 2020 03:17:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FZQ0DS424drmpPcRc3Q9TceRcYUqRFbSQpx/meAwqfw=; b=EviEP0bmA+WeR4kcljIMV9tvCQSqa/ylZ2eOnWIwsi4hiOXcmYeXaZKzXeDZQWk7IF EFoyWDEld0Vr9la+fy6lraUK4TozvuaH7YiF+xS+kX8jNLqM4ql10hao5PX2+ec8JQkd 7O7JGwUVB9hgODj3ZV/N14Vx3sPXJ1PmYPtkAGxOidupcbeMS9K3/L8uSarIKTYp9esX gdhy7DvlCD2er1443xCtVRxkc3aVLjn215ASt1u98bwhbaP7++fGs8qJbQRr0nB3xqu1 pkYl2unr+dZipb4J5wrddHl7HHV6rPsiQ8adGimgIxMtPX0zekqEqNAz3x0Kik3DMueh Jy/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FZQ0DS424drmpPcRc3Q9TceRcYUqRFbSQpx/meAwqfw=; b=aj+RruHlDILgf3BzeiMBJ+W1ziPMo0vKuxLDZLtyNAo0nfTEpOYkgPUb9arfHya3rd C6pYBWeHpeILyoAhGQgjSbQyrrKjdg2JXbBX4MqPgh3iH0YJDnsBxbBDkPMPwxzU9FCb IDpzpy3S5V70u8+fJhahC0wRTOaWJYSdqqySUNNvdfXCqEj338u/OTzJAhwTzmMlKSro 8z5f7YkLxSDD0XF+Od8b8dlUv3qE86M9Rcx56UIpxP/BvBDXILj4RMIqIe8Uwp8AnKgG AAS+ktnk0Nhd5/DT3Zuo75De1nRnUkL3cyBYZLU11dXMmlOawqnSj1E9sRe2sk3sGdEa R7ug== X-Gm-Message-State: APjAAAVmFwEqZ9ARutOy1w2+L5E/4eFzgkPvIr7v7+yT5Iu0Q9Sx/HrZ vJ1+xeXkxzJfD9xWGDNsDFfWP2XceuA= X-Google-Smtp-Source: APXvYqzITHMNh/Zhl8o8doX3O5cn2DqjE+bPVwSeVLABhZFvbnDXw1DUvfGTKJn4NWuAnOxQJMLRRg== X-Received: by 2002:a1c:9d07:: with SMTP id g7mr4046709wme.130.1579951034962; Sat, 25 Jan 2020 03:17:14 -0800 (PST) Received: from localhost (jirka.pirko.cz. [84.16.102.26]) by smtp.gmail.com with ESMTPSA id r68sm10011416wmr.43.2020.01.25.03.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2020 03:17:14 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, jakub.kicinski@netronome.com, saeedm@mellanox.com, leon@kernel.org, tariqt@mellanox.com, ayal@mellanox.com, vladbu@mellanox.com, michaelgur@mellanox.com, moshe@mellanox.com, mlxsw@mellanox.com, dsahern@gmail.com Subject: [patch net-next v2 3/4] net: introduce dev_net notifier register/unregister variants Date: Sat, 25 Jan 2020 12:17:08 +0100 Message-Id: <20200125111709.14566-4-jiri@resnulli.us> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200125111709.14566-1-jiri@resnulli.us> References: <20200125111709.14566-1-jiri@resnulli.us> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Introduce dev_net variants of netdev notifier register/unregister functions and allow per-net notifier to follow the netdevice into the namespace it is moved to. Signed-off-by: Jiri Pirko --- include/linux/netdevice.h | 17 +++++++++++++++ net/core/dev.c | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 5ec3537fbdb1..8c09886d1947 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -938,6 +938,11 @@ struct netdev_name_node { int netdev_name_node_alt_create(struct net_device *dev, const char *name); int netdev_name_node_alt_destroy(struct net_device *dev, const char *name); +struct netdev_net_notifier { + struct list_head list; + struct notifier_block *nb; +}; + /* * This structure defines the management hooks for network devices. * The following hooks can be defined; unless noted otherwise, they are @@ -1792,6 +1797,10 @@ enum netdev_priv_flags { * * @wol_enabled: Wake-on-LAN is enabled * + * @net_notifier_list: List of per-net netdev notifier block + * that follow this device when it is moved + * to another network namespace. + * * FIXME: cleanup struct net_device such that network protocol info * moves out. */ @@ -2084,6 +2093,8 @@ struct net_device { struct lock_class_key addr_list_lock_key; bool proto_down; unsigned wol_enabled:1; + + struct list_head net_notifier_list; }; #define to_net_dev(d) container_of(d, struct net_device, dev) @@ -2527,6 +2538,12 @@ int unregister_netdevice_notifier(struct notifier_block *nb); int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb); int unregister_netdevice_notifier_net(struct net *net, struct notifier_block *nb); +int register_netdevice_notifier_dev_net(struct net_device *dev, + struct notifier_block *nb, + struct netdev_net_notifier *nn); +int unregister_netdevice_notifier_dev_net(struct net_device *dev, + struct notifier_block *nb, + struct netdev_net_notifier *nn); struct netdev_notifier_info { struct net_device *dev; diff --git a/net/core/dev.c b/net/core/dev.c index 7e5aa58ce1ea..cf44debb2447 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1874,6 +1874,48 @@ int unregister_netdevice_notifier_net(struct net *net, } EXPORT_SYMBOL(unregister_netdevice_notifier_net); +int register_netdevice_notifier_dev_net(struct net_device *dev, + struct notifier_block *nb, + struct netdev_net_notifier *nn) +{ + int err; + + rtnl_lock(); + err = __register_netdevice_notifier_net(dev_net(dev), nb, false); + if (!err) { + nn->nb = nb; + list_add(&nn->list, &dev->net_notifier_list); + } + rtnl_unlock(); + return err; +} +EXPORT_SYMBOL(register_netdevice_notifier_dev_net); + +int unregister_netdevice_notifier_dev_net(struct net_device *dev, + struct notifier_block *nb, + struct netdev_net_notifier *nn) +{ + int err; + + rtnl_lock(); + list_del(&nn->list); + err = __unregister_netdevice_notifier_net(dev_net(dev), nb); + rtnl_unlock(); + return err; +} +EXPORT_SYMBOL(unregister_netdevice_notifier_dev_net); + +static void move_netdevice_notifiers_dev_net(struct net_device *dev, + struct net *net) +{ + struct netdev_net_notifier *nn; + + list_for_each_entry(nn, &dev->net_notifier_list, list) { + __unregister_netdevice_notifier_net(dev_net(dev), nn->nb); + __register_netdevice_notifier_net(net, nn->nb, true); + } +} + /** * call_netdevice_notifiers_info - call all network notifier blocks * @val: value passed unmodified to notifier function @@ -9773,6 +9815,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, INIT_LIST_HEAD(&dev->adj_list.lower); INIT_LIST_HEAD(&dev->ptype_all); INIT_LIST_HEAD(&dev->ptype_specific); + INIT_LIST_HEAD(&dev->net_notifier_list); #ifdef CONFIG_NET_SCHED hash_init(dev->qdisc_hash); #endif @@ -10036,6 +10079,9 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char kobject_uevent(&dev->dev.kobj, KOBJ_REMOVE); netdev_adjacent_del_links(dev); + /* Move per-net netdevice notifiers that are following the netdevice */ + move_netdevice_notifiers_dev_net(dev, net); + /* Actually switch the network namespace */ dev_net_set(dev, net); dev->ifindex = new_ifindex; From patchwork Sat Jan 25 11:17:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 1229203 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=aUVmBPRj; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 484YPt3jBbz9sS3 for ; Sat, 25 Jan 2020 22:17:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728292AbgAYLRU (ORCPT ); Sat, 25 Jan 2020 06:17:20 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:37334 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725767AbgAYLRS (ORCPT ); Sat, 25 Jan 2020 06:17:18 -0500 Received: by mail-wr1-f66.google.com with SMTP id w15so5174741wru.4 for ; Sat, 25 Jan 2020 03:17:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NVJVXWMmW6+azJuif5XHBsc9/5TTZmty+7ikIMETbWo=; b=aUVmBPRj8IuAJdVv+RT/8HW9IzKPtYNzHFOapbjJyg1fnSFhuz5gki1Cej72ItM79Y pD9ky8cvX+IsW8VFygdam9ndXeFAIqBcf3T3k53jDnn4hSh6uR3cQZcv5ksl9pRif4Z1 yw7XtslcoRFCC+itwhIOnFoXZTqVkY/550UIM0FhP1oCBcnND2Hsi3/tMCNMPDKUjL4o AdATmh3XrI1Z7k15hB8WJUHWnVRofIjOq0QM+7d9SW6gqOWJbqo/aTCmZUqirfLFf54T hNIS3Nt0fQMRsUNBg4rfrdloH7cGBAUvubfIK4uuimBCl2NfO6ai+nn9H22NmiLDxUue OP2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NVJVXWMmW6+azJuif5XHBsc9/5TTZmty+7ikIMETbWo=; b=gAb1IJQh2cFBmu2acHakr7V0oeJ/Kl3kMTAsTMSR3cQTx3IXoiF/GxUhSih+BfzgnA ZFOYUqubI9vqbcL36/kOVgqtArYOqr7qsAQIBEuOFGaL3zRXcZcCP028tRETCl4uNc56 g49HuudSGqQ0UYpv0Sqg/VdMwTLtVdpkC/3ISe87p49rvcYdWq9Grp9p6Q5pRUKCbfq6 RbJ8X/U7c6ixh6J4dSNhciA8JkyfmHcffsJmdpTZIhpYKO6OvECysus9ufEzRv2cHRXp gbrfQs2YSGCvow6pAOFgd71TY6Zt6bniny2sW7tS0sQ08D4ft2/uYY9GQQKaAqhU+fAn eIag== X-Gm-Message-State: APjAAAWmzpDfOSoMxKhAoceHRN/ot2zJrp1pbrqUqJW0R9y1CdxC86p4 xZFw7sxpnYrPpoipnDpK9rbZxDTrwB0= X-Google-Smtp-Source: APXvYqwPwWrQz/CvqFmao8hk7+Fn7HxVrXqedKeOQ/GpSNxjE3kufMWaTaOWaPCYfpJtfVcf959caA== X-Received: by 2002:a5d:5704:: with SMTP id a4mr10741978wrv.198.1579951036183; Sat, 25 Jan 2020 03:17:16 -0800 (PST) Received: from localhost (jirka.pirko.cz. [84.16.102.26]) by smtp.gmail.com with ESMTPSA id m21sm10394427wmi.27.2020.01.25.03.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2020 03:17:15 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, jakub.kicinski@netronome.com, saeedm@mellanox.com, leon@kernel.org, tariqt@mellanox.com, ayal@mellanox.com, vladbu@mellanox.com, michaelgur@mellanox.com, moshe@mellanox.com, mlxsw@mellanox.com, dsahern@gmail.com Subject: [patch net-next v2 4/4] mlx5: Use dev_net netdevice notifier registrations Date: Sat, 25 Jan 2020 12:17:09 +0100 Message-Id: <20200125111709.14566-5-jiri@resnulli.us> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200125111709.14566-1-jiri@resnulli.us> References: <20200125111709.14566-1-jiri@resnulli.us> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Register the dev_net notifier and allow the per-net notifier to follow the device into different namespace. Signed-off-by: Jiri Pirko --- v1->v2: - Rebased on top of recent changes --- drivers/net/ethernet/mellanox/mlx5/core/en/fs.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 3 ++- drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 13 ++++++++++--- drivers/net/ethernet/mellanox/mlx5/core/en_rep.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 9 +++++++-- drivers/net/ethernet/mellanox/mlx5/core/lag.c | 8 +++++--- drivers/net/ethernet/mellanox/mlx5/core/lag.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h | 2 +- 8 files changed, 28 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h b/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h index d48292ccda29..0416f7712109 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h @@ -21,6 +21,7 @@ struct mlx5e_tc_table { DECLARE_HASHTABLE(hairpin_tbl, 8); struct notifier_block netdevice_nb; + struct netdev_net_notifier netdevice_nn; }; struct mlx5e_flow_table { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index f3600ae4b0a1..454d3459bd8b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -5144,6 +5144,7 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv) static void mlx5e_nic_disable(struct mlx5e_priv *priv) { + struct net_device *netdev = priv->netdev; struct mlx5_core_dev *mdev = priv->mdev; #ifdef CONFIG_MLX5_CORE_EN_DCB @@ -5164,7 +5165,7 @@ static void mlx5e_nic_disable(struct mlx5e_priv *priv) mlx5e_monitor_counter_cleanup(priv); mlx5e_disable_async_events(priv); - mlx5_lag_remove(mdev); + mlx5_lag_remove(mdev, netdev); } int mlx5e_update_nic_rx(struct mlx5e_priv *priv) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c index 09061b4c43af..7b48ccacebe2 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c @@ -1731,7 +1731,9 @@ static int mlx5e_init_uplink_rep_tx(struct mlx5e_rep_priv *rpriv) /* init indirect block notifications */ INIT_LIST_HEAD(&uplink_priv->tc_indr_block_priv_list); uplink_priv->netdevice_nb.notifier_call = mlx5e_nic_rep_netdevice_event; - err = register_netdevice_notifier(&uplink_priv->netdevice_nb); + err = register_netdevice_notifier_dev_net(rpriv->netdev, + &uplink_priv->netdevice_nb, + &uplink_priv->netdevice_nn); if (err) { mlx5_core_err(priv->mdev, "Failed to register netdev notifier\n"); goto tc_esw_cleanup; @@ -1770,8 +1772,12 @@ static int mlx5e_init_rep_tx(struct mlx5e_priv *priv) static void mlx5e_cleanup_uplink_rep_tx(struct mlx5e_rep_priv *rpriv) { + struct mlx5_rep_uplink_priv *uplink_priv = &rpriv->uplink_priv; + /* clean indirect TC block notifications */ - unregister_netdevice_notifier(&rpriv->uplink_priv.netdevice_nb); + unregister_netdevice_notifier_dev_net(rpriv->netdev, + &uplink_priv->netdevice_nb, + &uplink_priv->netdevice_nn); mlx5e_rep_indr_clean_block_privs(rpriv); /* delete shared tc flow table */ @@ -1855,6 +1861,7 @@ static void mlx5e_uplink_rep_enable(struct mlx5e_priv *priv) static void mlx5e_uplink_rep_disable(struct mlx5e_priv *priv) { + struct net_device *netdev = priv->netdev; struct mlx5_core_dev *mdev = priv->mdev; struct mlx5e_rep_priv *rpriv = priv->ppriv; @@ -1863,7 +1870,7 @@ static void mlx5e_uplink_rep_disable(struct mlx5e_priv *priv) #endif mlx5_notifier_unregister(mdev, &priv->events_nb); cancel_work_sync(&rpriv->uplink_priv.reoffload_flows_work); - mlx5_lag_remove(mdev); + mlx5_lag_remove(mdev, netdev); } static MLX5E_DEFINE_STATS_GRP(sw_rep, 0); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h index 31f83c8adcc9..3f756d51435f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h @@ -73,6 +73,7 @@ struct mlx5_rep_uplink_priv { */ struct list_head tc_indr_block_priv_list; struct notifier_block netdevice_nb; + struct netdev_net_notifier netdevice_nn; struct mlx5_tun_entropy tun_entropy; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c index 4f184c770a45..92a63467ab82 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c @@ -4246,7 +4246,10 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv) return err; tc->netdevice_nb.notifier_call = mlx5e_tc_netdev_event; - if (register_netdevice_notifier(&tc->netdevice_nb)) { + err = register_netdevice_notifier_dev_net(priv->netdev, + &tc->netdevice_nb, + &tc->netdevice_nn); + if (err) { tc->netdevice_nb.notifier_call = NULL; mlx5_core_warn(priv->mdev, "Failed to register netdev notifier\n"); } @@ -4268,7 +4271,9 @@ void mlx5e_tc_nic_cleanup(struct mlx5e_priv *priv) struct mlx5e_tc_table *tc = &priv->fs.tc; if (tc->netdevice_nb.notifier_call) - unregister_netdevice_notifier(&tc->netdevice_nb); + unregister_netdevice_notifier_dev_net(priv->netdev, + &tc->netdevice_nb, + &tc->netdevice_nn); mutex_destroy(&tc->mod_hdr.lock); mutex_destroy(&tc->hairpin_tbl_lock); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag.c index fc0d9583475d..b91eabc09fbc 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag.c @@ -586,7 +586,8 @@ void mlx5_lag_add(struct mlx5_core_dev *dev, struct net_device *netdev) if (!ldev->nb.notifier_call) { ldev->nb.notifier_call = mlx5_lag_netdev_event; - if (register_netdevice_notifier(&ldev->nb)) { + if (register_netdevice_notifier_dev_net(netdev, &ldev->nb, + &ldev->nn)) { ldev->nb.notifier_call = NULL; mlx5_core_err(dev, "Failed to register LAG netdev notifier\n"); } @@ -599,7 +600,7 @@ void mlx5_lag_add(struct mlx5_core_dev *dev, struct net_device *netdev) } /* Must be called with intf_mutex held */ -void mlx5_lag_remove(struct mlx5_core_dev *dev) +void mlx5_lag_remove(struct mlx5_core_dev *dev, struct net_device *netdev) { struct mlx5_lag *ldev; int i; @@ -619,7 +620,8 @@ void mlx5_lag_remove(struct mlx5_core_dev *dev) if (i == MLX5_MAX_PORTS) { if (ldev->nb.notifier_call) - unregister_netdevice_notifier(&ldev->nb); + unregister_netdevice_notifier_dev_net(netdev, &ldev->nb, + &ldev->nn); mlx5_lag_mp_cleanup(ldev); cancel_delayed_work_sync(&ldev->bond_work); mlx5_lag_dev_free(ldev); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag.h b/drivers/net/ethernet/mellanox/mlx5/core/lag.h index f1068aac6406..316ab09e2664 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag.h @@ -44,6 +44,7 @@ struct mlx5_lag { struct workqueue_struct *wq; struct delayed_work bond_work; struct notifier_block nb; + struct netdev_net_notifier nn; struct lag_mp lag_mp; }; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h index da67b28d6e23..fcce9e0fc82c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h @@ -157,7 +157,7 @@ int mlx5_query_qcam_reg(struct mlx5_core_dev *mdev, u32 *qcam, u8 feature_group, u8 access_reg_group); void mlx5_lag_add(struct mlx5_core_dev *dev, struct net_device *netdev); -void mlx5_lag_remove(struct mlx5_core_dev *dev); +void mlx5_lag_remove(struct mlx5_core_dev *dev, struct net_device *netdev); int mlx5_irq_table_init(struct mlx5_core_dev *dev); void mlx5_irq_table_cleanup(struct mlx5_core_dev *dev);