Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3430694iog; Mon, 27 Jun 2022 16:14:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1st/BlZ0NJ4WVTcwlEZK1fZnXAIC57ZWjMTn9WzCiMANaUlydu2YgCM++aO7AET6/yyRdrO X-Received: by 2002:a17:902:cecc:b0:16a:416c:3d14 with SMTP id d12-20020a170902cecc00b0016a416c3d14mr563803plg.73.1656371654484; Mon, 27 Jun 2022 16:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656371654; cv=none; d=google.com; s=arc-20160816; b=q0AYIldq/8YOoz/LK+WnWwehjgaR//42WeAghhJYON1ymqIzRh3Ip8HiUctF180yYr jhuPCv6FjsPwIIcF8jsrArI4YWLvLO7Qv0hTOwyP6ioBg/X4uA0xNBbf9wUwd/QKQ1EX mEMz86WwLF0xH/KsFAZ9VXKGkytDr108uXXWRyhynw5/U8+Pf5+3f3YuF+u+yt1iBnbP AEqJSmgCJb2HPsfPtJ2UTwKxFbIbcsGQk6WZZMpWvFcDMmy/L6/tZsR9AnaP6kIEcUQh izEQ0jJNxTrmhUgycjiElFdPEW0Ue+H1YnCTL8w9UafFhR4Or+fhZ3KmyvNRLo/KXRjx Aakg== 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=GT462jkS5PNiKwn3sOakFCAvR69/dn9vgeTiffy5Ay4=; b=0azmaEkFEWn7ee2h9jh4ArXgXVuLXuVoYdTJSt9B1lWZeDQfCb9vLhRa1WYdrTTtcc YouGgH01O0HdHXJW87NoFLJUvW1veyF35+5iL+1dzS4kK2h3DNkRDOQVwrH4P4xKa4n0 NQ52nY2JH7yeyHAswV6aOEMOgX2BrqXppbdhtBIovaogIBaOn2TOGQbJeU/9vzDL807q XxhonSLBuNc6hsdlIKMjGICqwKgcoiWLdyXdmYovZItk1hpuMk8GOXbQg/Q/bxNxEx6F 2+WbLuh4Wc4GVsYQW3dSgr6nnHFkqLcw+33gA4l6hBz+zjAnM+7QHxRMIlwzapY9CSwe Xc8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PdPSLAui; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j4-20020a633c04000000b0040d4bd5d708si15977724pga.848.2022.06.27.16.14.02; Mon, 27 Jun 2022 16:14:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PdPSLAui; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242383AbiF0WBf (ORCPT + 99 others); Mon, 27 Jun 2022 18:01:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241574AbiF0Vzr (ORCPT ); Mon, 27 Jun 2022 17:55:47 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76EC413EBF; Mon, 27 Jun 2022 14:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656366907; x=1687902907; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kJUKMzgT8SnekcXjC1Tok9JmDm1LOJU3li+cNgtN/N4=; b=PdPSLAuiqWpH4NlYWw8Mvzk+45KLxvudZ3EYB8tAQ3XBEKnCA6rk3xPf 7jyfhy21pYmKKYid3qhKNiYe4xk4QT9ADuI6q9dFZesJyufhJc+mazyA0 VUuMUwB8pMlHn6lVewh4Ya126rTwd7UOC7gx3OKgnlPEPiZ6iVtKIVcIv FjetI46hcBn9Hw/7AY4TKF1k0iDbdADr/pfENTWjyD+rVbPJGpV3pNvc0 Fkh7bToYDpdYT64CHn8MhEtBSN8k6PGVxq+AocnF0J7/2SgXAs7t7R+Ik nWkF5KLazsBOVpW5JnI82ukrUNSinFZYEFGnswo4Xd91bZ0pMGjTtKyo2 w==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="279116132" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="279116132" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:55:00 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="657863714" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:55:00 -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 Subject: [PATCH v7 085/102] KVM: TDX: handle ept violation/misconfig exit Date: Mon, 27 Jun 2022 14:54:17 -0700 Message-Id: <31487c5f0b930f470c552c04b4e0d59dc80f78d6.1656366338.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 X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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: Isaku Yamahata On EPT violation, call a common function, __vmx_handle_ept_violation() to trigger x86 MMU code. On EPT misconfiguration, exit to ring 3 with KVM_EXIT_UNKNOWN. because EPT misconfiguration can't happen as MMIO is trigged by TDG.VP.VMCALL. No point to set a misconfiguration value for the fast path. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/tdx.c | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index e5268bfa8d27..14f65d7b3824 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1191,6 +1191,48 @@ void tdx_deliver_interrupt(struct kvm_lapic *apic, int delivery_mode, __vmx_deliver_posted_interrupt(vcpu, &tdx->pi_desc, vector); } +static int tdx_handle_ept_violation(struct kvm_vcpu *vcpu) +{ + unsigned long exit_qual; + + if (kvm_is_private_gpa(vcpu->kvm, tdexit_gpa(vcpu))) { + /* + * Always treat SEPT violations as write faults. Ignore the + * EXIT_QUALIFICATION reported by TDX-SEAM for SEPT violations. + * TD private pages are always RWX in the SEPT tables, + * i.e. they're always mapped writable. Just as importantly, + * treating SEPT violations as write faults is necessary to + * avoid COW allocations, which will cause TDAUGPAGE failures + * due to aliasing a single HPA to multiple GPAs. + */ +#define TDX_SEPT_VIOLATION_EXIT_QUAL EPT_VIOLATION_ACC_WRITE + exit_qual = TDX_SEPT_VIOLATION_EXIT_QUAL; + } else { + exit_qual = tdexit_exit_qual(vcpu);; + if (exit_qual & EPT_VIOLATION_ACC_INSTR) { + pr_warn("kvm: TDX instr fetch to shared GPA = 0x%lx @ RIP = 0x%lx\n", + tdexit_gpa(vcpu), kvm_rip_read(vcpu)); + vcpu->run->exit_reason = KVM_EXIT_EXCEPTION; + vcpu->run->ex.exception = PF_VECTOR; + vcpu->run->ex.error_code = exit_qual; + return 0; + } + } + + trace_kvm_page_fault(tdexit_gpa(vcpu), exit_qual); + return __vmx_handle_ept_violation(vcpu, tdexit_gpa(vcpu), exit_qual); +} + +static int tdx_handle_ept_misconfig(struct kvm_vcpu *vcpu) +{ + WARN_ON(1); + + vcpu->run->exit_reason = KVM_EXIT_UNKNOWN; + vcpu->run->hw.hardware_exit_reason = EXIT_REASON_EPT_MISCONFIG; + + return 0; +} + int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath) { union tdx_exit_reason exit_reason = to_tdx(vcpu)->exit_reason; @@ -1209,6 +1251,10 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath) WARN_ON_ONCE(fastpath != EXIT_FASTPATH_NONE); switch (exit_reason.basic) { + case EXIT_REASON_EPT_VIOLATION: + return tdx_handle_ept_violation(vcpu); + case EXIT_REASON_EPT_MISCONFIG: + return tdx_handle_ept_misconfig(vcpu); case EXIT_REASON_OTHER_SMI: /* * If reach here, it's not a Machine Check System Management -- 2.25.1