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: 10111953 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 E557D60327 for ; Thu, 14 Dec 2017 12:30:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D14AF29B78 for ; Thu, 14 Dec 2017 12:30:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C625129C0F; Thu, 14 Dec 2017 12:30:49 +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 5CF9229B78 for ; Thu, 14 Dec 2017 12:30:49 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SW916IIZz8DOYRkF17GSY/bnG4K1Jp/HouA54O7bZ84=; b=sZpOCpEb73ljjv K9dbP3N4g2UGcJONFhJ2pFdRRcDXYlvx2ZElYDzjYoiE25LeVbNvsXrvS2+Qs/4a3mKrFl2+BnFNx Gl8AbDyhTnnf2qUofWMd5Y5m/KafA4dHRGdGBXP1JzO6lRIT3dzvedQobQmwETtYcRcjqte8YraqL g+Kq/OwV4Ia/CswexzwhETtMdBtiVL4BVaX+Yici3ZCWiiUVlQMidqS/MMYaiXUqW4fXMKih6aznS 9T0RcvpZWEmQQ04teMp2cTeAKjYevaCpsUx9nMH4wNG+yLnMLQ6BTrkSbcwHq+5ewkBL79agm3u2C st1TWMD1Lu0SrrNJ8BNQ==; 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 1ePSf1-0007aU-6R; Thu, 14 Dec 2017 12:30:47 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ePSew-0007YK-KF for linux-arm-kernel@lists.infradead.org; Thu, 14 Dec 2017 12:30:44 +0000 Received: by mail-wm0-x244.google.com with SMTP id f140so11077528wmd.2 for ; Thu, 14 Dec 2017 04:30:21 -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=exy6btcQ/qVYnjhrGgQn0vldAbH+jJgrts+BzStysalV0xFT1BHC3zto97l3NYqymR hHSNgoZ3XM5ID4aXGiiXlsjxrtKcjnAQ1h2bCapim+9ohuzVZ1HDrv5OX+Fo8enbb2Ow k/Ayz3DclyhSlxxwWRv9JJ+Xm4aKeCC467uXeY4+dMfZ9ASnLnDEUuSPXUfrGpvuYGVV nL4L8036hTj5u7vQ9MdmFUixoOOiGTex9NoDXGb1k8QmSXFIW0N0EN3kMj1MbwOegyv3 lAsTlzkefPElZwjxRytotZtslTWCfBlGBAZCTz1CMOgKBXI2dzAZ55ws3sPdkln3duhG 3T4g== X-Gm-Message-State: AKGB3mKU0G2R4RPj0q377/8eKr+CukzkzvhCPNKUoEfsakLQHsF3wTTS Yln96XJ5OhUiFwyBOzfTimlPtQ2qM4k= 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 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) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171214_043042_871651_05451BF2 X-CRM114-Status: GOOD ( 19.96 ) 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: Shih-Wei Li , Andrew Jones , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org 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 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;