Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2606048lqp; Mon, 25 Mar 2024 04:19:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXmsX6t7/8WWyFroMQNLDE9bJsFXy3vIER3WYuaUq74YI6keQ+Q2tLKvDlLb4EzjGAUUPLc2LCsu/Vp8XaUNk9pR8zmpJ6WJm4sBfIufA== X-Google-Smtp-Source: AGHT+IE82zj18QdgTdaeW493oGoT/1G5wbsxPTv/gPVLINMlZ/tyjznr/pyErjRfLF9vkVs7yoyn X-Received: by 2002:a2e:b8d6:0:b0:2d6:bb86:5174 with SMTP id s22-20020a2eb8d6000000b002d6bb865174mr6020076ljp.7.1711365591281; Mon, 25 Mar 2024 04:19:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711365591; cv=pass; d=google.com; s=arc-20160816; b=IW7am14DJMK8BSlVn6EKB882qJTKSlgeK7hnQB0j7ddbAhepUmh4wko0QDZuK4qzLs 7mCmMQw0Zv+NyuXJr9knqLELEopg8UlLtntwQXn82B9NNLt9RbNki0NJqOsA4ME0CMWt FJTO5eefKC7AnY2De3HPKFTKttdo8HGBpcvo8mygrGWqrqQ3+TCFvoRnbyQFxrqwYKwp QaFWNsthEM9bzCTpSeXQ4JJmBMxpxitUi+Pqp7MzRaHP61FGvx8i7I2lFa/azKA5e/vC MI2JPWzJh0VmJNgdNCIbTQT38ch1KuYs07rusyN6tREfikUc0xrKZAM2NI73urf+tx8d kHjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nmAdZh8Ki26zo+9afU81jEQBNzQRqJSEBBIwOQDXnxE=; fh=tlNZfP7PAALaXZiTBQKQhkW6eNzFokNMXB5ZY5HYiQI=; b=O+IYOpr+oNH7ecV5P7hI9MeNrUVkHRN9ZqYk3CNoWYcmodCakZswMaCbZzDdFVf5+B w5iAYmObqPN9AV+HqYkIq+d0j1dufOiZ2MYExtlcTE3l9vdCMBeUvQkK/PUAU6/mUM6m NC9b76cGYBxfPqIJKG9MVOokFha7K3fLdOhevu4Z7Ug6vonztKiThQt51FDTGE5BjgXg hp+QS0LFClu9yRhmRTNSg2lEnkxVaG7OGdhuhNlE7sZiv9bUH7tZ4LPdhSoeBQqoqIyy M+zTEL7ZnGoQrfdv3tXe+Dgj8NbSNoXBjBSmNPVF6ehYPje8TI57lfzaJlL467GErj6O 1JWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=igKg23+t; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115563-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115563-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j2-20020a170906410200b00a46674fd64bsi2437486ejk.122.2024.03.25.04.19.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 04:19:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115563-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=igKg23+t; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115563-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115563-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EFEA31F3284E for ; Mon, 25 Mar 2024 11:19:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D44E2B36E6; Mon, 25 Mar 2024 02:43:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="igKg23+t" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6DD3612D1EA; Sun, 24 Mar 2024 22:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321092; cv=none; b=UwD5AWzCEUec7ioPrWgtiVZGbemP4Ehuq+zSLrbmgrhCBsqVj37a4K9iflnIeKobll3lGn/74eAvyyGvwjX4zXMq/hDmEIllDM/q+aLUwSlszWUjBHFcPjluHXYPL62z5aHvWSZR48UuImSiTyJFgiX0MqAinSbEKO+rkMoMPl8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321092; c=relaxed/simple; bh=OFz3rgG/onaMQNrx3aFTgv7GqQgKkbhaPyQhmTu14o4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m7xOCictZhXs9maZZywZ/tRe96B4miXWqnVYYr0E1q0y7DFUHzYbnEU8L7VX8+r9R/nCdJHbKkwUt2Ml6ZrsgaJ46Ho+US/Nf2MQDwUdqDqDxQqza2oIOLI4KoqtrndDdf4/YHebitJ0EQz7DIy8ckVtXCPcpi59QwS2i2c9SyM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=igKg23+t; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98F4DC43394; Sun, 24 Mar 2024 22:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711321092; bh=OFz3rgG/onaMQNrx3aFTgv7GqQgKkbhaPyQhmTu14o4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=igKg23+tbZ35ziy6nQ+gdCT4XgVj4FbYZWkJdbGFRGm1QFBvIGEsQycVmCBhu9UMP 13mTVCfoHhgJEV/x6FBllvzoIvpKSK+vKm9+XGk5BKsYvnzdF4q9JN+/4/cDpN5PKm yivvvAlIFf2V066mejkjGvYZNJQqvKvPSWzQ/oZQMOEJgg7bvymulPViyZ0LQS33CV SVw05LDRzeIQz+2D6RxphDqkpqkViwA07dv0DoJgrqrX352tf2SCcIgh/1ZZa+Xz4W rYNkK+dm8rr/KOPkV+DEzkjqYFrILvB3BVoIfXVjrCOj9NDqanAg9TTEZ12hefuCdU KCDARP459O6xA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Shay Drory , Jiri Pirko , "David S . Miller" , Sasha Levin Subject: [PATCH 6.7 655/713] devlink: Fix devlink parallel commands processing Date: Sun, 24 Mar 2024 18:46:21 -0400 Message-ID: <20240324224720.1345309-656-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324224720.1345309-1-sashal@kernel.org> References: <20240324224720.1345309-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Shay Drory [ Upstream commit d7d75124965aee23e5e4421d78376545cf070b0a ] Commit 870c7ad4a52b ("devlink: protect devlink->dev by the instance lock") added devlink instance locking inside a loop that iterates over all the registered devlink instances on the machine in the pre-doit phase. This can lead to serialization of devlink commands over different devlink instances. For example: While the first devlink instance is executing firmware flash, all commands to other devlink instances on the machine are forced to wait until the first devlink finishes. Therefore, in the pre-doit phase, take the devlink instance lock only for the devlink instance the command is targeting. Devlink layer is taking a reference on the devlink instance, ensuring the devlink->dev pointer is valid. This reference taking was introduced by commit a380687200e0 ("devlink: take device reference for devlink object"). Without this commit, it would not be safe to access devlink->dev lockless. Fixes: 870c7ad4a52b ("devlink: protect devlink->dev by the instance lock") Signed-off-by: Shay Drory Reviewed-by: Jiri Pirko Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/devlink/netlink.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 86f12531bf998..0f41fded6a6d7 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -80,12 +80,13 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, devname = nla_data(attrs[DEVLINK_ATTR_DEV_NAME]); devlinks_xa_for_each_registered_get(net, index, devlink) { - devl_dev_lock(devlink, dev_lock); - if (devl_is_registered(devlink) && - strcmp(devlink->dev->bus->name, busname) == 0 && - strcmp(dev_name(devlink->dev), devname) == 0) - return devlink; - devl_dev_unlock(devlink, dev_lock); + if (strcmp(devlink->dev->bus->name, busname) == 0 && + strcmp(dev_name(devlink->dev), devname) == 0) { + devl_dev_lock(devlink, dev_lock); + if (devl_is_registered(devlink)) + return devlink; + devl_dev_unlock(devlink, dev_lock); + } devlink_put(devlink); } -- 2.43.0