Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2484591pxj; Mon, 10 May 2021 04:13:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvZ3sIn9D7PgLQpxi5LOE9kOLYO23Z+q3XwgPXHcRO/50RPu9nEedp9PkynFlMBsdd43zr X-Received: by 2002:a6b:f30d:: with SMTP id m13mr17738318ioh.139.1620645061872; Mon, 10 May 2021 04:11:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645061; cv=none; d=google.com; s=arc-20160816; b=hbO4pCB9jo2dWnEJNLYUfvldmh2UUY33nvY/Wp2LsHfliEeW7FiPoGbgbtSrYjdJbI Jjg2U62TloJTHXXi9CbcB0Aav2+JQfGlnvirvfCeJWcLzbI856gpmwXgtCguNd5Cw1m+ MqJZ3mJd9FEZev1O+mQQDKFi8g3yR7BoWNSIfiQ5OsAaAvgXHQAElnUHLvmKCDrWCn0l j413rG7Pvp/m2p+VsF93f4KvwpDOWCtXtDB85sGHLow8XeAezVnaKaDDQWeG3ZowvAwZ zbfXkT5IUSZe8bH2xGuipspdk9HFNWfjQ5UrG5jMioBg3BkD9FQWpRviSaqoCzS/ywxr NbOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pXkyuR4X6K205y8Vev8Wh9NCSpHM/QoKnad0o5quXsg=; b=q04LT0mzgksTY2sZBXRNAkjUZdaSgtynh+uKHmgmGT2xusR1pJXcP55wv1lEvQr1DC JaZRKa8AN5kWB+Z6TEKGKsl5SkMKRsj8hfLXm0fThY1GJkYbSmudYnxpfsJiXzxEkDCU 6uCIMhzLqseNaT639bDHNhCahJy9uxysWycDZV0qAaze+VvEyCC7/yasxr+3zWKAucuC Zwl46vs1XQaDsWV0b6Ivh3dgUhdg0V++dWrJhzPisXefZyg8LQt6MGQQy2WHzAMvsrPs S8jxsrgigVZF9BpmuDuAXH/k5pTqsIMUh6wKRWwWR/+ouDVAYMcSSx2+03BEoNO4/Gg4 8aCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CzLjGmhd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u10si15792695iln.13.2021.05.10.04.10.49; Mon, 10 May 2021 04:11:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CzLjGmhd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235620AbhEJLFr (ORCPT + 99 others); Mon, 10 May 2021 07:05:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:32908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232281AbhEJKp5 (ORCPT ); Mon, 10 May 2021 06:45:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DECA1619B7; Mon, 10 May 2021 10:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643013; bh=9DPveqMov/n1cxMWsJb513aDejn/IKzSpNcX7r7YSn4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CzLjGmhdIFvPUQaId5M4qFynbFuVIMsX6tOJS4C7tGxKUCnRYqDc3jh8/oKFcm+CV RtEvNZTe7WI6rRNqdzz1yV+EIxpOwoIjE9DR3DhDF/EaIc3gkd0ATWB+m23FxKra8p IgZR8b4zbOhjm3NOLAF+Rkmauk1B/46CMS+ozBB0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lyude Paul , Anson Jacob , Alex Deucher , Felix Kuehling , Sasha Levin Subject: [PATCH 5.10 142/299] drm/amdkfd: Fix UBSAN shift-out-of-bounds warning Date: Mon, 10 May 2021 12:18:59 +0200 Message-Id: <20210510102009.652745605@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anson Jacob [ Upstream commit 50e2fc36e72d4ad672032ebf646cecb48656efe0 ] 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/1472 Reported-by: Lyude Paul Signed-off-by: Anson Jacob Reviewed-by: Alex Deucher Reviewed-by: Felix Kuehling Tested-by: Lyude Paul Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c index 8e5cfb1f8a51..6ea8a4b6efde 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c @@ -1128,6 +1128,9 @@ static int set_sched_resources(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)); mutex_init(&dqm->lock_hidden); @@ -1136,8 +1139,18 @@ static int initialize_cpsch(struct device_queue_manager *dqm) dqm->active_cp_queue_count = 0; dqm->gws_queue_count = 0; 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); -- 2.30.2