From patchwork Sun Oct 29 01:48:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10031207 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 584C060249 for ; Sun, 29 Oct 2017 01:49:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 468D2287BE for ; Sun, 29 Oct 2017 01:49:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37DF62879D; Sun, 29 Oct 2017 01:49:55 +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=ham 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 A942F28789 for ; Sun, 29 Oct 2017 01:49:54 +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=myTX6XnpqsySkRIURaJxsNTcC24P0/QejRmmdi3+4yk=; b=ITQh/H+83ZWebAVYHLDWzjCJdV thjL9xf1a4zdbE8mK6oeWBmDY07+C+Y9QzUl224ckkoAz/XuW/6aiBDU+OUqcuyTHgDi+3XYabKk9 6wvcSx3JLI4NDhFr3DjKyEjh5fORZ7AeCoMcglT1pgWsNUALTLCfHp/tWhG4efFTXUcuqNHZqg5Bz ny+A57kVosGKTRGgmCrMDxSGpoHr2whleNtaCxt43pjDBsC6nlrtfrFk07+FLhWjwqXKRkNJhWXhl MS2xu4c6S+JLmay3eqlGYb9HnEKpvGp5SyfnS/jQVcHUOYl6okh7JjVznTeMJgVOCOTJF6Aw4JfOH junCA7mA==; 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 1e8cjQ-00054J-D5; Sun, 29 Oct 2017 01:49:44 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e8cjM-00053C-RA for linux-arm-kernel@lists.infradead.org; Sun, 29 Oct 2017 01:49:42 +0000 Received: by mail-lf0-x241.google.com with SMTP id g70so11096454lfl.3 for ; Sat, 28 Oct 2017 18:49:18 -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=ex/VijpFdLv3rJcS4cEAdMlV/ad+SLBQP5ZBrWNj4DU=; b=bMGGqBPNOn+8ZA9oBEGneTx18IagFUKJ+vgUZMjGlX4ch3gs8sIDaQW5IgtI1QpCo8 rURYqRHAY6b0LzRux6t4rweSgbe+3fI9niYU2VB52zxemxe1TTtQ5/B0fv22DA6AfkJu Y55CcsBBv8QLIp1WhgSvBGQMAoHprslc/68EI= 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=ex/VijpFdLv3rJcS4cEAdMlV/ad+SLBQP5ZBrWNj4DU=; b=iHjL8+sypVlrYXWHDFvsc311FbgQHml829hSf0U3eFHSVAE99xyFCc84mziNcDk4lG U8tdYP4tZhwFHh3FbEs2042YqtLV25RJpIFj8oHzpH7gzjwiXOFgKaABjD0Dv6QL0Hvq 298PUrUn2WnZTdE33RaxOouADXerhjNC46LDY/bx7phgd8j7yEqKtpdn8EZz6KVa1syB FpHtoRGnv1DHrrnJGQvu0jpu8bNcthIyZEZ2iONE3doROO3ninCP4PVIWGbfw5KPWV41 Bc8ZJ8Kde5yzC3p6DF+1t7+s6fa8EnCb5b20jXc/bHnGg7CCpfKYD482IuqcF971E7Cg kihw== X-Gm-Message-State: AMCzsaWK9azb6HGA1SzsmF7lK2N+7LCp8VYSNUH9w8FsUh7srfFudM+u zAQdKJdarDaikuDfL/vZPeCQgg== X-Google-Smtp-Source: ABhQp+QxtNxqjDvHwnDh6D4OM594IO03gfO0+NlUxpntvx5nKIwhYpHrLZQ5vdlptNMg7i7IlBMscg== X-Received: by 10.46.99.86 with SMTP id x83mr2033811ljb.161.1509241755993; Sat, 28 Oct 2017 18:49:15 -0700 (PDT) Received: from localhost.localdomain (212.27.17.10.bredband.3.dk. [212.27.17.10]) by smtp.gmail.com with ESMTPSA id i13sm2106843lfa.44.2017.10.28.18.49.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 28 Oct 2017 18:49:15 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 21/20] arm/arm64: KVM: Load the timer state when enabling the timer Date: Sun, 29 Oct 2017 02:48:56 +0100 Message-Id: <1509241736-99913-1-git-send-email-christoffer.dall@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-20171028_184941_068393_918C1E4D X-CRM114-Status: GOOD ( 11.59 ) 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: kvm@vger.kernel.org, Marc Zyngier , Catalin Marinas , Will Deacon , Eric Auger , 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 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. Signed-off-by: Christoffer Dall Acked-by: Marc Zyngier --- 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 2035cf2..4db54ff 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; }