Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp10103969rwb; Fri, 25 Nov 2022 00:44:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5KG9rDv2VEmOPt26ybJC9/Rze/pU9We4mkmYjhohVBgIxiABBaAo8pL81csbw0fDQZt5L3 X-Received: by 2002:a05:6a02:118:b0:477:cce0:49d with SMTP id bg24-20020a056a02011800b00477cce0049dmr6379522pgb.74.1669365882526; Fri, 25 Nov 2022 00:44:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669365882; cv=none; d=google.com; s=arc-20160816; b=pZndilGn8Op1BRAK8ve3igAjsyQDWDcCKh/9gyiFAei7vfl5U5VGgjd9PI3iTfLHXm /lv+iztTDCyVtgiIsbX0ZScwCkFpM+4La0ODN1/NAN3cTUzS+EJd3BniItR8VWeGq92K Y4ZBcTgu7Wc1GHfQAvYell8c7QDnwf8WreqAR/U4FoHhSNYWhGWcPPO+zB74WBYYAawe YJg6XDfo5v4U8AtwJ+KV2gXn3wC248sWlYpBsbcU4pWss1XUSX3OxxbtpsWoOayHuis4 zkxwrX82BtQUj0wHgRgF4m1VYXwk1lIQ+AxuZiH93aTsEuexHIt92SAODgV7kOoMARak ccSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=5ZasVjgJoMBW9athPsZs3+fSVKgGLeyBs6IaGqGjJvY=; b=H9brKO7ltoQXXxV3/39DD+JeMjA3eV0FuSTauaIGT5ETSpLxG83LWzyyvDnfeVH6LS 5eckFqXgjvwg3XCmSsMHDFkAfrr5W0hbinErX8iBx2cgf3Zkfq1QkW5xSwKwKSalfUgN B328QE57N3Ud5ye3zMUzCHDuScBxfnNLnmnPgk8/9JXTF/A/YC+wi61NLm3ZWNhfQ/cV ALF7tWnLC83XRqScadLuGsRX9hB4eLT3+MOygyDAtmeD5PcpLvP+fCCGwc5AxYf9YL6d KRAmzT5hznf9rWtzGbHs8TPjBJGK+1+0t7k5uIwmHcF9EmgUKyvDBX1jtkzKBBB/bAcO NvQw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v20-20020a631514000000b004772b3d0bafsi3497182pgl.354.2022.11.25.00.44.22; Fri, 25 Nov 2022 00:44:42 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229489AbiKYIlM (ORCPT + 99 others); Fri, 25 Nov 2022 03:41:12 -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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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 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