bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf: use flexible array members, not zero-length
@ 2019-09-28 14:48 Stephen Kitt
  2019-09-29  5:49 ` Gustavo A. R. Silva
  2019-09-30  8:50 ` Daniel Borkmann
  0 siblings, 2 replies; 7+ messages in thread
From: Stephen Kitt @ 2019-09-28 14:48 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song
  Cc: linux-doc, netdev, bpf, Gustavo A . R . Silva, Stephen Kitt

This switches zero-length arrays in variable-length structs to C99
flexible array members. GCC will then ensure that the arrays are
always the last element in the struct.

Coccinelle:
@@
identifier S, fld;
type T;
@@

struct S {
  ...
- T fld[0];
+ T fld[];
  ...
};

Signed-off-by: Stephen Kitt <steve@sk2.org>
---
 Documentation/bpf/btf.rst       | 2 +-
 tools/lib/bpf/libbpf.c          | 2 +-
 tools/lib/bpf/libbpf_internal.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/bpf/btf.rst b/Documentation/bpf/btf.rst
index 4d565d202ce3..24ce50fc1fc1 100644
--- a/Documentation/bpf/btf.rst
+++ b/Documentation/bpf/btf.rst
@@ -670,7 +670,7 @@ func_info for each specific ELF section.::
         __u32   sec_name_off; /* offset to section name */
         __u32   num_info;
         /* Followed by num_info * record_size number of bytes */
