From patchwork Fri Jun 3 10:14:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 1638674 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDzKY1K7hz9s0w for ; Fri, 3 Jun 2022 20:15:29 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4LDzKY0YPnz4xZ7 for ; Fri, 3 Jun 2022 20:15:29 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4LDzKY0W7lz4xZD; Fri, 3 Jun 2022 20:15:29 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4LDzKY0RVcz4xZ7 for ; Fri, 3 Jun 2022 20:15:29 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243602AbiFCKP0 (ORCPT ); Fri, 3 Jun 2022 06:15:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243531AbiFCKPS (ORCPT ); Fri, 3 Jun 2022 06:15:18 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B00FC3B2B5; Fri, 3 Jun 2022 03:15:13 -0700 (PDT) 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 62BF315DB; Fri, 3 Jun 2022 03:15:13 -0700 (PDT) Received: from a077893.blr.arm.com (unknown [10.162.42.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A26C03F766; Fri, 3 Jun 2022 03:15:04 -0700 (PDT) From: Anshuman Khandual To: linux-mm@kvack.org Cc: Anshuman Khandual , Catalin Marinas , Will Deacon , Michael Ellerman , Paul Mackerras , "David S. Miller" , Thomas Gleixner , Ingo Molnar , Heiko Carstens , Vasily Gorbik , Thomas Bogendoerfer , Geert Uytterhoeven , Dinh Nguyen , Jonas Bonn , Andrew Morton , x86@kernel.org, openrisc@lists.librecores.org, linux-csky@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/6] nios2/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT Date: Fri, 3 Jun 2022 15:44:10 +0530 Message-Id: <20220603101411.488970-6-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220603101411.488970-1-anshuman.khandual@arm.com> References: <20220603101411.488970-1-anshuman.khandual@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: sparclinux@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. Cc: Dinh Nguyen Cc: linux-kernel@vger.kernel.org Acked-by: Dinh Nguyen Signed-off-by: Anshuman Khandual --- arch/nios2/Kconfig | 1 + arch/nios2/include/asm/pgtable.h | 24 ---------------- arch/nios2/mm/init.c | 47 ++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig index 4167f1eb4cd8..e0459dffd218 100644 --- a/arch/nios2/Kconfig +++ b/arch/nios2/Kconfig @@ -6,6 +6,7 @@ config NIOS2 select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_HAS_DMA_SET_UNCACHED + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_NO_SWAP select COMMON_CLK select TIMER_OF diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h index 262d0609268c..3c9f83c22733 100644 --- a/arch/nios2/include/asm/pgtable.h +++ b/arch/nios2/include/asm/pgtable.h @@ -34,30 +34,6 @@ struct mm_struct; ((x) ? _PAGE_EXEC : 0) | \ ((r) ? _PAGE_READ : 0) | \ ((w) ? _PAGE_WRITE : 0)) -/* - * These are the macros that generic kernel code needs - * (to populate protection_map[]) - */ - -/* Remove W bit on private pages for COW support */ -#define __P000 MKP(0, 0, 0) -#define __P001 MKP(0, 0, 1) -#define __P010 MKP(0, 0, 0) /* COW */ -#define __P011 MKP(0, 0, 1) /* COW */ -#define __P100 MKP(1, 0, 0) -#define __P101 MKP(1, 0, 1) -#define __P110 MKP(1, 0, 0) /* COW */ -#define __P111 MKP(1, 0, 1) /* COW */ - -/* Shared pages can have exact HW mapping */ -#define __S000 MKP(0, 0, 0) -#define __S001 MKP(0, 0, 1) -#define __S010 MKP(0, 1, 0) -#define __S011 MKP(0, 1, 1) -#define __S100 MKP(1, 0, 0) -#define __S101 MKP(1, 0, 1) -#define __S110 MKP(1, 1, 0) -#define __S111 MKP(1, 1, 1) /* Used all over the kernel */ #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_CACHED | _PAGE_READ | \ diff --git a/arch/nios2/mm/init.c b/arch/nios2/mm/init.c index 613fcaa5988a..e867f5d85580 100644 --- a/arch/nios2/mm/init.c +++ b/arch/nios2/mm/init.c @@ -124,3 +124,50 @@ const char *arch_vma_name(struct vm_area_struct *vma) { return (vma->vm_start == KUSER_BASE) ? "[kuser]" : NULL; } + +pgprot_t vm_get_page_prot(unsigned long vm_flags) +{ + switch (vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)) { + /* Remove W bit on private pages for COW support */ + case VM_NONE: + return MKP(0, 0, 0); + case VM_READ: + return MKP(0, 0, 1); + /* COW */ + case VM_WRITE: + return MKP(0, 0, 0); + /* COW */ + case VM_WRITE | VM_READ: + return MKP(0, 0, 1); + case VM_EXEC: + return MKP(1, 0, 0); + case VM_EXEC | VM_READ: + return MKP(1, 0, 1); + /* COW */ + case VM_EXEC | VM_WRITE: + return MKP(1, 0, 0); + /* COW */ + case VM_EXEC | VM_WRITE | VM_READ: + return MKP(1, 0, 1); + /* Shared pages can have exact HW mapping */ + case VM_SHARED: + return MKP(0, 0, 0); + case VM_SHARED | VM_READ: + return MKP(0, 0, 1); + case VM_SHARED | VM_WRITE: + return MKP(0, 1, 0); + case VM_SHARED | VM_WRITE | VM_READ: + return MKP(0, 1, 1); + case VM_SHARED | VM_EXEC: + return MKP(1, 0, 0); + case VM_SHARED | VM_EXEC | VM_READ: + return MKP(1, 0, 1); + case VM_SHARED | VM_EXEC | VM_WRITE: + return MKP(1, 1, 0); + case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ: + return MKP(1, 1, 1); + default: + BUILD_BUG(); + } +} +EXPORT_SYMBOL(vm_get_page_prot);