Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp122473rwb; Thu, 6 Oct 2022 15:37:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5zLWXExQ1td8CtaFFF4g1UMEEjejZY1CZXSYnUqJ2iFLscGS+27RFWdTwcaQhyCJfBgq58 X-Received: by 2002:a17:906:7952:b0:787:a14d:65a7 with SMTP id l18-20020a170906795200b00787a14d65a7mr1779573ejo.108.1665095824878; Thu, 06 Oct 2022 15:37:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665095824; cv=none; d=google.com; s=arc-20160816; b=BtnPxz7xCJhvGJhuWs9tYGXhOMIZ5qVOjZLd9FbMREz00lW8yJcEMaI1UvZkTaNSf8 7gcvbQ6IbI9kcFyhL0dHGWiqzQH+nteZET/h2aA847kDYll7UGSPC2y70p8en6AzF9rb wyGzjj2Xf4byI+vpja3FGwDVlWxZfz7UkOO4xo8E28nUc7tgRm6wNacVKeFsKcCz/hEX 5gHVQmMSi5q2POCYtQTKZ/YY9TYWCxmYMxatogsL/69kDCbf1OJ+PcKruTSlbIU8Yi4Y gfRHsYgIhiXBcvSM/OMpnphpW7602caMvUvJ9sDmRAQeWFcsGaEy9LycfF1NXDtE6smf iDoQ== 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=W4jQyBaAqxB5hXYqMT2DINItd/YLoIK4YtDAVH9jynk=; b=Dp6llwMUM2v6NZKKSKopI5UmUnQKMhsidk8m1Fb64pbsd9jWNMCqW0r/7uhp6dDPKq V89ZEuMFI32wEyuCKjRo40AWTgu8Ln08CVjyi1kscy8t5VlowOCUy1WC6/hsTJsw13sb XNruGI1C8t0iCD6dRPj/eTR1nyznjImRXHa50aIrRJJtYGwDBTEMhsrqttNHz+xmP8QD Uk9SHVO9cgt9IBhqzpwjq4mMIvOdKUcDzFsPmD0hOa3ZlIL/pddv7OZhLyRtipvQlLI1 x2+7BcVQI8m5I/ulZZs+FjnGecNVRV8/ihtjYFkpCjgavoj3CKNcHyZcSqHC/3WjY5Ot /1WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=SQSCgXRO; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=hpe.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k13-20020a17090666cd00b00781c229eee4si524854ejp.936.2022.10.06.15.36.31; Thu, 06 Oct 2022 15:37:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=SQSCgXRO; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=hpe.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232069AbiJFWcc (ORCPT + 99 others); Thu, 6 Oct 2022 18:32:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231994AbiJFWc3 (ORCPT ); Thu, 6 Oct 2022 18:32:29 -0400 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8F04C5114; Thu, 6 Oct 2022 15:32:28 -0700 (PDT) Received: from pps.filterd (m0150241.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 296IWLf3006721; Thu, 6 Oct 2022 22:32:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pps0720; bh=W4jQyBaAqxB5hXYqMT2DINItd/YLoIK4YtDAVH9jynk=; b=SQSCgXROlXa4+csUjEQxQgo0s7+Bv+VCgPnuav2T0Ok/XDCFjoeLitDnbN/lIR87Brnm pl4nh196U+uul8eQJmoz/KLSRX3oVOAfwe5/m9XZYAhLgLSVuBD6WGXRF35Se6/Z2VOZ V5iZtJf+LDVIi+wRfrkj4Uh9g7muCdCdHAPjKeqjr6yWiOlS3YctDzFkjwCh6m6zj4iC 8Y+uGm93CW4mxuCya50iy/yQu0OVLk59SSK4b1JYaASbcPvtvITfEEqNGToEI2Kqwmpa tac4+qPng5oSAdcypCYNoH8VRG7B531ofFXcMC1cIxMhTEfDlribTP78n1eP2U1Y8N5v Lw== Received: from p1lg14879.it.hpe.com (p1lg14879.it.hpe.com [16.230.97.200]) by mx0a-002e3701.pphosted.com (PPS) with ESMTPS id 3k22bhmrcm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Oct 2022 22:32:26 +0000 Received: from p1lg14885.dc01.its.hpecorp.net (unknown [10.119.18.236]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by p1lg14879.it.hpe.com (Postfix) with ESMTPS id 7D712D26D; Thu, 6 Oct 2022 22:32:25 +0000 (UTC) Received: from adevxp033-sys.us.rdlabs.hpecorp.net (unknown [16.231.227.36]) by p1lg14885.dc01.its.hpecorp.net (Postfix) with ESMTP id 291B6806184; Thu, 6 Oct 2022 22:32:25 +0000 (UTC) From: Robert Elliott To: herbert@gondor.apana.org.au, davem@davemloft.net, tim.c.chen@linux.intel.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Robert Elliott Subject: [RFC PATCH 4/7] crypto: x86/sm3 - limit FPU preemption Date: Thu, 6 Oct 2022 17:31:48 -0500 Message-Id: <20221006223151.22159-5-elliott@hpe.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221006223151.22159-1-elliott@hpe.com> References: <20221006223151.22159-1-elliott@hpe.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-ORIG-GUID: U4fVSM4QWnBCRlNVR049AYWW0stri5xV X-Proofpoint-GUID: U4fVSM4QWnBCRlNVR049AYWW0stri5xV X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-10-06_05,2022-10-06_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 spamscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 adultscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210060133 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org As done by the ECB and CBC helpers in arch/x86/crypt/ecb_cbc_helpers.h, limit the number of bytes processed between kernel_fpu_begin() and kernel_fpu_end() calls. Those functions call preempt_disable() and preempt_enable(), so the CPU core is unavailable for scheduling while running, causing: rcu: INFO: rcu_preempt detected expedited stalls on CPUs/tasks: {12-... } 22 jiffies s: 277 root: 0x1/. Fixes: 930ab34d906d ("crypto: x86/sm3 - add AVX assembly implementation") Suggested-by: Herbert Xu Signed-off-by: Robert Elliott --- arch/x86/crypto/sm3_avx_glue.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/arch/x86/crypto/sm3_avx_glue.c b/arch/x86/crypto/sm3_avx_glue.c index bfd11da956a4..adb9e55e2a16 100644 --- a/arch/x86/crypto/sm3_avx_glue.c +++ b/arch/x86/crypto/sm3_avx_glue.c @@ -18,6 +18,8 @@ #include #include +#define FPU_BYTES 4096U /* avoid kernel_fpu_begin/end scheduler/rcu stalls */ + asmlinkage void sm3_transform_avx(struct sm3_state *state, const u8 *data, int nblocks); @@ -25,6 +27,7 @@ static int sm3_avx_update(struct shash_desc *desc, const u8 *data, unsigned int len) { struct sm3_state *sctx = shash_desc_ctx(desc); + unsigned int chunk; if (!crypto_simd_usable() || (sctx->count % SM3_BLOCK_SIZE) + len < SM3_BLOCK_SIZE) { @@ -38,9 +41,14 @@ static int sm3_avx_update(struct shash_desc *desc, const u8 *data, */ BUILD_BUG_ON(offsetof(struct sm3_state, state) != 0); - kernel_fpu_begin(); - sm3_base_do_update(desc, data, len, sm3_transform_avx); - kernel_fpu_end(); + do { + chunk = min(len, FPU_BYTES); + len -= chunk; + kernel_fpu_begin(); + sm3_base_do_update(desc, data, chunk, sm3_transform_avx); + kernel_fpu_end(); + data += chunk; + } while (len); return 0; } @@ -48,6 +56,8 @@ static int sm3_avx_update(struct shash_desc *desc, const u8 *data, static int sm3_avx_finup(struct shash_desc *desc, const u8 *data, unsigned int len, u8 *out) { + unsigned int chunk; + if (!crypto_simd_usable()) { struct sm3_state *sctx = shash_desc_ctx(desc); @@ -58,9 +68,17 @@ static int sm3_avx_finup(struct shash_desc *desc, const u8 *data, return 0; } + do { + chunk = min(len, FPU_BYTES); + len -= chunk; + if (chunk) { + kernel_fpu_begin(); + sm3_base_do_update(desc, data, chunk, sm3_transform_avx); + kernel_fpu_end(); + } + data += chunk; + } while (len); kernel_fpu_begin(); - if (len) - sm3_base_do_update(desc, data, len, sm3_transform_avx); sm3_base_do_finalize(desc, sm3_transform_avx); kernel_fpu_end(); -- 2.37.3