linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] thunderbolt: Do not handle ICM events after domain is stopped
@ 2018-09-03 13:20 Mika Westerberg
  2018-09-03 13:20 ` [PATCH 2/2] thunderbolt: Initialize after IOMMUs Mika Westerberg
  2018-09-14  7:52 ` [PATCH 1/2] thunderbolt: Do not handle ICM events after domain is stopped Mika Westerberg
  0 siblings, 2 replies; 13+ messages in thread
From: Mika Westerberg @ 2018-09-03 13:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andreas Noever, Michael Jamet, Mika Westerberg, Yehezkel Bernat,
	Lukas Wunner, Lu Baolu

If there is a long chain of devices connected when the driver is loaded
ICM sends device connected event for each and those are put to tb->wq
for later processing. Now if the driver gets unloaded in the middle, so
that the work queue is not yet empty it gets flushed by tb_domain_stop().
However, by that time the root switch is already removed so the driver
crashes when it tries to dereference it in ICM event handling callbacks.

Fix this by checking whether the root switch is already removed. If it
is we know that the domain is stopped and we should merely skip handling
the event.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/thunderbolt/icm.c | 49 ++++++++++++++++-----------------------
 1 file changed, 20 insertions(+), 29 deletions(-)

diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c
index e1e264a9a4c7..28fc4ce75edb 100644
--- a/drivers/thunderbolt/icm.c
+++ b/drivers/thunderbolt/icm.c
@@ -738,14 +738,6 @@ icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr)
 	u8 link, depth;
 	u64 route;
 
-	/*
-	 * After NVM upgrade adding root switch device fails because we
-	 * initiated reset. During that time ICM might still send
-	 * XDomain connected message which we ignore here.
-	 */
-	if (!tb->root_switch)
-		return;
-
 	link = pkg->link_info & ICM_LINK_INFO_LINK_MASK;
 	depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >>
 		ICM_LINK_INFO_DEPTH_SHIFT;
@@ -1037,14 +1029,6 @@ icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
 	if (pkg->hdr.packet_id)
 		return;
 
-	/*
-	 * After NVM upgrade adding root switch device fails because we
-	 * initiated reset. During that time ICM might still send device
-	 * connected message which we ignore here.
-	 */
-	if (!tb->root_switch)
-		return;
-
 	route = get_route(pkg->route_hi, pkg->route_lo);
 	authorized = pkg->link_info & ICM_LINK_INFO_APPROVED;
 	security_level = (pkg->hdr.flags & ICM_FLAGS_SLEVEL_MASK) >>
@@ -1408,19 +1392,26 @@ static void icm_handle_notification(struct work_struct *work)
 
 	mutex_lock(&tb->lock);
 
-	switch (n->pkg->code) {
-	case ICM_EVENT_DEVICE_CONNECTED:
-		icm->device_connected(tb, n->pkg);
-		break;
-	case ICM_EVENT_DEVICE_DISCONNECTED:
-		icm->device_disconnected(tb, n->pkg);
-		break;
-	case ICM_EVENT_XDOMAIN_CONNECTED:
-		icm->xdomain_connected(tb, n->pkg);
-		break;
-	case ICM_EVENT_XDOMAIN_DISCONNECTED:
-		icm->xdomain_disconnected(tb, n->pkg);
-		break;
+	/*
+	 * When the domain is stopped we flush its workqueue but before
+	 * that the root switch is removed. In that case we should treat
+	 * the queued events as being canceled.
+	 */
+	if (tb->root_switch) {
+		switch (n->pkg->code) {
+		case ICM_EVENT_DEVICE_CONNECTED:
+			icm->device_connected(tb, n->pkg);
+			break;
+		case ICM_EVENT_DEVICE_DISCONNECTED:
+			icm->device_disconnected(tb, n->pkg);
+			break;
+		case ICM_EVENT_XDOMAIN_CONNECTED:
+			icm->xdomain_connected(tb, n->pkg);
+			break;
+		case ICM_EVENT_XDOMAIN_DISCONNECTED:
+			icm->xdomain_disconnected(tb, n->pkg);
+			break;
+		}
 	}
 
 	mutex_unlock(&tb->lock);
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread
* [PATCH 0/2] thunderbolt: Fixes for v4.19-rc6
@ 2018-09-24 10:20 Mika Westerberg
  2018-09-24 10:20 ` [PATCH 1/2] thunderbolt: Do not handle ICM events after domain is stopped Mika Westerberg
  0 siblings, 1 reply; 13+ messages in thread
From: Mika Westerberg @ 2018-09-24 10:20 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Andreas Noever, Michael Jamet, Mika Westerberg, Yehezkel Bernat,
	Lukas Wunner, linux-kernel

Hi Greg,

This includes two fixes:

  - Stop handling ICM events when the domain is already removed upon module
    removal.

  - If the module is built into the kernel image, initialize after IOMMUs
    to keep the driver working when IOMMUs are enabled.

I've included both patches as well in case prefer to apply them directely
instead of pulling the signed tag.

Thanks!

The following changes since commit 11da3a7f84f19c26da6f86af878298694ede0804:

  Linux 4.19-rc3 (2018-09-09 17:26:43 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt.git tags/thunderbolt-fixes-for-v4.19-rc6

for you to fetch changes up to b3cea5ec12adc0fe0c0d264e56aa97ab617a51d6:

  thunderbolt: Initialize after IOMMUs (2018-09-14 10:45:22 +0300)

----------------------------------------------------------------
thunderbolt: Fixes for v4.19-rc6

----------------------------------------------------------------

Mika Westerberg (2):
  thunderbolt: Do not handle ICM events after domain is stopped
  thunderbolt: Initialize after IOMMUs

 drivers/thunderbolt/icm.c | 49 ++++++++++++++++-----------------------
 drivers/thunderbolt/nhi.c |  2 +-
 2 files changed, 21 insertions(+), 30 deletions(-)

-- 
2.18.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2018-09-24 10:21 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-03 13:20 [PATCH 1/2] thunderbolt: Do not handle ICM events after domain is stopped Mika Westerberg
2018-09-03 13:20 ` [PATCH 2/2] thunderbolt: Initialize after IOMMUs Mika Westerberg
2018-09-05  8:47   ` Lukas Wunner
2018-09-05  9:46     ` Mika Westerberg
2018-09-06  8:13       ` Lukas Wunner
2018-09-06 10:36         ` Mika Westerberg
2018-09-06 11:00           ` Lukas Wunner
2018-09-06 11:07             ` Mika Westerberg
2018-09-06 11:21               ` Lukas Wunner
2018-09-06 11:46                 ` Mika Westerberg
2018-09-14  7:52   ` Mika Westerberg
2018-09-14  7:52 ` [PATCH 1/2] thunderbolt: Do not handle ICM events after domain is stopped Mika Westerberg
2018-09-24 10:20 [PATCH 0/2] thunderbolt: Fixes for v4.19-rc6 Mika Westerberg
2018-09-24 10:20 ` [PATCH 1/2] thunderbolt: Do not handle ICM events after domain is stopped Mika Westerberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).