The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] [v2] drm/amdgpu: avoid integer overflow warning in amdgpu_device_resize_fb_bar()
@ 2023-07-07 11:11 Arnd Bergmann
  2023-07-07 11:47 ` Christian König
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2023-07-07 11:11 UTC (permalink / raw)
  To: Alex Deucher, Christian König, Pan, Xinhui, David Airlie,
	Daniel Vetter
  Cc: Arnd Bergmann, Hawking Zhang, Lijo Lazar, Mario Limonciello,
	YiPeng Chai, Le Ma, Bokun Zhang, Srinivasan Shanmugam,
	Shiwu Zhang, amd-gfx, dri-devel, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

On 32-bit architectures comparing a resource against a value larger than
U32_MAX can cause a warning:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:1344:18: error: result of comparison of constant 4294967296 with expression of type 'resource_size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
                    res->start > 0x100000000ull)
                    ~~~~~~~~~~ ^ ~~~~~~~~~~~~~~

As gcc does not warn about this in dead code, add an IS_ENABLED() check at
the start of the function. This will always return success but not actually resize
the BAR on 32-bit architectures without high memory, which is exactly what
we want here, as the driver can fall back to bank switching the VRAM
access.

Fixes: 31b8adab3247e ("drm/amdgpu: require a root bus window above 4GB for BAR resize")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v2: return early instead of shutting up the warning with a cast and
running into a failure
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 7f069e1731fee..fcf5f07c47751 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -1325,6 +1325,9 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
 	u16 cmd;
 	int r;
 
+	if (!IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT))
+		return 0;
+
 	/* Bypass for VF */
 	if (amdgpu_sriov_vf(adev))
 		return 0;
-- 
2.39.2


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

* Re: [PATCH] [v2] drm/amdgpu: avoid integer overflow warning in amdgpu_device_resize_fb_bar()
  2023-07-07 11:11 [PATCH] [v2] drm/amdgpu: avoid integer overflow warning in amdgpu_device_resize_fb_bar() Arnd Bergmann
@ 2023-07-07 11:47 ` Christian König
  2023-07-07 18:40   ` Alex Deucher
  0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2023-07-07 11:47 UTC (permalink / raw)
  To: Arnd Bergmann, Alex Deucher, Pan, Xinhui, David Airlie,
	Daniel Vetter
  Cc: Arnd Bergmann, Hawking Zhang, Lijo Lazar, Mario Limonciello,
	YiPeng Chai, Le Ma, Bokun Zhang, Srinivasan Shanmugam,
	Shiwu Zhang, amd-gfx, dri-devel, linux-kernel

Am 07.07.23 um 13:11 schrieb Arnd Bergmann:
> From: Arnd Bergmann <arnd@arndb.de>
>
> On 32-bit architectures comparing a resource against a value larger than
> U32_MAX can cause a warning:
>
> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:1344:18: error: result of comparison of constant 4294967296 with expression of type 'resource_size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
>                      res->start > 0x100000000ull)
>                      ~~~~~~~~~~ ^ ~~~~~~~~~~~~~~
>
> As gcc does not warn about this in dead code, add an IS_ENABLED() check at
> the start of the function. This will always return success but not actually resize
> the BAR on 32-bit architectures without high memory, which is exactly what
> we want here, as the driver can fall back to bank switching the VRAM
> access.
>
> Fixes: 31b8adab3247e ("drm/amdgpu: require a root bus window above 4GB for BAR resize")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
> v2: return early instead of shutting up the warning with a cast and
> running into a failure
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 7f069e1731fee..fcf5f07c47751 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -1325,6 +1325,9 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
>   	u16 cmd;
>   	int r;
>   
> +	if (!IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT))
> +		return 0;
> +
>   	/* Bypass for VF */
>   	if (amdgpu_sriov_vf(adev))
>   		return 0;


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

* Re: [PATCH] [v2] drm/amdgpu: avoid integer overflow warning in amdgpu_device_resize_fb_bar()
  2023-07-07 11:47 ` Christian König
@ 2023-07-07 18:40   ` Alex Deucher
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2023-07-07 18:40 UTC (permalink / raw)
  To: Christian König
  Cc: Arnd Bergmann, Alex Deucher, Pan, Xinhui, David Airlie,
	Daniel Vetter, amd-gfx, Srinivasan Shanmugam, Arnd Bergmann,
	Bokun Zhang, dri-devel, Lijo Lazar, linux-kernel, Shiwu Zhang,
	Le Ma, YiPeng Chai, Mario Limonciello, Hawking Zhang

Applied.  thanks!

On Fri, Jul 7, 2023 at 7:47 AM Christian König <christian.koenig@amd.com> wrote:
>
> Am 07.07.23 um 13:11 schrieb Arnd Bergmann:
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > On 32-bit architectures comparing a resource against a value larger than
> > U32_MAX can cause a warning:
> >
> > drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:1344:18: error: result of comparison of constant 4294967296 with expression of type 'resource_size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> >                      res->start > 0x100000000ull)
> >                      ~~~~~~~~~~ ^ ~~~~~~~~~~~~~~
> >
> > As gcc does not warn about this in dead code, add an IS_ENABLED() check at
> > the start of the function. This will always return success but not actually resize
> > the BAR on 32-bit architectures without high memory, which is exactly what
> > we want here, as the driver can fall back to bank switching the VRAM
> > access.
> >
> > Fixes: 31b8adab3247e ("drm/amdgpu: require a root bus window above 4GB for BAR resize")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
>
> > ---
> > v2: return early instead of shutting up the warning with a cast and
> > running into a failure
> > ---
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++
> >   1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> > index 7f069e1731fee..fcf5f07c47751 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> > @@ -1325,6 +1325,9 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
> >       u16 cmd;
> >       int r;
> >
> > +     if (!IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT))
> > +             return 0;
> > +
> >       /* Bypass for VF */
> >       if (amdgpu_sriov_vf(adev))
> >               return 0;
>

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

end of thread, other threads:[~2023-07-07 18:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-07 11:11 [PATCH] [v2] drm/amdgpu: avoid integer overflow warning in amdgpu_device_resize_fb_bar() Arnd Bergmann
2023-07-07 11:47 ` Christian König
2023-07-07 18:40   ` Alex Deucher

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