From patchwork Thu Nov 10 13:28:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Hoo X-Patchwork-Id: 13038790 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF481C4332F for ; Thu, 10 Nov 2022 13:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230163AbiKJN3X (ORCPT ); Thu, 10 Nov 2022 08:29:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230498AbiKJN3T (ORCPT ); Thu, 10 Nov 2022 08:29:19 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CA3D6AEDA for ; Thu, 10 Nov 2022 05:29:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668086955; x=1699622955; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0KX7u92gIiOsZZYKiQHR0uesKuTfCCz/w2WdPjjpW1Y=; b=n45L/DI/o/56pIhEiz86U8elwGH05idCjK5hvEO3faLrDOWYnZOuwPHI lInGXtRBgkqacelainZcrlJC5OUR0dFbO7uHhnXJWgR4Qsq633A0QS7E0 4qngwv8k//SuVLYTJOuSz1eYbFKzrycbdvGuG3cJtjieLwg19ZdZRgFeI Y6LZLdsaXx48lcQ84mo8foKdcIQek9YFYqkNBgRSZ+myw1Ss/0lr5hYoI qPA7leDGdUO6SFvfIh6twbT7/Pa+Osho5xUoQwsxRgqjdK4CYBv15f3jJ tXGfl62hasuO203bTvnlmacpovI+NhE+5xwb7jC6HdzoA3ecm0udz7bDZ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="311306354" X-IronPort-AV: E=Sophos;i="5.96,153,1665471600"; d="scan'208";a="311306354" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 05:29:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="812038348" X-IronPort-AV: E=Sophos;i="5.96,153,1665471600"; d="scan'208";a="812038348" Received: from sqa-gate.sh.intel.com (HELO robert-clx2.tsp.org) ([10.239.48.212]) by orsmga005.jf.intel.com with ESMTP; 10 Nov 2022 05:29:13 -0800 From: Robert Hoo To: pbonzini@redhat.com, seanjc@google.com, kirill.shutemov@linux.intel.com Cc: kvm@vger.kernel.org, Robert Hoo , Jingqi Liu Subject: [PATCH v2 7/9] KVM: x86: When judging setting CR3 valid or not, consider LAM bits Date: Thu, 10 Nov 2022 21:28:46 +0800 Message-Id: <20221110132848.330793-8-robert.hu@linux.intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221110132848.330793-1-robert.hu@linux.intel.com> References: <20221110132848.330793-1-robert.hu@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Before apply to kvm_vcpu_is_illegal_gpa(), clear LAM bits if it's valid. Signed-off-by: Robert Hoo Reviewed-by: Jingqi Liu --- arch/x86/kvm/x86.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index fc1367011fa2..5130142fd66d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1231,6 +1231,14 @@ static void kvm_invalidate_pcid(struct kvm_vcpu *vcpu, unsigned long pcid) kvm_mmu_free_roots(vcpu->kvm, mmu, roots_to_free); } +static bool kvm_is_valid_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) +{ + if (guest_cpuid_has(vcpu, X86_FEATURE_LAM)) + cr3 &= ~(X86_CR3_LAM_U48 | X86_CR3_LAM_U57); + + return kvm_vcpu_is_legal_gpa(vcpu, cr3); +} + int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) { bool skip_tlb_flush = false; @@ -1254,7 +1262,7 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) * stuff CR3, e.g. for RSM emulation, and there is no guarantee that * the current vCPU mode is accurate. */ - if (kvm_vcpu_is_illegal_gpa(vcpu, cr3)) + if (!kvm_is_valid_cr3(vcpu, cr3)) return 1; if (is_pae_paging(vcpu) && !load_pdptrs(vcpu, cr3))