All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@orcam.me.uk>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Arnd Bergmann <arnd@arndb.de>, Theodore Ts'o <tytso@mit.edu>,
	Dominik Brodowski <linux@dominikbrodowski.net>,
	Russell King <linux@armlinux.org.uk>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	"David S . Miller" <davem@davemloft.net>,
	Richard Weinberger <richard@nod.at>,
	Anton Ivanov <anton.ivanov@cambridgegreys.com>,
	Johannes Berg <johannes@sipsolutions.net>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H . Peter Anvin" <hpa@zytor.com>,
	Chris Zankel <chris@zankel.net>,
	Max Filippov <jcmvbkbc@gmail.com>,
	John Stultz <john.stultz@linaro.org>,
	Stephen Boyd <sboyd@kernel.org>,
	Dinh Nguyen <dinguyen@kernel.org>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	linux-m68k <linux-m68k@lists.linux-m68k.org>,
	"open list:BROADCOM NVRAM DRIVER" <linux-mips@vger.kernel.org>,
	linux-riscv <linux-riscv@lists.infradead.org>,
	sparclinux@vger.kernel.org, linux-um@lists.infradead.org,
	X86 ML <x86@kernel.org>,
	linux-xtensa@linux-xtensa.org
Subject: Re: [PATCH v4 04/11] mips: use fallback for random_get_entropy() instead of zero
Date: Thu, 14 Apr 2022 02:16:18 +0100 (BST)	[thread overview]
Message-ID: <alpine.DEB.2.21.2204140014580.9383@angie.orcam.me.uk> (raw)
In-Reply-To: <CAHmME9pQ4xdeTUDxAdrOu=S9NRTonYzJVk50fa0Zfz4knZt5WA@mail.gmail.com>

Hi Jason,

> However, one thing that I've been thinking about is that the c0 random
> register is actually kind of garbage. In my fuzzy decade-old memory of
> MIPS, I believe the c0 random register starts at the maximum number of
> TLB entries (16?), and then counts down cyclically, decrementing once
> per CPU cycle. Is that right?

 Yes, for the relevant CPUs the range is 63-8 << 8 for R3k machines and 
47-0 (the lower bound can be higher if wired entries are used, which I 
think we occasionally do) for R4k machines with a buggy CP0 counter.  So 
there are either 56 or up to 48 distinct CP0 Random register values.

> If it is, there are some real pros and cons here to consider:
> - Pro: decrementing each CPU cycle means pretty good granularity
> - Con: wrapping at, like, 16 or something really is very limited, to
> the point of being almost bad
> 
> Meanwhile, on systems without the c0 cycles counter, what is the
> actual resolution of random_get_entropy_fallback()? Is this just
> falling back to jiffies?

 It depends on the exact system.  Some have a 32-bit high-resolution 
counter in the chipset (arch/mips/kernel/csrc-ioasic.c) giving like 25MHz 
resolution, some have nothing but jiffies.

> IF (a) the fallback is jiffies AND (b) c0 wraps at 16, then actually,
> what would be really nice would be something like:
> 
>     return (jiffies << 4) | read_c0_random();
> 
> It seems like that would give us something somewhat more ideal than
> the status quo. Still crap, of course, but undoubtedly better.

 It seems like a reasonable idea to me, but the details would have to be 
sorted out, because where a chipset high-resolution counter is available 
we want to factor it in, and otherwise we need to extract the right bits 
from the CP0 Random register, either 13:8 for the R3k or 5:0 for the R4k.

  Maciej

WARNING: multiple messages have this Message-ID (diff)
From: "Maciej W. Rozycki" <macro@orcam.me.uk>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	 LKML <linux-kernel@vger.kernel.org>,
	 Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	 Thomas Gleixner <tglx@linutronix.de>,
	Arnd Bergmann <arnd@arndb.de>,  Theodore Ts'o <tytso@mit.edu>,
	 Dominik Brodowski <linux@dominikbrodowski.net>,
	 Russell King <linux@armlinux.org.uk>,
	 Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	 Geert Uytterhoeven <geert@linux-m68k.org>,
	 Paul Walmsley <paul.walmsley@sifive.com>,
	 Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	 "David S . Miller" <davem@davemloft.net>,
	 Richard Weinberger <richard@nod.at>,
	 Anton Ivanov <anton.ivanov@cambridgegreys.com>,
	 Johannes Berg <johannes@sipsolutions.net>,
	Ingo Molnar <mingo@redhat.com>,  Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	 "H . Peter Anvin" <hpa@zytor.com>,
	Chris Zankel <chris@zankel.net>,
	 Max Filippov <jcmvbkbc@gmail.com>,
	John Stultz <john.stultz@linaro.org>,
	 Stephen Boyd <sboyd@kernel.org>,
	Dinh Nguyen <dinguyen@kernel.org>,
	 linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	 linux-m68k <linux-m68k@lists.linux-m68k.org>,
	 "open list:BROADCOM NVRAM DRIVER" <linux-mips@vger.kernel.org>,
	 linux-riscv <linux-riscv@lists.infradead.org>,
	sparclinux@vger.kernel.org,  linux-um@lists.infradead.org,
	X86 ML <x86@kernel.org>,
	 linux-xtensa@linux-xtensa.org
