* [PATCH net v3] team: fix hang in team_mode_get()
@ 2020-04-20 15:01 Taehee Yoo
2020-04-20 15:34 ` Jiri Pirko
2020-04-20 20:04 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Taehee Yoo @ 2020-04-20 15:01 UTC (permalink / raw)
To: davem, kuba, jiri, netdev; +Cc: ap420073
When team mode is changed or set, the team_mode_get() is called to check
whether the mode module is inserted or not. If the mode module is not
inserted, it calls the request_module().
In the request_module(), it creates a child process, which is
the "modprobe" process and waits for the done of the child process.
At this point, the following locks were used.
down_read(&cb_lock()); by genl_rcv()
genl_lock(); by genl_rcv_msc()
rtnl_lock(); by team_nl_cmd_options_set()
mutex_lock(&team->lock); by team_nl_team_get()
Concurrently, the team module could be removed by rmmod or "modprobe -r"
The __exit function of team module is team_module_exit(), which calls
team_nl_fini() and it tries to acquire following locks.
down_write(&cb_lock);
genl_lock();
Because of the genl_lock() and cb_lock, this process can't be finished
earlier than request_module() routine.
The problem secenario.
CPU0 CPU1
team_mode_get
request_module()
modprobe -r team_mode_roundrobin
team <--(B)
modprobe team <--(A)
team_mode_roundrobin
By request_module(), the "modprobe team_mode_roundrobin" command
will be executed. At this point, the modprobe process will decide
that the team module should be inserted before team_mode_roundrobin.
Because the team module is being removed.
By the module infrastructure, the same module insert/remove operations
can't be executed concurrently.
So, (A) waits for (B) but (B) also waits for (A) because of locks.
So that the hang occurs at this point.
Test commands:
while :
do
teamd -d &
killall teamd &
modprobe -rv team_mode_roundrobin &
done
The approach of this patch is to hold the reference count of the team
module if the team module is compiled as a module. If the reference count
of the team module is not zero while request_module() is being called,
the team module will not be removed at that moment.
So that the above scenario could not occur.
Fixes: 3d249d4ca7d0 ("net: introduce ethernet teaming device")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
---
v2 -> v3:
- Remove unrelated change
v1 -> v2:
- Remove unnecessary #if statement and 'put' variable
drivers/net/team/team.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index 4004f98e50d9..04845a4017f9 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -468,6 +468,9 @@ static const struct team_mode *team_mode_get(const char *kind)
struct team_mode_item *mitem;
const struct team_mode *mode = NULL;
+ if (!try_module_get(THIS_MODULE))
+ return NULL;
+
spin_lock(&mode_list_lock);
mitem = __find_mode(kind);
if (!mitem) {
@@ -483,6 +486,7 @@ static const struct team_mode *team_mode_get(const char *kind)
}
spin_unlock(&mode_list_lock);
+ module_put(THIS_MODULE);
return mode;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v3] team: fix hang in team_mode_get()
2020-04-20 15:01 [PATCH net v3] team: fix hang in team_mode_get() Taehee Yoo
@ 2020-04-20 15:34 ` Jiri Pirko
2020-04-20 20:04 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Jiri Pirko @ 2020-04-20 15:34 UTC (permalink / raw)
To: Taehee Yoo; +Cc: davem, kuba, netdev
Mon, Apr 20, 2020 at 05:01:33PM CEST, ap420073@gmail.com wrote:
>When team mode is changed or set, the team_mode_get() is called to check
>whether the mode module is inserted or not. If the mode module is not
>inserted, it calls the request_module().
>In the request_module(), it creates a child process, which is
>the "modprobe" process and waits for the done of the child process.
>At this point, the following locks were used.
>down_read(&cb_lock()); by genl_rcv()
> genl_lock(); by genl_rcv_msc()
> rtnl_lock(); by team_nl_cmd_options_set()
> mutex_lock(&team->lock); by team_nl_team_get()
>
>Concurrently, the team module could be removed by rmmod or "modprobe -r"
>The __exit function of team module is team_module_exit(), which calls
>team_nl_fini() and it tries to acquire following locks.
>down_write(&cb_lock);
> genl_lock();
>Because of the genl_lock() and cb_lock, this process can't be finished
>earlier than request_module() routine.
>
>The problem secenario.
>CPU0 CPU1
>team_mode_get
> request_module()
> modprobe -r team_mode_roundrobin
> team <--(B)
> modprobe team <--(A)
> team_mode_roundrobin
>
>By request_module(), the "modprobe team_mode_roundrobin" command
>will be executed. At this point, the modprobe process will decide
>that the team module should be inserted before team_mode_roundrobin.
>Because the team module is being removed.
>
>By the module infrastructure, the same module insert/remove operations
>can't be executed concurrently.
>So, (A) waits for (B) but (B) also waits for (A) because of locks.
>So that the hang occurs at this point.
>
>Test commands:
> while :
> do
> teamd -d &
> killall teamd &
> modprobe -rv team_mode_roundrobin &
> done
>
>The approach of this patch is to hold the reference count of the team
>module if the team module is compiled as a module. If the reference count
>of the team module is not zero while request_module() is being called,
>the team module will not be removed at that moment.
>So that the above scenario could not occur.
>
>Fixes: 3d249d4ca7d0 ("net: introduce ethernet teaming device")
>Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v3] team: fix hang in team_mode_get()
2020-04-20 15:01 [PATCH net v3] team: fix hang in team_mode_get() Taehee Yoo
2020-04-20 15:34 ` Jiri Pirko
@ 2020-04-20 20:04 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-04-20 20:04 UTC (permalink / raw)
To: ap420073; +Cc: kuba, jiri, netdev
From: Taehee Yoo <ap420073@gmail.com>
Date: Mon, 20 Apr 2020 15:01:33 +0000
> When team mode is changed or set, the team_mode_get() is called to check
> whether the mode module is inserted or not. If the mode module is not
> inserted, it calls the request_module().
> In the request_module(), it creates a child process, which is
> the "modprobe" process and waits for the done of the child process.
> At this point, the following locks were used.
> down_read(&cb_lock()); by genl_rcv()
> genl_lock(); by genl_rcv_msc()
> rtnl_lock(); by team_nl_cmd_options_set()
> mutex_lock(&team->lock); by team_nl_team_get()
>
> Concurrently, the team module could be removed by rmmod or "modprobe -r"
> The __exit function of team module is team_module_exit(), which calls
> team_nl_fini() and it tries to acquire following locks.
> down_write(&cb_lock);
> genl_lock();
> Because of the genl_lock() and cb_lock, this process can't be finished
> earlier than request_module() routine.
>
> The problem secenario.
> CPU0 CPU1
> team_mode_get
> request_module()
> modprobe -r team_mode_roundrobin
> team <--(B)
> modprobe team <--(A)
> team_mode_roundrobin
>
> By request_module(), the "modprobe team_mode_roundrobin" command
> will be executed. At this point, the modprobe process will decide
> that the team module should be inserted before team_mode_roundrobin.
> Because the team module is being removed.
>
> By the module infrastructure, the same module insert/remove operations
> can't be executed concurrently.
> So, (A) waits for (B) but (B) also waits for (A) because of locks.
> So that the hang occurs at this point.
>
> Test commands:
> while :
> do
> teamd -d &
> killall teamd &
> modprobe -rv team_mode_roundrobin &
> done
>
> The approach of this patch is to hold the reference count of the team
> module if the team module is compiled as a module. If the reference count
> of the team module is not zero while request_module() is being called,
> the team module will not be removed at that moment.
> So that the above scenario could not occur.
>
> Fixes: 3d249d4ca7d0 ("net: introduce ethernet teaming device")
> Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-20 20:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-20 15:01 [PATCH net v3] team: fix hang in team_mode_get() Taehee Yoo
2020-04-20 15:34 ` Jiri Pirko
2020-04-20 20:04 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).