From: Yicong Yang <yangyicong@huawei.com>
To: Andi Shyti <andi.shyti@kernel.org>
Cc: <yangyicong@hisilicon.com>, <wsa@kernel.org>,
<linux-i2c@vger.kernel.org>, <f.fangjian@huawei.com>,
<linuxarm@huawei.com>
Subject: Re: [PATCH] i2c: hisi: Only handle the interrupt of the driver's transfer
Date: Wed, 2 Aug 2023 10:39:04 +0800 [thread overview]
Message-ID: <517658b5-4f44-7903-bb86-074c7561e0f2@huawei.com> (raw)
In-Reply-To: <20230801221557.74z7lorwzq5nxqam@intel.intel>
On 2023/8/2 6:15, Andi Shyti wrote:
> Hi Yicong,
>
> On Tue, Aug 01, 2023 at 08:46:25PM +0800, Yicong Yang wrote:
>> From: Yicong Yang <yangyicong@hisilicon.com>
>>
>> The controller may be shared with other port, for example the firmware.
>> Handle the interrupt from other sources will cause crash since some
>> data are not initialized. So only handle the interrupt of the driver's
>> transfer and discard others.
>>
>> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
>
> Is this a fix? Then, could you please add:
>
> Fixes: d62fbdb99a85 ("i2c: add support for HiSilicon I2C controller")
> Cc: <stable@vger.kernel.org> # v5.13+
>
> What kind of crash is this? Is it a NULL pointer dereference?
I not quite sure this is a fix of the driver. On some use case the controller is
shared between the firmware and the OS and we have no synchronization method
from the hardware. A transfer started by the firmware cause the interrupt handled
by the driver and cause a NULL pointer dereference.
>
>> ---
>> drivers/i2c/busses/i2c-hisi.c | 8 ++++++++
>> 1 file changed, 8 insertions(+)
>>
>> diff --git a/drivers/i2c/busses/i2c-hisi.c b/drivers/i2c/busses/i2c-hisi.c
>> index e067671b3ce2..8328da4bc3ec 100644
>> --- a/drivers/i2c/busses/i2c-hisi.c
>> +++ b/drivers/i2c/busses/i2c-hisi.c
>> @@ -330,6 +330,14 @@ static irqreturn_t hisi_i2c_irq(int irq, void *context)
>> struct hisi_i2c_controller *ctlr = context;
>> u32 int_stat;
>>
>> + /*
>> + * Don't handle the interrupt if cltr->completion is NULL. We may
>> + * reach here because the interrupt is spurious or the transfer is
>> + * started by another port rather than us.
>> + */
>> + if (!ctlr->completion)
>> + return IRQ_NONE;
>
> Is this the place you should really check for completion being
> NULL? By reading the code I don't exclude that completion at this
> stage might be NULL.
>
> Can it be that the real fix is this one instead:
Maybe not. If we handle the case as late as below, we'll operate the hardware
which should be handled by the firmware which start the transfer. So we check
it as early as possible.
>
> @@ -352,7 +352,7 @@ static irqreturn_t hisi_i2c_irq(int irq, void *context)
> * Only use TRANS_CPLT to indicate the completion. On error cases we'll
> * get two interrupts, INT_ERR first then TRANS_CPLT.
> */
> - if (int_stat & HISI_I2C_INT_TRANS_CPLT) {
> + if (ctrl->completion && (int_stat & HISI_I2C_INT_TRANS_CPLT)) {
> hisi_i2c_disable_int(ctlr, HISI_I2C_INT_ALL);
> hisi_i2c_clear_int(ctlr, HISI_I2C_INT_ALL);
> complete(ctlr->completion);
>
> Anyway, this whole completion management smells a bit racy to me.
>
> Andi
>
>> int_stat = readl(ctlr->iobase + HISI_I2C_INT_MSTAT);
>> hisi_i2c_clear_int(ctlr, int_stat);
>> if (!(int_stat & HISI_I2C_INT_ALL))
>> --
>> 2.24.0
>>
> .
>
next prev parent reply other threads:[~2023-08-02 2:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-01 12:46 [PATCH] i2c: hisi: Only handle the interrupt of the driver's transfer Yicong Yang
2023-08-01 22:15 ` Andi Shyti
2023-08-02 2:39 ` Yicong Yang [this message]
2023-08-04 23:30 ` Andi Shyti
2023-08-08 13:11 ` Yicong Yang
2023-08-09 20:08 ` Andi Shyti
2023-08-09 20:43 ` Andi Shyti
2023-08-14 13:42 ` Wolfram Sang
2023-08-15 8:41 ` Geert Uytterhoeven
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=517658b5-4f44-7903-bb86-074c7561e0f2@huawei.com \
--to=yangyicong@huawei.com \
--cc=andi.shyti@kernel.org \
--cc=f.fangjian@huawei.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=wsa@kernel.org \
--cc=yangyicong@hisilicon.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