xen/public: fix flexible array definitions
PATCH v3 1/1 xen/public: fix flexible array definitions
Flexible arrays in public headers can be problematic with some compilers.
With XEN_FLEX_ARRAY_DIM there is a mechanism available to deal with this issue, but care must be taken to not change the affected structs in an incompatible way.
So bump __XEN_LATEST_INTERFACE_VERSION__ and introduce a new macro XENPV_FLEX_ARRAY_DIM which will be XENPV_FLEX_ARRAY_DIM with the interface version being new enough and "1" (the value used today in the affected headers) when the interface version is an old one.
Replace the arr[1] instances (this includes the ones seen to be problematic in recent Linux kernels [1]) with arr[XENPV_FLEX_ARRAY_DIM] in order to avoid compilation errors.
[1]: https://bugzilla.kernel.org/show_bug.cgi?id=217693
---
V2:
- bump interface version and make change only for new version (Jan Beulich)
V3:
- move XENPV_FLEX_ARRAY_DIM definition to ring.h (Jan Beulich)
- fix 2 wrong XENPV_FLEX_ARRAY_DIM use cases (Julien Grall)
- add CHANGELOG.md entry (Andrew Cooper)
--- CHANGELOG.md | 2 ++ xen/include/public/io/cameraif.h | 2 +- xen/include/public/io/displif.h | 2 +- xen/include/public/io/fsif.h | 4 ++-- xen/include/public/io/pvcalls.h | 2 +- xen/include/public/io/ring.h | 12 ++++++++++-- xen/include/public/io/sndif.h | 2 +- xen/include/public/xen-compat.h | 2 +- 8 files changed, 19 insertions(+), 9 deletions(-)
CHANGELOG.md +2 -0
@@ -7,6 +7,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [4.19.0 UNRELEASED](https://xenbits.xenproject.org/gitweb/?p=xen.git;a=shortlog;h=staging) - TBD ### Changed + - Changed flexible array definitions in public I/O interface headers to not + use "1" as the number of array elements. ### Added - On x86:
xen/include/public/io/cameraif.h +1 -1
@@ -763,7 +763,7 @@ struct xencamera_buf_create_req {*/ struct xencamera_page_directory {grant_ref_t gref_dir_next_page; -grant_ref_t gref[1 ];/* Variable length */ +grant_ref_t gref[XENPV_FLEX_ARRAY_DIM ]; };/*
xen/include/public/io/displif.h +1 -1
@@ -537,7 +537,7 @@ struct xendispl_dbuf_create_req {struct xendispl_page_directory {grant_ref_t gref_dir_next_page; -grant_ref_t gref[1 ];/* Variable length */ +grant_ref_t gref[XENPV_FLEX_ARRAY_DIM ]; };/*
xen/include/public/io/fsif.h +2 -2
@@ -40,7 +40,7 @@ struct fsif_read_request {int32_t pad;uint64_t len;uint64_t offset; -grant_ref_t grefs[1 ];/* Variable length */ +grant_ref_t grefs[XENPV_FLEX_ARRAY_DIM ]; };struct fsif_write_request {
@@ -48,7 +48,7 @@ struct fsif_write_request {int32_t pad;uint64_t len;uint64_t offset; -grant_ref_t grefs[1 ];/* Variable length */ +grant_ref_t grefs[XENPV_FLEX_ARRAY_DIM ]; };struct fsif_stat_request {
xen/include/public/io/pvcalls.h +1 -1
@@ -30,7 +30,7 @@ struct pvcalls_data_intf {uint8_t pad2[52 ];RING_IDX ring_order; -grant_ref_t ref[]; +grant_ref_t ref[XEN_FLEX_ARRAY_DIM ]; };DEFINE_XEN_FLEX_RING (pvcalls);
xen/include/public/io/ring.h +10 -2
@@ -25,8 +25,16 @@* and grant_table.h from the Xen public headers. */ +#include "../xen.h" #include "../xen-compat.h" +/* Some PV I/O interfaces need a compatibility variant. */ +#if __XEN_INTERFACE_VERSION__ <0x00041300 +#define XENPV_FLEX_ARRAY_DIM 1/* variable size */ +#else +#define XENPV_FLEX_ARRAY_DIM XEN_FLEX_ARRAY_DIM +#endif +#if __XEN_INTERFACE_VERSION__ <0x00030208 #define xen_mb () mb()#define xen_rmb () rmb()
@@ -110,7 +118,7 @@ struct __name##_sring { \uint8_t pvt_pad[4 ]; \ } pvt; \uint8_t __pad[44 ]; \ - union __name##_sring_entry ring[1]; /* variable-length */ \ + union __name##_sring_entry ring[XENPV_FLEX_ARRAY_DIM]; \ }; \ \/* "Front" end's private variables */ \
@@ -479,7 +487,7 @@ struct name##_data_intf { \uint8_t pad2[56 ]; \ \RING_IDX ring_order; \ -grant_ref_t ref[]; \ +grant_ref_t ref[XEN_FLEX_ARRAY_DIM ]; \ }; \DEFINE_XEN_FLEX_RING (name)
xen/include/public/io/sndif.h +1 -1
@@ -659,7 +659,7 @@ struct xensnd_open_req {struct xensnd_page_directory {grant_ref_t gref_dir_next_page; -grant_ref_t gref[1 ];/* Variable length */ +grant_ref_t gref[XENPV_FLEX_ARRAY_DIM ]; };/*
xen/include/public/xen-compat.h +1 -1
@@ -10,7 +10,7 @@#ifndef __XEN_PUBLIC_XEN_COMPAT_H__#define __XEN_PUBLIC_XEN_COMPAT_H__ -#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040e00 +#define __XEN_LATEST_INTERFACE_VERSION__ 0x00041300#if defined(__XEN__) || defined(__XEN_TOOLS__)/* Xen is built with matching headers and implements the latest interface. */
Signature · 1 line
2.35.3
Hi Juergen,
Quoted 14 lines · Juergen Gross
Flexible arrays in public headers can be problematic with some compilers.
With
XEN_FLEX_ARRAY_DIMthere is a mechanism available to deal with this issue, but care must be taken to not change the affected structs in an incompatible way.So bump
__XEN_LATEST_INTERFACE_VERSION__and introduce a new macroXENPV_FLEX_ARRAY_DIMwhich will beXENPV_FLEX_ARRAY_DIMwith the interface version being new enough and "1" (the value used today in the affected headers) when the interface version is an old one.
Quoted 7 lines
Replace the arr[1] instances (this includes the ones seen to be problematic in recent Linux kernels [1]) with arr[XENPV_FLEX_ARRAY_DIM] in order to avoid compilation errors.
[1]: https://bugzilla.kernel.org/show_bug.cgi?id=217693
Signed-off-by Juergen Gross <[email protected]>
Kind regards,
Henry
Quoted 12 lines · Juergen Gross
Flexible arrays in public headers can be problematic with some compilers.
With
XEN_FLEX_ARRAY_DIMthere is a mechanism available to deal with this issue, but care must be taken to not change the affected structs in an incompatible way.So bump
__XEN_LATEST_INTERFACE_VERSION__and introduce a new macroXENPV_FLEX_ARRAY_DIMwhich will beXENPV_FLEX_ARRAY_DIMwith the interface version being new enough and "1" (the value used today in the affected headers) when the interface version is an old one.
Quoted 7 lines
Replace the arr[1] instances (this includes the ones seen to be problematic in recent Linux kernels [1]) with arr[XENPV_FLEX_ARRAY_DIM] in order to avoid compilation errors.
[1]: https://bugzilla.kernel.org/show_bug.cgi?id=217693
Signed-off-by Juergen Gross <[email protected]>
xen/include/public/io/ring.h line 29
Quoted 8 lines
xen/include/public/io/ring.h +1
-0@@ -25,8 +25,16 @@* and grant_table.h from the Xen public headers. */ +#include "../xen.h" #include "../xen-compat.h"
Just to mention it: While perhaps good practice, I'm not convinced this extra #include is actually needed here.
Quoted 28 lines
xen/include/public/io/ring.h +9
-2+/* Some PV I/O interfaces need a compatibility variant. */ +#if __XEN_INTERFACE_VERSION__ <0x00041300 +#define XENPV_FLEX_ARRAY_DIM 1/* variable size */ +#else +#define XENPV_FLEX_ARRAY_DIM XEN_FLEX_ARRAY_DIM +#endif +#if __XEN_INTERFACE_VERSION__ <0x00030208 #define xen_mb () mb()#define xen_rmb () rmb()@@ -110,7 +118,7 @@ struct __name##_sring { \uint8_t pvt_pad[4 ]; \ } pvt; \uint8_t __pad[44 ]; \ - union __name##_sring_entry ring[1]; /* variable-length */ \ + union __name##_sring_entry ring[XENPV_FLEX_ARRAY_DIM]; \ }; \ \/* "Front" end's private variables */ \@@ -479,7 +487,7 @@ struct name##_data_intf { \uint8_t pad2[56 ]; \ \RING_IDX ring_order; \ -grant_ref_t ref[]; \ +grant_ref_t ref[XEN_FLEX_ARRAY_DIM ]; \ }; \DEFINE_XEN_FLEX_RING (name)
Quoted 12 lines · Juergen Gross
Flexible arrays in public headers can be problematic with some compilers.
With
XEN_FLEX_ARRAY_DIMthere is a mechanism available to deal with this issue, but care must be taken to not change the affected structs in an incompatible way.So bump
__XEN_LATEST_INTERFACE_VERSION__and introduce a new macroXENPV_FLEX_ARRAY_DIMwhich will beXENPV_FLEX_ARRAY_DIMwith the interface version being new enough and "1" (the value used today in the affected headers) when the interface version is an old one.
Quoted 7 lines
Replace the arr[1] instances (this includes the ones seen to be problematic in recent Linux kernels [1]) with arr[XENPV_FLEX_ARRAY_DIM] in order to avoid compilation errors.
[1]: https://bugzilla.kernel.org/show_bug.cgi?id=217693
Signed-off-by Juergen Gross <[email protected]>
Cheers,
Signature · 1 line
Julien Grall