Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1885345pxv; Fri, 2 Jul 2021 15:08:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0A6UXEOp6pNj6Vaq9URBo3IlwnmKxbDT5ZMpfPZJWWWcriPoEj87s1rmTR3rU7fXt8+LP X-Received: by 2002:aa7:dbc8:: with SMTP id v8mr1946006edt.242.1625263733045; Fri, 02 Jul 2021 15:08:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625263733; cv=none; d=google.com; s=arc-20160816; b=QJL6/zMyav8vuutqMInqhsQ8pCeOF7msbg3mHTVL4WZ119RyqkXYIWzW7i3x/hJ34w BJRKcjXHaJ+wVIPu/Dv3Jg7ZQwuC7ynwlnY8Zq8fYM6NDx1GN10hTNpGgSijnHqjNebH 7JEU3gnlYfxz/1BIlw5rS+kXc9D7xVeNp3BGv103YbIMUJR3+G3MipWlp70iwy4nF3B/ 68dv7qkojxIm1knLh+RU4c5UB9SI++dyhWgx93jH5+O8EXX6XHXDI/jzchizi4TKyPmJ xujQ7LTWP+XTzkceGJvT4EQcDEIt/bjwc7fXoRf60t1IRsK51gnDhlgsbUfRF4ZaAHtE Vdlw== 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; bh=rtRBTc8nRgI/9T/zx39lRtFdkGymMQmcCbv5Whlb7AI=; b=lvzpq6/qFD/a2V2PQarYB4Zd405Ghzmc+nsW3KHS6vyGYkazIEd6URcBctqtZoUii0 M1FZ283lQB3zsWdpWenO/6ySADB6gmlv49z+08mRtD1Eo8oHQdUCQTDhwrS3Fn+uwsjl tm28WpOCNV4MV6OqxCzmzVvOopbPB94tVMr4V4FexmBBKDHpzMdSFUd8fgwk9fE2qsG2 omjP1PO6tHlRtgM4THttH4HdBOK2KgZKlyTuCJREDasklVvbmXn/ckgiaGM492yeBNT9 r9wYvECuPaeL3ovk4vC3EE4C2n9Oujt7pcYirbsUW2dRDPX4jIjws+BUChjCuHJ75BoN QMMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e22si3985551edq.531.2021.07.02.15.08.30; Fri, 02 Jul 2021 15:08:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234146AbhGBWJQ (ORCPT + 99 others); Fri, 2 Jul 2021 18:09:16 -0400 Received: from mga12.intel.com ([192.55.52.136]:50201 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233160AbhGBWIA (ORCPT ); Fri, 2 Jul 2021 18:08:00 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10033"; a="188472751" X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="188472751" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:26 -0700 X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="642814798" 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; 02 Jul 2021 15:05:26 -0700 From: isaku.yamahata@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Sean Christopherson Subject: [RFC PATCH v2 38/69] KVM: x86: Add option to force LAPIC expiration wait Date: Fri, 2 Jul 2021 15:04:44 -0700 Message-Id: <357378fcb6e3e2becb6d4f00a5c3d2b00b2c566b.1625186503.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 Add an option to skip the IRR check in kvm_wait_lapic_expire(). This will be used by TDX to wait if there is an outstanding notification for a TD, i.e. a virtual interrupt is being triggered via posted interrupt processing. KVM TDX doesn't emulate PI processing, i.e. there will never be a bit set in IRR/ISR, so the default behavior for APICv of querying the IRR doesn't work as intended. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/x86/kvm/lapic.c | 4 ++-- arch/x86/kvm/lapic.h | 2 +- arch/x86/kvm/svm/svm.c | 2 +- arch/x86/kvm/vmx/vmx.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 977a704e3ff1..3cfc0485a46e 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1622,12 +1622,12 @@ static void __kvm_wait_lapic_expire(struct kvm_vcpu *vcpu) __wait_lapic_expire(vcpu, tsc_deadline - guest_tsc); } -void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu) +void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu, bool force_wait) { if (lapic_in_kernel(vcpu) && vcpu->arch.apic->lapic_timer.expired_tscdeadline && vcpu->arch.apic->lapic_timer.timer_advance_ns && - lapic_timer_int_injected(vcpu)) + (force_wait || lapic_timer_int_injected(vcpu))) __kvm_wait_lapic_expire(vcpu); } EXPORT_SYMBOL_GPL(kvm_wait_lapic_expire); diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index 997c45a5963a..2bd32d86ad6f 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -233,7 +233,7 @@ static inline int kvm_lapic_latched_init(struct kvm_vcpu *vcpu) bool kvm_apic_pending_eoi(struct kvm_vcpu *vcpu, int vector); -void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu); +void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu, bool force_wait); void kvm_bitmap_or_dest_vcpus(struct kvm *kvm, struct kvm_lapic_irq *irq, unsigned long *vcpu_bitmap); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index bcc3fc4872a3..b12bfdbc394b 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3774,7 +3774,7 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) clgi(); kvm_load_guest_xsave_state(vcpu); - kvm_wait_lapic_expire(vcpu); + kvm_wait_lapic_expire(vcpu, false); /* * If this vCPU has touched SPEC_CTRL, restore the guest's value if diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 36756a356704..7ce15a2c3490 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6727,7 +6727,7 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu) if (enable_preemption_timer) vmx_update_hv_timer(vcpu); - kvm_wait_lapic_expire(vcpu); + kvm_wait_lapic_expire(vcpu, false); /* * If this vCPU has touched SPEC_CTRL, restore the guest's value if -- 2.25.1