Received: by 10.223.185.116 with SMTP id b49csp1250618wrg; Fri, 23 Feb 2018 14:47:23 -0800 (PST) X-Google-Smtp-Source: AH8x226ENNj463we6HGZLps/CeBzzKKb5wF0V+x8/TgIN1BCCVzLshZPFIs7eivSRvOLNh0TBNhR X-Received: by 2002:a17:902:8bc2:: with SMTP id r2-v6mr3062750plo.213.1519426043721; Fri, 23 Feb 2018 14:47:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519426043; cv=none; d=google.com; s=arc-20160816; b=bUrmHvDprUmvkRyv7ULopc2mTKxN/OHm7478kZ5lDh6WcK1J1WIYJVOqm7gR8fJfBH 854w9/f5ed+pyypJ3KatTsczBGIUZCo5zn4bMeXvO/lX1dTcCXgnd7B9e1+t5F0tQTTt w7m5ZuhY3cusOh89c3jx0donAOGtyM85+LSNbWoXPxJ4YWBZGhmMmv8SbFyEBJfwVW5f BzWST0715zOlS610fI/7kHkoGrC9Li6mHLTvdKRqFqs36d+mmZzulyaIxj+Ay8RB49Da gXdytjollzeVrua1Vdp+O3CUN+VIhbpM8n6y0FLao1e+8RmTwjtCUUsDfXdsrsTDADj1 iMLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=yG0yUT76ywOFBB2i76D5D3FauSfcupTMYnfp6I0qadY=; b=SnIFWs9HRjXfK/iQWX3NoPnCBLDYqSAW5LCaBCV4aFPXj8zQJqWJwTPkyqk0Z2Pzp5 BUWyHmexb0+rxIV3W22J3vuzc/Ug+i/H+mJvZrVLyttUggbuouPyXNfrw0s+042ZUOJR ad7e6LcJ2y0fmOkMybdcwVTJuKAJYCQnB5cV7OhycoRIIptTrBjXP0R2CYx/b6/dzz0L bxP6uneOuWQFg7UbDpPmZHGYX4PQpKxFHpkhJNZXNvS0htsT25gkYsgMXAnGQZk9QvD5 QXToKwROaAPSJ1Hxq0T9d76triQNm6sp43e34krg1N3qQKcsGqwU6HXO92MryfWSEICS ii4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a23si2517234pfl.218.2018.02.23.14.47.09; Fri, 23 Feb 2018 14:47:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752333AbeBWWp6 (ORCPT + 99 others); Fri, 23 Feb 2018 17:45:58 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34772 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751907AbeBWWp4 (ORCPT ); Fri, 23 Feb 2018 17:45:56 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D31AB80D2EC8; Fri, 23 Feb 2018 22:45:55 +0000 (UTC) Received: from [10.36.117.249] (ovpn-117-249.ams2.redhat.com [10.36.117.249]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7DFB520A846E; Fri, 23 Feb 2018 22:45:54 +0000 (UTC) Subject: Re: [PATCH v2] KVM: x86: fix backward migration with async_PF To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Wanpeng Li , stable@vger.kernel.org References: <20180201211621.27371-1-rkrcmar@redhat.com> From: Paolo Bonzini Message-ID: <64ee2d55-8a56-bd12-1f4b-9787ab01a93e@redhat.com> Date: Fri, 23 Feb 2018 23:45:53 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180201211621.27371-1-rkrcmar@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 23 Feb 2018 22:45:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 23 Feb 2018 22:45:55 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/02/2018 22:16, Radim Krčmář wrote: > 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: > Signed-off-by: Radim Krčmář > --- > v2: > * added documentation [Paolo] > * retained compatibility recent kernels [Paolo] > --- > 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 dcab6dc11e3b..87a7506f31c2 100644 > --- a/Documentation/virtual/kvm/cpuid.txt > +++ b/Documentation/virtual/kvm/cpuid.txt > @@ -58,6 +58,10 @@ KVM_FEATURE_PV_TLB_FLUSH || 9 || guest checks this feature bit > || || before enabling paravirtualized > || || tlb flush. > ------------------------------------------------------------------------------ > +KVM_FEATURE_ASYNC_PF_VMEXIT || 10 || paravirtualized async PF VM exit > + || || can be enabled by setting bit 2 > + || || when writing to msr 0x4b564d02 > +------------------------------------------------------------------------------ > KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no guest-side > || || per-cpu warps are expected in > || || kvmclock. > diff --git a/Documentation/virtual/kvm/msr.txt b/Documentation/virtual/kvm/msr.txt > index 1ebecc115dc6..f3f0d57ced8e 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 == 0. Bit 2 is 1 if asynchronous page faults > - 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/uapi/asm/kvm_para.h > index 7a2ade4aa235..6cfa9c8cb7d6 100644 > --- a/arch/x86/include/uapi/asm/kvm_para.h > +++ b/arch/x86/include/uapi/asm/kvm_para.h > @@ -26,6 +26,7 @@ > #define KVM_FEATURE_PV_EOI 6 > #define KVM_FEATURE_PV_UNHALT 7 > #define KVM_FEATURE_PV_TLB_FLUSH 9 > +#define KVM_FEATURE_ASYNC_PF_VMEXIT 10 > > /* The last 8 bits are used to indicate how to interpret the flags field > * 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 4e37d1a851a6..971babe964d2 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 |= 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) & 0xffffffff, pa >> 32) < 0) > - wrmsrl(MSR_KVM_ASYNC_PF_EN, pa); > + if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF_VMEXIT)) > + pa |= 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 20e491b94f44..7fc04a176c57 100644 > --- a/arch/x86/kvm/cpuid.c > +++ b/arch/x86/kvm/cpuid.c > @@ -604,7 +604,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, > (1 << KVM_FEATURE_PV_EOI) | > (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT) | > (1 << KVM_FEATURE_PV_UNHALT) | > - (1 << KVM_FEATURE_PV_TLB_FLUSH); > + (1 << KVM_FEATURE_PV_TLB_FLUSH) | > + (1 << KVM_FEATURE_ASYNC_PF_VMEXIT); > > if (sched_info_on()) > entry->eax |= (1 << KVM_FEATURE_STEAL_TIME); > Queued, thanks. Paolo