Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4792787iob; Mon, 9 May 2022 01:35:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCzTBF/T85pChNQoISoBVlKRRZvSvOyrahPntoAd7TjwEfAE6tJYzQ6ckASQ12RuJRIzGY X-Received: by 2002:a63:24d:0:b0:3c2:2f74:2ddb with SMTP id 74-20020a63024d000000b003c22f742ddbmr12577457pgc.83.1652085309258; Mon, 09 May 2022 01:35:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652085309; cv=none; d=google.com; s=arc-20160816; b=E90U6Qxcv5OlYnxorEEqPH6G3zmQgwyflR0zrq6VV+WNEp0kOu8bMVLI1uZ3Z/51RU qCJZM3aBw8Nji8EYe1lfnV7Aw9rv+Yor/pUfTf/IvNVDAvABm1KyOM4rojqeSQC7/ol7 BY4oG5f28ThdONwQ0v8vKd87pGFDe2oqVrOlXAboQTEFPHZk3gWXh6hak/zut+rk9Ifm 8AjPf34JKK1pfagyohZyxn6E/TXjZGY4Pi3BGrc6LBqHQSbP5zHW4IoWMSEkGoXtUW9J 4cS3jZ5u4rqjx0DBZ22qKEnCfLQCE4I5f5YPj6r7GrsibFLhaJ9z8EEdfGBNE7sKg4lQ 3I3w== 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 :dkim-signature; bh=5CzVRobu7eg3oewcPwsSXInFvLXC6oSWOhDWmSnTbeQ=; b=TX3Fy0OxLa661odOwFUHo2B8DhISSgKtJmTzNRM7/208Dz8FzqT7tx0VvRbPUm5ISJ 5azI/fxwAym/PDs/4DiZu+uxWltAMQkYYEmyCeW5a/VJ1XCdxJX0QThsKzkCaAb2ohNk SiZySpz+blDa8eKmXZta3+BHF3phhknAimGg2Z8xQuekTdLVlw2CzTCCOpX8Dzdr4KSM TdEh4FfywXI81NNpKdqTiXkQ3Xk97lXgmFf3Y2hIYVWugkEnkftBgvXAIpiXCY0Zs27Q geHtKIcraATs1qaQ0DCdi8VapPZsyoFNlOO+1imb6jMfnoIcrB/pCbaHEtjEXg3sSwb0 SN5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=m2FidzIG; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id f7-20020a17090274c700b0015866d0026bsi9703910plt.575.2022.05.09.01.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 01:35:09 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=m2FidzIG; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D7E4B1A4485; Mon, 9 May 2022 01:18:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384131AbiEES14 (ORCPT + 99 others); Thu, 5 May 2022 14:27:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383337AbiEESTr (ORCPT ); Thu, 5 May 2022 14:19:47 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 816B518E10; Thu, 5 May 2022 11:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651774563; x=1683310563; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eYmfvBfYMquS6jwfZ3SHdNcbFWex4Khf+QLEW+sIm5g=; b=m2FidzIGh0E1vo+TmnE8MhYqTXGYV7tSTmm7N5nP845K+TUvkW4paaON b/FUnV7ZXGR8Ppcwq7IxxiGx4izRcoT2HqI5uSQOcfnQmtCCiAgAacTNq MILzO9iG2bwsRObl6miSFl9JXSlwYJe5qq3YCpSMmnQUzCD0SlM4UhAeb tBx+QGBTgeErrgt82xViBn4Hdak22ri5o4wY/FlMNjT3UoWJKFgr4lq72 K9Fug5XAwrJCTbvaHM6Pdh0+P/5/L09GDM89N5KT+eF+af8606Bv2Fju2 q9FCLEt8U/mG36cmBufD2W1GM5oyI1BDtl8brV2m1tpb4lZ/5URKL9gBL A==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="248742041" X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="248742041" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 11:15:48 -0700 X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="665083321" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 11:15:47 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar Subject: [RFC PATCH v6 051/104] KVM: VMX: Split out guts of EPT violation to common/exposed function Date: Thu, 5 May 2022 11:14:45 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson The difference of TDX EPT violation is how to retrieve information, GPA, and exit qualification. To share the code to handle EPT violation, split out the guts of EPT violation handler so that VMX/TDX exit handler can call it after retrieving GPA and exit qualification. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata Reviewed-by: Paolo Bonzini --- arch/x86/kvm/vmx/common.h | 33 +++++++++++++++++++++++++++++++++ arch/x86/kvm/vmx/vmx.c | 32 ++++++-------------------------- 2 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 arch/x86/kvm/vmx/common.h diff --git a/arch/x86/kvm/vmx/common.h b/arch/x86/kvm/vmx/common.h new file mode 100644 index 000000000000..235908f3e044 --- /dev/null +++ b/arch/x86/kvm/vmx/common.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __KVM_X86_VMX_COMMON_H +#define __KVM_X86_VMX_COMMON_H + +#include + +#include "mmu.h" + +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_RWX_MASK) + ? 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 60dedae31426..1a2e8d195891 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -50,6 +50,7 @@ #include #include "capabilities.h" +#include "common.h" #include "cpuid.h" #include "evmcs.h" #include "hyperv.h" @@ -5513,11 +5514,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, @@ -5526,29 +5526,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_RWX_MASK) - ? 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; /* @@ -5562,7 +5542,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