Skip to contentSkip to conversation

RDMA/hfi1: use a struct group to avoid warning

PATCH RESEND In review Arnd Bergmann 7 participants 17 messages Mar 20 – Mar 24

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

PATCH RESEND 1/3 RDMA/hfi1: use a struct group to avoid warning

From: Arnd Bergmann <[email protected]>

On gcc-11 and earlier, the driver sometimes produces a warning for memset:

In file included from include/linux/string.h:392,
from drivers/infiniband/hw/hfi1/mad.c:6:
In function 'fortify_memset_chk',

    inlined from '__subn_get_opa_hfi1_cong_log' at drivers/infiniband/hw/hfi1/mad.c:3873:2,
    inlined from 'subn_get_opa_sma' at drivers/infiniband/hw/hfi1/mad.c:4114:9:
include/linux/fortify-string.h:480:4: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror]
    __write_overflow_field(p_size_field, size);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This seems to be a false positive, and I found no nice way to rewrite the code to avoid the warning, but adding a a struct group works.

---
resending as the patch did not get picked up last year
https://lore.kernel.org/all/20250410075928.GN199604@unreal/

---
 drivers/infiniband/hw/hfi1/hfi.h | 6 ++++--
 drivers/infiniband/hw/hfi1/mad.c | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/infiniband/hw/hfi1/hfi.h +4 -2
index 5a0310f758dc..ae17cea4e8c9 100644
@@ -878,8 +878,10 @@ struct hfi1_pportdata {
 	 * cc_log_lock protects all congestion log related data
 	 */
 	spinlock_t cc_log_lock ____cacheline_aligned_in_smp;
-	u8 threshold_cong_event_map[OPA_MAX_SLS / 8];
-	u16 threshold_event_counter;
+	struct_group (zero_event_map,
+		u8 threshold_cong_event_map[OPA_MAX_SLS / 8];
+		u16 threshold_event_counter;
+	);
 	struct opa_hfi1_cong_log_event_internal cc_events[OPA_CONG_LOG_ELEMS];
 	int cc_log_idx; /* index for logging events */
 	int cc_mad_idx; /* index for reporting events */
drivers/infiniband/hw/hfi1/mad.c +2 -2
index 585f1d99b91b..9154638e9ce2 100644
@@ -3869,8 +3869,8 @@ static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am,
 	 * Reset threshold_cong_event_map, and threshold_event_counter
 	 * to 0 when log is read.
 	 */
-	memset(ppd->threshold_cong_event_map, 0x0,
-	       sizeof(ppd->threshold_cong_event_map));
+	memset(&ppd->zero_event_map, 0x0,
+	       sizeof(ppd->zero_event_map));
 	ppd->threshold_event_counter = 0;
 
 	spin_unlock_irq(&ppd->cc_log_lock);
Signature · 1 line
2.39.5
#1 lore raw

PATCH 2/3 RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()

From: Arnd Bergmann <[email protected]>

clang warns about a function missing a printf attribute:

include/rdma/rdma_vt.h:457:47: error: diagnostic behavior may be improved by adding the 'format(printf, 2, 3)' attribute to the declaration of 'rvt_set_ibdev_name' [-Werror,-Wmissing-format-attribute]

  447 | static inline void rvt_set_ibdev_name(struct rvt_dev_info *rdi,
      | __attribute__((format(printf, 2, 3)))
  448 |                                       const char *fmt, const char *name,
  449 |                                       const int unit)

The helper was originally added as an abstraction for the hfi1 and qib drivers needing the same thing, but now qib is gone, and hfi1 is the only remaining user of rdma_vt.

Avoid the warning and allow the compiler to check the format string by open-coding the helper and directly assigning the device name.

Fixes 5084c8ff21f2 ("IB/{rdmavt, hfi1, qib}: Self determine driver name")
---
 drivers/infiniband/hw/hfi1/init.c | 13 ++++++++++++-
 include/rdma/rdma_vt.h            | 20 --------------------
 2 files changed, 12 insertions(+), 21 deletions(-)
drivers/infiniband/hw/hfi1/init.c +12 -1
index 8b5a5b32b0fa..fb0a8325a43d 100644
@@ -1206,6 +1206,7 @@ static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev,
 					       size_t extra)
 {
 	struct hfi1_devdata *dd;
+	struct ib_device *ibdev;
 	int ret, nports;
 
 	/* extra is * number of ports */
@@ -1227,7 +1228,17 @@ static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev,
 			"Could not allocate unit ID: error %d\n", -ret);
 		goto bail;
 	}
-	rvt_set_ibdev_name(&dd->verbs_dev.rdi, "%s_%d", class_name(), dd->unit);
+
+	/*
+	 * FIXME: rvt and its users want to touch the ibdev before
+	 * registration and have things like the name work. We don't have the
+	 * infrastructure in the core to support this directly today, hack it
+	 * to work by setting the name manually here.
+	 */
+	ibdev = &dd->verbs_dev.rdi.ibdev;
+	dev_set_name(&ibdev->dev, "%s_%d", class_name(), dd->unit);
+	strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
+
 	/*
 	 * If the BIOS does not have the NUMA node information set, select
 	 * NUMA 0 so we get consistent performance.
include/rdma/rdma_vt.h +0 -20
index 7d8de561f71b..7ffc83262a01 100644
@@ -438,26 +438,6 @@ struct rvt_dev_info {
 	struct rvt_wss *wss;
 };
 
-/**
- * rvt_set_ibdev_name - Craft an IB device name from client info
- * @rdi: pointer to the client rvt_dev_info structure
- * @name: client specific name
- * @unit: client specific unit number.
- */
-static inline void rvt_set_ibdev_name(struct rvt_dev_info *rdi,
-				      const char *fmt, const char *name,
-				      const int unit)
-{
-	/*
-	 * FIXME: rvt and its users want to touch the ibdev before
-	 * registration and have things like the name work. We don't have the
-	 * infrastructure in the core to support this directly today, hack it
-	 * to work by setting the name manually here.
-	 */
-	dev_set_name(&rdi->ibdev.dev, fmt, name, unit);
-	strscpy(rdi->ibdev.name, dev_name(&rdi->ibdev.dev), IB_DEVICE_NAME_MAX);
-}
-
 /**
  * rvt_get_ibdev_name - return the IB name
  * @rdi: rdmavt device
Signature · 1 line
2.39.5
#2 lore raw

Re: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()

drivers/infiniband/hw/hfi1/init.c static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, · line 1241

Quoted 5 lines · Arnd Bergmann
drivers/infiniband/hw/hfi1/init.c +5 -0
+	 */
+	ibdev = &dd->verbs_dev.rdi.ibdev;
+	dev_set_name(&ibdev->dev, "%s_%d", class_name(), dd->unit);
+	strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
+

