From patchwork Fri Oct 27 08:34:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10029429 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 09CAD60249 for ; Fri, 27 Oct 2017 08:52:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE54928EC6 for ; Fri, 27 Oct 2017 08:52:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E241028F02; Fri, 27 Oct 2017 08:52:28 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED 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 6BAF628EC6 for ; Fri, 27 Oct 2017 08:52:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Mk2Yy0E1r53kLAn2PbH/Ek8Ktf/CmESWFE2+jFfT/v8=; b=GzM9oC4kSdbWovAUPfl2S/2agz pbYYYm7/LL5NiKPJUP9YJyoFPb5ia7cUyV7U3PbfroYBLzAonsm6WJElivgYRpZlij0FAPrMaoR3m A5GbxOc0068c6p4JtJ1gDFYIpxWjztSNDhoZmgVHMaLaJWEY3I8vq7T3pU/tp8k6AJqyvDtu5E57g A1Zwy1A1PHLXTAgkY1VWm/GQCqT2pDrwLK7v18hls7uejtho0wXSaSeqJjb8HBgdgpGae5WSkqJMb rTbye2qx/ndn/fqGUeZD25i3DL/IB7CmrJn+5H8zF3NNeTgxRwnseTJ8m5gWrAb8llFelTd4aLTUw l2K4hrzA==; 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 1e80NO-0002X1-R3; Fri, 27 Oct 2017 08:52:26 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e80NN-0002P4-HR for linux-arm-kernel@bombadil.infradead.org; Fri, 27 Oct 2017 08:52:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=puYm+rYrtsVjx8oPqLmTRK1ObuB4V0k00pNxm24dy7Q=; b=ZtWTlrS6wKe3iff7WMyXoURk1 KYG6o7OvE4mTFjnhleBIRQyV3vgBZL9XwjndGdvEz8MvSKVhf6omo0RVu3wOQ6V6OkZq0kGFTZBR7 3KCwU0h0gQKW7z2BysjclKwB/4DL2GQXgJlFzg4T2sddQ1AXMwUBEaAFsL9UUfDPLj0q1MCI3aXek 3KPusLD0jsCOdlkTI92575prf/hQ6bY1bnrtT4pZaW3dwE8WipXGELO6d9iVFhqhVkgicOBf9LKKM ElNZcfLfr24msBU0bhoBtvJaE8aNEQuueKlkg4UZmnL3mhveMTtYRGRigz6wUbh3iFgMZDaK+7kNn aQ6YY/xfA==; Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e808c-0006lT-00 for linux-arm-kernel@lists.infradead.org; Fri, 27 Oct 2017 08:37:14 +0000 Received: by mail-lf0-x241.google.com with SMTP id b190so6538448lfg.9 for ; Fri, 27 Oct 2017 01:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=puYm+rYrtsVjx8oPqLmTRK1ObuB4V0k00pNxm24dy7Q=; b=eum2p80/Jw0IcJMD/wtGOEFONlh4EPBX80y8LR+dtJpMkqRYmLsC4jvX3li8Z8G99M 7AT7wrWorci6B8pdk6Atauxi0WXOVUyKs6eYbKygVUsAnWbA9Q3bCL1BAB8ytTqblk0/ ryyZoF9b1zkH/M1yOLRmLf3uaSRJWjYo4+LGs= 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=puYm+rYrtsVjx8oPqLmTRK1ObuB4V0k00pNxm24dy7Q=; b=H0+PGDJJF3Xv20ynvdlbEMuaE9EBDLHonwH1k+MnHQ3vSJeW+dSdKxcFICTYoZQ2hb ijKSIf+TU5ndnfe+SydjnLEzbkheYiqoynGMJgJKhHBlSE1SEBs9s0rLhVpiBLtk6rbK skKRhbL/ts+NGJONO/IZ2SvQ3Nw3YHokD+7mZ/gceanLv5ezILCXPAk5O4qs8P7ZCXYN guEdo5Bvaf+lH0kuqvnVQ8rt14XEYt50Y9mlx/2KMVPl0L2pUZIFmVI8NJiXI5Twnp9F In5mkc+WLpjl/cFiH8/Yn5SR4OOfSrrXJ9BeFf3NOeJ6/PMDnYSNPaub6tiQytFA1HaR TqBQ== X-Gm-Message-State: AMCzsaX4Hen/BH3GIvW6x87Q5IRkAQ++BGKkBTJnFZykox9FofbKUvwC GHHFTa8CIKM9a2Y6LvZDNF5retmkAPs= X-Google-Smtp-Source: ABhQp+SfTBxLaZkOuiGp62OUlhRoQy2syZbt9HHQqaD7OqPXRUmbrLqgdPhOfxCY5EFt8v+/+78dHA== X-Received: by 10.46.85.16 with SMTP id j16mr11450118ljb.109.1509093408480; Fri, 27 Oct 2017 01:36:48 -0700 (PDT) Received: from localhost.localdomain (212.27.17.163.bredband.3.dk. [212.27.17.163]) by smtp.gmail.com with ESMTPSA id d204sm1471957lfe.73.2017.10.27.01.36.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Oct 2017 01:36:47 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 20/20] KVM: arm/arm64: Rework kvm_timer_should_fire Date: Fri, 27 Oct 2017 10:34:41 +0200 Message-Id: <1509093281-15225-21-git-send-email-cdall@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509093281-15225-1-git-send-email-cdall@linaro.org> References: <1509093281-15225-1-git-send-email-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171027_093710_294231_F71BDC34 X-CRM114-Status: GOOD ( 20.93 ) 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: Christoffer Dall , kvm@vger.kernel.org, Marc Zyngier , Catalin Marinas , Will Deacon , Eric Auger 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 kvm_timer_should_fire() can be called in two different situations from the kvm_vcpu_block(). The first case is before calling kvm_timer_schedule(), used for wait polling, and in this case the VCPU thread is running and the timer state is loaded onto the hardware so all we have to do is check if the virtual interrupt lines are asserted, becasue the timer interrupt handler functions will raise those lines as appropriate. The second case is inside the wait loop of kvm_vcpu_block(), where we have already called kvm_timer_schedule() and therefore the hardware will be disabled and the software view of the timer state is up to date (timer->loaded is false), and so we can simply check if the timer should fire by looking at the software state. Signed-off-by: Christoffer Dall Reviewed-by: Marc Zyngier --- include/kvm/arm_arch_timer.h | 3 ++- virt/kvm/arm/arch_timer.c | 22 +++++++++++++++++++++- virt/kvm/arm/arm.c | 3 +-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index 2352f3a..01ee473 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h @@ -78,7 +78,8 @@ int kvm_arm_timer_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr); int kvm_arm_timer_get_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr); int kvm_arm_timer_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr); -bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx); +bool kvm_timer_is_pending(struct kvm_vcpu *vcpu); + void kvm_timer_schedule(struct kvm_vcpu *vcpu); void kvm_timer_unschedule(struct kvm_vcpu *vcpu); diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 53d9bd4..2035cf2 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -49,6 +49,7 @@ static const struct kvm_irq_level default_vtimer_irq = { static bool kvm_timer_irq_can_fire(struct arch_timer_context *timer_ctx); static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level, struct arch_timer_context *timer_ctx); +static bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx); u64 kvm_phys_timer_read(void) { @@ -226,7 +227,7 @@ static enum hrtimer_restart kvm_phys_timer_expire(struct hrtimer *hrt) return HRTIMER_NORESTART; } -bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx) +static bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx) { u64 cval, now; @@ -239,6 +240,25 @@ bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx) return cval <= now; } +bool kvm_timer_is_pending(struct kvm_vcpu *vcpu) +{ + struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); + struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); + + if (vtimer->irq.level || ptimer->irq.level) + return true; + + /* + * When this is called from withing the wait loop of kvm_vcpu_block(), + * the software view of the timer state is up to date (timer->loaded + * is false), and so we can simply check if the timer should fire now. + */ + if (!vtimer->loaded && kvm_timer_should_fire(vtimer)) + return true; + + return kvm_timer_should_fire(ptimer); +} + /* * Reflect the timer output level into the kvm_run structure */ diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index 14c50d1..bc126fb 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -307,8 +307,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) { - return kvm_timer_should_fire(vcpu_vtimer(vcpu)) || - kvm_timer_should_fire(vcpu_ptimer(vcpu)); + return kvm_timer_is_pending(vcpu); } void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu)