Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thunderbolt: Run tb_xdp_handle_request() in system workqueue

We run all XDomain requests during discovery in tb->wq and since it only
runs one work at the time it means that sending back reply to the other
domain may be delayed too much depending whether there is an active
XDomain discovery request running.

To make sure we can send reply to the other domain as soon as possible
run tb_xdp_handle_request() in system workqueue instead. Since the
device can be hot-removed in the middle we need to make sure the domain
structure is still around when the function is run so increase reference
count before we schedule the reply work.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>

+11 -2
+7
drivers/thunderbolt/tb.h
··· 492 492 int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd); 493 493 int tb_domain_disconnect_all_paths(struct tb *tb); 494 494 495 + static inline struct tb *tb_domain_get(struct tb *tb) 496 + { 497 + if (tb) 498 + get_device(&tb->dev); 499 + return tb; 500 + } 501 + 495 502 static inline void tb_domain_put(struct tb *tb) 496 503 { 497 504 put_device(&tb->dev);
+4 -2
drivers/thunderbolt/xdomain.c
··· 524 524 out: 525 525 kfree(xw->pkg); 526 526 kfree(xw); 527 + 528 + tb_domain_put(tb); 527 529 } 528 530 529 531 static bool ··· 544 542 kfree(xw); 545 543 return false; 546 544 } 547 - xw->tb = tb; 545 + xw->tb = tb_domain_get(tb); 548 546 549 - queue_work(tb->wq, &xw->work); 547 + schedule_work(&xw->work); 550 548 return true; 551 549 } 552 550