Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2689663rwd; Sun, 28 May 2023 22:16:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ56J9Yy8yW8cuJs1BYyFbrmYFQ7pLD8ICvslK9/sCtwzQG/wW/00Q7bACboriVYuh+2DZBF X-Received: by 2002:a17:903:1112:b0:1ae:10bc:4ae8 with SMTP id n18-20020a170903111200b001ae10bc4ae8mr12189101plh.26.1685337416470; Sun, 28 May 2023 22:16:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685337416; cv=none; d=google.com; s=arc-20160816; b=D2vMiZ4YJ7ogkxj+WtpnhiiS2qqpOKn3IJ1/d7QxeKiB1E5k5dS6S91Lsu6W1Njzx1 ETqYZMzQPHNckS3AhSA22CvTAWIIAZ8TnrrL1+FodllfjhXMemN2JLQI88F14+Ou1cGR yFe2EiBsQcBWSfmEMX7EprSC9EcYAraJK55cPDkLoDb/ir05qehju7K2Gw8ZjElUMWAq QwC6TmBo1Q9Qy36qbzBIl+nu3AbmfSHj2j+z528CdfnjUG5AEtHISDxMBSdzNzrMRVk0 DbsEzr+enY7BTGOcpd8sYqboZx5pblRdMM3GmU1zfDjUli4E5aGt0d+By4JfN2ranOK6 BVkA== 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=I5iEBeMg/sZhgzm5jT/tltd666Nx5QVqulVENvJDdvU=; b=I4qftTJEhDmlODTLq44WU+z79Eqg0Bi78lyyGYvbkg40pYBk+ZUJlOQPjwC3ngLgAG srvb7ryS05TwX47uvHRpotxDUTmHTS8QYgM4zGJ12KIzt3f65ZNPrTX0XUQTcZmvOGDF yTU1LdVWvjffT6EUIMF1HGGtgikQncQifgoFKpIblZ1nQ44Gv0YBrPIYPvowhZzdzcB3 uoqmbM1mXcP8L7k+2cx3RF2BBhyVfuGmao3p60LvWbhumfCj0D8vaYvCM+vMrIX1vLHc t9ttWgGs2qeVa1B11DMmSx+fzK23k9shAafkLAF8NSGB3lYeUYg9+cqknhY+kTJvOJWm hlYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mA0+htex; 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 z8-20020a1709028f8800b001a6f0eab385si9018550plo.55.2023.05.28.22.16.45; Sun, 28 May 2023 22:16:56 -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=mA0+htex; 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 S232329AbjE2EeU (ORCPT + 99 others); Mon, 29 May 2023 00:34:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232322AbjE2E3u (ORCPT ); Mon, 29 May 2023 00:29:50 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89CD61BE2; Sun, 28 May 2023 21:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685334353; x=1716870353; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EQuWMKSt42MTq92WeWb/gwhuPct4CYbpjDth938SXSg=; b=mA0+htexRxH7litFqeZSAhvYSwfIZ2o+uww6SHYHUf5HQvgtXknPePNE sn4sfHrgBWEgEKlIFOno8W4FIYJSk3npS8XD0JXxx9uSYoa6aW3njxTFr 0e7Z8tNX7tDRrCyLhFkLbFU4lJeLAl+4YyMLpxGoAvuheiHUuk20hApgQ +Dp235irWMP5mDqdMQFvGDk9v18EbkiIffV/X99zBtVooDvaakuhHCpUm SnY3iihYQY/PbZSnRU3UoBhBR1jfUgIHWy0wLckkhvVwGGToJMuRkAh5Q Y8V3syBvDd8MmV72H7F0act8ZNB3nSkdKNyyuHnwmaFs6aw5uibVYPS3r Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="334966267" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="334966267" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="775784528" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="775784528" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:36 -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 , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com Subject: [PATCH v14 086/113] KVM: TDX: handle ept violation/misconfig exit Date: Sun, 28 May 2023 21:20:08 -0700 Message-Id: <20416a52a0e54f3bf0dd05b5758373f540899197.1685333728.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=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 c3cb65301158..f8adea0394d6 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1134,6 +1134,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(vcpu, 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_ONCE(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; @@ -1194,6 +1236,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