public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Lyude Paul <lyude@redhat.com>, Danilo Krummrich <dakr@kernel.org>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] drm/nouveau: svm: Avoid -Wflex-array-member-not-at-end warning
Date: Mon, 7 Apr 2025 12:25:50 -0700	[thread overview]
Message-ID: <202504071225.6AB490E7@keescook> (raw)
In-Reply-To: <Z-2uezeHt1aaHH6x@kspp>

On Wed, Apr 02, 2025 at 03:39:07PM -0600, 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.
> 
> Use the `DEFINE_RAW_FLEX()` helper for an on-stack definition of
> a flexible structure where the size of the flexible-array member
> is known at compile-time, and refactor the rest of the code,
> accordingly.
> 
> So, with these changes, fix the following warning:
> 
> drivers/gpu/drm/nouveau/nouveau_svm.c:724:44: 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/gpu/drm/nouveau/nouveau_svm.c | 39 +++++++++++++--------------
>  1 file changed, 18 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c
> index e12e2596ed84..6fa387da0637 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_svm.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c
> @@ -720,10 +720,7 @@ nouveau_svm_fault(struct work_struct *work)
>  	struct nouveau_svm *svm = container_of(buffer, typeof(*svm), buffer[buffer->id]);
>  	struct nvif_object *device = &svm->drm->client.device.object;
>  	struct nouveau_svmm *svmm;
> -	struct {
> -		struct nouveau_pfnmap_args i;
> -		u64 phys[1];
> -	} args;
> +	DEFINE_RAW_FLEX(struct nouveau_pfnmap_args, args, p.phys, 1);
>  	unsigned long hmm_flags;
>  	u64 inst, start, limit;
>  	int fi, fn;
> @@ -772,11 +769,11 @@ nouveau_svm_fault(struct work_struct *work)
>  	mutex_unlock(&svm->mutex);
>  
>  	/* Process list of faults. */
> -	args.i.i.version = 0;
> -	args.i.i.type = NVIF_IOCTL_V0_MTHD;
> -	args.i.m.version = 0;
> -	args.i.m.method = NVIF_VMM_V0_PFNMAP;
> -	args.i.p.version = 0;
> +	args->i.version = 0;
> +	args->i.type = NVIF_IOCTL_V0_MTHD;
> +	args->m.version = 0;
> +	args->m.method = NVIF_VMM_V0_PFNMAP;
> +	args->p.version = 0;
>  
>  	for (fi = 0; fn = fi + 1, fi < buffer->fault_nr; fi = fn) {
>  		struct svm_notifier notifier;
> @@ -802,9 +799,9 @@ nouveau_svm_fault(struct work_struct *work)
>  		 * fault window, determining required pages and access
>  		 * permissions based on pending faults.
>  		 */
> -		args.i.p.addr = start;
> -		args.i.p.page = PAGE_SHIFT;
> -		args.i.p.size = PAGE_SIZE;
> +		args->p.addr = start;
> +		args->p.page = PAGE_SHIFT;
> +		args->p.size = PAGE_SIZE;
>  		/*
>  		 * Determine required permissions based on GPU fault
>  		 * access flags.
> @@ -832,16 +829,16 @@ nouveau_svm_fault(struct work_struct *work)
>  
>  		notifier.svmm = svmm;
>  		if (atomic)
> -			ret = nouveau_atomic_range_fault(svmm, svm->drm,
> -							 &args.i, sizeof(args),
> +			ret = nouveau_atomic_range_fault(svmm, svm->drm, args,
> +							 __struct_size(args),
>  							 &notifier);
>  		else
> -			ret = nouveau_range_fault(svmm, svm->drm, &args.i,
> -						  sizeof(args), hmm_flags,
> -						  &notifier);
> +			ret = nouveau_range_fault(svmm, svm->drm, args,
> +						  __struct_size(args),
> +						  hmm_flags, &notifier);
>  		mmput(mm);
>  
> -		limit = args.i.p.addr + args.i.p.size;
> +		limit = args->p.addr + args->p.size;
>  		for (fn = fi; ++fn < buffer->fault_nr; ) {
>  			/* It's okay to skip over duplicate addresses from the
>  			 * same SVMM as faults are ordered by access type such
> @@ -855,14 +852,14 @@ nouveau_svm_fault(struct work_struct *work)
>  			if (buffer->fault[fn]->svmm != svmm ||
>  			    buffer->fault[fn]->addr >= limit ||
>  			    (buffer->fault[fi]->access == FAULT_ACCESS_READ &&
> -			     !(args.phys[0] & NVIF_VMM_PFNMAP_V0_V)) ||
> +			     !(args->p.phys[0] & NVIF_VMM_PFNMAP_V0_V)) ||
>  			    (buffer->fault[fi]->access != FAULT_ACCESS_READ &&
>  			     buffer->fault[fi]->access != FAULT_ACCESS_PREFETCH &&
> -			     !(args.phys[0] & NVIF_VMM_PFNMAP_V0_W)) ||
> +			     !(args->p.phys[0] & NVIF_VMM_PFNMAP_V0_W)) ||
>  			    (buffer->fault[fi]->access != FAULT_ACCESS_READ &&
>  			     buffer->fault[fi]->access != FAULT_ACCESS_WRITE &&
>  			     buffer->fault[fi]->access != FAULT_ACCESS_PREFETCH &&
> -			     !(args.phys[0] & NVIF_VMM_PFNMAP_V0_A)))
> +			     !(args->p.phys[0] & NVIF_VMM_PFNMAP_V0_A)))
>  				break;
>  		}
>  

LGTM, including the __struct_size() usage.

Reviewed-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook

      reply	other threads:[~2025-04-07 19:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-02 21:39 [PATCH][next] drm/nouveau: svm: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-04-07 19:25 ` Kees Cook [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202504071225.6AB490E7@keescook \
    --to=kees@kernel.org \
    --cc=airlied@gmail.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavoars@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lyude@redhat.com \
    --cc=nouveau@lists.freedesktop.org \
    --cc=simona@ffwll.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox