iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning
@ 2025-11-10 11:35 Gustavo A. R. Silva
  2025-11-10 18:02 ` Nicolin Chen
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Gustavo A. R. Silva @ 2025-11-10 11:35 UTC (permalink / raw)
  To: Jason Gunthorpe, Kevin Tian, Joerg Roedel, Will Deacon,
	Robin Murphy
  Cc: iommu, linux-kernel, Gustavo A. R. Silva, linux-hardening

-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]

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/iommu/iommufd/iommufd_private.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h
index 627f9b78483a..85d0843ed07b 100644
--- a/drivers/iommu/iommufd/iommufd_private.h
+++ b/drivers/iommu/iommufd/iommufd_private.h
@@ -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 *
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH][next] iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning
  2025-11-10 11:35 [PATCH][next] iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
@ 2025-11-10 18:02 ` Nicolin Chen
  2025-11-11  7:20   ` Gustavo A. R. Silva
  2025-11-17  7:13 ` Tian, Kevin
  2025-11-21 19:41 ` Jason Gunthorpe
  2 siblings, 1 reply; 7+ messages in thread
From: Nicolin Chen @ 2025-11-10 18:02 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Jason Gunthorpe, Kevin Tian, Joerg Roedel, Will Deacon,
	Robin Murphy, iommu, linux-kernel, linux-hardening

On Mon, Nov 10, 2025 at 08:35:31PM +0900, Gustavo A. R. Silva wrote:
> -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")
Cc: stable@vger.kernel.org

> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

With that,

Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>

Thanks for the patch!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH][next] iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning
  2025-11-10 18:02 ` Nicolin Chen
@ 2025-11-11  7:20   ` Gustavo A. R. Silva
  2025-11-11  8:49     ` Gustavo A. R. Silva
  0 siblings, 1 reply; 7+ messages in thread
From: Gustavo A. R. Silva @ 2025-11-11  7:20 UTC (permalink / raw)
  To: Nicolin Chen, Gustavo A. R. Silva
  Cc: Jason Gunthorpe, Kevin Tian, Joerg Roedel, Will Deacon,
	Robin Murphy, iommu, linux-kernel, linux-hardening



On 11/11/25 03:02, Nicolin Chen wrote:
> On Mon, Nov 10, 2025 at 08:35:31PM +0900, Gustavo A. R. Silva wrote:
>> -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

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:

diff --git a/drivers/iommu/iommufd/driver.c b/drivers/iommu/iommufd/driver.c
index 6f1010da221c..21d4a35538f6 100644
--- a/drivers/iommu/iommufd/driver.c
+++ b/drivers/iommu/iommufd/driver.c
@@ -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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH][next] iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning
  2025-11-11  7:20   ` Gustavo A. R. Silva
@ 2025-11-11  8:49     ` Gustavo A. R. Silva
  2025-11-11 18:58       ` Nicolin Chen
  0 siblings, 1 reply; 7+ messages in thread
From: Gustavo A. R. Silva @ 2025-11-11  8:49 UTC (permalink / raw)
  To: Nicolin Chen, Gustavo A. R. Silva
  Cc: Jason Gunthorpe, Kevin Tian, Joerg Roedel, Will Deacon,
	Robin Murphy, iommu, linux-kernel, linux-hardening



On 11/11/25 16:20, Gustavo A. R. Silva wrote:
> 
> 
> On 11/11/25 03:02, Nicolin Chen wrote:
>> On Mon, Nov 10, 2025 at 08:35:31PM +0900, Gustavo A. R. Silva wrote:
>>> -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

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

> 
> 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:
> 
> diff --git a/drivers/iommu/iommufd/driver.c b/drivers/iommu/iommufd/driver.c
> index 6f1010da221c..21d4a35538f6 100644
> --- a/drivers/iommu/iommufd/driver.c
> +++ b/drivers/iommu/iommufd/driver.c
> @@ -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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH][next] iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning
  2025-11-11  8:49     ` Gustavo A. R. Silva
@ 2025-11-11 18:58       ` Nicolin Chen
  0 siblings, 0 replies; 7+ messages in thread
From: Nicolin Chen @ 2025-11-11 18:58 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Gustavo A. R. Silva, Jason Gunthorpe, Kevin Tian, Joerg Roedel,
	Will Deacon, Robin Murphy, iommu, linux-kernel, linux-hardening

On Tue, Nov 11, 2025 at 05:49:20PM +0900, Gustavo A. R. Silva wrote:
> On 11/11/25 16:20, Gustavo A. R. Silva wrote:
> > On 11/11/25 03:02, Nicolin Chen wrote:
> > > On Mon, Nov 10, 2025 at 08:35:31PM +0900, Gustavo A. R. Silva wrote:
> > > > -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
> 
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH][next] iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning
  2025-11-10 11:35 [PATCH][next] iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
  2025-11-10 18:02 ` Nicolin Chen
@ 2025-11-17  7:13 ` Tian, Kevin
  2025-11-21 19:41 ` Jason Gunthorpe
  2 siblings, 0 replies; 7+ messages in thread
From: Tian, Kevin @ 2025-11-17  7:13 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Jason Gunthorpe, Joerg Roedel, Will Deacon,
	Robin Murphy
  Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org

> From: Gustavo A. R. Silva <gustavoars@kernel.org>
> 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.
> 
> 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]
> 
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH][next] iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning
  2025-11-10 11:35 [PATCH][next] iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
  2025-11-10 18:02 ` Nicolin Chen
  2025-11-17  7:13 ` Tian, Kevin
@ 2025-11-21 19:41 ` Jason Gunthorpe
  2 siblings, 0 replies; 7+ messages in thread
From: Jason Gunthorpe @ 2025-11-21 19:41 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Kevin Tian, Joerg Roedel, Will Deacon, Robin Murphy, iommu,
	linux-kernel, linux-hardening

On Mon, Nov 10, 2025 at 08:35:31PM +0900, Gustavo A. R. Silva wrote:
> -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]
> 
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
>  drivers/iommu/iommufd/iommufd_private.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Applied thanks

Jason

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-11-21 19:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-10 11:35 [PATCH][next] iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-11-10 18:02 ` Nicolin Chen
2025-11-11  7:20   ` Gustavo A. R. Silva
2025-11-11  8:49     ` Gustavo A. R. Silva
2025-11-11 18:58       ` Nicolin Chen
2025-11-17  7:13 ` Tian, Kevin
2025-11-21 19:41 ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).