From: Paolo Bonzini <pbonzini@redhat.com>
To: Andy Lutomirski <luto@amacapital.net>,
kvm@vger.kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
"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>,
bsd@redhat.com, Andrew Honig <ahonig@google.com>
Subject: Re: [PATCH v5 5/5] x86,kaslr: Use MSR_KVM_GET_RNG_SEED for KASLR if available
Date: Thu, 31 Jul 2014 13:56:42 +0200 [thread overview]
Message-ID: <53DA2EFA.9060602@redhat.com> (raw)
In-Reply-To: <3aa0b464e9aba9609de4d4118e4be7526f6dbab9.1406177531.git.luto@amacapital.net>
Il 24/07/2014 06:57, Andy Lutomirski ha scritto:
> It's considerably better than any of the alternatives on KVM.
>
> Rather than reinventing all of the cpu feature query code, this fixes
> native_cpuid to work in PIC objects.
>
> I haven't combined it with boot/cpuflags.c's cpuid implementation:
> including asm/processor.h from boot/cpuflags.c results in a flood of
> unrelated errors, and fixing it might be messy.
>
> Reviewed-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Andy Lutomirski <luto@amacapital.net>
> ---
> arch/x86/boot/compressed/aslr.c | 27 +++++++++++++++++++++++++++
> arch/x86/include/asm/processor.h | 21 ++++++++++++++++++---
> 2 files changed, 45 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/boot/compressed/aslr.c b/arch/x86/boot/compressed/aslr.c
> index fc6091a..8583f0e 100644
> --- a/arch/x86/boot/compressed/aslr.c
> +++ b/arch/x86/boot/compressed/aslr.c
> @@ -5,6 +5,8 @@
> #include <asm/archrandom.h>
> #include <asm/e820.h>
>
> +#include <uapi/asm/kvm_para.h>
> +
> #include <generated/compile.h>
> #include <linux/module.h>
> #include <linux/uts.h>
> @@ -15,6 +17,22 @@
> static const char build_str[] = UTS_RELEASE " (" LINUX_COMPILE_BY "@"
> LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION;
>
> +static bool kvm_para_has_feature(unsigned int feature)
> +{
> + u32 kvm_base;
> + u32 features;
> +
> + if (!has_cpuflag(X86_FEATURE_HYPERVISOR))
> + return false;
> +
> + kvm_base = hypervisor_cpuid_base("KVMKVMKVM\0\0\0", KVM_CPUID_FEATURES);
> + if (!kvm_base)
> + return false;
> +
> + features = cpuid_eax(kvm_base | KVM_CPUID_FEATURES);
> + return features & (1UL << feature);
> +}
> +
> #define I8254_PORT_CONTROL 0x43
> #define I8254_PORT_COUNTER0 0x40
> #define I8254_CMD_READBACK 0xC0
> @@ -81,6 +99,15 @@ static unsigned long get_random_long(void)
> }
> }
>
> + if (kvm_para_has_feature(KVM_FEATURE_GET_RNG_SEED)) {
> + u64 seed;
> +
> + debug_putstr(" MSR_KVM_GET_RNG_SEED");
> + rdmsrl(MSR_KVM_GET_RNG_SEED, seed);
> + random ^= (unsigned long)seed;
> + use_i8254 = false;
> + }
> +
> if (has_cpuflag(X86_FEATURE_TSC)) {
> debug_putstr(" RDTSC");
> rdtscll(raw);
> diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
> index a4ea023..6096f3c 100644
> --- a/arch/x86/include/asm/processor.h
> +++ b/arch/x86/include/asm/processor.h
> @@ -189,10 +189,25 @@ static inline int have_cpuid_p(void)
> static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
> unsigned int *ecx, unsigned int *edx)
> {
> - /* ecx is often an input as well as an output. */
> - asm volatile("cpuid"
> + /*
> + * This function can be used from the boot code, so it needs
> + * to avoid using EBX in constraints in PIC mode.
> + *
> + * ecx is often an input as well as an output.
> + */
> + asm volatile(".ifnc %%ebx,%1 ; .ifnc %%rbx,%1 \n\t"
> + "movl %%ebx,%1 \n\t"
> + ".endif ; .endif \n\t"
> + "cpuid \n\t"
> + ".ifnc %%ebx,%1 ; .ifnc %%rbx,%1 \n\t"
> + "xchgl %%ebx,%1 \n\t"
> + ".endif ; .endif"
> : "=a" (*eax),
> - "=b" (*ebx),
> +#if defined(__i386__) && defined(__PIC__)
> + "=r" (*ebx), /* gcc won't let us use ebx */
> +#else
> + "=b" (*ebx), /* ebx is okay */
> +#endif
> "=c" (*ecx),
> "=d" (*edx)
> : "0" (*eax), "2" (*ecx)
>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
next prev parent reply other threads:[~2014-07-31 11:56 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-24 4:57 [PATCH v5 0/5] random,x86,kvm: Rework arch RNG seeds and get some from kvm Andy Lutomirski
2014-07-24 4:57 ` [PATCH v5 1/5] x86,kvm: Add MSR_KVM_GET_RNG_SEED and a matching feature bit Andy Lutomirski
2014-07-31 11:56 ` Paolo Bonzini
2014-07-24 4:57 ` [PATCH v5 2/5] random: Add and use arch_get_rng_seed Andy Lutomirski
2014-07-29 23:46 ` Andy Lutomirski
2014-08-04 22:25 ` Theodore Ts'o
2014-07-24 4:57 ` [PATCH v5 3/5] x86,random: Add an x86 implementation of arch_get_rng_seed Andy Lutomirski
2014-07-24 4:57 ` [PATCH v5 4/5] x86,random,kvm: Use KVM_GET_RNG_SEED in arch_get_rng_seed Andy Lutomirski
2014-07-31 11:56 ` Paolo Bonzini
2014-07-24 4:57 ` [PATCH v5 5/5] x86,kaslr: Use MSR_KVM_GET_RNG_SEED for KASLR if available Andy Lutomirski
2014-07-31 11:56 ` Paolo Bonzini [this message]
2014-08-12 19:11 ` [PATCH v5 0/5] random,x86,kvm: Rework arch RNG seeds and get some from kvm Andy Lutomirski
2014-08-12 19:17 ` Theodore Ts'o
2014-08-12 19:22 ` Andy Lutomirski
2014-08-13 7:48 ` H. Peter Anvin
2014-08-13 8:37 ` Andy Lutomirski
2014-08-13 14:32 ` Theodore Ts'o
2014-08-13 16:13 ` Andy Lutomirski
2014-08-13 17:45 ` H. Peter Anvin
2014-08-13 18:22 ` Theodore Ts'o
2014-08-13 18:33 ` Andy Lutomirski
2014-08-13 18:44 ` H. Peter Anvin
2014-08-14 2:41 ` H. Peter Anvin
2014-08-14 5:14 ` Andy Lutomirski
2014-08-17 8:44 ` Paolo Bonzini
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=53DA2EFA.9060602@redhat.com \
--to=pbonzini@redhat.com \
--cc=ahonig@google.com \
--cc=bsd@redhat.com \
--cc=dborkman@redhat.com \
--cc=gleb@kernel.org \
--cc=hpa@zytor.com \
--cc=keescook@chromium.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--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;
as well as URLs for NNTP newsgroup(s).