Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4633868iob; Sun, 8 May 2022 20:01:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkjSJr2qEIvvknEEpre/dn+fnKMy4QT0Hqcf+2/6JTuaHoXelM69U1R0rarsy6ert7NSx0 X-Received: by 2002:a05:6a00:16c5:b0:505:c572:7c2a with SMTP id l5-20020a056a0016c500b00505c5727c2amr13765312pfc.46.1652065272768; Sun, 08 May 2022 20:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652065272; cv=none; d=google.com; s=arc-20160816; b=IXBPjXCSIcN4AcVv+gGv1YOqOoB6gLWuCLbTBKQr4ovVh1dE0+9xAO9837Y6bHa8Dm DurH1YJVrnBbqgSCq/1OrUhHomLWUvRvfn7kD//L/wlmQyykNsYzCNdvPXUvzS+krxZm WwXkV+2XLsKBmh9jlKowhdRdrN/LCk1r1AYmrknqHicrblvw2e7r+DnuQ4ESCjTTNFW2 dqi/MW2zG/AQCP6M2oTLts4FbohyjIMJIC3rt08xs/+MCRSt6hFMvLEa+MAPD8UzSp5g u+MNIYYNUAoCWYOwaG5+adFY6vJE1YWOaAztoxibtdOyaFdy2DZ9PQZuBj3WDimO9xxl HdQg== 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=LUuGl03vqv0c+i6ZSkj10B9RuLqgx0G1WKkpTADsOgE=; b=qf2A06s6Nf7TAK5MuLz7LnD1aHcPZdDCCB66K+/l9cz0nkA9VRQJ2DBoqBx3iguMBg XOtKg7HBlCWZzUAzQDQR4B6oHE5pn5P4s+h2voUUfJdFvVOSeV5sy1WJnOx+AC7Rd1hu GAxVslGqRg+7pJS8yvR9i7GqQ+oFuHkvDk6xsHNDNNNcIt62WEqvmbLTIS+/oNIPSIR4 8f0+xAD5C255HrLgrAZ4tb7HZVgNN0GJ1UO9zLPgteqvSDvX2ppokNbOCTWEArd2Dlk2 Hvbamf/KUw6ActLRl4O2/iv9sTgkD7UYGVcpZC+Bg4I41MqACh8HCpfneOclxX18oyUC 30Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="S6/aaKTE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c18-20020a63a412000000b003ab61da6faasi13676542pgf.466.2022.05.08.20.01.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 20:01:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="S6/aaKTE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 CE4F5852E8; Sun, 8 May 2022 20:00:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384168AbiEES2K (ORCPT + 99 others); Thu, 5 May 2022 14:28:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383339AbiEESTr (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 22FC01928D; Thu, 5 May 2022 11:16:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651774564; x=1683310564; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OPt5gdUrcNtS6wCuAiVXEkb7LwQ4j8XYfPRSPrOJvhE=; b=S6/aaKTEzrxheLHYNdNB3CcjXMNSurwFePKJsWl+AVVDZurPt+MeHY7y Y+xM+7/p9yvCZGF7DOtml2d9qPj6UkByad0nyBaZX71V85D2zzZjNyPKT AuYloFU5LayQnbDLvisoxem/leccjSVkfBSSa6cGsfY0TnPU+j5w4saH1 wlXcdiakBRcSJAmnfGX10Q0slu1mguVFw2Oh212p2oADbwWO/0W/Zb7ZP O+B5Y4CW+lzt0wMh8psesPD2fn3HygOVgb6K8/6zjRYF+w7iJ0MIYM3Kf JMCs3akMxEFJI8q+QRomkCWnnmWJGzhF12tYcOebQeGZ+pCbvag8jF00A g==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="248742059" X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="248742059" 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:53 -0700 X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="665083452" 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:53 -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 086/104] KVM: TDX: handle ept violation/misconfig exit Date: Thu, 5 May 2022 11:15:20 -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: 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 1f31dead31f2..82bfdb05e67b 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