diff mbox series

[RFC,net-next,04/15] devlink: protect devlink dump by the instance lock

Message ID 20221215020155.1619839-5-kuba@kernel.org (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series devlink: code split and structured instance walk | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 1 this patch: 1
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 13 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jakub Kicinski Dec. 15, 2022, 2:01 a.m. UTC
Take the instance lock around devlink_nl_fill() when the dumping.
We are only dumping basic info so in the worst case we were only
risking data races until now.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 net/devlink/basic.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Jiri Pirko Dec. 15, 2022, 8:42 a.m. UTC | #1
Thu, Dec 15, 2022 at 03:01:44AM CET, kuba@kernel.org wrote:
>Take the instance lock around devlink_nl_fill() when the dumping.
>We are only dumping basic info so in the worst case we were only
>risking data races until now.
>
>Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Should this be a separate patch targeted to -net with proper "fixes"
instead?
Jakub Kicinski Dec. 15, 2022, 7:17 p.m. UTC | #2
On Thu, 15 Dec 2022 09:42:27 +0100 Jiri Pirko wrote:
> Thu, Dec 15, 2022 at 03:01:44AM CET, kuba@kernel.org wrote:
> >Take the instance lock around devlink_nl_fill() when the dumping.
> >We are only dumping basic info so in the worst case we were only
> >risking data races until now.
> 
> Should this be a separate patch targeted to -net with proper "fixes"
> instead?

Will do, if nothing else it will make the series smaller :)
But TBH I could not spot any issue other than perhaps non-atomic 
dump of the reload stats, but that's meh..
diff mbox series

Patch

diff --git a/net/devlink/basic.c b/net/devlink/basic.c
index 4b0938a1854e..e01ba7999b91 100644
--- a/net/devlink/basic.c
+++ b/net/devlink/basic.c
@@ -1330,10 +1330,13 @@  static int devlink_nl_cmd_get_dumpit(struct sk_buff *msg,
 			continue;
 		}
 
+		devl_lock(devlink);
 		err = devlink_nl_fill(msg, devlink, DEVLINK_CMD_NEW,
 				      NETLINK_CB(cb->skb).portid,
 				      cb->nlh->nlmsg_seq, NLM_F_MULTI);
+		devl_unlock(devlink);
 		devlink_put(devlink);
+
 		if (err)
 			goto out;
 		idx++;