From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk0-f196.google.com ([209.85.220.196]:41895 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751102AbeCIOs4 (ORCPT ); Fri, 9 Mar 2018 09:48:56 -0500 Received: by mail-qk0-f196.google.com with SMTP id w142so3870209qkb.8 for ; Fri, 09 Mar 2018 06:48:55 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <2ad7637d-cbcd-657e-6d6a-833d29797f37@redhat.com> References: <1520601621-8728-1-git-send-email-jinpu.wangl@profitbricks.com> <2ad7637d-cbcd-657e-6d6a-833d29797f37@redhat.com> From: Jinpu Wang Date: Fri, 9 Mar 2018 15:48:34 +0100 Message-ID: Subject: Re: [stable-4.14/4.15] KVM: x86: fix backward migration with async_PF To: Paolo Bonzini Cc: stable , Greg Kroah-Hartman , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: stable-owner@vger.kernel.org List-ID: On Fri, Mar 9, 2018 at 3:43 PM, Paolo Bonzini wrote: > On 09/03/2018 14:20, Jack Wang wrote: >> From: Radim Kr=C4=8Dm=C3=A1=C5=99 >> >> commit fe2a3027e74e40a3ece3a4c1e4e51403090a907a upstream. >> >> Guests on new hypersiors might set KVM_ASYNC_PF_DELIVERY_AS_PF_VMEXIT >> bit when enabling async_PF, but this bit is reserved on old hypervisors, >> which results in a failure upon migration. >> >> To avoid breaking different cases, we are checking for CPUID feature bit >> before enabling the feature and nothing else. >> >> Fixes: 52a5c155cf79 ("KVM: async_pf: Let guest support delivery of async= _pf from guest mode") >> Cc: >> Reviewed-by: Wanpeng Li >> Reviewed-by: David Hildenbrand >> Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 >> Signed-off-by: Paolo Bonzini >> [jwang: port to 4.14] >> Signed-off-by: Jack Wang >> --- >> Documentation/virtual/kvm/cpuid.txt | 4 ++++ >> Documentation/virtual/kvm/msr.txt | 3 ++- >> arch/x86/include/uapi/asm/kvm_para.h | 1 + >> arch/x86/kernel/kvm.c | 8 ++++---- >> arch/x86/kvm/cpuid.c | 3 ++- >> 5 files changed, 13 insertions(+), 6 deletions(-) >> >> diff --git a/Documentation/virtual/kvm/cpuid.txt b/Documentation/virtual= /kvm/cpuid.txt >> index 3c65feb..a81c97a 100644 >> --- a/Documentation/virtual/kvm/cpuid.txt >> +++ b/Documentation/virtual/kvm/cpuid.txt >> @@ -54,6 +54,10 @@ KVM_FEATURE_PV_UNHALT || 7 || guest = checks this feature bit >> || || before enabling paravirt= ualized >> || || spinlock support. >> -----------------------------------------------------------------------= ------- >> +KVM_FEATURE_ASYNC_PF_VMEXIT || 10 || paravirtualized async PF= VM exit >> + || || can be enabled by settin= g bit 2 >> + || || when writing to msr 0x4b= 564d02 >> +-----------------------------------------------------------------------= ------- >> KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no gue= st-side >> || || per-cpu warps are expect= ed in >> || || kvmclock. >> diff --git a/Documentation/virtual/kvm/msr.txt b/Documentation/virtual/k= vm/msr.txt >> index 1ebecc1..f3f0d57 100644 >> --- a/Documentation/virtual/kvm/msr.txt >> +++ b/Documentation/virtual/kvm/msr.txt >> @@ -170,7 +170,8 @@ MSR_KVM_ASYNC_PF_EN: 0x4b564d02 >> when asynchronous page faults are enabled on the vcpu 0 when >> disabled. Bit 1 is 1 if asynchronous page faults can be injected >> when vcpu is in cpl =3D=3D 0. Bit 2 is 1 if asynchronous page faul= ts >> - are delivered to L1 as #PF vmexits. >> + are delivered to L1 as #PF vmexits. Bit 2 can be set only if >> + KVM_FEATURE_ASYNC_PF_VMEXIT is present in CPUID. >> >> First 4 byte of 64 byte memory location will be written to by >> the hypervisor at the time of asynchronous page fault (APF) >> diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uap= i/asm/kvm_para.h >> index 09cc064..989db88 100644 >> --- a/arch/x86/include/uapi/asm/kvm_para.h >> +++ b/arch/x86/include/uapi/asm/kvm_para.h >> @@ -25,6 +25,7 @@ >> #define KVM_FEATURE_STEAL_TIME 5 >> #define KVM_FEATURE_PV_EOI 6 >> #define KVM_FEATURE_PV_UNHALT 7 >> +#define KVM_FEATURE_ASYNC_PF_VMEXIT 10 >> >> /* The last 8 bits are used to indicate how to interpret the flags fiel= d >> * in pvclock structure. If no bits are set, all flags are ignored. >> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c >> index b40ffbf..0a93e83b 100644 >> --- a/arch/x86/kernel/kvm.c >> +++ b/arch/x86/kernel/kvm.c >> @@ -341,10 +341,10 @@ static void kvm_guest_cpu_init(void) >> #endif >> pa |=3D KVM_ASYNC_PF_ENABLED; >> >> - /* Async page fault support for L1 hypervisor is optional = */ >> - if (wrmsr_safe(MSR_KVM_ASYNC_PF_EN, >> - (pa | KVM_ASYNC_PF_DELIVERY_AS_PF_VMEXIT) & 0xffff= ffff, pa >> 32) < 0) >> - wrmsrl(MSR_KVM_ASYNC_PF_EN, pa); >> + if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF_VMEXIT)) >> + pa |=3D KVM_ASYNC_PF_DELIVERY_AS_PF_VMEXIT; >> + >> + wrmsrl(MSR_KVM_ASYNC_PF_EN, pa); >> __this_cpu_write(apf_reason.enabled, 1); >> printk(KERN_INFO"KVM setup async PF for cpu %d\n", >> smp_processor_id()); >> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c >> index 13f5d42..4f544f2 100644 >> --- a/arch/x86/kvm/cpuid.c >> +++ b/arch/x86/kvm/cpuid.c >> @@ -597,7 +597,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_en= try2 *entry, u32 function, >> (1 << KVM_FEATURE_ASYNC_PF) | >> (1 << KVM_FEATURE_PV_EOI) | >> (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT) | >> - (1 << KVM_FEATURE_PV_UNHALT); >> + (1 << KVM_FEATURE_PV_UNHALT) | >> + (1 << KVM_FEATURE_ASYNC_PF_VMEXIT); >> >> if (sched_info_on()) >> entry->eax |=3D (1 << KVM_FEATURE_STEAL_TIME); >> > > Acked-by: Paolo Bonzini > > Thanks Jack! > > Paolo Thanks Paolo! Jack