Skip to content

Commit d32c382

Browse files
idoschdavem330
authored andcommitted
devlink: Allow taking device lock in pre_doit operations
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 <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Signed-off-by: Petr Machata <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c8d0a7d commit d32c382

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

net/devlink/devl_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ typedef int devlink_nl_dump_one_func_t(struct sk_buff *msg,
152152
int flags);
153153

154154
struct devlink *
155-
devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs);
155+
devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs,
156+
bool dev_lock);
156157

157158
int devlink_nl_dumpit(struct sk_buff *msg, struct netlink_callback *cb,
158159
devlink_nl_dump_one_func_t *dump_one);

net/devlink/health.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,8 @@ devlink_health_reporter_get_from_cb_lock(struct netlink_callback *cb)
11511151
struct nlattr **attrs = info->attrs;
11521152
struct devlink *devlink;
11531153

1154-
devlink = devlink_get_from_attrs_lock(sock_net(cb->skb->sk), attrs);
1154+
devlink = devlink_get_from_attrs_lock(sock_net(cb->skb->sk), attrs,
1155+
false);
11551156
if (IS_ERR(devlink))
11561157
return NULL;
11571158

net/devlink/netlink.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#define DEVLINK_NL_FLAG_NEED_PORT BIT(0)
1313
#define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1)
14+
#define DEVLINK_NL_FLAG_NEED_DEV_LOCK BIT(2)
1415

1516
static const struct genl_multicast_group devlink_nl_mcgrps[] = {
1617
[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)
6465
}
6566

6667
struct devlink *
67-
devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs)
68+
devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs,
69+
bool dev_lock)
6870
{
6971
struct devlink *devlink;
7072
unsigned long index;
@@ -78,12 +80,12 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs)
7880
devname = nla_data(attrs[DEVLINK_ATTR_DEV_NAME]);
7981

8082
devlinks_xa_for_each_registered_get(net, index, devlink) {
81-
devl_lock(devlink);
83+
devl_dev_lock(devlink, dev_lock);
8284
if (devl_is_registered(devlink) &&
8385
strcmp(devlink->dev->bus->name, busname) == 0 &&
8486
strcmp(dev_name(devlink->dev), devname) == 0)
8587
return devlink;
86-
devl_unlock(devlink);
88+
devl_dev_unlock(devlink, dev_lock);
8789
devlink_put(devlink);
8890
}
8991

@@ -93,11 +95,13 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs)
9395
static int __devlink_nl_pre_doit(struct sk_buff *skb, struct genl_info *info,
9496
u8 flags)
9597
{
98+
bool dev_lock = flags & DEVLINK_NL_FLAG_NEED_DEV_LOCK;
9699
struct devlink_port *devlink_port;
97100
struct devlink *devlink;
98101
int err;
99102

100-
devlink = devlink_get_from_attrs_lock(genl_info_net(info), info->attrs);
103+
devlink = devlink_get_from_attrs_lock(genl_info_net(info), info->attrs,
104+
dev_lock);
101105
if (IS_ERR(devlink))
102106
return PTR_ERR(devlink);
103107

@@ -117,7 +121,7 @@ static int __devlink_nl_pre_doit(struct sk_buff *skb, struct genl_info *info,
117121
return 0;
118122

119123
unlock:
120-
devl_unlock(devlink);
124+
devl_dev_unlock(devlink, dev_lock);
121125
devlink_put(devlink);
122126
return err;
123127
}
@@ -144,10 +148,11 @@ int devlink_nl_pre_doit_port_optional(const struct genl_split_ops *ops,
144148
static void __devlink_nl_post_doit(struct sk_buff *skb, struct genl_info *info,
145149
u8 flags)
146150
{
151+
bool dev_lock = flags & DEVLINK_NL_FLAG_NEED_DEV_LOCK;
147152
struct devlink *devlink;
148153

149154
devlink = info->user_ptr[0];
150-
devl_unlock(devlink);
155+
devl_dev_unlock(devlink, dev_lock);
151156
devlink_put(devlink);
152157
}
153158

@@ -165,7 +170,7 @@ static int devlink_nl_inst_single_dumpit(struct sk_buff *msg,
165170
struct devlink *devlink;
166171
int err;
167172

168-
devlink = devlink_get_from_attrs_lock(sock_net(msg->sk), attrs);
173+
devlink = devlink_get_from_attrs_lock(sock_net(msg->sk), attrs, false);
169174
if (IS_ERR(devlink))
170175
return PTR_ERR(devlink);
171176
err = dump_one(msg, devlink, cb, flags | NLM_F_DUMP_FILTERED);

net/devlink/region.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,8 @@ int devlink_nl_region_read_dumpit(struct sk_buff *skb,
883883

884884
start_offset = state->start_offset;
885885

886-
devlink = devlink_get_from_attrs_lock(sock_net(cb->skb->sk), attrs);
886+
devlink = devlink_get_from_attrs_lock(sock_net(cb->skb->sk), attrs,
887+
false);
887888
if (IS_ERR(devlink))
888889
return PTR_ERR(devlink);
889890

0 commit comments

Comments
 (0)