All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] soundwire: bus: Fix for missing UNATTACH when re-enumerating
@ 2022-08-29  9:44 ` Richard Fitzgerald
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2022-08-29  9:44 UTC (permalink / raw)
  To: vkoul, yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale
  Cc: alsa-devel, linux-kernel, patches, Richard Fitzgerald

This is an alternative fix for the race where a device that is reset can
be found on #0 and its ID reprogrammed before the bus code has handled
a PING showing it unattached.

The other possible fix is here:
https://lore.kernel.org/all/20220825122241.273090-4-rf@opensource.cirrus.com/

Richard Fitzgerald (1):
  soundwire: bus: Don't re-enumerate before status is UNATTACHED

 drivers/soundwire/bus.c | 7 +++++++
 1 file changed, 7 insertions(+)

-- 
2.30.2


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

* [PATCH 0/1] soundwire: bus: Fix for missing UNATTACH when re-enumerating
@ 2022-08-29  9:44 ` Richard Fitzgerald
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2022-08-29  9:44 UTC (permalink / raw)
  To: vkoul, yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale
  Cc: patches, alsa-devel, Richard Fitzgerald, linux-kernel

This is an alternative fix for the race where a device that is reset can
be found on #0 and its ID reprogrammed before the bus code has handled
a PING showing it unattached.

The other possible fix is here:
https://lore.kernel.org/all/20220825122241.273090-4-rf@opensource.cirrus.com/

Richard Fitzgerald (1):
  soundwire: bus: Don't re-enumerate before status is UNATTACHED

 drivers/soundwire/bus.c | 7 +++++++
 1 file changed, 7 insertions(+)

-- 
2.30.2


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

* [PATCH 1/1] soundwire: bus: Don't re-enumerate before status is UNATTACHED
  2022-08-29  9:44 ` Richard Fitzgerald
@ 2022-08-29  9:44   ` Richard Fitzgerald
  -1 siblings, 0 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2022-08-29  9:44 UTC (permalink / raw)
  To: vkoul, yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale
  Cc: alsa-devel, linux-kernel, patches, Richard Fitzgerald

Don't re-enumerate a peripheral on #0 until we have seen and
handled an UNATTACHED notification for that peripheral.

Without this, it is possible for the UNATTACHED status to be missed
and so the slave->status remains at ATTACHED. If slave->status never
changes to UNATTACHED the child driver will never be notified of the
UNATTACH, and the code in sdw_handle_slave_status() will skip the
second part of enumeration because the slave->status has not changed.

This scenario can happen because PINGs are handled in a workqueue
function which is working from a snapshot of an old PING, and there
is no guarantee when this function will run.

A peripheral could report attached in the PING being handled by
sdw_handle_slave_status(), but has since reverted to device #0 and is
then found in the loop in sdw_program_device_num(). Previously the
code would not have updated slave->status to UNATTACHED because it had
not yet handled a PING where that peripheral had UNATTACHED.

