From patchwork Thu Dec 14 12:30:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10111951 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 9C59660327 for ; Thu, 14 Dec 2017 12:30:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88967297D3 for ; Thu, 14 Dec 2017 12:30:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B8A229868; Thu, 14 Dec 2017 12:30: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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 DD7D2297D3 for ; Thu, 14 Dec 2017 12:30:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751839AbdLNMaW (ORCPT ); Thu, 14 Dec 2017 07:30:22 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:41846 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751719AbdLNMaV (ORCPT ); Thu, 14 Dec 2017 07:30:21 -0500 Received: by mail-wm0-f66.google.com with SMTP id g75so11068337wme.0 for ; Thu, 14 Dec 2017 04:30:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=vyvmKKjXPgZWELUFv5Lml5DxutE1suRDc+oLpWDCVkY=; b=dZ7NAFNqdBqpB4yVN1y4jHLsbiooT6t28qeQwCU/u+rcYl6gKF0lfnz18QKGI6kwWR yQ5oF6omTRkx2ftykBrz0buGZo9uf3PkcPJe6PjHRI/jC/qzjJkuKKDcC9anlNuFmWXf jsKxUiRjW9TK6OIijb4RRQs6Ki/tB2LfNRm8M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=vyvmKKjXPgZWELUFv5Lml5DxutE1suRDc+oLpWDCVkY=; b=SrG7Fia3q0TFauzX4YBzhpo/c625MBa1Ur1nAHo18br9ba1Sof3497lHDSGa7EMVIi e+DSJAvY1Yd5QdzLzKFmNQLaHWS3rlGxzVWKfyFT3ArlpixNZmL79l1X8fWx1Bc0mDAs ZLfYJyQxAU8RWDe4XrsUg7EHn+t110YaeOD73VgzBSP0Fb633m8prunn/RxgqY3Eb9aO h4GZ43AdMpKk6eyRxdC/wd4nzDam+j+3LbAuZnJLiLNgecksKXPXJzv78kf8J9kd8b0h DiHXglNkYi3snGyY9qkFsPnqF6Kg4jHLrvTAuyIYRrloYWCx7kbzFlA/gbMESoYGoVc9 ztaQ== X-Gm-Message-State: AKGB3mLxb64qeluHulS9olv8dPbklJQvJgErXkz/rw38whtogTgBlUxS ExBZsDQ+Sn7lSRq7iBkhD3zg2w== X-Google-Smtp-Source: ACJfBouRZ5xf+HGHf3TIKnYiJqFHDrsk9xUXDWwUd6p1pOr+72fyXLF2gumPj/j1JSLaqHvGIdX5Dw== X-Received: by 10.80.161.37 with SMTP id 34mr12067706edj.15.1513254619989; Thu, 14 Dec 2017 04:30:19 -0800 (PST) Received: from localhost (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id f16sm3532099edj.65.2017.12.14.04.30.18 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 14 Dec 2017 04:30:18 -0800 (PST) Date: Thu, 14 Dec 2017 13:30:13 +0100 From: Christoffer Dall To: Marc Zyngier Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Shih-Wei Li , Andrew Jones Subject: Re: [PATCH v2 14/36] KVM: arm64: Remove noop calls to timer save/restore from VHE switch Message-ID: <20171214123013.GT910@cbox> References: <20171207170630.592-1-christoffer.dall@linaro.org> <20171207170630.592-15-christoffer.dall@linaro.org> <76009e9a-0518-6b0c-c1f4-9fc5ce6a1138@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <76009e9a-0518-6b0c-c1f4-9fc5ce6a1138@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Dec 11, 2017 at 10:02:58AM +0000, Marc Zyngier wrote: > On 07/12/17 17:06, Christoffer Dall wrote: > > 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. > > > > Signed-off-by: Christoffer Dall > > --- > > arch/arm64/kvm/hyp/switch.c | 2 -- > > virt/kvm/arm/hyp/timer-sr.c | 36 ++++++++++++++---------------------- > > 2 files changed, 14 insertions(+), 24 deletions(-) > > > > diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c > > index e783e2371b7c..09aafa0470f7 100644 > > --- a/arch/arm64/kvm/hyp/switch.c > > +++ b/arch/arm64/kvm/hyp/switch.c > > @@ -358,7 +358,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 > > @@ -377,7 +376,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..752b37f9133c 100644 > > --- a/virt/kvm/arm/hyp/timer-sr.c > > +++ b/virt/kvm/arm/hyp/timer-sr.c > > @@ -29,32 +29,24 @@ void __hyp_text __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high) > > > > 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); > > } > > > > 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); > > } > > > > Since we're not testing for !VHE anymore, can you add a small comment > saying that these two function are for the benefit of !VHE only and > shouldn't be called on VHE? Yes, absolutely: > > Otherwise, > > Acked-by: Marc Zyngier > Thanks, -Christoffer diff --git a/virt/kvm/arm/hyp/timer-sr.c b/virt/kvm/arm/hyp/timer-sr.c index 752b37f9133c..77754a62eb0c 100644 --- a/virt/kvm/arm/hyp/timer-sr.c +++ b/virt/kvm/arm/hyp/timer-sr.c @@ -27,6 +27,10 @@ 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) { u64 val; @@ -37,6 +41,10 @@ void __hyp_text __timer_disable_traps(struct kvm_vcpu *vcpu) 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) { u64 val;