* [PATCH 0/2] soundwire: Fix bandwidth leak in multi-link aggregation failure
@ 2026-11-02 6:04 Bard Liao
2026-11-02 6:04 ` [PATCH 1/2] soundwire: move lane bandwidth into bus params Bard Liao
2026-11-02 6:04 ` [PATCH 2/2] soundwire: stream: Fix bandwidth leak in multi-link aggregation failure Bard Liao
0 siblings, 2 replies; 3+ messages in thread
From: Bard Liao @ 2026-11-02 6:04 UTC (permalink / raw)
To: linux-sound, vkoul
Cc: vinod.koul, linux-kernel, pierre-louis.bossart, peter.ujfalusi,
bard.liao, david.lin
The existing code only copies the params from the first link to the
bus params, but it doesn't copy the bandwidth from the other links.
This can lead to a bandwidth leak when multi-link aggregation fails.
Fix this by saving a snapshot of each bus's parameters before making
any modifications.
Bard Liao (1):
soundwire: move lane bandwidth into bus params
David Lin (1):
soundwire: stream: Fix bandwidth leak in multi-link aggregation
failure
drivers/soundwire/bus.h | 3 +++
.../soundwire/generic_bandwidth_allocation.c | 8 +++----
drivers/soundwire/stream.c | 21 +++++++++++++------
include/linux/soundwire/sdw.h | 4 ++--
4 files changed, 24 insertions(+), 12 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] soundwire: move lane bandwidth into bus params
2026-11-02 6:04 [PATCH 0/2] soundwire: Fix bandwidth leak in multi-link aggregation failure Bard Liao
@ 2026-11-02 6:04 ` Bard Liao
2026-11-02 6:04 ` [PATCH 2/2] soundwire: stream: Fix bandwidth leak in multi-link aggregation failure Bard Liao
1 sibling, 0 replies; 3+ messages in thread
From: Bard Liao @ 2026-11-02 6:04 UTC (permalink / raw)
To: linux-sound, vkoul
Cc: vinod.koul, linux-kernel, pierre-louis.bossart, peter.ujfalusi,
bard.liao, david.lin
lane_used_bandwidth is used to store the used bandwidth for each lane.
When we restore the bus->params, the lane_used_bandwidth value will not
be restored in current code. Move it to sdw_bus_params to fix the issue.
Fixes: 366fd59fb894 ("soundwire: generic_bandwidth_allocation: add lane in sdw_group_params")
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: David Lin <david.lin@intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
---
drivers/soundwire/generic_bandwidth_allocation.c | 8 ++++----
drivers/soundwire/stream.c | 4 ++--
include/linux/soundwire/sdw.h | 4 ++--
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/soundwire/generic_bandwidth_allocation.c b/drivers/soundwire/generic_bandwidth_allocation.c
index 30a495abe19e..3d6b9c895e46 100644
--- a/drivers/soundwire/generic_bandwidth_allocation.c
+++ b/drivers/soundwire/generic_bandwidth_allocation.c
@@ -196,7 +196,7 @@ static void _sdw_compute_port_params(struct sdw_bus *bus,
/* Run loop for all groups to compute transport parameters */
for (l = 0; l < SDW_MAX_LANES; l++) {
- if (l > 0 && !bus->lane_used_bandwidth[l])
+ if (l > 0 && !bus->params.lane_used_bandwidth[l])
continue;
/* reset hstop for each lane */
hstop = bus->params.col - 1;
@@ -267,7 +267,7 @@ static int sdw_compute_group_params(struct sdw_bus *bus,
}
for (l = 0; l < SDW_MAX_LANES; l++) {
- if (l > 0 && !bus->lane_used_bandwidth[l])
+ if (l > 0 && !bus->params.lane_used_bandwidth[l])
continue;
/* reset column_needed for each lane */
column_needed = 0;
@@ -507,7 +507,7 @@ static int get_manager_lane(struct sdw_bus *bus, struct sdw_master_runtime *m_rt
m_rt->stream->params.bps;
}
if (required_bandwidth <=
- curr_dr_freq - bus->lane_used_bandwidth[l]) {
+ curr_dr_freq - bus->params.lane_used_bandwidth[l]) {
/* Check if m_lane is connected to all Peripherals */
if (!is_lane_connected_to_all_peripherals(m_rt,
slave_prop->lane_maps[l])) {
@@ -518,7 +518,7 @@ static int get_manager_lane(struct sdw_bus *bus, struct sdw_master_runtime *m_rt
}
m_lane = slave_prop->lane_maps[l];
dev_dbg(&s_rt->slave->dev, "M lane %d is used\n", m_lane);
- bus->lane_used_bandwidth[l] += required_bandwidth;
+ bus->params.lane_used_bandwidth[l] += required_bandwidth;
/*
* Use non-zero manager lane, subtract the lane 0
* bandwidth that is already calculated
diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index 0b00fcdcab2d..96613dd0677c 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -1792,8 +1792,8 @@ static int _sdw_deprepare_stream(struct sdw_stream_runtime *stream)
bandwidth = m_rt->stream->params.rate * hweight32(p_rt->ch_mask) *
m_rt->stream->params.bps;
multi_lane_bandwidth += bandwidth;
- bus->lane_used_bandwidth[p_rt->lane] -= bandwidth;
- if (!bus->lane_used_bandwidth[p_rt->lane])
+ bus->params.lane_used_bandwidth[p_rt->lane] -= bandwidth;
+ if (!bus->params.lane_used_bandwidth[p_rt->lane])
p_rt->lane = 0;
}
/* TODO: Update this during Device-Device support */
diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
index f710e5932b4b..fff30bb2d9ed 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -592,6 +592,7 @@ enum sdw_port_prep_ops {
* @bandwidth: Current bandwidth
* @col: Active columns
* @row: Active rows
+ * @lane_used_bandwidth: how much bandwidth in bits per second is used by each lane
* @s_data_mode: NORMAL, STATIC or PRBS mode for all Slave ports
* @m_data_mode: NORMAL, STATIC or PRBS mode for all Master ports. The value
* should be the same to detect transmission issues, but can be different to
@@ -605,6 +606,7 @@ struct sdw_bus_params {
unsigned int bandwidth;
unsigned int col;
unsigned int row;
+ unsigned int lane_used_bandwidth[SDW_MAX_LANES];
int s_data_mode;
int m_data_mode;
};
@@ -1028,7 +1030,6 @@ struct sdw_stream_runtime {
* @multi_link: Store bus property that indicates if multi links
* are supported. This flag is populated by drivers after reading
* appropriate firmware (ACPI/DT).
- * @lane_used_bandwidth: how much bandwidth in bits per second is used by each lane
*/
struct sdw_bus {
struct device *dev;
@@ -1063,7 +1064,6 @@ struct sdw_bus {
struct dentry *debugfs;
#endif
bool multi_link;
- unsigned int lane_used_bandwidth[SDW_MAX_LANES];
};
struct sdw_stream_runtime *sdw_alloc_stream(const char *stream_name, enum sdw_stream_type type);
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] soundwire: stream: Fix bandwidth leak in multi-link aggregation failure
2026-11-02 6:04 [PATCH 0/2] soundwire: Fix bandwidth leak in multi-link aggregation failure Bard Liao
2026-11-02 6:04 ` [PATCH 1/2] soundwire: move lane bandwidth into bus params Bard Liao
@ 2026-11-02 6:04 ` Bard Liao
1 sibling, 0 replies; 3+ messages in thread
From: Bard Liao @ 2026-11-02 6:04 UTC (permalink / raw)
To: linux-sound, vkoul
Cc: vinod.koul, linux-kernel, pierre-louis.bossart, peter.ujfalusi,
bard.liao, david.lin
From: David Lin <david.lin@intel.com>
When preparing a multi-link aggregation stream, a failure on a subsequent
link during _sdw_prepare_stream() causes the stream preparation to fail.
However, the bandwidth allocated on the preceding successful links is never
released, causing a cumulative bandwidth leak.
Fix this by saving a snapshot of each bus's parameters before making any
modifications. In case of failure, we iterate through the stream's master
list and restore each bus to its original parameter state, ensuring an
atomic rollback and preventing any bandwidth leaks.
Signed-off-by: David Lin <david.lin@intel.com>
Co-developed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
---
drivers/soundwire/bus.h | 3 +++
drivers/soundwire/stream.c | 17 +++++++++++++----
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/soundwire/bus.h b/drivers/soundwire/bus.h
index 44e4f5193917..476387b70472 100644
--- a/drivers/soundwire/bus.h
+++ b/drivers/soundwire/bus.h
@@ -155,6 +155,8 @@ struct sdw_slave_runtime {
*
* @bus: Bus handle
* @stream: Stream runtime handle
+ * @params_backup: Snapshot of original bus parameters saved before stream
+ * preparation, used for rollback recovery on failure.
* @direction: Data direction for Master
* @ch_count: Number of channels handled by the Master for
* this stream, can be zero.
@@ -166,6 +168,7 @@ struct sdw_slave_runtime {
struct sdw_master_runtime {
struct sdw_bus *bus;
struct sdw_stream_runtime *stream;
+ struct sdw_bus_params params_backup;
enum sdw_data_direction direction;
unsigned int ch_count;
struct list_head slave_rt_list;
diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index 96613dd0677c..86d951cc92f7 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -1477,19 +1477,22 @@ static int _sdw_prepare_stream(struct sdw_stream_runtime *stream,
struct sdw_master_runtime *m_rt;
struct sdw_bus *bus;
struct sdw_master_prop *prop;
- struct sdw_bus_params params;
int ret;
+ /* Pre-pass: snapshot original bus parameters for all masters */
+ list_for_each_entry(m_rt, &stream->master_list, stream_node)
+ m_rt->params_backup = m_rt->bus->params;
+
/* Prepare Master(s) and Slave(s) port(s) associated with stream */
list_for_each_entry(m_rt, &stream->master_list, stream_node) {
bus = m_rt->bus;
prop = &bus->prop;
- memcpy(¶ms, &bus->params, sizeof(params));
/* TODO: Support Asynchronous mode */
if ((prop->max_clk_freq % stream->params.rate) != 0) {
dev_err(bus->dev, "Async mode not supported\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto restore_params;
}
if (update_params) {
@@ -1540,7 +1543,13 @@ static int _sdw_prepare_stream(struct sdw_stream_runtime *stream,
return ret;
restore_params:
- memcpy(&bus->params, ¶ms, sizeof(params));
+ /*
+ * Revert all masters to their snapshotted original parameters.
+ * Any master that was not modified will safely revert to its own original state.
+ */
+ list_for_each_entry(m_rt, &stream->master_list, stream_node)
+ m_rt->bus->params = m_rt->params_backup;
+
return ret;
}
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-02 6:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 6:04 [PATCH 0/2] soundwire: Fix bandwidth leak in multi-link aggregation failure Bard Liao
2026-11-02 6:04 ` [PATCH 1/2] soundwire: move lane bandwidth into bus params Bard Liao
2026-11-02 6:04 ` [PATCH 2/2] soundwire: stream: Fix bandwidth leak in multi-link aggregation failure Bard Liao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®