Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2514462lqp; Mon, 25 Mar 2024 00:35:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW3FagMQoE4in0hXB7aFHVLFu1ug8ut2QO7KOLHuW5xH4dcN/ZmOztF/bh6V9nFrtYVAh/cnJr0z5oz4Sgq0hrcW++9aL0gw9/OyzXMcw== X-Google-Smtp-Source: AGHT+IGB4UOXgHeMrUUxYeE6NkghFeKjgXSVEy5Xny+6fQboYrdc7JRDdyKIJJ1lQQABb+fCJpjc X-Received: by 2002:a50:aadd:0:b0:56b:c1c7:63cd with SMTP id r29-20020a50aadd000000b0056bc1c763cdmr4211046edc.31.1711352158758; Mon, 25 Mar 2024 00:35:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711352158; cv=pass; d=google.com; s=arc-20160816; b=XCXe4ktsW4Jg4vBuXZu6aoKHvFEf8U3q+Ad4JewrFV5e+QyFzhgE+IrMgkGplmrufV aNhS6WTHVKm0sWCavdLy53WhC6AYMTnNHE+BcZCMjL4kRCk0Q0pfRy8PoFLtL7QiPChs 7LTbIuPVwkiOy83RO/AAKpdVrWnk36twSFX6vAvRXWsbpNIv+S8Xc+PhGmpuQQw5zdcp TYVyInH6lynTOtttDxiWWd9O1BjB6BSUwRHp8c21SyV68Scyff7Clfox5JoG4K7z0Cje 2OHgY1XWlgyyAaLdWMfvaJqnzvl2sB9FMqRch5P1bLZwO61RIOA+3aaOvG6jRqusfgsU qYOQ== 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=AmmkFbR2JI9fXWusiUXi3UwcL9KCvmFPrQwlZZgNq2I=; fh=tlNZfP7PAALaXZiTBQKQhkW6eNzFokNMXB5ZY5HYiQI=; b=cbz4isoHIGGjwa3cXhhw4COr5WoWztOj9FKgLcAGH6lsNBuoPoibPE6Q60dVGiVeDA 8YOoYX0MNT9oFRThBwh7bVjnKqxopXSf/wJSAOPU3yQMmc4EuJ8Ykinm8H0sBbPvtXNz eq7vD/eZHQT/pmUW2em+J+UNHuhp6nuNbU4AYk67ReR8rMTLNCegb+q4TUdJC5ux0cQg J8DyGGrv4bOqFpykS8Fbk6+YxS3JmwCsLArVO3OlGEgqL2Urua4QiyflpVMYFJHS3+xz v/CKr1sDRr4zUAJUNvhTvEpB/pGo2B36TTC5uzB1pU8dFiE+YEWh1gybwx7XpQMgOBg0 WOgg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aSw4XSsp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113540-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113540-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 g11-20020a0564021ecb00b0056c0a2c5f35si1065501edg.143.2024.03.25.00.35.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 00:35:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113540-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=aSw4XSsp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113540-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113540-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 7E22C1F2F4FF for ; Mon, 25 Mar 2024 07:35:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A2BF1C1BF3; Sun, 24 Mar 2024 22:45:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aSw4XSsp" 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 018F11C133B; Sun, 24 Mar 2024 22:45:41 +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=1711320342; cv=none; b=a2yDAqOt23pCLkzNTRUDOSZ403VXeecl8lb8jdCLOlzfVUG2cCzhfAzptlH5NHZNOgd+u1xHLY3+jOZr3Ph7GYzlptSY0MHMH49kZdpbfyc2wTKe0opxoylMk2AyvP191w1A3WGXJ1ZEDCaCOxRWFIHhy51M9Q64zCFjAEZl+bc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320342; c=relaxed/simple; bh=x5AIzp5pRdirbY3SVQfZZp+FdEWGqXBMpSCwWGurQY0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n4kB1EAG5foxAthMZM1h1s6hiAFjjjP1iXCyLrb5ZK4zD2rEU3yPVDCXOU5jifHXiaSVbtEHSeHJ/aQDeuQq9VuVX4KR/6qkRgTSSUoJ58DPyFejPf/odICrDaRvLp5yjvza6meVBSNhhF+JgwelRrSfDyL0D1KLNB6xYofLmrs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aSw4XSsp; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EFFBC43390; Sun, 24 Mar 2024 22:45:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320341; bh=x5AIzp5pRdirbY3SVQfZZp+FdEWGqXBMpSCwWGurQY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aSw4XSsp0NXt6uJIvJJAz5DNbT5sk37NT7w9yOtwL37174Uro20eo962GBgdJMx2J 7wFQ+F/7KM6qi/n3rzsDkciwMBPSv1Bd7w/VWqMWe4ZqRYEDGnlX+1vXiU20atdVBi N9+Gyt4CLclB6n271jQvrBnbSLAxCIQoEDEo4IO1k7zzfX+feaDsCXoD7pYa0twrjo frAdzpOHyvJTSw1aon4CetfmhwmBokcB1B8hjwq3T2m5MSNcn99xt3dBZBLufok98C b5o8Wc3WCbr3KxTgjjU/Zy/xWXTbSoFAo2qQIAILpd+KlOBIg79LuQRMCZNh8GQYoV x4r7ItfvhljuA== 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.8 649/715] devlink: Fix devlink parallel commands processing Date: Sun, 24 Mar 2024 18:33:48 -0400 Message-ID: <20240324223455.1342824-650-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-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 499885c8b9cae..593605c1b1ef4 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -193,12 +193,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