This situation happens fairly frequently with multiple peripherals on
a bus that are intentionally reset (for example after downloading
firmware).

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 drivers/soundwire/bus.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
index cb77da84a4f9..a3d3d66b3410 100644
--- a/drivers/soundwire/bus.c
+++ b/drivers/soundwire/bus.c
@@ -766,6 +766,13 @@ static int sdw_program_device_num(struct sdw_bus *bus)
 			if (sdw_compare_devid(slave, id) == 0) {
 				found = true;
 
+				/*
+				 * Don't re-enumerate a device until we've seen
+				 * it UNATTACH.
+				 */
+				if (slave->status != SDW_SLAVE_UNATTACHED)
+					break;
+
 				/*
 				 * Assign a new dev_num to this Slave and
 				 * not mark it present. It will be marked
-- 
2.30.2


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

* [PATCH 1/1] soundwire: bus: Don't re-enumerate before status is UNATTACHED
@ 2022-08-29  9:44   ` Richard Fitzgerald
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2022-08-29  9:44 UTC (permalink / raw)
  To: vkoul, yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale
  Cc: patches, alsa-devel, Richard Fitzgerald, linux-kernel

Don't re-enumerate a peripheral on #0 until we have seen and
handled an UNATTACHED notification for that peripheral.

Without this, it is possible for the UNATTACHED status to be missed
and so the slave->status remains at ATTACHED. If slave->status never
changes to UNATTACHED the child driver will never be notified of the
UNATTACH, and the code in sdw_handle_slave_status() will skip the
second part of enumeration because the slave->status has not changed.

This scenario can happen because PINGs are handled in a workqueue
function which is working from a snapshot of an old PING, and there
is no guarantee when this function will run.

A peripheral could report attached in the PING being handled by
sdw_handle_slave_status(), but has since reverted to device #0 and is
then found in the loop in sdw_program_device_num(). Previously the
code would not have updated slave->status to UNATTACHED because it had
not yet handled a PING where that peripheral had UNATTACHED.

This situation happens fairly frequently with multiple peripherals on
a bus that are intentionally reset (for example after downloading
firmware).

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 drivers/soundwire/bus.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
index cb77da84a4f9..a3d3d66b3410 100644
--- a/drivers/soundwire/bus.c
+++ b/drivers/soundwire/bus.c
@@ -766,6 +766,13 @@ static int sdw_program_device_num(struct sdw_bus *bus)
 			if (sdw_compare_devid(slave, id) == 0) {
 				found = true;
 
+				/*
+				 * Don't re-enumerate a device until we've seen
+				 * it UNATTACH.
+				 */
+				if (slave->status != SDW_SLAVE_UNATTACHED)
+					break;
+
 				/*
 				 * Assign a new dev_num to this Slave and
 				 * not mark it present. It will be marked
-- 
2.30.2


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

* Re: [PATCH 1/1] soundwire: bus: Don't re-enumerate before status is UNATTACHED
  2022-08-29  9:44   ` Richard Fitzgerald
@ 2022-08-30  9:02     ` Richard Fitzgerald
  -1 siblings, 0 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2022-08-30  9:02 UTC (permalink / raw)
  To: vkoul, yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale
  Cc: alsa-devel, linux-kernel, patches

On 29/08/2022 10:44, Richard Fitzgerald wrote:
> Don't re-enumerate a peripheral on #0 until we have seen and
> handled an UNATTACHED notification for that peripheral.
> 
> Without this, it is possible for the UNATTACHED status to be missed
> and so the slave->status remains at ATTACHED. If slave->status never
> changes to UNATTACHED the child driver will never be notified of the
> UNATTACH, and the code in sdw_handle_slave_status() will skip the
> second part of enumeration because the slave->status has not changed.
> 
> This scenario can happen because PINGs are handled in a workqueue
> function which is working from a snapshot of an old PING, and there
> is no guarantee when this function will run.
> 
> A peripheral could report attached in the PING being handled by
> sdw_handle_slave_status(), but has since reverted to device #0 and is
> then found in the loop in sdw_program_device_num(). Previously the
> code would not have updated slave->status to UNATTACHED because it had
> not yet handled a PING where that peripheral had UNATTACHED.
> 
> This situation happens fairly frequently with multiple peripherals on
> a bus that are intentionally reset (for example after downloading
> firmware).
> 
> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
> ---
>   drivers/soundwire/bus.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
> index cb77da84a4f9..a3d3d66b3410 100644
> --- a/drivers/soundwire/bus.c
> +++ b/drivers/soundwire/bus.c
> @@ -766,6 +766,13 @@ static int sdw_program_device_num(struct sdw_bus *bus)
>   			if (sdw_compare_devid(slave, id) == 0) {
>   				found = true;
>   
> +				/*
> +				 * Don't re-enumerate a device until we've seen
> +				 * it UNATTACH.
> +				 */
> +				if (slave->status != SDW_SLAVE_UNATTACHED)
> +					break;

This should return. We're going to keep seeing this peripheral as the
next to be enumerated until we program its device ID.

> +
>   				/*
>   				 * Assign a new dev_num to this Slave and
>   				 * not mark it present. It will be marked

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

* Re: [PATCH 1/1] soundwire: bus: Don't re-enumerate before status is UNATTACHED
@ 2022-08-30  9:02     ` Richard Fitzgerald
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2022-08-30  9:02 UTC (permalink / raw)
  To: vkoul, yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale
  Cc: patches, alsa-devel, linux-kernel

On 29/08/2022 10:44, Richard Fitzgerald wrote:
> Don't re-enumerate a peripheral on #0 until we have seen and
> handled an UNATTACHED notification for that peripheral.
> 
> Without this, it is possible for the UNATTACHED status to be missed
> and so the slave->status remains at ATTACHED. If slave->status never
> changes to UNATTACHED the child driver will never be notified of the
> UNATTACH, and the code in sdw_handle_slave_status() will skip the
> second part of enumeration because the slave->status has not changed.
> 
> This scenario can happen because PINGs are handled in a workqueue
> function which is working from a snapshot of an old PING, and there
> is no guarantee when this function will run.
> 
> A peripheral could report attached in the PING being handled by
> sdw_handle_slave_status(), but has since reverted to device #0 and is
> then found in the loop in sdw_program_device_num(). Previously the
> code would not have updated slave->status to UNATTACHED because it had
> not yet handled a PING where that peripheral had UNATTACHED.
> 
> This situation happens fairly frequently with multiple peripherals on
> a bus that are intentionally reset (for example after downloading
> firmware).
> 
> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
> ---
>   drivers/soundwire/bus.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
> index cb77da84a4f9..a3d3d66b3410 100644
> --- a/drivers/soundwire/bus.c
> +++ b/drivers/soundwire/bus.c
> @@ -766,6 +766,13 @@ static int sdw_program_device_num(struct sdw_bus *bus)
>   			if (sdw_compare_devid(slave, id) == 0) {
>   				found = true;
>   
> +				/*
> +				 * Don't re-enumerate a device until we've seen
> +				 * it UNATTACH.
> +				 */
> +				if (slave->status != SDW_SLAVE_UNATTACHED)
> +					break;

This should return. We're going to keep seeing this peripheral as the
next to be enumerated until we program its device ID.

> +
>   				/*
>   				 * Assign a new dev_num to this Slave and
>   				 * not mark it present. It will be marked

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

end of thread, other threads:[~2022-08-30  9:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-29  9:44 [PATCH 0/1] soundwire: bus: Fix for missing UNATTACH when re-enumerating Richard Fitzgerald
2022-08-29  9:44 ` Richard Fitzgerald
2022-08-29  9:44 ` [PATCH 1/1] soundwire: bus: Don't re-enumerate before status is UNATTACHED Richard Fitzgerald
2022-08-29  9:44   ` Richard Fitzgerald
2022-08-30  9:02   ` Richard Fitzgerald
2022-08-30  9:02     ` Richard Fitzgerald

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.