mirror of https://github.com/torvalds/linux.git
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>
This commit is contained in:
parent
eb4431bf88
commit
3db835dd8f
|
|
@ -59,6 +59,7 @@
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <linux/uaccess.h>
|
#include <linux/uaccess.h>
|
||||||
|
#include <linux/mutex.h>
|
||||||
#include "linux/ntb.h"
|
#include "linux/ntb.h"
|
||||||
#include "linux/ntb_transport.h"
|
#include "linux/ntb_transport.h"
|
||||||
|
|
||||||
|
|
@ -241,6 +242,9 @@ struct ntb_transport_ctx {
|
||||||
struct work_struct link_cleanup;
|
struct work_struct link_cleanup;
|
||||||
|
|
||||||
struct dentry *debugfs_node_dir;
|
struct dentry *debugfs_node_dir;
|
||||||
|
|
||||||
|
/* Make sure workq of link event be executed serially */
|
||||||
|
struct mutex link_event_lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
@ -1024,6 +1028,7 @@ static void ntb_transport_link_cleanup_work(struct work_struct *work)
|
||||||
struct ntb_transport_ctx *nt =
|
struct ntb_transport_ctx *nt =
|
||||||
container_of(work, struct ntb_transport_ctx, link_cleanup);
|
container_of(work, struct ntb_transport_ctx, link_cleanup);
|
||||||
|
|
||||||
|
guard(mutex)(&nt->link_event_lock);
|
||||||
ntb_transport_link_cleanup(nt);
|
ntb_transport_link_cleanup(nt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1047,6 +1052,8 @@ static void ntb_transport_link_work(struct work_struct *work)
|
||||||
u32 val;
|
u32 val;
|
||||||
int rc = 0, i, spad;
|
int rc = 0, i, spad;
|
||||||
|
|
||||||
|
guard(mutex)(&nt->link_event_lock);
|
||||||
|
|
||||||
/* send the local info, in the opposite order of the way we read it */
|
/* send the local info, in the opposite order of the way we read it */
|
||||||
|
|
||||||
if (nt->use_msi) {
|
if (nt->use_msi) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue