From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752249AbdK0BCt (ORCPT ); Sun, 26 Nov 2017 20:02:49 -0500 Received: from mail-ot0-f194.google.com ([74.125.82.194]:33295 "EHLO mail-ot0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752154AbdK0BCr (ORCPT ); Sun, 26 Nov 2017 20:02:47 -0500 X-Google-Smtp-Source: AGs4zMbxse7vNttKia2MM0rWdNmJZSsM7ETSD6dzfcswVyTXTE0uNl7RenLsxKT8W0pypHcgyMdMKxb8iSAvP06DdMI= MIME-Version: 1.0 In-Reply-To: <1511714482-3273-2-git-send-email-sironi@amazon.de> References: <1511714482-3273-1-git-send-email-sironi@amazon.de> <1511714482-3273-2-git-send-email-sironi@amazon.de> From: Wanpeng Li Date: Mon, 27 Nov 2017 09:02:46 +0800 Message-ID: Subject: Re: [PATCH 2/2] KVM: x86: Allow userspace to define what's the microcode version To: Filippo Sironi Cc: Paolo Bonzini , Radim Krcmar , kvm , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-27 0:41 GMT+08:00 Filippo Sironi : > ... 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. Is there a scenario which needs to refresh the microcode in the guest instead of on the host? Regards, Wanpeng Li > > 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; > + } > case KVM_SET_TSS_ADDR: > r = kvm_vm_ioctl_set_tss_addr(kvm, arg); > break; > diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h > index 282d7613fce8..e11887758e29 100644 > --- a/include/uapi/linux/kvm.h > +++ b/include/uapi/linux/kvm.h > @@ -1192,6 +1192,9 @@ struct kvm_s390_ucas_mapping { > #define KVM_S390_UCAS_UNMAP _IOW(KVMIO, 0x51, struct kvm_s390_ucas_mapping) > #define KVM_S390_VCPU_FAULT _IOW(KVMIO, 0x52, unsigned long) > > +#define KVM_GET_MICROCODE_VERSION _IOR(KVMIO, 0x5e, __u32) > +#define KVM_SET_MICROCODE_VERSION _IOW(KVMIO, 0x5f, __u32) > + > /* Device model IOC */ > #define KVM_CREATE_IRQCHIP _IO(KVMIO, 0x60) > #define KVM_IRQ_LINE _IOW(KVMIO, 0x61, struct kvm_irq_level) > -- > 2.7.4 >