Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1885452pxv; Fri, 2 Jul 2021 15:09:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8cOqlS5vgD+XVZI0xTXPBU7jldanPhfwYTX5+n/uVR14H11pdluJ0VuWrcnQNJWKQGqD3 X-Received: by 2002:a17:907:97c3:: with SMTP id js3mr2005303ejc.114.1625263742503; Fri, 02 Jul 2021 15:09:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625263742; cv=none; d=google.com; s=arc-20160816; b=YtC7fP8xg6qnCXJK5QQcL+zwCx00muyr051OfBSUP0MOPCkj5Pia04hgKYvtcJRtH6 BRhRV25vf4xRQzWqxK5zwKkzwdUvww8B7gTEU4JJ+vU2DY3MnNzOOU4KZ4QScVgICuIL m0Fw2kLvhHU3IZ+RRfJzyMRTWobTWb7I/c7GYGwtwbxXPG6w5jlz1ZXFvp12uOZDQ6wP Ly9jCF5bZo2UAB0q1eQ47Vb2tKyuNOphS57ZzG3uFw0dTlRE4ExBEXo6I/PQCh2Rk+0b GMoFniauQ313wGo/B/XpyPGbWGhUSj/UC1lQiKDIfTtsW0G0Hz+lzQCMAXBrFa/MEkyi QnBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=dD/Axwfl2WNuwXCSkftcOqwWOfRucXUmADRE5HjXZrg=; b=nwqwFhMb7GV0VOE2LUb7T/t1rb8ppRVU6rmakGQTfDg3wSzxMYWflQ8r5DpRNs7D7b u4I8UC9SGIrqhWtVmpvYjFhQn5maJGvQjs7/iRf1ZqiB0Q578hvNanZh4xW7reqitua+ rNQ5ddbnkiCdZuaUeve9nwbrblic5jkzP3PMOSONZpx5l78OKV2Dijp57teO/cRcAHLD w9D6WVwXCwwgZQYhC3iPRMaWAzIwVi1JXhq0TeckBzuExPEfXt3PBal1tJo47/zfOrDD yH+RlUhx8MQXfTmSoVk7ZMXH2H+a49YGYV46DNr9kBVoR+JQp0vUcnAi76FDJnAlRDvg IfBQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a19si4269216edr.397.2021.07.02.15.08.38; Fri, 02 Jul 2021 15:09:02 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234194AbhGBWJV (ORCPT + 99 others); Fri, 2 Jul 2021 18:09:21 -0400 Received: from mga17.intel.com ([192.55.52.151]:15277 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233283AbhGBWID (ORCPT ); Fri, 2 Jul 2021 18:08:03 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10033"; a="189168379" X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="189168379" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:29 -0700 X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="642814852" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:29 -0700 From: isaku.yamahata@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Sean Christopherson Subject: [RFC PATCH v2 52/69] KVM: VMX: Split out guts of EPT violation to common/exposed function Date: Fri, 2 Jul 2021 15:04:58 -0700 Message-Id: <8e246d479e8986172d19704ef4ef4d2b666d5ac1.1625186503.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/common.h | 29 +++++++++++++++++++++++++++++ arch/x86/kvm/vmx/vmx.c | 33 +++++---------------------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/arch/x86/kvm/vmx/common.h b/arch/x86/kvm/vmx/common.h index 81c73f30d01d..9e5865b05d47 100644 --- a/arch/x86/kvm/vmx/common.h +++ b/arch/x86/kvm/vmx/common.h @@ -5,8 +5,11 @@ #include #include +#include +#include "mmu.h" #include "vmcs.h" +#include "vmx.h" #include "x86.h" extern unsigned long vmx_host_idt_base; @@ -49,4 +52,30 @@ static inline void vmx_handle_external_interrupt_irqoff(struct kvm_vcpu *vcpu, vmx_handle_interrupt_nmi_irqoff(vcpu, gate_offset(desc)); } +static inline int __vmx_handle_ept_violation(struct kvm_vcpu *vcpu, gpa_t gpa, + unsigned long exit_qualification) +{ + u64 error_code; + + /* Is it a read fault? */ + error_code = (exit_qualification & EPT_VIOLATION_ACC_READ) + ? PFERR_USER_MASK : 0; + /* Is it a write fault? */ + error_code |= (exit_qualification & EPT_VIOLATION_ACC_WRITE) + ? PFERR_WRITE_MASK : 0; + /* Is it a fetch fault? */ + error_code |= (exit_qualification & EPT_VIOLATION_ACC_INSTR) + ? PFERR_FETCH_MASK : 0; + /* ept page table entry is present? */ + error_code |= (exit_qualification & + (EPT_VIOLATION_READABLE | EPT_VIOLATION_WRITABLE | + EPT_VIOLATION_EXECUTABLE)) + ? PFERR_PRESENT_MASK : 0; + + error_code |= (exit_qualification & EPT_VIOLATION_GVA_TRANSLATED) != 0 ? + PFERR_GUEST_FINAL_MASK : PFERR_GUEST_PAGE_MASK; + + return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0); +} + #endif /* __KVM_X86_VMX_COMMON_H */ diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 452d4d1400db..8a104a54121b 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5328,11 +5328,10 @@ static int handle_task_switch(struct kvm_vcpu *vcpu) static int handle_ept_violation(struct kvm_vcpu *vcpu) { - unsigned long exit_qualification; - gpa_t gpa; - u64 error_code; + unsigned long exit_qualification = vmx_get_exit_qual(vcpu); + gpa_t gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); - exit_qualification = vmx_get_exit_qual(vcpu); + trace_kvm_page_fault(gpa, exit_qualification); /* * EPT violation happened while executing iret from NMI, @@ -5341,31 +5340,9 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) * AAK134, BY25. */ if (!(to_vmx(vcpu)->idt_vectoring_info & VECTORING_INFO_VALID_MASK) && - enable_vnmi && - (exit_qualification & INTR_INFO_UNBLOCK_NMI)) + enable_vnmi && (exit_qualification & INTR_INFO_UNBLOCK_NMI)) vmcs_set_bits(GUEST_INTERRUPTIBILITY_INFO, GUEST_INTR_STATE_NMI); - gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); - trace_kvm_page_fault(gpa, exit_qualification); - - /* Is it a read fault? */ - error_code = (exit_qualification & EPT_VIOLATION_ACC_READ) - ? PFERR_USER_MASK : 0; - /* Is it a write fault? */ - error_code |= (exit_qualification & EPT_VIOLATION_ACC_WRITE) - ? PFERR_WRITE_MASK : 0; - /* Is it a fetch fault? */ - error_code |= (exit_qualification & EPT_VIOLATION_ACC_INSTR) - ? PFERR_FETCH_MASK : 0; - /* ept page table entry is present? */ - error_code |= (exit_qualification & - (EPT_VIOLATION_READABLE | EPT_VIOLATION_WRITABLE | - EPT_VIOLATION_EXECUTABLE)) - ? PFERR_PRESENT_MASK : 0; - - error_code |= (exit_qualification & EPT_VIOLATION_GVA_TRANSLATED) != 0 ? - PFERR_GUEST_FINAL_MASK : PFERR_GUEST_PAGE_MASK; - vcpu->arch.exit_qualification = exit_qualification; /* @@ -5379,7 +5356,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) if (unlikely(allow_smaller_maxphyaddr && kvm_vcpu_is_illegal_gpa(vcpu, gpa))) return kvm_emulate_instruction(vcpu, 0); - return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0); + return __vmx_handle_ept_violation(vcpu, gpa, exit_qualification); } static int handle_ept_misconfig(struct kvm_vcpu *vcpu) -- 2.25.1