Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7926263ybi; Thu, 6 Jun 2019 03:57:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkoKyuzoFDSjsFw7vMhSJJS3CFOOOH/wDEiRFVRxyAy4syE6bIT2w892J4FGEflFnDDIHy X-Received: by 2002:a63:4d0f:: with SMTP id a15mr2893454pgb.59.1559818631366; Thu, 06 Jun 2019 03:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559818631; cv=none; d=google.com; s=arc-20160816; b=NpqwRR3R3bz6nncU525Av+z+sTVmI71WYW2tVIlkMfuvt/A1Ae09oBeCcwfx2IkG2c HMXZKy8Kb4pLw85SZiGpr+WEkbWIegWtt4czWarGK93T0SZ9rlCA1lBr7wa7EvPuhJ76 QnNnfqG25x0CrWn3Y14ffaGoZLO7W/wDGmBEk/kWVvMpnWiSJn3ncc2O0X/tJ7qqDxYL qY0siMYI8As9NREeIt0MkZ1V8E0jAkShvQpMySbRGcNROH77sKlMAAJpYOkLdHzSB6Gw 8KHfCKXFMBJCB8xk2QSmlHkUI+fUsU+IHexJU/yuZISbkLz59IIFTBuOD7V6xZZf+U8v DI9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=u11NQoOcVc3KEqCmRt6p0L2NADGM3isejFoGnzfSN6E=; b=wjaHvYR95QIGaSdMwWWkD99MNKcLXkuK1jOPyhIRyfYPX5hRlGQuWCjxEjGvgAY5J9 YZokyv9OLO+abOAf23ssmHfSzLc0LBpuHXeW9nyesDVcXmNUUymsPds9XA4/zG8928M4 zl/8kxqTEFrLhjRLU9lCvsHsvTb+OSjKCA1WKja9g8YxSHW28QALPfp8xg5oDf5bJV9Q 3wyU/kwDA70pmTPZsjh4uyTznuriSNWcn31aGYs6tZR6ExpLQ0gtuS61s1fL7kmHzX7o mwABv43T/LEFYldNEUeWfARUcG5wi+wKd/Qe01QXBORGMv5hgie82V1PF7YJ2/a0cbhH CIGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CTpIPwBk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8si1586276pjp.78.2019.06.06.03.56.53; Thu, 06 Jun 2019 03:57:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CTpIPwBk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727504AbfFFKzk (ORCPT + 99 others); Thu, 6 Jun 2019 06:55:40 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:39801 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726040AbfFFKzk (ORCPT ); Thu, 6 Jun 2019 06:55:40 -0400 Received: by mail-pg1-f195.google.com with SMTP id 196so1148585pgc.6; Thu, 06 Jun 2019 03:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u11NQoOcVc3KEqCmRt6p0L2NADGM3isejFoGnzfSN6E=; b=CTpIPwBkWIu2kbKtsD3xwmvvC02dqEo8yUPXjFCyPCiFjWT6ZsYSdkZ+PG/g/sHnzG K0FStLpYv8QELGLHzuLfljfsgIOfG2+tXg2xXxXGCT5Ef0Ddr3HTXjBABHo+olQBUr6i yrAkl7JZ1oDPOYV0awiDLxXbJRZ/opHNKYDGXzRlEKvxEFDU3t82lbRx8kkk9DsdYifg gcNFM/9e8MLK7KWachFnFSyZftwWG+TTOJRIwCMHGm0NhsjA6vvuvZ4i8nfuX8lLTWdC hxnPC2qH7xNqp1BJoN55t/CADJPg5EnCdSKUEBx1dJAoPGtc2cduOY/TaycxMNz7L+00 Q83w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u11NQoOcVc3KEqCmRt6p0L2NADGM3isejFoGnzfSN6E=; b=eJeHODtCnAj71NEsKkucccCmtZNUxUnFsCyNxpCGcY3Tc2G9MDKKxNw2J+1ucf9inW Wk4JVYLTTl1HlwUX95GCSBCmVZ6g0Ely6Z92/2m3xs0OlNdL69R4YyYRNXxqlz+uBLhV k2ZBb5AnwpP5d0ZXdmVsGs6LZYacDKar+lFP7hDPSc3oQ7vCfmt1a4XkqDSLNjSZLjyO aQ0UmRGg3xnYbFHktUyC9V9673S4hyk+hMsexWvXRGjctKzzL4kSVfVdxNrINs1DwkSj NlQgiJQlNICv2TrAkq751akSjzJguO0yPkhYf2LyjNwZXgy2yWx/sHy/AHfhhroFLxtC Zx6w== X-Gm-Message-State: APjAAAXafwRqKNoPMSyEH9h/pBdF6HTZYo8PR9Bf1DIlvoPiPCu/1Sgq aeAp/pccH0MeYnFhnybuJJf+7QPn X-Received: by 2002:a62:b609:: with SMTP id j9mr38392045pff.145.1559818539414; Thu, 06 Jun 2019 03:55:39 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.123]) by smtp.googlemail.com with ESMTPSA id d10sm4340213pgh.43.2019.06.06.03.55.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Jun 2019 03:55:38 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PATCH v2 4/3] KVM: LAPIC: add advance timer support to pi_inject_timer Date: Thu, 6 Jun 2019 18:55:33 +0800 Message-Id: <1559818533-20529-1-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559799086-13912-4-git-send-email-wanpengli@tencent.com> References: <1559799086-13912-4-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li Wait before calling posted-interrupt deliver function directly to add advance timer support to pi_inject_timer. Cc: Paolo Bonzini Cc: Radim Krčmář Signed-off-by: Wanpeng Li --- arch/x86/kvm/lapic.c | 6 ++++-- arch/x86/kvm/lapic.h | 2 +- arch/x86/kvm/svm.c | 2 +- arch/x86/kvm/vmx/vmx.c | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index a3e4ca8..9581817 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1470,6 +1470,8 @@ static void apic_timer_expired(struct kvm_lapic *apic) return; if (unlikely(can_posted_interrupt_inject_timer(apic->vcpu))) { + if (apic->lapic_timer.timer_advance_ns) + kvm_wait_lapic_expire(vcpu, true); kvm_apic_inject_pending_timer_irqs(apic); return; } @@ -1561,7 +1563,7 @@ static inline void adjust_lapic_timer_advance(struct kvm_vcpu *vcpu, apic->lapic_timer.timer_advance_ns = timer_advance_ns; } -void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu) +void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu, bool pi_inject) { struct kvm_lapic *apic = vcpu->arch.apic; u64 guest_tsc, tsc_deadline; @@ -1569,7 +1571,7 @@ void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu) if (apic->lapic_timer.expired_tscdeadline == 0) return; - if (!lapic_timer_int_injected(vcpu)) + if (!lapic_timer_int_injected(vcpu) && !pi_inject) return; tsc_deadline = apic->lapic_timer.expired_tscdeadline; diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index f974a3d..16f0500 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -220,7 +220,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 pi_inject); bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *irq, struct kvm_vcpu **dest_vcpu); diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 302cb40..049ba64 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -5648,7 +5648,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu) if (lapic_in_kernel(vcpu) && vcpu->arch.apic->lapic_timer.timer_advance_ns) - 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 da24f18..302bac4 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6447,7 +6447,7 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu) if (lapic_in_kernel(vcpu) && vcpu->arch.apic->lapic_timer.timer_advance_ns) - 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.7.4