Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1180484rbb; Mon, 26 Feb 2024 00:56:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWpsOa2O4nQBjylx0pK2Q2ZLobXpyCSlchNfEuNnmxlLP2KERBmAOCJreaKYBboU5OE+/ZOeMEFNkbdEiAyFiZLQHjGW1oksZEjb1fUeA== X-Google-Smtp-Source: AGHT+IENFYXL3N8+20MI7CFnhCyg9rVQjVyKpSZpy6C6WOcCWQKxdbrH1N0cYMDEcjDNug6pAF7y X-Received: by 2002:a0c:f510:0:b0:68f:a301:e3c0 with SMTP id j16-20020a0cf510000000b0068fa301e3c0mr8026863qvm.18.1708937763616; Mon, 26 Feb 2024 00:56:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708937763; cv=pass; d=google.com; s=arc-20160816; b=w/7IRdYs0HxEFLh9iRuLIuwVpkxaYpB9lT4bxx/jabgB3zkzfJuCrKzVSx2VbmL4D1 a0IX80wOpI3IRj1CloREeYcMPFJs3SevzC27rfaaIIIF+y+0L+CY9g1nmFkgFqVgjOck gRAD2kMq5g/vUyuHHuktKtvjky8QR+BxmV2QrTIf5pO/k9BmHRkmhrCiehhTfoVB1H2Y ktUnh6SjAJ0q7Sk7Mw00t8a0PeU4RmNkaLjQ1OGhJkHHfPNnRL8LxkHpCUkN86JqdbLG BeZWcS8Yk/58IbPhiKujbjdXoGaE11DZHNf4BrhT7r+Oy8AoEAHIgGW423skHa1wDxV7 RsxA== 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=ATsEPvGwBB+ILLTll4DeNnheBcFwXkjd2ry5FLtnQOU=; fh=GU4KR9NKf1qQHjmWlEi4zSAEAxyD6Pa0rUGDupPjr4Q=; b=eTiusGdG9De/8qKjm5YS/6Rf8X88GrQVtcZqXQEB+8gnBSfgmC9QoSSsPj2LvZQ9NV Fno6qvBJuCcGbgrM2xtzqLWSwXEVTJMka1LAREL+dhdKkbrJ/u6FfB75txtqb2l7BFgP yui0rwMu0fcBSwi0nsr64tSj7jneaZNteb7DZaKcld3Ex8qDzHfTuHBTN0KCVdPLyS42 /g+X3CKGLA34AfeUCZUe9GmocsHgWwxVYx8ddwZVXzy0XEh/yT9UhqajOmgDHynRKcYb 3xVJpsFGMYcQrbrSHWlCcLvMnCeYmujsIJh5ZK4Va5J3LIRMWFEw90tYTW/e21bhyLrX 8qQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FCvGvELX; 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-80848-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80848-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pt21-20020a056214049500b0068ff2a53777si4098284qvb.136.2024.02.26.00.56.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 00:56:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80848-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FCvGvELX; 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-80848-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80848-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6022A1C211C6 for ; Mon, 26 Feb 2024 08:56:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18D6D7993F; Mon, 26 Feb 2024 08:28:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FCvGvELX" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 E831F77A0E; Mon, 26 Feb 2024 08:28:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936124; cv=none; b=naC9StShK8ALOm/UTQQEpS0Ue/wN7bssa3BCunW3Rt7ANPhBg/5QUrTEJiDNNv+uxp4NeAF249uegQ5AnG9PYkfiA0ZaeBXf3Upv0NOVqiOERCUhcHMyXkdqZx8uUiXPoQbbtqEYMz2qau1Uhj5dq6J4i6sYjjSTpJZ0OK+WiiY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936124; c=relaxed/simple; bh=d16HpBuwInS8Tw2Ei/8iq4CZW3uueOnKvGugn8F5q+Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tX6c46R/69xmEjBZjUGLz7uA83ZUwh15d4TfQ6+EzKpMc9s2tOP9Zjt1PMD8xvx774gETj2YCCefAdRH73XM/l2QwZOxTtlWlcJeCCXOJsF5+pEQi76Eys1kXpnKsGTcYjDdwxwm3wq4JALAOUz/QqUcY1/pZ5cfR1uGmaV0Vmg= 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=FCvGvELX; arc=none smtp.client-ip=198.175.65.19 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=1708936123; x=1740472123; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=d16HpBuwInS8Tw2Ei/8iq4CZW3uueOnKvGugn8F5q+Q=; b=FCvGvELXmKt3QrxVDZt7OmY9LRVIVwB6avar2149XGqho1QiTDqi+LvN XXFUcyQyGBVBcu/P3Hezj+QVbIjJpSgSdUT0u63/OPq/r7nFAxES9hLZb 07JKcDgt6ChoP/zf9d+t8ef7O/hBuzwyCUXcXaih3l5gsxw8WbYX4BDtn x1AAdl1okVA1rRjIffdDNSNs01LMMqWawAqdoIqLMI/CmMWLCEYjImDdG q2JjEp4otB6SP4JdxdsqlEa3f+VonJqhZg4qfwYYdYbyALaKSFceoxg1U jtGEzbEqAE7y+RBq3jVyf2UvRLlMcf5v3VtrZ3FBHxFZLYD9G2Yuqs/Nk A==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="3069529" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="3069529" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="11272581" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:42 -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, Binbin Wu Subject: [PATCH v19 085/130] KVM: TDX: Complete interrupts after tdexit Date: Mon, 26 Feb 2024 00:26:27 -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: Isaku Yamahata This corresponds to VMX __vmx_complete_interrupts(). Because TDX virtualize vAPIC, KVM only needs to care NMI injection. Signed-off-by: Isaku Yamahata Reviewed-by: Paolo Bonzini Reviewed-by: Binbin Wu --- v19: - move tdvps_management_check() to this patch - typo: complete -> Complete in short log --- arch/x86/kvm/vmx/tdx.c | 10 ++++++++++ arch/x86/kvm/vmx/tdx.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 83dcaf5b6fbd..b8b168f74dfe 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -535,6 +535,14 @@ void tdx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) */ } +static void tdx_complete_interrupts(struct kvm_vcpu *vcpu) +{ + /* Avoid costly SEAMCALL if no nmi was injected */ + if (vcpu->arch.nmi_injected) + vcpu->arch.nmi_injected = td_management_read8(to_tdx(vcpu), + TD_VCPU_PEND_NMI); +} + struct tdx_uret_msr { u32 msr; unsigned int slot; @@ -663,6 +671,8 @@ fastpath_t tdx_vcpu_run(struct kvm_vcpu *vcpu) vcpu->arch.regs_avail &= ~VMX_REGS_LAZY_LOAD_SET; trace_kvm_exit(vcpu, KVM_ISA_VMX); + tdx_complete_interrupts(vcpu); + return EXIT_FASTPATH_NONE; } diff --git a/arch/x86/kvm/vmx/tdx.h b/arch/x86/kvm/vmx/tdx.h index 44eab734e702..0d8a98feb58e 100644 --- a/arch/x86/kvm/vmx/tdx.h +++ b/arch/x86/kvm/vmx/tdx.h @@ -142,6 +142,8 @@ static __always_inline void tdvps_vmcs_check(u32 field, u8 bits) "Invalid TD VMCS access for 16-bit field"); } +static __always_inline void tdvps_management_check(u64 field, u8 bits) {} + #define TDX_BUILD_TDVPS_ACCESSORS(bits, uclass, lclass) \ static __always_inline u##bits td_##lclass##_read##bits(struct vcpu_tdx *tdx, \ u32 field) \ @@ -200,6 +202,8 @@ TDX_BUILD_TDVPS_ACCESSORS(16, VMCS, vmcs); TDX_BUILD_TDVPS_ACCESSORS(32, VMCS, vmcs); TDX_BUILD_TDVPS_ACCESSORS(64, VMCS, vmcs); +TDX_BUILD_TDVPS_ACCESSORS(8, MANAGEMENT, management); + static __always_inline u64 td_tdcs_exec_read64(struct kvm_tdx *kvm_tdx, u32 field) { struct tdx_module_args out; -- 2.25.1