Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3943092imm; Mon, 8 Oct 2018 12:04:32 -0700 (PDT) X-Google-Smtp-Source: ACcGV60kl5bk9RcVZwG/mapRJqG4oYDXrO1tUJcF3Vvb97uv4lgpN51XBigtIeuPSZKFVjVMCzPA X-Received: by 2002:a62:564e:: with SMTP id k75-v6mr7752466pfb.33.1539025472532; Mon, 08 Oct 2018 12:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539025472; cv=none; d=google.com; s=arc-20160816; b=FLiC2NSKnbfk+k3r7WEQ6+I2Im7iaUJIDmJv9k1+e4BrNbyHuhkiLZYnOTdFHf6u8Q HT4sX/GvIUJVpzs3t+rk0HXLsBvaTgW2HLNOs9OrLbW61PsXArMETyEuUoEUM7WNwc2w uTlXau8Ws0jEWqx9uVkLljpEwEEWwe6XG9DEjsw45v4XtkZhzFHaI0GlDOlk2tf6eC/6 zDpZCRSQo133aEiFfXK8tchOi2QNMc9O1eE8nuRfrKR1ffWV2F9Zya0SdKfQuXfsp48L QqGYo0KYL1VI38LbI+1GpKTl8tUM0hqgb3Sr/3zRJJx2Vh1VR9lITgrmfmEDbeEbFvy9 iNng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=39c6k5XXi2K1TBo2xV4IA2u56h3YG4b20L+n0L1oNOo=; b=r/BvjroHK2c7sll2Fa6gRS/IJkWwMSv4mkNXnjfbwXPrpbDqhjl6I7J623DfLCtB/4 qduCaZ0BHAZUQ+e64LWtISQUJpjkPSYZbstlTdL7XtRcQKcn9oiEvdKWOhH/ajb3Fys3 rPqE0fuVQUs0XGuxgjEdSxDVUtqY3NgM0e7aKXnGv9JAylhgtKQuS4s9vt6EoxUgDORw VVaE28bQEmM4i65PnvoHZVJbXddIleRFR/HYmdEE8a71DcnTckViOrmXQ7oqdgY1tdG+ /UNGIgAw/30M67qfvXhiCu0UirjvQXL8Ea32IQQ4nI5S81XbriNjBEX/nDYWjsScRPSe u0qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RsRf16x3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9-v6si17489639pgh.325.2018.10.08.12.04.17; Mon, 08 Oct 2018 12:04:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RsRf16x3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731028AbeJIB6n (ORCPT + 99 others); Mon, 8 Oct 2018 21:58:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:46800 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728570AbeJIB6l (ORCPT ); Mon, 8 Oct 2018 21:58:41 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 30D8D204FD; Mon, 8 Oct 2018 18:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024335; bh=uxYGQrx/xzQAFtHa952CntmJl81rZWgISuVn5VOQinc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RsRf16x3sif+UBnCXXdrrMDAbsxRMHfFNgqwGgyZV4sBwmzoui0rnYnnIU3okLM37 Ksgoi9UwJjKftl97tgVNFF9Pn1KFkVlJrvLMIvWCztyuUf1SbyCmfWywVaeqfs83fT VkmoH6isaT3s97iPuxEJTw4bDCrCg4iPhmki8M8I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leonard Crestez , Herbert Xu Subject: [PATCH 4.14 87/94] crypto: mxs-dcp - Fix wait logic on chan threads Date: Mon, 8 Oct 2018 20:32:08 +0200 Message-Id: <20181008175610.698381463@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175605.067676667@linuxfoundation.org> References: <20181008175605.067676667@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Leonard Crestez commit d80771c08363ad7fbf0f56f5301e7ca65065c582 upstream. When compiling with CONFIG_DEBUG_ATOMIC_SLEEP=y the mxs-dcp driver prints warnings such as: WARNING: CPU: 0 PID: 120 at kernel/sched/core.c:7736 __might_sleep+0x98/0x9c do not call blocking ops when !TASK_RUNNING; state=1 set at [<8081978c>] dcp_chan_thread_sha+0x3c/0x2ec The problem is that blocking ops will manipulate current->state themselves so it is not allowed to call them between set_current_state(TASK_INTERRUPTIBLE) and schedule(). Fix this by converting the per-chan mutex to a spinlock (it only protects tiny list ops anyway) and rearranging the wait logic so that callbacks are called current->state as TASK_RUNNING. Those callbacks will indeed call blocking ops themselves so this is required. Cc: Signed-off-by: Leonard Crestez Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/mxs-dcp.c | 53 ++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 23 deletions(-) --- a/drivers/crypto/mxs-dcp.c +++ b/drivers/crypto/mxs-dcp.c @@ -63,7 +63,7 @@ struct dcp { struct dcp_coherent_block *coh; struct completion completion[DCP_MAX_CHANS]; - struct mutex mutex[DCP_MAX_CHANS]; + spinlock_t lock[DCP_MAX_CHANS]; struct task_struct *thread[DCP_MAX_CHANS]; struct crypto_queue queue[DCP_MAX_CHANS]; }; @@ -349,13 +349,20 @@ static int dcp_chan_thread_aes(void *dat int ret; - do { - __set_current_state(TASK_INTERRUPTIBLE); + while (!kthread_should_stop()) { + set_current_state(TASK_INTERRUPTIBLE); - mutex_lock(&sdcp->mutex[chan]); + spin_lock(&sdcp->lock[chan]); backlog = crypto_get_backlog(&sdcp->queue[chan]); arq = crypto_dequeue_request(&sdcp->queue[chan]); - mutex_unlock(&sdcp->mutex[chan]); + spin_unlock(&sdcp->lock[chan]); + + if (!backlog && !arq) { + schedule(); + continue; + } + + set_current_state(TASK_RUNNING); if (backlog) backlog->complete(backlog, -EINPROGRESS); @@ -363,11 +370,8 @@ static int dcp_chan_thread_aes(void *dat if (arq) { ret = mxs_dcp_aes_block_crypt(arq); arq->complete(arq, ret); - continue; } - - schedule(); - } while (!kthread_should_stop()); + } return 0; } @@ -409,9 +413,9 @@ static int mxs_dcp_aes_enqueue(struct ab rctx->ecb = ecb; actx->chan = DCP_CHAN_CRYPTO; - mutex_lock(&sdcp->mutex[actx->chan]); + spin_lock(&sdcp->lock[actx->chan]); ret = crypto_enqueue_request(&sdcp->queue[actx->chan], &req->base); - mutex_unlock(&sdcp->mutex[actx->chan]); + spin_unlock(&sdcp->lock[actx->chan]); wake_up_process(sdcp->thread[actx->chan]); @@ -640,13 +644,20 @@ static int dcp_chan_thread_sha(void *dat struct ahash_request *req; int ret, fini; - do { - __set_current_state(TASK_INTERRUPTIBLE); + while (!kthread_should_stop()) { + set_current_state(TASK_INTERRUPTIBLE); - mutex_lock(&sdcp->mutex[chan]); + spin_lock(&sdcp->lock[chan]); backlog = crypto_get_backlog(&sdcp->queue[chan]); arq = crypto_dequeue_request(&sdcp->queue[chan]); - mutex_unlock(&sdcp->mutex[chan]); + spin_unlock(&sdcp->lock[chan]); + + if (!backlog && !arq) { + schedule(); + continue; + } + + set_current_state(TASK_RUNNING); if (backlog) backlog->complete(backlog, -EINPROGRESS); @@ -658,12 +669,8 @@ static int dcp_chan_thread_sha(void *dat ret = dcp_sha_req_to_buf(arq); fini = rctx->fini; arq->complete(arq, ret); - if (!fini) - continue; } - - schedule(); - } while (!kthread_should_stop()); + } return 0; } @@ -721,9 +728,9 @@ static int dcp_sha_update_fx(struct ahas rctx->init = 1; } - mutex_lock(&sdcp->mutex[actx->chan]); + spin_lock(&sdcp->lock[actx->chan]); ret = crypto_enqueue_request(&sdcp->queue[actx->chan], &req->base); - mutex_unlock(&sdcp->mutex[actx->chan]); + spin_unlock(&sdcp->lock[actx->chan]); wake_up_process(sdcp->thread[actx->chan]); mutex_unlock(&actx->mutex); @@ -983,7 +990,7 @@ static int mxs_dcp_probe(struct platform platform_set_drvdata(pdev, sdcp); for (i = 0; i < DCP_MAX_CHANS; i++) { - mutex_init(&sdcp->mutex[i]); + spin_lock_init(&sdcp->lock[i]); init_completion(&sdcp->completion[i]); crypto_init_queue(&sdcp->queue[i], 50); }