Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4744214rwb; Sun, 4 Dec 2022 07:26:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf47pXrm9Hf09uDbe6THSqAYs8xDRadahhqMBe1HvIWtrWZZfOy62g07Jo++Ykn46K2J/r97 X-Received: by 2002:a63:fa0b:0:b0:46b:2493:14ad with SMTP id y11-20020a63fa0b000000b0046b249314admr72753463pgh.274.1670167583658; Sun, 04 Dec 2022 07:26:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670167583; cv=none; d=google.com; s=arc-20160816; b=1BZHZn9PbGvfn8UMoy08o0zBpdbd1bZkUgr5yq65S+r7LPpMUkYR1mbHFOrke8vQtd 7N90RS/jipSGtVxWtc8c50WJAVzSWUpwoI8H7+pOR7Y7KlP6/0z1aLV+zpuihEmAEYZR sY+m6sdoC4h42eC5KNxz/haJcuksuuFnO9ey23N3kx+ur0qeDmH19hefavCHfLfgqOPw yFNX79zmWaWDrwK92jzosyzKHyrECmXFkLB9Rn08up/M5Vlg8+BZYKMjr9oYB9g+XEeR uh6GammG/EyfQLnTVd5P0aGUPebMb03mRji4PT7AxgX98qku04PBrzONLk1iIv+eIWBt v9Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=9T/sOOz0lDF99YFbJmZn+x5L6ZgnD4nCNxVAyJ2Nqho=; b=qm1i7j2cU0JWsMtv5BRn1ySt0yEsLv+un4iNbzY2jq+GmgUJu4aEbETMt/cP2bD3Mv PKpxsqnpA83oIpzSJCsI02+Dp2/ybufwj+sCTpWXXL9WgThNIPO67tAToO0BRrvEq4bp v6lnPyGTkV0O2faK449nXrh7Lh6r3YVl9koBGyaKok+FlAxHQ2cLaLwvkHPvbUxOVu9x wPU42WBEIDZ/NdrSRqk/WP5fPFAJqzxY1yp9SkqFWgYk7r7l3Lh1AkWwJFyfA9+5uxli 3Yze53vgjiyVDGNqW2Y8V71LKlfJcRnswGY7hAUtQzVNuoxl4VlKt2GN7aADBQsMesHi 1iwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IBbWkhGl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l3-20020a17090a850300b00219846484cbsi7494061pjn.176.2022.12.04.07.26.08; Sun, 04 Dec 2022 07:26:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IBbWkhGl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230007AbiLDO6E (ORCPT + 83 others); Sun, 4 Dec 2022 09:58:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbiLDO57 (ORCPT ); Sun, 4 Dec 2022 09:57:59 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB0CBDFD1 for ; Sun, 4 Dec 2022 06:57:58 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 31B4C60EA1 for ; Sun, 4 Dec 2022 14:57:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EAC0C433C1; Sun, 4 Dec 2022 14:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670165877; bh=Cgm74NkKEZ/DK5RPHt06OPQZsab/+7Dm33HMyFy16EQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=IBbWkhGldTnPxTm2GnBQewKJxktXrW8xPU5icmaUJHIc6PcgSX9oSrvnxV9D8cLcl jPYkNrjmWwB3TIlWFYT28Jv8O5lZHK/R3WTQP7i+bwz+oasHthcsKkk2XFtg+IVVZa Xc1hn1YayMhURTJIVCoswxTnOiAJv2JLbOegzL1Dix3VwQXPka+7IUorL1/j11AV0W W0VXR3DgPel2+vk7UyFeUKTOq9+TnNDLS8nmmDXYz0+Rztow0DSCl9KLFTWNPT8H0F FOE8A8wVMGTr68t9Hi23GWKt1E7EcQMEjzKRI0ZkwI3LRCfezpbpTS/zIx0DGQtycg u0GvX8eDS/veQ== Received: from [82.141.251.28] (helo=wait-a-minute.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 1p1qRG-00AP6F-Pg; Sun, 04 Dec 2022 14:57:54 +0000 Date: Sun, 04 Dec 2022 14:57:53 +0000 Message-ID: <87bkojtdvy.wl-maz@kernel.org> From: Marc Zyngier To: Akihiko Odaki Cc: Akihiko Odaki , linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Mathieu Poirier , Oliver Upton , Suzuki K Poulose , Alexandru Elisei , James Morse , Will Deacon , Catalin Marinas , asahi@lists.linux.dev, Alyssa Rosenzweig , Sven Peter , Hector Martin Subject: Re: [PATCH 0/3] KVM: arm64: Handle CCSIDR associativity mismatches In-Reply-To: References: <20221201104914.28944-1-akihiko.odaki@daynix.com> <867czbmlh1.wl-maz@kernel.org> <50499ee9-33fe-4f5d-9d0a-76ceef038333@daynix.com> <87lenqu37t.wl-maz@kernel.org> <525ff263-90b3-5b12-da31-171b09f9ad1b@daynix.com> <87h6yeta8b.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/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 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 82.141.251.28 X-SA-Exim-Rcpt-To: akihiko.odaki@gmail.com, akihiko.odaki@daynix.com, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, mathieu.poirier@linaro.org, oliver.upton@linux.dev, suzuki.poulose@arm.com, alexandru.elisei@arm.com, james.morse@arm.com, will@kernel.org, catalin.marinas@arm.com, asahi@lists.linux.dev, alyssa@rosenzweig.io, sven@svenpeter.dev, marcan@marcan.st X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 02 Dec 2022 09:55:24 +0000, Akihiko Odaki wrote: >=20 > On 2022/12/02 18:40, Marc Zyngier wrote: > > On Fri, 02 Dec 2022 05:17:12 +0000, > > Akihiko Odaki wrote: > >>=20 > >>>> On M2 MacBook Air, I have seen no other difference in standard ID > >>>> registers and CCSIDRs are exceptions. Perhaps Apple designed this way > >>>> so that macOS's Hypervisor can freely migrate vCPU, but I can't assu= re > >>>> that without more analysis. This is still enough to migrate vCPU > >>>> running Linux at least. > >>>=20 > >>> I guess that MacOS hides more of the underlying HW than KVM does. And > >>> KVM definitely doesn't hide the MIDR_EL1 registers, which *are* > >>> different between the two clusters. > >>=20 > >> It seems KVM stores a MIDR value of a CPU and reuse it as "invariant" > >> value for ioctls while it exposes the MIDR value each physical CPU > >> owns to vCPU. > >=20 > > This only affects the VMM though, and not the guest which sees the > > MIDR of the CPU it runs on. The problem is that at short of pinning > > the vcpus, you don't know where they will run. So any value is fair > > game. >=20 > Yes, my concern is that VMM can be confused if it sees something > different from what the guest on the vCPU sees. Well, this has been part of the ABI for about 10 years, since Rusty introduced this notion of invariant, so userspace is already working around it if that's an actual issue. This would be easily addressed though, and shouldn't result in any issue. The following should do the trick (only lightly tested on an M1). Thanks, M. =46rom f1caacb89eb8ae40dc38669160a2f081f87f4b15 Mon Sep 17 00:00:00 2001 From: Marc Zyngier Date: Sun, 4 Dec 2022 14:22:22 +0000 Subject: [PATCH] KVM: arm64: Return MIDR_EL1 to userspace as seen on the vc= pu thread When booting, KVM sample the MIDR of the CPU it initialises on, and keep this as the value that will forever be exposed to userspace. However, this has nothing to do with the value that the guest will see. On an asymetric system, this can result in userspace observing weird things, specially if it has pinned the vcpus on a *different* set of CPUs. Instead, return the MIDR value for the vpcu we're currently on and that the vcpu will observe if it has been pinned onto that CPU. For symmetric systems, this changes nothing. For asymmetric machines, they will observe the correct MIDR value at the point of the call. Reported-by: Akihiko Odaki Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index f4a7c5abcbca..f6bcf8ba9b2e 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1246,6 +1246,22 @@ static int set_id_reg(struct kvm_vcpu *vcpu, const s= truct sys_reg_desc *rd, return 0; } =20 +static int get_midr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, + u64 *val) +{ + *val =3D read_sysreg(midr_el1); + return 0; +} + +static int set_midr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, + u64 val) +{ + if (val !=3D read_sysreg(midr_el1)) + return -EINVAL; + + return 0; +} + static int get_raz_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r= d, u64 *val) { @@ -1432,6 +1448,7 @@ static const struct sys_reg_desc sys_reg_descs[] =3D { =20 { SYS_DESC(SYS_DBGVCR32_EL2), NULL, reset_val, DBGVCR32_EL2, 0 }, =20 + { SYS_DESC(SYS_MIDR_EL1), .get_user =3D get_midr, .set_user =3D set_midr = }, { SYS_DESC(SYS_MPIDR_EL1), NULL, reset_mpidr, MPIDR_EL1 }, =20 /* @@ -2609,7 +2626,6 @@ id_to_sys_reg_desc(struct kvm_vcpu *vcpu, u64 id, ((struct sys_reg_desc *)r)->val =3D read_sysreg(reg); \ } =20 -FUNCTION_INVARIANT(midr_el1) FUNCTION_INVARIANT(revidr_el1) FUNCTION_INVARIANT(clidr_el1) FUNCTION_INVARIANT(aidr_el1) @@ -2621,7 +2637,6 @@ static void get_ctr_el0(struct kvm_vcpu *v, const str= uct sys_reg_desc *r) =20 /* ->val is filled in by kvm_sys_reg_table_init() */ static struct sys_reg_desc invariant_sys_regs[] =3D { - { SYS_DESC(SYS_MIDR_EL1), NULL, get_midr_el1 }, { SYS_DESC(SYS_REVIDR_EL1), NULL, get_revidr_el1 }, { SYS_DESC(SYS_CLIDR_EL1), NULL, get_clidr_el1 }, { SYS_DESC(SYS_AIDR_EL1), NULL, get_aidr_el1 }, --=20 2.34.1 --=20 Without deviation from the norm, progress is not possible.