public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s390/vfio-ap: Replace one-element array with flexible array member
@ 2025-01-16 13:18 Thorsten Blum
  2025-01-28 13:56 ` Alexander Gordeev
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Thorsten Blum @ 2025-01-16 13:18 UTC (permalink / raw)
  To: Tony Krowiak, Halil Pasic, Jason Herne, Harald Freudenberger,
	Holger Dengler, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger, Sven Schnelle
  Cc: linux-hardening, Thorsten Blum, linux-s390, linux-kernel

Replace the deprecated one-element array with a modern flexible array
member in the struct ap_matrix_dev.

Use struct_size() to calculate the number of bytes to allocate for
matrix_dev with a single mdev_type.

Link: https://github.com/KSPP/linux/issues/79
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 drivers/s390/crypto/vfio_ap_drv.c     | 2 +-
 drivers/s390/crypto/vfio_ap_private.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c
index 67a807e2e75b..ea9ffa37f263 100644
--- a/drivers/s390/crypto/vfio_ap_drv.c
+++ b/drivers/s390/crypto/vfio_ap_drv.c
@@ -96,7 +96,7 @@ static int vfio_ap_matrix_dev_create(void)
 	if (ret)
 		goto bus_register_err;
 
-	matrix_dev = kzalloc(sizeof(*matrix_dev), GFP_KERNEL);
+	matrix_dev = kzalloc(struct_size(matrix_dev, mdev_types, 1), GFP_KERNEL);
 	if (!matrix_dev) {
 		ret = -ENOMEM;
 		goto matrix_alloc_err;
diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h
index 437a161c8659..9aed8994f567 100644
--- a/drivers/s390/crypto/vfio_ap_private.h
+++ b/drivers/s390/crypto/vfio_ap_private.h
@@ -53,7 +53,7 @@ struct ap_matrix_dev {
 	struct mutex guests_lock; /* serializes access to each KVM guest */
 	struct mdev_parent parent;
 	struct mdev_type mdev_type;
-	struct mdev_type *mdev_types[1];
+	struct mdev_type *mdev_types[];
 };
 
 extern struct ap_matrix_dev *matrix_dev;
-- 
2.48.0


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

* Re: [PATCH] s390/vfio-ap: Replace one-element array with flexible array member
  2025-01-16 13:18 [PATCH] s390/vfio-ap: Replace one-element array with flexible array member Thorsten Blum
@ 2025-01-28 13:56 ` Alexander Gordeev
  2025-01-29 14:27 ` Anthony Krowiak
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Alexander Gordeev @ 2025-01-28 13:56 UTC (permalink / raw)
  To: Thorsten Blum, Tony Krowiak, Halil Pasic, Jason Herne
  Cc: Harald Freudenberger, Holger Dengler, Heiko Carstens,
	Vasily Gorbik, Christian Borntraeger, Sven Schnelle,
	linux-hardening, linux-s390, linux-kernel

On Thu, Jan 16, 2025 at 02:18:59PM +0100, Thorsten Blum wrote:
> Replace the deprecated one-element array with a modern flexible array
> member in the struct ap_matrix_dev.
> 
> Use struct_size() to calculate the number of bytes to allocate for
> matrix_dev with a single mdev_type.
> 
> Link: https://github.com/KSPP/linux/issues/79
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  drivers/s390/crypto/vfio_ap_drv.c     | 2 +-
>  drivers/s390/crypto/vfio_ap_private.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)

Hi Tony, Halil, Jason,

Could you please take a look?

Thanks!

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

* Re: [PATCH] s390/vfio-ap: Replace one-element array with flexible array member
  2025-01-16 13:18 [PATCH] s390/vfio-ap: Replace one-element array with flexible array member Thorsten Blum
  2025-01-28 13:56 ` Alexander Gordeev
