From patchwork Fri Jan 27 01:04:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9540509 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 F3FE460429 for ; Fri, 27 Jan 2017 01:09:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E53192824F for ; Fri, 27 Jan 2017 01:09:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9F5E28306; Fri, 27 Jan 2017 01:09:27 +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.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable 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 8E7782824F for ; Fri, 27 Jan 2017 01:09:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754104AbdA0BIu (ORCPT ); Thu, 26 Jan 2017 20:08:50 -0500 Received: from outprodmail02.cc.columbia.edu ([128.59.72.51]:58104 "EHLO outprodmail02.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753004AbdA0BGZ (ORCPT ); Thu, 26 Jan 2017 20:06:25 -0500 Received: from hazelnut (hazelnut.cc.columbia.edu [128.59.213.250]) by outprodmail02.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v0R156HF063918 for ; Thu, 26 Jan 2017 20:05:11 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 313B985 for ; Thu, 26 Jan 2017 20:05:11 -0500 (EST) Received: from sendprodmail03.cc.columbia.edu (sendprodmail03.cc.columbia.edu [128.59.72.15]) by hazelnut (Postfix) with ESMTP id 2BCD986 for ; Thu, 26 Jan 2017 20:05:10 -0500 (EST) Received: from mail-qt0-f198.google.com (mail-qt0-f198.google.com [209.85.216.198]) by sendprodmail03.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v0R15A61035947 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 26 Jan 2017 20:05:10 -0500 Received: by mail-qt0-f198.google.com with SMTP id q3so256347980qtf.4 for ; Thu, 26 Jan 2017 17:05:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=k0zhaaVWiutxijalAwg65SJYQ1jV1s0RVb621RLiShE=; b=siJ5i/ogQSAU0g0HwjlJjIRsy65XWodOvtbXVEdlMdPBKGF9khcPu6LAUGREocElX2 1VUY+hlq3+arsPzBDtOOsIB++SHq5Q/k9bH1+APD2M4a6hJJtMlqhZ/UkaQ6BpdEgvma XSlY8lNZC4DIMiW71UL/zwDMbor2KM7bgKpyXnWpr8QDd1kzWUdV3DwpOlAGlcBpKOLJ m42DFhcQ7On7OBAWybGTNIJ3QEN80jmailJnkymUdBihRfPChH7YcZ9AcEO1w9lg6WF1 1MxMNvQ0b8W0mRilyx1JwS9jFXUixEDx8n2FcHMBb/iUexWY1vW+LCkHGmhh3myXtyDt E25A== X-Gm-Message-State: AIkVDXLgBSq0rSwTk9Md8pL2IuuQZTHTG4sJPvKbtkme+ibeZVVf0dfmRt0IAzFH5yDMjiy0JT/cip6y77RMWevZZO5Ps/DlRJu5JQCnMnLGoTJ7U8Z8FXxZzVudfHN2qAE/eQuBQll8QWM= X-Received: by 10.200.50.2 with SMTP id x2mr5278892qta.291.1485479109746; Thu, 26 Jan 2017 17:05:09 -0800 (PST) X-Received: by 10.200.50.2 with SMTP id x2mr5278877qta.291.1485479109503; Thu, 26 Jan 2017 17:05:09 -0800 (PST) Received: from jintack.cs.columbia.edu ([2001:18d8:ffff:16:21a:4aff:feaa:f900]) by smtp.gmail.com with ESMTPSA id f68sm2709538qkf.34.2017.01.26.17.05.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Jan 2017 17:05:09 -0800 (PST) From: Jintack Lim To: pbonzini@redhat.com, rkrcmar@redhat.com, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, andre.przywara@arm.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org Subject: [RFC v2 08/10] KVM: arm/arm64: Set up a background timer for the physical timer emulation Date: Thu, 26 Jan 2017 20:04:58 -0500 Message-Id: <1485479100-4966-9-git-send-email-jintack@cs.columbia.edu> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1485479100-4966-1-git-send-email-jintack@cs.columbia.edu> References: <1485479100-4966-1-git-send-email-jintack@cs.columbia.edu> X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.78 on 128.59.72.15 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Set a background timer for the EL1 physical timer emulation while VMs are running, so that VMs get the physical timer interrupts in a timely manner. Schedule the background timer on entry to the VM and cancel it on exit. This would not have any performance impact to the guest OSes that currently use the virtual timer since the physical timer is always not enabled. Signed-off-by: Jintack Lim --- virt/kvm/arm/arch_timer.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index d3925e2..b366bb2 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -247,6 +247,23 @@ static int kvm_timer_update_state(struct kvm_vcpu *vcpu) return 0; } +/* Schedule the background timer for the emulated timer. */ +static void kvm_timer_emulate(struct kvm_vcpu *vcpu, + struct arch_timer_context *timer_ctx) +{ + struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; + + if (kvm_timer_should_fire(vcpu, timer_ctx)) + return; + + if (!kvm_timer_irq_can_fire(timer_ctx)) + return; + + /* The timer has not yet expired, schedule a background timer */ + BUG_ON(timer_is_armed(timer)); + timer_arm(timer, kvm_timer_compute_delta(vcpu, timer_ctx)); +} + /* * Schedule the background timer before calling kvm_vcpu_block, so that this * thread is removed from its waitqueue and made runnable when there's a timer @@ -306,6 +323,9 @@ void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu) if (kvm_timer_update_state(vcpu)) return; + /* Set the background timer for the physical timer emulation. */ + kvm_timer_emulate(vcpu, vcpu_ptimer(vcpu)); + /* * If we enter the guest with the virtual input level to the VGIC * asserted, then we have already told the VGIC what we need to, and @@ -368,7 +388,11 @@ void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu) { struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; - BUG_ON(timer_is_armed(timer)); + /* + * This is to cancel the background timer for the physical timer + * emulation if it is set. + */ + timer_disarm(timer); /* * The guest could have modified the timer registers or the timer