Received: by 2002:a05:6a10:87d6:0:0:0:0 with SMTP id g22csp599096pxr; Mon, 11 Apr 2022 02:09:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJza10StMBtd5O4A+EWLrNs9Dz3+4rxRtQcatAIIgKjgSWshV3GPxNOZ6CI9v9smM0ermkcM X-Received: by 2002:a17:906:d555:b0:6db:148e:5cc with SMTP id cr21-20020a170906d55500b006db148e05ccmr28088287ejc.63.1649668160302; Mon, 11 Apr 2022 02:09:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649668160; cv=none; d=google.com; s=arc-20160816; b=KbvPN3nJbmddtSzqjg2QmIGXz2hCf4ZBuKQhmWHyCO0lod3ElvGfirVaacNH7aEVic etJZcE/yBchX+7uJcWqdEETcHyuKxX3BExyXTMpHs4BUb09vdDmwWRv01JOileJ7oebP yInBUJV+a2lCfuw1ANkdAdykaRXYIWIsphmLPaBbC8uj4MTyXzwvMY+jkYcOhO0PC1Vw RUOBhpsFv89nja+wVhnODcgOtXQva/o5+SDwAylryJoCC3U5VS/MBS56ilB+1rsbKDcy HX2u0oOho5mJuWY9Rqn5R+7wY/oHoQ3my+MrkpC08hUsgaZtMSpnhUBWMjeyxLMSkS17 Dhig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=hE+Xcw0JizEU8Wnq0ZP70KLvw79L4CjFSDQ+JeFdg1E=; b=0wQuudTi6Tgr+PAsjmn6bFjXoACBKdhjIYDVGA77KJ1ivd1yWGDXWNvOqGPnuQylEV dEOU3tbuBfaaQ6xtvNFAx92n52KKYGj4a6BVFKWQDoO9A2h3GGYMAhoPhwAw2EyvEg4l ubqh8zNhNDWuBY/WPvWKcdsWBLhX9/sodd40v1AApFPQW6bT+PRgXC3NG+gyPsQznF/4 R5HAxK+1spp2mkOm3yY9PO4RVs4sigpvtQBishwyA7KqU4EXCL8l5GtTsWPeLPrAbmg+ NWOW9dWS57ZDDLlOjMpVLBHWQLJOZPg+sFKkAhNVjaJtWknNQIuk3SXzcFlpSrIM9WPq 39jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wcxdyIRU; dkim=neutral (no key) header.i=@linutronix.de header.b=WYkLY0CP; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m2-20020a17090679c200b006e881149e83si3156262ejo.629.2022.04.11.02.08.45; Mon, 11 Apr 2022 02:09:20 -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=@linutronix.de header.s=2020 header.b=wcxdyIRU; dkim=neutral (no key) header.i=@linutronix.de header.b=WYkLY0CP; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235014AbiDJU7W (ORCPT + 99 others); Sun, 10 Apr 2022 16:59:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242351AbiDJU7U (ORCPT ); Sun, 10 Apr 2022 16:59:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01BFF11C2D; Sun, 10 Apr 2022 13:57:04 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1649624223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hE+Xcw0JizEU8Wnq0ZP70KLvw79L4CjFSDQ+JeFdg1E=; b=wcxdyIRUujqol7xM6/jNUaTiJK9LjQ2TxNswzkFqW9IdoCXdLl06LKnKcZu+/PhgcujoFD 4BL6UvqV2KyZxKcXAHyaYhKgWh+hW7kmtVsrR50bN2kEyItTRS4qenN4xdW+pqDVD/EBQJ FRBUDZAXAnKdCAGLESQsbxyitf9btYLvPr88J6g6SWQULeVv1+BpRryz8V4vlo0Sxn5A1B B7jn62NOZrsua6pLpW1KUXCpCdbVHaodhuhDNbeQMQoqpedjr6x5wCT5mekwEWTjKpLkBQ ZhVOGqfjVtVh2uqjxiB4TKZirCwCtL5e55pMSWAO2Ry+8zKLnyd7j8EtVVFiMg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1649624223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hE+Xcw0JizEU8Wnq0ZP70KLvw79L4CjFSDQ+JeFdg1E=; b=WYkLY0CPXnB/0QIxOUzf7pdAwpOuVx9Tljat/8ZOy+GrRKgqIku37SjusWmBW3We4uxu9x QGtzsFUk86/12iAg== To: "Jason A. Donenfeld" Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, arnd@arndb.de, Theodore Ts'o , Dominik Brodowski , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , "David S . Miller" , Richard Weinberger , Anton Ivanov , Johannes Berg , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, linux-xtensa@linux-xtensa.org Subject: Re: [PATCH RFC v1 00/10] archs/random: fallback to using sched_clock() if no cycle counter In-Reply-To: References: <20220408182145.142506-1-Jason@zx2c4.com> <87wnfxhm3n.ffs@tglx> Date: Sun, 10 Apr 2022 22:57:02 +0200 Message-ID: <877d7whd29.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Jason, On Sun, Apr 10 2022 at 16:25, Jason A. Donenfeld wrote: > On Sun, Apr 10, 2022 at 01:29:32AM +0200, Thomas Gleixner wrote: >> But the below uncompiled hack gives you access to the 'best' clocksource >> of a machine, i.e. the one which the platform decided to be the one >> which is giving the best resolution. The minimal bitwidth of that is >> AFAICT 20 bits. In the jiffies case this will at least advance every >> tick. > > Oh, huh, that's pretty cool. I can try to make a commit out of that. Are > you suggesting I use this as the fallback for all platforms that > currently return zero, or just for m68k per Arnd's suggestion, and then > use sched_clock() for the others? It sounds to me like you're saying > this would be best for all of them. If so, that'd be quite nice. It's the best in terms of timekeeping. Not the fastest :) >> The price, e.g. on x86 would be that RDTSC would be invoked via an >> indirect function call. Not the end of the world... > > Well on x86, random_get_entropy() is overridden in the arch/ code to > call get_cycles(). So this would really just be for 486 and for other > architectures with no cycle counter that are currently returning zero. > However, this brings up a good point: if your proposed > ktime_read_raw_clock() function really is so nice, should it be used > everywhere unconditionally with no arch-specific overrides? On x86, is > it really guaranteed to be RDTSC, and not, say, some off-core HPET > situation? And is this acceptable to call from the hard irq handler? No, that's the sad part. On system where TSC is unstable (for whatever reason) this might fallback to some off-core clock (HPET, PMTIMER). The good news is that this is mostly affecting older systems. After 20+ years of complaining the hardware people seem to have figured out that a fast accessible and realiable clocksource is something useful. :) > Not yet having too much knowledge, I'm tentatively leaning toward the > safe side, of just using ktime_read_raw_clock() in the current places > that return zero all the time -- that is, for the purpose this patchset > has. That's probably a good approach and it's init/runtime discoverable. Thanks, tglx