From patchwork Fri May 3 13:01:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13652779 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEE12C10F16 for ; Fri, 3 May 2024 13:02:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F8F76B008A; Fri, 3 May 2024 09:02:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AA0A6B008C; Fri, 3 May 2024 09:02:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 698BF6B0093; Fri, 3 May 2024 09:02:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4DB686B008A for ; Fri, 3 May 2024 09:02:00 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5C2891C03D5 for ; Fri, 3 May 2024 13:01:59 +0000 (UTC) X-FDA: 82077097158.10.4CEF679 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf14.hostedemail.com (Postfix) with ESMTP id B2FD4100010 for ; Fri, 3 May 2024 13:01:56 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf14.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714741317; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=psSQGy7p8y3Jxphkp4XEZOCexV2lMiMYK/FCbnHZ9GE=; b=5n7Hv05EgMcOV35Ea/AmRT2rVm+qRDq2CEhpEUECUEW6VRT3BDkGjOju9zPLcrMlAukePD +Q46U5wNqD+jJ7UYHlEzFlEHP/m2C2/iVkOrfa6EyNvfhU1mMKG3Af9ZZFpJmiRMPDkCBQ mA+BRfPRwUfux64/kgZDxQk2PmeAx68= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf14.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714741317; a=rsa-sha256; cv=none; b=HIWdptBz0qXyizK+bryf95J2+eazwy5kVdzR7IzooY4dgO6kxjDKvgVQJCFS6sgT3BqICh WkUcJSuhdPkYnStV5dkReJi7rRql2+xZHfpCNTCBFPgQXpLtmoQJ780zFLrkFbyz2EF7hq 9c+Q0NIpE/9nMGxr6toc+7ssL1ni9aU= 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 CC3E013D5; Fri, 3 May 2024 06:02:20 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7777C3F73F; Fri, 3 May 2024 06:01:52 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, joey.gouly@arm.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev Subject: [PATCH v4 00/29] arm64: Permission Overlay Extension Date: Fri, 3 May 2024 14:01:18 +0100 Message-Id: <20240503130147.1154804-1-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Stat-Signature: fthd5kenwtrxeepfx1hkno97f6xefsqg X-Rspamd-Queue-Id: B2FD4100010 X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1714741316-690800 X-HE-Meta: U2FsdGVkX1+WTJfzP2djTzOI/UKxfp/6zQ2vbmLWue8O2NMtS1gdPA2/IEfILDEjZ9GBak2JRBUK1tMfPvAZkIkHDv335mPTG4ygHx5E39kJCC29CRRurbaUNxxLkXDv7r0GCrqTCt/YmgrNAy0UbbwWjEyXzF8vqwH/sBnc9aboIWHTp5AUinFAYtHBHisSkWfEW8JDLDYvjOAvonoHVqHghzgLOuAttjCEyaVR+Wacy3oR7cWEXgP1/ZOnvmljHrJizBCPhfUt1Pt0xCImPQMZBlJxKRD790MNod6bL9dKDJRrccOnJ732n90AP/akxfvaUbs2CqmeVnPcGXStIb0qY+EuQMc86kQWyqPTcX9cSv7bEis+yKme43+BA/65iUBd+iDe6/Cq7WDYWG9LXSGmLoJ2sGefVA5pSXJLimFkM7G2S/qsyB98oxP20ZZlPGGoRDXXIIaNU+60ulI74xvlCbQnKOWEUdWspAMoD6qxNeWhpfaRzJnWNKwz6UFAoBu/WBann4xevuVG9fCtLjTpg8cHMpqQibDnNzq2I/xgnDo96JJQYoV7uicxddxOM4q6PBcBL0s5OSnsjjXhLPNsegBR5tanD/VALb+378QtaCg8KdpXdLY72e2E2BOW+LeeFo9VNXDjI7UCVjITuVUcL2nfk1cslQZOU6HO0/fizEAvk6u8LtcEFo4W9iVfWWkPNPfNkkgXdMgdV0Yo/00e8eG7LlCDqzu5JQ2cOvBmYZ7jt6PAALpXsq+aTWUAl08UITpghZTcZreRTtCqNqg3WuMJ/k6mJPiG9TviVSyo2tVZ/RZsJ4ZNscU1zi/JsfU8Xga7dbgdb2msRzBZ63I2mZ2foormiKLHnvRoAHX39LpNNRcY17T1lSDT7ZPwkdYv32/maYR2guHGkqWJerFjXgrz2OJkKYbLApkbJSWkFFn+Ax3Ke4KKacdSsxZqVB6MsTfrdJo+1k/sQAU dXz6a5qg +AErO8UbUo/9xuDYpuXqvnWDqUv+DFnQPNh/nAWOmrhG40yAUQuWU69n5kO9+Mu8mQCO0udGmWABigfFsqNzZQ2+5vFyarhSPcb5h X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi all, This series implements the Permission Overlay Extension introduced in 2022 VMSA enhancements [1]. It is based on v6.9-rc5. One possible issue with this version, I took the last bit of HWCAP2. Changes since v3[2]: - Moved Kconfig to nearer the end of the series - Reworked MMU Fault path, to check for POE faults earlier, under the mm lock - Rework VM_FLAGS to use Kconfig option - Don't check POR_EL0 in MTE sync tags function - Reworked KVM to fit into VNCR/VM configuration changes - Use new AT instruction in KVM - Rebase onto v6.9-rc5 The Permission Overlay Extension allows to constrain permissions on memory regions. This can be used from userspace (EL0) without a system call or TLB invalidation. POE is used to implement the Memory Protection Keys [3] Linux syscall. The first few patches add the basic framework, then the PKEYS interface is implemented, and then the selftests are made to work on arm64. I have tested the modified protection_keys test on x86_64, but not PPC. I haven't build tested the x86/ppc arch changes. Thanks, Joey Joey Gouly (29): powerpc/mm: add ARCH_PKEY_BITS to Kconfig x86/mm: add ARCH_PKEY_BITS to Kconfig mm: use ARCH_PKEY_BITS to define VM_PKEY_BITN arm64: disable trapping of POR_EL0 to EL2 arm64: cpufeature: add Permission Overlay Extension cpucap arm64: context switch POR_EL0 register KVM: arm64: Save/restore POE registers KVM: arm64: make kvm_at() take an OP_AT_* KVM: arm64: use `at s1e1a` for POE arm64: enable the Permission Overlay Extension for EL0 arm64: re-order MTE VM_ flags arm64: add POIndex defines arm64: convert protection key into vm_flags and pgprot values arm64: mask out POIndex when modifying a PTE arm64: handle PKEY/POE faults arm64: add pte_access_permitted_no_overlay() arm64: implement PKEYS support arm64: add POE signal support arm64: enable PKEY support for CPUs with S1POE arm64: enable POE and PIE to coexist arm64/ptrace: add support for FEAT_POE arm64: add Permission Overlay Extension Kconfig kselftest/arm64: move get_header() selftests: mm: move fpregs printing selftests: mm: make protection_keys test work on arm64 kselftest/arm64: add HWCAP test for FEAT_S1POE kselftest/arm64: parse POE_MAGIC in a signal frame kselftest/arm64: Add test case for POR_EL0 signal frame records KVM: selftests: get-reg-list: add Permission Overlay registers Documentation/arch/arm64/elf_hwcaps.rst | 2 + arch/arm64/Kconfig | 22 +++ arch/arm64/include/asm/cpufeature.h | 6 + arch/arm64/include/asm/el2_setup.h | 10 +- arch/arm64/include/asm/hwcap.h | 1 + arch/arm64/include/asm/kvm_asm.h | 3 +- arch/arm64/include/asm/kvm_host.h | 4 + arch/arm64/include/asm/mman.h | 8 +- arch/arm64/include/asm/mmu.h | 1 + arch/arm64/include/asm/mmu_context.h | 51 ++++++- arch/arm64/include/asm/pgtable-hwdef.h | 10 ++ arch/arm64/include/asm/pgtable-prot.h | 8 +- arch/arm64/include/asm/pgtable.h | 34 ++++- arch/arm64/include/asm/pkeys.h | 110 ++++++++++++++ arch/arm64/include/asm/por.h | 33 +++++ arch/arm64/include/asm/processor.h | 1 + arch/arm64/include/asm/sysreg.h | 3 + arch/arm64/include/asm/traps.h | 1 + arch/arm64/include/asm/vncr_mapping.h | 1 + arch/arm64/include/uapi/asm/hwcap.h | 1 + arch/arm64/include/uapi/asm/sigcontext.h | 7 + arch/arm64/kernel/cpufeature.c | 23 +++ arch/arm64/kernel/cpuinfo.c | 1 + arch/arm64/kernel/process.c | 28 ++++ arch/arm64/kernel/ptrace.c | 46 ++++++ arch/arm64/kernel/signal.c | 52 +++++++ arch/arm64/kernel/traps.c | 12 +- arch/arm64/kvm/hyp/include/hyp/fault.h | 5 +- arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 29 ++++ arch/arm64/kvm/sys_regs.c | 8 +- arch/arm64/mm/fault.c | 56 ++++++- arch/arm64/mm/mmap.c | 9 ++ arch/arm64/mm/mmu.c | 40 +++++ arch/arm64/tools/cpucaps | 1 + arch/powerpc/Kconfig | 4 + arch/x86/Kconfig | 4 + fs/proc/task_mmu.c | 2 + include/linux/mm.h | 20 ++- include/uapi/linux/elf.h | 1 + tools/testing/selftests/arm64/abi/hwcap.c | 14 ++ .../testing/selftests/arm64/signal/.gitignore | 1 + .../arm64/signal/testcases/poe_siginfo.c | 86 +++++++++++ .../arm64/signal/testcases/testcases.c | 27 +--- .../arm64/signal/testcases/testcases.h | 28 +++- .../selftests/kvm/aarch64/get-reg-list.c | 14 ++ tools/testing/selftests/mm/Makefile | 2 +- tools/testing/selftests/mm/pkey-arm64.h | 139 ++++++++++++++++++ tools/testing/selftests/mm/pkey-helpers.h | 8 + tools/testing/selftests/mm/pkey-powerpc.h | 3 + tools/testing/selftests/mm/pkey-x86.h | 4 + tools/testing/selftests/mm/protection_keys.c | 109 ++++++++++++-- 51 files changed, 1027 insertions(+), 66 deletions(-) create mode 100644 arch/arm64/include/asm/pkeys.h create mode 100644 arch/arm64/include/asm/por.h create mode 100644 tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c create mode 100644 tools/testing/selftests/mm/pkey-arm64.h