diff mbox series

[1/1] fpga: dfl: Avoid reads to AFU CSRs during enumeration

Message ID 20210916210733.153388-1-russell.h.weight@intel.com (mailing list archive)
State New
Headers show
Series [1/1] fpga: dfl: Avoid reads to AFU CSRs during enumeration | expand

Commit Message

Russ Weight Sept. 16, 2021, 9:07 p.m. UTC
CSR address space for Accelerator Functional Units (AFU) is not available
during the early Device Feature List (DFL) enumeration. Early access
to this space results in invalid data and port errors. This change adds
a condition to prevent an early read from the AFU CSR space.

Signed-off-by: Russ Weight <russell.h.weight@intel.com>

Fixes: 23bcda750558 ("fpga: dfl: expose feature revision from struct
dfl_device")
Cc: stable@vger.kernel.org
---
 drivers/fpga/dfl.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Comments

Moritz Fischer Sept. 16, 2021, 10:24 p.m. UTC | #1
On Thu, Sep 16, 2021 at 02:07:33PM -0700, Russ Weight wrote:
> CSR address space for Accelerator Functional Units (AFU) is not available
> during the early Device Feature List (DFL) enumeration. Early access
> to this space results in invalid data and port errors. This change adds
> a condition to prevent an early read from the AFU CSR space.
> 
> Signed-off-by: Russ Weight <russell.h.weight@intel.com>
> 
> Fixes: 23bcda750558 ("fpga: dfl: expose feature revision from struct
> dfl_device")
Did you mean:

Fixes: 1604986c3e6b ("fpga: dfl: expose feature revision from struct dfl_device")

And for future please don't line break those, or we'll get yelled at :)

I can locally fix it up, no need to resubmit

- Moritz
Russ Weight Sept. 16, 2021, 10:34 p.m. UTC | #2
On 9/16/21 3:24 PM, Moritz Fischer wrote:
> On Thu, Sep 16, 2021 at 02:07:33PM -0700, Russ Weight wrote:
>> CSR address space for Accelerator Functional Units (AFU) is not available
>> during the early Device Feature List (DFL) enumeration. Early access
>> to this space results in invalid data and port errors. This change adds
>> a condition to prevent an early read from the AFU CSR space.
>>
>> Signed-off-by: Russ Weight <russell.h.weight@intel.com>
>>
>> Fixes: 23bcda750558 ("fpga: dfl: expose feature revision from struct
>> dfl_device")
> Did you mean:
>
> Fixes: 1604986c3e6b ("fpga: dfl: expose feature revision from struct dfl_device")
Oops - I must have been looking at the wrong branch. Yes - you have the
correct commit ID
>
> And for future please don't line break those, or we'll get yelled at :)
Got it.

Thanks!
- Russ
>
> I can locally fix it up, no need to resubmit
>
> - Moritz
Moritz Fischer Sept. 16, 2021, 10:50 p.m. UTC | #3
On Thu, Sep 16, 2021 at 03:34:39PM -0700, Russ Weight wrote:
> 
> On 9/16/21 3:24 PM, Moritz Fischer wrote:
> > On Thu, Sep 16, 2021 at 02:07:33PM -0700, Russ Weight wrote:
> >> CSR address space for Accelerator Functional Units (AFU) is not available
> >> during the early Device Feature List (DFL) enumeration. Early access
> >> to this space results in invalid data and port errors. This change adds
> >> a condition to prevent an early read from the AFU CSR space.
> >>
> >> Signed-off-by: Russ Weight <russell.h.weight@intel.com>
> >>
> >> Fixes: 23bcda750558 ("fpga: dfl: expose feature revision from struct
> >> dfl_device")
> > Did you mean:
> >
> > Fixes: 1604986c3e6b ("fpga: dfl: expose feature revision from struct dfl_device")
> Oops - I must have been looking at the wrong branch. Yes - you have the
> correct commit ID
> >
> > And for future please don't line break those, or we'll get yelled at :)
> Got it.
> 
> Thanks!
> - Russ
> >
> > I can locally fix it up, no need to resubmit
> >
> > - Moritz
> 
Applied w/changes to fixes,

- Moritz
Greg Kroah-Hartman Sept. 17, 2021, 5:42 a.m. UTC | #4
On Thu, Sep 16, 2021 at 02:07:33PM -0700, Russ Weight wrote:
> CSR address space for Accelerator Functional Units (AFU) is not available
> during the early Device Feature List (DFL) enumeration. Early access
> to this space results in invalid data and port errors. This change adds
> a condition to prevent an early read from the AFU CSR space.
> 
> Signed-off-by: Russ Weight <russell.h.weight@intel.com>
> 
> Fixes: 23bcda750558 ("fpga: dfl: expose feature revision from struct
> dfl_device")

Nit, please keep this all on one line or our tools will complain about
it when we commit it to our trees :(

thanks,

greg k-h
Moritz Fischer Sept. 17, 2021, 4:26 p.m. UTC | #5
On Fri, Sep 17, 2021 at 07:42:28AM +0200, Greg KH wrote:
> On Thu, Sep 16, 2021 at 02:07:33PM -0700, Russ Weight wrote:
> > CSR address space for Accelerator Functional Units (AFU) is not available
> > during the early Device Feature List (DFL) enumeration. Early access
> > to this space results in invalid data and port errors. This change adds
> > a condition to prevent an early read from the AFU CSR space.
> > 
> > Signed-off-by: Russ Weight <russell.h.weight@intel.com>
> > 
> > Fixes: 23bcda750558 ("fpga: dfl: expose feature revision from struct
> > dfl_device")
> 
> Nit, please keep this all on one line or our tools will complain about
> it when we commit it to our trees :(

I had caught that and fixed it when applying :)

Thanks,
Moritz
Russ Weight Sept. 17, 2021, 6:24 p.m. UTC | #6
On 9/16/21 3:50 PM, Moritz Fischer wrote:
> On Thu, Sep 16, 2021 at 03:34:39PM -0700, Russ Weight wrote:
>> On 9/16/21 3:24 PM, Moritz Fischer wrote:
>>> On Thu, Sep 16, 2021 at 02:07:33PM -0700, Russ Weight wrote:
>>>> CSR address space for Accelerator Functional Units (AFU) is not available
>>>> during the early Device Feature List (DFL) enumeration. Early access
>>>> to this space results in invalid data and port errors. This change adds
>>>> a condition to prevent an early read from the AFU CSR space.
>>>>
>>>> Signed-off-by: Russ Weight <russell.h.weight@intel.com>
>>>>
>>>> Fixes: 23bcda750558 ("fpga: dfl: expose feature revision from struct
>>>> dfl_device")
>>> Did you mean:
>>>
>>> Fixes: 1604986c3e6b ("fpga: dfl: expose feature revision from struct dfl_device")
>> Oops - I must have been looking at the wrong branch. Yes - you have the
>> correct commit ID
>>> And for future please don't line break those, or we'll get yelled at :)
>> Got it.
>>
>> Thanks!
>> - Russ
>>> I can locally fix it up, no need to resubmit
>>>
>>> - Moritz
> Applied w/changes to fixes,

Can a signed-off tag still be added?

Signed-off-by: Roger Christensen <rc@silicom.dk>

There was also a suggestion the the variable v could be declared within
the scope of the "if" statement instead of being declared at function
scope. I haven't seen that done much (at all?) in kernel code.

- Russ
>
> - Moritz
diff mbox series

Patch

diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index c99b78ee008a..f86666cf2c6a 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -1019,16 +1019,18 @@  create_feature_instance(struct build_feature_devs_info *binfo,
 {
 	unsigned int irq_base, nr_irqs;
 	struct dfl_feature_info *finfo;
+	u8 revision = 0;
 	int ret;
-	u8 revision;
 	u64 v;
 
-	v = readq(binfo->ioaddr + ofst);
-	revision = FIELD_GET(DFH_REVISION, v);
+	if (fid != FEATURE_ID_AFU) {
+		v = readq(binfo->ioaddr + ofst);
+		revision = FIELD_GET(DFH_REVISION, v);
 
-	/* read feature size and id if inputs are invalid */
-	size = size ? size : feature_size(v);
-	fid = fid ? fid : feature_id(v);
+		/* read feature size and id if inputs are invalid */
+		size = size ? size : feature_size(v);
+		fid = fid ? fid : feature_id(v);
+	}
 
 	if (binfo->len - ofst < size)
 		return -EINVAL;