* [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL
@ 2024-03-28 7:27 Johannes Berg
2024-03-28 7:27 ` [PATCH net-next v2 2/2] netdevice: add DEFINE_FREE() for dev_put Johannes Berg
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Johannes Berg @ 2024-03-28 7:27 UTC (permalink / raw)
To: netdev; +Cc: jiri, jhs, victor, kuba, pctammela, martin, horms, Johannes Berg
From: Johannes Berg <johannes.berg@intel.com>
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 <johannes.berg@intel.com>
---
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 <linux/netdevice.h>
#include <linux/wait.h>
#include <linux/refcount.h>
+#include <linux/cleanup.h>
#include <uapi/linux/rtnetlink.h>
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;
--
2.44.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next v2 2/2] netdevice: add DEFINE_FREE() for dev_put
2024-03-28 7:27 [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL Johannes Berg
@ 2024-03-28 7:27 ` Johannes Berg
2024-04-02 8:28 ` Simon Horman
2024-04-02 8:27 ` [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL Simon Horman
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Johannes Berg @ 2024-03-28 7:27 UTC (permalink / raw)
To: netdev; +Cc: jiri, jhs, victor, kuba, pctammela, martin, horms, Johannes Berg
From: Johannes Berg <johannes.berg@intel.com>
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 <johannes.berg@intel.com>
---
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,
--
2.44.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL
2024-03-28 7:27 [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL Johannes Berg
2024-03-28 7:27 ` [PATCH net-next v2 2/2] netdevice: add DEFINE_FREE() for dev_put Johannes Berg
@ 2024-04-02 8:27 ` Simon Horman
2024-04-02 12:31 ` Jiri Pirko
2024-04-03 9:00 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 7+ messages in thread
From: Simon Horman @ 2024-04-02 8:27 UTC (permalink / raw)
To: Johannes Berg
Cc: netdev, jiri, jhs, victor, kuba, pctammela, martin, Johannes Berg
On Thu, Mar 28, 2024 at 08:27:49AM +0100, Johannes Berg wrote:
> From: Johannes Berg <johannes.berg@intel.com>
>
> 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 <johannes.berg@intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2 2/2] netdevice: add DEFINE_FREE() for dev_put
2024-03-28 7:27 ` [PATCH net-next v2 2/2] netdevice: add DEFINE_FREE() for dev_put Johannes Berg
@ 2024-04-02 8:28 ` Simon Horman
0 siblings, 0 replies; 7+ messages in thread
From: Simon Horman @ 2024-04-02 8:28 UTC (permalink / raw)
To: Johannes Berg
Cc: netdev, jiri, jhs, victor, kuba, pctammela, martin, Johannes Berg
On Thu, Mar 28, 2024 at 08:27:50AM +0100, Johannes Berg wrote:
> From: Johannes Berg <johannes.berg@intel.com>
>
> 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 <johannes.berg@intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL
2024-03-28 7:27 [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL Johannes Berg
2024-03-28 7:27 ` [PATCH net-next v2 2/2] netdevice: add DEFINE_FREE() for dev_put Johannes Berg
2024-04-02 8:27 ` [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL Simon Horman
@ 2024-04-02 12:31 ` Jiri Pirko
2024-04-02 15:04 ` Jakub Kicinski
2024-04-03 9:00 ` patchwork-bot+netdevbpf
3 siblings, 1 reply; 7+ messages in thread
From: Jiri Pirko @ 2024-04-02 12:31 UTC (permalink / raw)
To: Johannes Berg
Cc: netdev, jhs, victor, kuba, pctammela, martin, horms, Johannes Berg
Thu, Mar 28, 2024 at 08:27:49AM CET, johannes@sipsolutions.net wrote:
>From: Johannes Berg <johannes.berg@intel.com>
>
>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 <johannes.berg@intel.com>
Since you add couple of helpers, I believe it is a nice custom to add a
couple of patches that actually uses them. Would that make sense?
>---
>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 <linux/netdevice.h>
> #include <linux/wait.h>
> #include <linux/refcount.h>
>+#include <linux/cleanup.h>
> #include <uapi/linux/rtnetlink.h>
>
> 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;
>--
>2.44.0
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL
2024-04-02 12:31 ` Jiri Pirko
@ 2024-04-02 15:04 ` Jakub Kicinski
0 siblings, 0 replies; 7+ messages in thread
From: Jakub Kicinski @ 2024-04-02 15:04 UTC (permalink / raw)
To: Jiri Pirko
Cc: Johannes Berg, netdev, jhs, victor, pctammela, martin, horms,
Johannes Berg
On Tue, 2 Apr 2024 14:31:31 +0200 Jiri Pirko wrote:
> >Signed-off-by: Johannes Berg <johannes.berg@intel.com>
>
> Since you add couple of helpers, I believe it is a nice custom to add a
> couple of patches that actually uses them. Would that make sense?
We discussed on v1, we want to open up the use in new code but
I don't see any benefit in rewriting existing, well tested code.
The first users are likely to be in wireless.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL
2024-03-28 7:27 [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL Johannes Berg
` (2 preceding siblings ...)
2024-04-02 12:31 ` Jiri Pirko
@ 2024-04-03 9:00 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-03 9:00 UTC (permalink / raw)
To: Johannes Berg
Cc: netdev, jiri, jhs, victor, kuba, pctammela, martin, horms, johannes.berg
Hello:
This series was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:
On Thu, 28 Mar 2024 08:27:49 +0100 you wrote:
> From: Johannes Berg <johannes.berg@intel.com>
>
> 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
> }
>
> [...]
Here is the summary with links:
- [net-next,v2,1/2] rtnetlink: add guard for RTNL
https://git.kernel.org/netdev/net-next/c/464eb03c4a7c
- [net-next,v2,2/2] netdevice: add DEFINE_FREE() for dev_put
https://git.kernel.org/netdev/net-next/c/b1f81b9a535b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-04-03 9:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28 7:27 [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL Johannes Berg
2024-03-28 7:27 ` [PATCH net-next v2 2/2] netdevice: add DEFINE_FREE() for dev_put Johannes Berg
2024-04-02 8:28 ` Simon Horman
2024-04-02 8:27 ` [PATCH net-next v2 1/2] rtnetlink: add guard for RTNL Simon Horman
2024-04-02 12:31 ` Jiri Pirko
2024-04-02 15:04 ` Jakub Kicinski
2024-04-03 9:00 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.