i3c: dw: reduce do_daa time if there's no client
Subsystems (2)
PATCH 1/1 i3c: dw: reduce do_daa time if there's no client
If there's no client, wait for completion will timeout, then there's no need to add i3c dev at all. This can save boot time by ~6s if there's no client connected to the i3c interface.
--- drivers/i3c/master/dw-i3c-master.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i3c/master/dw-i3c-master.c +3 -1
@@ -885,8 +885,10 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)COMMAND_PORT_ROC ;dw_i3c_master_enqueue_xfer (master, xfer); -if (!wait_for_completion_timeout (&xfer->comp,XFER_TIMEOUT )) +if (!wait_for_completion_timeout (&xfer->comp,XFER_TIMEOUT )) {dw_i3c_master_dequeue_xfer (master, xfer); + goto rpm_out; + } newdevs =GENMASK (master->maxdevs - cmd->rx_len -1 ,0 ); newdevs &= ~olddevs;
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] A late hardware response from a timed-out transfer can erroneously complete a newly enqueued transfer due to insufficient hardware abortion.
- [High] Ignoring xfer->ret in dw_i3c_master_daa leads to Undefined Behavior in GENMASK and phantom device registration if the hardware completes with an error.
- [High] Queue stall in dw_i3c_master_dequeue_xfer_locked due to failure to start the next transfer after a timeout.
--
--- Patch [1]: [PATCH] i3c: dw: reduce do_daa time if there's no client --- commit 68e06554d2c19f165bbc91e6eef6e5857d1b346a
Author: Jisheng Zhang <[email protected]>
i3c: dw: reduce do_daa time if there's no client
If there's no client, wait for completion will timeout, then there's no need to add i3c dev at all. This can save boot time by ~6s if there's no client connected to the i3c interface.
drivers/i3c/master/dw-i3c-master.c static int dw_i3c_master_daa(struct i3c_master_controller *m) · line 889
Quoted 11 lines
drivers/i3c/master/dw-i3c-master.c +1
-1@@ -885,8 +885,10 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)COMMAND_PORT_ROC ;dw_i3c_master_enqueue_xfer (master, xfer); -if (!wait_for_completion_timeout (&xfer->comp,XFER_TIMEOUT )) +if (!wait_for_completion_timeout (&xfer->comp,XFER_TIMEOUT )) {dw_i3c_master_dequeue_xfer (master, xfer);
[Severity: High]
This is a pre-existing issue, but does this dequeue logic leave the hardware susceptible to late responses?
Looking at dw_i3c_master_dequeue_xfer_locked(), it resets the software queues:
dw_i3c_master_dequeue_xfer_locked() {
...
writel(RESET_CTRL_RX_FIFO | RESET_CTRL_TX_FIFO |
RESET_CTRL_RESP_QUEUE | RESET_CTRL_CMD_QUEUE,
master->regs + RESET_CTRL);
...
}However, this does not halt or soft-reset the underlying hardware state machine (using RESET_CTRL_SOFT). If the transaction is merely delayed on the bus and finishes later, won't a response be pushed to the newly cleared RESP_QUEUE? Since a subsequent single-command transfer (like another DAA) will use a Transaction ID (TID) of 0, could the IRQ handler mistakenly apply the late response to the new transfer, leading to state mismatch and data corruption?
[Severity: High]
This is also a pre-existing issue, but does dw_i3c_master_dequeue_xfer_locked() strand other pending transfers when a timeout occurs?
When setting the current transfer to NULL on timeout:
dw_i3c_master_dequeue_xfer_locked() {
...
master->xferqueue.cur = NULL;
...
}The driver fails to pull and start the next transfer from master->xferqueue.list.
Because cur is NULL, the next time dw_i3c_master_enqueue_xfer() is called, it will bypass the queue list entirely, set the new transfer as cur, and start it immediately:
dw_i3c_master_enqueue_xfer() {
...
if (master->xferqueue.cur) {
list_add_tail(&xfer->node, &master->xferqueue.list);
} else {
master->xferqueue.cur = xfer;
dw_i3c_master_start_xfer_locked(master);
}
}Will this cause older queued transfers to languish in the list forever and inevitably fail via timeout?
drivers/i3c/master/dw-i3c-master.c static int dw_i3c_master_daa(struct i3c_master_controller *m) · line 893
Quoted 4 lines
drivers/i3c/master/dw-i3c-master.c +2
-0+ goto rpm_out; + } newdevs =GENMASK (master->maxdevs - cmd->rx_len -1 ,0 );
[Severity: High]
This isn't a bug introduced by this patch, but if the transfer completes with a hardware error (like a parity error or NACK), is xfer->ret ignored?
If the completion succeeds but xfer->ret indicates an error occurred before any devices were assigned, cmd->rx_len will still equal the requested count (master->maxdevs). This makes the calculation:
master->maxdevs - cmd->rx_len - 1
evaluate to -1.
Doesn't GENMASK(-1, 0) trigger C undefined behavior by shifting by the type's width, resulting in ~0UL? This looks like it would cause the driver to erroneously register all free slots as phantom devices, which could lead to a system panic when communicating with them later.
Quoted 1 line
drivers/i3c/master/dw-i3c-master.c +0
-0newdevs &= ~olddevs;
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1 -- linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
Quoted 14 lines · Jisheng Zhang
If there's no client, wait for completion will timeout, then there's no need to add i3c dev at all. This can save boot time by ~6s if there's no client connected to the i3c interface.
Signed-off-by Jisheng Zhang <[email protected]>--- drivers/i3c/master/dw-i3c-master.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/i3c/master/dw-i3c-master.c +0
-0
drivers/i3c/master/dw-i3c-master.c static int dw_i3c_master_daa(struct i3c_master_controller *m) · line 890
Quoted 7 lines
drivers/i3c/master/dw-i3c-master.c +2
-1@@ -885,8 +885,10 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)COMMAND_PORT_ROC ;dw_i3c_master_enqueue_xfer (master, xfer); -if (!wait_for_completion_timeout (&xfer->comp,XFER_TIMEOUT )) +if (!wait_for_completion_timeout (&xfer->comp,XFER_TIMEOUT )) {dw_i3c_master_dequeue_xfer (master, xfer); + goto rpm_out;
not sure why save 6s. timeout already happen, does register i3c device takes 6s?
And if do_daa find 3 devices, then timeout, you skip register found 3 devices.
Frank
Quoted 7 lines
drivers/i3c/master/dw-i3c-master.c +1
-1+ } newdevs =GENMASK (master->maxdevs - cmd->rx_len -1 ,0 ); newdevs &= ~olddevs; --2.53.0
Quoted 17 lines · Frank Li
Quoted 16 lines · Jisheng Zhang
If there's no client, wait for completion will timeout, then there's no need to add i3c dev at all. This can save boot time by ~6s if there's no client connected to the i3c interface.
Signed-off-by Jisheng Zhang <[email protected]>--- drivers/i3c/master/dw-i3c-master.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/i3c/master/dw-i3c-master.c +0
-0@@ -885,8 +885,10 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)COMMAND_PORT_ROC ;
Quoted 8 lines
drivers/i3c/master/dw-i3c-master.c static int dw_i3c_master_daa(struct i3c_master_controller *m) · line 890
Quoted 5 lines
drivers/i3c/master/dw-i3c-master.c +2
-1dw_i3c_master_enqueue_xfer (master, xfer); -if (!wait_for_completion_timeout (&xfer->comp,XFER_TIMEOUT )) +if (!wait_for_completion_timeout (&xfer->comp,XFER_TIMEOUT )) {dw_i3c_master_dequeue_xfer (master, xfer); + goto rpm_out;not sure why save 6s. timeout already happen, does register i3c device takes 6s?
sorry, typo, s/6/4
For example if the maxdev == 4, when there's no i3c device connected, the max cmd->rx_len = 0 after timeout, then newdevs = 0xf, then go through the i3c_master_add_i3c_dev_locked(), each take ~1s, so adds up to 4s
Quoted 3 lines
And if
do_daafind 3 devices, then timeout, you skip register found 3 devices.
It's the addr assign cmd timeout, so if 3 devices respond, the addr assign cmd won't timeout.
Quoted 10 lines
Frank
Quoted 7 lines
drivers/i3c/master/dw-i3c-master.c +1
-1+ } newdevs =GENMASK (master->maxdevs - cmd->rx_len -1 ,0 ); newdevs &= ~olddevs; --2.53.0
Signature · 3 lines
linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
Quoted 27 lines · Jisheng Zhang
Quoted 17 lines · Frank Li
Quoted 16 lines · Jisheng Zhang
If there's no client, wait for completion will timeout, then there's no need to add i3c dev at all. This can save boot time by ~6s if there's no client connected to the i3c interface.
Signed-off-by Jisheng Zhang <[email protected]>--- drivers/i3c/master/dw-i3c-master.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/i3c/master/dw-i3c-master.c +0
-0@@ -885,8 +885,10 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)COMMAND_PORT_ROC ;Quoted 8 lines
drivers/i3c/master/dw-i3c-master.c static int dw_i3c_master_daa(struct i3c_master_controller *m) · line 890
Quoted 5 lines
drivers/i3c/master/dw-i3c-master.c +2
-1dw_i3c_master_enqueue_xfer (master, xfer); -if (!wait_for_completion_timeout (&xfer->comp,XFER_TIMEOUT )) +if (!wait_for_completion_timeout (&xfer->comp,XFER_TIMEOUT )) {dw_i3c_master_dequeue_xfer (master, xfer); + goto rpm_out;not sure why save 6s. timeout already happen, does register i3c device takes 6s?
Quoted 4 lines
sorry, typo, s/6/4
For example if the maxdev == 4, when there's no i3c device connected, the maxcmd->rx_len= 0 after timeout, then newdevs =0xf, then go through thei3c_master_add_i3c_dev_locked(), each take ~1s, so adds up to 4s
https://lore.kernel.org/linux-i3c/[email protected]/
Need fix newdevs, it should be 0, not 0xf.
Frank
Quoted 18 lines
Quoted 4 lines
And if
do_daafind 3 devices, then timeout, you skip register found 3 devices.It's the addr assign cmd timeout, so if 3 devices respond, the addr assign cmd won't timeout.
Quoted 10 lines
Frank
Quoted 7 lines
drivers/i3c/master/dw-i3c-master.c +1
-1+ } newdevs =GENMASK (master->maxdevs - cmd->rx_len -1 ,0 ); newdevs &= ~olddevs; --2.53.0
Quoted 34 lines · Frank Li
Quoted 27 lines · Jisheng Zhang
Quoted 17 lines · Frank Li
Quoted 16 lines · Jisheng Zhang
If there's no client, wait for completion will timeout, then there's no need to add i3c dev at all. This can save boot time by ~6s if there's no client connected to the i3c interface.
Signed-off-by Jisheng Zhang <[email protected]>--- drivers/i3c/master/dw-i3c-master.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/i3c/master/dw-i3c-master.c +0
-0@@ -885,8 +885,10 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)COMMAND_PORT_ROC ;Quoted 8 lines
drivers/i3c/master/dw-i3c-master.c static int dw_i3c_master_daa(struct i3c_master_controller *m) · line 890
Quoted 5 lines
drivers/i3c/master/dw-i3c-master.c +2
-1dw_i3c_master_enqueue_xfer (master, xfer); -if (!wait_for_completion_timeout (&xfer->comp,XFER_TIMEOUT )) +if (!wait_for_completion_timeout (&xfer->comp,XFER_TIMEOUT )) {dw_i3c_master_dequeue_xfer (master, xfer); + goto rpm_out;not sure why save 6s. timeout already happen, does register i3c device takes 6s?
Quoted 4 lines
sorry, typo, s/6/4
For example if the maxdev == 4, when there's no i3c device connected, the maxcmd->rx_len= 0 after timeout, then newdevs =0xf, then go through thei3c_master_add_i3c_dev_locked(), each take ~1s, so adds up to 4s
Quoted 3 lines
https://lore.kernel.org/linux-i3c/[email protected]/
Need fix newdevs, it should be 0, not
0xf.
Aha, this method also works. Let me cook a new version
Thanks a lot
Quoted 21 lines
Frank
Quoted 18 lines
Quoted 4 lines
And if
do_daafind 3 devices, then timeout, you skip register found 3 devices.It's the addr assign cmd timeout, so if 3 devices respond, the addr assign cmd won't timeout.
Quoted 10 lines
Frank
Quoted 7 lines
drivers/i3c/master/dw-i3c-master.c +1
-1+ } newdevs =GENMASK (master->maxdevs - cmd->rx_len -1 ,0 ); newdevs &= ~olddevs; --2.53.0