From patchwork Thu Nov 3 04:27:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Elliott, Robert (Servers)" X-Patchwork-Id: 14637 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp314638wru; Wed, 2 Nov 2022 21:36:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM40HWraVEs7SiEz1nmUVbdE+YcBPggfb/xiB2c3hxviHspkQ6KavfBjjcust+BdsKqHZfIu X-Received: by 2002:a17:907:9688:b0:7a5:74eb:d12b with SMTP id hd8-20020a170907968800b007a574ebd12bmr27441126ejc.60.1667450189025; Wed, 02 Nov 2022 21:36:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667450189; cv=none; d=google.com; s=arc-20160816; b=YCJGMbz9/PRiZqJCIIR/4tsRG/L5mTKZOJPXWMCl/YK21RwGCrAjemiHgynQbYAfSk VllzV2E8bA/Kjzcx2DzZkioSpGjnWpf6YEFG6V09HB37qJb1ux5MkyJeQfefKZthveS+ IRDqsGiXftm/EfI7tEiXXQAjGPJ90N4poyMfnRfC5oJCjIUpXJB6AaHIHtWgfHO4nuHA OgBSIK+bv2DnIXvmlFJykVeW7yxeHUZwYhf+tQmMYTiktbFJeoAdbjStDITcJx1Q3bZ3 yk8Rms46M3J4vFVta6jHGSnJnggHUIx0ewL4Xz1J14PknFNZPApZvhhxGh5UnGNJcEGm OVjg== 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=tECIyFvsPJywhFXUSQexirS6np6YIq2VopMOItdY5RU=; b=bEpwD1Med7DdiMod9JIz9HJqu7MwKBuxpQA1eesyUYAfvX617Vsdz/E4mTAgYadEYy 8s1lio6XCmoOaLtPA2Rs50xeDuhrP6U2SnG6zdTvWPTYTm9xM6WWGzwLEd48EELVTvvq ifyrYhkYPW9sJdBO0snybmhTbZ7SJrzDVFnxXoazETnPLHoIUS4hklRlVPCLXRuu7aCt X5PCaV1gpHkoPwNODqVIHzhtvBl4Zq3vsSQ4u5sRA7ys6RX+afTRNPeZMZitFSSnnH7r CJDn/dFI7N7PBUjaHe04WYcAgTYx4A5zrLMLeqbgeJcCeumijq+PxRiiEPlnS7iG6LjP AzlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=YQR9oc6C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=hpe.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go44-20020a1709070dac00b0078e1708513esi20371583ejc.824.2022.11.02.21.36.05; Wed, 02 Nov 2022 21:36:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=YQR9oc6C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S229598AbiKCEeb (ORCPT + 99 others); Thu, 3 Nov 2022 00:34:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbiKCEe2 (ORCPT ); Thu, 3 Nov 2022 00:34:28 -0400 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9293AF584; Wed, 2 Nov 2022 21:34:27 -0700 (PDT) Received: from pps.filterd (m0150244.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A3421BR024546; Thu, 3 Nov 2022 04:33:17 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=tECIyFvsPJywhFXUSQexirS6np6YIq2VopMOItdY5RU=; b=YQR9oc6CQ6SrCcwODtsWIijGOX2Fs/uznXdwwMH84PhNn1nwq4/Ts1oZB4DQwxwOz5ev A2hb5ehewwI4o9ZB1dR0MgFjt+hPG6BF6WkTDhb+H5cLEEhpt++/BMbvcTfkC1c/eUny 99pvtBnzK3yGSLTGVsbt3mpVp4/Mhp/ovWRZ/XmYrAW7uJVyQeApNqGtAsoxZ06Pbjvm z51bkl2rEmhVtcB4fJynrd1rl2lAj/6E/ZX1lrP4EKAPbCeG6D9LmIODJgb/609pcvjq +xw1o/jSeWrXeFLY4OKmvOCjpMeRtmyBxabFuwQ3JT4RFjq3OoHQS3kWXNupIkuApR0L 5Q== Received: from p1lg14878.it.hpe.com (p1lg14878.it.hpe.com [16.230.97.204]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3kkstj5yyf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Nov 2022 04:33:17 +0000 Received: from p1lg14886.dc01.its.hpecorp.net (unknown [10.119.18.237]) (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 p1lg14878.it.hpe.com (Postfix) with ESMTPS id 60D3BD254; Thu, 3 Nov 2022 04:28:16 +0000 (UTC) Received: from adevxp033-sys.us.rdlabs.hpecorp.net (unknown [16.231.227.36]) by p1lg14886.dc01.its.hpecorp.net (Postfix) with ESMTP id D7CC8801ADB; Thu, 3 Nov 2022 04:28:15 +0000 (UTC) From: Robert Elliott To: herbert@gondor.apana.org.au, davem@davemloft.net, tim.c.chen@linux.intel.com, ap420073@gmail.com, ardb@kernel.org, Jason@zx2c4.com, David.Laight@ACULAB.COM, ebiggers@kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Robert Elliott Subject: [PATCH v3 09/17] crypto: x86/ghash - limit FPU preemption Date: Wed, 2 Nov 2022 23:27:32 -0500 Message-Id: <20221103042740.6556-10-elliott@hpe.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221103042740.6556-1-elliott@hpe.com> References: <20221012215931.3896-1-elliott@hpe.com> <20221103042740.6556-1-elliott@hpe.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: kITOWZe31j6M8F9WiQefL_ZTAWSd0oNg X-Proofpoint-GUID: kITOWZe31j6M8F9WiQefL_ZTAWSd0oNg X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-02_15,2022-11-02_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 clxscore=1015 bulkscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 adultscore=0 mlxlogscore=999 lowpriorityscore=0 spamscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211030031 X-Spam-Status: No, score=-3.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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746615071137650807?= X-GMAIL-MSGID: =?utf-8?q?1748448249371807316?= 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, leading to: rcu: INFO: rcu_preempt detected expedited stalls on CPUs/tasks: ... Fixes: 0e1227d356e9 ("crypto: ghash - Add PCLMULQDQ accelerated implementation") Suggested-by: Herbert Xu Signed-off-by: Robert Elliott --- v3 change to static int, simplify while loop --- arch/x86/crypto/ghash-clmulni-intel_glue.c | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/arch/x86/crypto/ghash-clmulni-intel_glue.c b/arch/x86/crypto/ghash-clmulni-intel_glue.c index 22367e363d72..0f24c3b23fd2 100644 --- a/arch/x86/crypto/ghash-clmulni-intel_glue.c +++ b/arch/x86/crypto/ghash-clmulni-intel_glue.c @@ -20,8 +20,11 @@ #include #include -#define GHASH_BLOCK_SIZE 16 -#define GHASH_DIGEST_SIZE 16 +#define GHASH_BLOCK_SIZE 16U +#define GHASH_DIGEST_SIZE 16U + +/* avoid kernel_fpu_begin/end scheduler/rcu stalls */ +static const unsigned int bytes_per_fpu = 50 * 1024; void clmul_ghash_mul(u8 *dst, const u128 *shash); @@ -80,9 +83,11 @@ static int ghash_update(struct shash_desc *desc, struct ghash_ctx *ctx = crypto_shash_ctx(desc->tfm); u8 *dst = dctx->buffer; + BUILD_BUG_ON(bytes_per_fpu < GHASH_BLOCK_SIZE); + if (dctx->bytes) { int n = min(srclen, dctx->bytes); - u8 *pos = dst + (GHASH_BLOCK_SIZE - dctx->bytes); + u8 *pos = dst + GHASH_BLOCK_SIZE - dctx->bytes; dctx->bytes -= n; srclen -= n; @@ -97,13 +102,18 @@ static int ghash_update(struct shash_desc *desc, } } - kernel_fpu_begin(); - clmul_ghash_update(dst, src, srclen, &ctx->shash); - kernel_fpu_end(); + while (srclen >= GHASH_BLOCK_SIZE) { + unsigned int chunk = min(srclen, bytes_per_fpu); + + kernel_fpu_begin(); + clmul_ghash_update(dst, src, chunk, &ctx->shash); + kernel_fpu_end(); + + src += chunk & ~(GHASH_BLOCK_SIZE - 1); + srclen -= chunk & ~(GHASH_BLOCK_SIZE - 1); + } - if (srclen & 0xf) { - src += srclen - (srclen & 0xf); - srclen &= 0xf; + if (srclen) { dctx->bytes = GHASH_BLOCK_SIZE - srclen; while (srclen--) *dst++ ^= *src++;