From patchwork Wed Sep 27 14:01:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13400925 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 94D8CE80AAC for ; Wed, 27 Sep 2023 14:13:28 +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=4dJC45pCLoqZBC3OoXGk02gm2d6jAMvgIZAOeX+YEPM=; b=g46In0dYkfpV7j CxLsoafJsWYXZioGnymvuK5A+z3C6s66RnAFOTxpg5I+UJpekrWfRadTiJLYhRG3Ukh99kD1fEW/l w0posS4HQu4yjwnNmMnNnM/39qUiVsjHByQTmCTqXwL4Q4ixoR9EzTq0a3mGotEZmAac49471fWOG ClU5CYj/OYNbp1bak9tXq7lvgwau0uE9w52RxMiWal5ito6UU4kjb/2eihIdtuRJr+LygS5rYuxo/ oSPSn7I6DyiwWb7Q02/PkowiOGhaafIedEcNXmbE7+WV9NgRLVQ7kTqRRFbr9XAaQJ+mulpxs5dxd lHKNhnVyL+tFxZBGdo1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qlVHh-0016ia-37; Wed, 27 Sep 2023 14:13:01 +0000 Received: from mail-vi1eur04on0606.outbound.protection.outlook.com ([2a01:111:f400:fe0e::606] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qlVHe-0016hR-0c for linux-arm-kernel@lists.infradead.org; Wed, 27 Sep 2023 14:13:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GVoWYHMQcX5LFp8POkjXMK8ACJ6uEom3LEhUEexHH4s=; b=Ut0XBGmKgLu6cNap0G99Z8i/W4X2PvLYjOZQoFjkGFpLNH9NqhhPAAosjX3R0lM5mk/9OKWohjQxoD4ooZ6WeEIO9CoXFT4lM0mS/0ADmqdHPr3UmZ8Z6dSA9hzUpF45UlXlbeZOz3QJRO00N5WBV5wkzrDue5L7cd/B9aBLehA= Received: from AM6P194CA0078.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:8f::19) by AS8PR08MB9868.eurprd08.prod.outlook.com (2603:10a6:20b:5ac::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.28; Wed, 27 Sep 2023 14:12:50 +0000 Received: from AM7EUR03FT017.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8f:cafe::af) by AM6P194CA0078.outlook.office365.com (2603:10a6:209:8f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.21 via Frontend Transport; Wed, 27 Sep 2023 14:12:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT017.mail.protection.outlook.com (100.127.140.184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.21 via Frontend Transport; Wed, 27 Sep 2023 14:12:50 +0000 Received: ("Tessian outbound d219f9a4f5c9:v211"); Wed, 27 Sep 2023 14:12:49 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 8680f253fca9f365 X-CR-MTA-TID: 64aa7808 Received: from 56cd42496307.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id BD77DB7B-7D9B-4214-A879-AE631469B97F.1; Wed, 27 Sep 2023 14:01:38 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 56cd42496307.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 27 Sep 2023 14:01:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Axwwro8FvbUoEUHE1P2YtbVW4ulMJtv8dTqFFwNVuoiLx4tdkZ0R3zDybug+9C69g5WyD6LKeMga6nhkBM/3ubc1mpMmIyxszF2+886bq8aempn+PTg2KlEKnWC05BdEiLTHTEW+nqpnPpd3Vj3Fwo9VSrChqRXs7/HDVeF/3GGuS5+zp7GCkWKJGnemW0ZmsR0CdoOgPiwpuyVwvmVoM3YGgw1AXu151gpdT/715LTiUlna0W9zuQYssN8n55mH8IzJG/8nrnxm3mucdN2/0HedNvFsSpqNj7hMTKb7ibsn/qxu+9Dj4MLXwYf9yasPkWyG84Wq/7WndobJTFWEFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GVoWYHMQcX5LFp8POkjXMK8ACJ6uEom3LEhUEexHH4s=; b=UFLLBUaF5mMBwt8H2F/zI+2GPURLGaPfnv3GcVgjalAMkXMIoxAS+iatYtzrwOv55vgYnYyimUuCOptURVXHQ3ockVZWUoMimV5pU18SPIPqzT4cQ08l5dzHZGumfaMDXS8heWd2Qq2sd4ttWVPX5j0rsr1DJzmDwWN//OGcvqkygGHu8XKEAICJtwDvdKfgRguyUybAtVinnHBOoxDRDSrli5nCdkCtH6r83yAnNNdePXMcL4v/Aw8Dn+wn/GNni0yWluRJbRoGOyNKkMl8TTlQh3h+Xeghw0t/vMglmV+YQfZ0klTYg6p/TVOq2igigHCuazqU8+6Cbg7iMut6Eg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.infradead.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GVoWYHMQcX5LFp8POkjXMK8ACJ6uEom3LEhUEexHH4s=; b=Ut0XBGmKgLu6cNap0G99Z8i/W4X2PvLYjOZQoFjkGFpLNH9NqhhPAAosjX3R0lM5mk/9OKWohjQxoD4ooZ6WeEIO9CoXFT4lM0mS/0ADmqdHPr3UmZ8Z6dSA9hzUpF45UlXlbeZOz3QJRO00N5WBV5wkzrDue5L7cd/B9aBLehA= Received: from AS9PR07CA0053.eurprd07.prod.outlook.com (2603:10a6:20b:46b::20) by VI1PR08MB5405.eurprd08.prod.outlook.com (2603:10a6:803:12f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.19; Wed, 27 Sep 2023 14:01:35 +0000 Received: from AM7EUR03FT007.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:46b:cafe::95) by AS9PR07CA0053.outlook.office365.com (2603:10a6:20b:46b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.21 via Frontend Transport; Wed, 27 Sep 2023 14:01:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by AM7EUR03FT007.mail.protection.outlook.com (100.127.140.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.21 via Frontend Transport; Wed, 27 Sep 2023 14:01:35 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 27 Sep 2023 14:01:34 +0000 Received: from e124191.cambridge.arm.com (10.1.197.45) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 27 Sep 2023 14:01:33 +0000 From: Joey Gouly To: CC: , , , , , , , , , , , , , Subject: [PATCH v1 00/20] Permission Overlay Extension Date: Wed, 27 Sep 2023 15:01:03 +0100 Message-ID: <20230927140123.5283-1-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AM7EUR03FT007:EE_|VI1PR08MB5405:EE_|AM7EUR03FT017:EE_|AS8PR08MB9868:EE_ X-MS-Office365-Filtering-Correlation-Id: f3157933-02f3-4aec-0d61-08dbbf63d52d x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 49ZRb9FACtwHwO01o8ndvLJNjlM8sqXwMm/tHTS6vDpecslcbvI0rVMspBg8/7G2lx5+b326tORkaCCRzQPZAPL3mpH6Hqda15wv1jFd8gY90UhSGJkNa7B3mxV5MyxZb/l09Qsb4ESl7OX+EruEn15EYNrOsHIKIa8mT/QELtwkYRxMMwK08i0EbF5vgTon5oRZtStDa0NnBe2ycWIB8CxIc+d9yYUx/MZwpQfc1jNGNGhMrw0LGyIYAOtyUDxMmtIrwSpsEIP4LRrTa2Aq5peyiJ0OcrQI3B/GFoXyIeVlEhIit9Dd0bFedDBnOMAYlzdUtpLDYjGDhI3XNbWBHXseZp63q4Eq5nYZKyy2MjVeMXdmG62X0t5SjN1DFoliaK+iNPI75qVqYmY9BPmPh8IBMibpj3BcUeFXSRFHmgMvzHVetMlmds3E4GehqEAAeswgyS+FCTZBYUe8vnMm5qq03qYzFy19MI+9jLFXAsCUwmKzwiGyaKudrlXxlHVUPEopyOXUUSa2b1RomCSqeerdJcyt5alaCl3qPEYhIZIeICthJThrsqy4DSWw0ZuEX1eMfs3tl/S7CNI7NJ1Q/itM8QgUfxVvmQmw7LOimsgk4Kx28pftT/DMdvEO/cprTNmqkr8qgiXGVsaGizsNa/DCjJO7pyw4/UWda7exFAT43GpK49MDs7hMYOSy3Nf2VzdwTNIiXe1dhX1+n4ZFOKyIISRt27rdDsQEvfMmVTpkbUYI0A5bT7dQ+7eIvExQ X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(39860400002)(346002)(136003)(376002)(230922051799003)(82310400011)(1800799009)(451199024)(186009)(46966006)(36840700001)(7696005)(478600001)(6666004)(83380400001)(70586007)(54906003)(70206006)(8676002)(8936002)(316002)(6916009)(5660300002)(36860700001)(41300700001)(1076003)(2616005)(36756003)(40480700001)(426003)(86362001)(82740400003)(44832011)(4326008)(2906002)(81166007)(47076005)(336012)(26005)(7416002)(356005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5405 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT017.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 2d15f12f-8171-451f-d9cc-08dbbf624322 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VwTvdzNPzswX53jXeoUf8f0dF12XE5R354VbONa2NkG+TrQvm2N/tP628hitopxmMVIVk2pAxK75nLzwS+e5UEh45NbhRFiQFnYwcg4uPR2qHHwfjXB9hVe0v3wpy72N9GQYGrdVdMyvg3JFDTNpoSNQa1RRL6YRF7D4tRyrkd0I0UuD1PXtT/r7KtgMsqTGV1wxNiyqZA8UaH19QUNTX5Q6gs1kSiqikgOi5oCBTTgXNYJPA/xo50e/u88M/YTe5fm5kYTZOEjhjCdDTRIrTXZlM3M7th3XJN7KXhCblJ+Z2X/ejmvOws2UUNdhhy/2oGJ/RdazgKVDmV7Q4xE/Y490VIUDwd8i1mol5JPVRxnH6hF4LBfcst9hbdSh4+SvpkkDyZzhRSNLzFwlMfUFuIPUglA689d47CXtIn6wOkKv5MDTBgXXDJTiGvl9gCobaV3V88ivVskz2KJbOrIQAWV5XGfJx4YETTyoqUFssg3BnelcYBIgU7xZrRrQ60OXTHqo5Pc4fN58SuLQ/JEKKKAxWEKiyaHojOB2nNKu/GalEmrs1A2MwtGPSMtkMzXDkfjEjY77OEtSywa64HOBcoDs6jG+b7Br/65k69ULtT3JN1l9DvbLviHvsgmuACbHktIcbT63cyh/AM9nDacSvifylVGWsKyz/BswlP1pCrc6MGd3dhu8JF/C8/gCsYoqyFyxatisgvCvknRw+G8kYLQZSLgj30cKzkyPn7qkTecl4MsRghmPQ8Wfm2kqdHcF X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230031)(4636009)(346002)(39860400002)(396003)(136003)(376002)(230922051799003)(186009)(82310400011)(451199024)(1800799009)(40470700004)(46966006)(36840700001)(40460700003)(2906002)(47076005)(26005)(2616005)(426003)(336012)(1076003)(36756003)(6666004)(7696005)(83380400001)(36860700001)(478600001)(86362001)(82740400003)(81166007)(107886003)(40480700001)(5660300002)(70586007)(54906003)(70206006)(44832011)(8936002)(316002)(4326008)(6916009)(8676002)(41300700001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Sep 2023 14:12:50.1599 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f3157933-02f3-4aec-0d61-08dbbf63d52d X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM7EUR03FT017.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9868 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230927_071258_396498_CA7149E2 X-CRM114-Status: GOOD ( 16.82 ) 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 Hi all, This series implements the Permission Overlay Extension introduced in 2022 VMSA enhancements [1]. It is based on v6.6-rc3. 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 [2] 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. Patch 15 contains a call to cpus_have_const_cap(), which I couldn't avoid until Mark's patch to re-order when the alternatives were applied [3] is committed. The KVM part isn't tested yet. I have tested the modified protection_keys test on x86_64 [4], but not PPC. Hopefully I have CC'd everyone correctly. Thanks, Joey Joey Gouly (20): 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 Documentation/arch/arm64/elf_hwcaps.rst | 3 + arch/arm64/Kconfig | 1 + arch/arm64/include/asm/el2_setup.h | 10 +- arch/arm64/include/asm/hwcap.h | 1 + arch/arm64/include/asm/kvm_host.h | 4 + arch/arm64/include/asm/mman.h | 6 +- arch/arm64/include/asm/mmu.h | 2 + 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 | 28 +++- 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 | 15 ++ arch/arm64/kernel/cpuinfo.c | 1 + arch/arm64/kernel/process.c | 16 ++ arch/arm64/kernel/signal.c | 51 +++++++ arch/arm64/kernel/traps.c | 12 +- arch/arm64/kvm/sys_regs.c | 2 + arch/arm64/mm/fault.c | 44 +++++- arch/arm64/mm/mmap.c | 7 + arch/arm64/mm/mmu.c | 38 +++++ arch/arm64/tools/cpucaps | 1 + arch/arm64/tools/sysreg | 11 +- fs/proc/task_mmu.c | 2 + include/linux/mm.h | 11 +- .../arm64/signal/testcases/testcases.c | 23 --- .../arm64/signal/testcases/testcases.h | 26 +++- 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 ++-- 39 files changed, 685 insertions(+), 52 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/mm/pkey-arm64.h