Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2687030rwd; Sun, 28 May 2023 22:13:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7yV8HGHo6/F0qLDyFOx78exLRPy2EyfXQFNR9l/wpZ4ZUCvVdQjQrN/d9kvmfyNpog8gFg X-Received: by 2002:a17:902:e5d2:b0:1ae:4013:986c with SMTP id u18-20020a170902e5d200b001ae4013986cmr11873217plf.63.1685337197637; Sun, 28 May 2023 22:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685337197; cv=none; d=google.com; s=arc-20160816; b=QljDu+S613ShF9eGyvvoL6paAw9vYdMEN7VcPtKoKz0SMReztLCFgXgpjAEofJuSHN 5bUfTjXNTvXcHTBxjSf7pTik58DAXLthKaNRVby2C6yu5r2iwgjUy6TFJBX1jVUgKAR2 wVVS1BQ079LAaqzpD7aMoSbd1Y+6oRdpgNOuL9O05OiPO64EXLLygJJ1vrXdkkn50+qC Q/cXuwPSzI9W/WrmoPaiu3Ic4XFtcNX/L9kA3UG/XQNtNxwpI7VKquCOo85dw21rM4BR jPj1qEJ7gxp4vuh9iOtsqXVd/VwMMMZnTkotVnm6nHmwqUVnu9oJJaQuxcsWIAUYkYaK Eh5A== 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=ng5Z+ZfcoU80zycfN2HjhD5txFF+Hql9fmfr9Ea2FB8=; b=Gshf+7Od14kB4k1j9NznkLAEvwDca9dsNhxoi5YdyAAJ+8YT17lX/7yDE9W+47k2nj /DzqK4HP5yJ+uUIHBgy4mvqY6NRzdNoqlnQg3PygpdTDowmGnry18K50lWxxBgOFeEfS QpwHIaEvlmjrHbQRlZEWKP/orXftnvbTQj97RUtPBC/9C5ztNPnofVf9RKyu7VGEcB5a GiwCv0C8MKAscFqlqJ81L6jNLSXFG6K90afnbaLPHg7qQ3JgviaXGGcM6ebinrtM9b+T 1b3aqpaemxPS6QHrdOFcIKuEN1jxi9/My8thlt2njFCoVr4qQJYVbgVT8/gJcKC7BxjD vkLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=giv+UTdP; 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 z4-20020a170902834400b001ac9ab8539csi6656371pln.77.2023.05.28.22.13.05; Sun, 28 May 2023 22:13:17 -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=giv+UTdP; 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 S231788AbjE2EXt (ORCPT + 99 others); Mon, 29 May 2023 00:23:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231623AbjE2EXU (ORCPT ); Mon, 29 May 2023 00:23:20 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5787FE6A; Sun, 28 May 2023 21:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685334076; x=1716870076; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CoQnqLun9XBJdTIBa8S7YePe8TwiMfxkj+IV5w5Hkm4=; b=giv+UTdPMP39hygllnUhjxkUwhifOIsbwbz02+7/a2yUEHEJoIpWaVd/ DbcdQpeilEc4cBhFHyqssOg+bOEulFojctoYb2Q2D/MbpliIZrf/fNsu0 ulzr0uzg9A998Z1bN6rjJ4JCul2uluCkpoc+4hYfqg7Y8ZHlXumPOuYGg P4+9OLbZkISZnlx1OXiI9v4KdQwB1BMk6r0FJhjo54MQdmJWeTSCkWKNS jgMHYWn8w1gIVda0MVRP3gVDiZ5+2qMFeWjgyMdZvHSG0m7r8vA4gP4RS fPrhOrdPFxCH3iHDxN4u8oLxugqUamt1NxYvuNxjOBTtlrESZN0fPQDyz g==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="334965890" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="334965890" 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:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="775784227" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="775784227" 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:09 -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, Sean Christopherson Subject: [PATCH v14 032/113] KVM: x86/mmu: Allow non-zero value for non-present SPTE and removed SPTE Date: Sun, 28 May 2023 21:19:14 -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=-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: 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 a99eb7d4ae5d..a57667810344 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -148,7 +148,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; @@ -195,7 +208,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