Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2661240rwd; Sun, 28 May 2023 21:36:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4CWmzPxe/xCKcZ33Li42G5qfSrKuMI5qdHyvcc4s55YG1k06ucoJ+R4B4YuXa8hi3UI5UX X-Received: by 2002:a17:90a:bb0a:b0:24d:f739:d62a with SMTP id u10-20020a17090abb0a00b0024df739d62amr9973141pjr.23.1685334991798; Sun, 28 May 2023 21:36:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685334991; cv=none; d=google.com; s=arc-20160816; b=xNCo2QB8Jrhik5wky2zBdHVtLuHcjMOSNDMwkg9NH5z2caej/abckhxEMaSixXE3/v 9A/aRB/RbQAKS9SRrj5uS8hsDGCV7pxb1w+MAGLW2/l5gmgv7sbXinqMktpfk5NYScWH o6wDXfGUpAr5orxT/jOKBGqa5ANbxC74A17QHWtWQzD6luXU7JO7PeTZD6moIrXMgViw hiBocIbntN4BHymVFFUQancfvtMftWsd7Erq4k5U7EvWmUMA8BdzK6eWwMR0cm3EKPSP 23FcyaVepCbYltt7hryWfVuoglKBonSYf1W1DNPoHrQTnfLjUM7n99uP1UL+NER7j4+8 7APg== 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=qk27Jdq1hihhH96WsNbBKahNTpmdRhHH4aEMeYEcJCU=; b=LHAvM1afUazJQZFyaKDnbMfS8t4U3j522wX10zhGwbxMcu8B/hdtEkS3EnPn11f8Ky Xpw0if594vHKKagI4BN5qkKGShnH13N3yV2Xda8jM+qNv7OcyP7ZTb2SJbJ2nl2chLjN 1TiTC3PWOo2K7d/wK5AZ2W5aI3Bum/cznWDY9NxCBQzVyDzlynhTfQWJDtF44w33suNS +3P1ieNhXkaxUw+8MAaUki+vXwPy27XYVt3n0ELximf9TIAy0b7Y7hHodFAUtH8RkE9D kx2ICVjtfwaC5Wuui3iDe5cB8QiCds9N0y05Z0AHTMWWAbQc/FibOp1yKnvkcqolFa5b lpDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XFVYEZx+; 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 6-20020a17090a1a4600b0025672fbdad5si1708840pjl.178.2023.05.28.21.36.17; Sun, 28 May 2023 21:36:31 -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=XFVYEZx+; 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 S231842AbjE2Edf (ORCPT + 99 others); Mon, 29 May 2023 00:33:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232158AbjE2E26 (ORCPT ); Mon, 29 May 2023 00:28:58 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC3E31987; Sun, 28 May 2023 21:25:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685334313; x=1716870313; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ywg5sMZVHb2IQnj3J4ep6DC9fk7SuQKFRSN+L1ln7C0=; b=XFVYEZx+8F5NPwpeW18hrkKMCDzkC3pnUK1WOF4KcBmK+zEqw/UO6xbP qeYp9yYUqLlNZ8dvvtvoWyafsgaUUl7XGjIrRJ6o/IWGI2YT5mZ84p6iL MRsGjPmaMHEK3GJNoyBkOe5BVeQ4sN7h4/j40j+V3WFcsduB9C2UJWRAJ 8P8GRSePlwf0BrmYRsfz+V+IvWBC3YbI/uVTB1Rf55dlBtxEpFC5wStLI p9RGmfN4C0HTTZn6Kl9vR/hTxcKm6UUgZHYfradRaiLXCBMrMHDLpdJ3K v8bDIH4yuciBU/v8Zb1Py4+vMidjq5Wd00xfFIZT+JEQAsqEXt+BRV5oi w==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="334966186" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="334966186" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="775784470" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="775784470" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:29 -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 Subject: [PATCH v14 075/113] KVM: x86: Assume timer IRQ was injected if APIC state is proteced Date: Sun, 28 May 2023 21:19:57 -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=-4.6 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,T_SCC_BODY_TEXT_LINE 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 --- 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 b2612a86789f..6b2e2d38a48b 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1734,8 +1734,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