@ 2025-01-29 14:27 ` Anthony Krowiak
  2025-01-29 15:53 ` Alexander Gordeev
  2025-01-29 20:38 ` Halil Pasic
  3 siblings, 0 replies; 10+ messages in thread
From: Anthony Krowiak @ 2025-01-29 14:27 UTC (permalink / raw)
  To: Thorsten Blum, Halil Pasic, Jason Herne, Harald Freudenberger,
	Holger Dengler, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger, Sven Schnelle
  Cc: linux-hardening, linux-s390, linux-kernel




On 1/16/25 8:18 AM, Thorsten Blum wrote:
> Replace the deprecated one-element array with a modern flexible array
> member in the struct ap_matrix_dev.
>
> Use struct_size() to calculate the number of bytes to allocate for
> matrix_dev with a single mdev_type.
>
> Link: https://github.com/KSPP/linux/issues/79

LGTM:
Reviewed-by: Anthony Krowiak <akrowiak@linux.ibm.com>

> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>   drivers/s390/crypto/vfio_ap_drv.c     | 2 +-
>   drivers/s390/crypto/vfio_ap_private.h | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c
> index 67a807e2e75b..ea9ffa37f263 100644
> --- a/drivers/s390/crypto/vfio_ap_drv.c
> +++ b/drivers/s390/crypto/vfio_ap_drv.c
> @@ -96,7 +96,7 @@ static int vfio_ap_matrix_dev_create(void)
>   	if (ret)
>   		goto bus_register_err;
>   
> -	matrix_dev = kzalloc(sizeof(*matrix_dev), GFP_KERNEL);
> +	matrix_dev = kzalloc(struct_size(matrix_dev, mdev_types, 1), GFP_KERNEL);
>   	if (!matrix_dev) {
>   		ret = -ENOMEM;
>   		goto matrix_alloc_err;
> diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h
> index 437a161c8659..9aed8994f567 100644
> --- a/drivers/s390/crypto/vfio_ap_private.h
> +++ b/drivers/s390/crypto/vfio_ap_private.h
> @@ -53,7 +53,7 @@ struct ap_matrix_dev {
>   	struct mutex guests_lock; /* serializes access to each KVM guest */
>   	struct mdev_parent parent;
>   	struct mdev_type mdev_type;
> -	struct mdev_type *mdev_types[1];
> +	struct mdev_type *mdev_types[];
>   };
>   
>   extern struct ap_matrix_dev *matrix_dev;


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

* Re: [PATCH] s390/vfio-ap: Replace one-element array with flexible array member
  2025-01-16 13:18 [PATCH] s390/vfio-ap: Replace one-element array with flexible array member Thorsten Blum
  2025-01-28 13:56 ` Alexander Gordeev
  2025-01-29 14:27 ` Anthony Krowiak
@ 2025-01-29 15:53 ` Alexander Gordeev
  2025-01-29 20:38 ` Halil Pasic
  3 siblings, 0 replies; 10+ messages in thread
From: Alexander Gordeev @ 2025-01-29 15:53 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Tony Krowiak, Halil Pasic, Jason Herne, Harald Freudenberger,
	Holger Dengler, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger, Sven Schnelle, linux-hardening, linux-s390,
	linux-kernel

On Thu, Jan 16, 2025 at 02:18:59PM +0100, Thorsten Blum wrote:
> Replace the deprecated one-element array with a modern flexible array
> member in the struct ap_matrix_dev.
> 
> Use struct_size() to calculate the number of bytes to allocate for
> matrix_dev with a single mdev_type.
> 
> Link: https://github.com/KSPP/linux/issues/79
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  drivers/s390/crypto/vfio_ap_drv.c     | 2 +-
>  drivers/s390/crypto/vfio_ap_private.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c
> index 67a807e2e75b..ea9ffa37f263 100644
> --- a/drivers/s390/crypto/vfio_ap_drv.c
> +++ b/drivers/s390/crypto/vfio_ap_drv.c
> @@ -96,7 +96,7 @@ static int vfio_ap_matrix_dev_create(void)
>  	if (ret)
>  		goto bus_register_err;
>  
> -	matrix_dev = kzalloc(sizeof(*matrix_dev), GFP_KERNEL);
> +	matrix_dev = kzalloc(struct_size(matrix_dev, mdev_types, 1), GFP_KERNEL);
>  	if (!matrix_dev) {
>  		ret = -ENOMEM;
>  		goto matrix_alloc_err;
> diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h
> index 437a161c8659..9aed8994f567 100644
> --- a/drivers/s390/crypto/vfio_ap_private.h
> +++ b/drivers/s390/crypto/vfio_ap_private.h
> @@ -53,7 +53,7 @@ struct ap_matrix_dev {
>  	struct mutex guests_lock; /* serializes access to each KVM guest */
>  	struct mdev_parent parent;
>  	struct mdev_type mdev_type;
> -	struct mdev_type *mdev_types[1];
> +	struct mdev_type *mdev_types[];
>  };
>  
>  extern struct ap_matrix_dev *matrix_dev;

Applied, thanks!

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

* Re: [PATCH] s390/vfio-ap: Replace one-element array with flexible array member
  2025-01-16 13:18 [PATCH] s390/vfio-ap: Replace one-element array with flexible array member Thorsten Blum
                   ` (2 preceding siblings ...)
  2025-01-29 15:53 ` Alexander Gordeev
@ 2025-01-29 20:38 ` Halil Pasic
  2025-01-30  0:00   ` Gustavo A. R. Silva
  3 siblings, 1 reply; 10+ messages in thread
From: Halil Pasic @ 2025-01-29 20:38 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Tony Krowiak, Jason Herne, Harald Freudenberger, Holger Dengler,
	Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger, Sven Schnelle, linux-hardening, linux-s390,
	linux-kernel, Halil Pasic

On Thu, 16 Jan 2025 14:18:59 +0100
Thorsten Blum <thorsten.blum@linux.dev> wrote:

> Replace the deprecated one-element array with a modern flexible array
> member in the struct ap_matrix_dev.
> 

I'm not sure I understand the value of this. What we have here is not
a flexible array but a one element array. Something that in the generic
case could be many but particularly for vfio-ap is always one.

Imagine if we had exactly 2 supported mdev types. I guess you would not
come to the idea that the array of two needs to be changed to a modern
flexible array. Or am I wrong about that?

So I suppose the problem  here is that arrays of one are under general
suspicion of not actually being arrays of one but a pre C99 way of
doing flexible arrays. I kind of do understand that an array wih
one element is funny. But I think the current declaration of
struct ap_matrix_dev is more expressive the proposed one.

Now I understand that it is easy to grep for [1], but it is much
harder to tell.

I've checked in Documentation/process/coding-style.rst did not see this
documented. But then I checked in checkpatch.pl and it indeed seems to
warn about it and refer to
https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays

But as far as I can tell it is also talking about the case where one
needs a trailing array of an at compile time unknown size, and not
about the case where all we need is just one element and it happens
to be convenient to have it in an array.

If there is community consensus that one sized arrays are bad regardless
of what they are used for, then the one sized array has to go.

But please tell me what speaks against replacing it with a single
pointer and then taking passing in that pointers address into
mdev_register_parent()?


> Use struct_size() to calculate the number of bytes to allocate for
> matrix_dev with a single mdev_type.
> 
> Link: https://github.com/KSPP/linux/issues/79
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>


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

* Re: [PATCH] s390/vfio-ap: Replace one-element array with flexible array member
  2025-01-29 20:38 ` Halil Pasic