I messed this up during a rebase, that should have been

       strscpy(ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);

(without the extra &). I'll wait for comments before resending.

Arnd

#3 lore raw

Re: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()

Quoted 10 lines · Arnd Bergmann

drivers/infiniband/hw/hfi1/init.c static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, · line 1241

Quoted 5 lines · Arnd Bergmann
drivers/infiniband/hw/hfi1/init.c +5 -0
+	 */
+	ibdev = &dd->verbs_dev.rdi.ibdev;
+	dev_set_name(&ibdev->dev, "%s_%d", class_name(), dd->unit);
+	strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
+

I messed this up during a rebase, that should have been

Quoted 3 lines
       strscpy(ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);

(without the extra &). I'll wait for comments before resending.

The hfi1 driver is scheduled for removal. Dennis has already posted the hfi2 driver, which serves as its replacement.

Thanks

Quoted 3 lines

Arnd

#4 lore raw

Re: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()

Quoted 11 lines · Leon Romanovsky
Quoted 10 lines · Arnd Bergmann

drivers/infiniband/hw/hfi1/init.c static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, · line 1241

Quoted 5 lines · Arnd Bergmann
drivers/infiniband/hw/hfi1/init.c +5 -0
+	 */
+	ibdev = &dd->verbs_dev.rdi.ibdev;
+	dev_set_name(&ibdev->dev, "%s_%d", class_name(), dd->unit);
+	strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
+

I messed this up during a rebase, that should have been

Quoted 6 lines
Quoted 3 lines
       strscpy(ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);

(without the extra &). I'll wait for comments before resending.

The hfi1 driver is scheduled for removal. Dennis has already posted the hfi2 driver, which serves as its replacement.

Ok, that does sound like a sensible decision, and I'll just drop patches 1 and 3 then, which are just cleanups.

The cover letter at [1] suggests that the two drivers will still coexist for a bit though, so I think we'd still want patch 2/3 in order to get a clean 'allmodconfig' build when the -Wmissing-format-attribute is enabled by defaultt. I have a couple of patches in flight.

I took a quick look at the hfi2 driver, and noticed a few things that that may be worth addressing before it gets merged, mostly stuff copied from hfi1:

- A few global functions with questionable namespacing:
user_event_ack, ctxt_reset, iowait_init, register_pinning_interface, sc_{alloc,free,enable,disable}, pio_copy, acquire_hw_mutex, load_firmware, cap_mask.
It would make sense to prefix all global identifiers with 'hfi2_', both out of principle, and to allow building hfi1 and hfi2 into an allyesconfig kernel without link failures.

- The use of INFINIBAND_RDMAVT seems unnecessary: right now this is only used by hfi1, now shared with hfi2 but later to be exclusive to the latter. Since it is unlikely to ever be used by another driver again, this may be a good time to drop the abstraction again and integrate it all into hfi2, with the old version getting dropped along with hfi1.

- The pio_copy() function is particularly slow since it uses the full-barrier version of writeq() in a tight loop, this should probably use __iowrite64_copy() etc to make it work better on arm64 and other architectures

- The use of bitfields in drivers/infiniband/hw/hfi2/cport.h makes the structures nonportable especially for big-endian targets, if those describe device interfaces. Similarly the use of __packed attributes in the same file seems arbitrary and inconsistent, to the point where it is likely to cause more harm than it can help. E.g. in

+struct ib_cc_table_entry_shadow {
+ u16 entry; /* shift:2, multiplier:14 */
+};
+

Quoted 1 line

+struct ib_cc_table_attr_shadow {
+ u16 ccti_limit; /* max CCTI for cc table */
+ struct ib_cc_table_entry_shadow ccti_entries[IB_CCT_ENTRIES];
+} __packed;

the outer structure is unaligned while the inner one requires alignment.

Arnd

[1] https://lore.kernel.org/all/177325138778.57064.8330693913074464417.stgit@awdrv-04.cornelisnetworks.com/

#5 lore raw

Re: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()

Quoted 19 lines · Arnd Bergmann
Quoted 11 lines · Leon Romanovsky
Quoted 10 lines · Arnd Bergmann

drivers/infiniband/hw/hfi1/init.c static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, · line 1241

Quoted 5 lines · Arnd Bergmann
drivers/infiniband/hw/hfi1/init.c +5 -0
+	 */
+	ibdev = &dd->verbs_dev.rdi.ibdev;
+	dev_set_name(&ibdev->dev, "%s_%d", class_name(), dd->unit);
+	strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
+

I messed this up during a rebase, that should have been

Quoted 6 lines
Quoted 3 lines
       strscpy(ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);

(without the extra &). I'll wait for comments before resending.

The hfi1 driver is scheduled for removal. Dennis has already posted the hfi2 driver, which serves as its replacement.

Quoted 8 lines

Ok, that does sound like a sensible decision, and I'll just drop patches 1 and 3 then, which are just cleanups.

The cover letter at [1] suggests that the two drivers will still coexist for a bit though, so I think we'd still want patch 2/3 in order to get a clean 'allmodconfig' build when the -Wmissing-format-attribute is enabled by defaultt. I have a couple of patches in flight.

Sure, builds need to be fixed.

Quoted 13 lines

I took a quick look at the hfi2 driver, and noticed a few things that that may be worth addressing before it gets merged, mostly stuff copied from hfi1:

- A few global functions with questionable namespacing:
user_event_ack, ctxt_reset, iowait_init, register_pinning_interface, sc_{alloc,free,enable,disable}, pio_copy, acquire_hw_mutex, load_firmware, cap_mask.
It would make sense to prefix all global identifiers with 'hfi2_', both out of principle, and to allow building hfi1 and hfi2 into an allyesconfig kernel without link failures.

Quoted 6 lines

- The use of INFINIBAND_RDMAVT seems unnecessary: right now this is only used by hfi1, now shared with hfi2 but later to be exclusive to the latter. Since it is unlikely to ever be used by another driver again, this may be a good time to drop the abstraction again and integrate it all into hfi2, with the old version getting dropped along with hfi1.

The best approach is to drop rdmavt as well, since hfi2 is expected to align with the other drivers in drivers/infiniband/hw.

Dennis, is this feasible?

Thanks

#6 lore raw

Re: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()

Quoted 51 lines · Leon Romanovsky
Quoted 19 lines · Arnd Bergmann
Quoted 11 lines · Leon Romanovsky
Quoted 10 lines · Arnd Bergmann

