Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp1454611rwj; Sun, 30 Oct 2022 00:40:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Bojl1p56ljnNVtToiPYTyzW1/i+3M5wGpWB2ev25L2/Ijz2GmBCBEH1Ak05YPY0OvmwD/ X-Received: by 2002:a63:1d1:0:b0:43a:348b:63fd with SMTP id 200-20020a6301d1000000b0043a348b63fdmr7454643pgb.52.1667115600502; Sun, 30 Oct 2022 00:40:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667115600; cv=none; d=google.com; s=arc-20160816; b=PrwHhjtxhubi0xZEPmQatJ3JgsKk2fqinK2X9hLaKtnxhN67I1rZx9okS29e/JqiIx 6VWHNT8jQylrrYAO0GJqa22rQ8BQxjorbJOmh7Whns6m4bVSWjZy/8wXVfnfJBubTFMA h34Hr/mlN8s1rLZJrl1xU4k/muo41nIUpI58OWZ/UB/06v4G0NWiNsTIJjUnt2l677pA g344yoCEUkmKabq0LkW9jgfEMoSgGXYssHjAorZgaZJ2Qkp6hzbo5zJDrU1UBWjU1hWQ 6oTVXmzlBpgaafTvXiw5I4rZ1Xlk1HT2/SqQwJCx5+RHdcFAO1to7L0FmCXbAVsaSU5f iNsA== 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=KZd5jsFAN/ztHb9uYkr73charq0kJqurp9nCspx3TbY=; b=kdfyguQp3Tuf2sT+l3yaabK6VsGoVWt5qGa/HS1ioS/zZi1BVjlWkOOfepctmxqfve fr6/w0oZdvFTMHIKnOAvJiGhNpi4xhRRODfoXBN+9Yiyff4b5WZbkKYg7t69zKd/s/5a nc8EBfVTvspaCytNEGgwvxJAuYukmh0nUNVJ+3EOTbfEAvsBIZlskTGv3OL4bSY4jKrV gw/MKBMW9nZ5vezEPGjHGaYDHCzbwqf9ECi0e9Qt0mTgxh7uJcTjtO6zkVQn/ESmXBry /ttkNEZ43fFmP9Barb8PYr+/SE54NE0JsgxdKticbkpCkoDWoluVqqmDJVpuxeGQpIoc ON6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=glAILD5K; 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 il3-20020a17090b164300b002008948605esi4962177pjb.13.2022.10.30.00.39.49; Sun, 30 Oct 2022 00:40:00 -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=glAILD5K; 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 S231359AbiJ3Ga5 (ORCPT + 99 others); Sun, 30 Oct 2022 02:30:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230254AbiJ3G3k (ORCPT ); Sun, 30 Oct 2022 02:29:40 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF04D335; Sat, 29 Oct 2022 23:24:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667111085; x=1698647085; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FA/pCLrZQODOQdV1WGT35bNwtZsU35qRfGMumXhQubE=; b=glAILD5KStH5PDCZRIQ7lAGvWs5um1lGsYL5HsjcCh4khMxAiPKQj1g/ KOWBvBqY2+pALX/MPwRKvwnQvkYYLMg6IuuuVUx+s6hI8uvsXK2BMdHjq Ov0VtdoeJd3Ib2xA8Cr/raa2Q/m07rEFWJIVMslQwYMa7RZAA58XVTXXE 0nvdaVJyrcQuXtJpuMECwBhl0wqHnDBEcnkoTpUWzjLScVr052qvEg7OX a4P/J0leDuLtbVE3Lo5EnPguXZB0FDqZTcRbkcAXBus7J95HmURBEvIgq 1/m+WkvppKiuDsmmyNDMJBf922uLzXQrDQ9j7n+6/yDaV3UA5CQUHVF/E g==; X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="395037192" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="395037192" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:24:10 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="878393098" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="878393098" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:24:10 -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 Subject: [PATCH v10 079/108] KVM: x86: Assume timer IRQ was injected if APIC state is proteced Date: Sat, 29 Oct 2022 23:23:20 -0700 Message-Id: <62640c5b69b297151af1e8f512f75f953354f12d.1667110240.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 X-Spam-Status: No, score=-4.9 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 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 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 Signed-off-by: Isaku Yamahata --- 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 bcf339d02c0a..8d894c3959c8 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1606,8 +1606,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