Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3389957pxb; Mon, 17 Jan 2022 19:24:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxb0sQQe97iohDr1yd2K9/ataszXUS7949Z6Er2heQuy8xrz8Ux8Bfwumrg0bz3aBvA2TJU X-Received: by 2002:a17:903:11cd:b0:149:bf70:2031 with SMTP id q13-20020a17090311cd00b00149bf702031mr25414134plh.40.1642476246440; Mon, 17 Jan 2022 19:24:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642476246; cv=none; d=google.com; s=arc-20160816; b=lMGYr635K0Vt5mLPNjlPnN0zUdosaAVZMsAfx5alqAsgFn0gt2rfgmjY6OkP04paSy hmO3GNe3T1LfPkjTSjqoNq9gJf4P86/Z2ikWi9XOFbLIKDoEoNtFH+Wg2X2rk4WoaWjz f5SxtHAj6JkSfAGEWDTyECxMIm/s/G5QmfWCbI0o+lAp7w8iZumOLBkch29XevWpmVjZ 70jpuNARfG3AJj3biVkrGTsRxhyJnTZqIKb2BiCvZwJj1KAvTsO/iJcbZyuHPHbFv9Bw 8qhMLC2yLOcV0LSyrB3TRjKZjkGRJumPrn6IyvdBwBbQavIffPPr8StpKb7ikk2paG2M YVcQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lXYgqEIHj62KYOKGWPrlv1fj/PvIaIlzoyb2+RSqIbM=; b=PM/AiAxs0GQ9vzrh3p5owRFRFOjAC+jmWCa0i5QfuOMzHTlX8WFy/u77UaPtr3s98B TPSJkCHHJnOKCxiur30WFwkZk2bAs19mVajz/BxHdPWDKlatbCkhiKH+1VcKxBzTH+n5 ZtoiUM+142eF3kg0AK1wyd2ejTWwKIKICJ7ZzEqNoNAYdeswAk9A9RQnxZvD6txupCGL mhDXiQ7AGE98O8J0Vo53BhkLRF+eKYLcgLXizHjksNiaRQrv2NyW7xuJTEeTlpYIuvuY fbEQ5ZwniEvh0arQGHnJPkwuq/qKDhHxCvKN8EyYUvdQLGft+bng75CoPiYhHrFiUdKU /yxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Nj3ZbNhT; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x16si16968422pfh.45.2022.01.17.19.23.54; Mon, 17 Jan 2022 19:24:06 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=Nj3ZbNhT; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344915AbiARCfG (ORCPT + 99 others); Mon, 17 Jan 2022 21:35:06 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:40636 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343774AbiARC1O (ORCPT ); Mon, 17 Jan 2022 21:27:14 -0500 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 68248B81259; Tue, 18 Jan 2022 02:27:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C5B2C36AE3; Tue, 18 Jan 2022 02:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642472832; bh=B3cfPb453Nfcm6OQAWeKGIZpO4YqJTunOFtE/0tb9IA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nj3ZbNhTS/7HxQ8KVPi/hcO8XKWGNHtgM3RXxJs6p3NSt4Xycpa4JraV0faSZlFXH I5RphB1mjkmMKvzDkFy7sBZlcJdlpS/9xlxiDWVfPkhZjCZEX5WRzFfgyWXWzdjifi V5vpJNS+mr8h2isMpSPnSgB0Z47DP2KTFgS3rPEsjzBSCQXyPman29GBAVAmsVlQ90 yJc9+gzMcEfP3Pndc9LBOIaETYScxUn4G5TZdGju5Aay9nr66iuAn0bw8ArrFbt82A IgyTHgAKp70ZzCoJdan4FrHavLKCjyWfbPfNn6ug21w2U0adTsv7kTdBvi6ucs/rpy l/wuX2IS7YJGg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yang Shen , Herbert Xu , Sasha Levin , wangzhou1@hisilicon.com, davem@davemloft.net, linux-crypto@vger.kernel.org Subject: [PATCH AUTOSEL 5.16 148/217] crypto: hisilicon/qm - fix deadlock for remove driver Date: Mon, 17 Jan 2022 21:18:31 -0500 Message-Id: <20220118021940.1942199-148-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220118021940.1942199-1-sashal@kernel.org> References: <20220118021940.1942199-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yang Shen [ Upstream commit fc6c01f0cd10b89c4b01dd2940e0b0cda1bd82fb ] When remove the driver and executing the task occur at the same time, the following deadlock will be triggered: Chain exists of: sva_lock --> uacce_mutex --> &qm->qps_lock Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(&qm->qps_lock); lock(uacce_mutex); lock(&qm->qps_lock); lock(sva_lock); And the lock 'qps_lock' is used to protect qp. Therefore, it's reasonable cycle is to continue until the qp memory is released. So move the release lock infront of 'uacce_remove'. Signed-off-by: Yang Shen Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/hisilicon/qm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index 52d6cca6262e2..39517aa9630bb 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -3399,6 +3399,7 @@ void hisi_qm_uninit(struct hisi_qm *qm) dma_free_coherent(dev, qm->qdma.size, qm->qdma.va, qm->qdma.dma); } + up_write(&qm->qps_lock); qm_irq_unregister(qm); hisi_qm_pci_uninit(qm); @@ -3406,8 +3407,6 @@ void hisi_qm_uninit(struct hisi_qm *qm) uacce_remove(qm->uacce); qm->uacce = NULL; } - - up_write(&qm->qps_lock); } EXPORT_SYMBOL_GPL(hisi_qm_uninit); -- 2.34.1