Received: by 2002:a05:622a:251a:b0:39a:b4a2:e86 with SMTP id cm26csp316869qtb; Wed, 19 Oct 2022 02:44:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7OXRogLhhv1Cv/K60T1fO0uVxDFnAE/XaNYYNESEHEbHEjFhEODH5wKZIouVOtvXYDo5ZR X-Received: by 2002:a17:907:6d03:b0:782:abba:936c with SMTP id sa3-20020a1709076d0300b00782abba936cmr5983246ejc.758.1666172674923; Wed, 19 Oct 2022 02:44:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666172674; cv=none; d=google.com; s=arc-20160816; b=evgVfHVNvQEeGKDH+nbshmrKjlllae3m6HfY23YQAUKfv2HxePHcit1wp+nPHXEJfq Ldd/UPVktkgFWe2Ajj2mSKZ1IGWvNMZ2ODpFY7DYFDIevppegwtSXCh53jzbGAdpuCYb RIFKXod6YCrFY2rsHJAFOUgGuKmVBm6vokEND3V69MuEjHsu+gHcSumPXfcWo+TCB+Se ByGnjHoHDyxbzJKeJ8VKM7QworJRCSRDKx1d8vKQhImMvNQiTH2dzy7th4tpGIsdOwey Fm+yBUGUysScoaSkDPc3utuRlzWrFAS7SUQ7eTcUJUe0mQYp6zQDcpiRldchZ8QPkcz4 gz/w== 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=AAtOVqaO7hCarRCb4n0UUAtDwRsQklmG/7TwBNEZl8Y=; b=rNyHHBDtmZPb2dyzCctcOlX84pnHT1mA2zlcahZMASjZxQzmkKW9nUpx7FtKJB3gD+ Anfx6XvvDvZVK76eLs5JxUKlVyrqGV36v4/nlwwaCiOOurv5NxL9e1tEzHwBMMmjC24e 4xOATSiz4NMOdc0L6G4WMgsIohOC9gLjjrKVAUfJg2ym2YGbTM74TkkYUCPwPLbJl+Aa c/heUqCW8RltXcD/9GL11xGsJLm91qWuaLtdjJhE0XsjPTVZtW0/Kym7YLQ/8GPYa5uJ 4WPxHLWxE9baKCyyuHYvDpxVVF0PD24cU/8qKMxICOOd0VyaicRxD6HTTiH7XrMABSrB F0nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L1foq1xk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd41-20020a1709076e2900b0078c2c22d6cesi14828191ejc.70.2022.10.19.02.43.54; Wed, 19 Oct 2022 02:44:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L1foq1xk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233704AbiJSJbc (ORCPT + 99 others); Wed, 19 Oct 2022 05:31:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233558AbiJSJ1k (ORCPT ); Wed, 19 Oct 2022 05:27:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFCA2E8C62; Wed, 19 Oct 2022 02:12:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ED8E261866; Wed, 19 Oct 2022 09:12:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F002C4314D; Wed, 19 Oct 2022 09:12:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170735; bh=N4wF+6kGYuK5CrjAuFfYgXmfcNsLOqTRoXjZk208taQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L1foq1xk44heBTDK/gigTDPXOFAAMrXpDWWWsHfwoG+Lpr+UvFjymjCTGM11x1ji4 ePISaftWb8jz2b+hCs3+mKNNUloGMHM830lRJzUeoO5GqpTGVoyVAOQm7Qn6kgd8d0 r9DJ5wZ6Mnjk9i1GPzoLm3YpUb01an3yYs/woJpE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ellis Michael , Felix Kuehling , Graham Sider , Alex Deucher , Sasha Levin Subject: [PATCH 6.0 767/862] drm/amdkfd: Fix UBSAN shift-out-of-bounds warning Date: Wed, 19 Oct 2022 10:34:14 +0200 Message-Id: <20221019083323.814976471@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Felix Kuehling [ Upstream commit b292cafe2dd02d96a07147e4b160927e8399d5cc ] This was fixed in initialize_cpsch before, but not in initialize_nocpsch. Factor sdma bitmap initialization into a helper function to apply the correct implementation in both cases without duplicating it. v2: Added a range check Reported-by: Ellis Michael Signed-off-by: Felix Kuehling Reviewed-by: Graham Sider Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 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 007a3db69df1..ecb4c3abc629 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c @@ -1242,6 +1242,24 @@ static void init_interrupts(struct device_queue_manager *dqm) dqm->dev->kfd2kgd->init_interrupts(dqm->dev->adev, i); } +static void init_sdma_bitmaps(struct device_queue_manager *dqm) +{ + unsigned int num_sdma_queues = + min_t(unsigned int, sizeof(dqm->sdma_bitmap)*8, + get_num_sdma_queues(dqm)); + unsigned int num_xgmi_sdma_queues = + min_t(unsigned int, sizeof(dqm->xgmi_sdma_bitmap)*8, + get_num_xgmi_sdma_queues(dqm)); + + if (num_sdma_queues) + dqm->sdma_bitmap = GENMASK_ULL(num_sdma_queues-1, 0); + if (num_xgmi_sdma_queues) + dqm->xgmi_sdma_bitmap = GENMASK_ULL(num_xgmi_sdma_queues-1, 0); + + dqm->sdma_bitmap &= ~get_reserved_sdma_queues_bitmap(dqm); + pr_info("sdma_bitmap: %llx\n", dqm->sdma_bitmap); +} + static int initialize_nocpsch(struct device_queue_manager *dqm) { int pipe, queue; @@ -1270,11 +1288,7 @@ static int initialize_nocpsch(struct device_queue_manager *dqm) memset(dqm->vmid_pasid, 0, sizeof(dqm->vmid_pasid)); - dqm->sdma_bitmap = ~0ULL >> (64 - get_num_sdma_queues(dqm)); - dqm->sdma_bitmap &= ~(get_reserved_sdma_queues_bitmap(dqm)); - pr_info("sdma_bitmap: %llx\n", dqm->sdma_bitmap); - - dqm->xgmi_sdma_bitmap = ~0ULL >> (64 - get_num_xgmi_sdma_queues(dqm)); + init_sdma_bitmaps(dqm); return 0; } @@ -1452,9 +1466,6 @@ 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); @@ -1463,24 +1474,10 @@ static int initialize_cpsch(struct device_queue_manager *dqm) dqm->active_cp_queue_count = 0; dqm->gws_queue_count = 0; dqm->active_runlist = false; - - 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); - - dqm->sdma_bitmap &= ~(get_reserved_sdma_queues_bitmap(dqm)); - pr_info("sdma_bitmap: %llx\n", dqm->sdma_bitmap); - - 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_sdma_bitmaps(dqm); + return 0; } -- 2.35.1