soundwire: amd: SoundWire manager driver bug fixes
v6 cover soundwire: amd: SoundWire manager driver bug fixes
This series collects bug fixes for the AMD SoundWire manager driver (ACP6.3/7.0/7.1/7.2). The patches address correctness issues across five areas. Patches 9, 12, 13, 15, 20, and 21 fix issues reported by Lee Jones <[email protected]>.
Wake interrupt handling (patches 1-8): fixes reported on OEM platforms running ACP6.3/7.0/7.1/7.2. Consolidate pad register macros into amd_init.h, add correct SCHMEN/OE programming for ACP 7.0/7.1/7.2, introduce D0/D3 PM pad helpers, track full pad teardown across suspend/resume, fix missing wake interrupt and group wake-arming calls in runtime suspend, fix the IRQ thread dropping STATUS_0TO7 on simultaneous wake and state-change events, remove the spurious STATUS_8TO11 clear in amd_sdw_process_wake_event(), and fix a missing wake interrupt for ACP6.3 in POWER_OFF suspend.
Command response handling (patches 9-11): fix silent widening of -ETIMEDOUT to u64 (reported by Lee Jones), cache the last successful PING result to avoid spurious disconnect warnings on transient timeouts, and add lockdep_assert_held() to enforce the msg_lock contract.
Work-queue and driver lifecycle (patches 12-16): fix drain ordering in the remove path and defer dev_set_drvdata() until after INIT_WORK() to close a concurrent-remove window (both reported by Lee Jones), guard pm_runtime_disable() against unpaired calls, guard IRQ work execution with the interrupt_enabled flag using WRITE_ONCE/READ_ONCE to annotate the cross-context access (reported by Lee Jones), and delay *sdw_ctx publication until after sdw_amd_startup() succeeds. The corresponding NULL-check fixes for the IRQ handler window opened by patch 16 have been posted as ASoC companion patches and are already merged:
34ea81a7f284 ("ASoC: SOF: amd: guard adata->sdw dereferences with
NULL check in IRQ handler")
41e06aaef9c0 ("ASoC: amd: ps: guard adata->sdw dereferences with
NULL check in IRQ handler")
Power management (patches 17-20): propagate amd_init_sdw_manager() errors on POWER_OFF resume, drop amd_deinit_sdw_manager() in POWER_OFF suspend, replace the open-coded >= ACP70 comparison with an explicit switch/case, and fix interrupt-gate and work-drain ordering in PM ops (reported by Lee Jones).
Drvdata and register safety (patches 21-23): add a NULL drvdata guard in sdw_amd_startup() (reported by Lee Jones), and fix shared-register read-modify-write races in amd_sdw_set_device_state() and amd_sdw_host_wake_enable() by holding acp_sdw_lock.
Changes since v5:
- Drop patch 10 (return response on IMM status cleanup timeout) and patch 11 (clarify bad-state guard poll omission in IMM_RES_VALID path): dropped after review feedback.
- Patch 2: rename disable_oe to needs_schmen_oe for clarity; update Fixes tags to cite ACP 7.x introduction commits instead of the
ACP 6.3-only refactor commit:
commit 2c0ae8ef1e5e ("soundwire: amd: add support for ACP7.0 & ACP7.1 platforms") commit 34b1cb4ec286 ("soundwire: amd: Add support for acp7.2 platform")
- Patch 4: use "POWER_OFF_MODE runtime suspend" instead of
"wake-armed runtime suspend" for precision.
- Patch 5: add commit description explaining why the early return before wake-arming is correct when amd_deinit_sdw_manager() fails; update Fixes tag to commit dcc48a73eae7 ("soundwire: amd: change the soundwire wake enable/disable sequence").
- Patch 8: update Fixes tag to correct commit SHA.
- Patch 9: drop dev_err_ratelimited() calls for ping status timeout; the error is already tracked via the cache introduced in patch 10.
- Patch 14: update Fixes tag to commit ed5e8741b8db ("soundwire: amd:
refactor amd soundwire manager device node creation"), which introduced the partial-init startup sequence that makes the unconditional pm_runtime_disable() incorrect.
- Patch 15: add WRITE_ONCE() for all stores to interrupt_enabled and READ_ONCE() for the load in amd_sdw_irq_thread(); restore interrupt_enabled in the ACP6.3-specific wake-re-enable block in amd_suspend_runtime() POWER_OFF_MODE; guard IRQ work execution instead of scheduling.
- Patch 16: simplify to single-problem description (ctx leak on startup failure); remove the concurrent IRQ handler race rationale. Two ASoC companion patches addressing the IRQ handler NULL dereference window (adata->sdw dereferenced without NULL check between amd_enable_sdw_interrupts() and *sdw_ctx assignment) have been posted and merged in Mark Brown's ASoC tree:
34ea81a7f284 ("ASoC: SOF: amd: guard adata->sdw dereferences with
NULL check in IRQ handler")
41e06aaef9c0 ("ASoC: amd: ps: guard adata->sdw dereferences with
NULL check in IRQ handler")
- Patch 19: add WRITE_ONCE(interrupt_enabled, true) in the ACP6.3 wake-re-enable block in amd_suspend_runtime() POWER_OFF_MODE.
- Patch 20: expand description to explain the redundant amd_sdw_wake_enable(false) calls and clarify CLK_STOP_MODE
interrupt handling through D3.
- Link to v5:
https://lore.kernel.org/linux-sound/[email protected]/
Changes since v4:
- Add patches 1-8 (OEM-reported wake interrupt fixes for ACP6.3/7.0/7.1/7.2): pad register macro consolidation, SCHMEN/OE programming for ACP 7.0/7.1/7.2, D0/D3 PM helpers, pad teardown tracking, missing wake interrupt in runtime suspend, STATUS_0TO7 race fix (promoted from patch 12/13 in v4), STATUS_8TO11 fix reworked to a targeted removal of the clear in amd_sdw_process_wake_event(), and ACP6.3 POWER_OFF wake fix.
- Add patch 11: clarify bad-state guard poll omission in IMM_RES_VALID path.
- Add patch 15: defer dev_set_drvdata() until after INIT_WORK().
- Add patches 17-18: guard IRQ work with interrupt_enabled flag; delay *sdw_ctx publication until after startup succeeds (supersedes v4 patch 7 ctx-leak fix with a more robust approach).
- Add patches 23-25: NULL drvdata guard in sdw_amd_startup(), and shared-register RMW races in amd_sdw_set_device_state() and amd_sdw_host_wake_enable().
- Drop v4 patch 7 (fix ctx leak when sdw_amd_startup() fails):
superseded by patch 18.
- Link to v4:
https://lore.kernel.org/all/[email protected]/
Changes since v3:
- Add patch 12/13 to fix IRQ thread dropping STATUS_0TO7 when a wake event and a device-state change arrive simultaneously.
- Add patch 13/13 to fix STATUS_8TO11 double-clear race in the wake handler introduced by the simultaneous-wake fix.
- Add lockdep_assert_held() to amd_sdw_read_ping_status() (patch 4/13) to enforce the msg_lock contract machine-checkably.
- Add return response on IMM status cleanup timeout (patch 2/13).
- Update patch 11/13 (fix interrupt gate and work drain ordering in PM ops) to also fix amd_sdw_wake_enable() ordering in both CLK_STOP_MODE
paths: move the call to after amd_enable_sdw_interrupts() so the unconditional interrupt mask write does not clobber the wake bit.
Changes since v2:
- Update comment for ping_slave_stat variable description in patch 3/13.
- Split the remove path work drain and pm ops guard patch into separate patches (patches 5/13 and 6/13) to improve clarity and maintainability.
Changes since v1:
- Rework patch 1 to fix the u64 return type properly via out-parameter.
Vijendar Mukunda (23):
soundwire: amd: consolidate pad register macros into amd_init.h
soundwire: amd: program pad SCHMEN and OE control for ACP 7.0/7.1/7.2
soundwire: amd: add pad ctrl helpers for D0/D3 PM transitions
soundwire: amd: track full pad teardown across suspend/resume
soundwire: amd: fix missing wake interrupt and group wake-arming calls
in runtime suspend
soundwire: amd: fix IRQ thread dropping STATUS_0TO7 on simultaneous
wake
soundwire: amd: remove STATUS_8TO11 clear from
amd_sdw_process_wake_event()
soundwire: amd: fix missing wake interrupt for ACP6.3 in POWER_OFF
suspend
soundwire: amd: fix SDW command timeout return value handling
soundwire: amd: cache ping slave status to avoid spurious disconnect
on timeout
soundwire: amd: assert msg_lock is held in amd_sdw_read_ping_status()
soundwire: amd: fix work drain ordering in remove path
soundwire: amd: defer dev_set_drvdata() until after INIT_WORK()
soundwire: amd: pm_runtime guard in remove path
soundwire: amd: use interrupt_enabled flag to guard IRQ work
scheduling
soundwire: amd: delay *sdw_ctx publication until after startup
succeeds
soundwire: amd: propagate amd_init_sdw_manager() error on resume
soundwire: amd: drop amd_deinit_sdw_manager() in POWER_OFF suspend
soundwire: amd: replace >= ACP70 with explicit switch/case in PM paths
soundwire: amd: fix interrupt gate and work drain ordering in PM ops
soundwire: amd: check for NULL manager drvdata in sdw_amd_startup()
soundwire: amd: fix shared-register RMW race in
amd_sdw_set_device_state()
soundwire: amd: fix shared-register RMW race in
amd_sdw_host_wake_enable()
drivers/soundwire/amd_init.c | 75 +++++-- drivers/soundwire/amd_init.h | 18 ++ drivers/soundwire/amd_manager.c | 351 ++++++++++++++++++++++++------ drivers/soundwire/amd_manager.h | 10 - include/linux/soundwire/sdw_amd.h | 15 ++ 5 files changed, 365 insertions(+), 104 deletions(-)
Signature · 1 line
2.53.0
PATCH v6 1/23 soundwire: amd: consolidate pad register macros into amd_init.h
Move ACP_PAD_PULLDOWN_CTRL and ACP_SW_PAD_KEEPER_EN from their duplicate definitions in amd_init.c and amd_manager.h into amd_init.h, so a single canonical definition is shared by both translation units.
Drop the eight stale AMD_SDW{0,1}_PAD_*_{ENABLE,DISABLE}_MASK definitions from amd_manager.h; they are no longer referenced anywhere.
No functional change.
--- drivers/soundwire/amd_init.c | 2 -- drivers/soundwire/amd_init.h | 3 +++ drivers/soundwire/amd_manager.h | 10 ---------- 3 files changed, 3 insertions(+), 12 deletions(-)
drivers/soundwire/amd_init.c +0 -2
@@ -16,8 +16,6 @@#include "amd_init.h" -#define ACP_PAD_PULLDOWN_CTRL 0x0001448 -#define ACP_SW_PAD_KEEPER_EN 0x0001454#define AMD_SDW0_PAD_CTRL_MASK 0x60#define AMD_SDW1_PAD_CTRL_MASK 5#define AMD_SDW_PAD_CTRL_MASK (AMD_SDW0_PAD_CTRL_MASK | AMD_SDW1_PAD_CTRL_MASK)
drivers/soundwire/amd_init.h +3 -0
@@ -8,6 +8,9 @@#include <linux/soundwire/sdw_amd.h> +#define ACP_PAD_PULLDOWN_CTRL 0x0001448 +#define ACP_SW_PAD_KEEPER_EN 0x0001454 +int amd_sdw_manager_start (struct amd_sdw_manager *amd_manager);static inline void amd_updatel (void __iomem *mmio,int offset,u32 mask,u32 val)
drivers/soundwire/amd_manager.h +0 -10
@@ -11,8 +11,6 @@#define SDW_MANAGER_REG_OFFSET 0xc00#define AMD_SDW_DEFAULT_ROWS 50#define AMD_SDW_DEFAULT_COLUMNS 10 -#define ACP_PAD_PULLDOWN_CTRL 0x0001448 -#define ACP_SW_PAD_KEEPER_EN 0x0001454#define ACP_SW0_WAKE_EN 0x0001458#define ACP_EXTERNAL_INTR_CNTL0 0x0001a04#define ACP_EXTERNAL_INTR_STAT0 0x0001a0c
@@ -180,14 +178,6 @@#define AMD_DPN_CH_EN_LCTRL GENMASK(2, 0)#define AMD_DPN_CH_EN_CHMASK GENMASK(10, 3)#define AMD_SDW_STAT_MAX_RETRY_COUNT 100 -#define AMD_SDW0_PAD_PULLDOWN_CTRL_ENABLE_MASK 0x7f9f -#define AMD_SDW1_PAD_PULLDOWN_CTRL_ENABLE_MASK 0x7ffa -#define AMD_SDW0_PAD_PULLDOWN_CTRL_DISABLE_MASK 0x60 -#define AMD_SDW1_PAD_PULLDOWN_CTRL_DISABLE_MASK 5 -#define AMD_SDW0_PAD_KEEPER_EN_MASK 1 -#define AMD_SDW1_PAD_KEEPER_EN_MASK 0x10 -#define AMD_SDW0_PAD_KEEPER_DISABLE_MASK 0x1e -#define AMD_SDW1_PAD_KEEPER_DISABLE_MASK 0xf#define AMD_SDW_PREQ_INTR_STAT BIT(19)#define AMD_SDW_CLK_STOP_DONE 1#define AMD_SDW_CLK_RESUME_REQ 2
Signature · 1 line
2.53.0
PATCH v6 2/23 soundwire: amd: program pad SCHMEN and OE control for ACP 7.0/7.1/7.2
In reply to Vijendar MukundaACP 7.0/7.1/7.2 hardware requires SCHMEN control and output-enable (OE) registers to be programmed as part of the pad enable sequence, in addition to the existing keeper and pulldown writes.
Update amd_enable_sdw_pads() to program ACP_PAD_SCHMEN_CTRL and ACP_PAD_DISABLE_OE_CTRL for active pads. Pass acp_rev to amd_enable_sdw_pads() and restrict these writes to ACP 7.0/7.1/7.2; ACP 6.3 is unaffected.
Define per-register masks in amd_init.h replacing generic local defines in amd_init.c.
amd_enable_sdw_pads() targets ACP6.3/7.0/7.1/7.2 only. The default -EINVAL prevents applying this pad sequence to unsupported ACP revisions.
--- drivers/soundwire/amd_init.c | 54 ++++++++++++++++++++++++------------ drivers/soundwire/amd_init.h | 15 ++++++++++ 2 files changed, 51 insertions(+), 18 deletions(-)
drivers/soundwire/amd_init.c +36 -18
@@ -16,37 +16,55 @@#include "amd_init.h" -#define AMD_SDW0_PAD_CTRL_MASK 0x60 -#define AMD_SDW1_PAD_CTRL_MASK 5 -#define AMD_SDW_PAD_CTRL_MASK (AMD_SDW0_PAD_CTRL_MASK | AMD_SDW1_PAD_CTRL_MASK) -#define AMD_SDW0_PAD_EN 1 -#define AMD_SDW1_PAD_EN 0x10 -#define AMD_SDW_PAD_EN (AMD_SDW0_PAD_EN | AMD_SDW1_PAD_EN) - -static int amd_enable_sdw_pads (void __iomem *mmio,u32 link_mask,struct device *dev) +static int amd_enable_sdw_pads (void __iomem *mmio,u32 link_mask,u32 acp_rev,struct device *dev) { -u32 pad_keeper_en, pad_pulldown_ctrl_mask; +u32 pad_keeper_mask, pad_pulldown_mask, pad_schmen_mask, pad_oe_mask; +bool needs_schmen_oe; + +switch (acp_rev) { +case ACP70_PCI_REV_ID : +case ACP71_PCI_REV_ID : +case ACP72_PCI_REV_ID : + needs_schmen_oe = true; +break ; +case ACP63_PCI_REV_ID : + needs_schmen_oe = false; +break ; +default : +dev_err (dev,"unsupported ACP revision 0x%x\n" , acp_rev); +return -EINVAL ; + }switch (link_mask) {case 1 : - pad_keeper_en =AMD_SDW0_PAD_EN ; - pad_pulldown_ctrl_mask =AMD_SDW0_PAD_CTRL_MASK ; + pad_keeper_mask =AMD_SDW0_PAD_KEEPER_EN_MASK ; + pad_pulldown_mask =AMD_SDW0_PAD_PULLDOWN_MASK ; + pad_schmen_mask =AMD_SDW0_PAD_SCHMEN_MASK ; + pad_oe_mask =AMD_SDW0_PAD_OE_CTRL_MASK ;break ;case 2 : - pad_keeper_en =AMD_SDW1_PAD_EN ; - pad_pulldown_ctrl_mask =AMD_SDW1_PAD_CTRL_MASK ; + pad_keeper_mask =AMD_SDW1_PAD_KEEPER_EN_MASK ; + pad_pulldown_mask =AMD_SDW1_PAD_PULLDOWN_MASK ; + pad_schmen_mask =AMD_SDW1_PAD_SCHMEN_MASK ; + pad_oe_mask =AMD_SDW1_PAD_OE_CTRL_MASK ;break ;case 3 : - pad_keeper_en =AMD_SDW_PAD_EN ; - pad_pulldown_ctrl_mask =AMD_SDW_PAD_CTRL_MASK ; + pad_keeper_mask =AMD_SDW_PAD_KEEPER_EN_MASK ; + pad_pulldown_mask =AMD_SDW_PAD_PULLDOWN_MASK ; + pad_schmen_mask =AMD_SDW_PAD_SCHMEN_MASK ; + pad_oe_mask =AMD_SDW_PAD_OE_CTRL_MASK ;break ;default :dev_err (dev,"No SDW Links are enabled\n" );return -ENODEV ; } -amd_updatel (mmio,ACP_SW_PAD_KEEPER_EN , pad_keeper_en, pad_keeper_en); -amd_updatel (mmio,ACP_PAD_PULLDOWN_CTRL , pad_pulldown_ctrl_mask,0 ); +amd_updatel (mmio,ACP_SW_PAD_KEEPER_EN , pad_keeper_mask, pad_keeper_mask); +amd_updatel (mmio,ACP_PAD_PULLDOWN_CTRL , pad_pulldown_mask,0 ); +if (needs_schmen_oe) { +amd_updatel (mmio,ACP_PAD_SCHMEN_CTRL , pad_schmen_mask, pad_schmen_mask); +amd_updatel (mmio,ACP_PAD_DISABLE_OE_CTRL , pad_oe_mask,0 ); + }return 0 ; }
@@ -86,7 +104,7 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res) count = res->count;dev_dbg (&adev->dev,"Creating %d SDW Link devices\n" , count); - ret =amd_enable_sdw_pads (res->mmio_base, res->link_mask, res->parent); + ret =amd_enable_sdw_pads (res->mmio_base, res->link_mask, res->acp_rev, res->parent);if (ret)return NULL ;
drivers/soundwire/amd_init.h +15 -0
@@ -9,7 +9,22 @@#include <linux/soundwire/sdw_amd.h> #define ACP_PAD_PULLDOWN_CTRL 0x0001448 +#define ACP_PAD_SCHMEN_CTRL 0x0001450#define ACP_SW_PAD_KEEPER_EN 0x0001454 +#define ACP_PAD_DISABLE_OE_CTRL 0x0001468 + +#define AMD_SDW0_PAD_PULLDOWN_MASK (BIT(5) | BIT(6)) +#define AMD_SDW1_PAD_PULLDOWN_MASK (BIT(0) | BIT(2)) +#define AMD_SDW_PAD_PULLDOWN_MASK (AMD_SDW0_PAD_PULLDOWN_MASK | AMD_SDW1_PAD_PULLDOWN_MASK) +#define AMD_SDW0_PAD_KEEPER_EN_MASK BIT(0) +#define AMD_SDW1_PAD_KEEPER_EN_MASK BIT(4) +#define AMD_SDW_PAD_KEEPER_EN_MASK (AMD_SDW0_PAD_KEEPER_EN_MASK | AMD_SDW1_PAD_KEEPER_EN_MASK) +#define AMD_SDW0_PAD_OE_CTRL_MASK (BIT(5) | BIT(6)) +#define AMD_SDW1_PAD_OE_CTRL_MASK (BIT(0) | BIT(2)) +#define AMD_SDW_PAD_OE_CTRL_MASK (AMD_SDW0_PAD_OE_CTRL_MASK | AMD_SDW1_PAD_OE_CTRL_MASK) +#define AMD_SDW0_PAD_SCHMEN_MASK (BIT(5) | BIT(6)) +#define AMD_SDW1_PAD_SCHMEN_MASK (BIT(0) | BIT(2)) +#define AMD_SDW_PAD_SCHMEN_MASK (AMD_SDW0_PAD_SCHMEN_MASK | AMD_SDW1_PAD_SCHMEN_MASK)int amd_sdw_manager_start (struct amd_sdw_manager *amd_manager);
Signature · 1 line
2.53.0
PATCH v6 3/23 soundwire: amd: add pad ctrl helpers for D0/D3 PM transitions
In reply to Vijendar MukundaDuring POWER_OFF_MODE clock stop the SoundWire clock is expected to transition High to Low cleanly. On some OEM platforms based on ACP 7.0/7.1/7.2, a transient High pulse is observed after the initial Low; the clock briefly follows a High -> Low -> High -> Low sequence (High lasting a few milliseconds) instead of the expected High -> Low. This spurious High edge interferes with wake interrupt detection, causing wake events to be silently missed.
Hardware team analysis identified that the pad keeper, pulldown, SCHMEN control and output-enable registers must be programmed as a coordinated sequence during D3 entry and D0 re-entry to suppress the transient bounce and restore the pads correctly on resume.
Introduce amd_sdw_pad_ctrl() to program PAD_KEEPER_EN, PAD_PULLDOWN_CTRL, PAD_SCHMEN_CTRL and PAD_DISABLE_OE_CTRL in a single call for D0 entry (enable=true) or D3 entry (enable=false). Introduce amd_sdw_oe_ctrl() as a lighter helper that only toggles OE. Introduce amd_sdw_pad_ctrl_supported() to consolidate the ACP revision check; both helpers use it in place of duplicate switch statements.
Both helpers apply only to ACP 7.0/7.1/7.2; ACP 6.3 returns without error and unknown revisions emit a dev_err and return.
Wire amd_sdw_pad_ctrl() into amd_suspend() and amd_resume_runtime(). Wire amd_sdw_oe_ctrl() into amd_suspend_runtime() to disable OE while leaving keeper and schmen enabled; pads remain capable of detecting wake events when wake is armed.
--- drivers/soundwire/amd_manager.c | 108 ++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+)
drivers/soundwire/amd_manager.c +108 -0
@@ -152,6 +152,104 @@ static int amd_deinit_sdw_manager(struct amd_sdw_manager *amd_manager)return amd_disable_sdw_manager (amd_manager); } +static void __amd_sdw_oe_update (struct amd_sdw_manager *amd_manager, +u32 mask,bool enable) +{ +amd_updatel (amd_manager->acp_mmio,ACP_PAD_DISABLE_OE_CTRL , + mask, enable ?0 : mask); +} + +static bool amd_sdw_pad_ctrl_supported (struct amd_sdw_manager *amd_manager) +{ +switch (amd_manager->acp_rev) { +case ACP70_PCI_REV_ID : +case ACP71_PCI_REV_ID : +case ACP72_PCI_REV_ID : +return true; +case ACP63_PCI_REV_ID : +return false; +default : +dev_err (amd_manager->dev,"unknown ACP revision 0x%x\n" , + amd_manager->acp_rev); +return false; + } +} + +static void amd_sdw_oe_ctrl (struct amd_sdw_manager *amd_manager,bool enable) +{ +u32 mask; + +if (!amd_sdw_pad_ctrl_supported (amd_manager)) +return ; + +switch (amd_manager->instance) { +case ACP_SDW0 : + mask =AMD_SDW0_PAD_OE_CTRL_MASK ; +break ; +case ACP_SDW1 : + mask =AMD_SDW1_PAD_OE_CTRL_MASK ; +break ; +default : +dev_err (amd_manager->dev,"invalid SDW instance %d\n" , + amd_manager->instance); +return ; + } + +mutex_lock (amd_manager->acp_sdw_lock); +__amd_sdw_oe_update (amd_manager, mask, enable); +mutex_unlock (amd_manager->acp_sdw_lock); +} + +static void amd_sdw_pad_ctrl (struct amd_sdw_manager *amd_manager,bool enable) +{ +u32 keeper_mask, pulldown_mask, schmen_mask, oe_mask; + +if (!amd_sdw_pad_ctrl_supported (amd_manager)) +return ; + +switch (amd_manager->instance) { +case ACP_SDW0 : + keeper_mask =AMD_SDW0_PAD_KEEPER_EN_MASK ; + pulldown_mask =AMD_SDW0_PAD_PULLDOWN_MASK ; + schmen_mask =AMD_SDW0_PAD_SCHMEN_MASK ; + oe_mask =AMD_SDW0_PAD_OE_CTRL_MASK ; +break ; +case ACP_SDW1 : + keeper_mask =AMD_SDW1_PAD_KEEPER_EN_MASK ; + pulldown_mask =AMD_SDW1_PAD_PULLDOWN_MASK ; + schmen_mask =AMD_SDW1_PAD_SCHMEN_MASK ; + oe_mask =AMD_SDW1_PAD_OE_CTRL_MASK ; +break ; +default : +dev_err (amd_manager->dev,"invalid SDW instance %d\n" , + amd_manager->instance); +return ; + } + +mutex_lock (amd_manager->acp_sdw_lock); +if (enable) { +/* D0: set keeper, clear pulldown, set schmen */ +amd_updatel (amd_manager->acp_mmio,ACP_SW_PAD_KEEPER_EN , + keeper_mask, keeper_mask); +amd_updatel (amd_manager->acp_mmio,ACP_PAD_PULLDOWN_CTRL , + pulldown_mask,0 ); +amd_updatel (amd_manager->acp_mmio,ACP_PAD_SCHMEN_CTRL , + schmen_mask, schmen_mask); + }else { +/* D3: clear keeper, set pulldown, clear schmen */ +amd_updatel (amd_manager->acp_mmio,ACP_SW_PAD_KEEPER_EN , + keeper_mask,0 ); +amd_updatel (amd_manager->acp_mmio,ACP_PAD_PULLDOWN_CTRL , + pulldown_mask, pulldown_mask); +amd_updatel (amd_manager->acp_mmio,ACP_PAD_SCHMEN_CTRL , + schmen_mask,0 ); + } + +/* enable OE on D0 (clear disable bits), disable OE on D3 (set them) */ +__amd_sdw_oe_update (amd_manager, oe_mask, enable); +mutex_unlock (amd_manager->acp_sdw_lock); +} +static void amd_sdw_set_frameshape (struct amd_sdw_manager *amd_manager) {u32 frame_size;
@@ -1319,6 +1417,8 @@ static int __maybe_unused amd_suspend(struct device *dev) ret =amd_deinit_sdw_manager (amd_manager);if (ret)return ret; +/* System suspend: tear down all pads */ +amd_sdw_pad_ctrl (amd_manager, false); }if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { ret =amd_sdw_set_device_state (amd_manager,AMD_SDW_DEVICE_STATE_D3 );
@@ -1363,6 +1463,13 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev) ret =amd_deinit_sdw_manager (amd_manager);if (ret)return ret; +/* +* For ACP 7.0/7.1/7.2: disable OE only; keeper and schmen remain +* enabled unconditionally so that wake-capable devices can detect +* wake events if wake is armed. +* For ACP 6.3 this call is a no-op. +*/ +amd_sdw_oe_ctrl (amd_manager, false); }if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { ret =amd_sdw_set_device_state (amd_manager,AMD_SDW_DEVICE_STATE_D3 );
@@ -1403,6 +1510,7 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)return ret; } }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) { +amd_sdw_pad_ctrl (amd_manager, true);writel (0x00 , amd_manager->acp_mmio +ACP_SW_WAKE_EN (amd_manager->instance));if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { ret =amd_sdw_host_wake_enable (amd_manager, false);
Signature · 1 line
2.53.0
PATCH v6 4/23 soundwire: amd: track full pad teardown across suspend/resume
In reply to Vijendar Mukundaamd_sdw_pad_ctrl() performs a full pad teardown (keeper, pulldown, schmen and OE) for system suspend, while amd_sdw_oe_ctrl() disables only OE for POWER_OFF_MODE runtime suspend. amd_resume_runtime() must distinguish between these two cases to restore pads correctly: a full teardown requires amd_sdw_pad_ctrl(true) on resume; a POWER_OFF_MODE runtime suspend in which only OE was disabled requires only amd_sdw_oe_ctrl(true).
Introduce pad_fully_torn_down flag to track when a full pad teardown was performed. Set the flag after amd_sdw_pad_ctrl(false) in amd_suspend() using amd_sdw_pad_ctrl_supported() to gate the assignment to revisions that support pad control. Clear it after the full restore in amd_resume_runtime(). On resume, restore all pads if the flag is set, otherwise restore OE only; both paths delegate revision gating to the respective helpers.
--- drivers/soundwire/amd_manager.c | 12 ++++++++++-- include/linux/soundwire/sdw_amd.h | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-)
drivers/soundwire/amd_manager.c +10 -2
@@ -1418,7 +1418,10 @@ static int __maybe_unused amd_suspend(struct device *dev)if (ret)return ret;/* System suspend: tear down all pads */ -amd_sdw_pad_ctrl (amd_manager, false); +if (amd_sdw_pad_ctrl_supported (amd_manager)) { +amd_sdw_pad_ctrl (amd_manager, false); + amd_manager->pad_fully_torn_down = true; + } }if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { ret =amd_sdw_set_device_state (amd_manager,AMD_SDW_DEVICE_STATE_D3 );
@@ -1510,7 +1513,12 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)return ret; } }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) { -amd_sdw_pad_ctrl (amd_manager, true); +if (amd_manager->pad_fully_torn_down) { +amd_sdw_pad_ctrl (amd_manager, true); + amd_manager->pad_fully_torn_down = false; + }else { +amd_sdw_oe_ctrl (amd_manager, true); + }writel (0x00 , amd_manager->acp_mmio +ACP_SW_WAKE_EN (amd_manager->instance));if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { ret =amd_sdw_host_wake_enable (amd_manager, false);
include/linux/soundwire/sdw_amd.h +7 -0
@@ -75,6 +75,12 @@ struct sdw_amd_dai_runtime {* @wake_en_mask: wake enable mask per SoundWire manager * @acp_rev: acp pci device revision id * @clk_stopped: flag set to true when clock is stopped +* @pad_fully_torn_down: true when system suspend performed a full pad +* teardown (keeper, schmen and OE cleared, pulldown asserted). Cleared after +* all pads are restored in amd_resume_runtime(). False on initial probe +* (zero-initialized) and after a POWER_OFF_MODE runtime suspend in which +* only OE was disabled; in the latter case amd_resume_runtime() restores +* OE only, leaving keeper and schmen untouched. * @power_mode_mask: flag interprets amd SoundWire manager power mode * @dai_runtime_array: dai runtime array */
@@ -106,6 +112,7 @@ struct amd_sdw_manager {u32 power_mode_mask;u32 acp_rev;bool clk_stopped; +bool pad_fully_torn_down;struct sdw_amd_dai_runtime **dai_runtime_array; };
Signature · 1 line
2.53.0
PATCH v6 5/23 soundwire: amd: fix missing wake interrupt and group wake-arming calls in runtime suspend
In reply to Vijendar MukundaIn amd_suspend_runtime() POWER_OFF_MODE, amd_sdw_wake_enable() was called before amd_deinit_sdw_manager(), causing the wake IRQ mask to be silently overwritten.
amd_deinit_sdw_manager() calls amd_disable_sdw_interrupts() which writes 0x00 to ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11, wiping AMD_SDW_WAKE_INTR_MASK (BIT(16)) set by amd_sdw_wake_enable(). Move amd_sdw_wake_enable() to after amd_deinit_sdw_manager() so the wake mask is armed after the interrupt-disable sequence and cannot be clobbered.
Move amd_sdw_host_wake_enable() after amd_deinit_sdw_manager() as well, grouping both wake-arming calls together after the interrupt-disable sequence.
If amd_deinit_sdw_manager() fails (timeout waiting for ACP_SW_EN_STATUS), the hardware is in an indeterminate state and wake IRQ delivery cannot be expected to function; the early return before the wake-arming calls is correct in this case.
--- drivers/soundwire/amd_manager.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/soundwire/amd_manager.c +6 -6
@@ -1454,18 +1454,18 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)if (ret)return ret; }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) { -amd_sdw_wake_enable (amd_manager, true); -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, true); -if (ret) -return ret; - } ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; ret =amd_deinit_sdw_manager (amd_manager);if (ret)return ret; +amd_sdw_wake_enable (amd_manager, true); +if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { + ret =amd_sdw_host_wake_enable (amd_manager, true); +if (ret) +return ret; + }/* * For ACP 7.0/7.1/7.2: disable OE only; keeper and schmen remain * enabled unconditionally so that wake-capable devices can detect
Signature · 1 line
2.53.0
PATCH v6 6/23 soundwire: amd: fix IRQ thread dropping STATUS_0TO7 on simultaneous wake
In reply to Vijendar MukundaWhen a wake interrupt and a device-state change arrived simultaneously, amd_sdw_irq_thread() returned early after the wake path, silently discarding the STATUS_0TO7 bits.
Remove the early return and fall through to the normal slave-status processing path. Clear the wake bit from the local status_change_8to11 copy before proceeding so the remaining status checks are not confused by the wake bit.
--- drivers/soundwire/amd_manager.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/soundwire/amd_manager.c +5 -2
@@ -1110,8 +1110,11 @@ static void amd_sdw_irq_thread(struct work_struct *work)dev_dbg (amd_manager->dev,"[SDW%d] SDW INT: 0to7=0x%x, 8to11=0x%x\n" , amd_manager->instance, status_change_0to7, status_change_8to11); -if (status_change_8to11 &AMD_SDW_WAKE_STAT_MASK ) -return amd_sdw_process_wake_event (amd_manager); + +if (status_change_8to11 &AMD_SDW_WAKE_STAT_MASK ) { +amd_sdw_process_wake_event (amd_manager); + status_change_8to11 &= ~AMD_SDW_WAKE_STAT_MASK ; + }if (status_change_8to11 &AMD_SDW_PREQ_INTR_STAT ) {amd_sdw_read_and_process_ping_status (amd_manager);
Signature · 1 line
2.53.0
PATCH v6 7/23 soundwire: amd: remove STATUS_8TO11 clear from amd_sdw_process_wake_event()
In reply to Vijendar Mukundaamd_sdw_irq_thread() falls through after handling a wake event to process any coalesced PREQ or peripheral status events, rather than returning early. With the fall-through in place, both amd_sdw_process_wake_event() and the tail of amd_sdw_irq_thread() write 0x00 to ACP_SW_STATE_CHANGE_STATUS_8TO11 in the same invocation. Any status bit asserted by hardware between those two writes would be lost before the next invocation reads the register.
Remove the writel() from amd_sdw_process_wake_event() so that ACP_SW_STATE_CHANGE_STATUS_8TO11 is cleared exactly once per invocation by the tail of amd_sdw_irq_thread().
--- drivers/soundwire/amd_manager.c | 1 - 1 file changed, 1 deletion(-)
drivers/soundwire/amd_manager.c +0 -1
@@ -1093,7 +1093,6 @@ static void amd_sdw_process_wake_event(struct amd_sdw_manager *amd_manager)dev_dbg (amd_manager->dev,"SoundWire Wake event reported\n" );pm_request_resume (amd_manager->dev);writel (0x00 , amd_manager->acp_mmio +ACP_SW_WAKE_EN (amd_manager->instance)); -writel (0x00 , amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_8TO11 ); }static void amd_sdw_irq_thread (struct work_struct *work)
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v6 07/23] soundwire: amd: remove STATUS_8TO11 clear from amd_sdw_process_wake_event()
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] soundwire: amd: inaccurate Fixes trailer in amd_sdw_process_wake_event() change --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] soundwire: amd: inaccurate Fixes trailer in amd_sdw_process_wake_event() change
--
commit 37e17ac67e68c6f83de067cdc5e343eec8f2c9c9
Author: Vijendar Mukunda <[email protected]>
Quoted 10 lines
soundwire: amd: remove
STATUS_8TO11clear fromamd_sdw_process_wake_event()
amd_sdw_irq_thread()falls through after handling a wake event to process any coalesced PREQ or peripheral status events, rather than returning early. With the fall-through in place, bothamd_sdw_process_wake_event()and the tail ofamd_sdw_irq_thread()write0x00toACP_SW_STATE_CHANGE_STATUS_8TO11in the same invocation. Any status bit asserted by hardware between those two writes would be lost before the next invocation reads the register.
Quoted 6 lines
Remove the
writel()fromamd_sdw_process_wake_event()so thatACP_SW_STATE_CHANGE_STATUS_8TO11is cleared exactly once per invocation by the tail ofamd_sdw_irq_thread().Signed-off-by Vijendar Mukunda <[email protected]>Fixes 66c878838f37 ("soundwire: amd: handle SoundWire wake enable interrupt")
[Severity: Low]
Is the Fixes tag pointing at the right commit?
In 66c878838f37 ("soundwire: amd: handle SoundWire wake enable interrupt"), amd_sdw_irq_thread() returned early via amd_sdw_process_wake_event(), so ACP_SW_STATE_CHANGE_STATUS_8TO11 was only cleared once. The fall-through that causes the duplicate write was introduced by the preceding patch in this series, commit "soundwire: amd: fix IRQ thread dropping STATUS_0TO7 on simultaneous wake".
If this patch is backported to a tree with 66c878838f37 ("soundwire: amd:
handle SoundWire wake enable interrupt") without that preceding commit, amd_sdw_irq_thread() will return early on a wake event without clearing ACP_SW_STATE_CHANGE_STATUS_8TO11 at all. Should the Fixes tag be dropped or this change squashed into the preceding patch?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Re: [PATCH v6 07/23] soundwire: amd: remove STATUS_8TO11 clear from amd_sdw_process_wake_event()
Quoted 35 lines · On 17/11/26 12:56, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] soundwire: amd: inaccurate Fixes trailer inamd_sdw_process_wake_event()change
--commit
37e17ac67e68c6f83de067cdc5e343eec8f2c9c9
Author: Vijendar Mukunda <[email protected]>Quoted 10 lines
soundwire: amd: remove
STATUS_8TO11clear fromamd_sdw_process_wake_event()
amd_sdw_irq_thread()falls through after handling a wake event to process any coalesced PREQ or peripheral status events, rather than returning early. With the fall-through in place, bothamd_sdw_process_wake_event()and the tail ofamd_sdw_irq_thread()write0x00toACP_SW_STATE_CHANGE_STATUS_8TO11in the same invocation. Any status bit asserted by hardware between those two writes would be lost before the next invocation reads the register.Quoted 6 lines
Remove the
writel()fromamd_sdw_process_wake_event()so thatACP_SW_STATE_CHANGE_STATUS_8TO11is cleared exactly once per invocation by the tail ofamd_sdw_irq_thread().Signed-off-by Vijendar Mukunda <[email protected]>Fixes 66c878838f37 ("soundwire: amd: handle SoundWire wake enable interrupt")[Severity: Low]
Is the Fixes tag pointing at the right commit?In
66c878838f37("soundwire: amd: handle SoundWire wake enable interrupt"),amd_sdw_irq_thread()returned early viaamd_sdw_process_wake_event(), soACP_SW_STATE_CHANGE_STATUS_8TO11was only cleared once. The fall-through that causes the duplicate write was introduced by the preceding patch in this series, commit "soundwire: amd: fix IRQ thread droppingSTATUS_0TO7on simultaneous wake".
Quoted 5 lines
If this patch is backported to a tree with
66c878838f37("soundwire: amd:
handle SoundWire wake enable interrupt") without that preceding commit,amd_sdw_irq_thread()will return early on a wake event without clearingACP_SW_STATE_CHANGE_STATUS_8TO11at all. Should the Fixes tag be dropped or this change squashed into the preceding patch?
++
You are correct. The Fixes tag is incorrect.
In 66c878838f37 ("soundwire: amd: handle SoundWire wake enable interrupt"), amd_sdw_irq_thread() returned early via amd_sdw_process_wake_event(), so ACP_SW_STATE_CHANGE_STATUS_8TO11 was cleared only once. The double-clear did not exist in that commit.
The double-clear is introduced by patch 06 of this series, which changes the early return to a fall-through.
I prefer to keep the two fixes separate, as patch 06 fixes the dropped STATUS_0TO7 on simultaneous wake events, while patch 07 removes the STATUS_8TO11 clear that becomes redundant with the fall-through.
I will drop the Fixes tag from patch 07 in v7.
Quoted 1 line
PATCH v6 8/23 soundwire: amd: fix missing wake interrupt for ACP6.3 in POWER_OFF suspend
In reply to Vijendar MukundaOn some OEM platforms based on ACP 6.3, with a SoundWire topology where the UAJ peripheral is on one instance and the speaker peripheral is on the other, wake events from the UAJ instance are silently lost every time it enters POWER_OFF runtime suspend (D3) while speaker playback keeps ACP in D0.
On ACP6.3, unlike ACP7.0/7.1/7.2, there is no dedicated host wake interrupt path (no ACP_EXTERNAL_INTR_CNTL1 host wake mask bits and no PME wake mechanism). The wake event from a suspended SoundWire instance is delivered solely through the standard SoundWire interrupt bit in ACP_EXTERNAL_INTR_CNTL.
In the POWER_OFF_MODE runtime suspend path, amd_deinit_sdw_manager() calls amd_disable_sdw_interrupts() which clears the SoundWire instance bit in ACP_EXTERNAL_INTR_CNTL. After this, the wake interrupt has no delivery path to the CPU.
Fix this by re-enabling the SoundWire instance bit in ACP_EXTERNAL_INTR_CNTL after amd_deinit_sdw_manager() and amd_sdw_wake_enable() complete, when acp_rev is ACP63_PCI_REV_ID and wake_en_mask is set. The acp_sdw_lock mutex is held around the read-modify-write to prevent a race when both instances suspend or resume concurrently.
--- drivers/soundwire/amd_manager.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/soundwire/amd_manager.c +7 -0
@@ -1467,6 +1467,13 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev) ret =amd_sdw_host_wake_enable (amd_manager, true);if (ret)return ret; + }else if ((amd_manager->acp_rev ==ACP63_PCI_REV_ID ) && + amd_manager->wake_en_mask) { +mutex_lock (amd_manager->acp_sdw_lock); + val = sdw_manager_reg_mask_array[amd_manager->instance]; +amd_updatel (amd_manager->acp_mmio, +ACP_EXTERNAL_INTR_CNTL (amd_manager->instance), val, val); +mutex_unlock (amd_manager->acp_sdw_lock); }/* * For ACP 7.0/7.1/7.2: disable OE only; keeper and schmen remain
Signature · 1 line
2.53.0
PATCH v6 9/23 soundwire: amd: fix SDW command timeout return value handling
In reply to Vijendar Mukundaamd_sdw_send_cmd_get_resp() returned u64 but was returning -ETIMEDOUT (a negative int) on readl_poll_timeout() failures, which silently widens to a large u64 value.
Change the return type to int and pass the raw u64 response through an out-parameter. Timeout is detected directly from readl_poll_timeout() return value.
Update all callers: amd_program_scp_addr(), _amd_sdw_xfer_msg(), amd_sdw_read_and_process_ping_status(), and amd_sdw_read_ping_status() to check the return value and handle timeout explicitly.
--- drivers/soundwire/amd_manager.c | 49 ++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 22 deletions(-)
drivers/soundwire/amd_manager.c +27 -22
@@ -348,10 +348,9 @@ static void amd_sdw_ctl_word_prep(u32 *lower_word, u32 *upper_word, struct sdw_m *lower_word = lower_data; } -static u64 amd_sdw_send_cmd_get_resp (struct amd_sdw_manager *amd_manager,u32 lower_data, -u32 upper_data) +static int amd_sdw_send_cmd_get_resp (struct amd_sdw_manager *amd_manager,u32 lower_data, +u32 upper_data,u64 *response) { -u64 resp;u32 lower_resp, upper_resp;u32 sts;int ret;
@@ -389,9 +388,8 @@ static u64 amd_sdw_send_cmd_get_resp(struct amd_sdw_manager *amd_manager, u32 lo amd_manager->instance);return ret; } - resp = upper_resp; - resp = (resp <<32 ) | lower_resp; -return resp; + *response = ((u64 )upper_resp <<32 ) | lower_resp; +return 0 ; } static enum sdw_command_response
@@ -407,19 +405,22 @@ amd_program_scp_addr(struct amd_sdw_manager *amd_manager, struct sdw_msg *msg) scp_msg.buf = &msg->addr_page1; scp_msg.flags =SDW_MSG_FLAG_WRITE ;amd_sdw_ctl_word_prep (&lower_data, &upper_data, &scp_msg,0 ); - response_buf[0 ] =amd_sdw_send_cmd_get_resp (amd_manager, lower_data, upper_data); +if (amd_sdw_send_cmd_get_resp (amd_manager, lower_data, upper_data, &response_buf[0 ])) { +dev_err_ratelimited (amd_manager->dev, +"SCP_addrpage command timeout for Slave %d\n" , msg->dev_num); +return SDW_CMD_TIMEOUT ; + } scp_msg.addr =SDW_SCP_ADDRPAGE2 ; scp_msg.buf = &msg->addr_page2;amd_sdw_ctl_word_prep (&lower_data, &upper_data, &scp_msg,0 ); - response_buf[1 ] =amd_sdw_send_cmd_get_resp (amd_manager, lower_data, upper_data); +if (amd_sdw_send_cmd_get_resp (amd_manager, lower_data, upper_data, &response_buf[1 ])) { +dev_err_ratelimited (amd_manager->dev, +"SCP_addrpage command timeout for Slave %d\n" , msg->dev_num); +return SDW_CMD_TIMEOUT ; + }for (index =0 ; index <2 ; index++) { -if (response_buf[index] == -ETIMEDOUT ) { -dev_err_ratelimited (amd_manager->dev, -"SCP_addrpage command timeout for Slave %d\n" , - msg->dev_num); -return SDW_CMD_TIMEOUT ; - }else if (!(response_buf[index] &AMD_SDW_MCP_RESP_ACK )) { +if (!(response_buf[index] &AMD_SDW_MCP_RESP_ACK )) {if (response_buf[index] &AMD_SDW_MCP_RESP_NACK ) { dev_err_ratelimited(amd_manager->dev, "SCP_addrpage NACKed for Slave %d\n",
@@ -464,11 +465,7 @@ static enum sdw_command_response amd_sdw_fill_msg_resp(struct amd_sdw_manager *aif (msg->flags ==SDW_MSG_FLAG_READ ) msg->buf[offset] =FIELD_GET (AMD_SDW_MCP_RESP_RDATA , response); }else { -if (response == -ETIMEDOUT ) { -dev_err_ratelimited (amd_manager->dev,"command timeout for Slave %d\n" , - msg->dev_num); -return SDW_CMD_TIMEOUT ; - }else if (response &AMD_SDW_MCP_RESP_NACK ) { +if (response &AMD_SDW_MCP_RESP_NACK ) {dev_err_ratelimited (amd_manager->dev,"command response NACK received for Slave %d\n" , msg->dev_num);
@@ -488,7 +485,11 @@ static unsigned int _amd_sdw_xfer_msg(struct amd_sdw_manager *amd_manager, strucu32 upper_data =0 , lower_data =0 ;amd_sdw_ctl_word_prep (&lower_data, &upper_data, msg, cmd_offset); - response =amd_sdw_send_cmd_get_resp (amd_manager, lower_data, upper_data); +if (amd_sdw_send_cmd_get_resp (amd_manager, lower_data, upper_data, &response)) { +dev_err_ratelimited (amd_manager->dev,"command timeout for Slave %d\n" , + msg->dev_num); +return SDW_CMD_TIMEOUT ; + }return amd_sdw_fill_msg_resp (amd_manager, msg, response, cmd_offset); }
@@ -544,7 +545,10 @@ static void amd_sdw_read_and_process_ping_status(struct amd_sdw_manager *amd_manu64 response;mutex_lock (&amd_manager->bus.msg_lock); - response =amd_sdw_send_cmd_get_resp (amd_manager,0 ,0 ); +if (amd_sdw_send_cmd_get_resp (amd_manager,0 ,0 , &response)) { +mutex_unlock (&amd_manager->bus.msg_lock); +return ; + }mutex_unlock (&amd_manager->bus.msg_lock);amd_sdw_process_ping_status (response, amd_manager); }
@@ -555,7 +559,8 @@ static u32 amd_sdw_read_ping_status(struct sdw_bus *bus)u64 response;u32 slave_stat; - response =amd_sdw_send_cmd_get_resp (amd_manager,0 ,0 ); +if (amd_sdw_send_cmd_get_resp (amd_manager,0 ,0 , &response)) +return 0 ;/* slave status from ping response */ slave_stat =FIELD_GET (AMD_SDW_MCP_SLAVE_STAT_0_3 , response); slave_stat |=FIELD_GET (AMD_SDW_MCP_SLAVE_STAT_4_11 , response) <<8 ;
Signature · 1 line
2.53.0
PATCH v6 10/23 soundwire: amd: cache ping slave status to avoid spurious disconnect on timeout
In reply to Vijendar Mukundaamd_sdw_read_ping_status() returned 0 on a PING command timeout. This was indistinguishable from a valid "no peripherals attached" response, causing sdw_show_ping_status() to log a spurious disconnect warning even when devices were actually present.
Add ping_slave_stat to struct amd_sdw_manager to cache the slave_stat from the last successful ping response. On timeout, the cached value is returned instead of 0, so sdw_show_ping_status() sees the last known good state. The timeout itself is still reported via dev_err() - the cache does not suppress the error.
ping_slave_stat is initialised to U32_MAX in probe and reset to U32_MAX under msg_lock before any failable step in the POWER_OFF_MODE resume path, so a partially-failed resume cannot leave stale pre-suspend data behind for a subsequent ping timeout to report.
--- drivers/soundwire/amd_manager.c | 18 +++++++++++++++++- include/linux/soundwire/sdw_amd.h | 4 ++++ 2 files changed, 21 insertions(+), 1 deletion(-)
drivers/soundwire/amd_manager.c +17 -1
@@ -549,6 +549,9 @@ static void amd_sdw_read_and_process_ping_status(struct amd_sdw_manager *amd_manmutex_unlock (&amd_manager->bus.msg_lock);return ; } + amd_manager->ping_slave_stat = +FIELD_GET (AMD_SDW_MCP_SLAVE_STAT_0_3 , response) | + (FIELD_GET (AMD_SDW_MCP_SLAVE_STAT_4_11 , response) <<8 );mutex_unlock (&amd_manager->bus.msg_lock);amd_sdw_process_ping_status (response, amd_manager); }
@@ -560,11 +563,12 @@ static u32 amd_sdw_read_ping_status(struct sdw_bus *bus)u32 slave_stat;if (amd_sdw_send_cmd_get_resp (amd_manager,0 ,0 , &response)) -return 0 ; +return amd_manager->ping_slave_stat ==U32_MAX ?0 : amd_manager->ping_slave_stat;/* slave status from ping response */ slave_stat =FIELD_GET (AMD_SDW_MCP_SLAVE_STAT_0_3 , response); slave_stat |=FIELD_GET (AMD_SDW_MCP_SLAVE_STAT_4_11 , response) <<8 ;dev_dbg (amd_manager->dev,"slave_stat:0x%x\n" , slave_stat); + amd_manager->ping_slave_stat = slave_stat;return slave_stat; }
@@ -1182,6 +1186,7 @@ static int amd_sdw_manager_probe(struct platform_device *pdev)dev_err (dev,"mmio not found\n" );return -ENOMEM ; } + amd_manager->ping_slave_stat =U32_MAX ; amd_manager->instance = pdata->instance; amd_manager->mmio = amd_manager->acp_mmio + (amd_manager->instance *SDW_MANAGER_REG_OFFSET );
@@ -1534,6 +1539,17 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)amd_sdw_oe_ctrl (amd_manager, true); }writel (0x00 , amd_manager->acp_mmio +ACP_SW_WAKE_EN (amd_manager->instance)); +/* +* POWER_OFF_MODE tears the bus down completely; invalidate the +* cached ping status before any failable step so that a +* partially-failed resume leaves the first post-resume ping +* timeout returning 0 rather than stale pre-suspend data. +* CLK_STOP_MODE leaves peripherals attached, so the cache +* remains valid there. +*/ +mutex_lock (&amd_manager->bus.msg_lock); + amd_manager->ping_slave_stat =U32_MAX ; +mutex_unlock (&amd_manager->bus.msg_lock);if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { ret =amd_sdw_host_wake_enable (amd_manager, false);if (ret)
include/linux/soundwire/sdw_amd.h +4 -0
@@ -82,6 +82,9 @@ struct sdw_amd_dai_runtime {* only OE was disabled; in the latter case amd_resume_runtime() restores * OE only, leaving keeper and schmen untouched. * @power_mode_mask: flag interprets amd SoundWire manager power mode +* @ping_slave_stat: cached slave status from the last ping +* transaction that returned a response; +* initialised to U32_MAX ("no valid reading yet") * @dai_runtime_array: dai runtime array */ struct amd_sdw_manager {
@@ -111,6 +114,7 @@ struct amd_sdw_manager {u32 wake_en_mask;u32 power_mode_mask;u32 acp_rev; +u32 ping_slave_stat;bool clk_stopped;bool pad_fully_torn_down;
Signature · 1 line
2.53.0
PATCH v6 11/23 soundwire: amd: assert msg_lock is held in amd_sdw_read_ping_status()
In reply to Vijendar Mukundaamd_sdw_read_ping_status() is always called from sdw_show_ping_status() which holds bus->msg_lock. Add lockdep_assert_held() to document this locking requirement and catch any future callers that omit the lock.
--- drivers/soundwire/amd_manager.c | 1 + 1 file changed, 1 insertion(+)
drivers/soundwire/amd_manager.c +1 -0
@@ -562,6 +562,7 @@ static u32 amd_sdw_read_ping_status(struct sdw_bus *bus)u64 response;u32 slave_stat; +lockdep_assert_held (&bus->msg_lock);if (amd_sdw_send_cmd_get_resp (amd_manager,0 ,0 , &response))return amd_manager->ping_slave_stat ==U32_MAX ?0 : amd_manager->ping_slave_stat;/* slave status from ping response */
Signature · 1 line
2.53.0
PATCH v6 12/23 soundwire: amd: fix work drain ordering in remove path
In reply to Vijendar Mukundaamd_sdw_manager_remove() cancelled amd_sdw_work but not amd_sdw_irq_thread. Since amd_sdw_irq_thread() calls schedule_work(&amd_sdw_work), an in-flight irq_thread item can re-queue amd_sdw_work after its cancel returns, defeating the cancellation.
Fix by calling amd_disable_sdw_interrupts() first to quiesce the hardware IRQ source, then cancel_work_sync() for amd_sdw_irq_thread, then cancel_work_sync() for amd_sdw_work. The existing cancel_work_sync(amd_sdw_work) is also moved to after amd_disable_sdw_interrupts() so that any work item queued between the old cancel position and the interrupt disable cannot escape draining.
synchronize_irq() is deliberately not used before the cancel_work_sync() calls. Once SoundWire interrupts are masked, no new IRQ deliveries can occur. An IRQ handler already in flight may still queue amd_sdw_irq_thread, so cancel_work_sync() is used to drain both amd_sdw_irq_thread and any amd_sdw_work items it may have scheduled. This fully quiesces the driver workqueues, making synchronize_irq() unnecessary.
--- drivers/soundwire/amd_manager.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/soundwire/amd_manager.c +2 -1
@@ -1266,8 +1266,9 @@ static void amd_sdw_manager_remove(struct platform_device *pdev)int ret;pm_runtime_disable (&pdev->dev); -cancel_work_sync (&amd_manager->amd_sdw_work);amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread); +cancel_work_sync (&amd_manager->amd_sdw_work);sdw_bus_master_delete (&amd_manager->bus); ret =amd_disable_sdw_manager (amd_manager);if (ret)
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v6 12/23] soundwire: amd: fix work drain ordering in remove path
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] soundwire: amd: unsynchronized in-flight IRQ in amd_sdw_manager_remove() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] soundwire: amd: unsynchronized in-flight IRQ in amd_sdw_manager_remove()
--
commit 3506edf69d0fb093063647130bfc49c4745d7c81
Author: Vijendar Mukunda <[email protected]>
soundwire: amd: fix work drain ordering in remove path
This commit masks SoundWire interrupts before cancelling amd_sdw_irq_thread and amd_sdw_work in amd_sdw_manager_remove().
Quoted 5 lines
drivers/soundwire/amd_manager.c +0
-0
drivers/soundwire/amd_manager.c static void amd_sdw_manager_remove(struct platform_device *pdev) · line 1273
Quoted 10 lines
drivers/soundwire/amd_manager.c +2
-1@@ -1265,8 +1265,9 @@ static void amd_sdw_manager_remove(struct platform_device *pdev)int ret;pm_runtime_disable (&pdev->dev); -cancel_work_sync (&amd_manager->amd_sdw_work);amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread); +cancel_work_sync (&amd_manager->amd_sdw_work);sdw_bus_master_delete (&amd_manager->bus); ret =amd_disable_sdw_manager (amd_manager);if (ret)
[Severity: Medium]
Can an in-flight parent hard IRQ handler queue amd_sdw_irq_thread after cancel_work_sync() returns?
The commit message notes that an IRQ handler already in flight may still queue amd_sdw_irq_thread and relies on cancel_work_sync() to drain it without synchronize_irq(). However, cancel_work_sync() only cancels or waits for work that is already pending or running when checked, and leaves the work item enabled on return. When the amd_sdw_manager platform device is unbound via sysfs while the parent ACP PCI IRQ remains active, an IRQ that fired just before amd_disable_sdw_interrupts() can still schedule the work item after both cancel_work_sync() calls finish:
sound/soc/amd/ps/pci-ps.c:acp63_irq_handler() {
...
if (ext_intr_stat & ACP_SDW0_STAT) {
writel(ACP_SDW0_STAT, adata->acp63_base + ACP_EXTERNAL_INTR_STAT);
if (adata->sdw) {
amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev);
if (amd_manager)
schedule_work(&amd_manager->amd_sdw_irq_thread);
}
irq_flag = 1;
}
...
}CPU0 CPU1amd_sdw_manager_remove() acp63_irq_handler()
ext_intr_stat & ACP_SDW0_STAT amd_manager = dev_get_drvdata(...)
amd_disable_sdw_interrupts()
cancel_work_sync(...irq_thread) cancel_work_sync(...amd_sdw_work)
schedule_work(...irq_thread)
sdw_bus_master_delete()
...devres_release_all()
/* frees amd_manager */
amd_sdw_irq_thread()
readl(amd_manager->mmio + ...)
<-- use-after-freeEven with commit "soundwire: amd: use interrupt_enabled flag to guard IRQ work scheduling" later in the series, acp63_irq_handler() and acp_irq_handler() still call schedule_work(&amd_manager->amd_sdw_irq_thread) unconditionally. Using disable_work_sync() in amd_sdw_manager_remove() (or synchronizing with the parent IRQ after masking) would prevent the work items from being queued again during teardown.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Re: [PATCH v6 12/23] soundwire: amd: fix work drain ordering in remove path
Quoted 21 lines · On 17/11/26 13:00, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] soundwire: amd: unsynchronized in-flight IRQ inamd_sdw_manager_remove()
--commit
3506edf69d0fb093063647130bfc49c4745d7c81
Author: Vijendar Mukunda <[email protected]>soundwire: amd: fix work drain ordering in remove path
This commit masks SoundWire interrupts before cancelling
amd_sdw_irq_threadandamd_sdw_workinamd_sdw_manager_remove().Quoted 7 lines
drivers/soundwire/amd_manager.c +0
-0@@ -1265,8 +1265,9 @@ static void amd_sdw_manager_remove(struct platform_device *pdev)int ret;
Quoted 11 lines
drivers/soundwire/amd_manager.c static void amd_sdw_manager_remove(struct platform_device *pdev) · line 1274
Quoted 8 lines
drivers/soundwire/amd_manager.c +2
-1pm_runtime_disable (&pdev->dev); -cancel_work_sync (&amd_manager->amd_sdw_work);amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread); +cancel_work_sync (&amd_manager->amd_sdw_work);sdw_bus_master_delete (&amd_manager->bus); ret =amd_disable_sdw_manager (amd_manager);if (ret)[Severity: Medium]
Can an in-flight parent hard IRQ handler queueamd_sdw_irq_threadaftercancel_work_sync()returns?
No changes required.
Patch 15 later in this series ("soundwire: amd: use interrupt_enabled flag to guard IRQ work scheduling") adds an early-return check at the top of amd_sdw_irq_thread():
if (!READ_ONCE(amd_manager->interrupt_enabled))
return;
amd_disable_sdw_interrupts() clears interrupt_enabled before touching any hardware mask registers. Even if the parent IRQ handler re-schedules the work after cancel_work_sync() returns, the work exits immediately at the interrupt_enabled check without executing any interrupt handling logic.
Quoted 9 lines
The commit message notes that an IRQ handler already in flight may still queue
amd_sdw_irq_threadand relies oncancel_work_sync()to drain it withoutsynchronize_irq(). However,cancel_work_sync()only cancels or waits for work that is already pending or running when checked, and leaves the work item enabled on return. When theamd_sdw_managerplatform device is unbound via sysfs while the parent ACP PCI IRQ remains active, an IRQ that fired just beforeamd_disable_sdw_interrupts()can still schedule the work item after bothcancel_work_sync()calls finish:
Agreed. cancel_work_sync() drains work that is pending or running at the time of the call. The interrupt_enabled guard in patch 15 handles work re-scheduled after cancel_work_sync() returns: such work finds interrupt_enabled false and returns immediately.
Quoted 27 lines
sound/soc/amd/ps/pci-ps.c:acp63_irq_handler() { ... if (ext_intr_stat & ACP_SDW0_STAT) { writel(ACP_SDW0_STAT, adata->acp63_base + ACP_EXTERNAL_INTR_STAT); if (adata->sdw) { amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev); if (amd_manager) schedule_work(&amd_manager->amd_sdw_irq_thread); } irq_flag = 1; } ... }CPU0 CPU1
amd_sdw_manager_remove()acp63_irq_handler()
ext_intr_stat&ACP_SDW0_STATamd_manager=dev_get_drvdata(...)
amd_disable_sdw_interrupts()
cancel_work_sync(...irq_thread)cancel_work_sync(...amd_sdw_work)
schedule_work(...irq_thread)
sdw_bus_master_delete()
...devres_release_all()
/* freesamd_manager*/
Quoted 3 lines
amd_sdw_irq_thread()
readl(amd_manager->mmio + ...)
<-- use-after-freeWith the interrupt_enabled guard in patch 15, amd_sdw_irq_thread() no longer proceeds to readl(amd_manager->mmio + ...) in this scenario. The re-scheduled work checks READ_ONCE(amd_manager->interrupt_enabled), finds it false, and returns without touching any hardware registers or manager state.
Quoted 5 lines
Even with commit "soundwire: amd: use
interrupt_enabledflag to guard IRQ work scheduling" later in the series,acp63_irq_handler()andacp_irq_handler()still callschedule_work(&amd_manager->amd_sdw_irq_thread)unconditionally.
The unconditional schedule_work() in the parent handlers is intentional. The interrupt_enabled guard inside amd_sdw_irq_thread() restricts execution rather than scheduling, keeping the IRQ handler fast and lock-free. The result is the same: no interrupt handling runs during teardown.
Quoted 3 lines
Using
disable_work_sync()inamd_sdw_manager_remove()(or
synchronizing with the parent IRQ after masking) would prevent the work items from being queued again during teardown.
The patches 12 and 15 together achieve the same safety goal without requiring disable_work_sync() (a Linux 6.9+ API) or synchronize_irq() on the parent device's shared IRQ. The sequence is:
1. interrupt_enabled = false (before hardware mask writes)
2. hardware masks written
3. cancel_work_sync() drains pending/running work
4. any subsequently re-scheduled work returns at the interrupt_enabled check
Quoted 1 line
PATCH v6 13/23 soundwire: amd: defer dev_set_drvdata() until after INIT_WORK()
In reply to Vijendar Mukundaamd_sdw_manager_probe() called dev_set_drvdata() before initialising the amd_sdw_irq_thread and amd_sdw_work structures with INIT_WORK(). An interrupt arriving in that window could call the IRQ handler which enqueues amd_sdw_irq_thread before the work struct is initialised, leading to undefined behaviour.
Move dev_set_drvdata() to after both INIT_WORK() calls to close the race window.
--- drivers/soundwire/amd_manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soundwire/amd_manager.c +1 -1
@@ -1254,9 +1254,9 @@ static int amd_sdw_manager_probe(struct platform_device *pdev)sdw_bus_master_delete (&amd_manager->bus);return ret; } -dev_set_drvdata (dev, amd_manager);INIT_WORK (&amd_manager->amd_sdw_irq_thread, amd_sdw_irq_thread);INIT_WORK (&amd_manager->amd_sdw_work, amd_sdw_update_slave_status_work); +dev_set_drvdata (dev, amd_manager);return 0 ; }
Signature · 1 line
2.53.0
PATCH v6 14/23 soundwire: amd: pm_runtime guard in remove path
In reply to Vijendar MukundaGuard pm_runtime_disable() so it is only called when runtime PM was actually enabled. amd_sdw_manager_start() calls pm_runtime_enable() only at the very end, after several fallible hardware init steps. If sdw_amd_startup() fails mid-loop (one manager started, the next fails before pm_runtime_enable()), sdw_amd_exit() triggers platform_device_unregister() for all managers. Calling pm_runtime_disable() on the partially-started manager finds disable_depth already at its initial value of 1, silently increments it to 2 and returns without a warning, so a later pm_runtime_enable() would only bring it back to 1 and leave runtime PM disabled. Use pm_runtime_enabled() to skip the call when it was never paired with an enable.
--- drivers/soundwire/amd_manager.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/soundwire/amd_manager.c +2 -1
@@ -1265,7 +1265,8 @@ static void amd_sdw_manager_remove(struct platform_device *pdev)struct amd_sdw_manager *amd_manager =dev_get_drvdata (&pdev->dev);int ret; -pm_runtime_disable (&pdev->dev); +if (pm_runtime_enabled (&pdev->dev)) +pm_runtime_disable (&pdev->dev);amd_disable_sdw_interrupts (amd_manager);cancel_work_sync (&amd_manager->amd_sdw_irq_thread);cancel_work_sync (&amd_manager->amd_sdw_work);
Signature · 1 line
2.53.0
PATCH v6 15/23 soundwire: amd: use interrupt_enabled flag to guard IRQ work scheduling
In reply to Vijendar MukundaAdd an interrupt_enabled boolean to struct amd_sdw_manager to prevent already-queued work from executing during the window between starting to disable interrupts and the hardware masks taking effect.
- Add interrupt_enabled to struct amd_sdw_manager.
- Set it to true at the start of amd_enable_sdw_interrupts(), before unmasking any hardware registers, so no IRQ can fire with the flag false.
- Clear it to false at the start of amd_disable_sdw_interrupts(), before touching any hardware registers, so that queued work items that start executing after the flag is cleared will return early.
- Guard execution of amd_sdw_irq_thread() with an early-return flag check.
- Restore interrupt_enabled inside the ACP6.3-specific wake-re-enable block in amd_suspend_runtime() POWER_OFF_MODE, so that wake events are processed after hardware wake delivery is re-armed.
- Use WRITE_ONCE() for all stores to interrupt_enabled and READ_ONCE() for the load in amd_sdw_irq_thread() to annotate the intended single-writer/single-reader cross-context access and prevent compiler caching under LKMM.
--- drivers/soundwire/amd_manager.c | 17 +++++++++++++++++ include/linux/soundwire/sdw_amd.h | 4 ++++ 2 files changed, 21 insertions(+)
drivers/soundwire/amd_manager.c +17 -0
@@ -119,6 +119,7 @@ static void amd_enable_sdw_interrupts(struct amd_sdw_manager *amd_manager) {u32 val; +WRITE_ONCE (amd_manager->interrupt_enabled, true);mutex_lock (amd_manager->acp_sdw_lock); val = sdw_manager_reg_mask_array[amd_manager->instance];amd_updatel (amd_manager->acp_mmio,ACP_EXTERNAL_INTR_CNTL (amd_manager->instance), val, val);
@@ -135,6 +136,18 @@ static void amd_disable_sdw_interrupts(struct amd_sdw_manager *amd_manager) {u32 irq_mask; +/* +* Clear the flag before updating hardware masks. Work items already +* queued but not yet started will see the flag false at entry and +* return early; work items already running will complete their current +* invocation. Callers that need to ensure no instance of +* amd_sdw_irq_thread() is executing on return must follow this call +* with cancel_work_sync(&amd_manager->amd_sdw_irq_thread). Once the +* mask registers are written, the ACP hardware will not assert any new +* SDW interrupt. +*/ +WRITE_ONCE (amd_manager->interrupt_enabled, false); +mutex_lock (amd_manager->acp_sdw_lock); irq_mask = sdw_manager_reg_mask_array[amd_manager->instance]; amd_updatel(amd_manager->acp_mmio, ACP_EXTERNAL_INTR_CNTL(amd_manager->instance),
@@ -1112,6 +1125,9 @@ static void amd_sdw_irq_thread(struct work_struct *work)u32 status_change_8to11;u32 status_change_0to7; +if (!READ_ONCE (amd_manager->interrupt_enabled)) +return ; + status_change_8to11 =readl (amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_8TO11 ); status_change_0to7 =readl (amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_0TO7 );if (!status_change_0to7 && !status_change_8to11)
@@ -1482,6 +1498,7 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)return ret; }else if ((amd_manager->acp_rev ==ACP63_PCI_REV_ID ) && amd_manager->wake_en_mask) { +WRITE_ONCE (amd_manager->interrupt_enabled, true);mutex_lock (amd_manager->acp_sdw_lock); val = sdw_manager_reg_mask_array[amd_manager->instance]; amd_updatel(amd_manager->acp_mmio,
include/linux/soundwire/sdw_amd.h +4 -0
@@ -85,6 +85,9 @@ struct sdw_amd_dai_runtime {* @ping_slave_stat: cached slave status from the last ping * transaction that returned a response; * initialised to U32_MAX ("no valid reading yet") +* @interrupt_enabled: set when hardware interrupts are enabled; cleared +* before disabling to prevent queued work from executing +* interrupt events during teardown * @dai_runtime_array: dai runtime array */ struct amd_sdw_manager {
@@ -117,6 +120,7 @@ struct amd_sdw_manager {u32 ping_slave_stat;bool clk_stopped;bool pad_fully_torn_down; +bool interrupt_enabled;struct sdw_amd_dai_runtime **dai_runtime_array; };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v6 15/23] soundwire: amd: use interrupt_enabled flag to guard IRQ work scheduling
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] soundwire: amd: race with in-flight IRQ queuing amd_sdw_irq_thread - [Medium] soundwire: amd: race…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] soundwire: amd: race with in-flight IRQ queuing amd_sdw_irq_thread
- [Medium] soundwire: amd: race re-enabling IRQ masks in amd_disable_sdw_interrupts()
--
commit 14261a7c7d9c5975a602a89ef71b261091c3414b
Author: Vijendar Mukunda <[email protected]>
soundwire: amd: use interrupt_enabled flag to guard IRQ work scheduling
This commit adds an interrupt_enabled flag to struct amd_sdw_manager to prevent queued amd_sdw_irq_thread work items from running after interrupts are disabled.
Quoted 4 lines
drivers/soundwire/amd_manager.c +0
-0
[ ... ]
Quoted 9 lines
drivers/soundwire/amd_manager.c +5
-0@@ -135,6 +136,18 @@ static void amd_disable_sdw_interrupts(struct amd_sdw_manager *amd_manager) {u32 irq_mask; +/* +* Clear the flag before updating hardware masks. Work items already +* queued but not yet started will see the flag false at entry and +* return early; work items already running will complete their current +* invocation. Callers that need to ensure no instance of
drivers/soundwire/amd_manager.c static void amd_disable_sdw_interrupts(struct amd_sdw_manager *amd_manager) · line 153
Quoted 10 lines
drivers/soundwire/amd_manager.c +7
-0+* amd_sdw_irq_thread() is executing on return must follow this call +* with cancel_work_sync(&amd_manager->amd_sdw_irq_thread). Once the +* mask registers are written, the ACP hardware will not assert any new +* SDW interrupt. +*/ +WRITE_ONCE (amd_manager->interrupt_enabled, false); +mutex_lock (amd_manager->acp_sdw_lock); irq_mask = sdw_manager_reg_mask_array[amd_manager->instance]; amd_updatel(amd_manager->acp_mmio, ACP_EXTERNAL_INTR_CNTL(amd_manager->instance),
[Severity: Medium]
Can an in-flight parent PCI IRQ handler still queue amd_sdw_irq_thread after amd_disable_sdw_interrupts() and cancel_work_sync() have returned?
The parent PCI hard IRQ handlers (such as acp63_irq_handler() in sound/soc/amd/ps/pci-ps.c and acp_irq_handler() in sound/soc/sof/amd/acp.c) call schedule_work(&amd_manager->amd_sdw_irq_thread) without synchronizing with amd_disable_sdw_interrupts():
sound/soc/amd/ps/pci-ps.c:acp63_irq_handler() {
...
if (adata->sdw) {
amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev);
if (amd_manager)
schedule_work(&amd_manager->amd_sdw_irq_thread);
}
...
}If the interrupt fires just before ACP_EXTERNAL_INTR_CNTL is masked, the hard IRQ handler on another CPU can schedule the work after cancel_work_sync() completes:
CPU0 CPU1 (<hardirq>)amd_sdw_manager_remove() acp63_irq_handler()
amd_disable_sdw_interrupts()
interrupt_enabled = false
mask ACP_EXTERNAL_INTR_CNTL
cancel_work_sync(
&amd_manager->amd_sdw_irq_thread)
schedule_work(
&amd_manager->amd_sdw_irq_thread)
devres frees amd_manager
amd_sdw_irq_thread()
READ_ONCE(
amd_manager->interrupt_enabled)
<-- use-after-freeDuring amd_suspend() (in AMD_SDW_CLK_STOP_MODE) and amd_suspend_runtime() (in AMD_SDW_CLK_STOP_MODE or ACP6.3 AMD_SDW_POWER_OFF_MODE), interrupt_enabled is set back to true before suspend finishes, so a work item queued by an in-flight hard IRQ handler after cancel_work_sync() sees interrupt_enabled == true and accesses SoundWire MMIO registers while the manager is clock-stopped or powered down.
Using disable_work_sync(&amd_manager->amd_sdw_irq_thread) when disabling interrupts and enable_work() when re-enabling them (or synchronizing with the parent IRQ) would prevent late scheduling.
[ ... ]
drivers/soundwire/amd_manager.c static int __maybe_unused amd_suspend_runtime(struct device *dev) · line 1503
Quoted 8 lines
drivers/soundwire/amd_manager.c +1
-0@@ -1481,6 +1497,7 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)return ret; }else if ((amd_manager->acp_rev ==ACP63_PCI_REV_ID ) && amd_manager->wake_en_mask) { +WRITE_ONCE (amd_manager->interrupt_enabled, true);mutex_lock (amd_manager->acp_sdw_lock); val = sdw_manager_reg_mask_array[amd_manager->instance]; amd_updatel(amd_manager->acp_mmio,
[Severity: Medium]
Can an in-flight amd_sdw_update_slave_status_work() overwrite the zeroed interrupt masks during amd_disable_sdw_interrupts() and leave non-wake interrupts unmasked in runtime suspend?
amd_disable_sdw_interrupts() zeroes ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7 and ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11 before callers drain amd_sdw_work with cancel_work_sync(&amd_manager->amd_sdw_work). Meanwhile, amd_sdw_update_slave_status_work() unconditionally writes AMD_SDW_IRQ_MASK_0TO7 and AMD_SDW_IRQ_MASK_8TO11 back to those registers without checking interrupt_enabled:
drivers/soundwire/amd_manager.c:amd_sdw_update_slave_status_work() {
...
if (amd_manager->status[0] == SDW_SLAVE_ATTACHED) {
if (retry_count++ < SDW_MAX_DEVICES) {
writel(AMD_SDW_IRQ_MASK_0TO7, amd_manager->mmio +
ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7);
writel(AMD_SDW_IRQ_MASK_8TO11, amd_manager->mmio +
ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11);
...
}In amd_suspend_runtime() under AMD_SDW_POWER_OFF_MODE, that race leaves state-change interrupts enabled while the manager is powered off:
CPU0 CPU1 (kworker)amd_suspend_runtime() amd_sdw_update_slave_status_work()
...
amd_disable_sdw_interrupts()
interrupt_enabled = false
writel(0, ..._MASK_0TO7)
writel(0, ..._MASK_8TO11)
writel(AMD_SDW_IRQ_MASK_0TO7,
..._MASK_0TO7)
writel(AMD_SDW_IRQ_MASK_8TO11,
..._MASK_8TO11)
cancel_work_sync(&amd_sdw_work)
amd_sdw_wake_enable(..., true)
/* RMW preserves MASK_8TO11 */ interrupt_enabled = true
unmask ACP_EXTERNAL_INTR_CNTL <-- non-wake IRQs remain unmasked
Draining amd_sdw_irq_thread and amd_sdw_work (or checking interrupt_enabled in amd_sdw_update_slave_status_work()) before clearing the mask registers in amd_disable_sdw_interrupts() would avoid re-arming those masks.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
Re: [PATCH v6 15/23] soundwire: amd: use interrupt_enabled flag to guard IRQ work scheduling
Quoted 8 lines · On 17/11/26 13:07, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] soundwire: amd: race with in-flight IRQ queuingamd_sdw_irq_thread
- [Medium] soundwire: amd: race re-enabling IRQ masks inamd_disable_sdw_interrupts()
--
Quoted 8 lines
commit
14261a7c7d9c5975a602a89ef71b261091c3414b
Author: Vijendar Mukunda <[email protected]>soundwire: amd: use
interrupt_enabledflag to guard IRQ work schedulingThis commit adds an
interrupt_enabledflag to structamd_sdw_managerto prevent queuedamd_sdw_irq_threadwork items from running after interrupts are disabled.
No changes required; both concerns are addressed within this series. Details inline.
Quoted 53 lines
Quoted 4 lines
drivers/soundwire/amd_manager.c +0
-0[ ... ]
Quoted 9 lines
drivers/soundwire/amd_manager.c +5
-0@@ -135,6 +136,18 @@ static void amd_disable_sdw_interrupts(struct amd_sdw_manager *amd_manager) {u32 irq_mask; +/* +* Clear the flag before updating hardware masks. Work items already +* queued but not yet started will see the flag false at entry and +* return early; work items already running will complete their current +* invocation. Callers that need to ensure no instance of drivers/soundwire/amd_manager.c static void amd_disable_sdw_interrupts(struct amd_sdw_manager *amd_manager) · line 153
Quoted 10 lines
drivers/soundwire/amd_manager.c +7
-0+* amd_sdw_irq_thread() is executing on return must follow this call +* with cancel_work_sync(&amd_manager->amd_sdw_irq_thread). Once the +* mask registers are written, the ACP hardware will not assert any new +* SDW interrupt. +*/ +WRITE_ONCE (amd_manager->interrupt_enabled, false); +mutex_lock (amd_manager->acp_sdw_lock); irq_mask = sdw_manager_reg_mask_array[amd_manager->instance]; amd_updatel(amd_manager->acp_mmio, ACP_EXTERNAL_INTR_CNTL(amd_manager->instance),[Severity: Medium]
Can an in-flight parent PCI IRQ handler still queueamd_sdw_irq_threadafteramd_disable_sdw_interrupts()andcancel_work_sync()have returned?The parent PCI hard IRQ handlers (such as
acp63_irq_handler()insound/soc/amd/ps/pci-ps.candacp_irq_handler()insound/soc/sof/amd/acp.c) callschedule_work(&amd_manager->amd_sdw_irq_thread)without synchronizing withamd_disable_sdw_interrupts():sound/soc/amd/ps/pci-ps.c:acp63_irq_handler() { ... if (adata->sdw) { amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev); if (amd_manager) schedule_work(&amd_manager->amd_sdw_irq_thread); } ... }If the interrupt fires just before
ACP_EXTERNAL_INTR_CNTLis masked, the hard IRQ handler on another CPU can schedule the work aftercancel_work_sync()completes:CPU0 CPU1 (<hardirq>)
amd_sdw_manager_remove()acp63_irq_handler()
amd_disable_sdw_interrupts()
interrupt_enabled= false
maskACP_EXTERNAL_INTR_CNTL
cancel_work_sync(
Quoted 8 lines
&amd_manager->amd_sdw_irq_thread)
schedule_work(
&amd_manager->amd_sdw_irq_thread)
devres frees amd_manager
amd_sdw_irq_thread()
READ_ONCE(
amd_manager->interrupt_enabled)
<-- use-after-freeamd_disable_sdw_interrupts() clears ACP_EXTERNAL_INTR_CNTL before returning, so after it completes no new SoundWire IRQ can be delivered to the parent handler. The race window is therefore limited to IRQs that fired before the hardware mask was written, whose handler is still executing on CPU1 at the time cancel_work_sync() completes on CPU0.
For this to trigger, the parent PCI hard IRQ handler would need to remain live from before the ACP_EXTERNAL_INTR_CNTL write until after both cancel_work_sync() calls complete on CPU0. Hard IRQ handlers run to completion without sleeping; that window is not realistically long enough for both cancel_work_sync() calls and the subsequent devres cleanup to complete on CPU0 while CPU1 is still inside the hard IRQ handler.
Should such a re-scheduling occur during the narrow window, the interrupt_enabled guard added by this patch ensures amd_sdw_irq_thread returns immediately at READ_ONCE(interrupt_enabled) without accessing any hardware registers, preventing the hardware-access UAF.
Quoted 6 lines
During
amd_suspend()(inAMD_SDW_CLK_STOP_MODE) andamd_suspend_runtime()(inAMD_SDW_CLK_STOP_MODEor ACP6.3AMD_SDW_POWER_OFF_MODE),interrupt_enabledis set back to true before suspend finishes, so a work item queued by an in-flight hard IRQ handler aftercancel_work_sync()seesinterrupt_enabled== true and accesses SoundWire MMIO registers while the manager is clock-stopped or powered down.
Patch 20 later in this series ("soundwire: amd: fix interrupt gate and work drain ordering in PM ops") addresses this. It moves amd_disable_sdw_interrupts() to the head of every suspend branch, then drains amd_sdw_irq_thread and amd_sdw_work before proceeding to clock stop. interrupt_enabled is set back to true only after clock stop completes in CLK_STOP_MODE, by which point the drains have completed and no work item is running. In POWER_OFF_MODE interrupt_enabled is not restored, as wake delivery is handled through a separate path.
Quoted 55 lines
Using
disable_work_sync(&amd_manager->amd_sdw_irq_thread)when disabling interrupts andenable_work()when re-enabling them (or synchronizing with the parent IRQ) would prevent late scheduling.[ ... ]
drivers/soundwire/amd_manager.c static int __maybe_unused amd_suspend_runtime(struct device *dev) · line 1503
Quoted 8 lines
drivers/soundwire/amd_manager.c +1
-0@@ -1481,6 +1497,7 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)return ret; }else if ((amd_manager->acp_rev ==ACP63_PCI_REV_ID ) && amd_manager->wake_en_mask) { +WRITE_ONCE (amd_manager->interrupt_enabled, true);mutex_lock (amd_manager->acp_sdw_lock); val = sdw_manager_reg_mask_array[amd_manager->instance]; amd_updatel(amd_manager->acp_mmio,[Severity: Medium]
Can an in-flightamd_sdw_update_slave_status_work()overwrite the zeroed interrupt masks duringamd_disable_sdw_interrupts()and leave non-wake interrupts unmasked in runtime suspend?
amd_disable_sdw_interrupts()zeroesACP_SW_STATE_CHANGE_STATUS_MASK_0TO7andACP_SW_STATE_CHANGE_STATUS_MASK_8TO11before callers drainamd_sdw_workwithcancel_work_sync(&amd_manager->amd_sdw_work). Meanwhile,amd_sdw_update_slave_status_work()unconditionally writesAMD_SDW_IRQ_MASK_0TO7andAMD_SDW_IRQ_MASK_8TO11back to those registers without checkinginterrupt_enabled:drivers/soundwire/amd_manager.c:amd_sdw_update_slave_status_work() { ... if (amd_manager->status[0] == SDW_SLAVE_ATTACHED) { if (retry_count++ < SDW_MAX_DEVICES) { writel(AMD_SDW_IRQ_MASK_0TO7, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7); writel(AMD_SDW_IRQ_MASK_8TO11, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11); ... }In
amd_suspend_runtime()underAMD_SDW_POWER_OFF_MODE, that race leaves state-change interrupts enabled while the manager is powered off:CPU0 CPU1 (kworker)
amd_suspend_runtime()amd_sdw_update_slave_status_work()
...
amd_disable_sdw_interrupts()interrupt_enabled = false writel(0, ..._MASK_0TO7) writel(0, ..._MASK_8TO11) writel(AMD_SDW_IRQ_MASK_0TO7, ..._MASK_0TO7) writel(AMD_SDW_IRQ_MASK_8TO11, ..._MASK_8TO11) cancel_work_sync(&amd_sdw_work) amd_sdw_wake_enable(..., true) /* RMW preserves MASK_8TO11 */
Quoted 2 lines
interrupt_enabled= true
unmaskACP_EXTERNAL_INTR_CNTL<-- non-wake IRQs remain unmasked
Patch 20 fixes the suspend ordering so that amd_disable_sdw_interrupts() is called first, followed by cancel_work_sync(&amd_sdw_irq_thread) and then cancel_work_sync(&amd_sdw_work), before clock stop or power off.
After amd_disable_sdw_interrupts() sets interrupt_enabled = false, amd_sdw_irq_thread() will not schedule any new amd_sdw_work items (patch 15 guard). cancel_work_sync(&amd_sdw_irq_thread) ensures no instance of amd_sdw_irq_thread is running. cancel_work_sync(&amd_sdw_work) then drains any amd_sdw_update_slave_status_work() instance that was already queued.
If amd_sdw_update_slave_status_work() was running concurrently during amd_disable_sdw_interrupts() and re-arms STATUS_MASK_0TO7/8TO11, the outer ACP_EXTERNAL_INTR_CNTL gate is already cleared by amd_disable_sdw_interrupts(), so no interrupt can be delivered to the CPU regardless of the STATUS_MASK values. cancel_work_sync(&amd_sdw_work) ensures no instance of that work is running before suspend proceeds.
Quoted 4 lines
Draining
amd_sdw_irq_threadandamd_sdw_work(or checkinginterrupt_enabledinamd_sdw_update_slave_status_work()) before clearing the mask registers inamd_disable_sdw_interrupts()would avoid re-arming those masks.
Patch 20 addresses this by draining both work items in every suspend path after amd_disable_sdw_interrupts(). The ACP_EXTERNAL_INTR_CNTL gate closure in amd_disable_sdw_interrupts() prevents any new interrupt delivery irrespective of the per-manager STATUS_MASK register values.
PATCH v6 16/23 soundwire: amd: delay *sdw_ctx publication until after startup succeeds
In reply to Vijendar Mukundasdw_amd_probe() published *sdw_ctx immediately after sdw_amd_probe_controller() returned, before sdw_amd_startup() ran. If sdw_amd_startup() failed, the error was returned directly, leaving *sdw_ctx pointing to an allocated context whose platform devices were already registered. The caller has no way to distinguish this from a genuine probe success, so the context and devices leak.
Fix this by using a local variable for the context, running sdw_amd_startup() against it, and only writing *sdw_ctx after startup succeeds. On failure sdw_amd_exit() is called on the local pointer and the function returns without touching *sdw_ctx, so callers never observe a partially-initialised or freed context.
--- drivers/soundwire/amd_init.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/soundwire/amd_init.c +12 -3
@@ -182,11 +182,20 @@ static int sdw_amd_startup(struct sdw_amd_ctx *ctx)int sdw_amd_probe (struct sdw_amd_res *res,struct sdw_amd_ctx **sdw_ctx) { - *sdw_ctx =sdw_amd_probe_controller (res); -if (!*sdw_ctx) +struct sdw_amd_ctx *ctx; +int ret; + + ctx =sdw_amd_probe_controller (res); +if (!ctx)return -ENODEV ; -return sdw_amd_startup (*sdw_ctx); + ret =sdw_amd_startup (ctx); +if (ret) { +sdw_amd_exit (ctx); +return ret; + } + *sdw_ctx = ctx; +return 0 ; }EXPORT_SYMBOL_NS (sdw_amd_probe,"SOUNDWIRE_AMD_INIT" );
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v6 16/23] soundwire: amd: delay *sdw_ctx publication until after startup succeeds
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] soundwire: amd: lost IRQs in sdw_amd_startup() while *sdw_ctx is NULL --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] soundwire: amd: lost IRQs in sdw_amd_startup() while *sdw_ctx is NULL
--
commit 63d0953ca7aecb37f123b556809d3ebfd5afacf0
Author: Vijendar Mukunda <[email protected]>
soundwire: amd: delay *sdw_ctx publication until after startup succeeds
This commit delays assigning *sdw_ctx in sdw_amd_probe() until sdw_amd_startup() succeeds, and calls sdw_amd_exit() on failure.
Quoted 17 lines
drivers/soundwire/amd_init.c +5
-2@@ -182,11 +182,20 @@ static int sdw_amd_startup(struct sdw_amd_ctx *ctx)int sdw_amd_probe (struct sdw_amd_res *res,struct sdw_amd_ctx **sdw_ctx) { - *sdw_ctx =sdw_amd_probe_controller (res); -if (!*sdw_ctx) +struct sdw_amd_ctx *ctx; +int ret; + + ctx =sdw_amd_probe_controller (res); +if (!ctx)return -ENODEV ;
drivers/soundwire/amd_init.c static int sdw_amd_startup(struct sdw_amd_ctx *ctx) · line 200
Quoted 10 lines
drivers/soundwire/amd_init.c +7
-1-return sdw_amd_startup (*sdw_ctx); + ret =sdw_amd_startup (ctx); +if (ret) { +sdw_amd_exit (ctx); +return ret; + } + *sdw_ctx = ctx; +return 0 ; }EXPORT_SYMBOL_NS (sdw_amd_probe,"SOUNDWIRE_AMD_INIT" );
[Severity: Medium]
Can delaying the assignment to *sdw_ctx until after sdw_amd_startup() drop initial peripheral attachment interrupts?
All callers of sdw_amd_probe() register the top-level ACP PCI interrupt handler before calling sdw_amd_probe(&sdw_res, &adata->sdw), and sdw_amd_startup() -> amd_sdw_manager_start() unmasks the manager interrupts and starts the bus before sleeping in readl_poll_timeout():
CPU0 CPU1 (<hardirq>)sdw_amd_probe()
sdw_amd_startup(ctx)
amd_sdw_manager_start()
amd_enable_sdw_interrupts()
amd_enable_sdw_manager()
readl_poll_timeout(...)
acp63_irq_handler()
writel(ACP_SDW0_STAT, ...);
if (adata->sdw) <-- NULL, IRQ dropped *sdw_ctx = ctx;
In acp63_irq_handler() and acp_irq_handler():
sound/soc/amd/ps/pci-ps.c:acp63_irq_handler() {
if (ext_intr_stat & ACP_SDW0_STAT) {
writel(ACP_SDW0_STAT, adata->acp63_base + ACP_EXTERNAL_INTR_STAT);
if (adata->sdw) {
amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev);
if (amd_manager)
schedule_work(&amd_manager->amd_sdw_irq_thread);
}
irq_flag = 1;
}
}Because ACP_SDW0_STAT is cleared in ACP_EXTERNAL_INTR_STAT without scheduling amd_sdw_irq_thread, ACP_SW_STATE_CHANGE_STATUS_0TO7 is never processed and cleared, losing the peripheral attachment interrupt so peripherals fail to enumerate. On ACP7x SOF, acp7x_irq_handler() guards sof_acp7x_handle_sdw_manager_irq() altogether with if (adata->sdw), leaving the level-triggered shared PCI interrupt unacknowledged and returning IRQ_NONE while sdw_amd_startup() sleeps.
Would it be better to publish *sdw_ctx before sdw_amd_startup(), and reset *sdw_ctx = NULL on failure before calling sdw_amd_exit(ctx)?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
Re: [PATCH v6 16/23] soundwire: amd: delay *sdw_ctx publication until after startup succeeds
Quoted 6 lines · On 17/11/26 13:01, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] soundwire: amd: lost IRQs insdw_amd_startup()while*sdw_ctxis NULL
--
Quoted 7 lines
commit
63d0953ca7aecb37f123b556809d3ebfd5afacf0
Author: Vijendar Mukunda <[email protected]>soundwire: amd: delay
*sdw_ctxpublication until after startup succeedsThis commit delays assigning
*sdw_ctxinsdw_amd_probe()untilsdw_amd_startup()succeeds, and callssdw_amd_exit()on failure.
Will fix in v7; details inline.
Quoted 17 lines
Quoted 17 lines
drivers/soundwire/amd_init.c +5
-2@@ -182,11 +182,20 @@ static int sdw_amd_startup(struct sdw_amd_ctx *ctx)int sdw_amd_probe (struct sdw_amd_res *res,struct sdw_amd_ctx **sdw_ctx) { - *sdw_ctx =sdw_amd_probe_controller (res); -if (!*sdw_ctx) +struct sdw_amd_ctx *ctx; +int ret; + + ctx =sdw_amd_probe_controller (res); +if (!ctx)return -ENODEV ;
Quoted 13 lines
drivers/soundwire/amd_init.c static int sdw_amd_startup(struct sdw_amd_ctx *ctx) · line 200
Quoted 10 lines
drivers/soundwire/amd_init.c +7
-1-return sdw_amd_startup (*sdw_ctx); + ret =sdw_amd_startup (ctx); +if (ret) { +sdw_amd_exit (ctx); +return ret; + } + *sdw_ctx = ctx; +return 0 ; }EXPORT_SYMBOL_NS (sdw_amd_probe,"SOUNDWIRE_AMD_INIT" );[Severity: Medium]
Can delaying the assignment to*sdw_ctxuntil aftersdw_amd_startup()drop initial peripheral attachment interrupts?
Yes, the scenario is correct.
Quoted 31 lines
All callers of
sdw_amd_probe()register the top-level ACP PCI interrupt handler before callingsdw_amd_probe(&sdw_res, &adata->sdw), andsdw_amd_startup()->amd_sdw_manager_start()unmasks the manager interrupts and starts the bus before sleeping inreadl_poll_timeout():CPU0 CPU1 (<hardirq>)
sdw_amd_probe()
sdw_amd_startup(ctx)amd_sdw_manager_start() amd_enable_sdw_interrupts() amd_enable_sdw_manager() readl_poll_timeout(...) acp63_irq_handler() writel(ACP_SDW0_STAT, ...); if (adata->sdw) <-- NULL, IRQ dropped
*sdw_ctx= ctx;In
acp63_irq_handler()andacp_irq_handler():sound/soc/amd/ps/pci-ps.c:acp63_irq_handler() { if (ext_intr_stat & ACP_SDW0_STAT) { writel(ACP_SDW0_STAT, adata->acp63_base + ACP_EXTERNAL_INTR_STAT); if (adata->sdw) { amd_manager = dev_get_drvdata(&adata->sdw->pdev[0]->dev); if (amd_manager) schedule_work(&amd_manager->amd_sdw_irq_thread); } irq_flag = 1; } }
Quoted 4 lines
Because
ACP_SDW0_STATis cleared inACP_EXTERNAL_INTR_STATwithout schedulingamd_sdw_irq_thread,ACP_SW_STATE_CHANGE_STATUS_0TO7is never processed and cleared, losing the peripheral attachment interrupt so peripherals fail to enumerate.
Agreed. ACP_SW_STATE_CHANGE_STATUS_0TO7 and 8TO11 are pure status registers; pending bits there do not re-assert ACP_SDW0_STAT or generate a new PCI interrupt. The attachment event is permanently lost.
Quoted 4 lines
On ACP7x SOF,
acp7x_irq_handler()guardssof_acp7x_handle_sdw_manager_irq()altogether with if (adata->sdw), leaving the level-triggered shared PCI interrupt unacknowledged and returningIRQ_NONEwhilesdw_amd_startup()sleeps.
Agreed. Returning IRQ_NONE without clearing ACP_SDW0_STAT leaves the level-triggered PCI interrupt unacknowledged, causing an interrupt storm during the startup window.
Quoted 3 lines
Would it be better to publish
*sdw_ctxbeforesdw_amd_startup(), and reset*sdw_ctx= NULL on failure before callingsdw_amd_exit(ctx)?
Yes. I will update sdw_amd_probe() in v7 as follows:
*sdw_ctx = ctx;
ret = sdw_amd_startup(ctx);
if (ret) {
*sdw_ctx = NULL;
sdw_amd_exit(ctx);
return ret;
}
return 0;
This keeps adata->sdw valid throughout sdw_amd_startup(), allowing the ACP6.3 and ACP7x IRQ handlers to process and acknowledge interrupts during the startup window.
On failure, *sdw_ctx is cleared before sdw_amd_exit(), ensuring that callers cannot access a context that is being released.
A partially initialized context should not be exposed to an interrupt during startup, since the ACP_EXTERNAL_INTR_CNTL masks remain cleared until amd_enable_sdw_interrupts() is called. Therefore, ACP_SDW0_STAT cannot be asserted before the context is ready to handle interrupts.
Quoted 1 line
PATCH v6 17/23 soundwire: amd: propagate amd_init_sdw_manager() error on resume
In reply to Vijendar MukundaIn amd_resume_runtime() POWER_OFF_MODE, amd_init_sdw_manager() was called without capturing its return value. The function performs hardware bus resets using readl_poll_timeout() and can return -ETIMEDOUT if the hardware does not respond. When that happens, execution fell through to amd_enable_sdw_interrupts() and amd_enable_sdw_manager() on hardware that may still be in a broken reset state.
Fix by capturing the return value and returning early on failure.
--- drivers/soundwire/amd_manager.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/soundwire/amd_manager.c +3 -1
@@ -1591,7 +1591,9 @@ static int __maybe_unused amd_resume_runtime(struct device *dev) ret =amd_sdw_clk_init_ctrl (amd_manager);if (ret)return ret; -amd_init_sdw_manager (amd_manager); + ret =amd_init_sdw_manager (amd_manager); +if (ret) +return ret;amd_enable_sdw_interrupts (amd_manager); ret =amd_enable_sdw_manager (amd_manager);if (ret)
Signature · 1 line
2.53.0
PATCH v6 18/23 soundwire: amd: drop amd_deinit_sdw_manager() in POWER_OFF suspend
In reply to Vijendar Mukundaamd_deinit_sdw_manager() was a small helper that bundled amd_disable_sdw_interrupts() and amd_disable_sdw_manager() together. Expand the two POWER_OFF_MODE call sites in amd_suspend() and amd_suspend_runtime() to call those two functions directly, then remove the helper. No functional change.
--- drivers/soundwire/amd_manager.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/soundwire/amd_manager.c +4 -8
@@ -159,12 +159,6 @@ static void amd_disable_sdw_interrupts(struct amd_sdw_manager *amd_manager)writel (0x00 , amd_manager->mmio +ACP_SW_ERROR_INTR_MASK ); } -static int amd_deinit_sdw_manager (struct amd_sdw_manager *amd_manager) -{ -amd_disable_sdw_interrupts (amd_manager); -return amd_disable_sdw_manager (amd_manager); -} -static void __amd_sdw_oe_update (struct amd_sdw_manager *amd_manager,u32 mask,bool enable) {
@@ -1445,7 +1439,8 @@ static int __maybe_unused amd_suspend(struct device *dev) ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; - ret =amd_deinit_sdw_manager (amd_manager); +amd_disable_sdw_interrupts (amd_manager); + ret =amd_disable_sdw_manager (amd_manager);if (ret)return ret;/* System suspend: tear down all pads */
@@ -1488,7 +1483,8 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev) ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; - ret =amd_deinit_sdw_manager (amd_manager); +amd_disable_sdw_interrupts (amd_manager); + ret =amd_disable_sdw_manager (amd_manager);if (ret)return ret;amd_sdw_wake_enable (amd_manager, true);
Signature · 1 line
2.53.0
PATCH v6 19/23 soundwire: amd: replace >= ACP70 with explicit switch/case in PM paths
In reply to Vijendar MukundaReplace open-ended acp_rev >= ACP70_PCI_REV_ID comparisons in amd_suspend(), amd_suspend_runtime(), and amd_resume_runtime() with explicit per-revision handling enumerating ACP63, ACP70, ACP71, and ACP72, so that every supported revision is handled explicitly.
The host wake enable step is guarded by acp_rev at six PM call sites. Factor that repeated block into amd_sdw_host_wake_enable_by_rev() to avoid duplicating the switch/case at every site. The remaining device state transitions keep an inline switch/case as one of them carries additional PME handling.
An unrecognised revision cannot reach these PM callbacks because amd_sdw_manager_probe() already validates acp_rev with the same switch and fails registration for anything unknown. The switch default therefore emits dev_err() and returns -EINVAL to make the unexpected case visible while keeping the error path consistent across all PM operations.
--- drivers/soundwire/amd_manager.c | 100 +++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 34 deletions(-)
drivers/soundwire/amd_manager.c +66 -34
@@ -1401,6 +1401,23 @@ static int __maybe_unused amd_pm_prepare(struct device *dev)return 0 ; } +static int __maybe_unused amd_sdw_host_wake_enable_by_rev (struct amd_sdw_manager *amd_manager, +bool enable) +{ +switch (amd_manager->acp_rev) { +case ACP63_PCI_REV_ID : +break ; +case ACP70_PCI_REV_ID : +case ACP71_PCI_REV_ID : +case ACP72_PCI_REV_ID : +return amd_sdw_host_wake_enable (amd_manager, enable); +default : +dev_err (amd_manager->dev,"unexpected acp_rev 0x%x\n" , amd_manager->acp_rev); +return -EINVAL ; + } +return 0 ; +} +static int __maybe_unused amd_suspend (struct device *dev) {struct amd_sdw_manager *amd_manager =dev_get_drvdata (dev);
@@ -1416,22 +1433,18 @@ static int __maybe_unused amd_suspend(struct device *dev)if (amd_manager->power_mode_mask &AMD_SDW_CLK_STOP_MODE ) {cancel_work_sync (&amd_manager->amd_sdw_work);amd_sdw_wake_enable (amd_manager, false); -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, false); -if (ret) -return ret; - } + ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false); +if (ret) +return ret; ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) {cancel_work_sync (&amd_manager->amd_sdw_work);amd_sdw_wake_enable (amd_manager, false); -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, false); -if (ret) -return ret; - } + ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false); +if (ret) +return ret;/* * As per hardware programming sequence on AMD platforms, * clock stop should be invoked first before powering-off
@@ -1449,10 +1462,19 @@ static int __maybe_unused amd_suspend(struct device *dev) amd_manager->pad_fully_torn_down = true; } } -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { +switch (amd_manager->acp_rev) { +case ACP63_PCI_REV_ID : +break ; +case ACP70_PCI_REV_ID : +case ACP71_PCI_REV_ID : +case ACP72_PCI_REV_ID : ret =amd_sdw_set_device_state (amd_manager,AMD_SDW_DEVICE_STATE_D3 );if (ret)return ret; +break ; +default : +dev_err (amd_manager->dev,"unexpected acp_rev 0x%x\n" , amd_manager->acp_rev); +return -EINVAL ; }return 0 ; }
@@ -1471,11 +1493,9 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev) }if (amd_manager->power_mode_mask &AMD_SDW_CLK_STOP_MODE ) {amd_sdw_wake_enable (amd_manager, true); -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, true); -if (ret) -return ret; - } + ret =amd_sdw_host_wake_enable_by_rev (amd_manager, true); +if (ret) +return ret; ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret;
@@ -1488,12 +1508,10 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)if (ret)return ret;amd_sdw_wake_enable (amd_manager, true); -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, true); -if (ret) -return ret; - }else if ((amd_manager->acp_rev ==ACP63_PCI_REV_ID ) && - amd_manager->wake_en_mask) { + ret =amd_sdw_host_wake_enable_by_rev (amd_manager, true); +if (ret) +return ret; +if (amd_manager->acp_rev ==ACP63_PCI_REV_ID && amd_manager->wake_en_mask) {WRITE_ONCE (amd_manager->interrupt_enabled, true);mutex_lock (amd_manager->acp_sdw_lock); val = sdw_manager_reg_mask_array[amd_manager->instance];
@@ -1509,7 +1527,12 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)*/ amd_sdw_oe_ctrl (amd_manager, false); } -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { +switch (amd_manager->acp_rev) { +case ACP63_PCI_REV_ID : +break ; +case ACP70_PCI_REV_ID : +case ACP71_PCI_REV_ID : +case ACP72_PCI_REV_ID : ret =amd_sdw_set_device_state (amd_manager,AMD_SDW_DEVICE_STATE_D3 );if (ret)return ret;
@@ -1521,6 +1544,10 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)dev_dbg (amd_manager->dev,"ACP_PME_EN:0x%x\n" , val); } } +break ; +default : +dev_err (amd_manager->dev,"unexpected acp_rev 0x%x\n" , amd_manager->acp_rev); +return -EINVAL ; }return 0 ; }
@@ -1542,11 +1569,9 @@ static int __maybe_unused amd_resume_runtime(struct device *dev) ret =amd_sdw_clock_stop_exit (amd_manager);if (ret)return ret; -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, false); -if (ret) -return ret; - } + ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false); +if (ret) +return ret; }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) {if (amd_manager->pad_fully_torn_down) {amd_sdw_pad_ctrl (amd_manager, true);
@@ -1566,11 +1591,9 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)mutex_lock (&amd_manager->bus.msg_lock); amd_manager->ping_slave_stat =U32_MAX ;mutex_unlock (&amd_manager->bus.msg_lock); -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, false); -if (ret) -return ret; - } + ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false); +if (ret) +return ret; val =readl (amd_manager->mmio +ACP_SW_CLK_RESUME_CTRL );if (val) { val |=AMD_SDW_CLK_RESUME_REQ ;
@@ -1596,10 +1619,19 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)return ret;amd_sdw_set_frameshape (amd_manager); } -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { +switch (amd_manager->acp_rev) { +case ACP63_PCI_REV_ID : +break ; +case ACP70_PCI_REV_ID : +case ACP71_PCI_REV_ID : +case ACP72_PCI_REV_ID : ret =amd_sdw_set_device_state (amd_manager,AMD_SDW_DEVICE_STATE_D0 );if (ret)return ret; +break ; +default : +dev_err (amd_manager->dev,"unexpected acp_rev 0x%x\n" , amd_manager->acp_rev); +return -EINVAL ; }return 0 ; }
Signature · 1 line
2.53.0
PATCH v6 20/23 soundwire: amd: fix interrupt gate and work drain ordering in PM ops
In reply to Vijendar MukundaFix ordering and sequencing bugs across the CLK_STOP_MODE and POWER_OFF_MODE suspend paths:
amd_suspend():
- CLK_STOP_MODE: cancel_work_sync(&amd_sdw_work) ran without first closing the ACP_EXTERNAL_INTR_CNTL delivery gate or draining amd_sdw_irq_thread. An ISR already in flight when the drain completed could re-queue work after cancel_work_sync() returned, racing amd_sdw_clock_stop(). amd_sdw_wake_enable(false) preceding the work drain was also redundant: amd_disable_sdw_interrupts() already masks all SDW interrupt delivery including wake. The amd_enable_sdw_interrupts() call after clock stop restores all state-change, error, and delivery masks; in CLK_STOP_MODE only the SDW clock is gated so no state-change interrupt can be asserted after clock stop. The wake bit is not part of the restored masks; wake interrupts are only asserted when the system transitions to D3. If amd_sdw_host_wake_enable_by_rev() returns -EINVAL the operation aborts; this indicates an unrecognized acp_rev, which is an unsupported configuration on this driver.
- POWER_OFF_MODE: same missing gate closure and irq_thread drain before the work drain; a redundant amd_disable_sdw_interrupts() call was placed after clock stop instead of before the drains; amd_sdw_wake_enable(false) at the top of this branch was redundant because amd_disable_sdw_interrupts() (now moved first) already zeroes ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11, which covers the wake bit.
amd_suspend_runtime():
- CLK_STOP_MODE: neither amd_sdw_irq_thread nor amd_sdw_work was drained at all before amd_sdw_clock_stop(); the interrupt delivery gate was not closed before the drains and not reopened after clock stop; amd_sdw_wake_enable(true) was placed before the drains instead of after clock stop. If amd_sdw_host_wake_enable_by_rev() returns -EINVAL the operation aborts; this indicates an unrecognized acp_rev, which is an unsupported configuration on this driver.
- POWER_OFF_MODE: missing gate closure, irq_thread drain, and work drain before clock stop; amd_disable_sdw_interrupts() was placed after clock stop instead of before.
--- drivers/soundwire/amd_manager.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/soundwire/amd_manager.c +13 -5
@@ -1431,17 +1431,20 @@ static int __maybe_unused amd_suspend(struct device *dev) }if (amd_manager->power_mode_mask &AMD_SDW_CLK_STOP_MODE ) { +amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread);cancel_work_sync (&amd_manager->amd_sdw_work); -amd_sdw_wake_enable (amd_manager, false); ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false);if (ret)return ret; ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; +amd_enable_sdw_interrupts (amd_manager); }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) { +amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread);cancel_work_sync (&amd_manager->amd_sdw_work); -amd_sdw_wake_enable (amd_manager, false); ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false);if (ret)return ret;
@@ -1452,7 +1455,6 @@ static int __maybe_unused amd_suspend(struct device *dev) ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; -amd_disable_sdw_interrupts (amd_manager); ret =amd_disable_sdw_manager (amd_manager);if (ret)return ret;
@@ -1492,18 +1494,24 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)return 0 ; }if (amd_manager->power_mode_mask &AMD_SDW_CLK_STOP_MODE ) { -amd_sdw_wake_enable (amd_manager, true); +amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread); +cancel_work_sync (&amd_manager->amd_sdw_work); ret =amd_sdw_host_wake_enable_by_rev (amd_manager, true);if (ret)return ret; ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; +amd_enable_sdw_interrupts (amd_manager); +amd_sdw_wake_enable (amd_manager, true); }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) { +amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread); +cancel_work_sync (&amd_manager->amd_sdw_work); ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; -amd_disable_sdw_interrupts (amd_manager); ret =amd_disable_sdw_manager (amd_manager);if (ret)return ret;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v6 20/23] soundwire: amd: fix interrupt gate and work drain ordering in PM ops
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] soundwire: amd: runtime PM deadlock in amd_suspend_runtime() work drain - [Medium] soundwire: amd…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] soundwire: amd: runtime PM deadlock in amd_suspend_runtime() work drain
- [Medium] soundwire: amd: stale status bits and early IRQ enable in amd_suspend()
--
commit 9fb00434cce0e9e4cd0523448b2e4bde7b333b08
Author: Vijendar Mukunda <[email protected]>
soundwire: amd: fix interrupt gate and work drain ordering in PM ops
This commit reorders interrupt masking, workqueue draining, and wake configuration across the CLK_STOP_MODE and POWER_OFF_MODE paths in amd_suspend() and amd_suspend_runtime().
Quoted 9 lines
drivers/soundwire/amd_manager.c +1
-0@@ -1430,17 +1430,20 @@ static int __maybe_unused amd_suspend(struct device *dev) }if (amd_manager->power_mode_mask &AMD_SDW_CLK_STOP_MODE ) { +amd_disable_sdw_interrupts (amd_manager);
drivers/soundwire/amd_manager.c static int __maybe_unused amd_suspend(struct device *dev) · line 1442
Quoted 10 lines
drivers/soundwire/amd_manager.c +2
-1+cancel_work_sync (&amd_manager->amd_sdw_irq_thread);cancel_work_sync (&amd_manager->amd_sdw_work); -amd_sdw_wake_enable (amd_manager, false); ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false);if (ret)return ret; ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; +amd_enable_sdw_interrupts (amd_manager);
[Severity: Medium]
Can calling amd_enable_sdw_interrupts() after amd_sdw_clock_stop() without clearing ACP_SW_STATE_CHANGE_STATUS_0TO7 and ACP_SW_STATE_CHANGE_STATUS_8TO11 cause amd_sdw_irq_thread() to process stale peripheral status bits while the SoundWire clock is stopped?
When a SoundWire interrupt fires just before amd_disable_sdw_interrupts(), the parent ACP hard IRQ handler clears ACP_EXTERNAL_INTR_STAT and schedules amd_sdw_irq_thread, but the status registers are only cleared at the end of amd_sdw_irq_thread():
drivers/soundwire/amd_manager.c:amd_sdw_irq_thread() {
if (!READ_ONCE(amd_manager->interrupt_enabled))
return;
status_change_8to11 = readl(amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_8TO11);
status_change_0to7 = readl(amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_0TO7);
...
}Because amd_disable_sdw_interrupts() sets interrupt_enabled to false and cancels amd_sdw_irq_thread without clearing those registers, any pending status bits (or bits latched during amd_sdw_clock_stop()) remain set in hardware. In amd_suspend_runtime(), when a subsequent wake event triggers amd_sdw_irq_thread(), amd_sdw_process_wake_event() only queues an asynchronous pm_request_resume() before falling through to read the stale status_change_8to11 and status_change_0to7 bits and schedule amd_sdw_work while the link is still down, resulting in MIPI command timeouts (-ETIMEDOUT).
In addition, the parent ACP IRQ handlers do not check interrupt_enabled before calling schedule_work(&amd_manager->amd_sdw_irq_thread), so an in-flight hard IRQ can queue amd_sdw_irq_thread after cancel_work_sync() returns and run once amd_enable_sdw_interrupts() sets interrupt_enabled back to true. Finally, amd_sdw_clock_stop() returns 0 on its error paths, so if clock stop fails, amd_enable_sdw_interrupts() re-enables state-change interrupts with the bus clock still running.
[ ... ]
Quoted 10 lines
drivers/soundwire/amd_manager.c +3
-1@@ -1491,18 +1493,24 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)return 0 ; }if (amd_manager->power_mode_mask &AMD_SDW_CLK_STOP_MODE ) { -amd_sdw_wake_enable (amd_manager, true); +amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread); +cancel_work_sync (&amd_manager->amd_sdw_work); ret =amd_sdw_host_wake_enable_by_rev (amd_manager, true);if (ret)
drivers/soundwire/amd_manager.c static int __maybe_unused amd_suspend_runtime(struct device *dev) · line 1510
Quoted 10 lines
drivers/soundwire/amd_manager.c +5
-0return ret; ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; +amd_enable_sdw_interrupts (amd_manager); +amd_sdw_wake_enable (amd_manager, true); }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) { +amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread); +cancel_work_sync (&amd_manager->amd_sdw_work);
[Severity: High]
Can cancel_work_sync(&amd_manager->amd_sdw_work) in amd_suspend_runtime() deadlock with amd_sdw_update_slave_status_work()?
kworker/0 kworker/1rpm_suspend(amd_manager->dev)
runtime_status = RPM_SUSPENDING
amd_suspend_runtime()
amd_sdw_update_slave_status_work()
sdw_handle_slave_status()
sdw_handle_slave_alerts()
pm_runtime_get_sync(&slave->dev)
rpm_resume(bus->dev, 0)
rpm_resume(amd_manager->dev, 0)
/* waits on RPM_SUSPENDING */
cancel_work_sync(&amd_sdw_work) <-- deadlockIn the SoundWire device hierarchy, slave->dev is a child of bus->dev, which is a child of amd_manager->dev, so both children are in RPM_SUSPENDED when amd_manager->dev enters rpm_suspend(). If a peripheral alert schedules amd_sdw_work just before amd_disable_sdw_interrupts() masks interrupts, sdw_handle_slave_alerts() calls pm_runtime_get_sync(&slave->dev), which synchronously resumes the parent chain up to amd_manager->dev and sleeps on amd_manager->dev->power.wait_queue waiting for amd_suspend_runtime() to finish, while amd_suspend_runtime() waits in cancel_work_sync() for amd_sdw_work to complete.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
Re: [PATCH v6 20/23] soundwire: amd: fix interrupt gate and work drain ordering in PM ops
Quoted 33 lines · On 17/11/26 13:18, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] soundwire: amd: runtime PM deadlock inamd_suspend_runtime()work drain
- [Medium] soundwire: amd: stale status bits and early IRQ enable inamd_suspend()
--commit
9fb00434cce0e9e4cd0523448b2e4bde7b333b08
Author: Vijendar Mukunda <[email protected]>soundwire: amd: fix interrupt gate and work drain ordering in PM ops
This commit reorders interrupt masking, workqueue draining, and wake configuration across the
CLK_STOP_MODEandPOWER_OFF_MODEpaths inamd_suspend()andamd_suspend_runtime().Quoted 16 lines
drivers/soundwire/amd_manager.c +2
-1@@ -1430,17 +1430,20 @@ static int __maybe_unused amd_suspend(struct device *dev) }if (amd_manager->power_mode_mask &AMD_SDW_CLK_STOP_MODE ) { +amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread);cancel_work_sync (&amd_manager->amd_sdw_work); -amd_sdw_wake_enable (amd_manager, false); ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false);if (ret)return ret; ret =amd_sdw_clock_stop (amd_manager);
Quoted 8 lines
drivers/soundwire/amd_manager.c static int __maybe_unused amd_suspend(struct device *dev) · line 1443
Quoted 3 lines
drivers/soundwire/amd_manager.c +1
-0if (ret)return ret; +amd_enable_sdw_interrupts (amd_manager);[Severity: Medium]
Can callingamd_enable_sdw_interrupts()afteramd_sdw_clock_stop()without clearingACP_SW_STATE_CHANGE_STATUS_0TO7andACP_SW_STATE_CHANGE_STATUS_8TO11causeamd_sdw_irq_thread()to process stale peripheral status bits while the SoundWire clock is stopped?
No changes required. Once the SoundWire clock is stopped in CLK_STOP_MODE the hardware cannot assert new state-change interrupts -- the bus is quiesced and no peripheral can generate traffic. amd_enable_sdw_interrupts() restores the interrupt masks so the manager is ready to process events immediately on resume without needing a re-enable sequence.
Wake interrupts are a separate path and are only asserted when the SoundWire manager transitions to D3 (POWER_OFF_MODE). In CLK_STOP_MODE suspend the wake bit is not part of the masks restored by amd_enable_sdw_interrupts(), so no spurious wake event can be delivered through this path either.
Quoted 50 lines
When a SoundWire interrupt fires just before
amd_disable_sdw_interrupts(), the parent ACP hard IRQ handler clearsACP_EXTERNAL_INTR_STATand schedulesamd_sdw_irq_thread, but the status registers are only cleared at the end ofamd_sdw_irq_thread():drivers/soundwire/amd_manager.c:amd_sdw_irq_thread() { if (!READ_ONCE(amd_manager->interrupt_enabled)) return; status_change_8to11 = readl(amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_8TO11); status_change_0to7 = readl(amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_0TO7); ... }Because
amd_disable_sdw_interrupts()setsinterrupt_enabledto false and cancelsamd_sdw_irq_threadwithout clearing those registers, any pending status bits (or bits latched duringamd_sdw_clock_stop()) remain set in hardware. Inamd_suspend_runtime(), when a subsequent wake event triggersamd_sdw_irq_thread(),amd_sdw_process_wake_event()only queues an asynchronouspm_request_resume()before falling through to read the stalestatus_change_8to11andstatus_change_0to7bits and scheduleamd_sdw_workwhile the link is still down, resulting in MIPI command timeouts (-ETIMEDOUT).In addition, the parent ACP IRQ handlers do not check
interrupt_enabledbefore callingschedule_work(&amd_manager->amd_sdw_irq_thread), so an in-flight hard IRQ can queueamd_sdw_irq_threadaftercancel_work_sync()returns and run onceamd_enable_sdw_interrupts()setsinterrupt_enabledback to true. Finally,amd_sdw_clock_stop()returns 0 on its error paths, so if clock stop fails,amd_enable_sdw_interrupts()re-enables state-change interrupts with the bus clock still running.[ ... ]
Quoted 15 lines
drivers/soundwire/amd_manager.c +4
-1@@ -1491,18 +1493,24 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)return 0 ; }if (amd_manager->power_mode_mask &AMD_SDW_CLK_STOP_MODE ) { -amd_sdw_wake_enable (amd_manager, true); +amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread); +cancel_work_sync (&amd_manager->amd_sdw_work); ret =amd_sdw_host_wake_enable_by_rev (amd_manager, true);if (ret)return ret; ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; +amd_enable_sdw_interrupts (amd_manager);
Quoted 8 lines
drivers/soundwire/amd_manager.c static int __maybe_unused amd_suspend_runtime(struct device *dev) · line 1511
Quoted 5 lines
drivers/soundwire/amd_manager.c +4
-0+amd_sdw_wake_enable (amd_manager, true); }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) { +amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread); +cancel_work_sync (&amd_manager->amd_sdw_work);[Severity: High]
Cancancel_work_sync(&amd_manager->amd_sdw_work)inamd_suspend_runtime()deadlock withamd_sdw_update_slave_status_work()?
No changes required. The sequence is:
WRITE_ONCE(interrupt_enabled, false) /* amd_disable_sdw_interrupts() */ cancel_work_sync(&amd_sdw_irq_thread) /* no new amd_sdw_work can be queued after this returns */ cancel_work_sync(&amd_sdw_work)
For the deadlock to occur, amd_sdw_work must have started executing before interrupt_enabled was cleared, traversed the full call chain into pm_runtime_get_sync(), and remained blocked there until cancel_work_sync() is called. That window is extremely narrow given the sequencing above, and AMD has not observed this scenario in testing.
Quoted 24 lines
kworker/0 kworker/1
rpm_suspend(amd_manager->dev)
runtime_status=RPM_SUSPENDING
amd_suspend_runtime()amd_sdw_update_slave_status_work() sdw_handle_slave_status() sdw_handle_slave_alerts() pm_runtime_get_sync(&slave->dev) rpm_resume(bus->dev, 0) rpm_resume(amd_manager->dev, 0) /* waits on RPM_SUSPENDING */ cancel_work_sync(&amd_sdw_work) <-- deadlockIn the SoundWire device hierarchy,
slave->devis a child ofbus->dev, which is a child ofamd_manager->dev, so both children are inRPM_SUSPENDEDwhenamd_manager->deventersrpm_suspend(). If a peripheral alert schedulesamd_sdw_workjust beforeamd_disable_sdw_interrupts()masks interrupts,sdw_handle_slave_alerts()callspm_runtime_get_sync(&slave->dev), which synchronously resumes the parent chain up toamd_manager->devand sleeps onamd_manager->dev->power.wait_queuewaiting foramd_suspend_runtime()to finish, whileamd_suspend_runtime()waits incancel_work_sync()foramd_sdw_workto complete.
PATCH v6 21/23 soundwire: amd: check for NULL manager drvdata in sdw_amd_startup()
In reply to Vijendar Mukundasdw_amd_startup() calls dev_get_drvdata() to retrieve the per-manager context and passes the result unconditionally to amd_sdw_manager_start(). If the platform device for a manager instance was registered successfully but its probe failed (e.g. due to ENOMEM or a deferred probe), dev_get_drvdata() returns NULL and amd_sdw_manager_start() immediately dereferences it, causing a kernel panic.
Add a NULL check after dev_get_drvdata() and return -ENODEV so that a failed manager probe surfaces as an error from sdw_amd_probe() rather than a kernel crash.
--- drivers/soundwire/amd_init.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/soundwire/amd_init.c +4 -0
@@ -172,6 +172,10 @@ static int sdw_amd_startup(struct sdw_amd_ctx *ctx)if (!(ctx->link_mask &BIT (i)))continue ; amd_manager =dev_get_drvdata (&ctx->pdev[i]->dev); +if (!amd_manager) { +dev_err (&ctx->pdev[i]->dev,"SoundWire manager not probed\n" ); +return -ENODEV ; + } ret =amd_sdw_manager_start (amd_manager);if (ret)return ret;
Signature · 1 line
2.53.0
PATCH v6 22/23 soundwire: amd: fix shared-register RMW race in amd_sdw_set_device_state()
In reply to Vijendar MukundaAMD_SDW_DEVICE_STATE packs the D0/D3 state for SDW0 (bits [1:0]) and SDW1 (bits [3:2]) in a single ACP-level register. amd_sdw_set_device_state() performed a read-modify-write sequence on this shared register without holding acp_sdw_lock, leaving it open to a lost-update race when SDW0 and SDW1 execute concurrent PM transitions.
Acquire acp_sdw_lock around the read-modify-write sequence. Unlock before returning -EINVAL from the default branch so the mutex is always released on every exit path.
--- drivers/soundwire/amd_manager.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/soundwire/amd_manager.c +3 -0
@@ -282,6 +282,7 @@ static int amd_sdw_set_device_state(struct amd_sdw_manager *amd_manager, u32 tar {u32 sdw_dev_state; +mutex_lock (amd_manager->acp_sdw_lock); sdw_dev_state =readl (amd_manager->acp_mmio +AMD_SDW_DEVICE_STATE );switch (amd_manager->instance) {case ACP_SDW0 :
@@ -293,10 +294,12 @@ static int amd_sdw_set_device_state(struct amd_sdw_manager *amd_manager, u32 tar AMD_SDW1_DEVICE_STATE_MASK);break ;default : +mutex_unlock (amd_manager->acp_sdw_lock);return -EINVAL ; }writel (sdw_dev_state, amd_manager->acp_mmio +AMD_SDW_DEVICE_STATE ); sdw_dev_state =readl (amd_manager->acp_mmio +AMD_SDW_DEVICE_STATE ); +mutex_unlock (amd_manager->acp_sdw_lock);dev_dbg (amd_manager->dev,"AMD_SDW_DEVICE_STATE:0x%x\n" , sdw_dev_state);return 0 ; }
Signature · 1 line
2.53.0
PATCH v6 23/23 soundwire: amd: fix shared-register RMW race in amd_sdw_host_wake_enable()
In reply to Vijendar MukundaACP_EXTERNAL_INTR_CNTL(ACP_SDW1) holds host-wake interrupt bits for both instances (BIT(22) for SDW0, BIT(23) for SDW1). amd_sdw_host_wake_enable() performed a read-modify-write sequence on this shared register without holding acp_sdw_lock, leaving it open to a lost-update race when SDW0 and SDW1 execute concurrent PM transitions.
Acquire acp_sdw_lock around the read-modify-write sequence.
--- drivers/soundwire/amd_manager.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/soundwire/amd_manager.c +2 -0
@@ -323,12 +323,14 @@ static int amd_sdw_host_wake_enable(struct amd_sdw_manager *amd_manager, bool enreturn -EINVAL ; } +mutex_lock (amd_manager->acp_sdw_lock); intr_cntl1 =readl (amd_manager->acp_mmio +ACP_EXTERNAL_INTR_CNTL (ACP_SDW1 ));if (enable) intr_cntl1 |= sdw_host_wake_irq_mask;else intr_cntl1 &= ~sdw_host_wake_irq_mask;writel (intr_cntl1, amd_manager->acp_mmio +ACP_EXTERNAL_INTR_CNTL (ACP_SDW1 )); +mutex_unlock (amd_manager->acp_sdw_lock);return 0 ; }
Signature · 1 line
2.53.0