Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3711932pxt; Tue, 10 Aug 2021 09:35:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGMuoLjgExpGGFzshLUMfEI4t6/dgrhzpeEzr/4geMNTxklMvm33F20/7RZPbOjtFDGvyp X-Received: by 2002:a17:906:1fd5:: with SMTP id e21mr594311ejt.78.1628613326748; Tue, 10 Aug 2021 09:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628613326; cv=none; d=google.com; s=arc-20160816; b=Vt60IWJ2ywvn/g2/tW7O+u5Kxz7SkgQZLMqvILTQwewVjqci+QhMBns2esiFiFs58s deSVUrwZexb7yehq29m67f550fCq3kSnmVYbWYdFgisxj1IPzfzA29yOTtFoiohrAv7r nltqW2nGnILnVCwih48GhWJx1p6D36jLA7VpKWrmO1uhrZ9+IvvQmlr5lU8CMwHYIsDe 1Cc5p1EQBtNQ6G/EQTD7LYtvQRTZ0+s9OvATJAW5QWkTEtOWQMioUOWmUSdRxD5bfzr3 FkgVJOPRiFbKKCp7WQbSjEhaJcGFVXAxdWl5JJN43qZFYQzDS90Kw7MPHtZC2nM9bELd APog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4TdOzk55x/MjE1q1HM1XO4991OBbSbg9ArW1L6O8zDo=; b=X84IzwcPK684G0ToUXMLobFPLyHVg93ygdCUvglRC3q7t1cBmdN3AF+jpEiQKSxQc+ HOHbbUYaEyeuuTwZx2W/Eq423zx948iG4eEfyoCKot7NpjinKN2M39xVzRq0N2Ww3A8W ALjfmBSgRxxAMkoo7NqxCjwelsPshZidkgdm6Rc1jD5hzXziYz6ykH6AKUWuz6QpcVLk mUr23I4o8L+GJxtDKalozsA+g+TvsVdtQU74GinuyKbEcKoo11Iq1h9VuUgRiFYShZoS 7aLwCbE4EO1gYo5J3hJkxE856NVCReGDY9FKAw0/hDXFiLGHNrwPaw4sC64QfQLTo1VR lwOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W3pWCgta; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x23si10296239ejy.447.2021.08.10.09.35.02; Tue, 10 Aug 2021 09:35:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W3pWCgta; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241797AbhHJNpr (ORCPT + 99 others); Tue, 10 Aug 2021 09:45:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:51782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240192AbhHJNpq (ORCPT ); Tue, 10 Aug 2021 09:45:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0AEC561075; Tue, 10 Aug 2021 13:45:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628603124; bh=Glql89CKaEO2bKO5D0IqlIuTd5q4oxJ9Hn2ZSRZr+6k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=W3pWCgta7DCxFxMKzABYUZSAlENjwlFpfuHFoXXv2Eit9eMl2Z+UCcO5Dc43YQQMt WTVNyQ8MROBG3w8rJQO0Vcp2otFrz65A5789N/iQ/b/3s13ylFpmZfF1fcAyaedt3N ovC4qeJXiHZ331CjANyr3NzVzEvoZfFX9lJQHWfWjQT7fe/rRrKM6xabrSL4pAwcGO WAsrZtoEL2msoqVQ9ZFYcuNKnb/5PkDkqbuYEJEXJF/iG5535KgIcyS7mmOTgv7IMD CA0tzZ8OzXMMcuEEsgbziGo3jbol8i+tLifnzLmNjQRUT3CMMibJPFoNQ8K7rON1B/ /tR/laAwFJygA== Date: Tue, 10 Aug 2021 16:45:20 +0300 From: Leon Romanovsky To: Prabhakar Kushwaha Cc: "David S . Miller" , Jakub Kicinski , Alexandre Belloni , Andrew Lunn , Ariel Elior , Bin Luo , Claudiu Manoil , Coiby Xu , Derek Chickles , drivers@pensando.io, Felix Manlunas , Florian Fainelli , Geetha sowjanya , Greg Kroah-Hartman , GR-everest-linux-l2@marvell.com, GR-Linux-NIC-Dev@marvell.com, hariprasad , Ido Schimmel , intel-wired-lan@lists.osuosl.org, Ioana Ciornei , Jerin Jacob , Jesse Brandeburg , Jiri Pirko , Linu Cherian , Linux Kernel Mailing List , linux-omap@vger.kernel.org, linux-staging@lists.linux.dev, Manish Chopra , Michael Chan , netdev@vger.kernel.org, oss-drivers@corigine.com, Richard Cochran , Saeed Mahameed , Salil Mehta , Satanand Burla , Shannon Nelson , Simon Horman , Subbaraya Sundeep , Sunil Goutham , Taras Chornyi , Tariq Toukan , Tony Nguyen , UNGLinuxDriver@microchip.com, Vadym Kochan , Vivien Didelot , Vladimir Oltean , Yisen Zhuang , Prabhakar Kushwaha , Shai Malin , Shai Malin , rtoshniwal@marvell.com, Omkar Kulkarni Subject: Re: [PATCH net-next] devlink: Set device as early as possible Message-ID: References: <6859503f7e3e6cd706bf01ef06f1cae8c0b0970b.1628449004.git.leonro@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 10, 2021 at 06:08:51PM +0530, Prabhakar Kushwaha wrote: > Hi Leon, <...> > > 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? devlink_alloc() is used to allocated netdev structures for newly initialized device, it is not possible to share same devlink instance between different devices. > > > -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()? The line "list_add_tail(&devlink->list, &devlink_list);" makes the devlink instance visible to the devlink netlink users. We need to be sure that it is happening when the device is already initialized, while devlink_alloc() is performed usually as first line in .probe() routine. This means that we can't combine alloc an register and devlink_alloc_register() can't be valid scenario. Thanks > > --pk