Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2634823rdg; Mon, 16 Oct 2023 10:01:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvJHyRJX/KP37htzDGcHBrxZjsM8v28dXKA7wkvujxqmIiXRxMfBjRWT6a0eg2j6Vo8l4r X-Received: by 2002:a05:6a20:9187:b0:135:8a04:9045 with SMTP id v7-20020a056a20918700b001358a049045mr32361011pzd.1.1697475699689; Mon, 16 Oct 2023 10:01:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697475699; cv=none; d=google.com; s=arc-20160816; b=jUKOZLTleEors+Oxg0fjYVecLNv4r+pUazQe3zAO7EknFFszEgH9fd10PJj8e94dXU HhoAcxEfYR8EXnh+pBJCq/ri5Y1oSiOuo0FzhW0m+r6SorAeB1j7Sf6cOqQslOpQP4lI GPrEhOxP8eGhDHcPDt+ikF2FGdu+jqTux5Jt7V+OnwkmUScij01J0qUcPKdXFdKu/UYM x+eO0zCdnF8fnjMyMkGtZTgMPKRGz53/gkmCSmJxx2ASGD2FzKdDZ+V640aqJYznMLtt 3wdP/0Ayf4AsWHiCLn34YTFm7V19Xg7J+6ghUEjq1mGUcSwXV5jKELxd+PrdB7/BW1AD QOpQ== 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=vJALvZADRnYCIHaLOFajKxQrN12E6vXSyOYUl9laVbI=; fh=lRdU2Q/1zx5DcPdZuWBjshA5VT5Oc9cEhB1tCFiV0Nw=; b=cYPukCAYpESFNxKPs9y1tcrdTAeXmJNXTKV5okDOfemMss/4gGv/w4W+8be8rx1DRA xXXhwazPb5tgKzNAGtez+2P47XvMbFp5WGZDAMZKNfrzoEMwF7A3huWn4ce1CAlQ54mD 2VVWOUkbcdbeciYC2QxoyekAFH21MYztz7jogZufTwnxNomjG0PbqPDcLioVOfc2CMN+ t7GaRGyXbFTPOIz1N5NbWa5jhWkWDVczyOlpwsegyId55Ue9Co4ygjShC3rpTjatN+ZB cWoe3it/q6d7ZBpUVBub9IevtOUEAUuMeVo4rBWAGnRJbGWHG6xBofYDqVH4SE+HI+WT Qhbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lmkkqWcX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id c9-20020a631c49000000b00578a6aaae10si11014211pgm.86.2023.10.16.10.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 10:01:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lmkkqWcX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 315E88079AD3; Mon, 16 Oct 2023 10:00:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234646AbjJPQ76 (ORCPT + 99 others); Mon, 16 Oct 2023 12:59:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234092AbjJPQ7k (ORCPT ); Mon, 16 Oct 2023 12:59:40 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5EDD72A2; Mon, 16 Oct 2023 09:22:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697473368; x=1729009368; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w2jZkAdIHP1nj2m5XeNSsUCz/xC1Te/t4FJHSSEhalg=; b=lmkkqWcXxrMI4bAuuZAMein6BDDi8AFjEdBUo4WraIz1y3TvTYFn561P kUJQEVkHKi3hIsqRqTuXtDVJ6pIosYZlwCNH5ajVhfVLw+dkQ7ZY6zUnG 0wrb9k2Dh0rp7PvKn530rVn6FTMe8JFyxnZY5cL0sPolMzu0tXACjvvm5 zSovg3NcnEtBueTuToq2JJgeftXXF/Gmn7Av6G2ZHhaRF+kgcMwTVSfZH htIGmx/wTTtgVnsrwq8VZj2bkWdz9RceOedOwD8tx1Z27RE6xHLmpSXmR /2/ASRu9CXN5N+c+IZWBgbcYnNhAwzAIwzIigmlkSpcCYDKvbWCAES4hO w==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="364922152" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="364922152" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:16:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="1003006484" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="1003006484" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:16:12 -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, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v16 110/116] KVM: TDX: Inhibit APICv for TDX guest Date: Mon, 16 Oct 2023 09:15:02 -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=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 16 Oct 2023 10:00:19 -0700 (PDT) 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 | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 529c7e610d47..f0674ef1c17e 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1284,6 +1284,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 eb44f5784f18..5d61f5306ae3 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -1001,7 +1001,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 527fbcd7e2c5..924cbf97404a 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -2486,6 +2486,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; /* @@ -2849,6 +2851,10 @@ static int tdx_td_vcpu_init(struct kvm_vcpu *vcpu, u64 vcpu_rcx) } vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; + + WARN_ON_ONCE(kvm_apicv_activated(vcpu->kvm)); + vcpu->arch.apic->apicv_active = false; + return 0; free_tdvpx: -- 2.25.1