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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A4643C54E58 for ; Thu, 21 Mar 2024 16:58:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=XLt9w22no0r4I4O3FXrsqL0UnsIP2Vs0ynD4lh4sKQQ=; b=CZNauO/LQNgqrU M/vOihifOqMbXV9GO4OVzhV2Hlai8u9Op+LN62QS8eYFYt4JmDAMQga5IyKUbL3m4eIrgO0D2IA71 rpVx5/2p1Tuy2SLGSZxOis2XX+3yQEUoEHI0AdZdIIVuu0Vn1oK3GAb+9vggNjCxgj0BubQbAUo7W a8ze8K8jGE9pMYUDt0jB0U4omKmUhVZdOoeF18+zG7Nid0ws/EPte1HNbEnPZDDz1ZkRrBid18I6K Na/oahi3Tbru9AihVIxu6xDwfutP0L8Ifd5t6luLP1rRHJi16clyYkKKmb75rOAYZxnOqSRY5LZhI myNGyL5L7ONj9E5ZYx/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnLjh-00000003x3f-2kzP; Thu, 21 Mar 2024 16:57:49 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnLje-00000003x1m-0HhH for linux-arm-kernel@lists.infradead.org; Thu, 21 Mar 2024 16:57:47 +0000 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 DAA371007; Thu, 21 Mar 2024 09:58:15 -0700 (PDT) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 480613F67D; Thu, 21 Mar 2024 09:57:40 -0700 (PDT) From: James Morse To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Cc: Marc Zyngier , Oliver Upton , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Jing Zhang , James Morse Subject: [PATCH v3 0/6] KVM: arm64: Hide unsupported MPAM from the guest Date: Thu, 21 Mar 2024 16:57:22 +0000 Message-Id: <20240321165728.31907-1-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240321_095746_697943_C2AD3840 X-CRM114-Status: GOOD ( 20.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 'lo Sorry skipped a cycle, I got busy with the resctrl end of this, and it took me a while to convince myself doing this can still work if we need to prevent migration to incompatible hardware. The change since v2 is to (mostly) ignore the value provided by user-space as the simplest thing to do. The value is ignored when it matches the sanitised hardware value - as that is the value exposed by the bug. But otherwise is checked normally. This allows the value to be used to prevent migration on some hypothetical MPAM==2 hardware if that is incompatible. If it is compatible, the writeable-id-registers can be used. Sufficiently hairy that I added a test. ~ This series fixes up a long standing bug where MPAM was accidentally exposed to a guest, but the feature was not otherwise trapped or context switched. This could result in KVM warning about unexpected traps, and injecting an undef into the guest contradicting the ID registers. This would prevent an MPAM aware kernel from booting - fortunately, there aren't any of those. Ideally, we'd take the MPAM feature away from the ID registers, but that would leave existing guests unable to migrate to a newer kernel. Instead, just ignore that field when it matches the hardware. KVM wasn't going to expose MPAM anyway. The guest will not see MPAM in the id registers. This series includes the head.S and KVM changes to enable/disable traps. If MPAM is neither enabled nor emulated by EL3 firmware, these system register accesses will trap to EL3. If your kernel doesn't boot, and the problem bisects here - please update your firmware. MPAM has been supported by trusted firmware since v1.6 in 2018. (also noted on patch 2). This series is based on Linus' commit 23956900041d and can be retrieved from: https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/kvm_mpam_fix/v3 Sorry for the mid-merge window base, I'm away for a few weeks - this should rebase trivially onto rc1. Thanks James [v1] https://lore.kernel.org/linux-arm-kernel/20200925160102.118858-1-james.morse@arm.com/ [v2] https://lore.kernel.org/linux-arm-kernel/20231207150804.3425468-1-james.morse@arm.com/ James Morse (6): arm64: head.S: Initialise MPAM EL2 registers and disable traps arm64: cpufeature: discover CPU support for MPAM KVM: arm64: Fix missing traps of guest accesses to the MPAM registers KVM: arm64: Disable MPAM visibility by default and ignore VMM writes KVM: arm64: selftests: Move the bulky macro invocation to a helper KVM: arm64: selftests: Test ID_AA64PFR0.MPAM isn't completely ignored .../arch/arm64/cpu-feature-registers.rst | 2 + arch/arm64/Kconfig | 19 +++- arch/arm64/include/asm/cpu.h | 1 + arch/arm64/include/asm/cpufeature.h | 13 +++ arch/arm64/include/asm/el2_setup.h | 16 +++ arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/include/asm/mpam.h | 75 +++++++++++++ arch/arm64/include/asm/sysreg.h | 8 ++ arch/arm64/kernel/Makefile | 2 + arch/arm64/kernel/cpufeature.c | 104 ++++++++++++++++++ arch/arm64/kernel/cpuinfo.c | 4 + arch/arm64/kernel/image-vars.h | 5 + arch/arm64/kernel/mpam.c | 8 ++ arch/arm64/kvm/hyp/include/hyp/switch.h | 32 ++++++ arch/arm64/kvm/sys_regs.c | 43 +++++++- arch/arm64/tools/cpucaps | 1 + arch/arm64/tools/sysreg | 32 ++++++ .../selftests/kvm/aarch64/set_id_regs.c | 64 ++++++++++- 18 files changed, 424 insertions(+), 6 deletions(-) create mode 100644 arch/arm64/include/asm/mpam.h create mode 100644 arch/arm64/kernel/mpam.c -- 2.39.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel