From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB6A2C43461 for ; Fri, 9 Apr 2021 17:19:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 806B46115B for ; Fri, 9 Apr 2021 17:19:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234049AbhDIRTN (ORCPT ); Fri, 9 Apr 2021 13:19:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:60524 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232395AbhDIRTN (ORCPT ); Fri, 9 Apr 2021 13:19:13 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 184006113A; Fri, 9 Apr 2021 17:19:00 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lUumY-006aai-5g; Fri, 09 Apr 2021 18:18:58 +0100 Date: Fri, 09 Apr 2021 18:18:57 +0100 Message-ID: <87im4vnzpa.wl-maz@kernel.org> From: Marc Zyngier To: Alexandru Elisei Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, James Morse , Suzuki K Poulose , kernel-team@android.com, stable@vger.kernel.org, Will Deacon Subject: Re: [PATCH] KVM: arm64: Fully zero the vcpu state on reset In-Reply-To: References: <20210407181308.2265808-1-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: alexandru.elisei@arm.com, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, james.morse@arm.com, suzuki.poulose@arm.com, kernel-team@android.com, stable@vger.kernel.org, will@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On Thu, 08 Apr 2021 16:36:40 +0100, Alexandru Elisei wrote: > > Hi Marc, > > On 4/7/21 7:13 PM, Marc Zyngier wrote: > > On vcpu reset, we expect all the registers to be brought back > > to their initial state, which happens to be a bunch of zeroes. > > > > However, some recent commit broke this, and is now leaving a bunch > > of registers (such as a FP state) with whatever was left by the > > guest. My bad. > > > > Just zero the whole vcpu context on reset. It is more than we > > strictly need, but at least we won't miss anything. This also > > zeroes the __hyp_running_vcpu pointer, which is always NULL > > for a vcpu anyway. > > Had a look at struct kvm_cpu_context and indeed the only field which doesn't > represent a guest register is __hyp_running_vcpu. Did a grep for all the places > where __hyp_running_vcpu is used, and indeed the assumption is that for a guest > the pointer is NULL, as __sysreg_restore_el1_state() relies on it. > > > > > Cc: stable@vger.kernel.org > > Fixes: e47c2055c68e ("KVM: arm64: Make struct kvm_regs userspace-only") > > Signed-off-by: Marc Zyngier > > --- > > arch/arm64/kvm/reset.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c > > index bd354cd45d28..ef1c49a1a3ad 100644 > > --- a/arch/arm64/kvm/reset.c > > +++ b/arch/arm64/kvm/reset.c > > @@ -240,8 +240,8 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) > > break; > > } > > > > - /* Reset core registers */ > > - memset(vcpu_gp_regs(vcpu), 0, sizeof(*vcpu_gp_regs(vcpu))); > > + /* Zero all registers */ > > + memset(&vcpu->arch.ctxt, 0, sizeof(vcpu->arch.ctxt)); > > Checked that code earlier in the function does not touch the guest > registers from vcpu->arch.ctxt, to make sure we're not overwriting > other reset values by mistake. > Looks good to me: > > Reviewed-by: Alexandru Elisei Scratch that, this is breaks the setting of CNTVOFF, which gets populated when we create the vcpu. The gotcha is that creating a vcpu resets CNTVOFF for *all* vcpus: * If the VMM creates all vcpus, then reset them all, this works "fine": all the vcpus have CNTVOFF==0, which is an acceptable departure from the current behaviour (where vtime starts at 0). * If the VMM alternates vcpu creation and reset, then the last vcpu ends up with a CNTVOFF set to 0, while all the others have a different offset. QEMU does the former, and kvmtool the latter. Thanks to Will for the heads up. I'll drop the patch from -next and post a v2 shortly. Thanks, M. -- Without deviation from the norm, progress is not possible.