From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2F5FC4321E for ; Fri, 25 Nov 2022 08:41:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229688AbiKYIlN (ORCPT ); Fri, 25 Nov 2022 03:41:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbiKYIlL (ORCPT ); Fri, 25 Nov 2022 03:41:11 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29F1F23E88; Fri, 25 Nov 2022 00:41:10 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1oyUGQ-000gkp-AU; Fri, 25 Nov 2022 16:40:51 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Nov 2022 16:40:50 +0800 Date: Fri, 25 Nov 2022 16:40:50 +0800 From: Herbert Xu To: "Jason A. Donenfeld" Cc: Robert Elliott , davem@davemloft.net, tim.c.chen@linux.intel.com, ap420073@gmail.com, ardb@kernel.org, David.Laight@aculab.com, ebiggers@kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 10/24] crypto: x86/poly - limit FPU preemption Message-ID: References: <20221103042740.6556-1-elliott@hpe.com> <20221116041342.3841-1-elliott@hpe.com> <20221116041342.3841-11-elliott@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 16, 2022 at 12:13:51PM +0100, Jason A. Donenfeld wrote: > On Tue, Nov 15, 2022 at 10:13:28PM -0600, Robert Elliott wrote: > > +/* avoid kernel_fpu_begin/end scheduler/rcu stalls */ > > +static const unsigned int bytes_per_fpu = 337 * 1024; > > + > > Use an enum for constants like this: > > enum { BYTES_PER_FPU = ... }; > > You can even make it function-local, so it's near the code that uses it, > which will better justify its existence. > > Also, where did you get this number? Seems kind of weird. These numbers are highly dependent on hardware and I think having them hard-coded is wrong. Perhaps we should try a different approach. How about just limiting the size to 4K, and then depending on need_resched we break out of the loop? Something like: if (!len) return 0; kernel_fpu_begin(); for (;;) { unsigned int chunk = min(len, 4096); sha1_base_do_update(desc, data, chunk, sha1_xform); len -= chunk; data += chunk; if (!len) break; if (need_resched()) { kernel_fpu_end(); cond_resched(); kernel_fpu_begin(); } } kernel_fpu_end(); Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt