Linux I2C development
 help / color / mirror / Atom feed
From: Jan Bottorff <janb@os.amperecomputing.com>
To: Yann Sionneau <ysionneau@kalrayinc.com>,
	Wolfram Sang <wsa@kernel.org>,
	Serge Semin <fancer.lancer@gmail.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Yann Sionneau <yann@sionneau.net>, Will Deacon <will@kernel.org>,
	Jarkko Nikula <jarkko.nikula@linux.intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Jan Dabros <jsd@semihalf.com>, Andi Shyti <andi.shyti@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] i2c: designware: Fix corrupted memory seen in the ISR
Date: Wed, 20 Sep 2023 12:14:17 -0700	[thread overview]
Message-ID: <9219ad29-b9a3-4f07-81b5-43b4b6d9d178@os.amperecomputing.com> (raw)
In-Reply-To: <ba6d4378-b646-4514-3a45-4b6c951fbb9c@kalrayinc.com>

On 9/20/2023 6:27 AM, Yann Sionneau wrote:
> Hi,
> 
> On 20/09/2023 11:08, Wolfram Sang wrote:
>>> same thread." [1] Thus I'd suggest the next fix for the problem:
>>>
>>> --- a/drivers/i2c/busses/i2c-designware-common.c
>>> +++ b/drivers/i2c/busses/i2c-designware-common.c
>>> @@ -72,7 +72,10 @@ static int dw_reg_write(void *context, unsigned 
>>> int reg, unsigned int val)
>>>   {
>>>       struct dw_i2c_dev *dev = context;
>>> -    writel_relaxed(val, dev->base + reg);
>>> +    if (reg == DW_IC_INTR_MASK)
>>> +        writel(val, dev->base + reg);
>>> +    else
>>> +        writel_relaxed(val, dev->base + reg);
>>>       return 0;
>>>   }
>>>
>>> (and similar changes for dw_reg_write_swab() and dw_reg_write_word().)
>>>
>>> What do you think?
>> To me, this looks reasonable and much more what I would have expected as
>> a result (from a high level point of view). Let's hope it works. I am
>> optimistic, though...
>>
> It works if we make sure all the other register accesses to the 
> designware i2c IP can't generate IRQ.
> 
> Meaning that all register accesses that can trigger an IRQ are enclosed 
> in between a call to i2c_dw_disable_int() and a call to 
> regmap_write(dev->map, DW_IC_INTR_MASK, DW_IC_INTR_MASTER_MASK); or 
> equivalent.
> 
> It seems to be the case, I'm not sure what's the best way to make sure 
> it will stay that way.
> 
> Moreover, maybe writes to IC_ENABLE register should also use the 
> non-relaxed writel() version?
> 
> Since one could do something like:
> 
> [ IP is currently disabled ]
> 
> 1/ enable interrupts in DW_IC_INTR_MASK
> 
> 2/ update some variable in dev-> structure in DDR
> 
> 3/ enable the device by writing to IC_ENABLE, thus triggering for 
> instance the TX_FIFO_EMPTY irq.
> 

It does seem like there are a variety of register write combinations 
that could immediately cause an interrupt, so would need a barrier.

I understand barriers a bit better now, although still wonder about some 
cases. Like say you write to some driver memory and then write the DW 
command fifo register, and it does not immediately cause an interrupt, 
but will in the future. Even without the barrier the memory write would 
typically become visible to other cores after some small amount of time, 
but don't see that's it's architecturally guaranteed to be visible. This 
implies the barrier is perhaps needed on many/all of the registers.

Jan



  reply	other threads:[~2023-09-20 19:14 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13 23:29 [PATCH v2] i2c: designware: Fix corrupted memory seen in the ISR Jan Bottorff
2023-09-14 18:46 ` Andy Shevchenko
2023-09-14 18:47   ` Andy Shevchenko
2023-09-14 20:52     ` Jan Bottorff
2023-09-15 12:44 ` Jarkko Nikula
2023-09-15 15:21 ` Serge Semin
2023-09-16  1:47   ` Jan Bottorff
2023-09-17  0:01     ` Serge Semin
2023-09-17 20:08       ` Yann Sionneau
2023-09-18 23:14         ` Serge Semin
2023-09-19  3:45           ` Jan Bottorff
2023-09-19  9:55             ` Catalin Marinas
2023-09-19 10:19               ` Wolfram Sang
2023-09-19 12:38                 ` Yann Sionneau
2023-09-19 14:51                   ` Catalin Marinas
2023-09-19 14:55                     ` Wolfram Sang
2023-09-19 18:54                     ` Jan Bottorff
2023-09-19 21:05                       ` Serge Semin
2023-09-20  9:08                         ` Wolfram Sang
2023-09-20 13:27                           ` Yann Sionneau
2023-09-20 19:14                             ` Jan Bottorff [this message]
2023-09-25 12:54                               ` Serge Semin
2023-09-25 19:39                                 ` Jan Bottorff
2023-09-27 19:38                                   ` Wolfram Sang
2023-09-29  8:48                                     ` Jarkko Nikula
2023-10-26 11:18                                       ` Wolfram Sang
2023-10-31  0:12                                         ` Jan Bottorff
2023-10-31  5:51                                           ` Wolfram Sang
2023-10-31  8:44                                           ` Yann Sionneau
2023-10-31 12:10                                             ` Jarkko Nikula
2023-10-31 13:06                                               ` Serge Semin
2023-11-01 16:51                                                 ` Jan Bottorff
2023-09-20 11:03                         ` Catalin Marinas
2023-09-20 10:44                       ` Catalin Marinas
2023-09-20 11:05                         ` Catalin Marinas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9219ad29-b9a3-4f07-81b5-43b4b6d9d178@os.amperecomputing.com \
    --to=janb@os.amperecomputing.com \
    --cc=andi.shyti@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=catalin.marinas@arm.com \
    --cc=fancer.lancer@gmail.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=jsd@semihalf.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=p.zabel@pengutronix.de \
    --cc=will@kernel.org \
    --cc=wsa@kernel.org \
    --cc=yann@sionneau.net \
    --cc=ysionneau@kalrayinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox