From patchwork Tue Jun 20 13:13:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13285841 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 C802DEB64DC for ; Tue, 20 Jun 2023 13:17:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 99DA38D0001; Tue, 20 Jun 2023 09:17:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 900128D000F; Tue, 20 Jun 2023 09:17:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 689C58D0001; Tue, 20 Jun 2023 09:17:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 52A518D000D for ; Tue, 20 Jun 2023 09:17:16 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 16375160F3C for ; Tue, 20 Jun 2023 13:17:16 +0000 (UTC) X-FDA: 80923177272.01.EDBEF0A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 172CF100012 for ; Tue, 20 Jun 2023 13:17:13 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QQsTnsOy; spf=pass (imf14.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687267034; 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:dkim-signature; bh=BZDW/9l2SXpk3O4K9ggpnwprp0OjaYClAxIb9iSyrKo=; b=T+J7YQw5hw3EO75BSeEo0ED1QHbTKreCnOCsvmawrcgV5INDpTcwtMd5S+hXBQTdHe2+n4 yCtVWU0s6HIa+llCAiZXFZgMvqlRRUc3kFQIzJ+6oAiaGEuyGO7WkjyAuKUaFF5PmF/6v5 4Xa2YD4NxpXNwV7+gWkPv/I+MmLHv3Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687267034; a=rsa-sha256; cv=none; b=d50x0dt03agiA4mqC11h0WLuoU2ce2YSsp/L5do/9RvN35/tXRRnjYIdp2LW6bq36DFM5C uvUeKbQ+5JJVttJidzErXXLUuJ5uNWELhDtwJm/sYABZs15PdIiNlp2ydTf0Tep6O+iHTy X24afAI0adeccMy1nIxP7CJEE3ZU5MU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QQsTnsOy; spf=pass (imf14.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687267033; h=from:from: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=BZDW/9l2SXpk3O4K9ggpnwprp0OjaYClAxIb9iSyrKo=; b=QQsTnsOytuDz8GwU0gEhNDQdDqh+lNUtxM59d6J+SjT6VRh9XtA6eTBs8Iy6sdFSGzpC0Y 5+NUDnqqoHCq5vf5UZIpNDQgwboTM296lSfJ25b33m6vDApOGUCsZbmnTjTUC/8XdL4Sag 06CHrEiUBbsky2HKCeCen6ww4+7wRxE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-393-oaZkYfEhNpSZi9l2-OVjAg-1; Tue, 20 Jun 2023 09:17:09 -0400 X-MC-Unique: oaZkYfEhNpSZi9l2-OVjAg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3A9AD38470A6; Tue, 20 Jun 2023 13:16:04 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-166.pek2.redhat.com [10.72.12.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E0FFC1ED97; Tue, 20 Jun 2023 13:15:54 +0000 (UTC) From: Baoquan He To: 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, glaubitz@physik.fu-berlin.de, Baoquan He , Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org Subject: [PATCH v7 12/19] sh: mm: Convert to GENERIC_IOREMAP Date: Tue, 20 Jun 2023 21:13:49 +0800 Message-Id: <20230620131356.25440-13-bhe@redhat.com> In-Reply-To: <20230620131356.25440-1-bhe@redhat.com> References: <20230620131356.25440-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Queue-Id: 172CF100012 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: h9juieyb83q4xjnwtfjz6aggfa44817s X-HE-Tag: 1687267033-142862 X-HE-Meta: U2FsdGVkX1/qR/U+FoHxfZ7fdeXy5DBWpzwTgdcvrQgweBKBNF3g4nd5jW/8kgNHD+5e9x9PVvn1c4d0kuuyX6TqXj+CFa+0OUR70OMo1aX7+rJ+LztlSxaf2icQYx4NH6c+9NkVDyAEUQuK4S3osB7I3skFoWRcys8N5gvo9k/we4SbiHkq9usEi/O0iSlLUuimh2XjO5356pNfofXyu+Ly8dynW21LVUNDNRO4dA1BTLdLz5B/MyWfNziEif585QtcLlgM4X7BhpGJnKDM4ESKw4zgUBk/4L16FwlwdJso6bdJ/JBvVMCo36H8dfD1TcQEKhgr9GzIk3+brJMHvWRcv4cux+Fs8wex+ZDLKT7texOuJ27X1Ex/lVmdVinxDZ8Tva1cj2OFIjj+jXnOCpYPNY67NvUgagfSymGuKWb1ofzuOvN1G0xLyj177gbo2YuRCC+tWuB/AYGo3ko12W+zzwEZTHCWkxVsHeJjkDsDr7+3JbQl7/zR38Un0iMKh4Yz2M7ZoK3AFxKx4HzFOqYDUyeLGA+8WCEAWZR13U+IRTj01cvR+lYG+qUbeji6AuklXzPN7VCZ9a0xgKTIHEzHO53XEsP+uIIxW9f5qUxfKMBypaikkzCc4rOPS93jrumiiBlKI91zuqdhy3BiswaCQRq97nBBE9J4UyE4MswVwQ7D1PN9j+nTtdqoJLILFmKWHQsJVvM4LdDAFoAGU9UC3fBXrMuxpwc2Sx6XsKss417hvH77H9mpAsq7klhRwuOfikISOWg0NmG3dQhzh2cKwKLCuUkAbT112mvnGRJo+FWAGPzbALAYv3yc0yfxCWTpvjlTtKr5V/byEP29pXcHF3Eppftd3tssYuC43SmWc6atk3iAPDDrsOb8j66Ptus+ZpvqylF+GcZbfRkIIl0jYgnie849WPjmjtF+70O3BRZ79L2EtH0Ct69zrhKkSoWpBmXSbRWKpIyAYB4 wUfEknhY Ow7zvK9/Gg/0i+nLlj9yJ6DDgjNdsVKKPbzeSUmbn8MOGd+YmknXFpPTvxyln+TfQKV7ujinlbfheHqphSZOpuDhfU3D90Mx9KLghod7Ueb5Olv1HZDNIa9Qf59wmussl/atKlAho7ySv0ZrRlk8ywMPb9et4ynzbIYMRexZu7ZfWqpEdM9Fg4qmqyDm7GYe/ugyIMT70SMmuJldyyu/F80TmYA5lZilzKFJNPJyxnlzPwzMDAK6DjSRwECoSrbM5N8eNeGngcVf1Q0BLxbIcd0JEqoVq6cFoNymHRolxo5QDfEj7LIMyzRcz/UN2e3rgG/1iLY+Kv3sr3+D0q/ymfd3Q4A== 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: 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 with generic_ioremap_prot() and generic_iounmap(), and has the equivalent functioality as before. Here, add wrapper functions ioremap_prot() and iounmap() for SuperH's special operation when ioremap() and iounmap(). 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(-) 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 long long addr, #endif #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 size) -{ - 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 long 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 -#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) -static inline void iounmap(volatile void __iomem *addr) { } +#define ioremap_cache(addr, size) \ + ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL)) #endif /* CONFIG_MMU */ #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 size, pgprot_t prot) #define __ioremap_29bit(offset, size, prot) NULL #endif /* CONFIG_29BIT */ -/* - * 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 obviously - * have to convert them into an offset in a page-aligned mapping, but the - * 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 = __pgprot(prot); mapped = __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; - /* Don't allow wraparound or zero size */ - last_addr = 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 long size, * First try to remap through the PMB. * PMB entries are all pre-faulted. */ - mapped = pmb_remap_caller(phys_addr, size, pgprot, caller); + mapped = pmb_remap_caller(phys_addr, size, pgprot, + __builtin_return_address(0)); if (mapped && !IS_ERR(mapped)) return mapped; - /* - * Mappings have to be page-aligned - */ - offset = phys_addr & ~PAGE_MASK; - phys_addr &= PAGE_MASK; - size = PAGE_ALIGN(last_addr+1) - phys_addr; - - /* - * Ok, go for it.. - */ - area = get_vm_area_caller(size, VM_IOREMAP, caller); - if (!area) - return NULL; - area->phys_addr = phys_addr; - orig_addr = addr = (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); /* * Simple checks for non-translatable mappings. @@ -158,10 +122,9 @@ static inline int iomapping_nontranslatable(unsigned long offset) return 0; } -void iounmap(void __iomem *addr) +void iounmap(volatile void __iomem *addr) { unsigned long vaddr = (unsigned long __force)addr; - struct vm_struct *p; /* * 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) == 0) + if (iounmap_fixed((void __iomem *)addr) == 0) return; /* * If the PMB handled it, there's nothing else to do. */ - if (pmb_unmap(addr) == 0) + if (pmb_unmap((void __iomem *)addr) == 0) return; - p = 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);