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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 253C6C433ED for ; Fri, 9 Apr 2021 17:20:43 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C02CC610CA for ; Fri, 9 Apr 2021 17:20:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C02CC610CA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Subject:Cc:To: From:Message-ID:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZF53Dm/plNI9qVRtBUpDnPrsK3AR03YBmudg5smcGLI=; b=Dt0QbR67Q37smS2AmFnORcFAl bUM+VB/JU8gE8u02M0EJXmqX9dbZ2PjASr2WTDoTYWFyHHMRll29CdppsQZcYfaoBxxqlXFXmGsfi Sy8ADjuCqJvI+X+/6F28K6FuJkb3MS/BhWVfEsl4jI/LV+s2HioYkH5JXsbvRGIr2Uko9YRZoUiBT 5mHR3evtXu16lhY8WRMKrObE1euHfYdc0csqL13vbiznYu/7aA3ktutuB6CJEtBIrrq+JgVLEs3oU rHGOof3uasQF0qO4yKEZ3wbk14ZBToZR99AoxrN2mshDvrazbtpFaAkUmcZwPfyGc+WV1onwI8K+n 7RmZ4xSwg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lUumf-001BCz-0s; Fri, 09 Apr 2021 17:19:05 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lUumd-001BCo-LA for linux-arm-kernel@desiato.infradead.org; Fri, 09 Apr 2021 17:19:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:MIME-Version:References: In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lFJr3ejt8G70rZSL5vk3JLhETXHEA3Sngere1x+SnVU=; b=UPJx/BgUCfiEmHmciH9WjrZOkp hp/hBqpHIUkbMDF/cNi1oIvx2wDX9z8MhBHb3eCKxNegYryYh5MQ2g1yI4vbyouSA9NDF4Acw4eA4 FwAOqCL5r+IK4uYlDdRYrd5I8eNRC5bHvdBzx+d9gFEFHsYRZ4qYZTAbNwF++JMIUZe3AyfbA9eDp 7NgoEKHY9r6yA2bimcO/GmAkCuHeoXss4bhrSb1pbBcyPakogFI9kSV/WAFBaeKMgEyinfT2M431D sxdU2dE3kyc0vJND5cGINISt3csdL6iO4ZAI3JhkabnP2CCfTMBIc2lyxczKrrem1/JLMX/3HfnPB ULMIF3XA==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lUumb-004gck-2r for linux-arm-kernel@lists.infradead.org; Fri, 09 Apr 2021 17:19:02 +0000 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") 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210409_101901_188238_1557A973 X-CRM114-Status: GOOD ( 36.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel