* [PATCH] spi: dw: use "smp_mb()" to avoid sending spi data error
@ 2019-12-26 9:21 Xinwei Kong
2019-12-27 0:22 ` Mark Brown
0 siblings, 1 reply; 5+ messages in thread
From: Xinwei Kong @ 2019-12-26 9:21 UTC (permalink / raw)
To: broonie, linux-spi, linux-kernel; +Cc: linuxarm, Xinwei Kong, fengsheng
this patch will add memory barrier to ensure this "struct dw_spi *dws"
to complete data setting before enabling this SPI hardware interrupt.
eg:
it will fix to this following low possibility error in testing environment
which using SPI control to connect TPM Modules
kernel: tpm tpm0: Operation Timed out
kernel: tpm tpm0: tpm_relinquish_locality: : error -1
Signed-off-by: fengsheng <fengsheng5@huawei.com>
Signed-off-by: Xinwei Kong <kong.kongxinwei@hisilicon.com>
---
drivers/spi/spi-dw.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index a92aa5c..d0d77a2 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -288,6 +288,8 @@ static int dw_spi_transfer_one(struct spi_controller *master,
dws->rx_end = dws->rx + transfer->len;
dws->len = transfer->len;
+ smp_mb();
+
spi_enable_chip(dws, 0);
/* Handle per transfer options for bpw and speed */
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] spi: dw: use "smp_mb()" to avoid sending spi data error
2019-12-26 9:21 [PATCH] spi: dw: use "smp_mb()" to avoid sending spi data error Xinwei Kong
@ 2019-12-27 0:22 ` Mark Brown
2019-12-28 8:31 ` kongxinwei
0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2019-12-27 0:22 UTC (permalink / raw)
To: Xinwei Kong; +Cc: linux-spi, linux-kernel, linuxarm, fengsheng
[-- Attachment #1: Type: text/plain, Size: 911 bytes --]
On Thu, Dec 26, 2019 at 05:21:28PM +0800, Xinwei Kong wrote:
> this patch will add memory barrier to ensure this "struct dw_spi *dws"
> to complete data setting before enabling this SPI hardware interrupt.
> eg:
> it will fix to this following low possibility error in testing environment
> which using SPI control to connect TPM Modules
> --- a/drivers/spi/spi-dw.c
> +++ b/drivers/spi/spi-dw.c
> @@ -288,6 +288,8 @@ static int dw_spi_transfer_one(struct spi_controller *master,
> dws->rx_end = dws->rx + transfer->len;
> dws->len = transfer->len;
>
> + smp_mb();
> +
> spi_enable_chip(dws, 0);
I'd be much more comfortable here if I understood what this was
supposed to be syncing - what exactly gets flushed here and why
is a memory barrier enough to ensure it's synced? A comment in
the code would be especially good so anyone modifying the code
understands this in future.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] spi: dw: use "smp_mb()" to avoid sending spi data error
2019-12-27 0:22 ` Mark Brown
@ 2019-12-28 8:31 ` kongxinwei
2020-01-03 1:04 ` Mark Brown
0 siblings, 1 reply; 5+ messages in thread
From: kongxinwei @ 2019-12-28 8:31 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-spi, linux-kernel, linuxarm, fengsheng, Xinwei Kong
On 2019/12/27 8:22, Mark Brown wrote:
> On Thu, Dec 26, 2019 at 05:21:28PM +0800, Xinwei Kong wrote:
>> this patch will add memory barrier to ensure this "struct dw_spi *dws"
>> to complete data setting before enabling this SPI hardware interrupt.
>> eg:
>> it will fix to this following low possibility error in testing environment
>> which using SPI control to connect TPM Modules
>
>> --- a/drivers/spi/spi-dw.c
>> +++ b/drivers/spi/spi-dw.c
>> @@ -288,6 +288,8 @@ static int dw_spi_transfer_one(struct spi_controller *master,
>> dws->rx_end = dws->rx + transfer->len;
>> dws->len = transfer->len;
>>
>> + smp_mb();
>> +
>> spi_enable_chip(dws, 0);
>
> I'd be much more comfortable here if I understood what this was
> supposed to be syncing - what exactly gets flushed here and why
> is a memory barrier enough to ensure it's synced? A comment in
> the code would be especially good so anyone modifying the code
> understands this in future.
>
Because of out-of-order execution about some CPU architecture,
In this debug stage we find Completing spi interrupt enable ->
prodrucing TXEI interrupt -> running "interrupt_transfer" function
will prior to set "dw->rx and dws->rx_end" data, so it will result
in SPI sending error
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] spi: dw: use "smp_mb()" to avoid sending spi data error
2019-12-28 8:31 ` kongxinwei
@ 2020-01-03 1:04 ` Mark Brown
2020-01-03 1:34 ` kongxinwei
0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2020-01-03 1:04 UTC (permalink / raw)
To: kongxinwei; +Cc: linux-spi, linux-kernel, linuxarm, fengsheng
[-- Attachment #1: Type: text/plain, Size: 810 bytes --]
On Sat, Dec 28, 2019 at 04:31:53PM +0800, kongxinwei wrote:
> > I'd be much more comfortable here if I understood what this was
> > supposed to be syncing - what exactly gets flushed here and why
> > is a memory barrier enough to ensure it's synced? A comment in
> > the code would be especially good so anyone modifying the code
> > understands this in future.
> Because of out-of-order execution about some CPU architecture,
> In this debug stage we find Completing spi interrupt enable ->
> prodrucing TXEI interrupt -> running "interrupt_transfer" function
> will prior to set "dw->rx and dws->rx_end" data, so it will result
> in SPI sending error
Could you update the commit message to say that, and ideally also
add a comment saying something like "Ensure dw->rx and dw->rx_end
are visible" please?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] spi: dw: use "smp_mb()" to avoid sending spi data error
2020-01-03 1:04 ` Mark Brown
@ 2020-01-03 1:34 ` kongxinwei
0 siblings, 0 replies; 5+ messages in thread
From: kongxinwei @ 2020-01-03 1:34 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-spi, linux-kernel, linuxarm, fengsheng, kXinwei Kong
On 2020/1/3 9:04, Mark Brown wrote:
> On Sat, Dec 28, 2019 at 04:31:53PM +0800, kongxinwei wrote:
>
>>> I'd be much more comfortable here if I understood what this was
>>> supposed to be syncing - what exactly gets flushed here and why
>>> is a memory barrier enough to ensure it's synced? A comment in
>>> the code would be especially good so anyone modifying the code
>>> understands this in future.
>
>> Because of out-of-order execution about some CPU architecture,
>> In this debug stage we find Completing spi interrupt enable ->
>> prodrucing TXEI interrupt -> running "interrupt_transfer" function
>> will prior to set "dw->rx and dws->rx_end" data, so it will result
>> in SPI sending error
>
> Could you update the commit message to say that, and ideally also
> add a comment saying something like "Ensure dw->rx and dw->rx_end
> are visible" please?
>
OK, i WILL update it.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-01-03 1:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-26 9:21 [PATCH] spi: dw: use "smp_mb()" to avoid sending spi data error Xinwei Kong
2019-12-27 0:22 ` Mark Brown
2019-12-28 8:31 ` kongxinwei
2020-01-03 1:04 ` Mark Brown
2020-01-03 1:34 ` kongxinwei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).