drivers/infiniband/hw/hfi1/init.c static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, · line 1241

Quoted 5 lines · Arnd Bergmann
drivers/infiniband/hw/hfi1/init.c +5 -0
+	 */
+	ibdev = &dd->verbs_dev.rdi.ibdev;
+	dev_set_name(&ibdev->dev, "%s_%d", class_name(), dd->unit);
+	strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
+

I messed this up during a rebase, that should have been

Quoted 6 lines
Quoted 3 lines
        strscpy(ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);

(without the extra &). I'll wait for comments before resending.

The hfi1 driver is scheduled for removal. Dennis has already posted the hfi2 driver, which serves as its replacement.

Quoted 8 lines

Ok, that does sound like a sensible decision, and I'll just drop patches 1 and 3 then, which are just cleanups.

The cover letter at [1] suggests that the two drivers will still coexist for a bit though, so I think we'd still want patch 2/3 in order to get a clean 'allmodconfig' build when the -Wmissing-format-attribute is enabled by defaultt. I have a couple of patches in flight.

Sure, builds need to be fixed.

Quoted 13 lines

I took a quick look at the hfi2 driver, and noticed a few things that that may be worth addressing before it gets merged, mostly stuff copied from hfi1:

- A few global functions with questionable namespacing:
user_event_ack, ctxt_reset, iowait_init, register_pinning_interface, sc_{alloc,free,enable,disable}, pio_copy, acquire_hw_mutex, load_firmware, cap_mask.
It would make sense to prefix all global identifiers with 'hfi2_', both out of principle, and to allow building hfi1 and hfi2 into an allyesconfig kernel without link failures.

Quoted 6 lines

- The use of INFINIBAND_RDMAVT seems unnecessary: right now this is only used by hfi1, now shared with hfi2 but later to be exclusive to the latter. Since it is unlikely to ever be used by another driver again, this may be a good time to drop the abstraction again and integrate it all into hfi2, with the old version getting dropped along with hfi1.

Quoted 4 lines

The best approach is to drop rdmavt as well, since hfi2 is expected to align with the other drivers in drivers/infiniband/hw.

Dennis, is this feasible?

Feasible yes. I'd like to get hfi2 crossed off the list and in the tree first though. Then come back and do that. I'd like to do more than just plop rdmavt inside hfi2 and call it a day. There is a lot of code cleanup/simplification that we can do.

-Denny

#7 lore raw

Re: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()

Quoted 12 lines · Dennis Dalessandro
Quoted 11 lines · Leon Romanovsky
Quoted 6 lines · Arnd Bergmann

- The use of INFINIBAND_RDMAVT seems unnecessary: right now this is only used by hfi1, now shared with hfi2 but later to be exclusive to the latter. Since it is unlikely to ever be used by another driver again, this may be a good time to drop the abstraction again and integrate it all into hfi2, with the old version getting dropped along with hfi1.

The best approach is to drop rdmavt as well, since hfi2 is expected to align with the other drivers in drivers/infiniband/hw.

Quoted 6 lines
Quoted 1 line

Dennis, is this feasible?

Feasible yes. I'd like to get hfi2 crossed off the list and in the tree first though. Then come back and do that. I'd like to do more than just plop rdmavt inside hfi2 and call it a day. There is a lot of code cleanup/simplification that we can do.

Does rdmavt have its own user-space ABI? If there is anything that you'd want to change, this might be the one chance to do it, otherwise I see nothing wrong with integrating it only after hfi1 is gone.

Arnd

#8 lore raw

Re: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()

Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · Dennis Dalessandro
Quoted 12 lines · Leon Romanovsky
Quoted 6 lines · Arnd Bergmann

- The use of INFINIBAND_RDMAVT seems unnecessary: right now this is only used by hfi1, now shared with hfi2 but later to be exclusive to the latter. Since it is unlikely to ever be used by another driver again, this may be a good time to drop the abstraction again and integrate it all into hfi2, with the old version getting dropped along with hfi1.

The best approach is to drop rdmavt as well, since hfi2 is expected to align with the other drivers in drivers/infiniband/hw.

Dennis, is this feasible?

Quoted 8 lines
Quoted 4 lines

Feasible yes. I'd like to get hfi2 crossed off the list and in the tree first though. Then come back and do that. I'd like to do more than just plop rdmavt inside hfi2 and call it a day. There is a lot of code cleanup/simplification that we can do.

Does rdmavt have its own user-space ABI? If there is anything that you'd want to change, this might be the one chance to do it, otherwise I see nothing wrong with integrating it only after hfi1 is gone.

rdmavt has no user‑space exposure. It is a leftover from an old and never fully realized idea to provide a shim and common layer for RDMA drivers that require software handling in their data path.

Thanks

Quoted 2 lines

Arnd

#9 lore raw

Re: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()

In reply to Dennis Dalessandro
Quoted 57 lines · Dennis Dalessandro
Quoted 54 lines · Leon Romanovsky
Quoted 19 lines · Arnd Bergmann
Quoted 11 lines · Leon Romanovsky
Quoted 10 lines · Arnd Bergmann

drivers/infiniband/hw/hfi1/init.c static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, · line 1241

Quoted 5 lines · Arnd Bergmann
drivers/infiniband/hw/hfi1/init.c +5 -0
+	 */
+	ibdev = &dd->verbs_dev.rdi.ibdev;
+	dev_set_name(&ibdev->dev, "%s_%d", class_name(), dd->unit);
+	strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
+

I messed this up during a rebase, that should have been

Quoted 6 lines
Quoted 3 lines
        strscpy(ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);

(without the extra &). I'll wait for comments before resending.

The hfi1 driver is scheduled for removal. Dennis has already posted the hfi2 driver, which serves as its replacement.

Quoted 8 lines

Ok, that does sound like a sensible decision, and I'll just drop patches 1 and 3 then, which are just cleanups.

The cover letter at [1] suggests that the two drivers will still coexist for a bit though, so I think we'd still want patch 2/3 in order to get a clean 'allmodconfig' build when the -Wmissing-format-attribute is enabled by defaultt. I have a couple of patches in flight.

Sure, builds need to be fixed.

Quoted 13 lines

I took a quick look at the hfi2 driver, and noticed a few things that that may be worth addressing before it gets merged, mostly stuff copied from hfi1:

- A few global functions with questionable namespacing:
user_event_ack, ctxt_reset, iowait_init, register_pinning_interface, sc_{alloc,free,enable,disable}, pio_copy, acquire_hw_mutex, load_firmware, cap_mask.
It would make sense to prefix all global identifiers with 'hfi2_', both out of principle, and to allow building hfi1 and hfi2 into an allyesconfig kernel without link failures.

