提交 a51a08dd 编写于 作者: A Anson Jacob 提交者: Zheng Zengkai

drm/amdkfd: Fix UBSAN shift-out-of-bounds warning

stable inclusion
from stable-5.10.36
commit 1874b0ef1426b873de94c61861e38f29a8df714c
bugzilla: 51867
CVE: NA

--------------------------------

[ Upstream commit 50e2fc36 ]

If get_num_sdma_queues or get_num_xgmi_sdma_queues is 0, we end up
doing a shift operation where the number of bits shifted equals
number of bits in the operand. This behaviour is undefined.

Set num_sdma_queues or num_xgmi_sdma_queues to ULLONG_MAX, if the
count is >= number of bits in the operand.

Bug: https://gitlab.freedesktop.org/drm/amd/-/issues/1472Reported-by: NLyude Paul <lyude@redhat.com>
Signed-off-by: NAnson Jacob <Anson.Jacob@amd.com>
Reviewed-by: NAlex Deucher <alexander.deucher@amd.com>
Reviewed-by: NFelix Kuehling <Felix.Kuehling@amd.com>
Tested-by: NLyude Paul <lyude@redhat.com>
Signed-off-by: NAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NWeilong Chen <chenweilong@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 a9bd29bb
...@@ -1128,6 +1128,9 @@ static int set_sched_resources(struct device_queue_manager *dqm) ...@@ -1128,6 +1128,9 @@ static int set_sched_resources(struct device_queue_manager *dqm)
static int initialize_cpsch(struct device_queue_manager *dqm) static int initialize_cpsch(struct device_queue_manager *dqm)
{ {
uint64_t num_sdma_queues;
uint64_t num_xgmi_sdma_queues;
pr_debug("num of pipes: %d\n", get_pipes_per_mec(dqm)); pr_debug("num of pipes: %d\n", get_pipes_per_mec(dqm));
mutex_init(&dqm->lock_hidden); mutex_init(&dqm->lock_hidden);
...@@ -1136,8 +1139,18 @@ static int initialize_cpsch(struct device_queue_manager *dqm) ...@@ -1136,8 +1139,18 @@ static int initialize_cpsch(struct device_queue_manager *dqm)
dqm->active_cp_queue_count = 0; dqm->active_cp_queue_count = 0;
dqm->gws_queue_count = 0; dqm->gws_queue_count = 0;
dqm->active_runlist = false; dqm->active_runlist = false;
dqm->sdma_bitmap = ~0ULL >> (64 - get_num_sdma_queues(dqm));
dqm->xgmi_sdma_bitmap = ~0ULL >> (64 - get_num_xgmi_sdma_queues(dqm)); num_sdma_queues = get_num_sdma_queues(dqm);
if (num_sdma_queues >= BITS_PER_TYPE(dqm->sdma_bitmap))
dqm->sdma_bitmap = ULLONG_MAX;
else
dqm->sdma_bitmap = (BIT_ULL(num_sdma_queues) - 1);
num_xgmi_sdma_queues = get_num_xgmi_sdma_queues(dqm);
if (num_xgmi_sdma_queues >= BITS_PER_TYPE(dqm->xgmi_sdma_bitmap))
dqm->xgmi_sdma_bitmap = ULLONG_MAX;
else
dqm->xgmi_sdma_bitmap = (BIT_ULL(num_xgmi_sdma_queues) - 1);
INIT_WORK(&dqm->hw_exception_work, kfd_process_hw_exception); INIT_WORK(&dqm->hw_exception_work, kfd_process_hw_exception);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册