From: Baoquan He <bhe@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org,
wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org,
Baoquan He <bhe@redhat.com>
Subject: [PATCH 01/11] mm/ioremap: change the return value of io[re|un]map_allowed
Date: Mon, 1 Aug 2022 22:40:19 +0800 [thread overview]
Message-ID: <20220801144029.57829-2-bhe@redhat.com> (raw)
In-Reply-To: <20220801144029.57829-1-bhe@redhat.com>
In some architectures, there are arch specifici io address mapping
handling when calling ioremap() or ioremap_prot(), e.g, arc, ia64,
openrisc, s390, sh.
In oder to convert them to take GENERIC_IOREMAP method, we need change
the return value of ioremap_allowed() and iounmap_allowed() as below.
===
ioremap_allowed() return a bool,
- IS_ERR means return an error
- NULL means continue to remap
- a non-NULL, non-IS_ERR pointer is returned directly
iounmap_allowed() return a bool,
- 0 means continue to vunmap
- error code means skip vunmap and return directly
This is taken from Kefeng's below old patch. Christoph suggested the
return value because he foresaw the doablity of converting to take
GENERIC_IOREMAP on more architectures.
- [PATCH v3 4/6] mm: ioremap: Add arch_ioremap/iounmap()
- https://lore.kernel.org/all/20220519082552.117736-5-wangkefeng.wang@huawei.com/T/#u
This is preparation for later patch, no functionality change.
Signed-off-by: Baoquan He <bhe@redhat.com>
---
arch/arm64/include/asm/io.h | 2 +-
arch/arm64/mm/ioremap.c | 9 +++++----
include/asm-generic/io.h | 17 +++++++++--------
mm/ioremap.c | 10 +++++++---
4 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h
index 87dd42d74afe..9c56a077b687 100644
--- a/arch/arm64/include/asm/io.h
+++ b/arch/arm64/include/asm/io.h
@@ -164,7 +164,7 @@ extern void __memset_io(volatile void __iomem *, int, size_t);
* I/O memory mapping functions.
*/
-bool ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot);
+void __iomem *ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot);
#define ioremap_allowed ioremap_allowed
#define _PAGE_IOREMAP PROT_DEVICE_nGnRE
diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c
index c5af103d4ad4..49467c781283 100644
--- a/arch/arm64/mm/ioremap.c
+++ b/arch/arm64/mm/ioremap.c
@@ -3,19 +3,20 @@
#include <linux/mm.h>
#include <linux/io.h>
-bool ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot)
+void __iomem *ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot)
{
unsigned long last_addr = phys_addr + size - 1;
+ int ret = -EINVAL;
/* Don't allow outside PHYS_MASK */
if (last_addr & ~PHYS_MASK)
- return false;
+ return IOMEM_ERR_PTR(ret);
/* Don't allow RAM to be mapped. */
if (WARN_ON(pfn_is_map_memory(__phys_to_pfn(phys_addr))))
- return false;
+ return IOMEM_ERR_PTR(ret);
- return true;
+ return NULL;
}
/*
diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
index 72974cb81343..d72eb310fb3c 100644
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -967,26 +967,27 @@ static inline void iounmap(volatile void __iomem *addr)
/*
* Arch code can implement the following two hooks when using GENERIC_IOREMAP
* ioremap_allowed() return a bool,
- * - true means continue to remap
- * - false means skip remap and return directly
+ * - IS_ERR means return an error
+ * - NULL means continue to remap
+ * - a non-NULL, non-IS_ERR pointer is returned directly
* iounmap_allowed() return a bool,
- * - true means continue to vunmap
- * - false means skip vunmap and return directly
+ * - 0 means continue to vunmap
+ * - error code means skip vunmap and return directly
*/
#ifndef ioremap_allowed
#define ioremap_allowed ioremap_allowed
-static inline bool ioremap_allowed(phys_addr_t phys_addr, size_t size,
+static inline void __iomem *ioremap_allowed(phys_addr_t phys_addr, size_t size,
unsigned long prot)
{
- return true;
+ return NULL;
}
#endif
#ifndef iounmap_allowed
#define iounmap_allowed iounmap_allowed
-static inline bool iounmap_allowed(void *addr)
+static inline int iounmap_allowed(void *addr)
{
- return true;
+ return 0;
}
#endif
diff --git a/mm/ioremap.c b/mm/ioremap.c
index 8652426282cc..b16ee9debea2 100644
--- a/mm/ioremap.c
+++ b/mm/ioremap.c
@@ -17,6 +17,7 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,
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;
@@ -28,8 +29,11 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,
phys_addr -= offset;
size = PAGE_ALIGN(size + offset);
- if (!ioremap_allowed(phys_addr, size, prot))
+ base = ioremap_allowed(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));
@@ -50,9 +54,9 @@ EXPORT_SYMBOL(ioremap_prot);
void iounmap(volatile void __iomem *addr)
{
- void *vaddr = (void *)((unsigned long)addr & PAGE_MASK);
+ void __iomem *vaddr = (void __iomem *)((unsigned long)addr & PAGE_MASK);
- if (!iounmap_allowed(vaddr))
+ if (iounmap_allowed(vaddr))
return;
if (is_vmalloc_addr(vaddr))
--
2.34.1
next prev parent reply other threads:[~2022-08-01 14:40 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-01 14:40 [PATCH 00/11] mm: ioremap: Convert architectures to take GENERIC_IOREMAP way Baoquan He
2022-08-01 14:40 ` Baoquan He [this message]
2022-08-04 15:42 ` [PATCH 01/11] mm/ioremap: change the return value of io[re|un]map_allowed Alexander Gordeev
2022-08-06 2:29 ` Kefeng Wang
2022-08-06 8:29 ` Alexander Gordeev
2022-08-07 1:42 ` Baoquan He
2022-08-07 1:51 ` Baoquan He
2022-08-07 1:58 ` Baoquan He
2022-08-01 14:40 ` [PATCH 02/11] mm: ioremap: fixup the physical address Baoquan He
2022-08-04 16:02 ` Alexander Gordeev
2022-08-07 2:11 ` Baoquan He
2022-08-20 0:49 ` Baoquan He
2022-08-01 14:40 ` [PATCH 03/11] mm: ioremap: allow ARCH to have its own ioremap definition Baoquan He
2022-08-01 14:40 ` [PATCH 04/11] arc: mm: Convert to GENERIC_IOREMAP Baoquan He
2022-08-01 14:40 ` [PATCH 05/11] hexagon: " Baoquan He
2022-08-01 14:40 ` [PATCH 06/11] ia64: " Baoquan He
2022-08-01 14:40 ` [PATCH 07/11] openrisc: " Baoquan He
2022-08-01 14:40 ` [PATCH 08/11] parisc: " Baoquan He
2022-08-01 14:40 ` [PATCH 09/11] s390: " Baoquan He
2022-08-01 14:40 ` [PATCH 10/11] sh: " Baoquan He
2022-08-01 14:40 ` [PATCH 11/11] xtensa: " Baoquan He
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220801144029.57829-2-bhe@redhat.com \
--to=bhe@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=hch@infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=wangkefeng.wang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).