From patchwork Thu Aug 22 15:10:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773670 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 52032C531DF for ; Thu, 22 Aug 2024 15:11:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF4BF6B02EB; Thu, 22 Aug 2024 11:11:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA4A36B02EC; Thu, 22 Aug 2024 11:11:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9452D6B02ED; Thu, 22 Aug 2024 11:11:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7644B6B02EB for ; Thu, 22 Aug 2024 11:11:28 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F126FA8D50 for ; Thu, 22 Aug 2024 15:11:27 +0000 (UTC) X-FDA: 82480220214.17.09DA101 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf14.hostedemail.com (Postfix) with ESMTP id 373D210001D for ; Thu, 22 Aug 2024 15:11:25 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; 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; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339404; 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=1oMaKLN3AtqVYOoRQKNxswTCUzkgsbT4GtGNXCGcqwc=; b=7x+vox2R2VSvgY28had2HK9KKtEEDPEcj1hVpM5+M5WDvENvv42yIMOZJslZUXN5MGVhkc bS6j1YTG6VLoBO0RHg0LpJizxwTm24VZCyHvTUOKVbLL3ASyjx0SvS4WQ3HaeEeWbFmx5W idlgBDpNOH/XMEyFWcTTvO+zqQNa65c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339404; a=rsa-sha256; cv=none; b=OrRurciZ93thdCDPVShyw4XM3lL2a/IjoAneOxqolqitLqIUDGHqZLQQX6ekmPxePpQt81 ZFyM1/csnrNFUTq10xcHJyLMYBoyxr5CcIDy2a7jTipiHqhM/RLwU5k5t26nOQ4jjuvhns B0uZfyYTGiKFoXJjBgQIu2EL/TPaMYk= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; 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; dmarc=pass (policy=none) header.from=arm.com 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 5B47FDA7; Thu, 22 Aug 2024 08:11:50 -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 3A0263F58B; Thu, 22 Aug 2024 08:11:20 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.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, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: [PATCH v5 00/30] Permission Overlay Extension Date: Thu, 22 Aug 2024 16:10:43 +0100 Message-Id: <20240822151113.1479789-1-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Stat-Signature: csmbjqfs9m3dy7kpdhxe7qx7p63wcumm X-Rspamd-Queue-Id: 373D210001D X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724339485-282406 X-HE-Meta: U2FsdGVkX19OzlazVIUSEAOKkMq92bdfMt8c/t02b196uA6pVXdgwA7gi8t7DL/FAaiygMBgHa2PpGKcm7hAKeOuEq0I47kXePhytBZFGEsesK7YQ04baJpU+QAsL+GWqwqiSwTs95g78tKdmMafZudjEyInZ4PIEK20gIxUA2lKqKmeL9D4StNbP6rwvH9q8HwCnoQoaL0Rb2jzshIp9Tas2TfdrmnU5XDPIiRzkDXa7t5XP6oIJGR1ifenJ3akjdqgc29QNn+P5uwutZ/XMeGWaDO8Uzlf7qPowhT1p+5pTdgaDLmen6NI8HechFYoiB9n0dAK+GkO2Wxajxzi47aBJEN/AhPs3IRwGet+vuMk3qsCRK20LYrvb6YR5SGoeXP41Nvd7vXDJBbJ7rTZx+VNJMJPxJusKMP6O/BlhWARJjDCj2WUIXUEAgppwtkb+lLRT5oncFiM78G803HfguPrrcRBcAEJ0sRR2hBUlNK6RtkSIZYWTikr4mmLJiIKa+1mj7M2opTZ4RW6nFP+1HR9soox5s0aUOLeGnBebCb+NDLcNIm9cp1LiuYXYmA0710JpHQ+H+kDWGjKbEhCBExVBRnVOqkzmy1yPcDpVmw7HYvk44g1BODdq7TpTNA+ExM6kPtac08PW3XMrPTorMGR/9drnFqLAy62tnQyZVjV84XlqzTw+i6D4oH3oQCfW71mv/VePGZ8xGwc3tURjqV7ptVPA+V6k15V2jzr3/5ej3OKRRZWr54pLRenQoB1f7aPrfC9Fl9q/uODbtGf9dK1TnzjeEcwNz9T+UZX6tS1Qgk8lZuCy91nL8z2fgA8eYwcXp/ko+YVf8/aTvBR3AW45/98qFZfWSCWLhigz392jACsV0GdxJXCfd0EVt3ZIRScPlGJXNJhxqez0tjGwnBDJgi0EVkkk7e6W2lzFD8W07EcJCEdSr6EU+2SchZwrw6BsB5gkuJpCUzJ+Yw dmIXbpW0 fQUaAm4k2RI8VKAUIMuFi66cvgWLjHBwke8P319ZYAYRIHeImV5jxvnHlif2ptH5bPD0XXaLE/4BAWk36P7GqzkXv4NBQ58/1sxGdGQwEZzaRyUGnrKFhemj1zmeWAbdctm3jzYexRVLPuBG3KrW+ZuTokrOuKktcwXcaY6ijoZaRDMQcKGCOyJBBHbmSAQrDJUuCU4YR0hx8HvUN82XgDkz16A== 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.11-rc4. Changes since v4[2]: - Added Acks and R-bs, thanks! - KVM: - Move POR_EL{0,1} handling inside TCR_EL2 blocks - Add visibility functions for registers [4] - Make ID_AA64MMFR3_EL1 writable - use system_supports_poe() more consistently - use BIT instead of hex constants - fix off-by-one in arch_max_pkey() macro - add PKEY_DISABLE_EXECUTE and PKEY_DISABLE_READ - Update some comments and commit messages. - No change to when we save/restore POR_EL0 for signals! Conflicts with GCS: - Uses the same (last) bit in HWCAP2 - Uses the same VM_HIGH_ARCH_5 Conflicts with arm64 KVM: - Maz has taken patch 8 into one of his own series - I have taken and modified a patch from Maz (patch 9) 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 [1] https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/arm-a-profile-architecture-2022 [2] https://lore.kernel.org/linux-arm-kernel/20240503130147.1154804-1-joey.gouly@arm.com/ [3] Documentation/core-api/protection-keys.rst [4] https://lore.kernel.org/linux-arm-kernel/20240806-kvm-arm64-get-reg-list-v2-0-1d3fbc7b6844@kernel.org/ Joey Gouly (30): 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 KVM: arm64: Sanitise ID_AA64MMFR3_EL1 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/ptrace: add support for FEAT_POE arm64: enable POE and PIE to coexist arm64: enable PKEY support for CPUs with S1POE 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 | 23 +++ 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 | 10 +- arch/arm64/include/asm/mmu.h | 1 + arch/arm64/include/asm/mmu_context.h | 46 +++++- 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 | 108 ++++++++++++++ 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/mman.h | 9 ++ 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 | 62 ++++++++ arch/arm64/kernel/traps.c | 6 + arch/arm64/kvm/hyp/include/hyp/fault.h | 5 +- arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 27 ++++ arch/arm64/kvm/sys_regs.c | 25 +++- arch/arm64/mm/fault.c | 55 ++++++- arch/arm64/mm/mmap.c | 11 ++ arch/arm64/mm/mmu.c | 45 ++++++ 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 ++++++++++++-- 52 files changed, 1060 insertions(+), 63 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