From patchwork Thu Aug 22 15:10:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13773684 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 A2257C531DF for ; Thu, 22 Aug 2024 15:12:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DF8D6B0304; Thu, 22 Aug 2024 11:12:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2914A6B0306; Thu, 22 Aug 2024 11:12:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 130AB6B0305; Thu, 22 Aug 2024 11:12:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E5ABD6B0303 for ; Thu, 22 Aug 2024 11:12:27 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A89471216BB for ; Thu, 22 Aug 2024 15:12:27 +0000 (UTC) X-FDA: 82480222734.23.E8A3574 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf29.hostedemail.com (Postfix) with ESMTP id C1DA512000C for ; Thu, 22 Aug 2024 15:12:25 +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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724339529; 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:in-reply-to:references:references; bh=rtB0cFu4yhRz/z4tCR4fwR+sWZaGlGCX641JW7j6vJM=; b=4AGPyzxwfdUM7W7XcDJlX/aZ8D0mDx75vMqsiI1InI1sBrfuLJjJuuZUAC3ziapDEiEpSQ TIeErAf8KkIpmq43Er6jpveeQ6ftkHAxCMYFcGkVd0ICWs/+gSaJMXtjxqXyaSNTyp5lBI PypTIjqM5GeuWjLg8qjMWiAdiSQ46w8= 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724339529; a=rsa-sha256; cv=none; b=IPmbZMk00UqMwGE3N33W/WEn/U1AxOO/Sku6fl9JY34pebXplPYZy+mBke17KBSxgy/Xf0 B0miP0AveXPhFr72rVTxiOPrmHgyJEIOVNx9XfCgoaqplCfl3PSaITIigxcrMl7NyrHKR5 505ity3o91KX51050RGfbOgZ0GA9EmQ= 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 D16131655; Thu, 22 Aug 2024 08:12: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 B2D423F58B; Thu, 22 Aug 2024 08:12: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 14/30] arm64: convert protection key into vm_flags and pgprot values Date: Thu, 22 Aug 2024 16:10:57 +0100 Message-Id: <20240822151113.1479789-15-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240822151113.1479789-1-joey.gouly@arm.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: k54hi6bpeubourqzc6fcy7uehohrbgx3 X-Rspamd-Queue-Id: C1DA512000C X-Rspamd-Server: rspam11 X-HE-Tag: 1724339545-371403 X-HE-Meta: U2FsdGVkX19H5nwpAvjl30e9OPaz/48LJN1SlGrG5xi6NwOHI1+JghVnENHSZE5LSWRrodn/orGOX1LEyAJkjh/mt9/sFvJvJpfAbg43f6c9W/0r6zkV7clp2A8oT5Vr6RRyL2wMdPfEz33Wf1Wwn9LIFeLh776Y2fYcH4V1LYi5fKpNcMg9KIUt8LrPJTxt5+yy4XTivcHpxxp0Qkeq+tNYzsvDnlO2st9QRTjNwqEvtXLw/0dvAi412QpY8MhuZveGFjwlrtWlHKFEzOPG63NeNnB0Ga7+/Dl0nvYkyRwLf299rGd1cGzLRRBkOQ642pCMgxpmNU4rVS0Q5gDje2rT1GCKhV0aa+CEwd2ws1zcyNC3G5R9izc5IFzQrcgAUohApyHNbeAJFbCe+bZDKdpYJKmhYna9O6dMtygzY6QwV+v2l7+5ev4lZXZwkwocyVzLy/TeJAVqRQ3KnPRiGasVQrF8b7+E6QxCCyV9NqeP6Bc5ISyP281N/b8UsRfldHKT21sp7kBJuccXWERrswBpF8zN2jNSS1v/MpWClx04gybkaiqZHuU2s4BTv95BP6CJqAyK9fyFBF/OZxU+3o3XDbh5v9yfpLZPVOsm+fLdqUh5+Dt6iGG6NxD8uvLjlDhv2lyVpi5BRDmeYjwbr5/XBsAITbdYEfjm4GXfFWBrQrja9Uaa2l5KeryGVpqE0KCbXOKGxtnghQyQBpkI3y53wLAu/Fy9NVTpFkOmgabUXY9KFVBnnFjIcgi91/GrgpGywluhCQ84lbRBr5CMXEpHRUO52xOovu0yVZ1qhm10J44BgzJdeiLqcX3bLiBNtYZCE5RvSNkGDjcZgZWMd20qP09QSDNXXottBZOZzZQRMUd425LdLUkB98s3NPLF1nqCIoEky3g4k6dvdtLfDn1akY4ZcNicKRWSr6TqZXrUUsrokQTexJZLURDpFjAPe5tHpTdHLTsv8Qbh5Ao xf/KH3ap 8tPA0/xUG92X6FX3MHbrgsK7p6SJFuga7u4jOmlUsv12zwWflRmMQa1m2YISLPvQVNAgz2nDv7+7NFSTVOYJGd8oXyQcJ0KZTD/Lc8vsUZCT6aN5i3qqQkwd2Hc8tK/KMn3D467yy0+yXayh4U8tpAvvgPMQvbjHvJfEa8TnIvnXqykMckAe+Brr8NU+LCBjFfKcTXJP6hFnNzwKDSqgcPFpk8SFTmbAcznthig153wRKLYQFA5cZYF3ue7JhA1GmuZcjHA6waLR3PFg= 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: Modify arch_calc_vm_prot_bits() and vm_get_page_prot() such that the pkey value is set in the vm_flags and then into the pgprot value. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/mman.h | 10 +++++++++- arch/arm64/mm/mmap.c | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git arch/arm64/include/asm/mman.h arch/arm64/include/asm/mman.h index 5966ee4a6154..52791715f6e6 100644 --- arch/arm64/include/asm/mman.h +++ arch/arm64/include/asm/mman.h @@ -7,7 +7,7 @@ #include static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, - unsigned long pkey __always_unused) + unsigned long pkey) { unsigned long ret = 0; @@ -17,6 +17,14 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, if (system_supports_mte() && (prot & PROT_MTE)) ret |= VM_MTE; +#ifdef CONFIG_ARCH_HAS_PKEYS + if (system_supports_poe()) { + ret |= pkey & BIT(0) ? VM_PKEY_BIT0 : 0; + ret |= pkey & BIT(1) ? VM_PKEY_BIT1 : 0; + ret |= pkey & BIT(2) ? VM_PKEY_BIT2 : 0; + } +#endif + return ret; } #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey) diff --git arch/arm64/mm/mmap.c arch/arm64/mm/mmap.c index 642bdf908b22..7e3ad97e27d8 100644 --- arch/arm64/mm/mmap.c +++ arch/arm64/mm/mmap.c @@ -102,6 +102,17 @@ pgprot_t vm_get_page_prot(unsigned long vm_flags) if (vm_flags & VM_MTE) prot |= PTE_ATTRINDX(MT_NORMAL_TAGGED); +#ifdef CONFIG_ARCH_HAS_PKEYS + if (system_supports_poe()) { + if (vm_flags & VM_PKEY_BIT0) + prot |= PTE_PO_IDX_0; + if (vm_flags & VM_PKEY_BIT1) + prot |= PTE_PO_IDX_1; + if (vm_flags & VM_PKEY_BIT2) + prot |= PTE_PO_IDX_2; + } +#endif + return __pgprot(prot); } EXPORT_SYMBOL(vm_get_page_prot);