From patchwork Tue Aug 24 09:12:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12454319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA3F9C4320A for ; Tue, 24 Aug 2021 09:16:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 55E0761360 for ; Tue, 24 Aug 2021 09:16:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 55E0761360 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id DB6556B006C; Tue, 24 Aug 2021 05:16:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D6441900002; Tue, 24 Aug 2021 05:16:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C79586B0072; Tue, 24 Aug 2021 05:16:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0230.hostedemail.com [216.40.44.230]) by kanga.kvack.org (Postfix) with ESMTP id AD1286B006C for ; Tue, 24 Aug 2021 05:16:29 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 4C00C180AD817 for ; Tue, 24 Aug 2021 09:16:29 +0000 (UTC) X-FDA: 78509418498.32.AC2D324 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP id D0E93B000182 for ; Tue, 24 Aug 2021 09:16:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=6zolBoOP5T9T037rbery01Tu/sHMVMHoRpN0E1MW6ew=; b=J+l1B3gDQK7kcJZWKvooklQOOV LUUwyB+0dYSyx0wY/9Kv6ibzNFJqqynvjPHa03BO8WwF3ZlGwCldU5/FkSfnPYjvAOdttJxD2VL1Q AlFgw/8oWnf41yodDVZuklKa9hZ5SjfOqmw6vnKH6hkILeOAL/6vA5eMYfPCEEoqefaMA7X2ZbphZ SIXvQIhxZh7nf4noo04LBTTczzHNmSocMRtQnH6D4M58xkGB28Rikub1Bmc7CLXr0B4p935hLRXu+ Lwqtsj9yI5AGEXuj6Lnum7t2+adi7DzCaAxm0Arneq82e/fR8FgfVNZc/0LYZ2gGA25h71zV6QUI7 /Y9vW5rw==; Received: from [2001:4bb8:193:fd10:f8c0:1a4c:b688:f5a6] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mISVm-00ApxP-RK; Tue, 24 Aug 2021 09:14:45 +0000 From: Christoph Hellwig To: Andrew Morton Cc: Nicholas Piggin , Peter Zijlstra , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mm: move ioremap_page_range to vmalloc.c Date: Tue, 24 Aug 2021 11:12:58 +0200 Message-Id: <20210824091259.1324527-2-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824091259.1324527-1-hch@lst.de> References: <20210824091259.1324527-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: D0E93B000182 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=J+l1B3gD; dmarc=none; spf=none (imf25.hostedemail.com: domain of BATV@casper.srs.infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=BATV@casper.srs.infradead.org X-Rspamd-Server: rspam01 X-Stat-Signature: d9o4efkx3byuedbuuk6m5t6csjzsbpzx X-HE-Tag: 1629796588-957635 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: This keeps it together with the implementation, and to remove the vmap_range wrapper. Signed-off-by: Christoph Hellwig Reported-by: kernel test robot Reviewed-by: Nicholas Piggin --- include/linux/vmalloc.h | 3 --- mm/Makefile | 3 ++- mm/ioremap.c | 25 ------------------------- mm/vmalloc.c | 22 +++++++++++++++++----- 4 files changed, 19 insertions(+), 34 deletions(-) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 2644425b6dce..671d402c3778 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -225,9 +225,6 @@ static inline bool is_vm_area_hugepages(const void *addr) } #ifdef CONFIG_MMU -int vmap_range(unsigned long addr, unsigned long end, - phys_addr_t phys_addr, pgprot_t prot, - unsigned int max_page_shift); void vunmap_range(unsigned long addr, unsigned long end); static inline void set_vm_flush_reset_perms(void *addr) { diff --git a/mm/Makefile b/mm/Makefile index e3436741d539..0e0a5a6fe127 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -38,7 +38,7 @@ mmu-y := nommu.o mmu-$(CONFIG_MMU) := highmem.o memory.o mincore.o \ mlock.o mmap.o mmu_gather.o mprotect.o mremap.o \ msync.o page_vma_mapped.o pagewalk.o \ - pgtable-generic.o rmap.o vmalloc.o ioremap.o + pgtable-generic.o rmap.o vmalloc.o ifdef CONFIG_CROSS_MEMORY_ATTACH @@ -128,3 +128,4 @@ obj-$(CONFIG_PTDUMP_CORE) += ptdump.o obj-$(CONFIG_PAGE_REPORTING) += page_reporting.o obj-$(CONFIG_IO_MAPPING) += io-mapping.o obj-$(CONFIG_HAVE_BOOTMEM_INFO_NODE) += bootmem_info.o +obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o diff --git a/mm/ioremap.c b/mm/ioremap.c index 8ee0136f8cb0..5fe598ecd9b7 100644 --- a/mm/ioremap.c +++ b/mm/ioremap.c @@ -8,33 +8,9 @@ */ #include #include -#include #include #include -#include -#include "pgalloc-track.h" - -#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -static unsigned int __ro_after_init iomap_max_page_shift = BITS_PER_LONG - 1; - -static int __init set_nohugeiomap(char *str) -{ - iomap_max_page_shift = PAGE_SHIFT; - return 0; -} -early_param("nohugeiomap", set_nohugeiomap); -#else /* CONFIG_HAVE_ARCH_HUGE_VMAP */ -static const unsigned int iomap_max_page_shift = PAGE_SHIFT; -#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ - -int ioremap_page_range(unsigned long addr, - unsigned long end, phys_addr_t phys_addr, pgprot_t prot) -{ - return vmap_range(addr, end, phys_addr, prot, iomap_max_page_shift); -} - -#ifdef CONFIG_GENERIC_IOREMAP void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot) { unsigned long offset, vaddr; @@ -71,4 +47,3 @@ void iounmap(volatile void __iomem *addr) vunmap((void *)((unsigned long)addr & PAGE_MASK)); } EXPORT_SYMBOL(iounmap); -#endif /* CONFIG_GENERIC_IOREMAP */ diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d5cd52805149..e44983fb2d15 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -44,6 +44,19 @@ #include "internal.h" #include "pgalloc-track.h" +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP +static unsigned int __ro_after_init ioremap_max_page_shift = BITS_PER_LONG - 1; + +static int __init set_nohugeiomap(char *str) +{ + ioremap_max_page_shift = PAGE_SHIFT; + return 0; +} +early_param("nohugeiomap", set_nohugeiomap); +#else /* CONFIG_HAVE_ARCH_HUGE_VMAP */ +static const unsigned int ioremap_max_page_shift = PAGE_SHIFT; +#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ + #ifdef CONFIG_HAVE_ARCH_HUGE_VMALLOC static bool __ro_after_init vmap_allow_huge = true; @@ -298,15 +311,14 @@ static int vmap_range_noflush(unsigned long addr, unsigned long end, return err; } -int vmap_range(unsigned long addr, unsigned long end, - phys_addr_t phys_addr, pgprot_t prot, - unsigned int max_page_shift) +int ioremap_page_range(unsigned long addr, unsigned long end, + phys_addr_t phys_addr, pgprot_t prot) { int err; - err = vmap_range_noflush(addr, end, phys_addr, prot, max_page_shift); + err = vmap_range_noflush(addr, end, phys_addr, prot, + ioremap_max_page_shift); flush_cache_vmap(addr, end); - return err; } From patchwork Tue Aug 24 09:12:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12454321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB805C432BE for ; Tue, 24 Aug 2021 09:17:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 73CC561178 for ; Tue, 24 Aug 2021 09:17:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 73CC561178 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 1CC0B6B006C; Tue, 24 Aug 2021 05:17:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 17BCC6B0071; Tue, 24 Aug 2021 05:17:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 091B0900002; Tue, 24 Aug 2021 05:17:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0210.hostedemail.com [216.40.44.210]) by kanga.kvack.org (Postfix) with ESMTP id E50D26B006C for ; Tue, 24 Aug 2021 05:17:37 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8A1BA8249980 for ; Tue, 24 Aug 2021 09:17:37 +0000 (UTC) X-FDA: 78509421354.36.CFA5A3B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf06.hostedemail.com (Postfix) with ESMTP id 46E22801A88D for ; Tue, 24 Aug 2021 09:17:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=ti5A/ILf1WJ2CVbEVdaMaP5K64yHTjJmYJcdIRgT4r8=; b=cmMZmmlzsKVAb1WsZzJmBctNta JElthLUHejS1Bk9uTGAQL/8RXsl4qvXXFQz0fkLmojyKfUwfIDrYIsBISrk46s5gpb49mqvxOsbmG romH7HFI+3GBB35QTyFwg/Ic5S3qnFsKUygkxrmZns/TSzTdgst4VLSsW4aHOEuQH6332YiaedSZP o6Cug3YfZRVkYxVPgYPlOZeWMcAvscK4WiaCeAbIodrumWhWUMrBYgpK2i3PInK8hQnBZ8J/q0fGk hKQyDyLeaGi4mhLxBUHYA9N0XKOD7wnILJlLvQ0DhcsQJSy9QT+Z/49CuKETjybBiRnA3bQmNgXLD j4466HSA==; Received: from [2001:4bb8:193:fd10:f8c0:1a4c:b688:f5a6] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mISXM-00Aq2J-7b; Tue, 24 Aug 2021 09:16:27 +0000 From: Christoph Hellwig To: Andrew Morton Cc: Nicholas Piggin , Peter Zijlstra , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm: don't allow executable ioremap mappings Date: Tue, 24 Aug 2021 11:12:59 +0200 Message-Id: <20210824091259.1324527-3-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824091259.1324527-1-hch@lst.de> References: <20210824091259.1324527-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=cmMZmmlz; spf=none (imf06.hostedemail.com: domain of BATV@casper.srs.infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=BATV@casper.srs.infradead.org; dmarc=none X-Stat-Signature: cqf5gq6xne5c57hir3ebst1mo4s93x5w X-Rspamd-Queue-Id: 46E22801A88D X-Rspamd-Server: rspam04 X-HE-Tag: 1629796657-50105 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: There is no need to execute from iomem (and most platforms it is impossible anyway), so add the pgprot_nx() call similar to vmap. Signed-off-by: Christoph Hellwig --- mm/vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index e44983fb2d15..3055f04b486b 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -316,7 +316,7 @@ int ioremap_page_range(unsigned long addr, unsigned long end, { int err; - err = vmap_range_noflush(addr, end, phys_addr, prot, + err = vmap_range_noflush(addr, end, phys_addr, pgprot_nx(prot), ioremap_max_page_shift); flush_cache_vmap(addr, end); return err;