@ 2025-01-30  0:00   ` Gustavo A. R. Silva
  2025-01-30 10:46     ` Halil Pasic
  0 siblings, 1 reply; 10+ messages in thread
From: Gustavo A. R. Silva @ 2025-01-30  0:00 UTC (permalink / raw)
  To: Halil Pasic, Thorsten Blum
  Cc: Tony Krowiak, Jason Herne, Harald Freudenberger, Holger Dengler,
	Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger, Sven Schnelle, linux-hardening, linux-s390,
	linux-kernel



On 30/01/25 07:08, Halil Pasic wrote:
> On Thu, 16 Jan 2025 14:18:59 +0100
> Thorsten Blum <thorsten.blum@linux.dev> wrote:
> 
>> Replace the deprecated one-element array with a modern flexible array
>> member in the struct ap_matrix_dev.
>>
> 
> I'm not sure I understand the value of this. What we have here is not
> a flexible array but a one element array. Something that in the generic
> case could be many but particularly for vfio-ap is always one.

You are correct. Only fake flexible arrays should be transformed into
C99 flex-array members [1].

Thanks
-Gustavo

[1] https://lwn.net/Articles/908817/

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

* Re: [PATCH] s390/vfio-ap: Replace one-element array with flexible array member
  2025-01-30  0:00   ` Gustavo A. R. Silva
@ 2025-01-30 10:46     ` Halil Pasic
  2025-01-30 11:37       ` Alexander Gordeev
  0 siblings, 1 reply; 10+ messages in thread
From: Halil Pasic @ 2025-01-30 10:46 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Thorsten Blum, Tony Krowiak, Jason Herne, Harald Freudenberger,
	Holger Dengler, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger, Sven Schnelle, linux-hardening, linux-s390,
	linux-kernel, Halil Pasic

On Thu, 30 Jan 2025 10:30:30 +1030
"Gustavo A. R. Silva" <gustavo@embeddedor.com> wrote:

> On 30/01/25 07:08, Halil Pasic wrote:
> > On Thu, 16 Jan 2025 14:18:59 +0100
> > Thorsten Blum <thorsten.blum@linux.dev> wrote:
> >   
> >> Replace the deprecated one-element array with a modern flexible array
> >> member in the struct ap_matrix_dev.
> >>  
> > 
> > I'm not sure I understand the value of this. What we have here is not
> > a flexible array but a one element array. Something that in the generic
> > case could be many but particularly for vfio-ap is always one.  
> 
> You are correct. Only fake flexible arrays should be transformed into
> C99 flex-array members [1].
> 
> Thanks
> -Gustavo
> 
> [1] https://lwn.net/Articles/908817/
> 

Thanks! Alex, what do we do with this then? I think you picked it up
yesterday late. And I think, it might make sense to make this look
less like a fake flex-array...

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

* Re: [PATCH] s390/vfio-ap: Replace one-element array with flexible array member
  2025-01-30 10:46     ` Halil Pasic
