[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJ2QiJLJk73RDS_XwQ0FY0ODq9qXbmiEZ2Y8Fkz9vVheK4he8g@mail.gmail.com>
Date: Tue, 10 Aug 2021 18:08:51 +0530
From: Prabhakar Kushwaha <prabhakar.pkin@...il.com>
To: Leon Romanovsky <leon@...nel.org>
Cc: "David S . Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Leon Romanovsky <leonro@...dia.com>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
Andrew Lunn <andrew@...n.ch>, Ariel Elior <aelior@...vell.com>,
Bin Luo <luobin9@...wei.com>,
Claudiu Manoil <claudiu.manoil@....com>,
Coiby Xu <coiby.xu@...il.com>,
Derek Chickles <dchickles@...vell.com>, drivers@...sando.io,
Felix Manlunas <fmanlunas@...vell.com>,
Florian Fainelli <f.fainelli@...il.com>,
Geetha sowjanya <gakula@...vell.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
GR-everest-linux-l2@...vell.com, GR-Linux-NIC-Dev@...vell.com,
hariprasad <hkelam@...vell.com>,
Ido Schimmel <idosch@...dia.com>,
intel-wired-lan@...ts.osuosl.org,
Ioana Ciornei <ioana.ciornei@....com>,
Jerin Jacob <jerinj@...vell.com>,
Jesse Brandeburg <jesse.brandeburg@...el.com>,
Jiri Pirko <jiri@...dia.com>,
Linu Cherian <lcherian@...vell.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
linux-omap@...r.kernel.org, linux-staging@...ts.linux.dev,
Manish Chopra <manishc@...vell.com>,
Michael Chan <michael.chan@...adcom.com>,
netdev@...r.kernel.org, oss-drivers@...igine.com,
Richard Cochran <richardcochran@...il.com>,
Saeed Mahameed <saeedm@...dia.com>,
Salil Mehta <salil.mehta@...wei.com>,
Satanand Burla <sburla@...vell.com>,
Shannon Nelson <snelson@...sando.io>,
Simon Horman <simon.horman@...igine.com>,
Subbaraya Sundeep <sbhatta@...vell.com>,
Sunil Goutham <sgoutham@...vell.com>,
Taras Chornyi <tchornyi@...vell.com>,
Tariq Toukan <tariqt@...dia.com>,
Tony Nguyen <anthony.l.nguyen@...el.com>,
UNGLinuxDriver@...rochip.com, Vadym Kochan <vkochan@...vell.com>,
Vivien Didelot <vivien.didelot@...il.com>,
Vladimir Oltean <vladimir.oltean@....com>,
Yisen Zhuang <yisen.zhuang@...wei.com>,
Prabhakar Kushwaha <pkushwaha@...vell.com>,
Shai Malin <malin1024@...il.com>,
Shai Malin <smalin@...vell.com>, rtoshniwal@...vell.com,
Omkar Kulkarni <okulkarni@...vell.com>
Subject: Re: [PATCH net-next] devlink: Set device as early as possible
Hi Leon,
On Mon, Aug 9, 2021 at 12:33 AM Leon Romanovsky <leon@...nel.org> wrote:
>
> From: Leon Romanovsky <leonro@...dia.com>
>
> All kernel devlink implementations call to devlink_alloc() during
> initialization routine for specific device which is used later as
> a parent device for devlink_register().
>
> Such late device assignment causes to the situation which requires us to
> call to device_register() before setting other parameters, but that call
> opens devlink to the world and makes accessible for the netlink users.
>
> Any attempt to move devlink_register() to be the last call generates the
> following error due to access to the devlink->dev pointer.
>
> [ 8.758862] devlink_nl_param_fill+0x2e8/0xe50
> [ 8.760305] devlink_param_notify+0x6d/0x180
> [ 8.760435] __devlink_params_register+0x2f1/0x670
> [ 8.760558] devlink_params_register+0x1e/0x20
>
> The simple change of API to set devlink device in the devlink_alloc()
> instead of devlink_register() fixes all this above and ensures that
> prior to call to devlink_register() everything already set.
>
> Signed-off-by: Leon Romanovsky <leonro@...dia.com>
> ---
> .../net/ethernet/broadcom/bnxt/bnxt_devlink.c | 9 ++++---
> .../net/ethernet/cavium/liquidio/lio_main.c | 5 ++--
> .../freescale/dpaa2/dpaa2-eth-devlink.c | 5 ++--
> .../hisilicon/hns3/hns3pf/hclge_devlink.c | 4 +--
> .../hisilicon/hns3/hns3vf/hclgevf_devlink.c | 7 ++---
> .../net/ethernet/huawei/hinic/hinic_devlink.c | 8 +++---
> .../net/ethernet/huawei/hinic/hinic_devlink.h | 4 +--
> .../net/ethernet/huawei/hinic/hinic_hw_dev.c | 2 +-
> .../net/ethernet/huawei/hinic/hinic_main.c | 2 +-
> drivers/net/ethernet/intel/ice/ice_devlink.c | 4 +--
> .../marvell/octeontx2/af/rvu_devlink.c | 5 ++--
> .../marvell/prestera/prestera_devlink.c | 7 ++---
> .../marvell/prestera/prestera_devlink.h | 2 +-
> .../ethernet/marvell/prestera/prestera_main.c | 2 +-
> drivers/net/ethernet/mellanox/mlx4/main.c | 4 +--
> .../net/ethernet/mellanox/mlx5/core/devlink.c | 9 ++++---
> .../net/ethernet/mellanox/mlx5/core/devlink.h | 4 +--
> .../net/ethernet/mellanox/mlx5/core/main.c | 4 +--
> .../mellanox/mlx5/core/sf/dev/driver.c | 2 +-
> drivers/net/ethernet/mellanox/mlxsw/core.c | 5 ++--
> drivers/net/ethernet/mscc/ocelot_vsc7514.c | 5 ++--
> drivers/net/ethernet/netronome/nfp/nfp_main.c | 2 +-
> .../net/ethernet/netronome/nfp/nfp_net_main.c | 2 +-
> .../ethernet/pensando/ionic/ionic_devlink.c | 4 +--
> drivers/net/ethernet/qlogic/qed/qed_devlink.c | 5 ++--
> drivers/net/ethernet/ti/am65-cpsw-nuss.c | 4 +--
> drivers/net/ethernet/ti/cpsw_new.c | 4 +--
> drivers/net/netdevsim/dev.c | 4 +--
> drivers/ptp/ptp_ocp.c | 26 +++----------------
> drivers/staging/qlge/qlge_main.c | 5 ++--
> include/net/devlink.h | 10 ++++---
> net/core/devlink.c | 15 +++++------
> net/dsa/dsa2.c | 5 ++--
> 33 files changed, 91 insertions(+), 94 deletions(-)
>
<snip>
>
> diff --git a/include/net/devlink.h b/include/net/devlink.h
> index ccbfb3a844aa..0236c77f2fd0 100644
> --- a/include/net/devlink.h
> +++ b/include/net/devlink.h
> @@ -1544,13 +1544,15 @@ struct net *devlink_net(const struct devlink *devlink);
> * Drivers that operate on real HW must use devlink_alloc() instead.
> */
> struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
> - size_t priv_size, struct net *net);
> + size_t priv_size, struct net *net,
> + struct device *dev);
> static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
> - size_t priv_size)
> + size_t priv_size,
> + struct device *dev)
> {
> - return devlink_alloc_ns(ops, priv_size, &init_net);
> + return devlink_alloc_ns(ops, priv_size, &init_net, dev);
> }
> -int devlink_register(struct devlink *devlink, struct device *dev);
> +int devlink_register(struct devlink *devlink);
> void devlink_unregister(struct devlink *devlink);
> void devlink_reload_enable(struct devlink *devlink);
> void devlink_reload_disable(struct devlink *devlink);
> diff --git a/net/core/devlink.c b/net/core/devlink.c
> index ee95eee8d0ed..d3b16dd9f64e 100644
> --- a/net/core/devlink.c
> +++ b/net/core/devlink.c
> @@ -8768,24 +8768,26 @@ static bool devlink_reload_actions_valid(const struct devlink_ops *ops)
> * @ops: ops
> * @priv_size: size of user private data
> * @net: net namespace
> + * @dev: parent device
> *
> * Allocate new devlink instance resources, including devlink index
> * and name.
> */
> struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
> - size_t priv_size, struct net *net)
> + size_t priv_size, struct net *net,
> + struct device *dev)
> {
> struct devlink *devlink;
>
> - if (WARN_ON(!ops))
> - return NULL;
> -
> + WARN_ON(!ops || !dev);
> if (!devlink_reload_actions_valid(ops))
> return NULL;
>
> devlink = kzalloc(sizeof(*devlink) + priv_size, GFP_KERNEL);
> if (!devlink)
> return NULL;
> +
> + devlink->dev = dev;
> devlink->ops = ops;
> xa_init_flags(&devlink->snapshot_ids, XA_FLAGS_ALLOC);
> write_pnet(&devlink->_net, net);
> @@ -8810,12 +8812,9 @@ EXPORT_SYMBOL_GPL(devlink_alloc_ns);
> * devlink_register - Register devlink instance
> *
> * @devlink: devlink
> - * @dev: parent device
> */
This patch is converting devlink_alloc() to devlink_alloc_register().
There are 2 APIs: devlink_alloc() and devlink_register().
Both APIs can be used in a scenario,
Where devlink_alloc() can be done by code written around
one struct dev and used by another struct dev.
or
This scenario is not even a valid scenario?
> -int devlink_register(struct devlink *devlink, struct device *dev)
> +int devlink_register(struct devlink *devlink)
> {
> - WARN_ON(devlink->dev);
> - devlink->dev = dev;
> mutex_lock(&devlink_mutex);
> list_add_tail(&devlink->list, &devlink_list);
> devlink_notify(devlink, DEVLINK_CMD_NEW);
Considering device registration has been moved to devlink_alloc().
Can the remaining code of devlink_register() be also moved in devlink_alloc()?
--pk
Powered by blists - more mailing lists