Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1481667pxk; Fri, 2 Oct 2020 10:32:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZ2M6LZtyrdcLBqBIoBi1R4VeTdH3n5YweAwutBx3SmEjI8r4JjgFdqpfYJXlPcscq50VR X-Received: by 2002:a17:906:2dd:: with SMTP id 29mr3516198ejk.31.1601659944843; Fri, 02 Oct 2020 10:32:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601659944; cv=none; d=google.com; s=arc-20160816; b=cq3YDc9k+RBFFiNOdeOlMZtYu2LunVYs5KLi7a2u7D3SFj6rbNo9LQjLJWdXFbyjcY 6xR3yu48XI4I8bnSo2PIeX3GMaU5B2Xuh2OBE/8OdaxL0LkBU30dvCqWIj6yEe3koqqf PcxVdGtyAaRR4cMq/JpQoYpQJ8lXV+vAeuoCnmU1DZdAiAqbiq9A0Q4yEfcNtUwboP97 MJckClOBfS63AXBoquvL0zb/RfRj0V9JH4kVbaE0vsED9JuO4kKnOU3LZhT8ERwlcBAP RvlLDUudZ9m4PrzPbDDMAxk8T/4skM/nJXd7EoyHruVXMaflW+6PrbmDxN16AQLd3Kjj DEMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RQsg6ahWktyPvURwiyd1VgLtMh0Q43RTGiqOocC5R54=; b=T7CzlfP1WlgDMVRw/31XaRMWMAYpNORtUgg6+j9gX4GsoqsHPZlxRi9O3UPr5XcET5 IhhIdwmR6xd//x7W/YH4GCZuLu/YSubDTitHnB1ARQGPAYQkGqYLJhUAf7mxW+pJ+BPU iK5P0F8K+jGjN9Bj63U1FjEiwkeHCzA/4ZMfMN2EohxtGNxJpyrNN7QGZsCV2P3GinJs sU1oPNaHJBO/9Dk2llVNozpuWEOdyTMnNALnDNMZGHwUr60kuWR9pyrwGhUa7Ra8vU6P qCX4yi71eu8WgAeHLu6/uYU6P5CoxF0vQx4sbRQIaqs0FiczD36dqdOiS4mPliEA5uXP FoBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UO94HG6O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cd7si1562169ejb.433.2020.10.02.10.32.01; Fri, 02 Oct 2020 10:32:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UO94HG6O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388293AbgJBR3I (ORCPT + 99 others); Fri, 2 Oct 2020 13:29:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388219AbgJBR3F (ORCPT ); Fri, 2 Oct 2020 13:29:05 -0400 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95473C0613D0 for ; Fri, 2 Oct 2020 10:29:05 -0700 (PDT) Received: by mail-ot1-x342.google.com with SMTP id m12so2139070otr.0 for ; Fri, 02 Oct 2020 10:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RQsg6ahWktyPvURwiyd1VgLtMh0Q43RTGiqOocC5R54=; b=UO94HG6O0IX1kgvtQIyBLRmnKZ0ICSk8JVo/6rlaOMXI6yCPT+tEy43d5N5dN6RMUu qHNIfX1buI6VYT5mzWWRXhrkrkj7bUZ+hUM/ua2NafAM7SWj08OhoQ7wQ1ueK+5IqAkM sNCGxBatn9yvcPEuKxA+Pve+PTi6Vi1mFZnkwiSQYNmHbrRQ13vF8YFoSA0/Lgfpwmu1 zhVXPYiIUavX0O2QT2OgjblVpc713KBNN8kE+LdGbzN5mox0j1JgvbsndHaXkEfDAVVr 1I0Lcf8nmC2FfQBXdeV5JJ9t2sxYmmh/36bupWw2UhNHB3RgKF2i6VIxidXMdLy8dBEh hrCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RQsg6ahWktyPvURwiyd1VgLtMh0Q43RTGiqOocC5R54=; b=hU2z+eP5SBwO3R43dxxGz+/uky/E65g2MiD5rlZ3etjIZBr7rzHGnLejhbd81oY8Ov AtGf16KvwaeKkd04MasmH4pJxi2daKTpUUWrhMyz5GtS0AHuX64dgC3vOt8oVZk6U29h 7mOaVCP3HHSj6tFK6gacBan4OcKuD0vgDlpgOXZ6gIK4jlBPX34m6OFHRu6E4cR1GhQP Ox6bND9uqig107aawLE21O/P4cCabzkpnarHosm0+R0BfzxuD+G4hFbb15gsnIoMTUoM NTAFP/LVRPaaz9vlRTcDOtDGQnJbkrDli5QFBcSSpFSPLgirUnW+C7ioneLtHpRJag+n ln7Q== X-Gm-Message-State: AOAM533XisG2JTuQg2gYFRcpmidPI+QHSEjJGQZ6ZP0tRIuNNPzFWx3B 8fCxzupP/gJeILWLOxFR8o3dVZF9LoYc4vGq0c5ofA== X-Received: by 2002:a05:6830:2104:: with SMTP id i4mr2576095otc.266.1601659744837; Fri, 02 Oct 2020 10:29:04 -0700 (PDT) MIME-Version: 1.0 References: <20200903141122.72908-1-mgamal@redhat.com> <1f42d8f084083cdf6933977eafbb31741080f7eb.camel@redhat.com> <2063b592f82f680edf61dad575f7c092d11d8ba3.camel@redhat.com> In-Reply-To: From: Naresh Kamboju Date: Fri, 2 Oct 2020 22:58:53 +0530 Message-ID: Subject: Re: [PATCH] KVM: x86: VMX: Make smaller physical guest address space support user-configurable To: Paolo Bonzini Cc: Qian Cai , Mohammed Gamal , kvm list , open list , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Stephen Rothwell , Linux-Next Mailing List , Linus Torvalds , lkft-triage@lists.linaro.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Paolo, Thanks for the patch. On Tue, 29 Sep 2020 at 20:17, Paolo Bonzini wrote: > > On 29/09/20 15:39, Qian Cai wrote: > > On Tue, 2020-09-29 at 14:26 +0200, Paolo Bonzini wrote: > >> On 29/09/20 13:59, Qian Cai wrote: > >>> WARN_ON_ONCE(!allow_smaller_maxphyaddr); > >>> > >>> I noticed the origin patch did not have this WARN_ON_ONCE(), but the > >>> mainline > >>> commit b96e6506c2ea ("KVM: x86: VMX: Make smaller physical guest address > >>> space > >>> support user-configurable") does have it for some reasons. > >> > >> Because that part of the code should not be reached. The exception > >> bitmap is set up with > >> > >> if (!vmx_need_pf_intercept(vcpu)) > >> eb &= ~(1u << PF_VECTOR); > >> > >> where > >> > >> static inline bool vmx_need_pf_intercept(struct kvm_vcpu *vcpu) > >> { > >> if (!enable_ept) > >> return true; > >> > >> return allow_smaller_maxphyaddr && > >> cpuid_maxphyaddr(vcpu) < boot_cpu_data.x86_phys_bits; > >> } > >> > >> We shouldn't get here if "enable_ept && !allow_smaller_maxphyaddr", > >> which implies vmx_need_pf_intercept(vcpu) == false. So the warning is > >> genuine; I've sent a patch. > > > > Care to provide a link to the patch? Just curious. > > > > Ok, I haven't sent it yet. :) But here it is: > > commit 608e2791d7353e7d777bf32038ca3e7d548155a4 (HEAD -> kvm-master) > Author: Paolo Bonzini > Date: Tue Sep 29 08:31:32 2020 -0400 > > KVM: VMX: update PFEC_MASK/PFEC_MATCH together with PF intercept > > The PFEC_MASK and PFEC_MATCH fields in the VMCS reverse the meaning of > the #PF intercept bit in the exception bitmap when they do not match. > This means that, if PFEC_MASK and/or PFEC_MATCH are set, the > hypervisor can get a vmexit for #PF exceptions even when the > corresponding bit is clear in the exception bitmap. > > This is unexpected and is promptly reported as a WARN_ON_ONCE. > To fix it, reset PFEC_MASK and PFEC_MATCH when the #PF intercept > is disabled (as is common with enable_ept && !allow_smaller_maxphyaddr). I have tested this patch on an x86_64 machine and the reported issue is gone. > > Reported-by: Qian Cai > Signed-off-by: Paolo Bonzini Reported-by: Naresh Kamboju Tested-by: Naresh Kamboju > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index f0384e93548a..f4e9c310032a 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -794,6 +794,18 @@ void update_exception_bitmap(struct kvm_vcpu *vcpu) > */ > if (is_guest_mode(vcpu)) > eb |= get_vmcs12(vcpu)->exception_bitmap; > + else { > + /* > + * If EPT is enabled, #PF is only trapped if MAXPHYADDR is mismatched > + * between guest and host. In that case we only care about present > + * faults. For vmcs02, however, PFEC_MASK and PFEC_MATCH are set in > + * prepare_vmcs02_rare. > + */ > + bool selective_pf_trap = enable_ept && (eb & (1u << PF_VECTOR)); > + int mask = selective_pf_trap ? PFERR_PRESENT_MASK : 0; > + vmcs_write32(PAGE_FAULT_ERROR_CODE_MASK, mask); > + vmcs_write32(PAGE_FAULT_ERROR_CODE_MATCH, mask); > + } > > vmcs_write32(EXCEPTION_BITMAP, eb); > } > @@ -4355,16 +4367,6 @@ static void init_vmcs(struct vcpu_vmx *vmx) > vmx->pt_desc.guest.output_mask = 0x7F; > vmcs_write64(GUEST_IA32_RTIT_CTL, 0); > } > - > - /* > - * If EPT is enabled, #PF is only trapped if MAXPHYADDR is mismatched > - * between guest and host. In that case we only care about present > - * faults. > - */ > - if (enable_ept) { > - vmcs_write32(PAGE_FAULT_ERROR_CODE_MASK, PFERR_PRESENT_MASK); > - vmcs_write32(PAGE_FAULT_ERROR_CODE_MATCH, PFERR_PRESENT_MASK); > - } > } > > static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) > test log link https://lkft.validation.linaro.org/scheduler/job/1813223 - Naresh