From patchwork Thu Jun 30 00:52:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 9206387 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C4A1160757 for ; Thu, 30 Jun 2016 00:53:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7DC428462 for ; Thu, 30 Jun 2016 00:53:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACBF8284CE; Thu, 30 Jun 2016 00:53:56 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 3C8BE28462 for ; Thu, 30 Jun 2016 00:53:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751830AbcF3Ax2 (ORCPT ); Wed, 29 Jun 2016 20:53:28 -0400 Received: from mail-pa0-f68.google.com ([209.85.220.68]:36218 "EHLO mail-pa0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751601AbcF3Ax1 (ORCPT ); Wed, 29 Jun 2016 20:53:27 -0400 Received: by mail-pa0-f68.google.com with SMTP id av7so5682786pac.3; Wed, 29 Jun 2016 17:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Z/jhFOJP8OPyxyxrDkzcfNM7rJio2MDjR1IVu6zW8T4=; b=nf7jSVdOmkUXFpXgU9YaaIChmSYZF1P5V7mYGTXz3m9ETJaSgERk/6MM6VvUM1g3aE 06p8X0zqzk176NoEvFCC9syzva4TeB+vHhtph2+ztDjXkDurSwzWGCeOdeoahJrqlFcT OXDDgLSyEp78JMmPchnjaKTE6Dj6bv0/aP4+861EULN4INJyMTQGID/oU5cQV/uV78u4 /J4eXjsJNXCH+7/kF4N7Pco6/K6GMxAXwtwhMwy1Sz9wZW8Osot4v7EnZJX4p+Uanq96 ggdrOTGe5S+X+IcFsKUA2X11Lfz+fyKFmufxsakGf8hIUF38yznSewWNRr6uTGBuY7eF 3wJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Z/jhFOJP8OPyxyxrDkzcfNM7rJio2MDjR1IVu6zW8T4=; b=IXhqdJcksx/wbKMlGjPbMQhcpW83lQ1f+2sSicFNV44bnJ8mxlgUehOYf7tCVZUzu5 OQoU+FUAvAKgBJ8n9whMNK4OK9kKUrc954hyzesOL6XFiJtoYjYN8mnFMMsVw8SZMZ/a ooVFxsodlIEJnM2jtAShCtYMzrAgqzBExkfQ5HF1PwuJsyWCf1N8rIHauCcvPgJwipaa 7JqeNJ1A5a17Fys8PkQU/keF+Rnh4U+M+RGIaM9Z+2WXdWdpCKGxBxunWt6H+ibcDxgc pcuA2BOdTbcJRtGmps4zKcwyWNd8HoFq+nx8O2MjJKYuBZbuP/oY/S7J5dwbSnmb0qv4 toJg== X-Gm-Message-State: ALyK8tKp02Gx25jAAxjm75Y+063atKhOg8W4ONEyYlY8zc4YtPtUWw950ADwpIRvIYUQlg== X-Received: by 10.66.51.42 with SMTP id h10mr16598947pao.31.1467248006387; Wed, 29 Jun 2016 17:53:26 -0700 (PDT) Received: from kernel.kingsoft.cn ([219.141.176.227]) by smtp.gmail.com with ESMTPSA id d65sm643247pfa.45.2016.06.29.17.53.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Jun 2016 17:53:25 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Wanpeng Li , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Yunhong Jiang Subject: [PATCH v3 1/2] KVM: x86: introduce cancel_hv_tscdeadline Date: Thu, 30 Jun 2016 08:52:49 +0800 Message-Id: <1467247970-2986-1-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 1.9.1 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 Introduce cancel_hv_tscdeadline() to encapsulate preemption timer cancel stuff. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Yunhong Jiang Signed-off-by: Wanpeng Li --- arch/x86/kvm/lapic.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index fdc05ae..9c20ac1 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1349,14 +1349,19 @@ bool kvm_lapic_hv_timer_in_use(struct kvm_vcpu *vcpu) } EXPORT_SYMBOL_GPL(kvm_lapic_hv_timer_in_use); +static void cancel_hv_tscdeadline(struct kvm_lapic *apic) +{ + kvm_x86_ops->cancel_hv_timer(apic->vcpu); + apic->lapic_timer.hv_timer_in_use = false; +} + void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu) { struct kvm_lapic *apic = vcpu->arch.apic; WARN_ON(!apic->lapic_timer.hv_timer_in_use); WARN_ON(swait_active(&vcpu->wq)); - kvm_x86_ops->cancel_hv_timer(vcpu); - apic->lapic_timer.hv_timer_in_use = false; + cancel_hv_tscdeadline(apic); apic_timer_expired(apic); } EXPORT_SYMBOL_GPL(kvm_lapic_expired_hv_timer); @@ -1376,10 +1381,8 @@ void kvm_lapic_switch_to_hv_timer(struct kvm_vcpu *vcpu) hrtimer_cancel(&apic->lapic_timer.timer); /* In case the sw timer triggered in the window */ - if (atomic_read(&apic->lapic_timer.pending)) { - apic->lapic_timer.hv_timer_in_use = false; - kvm_x86_ops->cancel_hv_timer(apic->vcpu); - } + if (atomic_read(&apic->lapic_timer.pending)) + cancel_hv_tscdeadline(apic); } trace_kvm_hv_timer_state(vcpu->vcpu_id, apic->lapic_timer.hv_timer_in_use); @@ -1395,8 +1398,7 @@ void kvm_lapic_switch_to_sw_timer(struct kvm_vcpu *vcpu) if (!apic->lapic_timer.hv_timer_in_use) return; - kvm_x86_ops->cancel_hv_timer(vcpu); - apic->lapic_timer.hv_timer_in_use = false; + cancel_hv_tscdeadline(apic); if (atomic_read(&apic->lapic_timer.pending)) return;