From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B74D6C4332F for ; Thu, 18 Nov 2021 07:51:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9EA1861AF7 for ; Thu, 18 Nov 2021 07:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244056AbhKRHyE (ORCPT ); Thu, 18 Nov 2021 02:54:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:58372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244093AbhKRHxY (ORCPT ); Thu, 18 Nov 2021 02:53:24 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D7D6C61AF0; Thu, 18 Nov 2021 07:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637221824; bh=KAG7SN0Nsukz5N3+M2JeOStH3aani0FQz1yVYpMxlI4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=U/rCN1F5P7OJGKozjYIbfysxd1GNoJ7r2XbViuikvAKkPDKKnksCbzJa2IlbHnRax GoWEfisdL0drlW2opov+3kvSMtdymX3KwC9CSx24ibrIoE2wHpH/c7irksbGH7gCXW Q0h6qL7SSdphsv4RS+Mfpa5oRKD4q0K89KOfSTE4myt5TH3/fTYkWlEfO4FLCP3sP+ 0zdH/5WvExcVwBbWzxoMWRPvlXY+fKCPsUn24Llx2zkf79eennDsgYutbug/fZ1agB KhkNMnssPhXu7tzV+BBf3QYXcyhYEGTax+k0QCz2kH4UZ+pBEFmZQ+Et0intFBkLWn 4KRAyyeFsgTjA== Date: Thu, 18 Nov 2021 09:50:20 +0200 From: Leon Romanovsky To: Jakub Kicinski Cc: "David S . Miller" , Alexandre Belloni , Andrew Lunn , Aya Levin , Claudiu Manoil , drivers@pensando.io, Florian Fainelli , Ido Schimmel , intel-wired-lan@lists.osuosl.org, Ioana Ciornei , Jesse Brandeburg , Jiri Pirko , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Michael Chan , netdev@vger.kernel.org, oss-drivers@corigine.com, Saeed Mahameed , Shannon Nelson , Simon Horman , Taras Chornyi , Tariq Toukan , Tony Nguyen , UNGLinuxDriver@microchip.com, Vivien Didelot , Vladimir Oltean Subject: Re: [PATCH net-next 5/6] devlink: Reshuffle resource registration logic Message-ID: References: <6176a137a4ded48501e8a06fda0e305f9cfc787c.1637173517.git.leonro@nvidia.com> <20211117204956.6a36963b@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211117204956.6a36963b@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 17, 2021 at 08:49:56PM -0800, Jakub Kicinski wrote: > On Wed, 17 Nov 2021 20:26:21 +0200 Leon Romanovsky wrote: > > - top_hierarchy = parent_resource_id == DEVLINK_RESOURCE_ID_PARENT_TOP; > > - > > - mutex_lock(&devlink->lock); > > - resource = devlink_resource_find(devlink, NULL, resource_id); > > - if (resource) { > > - err = -EINVAL; > > - goto out; > > - } > > + WARN_ON(devlink_resource_find(devlink, NULL, resource_id)); > > This is not atomic with the add now. And it shouldn't. devlink_resource_find() will return valid resource only if there driver is completely bogus with races or incorrect allocations of resource_id. devlink_*_register(..) mutex_lock(&devlink->lock); if (devlink_*_find(...)) { mutex_unlock(&devlink->lock); return ....; } ..... It is almost always wrong from locking and layering perspective the pattern above, as it is racy by definition if not protected by top layer. There are exceptions from the rule above, but devlink is clearly not the one of such exceptions. Thanks