Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp523000iob; Fri, 13 May 2022 06:58:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxPjU2VeHVMeBPkXB3mMemD/vl9F4XuMipLfxMg77VC4RKAi3xp7Joao1L0ZmUYokP4gO9 X-Received: by 2002:a17:907:1ca4:b0:6f4:68b8:99d2 with SMTP id nb36-20020a1709071ca400b006f468b899d2mr4467114ejc.616.1652450289746; Fri, 13 May 2022 06:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652450289; cv=none; d=google.com; s=arc-20160816; b=TtujYL99fFPrdyKXPlT+uAOO4HqhfUoMAr8mDT1lPhBomajf5+OWDLQF7twclGuOJu +aocX6IeaDD7AJDrQAN9+lrnTn3UQkKgDCzMjx2Yw8NGnzZUI4XN74gJOekkxiD50ntj wKDLUECfhkL+yJ/YnlRC0Ma2pkopjXcXrwGc/g1u8CVX6oCKnTAneKz6ZGc/ULf6xdBv kH2+z9RfLMymDMST1a0dqEtM/5bGRSrvlHp2ZhUHOyGxIsSYyoSZZPncf9wHnZqJKw+L kMpEPOKkgu4q+BOAEKr4VYbuQ+iHYBq2Uax2jFlFrwiMh5syIHSyA905d7X8WYcLh3AK JB2Q== 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=yhm6I+mVwHld/MfSyWzr/Da+pYW2YBHwY3OziCbzqYc=; b=Iqx0R7WRa8SQkrTuLgX8kFm8Dd8fNZnq4QgMU3bRfnBU1CnEWfc9Yn22U3I0w/0ThQ ph7Mp+DK0/hBj5kH+CIH7pra/LL6LMYhGn7R6lemRQcxeH/G16NlBq9emV90+rvgocdS XSUpiFXDdRBLYsj+SPW3wnpwMer5oivM1Z6MFGA6wbZ5AgmNoBqmIGl3rS7hUr7Z6Vwg EXWehYevWvgFyo6zFgcWTBhHg4sBmyKjhrR/9k7qoFZ9Sqrli0V5FuRZ6qf68jkuTesm ZbvG3MUQ67nP+h5dBOSgiYddQC3i44tIZhsy3CmVxDcLcGlTtIrGehJ9V/uMtwPuxxPp D4+A== 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 cr15-20020a170906d54f00b006f3b763040asi2332713ejc.141.2022.05.13.06.57.42; Fri, 13 May 2022 06:58:09 -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; 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 S1377333AbiEMG03 (ORCPT + 99 others); Fri, 13 May 2022 02:26:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377311AbiEMG0Z (ORCPT ); Fri, 13 May 2022 02:26:25 -0400 Received: from isilmar-4.linta.de (isilmar-4.linta.de [136.243.71.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E71252980B; Thu, 12 May 2022 23:26:22 -0700 (PDT) X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES Received: from owl.dominikbrodowski.net (owl.brodo.linta [10.2.0.111]) by isilmar-4.linta.de (Postfix) with ESMTPSA id F3FF920140A; Fri, 13 May 2022 06:26:05 +0000 (UTC) Received: by owl.dominikbrodowski.net (Postfix, from userid 1000) id D88E880989; Fri, 13 May 2022 08:22:20 +0200 (CEST) Date: Fri, 13 May 2022 08:22:20 +0200 From: Dominik Brodowski To: "Jason A. Donenfeld" Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Theodore Ts'o , Sultan Alsawaf Subject: Re: [PATCH v4] random: use static branch for crng_ready() Message-ID: References: <20220512144235.2466-1-Jason@zx2c4.com> <20220512163748.3477-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220512163748.3477-1-Jason@zx2c4.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Am Thu, May 12, 2022 at 06:37:48PM +0200 schrieb Jason A. Donenfeld: > Since crng_ready() is only false briefly during initialization and then > forever after becomes true, we don't need to evaluate it after, making > it a prime candidate for a static branch. > > One complication, however, is that it changes state in a particular call > to credit_init_bits(), which might be made from atomic context, which > means we must kick off a workqueue to change the static key. Further > complicating things, credit_init_bits() may be called sufficiently early > on in system initialization such that system_wq is NULL. > > Fortunately, there exists the nice function execute_in_process_context(), > which will immediately execute the function if !in_interrupt(), and > otherwise defer it to a workqueue. During early init, before workqueues > are available, in_interrupt() is always false, because interrupts > haven't even been enabled yet, which means the function in that case > executes immediately. Later on, after workqueues are available, > in_interrupt() might be true, but in that case, the work is queued in > system_wq and all goes well. Reviewed-by: Dominik Brodowski Thanks, Dominik