public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Andy Lutomirski <luto@amacapital.net>,
	kvm@vger.kernel.org, "Theodore Ts'o" <tytso@mit.edu>,
	linux-kernel@vger.kernel.org, Kees Cook <keescook@chromium.org>,
	x86@kernel.org
Cc: Daniel Borkmann <dborkman@redhat.com>,
	Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>,
	Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>,
	Gleb Natapov <gleb@kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	bsd@redhat.com
Subject: Re: [PATCH v3 2/5] random,x86: Add arch_get_slow_rng_u64
Date: Wed, 16 Jul 2014 14:59:05 -0700	[thread overview]
Message-ID: <53C6F5A9.80400@zytor.com> (raw)
In-Reply-To: <5778e65d5ca52bebbaa023e177d863e44f098e96.1405546879.git.luto@amacapital.net>

On 07/16/2014 02:45 PM, Andy Lutomirski wrote:
> diff --git a/arch/x86/include/asm/archslowrng.h b/arch/x86/include/asm/archslowrng.h
> new file mode 100644
> index 0000000..c8e8d0d
> --- /dev/null
> +++ b/arch/x86/include/asm/archslowrng.h
> @@ -0,0 +1,30 @@
> +/*
> + * This file is part of the Linux kernel.
> + *
> + * Copyright (c) 2014 Andy Lutomirski
> + * Authors: Andy Lutomirski <luto@amacapital.net>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + */
> +
> +#ifndef ASM_X86_ARCHSLOWRANDOM_H
> +#define ASM_X86_ARCHSLOWRANDOM_H
> +
> +#ifndef CONFIG_ARCH_SLOW_RNG
> +# error archslowrng.h should not be included if !CONFIG_ARCH_SLOW_RNG
> +#endif
> +

I'm *seriously* questioning the wisdom of this.  A much saner thing
would be to do:

#ifndef CONFIG_ARCH_SLOW_RNG

/* Not supported */
static inline int arch_get_slow_rng_u64(u64 *v)
{
	(void)v;
	return 0;
}

#endif

... which is basically what we do for the archrandom stuff.

I'm also wondering if it makes sense to have a function which prefers
arch_get_random*() over this one as a preferred interface.  Something like:

int get_random_arch_u64_slow_ok(u64 *v)
{
	int i;
	u64 x = 0;
	unsigned long l;

	for (i = 0; i < 64/BITS_PER_LONG; i++) {
		if (!arch_get_random_long(&l))
			return arch_get_slow_rng_u64(v);

		x |=  l << (i*BITS_PER_LONG);
	}
	*v = l;
	return 0;
}

This still doesn't address the issue e.g. on x86 where RDRAND is
available but we haven't set up alternatives yet.  So it might be that
what we really want is to encapsulate this fallback in arch code and do
a more direct enumeration.

> +
> +static int kvm_get_slow_rng_u64(u64 *v)
> +{
> +	/*
> +	 * Allow migration from a hypervisor with the GET_RNG_SEED
> +	 * feature to a hypervisor without it.
> +	 */
> +	if (rdmsrl_safe(MSR_KVM_GET_RNG_SEED, v) == 0)
> +		return 1;
> +	else
> +		return 0;
> +}

How about:

return rdmsrl_safe(MSR_KVM_GET_RNG_SEED, v) == 0;

The naming also feels really inconsistent...
	
	-hpa


  reply	other threads:[~2014-07-16 21:59 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-16 21:45 [PATCH v3 0/5] random,x86,kvm: Add and use MSR_KVM_GET_RNG_SEED Andy Lutomirski
2014-07-16 21:45 ` [PATCH v3 1/5] x86,kvm: Add MSR_KVM_GET_RNG_SEED and a matching feature bit Andy Lutomirski
2014-07-17 17:43   ` Andrew Honig
2014-07-17 17:45     ` Andy Lutomirski
2014-07-16 21:45 ` [PATCH v3 2/5] random,x86: Add arch_get_slow_rng_u64 Andy Lutomirski
2014-07-16 21:59   ` H. Peter Anvin [this message]
2014-07-16 22:13     ` Andy Lutomirski
2014-07-16 22:40       ` Andy Lutomirski
2014-07-16 22:59         ` H. Peter Anvin
2014-07-17  0:03           ` Andy Lutomirski
2014-07-17  4:55             ` H. Peter Anvin
2014-07-17 10:33               ` Theodore Ts'o
2014-07-17 16:39                 ` H. Peter Anvin
2014-07-17 17:12                   ` Andy Lutomirski
2014-07-17 17:32                     ` Theodore Ts'o
2014-07-17 17:34                       ` Andy Lutomirski
2014-07-17 18:42                         ` Hannes Frederic Sowa
2014-07-17 19:15                           ` Andy Lutomirski
2014-07-17 12:39           ` Daniel Borkmann
2014-07-16 21:45 ` [PATCH v3 3/5] random: Seed pools from arch_get_slow_rng_u64 at startup Andy Lutomirski
2014-07-16 21:45 ` [PATCH v3 4/5] random: Log how many bits we managed to seed with in init_std_data Andy Lutomirski
2014-07-16 21:45 ` [PATCH v3 5/5] x86,kaslr: Use MSR_KVM_GET_RNG_SEED for KASLR if available Andy Lutomirski

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=53C6F5A9.80400@zytor.com \
    --to=hpa@zytor.com \
    --cc=bsd@redhat.com \
    --cc=dborkman@redhat.com \
    --cc=gleb@kernel.org \
    --cc=keescook@chromium.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=pbonzini@redhat.com \
    --cc=raghavendra.kt@linux.vnet.ibm.com \
    --cc=tytso@mit.edu \
    --cc=vatsa@linux.vnet.ibm.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