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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31A35EB64DD for ; Sun, 25 Jun 2023 21:13:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 339EE6B0074; Sun, 25 Jun 2023 17:13:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2EA2F6B0075; Sun, 25 Jun 2023 17:13:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B1996B0078; Sun, 25 Jun 2023 17:13:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0AF2D6B0074 for ; Sun, 25 Jun 2023 17:13:01 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id CCF8E1204D7 for ; Sun, 25 Jun 2023 21:13:00 +0000 (UTC) X-FDA: 80942520120.14.A604AFF Received: from outpost1.zedat.fu-berlin.de (outpost1.zedat.fu-berlin.de [130.133.4.66]) by imf17.hostedemail.com (Postfix) with ESMTP id BDF4140003 for ; Sun, 25 Jun 2023 21:12:58 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of glaubitz@zedat.fu-berlin.de designates 130.133.4.66 as permitted sender) smtp.mailfrom=glaubitz@zedat.fu-berlin.de; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687727579; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a2AvD8EMQCF00222AKetGSjaMCmSYFgNg/cyItuZpMY=; b=UlSzEfbp2vexPUVJxUW64BdKBuv8HoHh12BQ/covn5iQB7O8PAJ/hWUPnk7W2ZQFkb8qad Xbfs5Sswnmq55M2PDu365kmcIGvF+BrG/SIrwaHRfDstXwcG+YmHeBZvGUgjp9vydq6cKI 64lsJ6nL/F8HAmscxB/SPSYJisUvfms= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687727579; a=rsa-sha256; cv=none; b=J8050Hv4a96e/MNTD0M4+2Ot4AFa/ucENBCN1/LZqUj964QerXy592sB/tdMjqRqXE3v0x VB6rqNU+4gzGqKB5i70JJZFW+YKRiCNsBNmvE06zc7chbN5jEHt8EDGn90g6JVh82bA4m6 z68J6KnXENFizmgDApB5LQGF2ezcplE= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of glaubitz@zedat.fu-berlin.de designates 130.133.4.66 as permitted sender) smtp.mailfrom=glaubitz@zedat.fu-berlin.de; dmarc=none Received: from inpost2.zedat.fu-berlin.de ([130.133.4.69]) by outpost.zedat.fu-berlin.de (Exim 4.95) with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (envelope-from ) id 1qDX2R-002qMG-Dg; Sun, 25 Jun 2023 23:12:51 +0200 Received: from dynamic-089-014-168-195.89.14.pool.telefonica.de ([89.14.168.195] helo=[192.168.1.11]) by inpost2.zedat.fu-berlin.de (Exim 4.95) with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (envelope-from ) id 1qDX2R-000NkG-5k; Sun, 25 Jun 2023 23:12:51 +0200 Message-ID: <20fdf89dde5eee365ab15d9f4753e3c9fc43d46e.camel@physik.fu-berlin.de> Subject: Re: [PATCH v7 12/19] sh: mm: Convert to GENERIC_IOREMAP From: John Paul Adrian Glaubitz To: Baoquan He , linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org, linux-mm@kvack.org, arnd@arndb.de, hch@lst.de, christophe.leroy@csgroup.eu, rppt@kernel.org, willy@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, deller@gmx.de, nathan@kernel.org, Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org Date: Sun, 25 Jun 2023 23:12:50 +0200 In-Reply-To: <20230620131356.25440-13-bhe@redhat.com> References: <20230620131356.25440-1-bhe@redhat.com> <20230620131356.25440-13-bhe@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.3 MIME-Version: 1.0 X-Original-Sender: glaubitz@physik.fu-berlin.de X-Originating-IP: 89.14.168.195 X-ZEDAT-Hint: PO X-Stat-Signature: p7jt9jycoan8pdoo3pthwfj35obo7696 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: BDF4140003 X-Rspam-User: X-HE-Tag: 1687727578-848495 X-HE-Meta: U2FsdGVkX181HvYRmgLBa7CCBAvFV4GHJ7KaSl1xZwOffwIzl1eQ2s5F8WyDYk3nsdiG1lu2Xuuf0dPU3yxwnrMbyOcXRNsT/ngd3Wd9nxzFi6FkO8DaF94u2rm5kLuT4WEJvleSdYEt/ZJAMoxEJyGyl64Zpvzjv4jiV3PehYR2n1r7BJK4ce87RF4f1Y7DngxMpBjqLyZVNV2MgWns0Eumui1gttcqWe6XCWTeIbFr1tQ9zYtmMCKm00gi9dlEdqxW71PbNWKt7FS2+/RI/Ev2Lo8gBUy5smDAsHejXM80AgQ3g5QRFu0vNfhcpJf+aEU0KSjxmSSv5LabD8nf7DZTXTRqnR/nBNWkZgy5ekhEPCQAC0Qwlt5Cw3JZBImp/s7QyFhPS/wjsOFR4sMWcMcWW1mwWOpuYIy5iy6Cpvwv2T46gLJLffk5gG44wyEqdh4myjsvF6DZDdJ3XiBhfxxGisVu67Tps7EXLCr1Tny22RpbUr0ktKsm+yftoRNtSHAdI5KnD5hDkCv3SCTMYqT/8Jj41vZwsUyLIiAJxFekgNu+RfTKsB7t+D/7/Yc89SvESYp4aW2yxK8z37t6ZKTVRlKLndYD9dcS5TUbRm5L9WrL4nuRMMu3vmmdCap39XdftCanx6hUvrzSXYP4fefC2IMSxKV+rs6QY/cpmPEVawAoZGSZIJm7oSpq9WtAnBkNclEDLohdetdTjYFo5JL84q4NjmloaNQoq9lxFfrsh9wa2mFvqJBJfpoLAIbkONaL7Fpdnss25EK6mHeKu4CoW1mjJFz+h40jtqvYOc2ZS7/WQ7VJSqs/CRuAIxmY8HY777qrmtJ++sX3JyYZ/tzXlIKzI+XlFYNra68gQH5Xu8gRm4tz83V9+wccqrTJxfIoj0s4skU2u17Wm4+4uur1O3Qi4lEffp77+C2sMRP0jhCPEfOj61YQjTGnT8p4ZGB7Qv/Yh95scZ8QU6B 2cSyn6HV BAXpW6iew/33wthDWb5rIritffZuNCQEJC7rVYQh3Tgh4rCKfyGSLF/2z2ZTs0uT6CYIZe4Q7fI+UQOC7eepqi1SDuRkvBpWpy1+bXNLooVyaCVZr4yNxXg15U5kLQid1kpvKgP7a0vnmEj5F7++Z1ouNrDbWY+rZ3jteJv2+WUxgkcmKinEH5xnpHms/QAfOMdjFe3HCq1jow2ds7nqj76uKGYoljCF0/oHqbaqCXQiBquB66xvTaYR0LI2t1R+zPvkilJzXwwSqdyyHjqxCARmRS35gY5fmWNPxkfm61Y0jmuhljM/3zFAGHVBiFBcze16FnUbHdPU5c8xnVDJ2cjh0zrH/nici5mEfwS5p8qxUPpVgbo8twF2Q3nbGo474OmdLufubuIfP3FIzDFmuoXDr496z9pTMjhl/UrSLb10Xv0x5XnG/hCevV3V13P22cerCpPZhEaqBZJqdU/gTZ/YTZOLh3Vv833MBUNby9QTC5L7darb25HRO3ds2rO5nSJ8bSD2zkGSNmHc= 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: Hi Baoquan! On Tue, 2023-06-20 at 21:13 +0800, Baoquan He wrote: > By taking GENERIC_IOREMAP method, the generic generic_ioremap_prot(), > generic_iounmap(), and their generic wrapper ioremap_prot(), ioremap() > and iounmap() are all visible and available to arch. Arch needs to > provide wrapper functions to override the generic versions if there's > arch specific handling in its ioremap_prot(), ioremap() or iounmap(). > This change will simplify implementation by removing duplicated codes ^^^^^ Nit-pick: It should be "code", not "codes". I'll review and test the rest tomorrow. There are quite some changes. Adrian > with generic_ioremap_prot() and generic_iounmap(), and has the equivalent > functioality as before. >=20 > Here, add wrapper functions ioremap_prot() and iounmap() for SuperH's > special operation when ioremap() and iounmap(). >=20 > Signed-off-by: Baoquan He > Cc: Yoshinori Sato > Cc: Rich Felker > Cc: linux-sh@vger.kernel.org > --- > arch/sh/Kconfig | 1 + > arch/sh/include/asm/io.h | 40 +++++-------------------- > arch/sh/mm/ioremap.c | 65 +++++++--------------------------------- > 3 files changed, 20 insertions(+), 86 deletions(-) >=20 > diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig > index 9652d367fc37..f326985e46e0 100644 > --- a/arch/sh/Kconfig > +++ b/arch/sh/Kconfig > @@ -28,6 +28,7 @@ config SUPERH > select GENERIC_SMP_IDLE_THREAD > select GUP_GET_PXX_LOW_HIGH if X2TLB > select HAS_IOPORT if HAS_IOPORT_MAP > + select GENERIC_IOREMAP if MMU > select HAVE_ARCH_AUDITSYSCALL > select HAVE_ARCH_KGDB > select HAVE_ARCH_SECCOMP_FILTER > diff --git a/arch/sh/include/asm/io.h b/arch/sh/include/asm/io.h > index 270e7952950c..b3a26b405c8d 100644 > --- a/arch/sh/include/asm/io.h > +++ b/arch/sh/include/asm/io.h > @@ -266,40 +266,16 @@ unsigned long long poke_real_address_q(unsigned lon= g long addr, > #endif > =20 > #ifdef CONFIG_MMU > -void iounmap(void __iomem *addr); > -void __iomem *__ioremap_caller(phys_addr_t offset, unsigned long size, > - pgprot_t prot, void *caller); > - > -static inline void __iomem *ioremap(phys_addr_t offset, unsigned long si= ze) > -{ > - return __ioremap_caller(offset, size, PAGE_KERNEL_NOCACHE, > - __builtin_return_address(0)); > -} > - > -static inline void __iomem * > -ioremap_cache(phys_addr_t offset, unsigned long size) > -{ > - return __ioremap_caller(offset, size, PAGE_KERNEL, > - __builtin_return_address(0)); > -} > -#define ioremap_cache ioremap_cache > - > -#ifdef CONFIG_HAVE_IOREMAP_PROT > -static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned lo= ng size, > - unsigned long flags) > -{ > - return __ioremap_caller(offset, size, __pgprot(flags), > - __builtin_return_address(0)); > -} > -#endif /* CONFIG_HAVE_IOREMAP_PROT */ > +/* > + * I/O memory mapping functions. > + */ > +#define ioremap_prot ioremap_prot > +#define iounmap iounmap > =20 > -#else /* CONFIG_MMU */ > -static inline void __iomem *ioremap(phys_addr_t offset, size_t size) > -{ > - return (void __iomem *)(unsigned long)offset; > -} > +#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL_NOCACHE) > =20 > -static inline void iounmap(volatile void __iomem *addr) { } > +#define ioremap_cache(addr, size) \ > + ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL)) > #endif /* CONFIG_MMU */ > =20 > #define ioremap_uc ioremap > diff --git a/arch/sh/mm/ioremap.c b/arch/sh/mm/ioremap.c > index 21342581144d..c33b3daa4ad1 100644 > --- a/arch/sh/mm/ioremap.c > +++ b/arch/sh/mm/ioremap.c > @@ -72,22 +72,11 @@ __ioremap_29bit(phys_addr_t offset, unsigned long siz= e, pgprot_t prot) > #define __ioremap_29bit(offset, size, prot) NULL > #endif /* CONFIG_29BIT */ > =20 > -/* > - * Remap an arbitrary physical address space into the kernel virtual > - * address space. Needed when the kernel wants to access high addresses > - * directly. > - * > - * NOTE! We need to allow non-page-aligned mappings too: we will obvious= ly > - * have to convert them into an offset in a page-aligned mapping, but th= e > - * caller shouldn't need to know that small detail. > - */ > -void __iomem * __ref > -__ioremap_caller(phys_addr_t phys_addr, unsigned long size, > - pgprot_t pgprot, void *caller) > +void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, > + unsigned long prot) > { > - struct vm_struct *area; > - unsigned long offset, last_addr, addr, orig_addr; > void __iomem *mapped; > + pgprot_t pgprot =3D __pgprot(prot); > =20 > mapped =3D __ioremap_trapped(phys_addr, size); > if (mapped) > @@ -97,11 +86,6 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned long = size, > if (mapped) > return mapped; > =20 > - /* Don't allow wraparound or zero size */ > - last_addr =3D phys_addr + size - 1; > - if (!size || last_addr < phys_addr) > - return NULL; > - > /* > * If we can't yet use the regular approach, go the fixmap route. > */ > @@ -112,34 +96,14 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned lon= g size, > * First try to remap through the PMB. > * PMB entries are all pre-faulted. > */ > - mapped =3D pmb_remap_caller(phys_addr, size, pgprot, caller); > + mapped =3D pmb_remap_caller(phys_addr, size, pgprot, > + __builtin_return_address(0)); > if (mapped && !IS_ERR(mapped)) > return mapped; > =20 > - /* > - * Mappings have to be page-aligned > - */ > - offset =3D phys_addr & ~PAGE_MASK; > - phys_addr &=3D PAGE_MASK; > - size =3D PAGE_ALIGN(last_addr+1) - phys_addr; > - > - /* > - * Ok, go for it.. > - */ > - area =3D get_vm_area_caller(size, VM_IOREMAP, caller); > - if (!area) > - return NULL; > - area->phys_addr =3D phys_addr; > - orig_addr =3D addr =3D (unsigned long)area->addr; > - > - if (ioremap_page_range(addr, addr + size, phys_addr, pgprot)) { > - vunmap((void *)orig_addr); > - return NULL; > - } > - > - return (void __iomem *)(offset + (char *)orig_addr); > + return generic_ioremap_prot(phys_addr, size, pgprot); > } > -EXPORT_SYMBOL(__ioremap_caller); > +EXPORT_SYMBOL(ioremap_prot); > =20 > /* > * Simple checks for non-translatable mappings. > @@ -158,10 +122,9 @@ static inline int iomapping_nontranslatable(unsigned= long offset) > return 0; > } > =20 > -void iounmap(void __iomem *addr) > +void iounmap(volatile void __iomem *addr) > { > unsigned long vaddr =3D (unsigned long __force)addr; > - struct vm_struct *p; > =20 > /* > * Nothing to do if there is no translatable mapping. > @@ -172,21 +135,15 @@ void iounmap(void __iomem *addr) > /* > * There's no VMA if it's from an early fixed mapping. > */ > - if (iounmap_fixed(addr) =3D=3D 0) > + if (iounmap_fixed((void __iomem *)addr) =3D=3D 0) > return; > =20 > /* > * If the PMB handled it, there's nothing else to do. > */ > - if (pmb_unmap(addr) =3D=3D 0) > + if (pmb_unmap((void __iomem *)addr) =3D=3D 0) > return; > =20 > - p =3D remove_vm_area((void *)(vaddr & PAGE_MASK)); > - if (!p) { > - printk(KERN_ERR "%s: bad address %p\n", __func__, addr); > - return; > - } > - > - kfree(p); > + generic_iounmap(addr); > } > EXPORT_SYMBOL(iounmap); --=20 .''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913