linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] thunderbolt: Initialize HopID IDAs in tb_switch_alloc()
@ 2021-03-03 12:13 Mika Westerberg
  2021-03-03 12:13 ` [PATCH 2/2] thunderbolt: Increase runtime PM reference count on DP tunnel discovery Mika Westerberg
  2021-03-08 11:30 ` [PATCH 1/2] thunderbolt: Initialize HopID IDAs in tb_switch_alloc() Mika Westerberg
  0 siblings, 2 replies; 3+ messages in thread
From: Mika Westerberg @ 2021-03-03 12:13 UTC (permalink / raw)
  To: linux-usb
  Cc: Michael Jamet, Yehezkel Bernat, Andreas Noever, Mika Westerberg,
	Chiranjeevi Rapolu, Lukas Wunner

If there is a failure before the tb_switch_add() is called the switch
object is released by tb_switch_release() but at that point HopID IDAs
have not yet been initialized. So we see splat like this:

BUG: spinlock bad magic on CPU#2, kworker/u8:5/115
...
Workqueue: thunderbolt0 tb_handle_hotplug
Call Trace:
 dump_stack+0x97/0xdc
 ? spin_bug+0x9a/0xa7
 do_raw_spin_lock+0x68/0x98
 _raw_spin_lock_irqsave+0x3f/0x5d
 ida_destroy+0x4f/0x127
 tb_switch_release+0x6d/0xfd
 device_release+0x2c/0x7d
 kobject_put+0x9b/0xbc
 tb_handle_hotplug+0x278/0x452
 process_one_work+0x1db/0x396
 worker_thread+0x216/0x375
 kthread+0x14d/0x155
 ? pr_cont_work+0x58/0x58
 ? kthread_blkcg+0x2e/0x2e
 ret_from_fork+0x1f/0x40

Fix this by always initializing HopID IDAs in tb_switch_alloc().

Fixes: 0b2863ac3cfd ("thunderbolt: Add functions for allocating and releasing HopIDs")
Cc: stable@vger.kernel.org
Reported-by: Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/thunderbolt/switch.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
index b63fecca6c2a..2a95b4ce06c0 100644
--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -768,12 +768,6 @@ static int tb_init_port(struct tb_port *port)
 
 	tb_dump_port(port->sw->tb, &port->config);
 
-	/* Control port does not need HopID allocation */
-	if (port->port) {
-		ida_init(&port->in_hopids);
-		ida_init(&port->out_hopids);
-	}
-
 	INIT_LIST_HEAD(&port->list);
 	return 0;
 
@@ -1842,10 +1836,8 @@ static void tb_switch_release(struct device *dev)
 	dma_port_free(sw->dma_port);
 
 	tb_switch_for_each_port(sw, port) {
-		if (!port->disabled) {
-			ida_destroy(&port->in_hopids);
-			ida_destroy(&port->out_hopids);
-		}
+		ida_destroy(&port->in_hopids);
+		ida_destroy(&port->out_hopids);
 	}
 
 	kfree(sw->uuid);
@@ -2025,6 +2017,12 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent,
 		/* minimum setup for tb_find_cap and tb_drom_read to work */
 		sw->ports[i].sw = sw;
 		sw->ports[i].port = i;
+
+		/* Control port does not need HopID allocation */
+		if (i) {
+			ida_init(&sw->ports[i].in_hopids);
+			ida_init(&sw->ports[i].out_hopids);
+		}
 	}
 
 	ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_PLUG_EVENTS);
-- 
2.30.1


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

* [PATCH 2/2] thunderbolt: Increase runtime PM reference count on DP tunnel discovery
  2021-03-03 12:13 [PATCH 1/2] thunderbolt: Initialize HopID IDAs in tb_switch_alloc() Mika Westerberg
@ 2021-03-03 12:13 ` Mika Westerberg
  2021-03-08 11:30 ` [PATCH 1/2] thunderbolt: Initialize HopID IDAs in tb_switch_alloc() Mika Westerberg
  1 sibling, 0 replies; 3+ messages in thread
