mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/xe: circumvent bogus stringop-overflow warning
@ 2024-01-03 11:48 Arnd Bergmann
  2024-02-02 22:09 ` Lucas De Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2024-01-03 11:48 UTC (permalink / raw)
  To: Lucas De Marchi, Oded Gabbay, Thomas Hellström,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Daniel Vetter, Matthew Brost, Rodrigo Vivi
  Cc: Arnd Bergmann, Matt Roper, Brian Welty, intel-xe, dri-devel,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

gcc-13 warns about an array overflow that it sees but that is
prevented by the "asid % NUM_PF_QUEUE" calculation:

drivers/gpu/drm/xe/xe_gt_pagefault.c: In function 'xe_guc_pagefault_handler':
include/linux/fortify-string.h:57:33: error: writing 16 bytes into a region of size 0 [-Werror=stringop-overflow=]
include/linux/fortify-string.h:689:26: note: in expansion of macro '__fortify_memcpy_chk'
  689 | #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
      |                          ^~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/xe/xe_gt_pagefault.c:341:17: note: in expansion of macro 'memcpy'
  341 |                 memcpy(pf_queue->data + pf_queue->tail, msg, len * sizeof(u32));
      |                 ^~~~~~
drivers/gpu/drm/xe/xe_gt_types.h:102:25: note: at offset [1144, 265324] into destination object 'tile' of size 8

I found that rewriting the assignment using pointer addition rather than the
equivalent array index calculation prevents the warning, so use that instead.

I sent a bug report against gcc for the false positive warning.

Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113214
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/gpu/drm/xe/xe_gt_pagefault.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xe/xe_gt_pagefault.c b/drivers/gpu/drm/xe/xe_gt_pagefault.c
index 59a70d2e0a7a..78dc08cc2bfe 100644
--- a/drivers/gpu/drm/xe/xe_gt_pagefault.c
+++ b/drivers/gpu/drm/xe/xe_gt_pagefault.c
@@ -332,7 +332,7 @@ int xe_guc_pagefault_handler(struct xe_guc *guc, u32 *msg, u32 len)
 		return -EPROTO;
 
 	asid = FIELD_GET(PFD_ASID, msg[1]);
-	pf_queue = &gt->usm.pf_queue[asid % NUM_PF_QUEUE];
+	pf_queue = gt->usm.pf_queue + (asid % NUM_PF_QUEUE);
 
 	spin_lock_irqsave(&pf_queue->lock, flags);
 	full = pf_queue_full(pf_queue);
-- 
2.39.2


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

* Re: [PATCH] drm/xe: circumvent bogus stringop-overflow warning
  2024-01-03 11:48 [PATCH] drm/xe: circumvent bogus stringop-overflow warning Arnd Bergmann
@ 2024-02-02 22:09 ` Lucas De Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Lucas De Marchi @ 2024-02-02 22:09 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Oded Gabbay, Thomas Hellström, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Daniel Vetter,
	Matthew Brost, Rodrigo Vivi, Arnd Bergmann, linux-kernel,
	dri-devel, Matt Roper, intel-xe

On Wed, Jan 03, 2024 at 12:48:02PM +0100, Arnd Bergmann wrote:
>From: Arnd Bergmann <arnd@arndb.de>
>
>gcc-13 warns about an array overflow that it sees but that is
>prevented by the "asid % NUM_PF_QUEUE" calculation:
>
>drivers/gpu/drm/xe/xe_gt_pagefault.c: In function 'xe_guc_pagefault_handler':
>include/linux/fortify-string.h:57:33: error: writing 16 bytes into a region of size 0 [-Werror=stringop-overflow=]
>include/linux/fortify-string.h:689:26: note: in expansion of macro '__fortify_memcpy_chk'
>  689 | #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
>      |                          ^~~~~~~~~~~~~~~~~~~~
>drivers/gpu/drm/xe/xe_gt_pagefault.c:341:17: note: in expansion of macro 'memcpy'
>  341 |                 memcpy(pf_queue->data + pf_queue->tail, msg, len * sizeof(u32));
>      |                 ^~~~~~

ugh... I missed that this was for gcc 13 rather than the broken gcc 11
that we workarounded by excluding gcc 11.

>drivers/gpu/drm/xe/xe_gt_types.h:102:25: note: at offset [1144, 265324] into destination object 'tile' of size 8
>
>I found that rewriting the assignment using pointer addition rather than the
>equivalent array index calculation prevents the warning, so use that instead.
>
>I sent a bug report against gcc for the false positive warning.
>
>Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
>Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113214
>Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>---
> drivers/gpu/drm/xe/xe_gt_pagefault.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/drivers/gpu/drm/xe/xe_gt_pagefault.c b/drivers/gpu/drm/xe/xe_gt_pagefault.c
>index 59a70d2e0a7a..78dc08cc2bfe 100644
>--- a/drivers/gpu/drm/xe/xe_gt_pagefault.c
>+++ b/drivers/gpu/drm/xe/xe_gt_pagefault.c
>@@ -332,7 +332,7 @@ int xe_guc_pagefault_handler(struct xe_guc *guc, u32 *msg, u32 len)
> 		return -EPROTO;
>
> 	asid = FIELD_GET(PFD_ASID, msg[1]);
>-	pf_queue = &gt->usm.pf_queue[asid % NUM_PF_QUEUE];
>+	pf_queue = gt->usm.pf_queue + (asid % NUM_PF_QUEUE);

surprising that it fixed it, but looks fine to get in.

Applied to drm-xe-next, thanks.

Lucas De Marchi


>
> 	spin_lock_irqsave(&pf_queue->lock, flags);
> 	full = pf_queue_full(pf_queue);
>-- 
>2.39.2
>

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

end of thread, other threads:[~2024-02-02 22:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-03 11:48 [PATCH] drm/xe: circumvent bogus stringop-overflow warning Arnd Bergmann
2024-02-02 22:09 ` Lucas De Marchi

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

all inboxes | Powered by JetHome®