Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3518365pxb; Mon, 24 Jan 2022 11:14:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFkPVtxwvUmfPxD5uBVSpNqe8fOcbIOCwe79vyDYIodzKD8PPvVJUPpeZg2JqkIdF/T7ox X-Received: by 2002:a17:902:ecc7:b0:14b:1eed:e575 with SMTP id a7-20020a170902ecc700b0014b1eede575mr14788119plh.54.1643051665556; Mon, 24 Jan 2022 11:14:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643051665; cv=none; d=google.com; s=arc-20160816; b=l5Ev52LPM5uOgfEUP6zRa4UBFF+1diHhB9sV8kD0p2uwjpR6QOQYHNJNKC9r3sAXfa PIjxyBabn/KuMQ84VylrpDmaHO7Bg93yH61n8cctImLdeml4lnbu/+uXyp2oOhbTL5+7 e1MThQ3R59NQPE+EbNNp4ycJQO5zpiJYXldabgeENYNTL73WhMoU7Tf2vMYuEzNZnazu dQF9L5dM2jbyhX64WwptWSAM4/CEfXhNzQHrKE+8n4Z7b3Rm1n5Wge0Ejp2beA9kEEjI c0ShKqdTGnaukeDpszAI8h4ZTaJfkuY5ARz8tJl70poOqDehRdSo5/SboUCpZybPyOoc PPmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=A1giDMW1IvRud4C17zyF82FQT/n8drpsE0MuMElqNtQ=; b=BiGOJXM5rHjfNchdMJszY2V3GHks9iPQJ59rrTlO7ZtjeOVXe4jrOjl4vLkUmFvTZH lhUPa5BBeZYbYcciu7jh9h4QqIEgk+kIrBsl4kCU1G6NfE5k1O7EN7yg/kjBG5iw5UJc 4IHVQXYp25vG4jJTMIu7sZjydjvjOhrN2ihGP8Mud+6ewj1CSYbEYRG3Mlt8iaV0+QGX riAUZGF3zdl/3s5e9w91kQdZcaVGlPAyuxR1PfDXxy+k62NBxeGyMkYsqYYO2MsW5KAD Wy9htpiT3hDrirfN+ID8x0yT/52RXVsA/NLwOZ4w81pKXAWHDz2WPgRKBCGPiqwqGaMP SjUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f17si14449411pfj.217.2022.01.24.11.14.13; Mon, 24 Jan 2022 11:14:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242709AbiAXM5d (ORCPT + 99 others); Mon, 24 Jan 2022 07:57:33 -0500 Received: from foss.arm.com ([217.140.110.172]:32872 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242707AbiAXM5Z (ORCPT ); Mon, 24 Jan 2022 07:57:25 -0500 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 0F327D6E; Mon, 24 Jan 2022 04:57:25 -0800 (PST) Received: from p8cg001049571a15.arm.com (unknown [10.163.43.190]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 449A63F774; Mon, 24 Jan 2022 04:57:20 -0800 (PST) From: Anshuman Khandual To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, hch@infradead.org, akpm@linux-foundation.org, Anshuman Khandual , Michael Ellerman , Paul Mackerras , linuxppc-dev@lists.ozlabs.org Subject: [RFC V1 04/31] powerpc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT Date: Mon, 24 Jan 2022 18:26:41 +0530 Message-Id: <1643029028-12710-5-git-send-email-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1643029028-12710-1-git-send-email-anshuman.khandual@arm.com> References: <1643029028-12710-1-git-send-email-anshuman.khandual@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed. While here, this also localizes arch_vm_get_page_prot() as powerpc_vm_get_page_prot(). Cc: Michael Ellerman Cc: Paul Mackerras Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/mman.h | 3 +- arch/powerpc/include/asm/pgtable.h | 19 ------------ arch/powerpc/mm/mmap.c | 47 ++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index b779603978e1..ddb4a3687c05 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -135,6 +135,7 @@ config PPC select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAS_UACCESS_FLUSHCACHE select ARCH_HAS_UBSAN_SANITIZE_ALL + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_KEEP_MEMBLOCK select ARCH_MIGHT_HAVE_PC_PARPORT diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h index 7cb6d18f5cd6..7b10c2031e82 100644 --- a/arch/powerpc/include/asm/mman.h +++ b/arch/powerpc/include/asm/mman.h @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, } #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey) -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags) +static inline pgprot_t powerpc_vm_get_page_prot(unsigned long vm_flags) { #ifdef CONFIG_PPC_MEM_KEYS return (vm_flags & VM_SAO) ? @@ -34,7 +34,6 @@ static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags) return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0); #endif } -#define arch_vm_get_page_prot(vm_flags) arch_vm_get_page_prot(vm_flags) static inline bool arch_validate_prot(unsigned long prot, unsigned long addr) { diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h index d564d0ecd4cd..3cbb6de20f9d 100644 --- a/arch/powerpc/include/asm/pgtable.h +++ b/arch/powerpc/include/asm/pgtable.h @@ -20,25 +20,6 @@ struct mm_struct; #include #endif /* !CONFIG_PPC_BOOK3S */ -/* Note due to the way vm flags are laid out, the bits are XWR */ -#define __P000 PAGE_NONE -#define __P001 PAGE_READONLY -#define __P010 PAGE_COPY -#define __P011 PAGE_COPY -#define __P100 PAGE_READONLY_X -#define __P101 PAGE_READONLY_X -#define __P110 PAGE_COPY_X -#define __P111 PAGE_COPY_X - -#define __S000 PAGE_NONE -#define __S001 PAGE_READONLY -#define __S010 PAGE_SHARED -#define __S011 PAGE_SHARED -#define __S100 PAGE_READONLY_X -#define __S101 PAGE_READONLY_X -#define __S110 PAGE_SHARED_X -#define __S111 PAGE_SHARED_X - #ifndef __ASSEMBLY__ #ifndef MAX_PTRS_PER_PGD diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c index c475cf810aa8..7f05e7903bd2 100644 --- a/arch/powerpc/mm/mmap.c +++ b/arch/powerpc/mm/mmap.c @@ -254,3 +254,50 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) mm->get_unmapped_area = arch_get_unmapped_area_topdown; } } + +static inline pgprot_t __vm_get_page_prot(unsigned long vm_flags) +{ + switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) { + case VM_NONE: + return PAGE_NONE; + case VM_READ: + return PAGE_READONLY; + case VM_WRITE: + return PAGE_COPY; + case VM_READ | VM_WRITE: + return PAGE_COPY; + case VM_EXEC: + return PAGE_READONLY_X; + case VM_EXEC | VM_READ: + return PAGE_READONLY_X; + case VM_EXEC | VM_WRITE: + return PAGE_COPY_X; + case VM_EXEC | VM_READ | VM_WRITE: + return PAGE_COPY_X; + case VM_SHARED: + return PAGE_NONE; + case VM_SHARED | VM_READ: + return PAGE_READONLY; + case VM_SHARED | VM_WRITE: + return PAGE_SHARED; + case VM_SHARED | VM_READ | VM_WRITE: + return PAGE_SHARED; + case VM_SHARED | VM_EXEC: + return PAGE_READONLY_X; + case VM_SHARED | VM_EXEC | VM_READ: + return PAGE_READONLY_X; + case VM_SHARED | VM_EXEC | VM_WRITE: + return PAGE_SHARED_X; + case VM_SHARED | VM_EXEC | VM_READ | VM_WRITE: + return PAGE_SHARED_X; + default: + BUILD_BUG(); + } +} + +pgprot_t vm_get_page_prot(unsigned long vm_flags) +{ + return __pgprot(pgprot_val(__vm_get_page_prot(vm_flags)) | + pgprot_val(powerpc_vm_get_page_prot(vm_flags))); +} +EXPORT_SYMBOL(vm_get_page_prot); -- 2.25.1