From patchwork Mon Jul 17 14:27:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9845293 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 1C4A260386 for ; Mon, 17 Jul 2017 14:29:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EE2628509 for ; Mon, 17 Jul 2017 14:29:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 038FC2851E; Mon, 17 Jul 2017 14:29:12 +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,DKIM_SIGNED, DKIM_VALID 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 7710628509 for ; Mon, 17 Jul 2017 14:29:11 +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=L+5zs0HnKqBPFtBq4jMcJrt3LnVeEnmLpM5BpFLECN8=; b=SI26ztYp8yVjiYfoq3WoZs8KeH 6SFbzL7ZDGxW7kGCi0fqmPmTCQnR4a/yLV0qJl97uTpLGaHbaFZKIAQ0gGdHGYoRwiQ5P2w0cHMq0 TTflMSILC4KmpUR4bFr7dd4+Le6OfAZjCD5poe67n7eL5J1VMbcMZAVoic7z5C0UfFiLbX4ZtopJG 8KYtX9IhQxA1h8CCGYEPKFd8UshfLqmXkOyf1VvuhK981pLW0KC/PoIzI2342KMyhAy0ckCiPH6u0 A0M61NEGXjNJL1slPuWK2qGFw3CxNDSqQJ8fZ8OSp9CIT+WGCA1B4Y/VUmWQ3ArOD3RwcINV2qwMq r5IvvHYw==; 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 1dX71I-0002Z4-NL; Mon, 17 Jul 2017 14:29:08 +0000 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dX703-0001LW-K5 for linux-arm-kernel@lists.infradead.org; Mon, 17 Jul 2017 14:28:01 +0000 Received: by mail-wm0-x231.google.com with SMTP id t70so17257841wmt.1 for ; Mon, 17 Jul 2017 07:27:32 -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=bPL/Djk7Y8WBeTddW38LhnZR+TpAdofjIJiCWEKKxLY=; b=eoZt/v/9Z+QkoeApDQoDXux4mfdXfVZRcQHQTMFjd07zpqGFsnjhdUHpPGoB7aFx4H 8m1kbpSqBB0OzcS8VYvGzvvu8nqWXyaCpqJNfNZvQWcHWEiQZlSQIkCc6QLk7GE7H7y8 Hgg+zRxFZp6z9f200QgSmz/1weRkIExEHM6N4= 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=bPL/Djk7Y8WBeTddW38LhnZR+TpAdofjIJiCWEKKxLY=; b=g77xzHBeUg3QtZMOCE1DlSJREYUMRG81Fapav5a1CKAbee9lRROFzljoduHUUKuNy8 ZxQh6wyBz1RUIyJBb15rEX31CnFpb+zvM/19PG/Pz/FPcQHLWfXiqhkC+5FYcnmK2XMj jwuJTm3+u4N/ghnpG1Di+5VwsvKhTnUg1SQNKb+ATVG5fv/67o6rQR4IBN10zdetvCRO sOOaPcklXn7NviISA7jkAubh1woZnjgfPNrRbzXLrXlTcuPIUolZfxmqotW8XLlO4ST5 UpgmYyPGsyjD7k3aqF0cA9TVHptSbt4R6e6DDDIIfIrZzxR6UaJYjm7UYkxpqEXmymFJ bM8w== X-Gm-Message-State: AIVw111l5CjNgarC8UAvsEla+omOMBhN3XBg3ejW13VzmrQwVTcc7pn9 Ot+wv2Yp0hESCAiO X-Received: by 10.80.145.198 with SMTP id h6mr17382427eda.108.1500301650924; Mon, 17 Jul 2017 07:27:30 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id b30sm9428952edd.6.2017.07.17.07.27.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Jul 2017 07:27:30 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH v2 06/19] KVM: arm/arm64: Make timer_arm and timer_disarm helpers more generic Date: Mon, 17 Jul 2017 16:27:05 +0200 Message-Id: <20170717142718.13853-7-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170717142718.13853-1-cdall@linaro.org> References: <20170717142718.13853-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170717_072752_362429_D69768F3 X-CRM114-Status: GOOD ( 15.67 ) 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: Marc Zyngier , Christoffer Dall , kvm@vger.kernel.org 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 We are about to add an additional soft timer to the arch timer state for a VCPU and would like to be able to reuse the functions to program and cancel a timer, so we make them slightly more generic and rename to make it more clear that these functions work on soft timers and not the hardware resource that this code is managing. Signed-off-by: Christoffer Dall --- virt/kvm/arm/arch_timer.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 8e89d63..871d8ae 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -56,26 +56,22 @@ u64 kvm_phys_timer_read(void) return timecounter->cc->read(timecounter->cc); } -static bool timer_is_armed(struct arch_timer_cpu *timer) +static bool soft_timer_is_armed(struct arch_timer_cpu *timer) { return timer->armed; } -/* timer_arm: as in "arm the timer", not as in ARM the company */ -static void timer_arm(struct arch_timer_cpu *timer, u64 ns) +static void soft_timer_start(struct hrtimer *hrt, u64 ns) { - timer->armed = true; - hrtimer_start(&timer->timer, ktime_add_ns(ktime_get(), ns), + hrtimer_start(hrt, ktime_add_ns(ktime_get(), ns), HRTIMER_MODE_ABS); } -static void timer_disarm(struct arch_timer_cpu *timer) +static void soft_timer_cancel(struct hrtimer *hrt, struct work_struct *work) { - if (timer_is_armed(timer)) { - hrtimer_cancel(&timer->timer); - cancel_work_sync(&timer->expired); - timer->armed = false; - } + hrtimer_cancel(hrt); + if (work) + cancel_work_sync(work); } static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id) @@ -271,7 +267,7 @@ static void kvm_timer_emulate(struct kvm_vcpu *vcpu, return; /* The timer has not yet expired, schedule a background timer */ - timer_arm(timer, kvm_timer_compute_delta(timer_ctx)); + soft_timer_start(&timer->timer, kvm_timer_compute_delta(timer_ctx)); } /* @@ -285,7 +281,7 @@ void kvm_timer_schedule(struct kvm_vcpu *vcpu) struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); - BUG_ON(timer_is_armed(timer)); + BUG_ON(soft_timer_is_armed(timer)); /* * No need to schedule a background timer if any guest timer has @@ -306,13 +302,16 @@ void kvm_timer_schedule(struct kvm_vcpu *vcpu) * The guest timers have not yet expired, schedule a background timer. * Set the earliest expiration time among the guest timers. */ - timer_arm(timer, kvm_timer_earliest_exp(vcpu)); + timer->armed = true; + soft_timer_start(&timer->timer, kvm_timer_earliest_exp(vcpu)); } void kvm_timer_unschedule(struct kvm_vcpu *vcpu) { struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; - timer_disarm(timer); + + soft_timer_cancel(&timer->timer, &timer->expired); + timer->armed = false; } static void kvm_timer_flush_hwstate_vgic(struct kvm_vcpu *vcpu) @@ -448,7 +447,7 @@ void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu) * This is to cancel the background timer for the physical timer * emulation if it is set. */ - timer_disarm(timer); + soft_timer_cancel(&timer->timer, &timer->expired); /* * The guest could have modified the timer registers or the timer @@ -615,7 +614,7 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); - timer_disarm(timer); + soft_timer_cancel(&timer->timer, &timer->expired); kvm_vgic_unmap_phys_irq(vcpu, vtimer->irq.irq); }