Skip to contentSkip to conversation

iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning

PATCH In review Gustavo A. R. Silva 5 participants 7 messages Nov 10, 2025 – Nov 21, 2025

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

PATCH 1/1 iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Move the conflicting declaration to the end of the corresponding structure. Notice that struct iommufd_vevent is a flexible structure, this is a structure that contains a flexible-array member.

Fix the following warning:

drivers/iommu/iommufd/iommufd_private.h:621:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

---
 drivers/iommu/iommufd/iommufd_private.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/iommufd/iommufd_private.h +3 -1
index 627f9b78483a..85d0843ed07b 100644
@@ -614,7 +614,6 @@ struct iommufd_veventq {
 	struct iommufd_eventq common;
 	struct iommufd_viommu *viommu;
 	struct list_head node; /* for iommufd_viommu::veventqs */
-	struct iommufd_vevent lost_events_header;
 
 	enum iommu_veventq_type type;
 	unsigned int depth;
@@ -622,6 +621,9 @@ struct iommufd_veventq {
 	/* Use common.lock for protection */
 	u32 num_events;
 	u32 sequence;
+
+	/* Must be last as it ends in a flexible-array member. */
+	struct iommufd_vevent lost_events_header;
 };
 
 static inline struct iommufd_veventq *
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Gustavo A. R. Silva

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Move the conflicting declaration to the end of the corresponding structure. Notice that struct iommufd_vevent is a flexible structure, this is a structure that contains a flexible-array member.

Fix the following warning:

drivers/iommu/iommufd/iommufd_private.h:621:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

IIUIC, there might be data corruption due to this? If so, I think we should do:

[PATCH rc] iommufd: Fix flex-array-member-not-at-end in struct iommufd_veventq

And add:

Fixes e36ba5ab808e ("iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC")
Quoted 1 line

With that,

Thanks for the patch!

#2 lore raw
Quoted 9 lines · Nicolin Chen
Quoted 8 lines · Gustavo A. R. Silva

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Move the conflicting declaration to the end of the corresponding structure. Notice that struct iommufd_vevent is a flexible structure, this is a structure that contains a flexible-array member.

Quoted 5 lines
Quoted 3 lines

Fix the following warning:

drivers/iommu/iommufd/iommufd_private.h:621:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

IIUIC, there might be data corruption due to this? If so, I think

Yep. Also, after taking a look at the commit you mention, the counted_by annotation in struct iommufd_vevent is wrong in commit e8e1ef9b77a7 ("iommufd/viommu: Add iommufd_viommu_report_event helper"). The counter, in this case vevent->data_len must always be initialized before the first reference to the flexible array:

drivers/iommu/iommufd/driver.c +1 -1
index 6f1010da221c..21d4a35538f6 100644
@@ -161,8 +161,8 @@ int iommufd_viommu_report_event(struct iommufd_viommu *viommu,
                vevent = &veventq->lost_events_header;
                goto out_set_header;
        }
-       memcpy(vevent->event_data, event_data, data_len);
        vevent->data_len = data_len;
+       memcpy(vevent->event_data, event_data, data_len);
        veventq->num_events++;
 
 out_set_header:

I'll turn this into a small patch series to fix the above issue as well.

Thanks
-Gustavo

#3 lore raw
Quoted 12 lines · Gustavo A. R. Silva
Quoted 9 lines · Nicolin Chen
Quoted 8 lines · Gustavo A. R. Silva

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Move the conflicting declaration to the end of the corresponding structure. Notice that struct iommufd_vevent is a flexible structure, this is a structure that contains a flexible-array member.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Fix the following warning:

drivers/iommu/iommufd/iommufd_private.h:621:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array- member-not-at-end]

IIUIC, there might be data corruption due to this? If so, I think

Okay, I didn't find evidence of data corruption. So, this patch can be applied to a -next tree.

Quoted 11 lines

Yep. Also, after taking a look at the commit you mention, the counted_by annotation in struct iommufd_vevent is wrong in commit e8e1ef9b77a7 ("iommufd/viommu: Add iommufd_viommu_report_event helper"). The counter, in this case vevent->data_len must always be initialized before the first reference to the flexible array:

drivers/iommu/iommufd/driver.c +0 -0
index 6f1010da221c..21d4a35538f6 100644

drivers/iommu/iommufd/driver.c int iommufd_viommu_report_event(struct iommufd_viommu *viommu, · line 168

Quoted 9 lines
drivers/iommu/iommufd/driver.c +1 -1
@@ -161,8 +161,8 @@ int iommufd_viommu_report_event(struct iommufd_viommu *viommu,
                 vevent = &veventq->lost_events_header;
                 goto out_set_header;
         }
-       memcpy(vevent->event_data, event_data, data_len);
         vevent->data_len = data_len;
+       memcpy(vevent->event_data, event_data, data_len);
         veventq->num_events++;
 
  out_set_header:

I will submit the above as a separate patch.

Thanks
-Gustavo

#4 lore raw
Quoted 13 lines · Gustavo A. R. Silva
Quoted 12 lines · Gustavo A. R. Silva
Quoted 11 lines · Nicolin Chen
Quoted 10 lines · Gustavo A. R. Silva

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Move the conflicting declaration to the end of the corresponding structure. Notice that struct iommufd_vevent is a flexible structure, this is a structure that contains a flexible-array member.

Fix the following warning:

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

drivers/iommu/iommufd/iommufd_private.h:621:31: warning:
structure containing a flexible array member is not at the end of another structure [-Wflex-array- member-not-at-end]

IIUIC, there might be data corruption due to this? If so, I think

Okay, I didn't find evidence of data corruption. So, this patch can be applied to a -next tree.

Revisiting the design, the "lost_events_header" doesn't allocate data but only uses its internal header to raise a flag. So there should not be any data corruption.

Yea, I think we are fine with your for-next patch.

Thanks
Nicolin

maintainer Reviewed-by on v1 1/1
#5 lore raw
In reply to Gustavo A. R. Silva
Quoted 11 lines

From: Gustavo A. R. Silva <[email protected]>
Sent: Monday, November 10, 2025 7:36 PM

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Move the conflicting declaration to the end of the corresponding structure. Notice that struct iommufd_vevent is a flexible structure, this is a structure that contains a flexible-array member.

Quoted 7 lines

Fix the following warning:

drivers/iommu/iommufd/iommufd_private.h:621:31: warning: structure containing a flexible array member is not at the end of another structure [- Wflex-array-member-not-at-end]

#6 lore raw
In reply to Gustavo A. R. Silva
Quoted 8 lines · Gustavo A. R. Silva

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Move the conflicting declaration to the end of the corresponding structure. Notice that struct iommufd_vevent is a flexible structure, this is a structure that contains a flexible-array member.

Quoted 8 lines

Fix the following warning:

drivers/iommu/iommufd/iommufd_private.h:621:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

---
 drivers/iommu/iommufd/iommufd_private.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Applied thanks

Jason