[PATCH v2] ocxl: Fix endiannes bug in read_afu_name()

Subsystems: char and misc drivers, ocxl (open coherent accelerator processor interface opencapi) driver, the rest

STALE2786d REVIEWED: 1 (0M)

1 review trailer.

4 messages, 3 authors, 2018-12-23 · open the first message on its own page

[PATCH v2] ocxl: Fix endiannes bug in read_afu_name()

From: Greg Kurz <hidden>
Date: 2018-12-11 18:06:50

The AFU Descriptor Template in the PCI config space has a Name Space
field which is a 24 Byte ASCII character string of descriptive name
space for the AFU. The OCXL driver read the string four characters at
a time with pci_read_config_dword().

This optimization is valid on a little-endian system since this is PCI,
but a big-endian system ends up with each subset of four characters in
reverse order.

This could be fixed by switching to read characters one by one. Another
option is to swap the bytes if we're big-endian.

Go for the latter with le32_to_cpu().

Cc: stable@vger.kernel.org      # v4.16
Signed-off-by: Greg Kurz <redacted>
Acked-by: Frederic Barrat <redacted>
---
v2: - silence sparse with (__force __le32) cast
    - new changelog
---
 drivers/misc/ocxl/config.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
index 57a6bb1fd3c9..8f2c5d8bd2ee 100644
--- a/drivers/misc/ocxl/config.c
+++ b/drivers/misc/ocxl/config.c
@@ -318,7 +318,7 @@ static int read_afu_name(struct pci_dev *dev, struct ocxl_fn_config *fn,
 		if (rc)
 			return rc;
 		ptr = (u32 *) &afu->name[i];
-		*ptr = val;
+		*ptr = le32_to_cpu((__force __le32) val);
 	}
 	afu->name[OCXL_AFU_NAME_SZ - 1] = '\0'; /* play safe */
 	return 0;

Re: [PATCH v2] ocxl: Fix endiannes bug in read_afu_name()

From: Andrew Donnellan <hidden>
Date: 2018-12-12 02:26:21

On 12/12/18 4:58 am, Greg Kurz wrote:
The AFU Descriptor Template in the PCI config space has a Name Space
field which is a 24 Byte ASCII character string of descriptive name
space for the AFU. The OCXL driver read the string four characters at
a time with pci_read_config_dword().

This optimization is valid on a little-endian system since this is PCI,
but a big-endian system ends up with each subset of four characters in
reverse order.

This could be fixed by switching to read characters one by one. Another
option is to swap the bytes if we're big-endian.

Go for the latter with le32_to_cpu().

Cc: stable@vger.kernel.org      # v4.16
Signed-off-by: Greg Kurz <redacted>
Acked-by: Frederic Barrat <redacted>
Acked-by: Andrew Donnellan <redacted>
quoted hunk
---
v2: - silence sparse with (__force __le32) cast
     - new changelog
---
  drivers/misc/ocxl/config.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
index 57a6bb1fd3c9..8f2c5d8bd2ee 100644
--- a/drivers/misc/ocxl/config.c
+++ b/drivers/misc/ocxl/config.c
@@ -318,7 +318,7 @@ static int read_afu_name(struct pci_dev *dev, struct ocxl_fn_config *fn,
  		if (rc)
  			return rc;
  		ptr = (u32 *) &afu->name[i];
-		*ptr = val;
+		*ptr = le32_to_cpu((__force __le32) val);
  	}
  	afu->name[OCXL_AFU_NAME_SZ - 1] = '\0'; /* play safe */
  	return 0;
-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com  IBM Australia Limited

Re: [PATCH v2] ocxl: Fix endiannes bug in read_afu_name()

From: Greg Kurz <hidden>
Date: 2018-12-20 15:02:13

On Wed, 12 Dec 2018 13:26:10 +1100
Andrew Donnellan [off-list ref] wrote:
On 12/12/18 4:58 am, Greg Kurz wrote:
quoted
The AFU Descriptor Template in the PCI config space has a Name Space
field which is a 24 Byte ASCII character string of descriptive name
space for the AFU. The OCXL driver read the string four characters at
a time with pci_read_config_dword().

This optimization is valid on a little-endian system since this is PCI,
but a big-endian system ends up with each subset of four characters in
reverse order.

This could be fixed by switching to read characters one by one. Another
option is to swap the bytes if we're big-endian.

Go for the latter with le32_to_cpu().

Cc: stable@vger.kernel.org      # v4.16
Signed-off-by: Greg Kurz <redacted>
Acked-by: Frederic Barrat <redacted>  
Acked-by: Andrew Donnellan <redacted>
Friendly ping before Xmas break :)
quoted
---
v2: - silence sparse with (__force __le32) cast
     - new changelog
---
  drivers/misc/ocxl/config.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
index 57a6bb1fd3c9..8f2c5d8bd2ee 100644
--- a/drivers/misc/ocxl/config.c
+++ b/drivers/misc/ocxl/config.c
@@ -318,7 +318,7 @@ static int read_afu_name(struct pci_dev *dev, struct ocxl_fn_config *fn,
  		if (rc)
  			return rc;
  		ptr = (u32 *) &afu->name[i];
-		*ptr = val;
+		*ptr = le32_to_cpu((__force __le32) val);
  	}
  	afu->name[OCXL_AFU_NAME_SZ - 1] = '\0'; /* play safe */
  	return 0;
  

Re: [v2] ocxl: Fix endiannes bug in read_afu_name()

From: Michael Ellerman <hidden>
Date: 2018-12-23 13:52:20

On Tue, 2018-12-11 at 17:58:21 UTC, Greg Kurz wrote:
The AFU Descriptor Template in the PCI config space has a Name Space
field which is a 24 Byte ASCII character string of descriptive name
space for the AFU. The OCXL driver read the string four characters at
a time with pci_read_config_dword().

This optimization is valid on a little-endian system since this is PCI,
but a big-endian system ends up with each subset of four characters in
reverse order.

This could be fixed by switching to read characters one by one. Another
option is to swap the bytes if we're big-endian.

Go for the latter with le32_to_cpu().

Cc: stable@vger.kernel.org      # v4.16
Signed-off-by: Greg Kurz <redacted>
Acked-by: Frederic Barrat <redacted>
Acked-by: Andrew Donnellan <redacted>
Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/2f07229f02d4c55affccd11a61af4f

cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help