Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1177569rbb; Mon, 26 Feb 2024 00:47:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXzbapeu5MYne0EFEyr565hhqwviIE69LGkWeKM2lUumkHNFmmeISX0kvUvVsBS0CUEWY6KMQruHwVQmjlw9xF0DXRGKhONLVr4+dXBUQ== X-Google-Smtp-Source: AGHT+IGWWEu/b97FjdAu3thAHrvLSkEZqbjkq+jhG/a0nJmUS6K/dCfhDa33zlMmYkFrvqMB0R46 X-Received: by 2002:a62:5802:0:b0:6e4:c56f:aa65 with SMTP id m2-20020a625802000000b006e4c56faa65mr6369756pfb.19.1708937228865; Mon, 26 Feb 2024 00:47:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708937228; cv=pass; d=google.com; s=arc-20160816; b=JYZRrUZgeiWmWketzuH5pxNKNo+UO4xANVv+SvuWE5z5J6b3aL5e8bFGUjgYqgfubm i1BdOVWBuEy7Kx7Naj2qo9PUfM/U+SDTUjQXLSnFCtLhD93o95kKvlG1kJ5j1ioQfP67 21mGXapynI5AjQ/lh7+Zw+DekIz8uxcOkQrG8jwwUqJ6pD8yaa+6jvB4vKzisAy9YmLd mfzgyz9axSPYVfB4OtRIXa7YbneFP17DnnFUD/kXcdbTp15+ZwLtU07JeqsoCed7yTBi GZtYundDhn7BuH6yfg2fe7XyR+NIZuqB26XVsPET/qtKYtynNiEL1esX1qF9DsK7DRer oT3A== 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=mI7Y6ck9RTLNflywhZS3gkrGjhajzhX5bVJ2kmZEtbc=; fh=UknxTeocRKsk5nERx2/bB41fA0/K5tWK1mFTFyX1mUc=; b=u54l4j3mpiQXK0NPxOgEHNoUIoUoSD/+yYyMPt/52dgVwntKi9MAvQAiS68l6KzJDR NQGycghsQyOp18A7QIfN97uGd8hr//pCiBAkVuPHMDbvhnbtpx+SIYxmgE30JtWcPY+z MXl4Owoy+Z+IudV/uUyRIkoP+a15ecLBvZRfL6wFFRxRFxpJHRngHXz3LD0sAF9rkSSR BMh/5+D+cT9KwqmOjjAT1hTIzRzaOS02KxuLMGmofhPlOf0gFKYeOHga+oYm/2E0RElZ RVs/VgYKK71VcHGD/IKOeM6RTUSNaq0hdAqcbE4pJ+xekLfWk22KvURHV6b+mYUr27wU Fv7A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="PiSERU1/"; 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-80821-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80821-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id f4-20020a056a00238400b006e489241e68si3406992pfc.298.2024.02.26.00.47.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 00:47:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80821-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="PiSERU1/"; 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-80821-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80821-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 8B7B0281DA2 for ; Mon, 26 Feb 2024 08:47:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6AEB561698; Mon, 26 Feb 2024 08:28:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="PiSERU1/" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 D236160871; Mon, 26 Feb 2024 08:28:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936104; cv=none; b=PgXssba69nVAdtcPB+bGbZPWIW4FHIa+u3+VfPs44C5SauM8IJ5nP6sVhpDL4uiLvRxJuZirvHaSxT2lp+tGdGev6V9VrQK0caV0kTbexi72UItj1tqThR6/ImxsA9gqkRfTJO2iK0o7i/VQ/1oOnEMbI8PoJ5q4M5nsM8kV7Zc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936104; c=relaxed/simple; bh=vYP5GsQKWqAKjPBvrpOeKL1gl92Mny66GvJCS5Chluo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Zfre4WhHYivrqOy/USY3hDWB8oIr6TPA/NqZB4LDCLn+1dae35SFV166KLbM2IzeNQP0y4/jXvsGQmnmSpaqu16sBfGeZMuuorm7U3yt6IMZTuExFFNA70tJx2kwBvNYahE0KUvkiFTxeDjIm+bRgqNXngHXFfPPMqpaFB/YvX8= 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=PiSERU1/; arc=none smtp.client-ip=198.175.65.19 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=1708936103; x=1740472103; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vYP5GsQKWqAKjPBvrpOeKL1gl92Mny66GvJCS5Chluo=; b=PiSERU1/MQ2oIszD7CPYfDdVbAVu1iI0YNHMfmvKFFACKI7knf1AeCRg Ak0LfXH2NZvr44m0lR4tyyIe9budvuqZuLjvKVts/315TD58iGN+f2R60 2fSYQUIOI8LQ4UqdLGIuCvxC98PSDLVE+wZfAruVy54G8alLkLxsWO9aS z2SEmN7LCmQto3MY6SfsVA/HPHEt4/3xYhRTg5c6v5GN4bk3SIBOVhvCD SI4c7DfRBhaVfp8XG/U7F1OmUsQppgC9ovkRul6Cp5S5ESoicEaDYD3he hga55+Vzbb4pBBf4005SJk1kw41a9SajUz/Q7bc0tEaC7mMBeVqPDioQM w==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="3069443" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="3069443" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="11272333" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:22 -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 , Binbin Wu Subject: [PATCH v19 065/130] KVM: VMX: Split out guts of EPT violation to common/exposed function Date: Mon, 26 Feb 2024 00:26:07 -0800 Message-Id: <527220db2f197df57e67fa291272347e24a04386.1708933498.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 Reviewed-by: Binbin Wu --- 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 6fe895bd7807..162bb134aae6 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