Quoted 6 lines

- The use of INFINIBAND_RDMAVT seems unnecessary: right now this is only used by hfi1, now shared with hfi2 but later to be exclusive to the latter. Since it is unlikely to ever be used by another driver again, this may be a good time to drop the abstraction again and integrate it all into hfi2, with the old version getting dropped along with hfi1.

The best approach is to drop rdmavt as well, since hfi2 is expected to align with the other drivers in drivers/infiniband/hw.

Quoted 6 lines
Quoted 1 line

Dennis, is this feasible?

Feasible yes. I'd like to get hfi2 crossed off the list and in the tree first though. Then come back and do that. I'd like to do more than just plop rdmavt inside hfi2 and call it a day. There is a lot of code cleanup/simplification that we can do.

So let's add a TODO file under drivers/infiniband/hw/hfi2 to track these future improvements.

Thanks

Quoted 3 lines

-Denny

#10 lore raw

Re: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()

In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

I took a quick look at the hfi2 driver, and noticed a few things that that may be worth addressing before it gets merged, mostly stuff copied from hfi1:

- A few global functions with questionable namespacing:
user_event_ack, ctxt_reset, iowait_init, register_pinning_interface, sc_{alloc,free,enable,disable}, pio_copy, acquire_hw_mutex, load_firmware, cap_mask.
It would make sense to prefix all global identifiers with 'hfi2_', both out of principle, and to allow building hfi1 and hfi2 into an allyesconfig kernel without link failures.

Will address that stuff.

Quoted 6 lines

- The use of INFINIBAND_RDMAVT seems unnecessary: right now this is only used by hfi1, now shared with hfi2 but later to be exclusive to the latter. Since it is unlikely to ever be used by another driver again, this may be a good time to drop the abstraction again and integrate it all into hfi2, with the old version getting dropped along with hfi1.

Replied about RDMAVT stuff separately. Perhaps when we target removal of hfi1 that would be the time to get RDMAVT re-incorporated into the main hfi (hfi2) driver.

Quoted 5 lines

- The pio_copy() function is particularly slow since it uses the full-barrier version of writeq() in a tight loop, this should probably use __iowrite64_copy() etc to make it work better on arm64 and other architectures

Will certainly look into this. Thanks for pointing it out.

Quoted 7 lines

- The use of bitfields in drivers/infiniband/hw/hfi2/cport.h makes the structures nonportable especially for big-endian targets, if those describe device interfaces. Similarly the use of __packed attributes in the same file seems arbitrary and inconsistent, to the point where it is likely to cause more harm than it can help. E.g. in

Actually have a patch that addresses some of that. It's coming. We had previously only built on x86_64 but have plans to change that.

Review

Quoted 13 lines
(quoted diff) +4 -0
+struct ib_cc_table_entry_shadow {
+	u16 entry; /* shift:2, multiplier:14 */
+};
+
Quoted 1 line
(quoted diff) +4 -0
+struct ib_cc_table_attr_shadow {
+	u16 ccti_limit; /* max CCTI for cc table */
+	struct ib_cc_table_entry_shadow ccti_entries[IB_CCT_ENTRIES];
+} __packed;
 
   the outer structure is unaligned while the inner one requires
   alignment.

Will take care of that one too.

-Denny

#11 lore raw

Re: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()

In reply to Arnd Bergmann
kernel test robot noticed the following build errors:

Hi Arnd,

kernel test robot noticed the following build errors:

[auto build test ERROR on rdma/for-next]
[also build test ERROR on soc/for-next linus/master v7.0-rc4 next-20260320] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Arnd-Bergmann/RDMA-hfi1-rdmavt-open-code-rvt_set_ibdev_name/20260322-190924
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git for-next
patch link:    https://lore.kernel.org/r/20260320151511.3420818-2-arnd%40kernel.org
patch subject: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()
config: x86_64-rhel-9.4-ltp (https://download.01.org/0day-ci/archive/20260322/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260322/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from include/linux/uuid.h:11,
from include/linux/mod_devicetable.h:14, from include/linux/pci.h:27,
from drivers/infiniband/hw/hfi1/init.c:7:
drivers/infiniband/hw/hfi1/init.c: In function 'hfi1_alloc_devdata':

>> drivers/infiniband/hw/hfi1/init.c:1240:17: error: passing argument 1 of 'sized_strscpy' from incompatible pointer type [-Wincompatible-pointer-types]
    1240 |         strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
         |                 ^~~~~~~~~~~~
         |                 |
         |                 char (*)[64]
   include/linux/string.h:83:23: note: in definition of macro '__strscpy1'
      83 |         sized_strscpy(dst, src, size + __must_be_cstr(dst) + __must_be_cstr(src))
         |                       ^~~
   drivers/infiniband/hw/hfi1/init.c:1240:9: note: in expansion of macro 'strscpy'
    1240 |         strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
         |         ^~~~~~~

In file included from include/linux/string.h:386:
include/linux/fortify-string.h:275:57: note: expected 'char *' but argument is of type 'char (*)[64]'
275 | __FORTIFY_INLINE ssize_t sized_strscpy(char * const POS p, const char * const POS q, size_t size)
| ~~~~~~~~~~~~~~~~~^

vim +/sized_strscpy +1240 drivers/infiniband/hw/hfi1/init.c

1195
1196 /**
1197 * hfi1_alloc_devdata - Allocate our primary per-unit data structure.
1198 * @pdev: Valid PCI device
1199 * @extra: How many bytes to alloc past the default
1200 *
1201 * Must be done via verbs allocator, because the verbs cleanup process
1202 * both does cleanup and free of the data structure.
1203 * "extra" is for chip-specific data.
1204 */
1205 static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev,
1206 size_t extra)
1207 {
1208 struct hfi1_devdata *dd;
1209 struct ib_device *ibdev;
1210 int ret, nports;
1211
1212 /* extra is * number of ports */
1213 nports = extra / sizeof(struct hfi1_pportdata);
1214
1215 dd = (struct hfi1_devdata *)rvt_alloc_device(sizeof(*dd) + extra,
1216 nports);
1217 if (!dd)
1218 return ERR_PTR(-ENOMEM);
1219 dd->num_pports = nports;
1220 dd->pport = (struct hfi1_pportdata *)(dd + 1);
1221 dd->pcidev = pdev;
1222 pci_set_drvdata(pdev, dd);
1223
1224 ret = xa_alloc_irq(&hfi1_dev_table, &dd->unit, dd, xa_limit_32b,
1225 GFP_KERNEL);
1226 if (ret < 0) {
1227 dev_err(&pdev->dev,
1228 "Could not allocate unit ID: error %d\n", -ret);
1229 goto bail;
1230 }
1231
1232 /*
1233 * FIXME: rvt and its users want to touch the ibdev before
1234 * registration and have things like the name work. We don't have the
1235 * infrastructure in the core to support this directly today, hack it
1236 * to work by setting the name manually here.
1237 */
1238 ibdev = &dd->verbs_dev.rdi.ibdev;
1239 dev_set_name(&ibdev->dev, "%s_%d", class_name(), dd->unit);

> 1240		strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);

