From: Candice Li <candice.li@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: Candice Li <candice.li@amd.com>
Subject: [PATCH] drm/amdgpu: Fix UBSAN shift-out-of-bounds for gfx v9_0
Date: Mon, 15 Aug 2022 18:04:37 +0800 [thread overview]
Message-ID: <20220815100437.3207-1-candice.li@amd.com> (raw)
Check shift number to avoid doing a shift operation when the number
of bits shifted equal to or greater than number of bits in the operand.
Signed-off-by: Candice Li <candice.li@amd.com>
---
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index 7f187558220e9a..0b9215b6e4b316 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
@@ -2494,7 +2494,7 @@ static u32 gfx_v9_0_get_rb_active_bitmap(struct amdgpu_device *adev)
static void gfx_v9_0_setup_rb(struct amdgpu_device *adev)
{
int i, j;
- u32 data;
+ u32 data, shift_num;
u32 active_rbs = 0;
u32 rb_bitmap_width_per_sh = adev->gfx.config.max_backends_per_se /
adev->gfx.config.max_sh_per_se;
@@ -2504,8 +2504,10 @@ static void gfx_v9_0_setup_rb(struct amdgpu_device *adev)
for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
gfx_v9_0_select_se_sh(adev, i, j, 0xffffffff);
data = gfx_v9_0_get_rb_active_bitmap(adev);
- active_rbs |= data << ((i * adev->gfx.config.max_sh_per_se + j) *
- rb_bitmap_width_per_sh);
+ shift_num = min(((i * adev->gfx.config.max_sh_per_se + j) *
+ rb_bitmap_width_per_sh), __builtin_clz(data));
+ if (data)
+ active_rbs |= data << shift_num;
}
}
gfx_v9_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
--
2.17.1
reply other threads:[~2022-08-24 16:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220815100437.3207-1-candice.li@amd.com \
--to=candice.li@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.