From patchwork Thu Dec 7 15:08:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 13483417 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 247C8C4167B for ; Thu, 7 Dec 2023 15:08:47 +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=uegw09KMRhIM/1QHmH6cSvhYDrkBcH8hXx44xfSglXw=; b=buFonpuAJoN5pa DS9NLLMnTW49ZYqp0Eb8myORqNuyjvrk8aRKl08kRynGCwUuzsCuALHIS/pzPhxfDPCsH/X6dnv3D ZQjZs3pFPTf3F/jg8eaW27DhzI6zc5LnRxtWkvu7/Gn0P5e1WqrBqLc2mIRkwh7pd7ZMcPWTeMUUx biP9rFgvciMeSvH/FkphoEdWnH9AR1lqxdeveCbSO4D7L0H7FLAWEcs+caDH+AXmo6GFUKPhw7PUT rHJFN+P9YbNFsacPoRjTU9Cf8fAnNCklQi8mXbwcCIWfZ9BmQaTMr0o/GLKCXvUSY7AmFDh1N0sl6 8Bg1nKFFidp+GwiKnH4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rBFzC-00D8RN-06; Thu, 07 Dec 2023 15:08:22 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rBFz9-00D8QA-2Y for linux-arm-kernel@lists.infradead.org; Thu, 07 Dec 2023 15:08:21 +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 554ED139F; Thu, 7 Dec 2023 07:09:01 -0800 (PST) Received: from eglon.cambridge.arm.com (eglon.cambridge.arm.com [10.1.197.60]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 680573F762; Thu, 7 Dec 2023 07:08:14 -0800 (PST) From: James Morse To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: Marc Zyngier , Oliver Upton , Suzuki K Poulose , Zenghui Yu , James Morse Subject: [PATCH v2 0/4] KVM: arm64: Hide unsupported MPAM from the guest Date: Thu, 7 Dec 2023 15:08:00 +0000 Message-Id: <20231207150804.3425468-1-james.morse@arm.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231207_070819_923671_1800EA63 X-CRM114-Status: GOOD ( 17.95 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 'lo 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, use the writable ID registers to allow MPAM to be re-enabled - but emulate it as RAZ/WI for the system registers that are trapped. This means KVM emulates a machine with 0 PARTID and 0 PMG, so the MPAMx_ELy registers don't need to be preserved by KVM. This has the added advantage that MPAMx_ELy's 'MPAMEN' bit will be read as zero, telling guests that this feature is disabled. Guests have never been able to make use of MPAM as these system registers are only for configuring the CPU, to see any change in behaviour you need to configure the Memory System Components (MSC) which are MMIO gadgets that belong to the host. 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 v6.7-rc4 and can be retrieved from: https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/log/?h=mpam/kvm_mpam_fix/v2 Thanks, James Morse (4): 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 handle traps .../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 | 1 + arch/arm64/kernel/cpufeature.c | 67 +++++++++++++++++ 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 | 71 +++++++++++++++++- arch/arm64/tools/cpucaps | 1 + arch/arm64/tools/sysreg | 32 ++++++++ 17 files changed, 352 insertions(+), 4 deletions(-) create mode 100644 arch/arm64/include/asm/mpam.h create mode 100644 arch/arm64/kernel/mpam.c