@ 2025-01-30 11:37       ` Alexander Gordeev
  2025-01-30 12:46         ` Heiko Carstens
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Gordeev @ 2025-01-30 11:37 UTC (permalink / raw)
  To: Halil Pasic
  Cc: Gustavo A. R. Silva, Thorsten Blum, Tony Krowiak, Jason Herne,
	Harald Freudenberger, Holger Dengler, Heiko Carstens,
	Vasily Gorbik, Christian Borntraeger, Sven Schnelle,
	linux-hardening, linux-s390, linux-kernel

On Thu, Jan 30, 2025 at 11:46:15AM +0100, Halil Pasic wrote:
> > > I'm not sure I understand the value of this. What we have here is not
> > > a flexible array but a one element array. Something that in the generic
> > > case could be many but particularly for vfio-ap is always one.  
> > 
> > You are correct. Only fake flexible arrays should be transformed into
> > C99 flex-array members [1].
> > 
> > Thanks
> > -Gustavo
> > 
> > [1] https://lwn.net/Articles/908817/
> > 
> 
> Thanks! Alex, what do we do with this then? I think you picked it up
> yesterday late. And I think, it might make sense to make this look
> less like a fake flex-array...

Dropped.
Thanks for looking into it!

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

* Re: [PATCH] s390/vfio-ap: Replace one-element array with flexible array member
  2025-01-30 11:37       ` Alexander Gordeev
@ 2025-01-30 12:46         ` Heiko Carstens
  2025-01-31  8:06           ` Halil Pasic
  0 siblings, 1 reply; 10+ messages in thread
From: Heiko Carstens @ 2025-01-30 12:46 UTC (permalink / raw)
  To: Alexander Gordeev
  Cc: Halil Pasic, Gustavo A. R. Silva, Thorsten Blum, Tony Krowiak,
	Jason Herne, Harald Freudenberger, Holger Dengler, Vasily Gorbik,
	Christian Borntraeger, Sven Schnelle, linux-hardening, linux-s390,
	linux-kernel

On Thu, Jan 30, 2025 at 12:37:13PM +0100, Alexander Gordeev wrote:
> On Thu, Jan 30, 2025 at 11:46:15AM +0100, Halil Pasic wrote:
> > > > I'm not sure I understand the value of this. What we have here is not
> > > > a flexible array but a one element array. Something that in the generic
> > > > case could be many but particularly for vfio-ap is always one.  
> > > 
> > > You are correct. Only fake flexible arrays should be transformed into
> > > C99 flex-array members [1].
> > > 
> > > Thanks
> > > -Gustavo
> > > 
> > > [1] https://lwn.net/Articles/908817/
> > > 
> > 
> > Thanks! Alex, what do we do with this then? I think you picked it up
> > yesterday late. And I think, it might make sense to make this look
> > less like a fake flex-array...
> 
> Dropped.
> Thanks for looking into it!

Given that we already have 5dd4241964c8 ("vfio/ccw: replace one-element
array with flexible-array member") applied, we now end up with inconsistent
code. I'd prefer if we address _both_ code locations in a way that the code
looks similar, and people won't send similar patches again and again.

Halil, since you started this discussion, can you address this please?

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

* Re: [PATCH] s390/vfio-ap: Replace one-element array with flexible array member
  2025-01-30 12:46         ` Heiko Carstens
