[PATCH] drm/i915/gvt: Add __nonstring annotations for unterminated strings

Kees Cook posted 1 patch 11 months ago
drivers/gpu/drm/i915/gvt/opregion.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] drm/i915/gvt: Add __nonstring annotations for unterminated strings
Posted by Kees Cook 11 months ago
When a character array without a terminating NUL character has a static
initializer, GCC 15's -Wunterminated-string-initialization will only
warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
with __nonstring to and correctly identify the char array as "not a C
string" and thereby eliminate the warning.

Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
Cc: Zhi Wang <zhi.wang.linux@gmail.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Tvrtko Ursulin <tursulin@ursulin.net>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: intel-gvt-dev@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Kees Cook <kees@kernel.org>
---
 drivers/gpu/drm/i915/gvt/opregion.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
index 509f9ccae3a9..f701638d3145 100644
--- a/drivers/gpu/drm/i915/gvt/opregion.c
+++ b/drivers/gpu/drm/i915/gvt/opregion.c
@@ -43,7 +43,7 @@
 #define DEVICE_TYPE_EFP4   0x10
 
 struct opregion_header {
-	u8 signature[16];
+	u8 signature[16] __nonstring;
 	u32 size;
 	u32 opregion_ver;
 	u8 bios_ver[32];
@@ -222,7 +222,7 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
 	u8 *buf;
 	struct opregion_header *header;
 	struct vbt v;
-	const char opregion_signature[16] = OPREGION_SIGNATURE;
+	const char opregion_signature[16] __nonstring = OPREGION_SIGNATURE;
 
 	gvt_dbg_core("init vgpu%d opregion\n", vgpu->id);
 	vgpu_opregion(vgpu)->va = (void *)__get_free_pages(GFP_KERNEL |
-- 
2.34.1
Re: [PATCH] drm/i915/gvt: Add __nonstring annotations for unterminated strings
Posted by Thorsten Leemhuis 10 months, 1 week ago
On 10.03.25 23:23, Kees Cook wrote:
> When a character array without a terminating NUL character has a static
> initializer, GCC 15's -Wunterminated-string-initialization will only
> warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
> with __nonstring to and correctly identify the char array as "not a C
> string" and thereby eliminate the warning.
> 
> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> [...]
> Signed-off-by: Kees Cook <kees@kernel.org>

To provide another small data point:

Tested-by: Thorsten Leemhuis <linux@leemhuis.info>

A "Compile-Tested-by", to be precise: after a handful similar patches
reached mainline recently this is the only one I still need to compile
the pretty broad Fedora rawhide config on rawhide using the GCC 15
pre-release it currently includes. The latter or the final will
hopefully soon also reach Fedora 42 beta as well and bring the "[1]"
mentioned in the patch description above to F42 -- which will be
released in a few weeks, so I guess it would be nice to have this patch
mainlined rather sooner that later to avoid more people running into this.

HTH, ciao, Thorsten
Re: [PATCH] drm/i915/gvt: Add __nonstring annotations for unterminated strings
Posted by Jani Nikula 10 months, 1 week ago
On Mon, 31 Mar 2025, Thorsten Leemhuis <linux@leemhuis.info> wrote:
> On 10.03.25 23:23, Kees Cook wrote:
>> When a character array without a terminating NUL character has a static
>> initializer, GCC 15's -Wunterminated-string-initialization will only
>> warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
>> with __nonstring to and correctly identify the char array as "not a C
>> string" and thereby eliminate the warning.
>> 
>> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
>> [...]
>> Signed-off-by: Kees Cook <kees@kernel.org>
>
> To provide another small data point:
>
> Tested-by: Thorsten Leemhuis <linux@leemhuis.info>
>
> A "Compile-Tested-by", to be precise: after a handful similar patches
> reached mainline recently this is the only one I still need to compile
> the pretty broad Fedora rawhide config on rawhide using the GCC 15
> pre-release it currently includes. The latter or the final will
> hopefully soon also reach Fedora 42 beta as well and bring the "[1]"
> mentioned in the patch description above to F42 -- which will be
> released in a few weeks, so I guess it would be nice to have this patch
> mainlined rather sooner that later to avoid more people running into this.

Thanks for testing, though I've merged [1] instead.

BR,
Jani.



[1] https://lore.kernel.org/r/20250327124739.2609656-1-jani.nikula@intel.com


-- 
Jani Nikula, Intel
Re: [PATCH] drm/i915/gvt: Add __nonstring annotations for unterminated strings
Posted by Thorsten Leemhuis 10 months, 1 week ago
On 01.04.25 10:46, Jani Nikula wrote:
> On Mon, 31 Mar 2025, Thorsten Leemhuis <linux@leemhuis.info> wrote:
>> On 10.03.25 23:23, Kees Cook wrote:
>>> When a character array without a terminating NUL character has a static
>>> initializer, GCC 15's -Wunterminated-string-initialization will only
>>> warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
>>> with __nonstring to and correctly identify the char array as "not a C
>>> string" and thereby eliminate the warning.
>>>
>>> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
>>> [...]
>>> Signed-off-by: Kees Cook <kees@kernel.org>
>>
>> To provide another small data point:
>>
>> Tested-by: Thorsten Leemhuis <linux@leemhuis.info>
>>
>> A "Compile-Tested-by", to be precise: after a handful similar patches
>> reached mainline recently this is the only one I still need to compile
>> the pretty broad Fedora rawhide config on rawhide using the GCC 15
>> pre-release it currently includes. The latter or the final will
>> hopefully soon also reach Fedora 42 beta as well and bring the "[1]"
>> mentioned in the patch description above to F42 -- which will be
>> released in a few weeks, so I guess it would be nice to have this patch
>> mainlined rather sooner that later to avoid more people running into this.
> 
> Thanks for testing, though I've merged [1] instead.
> 
> [1] https://lore.kernel.org/r/20250327124739.2609656-1-jani.nikula@intel.com

Yeah, sorry, I only spotted that one two hours ago and started a test
compile a while ago, but seems I'm too late here. Whatever, happens. :-D

Many thx for taking care of that! Ciao, Thorsten
Re: [PATCH] drm/i915/gvt: Add __nonstring annotations for unterminated strings
Posted by Damian Tometzki 10 months, 2 weeks ago
On Mon, 10. Mar 15:23, Kees Cook wrote:
> When a character array without a terminating NUL character has a static
> initializer, GCC 15's -Wunterminated-string-initialization will only
> warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
> with __nonstring to and correctly identify the char array as "not a C
> string" and thereby eliminate the warning.
> 
> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
> Cc: Zhi Wang <zhi.wang.linux@gmail.com>
> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Tvrtko Ursulin <tursulin@ursulin.net>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Simona Vetter <simona@ffwll.ch>
> Cc: intel-gvt-dev@lists.freedesktop.org
> Cc: intel-gfx@lists.freedesktop.org
> Cc: dri-devel@lists.freedesktop.org
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
>  drivers/gpu/drm/i915/gvt/opregion.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
> index 509f9ccae3a9..f701638d3145 100644
> --- a/drivers/gpu/drm/i915/gvt/opregion.c
> +++ b/drivers/gpu/drm/i915/gvt/opregion.c
> @@ -43,7 +43,7 @@
>  #define DEVICE_TYPE_EFP4   0x10
>  
>  struct opregion_header {
> -	u8 signature[16];
> +	u8 signature[16] __nonstring;
>  	u32 size;
>  	u32 opregion_ver;
>  	u8 bios_ver[32];
> @@ -222,7 +222,7 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
>  	u8 *buf;
>  	struct opregion_header *header;
>  	struct vbt v;
> -	const char opregion_signature[16] = OPREGION_SIGNATURE;
> +	const char opregion_signature[16] __nonstring = OPREGION_SIGNATURE;
>  
>  	gvt_dbg_core("init vgpu%d opregion\n", vgpu->id);
>  	vgpu_opregion(vgpu)->va = (void *)__get_free_pages(GFP_KERNEL |
> -- 
> 2.34.1
> 
Hello together,

it doesnt resolve the build issue with gcc15 gcc (GCC) 15.0.1 20250228

CC [M]  drivers/gpu/drm/i915/gvt/scheduler.o
/home/damian/kernel/linux/drivers/gpu/drm/i915/gvt/opregion.c: In function ‘intel_vgpu_init_opregion’:
/home/damian/kernel/linux/drivers/gpu/drm/i915/gvt/opregion.c:35:28: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
   35 | #define OPREGION_SIGNATURE "IntelGraphicsMem"
      |                            ^~~~~~~~~~~~~~~~~~
/home/damian/kernel/linux/drivers/gpu/drm/i915/gvt/opregion.c:225:57: note: in expansion of macro ‘OPREGION_SIGNATURE’
  225 |         const char opregion_signature[16] __nonstring = OPREGION_SIGNATURE;
      |                                                         ^~~~~~~~~~~~~~~~~~
  CC [M]  drivers/gpu/drm/i915/gvt/trace_points.o
cc1: all warnings being treated as errors
make[7]: *** [/home/damian/kernel/linux/scripts/Makefile.build:207: drivers/gpu/drm/i915/gvt/opregion.o] Error 1
make[7]: *** Waiting for unfinished jobs....
  CC [M]  drivers/gpu/drm/i915/gvt/vgpu.o
make[6]: *** [/home/damian/kernel/linux/scripts/Makefile.build:465: drivers/gpu/drm/i915] Error 2
make[5]: *** [/home/damian/kernel/linux/s


-- 
VG
Damian Tometzki
Re: [PATCH] drm/i915/gvt: Add __nonstring annotations for unterminated strings
Posted by Kees Cook 10 months, 2 weeks ago
On Sun, Mar 23, 2025 at 12:42:41PM +0000, Damian Tometzki wrote:
> On Mon, 10. Mar 15:23, Kees Cook wrote:
> > When a character array without a terminating NUL character has a static
> > initializer, GCC 15's -Wunterminated-string-initialization will only
> > warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
> > with __nonstring to and correctly identify the char array as "not a C
> > string" and thereby eliminate the warning.
> > 
> > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> > Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
> > Cc: Zhi Wang <zhi.wang.linux@gmail.com>
> > Cc: Jani Nikula <jani.nikula@linux.intel.com>
> > Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> > Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> > Cc: Tvrtko Ursulin <tursulin@ursulin.net>
> > Cc: David Airlie <airlied@gmail.com>
> > Cc: Simona Vetter <simona@ffwll.ch>
> > Cc: intel-gvt-dev@lists.freedesktop.org
> > Cc: intel-gfx@lists.freedesktop.org
> > Cc: dri-devel@lists.freedesktop.org
> > Signed-off-by: Kees Cook <kees@kernel.org>
> > ---
> >  drivers/gpu/drm/i915/gvt/opregion.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
> > index 509f9ccae3a9..f701638d3145 100644
> > --- a/drivers/gpu/drm/i915/gvt/opregion.c
> > +++ b/drivers/gpu/drm/i915/gvt/opregion.c
> > @@ -43,7 +43,7 @@
> >  #define DEVICE_TYPE_EFP4   0x10
> >  
> >  struct opregion_header {
> > -	u8 signature[16];
> > +	u8 signature[16] __nonstring;
> >  	u32 size;
> >  	u32 opregion_ver;
> >  	u8 bios_ver[32];
> > @@ -222,7 +222,7 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
> >  	u8 *buf;
> >  	struct opregion_header *header;
> >  	struct vbt v;
> > -	const char opregion_signature[16] = OPREGION_SIGNATURE;
> > +	const char opregion_signature[16] __nonstring = OPREGION_SIGNATURE;
> >  
> >  	gvt_dbg_core("init vgpu%d opregion\n", vgpu->id);
> >  	vgpu_opregion(vgpu)->va = (void *)__get_free_pages(GFP_KERNEL |
> > -- 
> > 2.34.1
> > 
> Hello together,
> 
> it doesnt resolve the build issue with gcc15 gcc (GCC) 15.0.1 20250228

This was a recent enhancement to GCC, and that 20250228 build does not
include it. (GCC 15 is not actually released yet...)

-- 
Kees Cook
Re: [PATCH] drm/i915/gvt: Add __nonstring annotations for unterminated strings
Posted by Jani Nikula 10 months, 2 weeks ago
On Sun, 23 Mar 2025, Damian Tometzki <damian@riscv-rocks.de> wrote:
> On Mon, 10. Mar 15:23, Kees Cook wrote:
>> When a character array without a terminating NUL character has a static
>> initializer, GCC 15's -Wunterminated-string-initialization will only
>> warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
>> with __nonstring to and correctly identify the char array as "not a C
>> string" and thereby eliminate the warning.
>> 
>> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
>> Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
>> Cc: Zhi Wang <zhi.wang.linux@gmail.com>
>> Cc: Jani Nikula <jani.nikula@linux.intel.com>
>> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
>> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
>> Cc: Tvrtko Ursulin <tursulin@ursulin.net>
>> Cc: David Airlie <airlied@gmail.com>
>> Cc: Simona Vetter <simona@ffwll.ch>
>> Cc: intel-gvt-dev@lists.freedesktop.org
>> Cc: intel-gfx@lists.freedesktop.org
>> Cc: dri-devel@lists.freedesktop.org
>> Signed-off-by: Kees Cook <kees@kernel.org>
>> ---
>>  drivers/gpu/drm/i915/gvt/opregion.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
>> index 509f9ccae3a9..f701638d3145 100644
>> --- a/drivers/gpu/drm/i915/gvt/opregion.c
>> +++ b/drivers/gpu/drm/i915/gvt/opregion.c
>> @@ -43,7 +43,7 @@
>>  #define DEVICE_TYPE_EFP4   0x10
>>  
>>  struct opregion_header {
>> -	u8 signature[16];
>> +	u8 signature[16] __nonstring;

Why would this annotation be needed? It's not treated as a string
anywhere, and it's u8 not char.

>>  	u32 size;
>>  	u32 opregion_ver;
>>  	u8 bios_ver[32];
>> @@ -222,7 +222,7 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
>>  	u8 *buf;
>>  	struct opregion_header *header;
>>  	struct vbt v;
>> -	const char opregion_signature[16] = OPREGION_SIGNATURE;
>> +	const char opregion_signature[16] __nonstring = OPREGION_SIGNATURE;
>>  
>>  	gvt_dbg_core("init vgpu%d opregion\n", vgpu->id);
>>  	vgpu_opregion(vgpu)->va = (void *)__get_free_pages(GFP_KERNEL |
>> -- 
>> 2.34.1
>> 
> Hello together,
>
> it doesnt resolve the build issue with gcc15 gcc (GCC) 15.0.1 20250228
>
> CC [M]  drivers/gpu/drm/i915/gvt/scheduler.o
> /home/damian/kernel/linux/drivers/gpu/drm/i915/gvt/opregion.c: In function ‘intel_vgpu_init_opregion’:
> /home/damian/kernel/linux/drivers/gpu/drm/i915/gvt/opregion.c:35:28: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
>    35 | #define OPREGION_SIGNATURE "IntelGraphicsMem"
>       |                            ^~~~~~~~~~~~~~~~~~
> /home/damian/kernel/linux/drivers/gpu/drm/i915/gvt/opregion.c:225:57: note: in expansion of macro ‘OPREGION_SIGNATURE’
>   225 |         const char opregion_signature[16] __nonstring = OPREGION_SIGNATURE;
>       |                                                         ^~~~~~~~~~~~~~~~~~
>   CC [M]  drivers/gpu/drm/i915/gvt/trace_points.o
> cc1: all warnings being treated as errors
> make[7]: *** [/home/damian/kernel/linux/scripts/Makefile.build:207: drivers/gpu/drm/i915/gvt/opregion.o] Error 1
> make[7]: *** Waiting for unfinished jobs....
>   CC [M]  drivers/gpu/drm/i915/gvt/vgpu.o
> make[6]: *** [/home/damian/kernel/linux/scripts/Makefile.build:465: drivers/gpu/drm/i915] Error 2
> make[5]: *** [/home/damian/kernel/linux/s

What about this?

IMO it's anyway good practice to use sizeof(dest) rather than
sizeof(src) for memcpy.


diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
index 509f9ccae3a9..dbad4d853d3a 100644
--- a/drivers/gpu/drm/i915/gvt/opregion.c
+++ b/drivers/gpu/drm/i915/gvt/opregion.c
@@ -222,7 +222,6 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
 	u8 *buf;
 	struct opregion_header *header;
 	struct vbt v;
-	const char opregion_signature[16] = OPREGION_SIGNATURE;
 
 	gvt_dbg_core("init vgpu%d opregion\n", vgpu->id);
 	vgpu_opregion(vgpu)->va = (void *)__get_free_pages(GFP_KERNEL |
@@ -236,8 +235,10 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
 	/* emulated opregion with VBT mailbox only */
 	buf = (u8 *)vgpu_opregion(vgpu)->va;
 	header = (struct opregion_header *)buf;
-	memcpy(header->signature, opregion_signature,
-	       sizeof(opregion_signature));
+
+	static_assert(sizeof(header->signature) == sizeof(OPREGION_SIGNATURE) - 1);
+	memcpy(header->signature, OPREGION_SIGNATURE, sizeof(header->signature));
+
 	header->size = 0x8;
 	header->opregion_ver = 0x02000000;
 	header->mboxes = MBOX_VBT;



-- 
Jani Nikula, Intel
Re: [PATCH] drm/i915/gvt: Add __nonstring annotations for unterminated strings
Posted by Nicolas Chauvet 10 months, 2 weeks ago
Le lun. 24 mars 2025 à 13:54, Jani Nikula
<jani.nikula@linux.intel.com> a écrit :
>
> On Sun, 23 Mar 2025, Damian Tometzki <damian@riscv-rocks.de> wrote:
> > On Mon, 10. Mar 15:23, Kees Cook wrote:
> >> When a character array without a terminating NUL character has a static
> >> initializer, GCC 15's -Wunterminated-string-initialization will only
> >> warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
> >> with __nonstring to and correctly identify the char array as "not a C
> >> string" and thereby eliminate the warning.
> >>
> >> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> >> Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
> >> Cc: Zhi Wang <zhi.wang.linux@gmail.com>
> >> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> >> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> >> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> >> Cc: Tvrtko Ursulin <tursulin@ursulin.net>
> >> Cc: David Airlie <airlied@gmail.com>
> >> Cc: Simona Vetter <simona@ffwll.ch>
> >> Cc: intel-gvt-dev@lists.freedesktop.org
> >> Cc: intel-gfx@lists.freedesktop.org
> >> Cc: dri-devel@lists.freedesktop.org
> >> Signed-off-by: Kees Cook <kees@kernel.org>
> >> ---
> >>  drivers/gpu/drm/i915/gvt/opregion.c | 4 ++--
> >>  1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
> >> index 509f9ccae3a9..f701638d3145 100644
> >> --- a/drivers/gpu/drm/i915/gvt/opregion.c
> >> +++ b/drivers/gpu/drm/i915/gvt/opregion.c
> >> @@ -43,7 +43,7 @@
> >>  #define DEVICE_TYPE_EFP4   0x10
> >>
> >>  struct opregion_header {
> >> -    u8 signature[16];
> >> +    u8 signature[16] __nonstring;
>
> Why would this annotation be needed? It's not treated as a string
> anywhere, and it's u8 not char.
>
> >>      u32 size;
> >>      u32 opregion_ver;
> >>      u8 bios_ver[32];
> >> @@ -222,7 +222,7 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
> >>      u8 *buf;
> >>      struct opregion_header *header;
> >>      struct vbt v;
> >> -    const char opregion_signature[16] = OPREGION_SIGNATURE;
> >> +    const char opregion_signature[16] __nonstring = OPREGION_SIGNATURE;
> >>
> >>      gvt_dbg_core("init vgpu%d opregion\n", vgpu->id);
> >>      vgpu_opregion(vgpu)->va = (void *)__get_free_pages(GFP_KERNEL |
> >> --
> >> 2.34.1
> >>
> > Hello together,
> >
> > it doesnt resolve the build issue with gcc15 gcc (GCC) 15.0.1 20250228
> >
> > CC [M]  drivers/gpu/drm/i915/gvt/scheduler.o
> > /home/damian/kernel/linux/drivers/gpu/drm/i915/gvt/opregion.c: In function ‘intel_vgpu_init_opregion’:
> > /home/damian/kernel/linux/drivers/gpu/drm/i915/gvt/opregion.c:35:28: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
> >    35 | #define OPREGION_SIGNATURE "IntelGraphicsMem"
> >       |                            ^~~~~~~~~~~~~~~~~~
> > /home/damian/kernel/linux/drivers/gpu/drm/i915/gvt/opregion.c:225:57: note: in expansion of macro ‘OPREGION_SIGNATURE’
> >   225 |         const char opregion_signature[16] __nonstring = OPREGION_SIGNATURE;
> >       |                                                         ^~~~~~~~~~~~~~~~~~
> >   CC [M]  drivers/gpu/drm/i915/gvt/trace_points.o
> > cc1: all warnings being treated as errors
> > make[7]: *** [/home/damian/kernel/linux/scripts/Makefile.build:207: drivers/gpu/drm/i915/gvt/opregion.o] Error 1
> > make[7]: *** Waiting for unfinished jobs....
> >   CC [M]  drivers/gpu/drm/i915/gvt/vgpu.o
> > make[6]: *** [/home/damian/kernel/linux/scripts/Makefile.build:465: drivers/gpu/drm/i915] Error 2
> > make[5]: *** [/home/damian/kernel/linux/s
>
> What about this?
>
> IMO it's anyway good practice to use sizeof(dest) rather than
> sizeof(src) for memcpy.
>
>
> diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
> index 509f9ccae3a9..dbad4d853d3a 100644
> --- a/drivers/gpu/drm/i915/gvt/opregion.c
> +++ b/drivers/gpu/drm/i915/gvt/opregion.c
> @@ -222,7 +222,6 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
>         u8 *buf;
>         struct opregion_header *header;
>         struct vbt v;
> -       const char opregion_signature[16] = OPREGION_SIGNATURE;
>
>         gvt_dbg_core("init vgpu%d opregion\n", vgpu->id);
>         vgpu_opregion(vgpu)->va = (void *)__get_free_pages(GFP_KERNEL |
> @@ -236,8 +235,10 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
>         /* emulated opregion with VBT mailbox only */
>         buf = (u8 *)vgpu_opregion(vgpu)->va;
>         header = (struct opregion_header *)buf;
> -       memcpy(header->signature, opregion_signature,
> -              sizeof(opregion_signature));
> +
> +       static_assert(sizeof(header->signature) == sizeof(OPREGION_SIGNATURE) - 1);
> +       memcpy(header->signature, OPREGION_SIGNATURE, sizeof(header->signature));
> +
>         header->size = 0x8;
>         header->opregion_ver = 0x02000000;
>         header->mboxes = MBOX_VBT;
>
>
>
> --
> Jani Nikula, Intel

This patch does solve the build issue with gcc-15 on Fedora-42
(gcc-15.0.1-0.9.fc42.x86_64).
https://copr.fedorainfracloud.org/coprs/kwizart/kernel-longterm-6.12/build/8812754/

Thanks.
Re: [PATCH] drm/i915/gvt: Add __nonstring annotations for unterminated strings
Posted by Damian Tometzki 10 months, 2 weeks ago
On Mon, 24. Mar 22:19, Nicolas Chauvet wrote:
> Le lun. 24 mars 2025 à 13:54, Jani Nikula
> <jani.nikula@linux.intel.com> a écrit :
> >
> > On Sun, 23 Mar 2025, Damian Tometzki <damian@riscv-rocks.de> wrote:
> > > On Mon, 10. Mar 15:23, Kees Cook wrote:
> > >> When a character array without a terminating NUL character has a static
> > >> initializer, GCC 15's -Wunterminated-string-initialization will only
> > >> warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
> > >> with __nonstring to and correctly identify the char array as "not a C
> > >> string" and thereby eliminate the warning.
> > >>
> > >> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> > >> Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
> > >> Cc: Zhi Wang <zhi.wang.linux@gmail.com>
> > >> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> > >> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> > >> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> > >> Cc: Tvrtko Ursulin <tursulin@ursulin.net>
> > >> Cc: David Airlie <airlied@gmail.com>
> > >> Cc: Simona Vetter <simona@ffwll.ch>
> > >> Cc: intel-gvt-dev@lists.freedesktop.org
> > >> Cc: intel-gfx@lists.freedesktop.org
> > >> Cc: dri-devel@lists.freedesktop.org
> > >> Signed-off-by: Kees Cook <kees@kernel.org>
> > >> ---
> > >>  drivers/gpu/drm/i915/gvt/opregion.c | 4 ++--
> > >>  1 file changed, 2 insertions(+), 2 deletions(-)
> > >>
> > >> diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
> > >> index 509f9ccae3a9..f701638d3145 100644
> > >> --- a/drivers/gpu/drm/i915/gvt/opregion.c
> > >> +++ b/drivers/gpu/drm/i915/gvt/opregion.c
> > >> @@ -43,7 +43,7 @@
> > >>  #define DEVICE_TYPE_EFP4   0x10
> > >>
> > >>  struct opregion_header {
> > >> -    u8 signature[16];
> > >> +    u8 signature[16] __nonstring;
> >
> > Why would this annotation be needed? It's not treated as a string
> > anywhere, and it's u8 not char.
> >
> > >>      u32 size;
> > >>      u32 opregion_ver;
> > >>      u8 bios_ver[32];
> > >> @@ -222,7 +222,7 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
> > >>      u8 *buf;
> > >>      struct opregion_header *header;
> > >>      struct vbt v;
> > >> -    const char opregion_signature[16] = OPREGION_SIGNATURE;
> > >> +    const char opregion_signature[16] __nonstring = OPREGION_SIGNATURE;
> > >>
> > >>      gvt_dbg_core("init vgpu%d opregion\n", vgpu->id);
> > >>      vgpu_opregion(vgpu)->va = (void *)__get_free_pages(GFP_KERNEL |
> > >> --
> > >> 2.34.1
> > >>
> > > Hello together,
> > >
> > > it doesnt resolve the build issue with gcc15 gcc (GCC) 15.0.1 20250228
> > >
> > > CC [M]  drivers/gpu/drm/i915/gvt/scheduler.o
> > > /home/damian/kernel/linux/drivers/gpu/drm/i915/gvt/opregion.c: In function ‘intel_vgpu_init_opregion’:
> > > /home/damian/kernel/linux/drivers/gpu/drm/i915/gvt/opregion.c:35:28: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
> > >    35 | #define OPREGION_SIGNATURE "IntelGraphicsMem"
> > >       |                            ^~~~~~~~~~~~~~~~~~
> > > /home/damian/kernel/linux/drivers/gpu/drm/i915/gvt/opregion.c:225:57: note: in expansion of macro ‘OPREGION_SIGNATURE’
> > >   225 |         const char opregion_signature[16] __nonstring = OPREGION_SIGNATURE;
> > >       |                                                         ^~~~~~~~~~~~~~~~~~
> > >   CC [M]  drivers/gpu/drm/i915/gvt/trace_points.o
> > > cc1: all warnings being treated as errors
> > > make[7]: *** [/home/damian/kernel/linux/scripts/Makefile.build:207: drivers/gpu/drm/i915/gvt/opregion.o] Error 1
> > > make[7]: *** Waiting for unfinished jobs....
> > >   CC [M]  drivers/gpu/drm/i915/gvt/vgpu.o
> > > make[6]: *** [/home/damian/kernel/linux/scripts/Makefile.build:465: drivers/gpu/drm/i915] Error 2
> > > make[5]: *** [/home/damian/kernel/linux/s
> >
> > What about this?
> >
> > IMO it's anyway good practice to use sizeof(dest) rather than
> > sizeof(src) for memcpy.
> >
> >
> > diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
> > index 509f9ccae3a9..dbad4d853d3a 100644
> > --- a/drivers/gpu/drm/i915/gvt/opregion.c
> > +++ b/drivers/gpu/drm/i915/gvt/opregion.c
> > @@ -222,7 +222,6 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
> >         u8 *buf;
> >         struct opregion_header *header;
> >         struct vbt v;
> > -       const char opregion_signature[16] = OPREGION_SIGNATURE;
> >
> >         gvt_dbg_core("init vgpu%d opregion\n", vgpu->id);
> >         vgpu_opregion(vgpu)->va = (void *)__get_free_pages(GFP_KERNEL |
> > @@ -236,8 +235,10 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
> >         /* emulated opregion with VBT mailbox only */
> >         buf = (u8 *)vgpu_opregion(vgpu)->va;
> >         header = (struct opregion_header *)buf;
> > -       memcpy(header->signature, opregion_signature,
> > -              sizeof(opregion_signature));
> > +
> > +       static_assert(sizeof(header->signature) == sizeof(OPREGION_SIGNATURE) - 1);
> > +       memcpy(header->signature, OPREGION_SIGNATURE, sizeof(header->signature));
> > +
> >         header->size = 0x8;
> >         header->opregion_ver = 0x02000000;
> >         header->mboxes = MBOX_VBT;
> >
> >
> >
> > --
> > Jani Nikula, Intel
> 
> This patch does solve the build issue with gcc-15 on Fedora-42
> (gcc-15.0.1-0.9.fc42.x86_64).
> https://copr.fedorainfracloud.org/coprs/kwizart/kernel-longterm-6.12/build/8812754/
testet-by Damian Tometzki
Thanks
Damian

> 
> Thanks.

-- 
VG
Damian Tometzki