From patchwork Mon Nov 20 11:16:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10066327 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 BC055602B7 for ; Mon, 20 Nov 2017 11:17:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE26C2920F for ; Mon, 20 Nov 2017 11:17:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2AFE29238; Mon, 20 Nov 2017 11:17:06 +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 2F3252923B for ; Mon, 20 Nov 2017 11:17:05 +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: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:In-Reply-To: References:List-Owner; bh=TvoqW2V5e/6nU9Zg6T4AG905Gs9lTsYxssycGMH+0Xc=; b=ols K75TJ6dENMZjLbosUnryv+SjGeoyxawY3MPQQZ4PgpYkvPx8FkRrXIoP56YFUoFrnOCVHGWiYAjZC hJIMw3mh1IQjFOwJMKO7JEV8ghgvC6lkNnUpjKJk+6ZdUMfi0WRVjtCeUtH2jAr403wg0SQIytR0y IXudQCGeGR7xgil0f1fJo2Ngss4M8oUuOMVmFjzrTe3ROkq8pI5CqhuHUtwPN8phdu3ZrwlC9MkQT iPMjNAJSbQ/hXV/XYtvzUTJOJmWZJDJv40N7J6OIHUGTyOLIKdZ1vsFF9d3t/4K8ogy0nihyl0XC6 kg6cco1g3x9SThQeauHsSdD/mllnUgA==; 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 1eGk4W-00005V-T1; Mon, 20 Nov 2017 11:17:04 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eGk4K-0004HY-JL for linux-arm-kernel@lists.infradead.org; Mon, 20 Nov 2017 11:17:02 +0000 Received: by mail-wr0-x243.google.com with SMTP id 11so4377012wrb.6 for ; Mon, 20 Nov 2017 03:16:32 -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; bh=2H5nJMyClayczSYFGIm1RRxlPV3ufrTdU/cBFbYVBb0=; b=I7is9mfPWmjxqLqlkEaZP+5MaDbv52sQE5tRQNfHxZVMWklNdtfc7oQznNmwBixqjr JJTGGy/m+e7Jfw5BriS2bsGskaiKe+8e6+/TGRq1pZFIaQfjUj68N2TDTLVW0gYo/6dh BqTeJ/OGtEXai5xfGsEmszQWgZ12QXf44Px6s= 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; bh=2H5nJMyClayczSYFGIm1RRxlPV3ufrTdU/cBFbYVBb0=; b=Fsfys0eq2MCAI0k/fXRGAiQHAlIez32/tRAuzohu7dGKKK4WFAn6419h9eI9DvCqSw XQu9ClN4ucS8dJw/i2HK5ytuQ2EAawWGU002G8MBn3b9PnWyWffGxkUAkZNHtxNtgvQA +cfNbDcx4I+yqozkAoH2myiaEEHEslJCOr0QuldAEr1XGO2Y/+gk4HZsE0HkKAUsMX4M F/FAmSGYMGk+M48Yu+SeIxeKUjRNAr91zx/q5rLSeTIqF06kFaQewp3Mfh0DUy2nZMz8 eY3jPfnmHLpNqBCCynz0IM+oso09MxOc31p6NKQFRxltLMUuJtyK1WCFoqFBFUUh3npD bEkg== X-Gm-Message-State: AJaThX6KzotxkVqeZ5HOCrv4KET2y4r/C61wxF/cIM+ZjQwQfAg3XF9V XACylJnDEs6b1++3MdxY6g9EhQ== X-Google-Smtp-Source: AGs4zMalau50VN7jkqWk1oZCIgCJtJmRI288ebNFmIw74ZML2LYiBHx7TcsZGCedMKcmVrOkeTqM3g== X-Received: by 10.223.145.41 with SMTP id j38mr10062688wrj.133.1511176590606; Mon, 20 Nov 2017 03:16:30 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id 11sm11507855wmp.7.2017.11.20.03.16.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Nov 2017 03:16:29 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH] KVM: arm/arm64: Don't enable/disable physical timer access on VHE Date: Mon, 20 Nov 2017 12:16:37 +0100 Message-Id: <20171120111637.26215-1-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171120_031652_882253_F1F06124 X-CRM114-Status: GOOD ( 13.79 ) 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 , Jintack Lim , 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 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 Reviewed-by: Jintack Lim --- 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); + } }