Allow SoundWire devices to communicate during remove
cover Allow SoundWire devices to communicate during remove
Currently on Intel systems SoundWire drivers can't communicate with the device during driver removal. This is primarily because the IRQs are disabled before the driver remove callback is run. The result of this is such transactions timeout causing a) a lot of errors in the log and b) driver remove to take a very long time.
This issue affects cs42l43 and cs42l45, primarily due to both using regmap IRQ.
soundwire_intel soundwire_intel.link.0: IO transfer timed out, cmd 3 device 6 addr 5d len 1 soundwire sdw-master-0-0: trf on Slave 6 failed:-110 write addr 5d count 0 sdca_class sdw:0:0:01fa:4245:01: Failed to sync masks in 5d
As regmap IRQ is torn down it will mask the interrupts that are removed. However, there are many valid reasons a driver might want communicate with the device during removal, others would include disabling jack detection, putting the device into the lowest possible power state to save power, etc.
This patch set attempts to address this problem trying to locate the reason interrupts are disabled, fixing that and then leaving the IRQs enabled for the remove callback.
Charles Keepax (2):
soundwire: bus: Don't unassign dev_num before unregistering device
soundwire: intel_auxdevice: Don't disable IRQs before removing
children
drivers/soundwire/bus.c | 4 ++-- drivers/soundwire/intel.h | 1 + drivers/soundwire/intel_auxdevice.c | 5 ++++- drivers/soundwire/intel_init.c | 16 ++++++++++++++++ include/linux/soundwire/sdw_intel.h | 1 + 5 files changed, 24 insertions(+), 3 deletions(-)
Signature · 1 line
2.47.3
PATCH 1/2 soundwire: bus: Don't unassign dev_num before unregistering device
Don't mark dev_num as unassigned until after device_unregister() has been called. The driver may want to communicate with the device as part of the driver remove operation, so the dev_num should remain assigned until that has completed.
--- drivers/soundwire/bus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soundwire/bus.c +2 -2
@@ -175,8 +175,9 @@ static int sdw_delete_slave(struct device *dev, void *data)sdw_slave_debugfs_exit (slave); -mutex_lock (&bus->bus_lock); +device_unregister (dev); +mutex_lock (&bus->bus_lock);if (slave->dev_num) {/* clear dev_num if assigned */ clear_bit (slave->dev_num, bus->assigned);if (bus->ops && bus->ops->put_device_num)
@@ -185,7 +186,6 @@ static int sdw_delete_slave(struct device *dev, void *data)list_del_init (&slave->node);mutex_unlock (&bus->bus_lock); -device_unregister (dev);return 0 ; }
Signature · 1 line
2.47.3
PATCH 2/2 soundwire: intel_auxdevice: Don't disable IRQs before removing children
In reply to Charles KeepaxCurrently the auxiliary device for the link disables IRQs before it calls sdw_bus_master_delete(). This has the side effect that none of the devices on the link can access their own registers whilst their remove functions run, because the IRQs are required for bus transactions to function.
It would appear the reason for the disabling of the IRQs is that the IRQ handler iterates through a linked list of all the links, once a link is removed the memory pointed at by this linked list is freed, but not removed from the linked_list. Add a list_del() for the linked list item, note whilst the list itself is contained in the intel_init portion of the code, the list remove needs to be attached to the auxiliary device for the link, since that owns the memory that the list points at. Locking is also required to ensure the IRQ handler runs either before or after any additions/removals from the list.
--- drivers/soundwire/intel.h | 1 + drivers/soundwire/intel_auxdevice.c | 5 ++++- drivers/soundwire/intel_init.c | 16 ++++++++++++++++ include/linux/soundwire/sdw_intel.h | 1 + 4 files changed, 22 insertions(+), 1 deletion(-)
drivers/soundwire/intel.h +1 -0
@@ -47,6 +47,7 @@ struct sdw_intel_link_res {u32 link_mask;struct sdw_cdns *cdns;struct list_head list; +struct mutex *link_lock;/* lock protecting list */ struct hdac_bus *hbus; };
drivers/soundwire/intel_auxdevice.c +4 -1
@@ -508,9 +508,12 @@ static void intel_link_remove(struct auxiliary_device *auxdev)if (!bus->prop.hw_disabled) {sdw_intel_debugfs_exit (sdw);cancel_delayed_work_sync (&cdns->attach_dwork); -sdw_cdns_enable_interrupt (cdns, false); } +sdw_bus_master_delete (bus); + +if (!bus->prop.hw_disabled) +sdw_cdns_enable_interrupt (cdns, false); }int intel_link_process_wakeen_event (struct auxiliary_device *auxdev)
drivers/soundwire/intel_init.c +16 -0
@@ -28,6 +28,15 @@ static void intel_link_dev_release(struct device *dev)kfree (ldev); } +static void intel_link_list_del (void *data) +{ +struct sdw_intel_link_res *link = data; + +mutex_lock (link->link_lock); +list_del (&link->list); +mutex_unlock (link->link_lock); +} +/* alloc, init and add link devices */ static struct sdw_intel_link_dev *intel_link_dev_register(struct sdw_intel_res *res, struct sdw_intel_ctx *ctx,
@@ -79,6 +88,7 @@ static struct sdw_intel_link_dev *intel_link_dev_register(struct sdw_intel_res * link->shim_lock = res->eml_lock; link->mic_privacy = res->mic_privacy; } + link->link_lock = &ctx->link_lock; link->ops = res->ops; link->dev = res->dev;
@@ -145,8 +155,10 @@ irqreturn_t sdw_intel_thread(int irq, void *dev_id)struct sdw_intel_ctx *ctx = dev_id;struct sdw_intel_link_res *link; +mutex_lock (&ctx->link_lock);list_for_each_entry (link, &ctx->link_list, list)sdw_cdns_irq (irq, link->cdns); +mutex_unlock (&ctx->link_lock);return IRQ_HANDLED ; }
@@ -210,6 +222,7 @@ static struct sdw_intel_ctx ctx->link_mask = res->link_mask; ctx->handle = res->handle;mutex_init (&ctx->shim_lock); +mutex_init (&ctx->link_lock); link_mask = ctx->link_mask;
@@ -246,7 +259,10 @@ static struct sdw_intel_ctx i++; goto err; } +mutex_lock (&ctx->link_lock);list_add_tail (&link->list, &ctx->link_list); +mutex_unlock (&ctx->link_lock); +devm_add_action_or_reset (&ldev->auxdev.dev, intel_link_list_del, link); bus = &link->cdns->bus;/* Calculate number of slaves */ list_for_each (node, &bus->slaves)
include/linux/soundwire/sdw_intel.h +1 -0
@@ -307,6 +307,7 @@ struct sdw_intel_ctx {acpi_handle handle;struct sdw_intel_link_dev **ldev;struct list_head link_list; +struct mutex link_lock;/* lock protecting link_list */ struct mutex shim_lock;/* lock for access to shared SHIM registers */ u32 shim_mask;u32 shim_base;
Signature · 1 line
2.47.3
Re: [PATCH 1/2] soundwire: bus: Don't unassign dev_num before unregistering device
In reply to Charles KeepaxQuoted 4 lines · Charles Keepax
Don't mark
dev_numas unassigned until afterdevice_unregister()has been called. The driver may want to communicate with the device as part of the driver remove operation, so thedev_numshould remain assigned until that has completed.
That change looks fine.
But I am a bit worried about the dev_num handling now that I think of it. This is *only* at the manager level. At the peripheral level, the dev_num register has not been modified so the hardware still reports as ATTACHED with the dev_num whose mask was cleared on the host side. IOW we have a zombie peripheral on the link, and if we do a sequence rmmod/insmod things could be fun...
Quoted 29 lines
Signed-off-by Charles Keepax <[email protected]>--- drivers/soundwire/bus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/soundwire/bus.c +2
-2@@ -175,8 +175,9 @@ static int sdw_delete_slave(struct device *dev, void *data)sdw_slave_debugfs_exit (slave); -mutex_lock (&bus->bus_lock); +device_unregister (dev); +mutex_lock (&bus->bus_lock);if (slave->dev_num) {/* clear dev_num if assigned */ clear_bit (slave->dev_num, bus->assigned);if (bus->ops && bus->ops->put_device_num)@@ -185,7 +186,6 @@ static int sdw_delete_slave(struct device *dev, void *data)list_del_init (&slave->node);mutex_unlock (&bus->bus_lock); -device_unregister (dev);return 0 ; }
Pierre-Louis Bossart
reviewerRe: [PATCH 2/2] soundwire: intel_auxdevice: Don't disable IRQs before removing children
In reply to Charles KeepaxQuoted 10 lines · Charles Keepax
Currently the auxiliary device for the link disables IRQs before it calls
sdw_bus_master_delete(). This has the side effect that none of the devices on the link can access their own registers whilst their remove functions run, because the IRQs are required for bus transactions to function.It would appear the reason for the disabling of the IRQs is that the IRQ handler iterates through a linked list of all the links, once a link is removed the memory pointed at by this linked list is freed, but not removed from the
linked_list.
That wasn't the reason, even if you have a single link we all thought it made more sense to disable peripheral interrupts on the host before calling sdw_bus_master_delete()
Quoted 1 line
Add a
list_del()> for the linked list item, note whilst the list
itself is contained
Quoted 32 lines
in the
intel_initportion of the code, the list remove needs to be attached to the auxiliary device for the link, since that owns the memory that the list points at. Locking is also required to ensure the IRQ handler runs either before or after any additions/removals from the list.Signed-off-by Charles Keepax <[email protected]>--- drivers/soundwire/intel.h | 1 + drivers/soundwire/intel_auxdevice.c | 5 ++++- drivers/soundwire/intel_init.c | 16 ++++++++++++++++ include/linux/soundwire/sdw_intel.h | 1 + 4 files changed, 22 insertions(+), 1 deletion(-)drivers/soundwire/intel.h +1
-0@@ -47,6 +47,7 @@ struct sdw_intel_link_res {u32 link_mask;struct sdw_cdns *cdns;struct list_head list; +struct mutex *link_lock;/* lock protecting list */ struct hdac_bus *hbus; };drivers/soundwire/intel_auxdevice.c +0
-0@@ -508,9 +508,12 @@ static void intel_link_remove(struct auxiliary_device *auxdev)if (!bus->prop.hw_disabled) {
drivers/soundwire/intel_auxdevice.c static void intel_link_remove(struct auxiliary_device *auxdev) · line 517
Quoted 10 lines
drivers/soundwire/intel_auxdevice.c +4
-1sdw_intel_debugfs_exit (sdw);cancel_delayed_work_sync (&cdns->attach_dwork); -sdw_cdns_enable_interrupt (cdns, false); } +sdw_bus_master_delete (bus); + +if (!bus->prop.hw_disabled) +sdw_cdns_enable_interrupt (cdns, false); }
Sorry, that sequence looks really weird to me.
See the code in
void sdw_bus_master_delete(struct sdw_bus *bus)
{
device_for_each_child(bus->dev, NULL, sdw_delete_slave);
sdw_irq_delete(bus);
sdw_master_device_del(bus);After doing all this, one would mask the interrupts on the host side with
if (!bus->prop.hw_disabled) sdw_cdns_enable_interrupt(cdns, false);
but that host is long gone.
Does this even work?
The last sdw_cdns_enable_interrupt(cdns, false) looks either very racy or useless, no?
Quoted 65 lines
drivers/soundwire/intel_auxdevice.c +0
-0int intel_link_process_wakeen_event (struct auxiliary_device *auxdev)drivers/soundwire/intel_init.c +16
-0@@ -28,6 +28,15 @@ static void intel_link_dev_release(struct device *dev)kfree (ldev); } +static void intel_link_list_del (void *data) +{ +struct sdw_intel_link_res *link = data; + +mutex_lock (link->link_lock); +list_del (&link->list); +mutex_unlock (link->link_lock); +} +/* alloc, init and add link devices */ static struct sdw_intel_link_dev *intel_link_dev_register(struct sdw_intel_res *res, struct sdw_intel_ctx *ctx,@@ -79,6 +88,7 @@ static struct sdw_intel_link_dev *intel_link_dev_register(struct sdw_intel_res * link->shim_lock = res->eml_lock; link->mic_privacy = res->mic_privacy; } + link->link_lock = &ctx->link_lock; link->ops = res->ops; link->dev = res->dev;@@ -145,8 +155,10 @@ irqreturn_t sdw_intel_thread(int irq, void *dev_id)struct sdw_intel_ctx *ctx = dev_id;struct sdw_intel_link_res *link; +mutex_lock (&ctx->link_lock);list_for_each_entry (link, &ctx->link_list, list)sdw_cdns_irq (irq, link->cdns); +mutex_unlock (&ctx->link_lock);return IRQ_HANDLED ; }@@ -210,6 +222,7 @@ static struct sdw_intel_ctx ctx->link_mask = res->link_mask; ctx->handle = res->handle;mutex_init (&ctx->shim_lock); +mutex_init (&ctx->link_lock); link_mask = ctx->link_mask;@@ -246,7 +259,10 @@ static struct sdw_intel_ctx i++; goto err; } +mutex_lock (&ctx->link_lock);list_add_tail (&link->list, &ctx->link_list); +mutex_unlock (&ctx->link_lock); +devm_add_action_or_reset (&ldev->auxdev.dev, intel_link_list_del, link); bus = &link->cdns->bus;/* Calculate number of slaves */ list_for_each (node, &bus->slaves)include/linux/soundwire/sdw_intel.h +0
-0
include/linux/soundwire/sdw_intel.h struct sdw_intel_ctx { · line 311
Quoted 5 lines
include/linux/soundwire/sdw_intel.h +1
-0@@ -307,6 +307,7 @@ struct sdw_intel_ctx {acpi_handle handle;struct sdw_intel_link_dev **ldev;struct list_head link_list; +struct mutex link_lock;/* lock protecting link_list */ struct mutex shim_lock;/* lock for access to shared SHIM registers */
IIRC shim_lock was used to prevent access to common registers shared between links. How many locks do we need?
Quoted 2 lines
include/linux/soundwire/sdw_intel.h +0
-0u32 shim_mask;u32 shim_base;
Re: [PATCH 2/2] soundwire: intel_auxdevice: Don't disable IRQs before removing children
Quoted 7 lines · Pierre-Louis Bossart
Quoted 6 lines · Charles Keepax
Currently the auxiliary device for the link disables IRQs before it calls
sdw_bus_master_delete(). This has the side effect that none of the devices on the link can access their own registers whilst their remove functions run, because the IRQs are required for bus transactions to function.
Quoted 8 lines
Quoted 4 lines
It would appear the reason for the disabling of the IRQs is that the IRQ handler iterates through a linked list of all the links, once a link is removed the memory pointed at by this linked list is freed, but not removed from the
linked_list.That wasn't the reason, even if you have a single link we all thought it made more sense to disable peripheral interrupts on the host before calling
sdw_bus_master_delete()
What was the reason for deciding to do that, that is not in itself a reason? A drivers remove callback should be able to access registers on the device. The host here requires interrupts to do so. This was the only functional reason in the code I could find that things were done in this order.
Quoted 32 lines
Quoted 4 lines
drivers/soundwire/intel_auxdevice.c +0
-0@@ -508,9 +508,12 @@ static void intel_link_remove(struct auxiliary_device *auxdev)if (!bus->prop.hw_disabled) {drivers/soundwire/intel_auxdevice.c static void intel_link_remove(struct auxiliary_device *auxdev) · line 517
Quoted 10 lines
drivers/soundwire/intel_auxdevice.c +4
-1sdw_intel_debugfs_exit (sdw);cancel_delayed_work_sync (&cdns->attach_dwork); -sdw_cdns_enable_interrupt (cdns, false); } +sdw_bus_master_delete (bus); + +if (!bus->prop.hw_disabled) +sdw_cdns_enable_interrupt (cdns, false); }Sorry, that sequence looks really weird to me.
See the code in
void
sdw_bus_master_delete(struct sdw_bus *bus){ device_for_each_child(bus->dev, NULL, sdw_delete_slave); sdw_irq_delete(bus); sdw_master_device_del(bus);After doing all this, one would mask the interrupts on the host side with
if (!bus->prop.hw_disabled) sdw_cdns_enable_interrupt(cdns, false);
Quoted 6 lines
but that host is long gone.
Does this even work?
The last
sdw_cdns_enable_interrupt(cdns, false)looks either very racy or useless, no?
I mean it definitely works and fixes the problems on driver remove. I will check to see if the call is redundant at this stage, or if there are any potential dangers I am missing.
Quoted 5 lines
Quoted 5 lines
include/linux/soundwire/sdw_intel.h +0
-0@@ -307,6 +307,7 @@ struct sdw_intel_ctx {
Quoted 8 lines
include/linux/soundwire/sdw_intel.h struct sdw_intel_ctx { · line 311
Quoted 5 lines
include/linux/soundwire/sdw_intel.h +1
-0acpi_handle handle;struct sdw_intel_link_dev **ldev;struct list_head link_list; +struct mutex link_lock;/* lock protecting link_list */ struct mutex shim_lock;/* lock for access to shared SHIM registers */ IIRC
shim_lockwas used to prevent access to common registers shared between links. How many locks do we need?
I mean we could reuse the lock but in my experience locks having a clearly defined purpose is less error prone, than having catch all locks. The shim lock claims to protect the SHIM registers, this one protects the list of links. But if you feel strongly I am happy to try reuse the shim lock for this?
Ultimately, I am not super attached to this way of solving the problem but we do need to come up with some solution to allow drivers to access their device in driver remove. This causes devices to take 1-2 minutes to remove the driver and fills the log with loads of error messages. I am more than happy to entertain other ways of making that happen if you have ideas you prefer?
Thanks,
Charles
Re: [PATCH 1/2] soundwire: bus: Don't unassign dev_num before unregistering device
In reply to Pierre-Louis BossartQuoted 8 lines · Pierre-Louis Bossart
Quoted 4 lines · Charles Keepax
Don't mark
dev_numas unassigned until afterdevice_unregister()has been called. The driver may want to communicate with the device as part of the driver remove operation, so thedev_numshould remain assigned until that has completed.That change looks fine.
Quoted 8 lines
Reviewed-by Pierre-Louis Bossart <[email protected]>But I am a bit worried about the
dev_numhandling now that I think of it. This is *only* at the manager level. At the peripheral level, thedev_numregister has not been modified so the hardware still reports as ATTACHED with thedev_numwhose mask was cleared on the host side. IOW we have a zombie peripheral on the link, and if we do a sequence rmmod/insmod things could be fun...
Hmm... yeah would probably be nicer to update the slave too. I will think that through and see if I can find time to have a look at doing an extra patch for it.
Thanks,
Charles
Re: [PATCH 2/2] soundwire: intel_auxdevice: Don't disable IRQs before removing children
In reply to Charles KeepaxQuoted 21 lines · Charles Keepax
Quoted 20 lines · Pierre-Louis Bossart
On 9/11/26 18:19, Charles Keepax wrote:
Sorry, that sequence looks really weird to me.See the code in
void
sdw_bus_master_delete(struct sdw_bus *bus){ device_for_each_child(bus->dev, NULL, sdw_delete_slave); sdw_irq_delete(bus); sdw_master_device_del(bus);After doing all this, one would mask the interrupts on the host side with
if (!bus->prop.hw_disabled) sdw_cdns_enable_interrupt(cdns, false);but that host is long gone.
Quoted 8 lines
Quoted 4 lines
Does this even work?
The last
sdw_cdns_enable_interrupt(cdns, false)looks either very racy or useless, no?I mean it definitely works and fixes the problems on driver remove. I will check to see if the call is redundant at this stage, or if there are any potential dangers I am missing.
Hmm... ok so the call definitely isn't redundant nothing else masks all the IRQs. However, I think you might be onto something with the race, I think if we get a slave interrupt in this window it could cause problems (queues cdns->work which then uses things from the bus). I think we might need to export cdns_enable_slave_interrupt() so we can separately disable the slave interrupts whilst leaving the other interrupts functional.
Thanks,
Charles
Pierre-Louis Bossart
reviewerRe: [PATCH 2/2] soundwire: intel_auxdevice: Don't disable IRQs before removing children
In reply to Charles KeepaxQuoted 10 lines
Quoted 9 lines
Quoted 5 lines
It would appear the reason for the disabling of the IRQs is that the IRQ handler iterates through a linked list of all the links, once a link is removed the memory pointed at by this linked list is freed, but not removed from the
linked_list.That wasn't the reason, even if you have a single link we all thought it made more sense to disable peripheral interrupts on the host before calling
sdw_bus_master_delete()
Quoted 5 lines
What was the reason for deciding to do that, that is not in itself a reason? A drivers remove callback should be able to access registers on the device. The host here requires interrupts to do so. This was the only functional reason in the code I could find that things were done in this order.
like I said it was thought to be simpler this way, we never thought about the need to do anything in remove().
IOW this is a missed requirement that led to a simple solution, not a deliberate decision to cripple the remove() step.
Quoted 34 lines
Quoted 34 lines
Quoted 4 lines
drivers/soundwire/intel_auxdevice.c +0
-0@@ -508,9 +508,12 @@ static void intel_link_remove(struct auxiliary_device *auxdev)if (!bus->prop.hw_disabled) {drivers/soundwire/intel_auxdevice.c static void intel_link_remove(struct auxiliary_device *auxdev) · line 517
Quoted 10 lines
drivers/soundwire/intel_auxdevice.c +4
-1sdw_intel_debugfs_exit (sdw);cancel_delayed_work_sync (&cdns->attach_dwork); -sdw_cdns_enable_interrupt (cdns, false); } +sdw_bus_master_delete (bus); + +if (!bus->prop.hw_disabled) +sdw_cdns_enable_interrupt (cdns, false); }Sorry, that sequence looks really weird to me.
See the code in
void
sdw_bus_master_delete(struct sdw_bus *bus){ device_for_each_child(bus->dev, NULL, sdw_delete_slave); sdw_irq_delete(bus); sdw_master_device_del(bus);After doing all this, one would mask the interrupts on the host side with
if (!bus->prop.hw_disabled) sdw_cdns_enable_interrupt(cdns, false);but that host is long gone.
Quoted 8 lines
Quoted 4 lines
Does this even work?
The last
sdw_cdns_enable_interrupt(cdns, false)looks either very racy or useless, no?I mean it definitely works and fixes the problems on driver remove. I will check to see if the call is redundant at this stage, or if there are any potential dangers I am missing.
ok
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
include/linux/soundwire/sdw_intel.h +0
-0@@ -307,6 +307,7 @@ struct sdw_intel_ctx {Quoted 8 lines
include/linux/soundwire/sdw_intel.h struct sdw_intel_ctx { · line 311
Quoted 5 lines
include/linux/soundwire/sdw_intel.h +1
-0acpi_handle handle;struct sdw_intel_link_dev **ldev;struct list_head link_list; +struct mutex link_lock;/* lock protecting link_list */ struct mutex shim_lock;/* lock for access to shared SHIM registers */ IIRC
shim_lockwas used to prevent access to common registers shared between links. How many locks do we need?
Quoted 5 lines
I mean we could reuse the lock but in my experience locks having a clearly defined purpose is less error prone, than having catch all locks. The shim lock claims to protect the SHIM registers, this one protects the list of links. But if you feel strongly I am happy to try reuse the shim lock for this?
I am not asking for you to share, just that we need to have a discussion on whether this new lock is redundant or not, and wording that describes why using existing locks isn't desired/needed.
this shim_lock is a protection for very low-level access to registers, and completely tied to the way the IP registers were clustered together, it's indeed a different conceptual level you're after. So even if there is some redundancy or overlap, it's probably simpler to use a different lock for different things,
Quoted 6 lines
Ultimately, I am not super attached to this way of solving the problem but we do need to come up with some solution to allow drivers to access their device in driver remove. This causes devices to take 1-2 minutes to remove the driver and fills the log with loads of error messages. I am more than happy to entertain other ways of making that happen if you have ideas you prefer?
I don't have any objections with the requirement to let the codec do whatever it needs on remove(), this was a miss in the design and it needs to be addressed.
I am just nervous about the interrupt part and possible race conditions. Maybe the last stage of the remove() should be to mask all interrupts on the codec side with a common helper shared by all codec drivers?
BTW we did have scripts to remove/insert in loops to try and find issues, not sure if you're aware of them and if they still work, see:
https://github.com/thesofproject/sof-test/blob/main/tools/kmod/
Re: [PATCH 2/2] soundwire: intel_auxdevice: Don't disable IRQs before removing children
Quoted 16 lines · Pierre-Louis Bossart
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
It would appear the reason for the disabling of the IRQs is that the IRQ handler iterates through a linked list of all the links, once a link is removed the memory pointed at by this linked list is freed, but not removed from the
linked_list.That wasn't the reason, even if you have a single link we all thought it made more sense to disable peripheral interrupts on the host before calling
sdw_bus_master_delete()Quoted 5 lines
What was the reason for deciding to do that, that is not in itself a reason? A drivers remove callback should be able to access registers on the device. The host here requires interrupts to do so. This was the only functional reason in the code I could find that things were done in this order.
Quoted 4 lines
like I said it was thought to be simpler this way, we never thought about the need to do anything in
remove().
IOW this is a missed requirement that led to a simple solution, not a deliberate decision to cripple theremove()step.
Ok I will update to reflect this being more what we need to update to add this and remove the apparent reason wording.
Quoted 22 lines
Quoted 12 lines
Quoted 11 lines
include/linux/soundwire/sdw_intel.h struct sdw_intel_ctx { · line 311
Quoted 8 lines
include/linux/soundwire/sdw_intel.h +1
-0@@ -307,6 +307,7 @@ struct sdw_intel_ctx {acpi_handle handle;struct sdw_intel_link_dev **ldev;struct list_head link_list; +struct mutex link_lock;/* lock protecting link_list */ struct mutex shim_lock;/* lock for access to shared SHIM registers */ IIRC
shim_lockwas used to prevent access to common registers shared between links. How many locks do we need?Quoted 5 lines
I mean we could reuse the lock but in my experience locks having a clearly defined purpose is less error prone, than having catch all locks. The shim lock claims to protect the SHIM registers, this one protects the list of links. But if you feel strongly I am happy to try reuse the shim lock for this?
I am not asking for you to share, just that we need to have a discussion on whether this new lock is redundant or not, and wording that describes why using existing locks isn't desired/needed.
Quoted 5 lines
this
shim_lockis a protection for very low-level access to registers, and completely tied to the way the IP registers were clustered together, it's indeed a different conceptual level you're after. So even if there is some redundancy or overlap, it's probably simpler to use a different lock for different things,
So a quick test appears to suggest using the shim_lock would work. The original description is mostly focused on the low level registers, which does feel like a different purpose. That said though it does basically work the same its a lock linked to the controller and the initial description does make reference to protecting the shim_mask field as well so I guess it is already protecting some state in the same struct.
Happy to go with you and Intel's preferred options here.
Quoted 8 lines
Quoted 7 lines
Ultimately, I am not super attached to this way of solving the problem but we do need to come up with some solution to allow drivers to access their device in driver remove. This causes devices to take 1-2 minutes to remove the driver and fills the log with loads of error messages. I am more than happy to entertain other ways of making that happen if you have ideas you prefer?
Quoted 6 lines
I don't have any objections with the requirement to let the codec do whatever it needs on
remove(), this was a miss in the design and it needs to be addressed.
I am just nervous about the interrupt part and possible race conditions. Maybe the last stage of theremove()should be to mask all interrupts on the codec side with a common helper shared by all codec drivers?
Yeah that is fair, it is a major reshuffling. But we can carry on that discussion on the other branch.
Quoted 4 lines
BTW we did have scripts to remove/insert in loops to try and find issues, not sure if you're aware of them and if they still work, see:
https://github.com/thesofproject/sof-test/blob/main/tools/kmod/
Yeah I believe that causing problems is one of the main things people have been complaining about.
Thanks,
Charles
Re: [PATCH 1/2] soundwire: bus: Don't unassign dev_num before unregistering device
In reply to Pierre-Louis BossartQuoted 8 lines · Pierre-Louis Bossart
Quoted 4 lines · Charles Keepax
Don't mark
dev_numas unassigned until afterdevice_unregister()has been called. The driver may want to communicate with the device as part of the driver remove operation, so thedev_numshould remain assigned until that has completed.That change looks fine.
Quoted 8 lines
Reviewed-by Pierre-Louis Bossart <[email protected]>But I am a bit worried about the
dev_numhandling now that I think of it. This is *only* at the manager level. At the peripheral level, thedev_numregister has not been modified so the hardware still reports as ATTACHED with thedev_numwhose mask was cleared on the host side. IOW we have a zombie peripheral on the link, and if we do a sequence rmmod/insmod things could be fun...
I think there is also a bit of a race here as well. I think we can't access slave after we call device_unregister. Will think about this a little more and prepare a v2. We can probably cache the dev_num before but can't help wondering if we are clearing the dev_num in the right place.
Thanks,
Charles
Quoted 29 lines
Quoted 28 lines
Signed-off-by Charles Keepax <[email protected]>--- drivers/soundwire/bus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/soundwire/bus.c +2
-2@@ -175,8 +175,9 @@ static int sdw_delete_slave(struct device *dev, void *data)sdw_slave_debugfs_exit (slave); -mutex_lock (&bus->bus_lock); +device_unregister (dev); +mutex_lock (&bus->bus_lock);if (slave->dev_num) {/* clear dev_num if assigned */ clear_bit (slave->dev_num, bus->assigned);if (bus->ops && bus->ops->put_device_num)@@ -185,7 +186,6 @@ static int sdw_delete_slave(struct device *dev, void *data)list_del_init (&slave->node);mutex_unlock (&bus->bus_lock); -device_unregister (dev);return 0 ; }