From patchwork Thu Mar 28 07:27:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 13608071 X-Patchwork-Delegate: kuba@kernel.org Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (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 54268224D0 for ; Thu, 28 Mar 2024 07:27:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711610878; cv=none; b=PDw5dpQ2JH5OmgwFrP+1Ew/hThkv6Mz1B94/znNEQwh4EgGzPFZJeaOT41Lb5uLSA0yCdJ7QBVIoVZVCELFE6KiKiAAY8rb9XBsD97iFHw3s17BePDp6Z8f5nFjYX4nPhZ41ARig2p7trhPLSIte16U9ItJXQLd6VP2AwmeOZeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711610878; c=relaxed/simple; bh=gIrnG1iBFeXw1dwlQxHrJsjRLf5N4eGIDkOmKNjFuJM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=NXrKxiNeU4eykkv6L9NMPlCxUdg+HfV2i0eISyHRhzDGl6hoqLQg0tw76ZDWo+raUm9IZQX+Mj1g87aTq7AYFfwhsP3GV0acgWh7n02hMvOj95Pfk519xB/WCnlO2ePQ45wlIVUNli53sV093SYrFZNXdf7mto+3bpYE9YAzFLg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=AuZlg5Qu; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="AuZlg5Qu" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-To:Resent-Cc: Resent-Message-ID:In-Reply-To:References; bh=0P3K3P8x7LTqL9tZ0XygcKdtIshRGr5idfmac1j0PiM=; t=1711610875; x=1712820475; b=AuZlg5QuSvqWzc6wdAguOM3mSG15yWcWjyF30yeyFk9BrS3U1iiWNj3QranvPlvFE2WLcdX1Wo1 Fh2wd4rVdv3i1b9PHkDObyNWJGTlOA9q+7PDMV/xdVZHItuVUcltcKM250m3B+jGCS/Ccz25wzUFk Ih0wgCxPAgzs6F2iMROfPYiyBQqL+ws7ld4MTC/BhtwXyBGqZBwl8VgZ35BlbdAwOM0b0barCqtnz 22LLle00jn7h0EhamgYAZEWuH7fzW1uDAslelC2neW0tQjxL4DmDT1f/mSBvdw4O9nF7PKmmQDEfp OQxlhk4EKJ4AbBrLB/GMXGBcXMGfyTdS1vvw==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97) (envelope-from ) id 1rpkAx-00000000jvG-34dK; Thu, 28 Mar 2024 08:27:51 +0100 From: Johannes Berg To: netdev@vger.kernel.org Cc: jiri@resnulli.us, jhs@mojatatu.com, victor@mojatatu.com, kuba@kernel.org, pctammela@mojatatu.com, martin@strongswan.org, horms@kernel.org, Johannes Berg Subject: [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL Date: Thu, 28 Mar 2024 08:27:49 +0100 Message-ID: <20240328082748.b6003379b15b.I9da87266ad39fff647828b5822e6ac8898857b71@changeid> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Johannes Berg The new guard/scoped_gard can be useful for the RTNL as well, so add a guard definition for it. It gets used like { guard(rtnl)(); // RTNL held until end of block } or scoped_guard(rtnl) { // RTNL held in this block } as with any other guard/scoped_guard. Signed-off-by: Johannes Berg Reviewed-by: Simon Horman --- v2: resend --- include/linux/rtnetlink.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index cdfc897f1e3c..a7da7dfc06a2 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -7,6 +7,7 @@ #include #include #include +#include #include extern int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, u32 group, int echo); @@ -46,6 +47,8 @@ extern int rtnl_is_locked(void); extern int rtnl_lock_killable(void); extern bool refcount_dec_and_rtnl_lock(refcount_t *r); +DEFINE_LOCK_GUARD_0(rtnl, rtnl_lock(), rtnl_unlock()) + extern wait_queue_head_t netdev_unregistering_wq; extern atomic_t dev_unreg_count; extern struct rw_semaphore pernet_ops_rwsem; From patchwork Thu Mar 28 07:27:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 13608072 X-Patchwork-Delegate: kuba@kernel.org Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (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 ACE412561F for ; Thu, 28 Mar 2024 07:27:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711610878; cv=none; b=QNIdTuLV8a/CQs2UwJORqhsrF11yifwcyUuZsJnlrXaTViAOMlJgO+JSfXU7Q+x9Gg4sJ5QljkjmLoKb/C7x3wKUDCQ0zsWsI95nCvI6oO9NAkajm/zyRFB4unH+G25M1YO/aCOcjugjwkzhwALagDPF4GmooWD085WStqwkzmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711610878; c=relaxed/simple; bh=wkdatT5C0jwZccnhZqFH1RLssfB//i5tEVMb3hYcIe4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FvsWOfOGTVHXMaCb23taMfc/iM7pYzlsM4DHl6BTsJcaN04OkTnnVOTW3iXY6uUkO1ppcEndy8zz92kEyZnGnTJ2N6z1UQwmjlQsnNlS1rUeDg/8uMf9+xRrYmZor+O3xlFYzeSXdvZdMXgUz84pnnvQK78eMyqHKluWuMfc8xM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=MV54KqWu; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="MV54KqWu" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=2AEukLxIliae8y2z4gLCpGetRKM6887Vh6O3ET1Umy4=; t=1711610876; x=1712820476; b=MV54KqWuf0ofls2kfe7rlICL8Ex0EiXwOi3oCJty4ENvzY7 +2lEJa154v9Ty/ybLLzk8cXYZMTnxwkiQ674xDhpx/Ky5A894SV4mC/cLUWcVTmyF/PsJJvN+fx7f jDBDGlX9EG4diZRxcl5nuX+YUgmYWafd+c5mv6ePPbpNnCwGYVC4MzpsOIYz4Wkuk2nS/i5vEQT+m u8DLK+NAJHzH3akSjOwqW9fLG/aDtKzpy+WSB559F/ZR1B0WYO+duLFiVfyqyrICxqI1Z/Ik5Zw52 UEH3KT5BUyus364AX6+IdKwJ+EuJrS86HJN0G9S0SBAhDinrzI39gmXelM4GFHPA==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97) (envelope-from ) id 1rpkAy-00000000jvG-32Hz; Thu, 28 Mar 2024 08:27:52 +0100 From: Johannes Berg To: netdev@vger.kernel.org Cc: jiri@resnulli.us, jhs@mojatatu.com, victor@mojatatu.com, kuba@kernel.org, pctammela@mojatatu.com, martin@strongswan.org, horms@kernel.org, Johannes Berg Subject: [PATCH net-next v2 2/2] netdevice: add DEFINE_FREE() for dev_put Date: Thu, 28 Mar 2024 08:27:50 +0100 Message-ID: <20240328082748.4f7e1895ed81.I1515fdc09a9f39fdbc26558556dd65a2cb03576a@changeid> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240328082748.b6003379b15b.I9da87266ad39fff647828b5822e6ac8898857b71@changeid> References: <20240328082748.b6003379b15b.I9da87266ad39fff647828b5822e6ac8898857b71@changeid> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Johannes Berg For short netdev holds within a function there are still a lot of users of dev_put() rather than netdev_put(). Add DEFINE_FREE() to allow making those safer. Signed-off-by: Johannes Berg Reviewed-by: Simon Horman --- v2: resend --- include/linux/netdevice.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index cb37817d6382..f6c0d731fa35 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4127,6 +4127,8 @@ static inline void dev_put(struct net_device *dev) netdev_put(dev, NULL); } +DEFINE_FREE(dev_put, struct net_device *, if (_T) dev_put(_T)) + static inline void netdev_ref_replace(struct net_device *odev, struct net_device *ndev, netdevice_tracker *tracker,