From patchwork Thu Jul 6 15:45:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13303954 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 17952EB64D9 for ; Thu, 6 Jul 2023 15:45:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6A5C6B0072; Thu, 6 Jul 2023 11:45:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A1A646B0075; Thu, 6 Jul 2023 11:45:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E2FA8D0001; Thu, 6 Jul 2023 11:45:38 -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 7F34A6B0072 for ; Thu, 6 Jul 2023 11:45:38 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4D899B00C7 for ; Thu, 6 Jul 2023 15:45:38 +0000 (UTC) X-FDA: 80981611956.22.4E3F1BC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id D36184001D for ; Thu, 6 Jul 2023 15:45:35 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hGtMi6Y0; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688658335; a=rsa-sha256; cv=none; b=AM/F14cJKrP0/1OTnfJ9z0crmAyL45nPCQ80omUp+4ppTDt5cfzcavNKAiE7maIsI9SMCG +5WerMWt0G33VyvE1rXqnItWSxNz/FMHoyiRHVUL+wAo2sSbHdHMqiF+GPXDRpXtG7/nUY xIGfd9yQZ4Wsj6tlho/zwncr1QqblhM= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hGtMi6Y0; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688658335; 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: references:dkim-signature; bh=upnfIC4bq+WgcHwje6gJ4XudMj5Y60jZ1tJx6tn8wlw=; b=PbQcCQBl3EKB1N2ZQ1Ar3JUZpNEpIxW92tWa2FFf+573xZrXSdH7kW5Fmpf9AC7pNTvM97 FIYac8x89O4dJpefDPwLIFtmyOsPiOYYKj31mhXUzyXeKkC/Kxbmk2wk29PXDhLCGQyPwZ Zav5zyHAwSy4K/RD6kBAIo4GxfjZLIA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688658334; 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; bh=upnfIC4bq+WgcHwje6gJ4XudMj5Y60jZ1tJx6tn8wlw=; b=hGtMi6Y0iZPqDxEG+XeUOOrKyMl0a1sqj9VKuA8QKBApwWewvdct2/4xS+o1JOCiR04/5A SSMKmoKo/u2EbxEgRLKNGvlG7UoiEbzAEnqmq7RsedHFRD4SQWA12U9aORI83F+jiaL14O WFOhGPZJPQn11d5XCI4hgcG8cMrvnxU= 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-34-HVRO10GXNd6W5sBF63sfEg-1; Thu, 06 Jul 2023 11:45:33 -0400 X-MC-Unique: HVRO10GXNd6W5sBF63sfEg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 869951C0514C; Thu, 6 Jul 2023 15:45:32 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-39.pek2.redhat.com [10.72.12.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDA8BF5CF0; Thu, 6 Jul 2023 15:45:23 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.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, shorne@gmail.com, David.Laight@ACULAB.COM, deller@gmx.de, nathan@kernel.org, glaubitz@physik.fu-berlin.de, Baoquan He Subject: [PATCH v8 00/19] mm: ioremap: Convert architectures to take GENERIC_IOREMAP way Date: Thu, 6 Jul 2023 23:45:01 +0800 Message-Id: <20230706154520.11257-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D36184001D X-Stat-Signature: x36f7fhikd343mjmgjetu6jot6sogt4a X-HE-Tag: 1688658335-113772 X-HE-Meta: U2FsdGV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txK+W8W7R0JHQPEZcYsTHSFY+sqprIgPDH2wVA9DI363dNqKnO2qjLS+MmkKBBxhQvm1kKiEkIP4NHDyha9GYOar9e+9PiSYbJ05YhPizFOaCpQc63GmuNFlyz+oU1Q+Bn5X435Ef/xh9K7TqoQhp284xlj66BIL4amJNxoMcVm5Fz+xPS6FFv/tY5ovNzNBZgbLq06OnGFLG9IbHBdTM6b9Ux3u4HHoJYmsP0gKXSJqJnYlzsy+CF4fyNJTOH+WYRrg8hf21jCA8vHHaT4VIPyTkPqi9a4gtpvnKtfoHKvd16Jvw== 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: Motivation and implementation: ============================== Currently, many architecutres have't taken the standard GENERIC_IOREMAP way to implement ioremap_prot(), iounmap(), and ioremap_xx(), but make these functions specifically under each arch's folder. Those cause many duplicated code of ioremap() and iounmap(). In this patchset, firstly introduce generic_ioremap_prot() and generic_iounmap() to extract the generic code for GENERIC_IOREMAP. 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 version if there's arch specific handling in its corresponding ioremap_prot(), ioremap() or iounmap(). With these changes, duplicated ioremap/iounmap() code uder ARCH-es are removed, and the equivalent functioality is kept as before. Background info: ================ 1) The converting more architectures to take GENERIC_IOREMAP way is suggested by Christoph in below discussion: https://lore.kernel.org/all/Yp7h0Jv6vpgt6xdZ@infradead.org/T/#u 2) In the previous v1 to v3, it's basically further action after arm64 has converted to GENERIC_IOREMAP way in below patchset. It's done by adding hook ioremap_allowed() and iounmap_allowed() in ARCH to add ARCH specific handling the middle of ioremap_prot() and iounmap(). [PATCH v5 0/6] arm64: Cleanup ioremap() and support ioremap_prot() https://lore.kernel.org/all/20220607125027.44946-1-wangkefeng.wang@huawei.com/T/#u Later, during v3 reviewing, Christophe Leroy suggested to introduce generic_ioremap_prot() and generic_iounmap() to generic codes, and ARCH can provide wrapper function ioremap_prot(), ioremap() or iounmap() if needed. Christophe made a RFC patchset as below to specially demonstrate his idea. This is what v4 and now v5 is doing. [RFC PATCH 0/8] mm: ioremap: Convert architectures to take GENERIC_IOREMAP way https://lore.kernel.org/all/cover.1665568707.git.christophe.leroy@csgroup.eu/T/#u Testing: ======== In v8, I only applied this patchset onto the latest linus's tree to build and run on arm64 and s390. History: ======= v7->v8: - Fix the error reported by lkp test robot on patch [PATCH v7 02/19] hexagon: mm: Convert to GENERIC_IOREMAP Thanks to Nathan for providing the code fix after reproducing. - Fix the conflict in patch 15 when rebasing to latest linus's tree because of earlier commit ef104443bffa. v6->v7: - Fix the building error on s390 and hexagon reported by lkp test robot. - Add Christoph, Mike, Catalin and Helge's ack. v5->v6: - Remove stale descriptions in log - Mike - Remove the early unmapping handling from fixmap pool in iounmap() in openrisc; Based on that, iounmap() in openrisc ARCH can be removed - Mike - Add WARN_ON_ONCE to aid debugging in generic_ioremap_prot() - Christoph - Split the inclusion of include/asm-generic/io.h and redefining of the helpers from the old patch 11 into a prep patch; The following patch can only contain code converting to GENERIC_IOREMAP for SuperH - Christoph - Add header file linux/ioremap.h and move is_ioremap_addr() over there - Christoph v4->v5: - Ard and Christophe suggested adding a preparation patch to remove ARCH_HAS_IOREMAP_xx macros, this is done in newly added patch 1. - In the current patch 13 ("parisc: mm: Convert to GENERIC_IOREMAP"), so we don't need to add ARCH_HAS_IOREMAP_WC. v3->v4: - Change to contain arch specific handling in wrapper function ioremap(), ioremap_prot() or iounmap() to replace the old hook ioremap|iounmap_allowed() hook way for each arch. - Add two patches to convert powerpc to GENERIC_IOREMAP. They are picked from above Christophe's RFC patchset, I made some changes to make them formal. v2->v3: - Rewrite log of all patches to add more details as Christoph suggested. - Merge the old patch 1 and 2 which adjusts return values and parameters of arch_ioremap() into one patch, namely the current patch 3. Christoph suggested this. - Change the return value of arch_iounmap() to bool type since we only do arch specific address filtering or address checking, bool value can reflect the checking better. This is pointed out by Niklas when he reviewed the s390 patch. - Put hexagon patch at the beginning of patchset since hexagon has the same ioremap() and iounmap() as standard ones, no arch_ioremap() and arch_iounmap() hooks need be introduced. So the later arch_ioremap and arch_iounmap() adjustment are not related in hexagon. Christophe suggested this. - Remove the early ioremap code from openrisc ioremap() firstly since openrisc doesn't have early ioremap handling in openrisc arch code. This simplifies the later converting to GENERIC_IOREMAP method. Christoph and Stafford suggersted this. - Fix compiling erorrs reported by lkp in parisc and sh patches. Adding macro defintions for those port|mem io functions in to avoid repeated definition in . v1->v2: - Rename io[re|un]map_allowed() to arch_io[re|un]map() and made some minor changes in patch 1~2 as per Alexander and Kefeng's suggestions. Accordingly, adjust patches~4~11 because of the renaming arch_io[re|un]map(). Baoquan He (16): asm-generic/iomap.h: remove ARCH_HAS_IOREMAP_xx macros hexagon: mm: Convert to GENERIC_IOREMAP openrisc: mm: remove unneeded early ioremap code mm: ioremap: allow ARCH to have its own ioremap method definition mm/ioremap: add slab availability checking in ioremap_prot arc: mm: Convert to GENERIC_IOREMAP ia64: mm: Convert to GENERIC_IOREMAP openrisc: mm: Convert to GENERIC_IOREMAP s390: mm: Convert to GENERIC_IOREMAP sh: add including sh: mm: Convert to GENERIC_IOREMAP xtensa: mm: Convert to GENERIC_IOREMAP parisc: mm: Convert to GENERIC_IOREMAP mm: move is_ioremap_addr() into new header file arm64 : mm: add wrapper function ioremap_prot() mm: ioremap: remove unneeded ioremap_allowed and iounmap_allowed Christophe Leroy (3): mm/ioremap: Define generic_ioremap_prot() and generic_iounmap() mm/ioremap: Consider IOREMAP space in generic ioremap powerpc: mm: Convert to GENERIC_IOREMAP arch/arc/Kconfig | 1 + arch/arc/include/asm/io.h | 7 ++- arch/arc/mm/ioremap.c | 49 ++--------------- arch/arm64/include/asm/io.h | 3 +- arch/arm64/mm/ioremap.c | 10 ++-- arch/hexagon/Kconfig | 1 + arch/hexagon/include/asm/io.h | 11 ++-- arch/hexagon/kernel/hexagon_ksyms.c | 2 - arch/hexagon/mm/Makefile | 2 +- arch/hexagon/mm/ioremap.c | 44 ---------------- arch/ia64/Kconfig | 1 + arch/ia64/include/asm/io.h | 13 ++--- arch/ia64/mm/ioremap.c | 41 +++------------ arch/loongarch/include/asm/io.h | 2 - arch/m68k/include/asm/io_mm.h | 2 - arch/m68k/include/asm/kmap.h | 2 - arch/mips/include/asm/io.h | 5 +- arch/openrisc/Kconfig | 1 + arch/openrisc/include/asm/io.h | 11 ++-- arch/openrisc/mm/ioremap.c | 82 ----------------------------- arch/parisc/Kconfig | 1 + arch/parisc/include/asm/io.h | 15 ++++-- arch/parisc/mm/ioremap.c | 62 ++-------------------- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/io.h | 17 ++---- arch/powerpc/include/asm/pgtable.h | 10 ---- arch/powerpc/mm/ioremap.c | 26 +-------- arch/powerpc/mm/ioremap_32.c | 19 ++++--- arch/powerpc/mm/ioremap_64.c | 12 +---- arch/s390/Kconfig | 1 + arch/s390/include/asm/io.h | 21 ++++---- arch/s390/kernel/perf_cpum_sf.c | 2 +- arch/s390/pci/pci.c | 57 ++++---------------- arch/sh/Kconfig | 1 + arch/sh/include/asm/io.h | 65 ++++++++++++----------- arch/sh/include/asm/io_noioport.h | 7 +++ arch/sh/mm/ioremap.c | 65 ++++------------------- arch/x86/include/asm/io.h | 5 -- arch/xtensa/Kconfig | 1 + arch/xtensa/include/asm/io.h | 32 +++++------ arch/xtensa/mm/ioremap.c | 58 +++++--------------- drivers/net/ethernet/sfc/io.h | 2 +- drivers/net/ethernet/sfc/siena/io.h | 2 +- include/asm-generic/io.h | 31 +++-------- include/asm-generic/iomap.h | 6 +-- include/linux/ioremap.h | 30 +++++++++++ include/linux/mm.h | 5 -- kernel/iomem.c | 1 + mm/ioremap.c | 41 ++++++++++----- 49 files changed, 249 insertions(+), 637 deletions(-) delete mode 100644 arch/hexagon/mm/ioremap.c create mode 100644 include/linux/ioremap.h