Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2477189lqp; Sun, 24 Mar 2024 22:33:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWP4b3qdXbZBmg3inixqFXuiyIrcXvKamxP1uAOPRFpP3es/BaG3/3MQRASbNv+FDEREeRd4OAUIpObPE3YAV65Nk9naIr0uIcx8rimKg== X-Google-Smtp-Source: AGHT+IHlxvE9qmd8EZWyynVWAHpurHxc1VoMGVnIjzyKQP8x1wUi2sZyiiKcPb/mIOmn+Tc4+713 X-Received: by 2002:a05:6870:3923:b0:222:6406:4ce6 with SMTP id b35-20020a056870392300b0022264064ce6mr7881894oap.25.1711344792385; Sun, 24 Mar 2024 22:33:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711344792; cv=pass; d=google.com; s=arc-20160816; b=jiOZ2y/CPlsZ6LZju3MOgVjDlkmdbD5KCdLI32qSZ/3t56cDWieLQG6AV1UUdHn8Vh L1WrHFCkY2ECYPUEUkLt07Bz+nzw4YhGnugGQfzFkPKvaOK3PjdLbgQzL8tZGuWl7b11 G8rJK3rcr43pk6whj3ahKVS3TlsFUi+fyWLpDF7VvbUPd5L+RkRcVHcxE2WiuQgS9Wzk F3r5nRKO+W+pX8l7iH3Ql6XoVEGvifCuzJGccUxMDYdPY2AqcBKv5QJ1uVfmHdBSOkQg mpktGOkA+pziPTVU2fI3O5oFTBAET8eEje1LbncbalvcwkGON1187AO5vwjAY3dUO3Pk icfw== 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=k1gVHeJMxs1eJEEtTcUxEmTx9wGblbF77FQ9cEuP/wE=; fh=p3vriH4ZjJVuWSL5fFNv4zMhr9i8WcCZ9BBk7JeFxzE=; b=MSKv/jXbjVnAU138hJ76DunXfAA0DduMm9YJe02u4I0MwGEsADJ8/DreurnhZdgTht Aq1TQ4Rnli4WgAqIaR/w5UMEYruJFKboFibt+AoSaIiYZaHxcNNFen5TnYqM55axQ34C 1BTF4PRcjj4W4piJWfWoD5X5M0TL2uTYbFe2QMbTrgwAO8zFyAbm68+GHFCx8m28wEzb TPpZkWu2qVeLot5/9ArW6wGwkjEt9GQfBn1OE7VrTxGKGldpvgT5c7LRI95ihV/6VrOd M0pw/vLIm1xrHmCn5LUn9kqq6UnFhaOcFqO82sXrT2cpsjqjMXXemNCdz2mbZhQP/7/b x2Yw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Mli3KEUb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113970-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113970-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 72-20020a63014b000000b005e8d6617c6csi6945465pgb.563.2024.03.24.22.33.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 22:33:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113970-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Mli3KEUb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113970-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113970-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3583E28A107 for ; Mon, 25 Mar 2024 05:32:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 69B3E21EB7E; Sun, 24 Mar 2024 23:11:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Mli3KEUb" 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 793F812D1E3; Sun, 24 Mar 2024 22:58:11 +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=1711321091; cv=none; b=emyqmvrZzEfZf0dH9u4qR/XLaIAiagdmL6croO9Juj4i4gxGq+WfSssDq3UIewfZfkx0iIVSvSn7JJGYcxNrAwh0iTRK7jHp3pDydjtoCf4I23gZUWjpQa2/pVtYc9+BrV6GdELkx4ZfhjOJBY9r2Ub1lLdvEA9MrcxscZfgQkQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321091; c=relaxed/simple; bh=RH5xBxqj4zna3PlUXqAMUAdnATCX4ojjYcBm2UMLfC4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y7LEHL2h/F914Ujus6UYzE1qJo4EKK87AlqpS1IIgWFlfZbJ8phku5y0/etbLlxI26VTAF5Yh734cAqUllUVJAq7Do3umvGwuEcpsPZ3TZukL8VTDqqyTaLNgrSUeloueKxWqxkyyeIdH4RNwQElxETFTSve4Dd7UTTBu+HxWHQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Mli3KEUb; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C572C433A6; Sun, 24 Mar 2024 22:58:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711321091; bh=RH5xBxqj4zna3PlUXqAMUAdnATCX4ojjYcBm2UMLfC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mli3KEUbgC/r6TM+ilKSQ1WVPvCMvrVe/rs7hEa09MxduuY7YEc44kV1GqZGrraBo 0zjD2HUmFQT2wiMBnbTwLNM4YIETHBu3AiLK73ro1nbL5Ktk+sy4F0jBwR+byh2LUI qYm/pUPWjwzuzG++K8G7KmiKc4V5ggfpX8LJkV3XOpB4qSozaWADJVFT58HX8KCuOR 5Bh1kKfVjLUvg/Q2CsX6o7fAK6zEeETO8VJg2PLKnk897J8Loc6ry0meY2TY+jqYpA U4mKj0Z8zgv6+iUAiUXhaS7RtIFSGNI1jrqz5vogYoHW638Um3DLrtgkGUyj8hT6Er uUm/MGOIDSRew== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ido Schimmel , Jiri Pirko , Petr Machata , Simon Horman , "David S . Miller" , Sasha Levin Subject: [PATCH 6.7 654/713] devlink: Allow taking device lock in pre_doit operations Date: Sun, 24 Mar 2024 18:46:20 -0400 Message-ID: <20240324224720.1345309-655-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: Ido Schimmel [ Upstream commit d32c38256db30a2d55b849e2c77342bc70d58c6e ] Introduce a new private flag ('DEVLINK_NL_FLAG_NEED_DEV_LOCK') to allow netlink commands to specify that they need to acquire the device lock in their pre_doit operation and release it in their post_doit operation. The reload command will use this flag in the subsequent patch. No functional changes intended. Signed-off-by: Ido Schimmel Reviewed-by: Jiri Pirko Signed-off-by: Petr Machata Reviewed-by: Simon Horman Signed-off-by: David S. Miller Stable-dep-of: d7d75124965a ("devlink: Fix devlink parallel commands processing") Signed-off-by: Sasha Levin --- net/devlink/devl_internal.h | 3 ++- net/devlink/health.c | 3 ++- net/devlink/netlink.c | 19 ++++++++++++------- net/devlink/region.c | 3 ++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 178abaf74a107..5ea2e2012e930 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -152,7 +152,8 @@ typedef int devlink_nl_dump_one_func_t(struct sk_buff *msg, int flags); struct devlink * -devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs); +devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, + bool dev_lock); int devlink_nl_dumpit(struct sk_buff *msg, struct netlink_callback *cb, devlink_nl_dump_one_func_t *dump_one); diff --git a/net/devlink/health.c b/net/devlink/health.c index 695df61f8ac2a..71ae121dc739d 100644 --- a/net/devlink/health.c +++ b/net/devlink/health.c @@ -1151,7 +1151,8 @@ devlink_health_reporter_get_from_cb_lock(struct netlink_callback *cb) struct nlattr **attrs = info->attrs; struct devlink *devlink; - devlink = devlink_get_from_attrs_lock(sock_net(cb->skb->sk), attrs); + devlink = devlink_get_from_attrs_lock(sock_net(cb->skb->sk), attrs, + false); if (IS_ERR(devlink)) return NULL; diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 5bb6624f3288e..86f12531bf998 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -11,6 +11,7 @@ #define DEVLINK_NL_FLAG_NEED_PORT BIT(0) #define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1) +#define DEVLINK_NL_FLAG_NEED_DEV_LOCK BIT(2) static const struct genl_multicast_group devlink_nl_mcgrps[] = { [DEVLINK_MCGRP_CONFIG] = { .name = DEVLINK_GENL_MCGRP_CONFIG_NAME }, @@ -64,7 +65,8 @@ int devlink_nl_msg_reply_and_new(struct sk_buff **msg, struct genl_info *info) } struct devlink * -devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs) +devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, + bool dev_lock) { struct devlink *devlink; unsigned long index; @@ -78,12 +80,12 @@ 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_lock(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_unlock(devlink); + devl_dev_unlock(devlink, dev_lock); devlink_put(devlink); } @@ -93,11 +95,13 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs) static int __devlink_nl_pre_doit(struct sk_buff *skb, struct genl_info *info, u8 flags) { + bool dev_lock = flags & DEVLINK_NL_FLAG_NEED_DEV_LOCK; struct devlink_port *devlink_port; struct devlink *devlink; int err; - devlink = devlink_get_from_attrs_lock(genl_info_net(info), info->attrs); + devlink = devlink_get_from_attrs_lock(genl_info_net(info), info->attrs, + dev_lock); if (IS_ERR(devlink)) return PTR_ERR(devlink); @@ -117,7 +121,7 @@ static int __devlink_nl_pre_doit(struct sk_buff *skb, struct genl_info *info, return 0; unlock: - devl_unlock(devlink); + devl_dev_unlock(devlink, dev_lock); devlink_put(devlink); return err; } @@ -144,10 +148,11 @@ int devlink_nl_pre_doit_port_optional(const struct genl_split_ops *ops, static void __devlink_nl_post_doit(struct sk_buff *skb, struct genl_info *info, u8 flags) { + bool dev_lock = flags & DEVLINK_NL_FLAG_NEED_DEV_LOCK; struct devlink *devlink; devlink = info->user_ptr[0]; - devl_unlock(devlink); + devl_dev_unlock(devlink, dev_lock); devlink_put(devlink); } @@ -165,7 +170,7 @@ static int devlink_nl_inst_single_dumpit(struct sk_buff *msg, struct devlink *devlink; int err; - devlink = devlink_get_from_attrs_lock(sock_net(msg->sk), attrs); + devlink = devlink_get_from_attrs_lock(sock_net(msg->sk), attrs, false); if (IS_ERR(devlink)) return PTR_ERR(devlink); err = dump_one(msg, devlink, cb, flags | NLM_F_DUMP_FILTERED); diff --git a/net/devlink/region.c b/net/devlink/region.c index 0aab7b82d6780..e3bab458db940 100644 --- a/net/devlink/region.c +++ b/net/devlink/region.c @@ -883,7 +883,8 @@ int devlink_nl_region_read_dumpit(struct sk_buff *skb, start_offset = state->start_offset; - devlink = devlink_get_from_attrs_lock(sock_net(cb->skb->sk), attrs); + devlink = devlink_get_from_attrs_lock(sock_net(cb->skb->sk), attrs, + false); if (IS_ERR(devlink)) return PTR_ERR(devlink); -- 2.43.0