From patchwork Mon Jul 17 14:27:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9845371 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 68B2860392 for ; Mon, 17 Jul 2017 14:50:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B30B27F2B for ; Mon, 17 Jul 2017 14:50:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FF1727F91; Mon, 17 Jul 2017 14:50:18 +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 D9E452844E for ; Mon, 17 Jul 2017 14:50:17 +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=0VSvFA/spVOnc4wGPeabyx/dZ4hwRAfJBTfDOJceges=; b=XSwZaBvndC5G3wGy8nN6zlRm1Z OJ9znLkp5wmXTchexel4cdg2N/i5x6z492Z5L9ShJFJ/am50uhsF+XtJX/IiQ2giucH0iNN/6XNEC DXkHRl64gigyOWXDtmfTrF+i0bPB7xl9LOMU62a+NhDhImyXY55yxWDIxpX2WcTAUfhfAYQCHJfjG WYqgh1C6J5hGLbIHaHvXX3rKpuG80C08t6+AvaGyRa8dwXmp/tpWXMDcWijSWzXjdJAAHxH7JDnEI 472vlpD8xvEnzEtOoFg53KwH7LCT3S25LrNouobJfhTmDW0Isp5cMFUQzgoOkWT4fuh12GGqmyUwB 3u6TLWEQ==; 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 1dX7Lh-0001op-Ug; Mon, 17 Jul 2017 14:50:13 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dX7Ku-0008Gx-2i for linux-arm-kernel@bombadil.infradead.org; Mon, 17 Jul 2017 14:49:24 +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=erdHowNFd99ahHjAHfeymYtmSRdMUKeK1Gs2iCCZHBM=; b=qLcanMFUIqnc4waPvGZT9kphW jO/Tv0xDMzBbADYwBJB/yd5oNi9taORI91kM+K5WHlUSkqEgU1KCR+jqwgS+TPucZ206tp6bIp5At hjJ91NyNxbavyC94DqzDntCdeIOZlKkmOFPBIYNvrW6xC3/j9E6Nx5MUVpiIIYUsGDsn3Rj/jG1O4 lo4QMb1ztk2uUW0mhFuW+xps5nSYjFVezWvXqPYWDHnjm1dc5/jHlDmrh/mSsEBNm+vU5BXc5CxxM pWt+Ryyz/eK2voBqmiZeT+tYJOISc+XEueVuc6MuzXQ8GPaWt2IcAjtlo/iUvR5lwrbwbkMJxm+Ht R8/naPknQ==; Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dX70G-0001on-JE for linux-arm-kernel@lists.infradead.org; Mon, 17 Jul 2017 14:28:07 +0000 Received: by mail-wm0-x22f.google.com with SMTP id w126so77801730wme.0 for ; Mon, 17 Jul 2017 07:27:44 -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=erdHowNFd99ahHjAHfeymYtmSRdMUKeK1Gs2iCCZHBM=; b=FZStr6AivkIGy0ugvy7GCM8dnI8dGjAMMmGjOCpXiqdX0qU0VH3o6MlmZLh+8Uq+P+ YQLQhrKOaae2kDK/SpO+Ion5xN3iXcKZUpkuP//Vk9ODKtJj6hQ0k5veh20lWsgmPugc 0u6wn1WQzhSYwR9FPVu+8QTufUzHLdsvrz+l8= 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=erdHowNFd99ahHjAHfeymYtmSRdMUKeK1Gs2iCCZHBM=; b=DYMEZUUV5HG1LOQbC19WhXq2JvXhd+RUQCBp8IQi3OMX86vhxuFBaZTwsIDcubjxLo g4W0JJmkFY6ZYshDuwLyhw5WdPDhF8W798ki6w5wU0c0ZJssctQpHJMMH/rqpDb/jxHD KogSzoCLdhZhMHbzHBVRwWzhtcGI25keJwY9i28ZhhskykgaGUw6tTbPnQt9RzXe4cTi 73S3Gnu//YXwajEimCh6K2dl30Gn2q5T2uYBrczfSCh5h8GpjpmwBNwUKOqbYRCBiOAs 1gKizhfZWEd489MOv06Qtx1xLPG7BQ7HnZPFejazjlUz5zoxih5Ztq4aGxgw1XKfd6Lt 2Pug== X-Gm-Message-State: AIVw11344s7LaIVlxltROPqnGLQIOmz9joRD3QXVmKn9E7C0hk4ffPBl Wu4367hICOp9n/XMvl7YOg== X-Received: by 10.80.135.175 with SMTP id a44mr17726002eda.90.1500301663342; Mon, 17 Jul 2017 07:27:43 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Jul 2017 07:27:42 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH v2 19/19] KVM: arm/arm64: Rework kvm_timer_should_fire Date: Mon, 17 Jul 2017 16:27:18 +0200 Message-Id: <20170717142718.13853-20-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_152804_646173_CFCDCD94 X-CRM114-Status: GOOD ( 20.54 ) 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 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 --- 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 af29563..250db34 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h @@ -73,7 +73,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 f92459a..1d0cd3a 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) { @@ -223,7 +224,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; @@ -236,6 +237,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 6322605..1ea9980 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)