Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp165853rdb; Mon, 22 Jan 2024 16:04:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHOIcUV2qstgltVuh29kXVEM2xzZWTCILW5FrNP5gSy1NcTY5FiMTukFGKmteCk5NWflljL X-Received: by 2002:a05:6a20:3ba1:b0:19b:7e1b:d8e1 with SMTP id b33-20020a056a203ba100b0019b7e1bd8e1mr2110290pzh.65.1705968277581; Mon, 22 Jan 2024 16:04:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705968277; cv=pass; d=google.com; s=arc-20160816; b=DiChCzKemIQfP+1rL097W1DE4KLnK/1Gi5QeqZDVN28/x1dQD8Q67Ws2PBy+2d5yFa lRqNuxwmCgvvdJCJiWjFap2WcQvhTSP+/m8u0GWcZY2/yudrZltHXwVATL0QSI1Bu8C/ Mrs+Wt/3IOJRvh2ET+S920Rp2sD1Y9K2yJ7pOZC31LTy0g1svYYqTNeQSBw/3VIhdpeY SeCGjPxScOSpxavNBQzHaACy1UHebVSgqXPuEnwD3l44TDrLJHz396kWuOQi4XTQFN4h kLeMpGtPotLg7FELLRdBn5SPN3cU2YJFDBy3eBRkISMkP2Tf8rA5P9udgb6hUiAoWfcU ZTiA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zka2jbywC60jjwxU7kShPzYntolXTRPZ3nW67gHV+Gs=; fh=ka1BjeomumTXa1Vhgkzg2yK2f13tB8VguFI2e9zPJ3c=; b=D084JZSt/3h7QGJqJEBBw4Fh4y7V5Zf0h5gqnfAve7jp0FvGe+LQ+yw4gVg4p9tY3N NzC0mTk3u+u29En32XB3SncPK1GDWzICIdEOqwwrT3JZjCFwtZEhIf1AGZlWZewsjIxn C8xW1dfmYc/ddv+WveCzQo7oXtGjP4MOxHu/cUiLTol08v6Wcmjy4ZoTrmkD99mEYLDW seGq0vxM7y3ySnEEKkmU6/cf2xtDePvnVfY//ZjH8VUuR7bFeK9Hp7fS0ygti+bRa9sr cX8jM+Wm6PM9Z4GlmBm954w/A8AOW8sfCjLQvIQpuQCbo0/6gldawcJE1FMOfsflXL2z SH7g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BsiFvztl; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34366-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34366-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i70-20020a638749000000b005ce0166ee12si8853245pge.661.2024.01.22.16.04.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:04:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34366-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BsiFvztl; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34366-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34366-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 77C9D28B632 for ; Tue, 23 Jan 2024 00:03:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 56EF761688; Mon, 22 Jan 2024 23:55:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BsiFvztl" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E32860DE2; Mon, 22 Jan 2024 23:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967745; cv=none; b=UCTGlsQQVwmAfcgCgHZ6Zws/UUwWxvOkTzfwARQ0x7SEFNjzOvMQxyIMa2bm5eidTV2xUGVYmcjyXuTFznQYe4JVRkF4Try9ZNLBvO156/oQqt4h7jHRchGWfs11k21z4XRd5TzumeZZoxDmqTzhX2XK8NqNbPBmCxkIoz8/ONU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967745; c=relaxed/simple; bh=okbuOt5t7tIRDQS7vcT+s6srZiBX/84k2CBwwGBVL70=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DxJ94sJDbBfU9E9FrlTshdD6g+mTD5xG9MNxhKuJx3GmwQBgvzXCbG36FzkiqMtA39ed2VAQE9NymxX/qrMgUjJeRl2CJ+bY49QHqRQHpBMyqnFAOftc6bf4u/TgrEB7rIyrqSMm6TkOLL6WNA9WUFd7w5fnpK6jDis7ekEGEpA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=BsiFvztl; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705967744; x=1737503744; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=okbuOt5t7tIRDQS7vcT+s6srZiBX/84k2CBwwGBVL70=; b=BsiFvztlquKpsCceO8y1dUUJ9cfG0Lj37zwfes4lKyleJ7n73Zbt0wp0 Ia/FZqVZaXujEuzNLcPgCtHkTNaKGfQGdRq6tznPsFIPpBGg1j1oU6GOm zfyVGGsqjsR8GC26IiTYehh/JcOhBQNjoNARFSra61IHkqWKbkkU23AFp 9hO+VeVIMv7t8yMLMLOBqVvB1ojtU0qd/E5eEXF5hZy1eManht2pJseLZ R8oSJ0K6sza9Ohi6ifipAjnkAFXMwdTJk5iRLb1/TdMJM9yxdWXv+bL1C J4aMsgYNE56IYbtztdH2xlXgDN38VYv8ZzH2ykBLUIwkYMn8FndS86/Xl w==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="8016412" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="8016412" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="1468159" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:33 -0800 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 , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Sean Christopherson Subject: [PATCH v18 054/121] KVM: VMX: Split out guts of EPT violation to common/exposed function Date: Mon, 22 Jan 2024 15:53:30 -0800 Message-Id: <4aa3aaa6d12640ee9948308116c6f57ad3a0c1ba.1705965635.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Kai Huang --- arch/x86/kvm/vmx/common.h | 33 +++++++++++++++++++++++++++++++++ arch/x86/kvm/vmx/vmx.c | 25 +++---------------------- 2 files changed, 36 insertions(+), 22 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 89f31263fe9c..185e22a2e101 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 "hyperv.h" #include "kvm_onhyperv.h" @@ -5779,11 +5780,8 @@ static int handle_task_switch(struct kvm_vcpu *vcpu) static int handle_ept_violation(struct kvm_vcpu *vcpu) { - unsigned long exit_qualification; + unsigned long exit_qualification = vmx_get_exit_qual(vcpu); gpa_t gpa; - u64 error_code; - - exit_qualification = vmx_get_exit_qual(vcpu); /* * EPT violation happened while executing iret from NMI, @@ -5798,23 +5796,6 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); trace_kvm_page_fault(vcpu, 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; /* @@ -5828,7 +5809,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) if (unlikely(allow_smaller_maxphyaddr && !kvm_vcpu_is_legal_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