Commit bf6b200b authored by Ido Schimmel's avatar Ido Schimmel Committed by David S. Miller

devlink: Acquire device lock during reload command

Device drivers register with devlink from their probe routines (under
the device lock) by acquiring the devlink instance lock and calling
devl_register().

Drivers that support a devlink reload usually implement the
reload_{down, up}() operations in a similar fashion to their remove and
probe routines, respectively.

However, while the remove and probe routines are invoked with the device
lock held, the reload operations are only invoked with the devlink
instance lock held. It is therefore impossible for drivers to acquire
the device lock from their reload operations, as this would result in
lock inversion.

The motivating use case for invoking the reload operations with the
device lock held is in mlxsw which needs to trigger a PCI reset as part
of the reload. The driver cannot call pci_reset_function() as this
function acquires the device lock. Instead, it needs to call
__pci_reset_function_locked which expects the device lock to be held.

To that end, adjust devlink to always acquire the device lock before the
devlink instance lock when performing a reload.

Do that when reload is explicitly triggered by user space by specifying
the 'DEVLINK_NL_FLAG_NEED_DEV_LOCK' flag in the pre_doit and post_doit
operations of the reload command.

A previous patch already handled the case where reload is invoked as
part of netns dismantle.
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
Signed-off-by: default avatarPetr Machata <petrm@nvidia.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d32c3825
...@@ -1484,8 +1484,8 @@ operations: ...@@ -1484,8 +1484,8 @@ operations:
dont-validate: [ strict ] dont-validate: [ strict ]
flags: [ admin-perm ] flags: [ admin-perm ]
do: do:
pre: devlink-nl-pre-doit pre: devlink-nl-pre-doit-dev-lock
post: devlink-nl-post-doit post: devlink-nl-post-doit-dev-lock
request: request:
attributes: attributes:
- bus-name - bus-name
......
...@@ -138,6 +138,12 @@ int devlink_nl_pre_doit_port(const struct genl_split_ops *ops, ...@@ -138,6 +138,12 @@ int devlink_nl_pre_doit_port(const struct genl_split_ops *ops,
return __devlink_nl_pre_doit(skb, info, DEVLINK_NL_FLAG_NEED_PORT); return __devlink_nl_pre_doit(skb, info, DEVLINK_NL_FLAG_NEED_PORT);
} }
int devlink_nl_pre_doit_dev_lock(const struct genl_split_ops *ops,
struct sk_buff *skb, struct genl_info *info)
{
return __devlink_nl_pre_doit(skb, info, DEVLINK_NL_FLAG_NEED_DEV_LOCK);
}
int devlink_nl_pre_doit_port_optional(const struct genl_split_ops *ops, int devlink_nl_pre_doit_port_optional(const struct genl_split_ops *ops,
struct sk_buff *skb, struct sk_buff *skb,
struct genl_info *info) struct genl_info *info)
...@@ -162,6 +168,13 @@ void devlink_nl_post_doit(const struct genl_split_ops *ops, ...@@ -162,6 +168,13 @@ void devlink_nl_post_doit(const struct genl_split_ops *ops,
__devlink_nl_post_doit(skb, info, 0); __devlink_nl_post_doit(skb, info, 0);
} }
void
devlink_nl_post_doit_dev_lock(const struct genl_split_ops *ops,
struct sk_buff *skb, struct genl_info *info)
{
__devlink_nl_post_doit(skb, info, DEVLINK_NL_FLAG_NEED_DEV_LOCK);
}
static int devlink_nl_inst_single_dumpit(struct sk_buff *msg, static int devlink_nl_inst_single_dumpit(struct sk_buff *msg,
struct netlink_callback *cb, int flags, struct netlink_callback *cb, int flags,
devlink_nl_dump_one_func_t *dump_one, devlink_nl_dump_one_func_t *dump_one,
......
...@@ -846,9 +846,9 @@ const struct genl_split_ops devlink_nl_ops[73] = { ...@@ -846,9 +846,9 @@ const struct genl_split_ops devlink_nl_ops[73] = {
{ {
.cmd = DEVLINK_CMD_RELOAD, .cmd = DEVLINK_CMD_RELOAD,
.validate = GENL_DONT_VALIDATE_STRICT, .validate = GENL_DONT_VALIDATE_STRICT,
.pre_doit = devlink_nl_pre_doit, .pre_doit = devlink_nl_pre_doit_dev_lock,
.doit = devlink_nl_reload_doit, .doit = devlink_nl_reload_doit,
.post_doit = devlink_nl_post_doit, .post_doit = devlink_nl_post_doit_dev_lock,
.policy = devlink_reload_nl_policy, .policy = devlink_reload_nl_policy,
.maxattr = DEVLINK_ATTR_RELOAD_LIMITS, .maxattr = DEVLINK_ATTR_RELOAD_LIMITS,
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
......
...@@ -22,12 +22,17 @@ int devlink_nl_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb, ...@@ -22,12 +22,17 @@ int devlink_nl_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb,
struct genl_info *info); struct genl_info *info);
int devlink_nl_pre_doit_port(const struct genl_split_ops *ops, int devlink_nl_pre_doit_port(const struct genl_split_ops *ops,
struct sk_buff *skb, struct genl_info *info); struct sk_buff *skb, struct genl_info *info);
int devlink_nl_pre_doit_dev_lock(const struct genl_split_ops *ops,
struct sk_buff *skb, struct genl_info *info);
int devlink_nl_pre_doit_port_optional(const struct genl_split_ops *ops, int devlink_nl_pre_doit_port_optional(const struct genl_split_ops *ops,
struct sk_buff *skb, struct sk_buff *skb,
struct genl_info *info); struct genl_info *info);
void void
devlink_nl_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb, devlink_nl_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb,
struct genl_info *info); struct genl_info *info);
void
devlink_nl_post_doit_dev_lock(const struct genl_split_ops *ops,
struct sk_buff *skb, struct genl_info *info);
int devlink_nl_get_doit(struct sk_buff *skb, struct genl_info *info); int devlink_nl_get_doit(struct sk_buff *skb, struct genl_info *info);
int devlink_nl_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb); int devlink_nl_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment