2022-08-03 04:38:55

by Huacai Chen

[permalink] [raw]
Subject: [PATCH 1/2] irqchip/loongson-eiointc: Check hwirq overflow

Check hwirq overflow when allocate irq in eiointc domain.

Signed-off-by: Huacai Chen <[email protected]>
---
drivers/irqchip/irq-loongson-eiointc.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
index 80d8ca6f2d46..f8060e58ee06 100644
--- a/drivers/irqchip/irq-loongson-eiointc.c
+++ b/drivers/irqchip/irq-loongson-eiointc.c
@@ -241,8 +241,11 @@ static int eiointc_domain_alloc(struct irq_domain *domain, unsigned int virq,
struct eiointc *priv = domain->host_data;

ret = irq_domain_translate_onecell(domain, arg, &hwirq, &type);
- if (ret)
- return ret;
+ if (ret < 0)
+ return -EINVAL;
+
+ if (hwirq >= IOCSR_EXTIOI_VECTOR_NUM)
+ return -EINVAL;

for (i = 0; i < nr_irqs; i++) {
irq_domain_set_info(domain, virq + i, hwirq + i, &eiointc_irq_chip,
--
2.31.1



2022-08-03 04:54:05

by Huacai Chen

[permalink] [raw]
Subject: [PATCH 2/2] irqchip/loongson-eiointc: Fix irq affinity setting

In multi-node case, csr_any_send() should set EIOINTC_REG_ENABLE of the
first core of target node, not the first core of the whole.

Signed-off-by: Huacai Chen <[email protected]>
---
drivers/irqchip/irq-loongson-eiointc.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
index f8060e58ee06..58c1cf47b3d7 100644
--- a/drivers/irqchip/irq-loongson-eiointc.c
+++ b/drivers/irqchip/irq-loongson-eiointc.c
@@ -111,11 +111,15 @@ static int eiointc_set_irq_affinity(struct irq_data *d, const struct cpumask *af
regaddr = EIOINTC_REG_ENABLE + ((vector >> 5) << 2);

/* Mask target vector */
- csr_any_send(regaddr, EIOINTC_ALL_ENABLE & (~BIT(vector & 0x1F)), 0x0, 0);
+ csr_any_send(regaddr, EIOINTC_ALL_ENABLE & (~BIT(vector & 0x1F)),
+ 0x0, priv->node * CORES_PER_EIO_NODE);
+
/* Set route for target vector */
eiointc_set_irq_route(vector, cpu, priv->node, &priv->node_map);
+
/* Unmask target vector */
- csr_any_send(regaddr, EIOINTC_ALL_ENABLE, 0x0, 0);
+ csr_any_send(regaddr, EIOINTC_ALL_ENABLE,
+ 0x0, priv->node * CORES_PER_EIO_NODE);

irq_data_update_effective_affinity(d, cpumask_of(cpu));

--
2.31.1


2022-08-03 07:30:11

by Marc Zyngier

[permalink] [raw]
Subject: Re: [PATCH 1/2] irqchip/loongson-eiointc: Check hwirq overflow

On Wed, 03 Aug 2022 05:27:27 +0100,
Huacai Chen <[email protected]> wrote:
>
> Check hwirq overflow when allocate irq in eiointc domain.
>
> Signed-off-by: Huacai Chen <[email protected]>
> ---
> drivers/irqchip/irq-loongson-eiointc.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
> index 80d8ca6f2d46..f8060e58ee06 100644
> --- a/drivers/irqchip/irq-loongson-eiointc.c
> +++ b/drivers/irqchip/irq-loongson-eiointc.c
> @@ -241,8 +241,11 @@ static int eiointc_domain_alloc(struct irq_domain *domain, unsigned int virq,
> struct eiointc *priv = domain->host_data;
>
> ret = irq_domain_translate_onecell(domain, arg, &hwirq, &type);
> - if (ret)
> - return ret;
> + if (ret < 0)
> + return -EINVAL;
> +
> + if (hwirq >= IOCSR_EXTIOI_VECTOR_NUM)
> + return -EINVAL;

How can this happen? Also, you're allocating a *range*. Surely the
upper boundary should matter too?

And for the umpteenth time, please add a cover letter when sending
multiple patches. This is a hard requirement for me.

Thanks,

M.

--
Without deviation from the norm, progress is not possible.

2022-08-03 07:44:55

by Huacai Chen

[permalink] [raw]
Subject: Re: [PATCH 1/2] irqchip/loongson-eiointc: Check hwirq overflow

Hi, Jianmin,

On Wed, Aug 3, 2022 at 3:20 PM Marc Zyngier <[email protected]> wrote:
>
> On Wed, 03 Aug 2022 05:27:27 +0100,
> Huacai Chen <[email protected]> wrote:
> >
> > Check hwirq overflow when allocate irq in eiointc domain.
> >
> > Signed-off-by: Huacai Chen <[email protected]>
> > ---
> > drivers/irqchip/irq-loongson-eiointc.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
> > index 80d8ca6f2d46..f8060e58ee06 100644
> > --- a/drivers/irqchip/irq-loongson-eiointc.c
> > +++ b/drivers/irqchip/irq-loongson-eiointc.c
> > @@ -241,8 +241,11 @@ static int eiointc_domain_alloc(struct irq_domain *domain, unsigned int virq,
> > struct eiointc *priv = domain->host_data;
> >
> > ret = irq_domain_translate_onecell(domain, arg, &hwirq, &type);
> > - if (ret)
> > - return ret;
> > + if (ret < 0)
> > + return -EINVAL;
> > +
> > + if (hwirq >= IOCSR_EXTIOI_VECTOR_NUM)
> > + return -EINVAL;
>
> How can this happen? Also, you're allocating a *range*. Surely the
> upper boundary should matter too?
Do you know the exact reason? Please give some information, thanks.

>
> And for the umpteenth time, please add a cover letter when sending
> multiple patches. This is a hard requirement for me.
OK, I will add a cover letter, even for simple fix patches. Sorry.

Huacai
>
> Thanks,
>
> M.
>
> --
> Without deviation from the norm, progress is not possible.

2022-08-03 12:05:40

by 吕建民

[permalink] [raw]
Subject: Re: [PATCH 1/2] irqchip/loongson-eiointc: Check hwirq overflow



On 2022/8/3 下午3:33, Huacai Chen wrote:
> Hi, Jianmin,
>
> On Wed, Aug 3, 2022 at 3:20 PM Marc Zyngier <[email protected]> wrote:
>>
>> On Wed, 03 Aug 2022 05:27:27 +0100,
>> Huacai Chen <[email protected]> wrote:
>>>
>>> Check hwirq overflow when allocate irq in eiointc domain.
>>>
>>> Signed-off-by: Huacai Chen <[email protected]>
>>> ---
>>> drivers/irqchip/irq-loongson-eiointc.c | 7 +++++--
>>> 1 file changed, 5 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
>>> index 80d8ca6f2d46..f8060e58ee06 100644
>>> --- a/drivers/irqchip/irq-loongson-eiointc.c
>>> +++ b/drivers/irqchip/irq-loongson-eiointc.c
>>> @@ -241,8 +241,11 @@ static int eiointc_domain_alloc(struct irq_domain *domain, unsigned int virq,
>>> struct eiointc *priv = domain->host_data;
>>>
>>> ret = irq_domain_translate_onecell(domain, arg, &hwirq, &type);
>>> - if (ret)
>>> - return ret;
>>> + if (ret < 0)
>>> + return -EINVAL;
>>> +
>>> + if (hwirq >= IOCSR_EXTIOI_VECTOR_NUM)
>>> + return -EINVAL;
>>
>> How can this happen? Also, you're allocating a *range*. Surely the
>> upper boundary should matter too?
> Do you know the exact reason? Please give some information, thanks.
>

In our internal repo, we don't have middle domain in pch-msi driver, so
no check for hwirq as in alloc of middle domain. When hwirq is assigned
failed(negtive value), the wrong hwirq will be passed to parent
domain(eio domain)'s alloc, so we add check in eio domain's alloc there.


But here, it seems that the check is unnecessary, because in pch-msi driver:

static int pch_msi_middle_domain_alloc(struct irq_domain *domain,
unsigned int virq,
unsigned int nr_irqs, void
*args)
{
struct pch_msi_data *priv = domain->host_data;
int hwirq, err, i;


hwirq = pch_msi_allocate_hwirq(priv, nr_irqs);
if (hwirq < 0)
return hwirq;


for (i = 0; i < nr_irqs; i++) {
err = pch_msi_parent_domain_alloc(domain, virq + i,
hwirq + i);
[...]


If pch_msi_allocate_hwirq failed, pch_msi_middle_domain_alloc will
return, and pch_msi_parent_domain_alloc(will call eio domain's alloc)
will not be called.


>>
>> And for the umpteenth time, please add a cover letter when sending
>> multiple patches. This is a hard requirement for me.
> OK, I will add a cover letter, even for simple fix patches. Sorry.
>
> Huacai
>>
>> Thanks,
>>
>> M.
>>
>> --
>> Without deviation from the norm, progress is not possible.


2022-08-04 03:15:27

by Huacai Chen

[permalink] [raw]
Subject: Re: [PATCH 1/2] irqchip/loongson-eiointc: Check hwirq overflow

On Wed, Aug 3, 2022 at 7:59 PM Jianmin Lv <[email protected]> wrote:
>
>
>
> On 2022/8/3 下午3:33, Huacai Chen wrote:
> > Hi, Jianmin,
> >
> > On Wed, Aug 3, 2022 at 3:20 PM Marc Zyngier <[email protected]> wrote:
> >>
> >> On Wed, 03 Aug 2022 05:27:27 +0100,
> >> Huacai Chen <[email protected]> wrote:
> >>>
> >>> Check hwirq overflow when allocate irq in eiointc domain.
> >>>
> >>> Signed-off-by: Huacai Chen <[email protected]>
> >>> ---
> >>> drivers/irqchip/irq-loongson-eiointc.c | 7 +++++--
> >>> 1 file changed, 5 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
> >>> index 80d8ca6f2d46..f8060e58ee06 100644
> >>> --- a/drivers/irqchip/irq-loongson-eiointc.c
> >>> +++ b/drivers/irqchip/irq-loongson-eiointc.c
> >>> @@ -241,8 +241,11 @@ static int eiointc_domain_alloc(struct irq_domain *domain, unsigned int virq,
> >>> struct eiointc *priv = domain->host_data;
> >>>
> >>> ret = irq_domain_translate_onecell(domain, arg, &hwirq, &type);
> >>> - if (ret)
> >>> - return ret;
> >>> + if (ret < 0)
> >>> + return -EINVAL;
> >>> +
> >>> + if (hwirq >= IOCSR_EXTIOI_VECTOR_NUM)
> >>> + return -EINVAL;
> >>
> >> How can this happen? Also, you're allocating a *range*. Surely the
> >> upper boundary should matter too?
> > Do you know the exact reason? Please give some information, thanks.
> >
>
> In our internal repo, we don't have middle domain in pch-msi driver, so
> no check for hwirq as in alloc of middle domain. When hwirq is assigned
> failed(negtive value), the wrong hwirq will be passed to parent
> domain(eio domain)'s alloc, so we add check in eio domain's alloc there.
>
>
> But here, it seems that the check is unnecessary, because in pch-msi driver:
>
> static int pch_msi_middle_domain_alloc(struct irq_domain *domain,
> unsigned int virq,
> unsigned int nr_irqs, void
> *args)
> {
> struct pch_msi_data *priv = domain->host_data;
> int hwirq, err, i;
>
>
> hwirq = pch_msi_allocate_hwirq(priv, nr_irqs);
> if (hwirq < 0)
> return hwirq;
>
>
> for (i = 0; i < nr_irqs; i++) {
> err = pch_msi_parent_domain_alloc(domain, virq + i,
> hwirq + i);
> [...]
>
>
> If pch_msi_allocate_hwirq failed, pch_msi_middle_domain_alloc will
> return, and pch_msi_parent_domain_alloc(will call eio domain's alloc)
> will not be called.
OK, then this patch can be removed and I only need to send the 2nd one. Thanks.

Huacai

>
>
> >>
> >> And for the umpteenth time, please add a cover letter when sending
> >> multiple patches. This is a hard requirement for me.
> > OK, I will add a cover letter, even for simple fix patches. Sorry.
> >
> > Huacai
> >>
> >> Thanks,
> >>
> >> M.
> >>
> >> --
> >> Without deviation from the norm, progress is not possible.
>
>