Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4426157ioa; Wed, 27 Apr 2022 03:43:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbQur8HRgzFIIUzuoFKje8+kAWhtlYLRTGSeoCCFFaSzkRv+1K+oc3mjMT+jAuGcsFqyWH X-Received: by 2002:a63:1263:0:b0:3ab:812a:e070 with SMTP id 35-20020a631263000000b003ab812ae070mr8187322pgs.321.1651056182914; Wed, 27 Apr 2022 03:43:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651056182; cv=none; d=google.com; s=arc-20160816; b=m9rJKsPRNp85RYFA6+e3FIloSZZ5jyVuNb/K6J71E5bYtZsDcO1tPRtIm7VvKqKXY/ cEv2yTY9XXrM90k4AJIT6KNvs6ooLjzyhJdoPlJBt3yZnH8wdI2cmiN8pEQTKh5/G+dF Wib6cUaKLMCGImXZdMI2SrkVOy9LlmUnlfsIHYDduGh5iosIhgygV8At2Ky6rlc46S4W y1tcSgqzwbj/zESC+hoBHuKy5Pq1Mt07q86dRtPdAEp7k5/H8kBjDAZBWCsNA5JG3UnH diARCCKI3OGdhN88rENacBHi2b868iteBSBZW2gdv/YJmiBxiQRqxw2llTFg22guO/46 F/Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=wtLT16MNoQg9+Z2/jQF5iyDxVjOvWlqzxLSKVTMf8Mk=; b=EGJXdl6h3QPpa3ael7zwuIynrD5M210gzsHPvnA1DCgTmvfy85Yxp8Pa3tcj0jpvMB QZufxyJw2IMMkmkkDeB2BV4zvZ5XXOYrkVIg0pTLJ3S+GgdnI0hlTPqJdrBrmvPwyV1X zyw6FS2JyAcY4XNbh02/dVCh+a2OgS1o9kg2UjNw2UvUZWgPZXox0SQcKMXp8WMySi+r KjX8hoHXzuS4GpZOiH1terkc0Z1ZhXN8BMLgQ0kD4VhNEgp/umtOCODQ8r5Nn8gK/jGI TU6TZLnMdykalI87umcxjl61Ccp8XXMMxKhYbLGk5nWocvXwJRETvIm5gp5nxzwpX1TM giqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x36-20020a056a0018a400b0050cebeedf63si1212552pfh.42.2022.04.27.03.43.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 03:43:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 77DF83F56EC; Wed, 27 Apr 2022 02:52:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347978AbiDZJ6F (ORCPT + 99 others); Tue, 26 Apr 2022 05:58:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346695AbiDZJ5n (ORCPT ); Tue, 26 Apr 2022 05:57:43 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1D927387BE; Tue, 26 Apr 2022 02:15:49 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 854F823A; Tue, 26 Apr 2022 02:15:48 -0700 (PDT) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D32D23F73B; Tue, 26 Apr 2022 02:15:46 -0700 (PDT) Date: Tue, 26 Apr 2022 10:15:43 +0100 From: Alexandru Elisei To: Oliver Upton Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, reijiw@google.com, ricarkol@google.com Subject: Re: [PATCH v3 0/5] KVM: arm64: Limit feature register reads from AArch32 Message-ID: References: <20220425235342.3210912-1-oupton@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220425235342.3210912-1-oupton@google.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no 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 Hi, On Mon, Apr 25, 2022 at 11:53:37PM +0000, Oliver Upton wrote: > KVM/arm64 does not restrict the guest's view of the AArch32 feature > registers when read from AArch32. HCR_EL2.TID3 is cleared for AArch32 > guests, meaning that register reads come straight from hardware. This is > problematic as KVM relies on read_sanitised_ftr_reg() to expose a set of > features consistent for a particular system. > > Appropriate handlers must first be put in place for CP10 and CP15 ID > register accesses before setting TID3. Rather than exhaustively > enumerating each of the encodings for CP10 and CP15 registers, take the > lazy route and aim the register accesses at the AArch64 system register > table. > > Patches 1-2 are small cleanups to how we handle register emulation > failure. No functional change for current KVM, but required to do > register emulation correctly in this series. > > Patch 3 reroutes the CP15 registers into the AArch64 table, taking care > to immediately RAZ undefined ranges of registers. This is done to avoid > possibly conflicting with encodings for future AArch64 registers. > > Patch 4 installs an exit handler for the CP10 ID registers and also > relies on the general AArch64 register handler to implement reads. > > Finally, patch 5 actually sets TID3 for AArch32 guests, providing > known-safe values for feature register accesses. > > There is an argument that the series is in fact a bug fix for running > AArch32 VMs on heterogeneous systems. To that end, it could be > blamed/backported to when we first knew better: > > 93390c0a1b20 ("arm64: KVM: Hide unsupported AArch64 CPU features from guests") > > But I left that tag off as in the aforementioned change skipping > AArch32 was intentional. Up to you, Marc, if you want to call it a > bugfix ;-) > > Applies cleanly to 5.18-rc4. > > Tested with AArch32 kvm-unit-tests and booting an AArch32 debian guest > on a Raspberry Pi 4. Additionally, I tested AArch32 kvm-unit-tests w/ > pmu={on,off} and saw no splat, as Alex had discovered [1]. The test > correctly skips with the PMU feature bit disabled now. But a guest who ignores the fact that the ID register doesn't advertise a PMU and tries to access the PMU registers regardless would still trigger the splat, right? I don't think the series changes the AArch32 PMU registers visibility to REG_HIDDEN when the VCPU feature is not set. Thanks, Alex > > [1]: https://lore.kernel.org/r/20220425145530.723858-1-alexandru.elisei@arm.com > > v1: https://lore.kernel.org/kvmarm/20220329011301.1166265-1-oupton@google.com/ > v2: https://lore.kernel.org/r/20220401010832.3425787-1-oupton@google.com > > v2 -> v3: > - Collect R-b from Reiji (thanks!) > - Adopt Marc's suggestion for CP15 register handling > - Avoid writing to Rt when emulation fails (Marc) > - Print some debug info on an unexpected CP10 register access (Reiji) > > v1 -> v2: > - Actually set TID3! Oops. > - Refactor kvm_emulate_cp15_id_reg() to check preconditions before > proceeding to emulation (Reiji) > - Tighten up comment on kvm_is_cp15_id_reg() to indicate that the only > other trapped ID register (CTR) is already handled in the cp15 > > Oliver Upton (5): > KVM: arm64: Return a bool from emulate_cp() > KVM: arm64: Don't write to Rt unless sys_reg emulation succeeds > KVM: arm64: Wire up CP15 feature registers to their AArch64 > equivalents > KVM: arm64: Plumb cp10 ID traps through the AArch64 sysreg handler > KVM: arm64: Start trapping ID registers for 32 bit guests > > arch/arm64/include/asm/kvm_arm.h | 3 +- > arch/arm64/include/asm/kvm_emulate.h | 7 - > arch/arm64/include/asm/kvm_host.h | 1 + > arch/arm64/kvm/handle_exit.c | 1 + > arch/arm64/kvm/sys_regs.c | 197 +++++++++++++++++++++++---- > arch/arm64/kvm/sys_regs.h | 7 + > 6 files changed, 178 insertions(+), 38 deletions(-) > > -- > 2.36.0.rc2.479.g8af0fa9b8e-goog >