Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3431557iog; Mon, 27 Jun 2022 16:15:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sjXmK7RJ2mpFQVbWNtgBido8DvT+aKfu3qUrX1CGyb9T2axbnWohW7hMz+diYwaErjdYnl X-Received: by 2002:aa7:9823:0:b0:525:15b1:3297 with SMTP id q3-20020aa79823000000b0052515b13297mr434112pfl.13.1656371730442; Mon, 27 Jun 2022 16:15:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656371730; cv=none; d=google.com; s=arc-20160816; b=EF+8o557GT8b1JmKpzgZqUoWamG1qIXxFJ9C9AIMn4LjmNuwyfMr/X+FLDTT9JLs9e PmE+1ap+umo/svLRo/ggncCds+PDaKDQVGose46QtsQvuWq9Olt4L/BE1rpLJl/xsfu3 PfzlPvhDMrCbm9DLEnZpq1BrOdKXSVefEuBjduE579c676l791Wh+25NrWiJsxEpaVYX pZVFAZrfIAm63ukrC5Vs21FL8fIHe7P5wVpzEv/MGTQuaSMjcU4sUR9iq62m1R8UFXtR aa5EwwSMN5Sa+ldHdPYKM4opneMYtTTLIVgWIysA+2TcNUTqqzTS56wUiF2cZthcjTCW Neeg== 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=nGPQDZKDUiSzrpFKtmQ40jwlwbBFkJDYms1tFpQGJ5Y=; b=JID05BSMwdsl7WPE4k+1a579f1iCeEd4UGoP8hiliQtQOq4Bt+J9zdHQUNSmoz/0va XTKwODmUlsxAFW+7lq3rhdYm1AsdgZm4W3YZcwcPtZYpiXbdKmhiGvWHtRbzr1xRESVm oVIZlbrZmUCOrWfWCEjNOaTYr7SYzekiq074F7AIPMUSBF1ES4Mymeo8cxVpPDL058Sn czFr67Ur83MvyoY6pQon7APM2dQPqsLWQGC5VsUVCfS9RF8CKmYd5vIMk0oG2kxijsID IMp4cLOw6scq0AN/7Nf6hkFTnxygc+fa8/z9s8EX3R/qOItVEm4+rtJqkft94Xjl9ZKD acUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ggw5WfDd; 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 j4-20020a633c04000000b0040d4bd5d708si15977724pga.848.2022.06.27.16.15.18; Mon, 27 Jun 2022 16:15:30 -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=ggw5WfDd; 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 S242193AbiF0V7Q (ORCPT + 99 others); Mon, 27 Jun 2022 17:59:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241553AbiF0Vzq (ORCPT ); Mon, 27 Jun 2022 17:55:46 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B38B71114A; Mon, 27 Jun 2022 14:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656366903; x=1687902903; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yzehMGTZgz4slH2Wlmj2VzOPlB1rDEa+xprmlhmf7Vc=; b=ggw5WfDdorOZp0pVM3LQ2JgV6sO2mgMU1txPXpKZdvGcN2wJzFk0O5LW MA7jlGvBQrjF4xj3BSCJSCR4itS77ftNMvFlCGQfFUqzzJEfba7yeC9Go N3cbeNyiLESHauCJZKbQ8DPnKlChHy2RgEIxb8hxf7yJdeKixcevB9X6g QZ5uuIMh/h8OQnXI04jRQb5tTXtbD11SuEM7jMedcx+wdr1NV2esdnBpu /bnZjJkrYbSJ0dolBv1Ng2V90yznxs0D2v2ffspf6bLiotFD2CFIGdWTb dXjHxpZAxVybiBrSvNpKcaWaZLqsdKQVdtD2bAAHuyv5f5uIQh+hhKA+2 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="279116119" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="279116119" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:54:59 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="657863681" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:54:59 -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 , Sean Christopherson Subject: [PATCH v7 075/102] KVM: x86: Assume timer IRQ was injected if APIC state is proteced Date: Mon, 27 Jun 2022 14:54:07 -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=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 c85ed9f6a8c9..707f1ff90f8a 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1578,8 +1578,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