linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Baoquan He <bhe@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-arch@vger.kernel.org, linux-mm@kvack.org, arnd@arndb.de,
	christophe.leroy@csgroup.eu, hch@lst.de, 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,
	Baoquan He <bhe@redhat.com>
Subject: [PATCH v6 00/19] mm: ioremap:  Convert architectures to take GENERIC_IOREMAP way
Date: Fri,  9 Jun 2023 15:55:09 +0800	[thread overview]
Message-ID: <20230609075528.9390-1-bhe@redhat.com> (raw)

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 codes of ioremap() and iounmap().

In this patchset, firstly introduce generic_ioremap_prot() and
generic_iounmap() to extract the generic codes 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 v6, building and testing passed on arm64 and ppc64le, and only took
cross compiling on xtensa and passed.

------Old v5 testing
Old v4 has done below test. In v5, patch 1 is newly added to remove
ARCH_HAS_IOREMAP_xx, and patch 13 ("parisc: mm: Convert to GENERIC_IOREMAP")
is impacted, so I only built related x86_64, m68K, mips64, ppc64le, parisc and
all passed.

------Old v4 testing
- It's running well on arm64, s390x, ppc64le with this patchset applied
  on the latest upstream kernel 6.2-rc8+.
- Cross compiling passed on arc, ia64, parisc, sh, xtensa.
- cross compiling is not tried on hexagon, openrisc and powerpc 32bit
  because:
  - Didn't find cross compiling tools for hexagon, ppc 32bit;
  - there's error with openrisc compiling, while I have no idea how to
    fix it. Please see below pasted log:
    ---------------------------------------------------------------------
    [root@intel-knightslanding-lb-02 linux]# make ARCH=openrisc defconfig
    *** Default configuration is based on 'or1ksim_defconfig'
    #
    # configuration written to .config
    #
    [root@intel-knightslanding-lb-02 linux]# make ARCH=openrisc -j320 CROSS_COMPILE=/usr/bin/openrisc-linux-gnu-
      SYNC    include/config/auto.conf.cmd
      CC      scripts/mod/empty.o
    ./scripts/check-local-export: /usr/bin/openrisc-linux-gnu-nm failed
    make[1]: *** [scripts/Makefile.build:250: scripts/mod/empty.o] Error 1
    make[1]: *** Deleting file 'scripts/mod/empty.o'
    make: *** [Makefile:1275: prepare0] Error 2
    ----------------------------------------------------------------------

History:
=======
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
  <asm/io.h> to avoid repeated definition in <asm-generic/io.h>.

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 <asm-generic/io.h> 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       |  9 +++-
 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  |  8 ---
 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/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 ++++++++++-----
 46 files changed, 247 insertions(+), 629 deletions(-)
 delete mode 100644 arch/hexagon/mm/ioremap.c
 create mode 100644 include/linux/ioremap.h

-- 
2.34.1



             reply	other threads:[~2023-06-09  7:55 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09  7:55 Baoquan He [this message]
2023-06-09  7:55 ` [PATCH v6 01/19] asm-generic/iomap.h: remove ARCH_HAS_IOREMAP_xx macros Baoquan He
2023-06-09  7:55 ` [PATCH v6 02/19] hexagon: mm: Convert to GENERIC_IOREMAP Baoquan He
2023-06-09 11:09   ` kernel test robot
2023-06-10  8:26     ` Baoquan He
2023-06-11  5:40       ` Mike Rapoport
2023-06-11  7:57         ` Baoquan He
2023-06-12 16:02           ` Nathan Chancellor
2023-06-16 12:46             ` Baoquan He
2023-06-09  7:55 ` [PATCH v6 03/19] openrisc: mm: remove unneeded early ioremap code Baoquan He
2023-06-10  6:24   ` Christoph Hellwig
2023-06-11  5:44   ` Mike Rapoport
2023-06-09  7:55 ` [PATCH v6 04/19] mm/ioremap: Define generic_ioremap_prot() and generic_iounmap() Baoquan He
2023-06-10  6:24   ` Christoph Hellwig
2023-06-09  7:55 ` [PATCH v6 05/19] mm: ioremap: allow ARCH to have its own ioremap method definition Baoquan He
2023-06-09  7:55 ` [PATCH v6 06/19] mm/ioremap: add slab availability checking in ioremap_prot Baoquan He
2023-06-09  7:55 ` [PATCH v6 07/19] arc: mm: Convert to GENERIC_IOREMAP Baoquan He
2023-06-09  7:55 ` [PATCH v6 08/19] ia64: " Baoquan He
2023-06-09  7:55 ` [PATCH v6 09/19] openrisc: " Baoquan He
2023-06-10  6:25   ` Christoph Hellwig
2023-06-11  5:46   ` Mike Rapoport
2023-06-09  7:55 ` [PATCH v6 10/19] s390: " Baoquan He
2023-06-09 15:41   ` kernel test robot
2023-06-09 17:42   ` kernel test robot
2023-06-09 17:42   ` kernel test robot
2023-06-11 11:10     ` Baoquan He
2023-06-21 14:53       ` Alexander Gordeev
2023-06-09  7:55 ` [PATCH v6 11/19] sh: add <asm-generic/io.h> including Baoquan He
2023-06-09  8:10   ` John Paul Adrian Glaubitz
2023-06-09  8:34     ` Baoquan He
2023-06-09  7:55 ` [PATCH v6 12/19] sh: mm: Convert to GENERIC_IOREMAP Baoquan He
2023-06-09  7:55 ` [PATCH v6 13/19] xtensa: " Baoquan He
2023-06-09  7:55 ` [PATCH v6 14/19] parisc: " Baoquan He
2023-06-19  5:47   ` Helge Deller
2023-06-09  7:55 ` [PATCH v6 15/19] mm/ioremap: Consider IOREMAP space in generic ioremap Baoquan He
2023-06-10  6:26   ` Christoph Hellwig
2023-06-09  7:55 ` [PATCH v6 16/19] mm: move is_ioremap_addr() into new header file Baoquan He
2023-06-09  7:55 ` [PATCH v6 17/19] powerpc: mm: Convert to GENERIC_IOREMAP Baoquan He
2023-06-09  7:55 ` [PATCH v6 18/19] arm64 : mm: add wrapper function ioremap_prot() Baoquan He
2023-06-14 15:14   ` Catalin Marinas
2023-06-09  7:55 ` [PATCH v6 19/19] mm: ioremap: remove unneeded ioremap_allowed and iounmap_allowed 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=20230609075528.9390-1-bhe@redhat.com \
    --to=bhe@redhat.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=agordeev@linux.ibm.com \
    --cc=arnd@arndb.de \
    --cc=christophe.leroy@csgroup.eu \
    --cc=deller@gmx.de \
    --cc=hch@lst.de \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rppt@kernel.org \
    --cc=schnelle@linux.ibm.com \
    --cc=shorne@gmail.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=willy@infradead.org \
    /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).