From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 911F0A928 for ; Wed, 31 May 2023 07:24:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5706DC433EF; Wed, 31 May 2023 07:24:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685517852; bh=cPobS0FDQDC2RM/4dx6AuvjAZHc07sjiueJgxoqErzE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=V/hAxAD64Ao250VunieA9RR28JaZFX7DF0jJG7DoMp3sg462N9SHobK1FHf4eXC2U 6OkJZC8mFipA2BCETQEuaKm32nYDvfjbW//oHkBvvwZooXCjrZ3B99lHthjg1pJ0OS MhmmS/QEBfHxqv8Ax36yLAvYmkKLP+Ya9GsDZSg0jPunSlmZ5WjA9xuZhSEYqleMYb /w1+iyNj3PimxfaosIQUkblVafFBA0NiXN/iINXNluaW4qBzpJb3y/f2nhknbMCUJI XLKAo7S4TZQinOXsWw/3YaZV6BBhIARzafe5Kn7jA9oi7nMQA/GY6thnu1VKlhkHEX 1gXg1TrzK1umw== 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 1q4GBl-001Xi0-Vr; Wed, 31 May 2023 08:24:10 +0100 Date: Wed, 31 May 2023 08:24:09 +0100 Message-ID: <864jntc6au.wl-maz@kernel.org> From: Marc Zyngier To: Jing Zhang Cc: KVM , KVMARM , ARMLinux , Oliver Upton , Will Deacon , Paolo Bonzini , James Morse , Alexandru Elisei , Suzuki K Poulose , Fuad Tabba , Reiji Watanabe , Raghavendra Rao Ananta Subject: Re: [PATCH v10 1/5] KVM: arm64: Save ID registers' sanitized value per guest In-Reply-To: References: <20230522221835.957419-1-jingzhangos@google.com> <20230522221835.957419-2-jingzhangos@google.com> <87ttvwok3d.wl-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/28.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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: jingzhangos@google.com, kvm@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oupton@google.com, will@kernel.org, pbonzini@redhat.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, tabba@google.com, reijiw@google.com, rananta@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Tue, 30 May 2023 19:02:03 +0100, Jing Zhang wrote: [...] > > > +/* > > > + * Set the guest's ID registers with ID_SANITISED() to the host's sanitized value. > > > + */ > > > +void kvm_arm_init_id_regs(struct kvm *kvm) > > > +{ > > > + const struct sys_reg_desc *idreg; > > > + struct sys_reg_params params; > > > + u32 id; > > > + > > > + /* Find the first idreg (SYS_ID_PFR0_EL1) in sys_reg_descs. */ > > > + id = SYS_ID_PFR0_EL1; > > > + params = encoding_to_params(id); > > > + idreg = find_reg(¶ms, sys_reg_descs, ARRAY_SIZE(sys_reg_descs)); > > > + if (WARN_ON(!idreg)) > > > + return; > > > > What is this trying to guard against? Not finding ID_PFR0_EL1 in the > > sysreg table? But this says nothing about the following registers (all > > 55 of them), so why do we need to special-case this one? > Here is to find the first idreg in the array and warn that no idregs > found in the array with the assumption that ID_PFR0_EL1 is the first > one defined and if it is not found, then no other idregs are defined > either. I didn't make my point clear. What we have is a purely static array. Why should we perform such a test on every single VM creation? Any structural validation should only happen once, at KVM init time. > Another way is to go through all the regs in array sys_reg_descs and > do the initialization if it is a idreg. That'd be a waste of precious cycles. This WARN_ON()+early return should go, but the rest is fine. Thanks, M. -- Without deviation from the norm, progress is not possible.