Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3783051iob; Sat, 7 May 2022 15:14:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJze4nhg2bhSuDjPt4xWnEdQhWk7LZAFZtZmXxLfdV1xz/EvuMuUkGE31//dowBpVSV9d9t6 X-Received: by 2002:a05:6402:51d3:b0:428:4666:b389 with SMTP id r19-20020a05640251d300b004284666b389mr10380291edd.345.1651961657386; Sat, 07 May 2022 15:14:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651961657; cv=none; d=google.com; s=arc-20160816; b=h57dUyguIBpwF+KoEPC0l1vBWS3HzM9ATe+osjTh+65mPgNaeY2KPtZPT+8C3VQrKI 0o8CCXSMOvDh2F4nxA7Rz+mf/NvpasuBB/TEkFvR2jL0Qnef0w25JR9AHQXcSctj4H+L dDzQK65HGjislaoBvUtoppZfK2AYmc1zFUiQl0HFE5oE40E4QBAyi66QGpW0IiFLqDwb 9U45Yrl8O5kzj0u5yZMB8gJL51TV3BhvgEpuRc2bp76sKuZrbmpr6XytOKQvkMqpSPdn 3wQstdW80nQmF3VNqm7yxZQhbInVV469pXyhwRF+8/qC4qRv/giOmdNgK6sqi7tKuORc K7ug== 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=2mcWt4F8OEU9FtCWjuYgSgptKLRTQogO5Ztgrr+iZCE=; b=ebTsEDPAPae0a7cd3B2SDWUlGAMWb6c+wKgiVBTmgIEkR8difEi2YGT3kS/Ckp8ker DfPDbGCCOmHaZzKiUFnsyU+cg5+slSxDNCdZQJgCyu3d0Srip6EqfoGoo3B1bX9LPyil Ja7TEZ/Fpzi+xSe+pry1ZcKLksgjP1hzegkppqNB0odCQhosSu/J4DOdEBSJq0pR++r3 H7mpuoCijKsxAFvKthYiQjEpWhkzMQWJBcuzsCGNLcgG0Od8eTgs1OU6hjjlGQpcVwFg oNx8koDHcBvB2k1hzi3j1hLeLCLeXBxm0CbsJwdkm1auz8XY/hyV1QWYIVrkPKeiEGui ySCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FWHPv2wI; 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 e11-20020a170906504b00b006f407a163cesi8703371ejk.522.2022.05.07.15.13.52; Sat, 07 May 2022 15:14:17 -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=FWHPv2wI; 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 S1383866AbiEES0n (ORCPT + 99 others); Thu, 5 May 2022 14:26:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383227AbiEESTm (ORCPT ); Thu, 5 May 2022 14:19:42 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D79F5D676; Thu, 5 May 2022 11:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651774555; x=1683310555; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wCptZcUcsyZySNsXKqKhsEo8FgpHxpA5MijVVTkWO3g=; b=FWHPv2wIAiL3rH63zUqyWNNmuYSwhtZMIwbXtmMbXDuSIw1HFDZQ7972 mP4ovJmcS9lCVTG0JMhByUKonite8DiM9RXAFNQcZgMYHPWHXXmL/7Zz+ KS2MQXwW/rXD5MyW7iTD5Ljt7ZTXT3dheVCy6lRLZwVFloyi30fr+pQry 6gYrZhcOyM8JRwpZcAl5tc+NRholceyIRTeTgvxGAbZTdzR0dAeOIHMfB VliROIEo2KXZXSc69voVVYZYS8tB4lbtAvp5b8MTi/WDQNuu/LuW8cyMt vCee30FfcaQEzmCMIZwU0S+rVMiDDx26cRYb/aIWUQtXF2FN81FBx1jkS w==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="248113908" X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="248113908" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 11:15:51 -0700 X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="665083411" 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; 05 May 2022 11:15:51 -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 Subject: [RFC PATCH v6 076/104] KVM: x86: Assume timer IRQ was injected if APIC state is proteced Date: Thu, 5 May 2022 11:15:10 -0700 Message-Id: <5e167bdffa69ecd0d58b630036719c3a515ee5af.1651774250.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=-5.0 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_PASS,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 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 953b7f1d6257..f8e190da769f 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1577,8 +1577,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