Skip to contentSkip to conversation

fpga: dfl: Avoid reads to AFU CSRs during enumeration

PATCH In review Russ Weight 3 participants 7 messages Sep 16, 2021 – Sep 17, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

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.

Fixes 23bcda750558 ("fpga: dfl: expose feature revision from struct

dfl_device")
Cc: [email protected]

---
 drivers/fpga/dfl.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/fpga/dfl.c +8 -6
index c99b78ee008a..f86666cf2c6a 100644
@@ -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;
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 9 lines · Russ Weight

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.

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

#2 lore raw
Quoted 6 lines · Moritz Fischer
Quoted 5 lines · Russ Weight

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.

Quoted 7 lines
Quoted 4 lines
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

Quoted 2 lines

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

Got it.

Thanks!
- Russ

Quoted 4 lines

I can locally fix it up, no need to resubmit

- Moritz

maintainer
#3 lore raw
Quoted 15 lines · Russ Weight
Quoted 6 lines · Moritz Fischer
Quoted 5 lines · Russ Weight

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.

Quoted 7 lines
Quoted 4 lines
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")
Quoted 13 lines

Oops - I must have been looking at the wrong branch. Yes - you have the correct commit ID

Quoted 2 lines

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

Got it.

Thanks!
- Russ

Quoted 4 lines

I can locally fix it up, no need to resubmit

- Moritz

Applied w/changes to fixes,

- Moritz

#4 lore raw
Quoted 18 lines · Moritz Fischer
Quoted 17 lines · Russ Weight
Quoted 6 lines · Moritz Fischer
Quoted 5 lines · Russ Weight

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.

Quoted 7 lines
Quoted 4 lines
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

Quoted 1 line

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

Quoted 8 lines
Quoted 7 lines

Got it.

Thanks!
- Russ

Quoted 3 lines

I can locally fix it up, no need to resubmit

- Moritz

Applied w/changes to fixes,

Can a signed-off tag still be added?

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

Quoted 2 lines

- Moritz

maintainer
#5 lore raw
In reply to Russ Weight
Quoted 9 lines · Russ Weight

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.

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

maintainer
#6 lore raw
Quoted 6 lines · Greg KH
Quoted 5 lines · Russ Weight

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.

Quoted 7 lines
Quoted 4 lines
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