Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp627743pxv; Thu, 15 Jul 2021 11:55:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7CDxB2w5sS896s43P0ixHZ/rZPfx0qeUBeP/AIs9G4lXMK4bq6nNBzWnBFZNjGtlqGc/0 X-Received: by 2002:a05:6638:289:: with SMTP id c9mr5379565jaq.14.1626375310961; Thu, 15 Jul 2021 11:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375310; cv=none; d=google.com; s=arc-20160816; b=j0W93AgA8yZpHuLkbcPuPkSVEPhe6O/fK1/2rFUGQtDl1xX9Idrw1IGRgWjhaMyshP APHZ0LfkYlNfJzQPkWmir1up1tQL4J6Fr12xkpi0ekASyBqRcLNXBz9GtKRgSfP7xbrT vGOHWotYHAgVCEcEjy+KzYz9JjAS5EyRnNG/QLgPWtatLcg1UGTpj2UODLAKv5REWoLk ir7U/AvFevLCMnsFBam1FuV85wSSLzs9rxZsAP4RYGTM54OWyCw1T27w8HqNCXQwaezP 7Xmpt+irnsWWHwXBXgZxlcbxnaSRaEgXhPGngd1eU3I1oepzn8usmPqMP5g4Lwf53zRf yx5Q== 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=SVkBvDkIGgoKvp4Pwd1451mQX3Hi/qmZ0oSQPUIR6Ck=; b=QCE0MdG1ucT4zmtES1GwS3yj4sVAqsKUL7xhwU1B/RWqesEg/uMCKONlqjyIsEEMzS QwSOq5OYyBaXISvLMLbDcPq05R7i4t+drYwrBTr2dVTE/+db7eaG7CSaDWcIbmBLtNSg b/oaYjsz7FlJf+omqG24O50AUgWKdXD+/oRH5jGIE+1gFLmAvAIgv08sK+/ygNI9G0Tx Cb+DFS9rXRohY//6+WysAcqcyumkgmnXEj0rVhnB41r+EMIJGNfCXOIW5qtt5iJG7U+g SlQFKG/G6EC2pQD0yQp91FHJeqXMrPNTZu8vdcZ8HKTQmy3+uOXrDj6SzDllBleEdrZi Up8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RSJdluG7; 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 a16si7034048ilb.149.2021.07.15.11.54.58; Thu, 15 Jul 2021 11:55:10 -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=RSJdluG7; 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 S241771AbhGOS5T (ORCPT + 99 others); Thu, 15 Jul 2021 14:57:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:52350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239533AbhGOSvf (ORCPT ); Thu, 15 Jul 2021 14:51:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 93C25613F8; Thu, 15 Jul 2021 18:48:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626374920; bh=18JrPegVgdlgr50MO0CVXnGeUnuBf0s/SDlzkj9hRcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RSJdluG7voYuB1F+SShnBdnmGihPenAHJnCcnIFKONwsYKuxutXEQLr4scYd4rjKQ ixikeicKmhDmLxVp6Rioc2+ZIu7RDdCIyQPxBVwYRqNpCHfyC8IbnXKWH/ULar6j4F lLbIHKHgJRIY39fvkk/HD1hkJgN/+GlDMeP4qtII= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jonathan Kim , Felix Kuehling , Alex Deucher , Sasha Levin Subject: [PATCH 5.10 082/215] drm/amdkfd: fix circular locking on get_wave_state Date: Thu, 15 Jul 2021 20:37:34 +0200 Message-Id: <20210715182613.959607466@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182558.381078833@linuxfoundation.org> References: <20210715182558.381078833@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: Jonathan Kim [ Upstream commit 63f6e01237257e7226efc5087f3f0b525d320f54 ] get_wave_state acquires the mmap_lock on copy_to_user but so do mmu_notifiers. mmu_notifiers allows dqm locking so do get_wave_state outside the dqm_lock to prevent circular locking. v2: squash in unused variable removal. Signed-off-by: Jonathan Kim Reviewed-by: Felix Kuehling Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 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 6ea8a4b6efde..b971532e69eb 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c @@ -1677,29 +1677,27 @@ static int get_wave_state(struct device_queue_manager *dqm, u32 *save_area_used_size) { struct mqd_manager *mqd_mgr; - int r; dqm_lock(dqm); - if (q->properties.type != KFD_QUEUE_TYPE_COMPUTE || - q->properties.is_active || !q->device->cwsr_enabled) { - r = -EINVAL; - goto dqm_unlock; - } - mqd_mgr = dqm->mqd_mgrs[KFD_MQD_TYPE_CP]; - if (!mqd_mgr->get_wave_state) { - r = -EINVAL; - goto dqm_unlock; + if (q->properties.type != KFD_QUEUE_TYPE_COMPUTE || + q->properties.is_active || !q->device->cwsr_enabled || + !mqd_mgr->get_wave_state) { + dqm_unlock(dqm); + return -EINVAL; } - r = mqd_mgr->get_wave_state(mqd_mgr, q->mqd, ctl_stack, - ctl_stack_used_size, save_area_used_size); - -dqm_unlock: dqm_unlock(dqm); - return r; + + /* + * get_wave_state is outside the dqm lock to prevent circular locking + * and the queue should be protected against destruction by the process + * lock. + */ + return mqd_mgr->get_wave_state(mqd_mgr, q->mqd, ctl_stack, + ctl_stack_used_size, save_area_used_size); } static int process_termination_cpsch(struct device_queue_manager *dqm, -- 2.30.2