Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp651232pxv; Thu, 15 Jul 2021 12:29:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQBRnbGBLPXAvKZ2gace0BrVJT7VirlgsFdK5sHcbJj7GhyI8X/3OQwr6xSsLJrerhypMs X-Received: by 2002:a17:907:988e:: with SMTP id ja14mr7127709ejc.173.1626377395277; Thu, 15 Jul 2021 12:29:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626377395; cv=none; d=google.com; s=arc-20160816; b=vYqZh1EKJh2jmjAfHcUcKo4RLmODMGUTsa+34vWguCyEta81CBtCnS+1MZj4YL0ORT nt4iUcTIu9OhBwfghDwanrqQBiLUtiMz17464Oy8pTWVnmis2XvM49TZ9naqjXMB7F0o jKfHfoCvQL9qqdWH33JPEJoadEEdC3JSSTn+4qDaBjlBq5im2upIa078UNbpSmW+rLgt 2+vDLoJ1AX8VLgY3Kpj+UKVyPmP3e+KdpR0lLpmHu5TWt01tMrWTFUW1/xEygaNt1oSy UapmJaAKhnsWsrIIShHVGVuLRHHVpStjT9mPQsxm8vBWPLiS1DAOunonI9WadIbkiOv1 MF2w== 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=+kGy0RakQWy0DaQO8HIgFYaRiwFi8rokNXJnXOGPotc=; b=aqZchTTY2d5NYuaIEF5QbWE1oRSVr+XcDQP/a8NvQJT2r1VmflFj9bZ2R8Zor4pdD6 tPwP48UkIVEm+W7RTXFPj2dGYo21PBqS3hY5axPzx290UM9r39MGaD1yOuQuSMoW3IeI WdZfzyYH+D1Pb988CBXXR7+ebImrGZYMVf7HNTrfSBK+L25f3qb0rUvU5LVjDu9abn3p iZH8NAwwsCAornaoT0nNCMk/5oUcMCsCIewk02ixxeb7jvYWfS1aC+WWpG9DZByNhXvU BIJATiMoQUcM1U2kpukGjR1p/c2qJyTIR9dUhG08EvQ6am2YyhEUMieCQW87XY2WFgrx v55Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="cqEtPJs/"; 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 u19si9383677edo.288.2021.07.15.12.29.32; Thu, 15 Jul 2021 12:29:55 -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="cqEtPJs/"; 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 S1344822AbhGOTa3 (ORCPT + 99 others); Thu, 15 Jul 2021 15:30:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:46402 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244019AbhGOTKc (ORCPT ); Thu, 15 Jul 2021 15:10:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D9FF4613D7; Thu, 15 Jul 2021 19:07:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626376052; bh=6i81rY4oU0A9X/YDYj2KARlvcWcHTR1SBEgRNN/YNp4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cqEtPJs/APWT4LD9CQAsITLPyyJV0MyH8DOdimrTDeQlCJVaSyytbHldaZdjB6Nig SKyB8qEDEXUhs9kDZ1O38NaS6/eKmLb0/WUtTnS45fq/Yp0BXfp14Nffy0nS7TKp7P aq1SPoFsfUtbvgeXBr3WmMEgS2uVMEKn+/iBhssc= 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.13 105/266] drm/amdkfd: fix circular locking on get_wave_state Date: Thu, 15 Jul 2021 20:37:40 +0200 Message-Id: <20210715182632.478648054@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182613.933608881@linuxfoundation.org> References: <20210715182613.933608881@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 d3eaa1549bd7..ccc9d108caff 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c @@ -1674,29 +1674,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