From patchwork Tue Feb 27 11:34:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10244897 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 9013460208 for ; Tue, 27 Feb 2018 11:36:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8526E28843 for ; Tue, 27 Feb 2018 11:36:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79C5428848; Tue, 27 Feb 2018 11:36:20 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 DEEE228843 for ; Tue, 27 Feb 2018 11:36:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932119AbeB0LgK (ORCPT ); Tue, 27 Feb 2018 06:36:10 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:37024 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932118AbeB0Le4 (ORCPT ); Tue, 27 Feb 2018 06:34:56 -0500 Received: by mail-wm0-f66.google.com with SMTP id 139so9997759wmn.2 for ; Tue, 27 Feb 2018 03:34:55 -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=qbiMtHWWFJUjAzCm6fqtzQPXMtZbUCk/SUwVI2PrAL8=; b=D/Qm8Gok8tm81jNEaYsRCa2i/MDTD8t15u8mmde5yCJDHD62d2uqFzugX7sTZl20ZI DuajNolc+Nzp/DZGAA71l8RnP1M7PtaEdFKMbljdDlFw6r5qdbNjn8AQoeZcz+g95gxJ jO8DWMtmLLCJx4eoVhuZYkvh3xvSE5069T1mSgOxRS0vXJYuen0/L8DuWv4DOEPYlPsW V+xT707Wxj1a7vVAvrgTHQoRLEXRn9JYrh/csK0+3rj9b26ySD05hwyJVkx/PkQUAACS 3sZ5cPckwYxeXvhouHcQMeHh5//uOizY0ZabqJG1MU06LkZRacXU2ktIIGzM65pyHDnG CZRg== 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=qbiMtHWWFJUjAzCm6fqtzQPXMtZbUCk/SUwVI2PrAL8=; b=FFjjF90hLgCBcwQSIIpOHjwBUmDbmJU5DI+9V6KjbjC9yw7hnjSizcWPM87bbUsy8S EeQ0AitJO97EznDY77EsDquDuPPx6Q49KLH8CaFOqE4UvqJqmHdWWo6wWXM3TSjxTrsW Wu8xQi0zkV9WJMfdKJa2ExKBdjZaze7EVhDl9cerilZTHeTtny9yHux/FK3zahQBl8SW mihWL4WuzvTmcrdB+Er+hWC0Mc6zwrzWwI/oiZ7n8F/v6bwSps/VNO1zoYAwAPmCcnQh kMcld5dFzVXxP/XwLcL9RF7z7shhOkWRzpXePQXC78b0RHfe3SXWJ58ti9Hi9LozWiuk bm1w== X-Gm-Message-State: APf1xPDoCadA9qqPqtzyjLJE0IMHL+GCSoksMyL/hMlU1hx66oKuCNmi q0TfdpUqDvTZZC2fgFrNJnT0yw== X-Google-Smtp-Source: AG47ELvRqCIqT6yuCdQgLzPyX9P6d/6IshGkMosNlLZsxfiZ7SqtAAsxVzP+L5lK34dlWRARCBDkMA== X-Received: by 10.80.224.205 with SMTP id j13mr5999274edl.304.1519731294982; Tue, 27 Feb 2018 03:34:54 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id m1sm9176786ede.39.2018.02.27.03.34.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 03:34:54 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Marc Zyngier , Andrew Jones , Shih-Wei Li , Dave Martin , Julien Grall , Tomasz Nowicki , Yury Norov Subject: [PATCH v5 16/40] KVM: arm64: Remove noop calls to timer save/restore from VHE switch Date: Tue, 27 Feb 2018 12:34:05 +0100 Message-Id: <20180227113429.637-17-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180227113429.637-1-cdall@kernel.org> References: <20180227113429.637-1-cdall@kernel.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christoffer Dall The VHE switch function calls __timer_enable_traps and __timer_disable_traps which don't do anything on VHE systems. Therefore, simply remove these calls from the VHE switch function and make the functions non-conditional as they are now only called from the non-VHE switch path. Acked-by: Marc Zyngier Reviewed-by: Andrew Jones Signed-off-by: Christoffer Dall --- Notes: Changes since v2: - Added comment explaining the timer enable/disable functions are for !VHE only. arch/arm64/kvm/hyp/switch.c | 2 -- virt/kvm/arm/hyp/timer-sr.c | 44 ++++++++++++++++++++++---------------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 9ffd802e775d..307f8c1fcc2f 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -379,7 +379,6 @@ int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) __activate_vm(vcpu->kvm); __vgic_restore_state(vcpu); - __timer_enable_traps(vcpu); /* * We must restore the 32-bit state before the sysregs, thanks @@ -400,7 +399,6 @@ int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) __sysreg_save_guest_state(guest_ctxt); __sysreg32_save_state(vcpu); - __timer_disable_traps(vcpu); __vgic_save_state(vcpu); __deactivate_traps(vcpu); diff --git a/virt/kvm/arm/hyp/timer-sr.c b/virt/kvm/arm/hyp/timer-sr.c index f24404b3c8df..77754a62eb0c 100644 --- a/virt/kvm/arm/hyp/timer-sr.c +++ b/virt/kvm/arm/hyp/timer-sr.c @@ -27,34 +27,34 @@ void __hyp_text __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high) write_sysreg(cntvoff, cntvoff_el2); } +/* + * Should only be called on non-VHE systems. + * VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe(). + */ 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()) { - u64 val; + 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); - } + /* Allow physical timer/counter access for the host */ + val = read_sysreg(cnthctl_el2); + val |= CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN; + write_sysreg(val, cnthctl_el2); } +/* + * Should only be called on non-VHE systems. + * VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe(). + */ void __hyp_text __timer_enable_traps(struct kvm_vcpu *vcpu) { - if (!has_vhe()) { - u64 val; + 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); - } + /* + * 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); }