linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: x86@kernel.org, Jann Horn <jannh@google.com>,
	Natalie Silvanovich <natashenka@google.com>,
	Seth Jenkins <sethjenkins@google.com>,
	Kees Cook <keescook@chromium.org>,
	linux-kernel@vger.kernel.org
Subject: Re: x86/mm: Randomize per-cpu entry area
Date: Fri, 7 Oct 2022 08:44:52 -0600	[thread overview]
Message-ID: <Y0A7ZAjtDcq2PJaX@zx2c4.com> (raw)
In-Reply-To: <Yz/mfJ1gjgshF19t@hirez.programming.kicks-ass.net>

On Fri, Oct 07, 2022 at 10:42:36AM +0200, Peter Zijlstra wrote:
> +	max_cea = (CPU_ENTRY_AREA_MAP_SIZE - PAGE_SIZE) / CPU_ENTRY_AREA_SIZE;
> +
> +	/* O(sodding terrible) */
> +	for_each_possible_cpu(i) {
> +		unsigned int cea;
> +
> +again:
> +		cea = prandom_u32_max(max_cea);

Just FYI, max_cea is 2274876 (at least in my test rig), which means the
values returned from prandom_u32_max() won't be uniformly distributed.
Right now the kernel doesn't have a function that does rejection
sampling to get uniform distribution, but I could add one if you need.
Alternatively, maybe you don't actually *need* this to be perfectly
distributed -- which seems to be a common perspective -- and so this is
good enough. Your call, but just wanted to make you aware.

Jason

  reply	other threads:[~2022-10-07 14:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-07  8:42 x86/mm: Randomize per-cpu entry area Peter Zijlstra
2022-10-07 14:44 ` Jason A. Donenfeld [this message]
2022-10-07 15:14   ` Peter Zijlstra

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=Y0A7ZAjtDcq2PJaX@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=jannh@google.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=natashenka@google.com \
    --cc=peterz@infradead.org \
    --cc=sethjenkins@google.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).