Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1367580rwb; Thu, 1 Dec 2022 16:38:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf6WoFqphQ/a+98T3+uYNDJ8xiecqc22RpKen382JQjx6lPnCtG4HHFsB7kH48jyYLErgp0G X-Received: by 2002:a17:90a:7a82:b0:211:55d8:4cdd with SMTP id q2-20020a17090a7a8200b0021155d84cddmr71782079pjf.133.1669941515642; Thu, 01 Dec 2022 16:38:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669941515; cv=none; d=google.com; s=arc-20160816; b=ZailOIkOjgu9EI00MyrMfyupz9KXZWK8eLNTan/g9QSXWWjPRoi2MnyaZ+ZypPo7kX Os+uFpxn/wBAzy6lqY6y2cys9iRKI/ycXwVUFXPEfaF3mjtK98WfkCr0fSYqO+ph2P/W 5yVxiAd3lTP2MlQnuhbJ3t9bweUrxT8h/rDrSmUJXMtUtv8AqasUcJNKeh4TzeawSQJN SY2K3lKujIcoQaKfwZEmB8OGKg/8XRz7i9bOXMoo9PvdRKbunqIaZySMdNtJpsgJqkys gk4/xjh/NEqL5umParblA5IBW+g1ZjeosBLBAOcF9oRB4RxjiemzmY5wC8yxhPkE6Z+o ShOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=CxwtlUR6TnFS5LXoAL03jv6FE2q8nsMibqS1+rJZDJM=; b=kLaDFXWNW9gPOHRdbYp810lEwxnYOQVdOnmeSb4zfBb3pBg3buRsVZyuxD1b23RqOc Ed+KpM5ARNWg4Rv0scGMeHZZ/HNfKgcMbe5RjGFbiyJp90FlHKCs1ywOFxjjT3yMtGFZ 2c25AGVAH+mv/T1MHovh6K6fPmSUNQ0ADHATD9S8YpAf4MxGMf2OJ+RfDM0A9R4h5jXe HtCUFz90UqG8lVZLy0UXqbbrtpDJf6TYI+5pfRLlIeLPJWsfZ6Z4QN/3Pe61DTAyQZfR P6GAXw7/RGBF4OnXioWLPZXDnZrtPMLiYiTpdz2LiDLa3AFFlSDO6r1Ykh7rkR9yYO4S BImQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RdPD0jGl; 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 u11-20020a17090341cb00b001892c399db0si6258882ple.363.2022.12.01.16.38.24; Thu, 01 Dec 2022 16:38:35 -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=RdPD0jGl; 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 S231154AbiLAXOJ (ORCPT + 81 others); Thu, 1 Dec 2022 18:14:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230422AbiLAXOH (ORCPT ); Thu, 1 Dec 2022 18:14:07 -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 B84BE14D1B for ; Thu, 1 Dec 2022 15:14:05 -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 5EF396219D for ; Thu, 1 Dec 2022 23:14:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF261C433C1; Thu, 1 Dec 2022 23:14:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669936444; bh=ozp0kC2g9+TotjQ9j2Pw3XRqzPeryuGFH0wGXi5UC/Y=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=RdPD0jGlqLp3uEAhn0aFEjETKR8VNVD/JPLofMJf3Yp7CXvgsXMteQfqb2UGCnPQM 29Zdpm8HsAtw/CblVCJKkiQ/OcMXphmydCW9m5W6eNXPJPRxf6Z7QLwsWBwul9Gj33 0VjEN3YfMM3rseBp6VpGvpAxLa86qiKaXWYVx+MOtYyD8nrOkDz3DWGT/zrfDbRi/M ehn9I/+41au4Bk7FNHDbNRc7qTC6z3akboH6ko5yTg+stWIIbmQDsq5JMWtrqbCRdq MUazZozc/2xl3tg+JMZO2NulQr7n+Byv273rvkxjBccRJqLpgMgALYRJXC0UEV9O7W OBBbHwAyWKkhw== Received: from 51-171-6-54-dynamic.agg9.chf.chf-qkr.eircom.net ([51.171.6.54] 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 1p0skk-009wGh-B3; Thu, 01 Dec 2022 23:14:02 +0000 Date: Thu, 01 Dec 2022 23:13:58 +0000 Message-ID: <87lenqu37t.wl-maz@kernel.org> From: Marc Zyngier To: Akihiko Odaki Cc: 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: <50499ee9-33fe-4f5d-9d0a-76ceef038333@daynix.com> References: <20221201104914.28944-1-akihiko.odaki@daynix.com> <867czbmlh1.wl-maz@kernel.org> <50499ee9-33fe-4f5d-9d0a-76ceef038333@daynix.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/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: 51.171.6.54 X-SA-Exim-Rcpt-To: 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 Thu, 01 Dec 2022 17:26:08 +0000, Akihiko Odaki wrote: > > On 2022/12/01 20:06, Marc Zyngier wrote: > > On Thu, 01 Dec 2022 10:49:11 +0000, > > Akihiko Odaki wrote: > > > > Thanks for looking into this. > > > >> M2 MacBook Air has mismatched CCSIDR associativity bits, which makes the > >> bits a KVM vCPU sees inconsistent when migrating. > > > > Can you describe the actual discrepancy? Is that an issue between the > > two core types? In which case, nothing says that these two cluster > > should have the same cache topology. > > Yes, the processor has big.LITTLE configuration. > > On the processor, the valid CSSELR values are 0 (L1D), 1 (L1I), 3 > (L2D). For each CSSELR values, each cluster has: > - 0x700FE03A, 0x203FE01A, 0x70FFE07B > - 0x701FE03A, 0x203FE02A, 0x73FFE07B This is a perfectly valid configuration. The architecture doesn't place any limitation on how different or identical the cache hierarchies are from the PoV of each CPU. Actually, most big-little systems show similar differences across their clusters. > >> It also makes QEMU fail restoring the vCPU registers because QEMU saves > >> and restores all of the registers including CCSIDRs, and if the vCPU > >> migrated among physical CPUs between saving and restoring, it tries to > >> restore CCSIDR values that mismatch with the current physical CPU, which > >> causes EFAULT. > > > > Well, QEMU will have plenty of other problems, starting with MIDRs, > > which always reflect the physical one. In general, KVM isn't well > > geared for VMs spanning multiple CPU types. It is improving, but there > > is a long way to go. > > 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 assure > that without more analysis. This is still enough to migrate vCPU > running Linux at least. 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. > >> Trap CCSIDRs if there are CCSIDR value msimatches, and override the > >> associativity bits when handling the trap. > > > > TBH, I'd rather we stop reporting this stuff altogether. > > > > There is nothing a correctly written arm64 guest should do with any of > > this (this is only useful for set/way CMOs, which non-secure SW should > > never issue). It would be a lot better to expose a virtual topology > > (one set, one way, one level). It would also save us from the CCSIDRX > > silliness. > > > > The only complexity would be to still accept different topologies from > > userspace so that we can restore a VM saved before this virtual > > topology. > > Another (minor) concern is that trapping relevant registers may cost > too much. Currently KVM traps CSSELR and CCSIDR accesses with > HCR_TID2, but HCR_TID2 also affects CTR_EL0. It will have an additional impact (JITs, for example, will take a hit if they don't cache that value), but this is pretty easy to mitigate if it proves to have too much of an impact. We already have a bunch of fast-paths for things that we want to emulate more efficiently, and CTR_EL0 could be one of them, > Although I'm not sure if the register is referred frequently, Arm > introduced FEAT_EVT to trap CSSELR and CSSIDR but not CTR_EL0 so > there may be some case where trapping CTR_EL0 is not > tolerated. Perhaps Arm worried that a userspace application may read > CTR_EL0 frequently. FEAT_EVT is one of these "let's add random traps" extensions, culminating in FEAT_FGT. Having FEAT_EVT would make it more efficient, but we need to support this for all revisions of the architecture. So let's first build on top of HCR_EL2.TID2, and only then once we have an idea of the overhead add support for HCR_EL2.TID4 for the systems that have FEAT_EVT. > If you think the concern on VM restoration you mentioned and the > trapping overhead is tolerable, I'll write a new, much smaller patch > accordingly. That would great, thanks. There are a number of gotchas around that (like the 32bit stuff that already plays the emulation game), but this is the right time to start and have something in 6.3 if you keep to it! M. -- Without deviation from the norm, progress is not possible.