From patchwork Fri Feb 3 15:20:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9554371 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 0C9A9602B7 for ; Fri, 3 Feb 2017 15:21:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0908E2808C for ; Fri, 3 Feb 2017 15:21:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1F1D283FC; Fri, 3 Feb 2017 15:21:48 +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=-1.9 required=2.0 tests=BAYES_00 autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 08D672808C for ; Fri, 3 Feb 2017 15:21:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cZfgH-0001ed-9Y; Fri, 03 Feb 2017 15:21:45 +0000 Received: from outprodmail02.cc.columbia.edu ([128.59.72.51]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cZffC-0008OK-2U for linux-arm-kernel@lists.infradead.org; Fri, 03 Feb 2017 15:20:43 +0000 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 v13FFLFh023249 for ; Fri, 3 Feb 2017 10:20:19 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 386E58A for ; Fri, 3 Feb 2017 10:20:19 -0500 (EST) Received: from sendprodmail01.cc.columbia.edu (sendprodmail01.cc.columbia.edu [128.59.72.13]) by hazelnut (Postfix) with ESMTP id 16DEF8A for ; Fri, 3 Feb 2017 10:20:19 -0500 (EST) Received: from mail-qk0-f197.google.com (mail-qk0-f197.google.com [209.85.220.197]) by sendprodmail01.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v13FKIEv035340 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 3 Feb 2017 10:20:18 -0500 Received: by mail-qk0-f197.google.com with SMTP id d201so640044qkg.2 for ; Fri, 03 Feb 2017 07:20:18 -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:cc:subject:date:message-id:in-reply-to :references; bh=YmUPuvLqR81G+tW64EOtnRXrKu6m8PVGnKMzdzXpgbY=; b=C+Mah/fD7sPVb4TZ3w8at5AcaRlQx7VfdO6dBjDN7ge3sr5AWx7w02pJsDkVlUpsOE SKbjxnKFTh55DvguZ993qs0tHC2hIs2/GL9jzKslwW2mKteG0uuK1khTQw5TPJxaIuCc 3pXk03cNMy70m/WrAITMm/KCdX1Os9BrFliYbJDEVi6C8Zr0hu9c8HhKy5Jp1lM3Hbhf SMeL2cgJl9TG8IibRuqWuTkrqXQdopi7nd+8CW5IDjg7F6s90VjKL4gFAk3NW+0rdlgb ZdDkK+D8y06smwgjb4pk4rPLoUjeaq68UjDJQBwcLVqHHNfM8o2dwDgTDg7CIceTRpB5 oZbw== X-Gm-Message-State: AIkVDXJ0P6516tPKDqne8NKB274C+tebTDRUgS0C9j7NddLdVogUXAUmQTUVsBmWogpkJq9njBVPjb+lKHHJw6MEV3HvAXUdcycyfMRCXdLAk9RAUM+oKkifBTaYpquvZXuJADTUWIyaDFdptIIQAWrrz/JbLWu5Bc8w7w== X-Received: by 10.200.35.150 with SMTP id q22mr14190332qtq.237.1486135218650; Fri, 03 Feb 2017 07:20:18 -0800 (PST) X-Received: by 10.200.35.150 with SMTP id q22mr14190306qtq.237.1486135218461; Fri, 03 Feb 2017 07:20:18 -0800 (PST) Received: from jintack.cs.columbia.edu ([2001:18d8:ffff:16:21a:4aff:feaa:f900]) by smtp.gmail.com with ESMTPSA id t35sm24462204qtc.40.2017.02.03.07.20.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Feb 2017 07:20:17 -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 v4 08/10] KVM: arm/arm64: Set up a background timer for the physical timer emulation Date: Fri, 3 Feb 2017 10:20:06 -0500 Message-Id: <1486135208-13415-9-git-send-email-jintack@cs.columbia.edu> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486135208-13415-1-git-send-email-jintack@cs.columbia.edu> References: <1486135208-13415-1-git-send-email-jintack@cs.columbia.edu> X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.78 on 128.59.72.13 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170203_072038_506947_7E210A9A X-CRM114-Status: GOOD ( 14.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jintack@cs.columbia.edu MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 Reviewed-by: Christoffer Dall --- virt/kvm/arm/arch_timer.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 0ea7452..33257b5 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -229,6 +229,22 @@ 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(timer_ctx)) + return; + + if (!kvm_timer_irq_can_fire(timer_ctx)) + return; + + /* The timer has not yet expired, schedule a background timer */ + timer_arm(timer, kvm_timer_compute_delta(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 @@ -286,6 +302,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 @@ -348,7 +367,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