Skip to content

Commit 35539b5

Browse files
lsgunthjonmason
authored andcommitted
ntb_perf: clear link_is_up flag when the link goes down.
When the link goes down, the link_is_up flag did not return to false. This could have caused some subtle corner case bugs when the link goes up and down quickly. Once that was fixed, there was found to be a race if the link was brought down then immediately up. The link_cleanup work would occasionally be scheduled after the next link up event. This would cancel the link_work that was supposed to occur and leave ntb_perf in an unusable state. To fix this we get rid of the link_cleanup work and put the actions directly in the link_down event. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Dave Jiang <dave.jiang@intel.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
1 parent 20572ee commit 35539b5

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

drivers/ntb/test/ntb_perf.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ struct perf_ctx {
133133
spinlock_t db_lock;
134134
struct perf_mw mw;
135135
bool link_is_up;
136-
struct work_struct link_cleanup;
137136
struct delayed_work link_work;
138137
wait_queue_head_t link_wq;
139138
struct dentry *debugfs_node_dir;
@@ -158,10 +157,16 @@ static void perf_link_event(void *ctx)
158157
{
159158
struct perf_ctx *perf = ctx;
160159

161-
if (ntb_link_is_up(perf->ntb, NULL, NULL) == 1)
160+
if (ntb_link_is_up(perf->ntb, NULL, NULL) == 1) {
162161
schedule_delayed_work(&perf->link_work, 2*HZ);
163-
else
164-
schedule_work(&perf->link_cleanup);
162+
} else {
163+
dev_dbg(&perf->ntb->pdev->dev, "link down\n");
164+
165+
if (!perf->link_is_up)
166+
cancel_delayed_work_sync(&perf->link_work);
167+
168+
perf->link_is_up = false;
169+
}
165170
}
166171

167172
static void perf_db_event(void *ctx, int vec)
@@ -547,18 +552,6 @@ static void perf_link_work(struct work_struct *work)
547552
msecs_to_jiffies(PERF_LINK_DOWN_TIMEOUT));
548553
}
549554

550-
static void perf_link_cleanup(struct work_struct *work)
551-
{
552-
struct perf_ctx *perf = container_of(work,
553-
struct perf_ctx,
554-
link_cleanup);
555-
556-
dev_dbg(&perf->ntb->pdev->dev, "%s called\n", __func__);
557-
558-
if (!perf->link_is_up)
559-
cancel_delayed_work_sync(&perf->link_work);
560-
}
561-
562555
static int perf_setup_mw(struct ntb_dev *ntb, struct perf_ctx *perf)
563556
{
564557
struct perf_mw *mw;
@@ -787,7 +780,6 @@ static int perf_probe(struct ntb_client *client, struct ntb_dev *ntb)
787780
perf_setup_mw(ntb, perf);
788781
init_waitqueue_head(&perf->link_wq);
789782
INIT_DELAYED_WORK(&perf->link_work, perf_link_work);
790-
INIT_WORK(&perf->link_cleanup, perf_link_cleanup);
791783

792784
rc = ntb_set_ctx(ntb, perf, &perf_ops);
793785
if (rc)
@@ -807,7 +799,6 @@ static int perf_probe(struct ntb_client *client, struct ntb_dev *ntb)
807799

808800
err_ctx:
809801
cancel_delayed_work_sync(&perf->link_work);
810-
cancel_work_sync(&perf->link_cleanup);
811802
kfree(perf);
812803
err_perf:
813804
return rc;
@@ -823,7 +814,6 @@ static void perf_remove(struct ntb_client *client, struct ntb_dev *ntb)
823814
mutex_lock(&perf->run_mutex);
824815

825816
cancel_delayed_work_sync(&perf->link_work);
826-
cancel_work_sync(&perf->link_cleanup);
827817

828818
ntb_clear_ctx(ntb);
829819
ntb_link_disable(ntb);

0 commit comments

Comments
 (0)