1241
1242 /*
1243 * If the BIOS does not have the NUMA node information set, select
1244 * NUMA 0 so we get consistent performance.
1245 */
1246 dd->node = pcibus_to_node(pdev->bus);
1247 if (dd->node == NUMA_NO_NODE) {
1248 dd_dev_err(dd, "Invalid PCI NUMA node. Performance may be affected\n");
1249 dd->node = 0;
1250 }
1251
1252 /*
1253 * Initialize all locks for the device. This needs to be as early as
1254 * possible so locks are usable.
1255 */
1256 spin_lock_init(&dd->sc_lock);
1257 spin_lock_init(&dd->sendctrl_lock);
1258 spin_lock_init(&dd->rcvctrl_lock);
1259 spin_lock_init(&dd->uctxt_lock);
1260 spin_lock_init(&dd->hfi1_diag_trans_lock);
1261 spin_lock_init(&dd->sc_init_lock);
1262 spin_lock_init(&dd->dc8051_memlock);
1263 seqlock_init(&dd->sc2vl_lock);
1264 spin_lock_init(&dd->sde_map_lock);
1265 spin_lock_init(&dd->pio_map_lock);
1266 mutex_init(&dd->dc8051_lock);
1267 init_waitqueue_head(&dd->event_queue);
1268 spin_lock_init(&dd->irq_src_lock);
1269
1270 dd->int_counter = alloc_percpu(u64);
1271 if (!dd->int_counter) {
1272 ret = -ENOMEM;
1273 goto bail;
1274 }
1275
1276 dd->rcv_limit = alloc_percpu(u64);
1277 if (!dd->rcv_limit) {
1278 ret = -ENOMEM;
1279 goto bail;
1280 }
1281
1282 dd->send_schedule = alloc_percpu(u64);
1283 if (!dd->send_schedule) {
1284 ret = -ENOMEM;
1285 goto bail;
1286 }
1287
1288 dd->tx_opstats = alloc_percpu(struct hfi1_opcode_stats_perctx);
1289 if (!dd->tx_opstats) {
1290 ret = -ENOMEM;
1291 goto bail;
1292 }
1293
1294 dd->comp_vect = kzalloc_obj(*dd->comp_vect);
1295 if (!dd->comp_vect) {
1296 ret = -ENOMEM;
1297 goto bail;
1298 }
1299
1300 /* allocate dummy tail memory for all receive contexts */
1301 dd->rcvhdrtail_dummy_kvaddr =
1302 dma_alloc_coherent(&dd->pcidev->dev, sizeof(u64),
1303 &dd->rcvhdrtail_dummy_dma, GFP_KERNEL);
1304 if (!dd->rcvhdrtail_dummy_kvaddr) {
1305 ret = -ENOMEM;
1306 goto bail;
1307 }
1308
1309 atomic_set(&dd->ipoib_rsm_usr_num, 0);
1310 return dd;
1311
1312 bail:
1313 hfi1_free_devdata(dd);
1314 return ERR_PTR(ret);
1315 }
1316

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#12 lore raw

Re: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()

In reply to Arnd Bergmann
kernel test robot noticed the following build errors:

Hi Arnd,

kernel test robot noticed the following build errors:

[auto build test ERROR on rdma/for-next]
[also build test ERROR on soc/for-next linus/master v7.0-rc4 next-20260320] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Arnd-Bergmann/RDMA-hfi1-rdmavt-open-code-rvt_set_ibdev_name/20260322-190924
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git for-next
patch link:    https://lore.kernel.org/r/20260320151511.3420818-2-arnd%40kernel.org
patch subject: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()
config: x86_64-rhel-9.4-ltp (https://download.01.org/0day-ci/archive/20260323/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260323/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from include/linux/uuid.h:11,
from include/linux/mod_devicetable.h:14, from include/linux/pci.h:27,
from drivers/infiniband/hw/hfi1/init.c:7:
drivers/infiniband/hw/hfi1/init.c: In function 'hfi1_alloc_devdata':

>> drivers/infiniband/hw/hfi1/init.c:1240:17: error: passing argument 1 of 'sized_strscpy' from incompatible pointer type [-Wincompatible-pointer-types]
    1240 |         strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
         |                 ^~~~~~~~~~~~
         |                 |
         |                 char (*)[64]
   include/linux/string.h:83:23: note: in definition of macro '__strscpy1'
      83 |         sized_strscpy(dst, src, size + __must_be_cstr(dst) + __must_be_cstr(src))
         |                       ^~~
   drivers/infiniband/hw/hfi1/init.c:1240:9: note: in expansion of macro 'strscpy'
    1240 |         strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
         |         ^~~~~~~

In file included from include/linux/string.h:386:
include/linux/fortify-string.h:275:57: note: expected 'char *' but argument is of type 'char (*)[64]'
275 | __FORTIFY_INLINE ssize_t sized_strscpy(char * const POS p, const char * const POS q, size_t size)
| ~~~~~~~~~~~~~~~~~^

vim +/sized_strscpy +1240 drivers/infiniband/hw/hfi1/init.c

1195
1196 /**
1197 * hfi1_alloc_devdata - Allocate our primary per-unit data structure.
1198 * @pdev: Valid PCI device
1199 * @extra: How many bytes to alloc past the default
1200 *
1201 * Must be done via verbs allocator, because the verbs cleanup process
1202 * both does cleanup and free of the data structure.
1203 * "extra" is for chip-specific data.
1204 */
1205 static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev,
1206 size_t extra)
1207 {
1208 struct hfi1_devdata *dd;
1209 struct ib_device *ibdev;
1210 int ret, nports;
1211
1212 /* extra is * number of ports */
1213 nports = extra / sizeof(struct hfi1_pportdata);
1214
1215 dd = (struct hfi1_devdata *)rvt_alloc_device(sizeof(*dd) + extra,
1216 nports);
1217 if (!dd)
1218 return ERR_PTR(-ENOMEM);
1219 dd->num_pports = nports;
1220 dd->pport = (struct hfi1_pportdata *)(dd + 1);
1221 dd->pcidev = pdev;
1222 pci_set_drvdata(pdev, dd);
1223
1224 ret = xa_alloc_irq(&hfi1_dev_table, &dd->unit, dd, xa_limit_32b,
1225 GFP_KERNEL);
1226 if (ret < 0) {
1227 dev_err(&pdev->dev,
1228 "Could not allocate unit ID: error %d\n", -ret);
1229 goto bail;
1230 }
1231
1232 /*
1233 * FIXME: rvt and its users want to touch the ibdev before
1234 * registration and have things like the name work. We don't have the
1235 * infrastructure in the core to support this directly today, hack it
1236 * to work by setting the name manually here.
1237 */
1238 ibdev = &dd->verbs_dev.rdi.ibdev;
1239 dev_set_name(&ibdev->dev, "%s_%d", class_name(), dd->unit);

> 1240		strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);