Subject: Re: [PATCH v4 04/11] mips: use fallback for random_get_entropy() instead of zero
Date: Thu, 14 Apr 2022 02:16:18 +0100 (BST)	[thread overview]
Message-ID: <alpine.DEB.2.21.2204140014580.9383@angie.orcam.me.uk> (raw)
In-Reply-To: <CAHmME9pQ4xdeTUDxAdrOu=S9NRTonYzJVk50fa0Zfz4knZt5WA@mail.gmail.com>

Hi Jason,

> However, one thing that I've been thinking about is that the c0 random
> register is actually kind of garbage. In my fuzzy decade-old memory of
> MIPS, I believe the c0 random register starts at the maximum number of
> TLB entries (16?), and then counts down cyclically, decrementing once
> per CPU cycle. Is that right?

 Yes, for the relevant CPUs the range is 63-8 << 8 for R3k machines and 
47-0 (the lower bound can be higher if wired entries are used, which I 
think we occasionally do) for R4k machines with a buggy CP0 counter.  So 
there are either 56 or up to 48 distinct CP0 Random register values.

> If it is, there are some real pros and cons here to consider:
> - Pro: decrementing each CPU cycle means pretty good granularity
> - Con: wrapping at, like, 16 or something really is very limited, to
> the point of being almost bad
> 
> Meanwhile, on systems without the c0 cycles counter, what is the
> actual resolution of random_get_entropy_fallback()? Is this just
> falling back to jiffies?

 It depends on the exact system.  Some have a 32-bit high-resolution 
counter in the chipset (arch/mips/kernel/csrc-ioasic.c) giving like 25MHz 
resolution, some have nothing but jiffies.

> IF (a) the fallback is jiffies AND (b) c0 wraps at 16, then actually,
> what would be really nice would be something like:
> 
>     return (jiffies << 4) | read_c0_random();
> 
> It seems like that would give us something somewhat more ideal than
> the status quo. Still crap, of course, but undoubtedly better.

 It seems like a reasonable idea to me, but the details would have to be 
sorted out, because where a chipset high-resolution counter is available 
we want to factor it in, and otherwise we need to extract the right bits 
from the CP0 Random register, either 13:8 for the R3k or 5:0 for the R4k.

  Maciej

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

WARNING: multiple messages have this Message-ID (diff)
From: "Maciej W. Rozycki" <macro@orcam.me.uk>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	 LKML <linux-kernel@vger.kernel.org>,
	 Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	 Thomas Gleixner <tglx@linutronix.de>,
	Arnd Bergmann <arnd@arndb.de>,  Theodore Ts'o <tytso@mit.edu>,
	 Dominik Brodowski <linux@dominikbrodowski.net>,
	 Russell King <linux@armlinux.org.uk>,
	 Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	 Geert Uytterhoeven <geert@linux-m68k.org>,
	 Paul Walmsley <paul.walmsley@sifive.com>,
	 Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	 "David S . Miller" <davem@davemloft.net>,
	 Richard Weinberger <richard@nod.at>,
	 Anton Ivanov <anton.ivanov@cambridgegreys.com>,
	 Johannes Berg <johannes@sipsolutions.net>,
	Ingo Molnar <mingo@redhat.com>,  Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	 "H . Peter Anvin" <hpa@zytor.com>,
	Chris Zankel <chris@zankel.net>,
	 Max Filippov <jcmvbkbc@gmail.com>,
	John Stultz <john.stultz@linaro.org>,
	 Stephen Boyd <sboyd@kernel.org>,
	Dinh Nguyen <dinguyen@kernel.org>,
	 linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	 linux-m68k <linux-m68k@lists.linux-m68k.org>,
	 "open list:BROADCOM NVRAM DRIVER" <linux-mips@vger.kernel.org>,
	 linux-riscv <linux-riscv@lists.infradead.org>,
	sparclinux@vger.kernel.org,  linux-um@lists.infradead.org,
	X86 ML <x86@kernel.org>,
	 linux-xtensa@linux-xtensa.org