From: Mika Westerberg @ 2021-03-03 12:13 UTC (permalink / raw)
  To: linux-usb
  Cc: Michael Jamet, Yehezkel Bernat, Andreas Noever, Mika Westerberg,
	Chiranjeevi Rapolu, Lukas Wunner

If the driver is unbound and then bound back it goes over the topology
and figure out the existing tunnels. However, if it finds DP tunnel it
should make sure the domain does not runtime suspend as otherwise it
will tear down the DP tunnel unexpectedly.

Fixes: 6ac6faee5d7d ("thunderbolt: Add runtime PM for Software CM")
Cc: stable@vger.kernel.org
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/thunderbolt/tb.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 1f000ac1728b..c348b1fc0efc 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -138,6 +138,10 @@ static void tb_discover_tunnels(struct tb_switch *sw)
 				parent->boot = true;
 				parent = tb_switch_parent(parent);
 			}
+		} else if (tb_tunnel_is_dp(tunnel)) {
+			/* Keep the domain from powering down */
+			pm_runtime_get_sync(&tunnel->src_port->sw->dev);
+			pm_runtime_get_sync(&tunnel->dst_port->sw->dev);
 		}
 
 		list_add_tail(&tunnel->list, &tcm->tunnel_list);
-- 
2.30.1


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

* Re: [PATCH 1/2] thunderbolt: Initialize HopID IDAs in tb_switch_alloc()
  2021-03-03 12:13 [PATCH 1/2] thunderbolt: Initialize HopID IDAs in tb_switch_alloc() Mika Westerberg
  2021-03-03 12:13 ` [PATCH 2/2] thunderbolt: Increase runtime PM reference count on DP tunnel discovery Mika Westerberg
@ 2021-03-08 11:30 ` Mika Westerberg
  1 sibling, 0 replies; 3+ messages in thread
From: Mika Westerberg @ 2021-03-08 11:30 UTC (permalink / raw)
  To: linux-usb
  Cc: Michael Jamet, Yehezkel Bernat, Andreas Noever,
	Chiranjeevi Rapolu, Lukas Wunner

On Wed, Mar 03, 2021 at 03:13:09PM +0300, Mika Westerberg wrote:
> If there is a failure before the tb_switch_add() is called the switch
> object is released by tb_switch_release() but at that point HopID IDAs
> have not yet been initialized. So we see splat like this:
> 
> BUG: spinlock bad magic on CPU#2, kworker/u8:5/115
> ...
> Workqueue: thunderbolt0 tb_handle_hotplug
> Call Trace:
>  dump_stack+0x97/0xdc
>  ? spin_bug+0x9a/0xa7
>  do_raw_spin_lock+0x68/0x98
>  _raw_spin_lock_irqsave+0x3f/0x5d
>  ida_destroy+0x4f/0x127
>  tb_switch_release+0x6d/0xfd
>  device_release+0x2c/0x7d
>  kobject_put+0x9b/0xbc
>  tb_handle_hotplug+0x278/0x452
>  process_one_work+0x1db/0x396
>  worker_thread+0x216/0x375
>  kthread+0x14d/0x155
>  ? pr_cont_work+0x58/0x58
>  ? kthread_blkcg+0x2e/0x2e
>  ret_from_fork+0x1f/0x40
> 
> Fix this by always initializing HopID IDAs in tb_switch_alloc().
> 
> Fixes: 0b2863ac3cfd ("thunderbolt: Add functions for allocating and releasing HopIDs")
> Cc: stable@vger.kernel.org
> Reported-by: Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>

Applied this and the 2/2 to thunderbolt.git/fixes.

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

end of thread, other threads:[~2021-03-08 11:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03 12:13 [PATCH 1/2] thunderbolt: Initialize HopID IDAs in tb_switch_alloc() Mika Westerberg
2021-03-03 12:13 ` [PATCH 2/2] thunderbolt: Increase runtime PM reference count on DP tunnel discovery Mika Westerberg
2021-03-08 11:30 ` [PATCH 1/2] thunderbolt: Initialize HopID IDAs in tb_switch_alloc() 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).