1241
1242 /*
1243 * If the BIOS does not have the NUMA node information set, select
1244 * NUMA 0 so we get consistent performance.
1245 */
1246 dd->node = pcibus_to_node(pdev->bus);
1247 if (dd->node == NUMA_NO_NODE) {
1248 dd_dev_err(dd, "Invalid PCI NUMA node. Performance may be affected\n");
1249 dd->node = 0;
1250 }
1251
1252 /*
1253 * Initialize all locks for the device. This needs to be as early as
1254 * possible so locks are usable.
1255 */
1256 spin_lock_init(&dd->sc_lock);
1257 spin_lock_init(&dd->sendctrl_lock);
1258 spin_lock_init(&dd->rcvctrl_lock);
1259 spin_lock_init(&dd->uctxt_lock);
1260 spin_lock_init(&dd->hfi1_diag_trans_lock);
1261 spin_lock_init(&dd->sc_init_lock);
1262 spin_lock_init(&dd->dc8051_memlock);
1263 seqlock_init(&dd->sc2vl_lock);
1264 spin_lock_init(&dd->sde_map_lock);
1265 spin_lock_init(&dd->pio_map_lock);
1266 mutex_init(&dd->dc8051_lock);
1267 init_waitqueue_head(&dd->event_queue);
1268 spin_lock_init(&dd->irq_src_lock);
1269
1270 dd->int_counter = alloc_percpu(u64);
1271 if (!dd->int_counter) {
1272 ret = -ENOMEM;
1273 goto bail;
1274 }
1275
1276 dd->rcv_limit = alloc_percpu(u64);
1277 if (!dd->rcv_limit) {
1278 ret = -ENOMEM;
1279 goto bail;
1280 }
1281
1282 dd->send_schedule = alloc_percpu(u64);
1283 if (!dd->send_schedule) {
1284 ret = -ENOMEM;
1285 goto bail;
1286 }
1287
1288 dd->tx_opstats = alloc_percpu(struct hfi1_opcode_stats_perctx);
1289 if (!dd->tx_opstats) {
1290 ret = -ENOMEM;
1291 goto bail;
1292 }
1293
1294 dd->comp_vect = kzalloc_obj(*dd->comp_vect);
1295 if (!dd->comp_vect) {
1296 ret = -ENOMEM;
1297 goto bail;
1298 }
1299
1300 /* allocate dummy tail memory for all receive contexts */
1301 dd->rcvhdrtail_dummy_kvaddr =
1302 dma_alloc_coherent(&dd->pcidev->dev, sizeof(u64),
1303 &dd->rcvhdrtail_dummy_dma, GFP_KERNEL);
1304 if (!dd->rcvhdrtail_dummy_kvaddr) {
1305 ret = -ENOMEM;
1306 goto bail;
1307 }
1308
1309 atomic_set(&dd->ipoib_rsm_usr_num, 0);
1310 return dd;
1311
1312 bail:
1313 hfi1_free_devdata(dd);
1314 return ERR_PTR(ret);
1315 }
1316

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#13 lore raw

Re: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()

In reply to Arnd Bergmann
kernel test robot noticed the following build errors:

Hi Arnd,

kernel test robot noticed the following build errors:

[auto build test ERROR on rdma/for-next]
[also build test ERROR on soc/for-next linus/master v7.0-rc5 next-20260323] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Arnd-Bergmann/RDMA-hfi1-rdmavt-open-code-rvt_set_ibdev_name/20260322-190924
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git for-next
patch link:    https://lore.kernel.org/r/20260320151511.3420818-2-arnd%40kernel.org
patch subject: [PATCH 2/3] RDMA/hfi1, rdmavt: open-code rvt_set_ibdev_name()
config: x86_64-rhel-9.4-rust (https://download.01.org/0day-ci/archive/20260324/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260324/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/infiniband/hw/hfi1/init.c:1240:10: error: incompatible pointer types passing 'char (*)[64]' to parameter of type 'char *' [-Werror,-Wincompatible-pointer-types]
    1240 |         strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
         |                 ^~~~~~~~~~~~
   include/linux/string.h:114:50: note: expanded from macro 'strscpy'
     114 |         CONCATENATE(__strscpy, COUNT_ARGS(__VA_ARGS__))(dst, src, __VA_ARGS__)
         |                                                         ^~~
   include/linux/string.h:83:16: note: expanded from macro '__strscpy1'
      83 |         sized_strscpy(dst, src, size + __must_be_cstr(dst) + __must_be_cstr(src))
         |                       ^~~

include/linux/fortify-string.h:275:57: note: passing argument to parameter 'p' here
275 | __FORTIFY_INLINE ssize_t sized_strscpy(char * const POS p, const char * const POS q, size_t size)
| ^
1 error generated.

vim +1240 drivers/infiniband/hw/hfi1/init.c

1195
1196 /**
1197 * hfi1_alloc_devdata - Allocate our primary per-unit data structure.
1198 * @pdev: Valid PCI device
1199 * @extra: How many bytes to alloc past the default
1200 *
1201 * Must be done via verbs allocator, because the verbs cleanup process
1202 * both does cleanup and free of the data structure.
1203 * "extra" is for chip-specific data.
1204 */
1205 static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev,
1206 size_t extra)
1207 {
1208 struct hfi1_devdata *dd;
1209 struct ib_device *ibdev;
1210 int ret, nports;
1211
1212 /* extra is * number of ports */
1213 nports = extra / sizeof(struct hfi1_pportdata);
1214
1215 dd = (struct hfi1_devdata *)rvt_alloc_device(sizeof(*dd) + extra,
1216 nports);
1217 if (!dd)
1218 return ERR_PTR(-ENOMEM);
1219 dd->num_pports = nports;
1220 dd->pport = (struct hfi1_pportdata *)(dd + 1);
1221 dd->pcidev = pdev;
1222 pci_set_drvdata(pdev, dd);
1223
1224 ret = xa_alloc_irq(&hfi1_dev_table, &dd->unit, dd, xa_limit_32b,
1225 GFP_KERNEL);
1226 if (ret < 0) {
1227 dev_err(&pdev->dev,
1228 "Could not allocate unit ID: error %d\n", -ret);
1229 goto bail;
1230 }
1231
1232 /*
1233 * FIXME: rvt and its users want to touch the ibdev before
1234 * registration and have things like the name work. We don't have the
1235 * infrastructure in the core to support this directly today, hack it
1236 * to work by setting the name manually here.
1237 */
1238 ibdev = &dd->verbs_dev.rdi.ibdev;
1239 dev_set_name(&ibdev->dev, "%s_%d", class_name(), dd->unit);

> 1240		strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);

