From patchwork Mon Dec 4 13:56:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10090313 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 549046056E for ; Mon, 4 Dec 2017 13:57:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39F1629035 for ; Mon, 4 Dec 2017 13:57:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E9DE2912F; Mon, 4 Dec 2017 13:57:47 +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=-2.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED, URIBL_DBL_ABUSE_SPAM 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 946B829035 for ; Mon, 4 Dec 2017 13:57:46 +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=zHJFWG4f3nm1w7ndnFcWw5Z2hcGJ+YHIu9ScbeOXkxw=; b=Q/ZBQTjN52bAJ7VqcBAh3HCd9Y ZdtBU9uL6mpGCg5bsMNo2N9KtsgQcD+5N+SLl8ggqB53FnywAgA3B5j1y1qgrUjiSvEMTR2HjRyJC e4KI39/JjZkWCJ/BQWOzY2yDR4RdVlnk1sJ0iJiAYFYqPhcCGMb9MYSq2sXV+Li2HE96SkjoOfOWn es0ELF8SmGr+nTkXX0IPo5ukbvygCYbnI3wsnR4mjN0eK42Vr5l9DDT9xd+tpcDAFrJfR7eZfzNF+ YUVPYfZymjgtpPhTaocEEXA1qmEEcuK79BeeL3735iY6allECPkNeO0Onzu2vCu34RdrNaE1bhhtG CMf9+7PQ==; 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 1eLrFi-0008Rg-0P; Mon, 04 Dec 2017 13:57:46 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eLrEz-0007aD-7b for linux-arm-kernel@lists.infradead.org; Mon, 04 Dec 2017 13:57:11 +0000 Received: by mail-wm0-x242.google.com with SMTP id f140so14429249wmd.2 for ; Mon, 04 Dec 2017 05:56:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=hkJmv4rWNDbA8IOd5reSJYs8etlLThS2tkha/5Xv1BA=; b=srNFFZ85AqM2UFbyoOjBMZaclO2BkP5X4tEmBTu6qeI/dlbB2fMMoUil1krQQ1uVly H+0cPXmvp7EPM8Rj9iFc95InH9YnZeZq79WUfC/6H6JgwnyWGnU1rHHfZSTjURcTKOxR onYzCACxSQy+spUFCMSoQi43anPBtOi64Rd/6/gu46rk6GQmvWaPXzUeSzbwxx3ScRx1 0JU/WSt0paPvb5Pl0Yn6N5rg6HACCPrjAhaVPxjrEt5BIQh6vahvKWKI1Di2a77bzQby v3ax/B85hBqc2fpnfjOBQYva4W+XGgrjT+1ASvA4EcAi3yxgPeGYWLVONF0xH8p/ugLR +Fhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=hkJmv4rWNDbA8IOd5reSJYs8etlLThS2tkha/5Xv1BA=; b=dvrSkeLiei7t/UWMgzAeCI0qj8r77wuLTzWlxsfiCayIXQBA++7GmAIRszCjlolXFT 4UvZWd07UmUvr0Ys5qhwHy9YG4LEndOMqeJe/FxRZITGXrJix2BS280LNzXCbIe96usZ WxmrpK+xBa11c+DzVx3w4scUrqGOn17U4PY6ankAurUbVlORNwVIBTrGiy1EGdVjzgHC GHUXhrqUUXR9b1ldGUrOyL429myBbsPeRAQML5cPTe/ZjEBkj4fOqDwsP76Ofav1HOzT PkFGsyj9ZKx0xePmvu04MTMZ8E0HedG70mMf72dcuEwsmdNRmFJzSUuWDIAh14+6f053 nybA== X-Gm-Message-State: AKGB3mKtZaukZdJppe+h6r+qM1z5durQdG1D4RF21cftIb4KRVflBh6i mM2YYNCRtdrQBhIuaPVJZInMIacGlrQ= X-Google-Smtp-Source: AGs4zMaNb1xVXq3aJoCJ5TdkcimX7zmlvxWxeztGR3/QUCQ5JK2Slrrl0TGCa91GEC2jIhiY6sXfxQ== X-Received: by 10.28.69.136 with SMTP id l8mr6805244wmi.19.1512395799254; Mon, 04 Dec 2017 05:56:39 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id o27sm12056103wro.9.2017.12.04.05.56.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Dec 2017 05:56:38 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 01/19] KVM: arm/arm64: Don't enable/disable physical timer access on VHE Date: Mon, 4 Dec 2017 14:56:19 +0100 Message-Id: <20171204135637.21620-2-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171204135637.21620-1-cdall@kernel.org> References: <20171204135637.21620-1-cdall@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171204_055702_702261_235EA41A X-CRM114-Status: GOOD ( 13.57 ) 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, linux-arm-kernel@lists.infradead.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 From: Christoffer Dall After the timer optimization rework we accidentally end up calling physical timer enable/disable functions on VHE systems, which is neither needed nor correct, since the CNTHCTL_EL2 register format is different when HCR_EL2.E2H is set. The CNTHCTL_EL2 is initialized when CPUs become online in kvm_timer_init_vhe() and we don't have to call these functions on VHE systems, which also allows us to inline the non-VHE functionality. Reported-by: Jintack Lim Signed-off-by: Christoffer Dall --- include/kvm/arm_arch_timer.h | 3 --- virt/kvm/arm/arch_timer.c | 6 ------ virt/kvm/arm/hyp/timer-sr.c | 48 ++++++++++++++++++-------------------------- 3 files changed, 20 insertions(+), 37 deletions(-) diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index 01ee473517e2..6e45608b2399 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h @@ -93,7 +93,4 @@ void kvm_timer_init_vhe(void); #define vcpu_vtimer(v) (&(v)->arch.timer_cpu.vtimer) #define vcpu_ptimer(v) (&(v)->arch.timer_cpu.ptimer) -void enable_el1_phys_timer_access(void); -void disable_el1_phys_timer_access(void); - #endif diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 4151250ce8da..190c99ed1b73 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -479,9 +479,6 @@ void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu) vtimer_restore_state(vcpu); - if (has_vhe()) - disable_el1_phys_timer_access(); - /* Set the background timer for the physical timer emulation. */ phys_timer_emulate(vcpu); } @@ -510,9 +507,6 @@ void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu) if (unlikely(!timer->enabled)) return; - if (has_vhe()) - enable_el1_phys_timer_access(); - vtimer_save_state(vcpu); /* diff --git a/virt/kvm/arm/hyp/timer-sr.c b/virt/kvm/arm/hyp/timer-sr.c index f39861639f08..f24404b3c8df 100644 --- a/virt/kvm/arm/hyp/timer-sr.c +++ b/virt/kvm/arm/hyp/timer-sr.c @@ -27,42 +27,34 @@ void __hyp_text __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high) write_sysreg(cntvoff, cntvoff_el2); } -void __hyp_text enable_el1_phys_timer_access(void) -{ - u64 val; - - /* Allow physical timer/counter access for the host */ - val = read_sysreg(cnthctl_el2); - val |= CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN; - write_sysreg(val, cnthctl_el2); -} - -void __hyp_text disable_el1_phys_timer_access(void) -{ - u64 val; - - /* - * Disallow physical timer access for the guest - * Physical counter access is allowed - */ - val = read_sysreg(cnthctl_el2); - val &= ~CNTHCTL_EL1PCEN; - val |= CNTHCTL_EL1PCTEN; - write_sysreg(val, cnthctl_el2); -} - void __hyp_text __timer_disable_traps(struct kvm_vcpu *vcpu) { /* * We don't need to do this for VHE since the host kernel runs in EL2 * with HCR_EL2.TGE ==1, which makes those bits have no impact. */ - if (!has_vhe()) - enable_el1_phys_timer_access(); + if (!has_vhe()) { + u64 val; + + /* Allow physical timer/counter access for the host */ + val = read_sysreg(cnthctl_el2); + val |= CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN; + write_sysreg(val, cnthctl_el2); + } } void __hyp_text __timer_enable_traps(struct kvm_vcpu *vcpu) { - if (!has_vhe()) - disable_el1_phys_timer_access(); + if (!has_vhe()) { + u64 val; + + /* + * Disallow physical timer access for the guest + * Physical counter access is allowed + */ + val = read_sysreg(cnthctl_el2); + val &= ~CNTHCTL_EL1PCEN; + val |= CNTHCTL_EL1PCTEN; + write_sysreg(val, cnthctl_el2); + } }