History

net/mlx5: E-Switch, Use atomic rep state to serialize state change

When the state of rep was introduced, it was also designed to prevent duplicate unloading of the same rep. Considering the following two flows when an eswitch manager is at switchdev mode with n VF reps loaded. +--------------------------------------+--------------------------------+ | cpu-0 | cpu-1 | | -------- | -------- | | mlx5_ib_remove | mlx5_eswitch_disable_sriov | | mlx5_ib_unregister_vport_reps | esw_offloads_cleanup | | mlx5_eswitch_unregister_vport_reps | esw_offloads_unload_all_reps | | __unload_reps_all_vport | __unload_reps_all_vport | +--------------------------------------+--------------------------------+ These two flows will try to unload the same rep. Per original design, once one flow unloads the rep, the state moves to REGISTERED. The 2nd flow will no longer needs to do the unload and bails out. However, as read and write of the state is not atomic, when 1st flow is doing the unload, the state is still LOADED, 2nd flow is able to do the same unload action. Kernel crash will happen. To solve this, driver should do atomic test-and-set for the state. So that only one flow can change the rep state from LOADED to REGISTERED, and proceed to do the actual unloading. Since the state is changing to atomic type, all other read/write should be atomic action as well.

Bodong Wang committed 7 years ago

Commit 6f4e0211 parent 5d9986a2 files · +18 −20Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/mlx5/eswitch.h+1−1
@@ -35,7 +35,7 @@ struct mlx5_eswitch_rep_if { · 34 unmodified lines
3535 void (*unload)(struct mlx5_eswitch_rep *rep);
3636 void *(*get_proto_dev)(struct mlx5_eswitch_rep *rep);
3737 void *priv;
38− u8 state;
38+ atomic_t state;
3939 };
4040
4141 struct mlx5_eswitch_rep {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t