From mboxrd@z Thu Jan 1 00:00:00 1970 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 83CD6C433EF for ; Wed, 27 Apr 2022 12:04:07 +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:References:In-Reply-To: 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: List-Owner; bh=ouZftvkPp8RzHKTmDV8DGSg5N7QBwnJB8oDQJ0b6/Y4=; b=FiHrReTAEPYdud 4fFXilG9S+dnccZptQVC9+L5vJdprKdJ+aJsBAt0tERB0IS7I0vtqKUYQug1fha14Ll4/JCvTgBQ8 zcaFr8FCvRvYeNVqeXW/OkA5DpPS5BaE4uHTSAa4jznNEgqXH5hUiN34hFEUfQ0nxQBaDCVcu57Wq 5S5F607vevbMTBN6C8DpQLmnw3LO1Atrcs3ljYEA7BfqYfoGqWvO0j3QVbcl7adGBFcejIyYBDN5s dw2H/ictS/jK/T9evk8Qwk1YzMG7IxRNAbDRLCV/4Oy0PPbSYwaZiJSBIa0bV3wEknBjhQ/JilWT/ NErkmrX0fa7bOcVfY4EA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1njgNr-001Cac-PY; Wed, 27 Apr 2022 12:03:03 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1njgNW-001CPt-Tn for linux-arm-kernel@lists.infradead.org; Wed, 27 Apr 2022 12:02:44 +0000 Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KpHQr4cVVz1JBqV; Wed, 27 Apr 2022 20:01:24 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 27 Apr 2022 20:02:18 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 27 Apr 2022 20:02:18 +0800 From: Kefeng Wang To: Catalin Marinas , Will Deacon , Andrew Morton , , CC: , Kefeng Wang Subject: [PATCH 2/4] mm: ioremap: Add arch_ioremap/iounmap_check() Date: Wed, 27 Apr 2022 20:14:11 +0800 Message-ID: <20220427121413.168468-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220427121413.168468-1-wangkefeng.wang@huawei.com> References: <20220427121413.168468-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220427_050243_146120_7882972E X-CRM114-Status: GOOD ( 11.43 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add special check hook for architecture to verify addr, size or prot when ioremap() or iounmap(), which will make the generic ioremap more useful. Signed-off-by: Kefeng Wang --- include/asm-generic/io.h | 3 +++ mm/ioremap.c | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index 7ce93aaf69f8..26924fded7c3 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -964,6 +964,9 @@ static inline void iounmap(volatile void __iomem *addr) #elif defined(CONFIG_GENERIC_IOREMAP) #include +bool arch_ioremap_check(phys_addr_t addr, size_t size, unsigned long prot); +bool arch_iounmap_check(void __iomem *addr); + void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot); void iounmap(volatile void __iomem *addr); diff --git a/mm/ioremap.c b/mm/ioremap.c index 522ef899c35f..d1117005dcc7 100644 --- a/mm/ioremap.c +++ b/mm/ioremap.c @@ -11,6 +11,16 @@ #include #include +bool __weak arch_ioremap_check(phys_addr_t addr, size_t size, unsigned long prot) +{ + return true; +} + +bool __weak arch_iounmap_check(void __iomem *addr) +{ + return true; +} + void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot) { unsigned long offset, vaddr; @@ -27,6 +37,9 @@ void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot) addr -= offset; size = PAGE_ALIGN(size + offset); + if (!arch_ioremap_check(addr, size, prot)) + return NULL; + area = get_vm_area_caller(size, VM_IOREMAP, __builtin_return_address(0)); if (!area) @@ -45,6 +58,11 @@ EXPORT_SYMBOL(ioremap_prot); void iounmap(volatile void __iomem *addr) { - vunmap((void *)((unsigned long)addr & PAGE_MASK)); + void *vaddr = (void *)((unsigned long)addr & PAGE_MASK); + + if (!arch_iounmap_check(vaddr)) + return; + + vunmap(vaddr); } EXPORT_SYMBOL(iounmap); -- 2.26.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel