Skip to content

Commit 3db835d

Browse files
fuyuanlijonmason
authored andcommitted
ntb: Add mutex to make link_event_callback executed linearly.
Since the CPU selected by schedule_work is uncertain, multiple link_event callbacks may be executed at same time. For example, after peer's link is up, it is down quickly before local link_work completed. If link_cleanup is added to the workqueue of another CPU, then link_work and link_cleanup may be executed at the same time. So add a mutex to prevent them from being executed concurrently. Signed-off-by: fuyuanli <fuyuanli@didiglobal.com> Reviewed-by: Logan Gunthorpe <logang@deltatee.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
1 parent eb4431b commit 3db835d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/ntb/ntb_transport.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include <linux/slab.h>
6060
#include <linux/types.h>
6161
#include <linux/uaccess.h>
62+
#include <linux/mutex.h>
6263
#include "linux/ntb.h"
6364
#include "linux/ntb_transport.h"
6465

@@ -241,6 +242,9 @@ struct ntb_transport_ctx {
241242
struct work_struct link_cleanup;
242243

243244
struct dentry *debugfs_node_dir;
245+
246+
/* Make sure workq of link event be executed serially */
247+
struct mutex link_event_lock;
244248
};
245249

246250
enum {
@@ -1024,6 +1028,7 @@ static void ntb_transport_link_cleanup_work(struct work_struct *work)
10241028
struct ntb_transport_ctx *nt =
10251029
container_of(work, struct ntb_transport_ctx, link_cleanup);
10261030

1031+
guard(mutex)(&nt->link_event_lock);
10271032
ntb_transport_link_cleanup(nt);
10281033
}
10291034

@@ -1047,6 +1052,8 @@ static void ntb_transport_link_work(struct work_struct *work)
10471052
u32 val;
10481053
int rc = 0, i, spad;
10491054

1055+
guard(mutex)(&nt->link_event_lock);
1056+
10501057
/* send the local info, in the opposite order of the way we read it */
10511058

10521059
if (nt->use_msi) {

0 commit comments

Comments
 (0)