From patchwork Fri Oct 27 18:08:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13438772 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 E6C46C25B70 for ; Fri, 27 Oct 2023 18:09:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EA9C6B0382; Fri, 27 Oct 2023 14:09:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 574226B03D8; Fri, 27 Oct 2023 14:09:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43B256B03D9; Fri, 27 Oct 2023 14:09:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 307AD6B0382 for ; Fri, 27 Oct 2023 14:09:08 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0BD03A09C9 for ; Fri, 27 Oct 2023 18:09:08 +0000 (UTC) X-FDA: 81392027976.29.7359F54 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf29.hostedemail.com (Postfix) with ESMTP id 70C86120017 for ; Fri, 27 Oct 2023 18:09:05 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698430146; a=rsa-sha256; cv=none; b=Q8MWT/hEDSaTTwbmAhJB0btniiot1wnTt4X7j+CnMSoe4NgJnN9oZHK4QLVMVApc1ohnqa dRoAq1dd/eIto1nIlcBuTzamy3dRkD4bAM1S6JfpKpOzNkrRUatRJJaxRsz41n2visNyJ1 9z5ialLnb1JCfhTzwPSnUPp1BmaCw/U= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.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=1698430146; 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=wAxA2behC9XWjF/w4hUCkL5uvvYgCYzkge3OuADPEOo=; b=VSPL04vfz/PvwPfcPb/TLdbsVlZ+kL0HOlzH6whhTom1xH3z9VAakop4Xn14XuOL0ncAo+ 0DHTmBb9uAlOs6aUIEu+wrSEp4R6CG6c43+SSrf/QC3+g7hVReosIYRVRcZE1pO/BK+aIm QYk/tpv8VyEQjEi7D1LRg4Ez9rw+Lz0= 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 E70AB1424; Fri, 27 Oct 2023 11:09:45 -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 232DF3F64C; Fri, 27 Oct 2023 11:09:02 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: akpm@linux-foundation.org, aneesh.kumar@linux.ibm.com, broonie@kernel.org, catalin.marinas@arm.com, dave.hansen@linux.intel.com, joey.gouly@arm.com, maz@kernel.org, oliver.upton@linux.dev, shuah@kernel.org, will@kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, James Morse , Suzuki K Poulose , Zenghui Yu Subject: [PATCH v2 00/20] Permission Overlay Extension Date: Fri, 27 Oct 2023 19:08:26 +0100 Message-Id: <20231027180850.1068089-1-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 70C86120017 X-Stat-Signature: 4q1nfxgptfdc8zge8hykybd49wpbiowg X-HE-Tag: 1698430145-305778 X-HE-Meta: U2FsdGVkX1/gFCXG3pkU8MvwlBm7Q+XPYAoA24RxWzlmonTJOPxowvIUcEKE9CIg4CWnDwwW4m3PLb3I81s0SEclaJRBEYIGxXc4BOIilGL2ildzidVkCsLjTnhboLQq2kfigzaZa6cxdPhfWfjXgfhMe6xLiJem36I+pmSq6q/vm/ohTutFFXk1oHPjy9DJ6VUu8qMovMGOQ8rzDGnndlaCMNlbewKAEyTpunRfS8+ghS8I5MswCGjGaBEYpU2iA4kLnIolpIZKsOuMfJKGK1IRuClhNNWZt0sMDEz2xtP7VyFDpxQmfr7VQGwrhqq4TkSRFOJVL8C6RHnwQG4kgRkKYW6GLWLMKslfNuDl0Ttk3QaRQn2mthF00xsanMJmqhRnqmtI+uWSJF+A1XC7WvFjHBjDX2bDq2IIA95otDBQWY/PXZM0Ce+CmQTrXYKwAkxiMoBuVFQnYxtGeAyZiivr/2QI09+w1O45WHaJ3TkzvIZsGv77ruNuKLPHWZO/BTWCt9tAOZ26YBBTOfGaVQXbYFT77no2HorM+TvHXXLqr3ZCwsUFplkHI8eQXSNPiKtOOPlf9LPCN5vLQR9M93c/TBt5GdzHSDfJnu9XMq0OCzgKxTxunKklO+2gufMeS07vvqKVHMOfYHGdzCwR7WlSg6s8usIUQ/9TwdMxWJZ9WA1BBoROWIK/spCVMxKLk/a8xwtLlgtV+sEVONaikjdW5pK3rM+sNNmDuwwy4NxN+VY78mtc0SgGkXUJ+FlUVZ8PC7Ny7WiNqD+lOaqM7I8JJwh9t1g41qVlmf+pqOZCIhiRkAiRWohQDn0lq6DFBFEGMt4zSJiwSrC8wMeKjkqd3KZX2MLeKKDDERT7Xf7LiAT7XYK0/kCeRdzr2VHIq0jCMsTgUuXTC8Fdp+zm33kybvalxhPwJpkr1+qCO69BxvPiebt6l/6zedmDDGMwC95KKNvcdoI3vig1ZAG UJuRgSOS 04dmZ/VxBd1IRzZaE2gkCtKU0YJiEmNcBZYh1jfdj+vUzi2LD/qE9Ka7+CIzL8WHFO2U7qANLMasfq5f4ZXgA9TZ4uJGWx6unHRO1wAzAjBO6FMD8LWRiMIkJo/VpGQ3TExOuFUubJFZ6JIhoz4ve7SCz1p5e0+T8yWf4mS3zrJeT4XuTDplkIeT3ft/npP0efHTrNhvqHsaZZWQsqPp0HOCU3w0eGTCYAFYI 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: Hello everyone, This series implements the Permission Overlay Extension introduced in 2022 VMSA enhancements [1]. It is based on v6.6-rc3. Changes since v1[2]: # Added Kconfig option # Added KVM support # Move VM_PKEY* defines into arch/ # Add isb() for POR_EL0 context switch # Added hwcap test, get-reg-list-test, signal frame handling test ptrace support is missing, I will add that for v3. 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. There was discussion about what the 'default' protection key value should be, I used disallow-all (apart from pkey 0), which matches what x86 does. I have tested the modified protection_keys test on x86_64 [5], but not PPC. I haven't build tested the x86/ppc changes, will work on getting at least an x86 build environment working. 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/20230927140123.5283-1-joey.gouly@arm.com/ [3] Documentation/core-api/protection-keys.rst [4] https://lore.kernel.org/linux-arm-kernel/20230919092850.1940729-7-mark.rutland@arm.com/#t [5] test_ptrace_modifies_pkru asserts for me on a Ubuntu 5.4 kernel, but does so before my changes as well Joey Gouly (24): arm64/sysreg: add system register POR_EL{0,1} arm64/sysreg: update CPACR_EL1 register arm64: cpufeature: add Permission Overlay Extension cpucap arm64: disable trapping of POR_EL0 to EL2 arm64: context switch POR_EL0 register KVM: arm64: Save/restore POE registers arm64: enable the Permission Overlay Extension for EL0 arm64: add POIndex defines arm64: define VM_PKEY_BIT* for arm64 arm64: mask out POIndex when modifying a PTE arm64: enable ARCH_HAS_PKEYS on arm64 arm64: handle PKEY/POE faults arm64: stop using generic mm_hooks.h arm64: implement PKEYS support arm64: add POE signal support arm64: enable PKEY support for CPUs with S1POE arm64: enable POE and PIE to coexist 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 | 3 + arch/arm64/Kconfig | 18 +++ 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_arm.h | 4 +- arch/arm64/include/asm/kvm_host.h | 4 + arch/arm64/include/asm/mman.h | 8 +- arch/arm64/include/asm/mmu.h | 2 + arch/arm64/include/asm/mmu_context.h | 51 ++++++- arch/arm64/include/asm/page.h | 10 ++ arch/arm64/include/asm/pgtable-hwdef.h | 10 ++ arch/arm64/include/asm/pgtable-prot.h | 8 +- arch/arm64/include/asm/pgtable.h | 26 +++- 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 | 16 ++ arch/arm64/include/asm/traps.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 | 19 +++ arch/arm64/kernel/signal.c | 51 +++++++ arch/arm64/kernel/traps.c | 12 +- arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 10 ++ arch/arm64/kvm/sys_regs.c | 2 + arch/arm64/mm/fault.c | 44 +++++- arch/arm64/mm/mmap.c | 9 ++ arch/arm64/mm/mmu.c | 40 +++++ arch/arm64/tools/cpucaps | 1 + arch/arm64/tools/sysreg | 15 +- arch/powerpc/include/asm/page.h | 11 ++ arch/x86/include/asm/page.h | 10 ++ fs/proc/task_mmu.c | 2 + include/linux/mm.h | 13 -- tools/testing/selftests/arm64/abi/hwcap.c | 13 ++ .../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 | 138 ++++++++++++++++++ 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 | 29 ++-- 49 files changed, 880 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