From patchwork Sat Oct 22 07:28:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7679 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1108770wrr; Sat, 22 Oct 2022 01:45:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5jyiZO5KYUG6h0cRQdET8Wzxl5eL6v0Y34QeXhO3curUZDw/tXa6/m3Yw9+XJn5zJL5EaD X-Received: by 2002:a05:6402:50d4:b0:45d:fe2:45 with SMTP id h20-20020a05640250d400b0045d0fe20045mr21825282edb.221.1666428359733; Sat, 22 Oct 2022 01:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666428359; cv=none; d=google.com; s=arc-20160816; b=XMV/j7MIBVuVyjrutZ8bkhmM5EUG77InHqfFEhxhTBC8xrzSsxpY2wf/XBQDL7xt86 k8aLEI81MDa+DiIBN0m21NdwPsfdwCVhSQ4Zdp3ZzuRYr4xjzzT+cjA83gDjSiFM9TEr sQi5snRyO9B2UOzEeerAbNxGxaXSojKwZQAEfXA+NFhT1CWXgWHaQufqEH3fUfVgnYtp uhH9PhyQbqB0Xf3TeupakhypGA7o+R826Jc94i1CBvAZ5VhwDuMYGPgcTa1c3flxQpAw fICps7lew9P2V6hJSZ2h3qcQE5SHVM2PPbEsPc+RqpzY0DfwnIsjjsGF99hGLitfMHgR NU6A== 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=uHhcwSPdlBDaocEN6zt5HXT7/z4E6ddhR0NhFRFVQO8=; b=AleCk0ytoi9nLdKlg+zUoYC4dmuCA074TmO95YLrlozAiPTudHN87by3A1LzOPoK2E UcBqdf5xRETKRVn4gqSxTKeAVknjHZi33fLKEauzqKGYI5gK1jmA3dif2YvvImpdQNSc PcsTT0C/3Cfd7yOxj3FYc7HIhW5wlJz70isJD/QuojWj+vNjuWXNM9TwxY5DKxxuGM2i hNYYxrnDi7BCyzGMTp/RvsXvH7W7+dXbifY1LX1QKWwhLG2PVk/PWm2WZ6Y3c+09FY8r L9lvvcvvyHLPVTfKm3gO6uwb3zItq8qSSsAiD/9wqA36lmUAgW6m/jwR+0cs0j0Xs93x Ug8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SeHrdDuw; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g8-20020a170906538800b0073dbc331a40si18619965ejo.188.2022.10.22.01.45.35; Sat, 22 Oct 2022 01:45:59 -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=SeHrdDuw; 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 S234854AbiJVInt (ORCPT + 99 others); Sat, 22 Oct 2022 04:43:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234758AbiJVImi (ORCPT ); Sat, 22 Oct 2022 04:42:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C24902E8D8B; Sat, 22 Oct 2022 01:06:59 -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 ams.source.kernel.org (Postfix) with ESMTPS id 5A2FBB82E13; Sat, 22 Oct 2022 08:05:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B630AC433D6; Sat, 22 Oct 2022 08:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425919; bh=k1aIw9YxKECaGaO2jmbXqWliP/zH74AICWyaTZxJlzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SeHrdDuwZaQBDX6YjEHvPj32brHotlhPh/knXgM7Z2jVGigQrNig2Y7gBr0E/dVhG b0fcbVB9klOKnGjlLhJSv0yh0IpNoVMzytWwNzjv2kitdlpqunODbjAs4rqUDNJEz1 lI91QbfCXcXfudiAMzJFGYR+YP7XeXJOs32p3aQA= 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 5.19 628/717] drm/amdkfd: Fix UBSAN shift-out-of-bounds warning Date: Sat, 22 Oct 2022 09:28:27 +0200 Message-Id: <20221022072526.233866903@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747376784176195295?= X-GMAIL-MSGID: =?utf-8?q?1747376784176195295?= 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 e1797657b04c..7d3fc5849466 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c @@ -1232,6 +1232,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; @@ -1260,11 +1278,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; } @@ -1442,9 +1456,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); @@ -1453,24 +1464,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; }