1241
1242 /*
1243 * If the BIOS does not have the NUMA node information set, select
1244 * NUMA 0 so we get consistent performance.
1245 */
1246 dd->node = pcibus_to_node(pdev->bus);
1247 if (dd->node == NUMA_NO_NODE) {
1248 dd_dev_err(dd, "Invalid PCI NUMA node. Performance may be affected\n");
1249 dd->node = 0;
1250 }
1251
1252 /*
1253 * Initialize all locks for the device. This needs to be as early as
1254 * possible so locks are usable.
1255 */
1256 spin_lock_init(&dd->sc_lock);
1257 spin_lock_init(&dd->sendctrl_lock);
1258 spin_lock_init(&dd->rcvctrl_lock);
1259 spin_lock_init(&dd->uctxt_lock);
1260 spin_lock_init(&dd->hfi1_diag_trans_lock);
1261 spin_lock_init(&dd->sc_init_lock);
1262 spin_lock_init(&dd->dc8051_memlock);
1263 seqlock_init(&dd->sc2vl_lock);
1264 spin_lock_init(&dd->sde_map_lock);
1265 spin_lock_init(&dd->pio_map_lock);
1266 mutex_init(&dd->dc8051_lock);
1267 init_waitqueue_head(&dd->event_queue);
1268 spin_lock_init(&dd->irq_src_lock);
1269
1270 dd->int_counter = alloc_percpu(u64);
1271 if (!dd->int_counter) {
1272 ret = -ENOMEM;
1273 goto bail;
1274 }
1275
1276 dd->rcv_limit = alloc_percpu(u64);
1277 if (!dd->rcv_limit) {
1278 ret = -ENOMEM;
1279 goto bail;
1280 }
1281
1282 dd->send_schedule = alloc_percpu(u64);
1283 if (!dd->send_schedule) {
1284 ret = -ENOMEM;
1285 goto bail;
1286 }
1287
1288 dd->tx_opstats = alloc_percpu(struct hfi1_opcode_stats_perctx);
1289 if (!dd->tx_opstats) {
1290 ret = -ENOMEM;
1291 goto bail;
1292 }
1293
1294 dd->comp_vect = kzalloc_obj(*dd->comp_vect);
1295 if (!dd->comp_vect) {
1296 ret = -ENOMEM;
1297 goto bail;
1298 }
1299
1300 /* allocate dummy tail memory for all receive contexts */
1301 dd->rcvhdrtail_dummy_kvaddr =
1302 dma_alloc_coherent(&dd->pcidev->dev, sizeof(u64),
1303 &dd->rcvhdrtail_dummy_dma, GFP_KERNEL);
1304 if (!dd->rcvhdrtail_dummy_kvaddr) {
1305 ret = -ENOMEM;
1306 goto bail;
1307 }
1308
1309 atomic_set(&dd->ipoib_rsm_usr_num, 0);
1310 return dd;
1311
1312 bail:
1313 hfi1_free_devdata(dd);
1314 return ERR_PTR(ret);
1315 }
1316

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#14 lore raw

PATCH 3/3 RDMA/hfi1: reduce namespace pollution

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>

While looking at an unrelated bug, I noticed that the global "class_name" function is not suitable for a driver-internal interface. The same file that declares this also has dev_init() and dev_exit() functions, which are equally problematic.

Remove the class_name() function entirely and just hardcode the string where it is used, and rename the other two functions to fit into the hfi1 namespace.

----
The driver contains many more functions that should not be in the global namespace, but I decided not to fix the other ones. Maybe the maintainers can continue renaming the rest.

---
 drivers/infiniband/hw/hfi1/debugfs.c  |  2 +-
 drivers/infiniband/hw/hfi1/device.c   | 11 ++---------
 drivers/infiniband/hw/hfi1/device.h   |  5 ++---
 drivers/infiniband/hw/hfi1/file_ops.c |  2 +-
 drivers/infiniband/hw/hfi1/init.c     |  8 ++++----
 5 files changed, 10 insertions(+), 18 deletions(-)
drivers/infiniband/hw/hfi1/debugfs.c +1 -1
index ac37ab7f8995..24346b74d5e0 100644
@@ -1161,7 +1161,7 @@ void hfi1_dbg_ibdev_init(struct hfi1_ibdev *ibd)
 
 	if (!hfi1_dbg_root)
 		return;
-	snprintf(name, sizeof(name), "%s_%d", class_name(), unit);
+	snprintf(name, sizeof(name), "hfi1_%d", unit);
 	snprintf(link, sizeof(link), "%d", unit);
 	root = debugfs_create_dir(name, hfi1_dbg_root);
 	ibd->hfi1_ibdev_dbg = root;
drivers/infiniband/hw/hfi1/device.c +2 -9
index 1aac6c2f45b4..a26b71867a2a 100644
@@ -86,14 +86,7 @@ void hfi1_cdev_cleanup(struct cdev *cdev, struct device **devp)
 	}
 }
 
-static const char *hfi1_class_name = "hfi1";
-
-const char *class_name(void)
-{
-	return hfi1_class_name;
-}
-
-int __init dev_init(void)
+int __init hfi1_dev_init(void)
 {
 	int ret;
 
@@ -123,7 +116,7 @@ int __init dev_init(void)
 	return ret;
 }
 
