Skip to contentSkip to conversation

RDMA/efa: Fix node guid compiler warning

PATCH In review Michael Margolin 3 participants 10 messages Sep 24, 2024 – Oct 6, 2024

Subsystems (2)
lore
Share & tools
lore

Michael Margolin

author maintainer
#0 lore raw

PATCH 1/1 RDMA/efa: Fix node guid compiler warning

The GUID is received in big-endian so align types accordingly to avoid compiler warnings.

Fixes 04e36fd27a2a ("RDMA/efa: Add support for node guid")
---
 drivers/infiniband/hw/efa/efa_com_cmd.c | 2 +-
 drivers/infiniband/hw/efa/efa_com_cmd.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/efa/efa_com_cmd.c +1 -1
index 5a774925cdea..5754da4e6ff8 100644
@@ -465,7 +465,7 @@ int efa_com_get_device_attr(struct efa_com_dev *edev,
 	result->db_bar = resp.u.device_attr.db_bar;
 	result->max_rdma_size = resp.u.device_attr.max_rdma_size;
 	result->device_caps = resp.u.device_attr.device_caps;
-	result->guid = resp.u.device_attr.guid;
+	result->guid = (__force __be64)resp.u.device_attr.guid;
 
 	if (result->admin_api_version < 1) {
 		ibdev_err_ratelimited(
drivers/infiniband/hw/efa/efa_com_cmd.h +1 -1
index 668d033f7477..56382cd1b7c4 100644
@@ -112,7 +112,7 @@ struct efa_com_get_device_attr_result {
 	u8 addr[EFA_GID_SIZE];
 	u64 page_size_cap;
 	u64 max_mr_pages;
-	u64 guid;
+	__be64 guid;
 	u32 mtu;
 	u32 fw_version;
 	u32 admin_api_version;
Signature · 1 line
2.40.1
maintainer
#1 lore raw
Quoted 20 lines · Michael Margolin

The GUID is received in big-endian so align types accordingly to avoid compiler warnings.

Fixes 04e36fd27a2a ("RDMA/efa: Add support for node guid")
---
 drivers/infiniband/hw/efa/efa_com_cmd.c | 2 +-
 drivers/infiniband/hw/efa/efa_com_cmd.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/efa/efa_com_cmd.c +0 -0
index 5a774925cdea..5754da4e6ff8 100644

drivers/infiniband/hw/efa/efa_com_cmd.c int efa_com_get_device_attr(struct efa_com_dev *edev, · line 468

Quoted 5 lines
drivers/infiniband/hw/efa/efa_com_cmd.c +1 -1
@@ -465,7 +465,7 @@ int efa_com_get_device_attr(struct efa_com_dev *edev,
 	result->db_bar = resp.u.device_attr.db_bar;
 	result->max_rdma_size = resp.u.device_attr.max_rdma_size;
 	result->device_caps = resp.u.device_attr.device_caps;
-	result->guid = resp.u.device_attr.guid;
+	result->guid = (__force __be64)resp.u.device_attr.guid;

That can't be right, use the proper conversion function, or the proper type..

Jason

author maintainer
#2 lore raw
Quoted 33 lines · Jason Gunthorpe

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

Quoted 20 lines · Michael Margolin

The GUID is received in big-endian so align types accordingly to avoid compiler warnings.

Fixes 04e36fd27a2a ("RDMA/efa: Add support for node guid")
---
  drivers/infiniband/hw/efa/efa_com_cmd.c | 2 +-
  drivers/infiniband/hw/efa/efa_com_cmd.h | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/efa/efa_com_cmd.c +0 -0
index 5a774925cdea..5754da4e6ff8 100644

drivers/infiniband/hw/efa/efa_com_cmd.c int efa_com_get_device_attr(struct efa_com_dev *edev, · line 468

Quoted 5 lines
drivers/infiniband/hw/efa/efa_com_cmd.c +1 -1
@@ -465,7 +465,7 @@ int efa_com_get_device_attr(struct efa_com_dev *edev,
       result->db_bar = resp.u.device_attr.db_bar;
       result->max_rdma_size = resp.u.device_attr.max_rdma_size;
       result->device_caps = resp.u.device_attr.device_caps;
-     result->guid = resp.u.device_attr.guid;
+     result->guid = (__force __be64)resp.u.device_attr.guid;

That can't be right, use the proper conversion function, or the proper type..

Quoted 1 line

Jason

The current assumption in the driver is that data from the device arrives in a correct byte order for the CPU, while the guid field is in reversed order.

Would you suggest doing something like:

Review

Quoted 2 lines
(quoted diff) +1 -1
-     result->guid = resp.u.device_attr.guid;
+     result->guid = __cpu_to_be64(__swab64(resp.u.device_attr.guid));

Michael

author maintainer
#3 lore raw
Quoted 37 lines · Michael
Quoted 34 lines · Jason Gunthorpe

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

Quoted 20 lines · Michael Margolin

The GUID is received in big-endian so align types accordingly to avoid compiler warnings.

Fixes 04e36fd27a2a ("RDMA/efa: Add support for node guid")

---
  drivers/infiniband/hw/efa/efa_com_cmd.c | 2 +- drivers/infiniband/hw/efa/efa_com_cmd.h | 2 +-

  2 files changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/efa/efa_com_cmd.c +0 -0
index 5a774925cdea..5754da4e6ff8 100644

drivers/infiniband/hw/efa/efa_com_cmd.c int efa_com_get_device_attr(struct efa_com_dev · line 469

Quoted 6 lines
drivers/infiniband/hw/efa/efa_com_cmd.c +1 -1
@@ -465,7 +465,7 @@ int efa_com_get_device_attr(struct efa_com_dev 
 *edev,
        result->db_bar = resp.u.device_attr.db_bar;
        result->max_rdma_size = resp.u.device_attr.max_rdma_size;
        result->device_caps = resp.u.device_attr.device_caps;
-     result->guid = resp.u.device_attr.guid;
+     result->guid = (__force __be64)resp.u.device_attr.guid;

That can't be right, use the proper conversion function, or the proper type..

Quoted 1 line

Jason

Quoted 9 lines

The current assumption in the driver is that data from the device arrives in a correct byte order for the CPU, while the guid field is in reversed order.

Would you suggest doing something like:

Quoted 2 lines

-     result->guid = resp.u.device_attr.guid;
+     result->guid = __cpu_to_be64(__swab64(resp.u.device_attr.guid));

Michael

Actually that's wrong, the device always sets guid in BE order so no swap is needed in the driver in any case.

maintainer
#4 lore raw
Quoted 2 lines · Michael

Actually that's wrong, the device always sets guid in BE order so no swap is needed in the driver in any case.

They you just mark it as _be64 in the struct and there is no reason for the __force ?

Jason

author maintainer
#5 lore raw
Quoted 4 lines · Jason Gunthorpe

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

Quoted 8 lines
Quoted 2 lines · Michael

Actually that's wrong, the device always sets guid in BE order so no swap is needed in the driver in any case.

They you just mark it as _be64 in the struct and there is no reason for the __force ?

Jason

That's probably the most correct way but I prefer to avoid introducing kernel specific types in a shared interface file.

Michael

maintainer
#6 lore raw
Quoted 10 lines · Michael
Quoted 8 lines · Jason Gunthorpe

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

Quoted 2 lines · Michael

Actually that's wrong, the device always sets guid in BE order so no swap is needed in the driver in any case.

Quoted 7 lines
Quoted 4 lines

They you just mark it as _be64 in the struct and there is no reason for the __force ?

Jason

That's probably the most correct way but I prefer to avoid introducing kernel specific types in a shared interface file.

?

what is a "shared interface file" ?

That doesn't sound like a linux thing

Jason

author maintainer
#7 lore raw
Quoted 20 lines · Jason Gunthorpe

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

Quoted 7 lines · Michael
Quoted 6 lines · Jason Gunthorpe

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

On Thu, Sep 26, 2024 at 04:25:19PM +0300, Margolin, Michael wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Actually that's wrong, the device always sets guid in BE order so no swap is needed in the driver in any case.

They you just mark it as _be64 in the struct and there is no reason for the __force ?

Jason

That's probably the most correct way but I prefer to avoid introducing kernel specific types in a shared interface file.

Quoted 7 lines

?

what is a "shared interface file" ?

That doesn't sound like a linux thing

Jason

Nothing particularly related to linux, just a common practice of having the same interface on both sides (driver and device in this case).

Michael

maintainer
#8 lore raw
Quoted 8 lines · Michael
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Actually that's wrong, the device always sets guid in BE order so no swap is needed in the driver in any case.

They you just mark it as _be64 in the struct and there is no reason for the __force ?

That's probably the most correct way but I prefer to avoid introducing kernel specific types in a shared interface file.

Quoted 8 lines
Quoted 5 lines

?

what is a "shared interface file" ?

That doesn't sound like a linux thing

Nothing particularly related to linux, just a common practice of having the same interface on both sides (driver and device in this case).

Well, you still have to use correct types in the linux headers and work that out somehow

Jason

#9 lore raw
In reply to Michael Margolin
Quoted 20 lines · Michael Margolin

The GUID is received in big-endian so align types accordingly to avoid compiler warnings.

Fixes 04e36fd27a2a ("RDMA/efa: Add support for node guid")
---
 drivers/infiniband/hw/efa/efa_com_cmd.c | 2 +-
 drivers/infiniband/hw/efa/efa_com_cmd.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/efa/efa_com_cmd.c +0 -0
index 5a774925cdea..5754da4e6ff8 100644

drivers/infiniband/hw/efa/efa_com_cmd.c int efa_com_get_device_attr(struct efa_com_dev *edev, · line 468

Quoted 5 lines
drivers/infiniband/hw/efa/efa_com_cmd.c +1 -1
@@ -465,7 +465,7 @@ int efa_com_get_device_attr(struct efa_com_dev *edev,
 	result->db_bar = resp.u.device_attr.db_bar;
 	result->max_rdma_size = resp.u.device_attr.max_rdma_size;
 	result->device_caps = resp.u.device_attr.device_caps;
-	result->guid = resp.u.device_attr.guid;
+	result->guid = (__force __be64)resp.u.device_attr.guid;

Based on the discussion, I'm dropping this patch.

Thanks