Received: by 10.223.176.5 with SMTP id f5csp544425wra; Fri, 2 Feb 2018 02:04:57 -0800 (PST) X-Google-Smtp-Source: AH8x227gXM87Wnvntq0yjiUrRx3pUVENvp4Ecsmzf+w8L8F/z5S+vyA45SKzEyb3YWV7d+TxEamJ X-Received: by 10.98.156.143 with SMTP id u15mr39270305pfk.170.1517565897393; Fri, 02 Feb 2018 02:04:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517565897; cv=none; d=google.com; s=arc-20160816; b=c7iZ7WI0qF0Y9RyIjsCoMEOozdQWTFF9jVCDbiLnKvPcAVY5jGlQm5D8gAqHe162XU elLj+YM22Rtye10hcSUN6vu3dTNAYjNxH6PLYJKb4/0irl//6uVbQJV37T3j4SCvTlsq oXx9uRe1svP79qsqKu6FCm/vAGExSbs/U4rbzE+V7xo+2qle52Ybhl1RU8/zGDbTNBaN 7ODqLEY7+7mnJnEys8F1kG25to5msC2Q3B4OEqy/EviNQAFKnW9N62GvGIUCvHWBlR6M tgJWy9wZL0doQHtWchyLDFP6hbXRG8PjyfiN4m6Mq6oyaIhYakkOMykZJErARulDk2f1 EBuQ== 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:organization:from:references:cc:to:subject :arc-authentication-results; bh=P12gzHc1Ss2iz431FQMo23T++aFwSfoNSMkuRcx4KkI=; b=lO12nbVkwuP/FxWDc2yo1UnqeCjCO+CBXxyNwKVc/+TrTb4SeEXoZjRazsiQs5Hwyj hDWkbBpFguWPZGr6UIL3tqRVZBYtgIzN94s8IrLFxPZlAVkrkPCcllQOObzFICxQWz+d h0vGnGo9rRF82Phdwt3z+6aiI2gP93YGFa4UsXtpmanHbmJZfUONakFONYDdd0zkvlUA En+hPoGUikZXHyrBNkjaO2cMy8cvJpLV15Vwzo6O7UkQoZhe6M3FxaVVUdBuJ3itBieX ggfO+VdV3F9ambSsJWk/s4tP8PWc1q7v58PinNS7IKVkVspNSupcEfV44/kcfqBecDXB Wypg== 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 d13-v6si1475744pln.747.2018.02.02.02.04.42; Fri, 02 Feb 2018 02:04:57 -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 S1751557AbeBBKEP (ORCPT + 99 others); Fri, 2 Feb 2018 05:04:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39972 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750773AbeBBKEI (ORCPT ); Fri, 2 Feb 2018 05:04:08 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4E333E508; Fri, 2 Feb 2018 10:04:07 +0000 (UTC) Received: from [10.36.118.20] (unknown [10.36.118.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71B827981B; Fri, 2 Feb 2018 10:04:06 +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: Paolo Bonzini , Wanpeng Li , stable@vger.kernel.org References: <20180201211621.27371-1-rkrcmar@redhat.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <956a28c7-bafa-bd57-5566-23ab34cd1e65@redhat.com> Date: Fri, 2 Feb 2018 11:04:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 02 Feb 2018 10:04:07 +0000 (UTC) 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); > Reviewed-by: David Hildenbrand -- Thanks, David / dhildenb