-void dev_cleanup(void)
+void hfi1_dev_cleanup(void)
 {
 	class_unregister(&class);
 	class_unregister(&user_class);
drivers/infiniband/hw/hfi1/device.h +2 -3
index a91bea426ba5..d7775f92e0b1 100644
@@ -12,8 +12,7 @@ int hfi1_cdev_init(int minor, const char *name,
 		   bool user_accessible,
 		   struct kobject *parent);
 void hfi1_cdev_cleanup(struct cdev *cdev, struct device **devp);
-const char *class_name(void);
-int __init dev_init(void);
-void dev_cleanup(void);
+int __init hfi1_dev_init(void);
+void hfi1_dev_cleanup(void);
 
 #endif                          /* _HFI1_DEVICE_H */
drivers/infiniband/hw/hfi1/file_ops.c +1 -1
index 56031becb273..2fe7f7df7d09 100644
@@ -1686,7 +1686,7 @@ static int user_add(struct hfi1_devdata *dd)
 	char name[10];
 	int ret;
 
-	snprintf(name, sizeof(name), "%s_%d", class_name(), dd->unit);
+	snprintf(name, sizeof(name), "hfi1_%d", dd->unit);
 	ret = hfi1_cdev_init(dd->unit, name, &hfi1_file_ops,
 			     &dd->user_cdev, &dd->user_device,
 			     true, &dd->verbs_dev.rdi.ibdev.dev.kobj);
drivers/infiniband/hw/hfi1/init.c +4 -4
index fb0a8325a43d..28213ddcf2e9 100644
@@ -1236,7 +1236,7 @@ static struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev,
 	 * to work by setting the name manually here.
 	 */
 	ibdev = &dd->verbs_dev.rdi.ibdev;
-	dev_set_name(&ibdev->dev, "%s_%d", class_name(), dd->unit);
+	dev_set_name(&ibdev->dev, "hfi1_%d", dd->unit);
 	strscpy(&ibdev->name, dev_name(&ibdev->dev), IB_DEVICE_NAME_MAX);
 
 	/*
@@ -1387,7 +1387,7 @@ static int __init hfi1_mod_init(void)
 {
 	int ret;
 
-	ret = dev_init();
+	ret = hfi1_dev_init();
 	if (ret)
 		goto bail;
 
@@ -1460,7 +1460,7 @@ static int __init hfi1_mod_init(void)
 
 bail_dev:
 	hfi1_dbg_exit();
-	dev_cleanup();
+	hfi1_dev_cleanup();
 bail:
 	return ret;
 }
@@ -1479,7 +1479,7 @@ static void __exit hfi1_mod_cleanup(void)
 
 	WARN_ON(!xa_empty(&hfi1_dev_table));
 	dispose_firmware();	/* asymmetric with obtain_firmware() */
-	dev_cleanup();
+	hfi1_dev_cleanup();
 }
 
 module_exit(hfi1_mod_cleanup);
Signature · 1 line
2.39.5
Reviewed-by on v1 1/3
#15 lore raw
In reply to Arnd Bergmann
Quoted 14 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

On gcc-11 and earlier, the driver sometimes produces a warning for memset:

In file included from include/linux/string.h:392,
from drivers/infiniband/hw/hfi1/mad.c:6:
In function 'fortify_memset_chk',

    inlined from '__subn_get_opa_hfi1_cong_log' at drivers/infiniband/hw/hfi1/mad.c:3873:2,
    inlined from 'subn_get_opa_sma' at drivers/infiniband/hw/hfi1/mad.c:4114:9:
include/linux/fortify-string.h:480:4: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror]
    __write_overflow_field(p_size_field, size);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 4 lines

This seems to be a false positive, and I found no nice way to rewrite the code to avoid the warning, but adding a a struct group works.

Signature · 1 line
Kees Cook
#16 lore raw
In reply to Arnd Bergmann
Quoted 48 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

On gcc-11 and earlier, the driver sometimes produces a warning for memset:

In file included from include/linux/string.h:392,
from drivers/infiniband/hw/hfi1/mad.c:6:
In function 'fortify_memset_chk',

     inlined from '__subn_get_opa_hfi1_cong_log' at drivers/infiniband/hw/hfi1/mad.c:3873:2,
     inlined from 'subn_get_opa_sma' at drivers/infiniband/hw/hfi1/mad.c:4114:9:
include/linux/fortify-string.h:480:4: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror]
     __write_overflow_field(p_size_field, size);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This seems to be a false positive, and I found no nice way to rewrite the code to avoid the warning, but adding a a struct group works.

---
resending as the patch did not get picked up last year
https://lore.kernel.org/all/20250410075928.GN199604@unreal/

---
  drivers/infiniband/hw/hfi1/hfi.h | 6 ++++--
  drivers/infiniband/hw/hfi1/mad.c | 4 ++--
  2 files changed, 6 insertions(+), 4 deletions(-)
drivers/infiniband/hw/hfi1/hfi.h +4 -2
index 5a0310f758dc..ae17cea4e8c9 100644
@@ -878,8 +878,10 @@ struct hfi1_pportdata {
  	 * cc_log_lock protects all congestion log related data
  	 */
  	spinlock_t cc_log_lock ____cacheline_aligned_in_smp;
-	u8 threshold_cong_event_map[OPA_MAX_SLS / 8];
-	u16 threshold_event_counter;
+	struct_group (zero_event_map,
+		u8 threshold_cong_event_map[OPA_MAX_SLS / 8];
+		u16 threshold_event_counter;
+	);
  	struct opa_hfi1_cong_log_event_internal cc_events[OPA_CONG_LOG_ELEMS];
  	int cc_log_idx; /* index for logging events */
  	int cc_mad_idx; /* index for reporting events */
drivers/infiniband/hw/hfi1/mad.c +0 -0
index 585f1d99b91b..9154638e9ce2 100644

drivers/infiniband/hw/hfi1/mad.c static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am, · line 3874

Quoted 8 lines
drivers/infiniband/hw/hfi1/mad.c +2 -2
@@ -3869,8 +3869,8 @@ static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am,
  	 * Reset threshold_cong_event_map, and threshold_event_counter
  	 * to 0 when log is read.
  	 */
-	memset(ppd->threshold_cong_event_map, 0x0,
-	       sizeof(ppd->threshold_cong_event_map));
+	memset(&ppd->zero_event_map, 0x0,
+	       sizeof(ppd->zero_event_map));
  	ppd->threshold_event_counter = 0;

Not sure if ppd->threshold_event_counter is also set to 0 in memset or not. If yes, this line "ppd->threshold_event_counter = 0;" can be removed?

Zhu Yanjun

Quoted 2 lines
drivers/infiniband/hw/hfi1/mad.c +0 -0
  	spin_unlock_irq(&ppd->cc_log_lock);