From patchwork Fri Jun 21 09:40:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11009303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB5C91398 for ; Fri, 21 Jun 2019 09:41:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAE40289A6 for ; Fri, 21 Jun 2019 09:41:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF344289E5; Fri, 21 Jun 2019 09:41:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60F8D289A6 for ; Fri, 21 Jun 2019 09:41:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726920AbfFUJlf (ORCPT ); Fri, 21 Jun 2019 05:41:35 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34080 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726877AbfFUJkV (ORCPT ); Fri, 21 Jun 2019 05:40:21 -0400 Received: by mail-pf1-f195.google.com with SMTP id c85so3324146pfc.1; Fri, 21 Jun 2019 02:40:21 -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=gDChq3jgrlh7Kfl67z51Bq3UYV+aDXpvLz2pr3LXsbw=; b=atUeVU1wcczoU76Kdq0ubtl5EaLRaarzaAxHhV7CRiTol2lTgAi9mSfuHgTZ4jKcj0 jWsm59MMmrpQlZaBYrKadRnDSwL6g0pmpPvaQtwuaR6FC3AZ+mSoKRamYX4T8dGWFWQH XTjaJUe0QI7NHZcmtnAQthuYuXr5FeKtPUNEqo6E2SYRKGV5I2om1c8raJLtJlcKKCGu +KCqV1Auk6nxjztT0Izd9sbJnH3S74UFGKxP00k2HT883OVeZkzArgneusEK8A4+RO7c oNkB5OOftcpimbjwsuXTAAZ8VK2LneXxrWqyuw6QdVDA36ixe73J6xaF41jOmcSNErN9 rXfA== 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=gDChq3jgrlh7Kfl67z51Bq3UYV+aDXpvLz2pr3LXsbw=; b=FZMW3GkllWkTb3eF/zqt4/LPMIVRIBzmTG7IdqgEUPFnoewUNrTpRneaDvudfhxpt+ oBbjjvZVXqj6vwy62x4KwqvUjWbZ02WqMqu0yhrUEgcHFBxfdOcXPevZLkxCYJZeoGrZ 1eL9UNN3PDvpRXmt6y9IYOUEr0BwSDU15In5KcWkUKpjNmmeDAcf1Wubxws0EK2zPVm0 Mw6czHqFIi4dIc8H+1PxEbYBP+yXqy6yoqnnjZHzPU0oA+OHFqQQVzCKuucmBWGNKL2p 4Ouj02Ax8toe/DXkpbW6pAc/KceipuDbfvZcYf06oPlJUN/RWmY7SE19JbRB/yitrnYv Yung== X-Gm-Message-State: APjAAAWELRfHiG3io65i8yuZv87dhMEXX5n5/NRhMnTuhnxo2PxRsSmH sfH9HRcUsjv83v7R1PWtZkXpV2NW X-Google-Smtp-Source: APXvYqzSpDiVbBYFbXVJ82vVhV16mKsR/7Exr86GibnvfdCZ6k7SBKf0ewTsP0MSq+vCZSjvt2AhHQ== X-Received: by 2002:a17:90a:22ef:: with SMTP id s102mr5601135pjc.2.1561110021153; Fri, 21 Jun 2019 02:40:21 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.123]) by smtp.googlemail.com with ESMTPSA id y14sm1999506pjr.13.2019.06.21.02.40.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Jun 2019 02:40:20 -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?b?UmFkaW0gS3LEjW3DocWZ?= , Marcelo Tosatti Subject: [PATCH v5 4/4] KVM: LAPIC: Don't inject already-expired timer via posted interrupt Date: Fri, 21 Jun 2019 17:40:02 +0800 Message-Id: <1561110002-4438-5-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1561110002-4438-1-git-send-email-wanpengli@tencent.com> References: <1561110002-4438-1-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wanpeng Li already-expired timer interrupt can be injected to guest when vCPU who arms the lapic timer re-vmentry, don't posted inject in this case. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Marcelo Tosatti Signed-off-by: Wanpeng Li --- arch/x86/kvm/lapic.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index ae575c0..7cd95ea 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1452,7 +1452,7 @@ static void kvm_apic_inject_pending_timer_irqs(struct kvm_lapic *apic) } } -static void apic_timer_expired(struct kvm_lapic *apic) +static void apic_timer_expired(struct kvm_lapic *apic, bool can_pi_inject) { struct kvm_vcpu *vcpu = apic->vcpu; struct swait_queue_head *q = &vcpu->wq; @@ -1464,7 +1464,7 @@ static void apic_timer_expired(struct kvm_lapic *apic) if (apic_lvtt_tscdeadline(apic) || ktimer->hv_timer_in_use) ktimer->expired_tscdeadline = ktimer->tscdeadline; - if (posted_interrupt_inject_timer(apic->vcpu)) { + if (can_pi_inject && 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); @@ -1607,7 +1607,7 @@ static void start_sw_tscdeadline(struct kvm_lapic *apic) expire = ktime_sub_ns(expire, ktimer->timer_advance_ns); hrtimer_start(&ktimer->timer, expire, HRTIMER_MODE_ABS); } else - apic_timer_expired(apic); + apic_timer_expired(apic, false); local_irq_restore(flags); } @@ -1697,7 +1697,7 @@ static void start_sw_period(struct kvm_lapic *apic) if (ktime_after(ktime_get(), apic->lapic_timer.target_expiration)) { - apic_timer_expired(apic); + apic_timer_expired(apic, false); if (apic_lvtt_oneshot(apic)) return; @@ -1759,7 +1759,7 @@ static bool start_hv_timer(struct kvm_lapic *apic) if (atomic_read(&ktimer->pending)) { cancel_hv_timer(apic); } else if (expired) { - apic_timer_expired(apic); + apic_timer_expired(apic, false); cancel_hv_timer(apic); } } @@ -1809,7 +1809,7 @@ void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu) goto out; WARN_ON(swait_active(&vcpu->wq)); cancel_hv_timer(apic); - apic_timer_expired(apic); + apic_timer_expired(apic, false); if (apic_lvtt_period(apic) && apic->lapic_timer.period) { advance_periodic_target_expiration(apic); @@ -2312,7 +2312,7 @@ static enum hrtimer_restart apic_timer_fn(struct hrtimer *data) struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer); struct kvm_lapic *apic = container_of(ktimer, struct kvm_lapic, lapic_timer); - apic_timer_expired(apic); + apic_timer_expired(apic, true); if (lapic_is_periodic(apic)) { advance_periodic_target_expiration(apic);