From patchwork Sat Sep 23 00:42:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9967359 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 D25C5600C5 for ; Sat, 23 Sep 2017 00:52:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3EC529A7D for ; Sat, 23 Sep 2017 00:52:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8AE529A7F; Sat, 23 Sep 2017 00:52:50 +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 3A94529A7D for ; Sat, 23 Sep 2017 00:52:50 +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=wKyp4AjMH993UY3LDLRKfCA27EwTvVPICSjSAHeIDY8=; b=q3813FiBkwVupkL0rcANZzUXMv TsHd4GO3eoaLNAoO7pLvyIewiwZDO/3wCvFQ0otqkae/0pysUZRfKPnw4fanML352GdEU3R0DPjp8 aqKvsmeHtsxtxm9IwrRdRbQL2fmxTap9PwVR+qzgA4OvD+gxGzXkkJO4WXglLbl/lWPeivmxpazm9 1UJzNyJDR9AOi3grhCYSSkBWj3lTW+G7S74vg5kncy9whwgpEv6Y1FrjQ97oIMxfrqChrI/i7qQ8G 3nT8NWY83791rmsvjQZzHSGEg4qpBnvgkfN7fhyT75pL8FXL69u0JbDKQd6Wu0lC0leNIdavubOJU xd05+bsA==; 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 1dvYgV-0004AA-OA; Sat, 23 Sep 2017 00:52:43 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dvYXC-00047e-43 for linux-arm-kernel@bombadil.infradead.org; Sat, 23 Sep 2017 00:43:06 +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=QJpoqFvx+TSH/5CS37Oz0hvyyRP9AxzHtS1pvI/JHUU=; b=XPcTneCc50CMfOq44C1UzVc3B czi2pK/GcTPGNbiCuVGLYWdjrSgc+sDtW8xFi9+V5ZF/LXVBtsBgrSncAXceroauc1iZhay+rC/Cw mdldKGnMRBjC7+dY0X1+EN3wCtpbSj++g8zmJCDCw480WgrRtm7dzcPhwfEcXN4pQm7Gs8j7ETao6 6BK2PCfU3v5W3sz8a+IINSYxY2euXbIWz23gqLTrJM55uCyWQ6a1CKUjWkVGnFX0ffUYEP44+Bk5f 6+tQod7GlXp3Yl5bstE6zXwXq0z5q929pgR7UtuEDoxiH2wIzkFj9XzhpmR7ni8XFFpnn/yCDGHte kV+BcR0Hw==; Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dvYX5-0004u8-A9 for linux-arm-kernel@lists.infradead.org; Sat, 23 Sep 2017 00:43:04 +0000 Received: by mail-wm0-x232.google.com with SMTP id m72so3844536wmc.0 for ; Fri, 22 Sep 2017 17:42:38 -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=QJpoqFvx+TSH/5CS37Oz0hvyyRP9AxzHtS1pvI/JHUU=; b=c/tF9AlfBxpvmOaROebnq1t3Wt7bic+y+H56Rl+bvVChKI0D1Egj/A0eJ91bTu9SaE TbUgInhbEtCZwUt56JbRf0hxTOuEZLBCRSE6lBekzIhNHgz6lszXYaNxA6FfKNrh+Ng7 WFvkt8YYT8OGSsEFhFJovF/2wf5te3VlU0OPM= 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=QJpoqFvx+TSH/5CS37Oz0hvyyRP9AxzHtS1pvI/JHUU=; b=uYBq9QK4F9xyOo6DpHyfP7w68l4KIifPC7lSrd2ELLcoUmFRG3DPFTKyI6PYH/uqf8 CJs1Pd41zh4XYA/n6z9squeP9J7fmnMpCtfFT0DDFMJENapN9N6sJX3zTC2E6DlYThEX 4A45Rt1Q7XhdAnOBO6yu+HRNJ6XQksRejtmSbe04snt/D0V7HsBZ1R/ToqpgPv1ZhEd+ da9cTfEAkLrCkddDC/yJFJjwS+23aWxAQIdjwvEfH/3hFrdFvxs2IYWzwxFsnt4WNY4r rn2I7678/T0mbgrMH4G1Th+L1O7aY0IIm8bFkor6G9/Kjq3VfBc8VZA5ijXl7TDR+LVl jynQ== X-Gm-Message-State: AHPjjUgsGfHU9O+Z8Fv+87/C8Iad2MdxjJLIRCB0OwGLZ+kvt5ylQCbB QtQkqjL/HVHZkBUjGaZaMkSrXw== X-Google-Smtp-Source: AOwi7QC0JDLvQwzql2YfF1JJVE1Erp5x0yuAZAvRKFPMIy1qmgdSK2QZMFBsD3FAB8FTXWMxOAlAUg== X-Received: by 10.80.212.9 with SMTP id t9mr6645529edh.240.1506127354512; Fri, 22 Sep 2017 17:42:34 -0700 (PDT) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id c25sm646085edb.57.2017.09.22.17.42.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Sep 2017 17:42:33 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 20/20] KVM: arm/arm64: Rework kvm_timer_should_fire Date: Sat, 23 Sep 2017 02:42:07 +0200 Message-Id: <20170923004207.22356-21-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170923004207.22356-1-cdall@linaro.org> References: <20170923004207.22356-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170923_014259_462516_AAE636AF X-CRM114-Status: GOOD ( 21.09 ) 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 , Catalin Marinas , Will Deacon , kvm@vger.kernel.org, Christoffer Dall 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 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 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)