Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp510028pxx; Wed, 28 Oct 2020 09:58:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyakfdY3fqAB8cE43XFmafNxPUdz6xegyr7HdnMLw/j2ouz0oqHSMdA+KHK+QMbLbfUqMpn X-Received: by 2002:aa7:d7d9:: with SMTP id e25mr8844488eds.253.1603904282180; Wed, 28 Oct 2020 09:58:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603904282; cv=none; d=google.com; s=arc-20160816; b=KedaXfEkrc6pQorq0wSuoaG+PnCWRVXQp4V9oSLGnwg31X1Na9iUDF6fi9VRuXOzWV Q8zbzDmiFsaqtNzICLY/eEeI4lzqSF9CZni5nMTKJxFPr1hUrrqLfGxyutuz3dovQM7S fNr50r9AvK+ESxSWGFyNUlma4jf1Npcom4w6dIirn8r3XCja+sVghmisFW4AVHLS4ovh um23cRaVEwH5pSbeG2SRsoJB+gn7Cmz/+kONmoeVcpCiELW73HuMTgdoU4AbS2OJQaeA 8KJ5VE9gyR0t4mOcT0zwazSZ++4SYz468tp4YdspLXzUI3gH5I6PT4vTZiotDuFzc7a7 9PTw== 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=Bd5HzD9uLKdFXg/03Ml8s8uPWEROabUM77hPA24qGgQ=; b=Zo9tfZT4HiYiX9DZOoQxNJ+oQ/5hy+HKA0nMUa+ON/Q2X6Kn7BHglA+b4KLyycIL3o fgIWO6OqBRaS2mVlG3/39XWi4ZcTw8V+solcVDFMN+7Yh7wUEymlwyljNPxgau6tVfKe GN9qfeZKHT8jYTP9dCUxEpjHUQuWaf011V23vagXt2/FfMABgdiwtG1RNrmKm8dnTDKY D27+XiE8cd/Palb/R9+01MLKxvl/0mBU/tz+3UIgwCxTk8TeqMi2qofc73grA4xXJyO7 JprA5y1/AvraF1QrJ8E4dGdAFXFDm8YKVE5c5m3Pd1l9cEeSL4UjGMhQj+8gVIZ4DSvH 5m6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rxqhk7UC; 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=fail (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 g1si6073edt.484.2020.10.28.09.57.40; Wed, 28 Oct 2020 09:58:02 -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=@kernel.org header.s=default header.b=rxqhk7UC; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1819085AbgJ0R1Q (ORCPT + 99 others); Tue, 27 Oct 2020 13:27:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:54092 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1780050AbgJ0Oxn (ORCPT ); Tue, 27 Oct 2020 10:53:43 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 142DD22284; Tue, 27 Oct 2020 14:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810422; bh=Oky0kQbUmdVT7RxWFVQPDpHpT3abUf6UOiboywpHHQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rxqhk7UCEyPhhgz8opaVDUIk2B0GEO3xpSBbbPuERDHnvxBUd+UJkmN7TeurxI1ni a7qr+Oyv+vQunzOTyVzmHEHU+ob0o5WxIx3F/Yj4+RZ/1GhpIdJiI3Gnobz9kQIe56 Ft377yUFYWPTiDS3oUy5f3J1mZI6RB65lDIDAdxE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolas Toromanoff , Herbert Xu , Sasha Levin Subject: [PATCH 5.8 133/633] crypto: stm32/crc32 - Avoid lock if hardware is already used Date: Tue, 27 Oct 2020 14:47:56 +0100 Message-Id: <20201027135528.927823983@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@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: Nicolas Toromanoff [ Upstream commit bbf2cb1ea1e1428589d7f4d652bed15b265ce92d ] If STM32 CRC device is already in use, calculate CRC by software. This will release CPU constraint for a concurrent access to the hardware, and avoid masking irqs during the whole block processing. Fixes: 7795c0baf5ac ("crypto: stm32/crc32 - protect from concurrent accesses") Signed-off-by: Nicolas Toromanoff Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/stm32/Kconfig | 1 + drivers/crypto/stm32/stm32-crc32.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/stm32/Kconfig b/drivers/crypto/stm32/Kconfig index 4ef3eb11361c2..4a4c3284ae1f3 100644 --- a/drivers/crypto/stm32/Kconfig +++ b/drivers/crypto/stm32/Kconfig @@ -3,6 +3,7 @@ config CRYPTO_DEV_STM32_CRC tristate "Support for STM32 crc accelerators" depends on ARCH_STM32 select CRYPTO_HASH + select CRC32 help This enables support for the CRC32 hw accelerator which can be found on STMicroelectronics STM32 SOC. diff --git a/drivers/crypto/stm32/stm32-crc32.c b/drivers/crypto/stm32/stm32-crc32.c index 3ba41148c2a46..2c13f5214d2cf 100644 --- a/drivers/crypto/stm32/stm32-crc32.c +++ b/drivers/crypto/stm32/stm32-crc32.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -147,7 +148,6 @@ static int burst_update(struct shash_desc *desc, const u8 *d8, struct stm32_crc_desc_ctx *ctx = shash_desc_ctx(desc); struct stm32_crc_ctx *mctx = crypto_shash_ctx(desc->tfm); struct stm32_crc *crc; - unsigned long flags; crc = stm32_crc_get_next_crc(); if (!crc) @@ -155,7 +155,15 @@ static int burst_update(struct shash_desc *desc, const u8 *d8, pm_runtime_get_sync(crc->dev); - spin_lock_irqsave(&crc->lock, flags); + if (!spin_trylock(&crc->lock)) { + /* Hardware is busy, calculate crc32 by software */ + if (mctx->poly == CRC32_POLY_LE) + ctx->partial = crc32_le(ctx->partial, d8, length); + else + ctx->partial = __crc32c_le(ctx->partial, d8, length); + + goto pm_out; + } /* * Restore previously calculated CRC for this context as init value @@ -195,8 +203,9 @@ static int burst_update(struct shash_desc *desc, const u8 *d8, /* Store partial result */ ctx->partial = readl_relaxed(crc->regs + CRC_DR); - spin_unlock_irqrestore(&crc->lock, flags); + spin_unlock(&crc->lock); +pm_out: pm_runtime_mark_last_busy(crc->dev); pm_runtime_put_autosuspend(crc->dev); -- 2.25.1