Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751263AbdLIHmV (ORCPT ); Sat, 9 Dec 2017 02:42:21 -0500 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:11070 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751015AbdLIHmS (ORCPT ); Sat, 9 Dec 2017 02:42:18 -0500 X-IronPort-AV: E=Sophos;i="5.45,381,1508803200"; d="scan'208";a="323196972" From: "Sironi, Filippo" To: Paolo Bonzini CC: "rkrcmar@redhat.com" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 2/2] KVM: x86: Allow userspace to define what's the microcode version Thread-Topic: [PATCH 2/2] KVM: x86: Allow userspace to define what's the microcode version Thread-Index: AQHTZtVpIVnd2IPHOEWS92aoXsxI36MoIFcAgBKUZQA= Date: Sat, 9 Dec 2017 07:42:03 +0000 Message-ID: <7FD2AE1E-8AFA-481C-AADC-BA6889F40B0F@amazon.de> References: <1511714482-3273-1-git-send-email-sironi@amazon.de> <1511714482-3273-2-git-send-email-sironi@amazon.de> <510cf2fb-1d53-485f-bfd1-3d852378c866@redhat.com> In-Reply-To: <510cf2fb-1d53-485f-bfd1-3d852378c866@redhat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.43.166.251] Content-Type: text/plain; charset="us-ascii" Content-ID: <9A58D8884BAF374B819C811A3CCD3764@amazon.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id vB97gQCk007037 Content-Length: 2510 Lines: 75 > On 27. Nov 2017, at 03:58, Paolo Bonzini wrote: > > On 26/11/2017 17:41, Filippo Sironi wrote: >> ... that the guest should see. >> Guest operating systems may check the microcode version to decide whether >> to disable certain features that are known to be buggy up to certain >> microcode versions. Address the issue by making the microcode version >> that the guest should see settable. >> The rationale for having userspace specifying the microcode version, rather >> than having the kernel picking it, is to ensure consistency for live-migrated >> instances; we don't want them to see a microcode version increase without a >> reset. >> >> Signed-off-by: Filippo Sironi >> --- >> arch/x86/kvm/x86.c | 23 +++++++++++++++++++++++ >> include/uapi/linux/kvm.h | 3 +++ >> 2 files changed, 26 insertions(+) >> >> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >> index 925c3e29cad3..741588f27ebc 100644 >> --- a/arch/x86/kvm/x86.c >> +++ b/arch/x86/kvm/x86.c >> @@ -4033,6 +4033,29 @@ long kvm_arch_vm_ioctl(struct file *filp, >> } u; >> >> switch (ioctl) { >> + case KVM_GET_MICROCODE_VERSION: { >> + r = -EFAULT; >> + if (copy_to_user(argp, >> + &kvm->arch.microcode_version, >> + sizeof(kvm->arch.microcode_version))) >> + goto out; >> + break; >> + } >> + case KVM_SET_MICROCODE_VERSION: { >> + u32 microcode_version; >> + >> + r = -EFAULT; >> + if (copy_from_user(µcode_version, >> + argp, >> + sizeof(microcode_version))) >> + goto out; >> + r = -EINVAL; >> + if (!microcode_version) >> + goto out; >> + kvm->arch.microcode_version = microcode_version; >> + r = 0; >> + break; >> + } > > Also, there's no need to define new ioctls, instead you can just place > it in the vcpu and use KVM_GET_MSR/KVM_SET_MSR. I'd agree that's > slightly less polished, but it matches what we do already for e.g. > nested VMX model specific registers. And it spares you for writing the > documentation that you didn't include in this patch. :) > > Paolo I wanted to do the work once rather than doing it per vCPU but using KVM_{GET|SET}_MSR and extending the list of MSRs that userspace can save/restore is certainly doable. I'll look into that and post a v2. Filippo Amazon Development Center Germany GmbH Berlin - Dresden - Aachen main office: Krausenstr. 38, 10117 Berlin Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger Ust-ID: DE289237879 Eingetragen am Amtsgericht Charlottenburg HRB 149173 B