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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6CF9C6FA8E for ; Fri, 24 Feb 2023 19:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229959AbjBXTD3 (ORCPT ); Fri, 24 Feb 2023 14:03:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229630AbjBXTD2 (ORCPT ); Fri, 24 Feb 2023 14:03:28 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 652711B2F8 for ; Fri, 24 Feb 2023 11:03:26 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1B869B81CF5 for ; Fri, 24 Feb 2023 19:03:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BECAEC433EF; Fri, 24 Feb 2023 19:03:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677265403; bh=gCXvVswG+5BJ4eLw8cXXd2lIKc6j1StQlEVV4zpsmGY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=bteC247cuY8lqVHIP5fSW8WbA80ZJaeeA0QA2eU9K5g7K0UGRNPpDn+xnVoGV6GJa ERbEYw/u4vNPBQmhE39jH7ueEuWpRRpev1dV4dbjpl6rB+9z1LlPX6bPaOcT0v/OU/ 6fZ+Ddop7SjirvXVRd/fpkt2Gg3Mnr3za2u1G79Xd7MAcxocwgdDTOR0tnKV3/LQlJ 0bnazS3Hx6QMeIvXPuZq+cktOM4xr99F9YWhwbgjI9X+Dz9+GQ0fuPqX5JlQsmU7c8 4B1pJPQ19oRaX1ei938Qiz4o5nwBwnKFSwSC0mCH4t2hiz7ktHjc3Z5gXiWmI+s0CM XqH21f28/LMTQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pVdLl-00Czbp-BB; Fri, 24 Feb 2023 19:03:21 +0000 Date: Fri, 24 Feb 2023 19:03:21 +0000 Message-ID: <86v8jqx4w6.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Cc: Joey Gouly , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Alexandru Elisei , Andre Przywara , Catalin Marinas , Christoffer Dall , Ganapatrao Kulkarni , Russell King , James Morse , Suzuki K Poulose , Zenghui Yu , nd@arm.com Subject: Re: [PATCH 08/18] KVM: arm64: nv: Handle HCR_EL2.NV system register traps In-Reply-To: References: <20230209175820.1939006-1-maz@kernel.org> <20230209175820.1939006-9-maz@kernel.org> <20230224173915.GA17407@e124191.cambridge.arm.com> 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/28.2 (aarch64-unknown-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: 185.219.108.64 X-SA-Exim-Rcpt-To: oliver.upton@linux.dev, joey.gouly@arm.com, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, alexandru.elisei@arm.com, andre.przywara@arm.com, catalin.marinas@arm.com, christoffer.dall@arm.com, gankulkarni@os.amperecomputing.com, rmk+kernel@armlinux.org.uk, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, nd@arm.com 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: kvm@vger.kernel.org On Fri, 24 Feb 2023 18:36:23 +0000, Oliver Upton wrote: > > Hi Joey, > > On Fri, Feb 24, 2023 at 05:39:15PM +0000, Joey Gouly wrote: > > I'm having an issue with this commit where a VCPU is getting a CNTVOFF_EL2 set > > to 0, so it sees the same time as the host system, and the other VCPU has the > > correct offset. > > Yikes! > > > The flow of execution looks like this: > > KVM_CREATE_VCPU 0 (VMM) -> > > kvm_timer_vcpu_init -> > > update_vtimer_cntvoff (VCPU0.CNTVOFF_EL2=kvm_phys_timer_read) > > KVM_ARM_VCPU_INIT (VMM) -> > > kvm_arch_vcpu_ioctl_vcpu_init -> > > kvm_vcpu_set_target -> > > kvm_reset_vcpu -> > > kvm_reset_sys_regs (VCPU0.CNTVOFF_EL2=0) > > > > KVM_CREATE_VCPU 1 (VMM) -> > > kvm_timer_vcpu_init -> > > update_vtimer_cntvoff (VCPU0.CNTVOFF_EL2=VCPU1.CNTVOFF_EL2=kvm_phys_timer_read) > > KVM_ARM_VCPU_INIT (VMM) -> > > kvm_arch_vcpu_ioctl_vcpu_init -> > > kvm_vcpu_set_target -> > > kvm_reset_vcpu -> > > kvm_reset_sys_regs (VCPU1.CNTVOFF_EL2=0) > > > > At this point VCPU0 has CNTVOFF_EL2 == kvm_phys_timer_read, and VCPU1 > > has CNTVOFF_EL2 == 0. > > > > The VCPUs having different CNTVOFF_EL2 valuess is just a symptom of the fact that > > CNTVOFF_EL2 is now reset in kvm_reset_sys_regs. > > Right, and the fundamental problem at hand is that we used CNTVOFF_EL2 > to stash the _host's_ offset even though we are trying to change the > meaning of it to be part of the virtual EL2's context. What is driving me nuts is that I have never managed to reproduce the problem so far. I guess I have too much crap in my tree to spot it... > > > The following patch gets it booting again, but I'm sure it's not the right fix. > > I'd rather we just break the host away from using the shadow reg > altogether and separately track the host offset. As it so happens Marc > has a patch that does exactly that [*]. Yup, might as well fix that *and* kill the lock inversion issue in one go... > Marc, do you want to resend that patch in isolation addressing the > feedback and link to this bug report? > > [*] https://lore.kernel.org/kvmarm/20230216142123.2638675-6-maz@kernel.org/ Joey, could you please give that patch a go, just to be on the safe side? Thanks, M. -- Without deviation from the norm, progress is not possible.