From patchwork Tue Nov 7 10:47:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10046345 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 1949E60360 for ; Tue, 7 Nov 2017 10:48:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAAD62846F for ; Tue, 7 Nov 2017 10:48:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF50C29D1B; Tue, 7 Nov 2017 10:48:52 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 028BA2846F for ; Tue, 7 Nov 2017 10:48:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757402AbdKGKst (ORCPT ); Tue, 7 Nov 2017 05:48:49 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:56493 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757384AbdKGKsi (ORCPT ); Tue, 7 Nov 2017 05:48:38 -0500 Received: by mail-wm0-f68.google.com with SMTP id z3so2810391wme.5 for ; Tue, 07 Nov 2017 02:48:37 -0800 (PST) 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=fMQ4oNE55hiyoOwgXjfXD4GLpeWp7FnZbmjYAkziyDo=; b=hmNI6JslkPjAsP4mnX+z27rIiHZrPpYMEavgKIBBc7ltWo1p/oc9H77HO+0ZkYBPm4 ityaaKjlyk5IbzJxn6kzktiKHkqIJbdk7o1aReRp6+MtyGxR+ovZ8yAZ3LTt6iCOcxDm sMAPvmwH/Q3cpE5sS5qsGGma87Ojaps6bU4Ss= 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=fMQ4oNE55hiyoOwgXjfXD4GLpeWp7FnZbmjYAkziyDo=; b=n+2WH1wcZaMz9k47dAUpXrSrQ0pvaIcFfSjcmCl9ENNMg+SAqLhHMsrvjEz24wfe08 z9z/G7SeupHrp9Aqc3HrxhNRUtyldVPr7i00Tov4DNlKIjp67DkDPGaW12Jj5/WPf3Th PFVkgU1Q2kAvaBniRSnvrj6+meqNuKZSUhSic/W80jX6joYmwc/Omr5xHLtPY9uypeun EFY656T/XZBoHuVP1KuHB7ja23LJ9oUT9xgcoynmaYgBqz9EgpUzyhiYRuUDeX8Q2Nf2 gJgsKF0gshZpaXx5IhBjdykWbuI06AUJi5b3m2xZ2quHu4MZvo96HGF728TWiLxaBIap cEDg== X-Gm-Message-State: AMCzsaXdAsswKAPacfyb8k7WOyYDmMLY+/Y2fCc1lJ1LKlzMYc8wpp8p EY0po+6tCoz4WV0v5Rf7J91qoA== X-Google-Smtp-Source: ABhQp+SJ7RIMFZsFvWL9yZ4mH+W/o2ZnsZCckstpSUVHo1for7f77lQ3Ty/k9426k49r+XwWKOrHCQ== X-Received: by 10.80.180.18 with SMTP id b18mr24355265edh.136.1510051717019; Tue, 07 Nov 2017 02:48:37 -0800 (PST) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id q12sm1044958edj.29.2017.11.07.02.48.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Nov 2017 02:48:36 -0800 (PST) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: Marc Zyngier , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Christoffer Dall Subject: [PULL 19/26] arm/arm64: KVM: Load the timer state when enabling the timer Date: Tue, 7 Nov 2017 11:47:52 +0100 Message-Id: <20171107104800.30021-20-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171107104800.30021-1-christoffer.dall@linaro.org> References: <20171107104800.30021-1-christoffer.dall@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After being lazy with saving/restoring the timer state, we defer that work to vcpu_load and vcpu_put, which ensure that the timer state is loaded on the hardware timers whenever the VCPU runs. Unfortunately, we are failing to do that the first time vcpu_load() runs, because the timer has not yet been enabled at that time. As long as the initialized timer state matches what happens to be in the hardware (a disabled timer, because we never leave the timer screaming), this does not show up as a problem, but is nevertheless incorrect. The solution is simple; disable preemption while setting the timer to be enabled, and call the timer load function when first enabling the timer. Acked-by: Marc Zyngier Signed-off-by: Christoffer Dall --- virt/kvm/arm/arch_timer.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 2035cf251701..4db54ff08d9e 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -861,7 +861,11 @@ int kvm_timer_enable(struct kvm_vcpu *vcpu) return ret; no_vgic: + preempt_disable(); timer->enabled = 1; + kvm_timer_vcpu_load_vgic(vcpu); + preempt_enable(); + return 0; }