Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp187601rdb; Mon, 22 Jan 2024 17:00:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IG2qq0u68ypmFV+9fhfJ5Xpxy8grqkqSJmdANxTnJJ5wbD3AxmBQXWX+ISPFqSVakWQHOHV X-Received: by 2002:a05:6870:3288:b0:206:c65c:82fb with SMTP id q8-20020a056870328800b00206c65c82fbmr817077oac.87.1705971626939; Mon, 22 Jan 2024 17:00:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705971626; cv=pass; d=google.com; s=arc-20160816; b=SR1EEa/53fXvQiS7EqMc5p6quKSFNYiTbnc+UBeqxQ2oVYbnG9WWE8JLf9HquKXTCd +E1gTI7Eisb6X0Wb+w/V9hYyotCeqPltge/F26uLrQZGI1jVEtpvvSkZL8g4M2ufcfiu 7Lb0Ooynuo+FdP8InRVV0RNklFvMI4ir8Bkgg/Nr3PkpHFikRpM49f8YzKSSO10wKI6M nTrQpoAC9ToiFIcEuwi0t+Gd/eojOd7O36zyPzqZFEGXEUeYc46PHGkNbX5DpZR1g2ql vOZlSC1RDjiGcIWE162UZRxrqf3lmoIi6LDvFQRBiS53ZXgH/ep3ZzoJpkF9Iu3dcH34 IrzQ== 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=DVbx3/K6STkoUOO4Kzz9czqHC9kX/gu0qiQJAcuB5SA=; fh=ka1BjeomumTXa1Vhgkzg2yK2f13tB8VguFI2e9zPJ3c=; b=Sa8+MiYg7fe4ONj+QD+NzRkJsFf6FFrnWp3ZFJM4aCSBURgXawrxUTCv47Feoo/Fbj ZTCdqWnrbHwZrk/0lltK1NWPqMq1mX/vEBDkyySEHH7DriWdKvZqV4blinJapEK0xJQT wC9kSm9hjvp8Kp3B/FrQ6sv3xyGLYGFlD+G+8oiaDiuyOprnn0zWedTm8RxoDwwh2GWe t+h00990OtXkhRCZcvPQpH7Yiu48XKdJsFccxHOOpQZujP/CKGmg6Mz5zUSJAx9yErg3 +DX4/3LJ0iT1xqNLQUZAUa8cFzbFHI9fsIg26fFKWnb35L1R3LqDWdU+78lYm0wFzpMj BVkA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=E+RetZok; 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-34346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34346-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k10-20020a634b4a000000b005cdb0622c89si8968762pgl.16.2024.01.22.17.00.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 17:00:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=E+RetZok; 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-34346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34346-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 96757B25591 for ; Tue, 23 Jan 2024 00:36:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F02C5F87D; Mon, 22 Jan 2024 23:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="E+RetZok" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 9334A5F55B; Mon, 22 Jan 2024 23:55:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967728; cv=none; b=Kwe8AaQvFLAY+tK1Hy+Xs+n8/4ThYU4RRll1/jcdbIHZU6NoyoRzporYnWlkz5pdW6/tE9OqULxna72uuBnVxPWl5FXSeJOB+lUJO/mbtLmCCDXYQwIJ5Ahizmi9cmMJt0WbnjUtxnfiCnGNoHEMTREoChflPgrpFrdSRzVSsp0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967728; c=relaxed/simple; bh=fq9sl/Hvu6AYyJ20Nrfcvuiz9xnZGWqLLJDKXzXZMyU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JVCcss0eRZg0c4qOROJngGdL5zc9gjdNGFBmIH9+9cNKRDktNm386Y6mQP5S0gzOTLJMTG/cNQdQA6Dk7UE4eE9gh52RIoP2tvHo19TPJV6wtuu5Nt+3TnRP4EljAAIjnxKQRH/gZjNECYBXUHVjVUUU5JJRYN/NAxCxqOovZNg= 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=E+RetZok; arc=none smtp.client-ip=198.175.65.15 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=1705967727; x=1737503727; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fq9sl/Hvu6AYyJ20Nrfcvuiz9xnZGWqLLJDKXzXZMyU=; b=E+RetZokezWKhD3ptLyyS7KaQfNCT2yxslHL0N9j8+fwD9nZ1R1DT2eX xEKHGOjPo3zonVJgMbI67hRxaXw1SxZkHcnv1aSU5ycVJ1NqjKom2JvgH Ef6tLNrcAmbd46raF2goatHwmX44Wia1EDDpFJ47iaFgp3iLtx1pu0icj 4oOwpqvmL94p6ChZgNJ9patzDi8v9g4u2a3xPPiVXoTn7WXUz9YbwSMB6 qfjrTZC1x1Hy2FjupnQ+kC84x6MOnifLXGQ0LI65ghXQRqQQ1oUWFOixr AVGu7IG87MAwyVT+6BgYixddugDd5PddBtXQfHaifle5VmOiTohIzEg2q w==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="1243884" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="1243884" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="819888665" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="819888665" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:25 -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 037/121] KVM: x86/mmu: Allow non-zero value for non-present SPTE and removed SPTE Date: Mon, 22 Jan 2024 15:53:13 -0800 Message-Id: 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 For TD guest, the current way to emulate MMIO doesn't work any more, as KVM is not able to access the private memory of TD guest and do the emulation. Instead, TD guest expects to receive #VE when it accesses the MMIO and then it can explicitly make hypercall to KVM to get the expected information. To achieve this, the TDX module always enables "EPT-violation #VE" in the VMCS control. And accordingly, for the MMIO spte for the shared GPA, 1. KVM needs to set "suppress #VE" bit for the non-present SPTE so that EPT violation happens on TD accessing MMIO range. 2. On EPT violation, KVM sets the MMIO spte to clear "suppress #VE" bit so the TD guest can receive the #VE instead of EPT misconfigration unlike VMX case. For the shared GPA that is not populated yet, EPT violation need to be triggered when TD guest accesses such shared GPA. The non-present SPTE value for shared GPA should set "suppress #VE" bit. Add "suppress #VE" bit (bit 63) to SHADOW_NONPRESENT_VALUE and REMOVED_SPTE. Unconditionally set the "suppress #VE" bit (which is bit 63) for both AMD and Intel as: 1) AMD hardware doesn't use this bit when present bit is off; 2) for normal VMX guest, KVM never enables the "EPT-violation #VE" in VMCS control and "suppress #VE" bit is ignored by hardware. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/x86/kvm/mmu/spte.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h index 4d1799ba2bf8..26bc95bbc962 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -149,7 +149,20 @@ static_assert(MMIO_SPTE_GEN_LOW_BITS == 8 && MMIO_SPTE_GEN_HIGH_BITS == 11); #define MMIO_SPTE_GEN_MASK GENMASK_ULL(MMIO_SPTE_GEN_LOW_BITS + MMIO_SPTE_GEN_HIGH_BITS - 1, 0) +/* + * Non-present SPTE value for both VMX and SVM for TDP MMU. + * For SVM NPT, for non-present spte (bit 0 = 0), other bits are ignored. + * For VMX EPT, bit 63 is ignored if #VE is disabled. (EPT_VIOLATION_VE=0) + * bit 63 is #VE suppress if #VE is enabled. (EPT_VIOLATION_VE=1) + * For TDX: + * TDX module sets EPT_VIOLATION_VE for Secure-EPT and conventional EPT + */ +#ifdef CONFIG_X86_64 +#define SHADOW_NONPRESENT_VALUE BIT_ULL(63) +static_assert(!(SHADOW_NONPRESENT_VALUE & SPTE_MMU_PRESENT_MASK)); +#else #define SHADOW_NONPRESENT_VALUE 0ULL +#endif extern u64 __read_mostly shadow_host_writable_mask; extern u64 __read_mostly shadow_mmu_writable_mask; @@ -196,7 +209,7 @@ extern u64 __read_mostly shadow_nonpresent_or_rsvd_mask; * * Only used by the TDP MMU. */ -#define REMOVED_SPTE 0x5a0ULL +#define REMOVED_SPTE (SHADOW_NONPRESENT_VALUE | 0x5a0ULL) /* Removed SPTEs must not be misconstrued as shadow present PTEs. */ static_assert(!(REMOVED_SPTE & SPTE_MMU_PRESENT_MASK)); -- 2.25.1