Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp172863rdb; Mon, 22 Jan 2024 16:20:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IHSIINzSxjl5LWl3pKSVfz0Tp6SNgKSrQMfghPVPOPG74fD3IlcAwzc8S2ps859BpJ28ZXd X-Received: by 2002:a17:907:d411:b0:a30:49d6:5abf with SMTP id vi17-20020a170907d41100b00a3049d65abfmr2469720ejc.37.1705969240375; Mon, 22 Jan 2024 16:20:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705969240; cv=pass; d=google.com; s=arc-20160816; b=Y4/7qM4RvZI/CsyIvWqdt9x+6d3MKUNNe6qO/6KvWhSToSFUp1VwZBRGeLka4gFN6+ HXEG38jEhkOhduj26CNVcH4/Igy7fPy65lwu1qxnOruzTyVC0rpZL3SCSVGA6qlbV2ya 5P8TOf7Iw8gviVtLnWwHr5mLjHzgWCadJEGdOo8HH+58GpbB6l+gRasibkp0TbcltsDk 7ogRGUMatCF32mfNZ+n3V/hROTpKW9SUdxkUVSIwFfKv6dF/UdjzIhO0Qim9xGvSUVl2 +X8KTS43BRyqC0kzXGknnCIjlqjH5kDl+enqifbt30vy7OtWgPR4qbIhe5bxaL8+Hf+G aRCg== 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=DmbFCPBCGAmfheylcnTQqGfnJpJ0Rs3L1P1AqiDqrCE=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=wNZQgpX6/w+ORFI/dgPhDq8bmlyKJJ33LbLGMxaQHEgSEOyI34tOMgbM6amHfIB7X6 /ZdYQSxWd+KARspylGUZd/J6gXQjWYImsYL6hUbNMq6bvFGQVMRBbOOJHyjqa7hJMqBj wHS9Agh3Hk5B7Z+yoqfoQC6YFeks1jrbQlHHw232/ImMNT7PgtQ1k/opzzjHdzQcHH8+ Eo10SSVm3bjYd9wYGJP+awjsRB8+Zsoni8XnJfQh5X0igNeWPabEvyNWMzZMJYgwwRhH ePLfUlCF4+Bu2SxqdDSA0djM68b65yGC6v158P2mF0AbvwjYHvnIRs+zHOTt8wiZnKhi jaUw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gnLoQTH+; 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-34423-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34423-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d5-20020a1709061f4500b00a2ab81a2ffesi11088605ejk.439.2024.01.22.16.20.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:20:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34423-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gnLoQTH+; 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-34423-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34423-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 21DE81F240D2 for ; Tue, 23 Jan 2024 00:20:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7056881AC3; Mon, 22 Jan 2024 23:56:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gnLoQTH+" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (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 E596950243; Mon, 22 Jan 2024 23:56:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967775; cv=none; b=llGGz4NfEvJMbEoL71EuN4N9KanW+pUhwqD/EaxAdiEHIglsiF/gCXYj+9qTnZN961OJSTBqHnmCYpHl849cMfe8uo+01BlGqEmIz48q65xTJ8iX6dnDl01uvpt08sUbWYXvzLAJuxCib+mXjnP48S0WPHYWsinRBpuioUB+tLU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967775; c=relaxed/simple; bh=CPzg9MzLi+bzjnrxuAOhesiBsliVVuVv8X2j8Iy9fAU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=doSIUWwC82FMzM9i6UViDTZvJ/rhE43fUzE1rdM4gL8eX3lUz7SfxTgMwRY0AbA5qqAqc34xMl1W2wyVqhP7Zk0RdUaQwhi+8+taKyhh9gjrVioo2iievyJlrTqrWJtgTQ/TJDXIdkAyj8+Ii/8wsNRVsPRlCysk74jKymRDaEQ= 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=gnLoQTH+; arc=none smtp.client-ip=192.55.52.120 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=1705967773; x=1737503773; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CPzg9MzLi+bzjnrxuAOhesiBsliVVuVv8X2j8Iy9fAU=; b=gnLoQTH+cA4wjH9HhJw3h1AfLf1ccDTIAXgVBM+ulNeocuSinaJvyq6/ TcPOUCiAP9c9i+FcqluzNxW5VFlDKQPlbvtONBX+VeaTUwSXCm+34zdbw zX/3oPUD5dt6KmrFMuVQQUQnYNBMMWmKo6YkXjFYN4uiT6SfS0yGobxQw kNjiEinWwqNt90Qkxb+orXxHZnpUDFa6IcdjJfIz+H2IJG3vd1yZOA2xQ 9uAmkXFlTZCiBi4ctaSx44u52C/GUfnJ+dXZWhBj7Esp99q4F6scTZK/D oERkHG8NPyOjYFm+ebBYOVXuohf1y6bz4fRP2AuBrfTqxkNogLJoJPq5b Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="400217945" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="400217945" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="27818035" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:58 -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 Subject: [PATCH v18 115/121] KVM: TDX: Inhibit APICv for TDX guest Date: Mon, 22 Jan 2024 15:54:31 -0800 Message-Id: <201f04ffc055319c9958ba0e37dd2e9833084c05.1705965635.git.isaku.yamahata@intel.com> 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 TDX doesn't support APICV, inhibit APICv for TDX guest. Follow how SEV does it. Define a new inhibit reason for TDX, set it on TD initialization, and add the flag to kvm_x86_ops.required_apicv_inhibits. Signed-off-by: Isaku Yamahata --- arch/x86/include/asm/kvm_host.h | 9 +++++++++ arch/x86/kvm/vmx/main.c | 3 ++- arch/x86/kvm/vmx/tdx.c | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 59a1c55c48f0..54ac65b75f18 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1314,6 +1314,15 @@ enum kvm_apicv_inhibit { * mapping between logical ID and vCPU. */ APICV_INHIBIT_REASON_LOGICAL_ID_ALIASED, + + /*********************************************************/ + /* INHIBITs that are relevant only to the Intel's APICv. */ + /*********************************************************/ + + /* + * APICv is disabled because TDX doesn't support it. + */ + APICV_INHIBIT_REASON_TDX, }; struct kvm_arch { diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 48d71c2cef1b..dd2859328593 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -1005,7 +1005,8 @@ static int vt_vcpu_mem_enc_ioctl(struct kvm_vcpu *vcpu, void __user *argp) BIT(APICV_INHIBIT_REASON_BLOCKIRQ) | \ BIT(APICV_INHIBIT_REASON_PHYSICAL_ID_ALIASED) | \ BIT(APICV_INHIBIT_REASON_APIC_ID_MODIFIED) | \ - BIT(APICV_INHIBIT_REASON_APIC_BASE_MODIFIED)) + BIT(APICV_INHIBIT_REASON_APIC_BASE_MODIFIED) | \ + BIT(APICV_INHIBIT_REASON_TDX)) struct kvm_x86_ops vt_x86_ops __initdata = { .name = KBUILD_MODNAME, diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index a879a7fb0f03..be1cc08dd74a 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -2533,6 +2533,8 @@ static int __tdx_td_init(struct kvm *kvm, struct td_params *td_params, goto teardown; } + kvm_set_apicv_inhibit(kvm, APICV_INHIBIT_REASON_TDX); + return 0; /* @@ -2895,6 +2897,8 @@ static int tdx_td_vcpu_init(struct kvm_vcpu *vcpu, u64 vcpu_rcx) return -EIO; } + WARN_ON_ONCE(kvm_apicv_activated(vcpu->kvm)); + vcpu->arch.apic->apicv_active = false; vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; tdx->td_vcpu_created = true; return 0; -- 2.25.1