Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D3A3C7EE2D for ; Mon, 27 Feb 2023 08:29:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231690AbjB0I3D (ORCPT ); Mon, 27 Feb 2023 03:29:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231501AbjB0I2Y (ORCPT ); Mon, 27 Feb 2023 03:28:24 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3074B1EFEC; Mon, 27 Feb 2023 00:25:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677486328; x=1709022328; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GFLU4367mK+hlnmpk1ajR6jDNEWYTf2ro/PSD8hACls=; b=V4Tm2UjOeY88IZbF8Au7baazQlq+j8Ac1a4eIzakNK6KycXAAYeSfb5k kUhNdtvFwCTnLjwbgPG+Ji6ahI+IZ5nMz/f571IGDK+h70LTo/mkPg2gu SE5O4Y+3EeC61GGFuCiM7+VRQcdyWi6aI5/6729xroDb1SKdpIp0ugBLU t5Hh3FbLneX/TM0crSTRDJx3Do1mRy8lZC6mCNVu1t27kOSmInSCwnfGA Nz8+2v8MNZS7z5DgXlKiDqFsmr8BRuyXezuno5+XZiZ0+MCjbeWn12t7g tHz3DW2Q3cMjd6DKCiCh03mGcv2X1v3YTwi59qtCPQDYpEzEOj4tYLO1C A==; X-IronPort-AV: E=McAfee;i="6500,9779,10633"; a="317608964" X-IronPort-AV: E=Sophos;i="5.97,331,1669104000"; d="scan'208";a="317608964" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 00:24:15 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10633"; a="783242318" X-IronPort-AV: E=Sophos;i="5.97,331,1669104000"; d="scan'208";a="783242318" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 00:24:14 -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 , David Matlack , Kai Huang , Zhi Wang Subject: [PATCH v12 068/106] KVM: x86: Assume timer IRQ was injected if APIC state is proteced Date: Mon, 27 Feb 2023 00:23:07 -0800 Message-Id: <562d136ca6bb573f59c4bfa67f8376da27f795f2.1677484918.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson If APIC state is protected, i.e. the vCPU is a TDX guest, assume a timer IRQ was injected when deciding whether or not to busy wait in the "timer advanced" path. The "real" vIRR is not readable/writable, so trying to query for a pending timer IRQ will return garbage. Note, TDX can scour the PIR if it wants to be more precise and skip the "wait" call entirely. Signed-off-by: Sean Christopherson --- arch/x86/kvm/lapic.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 8c99a9d7b39b..eae1459f8283 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1694,8 +1694,17 @@ static void apic_update_lvtt(struct kvm_lapic *apic) static bool lapic_timer_int_injected(struct kvm_vcpu *vcpu) { struct kvm_lapic *apic = vcpu->arch.apic; - u32 reg = kvm_lapic_get_reg(apic, APIC_LVTT); + u32 reg; + /* + * Assume a timer IRQ was "injected" if the APIC is protected. KVM's + * copy of the vIRR is bogus, it's the responsibility of the caller to + * precisely check whether or not a timer IRQ is pending. + */ + if (apic->guest_apic_protected) + return true; + + reg = kvm_lapic_get_reg(apic, APIC_LVTT); if (kvm_apic_hw_enabled(apic)) { int vec = reg & APIC_VECTOR_MASK; void *bitmap = apic->regs + APIC_ISR; -- 2.25.1