-        __u8    data[0];
+        __u8    data[];
      };
 
 Here, num_info must be greater than 0.
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index e0276520171b..c02ea0e1a588 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -5577,7 +5577,7 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt,
 struct perf_sample_raw {
 	struct perf_event_header header;
 	uint32_t size;
-	char data[0];
+	char data[];
 };
 
 struct perf_sample_lost {
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 2e83a34f8c79..26eaa3f594aa 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -86,7 +86,7 @@ struct btf_ext_info_sec {
 	__u32	sec_name_off;
 	__u32	num_info;
 	/* Followed by num_info * record_size number of bytes */
-	__u8	data[0];
+	__u8 data[];
 };
 
 /* The minimum bpf_func_info checked by the loader */
-- 
2.20.1


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

* Re: [PATCH] bpf: use flexible array members, not zero-length
  2019-09-28 14:48 [PATCH] bpf: use flexible array members, not zero-length Stephen Kitt
@ 2019-09-29  5:49 ` Gustavo A. R. Silva
  2019-09-30  6:07   ` Song Liu
  2019-09-30  8:50 ` Daniel Borkmann
  1 sibling, 1 reply; 7+ messages in thread
From: Gustavo A. R. Silva @ 2019-09-29  5:49 UTC (permalink / raw)
  To: Stephen Kitt, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song
  Cc: linux-doc, netdev, bpf



On 9/28/19 09:48, Stephen Kitt wrote:
> This switches zero-length arrays in variable-length structs to C99
> flexible array members. GCC will then ensure that the arrays are
> always the last element in the struct.
> 
> Coccinelle:
> @@
> identifier S, fld;
> type T;
> @@
> 
> struct S {
>   ...
> - T fld[0];
> + T fld[];
>   ...
> };
> 
> Signed-off-by: Stephen Kitt <steve@sk2.org>
> ---
>  Documentation/bpf/btf.rst       | 2 +-
>  tools/lib/bpf/libbpf.c          | 2 +-
>  tools/lib/bpf/libbpf_internal.h | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/bpf/btf.rst b/Documentation/bpf/btf.rst
> index 4d565d202ce3..24ce50fc1fc1 100644
> --- a/Documentation/bpf/btf.rst
> +++ b/Documentation/bpf/btf.rst
> @@ -670,7 +670,7 @@ func_info for each specific ELF section.::
>          __u32   sec_name_off; /* offset to section name */
>          __u32   num_info;
>          /* Followed by num_info * record_size number of bytes */
> -        __u8    data[0];
> +        __u8    data[];
>       };
>  
>  Here, num_info must be greater than 0.
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index e0276520171b..c02ea0e1a588 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -5577,7 +5577,7 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt,
>  struct perf_sample_raw {
>  	struct perf_event_header header;
>  	uint32_t size;
> -	char data[0];
> +	char data[];
>  };
>  
>  struct perf_sample_lost {
> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> index 2e83a34f8c79..26eaa3f594aa 100644
> --- a/tools/lib/bpf/libbpf_internal.h
> +++ b/tools/lib/bpf/libbpf_internal.h
> @@ -86,7 +86,7 @@ struct btf_ext_info_sec {
>  	__u32	sec_name_off;
>  	__u32	num_info;
>  	/* Followed by num_info * record_size number of bytes */
> -	__u8	data[0];
> +	__u8 data[];

I think you should preserve the tab here.

--
Gustavo

>  };
>  
>  /* The minimum bpf_func_info checked by the loader */
> 

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

* Re: [PATCH] bpf: use flexible array members, not zero-length
  2019-09-29  5:49 ` Gustavo A. R. Silva
@ 2019-09-30  6:07   ` Song Liu
  2019-09-30  7:38     ` [PATCH v2] " Stephen Kitt
  2019-09-30  7:41     ` [PATCH] " Stephen Kitt
  0 siblings, 2 replies; 7+ messages in thread
From: Song Liu @ 2019-09-30  6:07 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Stephen Kitt, Alexei Starovoitov, Daniel Borkmann, Martin Lau,
	Yonghong Song, linux-doc, netdev, bpf



> On Sep 28, 2019, at 10:49 PM, Gustavo A. R. Silva <gustavo@embeddedor.com> wrote:
> 
> 
> 
> On 9/28/19 09:48, Stephen Kitt wrote:
>> This switches zero-length arrays in variable-length structs to C99
>> flexible array members. GCC will then ensure that the arrays are
>> always the last element in the struct.
>> 
>> Coccinelle:
>> @@
>> identifier S, fld;
>> type T;
>> @@
>> 
>> struct S {
>>  ...
>> - T fld[0];
>> + T fld[];
>>  ...
>> };
>> 
>> Signed-off-by: Stephen Kitt <steve@sk2.org>
>> ---
>> Documentation/bpf/btf.rst       | 2 +-
>> tools/lib/bpf/libbpf.c          | 2 +-
>> tools/lib/bpf/libbpf_internal.h | 2 +-
>> 3 files changed, 3 insertions(+), 3 deletions(-)
>> 
>> diff --git a/Documentation/bpf/btf.rst b/Documentation/bpf/btf.rst
>> index 4d565d202ce3..24ce50fc1fc1 100644
>> --- a/Documentation/bpf/btf.rst
>> +++ b/Documentation/bpf/btf.rst
>> @@ -670,7 +670,7 @@ func_info for each specific ELF section.::
>>         __u32   sec_name_off; /* offset to section name */
>>         __u32   num_info;
>>         /* Followed by num_info * record_size number of bytes */
>> -        __u8    data[0];
>> +        __u8    data[];
>>      };
>> 
>> Here, num_info must be greater than 0.
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index e0276520171b..c02ea0e1a588 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -5577,7 +5577,7 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt,
>> struct perf_sample_raw {
>> 	struct perf_event_header header;
>> 	uint32_t size;
>> -	char data[0];
>> +	char data[];
>> };
>> 
>> struct perf_sample_lost {
>> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
>> index 2e83a34f8c79..26eaa3f594aa 100644
>> --- a/tools/lib/bpf/libbpf_internal.h
>> +++ b/tools/lib/bpf/libbpf_internal.h
>> @@ -86,7 +86,7 @@ struct btf_ext_info_sec {
>> 	__u32	sec_name_off;
>> 	__u32	num_info;
>> 	/* Followed by num_info * record_size number of bytes */
>> -	__u8	data[0];
>> +	__u8 data[];
> 
> I think you should preserve the tab here.

Agreed. 

Besides this:

Acked-by: Song Liu <songliubraving@fb.com>


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

* [PATCH v2] bpf: use flexible array members, not zero-length
  2019-09-30  6:07   ` Song Liu
@ 2019-09-30  7:38     ` Stephen Kitt
  2019-09-30 23:18       ` Gustavo A. R. Silva
  2019-09-30  7:41     ` [PATCH] " Stephen Kitt
  1 sibling, 1 reply; 7+ messages in thread
From: Stephen Kitt @ 2019-09-30  7:38 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song
  Cc: linux-doc, netdev, bpf, Gustavo A . R . Silva, Stephen Kitt

This switches zero-length arrays in variable-length structs to C99
flexible array members. GCC will then ensure that the arrays are
always the last element in the struct.

Coccinelle:
@@
identifier S, fld;
type T;
@@

struct S {
  ...
  T fld[
- 0
  ];
  ...
};

Signed-off-by: Stephen Kitt <steve@sk2.org>
---
 Documentation/bpf/btf.rst       | 2 +-
 tools/lib/bpf/libbpf.c          | 2 +-
 tools/lib/bpf/libbpf_internal.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/bpf/btf.rst b/Documentation/bpf/btf.rst
index 4d565d202ce3..24ce50fc1fc1 100644
--- a/Documentation/bpf/btf.rst
+++ b/Documentation/bpf/btf.rst
@@ -670,7 +670,7 @@ func_info for each specific ELF section.::
         __u32   sec_name_off; /* offset to section name */
         __u32   num_info;
         /* Followed by num_info * record_size number of bytes */
-        __u8    data[0];
+        __u8    data[];
      };
 
 Here, num_info must be greater than 0.
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index e0276520171b..c02ea0e1a588 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -5577,7 +5577,7 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt,
 struct perf_sample_raw {
 	struct perf_event_header header;
 	uint32_t size;
-	char data[0];
+	char data[];
 };
 
 struct perf_sample_lost {
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 2e83a34f8c79..930ada2276bf 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -86,7 +86,7 @@ struct btf_ext_info_sec {
 	__u32	sec_name_off;
 	__u32	num_info;
 	/* Followed by num_info * record_size number of bytes */
-	__u8	data[0];
+	__u8	data[];
 };
 
 /* The minimum bpf_func_info checked by the loader */
-- 
2.20.1


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

* Re: [PATCH] bpf: use flexible array members, not zero-length
  2019-09-30  6:07   ` Song Liu
  2019-09-30  7:38     ` [PATCH v2] " Stephen Kitt
@ 2019-09-30  7:41     ` Stephen Kitt
  1 sibling, 0 replies; 7+ messages in thread
From: Stephen Kitt @ 2019-09-30  7:41 UTC (permalink / raw)
  To: Song Liu
  Cc: Gustavo A. R. Silva, Alexei Starovoitov, Daniel Borkmann,
	Martin Lau, Yonghong Song, linux-doc, netdev, bpf

Le 30/09/2019 08:07, Song Liu a écrit :
>> On Sep 28, 2019, at 10:49 PM, Gustavo A. R. Silva 
>> <gustavo@embeddedor.com> wrote:
>> I think you should preserve the tab here.
> 
> Agreed.

Indeed (and I thought I’d checked whitespace changes!). V2 upcoming with 
an improved Coccinelle script which preserves whitespace and fixes a 
couple of other issues which appear in other files (attributes, and 
structs defined alongside the field declaration).

> Besides this:
> 
> Acked-by: Song Liu <songliubraving@fb.com>

Thanks!

Regards,

Stephen

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

* Re: [PATCH] bpf: use flexible array members, not zero-length
  2019-09-28 14:48 [PATCH] bpf: use flexible array members, not zero-length Stephen Kitt
  2019-09-29  5:49 ` Gustavo A. R. Silva
@ 2019-09-30  8:50 ` Daniel Borkmann
  1 sibling, 0 replies; 7+ messages in thread
From: Daniel Borkmann @ 2019-09-30  8:50 UTC (permalink / raw)
  To: Stephen Kitt
  Cc: Alexei Starovoitov, Martin KaFai Lau, Song Liu, Yonghong Song,
	linux-doc, netdev, bpf, Gustavo A . R . Silva

On Sat, Sep 28, 2019 at 04:48:14PM +0200, Stephen Kitt wrote:
> This switches zero-length arrays in variable-length structs to C99
> flexible array members. GCC will then ensure that the arrays are
> always the last element in the struct.
> 
> Coccinelle:
> @@
> identifier S, fld;
> type T;
> @@
> 
> struct S {
>   ...
> - T fld[0];
> + T fld[];
>   ...
> };

You did not explain the "why is it needed" part, only what your
change is doing. What [compilation?] issue are you seeing that
you're trying to fix? This sort of information must be present
in a changelog.

> Signed-off-by: Stephen Kitt <steve@sk2.org>

Thanks,
Daniel

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

* Re: [PATCH v2] bpf: use flexible array members, not zero-length
  2019-09-30  7:38     ` [PATCH v2] " Stephen Kitt
@ 2019-09-30 23:18       ` Gustavo A. R. Silva
  0 siblings, 0 replies; 7+ messages in thread
From: Gustavo A. R. Silva @ 2019-09-30 23:18 UTC (permalink / raw)
  To: Stephen Kitt, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song
  Cc: linux-doc, netdev, bpf, Linux Kernel Mailing List



On 9/30/19 02:38, Stephen Kitt wrote:
> This switches zero-length arrays in variable-length structs to C99
> flexible array members. GCC will then ensure that the arrays are
> always the last element in the struct.
> 
> Coccinelle:
> @@
> identifier S, fld;
> type T;
> @@
> 
> struct S {
>   ...
>   T fld[
> - 0
>   ];
>   ...
> };
> 
> Signed-off-by: Stephen Kitt <steve@sk2.org>
> ---

What changed in v2?

You should include a changelog here.

I encourage you to read the following document:

https://kernelnewbies.org/Outreachyfirstpatch

In particular this section "Versioning one patch revision"

Also, always CC the lkml: linux-kernel@vger.kernel.org

Thanks
--
Gustavo



>  Documentation/bpf/btf.rst       | 2 +-
>  tools/lib/bpf/libbpf.c          | 2 +-
>  tools/lib/bpf/libbpf_internal.h | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/bpf/btf.rst b/Documentation/bpf/btf.rst
> index 4d565d202ce3..24ce50fc1fc1 100644
> --- a/Documentation/bpf/btf.rst
> +++ b/Documentation/bpf/btf.rst
> @@ -670,7 +670,7 @@ func_info for each specific ELF section.::
>          __u32   sec_name_off; /* offset to section name */
>          __u32   num_info;
>          /* Followed by num_info * record_size number of bytes */
> -        __u8    data[0];
> +        __u8    data[];
>       };
>  
>  Here, num_info must be greater than 0.
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index e0276520171b..c02ea0e1a588 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -5577,7 +5577,7 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt,
>  struct perf_sample_raw {
>  	struct perf_event_header header;
>  	uint32_t size;
> -	char data[0];
> +	char data[];
>  };
>  
>  struct perf_sample_lost {
> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> index 2e83a34f8c79..930ada2276bf 100644
> --- a/tools/lib/bpf/libbpf_internal.h
> +++ b/tools/lib/bpf/libbpf_internal.h
> @@ -86,7 +86,7 @@ struct btf_ext_info_sec {
>  	__u32	sec_name_off;
>  	__u32	num_info;
>  	/* Followed by num_info * record_size number of bytes */
> -	__u8	data[0];
> +	__u8	data[];
>  };
>  
>  /* The minimum bpf_func_info checked by the loader */
> 

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

end of thread, other threads:[~2019-09-30 16:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-28 14:48 [PATCH] bpf: use flexible array members, not zero-length Stephen Kitt
2019-09-29  5:49 ` Gustavo A. R. Silva
2019-09-30  6:07   ` Song Liu
2019-09-30  7:38     ` [PATCH v2] " Stephen Kitt
2019-09-30 23:18       ` Gustavo A. R. Silva
2019-09-30  7:41     ` [PATCH] " Stephen Kitt
2019-09-30  8:50 ` Daniel Borkmann

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).