2022-02-14 17:38:08

by Zhang, Tianfei

[permalink] [raw]
Subject: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info

From: Tianfei Zhang <[email protected]>

The feature ID of "Port User Interrupt" and the
"PMCI Subsystem" are identical, 0x12, but one is for FME,
other is for Port. It should check the feature type While
parsing the irq info in parse_feature_irqs().

Signed-off-by: Tianfei Zhang <[email protected]>
---
drivers/fpga/dfl.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index 599bb21d86af..26f8cf890700 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -940,9 +940,14 @@ static int parse_feature_irqs(struct build_feature_devs_info *binfo,
{
void __iomem *base = binfo->ioaddr + ofst;
unsigned int i, ibase, inr = 0;
+ enum dfl_id_type type;
int virq;
u64 v;

+ type = feature_dev_id_type(binfo->feature_dev);
+ if (type >= DFL_ID_MAX)
+ return -EINVAL;
+
/*
* Ideally DFL framework should only read info from DFL header, but
* current version DFL only provides mmio resources information for
@@ -959,16 +964,22 @@ static int parse_feature_irqs(struct build_feature_devs_info *binfo,
*/
switch (fid) {
case PORT_FEATURE_ID_UINT:
+ if (type != PORT_ID)
+ break;
v = readq(base + PORT_UINT_CAP);
ibase = FIELD_GET(PORT_UINT_CAP_FST_VECT, v);
inr = FIELD_GET(PORT_UINT_CAP_INT_NUM, v);
break;
case PORT_FEATURE_ID_ERROR:
+ if (type != PORT_ID)
+ break;
v = readq(base + PORT_ERROR_CAP);
ibase = FIELD_GET(PORT_ERROR_CAP_INT_VECT, v);
inr = FIELD_GET(PORT_ERROR_CAP_SUPP_INT, v);
break;
case FME_FEATURE_ID_GLOBAL_ERR:
+ if (type != FME_ID)
+ break;
v = readq(base + FME_ERROR_CAP);
ibase = FIELD_GET(FME_ERROR_CAP_INT_VECT, v);
inr = FIELD_GET(FME_ERROR_CAP_SUPP_INT, v);
--
2.17.1


2022-02-15 20:47:54

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info


On 2/14/22 3:26 AM, Tianfei zhang wrote:
> From: Tianfei Zhang <[email protected]>
>
> The feature ID of "Port User Interrupt" and the
> "PMCI Subsystem" are identical, 0x12, but one is for FME,
> other is for Port. It should check the feature type While
> parsing the irq info in parse_feature_irqs().

This seems like a bug fix and not part of iofs feature.

Split this out of the patchset.

This is a workaround a hardware problem, there should be some comments
to the effect that you can't trust _this_ or _that_ feature id and some
special handling earlier.

The ambiguity of feature id is a problem, and this sort of bug will
happen again.

What can be done to prevent this in the future ?

>
> Signed-off-by: Tianfei Zhang <[email protected]>
> ---
> drivers/fpga/dfl.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> index 599bb21d86af..26f8cf890700 100644
> --- a/drivers/fpga/dfl.c
> +++ b/drivers/fpga/dfl.c
> @@ -940,9 +940,14 @@ static int parse_feature_irqs(struct build_feature_devs_info *binfo,
> {
> void __iomem *base = binfo->ioaddr + ofst;
> unsigned int i, ibase, inr = 0;
> + enum dfl_id_type type;
> int virq;
> u64 v;
>
> + type = feature_dev_id_type(binfo->feature_dev);
> + if (type >= DFL_ID_MAX)
> + return -EINVAL;
> +
> /*
> * Ideally DFL framework should only read info from DFL header, but
> * current version DFL only provides mmio resources information for
> @@ -959,16 +964,22 @@ static int parse_feature_irqs(struct build_feature_devs_info *binfo,
> */
> switch (fid) {
> case PORT_FEATURE_ID_UINT:
> + if (type != PORT_ID)
> + break;

Instead of embedding a break in the switch, break the switch into fme
switch and port switch

if (type == PORT_ID)

  port-switch

else if (type == FME_ID

  fme-switch

Tom

> v = readq(base + PORT_UINT_CAP);
> ibase = FIELD_GET(PORT_UINT_CAP_FST_VECT, v);
> inr = FIELD_GET(PORT_UINT_CAP_INT_NUM, v);
> break;
> case PORT_FEATURE_ID_ERROR:
> + if (type != PORT_ID)
> + break;
> v = readq(base + PORT_ERROR_CAP);
> ibase = FIELD_GET(PORT_ERROR_CAP_INT_VECT, v);
> inr = FIELD_GET(PORT_ERROR_CAP_SUPP_INT, v);
> break;
> case FME_FEATURE_ID_GLOBAL_ERR:
> + if (type != FME_ID)
> + break;
> v = readq(base + FME_ERROR_CAP);
> ibase = FIELD_GET(FME_ERROR_CAP_INT_VECT, v);
> inr = FIELD_GET(FME_ERROR_CAP_SUPP_INT, v);

2022-02-16 07:07:44

by Wu Hao

[permalink] [raw]
Subject: Re: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info

> Subject: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info
>
> From: Tianfei Zhang <[email protected]>
>
> The feature ID of "Port User Interrupt" and the
> "PMCI Subsystem" are identical, 0x12, but one is for FME,
> other is for Port. It should check the feature type While
> parsing the irq info in parse_feature_irqs().
>
> Signed-off-by: Tianfei Zhang <[email protected]>
> ---
> drivers/fpga/dfl.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> index 599bb21d86af..26f8cf890700 100644
> --- a/drivers/fpga/dfl.c
> +++ b/drivers/fpga/dfl.c
> @@ -940,9 +940,14 @@ static int parse_feature_irqs(struct
> build_feature_devs_info *binfo,
> {
> void __iomem *base = binfo->ioaddr + ofst;
> unsigned int i, ibase, inr = 0;
> + enum dfl_id_type type;
> int virq;
> u64 v;
>
> + type = feature_dev_id_type(binfo->feature_dev);
> + if (type >= DFL_ID_MAX)
> + return -EINVAL;
> +

You don't have to check this, it doesn't allow creating feature dev with type >= DFL_ID_MAX.

> /*
> * Ideally DFL framework should only read info from DFL header, but
> * current version DFL only provides mmio resources information for
> @@ -959,16 +964,22 @@ static int parse_feature_irqs(struct
> build_feature_devs_info *binfo,
> */
> switch (fid) {
> case PORT_FEATURE_ID_UINT:
> + if (type != PORT_ID)
> + break;
> v = readq(base + PORT_UINT_CAP);
> ibase = FIELD_GET(PORT_UINT_CAP_FST_VECT, v);
> inr = FIELD_GET(PORT_UINT_CAP_INT_NUM, v);
> break;
> case PORT_FEATURE_ID_ERROR:
> + if (type != PORT_ID)
> + break;
> v = readq(base + PORT_ERROR_CAP);
> ibase = FIELD_GET(PORT_ERROR_CAP_INT_VECT, v);
> inr = FIELD_GET(PORT_ERROR_CAP_SUPP_INT, v);
> break;
> case FME_FEATURE_ID_GLOBAL_ERR:
> + if (type != FME_ID)
> + break;
> v = readq(base + FME_ERROR_CAP);
> ibase = FIELD_GET(FME_ERROR_CAP_INT_VECT, v);
> inr = FIELD_GET(FME_ERROR_CAP_SUPP_INT, v);
> --
> 2.17.1

2022-02-17 14:22:17

by Xu Yilun

[permalink] [raw]
Subject: Re: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info

On Tue, Feb 15, 2022 at 06:49:05AM -0800, Tom Rix wrote:
>
> On 2/14/22 3:26 AM, Tianfei zhang wrote:
> > From: Tianfei Zhang <[email protected]>
> >
> > The feature ID of "Port User Interrupt" and the
> > "PMCI Subsystem" are identical, 0x12, but one is for FME,
> > other is for Port. It should check the feature type While
> > parsing the irq info in parse_feature_irqs().
>
> This seems like a bug fix and not part of iofs feature.
>
> Split this out of the patchset.
>
> This is a workaround a hardware problem, there should be some comments to
> the effect that you can't trust _this_ or _that_ feature id and some special
> handling earlier.
>
> The ambiguity of feature id is a problem, and this sort of bug will happen

Actually this is not the feature id definition problem. The identity of the
feature is determined by the dfl_id_type(FME, PORT) AND feature_id. So the
driver should match the dfl_id_type & feature_id to know what feature it
is.

Thanks,
Yilun

> again.
>
> What can be done to prevent this in the future ?
>
> >
> > Signed-off-by: Tianfei Zhang <[email protected]>
> > ---
> > drivers/fpga/dfl.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> > index 599bb21d86af..26f8cf890700 100644
> > --- a/drivers/fpga/dfl.c
> > +++ b/drivers/fpga/dfl.c
> > @@ -940,9 +940,14 @@ static int parse_feature_irqs(struct build_feature_devs_info *binfo,
> > {
> > void __iomem *base = binfo->ioaddr + ofst;
> > unsigned int i, ibase, inr = 0;
> > + enum dfl_id_type type;
> > int virq;
> > u64 v;
> > + type = feature_dev_id_type(binfo->feature_dev);
> > + if (type >= DFL_ID_MAX)
> > + return -EINVAL;
> > +
> > /*
> > * Ideally DFL framework should only read info from DFL header, but
> > * current version DFL only provides mmio resources information for
> > @@ -959,16 +964,22 @@ static int parse_feature_irqs(struct build_feature_devs_info *binfo,
> > */
> > switch (fid) {
> > case PORT_FEATURE_ID_UINT:
> > + if (type != PORT_ID)
> > + break;
>
> Instead of embedding a break in the switch, break the switch into fme switch
> and port switch
>
> if (type == PORT_ID)
>
> ? port-switch
>
> else if (type == FME_ID
>
> ? fme-switch
>
> Tom
>
> > v = readq(base + PORT_UINT_CAP);
> > ibase = FIELD_GET(PORT_UINT_CAP_FST_VECT, v);
> > inr = FIELD_GET(PORT_UINT_CAP_INT_NUM, v);
> > break;
> > case PORT_FEATURE_ID_ERROR:
> > + if (type != PORT_ID)
> > + break;
> > v = readq(base + PORT_ERROR_CAP);
> > ibase = FIELD_GET(PORT_ERROR_CAP_INT_VECT, v);
> > inr = FIELD_GET(PORT_ERROR_CAP_SUPP_INT, v);
> > break;
> > case FME_FEATURE_ID_GLOBAL_ERR:
> > + if (type != FME_ID)
> > + break;
> > v = readq(base + FME_ERROR_CAP);
> > ibase = FIELD_GET(FME_ERROR_CAP_INT_VECT, v);
> > inr = FIELD_GET(FME_ERROR_CAP_SUPP_INT, v);

2022-02-18 07:07:28

by Zhang, Tianfei

[permalink] [raw]
Subject: RE: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info



> -----Original Message-----
> From: Tom Rix <[email protected]>
> Sent: Tuesday, February 15, 2022 10:49 PM
> To: Zhang, Tianfei <[email protected]>; Wu, Hao <[email protected]>;
> [email protected]; Xu, Yilun <[email protected]>; [email protected];
> [email protected]; [email protected]
> Cc: [email protected]
> Subject: Re: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info
>
>
> On 2/14/22 3:26 AM, Tianfei zhang wrote:
> > From: Tianfei Zhang <[email protected]>
> >
> > The feature ID of "Port User Interrupt" and the "PMCI Subsystem" are
> > identical, 0x12, but one is for FME, other is for Port. It should
> > check the feature type While parsing the irq info in
> > parse_feature_irqs().
>
> This seems like a bug fix and not part of iofs feature.
>
> Split this out of the patchset.
>
> This is a workaround a hardware problem, there should be some comments to
> the effect that you can't trust _this_ or _that_ feature id and some special
> handling earlier.
>
> The ambiguity of feature id is a problem, and this sort of bug will happen again.
>
> What can be done to prevent this in the future ?

This patch is not workaround, this is a bug fix for DFL driver.
The root cause is that DLF driver miss check the feature type while parsing the interrupt information,
because some Feature IDs are identical between FME and Port, like PMCI in FME and "Port User Interrupt"
in Port.
The definition of Feature ID is here:
https://github.com/OPAE/linux-dfl-feature-id/blob/master/dfl-feature-ids.rst

>
> >
> > Signed-off-by: Tianfei Zhang <[email protected]>
> > ---
> > drivers/fpga/dfl.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c index
> > 599bb21d86af..26f8cf890700 100644
> > --- a/drivers/fpga/dfl.c
> > +++ b/drivers/fpga/dfl.c
> > @@ -940,9 +940,14 @@ static int parse_feature_irqs(struct
> build_feature_devs_info *binfo,
> > {
> > void __iomem *base = binfo->ioaddr + ofst;
> > unsigned int i, ibase, inr = 0;
> > + enum dfl_id_type type;
> > int virq;
> > u64 v;
> >
> > + type = feature_dev_id_type(binfo->feature_dev);
> > + if (type >= DFL_ID_MAX)
> > + return -EINVAL;
> > +
> > /*
> > * Ideally DFL framework should only read info from DFL header, but
> > * current version DFL only provides mmio resources information for
> > @@ -959,16 +964,22 @@ static int parse_feature_irqs(struct
> build_feature_devs_info *binfo,
> > */
> > switch (fid) {
> > case PORT_FEATURE_ID_UINT:
> > + if (type != PORT_ID)
> > + break;
>
> Instead of embedding a break in the switch, break the switch into fme switch
> and port switch
>
> if (type == PORT_ID)
>
>   port-switch
>
> else if (type == FME_ID
>
>   fme-switch

Your suggestion is looks good for me, I will change on next version.

>
> Tom
>
> > v = readq(base + PORT_UINT_CAP);
> > ibase = FIELD_GET(PORT_UINT_CAP_FST_VECT, v);
> > inr = FIELD_GET(PORT_UINT_CAP_INT_NUM, v);
> > break;
> > case PORT_FEATURE_ID_ERROR:
> > + if (type != PORT_ID)
> > + break;
> > v = readq(base + PORT_ERROR_CAP);
> > ibase = FIELD_GET(PORT_ERROR_CAP_INT_VECT, v);
> > inr = FIELD_GET(PORT_ERROR_CAP_SUPP_INT, v);
> > break;
> > case FME_FEATURE_ID_GLOBAL_ERR:
> > + if (type != FME_ID)
> > + break;
> > v = readq(base + FME_ERROR_CAP);
> > ibase = FIELD_GET(FME_ERROR_CAP_INT_VECT, v);
> > inr = FIELD_GET(FME_ERROR_CAP_SUPP_INT, v);

2022-02-18 14:55:40

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info


On 2/17/22 10:53 PM, Zhang, Tianfei wrote:
>
>> -----Original Message-----
>> From: Tom Rix <[email protected]>
>> Sent: Tuesday, February 15, 2022 10:49 PM
>> To: Zhang, Tianfei <[email protected]>; Wu, Hao <[email protected]>;
>> [email protected]; Xu, Yilun <[email protected]>; [email protected];
>> [email protected]; [email protected]
>> Cc: [email protected]
>> Subject: Re: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info
>>
>>
>> On 2/14/22 3:26 AM, Tianfei zhang wrote:
>>> From: Tianfei Zhang <[email protected]>
>>>
>>> The feature ID of "Port User Interrupt" and the "PMCI Subsystem" are
>>> identical, 0x12, but one is for FME, other is for Port. It should
>>> check the feature type While parsing the irq info in
>>> parse_feature_irqs().
>> This seems like a bug fix and not part of iofs feature.
>>
>> Split this out of the patchset.

?

>>
>> This is a workaround a hardware problem, there should be some comments to
>> the effect that you can't trust _this_ or _that_ feature id and some special
>> handling earlier.
>>
>> The ambiguity of feature id is a problem, and this sort of bug will happen again.
>>
>> What can be done to prevent this in the future ?
> This patch is not workaround, this is a bug fix for DFL driver.
> The root cause is that DLF driver miss check the feature type while parsing the interrupt information,
> because some Feature IDs are identical between FME and Port, like PMCI in FME and "Port User Interrupt"
> in Port.
> The definition of Feature ID is here:
> https://github.com/OPAE/linux-dfl-feature-id/blob/master/dfl-feature-ids.rst
Helpful but hidden.  At least a link to this should be added to
Documentation/fpga/dfl.rst.
>>> Signed-off-by: Tianfei Zhang <[email protected]>
>>> ---
>>> drivers/fpga/dfl.c | 11 +++++++++++
>>> 1 file changed, 11 insertions(+)
>>>
>>> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c index
>>> 599bb21d86af..26f8cf890700 100644
>>> --- a/drivers/fpga/dfl.c
>>> +++ b/drivers/fpga/dfl.c
>>> @@ -940,9 +940,14 @@ static int parse_feature_irqs(struct
>> build_feature_devs_info *binfo,
>>> {
>>> void __iomem *base = binfo->ioaddr + ofst;
>>> unsigned int i, ibase, inr = 0;
>>> + enum dfl_id_type type;
>>> int virq;
>>> u64 v;
>>>
>>> + type = feature_dev_id_type(binfo->feature_dev);
>>> + if (type >= DFL_ID_MAX)
>>> + return -EINVAL;
>>> +
>>> /*
>>> * Ideally DFL framework should only read info from DFL header, but
>>> * current version DFL only provides mmio resources information for
>>> @@ -959,16 +964,22 @@ static int parse_feature_irqs(struct
>> build_feature_devs_info *binfo,
>>> */
>>> switch (fid) {
>>> case PORT_FEATURE_ID_UINT:
>>> + if (type != PORT_ID)
>>> + break;
>> Instead of embedding a break in the switch, break the switch into fme switch
>> and port switch
>>
>> if (type == PORT_ID)
>>
>>   port-switch
>>
>> else if (type == FME_ID
>>
>>   fme-switch
> Your suggestion is looks good for me, I will change on next version.
>
>> Tom
>>
>>> v = readq(base + PORT_UINT_CAP);
>>> ibase = FIELD_GET(PORT_UINT_CAP_FST_VECT, v);
>>> inr = FIELD_GET(PORT_UINT_CAP_INT_NUM, v);
>>> break;
>>> case PORT_FEATURE_ID_ERROR:
>>> + if (type != PORT_ID)
>>> + break;
>>> v = readq(base + PORT_ERROR_CAP);
>>> ibase = FIELD_GET(PORT_ERROR_CAP_INT_VECT, v);
>>> inr = FIELD_GET(PORT_ERROR_CAP_SUPP_INT, v);
>>> break;
>>> case FME_FEATURE_ID_GLOBAL_ERR:
>>> + if (type != FME_ID)
>>> + break;
>>> v = readq(base + FME_ERROR_CAP);
>>> ibase = FIELD_GET(FME_ERROR_CAP_INT_VECT, v);
>>> inr = FIELD_GET(FME_ERROR_CAP_SUPP_INT, v);

2022-02-21 08:42:59

by Zhang, Tianfei

[permalink] [raw]
Subject: RE: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info



> -----Original Message-----
> From: Xu, Yilun <[email protected]>
> Sent: Thursday, February 17, 2022 10:38 AM
> To: Tom Rix <[email protected]>
> Cc: Zhang, Tianfei <[email protected]>; Wu, Hao <[email protected]>;
> [email protected]; [email protected]; [email protected]; linux-
> [email protected]; [email protected]
> Subject: Re: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info
>
> On Tue, Feb 15, 2022 at 06:49:05AM -0800, Tom Rix wrote:
> >
> > On 2/14/22 3:26 AM, Tianfei zhang wrote:
> > > From: Tianfei Zhang <[email protected]>
> > >
> > > The feature ID of "Port User Interrupt" and the "PMCI Subsystem" are
> > > identical, 0x12, but one is for FME, other is for Port. It should
> > > check the feature type While parsing the irq info in
> > > parse_feature_irqs().
> >
> > This seems like a bug fix and not part of iofs feature.
> >
> > Split this out of the patchset.
> >
> > This is a workaround a hardware problem, there should be some comments
> > to the effect that you can't trust _this_ or _that_ feature id and
> > some special handling earlier.
> >
> > The ambiguity of feature id is a problem, and this sort of bug will
> > happen
>
> Actually this is not the feature id definition problem. The identity of the feature
> is determined by the dfl_id_type(FME, PORT) AND feature_id. So the driver
> should match the dfl_id_type & feature_id to know what feature it is.

In this function flow, create_feature_instance() -> parse_feature_irqs(), the DFL driver has not
check the dfl_id_type yet.

>
> Thanks,
> Yilun
>
> > again.
> >
> > What can be done to prevent this in the future ?
> >
> > >
> > > Signed-off-by: Tianfei Zhang <[email protected]>
> > > ---
> > > drivers/fpga/dfl.c | 11 +++++++++++
> > > 1 file changed, 11 insertions(+)
> > >
> > > diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c index
> > > 599bb21d86af..26f8cf890700 100644
> > > --- a/drivers/fpga/dfl.c
> > > +++ b/drivers/fpga/dfl.c
> > > @@ -940,9 +940,14 @@ static int parse_feature_irqs(struct
> build_feature_devs_info *binfo,
> > > {
> > > void __iomem *base = binfo->ioaddr + ofst;
> > > unsigned int i, ibase, inr = 0;
> > > + enum dfl_id_type type;
> > > int virq;
> > > u64 v;
> > > + type = feature_dev_id_type(binfo->feature_dev);
> > > + if (type >= DFL_ID_MAX)
> > > + return -EINVAL;
> > > +
> > > /*
> > > * Ideally DFL framework should only read info from DFL header, but
> > > * current version DFL only provides mmio resources information
> > > for @@ -959,16 +964,22 @@ static int parse_feature_irqs(struct
> build_feature_devs_info *binfo,
> > > */
> > > switch (fid) {
> > > case PORT_FEATURE_ID_UINT:
> > > + if (type != PORT_ID)
> > > + break;
> >
> > Instead of embedding a break in the switch, break the switch into fme
> > switch and port switch
> >
> > if (type == PORT_ID)
> >
> > ? port-switch
> >
> > else if (type == FME_ID
> >
> > ? fme-switch
> >
> > Tom
> >
> > > v = readq(base + PORT_UINT_CAP);
> > > ibase = FIELD_GET(PORT_UINT_CAP_FST_VECT, v);
> > > inr = FIELD_GET(PORT_UINT_CAP_INT_NUM, v);
> > > break;
> > > case PORT_FEATURE_ID_ERROR:
> > > + if (type != PORT_ID)
> > > + break;
> > > v = readq(base + PORT_ERROR_CAP);
> > > ibase = FIELD_GET(PORT_ERROR_CAP_INT_VECT, v);
> > > inr = FIELD_GET(PORT_ERROR_CAP_SUPP_INT, v);
> > > break;
> > > case FME_FEATURE_ID_GLOBAL_ERR:
> > > + if (type != FME_ID)
> > > + break;
> > > v = readq(base + FME_ERROR_CAP);
> > > ibase = FIELD_GET(FME_ERROR_CAP_INT_VECT, v);
> > > inr = FIELD_GET(FME_ERROR_CAP_SUPP_INT, v);

2022-02-21 09:13:25

by Zhang, Tianfei

[permalink] [raw]
Subject: RE: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info



> -----Original Message-----
> From: Wu, Hao <[email protected]>
> Sent: Wednesday, February 16, 2022 11:35 AM
> To: Zhang, Tianfei <[email protected]>; [email protected];
> [email protected]; Xu, Yilun <[email protected]>; [email protected];
> [email protected]; [email protected]
> Cc: [email protected]
> Subject: Re: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info
>
> > Subject: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq
> > info
> >
> > From: Tianfei Zhang <[email protected]>
> >
> > The feature ID of "Port User Interrupt" and the "PMCI Subsystem" are
> > identical, 0x12, but one is for FME, other is for Port. It should
> > check the feature type While parsing the irq info in
> > parse_feature_irqs().
> >
> > Signed-off-by: Tianfei Zhang <[email protected]>
> > ---
> > drivers/fpga/dfl.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c index
> > 599bb21d86af..26f8cf890700 100644
> > --- a/drivers/fpga/dfl.c
> > +++ b/drivers/fpga/dfl.c
> > @@ -940,9 +940,14 @@ static int parse_feature_irqs(struct
> > build_feature_devs_info *binfo, {
> > void __iomem *base = binfo->ioaddr + ofst;
> > unsigned int i, ibase, inr = 0;
> > + enum dfl_id_type type;
> > int virq;
> > u64 v;
> >
> > + type = feature_dev_id_type(binfo->feature_dev);
> > + if (type >= DFL_ID_MAX)
> > + return -EINVAL;
> > +
>
> You don't have to check this, it doesn't allow creating feature dev with type >=
> DFL_ID_MAX.

I agree, I will fix on next version.

>
> > /*
> > * Ideally DFL framework should only read info from DFL header, but
> > * current version DFL only provides mmio resources information for
> > @@ -959,16 +964,22 @@ static int parse_feature_irqs(struct
> > build_feature_devs_info *binfo,
> > */
> > switch (fid) {
> > case PORT_FEATURE_ID_UINT:
> > + if (type != PORT_ID)
> > + break;
> > v = readq(base + PORT_UINT_CAP);
> > ibase = FIELD_GET(PORT_UINT_CAP_FST_VECT, v);
> > inr = FIELD_GET(PORT_UINT_CAP_INT_NUM, v);
> > break;
> > case PORT_FEATURE_ID_ERROR:
> > + if (type != PORT_ID)
> > + break;
> > v = readq(base + PORT_ERROR_CAP);
> > ibase = FIELD_GET(PORT_ERROR_CAP_INT_VECT, v);
> > inr = FIELD_GET(PORT_ERROR_CAP_SUPP_INT, v);
> > break;
> > case FME_FEATURE_ID_GLOBAL_ERR:
> > + if (type != FME_ID)
> > + break;
> > v = readq(base + FME_ERROR_CAP);
> > ibase = FIELD_GET(FME_ERROR_CAP_INT_VECT, v);
> > inr = FIELD_GET(FME_ERROR_CAP_SUPP_INT, v);
> > --
> > 2.17.1

2022-02-21 17:50:12

by Zhang, Tianfei

[permalink] [raw]
Subject: RE: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info



> -----Original Message-----
> From: Tom Rix <[email protected]>
> Sent: Friday, February 18, 2022 10:30 PM
> To: Zhang, Tianfei <[email protected]>; Wu, Hao <[email protected]>;
> [email protected]; Xu, Yilun <[email protected]>; [email protected];
> [email protected]; [email protected]
> Cc: [email protected]
> Subject: Re: [PATCH v1 2/7] fpga: dfl: check feature type before parse irq info
>
>
> On 2/17/22 10:53 PM, Zhang, Tianfei wrote:
> >
> >> -----Original Message-----
> >> From: Tom Rix <[email protected]>
> >> Sent: Tuesday, February 15, 2022 10:49 PM
> >> To: Zhang, Tianfei <[email protected]>; Wu, Hao
> >> <[email protected]>; [email protected]; Xu, Yilun <[email protected]>;
> >> [email protected]; [email protected];
> >> [email protected]
> >> Cc: [email protected]
> >> Subject: Re: [PATCH v1 2/7] fpga: dfl: check feature type before
> >> parse irq info
> >>
> >>
> >> On 2/14/22 3:26 AM, Tianfei zhang wrote:
> >>> From: Tianfei Zhang <[email protected]>
> >>>
> >>> The feature ID of "Port User Interrupt" and the "PMCI Subsystem" are
> >>> identical, 0x12, but one is for FME, other is for Port. It should
> >>> check the feature type While parsing the irq info in
> >>> parse_feature_irqs().
> >> This seems like a bug fix and not part of iofs feature.
> >>
> >> Split this out of the patchset.
>
> ?

I agree, I will send this patch as a bug fix.

>
> >>
> >> This is a workaround a hardware problem, there should be some
> >> comments to the effect that you can't trust _this_ or _that_ feature
> >> id and some special handling earlier.
> >>
> >> The ambiguity of feature id is a problem, and this sort of bug will happen
> again.
> >>
> >> What can be done to prevent this in the future ?
> > This patch is not workaround, this is a bug fix for DFL driver.
> > The root cause is that DLF driver miss check the feature type while
> > parsing the interrupt information, because some Feature IDs are identical
> between FME and Port, like PMCI in FME and "Port User Interrupt"
> > in Port.
> > The definition of Feature ID is here:
> > https://github.com/OPAE/linux-dfl-feature-id/blob/master/dfl-feature-i
> > ds.rst
> Helpful but hidden.  At least a link to this should be added to
> Documentation/fpga/dfl.rst.
> >>> Signed-off-by: Tianfei Zhang <[email protected]>
> >>> ---
> >>> drivers/fpga/dfl.c | 11 +++++++++++
> >>> 1 file changed, 11 insertions(+)
> >>>
> >>> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c index
> >>> 599bb21d86af..26f8cf890700 100644
> >>> --- a/drivers/fpga/dfl.c
> >>> +++ b/drivers/fpga/dfl.c
> >>> @@ -940,9 +940,14 @@ static int parse_feature_irqs(struct
> >> build_feature_devs_info *binfo,
> >>> {
> >>> void __iomem *base = binfo->ioaddr + ofst;
> >>> unsigned int i, ibase, inr = 0;
> >>> + enum dfl_id_type type;
> >>> int virq;
> >>> u64 v;
> >>>
> >>> + type = feature_dev_id_type(binfo->feature_dev);
> >>> + if (type >= DFL_ID_MAX)
> >>> + return -EINVAL;
> >>> +
> >>> /*
> >>> * Ideally DFL framework should only read info from DFL header, but
> >>> * current version DFL only provides mmio resources information
> >>> for @@ -959,16 +964,22 @@ static int parse_feature_irqs(struct
> >> build_feature_devs_info *binfo,
> >>> */
> >>> switch (fid) {
> >>> case PORT_FEATURE_ID_UINT:
> >>> + if (type != PORT_ID)
> >>> + break;
> >> Instead of embedding a break in the switch, break the switch into fme
> >> switch and port switch
> >>
> >> if (type == PORT_ID)
> >>
> >>   port-switch
> >>
> >> else if (type == FME_ID
> >>
> >>   fme-switch
> > Your suggestion is looks good for me, I will change on next version.
> >
> >> Tom
> >>
> >>> v = readq(base + PORT_UINT_CAP);
> >>> ibase = FIELD_GET(PORT_UINT_CAP_FST_VECT, v);
> >>> inr = FIELD_GET(PORT_UINT_CAP_INT_NUM, v);
> >>> break;
> >>> case PORT_FEATURE_ID_ERROR:
> >>> + if (type != PORT_ID)
> >>> + break;
> >>> v = readq(base + PORT_ERROR_CAP);
> >>> ibase = FIELD_GET(PORT_ERROR_CAP_INT_VECT, v);
> >>> inr = FIELD_GET(PORT_ERROR_CAP_SUPP_INT, v);
> >>> break;
> >>> case FME_FEATURE_ID_GLOBAL_ERR:
> >>> + if (type != FME_ID)
> >>> + break;
> >>> v = readq(base + FME_ERROR_CAP);
> >>> ibase = FIELD_GET(FME_ERROR_CAP_INT_VECT, v);
> >>> inr = FIELD_GET(FME_ERROR_CAP_SUPP_INT, v);