From patchwork Fri Apr 29 10:32:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 12831774 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 826F2C433F5 for ; Fri, 29 Apr 2022 10:30:31 +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=e/1HeYWgETpj5jKcpSlS29OnJkxvIWTh7/JteNjiyXQ=; b=KBwbnxGWEKkrBY 8OklPmhWI48srRmklt7SdtGJyBhEtSHISEgf0UuZKEtNjN6teQYSAVmH5Jyloo23EHTewZRM+WPT2 DqhdKsH8FdFW2vIcVqArH38FlzC+eWpwQkAxqoJRLmkCn01FwzpcxLpaDQaZTHWZpCz6O3XApqrI3 Rrg0AuMGfzRViLhINP9xK0b/wFvqzHn3XNufUacAPHK+UXzKZ2oFEpifZWgFL8nR3b1iQ07T+N08f XDFe6th1g4ahkbq0yGGZhc/eHAziu+meTyW8L+JYB/oyh+LDPFRhOqKOetk+XitjkFl5hWV+NNK9J JqOM/0+b1hFAkc55yTdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkNsB-00Anml-0G; Fri, 29 Apr 2022 10:29:15 +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 1nkNko-00AkAJ-SX for linux-arm-kernel@lists.infradead.org; Fri, 29 Apr 2022 10:21:43 +0000 Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KqT5Z6TsHz1JBj4; Fri, 29 Apr 2022 18:20:34 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 29 Apr 2022 18:21:31 +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; Fri, 29 Apr 2022 18:21:30 +0800 From: Kefeng Wang To: , , , , CC: , , , Kefeng Wang Subject: [PATCH v2 1/5] mm: ioremap: Use more sensibly name in ioremap_prot() Date: Fri, 29 Apr 2022 18:32:21 +0800 Message-ID: <20220429103225.75121-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220429103225.75121-1-wangkefeng.wang@huawei.com> References: <20220429103225.75121-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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-20220429_032139_114044_CE488FE8 X-CRM114-Status: GOOD ( 11.80 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use more meaningful and sensibly naming phys_addr instead addr in ioremap_prot(). Suggested-by: Andrew Morton Signed-off-by: Kefeng Wang Reviewed-by: Anshuman Khandual --- include/asm-generic/io.h | 2 +- mm/ioremap.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index 7ce93aaf69f8..e6ffa2519f08 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -964,7 +964,7 @@ static inline void iounmap(volatile void __iomem *addr) #elif defined(CONFIG_GENERIC_IOREMAP) #include -void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot); +void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long prot); void iounmap(volatile void __iomem *addr); static inline void __iomem *ioremap(phys_addr_t addr, size_t size) diff --git a/mm/ioremap.c b/mm/ioremap.c index 5fe598ecd9b7..1f9597fbcc07 100644 --- a/mm/ioremap.c +++ b/mm/ioremap.c @@ -11,20 +11,20 @@ #include #include -void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot) +void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long prot) { unsigned long offset, vaddr; phys_addr_t last_addr; struct vm_struct *area; /* Disallow wrap-around or zero size */ - last_addr = addr + size - 1; - if (!size || last_addr < addr) + last_addr = phys_addr + size - 1; + if (!size || last_addr < phys_addr) return NULL; /* Page-align mappings */ - offset = addr & (~PAGE_MASK); - addr -= offset; + offset = phys_addr & (~PAGE_MASK); + phys_addr -= offset; size = PAGE_ALIGN(size + offset); area = get_vm_area_caller(size, VM_IOREMAP, @@ -33,7 +33,7 @@ void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot) return NULL; vaddr = (unsigned long)area->addr; - if (ioremap_page_range(vaddr, vaddr + size, addr, __pgprot(prot))) { + if (ioremap_page_range(vaddr, vaddr + size, phys_addr, __pgprot(prot))) { free_vm_area(area); return NULL; } From patchwork Fri Apr 29 10:32:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 12831772 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 0DAE6C433F5 for ; Fri, 29 Apr 2022 10:29:08 +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=5jOhoftNsqKL6i/M0ebckcPB0vO7EXE0aZo+dKMmCOE=; b=XrA+hcnYgbAmRq YP9cCBjXuabjXT2h0zzI4oO5rs80xKlzBNYZ+UfcoM7MZr1wGatIArh0EBIMmV2Rs28lLa2xZySTq Hf6slXpA0kjc5KsUaMPzepx5O5/EPQzmg3rMFAoaA12g0MK57ejoY1bZCSinUM5iGkBDmx4VF04A2 hoilms4qjRXgrzHRoCBjwL5azgdEUEcVdwczspp42TsLTTEZHnef+zLvSFextediiT+PdVCaI3vvR UBMwR7IgGlF85euE9n4mLCjcdn4Kh+XXAf9dgRJUaTn0jh+plq2WFt/cByWsDbRoGGGcPy62ZRRr3 kqf9XJJLEKqeTvfGBNSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkNqw-00AnFD-GE; Fri, 29 Apr 2022 10:27:59 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkNko-00AkAh-SS for linux-arm-kernel@lists.infradead.org; Fri, 29 Apr 2022 10:21:43 +0000 Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KqT5b0cMczfZfD; Fri, 29 Apr 2022 18:20:35 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 29 Apr 2022 18:21:31 +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; Fri, 29 Apr 2022 18:21:31 +0800 From: Kefeng Wang To: , , , , CC: , , , Kefeng Wang , Christoph Hellwig Subject: [PATCH v2 2/5] mm: ioremap: Setup phys_addr of struct vm_struct Date: Fri, 29 Apr 2022 18:32:22 +0800 Message-ID: <20220429103225.75121-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220429103225.75121-1-wangkefeng.wang@huawei.com> References: <20220429103225.75121-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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-20220429_032139_201738_6D0AE8D2 X-CRM114-Status: UNSURE ( 9.58 ) X-CRM114-Notice: Please train this message. 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Show physical address of each ioremap in /proc/vmallocinfo. Acked-by: Andrew Morton Reviewed-by: Christoph Hellwig Signed-off-by: Kefeng Wang Reviewed-by: Anshuman Khandual --- mm/ioremap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/ioremap.c b/mm/ioremap.c index 1f9597fbcc07..7cb9996b0c12 100644 --- a/mm/ioremap.c +++ b/mm/ioremap.c @@ -32,6 +32,7 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long pro if (!area) return NULL; vaddr = (unsigned long)area->addr; + area->phys_addr = phys_addr; if (ioremap_page_range(vaddr, vaddr + size, phys_addr, __pgprot(prot))) { free_vm_area(area); From patchwork Fri Apr 29 10:32:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 12831775 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 CF0EDC433F5 for ; Fri, 29 Apr 2022 10:31:20 +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=md7UOP48QnDOBMBE134W/l5+BohlGrmw2NDwu+hWqAk=; b=sShHLBuhGcqn5H ClgSvl1RPskdf6HKzR0HnEu1L1WBAK+bn3LK6jcocVygg8RBbwEKWBA/YqaqT7Grwbi58Niyur6xi f5+s3Gls3PkyJc/iGdrJKY8+f3ZIiz9nyVRmaDQ1wmzzEBQsvOQHIi/uzUuf6en1cO1smBf7+ed2B owt0+wyTPlgyh7TQYdHFph2i4hXLJvpl9bVCdxknRzYrVz0NHfUGibv+ZNnyQrr+cMHM7VdSzc6o8 o1556taf6WrNj1WaYwA1yrqkhcNR9givibCLPuG6yZJk6/KY6M8ZrMJ3+qAmS5wsKamvsf5/Mw1lJ LXvxcc1WM5V3KNHYq41Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkNt3-00Ao4t-8E; Fri, 29 Apr 2022 10:30:09 +0000 Received: from szxga03-in.huawei.com ([45.249.212.189]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkNkp-00AkB1-IP for linux-arm-kernel@lists.infradead.org; Fri, 29 Apr 2022 10:21:45 +0000 Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KqT1P4ZZzzCsLX; Fri, 29 Apr 2022 18:16:57 +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; Fri, 29 Apr 2022 18:21:32 +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; Fri, 29 Apr 2022 18:21:31 +0800 From: Kefeng Wang To: , , , , CC: , , , Kefeng Wang Subject: [PATCH v2 3/5] mm: ioremap: Add arch_ioremap/iounmap() Date: Fri, 29 Apr 2022 18:32:23 +0800 Message-ID: <20220429103225.75121-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220429103225.75121-1-wangkefeng.wang@huawei.com> References: <20220429103225.75121-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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-20220429_032140_026362_5864A32B X-CRM114-Status: GOOD ( 12.86 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add special hook for architecture to verify addr, size and prot or setup when ioremap() or iounmap(), which will make the generic ioremap more useful. arch_ioremap() return a 'void __iomem *', - IS_ERR means return an error - NULL means continue to remap - a non-NULL, non-IS_ERR pointer is directly returned arch_iounmap() return a int value, - 0 means continue to vunmap - error code means skip vunmap and return directly Signed-off-by: Kefeng Wang --- include/asm-generic/io.h | 14 ++++++++++++++ mm/ioremap.c | 14 +++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index e6ffa2519f08..f2f9aeedb5e8 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -964,6 +964,20 @@ static inline void iounmap(volatile void __iomem *addr) #elif defined(CONFIG_GENERIC_IOREMAP) #include +#ifndef arch_ioremap +static inline void __iomem *arch_ioremap(phys_addr_t phys_addr, size_t size, unsigned long prot) +{ + return NULL; +} +#endif + +#ifndef arch_iounmap +static inline int arch_iounmap(void __iomem *addr) +{ + return 0; +} +#endif + void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long prot); void iounmap(volatile void __iomem *addr); diff --git a/mm/ioremap.c b/mm/ioremap.c index 7cb9996b0c12..de5a2e899e14 100644 --- a/mm/ioremap.c +++ b/mm/ioremap.c @@ -16,6 +16,7 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long pro unsigned long offset, vaddr; phys_addr_t last_addr; struct vm_struct *area; + void __iomem *base; /* Disallow wrap-around or zero size */ last_addr = phys_addr + size - 1; @@ -27,6 +28,12 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long pro phys_addr -= offset; size = PAGE_ALIGN(size + offset); + base = arch_ioremap(phys_addr, size, prot); + if (IS_ERR(base)) + return NULL; + else if (base) + return base; + area = get_vm_area_caller(size, VM_IOREMAP, __builtin_return_address(0)); if (!area) @@ -45,6 +52,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(vaddr)) + return; + + vunmap(vaddr); } EXPORT_SYMBOL(iounmap); From patchwork Fri Apr 29 10:32:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 12831777 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 9B45AC433EF for ; Fri, 29 Apr 2022 10:32:25 +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=PoSFioIRyUAtZPlJGVrkGVA47r4lhLkvlYt3Te6wX18=; b=J/8XrkorHLsoPl 83M64eSDAr5YbfZdFqxDKr9s5W4oLxoMnS/XUChS1XHO1hRyKjNfKOmoEHr0eQwZ97JcvJ/l7UFyS tFGvE6j8kJK6h5gkDCy2u8KTQhBpifEAE1zXjMKFjjEytbh54biYn3FLRfWKL7+JbdxmEnZfsm5y2 rBemkKmDdpKBeCaMmQXUaCkjMqOlR76+DAV74La9inWOFEmR+wao4jmicFkIDgcysFzG6XgePgv3p +qi+HvJUqWz0cSmbhFdcQ+d4il+srfdwOpTJdX9+42abqQDzCkENbbc/jHAc7du/FvMiUHeQAaLj3 h1aPOSebCkXpN3brF78w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkNu0-00AoTJ-UP; Fri, 29 Apr 2022 10:31:09 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkNl9-00AkUU-0m for linux-arm-kernel@bombadil.infradead.org; Fri, 29 Apr 2022 10:21:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=hICG07PpmKtV0WhyZimmj++pqmGNf9Aq6MGFe0yaq9Q=; b=fad12DztenbVL2c6J93GityC+A FwdQ8k45v4MNXpXcLrdLvi4dbVGN6DPCmkBzqJ2chMpH5k7Fl7QTRl2s4KF2xUw6Rd2xglw1YMCQe hIAq6i5wX1grinCiM4ln6BZyoVCWmyGKAbcq+EE2yIDM8QzII7AlsjfVx+fUK7+IHB7gCdg6ub7oO tswh4HpQrWhXk9drz2xlyLgPVeD/SWbRP3K1CWG2pgTOE4MMOf+9VqfqypuN9c3ecprYA2qzXMsJD hhD43ZJhBmmC1pkbHpC4XK0ZckaA97euu2EX4ZRRpv434xrEx2SGk0F1VuvcTdMkKDOebFXkPp/Zv bY1TWiUQ==; Received: from szxga01-in.huawei.com ([45.249.212.187]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkNl4-009aT6-0j for linux-arm-kernel@lists.infradead.org; Fri, 29 Apr 2022 10:21:57 +0000 Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KqT6W1bX6zhYnr; Fri, 29 Apr 2022 18:21:23 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 29 Apr 2022 18:21:33 +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; Fri, 29 Apr 2022 18:21:32 +0800 From: Kefeng Wang To: , , , , CC: , , , Kefeng Wang Subject: [PATCH v2 4/5] arm64: mm: Convert to GENERIC_IOREMAP Date: Fri, 29 Apr 2022 18:32:24 +0800 Message-ID: <20220429103225.75121-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220429103225.75121-1-wangkefeng.wang@huawei.com> References: <20220429103225.75121-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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-20220429_112155_620096_47368CB7 X-CRM114-Status: GOOD ( 17.92 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add hook for arm64's special operation when ioremap() and iounmap(), then ioremap_wc/np/cache is converted to use ioremap_prot() from GENERIC_IOREMAP, update the Copyright and kill the unused inclusions. Signed-off-by: Kefeng Wang Reported-by: kernel test robot --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/io.h | 20 ++++++--- arch/arm64/kernel/acpi.c | 2 +- arch/arm64/mm/ioremap.c | 85 +++++-------------------------------- 4 files changed, 27 insertions(+), 81 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 20ea89d9ac2f..56673209fdb9 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -123,6 +123,7 @@ config ARM64 select GENERIC_CPU_VULNERABILITIES select GENERIC_EARLY_IOREMAP select GENERIC_IDLE_POLL_SETUP + select GENERIC_IOREMAP select GENERIC_IRQ_IPI select GENERIC_IRQ_PROBE select GENERIC_IRQ_SHOW diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h index 7fd836bea7eb..042fa01940b8 100644 --- a/arch/arm64/include/asm/io.h +++ b/arch/arm64/include/asm/io.h @@ -163,13 +163,21 @@ extern void __memset_io(volatile void __iomem *, int, size_t); /* * I/O memory mapping functions. */ -extern void __iomem *__ioremap(phys_addr_t phys_addr, size_t size, pgprot_t prot); -extern void iounmap(volatile void __iomem *addr); -extern void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size); -#define ioremap(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE)) -#define ioremap_wc(addr, size) __ioremap((addr), (size), __pgprot(PROT_NORMAL_NC)) -#define ioremap_np(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRnE)) +void __iomem *arch_ioremap(phys_addr_t phys_addr, size_t size, unsigned long prot); +#define arch_ioremap arch_ioremap + +int arch_iounmap(void __iomem *addr); +#define arch_iounmap arch_iounmap + +#define _PAGE_IOREMAP PROT_DEVICE_nGnRE + +#define ioremap_wc(addr, size) ioremap_prot((addr), (size), PROT_NORMAL_NC) +#define ioremap_np(addr, size) ioremap_prot((addr), (size), PROT_DEVICE_nGnRnE) +#define ioremap_cache(addr, size) ({ \ + pfn_is_map_memory(__phys_to_pfn(addr)) ? \ + (void __iomem *)__phys_to_virt(addr) : ioremap_prot(addr, size, PROT_NORMAL); \ +}) /* * io{read,write}{16,32,64}be() macros diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index e4dea8db6924..a5a256e3f9fe 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -351,7 +351,7 @@ void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size) prot = __acpi_get_writethrough_mem_attribute(); } } - return __ioremap(phys, size, prot); + return ioremap_prot(phys, size, pgprot_val(prot)); } /* diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c index b7c81dacabf0..a12e315726e7 100644 --- a/arch/arm64/mm/ioremap.c +++ b/arch/arm64/mm/ioremap.c @@ -1,96 +1,33 @@ // SPDX-License-Identifier: GPL-2.0-only -/* - * Based on arch/arm/mm/ioremap.c - * - * (C) Copyright 1995 1996 Linus Torvalds - * Hacked for ARM by Phil Blundell - * Hacked to allow all architectures to build, and various cleanups - * by Russell King - * Copyright (C) 2012 ARM Ltd. - */ -#include #include #include #include -#include -#include - -static void __iomem *__ioremap_caller(phys_addr_t phys_addr, size_t size, - pgprot_t prot, void *caller) +void __iomem *arch_ioremap(phys_addr_t phys_addr, size_t size, unsigned long prot) { - unsigned long last_addr; - unsigned long offset = phys_addr & ~PAGE_MASK; - int err; - unsigned long addr; - struct vm_struct *area; - - /* - * Page align the mapping address and size, taking account of any - * offset. - */ - phys_addr &= PAGE_MASK; - size = PAGE_ALIGN(size + offset); + unsigned long last_addr = phys_addr + size - 1; + int ret = -EINVAL; - /* - * Don't allow wraparound, zero size or outside PHYS_MASK. - */ - last_addr = phys_addr + size - 1; - if (!size || last_addr < phys_addr || (last_addr & ~PHYS_MASK)) - return NULL; + /* Don't allow outside PHYS_MASK */ + if (last_addr & ~PHYS_MASK) + return ERR_PTR(ret); - /* - * Don't allow RAM to be mapped. - */ + /* Don't allow RAM to be mapped. */ if (WARN_ON(pfn_is_map_memory(__phys_to_pfn(phys_addr)))) - return NULL; + return ERR_PTR(ret); - area = get_vm_area_caller(size, VM_IOREMAP, caller); - if (!area) - return NULL; - addr = (unsigned long)area->addr; - area->phys_addr = phys_addr; - - err = ioremap_page_range(addr, addr + size, phys_addr, prot); - if (err) { - vunmap((void *)addr); - return NULL; - } - - return (void __iomem *)(offset + addr); -} - -void __iomem *__ioremap(phys_addr_t phys_addr, size_t size, pgprot_t prot) -{ - return __ioremap_caller(phys_addr, size, prot, - __builtin_return_address(0)); + return NULL; } -EXPORT_SYMBOL(__ioremap); -void iounmap(volatile void __iomem *io_addr) +int arch_iounmap(void __iomem *addr) { - unsigned long addr = (unsigned long)io_addr & PAGE_MASK; - /* * We could get an address outside vmalloc range in case * of ioremap_cache() reusing a RAM mapping. */ - if (is_vmalloc_addr((void *)addr)) - vunmap((void *)addr); -} -EXPORT_SYMBOL(iounmap); - -void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size) -{ - /* For normal memory we already have a cacheable mapping. */ - if (pfn_is_map_memory(__phys_to_pfn(phys_addr))) - return (void __iomem *)__phys_to_virt(phys_addr); - - return __ioremap_caller(phys_addr, size, __pgprot(PROT_NORMAL), - __builtin_return_address(0)); + return is_vmalloc_addr(addr) ? 0 : -EINVAL; } -EXPORT_SYMBOL(ioremap_cache); /* * Must be called after early_fixmap_init From patchwork Fri Apr 29 10:32:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 12831776 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 5DBEBC433F5 for ; Fri, 29 Apr 2022 10:31:47 +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=+pT2TGNyX5bhFfIEcZlFWu0qogIXoyOcE/j5ph8BD50=; b=p/j1OBznEEfQJ5 k6okFTsSLjVkRVnN+5HzMsD/NeD9Te2V1RcWvxWX6ar1KpCnWx7GxfXQiA8KkcxdbJ3LLUF9htAKt Vk3pkTMdDx4yC+XX2wvre1MRZjNyPY6k57CpLkWlumJvwd/KFcVk8Pic+rjf5RAdAXM3vE4GcvIEq EUiVhXwI0cFR9CMf8c0TMXjZpOYTIc+27L18lVYI7UEaLm1mxdUuUk+tE3Sz8HvJTE2izw0DVn+VD zH4yPHSR9bRayneTLhXhFiw7o/S8xplw/awRWzYTmTFVG/0Z7e4xgRL1JRaboZhd8Qe6Y6VlFduI1 bpydbccGEVIrwIbTvTqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkNtU-00AoGM-Vo; Fri, 29 Apr 2022 10:30:37 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkNkr-00AkEn-2l for linux-arm-kernel@lists.infradead.org; Fri, 29 Apr 2022 10:21:45 +0000 Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KqT3l2frJzGpKh; Fri, 29 Apr 2022 18:18:59 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 29 Apr 2022 18:21:33 +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; Fri, 29 Apr 2022 18:21:32 +0800 From: Kefeng Wang To: , , , , CC: , , , Kefeng Wang Subject: [PATCH v2 5/5] arm64: Add HAVE_IOREMAP_PROT support Date: Fri, 29 Apr 2022 18:32:25 +0800 Message-ID: <20220429103225.75121-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220429103225.75121-1-wangkefeng.wang@huawei.com> References: <20220429103225.75121-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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-20220429_032141_515863_1ED0AA75 X-CRM114-Status: GOOD ( 10.41 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With ioremap_prot() defination from generic ioremap, also move pte_pgprot() from hugetlbpage.c into pgtable.h, then arm64 could have HAVE_IOREMAP_PROT, which will enable generic_access_phys() code. Signed-off-by: Kefeng Wang Acked-by: Catalin Marinas Reviewed-by: Anshuman Khandual --- .../features/vm/ioremap_prot/arch-support.txt | 2 +- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/pgtable.h | 10 ++++++++++ arch/arm64/mm/hugetlbpage.c | 10 ---------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Documentation/features/vm/ioremap_prot/arch-support.txt b/Documentation/features/vm/ioremap_prot/arch-support.txt index a6dcbe5f47b6..b39ad5d61216 100644 --- a/Documentation/features/vm/ioremap_prot/arch-support.txt +++ b/Documentation/features/vm/ioremap_prot/arch-support.txt @@ -9,7 +9,7 @@ | alpha: | TODO | | arc: | ok | | arm: | TODO | - | arm64: | TODO | + | arm64: | ok | | csky: | TODO | | h8300: | TODO | | hexagon: | TODO | diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 56673209fdb9..5e5889049af0 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -186,6 +186,7 @@ config ARM64 select HAVE_FUNCTION_GRAPH_TRACER select HAVE_GCC_PLUGINS select HAVE_HW_BREAKPOINT if PERF_EVENTS + select HAVE_IOREMAP_PROT select HAVE_IRQ_TIME_ACCOUNTING select HAVE_KVM select HAVE_NMI diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index dff2b483ea50..1402a2739024 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -402,6 +402,16 @@ static inline pgprot_t mk_pmd_sect_prot(pgprot_t prot) return __pgprot((pgprot_val(prot) & ~PMD_TABLE_BIT) | PMD_TYPE_SECT); } +/* + * Select all bits except the pfn + */ +static inline pgprot_t pte_pgprot(pte_t pte) +{ + unsigned long pfn = pte_pfn(pte); + + return __pgprot(pte_val(pfn_pte(pfn, __pgprot(0))) ^ pte_val(pte)); +} + #ifdef CONFIG_NUMA_BALANCING /* * See the comment in include/linux/pgtable.h diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index cbace1c9e137..38d03406f6aa 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -100,16 +100,6 @@ int pud_huge(pud_t pud) #endif } -/* - * Select all bits except the pfn - */ -static inline pgprot_t pte_pgprot(pte_t pte) -{ - unsigned long pfn = pte_pfn(pte); - - return __pgprot(pte_val(pfn_pte(pfn, __pgprot(0))) ^ pte_val(pte)); -} - static int find_num_contig(struct mm_struct *mm, unsigned long addr, pte_t *ptep, size_t *pgsize) {