Subject: Re: [PATCH v4 04/11] mips: use fallback for random_get_entropy() instead of zero
Date: Thu, 14 Apr 2022 02:16:18 +0100 (BST)	[thread overview]
Message-ID: <alpine.DEB.2.21.2204140014580.9383@angie.orcam.me.uk> (raw)
In-Reply-To: <CAHmME9pQ4xdeTUDxAdrOu=S9NRTonYzJVk50fa0Zfz4knZt5WA@mail.gmail.com>

Hi Jason,

> However, one thing that I've been thinking about is that the c0 random
> register is actually kind of garbage. In my fuzzy decade-old memory of
> MIPS, I believe the c0 random register starts at the maximum number of
> TLB entries (16?), and then counts down cyclically, decrementing once
> per CPU cycle. Is that right?

 Yes, for the relevant CPUs the range is 63-8 << 8 for R3k machines and 
47-0 (the lower bound can be higher if wired entries are used, which I 
think we occasionally do) for R4k machines with a buggy CP0 counter.  So 
there are either 56 or up to 48 distinct CP0 Random register values.

> If it is, there are some real pros and cons here to consider:
> - Pro: decrementing each CPU cycle means pretty good granularity
> - Con: wrapping at, like, 16 or something really is very limited, to
> the point of being almost bad
> 
> Meanwhile, on systems without the c0 cycles counter, what is the
> actual resolution of random_get_entropy_fallback()? Is this just
> falling back to jiffies?

 It depends on the exact system.  Some have a 32-bit high-resolution 
counter in the chipset (arch/mips/kernel/csrc-ioasic.c) giving like 25MHz 
resolution, some have nothing but jiffies.

> IF (a) the fallback is jiffies AND (b) c0 wraps at 16, then actually,
> what would be really nice would be something like:
> 
>     return (jiffies << 4) | read_c0_random();
> 
> It seems like that would give us something somewhat more ideal than
> the status quo. Still crap, of course, but undoubtedly better.

 It seems like a reasonable idea to me, but the details would have to be 
sorted out, because where a chipset high-resolution counter is available 
we want to factor it in, and otherwise we need to extract the right bits 
from the CP0 Random register, either 13:8 for the R3k or 5:0 for the R4k.

  Maciej

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-04-14  1:16 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-13 11:54 [PATCH v4 00/11] archs/random: fallback to best raw ktime when no cycle counter Jason A. Donenfeld
2022-04-13 11:54 ` Jason A. Donenfeld
2022-04-13 11:54 ` Jason A. Donenfeld
2022-04-13 11:54 ` [PATCH v4 01/11] timekeeping: add raw clock fallback for random_get_entropy() Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 14:32   ` Rob Herring
2022-04-13 14:32     ` Rob Herring
2022-04-13 14:32     ` Rob Herring
2022-04-13 22:38     ` Jason A. Donenfeld
2022-04-13 22:38       ` Jason A. Donenfeld
2022-04-13 22:38       ` Jason A. Donenfeld
2022-04-14 20:41       ` Rob Herring
2022-04-14 20:41         ` Rob Herring
2022-04-14 20:41         ` Rob Herring
2022-04-14 21:49         ` H. Peter Anvin
2022-04-14 21:49           ` H. Peter Anvin
2022-04-14 21:49           ` H. Peter Anvin
2022-04-14 10:12   ` Russell King (Oracle)
2022-04-14 10:12     ` Russell King (Oracle)
2022-04-14 10:12     ` Russell King (Oracle)
2022-04-14 11:56     ` Jason A. Donenfeld
2022-04-14 11:56       ` Jason A. Donenfeld
2022-04-14 11:56       ` Jason A. Donenfeld
2022-04-13 11:54 ` [PATCH v4 02/11] m68k: use fallback for random_get_entropy() instead of zero Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54 ` [PATCH v4 03/11] riscv: " Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 14:40   ` Rob Herring
2022-04-13 14:40     ` Rob Herring
2022-04-13 14:40     ` Rob Herring
2022-04-13 22:40     ` Jason A. Donenfeld
2022-04-13 22:40       ` Jason A. Donenfeld
2022-04-13 22:40       ` Jason A. Donenfeld
2022-04-13 11:54 ` [PATCH v4 04/11] mips: " Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 12:25   ` Thomas Bogendoerfer
2022-04-13 12:25     ` Thomas Bogendoerfer
2022-04-13 12:25     ` Thomas Bogendoerfer
2022-04-13 12:46     ` Maciej W. Rozycki
2022-04-13 12:46       ` Maciej W. Rozycki
2022-04-13 12:46       ` Maciej W. Rozycki
2022-04-13 22:35       ` Jason A. Donenfeld
2022-04-13 22:35         ` Jason A. Donenfeld
2022-04-13 22:35         ` Jason A. Donenfeld
2022-04-14  1:16         ` Maciej W. Rozycki [this message]
2022-04-14  1:16           ` Maciej W. Rozycki
2022-04-14  1:16           ` Maciej W. Rozycki
2022-04-14  9:27           ` Jason A. Donenfeld
2022-04-14  9:27             ` Jason A. Donenfeld
2022-04-14  9:27             ` Jason A. Donenfeld
2022-04-15 12:26             ` Maciej W. Rozycki
2022-04-15 12:26               ` Maciej W. Rozycki
2022-04-15 12:26               ` Maciej W. Rozycki
2022-04-16 11:09               ` Jason A. Donenfeld
2022-04-16 11:09                 ` Jason A. Donenfeld
2022-04-16 11:09                 ` Jason A. Donenfeld
2022-04-16 14:44                 ` Maciej W. Rozycki
2022-04-16 14:44                   ` Maciej W. Rozycki
2022-04-16 14:44                   ` Maciej W. Rozycki
2022-04-16 22:54                   ` Jason A. Donenfeld
2022-04-16 22:54                     ` Jason A. Donenfeld
2022-04-16 22:54                     ` Jason A. Donenfeld
2022-04-18  7:10               ` Thomas Bogendoerfer
2022-04-18  7:10                 ` Thomas Bogendoerfer
2022-04-18  7:10                 ` Thomas Bogendoerfer
2022-04-18  7:10                 ` Thomas Bogendoerfer
2022-04-23 23:33                 ` Maciej W. Rozycki
2022-04-23 23:33                   ` Maciej W. Rozycki
2022-04-23 23:33                   ` Maciej W. Rozycki
2022-04-24  8:15                   ` Jason A. Donenfeld
2022-04-24  8:15                     ` Jason A. Donenfeld
2022-04-24  8:15                     ` Jason A. Donenfeld
2022-04-24 10:51                     ` Maciej W. Rozycki
2022-04-24 10:51                       ` Maciej W. Rozycki
2022-04-24 10:51                       ` Maciej W. Rozycki
2022-04-13 11:54 ` [PATCH v4 05/11] arm: " Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54 ` [PATCH v4 06/11] nios2: " Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-05-23 13:58   ` Dinh Nguyen
2022-05-23 13:58     ` Dinh Nguyen
2022-05-23 13:58     ` Dinh Nguyen
2022-04-13 11:54 ` [PATCH v4 07/11] x86: " Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54 ` [PATCH v4 08/11] um: " Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54 ` [PATCH v4 09/11] sparc: " Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54 ` [PATCH v4 10/11] xtensa: " Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54 ` [PATCH v4 11/11] random: insist on random_get_entropy() existing in order to simplify Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld
2022-04-13 11:54   ` Jason A. Donenfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.21.2204140014580.9383@angie.orcam.me.uk \
    --to=macro@orcam.me.uk \
    --cc=Jason@zx2c4.com \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=chris@zankel.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=dinguyen@kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=hpa@zytor.com \
    --cc=jcmvbkbc@gmail.com \
    --cc=johannes@sipsolutions.net \
    --cc=john.stultz@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-um@lists.infradead.org \
    --cc=linux-xtensa@linux-xtensa.org \
    --cc=linux@armlinux.org.uk \
    --cc=linux@dominikbrodowski.net \
    --cc=mingo@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=richard@nod.at \
    --cc=sboyd@kernel.org \
    --cc=sparclinux@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tsbogend@alpha.franken.de \
    --cc=tytso@mit.edu \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.