@ 2025-01-31  8:06           ` Halil Pasic
  0 siblings, 0 replies; 10+ messages in thread
From: Halil Pasic @ 2025-01-31  8:06 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Alexander Gordeev, Gustavo A. R. Silva, Thorsten Blum,
	Tony Krowiak, Jason Herne, Harald Freudenberger, Holger Dengler,
	Vasily Gorbik, Christian Borntraeger, Sven Schnelle,
	linux-hardening, linux-s390, linux-kernel, Halil Pasic

On Thu, 30 Jan 2025 13:46:47 +0100
Heiko Carstens <hca@linux.ibm.com> wrote:

> > > Thanks! Alex, what do we do with this then? I think you picked it up
> > > yesterday late. And I think, it might make sense to make this look
> > > less like a fake flex-array...  
> > 
> > Dropped.
> > Thanks for looking into it!  
> 
> Given that we already have 5dd4241964c8 ("vfio/ccw: replace one-element
> array with flexible-array member") applied, we now end up with inconsistent
> code. I'd prefer if we address _both_ code locations in a way that the code
> looks similar, and people won't send similar patches again and again.
> 

Yes, I agree. We should make this not look like a fake flex array.

> Halil, since you started this discussion, can you address this please?

Sure! But I won't get around before late in the evening.

Regards,
Halil

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

end of thread, other threads:[~2025-01-31  8:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-16 13:18 [PATCH] s390/vfio-ap: Replace one-element array with flexible array member Thorsten Blum
2025-01-28 13:56 ` Alexander Gordeev
2025-01-29 14:27 ` Anthony Krowiak
2025-01-29 15:53 ` Alexander Gordeev
2025-01-29 20:38 ` Halil Pasic
2025-01-30  0:00   ` Gustavo A. R. Silva
2025-01-30 10:46     ` Halil Pasic
2025-01-30 11:37       ` Alexander Gordeev
2025-01-30 12:46         ` Heiko Carstens
2025-01-31  8:06           ` Halil Pasic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox