Skip to contentSkip to conversation

hyperv: Avoid a hundred -Wflex-array-member-not-at-end warnings

PATCH In review Gustavo A. R. Silva 3 participants 3 messages Aug 29, 2025

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

PATCH v2 1/1 hyperv: Avoid a hundred -Wflex-array-member-not-at-end warnings

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

Use the new TRAILING_OVERLAP() helper to fix 159 of the following type of warnings:

159 ./include/linux/hyperv.h:711:38: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

This helper creates a union between a flexible-array member (FAM) and a set of members that would otherwise follow it. This overlays the trailing members onto the FAM while preserving the original memory layout.

Also, move struct vmbus_close_msg close_msg; at the end of struct vmbus_channel, as struct vmbus_channel_msginfo, ends in a flexible array member.

--
Changes in v2:
- Fix subject line.

v1:
- Link: https://lore.kernel.org/linux-hardening/aLGSDpi4xDjUUYVm@kspp/

 include/linux/hyperv.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
include/linux/hyperv.h +6 -4
index a59c5c3e95fb..efdd570669fa 100644
@@ -708,8 +708,9 @@ struct vmbus_channel_msginfo {
 };
 
 struct vmbus_close_msg {
-	struct vmbus_channel_msginfo info;
-	struct vmbus_channel_close_channel msg;
+	TRAILING_OVERLAP(struct vmbus_channel_msginfo, info, msg,
+		struct vmbus_channel_close_channel msg;
+	);
 };
 
 enum vmbus_device_type {
@@ -800,8 +801,6 @@ struct vmbus_channel {
 	struct hv_ring_buffer_info outbound;	/* send to parent */
 	struct hv_ring_buffer_info inbound;	/* receive from parent */
 
-	struct vmbus_close_msg close_msg;
-
 	/* Statistics */
 	u64	interrupts;	/* Host to Guest interrupts */
 	u64	sig_events;	/* Guest to Host events */
@@ -1008,6 +1007,9 @@ struct vmbus_channel {
 
 	/* boolean to control visibility of sysfs for ring buffer */
 	bool ring_sysfs_visible;
+
+	/* Must be last --ends in a flexible-array member. */
+	struct vmbus_close_msg close_msg;
 };
 
 #define lock_requestor(channel, flags)					\
Signature · 1 line
2.43.0
#1 lore raw

From: Gustavo A. R. Silva <[email protected]> Sent: Friday, August 29, 2025 4:44 AM

Quoted 35 lines

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

Use the new TRAILING_OVERLAP() helper to fix 159 of the following type of warnings:

159 ./include/linux/hyperv.h:711:38: warning: structure containing a flexible array
member is not at the end of another structure [-Wflex-array-member-not-at-end]

This helper creates a union between a flexible-array member (FAM) and a set of members that would otherwise follow it. This overlays the trailing members onto the FAM while preserving the original memory layout.

Also, move struct vmbus_close_msg close_msg; at the end of struct vmbus_channel, as struct vmbus_channel_msginfo, ends in a flexible array member.

--
Changes in v2:
- Fix subject line.

v1:
- Link: https://lore.kernel.org/linux-hardening/aLGSDpi4xDjUUYVm@kspp/

 include/linux/hyperv.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
include/linux/hyperv.h +0 -0
index a59c5c3e95fb..efdd570669fa 100644

include/linux/hyperv.h struct vmbus_channel_msginfo { · line 711

Quoted 4 lines
include/linux/hyperv.h +0 -1
@@ -708,8 +708,9 @@ struct vmbus_channel_msginfo {
 };
 
 struct vmbus_close_msg {
-	struct vmbus_channel_msginfo info;

It turns out that this field of struct vmbus_close_msg is never used. It dates back to 2011, so maybe somewhere along the way it stopped being used, but struct vmbus_close_msg was left unchanged.

So a better solution to the "flex-array-member-not-at-end" issue is to eliminate this structure entirely, and use struct vmbus_channel_close_channel directly in the one place where struct vmbus_close_msg is currently used. I've done a quick test of this change and I don't see any problems.

I'll submit a separate patch with my proposed change, and this patch can be dropped. Does that work?

Michael

Quoted 29 lines
include/linux/hyperv.h +6 -4
-	struct vmbus_channel_close_channel msg;
+	TRAILING_OVERLAP(struct vmbus_channel_msginfo, info, msg,
+		struct vmbus_channel_close_channel msg;
+	);
 };
 
 enum vmbus_device_type {
@@ -800,8 +801,6 @@ struct vmbus_channel {
 	struct hv_ring_buffer_info outbound;	/* send to parent */
 	struct hv_ring_buffer_info inbound;	/* receive from parent */
 
-	struct vmbus_close_msg close_msg;
-
 	/* Statistics */
 	u64	interrupts;	/* Host to Guest interrupts */
 	u64	sig_events;	/* Guest to Host events */
@@ -1008,6 +1007,9 @@ struct vmbus_channel {
 
 	/* boolean to control visibility of sysfs for ring buffer */
 	bool ring_sysfs_visible;
+
+	/* Must be last --ends in a flexible-array member. */
+	struct vmbus_close_msg close_msg;
 };
 
 #define lock_requestor(channel, flags)					\
--

2.43.0

#2 lore raw
Quoted 45 lines · Michael Kelley

From: Gustavo A. R. Silva <[email protected]> Sent: Friday, August 29, 2025 4:44 AM

Quoted 35 lines

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

Use the new TRAILING_OVERLAP() helper to fix 159 of the following type of warnings:

159 ./include/linux/hyperv.h:711:38: warning: structure containing a flexible array
member is not at the end of another structure [-Wflex-array-member-not-at-end]

This helper creates a union between a flexible-array member (FAM) and a set of members that would otherwise follow it. This overlays the trailing members onto the FAM while preserving the original memory layout.

Also, move struct vmbus_close_msg close_msg; at the end of struct vmbus_channel, as struct vmbus_channel_msginfo, ends in a flexible array member.

--
Changes in v2:
- Fix subject line.

v1:
- Link: https://lore.kernel.org/linux-hardening/aLGSDpi4xDjUUYVm@kspp/

  include/linux/hyperv.h | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
include/linux/hyperv.h +0 -0
index a59c5c3e95fb..efdd570669fa 100644

include/linux/hyperv.h struct vmbus_channel_msginfo { · line 711

Quoted 4 lines
include/linux/hyperv.h +0 -1
@@ -708,8 +708,9 @@ struct vmbus_channel_msginfo {
  };
 
  struct vmbus_close_msg {
-	struct vmbus_channel_msginfo info;

It turns out that this field of struct vmbus_close_msg is never used. It dates back to 2011, so maybe somewhere along the way it stopped being used, but struct vmbus_close_msg was left unchanged.

Quoted 8 lines

So a better solution to the "flex-array-member-not-at-end" issue is to eliminate this structure entirely, and use struct vmbus_channel_close_channel directly in the one place where struct vmbus_close_msg is currently used. I've done a quick test of this change and I don't see any problems.

I'll submit a separate patch with my proposed change, and this patch can be dropped. Does that work?

Yes, please. Go for it. :)

Thanks!
-Gustavo