All of lore.kernel.org
 help / color / mirror / Atom feed
* cleanup swiotlb initialization v8
@ 2022-04-04  5:05 ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Hi all,

this series tries to clean up the swiotlb initialization, including
that of swiotlb-xen.  To get there is also removes the x86 iommu table
infrastructure that massively obsfucates the initialization path.

Git tree:

    git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup

Gitweb:

    http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup

Changes since v7:
 - rebased to Linux 5.18-rc1
 - better document the lower bound swiotlb size for xen-swiotlb
 - improve the nslabs calculation for the retry case in
   swiotlb_init_remap and swiotlb_init_late

Changes since v6:
 - use IO_TLB_MIN_SLABS instead of open coding the constant
 - call the remap callback later in swiotlb_init_late
 - set SWIOTLB_ANY for xen/x86

Changes since v5:
 - split a patch into three
 - fix setting x86_swiotlb_enable for Xen
 - fix a comment about forced bounce buffering for guest memory
   encryption
 - remove the xen_initial_domain check from
   xen_create_contiguous_region

Changes since v3:
 - fix a compilation issue on some powerpc configfs
 - fix and cleanup how forced bounce buffering is enabled for
   guest memory encryption

Changes since v2:
 - make ppc_swiotlb_flags actually work again
 - also force enable swiotlb for guest encrypted memory to cater
   to hyperv which doesn't set the host encrypted memory flag

Changes since v1:
 - skip IOMMU initialization on Xen PV kernels
 - various small whitespace / typo fixes

Diffstat:
 arch/ia64/include/asm/iommu_table.h      |    7 -
 arch/x86/include/asm/iommu_table.h       |  102 -------------------
 arch/x86/include/asm/swiotlb.h           |   30 -----
 arch/x86/kernel/pci-iommu_table.c        |   77 --------------
 arch/x86/kernel/pci-swiotlb.c            |   77 --------------
 arch/x86/xen/pci-swiotlb-xen.c           |   96 ------------------
 b/arch/arm/mm/init.c                     |    6 -
 b/arch/arm/xen/mm.c                      |   26 ++--
 b/arch/arm64/mm/init.c                   |    6 -
 b/arch/ia64/mm/init.c                    |    4 
 b/arch/mips/cavium-octeon/dma-octeon.c   |   15 --
 b/arch/mips/loongson64/dma.c             |    2 
 b/arch/mips/pci/pci-octeon.c             |    2 
 b/arch/mips/sibyte/common/dma.c          |    2 
 b/arch/powerpc/include/asm/svm.h         |    4 
 b/arch/powerpc/include/asm/swiotlb.h     |    1 
 b/arch/powerpc/kernel/dma-swiotlb.c      |    1 
 b/arch/powerpc/mm/mem.c                  |    6 -
 b/arch/powerpc/platforms/pseries/setup.c |    3 
 b/arch/powerpc/platforms/pseries/svm.c   |   26 ----
 b/arch/riscv/mm/init.c                   |    8 -
 b/arch/s390/mm/init.c                    |    3 
 b/arch/x86/include/asm/dma-mapping.h     |   12 --
 b/arch/x86/include/asm/gart.h            |    5 
 b/arch/x86/include/asm/iommu.h           |    8 +
 b/arch/x86/include/asm/xen/page.h        |    5 
 b/arch/x86/include/asm/xen/swiotlb-xen.h |    2 
 b/arch/x86/kernel/Makefile               |    2 
 b/arch/x86/kernel/amd_gart_64.c          |    5 
 b/arch/x86/kernel/aperture_64.c          |   14 --
 b/arch/x86/kernel/cpu/mshyperv.c         |    8 -
 b/arch/x86/kernel/pci-dma.c              |  114 +++++++++++++++++----
 b/arch/x86/kernel/tboot.c                |    1 
 b/arch/x86/kernel/vmlinux.lds.S          |   12 --
 b/arch/x86/mm/mem_encrypt_amd.c          |    3 
 b/arch/x86/pci/sta2x11-fixup.c           |    2 
 b/arch/x86/xen/Makefile                  |    2 
 b/drivers/iommu/amd/init.c               |    6 -
 b/drivers/iommu/amd/iommu.c              |    5 
 b/drivers/iommu/intel/dmar.c             |    6 -
 b/drivers/xen/swiotlb-xen.c              |  132 -------------------------
 b/include/linux/dmar.h                   |    6 -
 b/include/linux/swiotlb.h                |   22 ++--
 b/include/trace/events/swiotlb.h         |   29 +----
 b/include/xen/arm/page.h                 |    1 
 b/include/xen/swiotlb-xen.h              |    8 +
 b/kernel/dma/direct.h                    |    2 
 b/kernel/dma/swiotlb.c                   |  163 ++++++++++++++-----------------
 48 files changed, 252 insertions(+), 827 deletions(-)
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* cleanup swiotlb initialization v8
@ 2022-04-04  5:05 ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Hi all,

this series tries to clean up the swiotlb initialization, including
that of swiotlb-xen.  To get there is also removes the x86 iommu table
infrastructure that massively obsfucates the initialization path.

Git tree:

    git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup

Gitweb:

    http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup

Changes since v7:
 - rebased to Linux 5.18-rc1
 - better document the lower bound swiotlb size for xen-swiotlb
 - improve the nslabs calculation for the retry case in
   swiotlb_init_remap and swiotlb_init_late

Changes since v6:
 - use IO_TLB_MIN_SLABS instead of open coding the constant
 - call the remap callback later in swiotlb_init_late
 - set SWIOTLB_ANY for xen/x86

Changes since v5:
 - split a patch into three
 - fix setting x86_swiotlb_enable for Xen
 - fix a comment about forced bounce buffering for guest memory
   encryption
 - remove the xen_initial_domain check from
   xen_create_contiguous_region

Changes since v3:
 - fix a compilation issue on some powerpc configfs
 - fix and cleanup how forced bounce buffering is enabled for
   guest memory encryption

Changes since v2:
 - make ppc_swiotlb_flags actually work again
 - also force enable swiotlb for guest encrypted memory to cater
   to hyperv which doesn't set the host encrypted memory flag

Changes since v1:
 - skip IOMMU initialization on Xen PV kernels
 - various small whitespace / typo fixes

Diffstat:
 arch/ia64/include/asm/iommu_table.h      |    7 -
 arch/x86/include/asm/iommu_table.h       |  102 -------------------
 arch/x86/include/asm/swiotlb.h           |   30 -----
 arch/x86/kernel/pci-iommu_table.c        |   77 --------------
 arch/x86/kernel/pci-swiotlb.c            |   77 --------------
 arch/x86/xen/pci-swiotlb-xen.c           |   96 ------------------
 b/arch/arm/mm/init.c                     |    6 -
 b/arch/arm/xen/mm.c                      |   26 ++--
 b/arch/arm64/mm/init.c                   |    6 -
 b/arch/ia64/mm/init.c                    |    4 
 b/arch/mips/cavium-octeon/dma-octeon.c   |   15 --
 b/arch/mips/loongson64/dma.c             |    2 
 b/arch/mips/pci/pci-octeon.c             |    2 
 b/arch/mips/sibyte/common/dma.c          |    2 
 b/arch/powerpc/include/asm/svm.h         |    4 
 b/arch/powerpc/include/asm/swiotlb.h     |    1 
 b/arch/powerpc/kernel/dma-swiotlb.c      |    1 
 b/arch/powerpc/mm/mem.c                  |    6 -
 b/arch/powerpc/platforms/pseries/setup.c |    3 
 b/arch/powerpc/platforms/pseries/svm.c   |   26 ----
 b/arch/riscv/mm/init.c                   |    8 -
 b/arch/s390/mm/init.c                    |    3 
 b/arch/x86/include/asm/dma-mapping.h     |   12 --
 b/arch/x86/include/asm/gart.h            |    5 
 b/arch/x86/include/asm/iommu.h           |    8 +
 b/arch/x86/include/asm/xen/page.h        |    5 
 b/arch/x86/include/asm/xen/swiotlb-xen.h |    2 
 b/arch/x86/kernel/Makefile               |    2 
 b/arch/x86/kernel/amd_gart_64.c          |    5 
 b/arch/x86/kernel/aperture_64.c          |   14 --
 b/arch/x86/kernel/cpu/mshyperv.c         |    8 -
 b/arch/x86/kernel/pci-dma.c              |  114 +++++++++++++++++----
 b/arch/x86/kernel/tboot.c                |    1 
 b/arch/x86/kernel/vmlinux.lds.S          |   12 --
 b/arch/x86/mm/mem_encrypt_amd.c          |    3 
 b/arch/x86/pci/sta2x11-fixup.c           |    2 
 b/arch/x86/xen/Makefile                  |    2 
 b/drivers/iommu/amd/init.c               |    6 -
 b/drivers/iommu/amd/iommu.c              |    5 
 b/drivers/iommu/intel/dmar.c             |    6 -
 b/drivers/xen/swiotlb-xen.c              |  132 -------------------------
 b/include/linux/dmar.h                   |    6 -
 b/include/linux/swiotlb.h                |   22 ++--
 b/include/trace/events/swiotlb.h         |   29 +----
 b/include/xen/arm/page.h                 |    1 
 b/include/xen/swiotlb-xen.h              |    8 +
 b/kernel/dma/direct.h                    |    2 
 b/kernel/dma/swiotlb.c                   |  163 ++++++++++++++-----------------
 48 files changed, 252 insertions(+), 827 deletions(-)

^ permalink raw reply	[flat|nested] 197+ messages in thread

* cleanup swiotlb initialization v8
@ 2022-04-04  5:05 ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Hi all,

this series tries to clean up the swiotlb initialization, including
that of swiotlb-xen.  To get there is also removes the x86 iommu table
infrastructure that massively obsfucates the initialization path.

Git tree:

    git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup

Gitweb:

    http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup

Changes since v7:
 - rebased to Linux 5.18-rc1
 - better document the lower bound swiotlb size for xen-swiotlb
 - improve the nslabs calculation for the retry case in
   swiotlb_init_remap and swiotlb_init_late

Changes since v6:
 - use IO_TLB_MIN_SLABS instead of open coding the constant
 - call the remap callback later in swiotlb_init_late
 - set SWIOTLB_ANY for xen/x86

Changes since v5:
 - split a patch into three
 - fix setting x86_swiotlb_enable for Xen
 - fix a comment about forced bounce buffering for guest memory
   encryption
 - remove the xen_initial_domain check from
   xen_create_contiguous_region

Changes since v3:
 - fix a compilation issue on some powerpc configfs
 - fix and cleanup how forced bounce buffering is enabled for
   guest memory encryption

Changes since v2:
 - make ppc_swiotlb_flags actually work again
 - also force enable swiotlb for guest encrypted memory to cater
   to hyperv which doesn't set the host encrypted memory flag

Changes since v1:
 - skip IOMMU initialization on Xen PV kernels
 - various small whitespace / typo fixes

Diffstat:
 arch/ia64/include/asm/iommu_table.h      |    7 -
 arch/x86/include/asm/iommu_table.h       |  102 -------------------
 arch/x86/include/asm/swiotlb.h           |   30 -----
 arch/x86/kernel/pci-iommu_table.c        |   77 --------------
 arch/x86/kernel/pci-swiotlb.c            |   77 --------------
 arch/x86/xen/pci-swiotlb-xen.c           |   96 ------------------
 b/arch/arm/mm/init.c                     |    6 -
 b/arch/arm/xen/mm.c                      |   26 ++--
 b/arch/arm64/mm/init.c                   |    6 -
 b/arch/ia64/mm/init.c                    |    4 
 b/arch/mips/cavium-octeon/dma-octeon.c   |   15 --
 b/arch/mips/loongson64/dma.c             |    2 
 b/arch/mips/pci/pci-octeon.c             |    2 
 b/arch/mips/sibyte/common/dma.c          |    2 
 b/arch/powerpc/include/asm/svm.h         |    4 
 b/arch/powerpc/include/asm/swiotlb.h     |    1 
 b/arch/powerpc/kernel/dma-swiotlb.c      |    1 
 b/arch/powerpc/mm/mem.c                  |    6 -
 b/arch/powerpc/platforms/pseries/setup.c |    3 
 b/arch/powerpc/platforms/pseries/svm.c   |   26 ----
 b/arch/riscv/mm/init.c                   |    8 -
 b/arch/s390/mm/init.c                    |    3 
 b/arch/x86/include/asm/dma-mapping.h     |   12 --
 b/arch/x86/include/asm/gart.h            |    5 
 b/arch/x86/include/asm/iommu.h           |    8 +
 b/arch/x86/include/asm/xen/page.h        |    5 
 b/arch/x86/include/asm/xen/swiotlb-xen.h |    2 
 b/arch/x86/kernel/Makefile               |    2 
 b/arch/x86/kernel/amd_gart_64.c          |    5 
 b/arch/x86/kernel/aperture_64.c          |   14 --
 b/arch/x86/kernel/cpu/mshyperv.c         |    8 -
 b/arch/x86/kernel/pci-dma.c              |  114 +++++++++++++++++----
 b/arch/x86/kernel/tboot.c                |    1 
 b/arch/x86/kernel/vmlinux.lds.S          |   12 --
 b/arch/x86/mm/mem_encrypt_amd.c          |    3 
 b/arch/x86/pci/sta2x11-fixup.c           |    2 
 b/arch/x86/xen/Makefile                  |    2 
 b/drivers/iommu/amd/init.c               |    6 -
 b/drivers/iommu/amd/iommu.c              |    5 
 b/drivers/iommu/intel/dmar.c             |    6 -
 b/drivers/xen/swiotlb-xen.c              |  132 -------------------------
 b/include/linux/dmar.h                   |    6 -
 b/include/linux/swiotlb.h                |   22 ++--
 b/include/trace/events/swiotlb.h         |   29 +----
 b/include/xen/arm/page.h                 |    1 
 b/include/xen/swiotlb-xen.h              |    8 +
 b/kernel/dma/direct.h                    |    2 
 b/kernel/dma/swiotlb.c                   |  163 ++++++++++++++-----------------
 48 files changed, 252 insertions(+), 827 deletions(-)

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* cleanup swiotlb initialization v8
@ 2022-04-04  5:05 ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

Hi all,

this series tries to clean up the swiotlb initialization, including
that of swiotlb-xen.  To get there is also removes the x86 iommu table
infrastructure that massively obsfucates the initialization path.

Git tree:

    git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup

Gitweb:

    http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup

Changes since v7:
 - rebased to Linux 5.18-rc1
 - better document the lower bound swiotlb size for xen-swiotlb
 - improve the nslabs calculation for the retry case in
   swiotlb_init_remap and swiotlb_init_late

Changes since v6:
 - use IO_TLB_MIN_SLABS instead of open coding the constant
 - call the remap callback later in swiotlb_init_late
 - set SWIOTLB_ANY for xen/x86

Changes since v5:
 - split a patch into three
 - fix setting x86_swiotlb_enable for Xen
 - fix a comment about forced bounce buffering for guest memory
   encryption
 - remove the xen_initial_domain check from
   xen_create_contiguous_region

Changes since v3:
 - fix a compilation issue on some powerpc configfs
 - fix and cleanup how forced bounce buffering is enabled for
   guest memory encryption

Changes since v2:
 - make ppc_swiotlb_flags actually work again
 - also force enable swiotlb for guest encrypted memory to cater
   to hyperv which doesn't set the host encrypted memory flag

Changes since v1:
 - skip IOMMU initialization on Xen PV kernels
 - various small whitespace / typo fixes

Diffstat:
 arch/ia64/include/asm/iommu_table.h      |    7 -
 arch/x86/include/asm/iommu_table.h       |  102 -------------------
 arch/x86/include/asm/swiotlb.h           |   30 -----
 arch/x86/kernel/pci-iommu_table.c        |   77 --------------
 arch/x86/kernel/pci-swiotlb.c            |   77 --------------
 arch/x86/xen/pci-swiotlb-xen.c           |   96 ------------------
 b/arch/arm/mm/init.c                     |    6 -
 b/arch/arm/xen/mm.c                      |   26 ++--
 b/arch/arm64/mm/init.c                   |    6 -
 b/arch/ia64/mm/init.c                    |    4 
 b/arch/mips/cavium-octeon/dma-octeon.c   |   15 --
 b/arch/mips/loongson64/dma.c             |    2 
 b/arch/mips/pci/pci-octeon.c             |    2 
 b/arch/mips/sibyte/common/dma.c          |    2 
 b/arch/powerpc/include/asm/svm.h         |    4 
 b/arch/powerpc/include/asm/swiotlb.h     |    1 
 b/arch/powerpc/kernel/dma-swiotlb.c      |    1 
 b/arch/powerpc/mm/mem.c                  |    6 -
 b/arch/powerpc/platforms/pseries/setup.c |    3 
 b/arch/powerpc/platforms/pseries/svm.c   |   26 ----
 b/arch/riscv/mm/init.c                   |    8 -
 b/arch/s390/mm/init.c                    |    3 
 b/arch/x86/include/asm/dma-mapping.h     |   12 --
 b/arch/x86/include/asm/gart.h            |    5 
 b/arch/x86/include/asm/iommu.h           |    8 +
 b/arch/x86/include/asm/xen/page.h        |    5 
 b/arch/x86/include/asm/xen/swiotlb-xen.h |    2 
 b/arch/x86/kernel/Makefile               |    2 
 b/arch/x86/kernel/amd_gart_64.c          |    5 
 b/arch/x86/kernel/aperture_64.c          |   14 --
 b/arch/x86/kernel/cpu/mshyperv.c         |    8 -
 b/arch/x86/kernel/pci-dma.c              |  114 +++++++++++++++++----
 b/arch/x86/kernel/tboot.c                |    1 
 b/arch/x86/kernel/vmlinux.lds.S          |   12 --
 b/arch/x86/mm/mem_encrypt_amd.c          |    3 
 b/arch/x86/pci/sta2x11-fixup.c           |    2 
 b/arch/x86/xen/Makefile                  |    2 
 b/drivers/iommu/amd/init.c               |    6 -
 b/drivers/iommu/amd/iommu.c              |    5 
 b/drivers/iommu/intel/dmar.c             |    6 -
 b/drivers/xen/swiotlb-xen.c              |  132 -------------------------
 b/include/linux/dmar.h                   |    6 -
 b/include/linux/swiotlb.h                |   22 ++--
 b/include/trace/events/swiotlb.h         |   29 +----
 b/include/xen/arm/page.h                 |    1 
 b/include/xen/swiotlb-xen.h              |    8 +
 b/kernel/dma/direct.h                    |    2 
 b/kernel/dma/swiotlb.c                   |  163 ++++++++++++++-----------------
 48 files changed, 252 insertions(+), 827 deletions(-)

^ permalink raw reply	[flat|nested] 197+ messages in thread

* cleanup swiotlb initialization v8
@ 2022-04-04  5:05 ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Hi all,

this series tries to clean up the swiotlb initialization, including
that of swiotlb-xen.  To get there is also removes the x86 iommu table
infrastructure that massively obsfucates the initialization path.

Git tree:

    git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup

Gitweb:

    http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup

Changes since v7:
 - rebased to Linux 5.18-rc1
 - better document the lower bound swiotlb size for xen-swiotlb
 - improve the nslabs calculation for the retry case in
   swiotlb_init_remap and swiotlb_init_late

Changes since v6:
 - use IO_TLB_MIN_SLABS instead of open coding the constant
 - call the remap callback later in swiotlb_init_late
 - set SWIOTLB_ANY for xen/x86

Changes since v5:
 - split a patch into three
 - fix setting x86_swiotlb_enable for Xen
 - fix a comment about forced bounce buffering for guest memory
   encryption
 - remove the xen_initial_domain check from
   xen_create_contiguous_region

Changes since v3:
 - fix a compilation issue on some powerpc configfs
 - fix and cleanup how forced bounce buffering is enabled for
   guest memory encryption

Changes since v2:
 - make ppc_swiotlb_flags actually work again
 - also force enable swiotlb for guest encrypted memory to cater
   to hyperv which doesn't set the host encrypted memory flag

Changes since v1:
 - skip IOMMU initialization on Xen PV kernels
 - various small whitespace / typo fixes

Diffstat:
 arch/ia64/include/asm/iommu_table.h      |    7 -
 arch/x86/include/asm/iommu_table.h       |  102 -------------------
 arch/x86/include/asm/swiotlb.h           |   30 -----
 arch/x86/kernel/pci-iommu_table.c        |   77 --------------
 arch/x86/kernel/pci-swiotlb.c            |   77 --------------
 arch/x86/xen/pci-swiotlb-xen.c           |   96 ------------------
 b/arch/arm/mm/init.c                     |    6 -
 b/arch/arm/xen/mm.c                      |   26 ++--
 b/arch/arm64/mm/init.c                   |    6 -
 b/arch/ia64/mm/init.c                    |    4 
 b/arch/mips/cavium-octeon/dma-octeon.c   |   15 --
 b/arch/mips/loongson64/dma.c             |    2 
 b/arch/mips/pci/pci-octeon.c             |    2 
 b/arch/mips/sibyte/common/dma.c          |    2 
 b/arch/powerpc/include/asm/svm.h         |    4 
 b/arch/powerpc/include/asm/swiotlb.h     |    1 
 b/arch/powerpc/kernel/dma-swiotlb.c      |    1 
 b/arch/powerpc/mm/mem.c                  |    6 -
 b/arch/powerpc/platforms/pseries/setup.c |    3 
 b/arch/powerpc/platforms/pseries/svm.c   |   26 ----
 b/arch/riscv/mm/init.c                   |    8 -
 b/arch/s390/mm/init.c                    |    3 
 b/arch/x86/include/asm/dma-mapping.h     |   12 --
 b/arch/x86/include/asm/gart.h            |    5 
 b/arch/x86/include/asm/iommu.h           |    8 +
 b/arch/x86/include/asm/xen/page.h        |    5 
 b/arch/x86/include/asm/xen/swiotlb-xen.h |    2 
 b/arch/x86/kernel/Makefile               |    2 
 b/arch/x86/kernel/amd_gart_64.c          |    5 
 b/arch/x86/kernel/aperture_64.c          |   14 --
 b/arch/x86/kernel/cpu/mshyperv.c         |    8 -
 b/arch/x86/kernel/pci-dma.c              |  114 +++++++++++++++++----
 b/arch/x86/kernel/tboot.c                |    1 
 b/arch/x86/kernel/vmlinux.lds.S          |   12 --
 b/arch/x86/mm/mem_encrypt_amd.c          |    3 
 b/arch/x86/pci/sta2x11-fixup.c           |    2 
 b/arch/x86/xen/Makefile                  |    2 
 b/drivers/iommu/amd/init.c               |    6 -
 b/drivers/iommu/amd/iommu.c              |    5 
 b/drivers/iommu/intel/dmar.c             |    6 -
 b/drivers/xen/swiotlb-xen.c              |  132 -------------------------
 b/include/linux/dmar.h                   |    6 -
 b/include/linux/swiotlb.h                |   22 ++--
 b/include/trace/events/swiotlb.h         |   29 +----
 b/include/xen/arm/page.h                 |    1 
 b/include/xen/swiotlb-xen.h              |    8 +
 b/kernel/dma/direct.h                    |    2 
 b/kernel/dma/swiotlb.c                   |  163 ++++++++++++++-----------------
 48 files changed, 252 insertions(+), 827 deletions(-)

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* cleanup swiotlb initialization v8
@ 2022-04-04  5:05 ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Hi all,

this series tries to clean up the swiotlb initialization, including
that of swiotlb-xen.  To get there is also removes the x86 iommu table
infrastructure that massively obsfucates the initialization path.

Git tree:

    git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup

Gitweb:

    http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup

Changes since v7:
 - rebased to Linux 5.18-rc1
 - better document the lower bound swiotlb size for xen-swiotlb
 - improve the nslabs calculation for the retry case in
   swiotlb_init_remap and swiotlb_init_late

Changes since v6:
 - use IO_TLB_MIN_SLABS instead of open coding the constant
 - call the remap callback later in swiotlb_init_late
 - set SWIOTLB_ANY for xen/x86

Changes since v5:
 - split a patch into three
 - fix setting x86_swiotlb_enable for Xen
 - fix a comment about forced bounce buffering for guest memory
   encryption
 - remove the xen_initial_domain check from
   xen_create_contiguous_region

Changes since v3:
 - fix a compilation issue on some powerpc configfs
 - fix and cleanup how forced bounce buffering is enabled for
   guest memory encryption

Changes since v2:
 - make ppc_swiotlb_flags actually work again
 - also force enable swiotlb for guest encrypted memory to cater
   to hyperv which doesn't set the host encrypted memory flag

Changes since v1:
 - skip IOMMU initialization on Xen PV kernels
 - various small whitespace / typo fixes

Diffstat:
 arch/ia64/include/asm/iommu_table.h      |    7 -
 arch/x86/include/asm/iommu_table.h       |  102 -------------------
 arch/x86/include/asm/swiotlb.h           |   30 -----
 arch/x86/kernel/pci-iommu_table.c        |   77 --------------
 arch/x86/kernel/pci-swiotlb.c            |   77 --------------
 arch/x86/xen/pci-swiotlb-xen.c           |   96 ------------------
 b/arch/arm/mm/init.c                     |    6 -
 b/arch/arm/xen/mm.c                      |   26 ++--
 b/arch/arm64/mm/init.c                   |    6 -
 b/arch/ia64/mm/init.c                    |    4 
 b/arch/mips/cavium-octeon/dma-octeon.c   |   15 --
 b/arch/mips/loongson64/dma.c             |    2 
 b/arch/mips/pci/pci-octeon.c             |    2 
 b/arch/mips/sibyte/common/dma.c          |    2 
 b/arch/powerpc/include/asm/svm.h         |    4 
 b/arch/powerpc/include/asm/swiotlb.h     |    1 
 b/arch/powerpc/kernel/dma-swiotlb.c      |    1 
 b/arch/powerpc/mm/mem.c                  |    6 -
 b/arch/powerpc/platforms/pseries/setup.c |    3 
 b/arch/powerpc/platforms/pseries/svm.c   |   26 ----
 b/arch/riscv/mm/init.c                   |    8 -
 b/arch/s390/mm/init.c                    |    3 
 b/arch/x86/include/asm/dma-mapping.h     |   12 --
 b/arch/x86/include/asm/gart.h            |    5 
 b/arch/x86/include/asm/iommu.h           |    8 +
 b/arch/x86/include/asm/xen/page.h        |    5 
 b/arch/x86/include/asm/xen/swiotlb-xen.h |    2 
 b/arch/x86/kernel/Makefile               |    2 
 b/arch/x86/kernel/amd_gart_64.c          |    5 
 b/arch/x86/kernel/aperture_64.c          |   14 --
 b/arch/x86/kernel/cpu/mshyperv.c         |    8 -
 b/arch/x86/kernel/pci-dma.c              |  114 +++++++++++++++++----
 b/arch/x86/kernel/tboot.c                |    1 
 b/arch/x86/kernel/vmlinux.lds.S          |   12 --
 b/arch/x86/mm/mem_encrypt_amd.c          |    3 
 b/arch/x86/pci/sta2x11-fixup.c           |    2 
 b/arch/x86/xen/Makefile                  |    2 
 b/drivers/iommu/amd/init.c               |    6 -
 b/drivers/iommu/amd/iommu.c              |    5 
 b/drivers/iommu/intel/dmar.c             |    6 -
 b/drivers/xen/swiotlb-xen.c              |  132 -------------------------
 b/include/linux/dmar.h                   |    6 -
 b/include/linux/swiotlb.h                |   22 ++--
 b/include/trace/events/swiotlb.h         |   29 +----
 b/include/xen/arm/page.h                 |    1 
 b/include/xen/swiotlb-xen.h              |    8 +
 b/kernel/dma/direct.h                    |    2 
 b/kernel/dma/swiotlb.c                   |  163 ++++++++++++++-----------------
 48 files changed, 252 insertions(+), 827 deletions(-)

^ permalink raw reply	[flat|nested] 197+ messages in thread

* [PATCH 01/15] dma-direct: use is_swiotlb_active in dma_direct_map_page
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Use the more specific is_swiotlb_active check instead of checking the
global swiotlb_force variable.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 kernel/dma/direct.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/direct.h b/kernel/dma/direct.h
index 4632b0f4f72eb..4dc16e08c7e1a 100644
--- a/kernel/dma/direct.h
+++ b/kernel/dma/direct.h
@@ -91,7 +91,7 @@ static inline dma_addr_t dma_direct_map_page(struct device *dev,
 		return swiotlb_map(dev, phys, size, dir, attrs);
 
 	if (unlikely(!dma_capable(dev, dma_addr, size, true))) {
-		if (swiotlb_force != SWIOTLB_NO_FORCE)
+		if (is_swiotlb_active(dev))
 			return swiotlb_map(dev, phys, size, dir, attrs);
 
 		dev_WARN_ONCE(dev, 1,
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 01/15] dma-direct: use is_swiotlb_active in dma_direct_map_page
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Use the more specific is_swiotlb_active check instead of checking the
global swiotlb_force variable.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 kernel/dma/direct.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/direct.h b/kernel/dma/direct.h
index 4632b0f4f72eb..4dc16e08c7e1a 100644
--- a/kernel/dma/direct.h
+++ b/kernel/dma/direct.h
@@ -91,7 +91,7 @@ static inline dma_addr_t dma_direct_map_page(struct device *dev,
 		return swiotlb_map(dev, phys, size, dir, attrs);
 
 	if (unlikely(!dma_capable(dev, dma_addr, size, true))) {
-		if (swiotlb_force != SWIOTLB_NO_FORCE)
+		if (is_swiotlb_active(dev))
 			return swiotlb_map(dev, phys, size, dir, attrs);
 
 		dev_WARN_ONCE(dev, 1,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 01/15] dma-direct: use is_swiotlb_active in dma_direct_map_page
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Use the more specific is_swiotlb_active check instead of checking the
global swiotlb_force variable.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 kernel/dma/direct.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/direct.h b/kernel/dma/direct.h
index 4632b0f4f72eb..4dc16e08c7e1a 100644
--- a/kernel/dma/direct.h
+++ b/kernel/dma/direct.h
@@ -91,7 +91,7 @@ static inline dma_addr_t dma_direct_map_page(struct device *dev,
 		return swiotlb_map(dev, phys, size, dir, attrs);
 
 	if (unlikely(!dma_capable(dev, dma_addr, size, true))) {
-		if (swiotlb_force != SWIOTLB_NO_FORCE)
+		if (is_swiotlb_active(dev))
 			return swiotlb_map(dev, phys, size, dir, attrs);
 
 		dev_WARN_ONCE(dev, 1,
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 01/15] dma-direct: use is_swiotlb_active in dma_direct_map_page
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Use the more specific is_swiotlb_active check instead of checking the
global swiotlb_force variable.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 kernel/dma/direct.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/direct.h b/kernel/dma/direct.h
index 4632b0f4f72eb..4dc16e08c7e1a 100644
--- a/kernel/dma/direct.h
+++ b/kernel/dma/direct.h
@@ -91,7 +91,7 @@ static inline dma_addr_t dma_direct_map_page(struct device *dev,
 		return swiotlb_map(dev, phys, size, dir, attrs);
 
 	if (unlikely(!dma_capable(dev, dma_addr, size, true))) {
-		if (swiotlb_force != SWIOTLB_NO_FORCE)
+		if (is_swiotlb_active(dev))
 			return swiotlb_map(dev, phys, size, dir, attrs);
 
 		dev_WARN_ONCE(dev, 1,
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 01/15] dma-direct: use is_swiotlb_active in dma_direct_map_page
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

Use the more specific is_swiotlb_active check instead of checking the
global swiotlb_force variable.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 kernel/dma/direct.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/direct.h b/kernel/dma/direct.h
index 4632b0f4f72eb..4dc16e08c7e1a 100644
--- a/kernel/dma/direct.h
+++ b/kernel/dma/direct.h
@@ -91,7 +91,7 @@ static inline dma_addr_t dma_direct_map_page(struct device *dev,
 		return swiotlb_map(dev, phys, size, dir, attrs);
 
 	if (unlikely(!dma_capable(dev, dma_addr, size, true))) {
-		if (swiotlb_force != SWIOTLB_NO_FORCE)
+		if (is_swiotlb_active(dev))
 			return swiotlb_map(dev, phys, size, dir, attrs);
 
 		dev_WARN_ONCE(dev, 1,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 01/15] dma-direct: use is_swiotlb_active in dma_direct_map_page
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Use the more specific is_swiotlb_active check instead of checking the
global swiotlb_force variable.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 kernel/dma/direct.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/direct.h b/kernel/dma/direct.h
index 4632b0f4f72eb..4dc16e08c7e1a 100644
--- a/kernel/dma/direct.h
+++ b/kernel/dma/direct.h
@@ -91,7 +91,7 @@ static inline dma_addr_t dma_direct_map_page(struct device *dev,
 		return swiotlb_map(dev, phys, size, dir, attrs);
 
 	if (unlikely(!dma_capable(dev, dma_addr, size, true))) {
-		if (swiotlb_force != SWIOTLB_NO_FORCE)
+		if (is_swiotlb_active(dev))
 			return swiotlb_map(dev, phys, size, dir, attrs);
 
 		dev_WARN_ONCE(dev, 1,
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 02/15] swiotlb: make swiotlb_exit a no-op if SWIOTLB_FORCE is set
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

If force bouncing is enabled we can't release the buffers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 kernel/dma/swiotlb.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 73a41cec9e386..98bb0eb44a7bf 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -369,6 +369,9 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
+	if (swiotlb_force == SWIOTLB_FORCE)
+		return;
+
 	if (!mem->nslabs)
 		return;
 
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 02/15] swiotlb: make swiotlb_exit a no-op if SWIOTLB_FORCE is set
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

If force bouncing is enabled we can't release the buffers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 kernel/dma/swiotlb.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 73a41cec9e386..98bb0eb44a7bf 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -369,6 +369,9 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
+	if (swiotlb_force == SWIOTLB_FORCE)
+		return;
+
 	if (!mem->nslabs)
 		return;
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 02/15] swiotlb: make swiotlb_exit a no-op if SWIOTLB_FORCE is set
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

If force bouncing is enabled we can't release the buffers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 kernel/dma/swiotlb.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 73a41cec9e386..98bb0eb44a7bf 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -369,6 +369,9 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
+	if (swiotlb_force == SWIOTLB_FORCE)
+		return;
+
 	if (!mem->nslabs)
 		return;
 
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 02/15] swiotlb: make swiotlb_exit a no-op if SWIOTLB_FORCE is set
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

If force bouncing is enabled we can't release the buffers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 kernel/dma/swiotlb.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 73a41cec9e386..98bb0eb44a7bf 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -369,6 +369,9 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
+	if (swiotlb_force == SWIOTLB_FORCE)
+		return;
+
 	if (!mem->nslabs)
 		return;
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 02/15] swiotlb: make swiotlb_exit a no-op if SWIOTLB_FORCE is set
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

If force bouncing is enabled we can't release the buffers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 kernel/dma/swiotlb.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 73a41cec9e386..98bb0eb44a7bf 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -369,6 +369,9 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
+	if (swiotlb_force == SWIOTLB_FORCE)
+		return;
+
 	if (!mem->nslabs)
 		return;
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 02/15] swiotlb: make swiotlb_exit a no-op if SWIOTLB_FORCE is set
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

If force bouncing is enabled we can't release the buffers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 kernel/dma/swiotlb.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 73a41cec9e386..98bb0eb44a7bf 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -369,6 +369,9 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
+	if (swiotlb_force = SWIOTLB_FORCE)
+		return;
+
 	if (!mem->nslabs)
 		return;
 
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 03/15] swiotlb: simplify swiotlb_max_segment
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Remove the bogus Xen override that was usually larger than the actual
size and just calculate the value on demand.  Note that
swiotlb_max_segment still doesn't make sense as an interface and should
eventually be removed.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 drivers/xen/swiotlb-xen.c |  2 --
 include/linux/swiotlb.h   |  1 -
 kernel/dma/swiotlb.c      | 20 +++-----------------
 3 files changed, 3 insertions(+), 20 deletions(-)

diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 47aebd98f52f5..485cd06ed39e7 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -202,7 +202,6 @@ int xen_swiotlb_init(void)
 	rc = swiotlb_late_init_with_tbl(start, nslabs);
 	if (rc)
 		return rc;
-	swiotlb_set_max_segment(PAGE_SIZE);
 	return 0;
 error:
 	if (nslabs > 1024 && repeat--) {
@@ -254,7 +253,6 @@ void __init xen_swiotlb_init_early(void)
 
 	if (swiotlb_init_with_tbl(start, nslabs, true))
 		panic("Cannot allocate SWIOTLB buffer");
-	swiotlb_set_max_segment(PAGE_SIZE);
 }
 #endif /* CONFIG_X86 */
 
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index f6c3638255d54..9fb3a568f0c51 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -164,7 +164,6 @@ static inline void swiotlb_adjust_size(unsigned long size)
 #endif /* CONFIG_SWIOTLB */
 
 extern void swiotlb_print_info(void);
-extern void swiotlb_set_max_segment(unsigned int);
 
 #ifdef CONFIG_DMA_RESTRICTED_POOL
 struct page *swiotlb_alloc(struct device *dev, size_t size);
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 98bb0eb44a7bf..e0127e397335e 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -68,12 +68,6 @@ struct io_tlb_mem io_tlb_default_mem;
 
 phys_addr_t swiotlb_unencrypted_base;
 
-/*
- * Max segment that we can provide which (if pages are contingous) will
- * not be bounced (unless SWIOTLB_FORCE is set).
- */
-static unsigned int max_segment;
-
 static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT;
 
 static int __init
@@ -97,18 +91,12 @@ early_param("swiotlb", setup_io_tlb_npages);
 
 unsigned int swiotlb_max_segment(void)
 {
-	return io_tlb_default_mem.nslabs ? max_segment : 0;
+	if (!io_tlb_default_mem.nslabs)
+		return 0;
+	return rounddown(io_tlb_default_mem.nslabs << IO_TLB_SHIFT, PAGE_SIZE);
 }
 EXPORT_SYMBOL_GPL(swiotlb_max_segment);
 
-void swiotlb_set_max_segment(unsigned int val)
-{
-	if (swiotlb_force == SWIOTLB_FORCE)
-		max_segment = 1;
-	else
-		max_segment = rounddown(val, PAGE_SIZE);
-}
-
 unsigned long swiotlb_size_or_default(void)
 {
 	return default_nslabs << IO_TLB_SHIFT;
@@ -258,7 +246,6 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 
 	if (verbose)
 		swiotlb_print_info();
-	swiotlb_set_max_segment(mem->nslabs << IO_TLB_SHIFT);
 	return 0;
 }
 
@@ -359,7 +346,6 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
 
 	swiotlb_print_info();
-	swiotlb_set_max_segment(mem->nslabs << IO_TLB_SHIFT);
 	return 0;
 }
 
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 03/15] swiotlb: simplify swiotlb_max_segment
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Remove the bogus Xen override that was usually larger than the actual
size and just calculate the value on demand.  Note that
swiotlb_max_segment still doesn't make sense as an interface and should
eventually be removed.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 drivers/xen/swiotlb-xen.c |  2 --
 include/linux/swiotlb.h   |  1 -
 kernel/dma/swiotlb.c      | 20 +++-----------------
 3 files changed, 3 insertions(+), 20 deletions(-)

diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 47aebd98f52f5..485cd06ed39e7 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -202,7 +202,6 @@ int xen_swiotlb_init(void)
 	rc = swiotlb_late_init_with_tbl(start, nslabs);
 	if (rc)
 		return rc;
-	swiotlb_set_max_segment(PAGE_SIZE);
 	return 0;
 error:
 	if (nslabs > 1024 && repeat--) {
@@ -254,7 +253,6 @@ void __init xen_swiotlb_init_early(void)
 
 	if (swiotlb_init_with_tbl(start, nslabs, true))
 		panic("Cannot allocate SWIOTLB buffer");
-	swiotlb_set_max_segment(PAGE_SIZE);
 }
 #endif /* CONFIG_X86 */
 
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index f6c3638255d54..9fb3a568f0c51 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -164,7 +164,6 @@ static inline void swiotlb_adjust_size(unsigned long size)
 #endif /* CONFIG_SWIOTLB */
 
 extern void swiotlb_print_info(void);
-extern void swiotlb_set_max_segment(unsigned int);
 
 #ifdef CONFIG_DMA_RESTRICTED_POOL
 struct page *swiotlb_alloc(struct device *dev, size_t size);
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 98bb0eb44a7bf..e0127e397335e 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -68,12 +68,6 @@ struct io_tlb_mem io_tlb_default_mem;
 
 phys_addr_t swiotlb_unencrypted_base;
 
-/*
- * Max segment that we can provide which (if pages are contingous) will
- * not be bounced (unless SWIOTLB_FORCE is set).
- */
-static unsigned int max_segment;
-
 static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT;
 
 static int __init
@@ -97,18 +91,12 @@ early_param("swiotlb", setup_io_tlb_npages);
 
 unsigned int swiotlb_max_segment(void)
 {
-	return io_tlb_default_mem.nslabs ? max_segment : 0;
+	if (!io_tlb_default_mem.nslabs)
+		return 0;
+	return rounddown(io_tlb_default_mem.nslabs << IO_TLB_SHIFT, PAGE_SIZE);
 }
 EXPORT_SYMBOL_GPL(swiotlb_max_segment);
 
-void swiotlb_set_max_segment(unsigned int val)
-{
-	if (swiotlb_force == SWIOTLB_FORCE)
-		max_segment = 1;
-	else
-		max_segment = rounddown(val, PAGE_SIZE);
-}
-
 unsigned long swiotlb_size_or_default(void)
 {
 	return default_nslabs << IO_TLB_SHIFT;
@@ -258,7 +246,6 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 
 	if (verbose)
 		swiotlb_print_info();
-	swiotlb_set_max_segment(mem->nslabs << IO_TLB_SHIFT);
 	return 0;
 }
 
@@ -359,7 +346,6 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
 
 	swiotlb_print_info();
-	swiotlb_set_max_segment(mem->nslabs << IO_TLB_SHIFT);
 	return 0;
 }
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 03/15] swiotlb: simplify swiotlb_max_segment
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Remove the bogus Xen override that was usually larger than the actual
size and just calculate the value on demand.  Note that
swiotlb_max_segment still doesn't make sense as an interface and should
eventually be removed.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 drivers/xen/swiotlb-xen.c |  2 --
 include/linux/swiotlb.h   |  1 -
 kernel/dma/swiotlb.c      | 20 +++-----------------
 3 files changed, 3 insertions(+), 20 deletions(-)

diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 47aebd98f52f5..485cd06ed39e7 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -202,7 +202,6 @@ int xen_swiotlb_init(void)
 	rc = swiotlb_late_init_with_tbl(start, nslabs);
 	if (rc)
 		return rc;
-	swiotlb_set_max_segment(PAGE_SIZE);
 	return 0;
 error:
 	if (nslabs > 1024 && repeat--) {
@@ -254,7 +253,6 @@ void __init xen_swiotlb_init_early(void)
 
 	if (swiotlb_init_with_tbl(start, nslabs, true))
 		panic("Cannot allocate SWIOTLB buffer");
-	swiotlb_set_max_segment(PAGE_SIZE);
 }
 #endif /* CONFIG_X86 */
 
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index f6c3638255d54..9fb3a568f0c51 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -164,7 +164,6 @@ static inline void swiotlb_adjust_size(unsigned long size)
 #endif /* CONFIG_SWIOTLB */
 
 extern void swiotlb_print_info(void);
-extern void swiotlb_set_max_segment(unsigned int);
 
 #ifdef CONFIG_DMA_RESTRICTED_POOL
 struct page *swiotlb_alloc(struct device *dev, size_t size);
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 98bb0eb44a7bf..e0127e397335e 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -68,12 +68,6 @@ struct io_tlb_mem io_tlb_default_mem;
 
 phys_addr_t swiotlb_unencrypted_base;
 
-/*
- * Max segment that we can provide which (if pages are contingous) will
- * not be bounced (unless SWIOTLB_FORCE is set).
- */
-static unsigned int max_segment;
-
 static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT;
 
 static int __init
@@ -97,18 +91,12 @@ early_param("swiotlb", setup_io_tlb_npages);
 
 unsigned int swiotlb_max_segment(void)
 {
-	return io_tlb_default_mem.nslabs ? max_segment : 0;
+	if (!io_tlb_default_mem.nslabs)
+		return 0;
+	return rounddown(io_tlb_default_mem.nslabs << IO_TLB_SHIFT, PAGE_SIZE);
 }
 EXPORT_SYMBOL_GPL(swiotlb_max_segment);
 
-void swiotlb_set_max_segment(unsigned int val)
-{
-	if (swiotlb_force == SWIOTLB_FORCE)
-		max_segment = 1;
-	else
-		max_segment = rounddown(val, PAGE_SIZE);
-}
-
 unsigned long swiotlb_size_or_default(void)
 {
 	return default_nslabs << IO_TLB_SHIFT;
@@ -258,7 +246,6 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 
 	if (verbose)
 		swiotlb_print_info();
-	swiotlb_set_max_segment(mem->nslabs << IO_TLB_SHIFT);
 	return 0;
 }
 
@@ -359,7 +346,6 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
 
 	swiotlb_print_info();
-	swiotlb_set_max_segment(mem->nslabs << IO_TLB_SHIFT);
 	return 0;
 }
 
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 03/15] swiotlb: simplify swiotlb_max_segment
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

Remove the bogus Xen override that was usually larger than the actual
size and just calculate the value on demand.  Note that
swiotlb_max_segment still doesn't make sense as an interface and should
eventually be removed.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 drivers/xen/swiotlb-xen.c |  2 --
 include/linux/swiotlb.h   |  1 -
 kernel/dma/swiotlb.c      | 20 +++-----------------
 3 files changed, 3 insertions(+), 20 deletions(-)

diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 47aebd98f52f5..485cd06ed39e7 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -202,7 +202,6 @@ int xen_swiotlb_init(void)
 	rc = swiotlb_late_init_with_tbl(start, nslabs);
 	if (rc)
 		return rc;
-	swiotlb_set_max_segment(PAGE_SIZE);
 	return 0;
 error:
 	if (nslabs > 1024 && repeat--) {
@@ -254,7 +253,6 @@ void __init xen_swiotlb_init_early(void)
 
 	if (swiotlb_init_with_tbl(start, nslabs, true))
 		panic("Cannot allocate SWIOTLB buffer");
-	swiotlb_set_max_segment(PAGE_SIZE);
 }
 #endif /* CONFIG_X86 */
 
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index f6c3638255d54..9fb3a568f0c51 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -164,7 +164,6 @@ static inline void swiotlb_adjust_size(unsigned long size)
 #endif /* CONFIG_SWIOTLB */
 
 extern void swiotlb_print_info(void);
-extern void swiotlb_set_max_segment(unsigned int);
 
 #ifdef CONFIG_DMA_RESTRICTED_POOL
 struct page *swiotlb_alloc(struct device *dev, size_t size);
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 98bb0eb44a7bf..e0127e397335e 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -68,12 +68,6 @@ struct io_tlb_mem io_tlb_default_mem;
 
 phys_addr_t swiotlb_unencrypted_base;
 
-/*
- * Max segment that we can provide which (if pages are contingous) will
- * not be bounced (unless SWIOTLB_FORCE is set).
- */
-static unsigned int max_segment;
-
 static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT;
 
 static int __init
@@ -97,18 +91,12 @@ early_param("swiotlb", setup_io_tlb_npages);
 
 unsigned int swiotlb_max_segment(void)
 {
-	return io_tlb_default_mem.nslabs ? max_segment : 0;
+	if (!io_tlb_default_mem.nslabs)
+		return 0;
+	return rounddown(io_tlb_default_mem.nslabs << IO_TLB_SHIFT, PAGE_SIZE);
 }
 EXPORT_SYMBOL_GPL(swiotlb_max_segment);
 
-void swiotlb_set_max_segment(unsigned int val)
-{
-	if (swiotlb_force == SWIOTLB_FORCE)
-		max_segment = 1;
-	else
-		max_segment = rounddown(val, PAGE_SIZE);
-}
-
 unsigned long swiotlb_size_or_default(void)
 {
 	return default_nslabs << IO_TLB_SHIFT;
@@ -258,7 +246,6 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 
 	if (verbose)
 		swiotlb_print_info();
-	swiotlb_set_max_segment(mem->nslabs << IO_TLB_SHIFT);
 	return 0;
 }
 
@@ -359,7 +346,6 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
 
 	swiotlb_print_info();
-	swiotlb_set_max_segment(mem->nslabs << IO_TLB_SHIFT);
 	return 0;
 }
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 03/15] swiotlb: simplify swiotlb_max_segment
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Remove the bogus Xen override that was usually larger than the actual
size and just calculate the value on demand.  Note that
swiotlb_max_segment still doesn't make sense as an interface and should
eventually be removed.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 drivers/xen/swiotlb-xen.c |  2 --
 include/linux/swiotlb.h   |  1 -
 kernel/dma/swiotlb.c      | 20 +++-----------------
 3 files changed, 3 insertions(+), 20 deletions(-)

diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 47aebd98f52f5..485cd06ed39e7 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -202,7 +202,6 @@ int xen_swiotlb_init(void)
 	rc = swiotlb_late_init_with_tbl(start, nslabs);
 	if (rc)
 		return rc;
-	swiotlb_set_max_segment(PAGE_SIZE);
 	return 0;
 error:
 	if (nslabs > 1024 && repeat--) {
@@ -254,7 +253,6 @@ void __init xen_swiotlb_init_early(void)
 
 	if (swiotlb_init_with_tbl(start, nslabs, true))
 		panic("Cannot allocate SWIOTLB buffer");
-	swiotlb_set_max_segment(PAGE_SIZE);
 }
 #endif /* CONFIG_X86 */
 
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index f6c3638255d54..9fb3a568f0c51 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -164,7 +164,6 @@ static inline void swiotlb_adjust_size(unsigned long size)
 #endif /* CONFIG_SWIOTLB */
 
 extern void swiotlb_print_info(void);
-extern void swiotlb_set_max_segment(unsigned int);
 
 #ifdef CONFIG_DMA_RESTRICTED_POOL
 struct page *swiotlb_alloc(struct device *dev, size_t size);
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 98bb0eb44a7bf..e0127e397335e 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -68,12 +68,6 @@ struct io_tlb_mem io_tlb_default_mem;
 
 phys_addr_t swiotlb_unencrypted_base;
 
-/*
- * Max segment that we can provide which (if pages are contingous) will
- * not be bounced (unless SWIOTLB_FORCE is set).
- */
-static unsigned int max_segment;
-
 static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT;
 
 static int __init
@@ -97,18 +91,12 @@ early_param("swiotlb", setup_io_tlb_npages);
 
 unsigned int swiotlb_max_segment(void)
 {
-	return io_tlb_default_mem.nslabs ? max_segment : 0;
+	if (!io_tlb_default_mem.nslabs)
+		return 0;
+	return rounddown(io_tlb_default_mem.nslabs << IO_TLB_SHIFT, PAGE_SIZE);
 }
 EXPORT_SYMBOL_GPL(swiotlb_max_segment);
 
-void swiotlb_set_max_segment(unsigned int val)
-{
-	if (swiotlb_force == SWIOTLB_FORCE)
-		max_segment = 1;
-	else
-		max_segment = rounddown(val, PAGE_SIZE);
-}
-
 unsigned long swiotlb_size_or_default(void)
 {
 	return default_nslabs << IO_TLB_SHIFT;
@@ -258,7 +246,6 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 
 	if (verbose)
 		swiotlb_print_info();
-	swiotlb_set_max_segment(mem->nslabs << IO_TLB_SHIFT);
 	return 0;
 }
 
@@ -359,7 +346,6 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
 
 	swiotlb_print_info();
-	swiotlb_set_max_segment(mem->nslabs << IO_TLB_SHIFT);
 	return 0;
 }
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 03/15] swiotlb: simplify swiotlb_max_segment
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Remove the bogus Xen override that was usually larger than the actual
size and just calculate the value on demand.  Note that
swiotlb_max_segment still doesn't make sense as an interface and should
eventually be removed.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 drivers/xen/swiotlb-xen.c |  2 --
 include/linux/swiotlb.h   |  1 -
 kernel/dma/swiotlb.c      | 20 +++-----------------
 3 files changed, 3 insertions(+), 20 deletions(-)

diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 47aebd98f52f5..485cd06ed39e7 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -202,7 +202,6 @@ int xen_swiotlb_init(void)
 	rc = swiotlb_late_init_with_tbl(start, nslabs);
 	if (rc)
 		return rc;
-	swiotlb_set_max_segment(PAGE_SIZE);
 	return 0;
 error:
 	if (nslabs > 1024 && repeat--) {
@@ -254,7 +253,6 @@ void __init xen_swiotlb_init_early(void)
 
 	if (swiotlb_init_with_tbl(start, nslabs, true))
 		panic("Cannot allocate SWIOTLB buffer");
-	swiotlb_set_max_segment(PAGE_SIZE);
 }
 #endif /* CONFIG_X86 */
 
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index f6c3638255d54..9fb3a568f0c51 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -164,7 +164,6 @@ static inline void swiotlb_adjust_size(unsigned long size)
 #endif /* CONFIG_SWIOTLB */
 
 extern void swiotlb_print_info(void);
-extern void swiotlb_set_max_segment(unsigned int);
 
 #ifdef CONFIG_DMA_RESTRICTED_POOL
 struct page *swiotlb_alloc(struct device *dev, size_t size);
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 98bb0eb44a7bf..e0127e397335e 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -68,12 +68,6 @@ struct io_tlb_mem io_tlb_default_mem;
 
 phys_addr_t swiotlb_unencrypted_base;
 
-/*
- * Max segment that we can provide which (if pages are contingous) will
- * not be bounced (unless SWIOTLB_FORCE is set).
- */
-static unsigned int max_segment;
-
 static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT;
 
 static int __init
@@ -97,18 +91,12 @@ early_param("swiotlb", setup_io_tlb_npages);
 
 unsigned int swiotlb_max_segment(void)
 {
-	return io_tlb_default_mem.nslabs ? max_segment : 0;
+	if (!io_tlb_default_mem.nslabs)
+		return 0;
+	return rounddown(io_tlb_default_mem.nslabs << IO_TLB_SHIFT, PAGE_SIZE);
 }
 EXPORT_SYMBOL_GPL(swiotlb_max_segment);
 
-void swiotlb_set_max_segment(unsigned int val)
-{
-	if (swiotlb_force = SWIOTLB_FORCE)
-		max_segment = 1;
-	else
-		max_segment = rounddown(val, PAGE_SIZE);
-}
-
 unsigned long swiotlb_size_or_default(void)
 {
 	return default_nslabs << IO_TLB_SHIFT;
@@ -258,7 +246,6 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 
 	if (verbose)
 		swiotlb_print_info();
-	swiotlb_set_max_segment(mem->nslabs << IO_TLB_SHIFT);
 	return 0;
 }
 
@@ -359,7 +346,6 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
 
 	swiotlb_print_info();
-	swiotlb_set_max_segment(mem->nslabs << IO_TLB_SHIFT);
 	return 0;
 }
 
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 04/15] swiotlb: rename swiotlb_late_init_with_default_size
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

swiotlb_late_init_with_default_size is an overly verbose name that
doesn't even catch what the function is doing, given that the size is
not just a default but the actual requested size.

Rename it to swiotlb_init_late.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/pci/sta2x11-fixup.c | 2 +-
 include/linux/swiotlb.h      | 2 +-
 kernel/dma/swiotlb.c         | 6 ++----
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index 101081ad64b6d..e0c039a75b2db 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_late_init_with_default_size(size))
+		if (swiotlb_init_late(size))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 9fb3a568f0c51..b48b26bfa0edb 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -40,7 +40,7 @@ extern void swiotlb_init(int verbose);
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-extern int swiotlb_late_init_with_default_size(size_t default_size);
+int swiotlb_init_late(size_t size);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index e0127e397335e..9a4fe6e48a074 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -281,11 +281,9 @@ swiotlb_init(int verbose)
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int
-swiotlb_late_init_with_default_size(size_t default_size)
+int swiotlb_init_late(size_t size)
 {
-	unsigned long nslabs =
-		ALIGN(default_size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
+	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
 	unsigned char *vstart = NULL;
 	unsigned int order;
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 04/15] swiotlb: rename swiotlb_late_init_with_default_size
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

swiotlb_late_init_with_default_size is an overly verbose name that
doesn't even catch what the function is doing, given that the size is
not just a default but the actual requested size.

Rename it to swiotlb_init_late.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/pci/sta2x11-fixup.c | 2 +-
 include/linux/swiotlb.h      | 2 +-
 kernel/dma/swiotlb.c         | 6 ++----
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index 101081ad64b6d..e0c039a75b2db 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_late_init_with_default_size(size))
+		if (swiotlb_init_late(size))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 9fb3a568f0c51..b48b26bfa0edb 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -40,7 +40,7 @@ extern void swiotlb_init(int verbose);
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-extern int swiotlb_late_init_with_default_size(size_t default_size);
+int swiotlb_init_late(size_t size);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index e0127e397335e..9a4fe6e48a074 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -281,11 +281,9 @@ swiotlb_init(int verbose)
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int
-swiotlb_late_init_with_default_size(size_t default_size)
+int swiotlb_init_late(size_t size)
 {
-	unsigned long nslabs =
-		ALIGN(default_size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
+	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
 	unsigned char *vstart = NULL;
 	unsigned int order;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 04/15] swiotlb: rename swiotlb_late_init_with_default_size
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

swiotlb_late_init_with_default_size is an overly verbose name that
doesn't even catch what the function is doing, given that the size is
not just a default but the actual requested size.

Rename it to swiotlb_init_late.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/pci/sta2x11-fixup.c | 2 +-
 include/linux/swiotlb.h      | 2 +-
 kernel/dma/swiotlb.c         | 6 ++----
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index 101081ad64b6d..e0c039a75b2db 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_late_init_with_default_size(size))
+		if (swiotlb_init_late(size))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 9fb3a568f0c51..b48b26bfa0edb 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -40,7 +40,7 @@ extern void swiotlb_init(int verbose);
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-extern int swiotlb_late_init_with_default_size(size_t default_size);
+int swiotlb_init_late(size_t size);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index e0127e397335e..9a4fe6e48a074 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -281,11 +281,9 @@ swiotlb_init(int verbose)
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int
-swiotlb_late_init_with_default_size(size_t default_size)
+int swiotlb_init_late(size_t size)
 {
-	unsigned long nslabs =
-		ALIGN(default_size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
+	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
 	unsigned char *vstart = NULL;
 	unsigned int order;
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 04/15] swiotlb: rename swiotlb_late_init_with_default_size
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

swiotlb_late_init_with_default_size is an overly verbose name that
doesn't even catch what the function is doing, given that the size is
not just a default but the actual requested size.

Rename it to swiotlb_init_late.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/pci/sta2x11-fixup.c | 2 +-
 include/linux/swiotlb.h      | 2 +-
 kernel/dma/swiotlb.c         | 6 ++----
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index 101081ad64b6d..e0c039a75b2db 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_late_init_with_default_size(size))
+		if (swiotlb_init_late(size))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 9fb3a568f0c51..b48b26bfa0edb 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -40,7 +40,7 @@ extern void swiotlb_init(int verbose);
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-extern int swiotlb_late_init_with_default_size(size_t default_size);
+int swiotlb_init_late(size_t size);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index e0127e397335e..9a4fe6e48a074 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -281,11 +281,9 @@ swiotlb_init(int verbose)
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int
-swiotlb_late_init_with_default_size(size_t default_size)
+int swiotlb_init_late(size_t size)
 {
-	unsigned long nslabs =
-		ALIGN(default_size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
+	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
 	unsigned char *vstart = NULL;
 	unsigned int order;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 04/15] swiotlb: rename swiotlb_late_init_with_default_size
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

swiotlb_late_init_with_default_size is an overly verbose name that
doesn't even catch what the function is doing, given that the size is
not just a default but the actual requested size.

Rename it to swiotlb_init_late.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/pci/sta2x11-fixup.c | 2 +-
 include/linux/swiotlb.h      | 2 +-
 kernel/dma/swiotlb.c         | 6 ++----
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index 101081ad64b6d..e0c039a75b2db 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_late_init_with_default_size(size))
+		if (swiotlb_init_late(size))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 9fb3a568f0c51..b48b26bfa0edb 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -40,7 +40,7 @@ extern void swiotlb_init(int verbose);
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-extern int swiotlb_late_init_with_default_size(size_t default_size);
+int swiotlb_init_late(size_t size);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index e0127e397335e..9a4fe6e48a074 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -281,11 +281,9 @@ swiotlb_init(int verbose)
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int
-swiotlb_late_init_with_default_size(size_t default_size)
+int swiotlb_init_late(size_t size)
 {
-	unsigned long nslabs =
-		ALIGN(default_size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
+	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
 	unsigned char *vstart = NULL;
 	unsigned int order;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 04/15] swiotlb: rename swiotlb_late_init_with_default_size
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

swiotlb_late_init_with_default_size is an overly verbose name that
doesn't even catch what the function is doing, given that the size is
not just a default but the actual requested size.

Rename it to swiotlb_init_late.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/pci/sta2x11-fixup.c | 2 +-
 include/linux/swiotlb.h      | 2 +-
 kernel/dma/swiotlb.c         | 6 ++----
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index 101081ad64b6d..e0c039a75b2db 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_late_init_with_default_size(size))
+		if (swiotlb_init_late(size))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 9fb3a568f0c51..b48b26bfa0edb 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -40,7 +40,7 @@ extern void swiotlb_init(int verbose);
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-extern int swiotlb_late_init_with_default_size(size_t default_size);
+int swiotlb_init_late(size_t size);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index e0127e397335e..9a4fe6e48a074 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -281,11 +281,9 @@ swiotlb_init(int verbose)
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int
-swiotlb_late_init_with_default_size(size_t default_size)
+int swiotlb_init_late(size_t size)
 {
-	unsigned long nslabs -		ALIGN(default_size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
+	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
 	unsigned char *vstart = NULL;
 	unsigned int order;
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 05/15] arm/xen: don't check for xen_initial_domain() in xen_create_contiguous_region
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Konrad Rzeszutek Wilk,
	tboot-devel, xen-devel, Stefano Stabellini, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, linuxppc-dev, linux-mips,
	Robin Murphy

From: Stefano Stabellini <sstabellini@kernel.org>

It used to be that Linux enabled swiotlb-xen when running a dom0 on ARM.
Since f5079a9a2a31 "xen/arm: introduce XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped", Linux detects whether to enable or disable
swiotlb-xen based on the new feature flags: XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped.

However, there is still a leftover xen_initial_domain() check in
xen_create_contiguous_region. Remove the check as
xen_create_contiguous_region is only called by swiotlb-xen during
initialization. If xen_create_contiguous_region is called, we know Linux
is running 1:1 mapped so there is no need for additional checks.

Also update the in-code comment.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/xen/mm.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index a7e54a087b802..28c2070602535 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -122,10 +122,7 @@ int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
 				 unsigned int address_bits,
 				 dma_addr_t *dma_handle)
 {
-	if (!xen_initial_domain())
-		return -EINVAL;
-
-	/* we assume that dom0 is mapped 1:1 for now */
+	/* the domain is 1:1 mapped to use swiotlb-xen */
 	*dma_handle = pstart;
 	return 0;
 }
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 05/15] arm/xen: don't check for xen_initial_domain() in xen_create_contiguous_region
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci,
	Stefano Stabellini

From: Stefano Stabellini <sstabellini@kernel.org>

It used to be that Linux enabled swiotlb-xen when running a dom0 on ARM.
Since f5079a9a2a31 "xen/arm: introduce XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped", Linux detects whether to enable or disable
swiotlb-xen based on the new feature flags: XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped.

However, there is still a leftover xen_initial_domain() check in
xen_create_contiguous_region. Remove the check as
xen_create_contiguous_region is only called by swiotlb-xen during
initialization. If xen_create_contiguous_region is called, we know Linux
is running 1:1 mapped so there is no need for additional checks.

Also update the in-code comment.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/xen/mm.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index a7e54a087b802..28c2070602535 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -122,10 +122,7 @@ int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
 				 unsigned int address_bits,
 				 dma_addr_t *dma_handle)
 {
-	if (!xen_initial_domain())
-		return -EINVAL;
-
-	/* we assume that dom0 is mapped 1:1 for now */
+	/* the domain is 1:1 mapped to use swiotlb-xen */
 	*dma_handle = pstart;
 	return 0;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 05/15] arm/xen: don't check for xen_initial_domain() in xen_create_contiguous_region
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci,
	Stefano Stabellini

From: Stefano Stabellini <sstabellini@kernel.org>

It used to be that Linux enabled swiotlb-xen when running a dom0 on ARM.
Since f5079a9a2a31 "xen/arm: introduce XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped", Linux detects whether to enable or disable
swiotlb-xen based on the new feature flags: XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped.

However, there is still a leftover xen_initial_domain() check in
xen_create_contiguous_region. Remove the check as
xen_create_contiguous_region is only called by swiotlb-xen during
initialization. If xen_create_contiguous_region is called, we know Linux
is running 1:1 mapped so there is no need for additional checks.

Also update the in-code comment.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/xen/mm.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index a7e54a087b802..28c2070602535 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -122,10 +122,7 @@ int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
 				 unsigned int address_bits,
 				 dma_addr_t *dma_handle)
 {
-	if (!xen_initial_domain())
-		return -EINVAL;
-
-	/* we assume that dom0 is mapped 1:1 for now */
+	/* the domain is 1:1 mapped to use swiotlb-xen */
 	*dma_handle = pstart;
 	return 0;
 }
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 05/15] arm/xen: don't check for xen_initial_domain() in xen_create_contiguous_region
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci,
	Stefano Stabellini

From: Stefano Stabellini <sstabellini@kernel.org>

It used to be that Linux enabled swiotlb-xen when running a dom0 on ARM.
Since f5079a9a2a31 "xen/arm: introduce XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped", Linux detects whether to enable or disable
swiotlb-xen based on the new feature flags: XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped.

However, there is still a leftover xen_initial_domain() check in
xen_create_contiguous_region. Remove the check as
xen_create_contiguous_region is only called by swiotlb-xen during
initialization. If xen_create_contiguous_region is called, we know Linux
is running 1:1 mapped so there is no need for additional checks.

Also update the in-code comment.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/xen/mm.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index a7e54a087b802..28c2070602535 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -122,10 +122,7 @@ int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
 				 unsigned int address_bits,
 				 dma_addr_t *dma_handle)
 {
-	if (!xen_initial_domain())
-		return -EINVAL;
-
-	/* we assume that dom0 is mapped 1:1 for now */
+	/* the domain is 1:1 mapped to use swiotlb-xen */
 	*dma_handle = pstart;
 	return 0;
 }
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 05/15] arm/xen: don't check for xen_initial_domain() in xen_create_contiguous_region
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Joerg Roedel,
	Konrad Rzeszutek Wilk, tboot-devel, xen-devel,
	Stefano Stabellini, David Woodhouse, Tom Lendacky,
	Anshuman Khandual, Boris Ostrovsky, linux-arm-kernel,
	Juergen Gross, linuxppc-dev, linux-mips, Robin Murphy, Lu Baolu

From: Stefano Stabellini <sstabellini@kernel.org>

It used to be that Linux enabled swiotlb-xen when running a dom0 on ARM.
Since f5079a9a2a31 "xen/arm: introduce XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped", Linux detects whether to enable or disable
swiotlb-xen based on the new feature flags: XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped.

However, there is still a leftover xen_initial_domain() check in
xen_create_contiguous_region. Remove the check as
xen_create_contiguous_region is only called by swiotlb-xen during
initialization. If xen_create_contiguous_region is called, we know Linux
is running 1:1 mapped so there is no need for additional checks.

Also update the in-code comment.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/xen/mm.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index a7e54a087b802..28c2070602535 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -122,10 +122,7 @@ int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
 				 unsigned int address_bits,
 				 dma_addr_t *dma_handle)
 {
-	if (!xen_initial_domain())
-		return -EINVAL;
-
-	/* we assume that dom0 is mapped 1:1 for now */
+	/* the domain is 1:1 mapped to use swiotlb-xen */
 	*dma_handle = pstart;
 	return 0;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 05/15] arm/xen: don't check for xen_initial_domain() in xen_create_contiguous_region
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Konrad Rzeszutek Wilk,
	tboot-devel, xen-devel, Stefano Stabellini, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, linuxppc-dev, linux-mips,
	Robin Murphy

From: Stefano Stabellini <sstabellini@kernel.org>

It used to be that Linux enabled swiotlb-xen when running a dom0 on ARM.
Since f5079a9a2a31 "xen/arm: introduce XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped", Linux detects whether to enable or disable
swiotlb-xen based on the new feature flags: XENFEAT_direct_mapped and
XENFEAT_not_direct_mapped.

However, there is still a leftover xen_initial_domain() check in
xen_create_contiguous_region. Remove the check as
xen_create_contiguous_region is only called by swiotlb-xen during
initialization. If xen_create_contiguous_region is called, we know Linux
is running 1:1 mapped so there is no need for additional checks.

Also update the in-code comment.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/xen/mm.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index a7e54a087b802..28c2070602535 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -122,10 +122,7 @@ int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
 				 unsigned int address_bits,
 				 dma_addr_t *dma_handle)
 {
-	if (!xen_initial_domain())
-		return -EINVAL;
-
-	/* we assume that dom0 is mapped 1:1 for now */
+	/* the domain is 1:1 mapped to use swiotlb-xen */
 	*dma_handle = pstart;
 	return 0;
 }
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 06/15] MIPS/octeon: use swiotlb_init instead of open coding it
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Konrad Rzeszutek Wilk,
	tboot-devel, xen-devel, David Woodhouse, Tom Lendacky,
	Anshuman Khandual, Boris Ostrovsky, linux-arm-kernel,
	Juergen Gross, Thomas Bogendoerfer, linuxppc-dev, linux-mips,
	Robin Murphy

Use the generic swiotlb initialization helper instead of open coding it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
---
 arch/mips/cavium-octeon/dma-octeon.c | 15 ++-------------
 arch/mips/pci/pci-octeon.c           |  2 +-
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index df70308db0e69..fb7547e217263 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -186,15 +186,12 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 	return daddr;
 }
 
-char *octeon_swiotlb;
-
 void __init plat_swiotlb_setup(void)
 {
 	phys_addr_t start, end;
 	phys_addr_t max_addr;
 	phys_addr_t addr_size;
 	size_t swiotlbsize;
-	unsigned long swiotlb_nslabs;
 	u64 i;
 
 	max_addr = 0;
@@ -236,15 +233,7 @@ void __init plat_swiotlb_setup(void)
 	if (OCTEON_IS_OCTEON2() && max_addr >= 0x100000000ul)
 		swiotlbsize = 64 * (1<<20);
 #endif
-	swiotlb_nslabs = swiotlbsize >> IO_TLB_SHIFT;
-	swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
-	swiotlbsize = swiotlb_nslabs << IO_TLB_SHIFT;
-
-	octeon_swiotlb = memblock_alloc_low(swiotlbsize, PAGE_SIZE);
-	if (!octeon_swiotlb)
-		panic("%s: Failed to allocate %zu bytes align=%lx\n",
-		      __func__, swiotlbsize, PAGE_SIZE);
 
-	if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlb_nslabs, 1) == -ENOMEM)
-		panic("Cannot allocate SWIOTLB buffer");
+	swiotlb_adjust_size(swiotlbsize);
+	swiotlb_init(1);
 }
diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
index fc29b85cfa926..e457a18cbdc59 100644
--- a/arch/mips/pci/pci-octeon.c
+++ b/arch/mips/pci/pci-octeon.c
@@ -664,7 +664,7 @@ static int __init octeon_pci_setup(void)
 
 		/* BAR1 movable regions contiguous to cover the swiotlb */
 		octeon_bar1_pci_phys =
-			virt_to_phys(octeon_swiotlb) & ~((1ull << 22) - 1);
+			io_tlb_default_mem.start & ~((1ull << 22) - 1);
 
 		for (index = 0; index < 32; index++) {
 			union cvmx_pci_bar1_indexx bar1_index;
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 06/15] MIPS/octeon: use swiotlb_init instead of open coding it
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci,
	Thomas Bogendoerfer

Use the generic swiotlb initialization helper instead of open coding it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
---
 arch/mips/cavium-octeon/dma-octeon.c | 15 ++-------------
 arch/mips/pci/pci-octeon.c           |  2 +-
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index df70308db0e69..fb7547e217263 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -186,15 +186,12 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 	return daddr;
 }
 
-char *octeon_swiotlb;
-
 void __init plat_swiotlb_setup(void)
 {
 	phys_addr_t start, end;
 	phys_addr_t max_addr;
 	phys_addr_t addr_size;
 	size_t swiotlbsize;
-	unsigned long swiotlb_nslabs;
 	u64 i;
 
 	max_addr = 0;
@@ -236,15 +233,7 @@ void __init plat_swiotlb_setup(void)
 	if (OCTEON_IS_OCTEON2() && max_addr >= 0x100000000ul)
 		swiotlbsize = 64 * (1<<20);
 #endif
-	swiotlb_nslabs = swiotlbsize >> IO_TLB_SHIFT;
-	swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
-	swiotlbsize = swiotlb_nslabs << IO_TLB_SHIFT;
-
-	octeon_swiotlb = memblock_alloc_low(swiotlbsize, PAGE_SIZE);
-	if (!octeon_swiotlb)
-		panic("%s: Failed to allocate %zu bytes align=%lx\n",
-		      __func__, swiotlbsize, PAGE_SIZE);
 
-	if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlb_nslabs, 1) == -ENOMEM)
-		panic("Cannot allocate SWIOTLB buffer");
+	swiotlb_adjust_size(swiotlbsize);
+	swiotlb_init(1);
 }
diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
index fc29b85cfa926..e457a18cbdc59 100644
--- a/arch/mips/pci/pci-octeon.c
+++ b/arch/mips/pci/pci-octeon.c
@@ -664,7 +664,7 @@ static int __init octeon_pci_setup(void)
 
 		/* BAR1 movable regions contiguous to cover the swiotlb */
 		octeon_bar1_pci_phys =
-			virt_to_phys(octeon_swiotlb) & ~((1ull << 22) - 1);
+			io_tlb_default_mem.start & ~((1ull << 22) - 1);
 
 		for (index = 0; index < 32; index++) {
 			union cvmx_pci_bar1_indexx bar1_index;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 06/15] MIPS/octeon: use swiotlb_init instead of open coding it
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci,
	Thomas Bogendoerfer

Use the generic swiotlb initialization helper instead of open coding it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
---
 arch/mips/cavium-octeon/dma-octeon.c | 15 ++-------------
 arch/mips/pci/pci-octeon.c           |  2 +-
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index df70308db0e69..fb7547e217263 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -186,15 +186,12 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 	return daddr;
 }
 
-char *octeon_swiotlb;
-
 void __init plat_swiotlb_setup(void)
 {
 	phys_addr_t start, end;
 	phys_addr_t max_addr;
 	phys_addr_t addr_size;
 	size_t swiotlbsize;
-	unsigned long swiotlb_nslabs;
 	u64 i;
 
 	max_addr = 0;
@@ -236,15 +233,7 @@ void __init plat_swiotlb_setup(void)
 	if (OCTEON_IS_OCTEON2() && max_addr >= 0x100000000ul)
 		swiotlbsize = 64 * (1<<20);
 #endif
-	swiotlb_nslabs = swiotlbsize >> IO_TLB_SHIFT;
-	swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
-	swiotlbsize = swiotlb_nslabs << IO_TLB_SHIFT;
-
-	octeon_swiotlb = memblock_alloc_low(swiotlbsize, PAGE_SIZE);
-	if (!octeon_swiotlb)
-		panic("%s: Failed to allocate %zu bytes align=%lx\n",
-		      __func__, swiotlbsize, PAGE_SIZE);
 
-	if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlb_nslabs, 1) == -ENOMEM)
-		panic("Cannot allocate SWIOTLB buffer");
+	swiotlb_adjust_size(swiotlbsize);
+	swiotlb_init(1);
 }
diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
index fc29b85cfa926..e457a18cbdc59 100644
--- a/arch/mips/pci/pci-octeon.c
+++ b/arch/mips/pci/pci-octeon.c
@@ -664,7 +664,7 @@ static int __init octeon_pci_setup(void)
 
 		/* BAR1 movable regions contiguous to cover the swiotlb */
 		octeon_bar1_pci_phys =
-			virt_to_phys(octeon_swiotlb) & ~((1ull << 22) - 1);
+			io_tlb_default_mem.start & ~((1ull << 22) - 1);
 
 		for (index = 0; index < 32; index++) {
 			union cvmx_pci_bar1_indexx bar1_index;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 06/15] MIPS/octeon: use swiotlb_init instead of open coding it
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci,
	Thomas Bogendoerfer

Use the generic swiotlb initialization helper instead of open coding it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
---
 arch/mips/cavium-octeon/dma-octeon.c | 15 ++-------------
 arch/mips/pci/pci-octeon.c           |  2 +-
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index df70308db0e69..fb7547e217263 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -186,15 +186,12 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 	return daddr;
 }
 
-char *octeon_swiotlb;
-
 void __init plat_swiotlb_setup(void)
 {
 	phys_addr_t start, end;
 	phys_addr_t max_addr;
 	phys_addr_t addr_size;
 	size_t swiotlbsize;
-	unsigned long swiotlb_nslabs;
 	u64 i;
 
 	max_addr = 0;
@@ -236,15 +233,7 @@ void __init plat_swiotlb_setup(void)
 	if (OCTEON_IS_OCTEON2() && max_addr >= 0x100000000ul)
 		swiotlbsize = 64 * (1<<20);
 #endif
-	swiotlb_nslabs = swiotlbsize >> IO_TLB_SHIFT;
-	swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
-	swiotlbsize = swiotlb_nslabs << IO_TLB_SHIFT;
-
-	octeon_swiotlb = memblock_alloc_low(swiotlbsize, PAGE_SIZE);
-	if (!octeon_swiotlb)
-		panic("%s: Failed to allocate %zu bytes align=%lx\n",
-		      __func__, swiotlbsize, PAGE_SIZE);
 
-	if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlb_nslabs, 1) == -ENOMEM)
-		panic("Cannot allocate SWIOTLB buffer");
+	swiotlb_adjust_size(swiotlbsize);
+	swiotlb_init(1);
 }
diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
index fc29b85cfa926..e457a18cbdc59 100644
--- a/arch/mips/pci/pci-octeon.c
+++ b/arch/mips/pci/pci-octeon.c
@@ -664,7 +664,7 @@ static int __init octeon_pci_setup(void)
 
 		/* BAR1 movable regions contiguous to cover the swiotlb */
 		octeon_bar1_pci_phys =
-			virt_to_phys(octeon_swiotlb) & ~((1ull << 22) - 1);
+			io_tlb_default_mem.start & ~((1ull << 22) - 1);
 
 		for (index = 0; index < 32; index++) {
 			union cvmx_pci_bar1_indexx bar1_index;
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 06/15] MIPS/octeon: use swiotlb_init instead of open coding it
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Joerg Roedel,
	Konrad Rzeszutek Wilk, tboot-devel, xen-devel, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, Thomas Bogendoerfer,
	linuxppc-dev, linux-mips, Robin Murphy, Lu Baolu

Use the generic swiotlb initialization helper instead of open coding it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
---
 arch/mips/cavium-octeon/dma-octeon.c | 15 ++-------------
 arch/mips/pci/pci-octeon.c           |  2 +-
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index df70308db0e69..fb7547e217263 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -186,15 +186,12 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 	return daddr;
 }
 
-char *octeon_swiotlb;
-
 void __init plat_swiotlb_setup(void)
 {
 	phys_addr_t start, end;
 	phys_addr_t max_addr;
 	phys_addr_t addr_size;
 	size_t swiotlbsize;
-	unsigned long swiotlb_nslabs;
 	u64 i;
 
 	max_addr = 0;
@@ -236,15 +233,7 @@ void __init plat_swiotlb_setup(void)
 	if (OCTEON_IS_OCTEON2() && max_addr >= 0x100000000ul)
 		swiotlbsize = 64 * (1<<20);
 #endif
-	swiotlb_nslabs = swiotlbsize >> IO_TLB_SHIFT;
-	swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
-	swiotlbsize = swiotlb_nslabs << IO_TLB_SHIFT;
-
-	octeon_swiotlb = memblock_alloc_low(swiotlbsize, PAGE_SIZE);
-	if (!octeon_swiotlb)
-		panic("%s: Failed to allocate %zu bytes align=%lx\n",
-		      __func__, swiotlbsize, PAGE_SIZE);
 
-	if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlb_nslabs, 1) == -ENOMEM)
-		panic("Cannot allocate SWIOTLB buffer");
+	swiotlb_adjust_size(swiotlbsize);
+	swiotlb_init(1);
 }
diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
index fc29b85cfa926..e457a18cbdc59 100644
--- a/arch/mips/pci/pci-octeon.c
+++ b/arch/mips/pci/pci-octeon.c
@@ -664,7 +664,7 @@ static int __init octeon_pci_setup(void)
 
 		/* BAR1 movable regions contiguous to cover the swiotlb */
 		octeon_bar1_pci_phys =
-			virt_to_phys(octeon_swiotlb) & ~((1ull << 22) - 1);
+			io_tlb_default_mem.start & ~((1ull << 22) - 1);
 
 		for (index = 0; index < 32; index++) {
 			union cvmx_pci_bar1_indexx bar1_index;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 06/15] MIPS/octeon: use swiotlb_init instead of open coding it
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Konrad Rzeszutek Wilk,
	tboot-devel, xen-devel, David Woodhouse, Tom Lendacky,
	Anshuman Khandual, Boris Ostrovsky, linux-arm-kernel,
	Juergen Gross, Thomas Bogendoerfer, linuxppc-dev, linux-mips,
	Robin Murphy

Use the generic swiotlb initialization helper instead of open coding it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
---
 arch/mips/cavium-octeon/dma-octeon.c | 15 ++-------------
 arch/mips/pci/pci-octeon.c           |  2 +-
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index df70308db0e69..fb7547e217263 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -186,15 +186,12 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 	return daddr;
 }
 
-char *octeon_swiotlb;
-
 void __init plat_swiotlb_setup(void)
 {
 	phys_addr_t start, end;
 	phys_addr_t max_addr;
 	phys_addr_t addr_size;
 	size_t swiotlbsize;
-	unsigned long swiotlb_nslabs;
 	u64 i;
 
 	max_addr = 0;
@@ -236,15 +233,7 @@ void __init plat_swiotlb_setup(void)
 	if (OCTEON_IS_OCTEON2() && max_addr >= 0x100000000ul)
 		swiotlbsize = 64 * (1<<20);
 #endif
-	swiotlb_nslabs = swiotlbsize >> IO_TLB_SHIFT;
-	swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
-	swiotlbsize = swiotlb_nslabs << IO_TLB_SHIFT;
-
-	octeon_swiotlb = memblock_alloc_low(swiotlbsize, PAGE_SIZE);
-	if (!octeon_swiotlb)
-		panic("%s: Failed to allocate %zu bytes align=%lx\n",
-		      __func__, swiotlbsize, PAGE_SIZE);
 
-	if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlb_nslabs, 1) = -ENOMEM)
-		panic("Cannot allocate SWIOTLB buffer");
+	swiotlb_adjust_size(swiotlbsize);
+	swiotlb_init(1);
 }
diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
index fc29b85cfa926..e457a18cbdc59 100644
--- a/arch/mips/pci/pci-octeon.c
+++ b/arch/mips/pci/pci-octeon.c
@@ -664,7 +664,7 @@ static int __init octeon_pci_setup(void)
 
 		/* BAR1 movable regions contiguous to cover the swiotlb */
 		octeon_bar1_pci_phys -			virt_to_phys(octeon_swiotlb) & ~((1ull << 22) - 1);
+			io_tlb_default_mem.start & ~((1ull << 22) - 1);
 
 		for (index = 0; index < 32; index++) {
 			union cvmx_pci_bar1_indexx bar1_index;
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 07/15] x86: remove the IOMMU table infrastructure
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

The IOMMU table tries to separate the different IOMMUs into different
backends, but actually requires various cross calls.

Rewrite the code to do the generic swiotlb/swiotlb-xen setup directly
in pci-dma.c and then just call into the IOMMU drivers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/ia64/include/asm/iommu_table.h    |   7 --
 arch/x86/include/asm/dma-mapping.h     |   1 -
 arch/x86/include/asm/gart.h            |   5 +-
 arch/x86/include/asm/iommu.h           |   6 ++
 arch/x86/include/asm/iommu_table.h     | 102 -----------------------
 arch/x86/include/asm/swiotlb.h         |  30 -------
 arch/x86/include/asm/xen/swiotlb-xen.h |   2 -
 arch/x86/kernel/Makefile               |   2 -
 arch/x86/kernel/amd_gart_64.c          |   5 +-
 arch/x86/kernel/aperture_64.c          |  14 ++--
 arch/x86/kernel/pci-dma.c              | 107 ++++++++++++++++++++-----
 arch/x86/kernel/pci-iommu_table.c      |  77 ------------------
 arch/x86/kernel/pci-swiotlb.c          |  77 ------------------
 arch/x86/kernel/tboot.c                |   1 -
 arch/x86/kernel/vmlinux.lds.S          |  12 ---
 arch/x86/xen/Makefile                  |   2 -
 arch/x86/xen/pci-swiotlb-xen.c         |  96 ----------------------
 drivers/iommu/amd/init.c               |   6 --
 drivers/iommu/amd/iommu.c              |   5 +-
 drivers/iommu/intel/dmar.c             |   6 +-
 include/linux/dmar.h                   |   6 +-
 21 files changed, 110 insertions(+), 459 deletions(-)
 delete mode 100644 arch/ia64/include/asm/iommu_table.h
 delete mode 100644 arch/x86/include/asm/iommu_table.h
 delete mode 100644 arch/x86/include/asm/swiotlb.h
 delete mode 100644 arch/x86/kernel/pci-iommu_table.c
 delete mode 100644 arch/x86/kernel/pci-swiotlb.c
 delete mode 100644 arch/x86/xen/pci-swiotlb-xen.c

diff --git a/arch/ia64/include/asm/iommu_table.h b/arch/ia64/include/asm/iommu_table.h
deleted file mode 100644
index cc96116ac276a..0000000000000
--- a/arch/ia64/include/asm/iommu_table.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_IA64_IOMMU_TABLE_H
-#define _ASM_IA64_IOMMU_TABLE_H
-
-#define IOMMU_INIT_POST(_detect)
-
-#endif /* _ASM_IA64_IOMMU_TABLE_H */
diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index bb1654fe0ce74..256fd8115223d 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -9,7 +9,6 @@
 
 #include <linux/scatterlist.h>
 #include <asm/io.h>
-#include <asm/swiotlb.h>
 
 extern int iommu_merge;
 extern int panic_on_overflow;
diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
index 3185565743459..5af8088a10df6 100644
--- a/arch/x86/include/asm/gart.h
+++ b/arch/x86/include/asm/gart.h
@@ -38,7 +38,7 @@ extern int gart_iommu_aperture_disabled;
 extern void early_gart_iommu_check(void);
 extern int gart_iommu_init(void);
 extern void __init gart_parse_options(char *);
-extern int gart_iommu_hole_init(void);
+void gart_iommu_hole_init(void);
 
 #else
 #define gart_iommu_aperture            0
@@ -51,9 +51,8 @@ static inline void early_gart_iommu_check(void)
 static inline void gart_parse_options(char *options)
 {
 }
-static inline int gart_iommu_hole_init(void)
+static inline void gart_iommu_hole_init(void)
 {
-	return -ENODEV;
 }
 #endif
 
diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
index bf1ed2ddc74bd..dba89ed40d38d 100644
--- a/arch/x86/include/asm/iommu.h
+++ b/arch/x86/include/asm/iommu.h
@@ -9,6 +9,12 @@
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
 
+#ifdef CONFIG_SWIOTLB
+extern bool x86_swiotlb_enable;
+#else
+#define x86_swiotlb_enable false
+#endif
+
 /* 10 seconds */
 #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
 
diff --git a/arch/x86/include/asm/iommu_table.h b/arch/x86/include/asm/iommu_table.h
deleted file mode 100644
index 1fb3fd1a83c25..0000000000000
--- a/arch/x86/include/asm/iommu_table.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_X86_IOMMU_TABLE_H
-#define _ASM_X86_IOMMU_TABLE_H
-
-#include <asm/swiotlb.h>
-
-/*
- * History lesson:
- * The execution chain of IOMMUs in 2.6.36 looks as so:
- *
- *            [xen-swiotlb]
- *                 |
- *         +----[swiotlb *]--+
- *        /         |         \
- *       /          |          \
- *    [GART]     [Calgary]  [Intel VT-d]
- *     /
- *    /
- * [AMD-Vi]
- *
- * *: if SWIOTLB detected 'iommu=soft'/'swiotlb=force' it would skip
- * over the rest of IOMMUs and unconditionally initialize the SWIOTLB.
- * Also it would surreptitiously initialize set the swiotlb=1 if there were
- * more than 4GB and if the user did not pass in 'iommu=off'. The swiotlb
- * flag would be turned off by all IOMMUs except the Calgary one.
- *
- * The IOMMU_INIT* macros allow a similar tree (or more complex if desired)
- * to be built by defining who we depend on.
- *
- * And all that needs to be done is to use one of the macros in the IOMMU
- * and the pci-dma.c will take care of the rest.
- */
-
-struct iommu_table_entry {
-	initcall_t	detect;
-	initcall_t	depend;
-	void		(*early_init)(void); /* No memory allocate available. */
-	void		(*late_init)(void); /* Yes, can allocate memory. */
-#define IOMMU_FINISH_IF_DETECTED (1<<0)
-#define IOMMU_DETECTED		 (1<<1)
-	int		flags;
-};
-/*
- * Macro fills out an entry in the .iommu_table that is equivalent
- * to the fields that 'struct iommu_table_entry' has. The entries
- * that are put in the .iommu_table section are not put in any order
- * hence during boot-time we will have to resort them based on
- * dependency. */
-
-
-#define __IOMMU_INIT(_detect, _depend, _early_init, _late_init, _finish)\
-	static const struct iommu_table_entry				\
-		__iommu_entry_##_detect __used				\
-	__attribute__ ((unused, __section__(".iommu_table"),		\
-			aligned((sizeof(void *)))))	\
-	= {_detect, _depend, _early_init, _late_init,			\
-	   _finish ? IOMMU_FINISH_IF_DETECTED : 0}
-/*
- * The simplest IOMMU definition. Provide the detection routine
- * and it will be run after the SWIOTLB and the other IOMMUs
- * that utilize this macro. If the IOMMU is detected (ie, the
- * detect routine returns a positive value), the other IOMMUs
- * are also checked. You can use IOMMU_INIT_POST_FINISH if you prefer
- * to stop detecting the other IOMMUs after yours has been detected.
- */
-#define IOMMU_INIT_POST(_detect)					\
-	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 0)
-
-#define IOMMU_INIT_POST_FINISH(detect)					\
-	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 1)
-
-/*
- * A more sophisticated version of IOMMU_INIT. This variant requires:
- *  a). A detection routine function.
- *  b). The name of the detection routine we depend on to get called
- *      before us.
- *  c). The init routine which gets called if the detection routine
- *      returns a positive value from the pci_iommu_alloc. This means
- *      no presence of a memory allocator.
- *  d). Similar to the 'init', except that this gets called from pci_iommu_init
- *      where we do have a memory allocator.
- *
- * The standard IOMMU_INIT differs from the IOMMU_INIT_FINISH variant
- * in that the former will continue detecting other IOMMUs in the call
- * list after the detection routine returns a positive number, while the
- * latter will stop the execution chain upon first successful detection.
- * Both variants will still call the 'init' and 'late_init' functions if
- * they are set.
- */
-#define IOMMU_INIT_FINISH(_detect, _depend, _init, _late_init)		\
-	__IOMMU_INIT(_detect, _depend, _init, _late_init, 1)
-
-#define IOMMU_INIT(_detect, _depend, _init, _late_init)			\
-	__IOMMU_INIT(_detect, _depend, _init, _late_init, 0)
-
-void sort_iommu_table(struct iommu_table_entry *start,
-		      struct iommu_table_entry *finish);
-
-void check_iommu_entries(struct iommu_table_entry *start,
-			 struct iommu_table_entry *finish);
-
-#endif /* _ASM_X86_IOMMU_TABLE_H */
diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
deleted file mode 100644
index ff6c92eff035a..0000000000000
--- a/arch/x86/include/asm/swiotlb.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_X86_SWIOTLB_H
-#define _ASM_X86_SWIOTLB_H
-
-#include <linux/swiotlb.h>
-
-#ifdef CONFIG_SWIOTLB
-extern int swiotlb;
-extern int __init pci_swiotlb_detect_override(void);
-extern int __init pci_swiotlb_detect_4gb(void);
-extern void __init pci_swiotlb_init(void);
-extern void __init pci_swiotlb_late_init(void);
-#else
-#define swiotlb 0
-static inline int pci_swiotlb_detect_override(void)
-{
-	return 0;
-}
-static inline int pci_swiotlb_detect_4gb(void)
-{
-	return 0;
-}
-static inline void pci_swiotlb_init(void)
-{
-}
-static inline void pci_swiotlb_late_init(void)
-{
-}
-#endif
-#endif /* _ASM_X86_SWIOTLB_H */
diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h
index 66b4ddde77430..e5a90b42e4dde 100644
--- a/arch/x86/include/asm/xen/swiotlb-xen.h
+++ b/arch/x86/include/asm/xen/swiotlb-xen.h
@@ -3,10 +3,8 @@
 #define _ASM_X86_SWIOTLB_XEN_H
 
 #ifdef CONFIG_SWIOTLB_XEN
-extern int __init pci_xen_swiotlb_detect(void);
 extern int pci_xen_swiotlb_init_late(void);
 #else
-#define pci_xen_swiotlb_detect NULL
 static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
 #endif
 
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index c41ef42adbe8a..e17b7e92a3fa3 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -68,7 +68,6 @@ obj-y			+= bootflag.o e820.o
 obj-y			+= pci-dma.o quirks.o topology.o kdebugfs.o
 obj-y			+= alternative.o i8253.o hw_breakpoint.o
 obj-y			+= tsc.o tsc_msr.o io_delay.o rtc.o
-obj-y			+= pci-iommu_table.o
 obj-y			+= resource.o
 obj-y			+= irqflags.o
 obj-y			+= static_call.o
@@ -134,7 +133,6 @@ obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
 
 obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
 
-obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
 obj-$(CONFIG_OF)			+= devicetree.o
 obj-$(CONFIG_UPROBES)			+= uprobes.o
 
diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
index ed837383de5c8..194d54eed5376 100644
--- a/arch/x86/kernel/amd_gart_64.c
+++ b/arch/x86/kernel/amd_gart_64.c
@@ -38,11 +38,9 @@
 #include <asm/iommu.h>
 #include <asm/gart.h>
 #include <asm/set_memory.h>
-#include <asm/swiotlb.h>
 #include <asm/dma.h>
 #include <asm/amd_nb.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
 
 static unsigned long iommu_bus_base;	/* GART remapping area (physical) */
 static unsigned long iommu_size;	/* size of remapping area bytes */
@@ -808,7 +806,7 @@ int __init gart_iommu_init(void)
 	flush_gart();
 	dma_ops = &gart_dma_ops;
 	x86_platform.iommu_shutdown = gart_iommu_shutdown;
-	swiotlb = 0;
+	x86_swiotlb_enable = false;
 
 	return 0;
 }
@@ -842,4 +840,3 @@ void __init gart_parse_options(char *p)
 		}
 	}
 }
-IOMMU_INIT_POST(gart_iommu_hole_init);
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index af3ba08b684b5..7a5630d904b23 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -392,7 +392,7 @@ void __init early_gart_iommu_check(void)
 
 static int __initdata printed_gart_size_msg;
 
-int __init gart_iommu_hole_init(void)
+void __init gart_iommu_hole_init(void)
 {
 	u32 agp_aper_base = 0, agp_aper_order = 0;
 	u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0;
@@ -401,11 +401,11 @@ int __init gart_iommu_hole_init(void)
 	int i, node;
 
 	if (!amd_gart_present())
-		return -ENODEV;
+		return;
 
 	if (gart_iommu_aperture_disabled || !fix_aperture ||
 	    !early_pci_allowed())
-		return -ENODEV;
+		return;
 
 	pr_info("Checking aperture...\n");
 
@@ -491,10 +491,8 @@ int __init gart_iommu_hole_init(void)
 			 * and fixed up the northbridge
 			 */
 			exclude_from_core(last_aper_base, last_aper_order);
-
-			return 1;
 		}
-		return 0;
+		return;
 	}
 
 	if (!fallback_aper_force) {
@@ -527,7 +525,7 @@ int __init gart_iommu_hole_init(void)
 			panic("Not enough memory for aperture");
 		}
 	} else {
-		return 0;
+		return;
 	}
 
 	/*
@@ -561,6 +559,4 @@ int __init gart_iommu_hole_init(void)
 	}
 
 	set_up_gart_resume(aper_order, aper_alloc);
-
-	return 1;
 }
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index de234e7a8962e..df96926421be0 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -7,13 +7,16 @@
 #include <linux/memblock.h>
 #include <linux/gfp.h>
 #include <linux/pci.h>
+#include <linux/amd-iommu.h>
 
 #include <asm/proto.h>
 #include <asm/dma.h>
 #include <asm/iommu.h>
 #include <asm/gart.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
+
+#include <xen/xen.h>
+#include <xen/swiotlb-xen.h>
 
 static bool disable_dac_quirk __read_mostly;
 
@@ -34,24 +37,83 @@ int no_iommu __read_mostly;
 /* Set this to 1 if there is a HW IOMMU in the system */
 int iommu_detected __read_mostly = 0;
 
-extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
+#ifdef CONFIG_SWIOTLB
+bool x86_swiotlb_enable;
+
+static void __init pci_swiotlb_detect(void)
+{
+	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
+	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
+		x86_swiotlb_enable = true;
+
+	/*
+	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
+	 * devices that can't support DMA to encrypted memory.
+	 */
+	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
+		x86_swiotlb_enable = true;
+
+	if (swiotlb_force == SWIOTLB_FORCE)
+		x86_swiotlb_enable = true;
+}
+#else
+static inline void __init pci_swiotlb_detect(void)
+{
+}
+#endif /* CONFIG_SWIOTLB */
+
+#ifdef CONFIG_SWIOTLB_XEN
+static bool xen_swiotlb;
+
+static void __init pci_xen_swiotlb_init(void)
+{
+	if (!xen_initial_domain() && !x86_swiotlb_enable &&
+	    swiotlb_force != SWIOTLB_FORCE)
+		return;
+	x86_swiotlb_enable = true;
+	xen_swiotlb = true;
+	xen_swiotlb_init_early();
+	dma_ops = &xen_swiotlb_dma_ops;
+	if (IS_ENABLED(CONFIG_PCI))
+		pci_request_acs();
+}
+
+int pci_xen_swiotlb_init_late(void)
+{
+	int rc;
+
+	if (xen_swiotlb)
+		return 0;
+
+	rc = xen_swiotlb_init();
+	if (rc)
+		return rc;
+
+	/* XXX: this switches the dma ops under live devices! */
+	dma_ops = &xen_swiotlb_dma_ops;
+	if (IS_ENABLED(CONFIG_PCI))
+		pci_request_acs();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
+#else
+static inline void __init pci_xen_swiotlb_init(void)
+{
+}
+#endif /* CONFIG_SWIOTLB_XEN */
 
 void __init pci_iommu_alloc(void)
 {
-	struct iommu_table_entry *p;
-
-	sort_iommu_table(__iommu_table, __iommu_table_end);
-	check_iommu_entries(__iommu_table, __iommu_table_end);
-
-	for (p = __iommu_table; p < __iommu_table_end; p++) {
-		if (p && p->detect && p->detect() > 0) {
-			p->flags |= IOMMU_DETECTED;
-			if (p->early_init)
-				p->early_init();
-			if (p->flags & IOMMU_FINISH_IF_DETECTED)
-				break;
-		}
+	if (xen_pv_domain()) {
+		pci_xen_swiotlb_init();
+		return;
 	}
+	pci_swiotlb_detect();
+	gart_iommu_hole_init();
+	amd_iommu_detect();
+	detect_intel_iommu();
+	if (x86_swiotlb_enable)
+		swiotlb_init(0);
 }
 
 /*
@@ -102,7 +164,7 @@ static __init int iommu_setup(char *p)
 		}
 #ifdef CONFIG_SWIOTLB
 		if (!strncmp(p, "soft", 4))
-			swiotlb = 1;
+			x86_swiotlb_enable = true;
 #endif
 		if (!strncmp(p, "pt", 2))
 			iommu_set_default_passthrough(true);
@@ -121,14 +183,17 @@ early_param("iommu", iommu_setup);
 
 static int __init pci_iommu_init(void)
 {
-	struct iommu_table_entry *p;
-
 	x86_init.iommu.iommu_init();
 
-	for (p = __iommu_table; p < __iommu_table_end; p++) {
-		if (p && (p->flags & IOMMU_DETECTED) && p->late_init)
-			p->late_init();
+#ifdef CONFIG_SWIOTLB
+	/* An IOMMU turned us off. */
+	if (x86_swiotlb_enable) {
+		pr_info("PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
+		swiotlb_print_info();
+	} else {
+		swiotlb_exit();
 	}
+#endif
 
 	return 0;
 }
diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
deleted file mode 100644
index 42e92ec62973b..0000000000000
--- a/arch/x86/kernel/pci-iommu_table.c
+++ /dev/null
@@ -1,77 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/dma-mapping.h>
-#include <asm/iommu_table.h>
-#include <linux/string.h>
-#include <linux/kallsyms.h>
-
-static struct iommu_table_entry * __init
-find_dependents_of(struct iommu_table_entry *start,
-		   struct iommu_table_entry *finish,
-		   struct iommu_table_entry *q)
-{
-	struct iommu_table_entry *p;
-
-	if (!q)
-		return NULL;
-
-	for (p = start; p < finish; p++)
-		if (p->detect == q->depend)
-			return p;
-
-	return NULL;
-}
-
-
-void __init sort_iommu_table(struct iommu_table_entry *start,
-			     struct iommu_table_entry *finish) {
-
-	struct iommu_table_entry *p, *q, tmp;
-
-	for (p = start; p < finish; p++) {
-again:
-		q = find_dependents_of(start, finish, p);
-		/* We are bit sneaky here. We use the memory address to figure
-		 * out if the node we depend on is past our point, if so, swap.
-		 */
-		if (q > p) {
-			tmp = *p;
-			memmove(p, q, sizeof(*p));
-			*q = tmp;
-			goto again;
-		}
-	}
-
-}
-
-#ifdef DEBUG
-void __init check_iommu_entries(struct iommu_table_entry *start,
-				struct iommu_table_entry *finish)
-{
-	struct iommu_table_entry *p, *q, *x;
-
-	/* Simple cyclic dependency checker. */
-	for (p = start; p < finish; p++) {
-		q = find_dependents_of(start, finish, p);
-		x = find_dependents_of(start, finish, q);
-		if (p == x) {
-			printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %pS depends on %pS and vice-versa. BREAKING IT.\n",
-			       p->detect, q->detect);
-			/* Heavy handed way..*/
-			x->depend = NULL;
-		}
-	}
-
-	for (p = start; p < finish; p++) {
-		q = find_dependents_of(p, finish, p);
-		if (q && q > p) {
-			printk(KERN_ERR "EXECUTION ORDER INVALID! %pS should be called before %pS!\n",
-			       p->detect, q->detect);
-		}
-	}
-}
-#else
-void __init check_iommu_entries(struct iommu_table_entry *start,
-				       struct iommu_table_entry *finish)
-{
-}
-#endif
diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
deleted file mode 100644
index 814ab46a0dada..0000000000000
--- a/arch/x86/kernel/pci-swiotlb.c
+++ /dev/null
@@ -1,77 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/pci.h>
-#include <linux/cache.h>
-#include <linux/init.h>
-#include <linux/swiotlb.h>
-#include <linux/memblock.h>
-#include <linux/dma-direct.h>
-#include <linux/cc_platform.h>
-
-#include <asm/iommu.h>
-#include <asm/swiotlb.h>
-#include <asm/dma.h>
-#include <asm/xen/swiotlb-xen.h>
-#include <asm/iommu_table.h>
-
-int swiotlb __read_mostly;
-
-/*
- * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
- *
- * This returns non-zero if we are forced to use swiotlb (by the boot
- * option).
- */
-int __init pci_swiotlb_detect_override(void)
-{
-	if (swiotlb_force == SWIOTLB_FORCE)
-		swiotlb = 1;
-
-	return swiotlb;
-}
-IOMMU_INIT_FINISH(pci_swiotlb_detect_override,
-		  pci_xen_swiotlb_detect,
-		  pci_swiotlb_init,
-		  pci_swiotlb_late_init);
-
-/*
- * If 4GB or more detected (and iommu=off not set) or if SME is active
- * then set swiotlb to 1 and return 1.
- */
-int __init pci_swiotlb_detect_4gb(void)
-{
-	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
-	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
-		swiotlb = 1;
-
-	/*
-	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
-	 * devices that can't support DMA to encrypted memory.
-	 */
-	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
-		swiotlb = 1;
-
-	return swiotlb;
-}
-IOMMU_INIT(pci_swiotlb_detect_4gb,
-	   pci_swiotlb_detect_override,
-	   pci_swiotlb_init,
-	   pci_swiotlb_late_init);
-
-void __init pci_swiotlb_init(void)
-{
-	if (swiotlb)
-		swiotlb_init(0);
-}
-
-void __init pci_swiotlb_late_init(void)
-{
-	/* An IOMMU turned us off. */
-	if (!swiotlb)
-		swiotlb_exit();
-	else {
-		printk(KERN_INFO "PCI-DMA: "
-		       "Using software bounce buffering for IO (SWIOTLB)\n");
-		swiotlb_print_info();
-	}
-}
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index f9af561c3cd4f..0c1154a1c4032 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -24,7 +24,6 @@
 #include <asm/processor.h>
 #include <asm/bootparam.h>
 #include <asm/pgalloc.h>
-#include <asm/swiotlb.h>
 #include <asm/fixmap.h>
 #include <asm/proto.h>
 #include <asm/setup.h>
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 7fda7f27e7620..f5f6dc2e80072 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -315,18 +315,6 @@ SECTIONS
 		*(.altinstr_replacement)
 	}
 
-	/*
-	 * struct iommu_table_entry entries are injected in this section.
-	 * It is an array of IOMMUs which during run time gets sorted depending
-	 * on its dependency order. After rootfs_initcall is complete
-	 * this section can be safely removed.
-	 */
-	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
-		__iommu_table = .;
-		*(.iommu_table)
-		__iommu_table_end = .;
-	}
-
 	. = ALIGN(8);
 	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
 		__apicdrivers = .;
diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
index 4953260e281c3..3c5b52fbe4a7f 100644
--- a/arch/x86/xen/Makefile
+++ b/arch/x86/xen/Makefile
@@ -47,6 +47,4 @@ obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
 
 obj-$(CONFIG_XEN_PV_DOM0)	+= vga.o
 
-obj-$(CONFIG_SWIOTLB_XEN)	+= pci-swiotlb-xen.o
-
 obj-$(CONFIG_XEN_EFI)		+= efi.o
diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
deleted file mode 100644
index 46df59aeaa06a..0000000000000
--- a/arch/x86/xen/pci-swiotlb-xen.c
+++ /dev/null
@@ -1,96 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-/* Glue code to lib/swiotlb-xen.c */
-
-#include <linux/dma-map-ops.h>
-#include <linux/pci.h>
-#include <xen/swiotlb-xen.h>
-
-#include <asm/xen/hypervisor.h>
-#include <xen/xen.h>
-#include <asm/iommu_table.h>
-
-
-#include <asm/xen/swiotlb-xen.h>
-#ifdef CONFIG_X86_64
-#include <asm/iommu.h>
-#include <asm/dma.h>
-#endif
-#include <linux/export.h>
-
-static int xen_swiotlb __read_mostly;
-
-/*
- * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
- *
- * This returns non-zero if we are forced to use xen_swiotlb (by the boot
- * option).
- */
-int __init pci_xen_swiotlb_detect(void)
-{
-
-	if (!xen_pv_domain())
-		return 0;
-
-	/* If running as PV guest, either iommu=soft, or swiotlb=force will
-	 * activate this IOMMU. If running as PV privileged, activate it
-	 * irregardless.
-	 */
-	if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
-		xen_swiotlb = 1;
-
-	/* If we are running under Xen, we MUST disable the native SWIOTLB.
-	 * Don't worry about swiotlb_force flag activating the native, as
-	 * the 'swiotlb' flag is the only one turning it on. */
-	swiotlb = 0;
-
-#ifdef CONFIG_X86_64
-	/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
-	 * (so no iommu=X command line over-writes).
-	 * Considering that PV guests do not want the *native SWIOTLB* but
-	 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
-	 */
-	if (max_pfn > MAX_DMA32_PFN)
-		no_iommu = 1;
-#endif
-	return xen_swiotlb;
-}
-
-static void __init pci_xen_swiotlb_init(void)
-{
-	if (xen_swiotlb) {
-		xen_swiotlb_init_early();
-		dma_ops = &xen_swiotlb_dma_ops;
-
-#ifdef CONFIG_PCI
-		/* Make sure ACS will be enabled */
-		pci_request_acs();
-#endif
-	}
-}
-
-int pci_xen_swiotlb_init_late(void)
-{
-	int rc;
-
-	if (xen_swiotlb)
-		return 0;
-
-	rc = xen_swiotlb_init();
-	if (rc)
-		return rc;
-
-	dma_ops = &xen_swiotlb_dma_ops;
-#ifdef CONFIG_PCI
-	/* Make sure ACS will be enabled */
-	pci_request_acs();
-#endif
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
-
-IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
-		  NULL,
-		  pci_xen_swiotlb_init,
-		  NULL);
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index b4a798c7b347f..1a3ad58ba8465 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -27,7 +27,6 @@
 #include <asm/apic.h>
 #include <asm/gart.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
 #include <asm/io_apic.h>
 #include <asm/irq_remapping.h>
 #include <asm/set_memory.h>
@@ -3257,11 +3256,6 @@ __setup("ivrs_ioapic",		parse_ivrs_ioapic);
 __setup("ivrs_hpet",		parse_ivrs_hpet);
 __setup("ivrs_acpihid",		parse_ivrs_acpihid);
 
-IOMMU_INIT_FINISH(amd_iommu_detect,
-		  gart_iommu_hole_init,
-		  NULL,
-		  NULL);
-
 bool amd_iommu_v2_supported(void)
 {
 	return amd_iommu_v2_present;
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index a1ada7bff44e6..b47220ac09eaa 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -1840,7 +1840,10 @@ void amd_iommu_domain_update(struct protection_domain *domain)
 
 static void __init amd_iommu_init_dma_ops(void)
 {
-	swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
+	if (iommu_default_passthrough() || sme_me_mask)
+		x86_swiotlb_enable = true;
+	else
+		x86_swiotlb_enable = false;
 }
 
 int __init amd_iommu_init_api(void)
diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
index 4de960834a1b2..592c1e1a5d4b9 100644
--- a/drivers/iommu/intel/dmar.c
+++ b/drivers/iommu/intel/dmar.c
@@ -30,7 +30,6 @@
 #include <linux/numa.h>
 #include <linux/limits.h>
 #include <asm/irq_remapping.h>
-#include <asm/iommu_table.h>
 #include <trace/events/intel_iommu.h>
 
 #include "../irq_remapping.h"
@@ -912,7 +911,7 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)
 	return 0;
 }
 
-int __init detect_intel_iommu(void)
+void __init detect_intel_iommu(void)
 {
 	int ret;
 	struct dmar_res_callback validate_drhd_cb = {
@@ -945,8 +944,6 @@ int __init detect_intel_iommu(void)
 		dmar_tbl = NULL;
 	}
 	up_write(&dmar_global_lock);
-
-	return ret ? ret : 1;
 }
 
 static void unmap_iommu(struct intel_iommu *iommu)
@@ -2164,7 +2161,6 @@ static int __init dmar_free_unused_resources(void)
 }
 
 late_initcall(dmar_free_unused_resources);
-IOMMU_INIT_POST(detect_intel_iommu);
 
 /*
  * DMAR Hotplug Support
diff --git a/include/linux/dmar.h b/include/linux/dmar.h
index 45e903d847335..cbd714a198a0a 100644
--- a/include/linux/dmar.h
+++ b/include/linux/dmar.h
@@ -121,7 +121,7 @@ extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
 				 u16 segment, struct dmar_dev_scope *devices,
 				 int count);
 /* Intel IOMMU detection */
-extern int detect_intel_iommu(void);
+void detect_intel_iommu(void);
 extern int enable_drhd_fault_handling(void);
 extern int dmar_device_add(acpi_handle handle);
 extern int dmar_device_remove(acpi_handle handle);
@@ -197,6 +197,10 @@ static inline bool dmar_platform_optin(void)
 	return false;
 }
 
+static inline void detect_intel_iommu(void)
+{
+}
+
 #endif /* CONFIG_DMAR_TABLE */
 
 struct irte {
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 07/15] x86: remove the IOMMU table infrastructure
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

The IOMMU table tries to separate the different IOMMUs into different
backends, but actually requires various cross calls.

Rewrite the code to do the generic swiotlb/swiotlb-xen setup directly
in pci-dma.c and then just call into the IOMMU drivers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/ia64/include/asm/iommu_table.h    |   7 --
 arch/x86/include/asm/dma-mapping.h     |   1 -
 arch/x86/include/asm/gart.h            |   5 +-
 arch/x86/include/asm/iommu.h           |   6 ++
 arch/x86/include/asm/iommu_table.h     | 102 -----------------------
 arch/x86/include/asm/swiotlb.h         |  30 -------
 arch/x86/include/asm/xen/swiotlb-xen.h |   2 -
 arch/x86/kernel/Makefile               |   2 -
 arch/x86/kernel/amd_gart_64.c          |   5 +-
 arch/x86/kernel/aperture_64.c          |  14 ++--
 arch/x86/kernel/pci-dma.c              | 107 ++++++++++++++++++++-----
 arch/x86/kernel/pci-iommu_table.c      |  77 ------------------
 arch/x86/kernel/pci-swiotlb.c          |  77 ------------------
 arch/x86/kernel/tboot.c                |   1 -
 arch/x86/kernel/vmlinux.lds.S          |  12 ---
 arch/x86/xen/Makefile                  |   2 -
 arch/x86/xen/pci-swiotlb-xen.c         |  96 ----------------------
 drivers/iommu/amd/init.c               |   6 --
 drivers/iommu/amd/iommu.c              |   5 +-
 drivers/iommu/intel/dmar.c             |   6 +-
 include/linux/dmar.h                   |   6 +-
 21 files changed, 110 insertions(+), 459 deletions(-)
 delete mode 100644 arch/ia64/include/asm/iommu_table.h
 delete mode 100644 arch/x86/include/asm/iommu_table.h
 delete mode 100644 arch/x86/include/asm/swiotlb.h
 delete mode 100644 arch/x86/kernel/pci-iommu_table.c
 delete mode 100644 arch/x86/kernel/pci-swiotlb.c
 delete mode 100644 arch/x86/xen/pci-swiotlb-xen.c

diff --git a/arch/ia64/include/asm/iommu_table.h b/arch/ia64/include/asm/iommu_table.h
deleted file mode 100644
index cc96116ac276a..0000000000000
--- a/arch/ia64/include/asm/iommu_table.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_IA64_IOMMU_TABLE_H
-#define _ASM_IA64_IOMMU_TABLE_H
-
-#define IOMMU_INIT_POST(_detect)
-
-#endif /* _ASM_IA64_IOMMU_TABLE_H */
diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index bb1654fe0ce74..256fd8115223d 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -9,7 +9,6 @@
 
 #include <linux/scatterlist.h>
 #include <asm/io.h>
-#include <asm/swiotlb.h>
 
 extern int iommu_merge;
 extern int panic_on_overflow;
diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
index 3185565743459..5af8088a10df6 100644
--- a/arch/x86/include/asm/gart.h
+++ b/arch/x86/include/asm/gart.h
@@ -38,7 +38,7 @@ extern int gart_iommu_aperture_disabled;
 extern void early_gart_iommu_check(void);
 extern int gart_iommu_init(void);
 extern void __init gart_parse_options(char *);
-extern int gart_iommu_hole_init(void);
+void gart_iommu_hole_init(void);
 
 #else
 #define gart_iommu_aperture            0
@@ -51,9 +51,8 @@ static inline void early_gart_iommu_check(void)
 static inline void gart_parse_options(char *options)
 {
 }
-static inline int gart_iommu_hole_init(void)
+static inline void gart_iommu_hole_init(void)
 {
-	return -ENODEV;
 }
 #endif
 
diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
index bf1ed2ddc74bd..dba89ed40d38d 100644
--- a/arch/x86/include/asm/iommu.h
+++ b/arch/x86/include/asm/iommu.h
@@ -9,6 +9,12 @@
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
 
+#ifdef CONFIG_SWIOTLB
+extern bool x86_swiotlb_enable;
+#else
+#define x86_swiotlb_enable false
+#endif
+
 /* 10 seconds */
 #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
 
diff --git a/arch/x86/include/asm/iommu_table.h b/arch/x86/include/asm/iommu_table.h
deleted file mode 100644
index 1fb3fd1a83c25..0000000000000
--- a/arch/x86/include/asm/iommu_table.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_X86_IOMMU_TABLE_H
-#define _ASM_X86_IOMMU_TABLE_H
-
-#include <asm/swiotlb.h>
-
-/*
- * History lesson:
- * The execution chain of IOMMUs in 2.6.36 looks as so:
- *
- *            [xen-swiotlb]
- *                 |
- *         +----[swiotlb *]--+
- *        /         |         \
- *       /          |          \
- *    [GART]     [Calgary]  [Intel VT-d]
- *     /
- *    /
- * [AMD-Vi]
- *
- * *: if SWIOTLB detected 'iommu=soft'/'swiotlb=force' it would skip
- * over the rest of IOMMUs and unconditionally initialize the SWIOTLB.
- * Also it would surreptitiously initialize set the swiotlb=1 if there were
- * more than 4GB and if the user did not pass in 'iommu=off'. The swiotlb
- * flag would be turned off by all IOMMUs except the Calgary one.
- *
- * The IOMMU_INIT* macros allow a similar tree (or more complex if desired)
- * to be built by defining who we depend on.
- *
- * And all that needs to be done is to use one of the macros in the IOMMU
- * and the pci-dma.c will take care of the rest.
- */
-
-struct iommu_table_entry {
-	initcall_t	detect;
-	initcall_t	depend;
-	void		(*early_init)(void); /* No memory allocate available. */
-	void		(*late_init)(void); /* Yes, can allocate memory. */
-#define IOMMU_FINISH_IF_DETECTED (1<<0)
-#define IOMMU_DETECTED		 (1<<1)
-	int		flags;
-};
-/*
- * Macro fills out an entry in the .iommu_table that is equivalent
- * to the fields that 'struct iommu_table_entry' has. The entries
- * that are put in the .iommu_table section are not put in any order
- * hence during boot-time we will have to resort them based on
- * dependency. */
-
-
-#define __IOMMU_INIT(_detect, _depend, _early_init, _late_init, _finish)\
-	static const struct iommu_table_entry				\
-		__iommu_entry_##_detect __used				\
-	__attribute__ ((unused, __section__(".iommu_table"),		\
-			aligned((sizeof(void *)))))	\
-	= {_detect, _depend, _early_init, _late_init,			\
-	   _finish ? IOMMU_FINISH_IF_DETECTED : 0}
-/*
- * The simplest IOMMU definition. Provide the detection routine
- * and it will be run after the SWIOTLB and the other IOMMUs
- * that utilize this macro. If the IOMMU is detected (ie, the
- * detect routine returns a positive value), the other IOMMUs
- * are also checked. You can use IOMMU_INIT_POST_FINISH if you prefer
- * to stop detecting the other IOMMUs after yours has been detected.
- */
-#define IOMMU_INIT_POST(_detect)					\
-	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 0)
-
-#define IOMMU_INIT_POST_FINISH(detect)					\
-	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 1)
-
-/*
- * A more sophisticated version of IOMMU_INIT. This variant requires:
- *  a). A detection routine function.
- *  b). The name of the detection routine we depend on to get called
- *      before us.
- *  c). The init routine which gets called if the detection routine
- *      returns a positive value from the pci_iommu_alloc. This means
- *      no presence of a memory allocator.
- *  d). Similar to the 'init', except that this gets called from pci_iommu_init
- *      where we do have a memory allocator.
- *
- * The standard IOMMU_INIT differs from the IOMMU_INIT_FINISH variant
- * in that the former will continue detecting other IOMMUs in the call
- * list after the detection routine returns a positive number, while the
- * latter will stop the execution chain upon first successful detection.
- * Both variants will still call the 'init' and 'late_init' functions if
- * they are set.
- */
-#define IOMMU_INIT_FINISH(_detect, _depend, _init, _late_init)		\
-	__IOMMU_INIT(_detect, _depend, _init, _late_init, 1)
-
-#define IOMMU_INIT(_detect, _depend, _init, _late_init)			\
-	__IOMMU_INIT(_detect, _depend, _init, _late_init, 0)
-
-void sort_iommu_table(struct iommu_table_entry *start,
-		      struct iommu_table_entry *finish);
-
-void check_iommu_entries(struct iommu_table_entry *start,
-			 struct iommu_table_entry *finish);
-
-#endif /* _ASM_X86_IOMMU_TABLE_H */
diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
deleted file mode 100644
index ff6c92eff035a..0000000000000
--- a/arch/x86/include/asm/swiotlb.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_X86_SWIOTLB_H
-#define _ASM_X86_SWIOTLB_H
-
-#include <linux/swiotlb.h>
-
-#ifdef CONFIG_SWIOTLB
-extern int swiotlb;
-extern int __init pci_swiotlb_detect_override(void);
-extern int __init pci_swiotlb_detect_4gb(void);
-extern void __init pci_swiotlb_init(void);
-extern void __init pci_swiotlb_late_init(void);
-#else
-#define swiotlb 0
-static inline int pci_swiotlb_detect_override(void)
-{
-	return 0;
-}
-static inline int pci_swiotlb_detect_4gb(void)
-{
-	return 0;
-}
-static inline void pci_swiotlb_init(void)
-{
-}
-static inline void pci_swiotlb_late_init(void)
-{
-}
-#endif
-#endif /* _ASM_X86_SWIOTLB_H */
diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h
index 66b4ddde77430..e5a90b42e4dde 100644
--- a/arch/x86/include/asm/xen/swiotlb-xen.h
+++ b/arch/x86/include/asm/xen/swiotlb-xen.h
@@ -3,10 +3,8 @@
 #define _ASM_X86_SWIOTLB_XEN_H
 
 #ifdef CONFIG_SWIOTLB_XEN
-extern int __init pci_xen_swiotlb_detect(void);
 extern int pci_xen_swiotlb_init_late(void);
 #else
-#define pci_xen_swiotlb_detect NULL
 static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
 #endif
 
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index c41ef42adbe8a..e17b7e92a3fa3 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -68,7 +68,6 @@ obj-y			+= bootflag.o e820.o
 obj-y			+= pci-dma.o quirks.o topology.o kdebugfs.o
 obj-y			+= alternative.o i8253.o hw_breakpoint.o
 obj-y			+= tsc.o tsc_msr.o io_delay.o rtc.o
-obj-y			+= pci-iommu_table.o
 obj-y			+= resource.o
 obj-y			+= irqflags.o
 obj-y			+= static_call.o
@@ -134,7 +133,6 @@ obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
 
 obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
 
-obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
 obj-$(CONFIG_OF)			+= devicetree.o
 obj-$(CONFIG_UPROBES)			+= uprobes.o
 
diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
index ed837383de5c8..194d54eed5376 100644
--- a/arch/x86/kernel/amd_gart_64.c
+++ b/arch/x86/kernel/amd_gart_64.c
@@ -38,11 +38,9 @@
 #include <asm/iommu.h>
 #include <asm/gart.h>
 #include <asm/set_memory.h>
-#include <asm/swiotlb.h>
 #include <asm/dma.h>
 #include <asm/amd_nb.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
 
 static unsigned long iommu_bus_base;	/* GART remapping area (physical) */
 static unsigned long iommu_size;	/* size of remapping area bytes */
@@ -808,7 +806,7 @@ int __init gart_iommu_init(void)
 	flush_gart();
 	dma_ops = &gart_dma_ops;
 	x86_platform.iommu_shutdown = gart_iommu_shutdown;
-	swiotlb = 0;
+	x86_swiotlb_enable = false;
 
 	return 0;
 }
@@ -842,4 +840,3 @@ void __init gart_parse_options(char *p)
 		}
 	}
 }
-IOMMU_INIT_POST(gart_iommu_hole_init);
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index af3ba08b684b5..7a5630d904b23 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -392,7 +392,7 @@ void __init early_gart_iommu_check(void)
 
 static int __initdata printed_gart_size_msg;
 
-int __init gart_iommu_hole_init(void)
+void __init gart_iommu_hole_init(void)
 {
 	u32 agp_aper_base = 0, agp_aper_order = 0;
 	u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0;
@@ -401,11 +401,11 @@ int __init gart_iommu_hole_init(void)
 	int i, node;
 
 	if (!amd_gart_present())
-		return -ENODEV;
+		return;
 
 	if (gart_iommu_aperture_disabled || !fix_aperture ||
 	    !early_pci_allowed())
-		return -ENODEV;
+		return;
 
 	pr_info("Checking aperture...\n");
 
@@ -491,10 +491,8 @@ int __init gart_iommu_hole_init(void)
 			 * and fixed up the northbridge
 			 */
 			exclude_from_core(last_aper_base, last_aper_order);
-
-			return 1;
 		}
-		return 0;
+		return;
 	}
 
 	if (!fallback_aper_force) {
@@ -527,7 +525,7 @@ int __init gart_iommu_hole_init(void)
 			panic("Not enough memory for aperture");
 		}
 	} else {
-		return 0;
+		return;
 	}
 
 	/*
@@ -561,6 +559,4 @@ int __init gart_iommu_hole_init(void)
 	}
 
 	set_up_gart_resume(aper_order, aper_alloc);
-
-	return 1;
 }
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index de234e7a8962e..df96926421be0 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -7,13 +7,16 @@
 #include <linux/memblock.h>
 #include <linux/gfp.h>
 #include <linux/pci.h>
+#include <linux/amd-iommu.h>
 
 #include <asm/proto.h>
 #include <asm/dma.h>
 #include <asm/iommu.h>
 #include <asm/gart.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
+
+#include <xen/xen.h>
+#include <xen/swiotlb-xen.h>
 
 static bool disable_dac_quirk __read_mostly;
 
@@ -34,24 +37,83 @@ int no_iommu __read_mostly;
 /* Set this to 1 if there is a HW IOMMU in the system */
 int iommu_detected __read_mostly = 0;
 
-extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
+#ifdef CONFIG_SWIOTLB
+bool x86_swiotlb_enable;
+
+static void __init pci_swiotlb_detect(void)
+{
+	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
+	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
+		x86_swiotlb_enable = true;
+
+	/*
+	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
+	 * devices that can't support DMA to encrypted memory.
+	 */
+	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
+		x86_swiotlb_enable = true;
+
+	if (swiotlb_force == SWIOTLB_FORCE)
+		x86_swiotlb_enable = true;
+}
+#else
+static inline void __init pci_swiotlb_detect(void)
+{
+}
+#endif /* CONFIG_SWIOTLB */
+
+#ifdef CONFIG_SWIOTLB_XEN
+static bool xen_swiotlb;
+
+static void __init pci_xen_swiotlb_init(void)
+{
+	if (!xen_initial_domain() && !x86_swiotlb_enable &&
+	    swiotlb_force != SWIOTLB_FORCE)
+		return;
+	x86_swiotlb_enable = true;
+	xen_swiotlb = true;
+	xen_swiotlb_init_early();
+	dma_ops = &xen_swiotlb_dma_ops;
+	if (IS_ENABLED(CONFIG_PCI))
+		pci_request_acs();
+}
+
+int pci_xen_swiotlb_init_late(void)
+{
+	int rc;
+
+	if (xen_swiotlb)
+		return 0;
+
+	rc = xen_swiotlb_init();
+	if (rc)
+		return rc;
+
+	/* XXX: this switches the dma ops under live devices! */
+	dma_ops = &xen_swiotlb_dma_ops;
+	if (IS_ENABLED(CONFIG_PCI))
+		pci_request_acs();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
+#else
+static inline void __init pci_xen_swiotlb_init(void)
+{
+}
+#endif /* CONFIG_SWIOTLB_XEN */
 
 void __init pci_iommu_alloc(void)
 {
-	struct iommu_table_entry *p;
-
-	sort_iommu_table(__iommu_table, __iommu_table_end);
-	check_iommu_entries(__iommu_table, __iommu_table_end);
-
-	for (p = __iommu_table; p < __iommu_table_end; p++) {
-		if (p && p->detect && p->detect() > 0) {
-			p->flags |= IOMMU_DETECTED;
-			if (p->early_init)
-				p->early_init();
-			if (p->flags & IOMMU_FINISH_IF_DETECTED)
-				break;
-		}
+	if (xen_pv_domain()) {
+		pci_xen_swiotlb_init();
+		return;
 	}
+	pci_swiotlb_detect();
+	gart_iommu_hole_init();
+	amd_iommu_detect();
+	detect_intel_iommu();
+	if (x86_swiotlb_enable)
+		swiotlb_init(0);
 }
 
 /*
@@ -102,7 +164,7 @@ static __init int iommu_setup(char *p)
 		}
 #ifdef CONFIG_SWIOTLB
 		if (!strncmp(p, "soft", 4))
-			swiotlb = 1;
+			x86_swiotlb_enable = true;
 #endif
 		if (!strncmp(p, "pt", 2))
 			iommu_set_default_passthrough(true);
@@ -121,14 +183,17 @@ early_param("iommu", iommu_setup);
 
 static int __init pci_iommu_init(void)
 {
-	struct iommu_table_entry *p;
-
 	x86_init.iommu.iommu_init();
 
-	for (p = __iommu_table; p < __iommu_table_end; p++) {
-		if (p && (p->flags & IOMMU_DETECTED) && p->late_init)
-			p->late_init();
+#ifdef CONFIG_SWIOTLB
+	/* An IOMMU turned us off. */
+	if (x86_swiotlb_enable) {
+		pr_info("PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
+		swiotlb_print_info();
+	} else {
+		swiotlb_exit();
 	}
+#endif
 
 	return 0;
 }
diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
deleted file mode 100644
index 42e92ec62973b..0000000000000
--- a/arch/x86/kernel/pci-iommu_table.c
+++ /dev/null
@@ -1,77 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/dma-mapping.h>
-#include <asm/iommu_table.h>
-#include <linux/string.h>
-#include <linux/kallsyms.h>
-
-static struct iommu_table_entry * __init
-find_dependents_of(struct iommu_table_entry *start,
-		   struct iommu_table_entry *finish,
-		   struct iommu_table_entry *q)
-{
-	struct iommu_table_entry *p;
-
-	if (!q)
-		return NULL;
-
-	for (p = start; p < finish; p++)
-		if (p->detect == q->depend)
-			return p;
-
-	return NULL;
-}
-
-
-void __init sort_iommu_table(struct iommu_table_entry *start,
-			     struct iommu_table_entry *finish) {
-
-	struct iommu_table_entry *p, *q, tmp;
-
-	for (p = start; p < finish; p++) {
-again:
-		q = find_dependents_of(start, finish, p);
-		/* We are bit sneaky here. We use the memory address to figure
-		 * out if the node we depend on is past our point, if so, swap.
-		 */
-		if (q > p) {
-			tmp = *p;
-			memmove(p, q, sizeof(*p));
-			*q = tmp;
-			goto again;
-		}
-	}
-
-}
-
-#ifdef DEBUG
-void __init check_iommu_entries(struct iommu_table_entry *start,
-				struct iommu_table_entry *finish)
-{
-	struct iommu_table_entry *p, *q, *x;
-
-	/* Simple cyclic dependency checker. */
-	for (p = start; p < finish; p++) {
-		q = find_dependents_of(start, finish, p);
-		x = find_dependents_of(start, finish, q);
-		if (p == x) {
-			printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %pS depends on %pS and vice-versa. BREAKING IT.\n",
-			       p->detect, q->detect);
-			/* Heavy handed way..*/
-			x->depend = NULL;
-		}
-	}
-
-	for (p = start; p < finish; p++) {
-		q = find_dependents_of(p, finish, p);
-		if (q && q > p) {
-			printk(KERN_ERR "EXECUTION ORDER INVALID! %pS should be called before %pS!\n",
-			       p->detect, q->detect);
-		}
-	}
-}
-#else
-void __init check_iommu_entries(struct iommu_table_entry *start,
-				       struct iommu_table_entry *finish)
-{
-}
-#endif
diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
deleted file mode 100644
index 814ab46a0dada..0000000000000
--- a/arch/x86/kernel/pci-swiotlb.c
+++ /dev/null
@@ -1,77 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/pci.h>
-#include <linux/cache.h>
-#include <linux/init.h>
-#include <linux/swiotlb.h>
-#include <linux/memblock.h>
-#include <linux/dma-direct.h>
-#include <linux/cc_platform.h>
-
-#include <asm/iommu.h>
-#include <asm/swiotlb.h>
-#include <asm/dma.h>
-#include <asm/xen/swiotlb-xen.h>
-#include <asm/iommu_table.h>
-
-int swiotlb __read_mostly;
-
-/*
- * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
- *
- * This returns non-zero if we are forced to use swiotlb (by the boot
- * option).
- */
-int __init pci_swiotlb_detect_override(void)
-{
-	if (swiotlb_force == SWIOTLB_FORCE)
-		swiotlb = 1;
-
-	return swiotlb;
-}
-IOMMU_INIT_FINISH(pci_swiotlb_detect_override,
-		  pci_xen_swiotlb_detect,
-		  pci_swiotlb_init,
-		  pci_swiotlb_late_init);
-
-/*
- * If 4GB or more detected (and iommu=off not set) or if SME is active
- * then set swiotlb to 1 and return 1.
- */
-int __init pci_swiotlb_detect_4gb(void)
-{
-	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
-	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
-		swiotlb = 1;
-
-	/*
-	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
-	 * devices that can't support DMA to encrypted memory.
-	 */
-	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
-		swiotlb = 1;
-
-	return swiotlb;
-}
-IOMMU_INIT(pci_swiotlb_detect_4gb,
-	   pci_swiotlb_detect_override,
-	   pci_swiotlb_init,
-	   pci_swiotlb_late_init);
-
-void __init pci_swiotlb_init(void)
-{
-	if (swiotlb)
-		swiotlb_init(0);
-}
-
-void __init pci_swiotlb_late_init(void)
-{
-	/* An IOMMU turned us off. */
-	if (!swiotlb)
-		swiotlb_exit();
-	else {
-		printk(KERN_INFO "PCI-DMA: "
-		       "Using software bounce buffering for IO (SWIOTLB)\n");
-		swiotlb_print_info();
-	}
-}
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index f9af561c3cd4f..0c1154a1c4032 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -24,7 +24,6 @@
 #include <asm/processor.h>
 #include <asm/bootparam.h>
 #include <asm/pgalloc.h>
-#include <asm/swiotlb.h>
 #include <asm/fixmap.h>
 #include <asm/proto.h>
 #include <asm/setup.h>
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 7fda7f27e7620..f5f6dc2e80072 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -315,18 +315,6 @@ SECTIONS
 		*(.altinstr_replacement)
 	}
 
-	/*
-	 * struct iommu_table_entry entries are injected in this section.
-	 * It is an array of IOMMUs which during run time gets sorted depending
-	 * on its dependency order. After rootfs_initcall is complete
-	 * this section can be safely removed.
-	 */
-	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
-		__iommu_table = .;
-		*(.iommu_table)
-		__iommu_table_end = .;
-	}
-
 	. = ALIGN(8);
 	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
 		__apicdrivers = .;
diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
index 4953260e281c3..3c5b52fbe4a7f 100644
--- a/arch/x86/xen/Makefile
+++ b/arch/x86/xen/Makefile
@@ -47,6 +47,4 @@ obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
 
 obj-$(CONFIG_XEN_PV_DOM0)	+= vga.o
 
-obj-$(CONFIG_SWIOTLB_XEN)	+= pci-swiotlb-xen.o
-
 obj-$(CONFIG_XEN_EFI)		+= efi.o
diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
deleted file mode 100644
index 46df59aeaa06a..0000000000000
--- a/arch/x86/xen/pci-swiotlb-xen.c
+++ /dev/null
@@ -1,96 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-/* Glue code to lib/swiotlb-xen.c */
-
-#include <linux/dma-map-ops.h>
-#include <linux/pci.h>
-#include <xen/swiotlb-xen.h>
-
-#include <asm/xen/hypervisor.h>
-#include <xen/xen.h>
-#include <asm/iommu_table.h>
-
-
-#include <asm/xen/swiotlb-xen.h>
-#ifdef CONFIG_X86_64
-#include <asm/iommu.h>
-#include <asm/dma.h>
-#endif
-#include <linux/export.h>
-
-static int xen_swiotlb __read_mostly;
-
-/*
- * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
- *
- * This returns non-zero if we are forced to use xen_swiotlb (by the boot
- * option).
- */
-int __init pci_xen_swiotlb_detect(void)
-{
-
-	if (!xen_pv_domain())
-		return 0;
-
-	/* If running as PV guest, either iommu=soft, or swiotlb=force will
-	 * activate this IOMMU. If running as PV privileged, activate it
-	 * irregardless.
-	 */
-	if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
-		xen_swiotlb = 1;
-
-	/* If we are running under Xen, we MUST disable the native SWIOTLB.
-	 * Don't worry about swiotlb_force flag activating the native, as
-	 * the 'swiotlb' flag is the only one turning it on. */
-	swiotlb = 0;
-
-#ifdef CONFIG_X86_64
-	/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
-	 * (so no iommu=X command line over-writes).
-	 * Considering that PV guests do not want the *native SWIOTLB* but
-	 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
-	 */
-	if (max_pfn > MAX_DMA32_PFN)
-		no_iommu = 1;
-#endif
-	return xen_swiotlb;
-}
-
-static void __init pci_xen_swiotlb_init(void)
-{
-	if (xen_swiotlb) {
-		xen_swiotlb_init_early();
-		dma_ops = &xen_swiotlb_dma_ops;
-
-#ifdef CONFIG_PCI
-		/* Make sure ACS will be enabled */
-		pci_request_acs();
-#endif
-	}
-}
-
-int pci_xen_swiotlb_init_late(void)
-{
-	int rc;
-
-	if (xen_swiotlb)
-		return 0;
-
-	rc = xen_swiotlb_init();
-	if (rc)
-		return rc;
-
-	dma_ops = &xen_swiotlb_dma_ops;
-#ifdef CONFIG_PCI
-	/* Make sure ACS will be enabled */
-	pci_request_acs();
-#endif
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
-
-IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
-		  NULL,
-		  pci_xen_swiotlb_init,
-		  NULL);
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index b4a798c7b347f..1a3ad58ba8465 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -27,7 +27,6 @@
 #include <asm/apic.h>
 #include <asm/gart.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
 #include <asm/io_apic.h>
 #include <asm/irq_remapping.h>
 #include <asm/set_memory.h>
@@ -3257,11 +3256,6 @@ __setup("ivrs_ioapic",		parse_ivrs_ioapic);
 __setup("ivrs_hpet",		parse_ivrs_hpet);
 __setup("ivrs_acpihid",		parse_ivrs_acpihid);
 
-IOMMU_INIT_FINISH(amd_iommu_detect,
-		  gart_iommu_hole_init,
-		  NULL,
-		  NULL);
-
 bool amd_iommu_v2_supported(void)
 {
 	return amd_iommu_v2_present;
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index a1ada7bff44e6..b47220ac09eaa 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -1840,7 +1840,10 @@ void amd_iommu_domain_update(struct protection_domain *domain)
 
 static void __init amd_iommu_init_dma_ops(void)
 {
-	swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
+	if (iommu_default_passthrough() || sme_me_mask)
+		x86_swiotlb_enable = true;
+	else
+		x86_swiotlb_enable = false;
 }
 
 int __init amd_iommu_init_api(void)
diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
index 4de960834a1b2..592c1e1a5d4b9 100644
--- a/drivers/iommu/intel/dmar.c
+++ b/drivers/iommu/intel/dmar.c
@@ -30,7 +30,6 @@
 #include <linux/numa.h>
 #include <linux/limits.h>
 #include <asm/irq_remapping.h>
-#include <asm/iommu_table.h>
 #include <trace/events/intel_iommu.h>
 
 #include "../irq_remapping.h"
@@ -912,7 +911,7 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)
 	return 0;
 }
 
-int __init detect_intel_iommu(void)
+void __init detect_intel_iommu(void)
 {
 	int ret;
 	struct dmar_res_callback validate_drhd_cb = {
@@ -945,8 +944,6 @@ int __init detect_intel_iommu(void)
 		dmar_tbl = NULL;
 	}
 	up_write(&dmar_global_lock);
-
-	return ret ? ret : 1;
 }
 
 static void unmap_iommu(struct intel_iommu *iommu)
@@ -2164,7 +2161,6 @@ static int __init dmar_free_unused_resources(void)
 }
 
 late_initcall(dmar_free_unused_resources);
-IOMMU_INIT_POST(detect_intel_iommu);
 
 /*
  * DMAR Hotplug Support
diff --git a/include/linux/dmar.h b/include/linux/dmar.h
index 45e903d847335..cbd714a198a0a 100644
--- a/include/linux/dmar.h
+++ b/include/linux/dmar.h
@@ -121,7 +121,7 @@ extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
 				 u16 segment, struct dmar_dev_scope *devices,
 				 int count);
 /* Intel IOMMU detection */
-extern int detect_intel_iommu(void);
+void detect_intel_iommu(void);
 extern int enable_drhd_fault_handling(void);
 extern int dmar_device_add(acpi_handle handle);
 extern int dmar_device_remove(acpi_handle handle);
@@ -197,6 +197,10 @@ static inline bool dmar_platform_optin(void)
 	return false;
 }
 
+static inline void detect_intel_iommu(void)
+{
+}
+
 #endif /* CONFIG_DMAR_TABLE */
 
 struct irte {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 07/15] x86: remove the IOMMU table infrastructure
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

The IOMMU table tries to separate the different IOMMUs into different
backends, but actually requires various cross calls.

Rewrite the code to do the generic swiotlb/swiotlb-xen setup directly
in pci-dma.c and then just call into the IOMMU drivers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/ia64/include/asm/iommu_table.h    |   7 --
 arch/x86/include/asm/dma-mapping.h     |   1 -
 arch/x86/include/asm/gart.h            |   5 +-
 arch/x86/include/asm/iommu.h           |   6 ++
 arch/x86/include/asm/iommu_table.h     | 102 -----------------------
 arch/x86/include/asm/swiotlb.h         |  30 -------
 arch/x86/include/asm/xen/swiotlb-xen.h |   2 -
 arch/x86/kernel/Makefile               |   2 -
 arch/x86/kernel/amd_gart_64.c          |   5 +-
 arch/x86/kernel/aperture_64.c          |  14 ++--
 arch/x86/kernel/pci-dma.c              | 107 ++++++++++++++++++++-----
 arch/x86/kernel/pci-iommu_table.c      |  77 ------------------
 arch/x86/kernel/pci-swiotlb.c          |  77 ------------------
 arch/x86/kernel/tboot.c                |   1 -
 arch/x86/kernel/vmlinux.lds.S          |  12 ---
 arch/x86/xen/Makefile                  |   2 -
 arch/x86/xen/pci-swiotlb-xen.c         |  96 ----------------------
 drivers/iommu/amd/init.c               |   6 --
 drivers/iommu/amd/iommu.c              |   5 +-
 drivers/iommu/intel/dmar.c             |   6 +-
 include/linux/dmar.h                   |   6 +-
 21 files changed, 110 insertions(+), 459 deletions(-)
 delete mode 100644 arch/ia64/include/asm/iommu_table.h
 delete mode 100644 arch/x86/include/asm/iommu_table.h
 delete mode 100644 arch/x86/include/asm/swiotlb.h
 delete mode 100644 arch/x86/kernel/pci-iommu_table.c
 delete mode 100644 arch/x86/kernel/pci-swiotlb.c
 delete mode 100644 arch/x86/xen/pci-swiotlb-xen.c

diff --git a/arch/ia64/include/asm/iommu_table.h b/arch/ia64/include/asm/iommu_table.h
deleted file mode 100644
index cc96116ac276a..0000000000000
--- a/arch/ia64/include/asm/iommu_table.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_IA64_IOMMU_TABLE_H
-#define _ASM_IA64_IOMMU_TABLE_H
-
-#define IOMMU_INIT_POST(_detect)
-
-#endif /* _ASM_IA64_IOMMU_TABLE_H */
diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index bb1654fe0ce74..256fd8115223d 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -9,7 +9,6 @@
 
 #include <linux/scatterlist.h>
 #include <asm/io.h>
-#include <asm/swiotlb.h>
 
 extern int iommu_merge;
 extern int panic_on_overflow;
diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
index 3185565743459..5af8088a10df6 100644
--- a/arch/x86/include/asm/gart.h
+++ b/arch/x86/include/asm/gart.h
@@ -38,7 +38,7 @@ extern int gart_iommu_aperture_disabled;
 extern void early_gart_iommu_check(void);
 extern int gart_iommu_init(void);
 extern void __init gart_parse_options(char *);
-extern int gart_iommu_hole_init(void);
+void gart_iommu_hole_init(void);
 
 #else
 #define gart_iommu_aperture            0
@@ -51,9 +51,8 @@ static inline void early_gart_iommu_check(void)
 static inline void gart_parse_options(char *options)
 {
 }
-static inline int gart_iommu_hole_init(void)
+static inline void gart_iommu_hole_init(void)
 {
-	return -ENODEV;
 }
 #endif
 
diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
index bf1ed2ddc74bd..dba89ed40d38d 100644
--- a/arch/x86/include/asm/iommu.h
+++ b/arch/x86/include/asm/iommu.h
@@ -9,6 +9,12 @@
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
 
+#ifdef CONFIG_SWIOTLB
+extern bool x86_swiotlb_enable;
+#else
+#define x86_swiotlb_enable false
+#endif
+
 /* 10 seconds */
 #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
 
diff --git a/arch/x86/include/asm/iommu_table.h b/arch/x86/include/asm/iommu_table.h
deleted file mode 100644
index 1fb3fd1a83c25..0000000000000
--- a/arch/x86/include/asm/iommu_table.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_X86_IOMMU_TABLE_H
-#define _ASM_X86_IOMMU_TABLE_H
-
-#include <asm/swiotlb.h>
-
-/*
- * History lesson:
- * The execution chain of IOMMUs in 2.6.36 looks as so:
- *
- *            [xen-swiotlb]
- *                 |
- *         +----[swiotlb *]--+
- *        /         |         \
- *       /          |          \
- *    [GART]     [Calgary]  [Intel VT-d]
- *     /
- *    /
- * [AMD-Vi]
- *
- * *: if SWIOTLB detected 'iommu=soft'/'swiotlb=force' it would skip
- * over the rest of IOMMUs and unconditionally initialize the SWIOTLB.
- * Also it would surreptitiously initialize set the swiotlb=1 if there were
- * more than 4GB and if the user did not pass in 'iommu=off'. The swiotlb
- * flag would be turned off by all IOMMUs except the Calgary one.
- *
- * The IOMMU_INIT* macros allow a similar tree (or more complex if desired)
- * to be built by defining who we depend on.
- *
- * And all that needs to be done is to use one of the macros in the IOMMU
- * and the pci-dma.c will take care of the rest.
- */
-
-struct iommu_table_entry {
-	initcall_t	detect;
-	initcall_t	depend;
-	void		(*early_init)(void); /* No memory allocate available. */
-	void		(*late_init)(void); /* Yes, can allocate memory. */
-#define IOMMU_FINISH_IF_DETECTED (1<<0)
-#define IOMMU_DETECTED		 (1<<1)
-	int		flags;
-};
-/*
- * Macro fills out an entry in the .iommu_table that is equivalent
- * to the fields that 'struct iommu_table_entry' has. The entries
- * that are put in the .iommu_table section are not put in any order
- * hence during boot-time we will have to resort them based on
- * dependency. */
-
-
-#define __IOMMU_INIT(_detect, _depend, _early_init, _late_init, _finish)\
-	static const struct iommu_table_entry				\
-		__iommu_entry_##_detect __used				\
-	__attribute__ ((unused, __section__(".iommu_table"),		\
-			aligned((sizeof(void *)))))	\
-	= {_detect, _depend, _early_init, _late_init,			\
-	   _finish ? IOMMU_FINISH_IF_DETECTED : 0}
-/*
- * The simplest IOMMU definition. Provide the detection routine
- * and it will be run after the SWIOTLB and the other IOMMUs
- * that utilize this macro. If the IOMMU is detected (ie, the
- * detect routine returns a positive value), the other IOMMUs
- * are also checked. You can use IOMMU_INIT_POST_FINISH if you prefer
- * to stop detecting the other IOMMUs after yours has been detected.
- */
-#define IOMMU_INIT_POST(_detect)					\
-	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 0)
-
-#define IOMMU_INIT_POST_FINISH(detect)					\
-	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 1)
-
-/*
- * A more sophisticated version of IOMMU_INIT. This variant requires:
- *  a). A detection routine function.
- *  b). The name of the detection routine we depend on to get called
- *      before us.
- *  c). The init routine which gets called if the detection routine
- *      returns a positive value from the pci_iommu_alloc. This means
- *      no presence of a memory allocator.
- *  d). Similar to the 'init', except that this gets called from pci_iommu_init
- *      where we do have a memory allocator.
- *
- * The standard IOMMU_INIT differs from the IOMMU_INIT_FINISH variant
- * in that the former will continue detecting other IOMMUs in the call
- * list after the detection routine returns a positive number, while the
- * latter will stop the execution chain upon first successful detection.
- * Both variants will still call the 'init' and 'late_init' functions if
- * they are set.
- */
-#define IOMMU_INIT_FINISH(_detect, _depend, _init, _late_init)		\
-	__IOMMU_INIT(_detect, _depend, _init, _late_init, 1)
-
-#define IOMMU_INIT(_detect, _depend, _init, _late_init)			\
-	__IOMMU_INIT(_detect, _depend, _init, _late_init, 0)
-
-void sort_iommu_table(struct iommu_table_entry *start,
-		      struct iommu_table_entry *finish);
-
-void check_iommu_entries(struct iommu_table_entry *start,
-			 struct iommu_table_entry *finish);
-
-#endif /* _ASM_X86_IOMMU_TABLE_H */
diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
deleted file mode 100644
index ff6c92eff035a..0000000000000
--- a/arch/x86/include/asm/swiotlb.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_X86_SWIOTLB_H
-#define _ASM_X86_SWIOTLB_H
-
-#include <linux/swiotlb.h>
-
-#ifdef CONFIG_SWIOTLB
-extern int swiotlb;
-extern int __init pci_swiotlb_detect_override(void);
-extern int __init pci_swiotlb_detect_4gb(void);
-extern void __init pci_swiotlb_init(void);
-extern void __init pci_swiotlb_late_init(void);
-#else
-#define swiotlb 0
-static inline int pci_swiotlb_detect_override(void)
-{
-	return 0;
-}
-static inline int pci_swiotlb_detect_4gb(void)
-{
-	return 0;
-}
-static inline void pci_swiotlb_init(void)
-{
-}
-static inline void pci_swiotlb_late_init(void)
-{
-}
-#endif
-#endif /* _ASM_X86_SWIOTLB_H */
diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h
index 66b4ddde77430..e5a90b42e4dde 100644
--- a/arch/x86/include/asm/xen/swiotlb-xen.h
+++ b/arch/x86/include/asm/xen/swiotlb-xen.h
@@ -3,10 +3,8 @@
 #define _ASM_X86_SWIOTLB_XEN_H
 
 #ifdef CONFIG_SWIOTLB_XEN
-extern int __init pci_xen_swiotlb_detect(void);
 extern int pci_xen_swiotlb_init_late(void);
 #else
-#define pci_xen_swiotlb_detect NULL
 static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
 #endif
 
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index c41ef42adbe8a..e17b7e92a3fa3 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -68,7 +68,6 @@ obj-y			+= bootflag.o e820.o
 obj-y			+= pci-dma.o quirks.o topology.o kdebugfs.o
 obj-y			+= alternative.o i8253.o hw_breakpoint.o
 obj-y			+= tsc.o tsc_msr.o io_delay.o rtc.o
-obj-y			+= pci-iommu_table.o
 obj-y			+= resource.o
 obj-y			+= irqflags.o
 obj-y			+= static_call.o
@@ -134,7 +133,6 @@ obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
 
 obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
 
-obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
 obj-$(CONFIG_OF)			+= devicetree.o
 obj-$(CONFIG_UPROBES)			+= uprobes.o
 
diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
index ed837383de5c8..194d54eed5376 100644
--- a/arch/x86/kernel/amd_gart_64.c
+++ b/arch/x86/kernel/amd_gart_64.c
@@ -38,11 +38,9 @@
 #include <asm/iommu.h>
 #include <asm/gart.h>
 #include <asm/set_memory.h>
-#include <asm/swiotlb.h>
 #include <asm/dma.h>
 #include <asm/amd_nb.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
 
 static unsigned long iommu_bus_base;	/* GART remapping area (physical) */
 static unsigned long iommu_size;	/* size of remapping area bytes */
@@ -808,7 +806,7 @@ int __init gart_iommu_init(void)
 	flush_gart();
 	dma_ops = &gart_dma_ops;
 	x86_platform.iommu_shutdown = gart_iommu_shutdown;
-	swiotlb = 0;
+	x86_swiotlb_enable = false;
 
 	return 0;
 }
@@ -842,4 +840,3 @@ void __init gart_parse_options(char *p)
 		}
 	}
 }
-IOMMU_INIT_POST(gart_iommu_hole_init);
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index af3ba08b684b5..7a5630d904b23 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -392,7 +392,7 @@ void __init early_gart_iommu_check(void)
 
 static int __initdata printed_gart_size_msg;
 
-int __init gart_iommu_hole_init(void)
+void __init gart_iommu_hole_init(void)
 {
 	u32 agp_aper_base = 0, agp_aper_order = 0;
 	u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0;
@@ -401,11 +401,11 @@ int __init gart_iommu_hole_init(void)
 	int i, node;
 
 	if (!amd_gart_present())
-		return -ENODEV;
+		return;
 
 	if (gart_iommu_aperture_disabled || !fix_aperture ||
 	    !early_pci_allowed())
-		return -ENODEV;
+		return;
 
 	pr_info("Checking aperture...\n");
 
@@ -491,10 +491,8 @@ int __init gart_iommu_hole_init(void)
 			 * and fixed up the northbridge
 			 */
 			exclude_from_core(last_aper_base, last_aper_order);
-
-			return 1;
 		}
-		return 0;
+		return;
 	}
 
 	if (!fallback_aper_force) {
@@ -527,7 +525,7 @@ int __init gart_iommu_hole_init(void)
 			panic("Not enough memory for aperture");
 		}
 	} else {
-		return 0;
+		return;
 	}
 
 	/*
@@ -561,6 +559,4 @@ int __init gart_iommu_hole_init(void)
 	}
 
 	set_up_gart_resume(aper_order, aper_alloc);
-
-	return 1;
 }
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index de234e7a8962e..df96926421be0 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -7,13 +7,16 @@
 #include <linux/memblock.h>
 #include <linux/gfp.h>
 #include <linux/pci.h>
+#include <linux/amd-iommu.h>
 
 #include <asm/proto.h>
 #include <asm/dma.h>
 #include <asm/iommu.h>
 #include <asm/gart.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
+
+#include <xen/xen.h>
+#include <xen/swiotlb-xen.h>
 
 static bool disable_dac_quirk __read_mostly;
 
@@ -34,24 +37,83 @@ int no_iommu __read_mostly;
 /* Set this to 1 if there is a HW IOMMU in the system */
 int iommu_detected __read_mostly = 0;
 
-extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
+#ifdef CONFIG_SWIOTLB
+bool x86_swiotlb_enable;
+
+static void __init pci_swiotlb_detect(void)
+{
+	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
+	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
+		x86_swiotlb_enable = true;
+
+	/*
+	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
+	 * devices that can't support DMA to encrypted memory.
+	 */
+	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
+		x86_swiotlb_enable = true;
+
+	if (swiotlb_force == SWIOTLB_FORCE)
+		x86_swiotlb_enable = true;
+}
+#else
+static inline void __init pci_swiotlb_detect(void)
+{
+}
+#endif /* CONFIG_SWIOTLB */
+
+#ifdef CONFIG_SWIOTLB_XEN
+static bool xen_swiotlb;
+
+static void __init pci_xen_swiotlb_init(void)
+{
+	if (!xen_initial_domain() && !x86_swiotlb_enable &&
+	    swiotlb_force != SWIOTLB_FORCE)
+		return;
+	x86_swiotlb_enable = true;
+	xen_swiotlb = true;
+	xen_swiotlb_init_early();
+	dma_ops = &xen_swiotlb_dma_ops;
+	if (IS_ENABLED(CONFIG_PCI))
+		pci_request_acs();
+}
+
+int pci_xen_swiotlb_init_late(void)
+{
+	int rc;
+
+	if (xen_swiotlb)
+		return 0;
+
+	rc = xen_swiotlb_init();
+	if (rc)
+		return rc;
+
+	/* XXX: this switches the dma ops under live devices! */
+	dma_ops = &xen_swiotlb_dma_ops;
+	if (IS_ENABLED(CONFIG_PCI))
+		pci_request_acs();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
+#else
+static inline void __init pci_xen_swiotlb_init(void)
+{
+}
+#endif /* CONFIG_SWIOTLB_XEN */
 
 void __init pci_iommu_alloc(void)
 {
-	struct iommu_table_entry *p;
-
-	sort_iommu_table(__iommu_table, __iommu_table_end);
-	check_iommu_entries(__iommu_table, __iommu_table_end);
-
-	for (p = __iommu_table; p < __iommu_table_end; p++) {
-		if (p && p->detect && p->detect() > 0) {
-			p->flags |= IOMMU_DETECTED;
-			if (p->early_init)
-				p->early_init();
-			if (p->flags & IOMMU_FINISH_IF_DETECTED)
-				break;
-		}
+	if (xen_pv_domain()) {
+		pci_xen_swiotlb_init();
+		return;
 	}
+	pci_swiotlb_detect();
+	gart_iommu_hole_init();
+	amd_iommu_detect();
+	detect_intel_iommu();
+	if (x86_swiotlb_enable)
+		swiotlb_init(0);
 }
 
 /*
@@ -102,7 +164,7 @@ static __init int iommu_setup(char *p)
 		}
 #ifdef CONFIG_SWIOTLB
 		if (!strncmp(p, "soft", 4))
-			swiotlb = 1;
+			x86_swiotlb_enable = true;
 #endif
 		if (!strncmp(p, "pt", 2))
 			iommu_set_default_passthrough(true);
@@ -121,14 +183,17 @@ early_param("iommu", iommu_setup);
 
 static int __init pci_iommu_init(void)
 {
-	struct iommu_table_entry *p;
-
 	x86_init.iommu.iommu_init();
 
-	for (p = __iommu_table; p < __iommu_table_end; p++) {
-		if (p && (p->flags & IOMMU_DETECTED) && p->late_init)
-			p->late_init();
+#ifdef CONFIG_SWIOTLB
+	/* An IOMMU turned us off. */
+	if (x86_swiotlb_enable) {
+		pr_info("PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
+		swiotlb_print_info();
+	} else {
+		swiotlb_exit();
 	}
+#endif
 
 	return 0;
 }
diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
deleted file mode 100644
index 42e92ec62973b..0000000000000
--- a/arch/x86/kernel/pci-iommu_table.c
+++ /dev/null
@@ -1,77 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/dma-mapping.h>
-#include <asm/iommu_table.h>
-#include <linux/string.h>
-#include <linux/kallsyms.h>
-
-static struct iommu_table_entry * __init
-find_dependents_of(struct iommu_table_entry *start,
-		   struct iommu_table_entry *finish,
-		   struct iommu_table_entry *q)
-{
-	struct iommu_table_entry *p;
-
-	if (!q)
-		return NULL;
-
-	for (p = start; p < finish; p++)
-		if (p->detect == q->depend)
-			return p;
-
-	return NULL;
-}
-
-
-void __init sort_iommu_table(struct iommu_table_entry *start,
-			     struct iommu_table_entry *finish) {
-
-	struct iommu_table_entry *p, *q, tmp;
-
-	for (p = start; p < finish; p++) {
-again:
-		q = find_dependents_of(start, finish, p);
-		/* We are bit sneaky here. We use the memory address to figure
-		 * out if the node we depend on is past our point, if so, swap.
-		 */
-		if (q > p) {
-			tmp = *p;
-			memmove(p, q, sizeof(*p));
-			*q = tmp;
-			goto again;
-		}
-	}
-
-}
-
-#ifdef DEBUG
-void __init check_iommu_entries(struct iommu_table_entry *start,
-				struct iommu_table_entry *finish)
-{
-	struct iommu_table_entry *p, *q, *x;
-
-	/* Simple cyclic dependency checker. */
-	for (p = start; p < finish; p++) {
-		q = find_dependents_of(start, finish, p);
-		x = find_dependents_of(start, finish, q);
-		if (p == x) {
-			printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %pS depends on %pS and vice-versa. BREAKING IT.\n",
-			       p->detect, q->detect);
-			/* Heavy handed way..*/
-			x->depend = NULL;
-		}
-	}
-
-	for (p = start; p < finish; p++) {
-		q = find_dependents_of(p, finish, p);
-		if (q && q > p) {
-			printk(KERN_ERR "EXECUTION ORDER INVALID! %pS should be called before %pS!\n",
-			       p->detect, q->detect);
-		}
-	}
-}
-#else
-void __init check_iommu_entries(struct iommu_table_entry *start,
-				       struct iommu_table_entry *finish)
-{
-}
-#endif
diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
deleted file mode 100644
index 814ab46a0dada..0000000000000
--- a/arch/x86/kernel/pci-swiotlb.c
+++ /dev/null
@@ -1,77 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/pci.h>
-#include <linux/cache.h>
-#include <linux/init.h>
-#include <linux/swiotlb.h>
-#include <linux/memblock.h>
-#include <linux/dma-direct.h>
-#include <linux/cc_platform.h>
-
-#include <asm/iommu.h>
-#include <asm/swiotlb.h>
-#include <asm/dma.h>
-#include <asm/xen/swiotlb-xen.h>
-#include <asm/iommu_table.h>
-
-int swiotlb __read_mostly;
-
-/*
- * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
- *
- * This returns non-zero if we are forced to use swiotlb (by the boot
- * option).
- */
-int __init pci_swiotlb_detect_override(void)
-{
-	if (swiotlb_force == SWIOTLB_FORCE)
-		swiotlb = 1;
-
-	return swiotlb;
-}
-IOMMU_INIT_FINISH(pci_swiotlb_detect_override,
-		  pci_xen_swiotlb_detect,
-		  pci_swiotlb_init,
-		  pci_swiotlb_late_init);
-
-/*
- * If 4GB or more detected (and iommu=off not set) or if SME is active
- * then set swiotlb to 1 and return 1.
- */
-int __init pci_swiotlb_detect_4gb(void)
-{
-	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
-	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
-		swiotlb = 1;
-
-	/*
-	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
-	 * devices that can't support DMA to encrypted memory.
-	 */
-	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
-		swiotlb = 1;
-
-	return swiotlb;
-}
-IOMMU_INIT(pci_swiotlb_detect_4gb,
-	   pci_swiotlb_detect_override,
-	   pci_swiotlb_init,
-	   pci_swiotlb_late_init);
-
-void __init pci_swiotlb_init(void)
-{
-	if (swiotlb)
-		swiotlb_init(0);
-}
-
-void __init pci_swiotlb_late_init(void)
-{
-	/* An IOMMU turned us off. */
-	if (!swiotlb)
-		swiotlb_exit();
-	else {
-		printk(KERN_INFO "PCI-DMA: "
-		       "Using software bounce buffering for IO (SWIOTLB)\n");
-		swiotlb_print_info();
-	}
-}
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index f9af561c3cd4f..0c1154a1c4032 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -24,7 +24,6 @@
 #include <asm/processor.h>
 #include <asm/bootparam.h>
 #include <asm/pgalloc.h>
-#include <asm/swiotlb.h>
 #include <asm/fixmap.h>
 #include <asm/proto.h>
 #include <asm/setup.h>
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 7fda7f27e7620..f5f6dc2e80072 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -315,18 +315,6 @@ SECTIONS
 		*(.altinstr_replacement)
 	}
 
-	/*
-	 * struct iommu_table_entry entries are injected in this section.
-	 * It is an array of IOMMUs which during run time gets sorted depending
-	 * on its dependency order. After rootfs_initcall is complete
-	 * this section can be safely removed.
-	 */
-	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
-		__iommu_table = .;
-		*(.iommu_table)
-		__iommu_table_end = .;
-	}
-
 	. = ALIGN(8);
 	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
 		__apicdrivers = .;
diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
index 4953260e281c3..3c5b52fbe4a7f 100644
--- a/arch/x86/xen/Makefile
+++ b/arch/x86/xen/Makefile
@@ -47,6 +47,4 @@ obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
 
 obj-$(CONFIG_XEN_PV_DOM0)	+= vga.o
 
-obj-$(CONFIG_SWIOTLB_XEN)	+= pci-swiotlb-xen.o
-
 obj-$(CONFIG_XEN_EFI)		+= efi.o
diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
deleted file mode 100644
index 46df59aeaa06a..0000000000000
--- a/arch/x86/xen/pci-swiotlb-xen.c
+++ /dev/null
@@ -1,96 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-/* Glue code to lib/swiotlb-xen.c */
-
-#include <linux/dma-map-ops.h>
-#include <linux/pci.h>
-#include <xen/swiotlb-xen.h>
-
-#include <asm/xen/hypervisor.h>
-#include <xen/xen.h>
-#include <asm/iommu_table.h>
-
-
-#include <asm/xen/swiotlb-xen.h>
-#ifdef CONFIG_X86_64
-#include <asm/iommu.h>
-#include <asm/dma.h>
-#endif
-#include <linux/export.h>
-
-static int xen_swiotlb __read_mostly;
-
-/*
- * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
- *
- * This returns non-zero if we are forced to use xen_swiotlb (by the boot
- * option).
- */
-int __init pci_xen_swiotlb_detect(void)
-{
-
-	if (!xen_pv_domain())
-		return 0;
-
-	/* If running as PV guest, either iommu=soft, or swiotlb=force will
-	 * activate this IOMMU. If running as PV privileged, activate it
-	 * irregardless.
-	 */
-	if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
-		xen_swiotlb = 1;
-
-	/* If we are running under Xen, we MUST disable the native SWIOTLB.
-	 * Don't worry about swiotlb_force flag activating the native, as
-	 * the 'swiotlb' flag is the only one turning it on. */
-	swiotlb = 0;
-
-#ifdef CONFIG_X86_64
-	/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
-	 * (so no iommu=X command line over-writes).
-	 * Considering that PV guests do not want the *native SWIOTLB* but
-	 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
-	 */
-	if (max_pfn > MAX_DMA32_PFN)
-		no_iommu = 1;
-#endif
-	return xen_swiotlb;
-}
-
-static void __init pci_xen_swiotlb_init(void)
-{
-	if (xen_swiotlb) {
-		xen_swiotlb_init_early();
-		dma_ops = &xen_swiotlb_dma_ops;
-
-#ifdef CONFIG_PCI
-		/* Make sure ACS will be enabled */
-		pci_request_acs();
-#endif
-	}
-}
-
-int pci_xen_swiotlb_init_late(void)
-{
-	int rc;
-
-	if (xen_swiotlb)
-		return 0;
-
-	rc = xen_swiotlb_init();
-	if (rc)
-		return rc;
-
-	dma_ops = &xen_swiotlb_dma_ops;
-#ifdef CONFIG_PCI
-	/* Make sure ACS will be enabled */
-	pci_request_acs();
-#endif
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
-
-IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
-		  NULL,
-		  pci_xen_swiotlb_init,
-		  NULL);
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index b4a798c7b347f..1a3ad58ba8465 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -27,7 +27,6 @@
 #include <asm/apic.h>
 #include <asm/gart.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
 #include <asm/io_apic.h>
 #include <asm/irq_remapping.h>
 #include <asm/set_memory.h>
@@ -3257,11 +3256,6 @@ __setup("ivrs_ioapic",		parse_ivrs_ioapic);
 __setup("ivrs_hpet",		parse_ivrs_hpet);
 __setup("ivrs_acpihid",		parse_ivrs_acpihid);
 
-IOMMU_INIT_FINISH(amd_iommu_detect,
-		  gart_iommu_hole_init,
-		  NULL,
-		  NULL);
-
 bool amd_iommu_v2_supported(void)
 {
 	return amd_iommu_v2_present;
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index a1ada7bff44e6..b47220ac09eaa 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -1840,7 +1840,10 @@ void amd_iommu_domain_update(struct protection_domain *domain)
 
 static void __init amd_iommu_init_dma_ops(void)
 {
-	swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
+	if (iommu_default_passthrough() || sme_me_mask)
+		x86_swiotlb_enable = true;
+	else
+		x86_swiotlb_enable = false;
 }
 
 int __init amd_iommu_init_api(void)
diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
index 4de960834a1b2..592c1e1a5d4b9 100644
--- a/drivers/iommu/intel/dmar.c
+++ b/drivers/iommu/intel/dmar.c
@@ -30,7 +30,6 @@
 #include <linux/numa.h>
 #include <linux/limits.h>
 #include <asm/irq_remapping.h>
-#include <asm/iommu_table.h>
 #include <trace/events/intel_iommu.h>
 
 #include "../irq_remapping.h"
@@ -912,7 +911,7 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)
 	return 0;
 }
 
-int __init detect_intel_iommu(void)
+void __init detect_intel_iommu(void)
 {
 	int ret;
 	struct dmar_res_callback validate_drhd_cb = {
@@ -945,8 +944,6 @@ int __init detect_intel_iommu(void)
 		dmar_tbl = NULL;
 	}
 	up_write(&dmar_global_lock);
-
-	return ret ? ret : 1;
 }
 
 static void unmap_iommu(struct intel_iommu *iommu)
@@ -2164,7 +2161,6 @@ static int __init dmar_free_unused_resources(void)
 }
 
 late_initcall(dmar_free_unused_resources);
-IOMMU_INIT_POST(detect_intel_iommu);
 
 /*
  * DMAR Hotplug Support
diff --git a/include/linux/dmar.h b/include/linux/dmar.h
index 45e903d847335..cbd714a198a0a 100644
--- a/include/linux/dmar.h
+++ b/include/linux/dmar.h
@@ -121,7 +121,7 @@ extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
 				 u16 segment, struct dmar_dev_scope *devices,
 				 int count);
 /* Intel IOMMU detection */
-extern int detect_intel_iommu(void);
+void detect_intel_iommu(void);
 extern int enable_drhd_fault_handling(void);
 extern int dmar_device_add(acpi_handle handle);
 extern int dmar_device_remove(acpi_handle handle);
@@ -197,6 +197,10 @@ static inline bool dmar_platform_optin(void)
 	return false;
 }
 
+static inline void detect_intel_iommu(void)
+{
+}
+
 #endif /* CONFIG_DMAR_TABLE */
 
 struct irte {
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 07/15] x86: remove the IOMMU table infrastructure
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

The IOMMU table tries to separate the different IOMMUs into different
backends, but actually requires various cross calls.

Rewrite the code to do the generic swiotlb/swiotlb-xen setup directly
in pci-dma.c and then just call into the IOMMU drivers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/ia64/include/asm/iommu_table.h    |   7 --
 arch/x86/include/asm/dma-mapping.h     |   1 -
 arch/x86/include/asm/gart.h            |   5 +-
 arch/x86/include/asm/iommu.h           |   6 ++
 arch/x86/include/asm/iommu_table.h     | 102 -----------------------
 arch/x86/include/asm/swiotlb.h         |  30 -------
 arch/x86/include/asm/xen/swiotlb-xen.h |   2 -
 arch/x86/kernel/Makefile               |   2 -
 arch/x86/kernel/amd_gart_64.c          |   5 +-
 arch/x86/kernel/aperture_64.c          |  14 ++--
 arch/x86/kernel/pci-dma.c              | 107 ++++++++++++++++++++-----
 arch/x86/kernel/pci-iommu_table.c      |  77 ------------------
 arch/x86/kernel/pci-swiotlb.c          |  77 ------------------
 arch/x86/kernel/tboot.c                |   1 -
 arch/x86/kernel/vmlinux.lds.S          |  12 ---
 arch/x86/xen/Makefile                  |   2 -
 arch/x86/xen/pci-swiotlb-xen.c         |  96 ----------------------
 drivers/iommu/amd/init.c               |   6 --
 drivers/iommu/amd/iommu.c              |   5 +-
 drivers/iommu/intel/dmar.c             |   6 +-
 include/linux/dmar.h                   |   6 +-
 21 files changed, 110 insertions(+), 459 deletions(-)
 delete mode 100644 arch/ia64/include/asm/iommu_table.h
 delete mode 100644 arch/x86/include/asm/iommu_table.h
 delete mode 100644 arch/x86/include/asm/swiotlb.h
 delete mode 100644 arch/x86/kernel/pci-iommu_table.c
 delete mode 100644 arch/x86/kernel/pci-swiotlb.c
 delete mode 100644 arch/x86/xen/pci-swiotlb-xen.c

diff --git a/arch/ia64/include/asm/iommu_table.h b/arch/ia64/include/asm/iommu_table.h
deleted file mode 100644
index cc96116ac276a..0000000000000
--- a/arch/ia64/include/asm/iommu_table.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_IA64_IOMMU_TABLE_H
-#define _ASM_IA64_IOMMU_TABLE_H
-
-#define IOMMU_INIT_POST(_detect)
-
-#endif /* _ASM_IA64_IOMMU_TABLE_H */
diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index bb1654fe0ce74..256fd8115223d 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -9,7 +9,6 @@
 
 #include <linux/scatterlist.h>
 #include <asm/io.h>
-#include <asm/swiotlb.h>
 
 extern int iommu_merge;
 extern int panic_on_overflow;
diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
index 3185565743459..5af8088a10df6 100644
--- a/arch/x86/include/asm/gart.h
+++ b/arch/x86/include/asm/gart.h
@@ -38,7 +38,7 @@ extern int gart_iommu_aperture_disabled;
 extern void early_gart_iommu_check(void);
 extern int gart_iommu_init(void);
 extern void __init gart_parse_options(char *);
-extern int gart_iommu_hole_init(void);
+void gart_iommu_hole_init(void);
 
 #else
 #define gart_iommu_aperture            0
@@ -51,9 +51,8 @@ static inline void early_gart_iommu_check(void)
 static inline void gart_parse_options(char *options)
 {
 }
-static inline int gart_iommu_hole_init(void)
+static inline void gart_iommu_hole_init(void)
 {
-	return -ENODEV;
 }
 #endif
 
diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
index bf1ed2ddc74bd..dba89ed40d38d 100644
--- a/arch/x86/include/asm/iommu.h
+++ b/arch/x86/include/asm/iommu.h
@@ -9,6 +9,12 @@
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
 
+#ifdef CONFIG_SWIOTLB
+extern bool x86_swiotlb_enable;
+#else
+#define x86_swiotlb_enable false
+#endif
+
 /* 10 seconds */
 #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
 
diff --git a/arch/x86/include/asm/iommu_table.h b/arch/x86/include/asm/iommu_table.h
deleted file mode 100644
index 1fb3fd1a83c25..0000000000000
--- a/arch/x86/include/asm/iommu_table.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_X86_IOMMU_TABLE_H
-#define _ASM_X86_IOMMU_TABLE_H
-
-#include <asm/swiotlb.h>
-
-/*
- * History lesson:
- * The execution chain of IOMMUs in 2.6.36 looks as so:
- *
- *            [xen-swiotlb]
- *                 |
- *         +----[swiotlb *]--+
- *        /         |         \
- *       /          |          \
- *    [GART]     [Calgary]  [Intel VT-d]
- *     /
- *    /
- * [AMD-Vi]
- *
- * *: if SWIOTLB detected 'iommu=soft'/'swiotlb=force' it would skip
- * over the rest of IOMMUs and unconditionally initialize the SWIOTLB.
- * Also it would surreptitiously initialize set the swiotlb=1 if there were
- * more than 4GB and if the user did not pass in 'iommu=off'. The swiotlb
- * flag would be turned off by all IOMMUs except the Calgary one.
- *
- * The IOMMU_INIT* macros allow a similar tree (or more complex if desired)
- * to be built by defining who we depend on.
- *
- * And all that needs to be done is to use one of the macros in the IOMMU
- * and the pci-dma.c will take care of the rest.
- */
-
-struct iommu_table_entry {
-	initcall_t	detect;
-	initcall_t	depend;
-	void		(*early_init)(void); /* No memory allocate available. */
-	void		(*late_init)(void); /* Yes, can allocate memory. */
-#define IOMMU_FINISH_IF_DETECTED (1<<0)
-#define IOMMU_DETECTED		 (1<<1)
-	int		flags;
-};
-/*
- * Macro fills out an entry in the .iommu_table that is equivalent
- * to the fields that 'struct iommu_table_entry' has. The entries
- * that are put in the .iommu_table section are not put in any order
- * hence during boot-time we will have to resort them based on
- * dependency. */
-
-
-#define __IOMMU_INIT(_detect, _depend, _early_init, _late_init, _finish)\
-	static const struct iommu_table_entry				\
-		__iommu_entry_##_detect __used				\
-	__attribute__ ((unused, __section__(".iommu_table"),		\
-			aligned((sizeof(void *)))))	\
-	= {_detect, _depend, _early_init, _late_init,			\
-	   _finish ? IOMMU_FINISH_IF_DETECTED : 0}
-/*
- * The simplest IOMMU definition. Provide the detection routine
- * and it will be run after the SWIOTLB and the other IOMMUs
- * that utilize this macro. If the IOMMU is detected (ie, the
- * detect routine returns a positive value), the other IOMMUs
- * are also checked. You can use IOMMU_INIT_POST_FINISH if you prefer
- * to stop detecting the other IOMMUs after yours has been detected.
- */
-#define IOMMU_INIT_POST(_detect)					\
-	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 0)
-
-#define IOMMU_INIT_POST_FINISH(detect)					\
-	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 1)
-
-/*
- * A more sophisticated version of IOMMU_INIT. This variant requires:
- *  a). A detection routine function.
- *  b). The name of the detection routine we depend on to get called
- *      before us.
- *  c). The init routine which gets called if the detection routine
- *      returns a positive value from the pci_iommu_alloc. This means
- *      no presence of a memory allocator.
- *  d). Similar to the 'init', except that this gets called from pci_iommu_init
- *      where we do have a memory allocator.
- *
- * The standard IOMMU_INIT differs from the IOMMU_INIT_FINISH variant
- * in that the former will continue detecting other IOMMUs in the call
- * list after the detection routine returns a positive number, while the
- * latter will stop the execution chain upon first successful detection.
- * Both variants will still call the 'init' and 'late_init' functions if
- * they are set.
- */
-#define IOMMU_INIT_FINISH(_detect, _depend, _init, _late_init)		\
-	__IOMMU_INIT(_detect, _depend, _init, _late_init, 1)
-
-#define IOMMU_INIT(_detect, _depend, _init, _late_init)			\
-	__IOMMU_INIT(_detect, _depend, _init, _late_init, 0)
-
-void sort_iommu_table(struct iommu_table_entry *start,
-		      struct iommu_table_entry *finish);
-
-void check_iommu_entries(struct iommu_table_entry *start,
-			 struct iommu_table_entry *finish);
-
-#endif /* _ASM_X86_IOMMU_TABLE_H */
diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
deleted file mode 100644
index ff6c92eff035a..0000000000000
--- a/arch/x86/include/asm/swiotlb.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_X86_SWIOTLB_H
-#define _ASM_X86_SWIOTLB_H
-
-#include <linux/swiotlb.h>
-
-#ifdef CONFIG_SWIOTLB
-extern int swiotlb;
-extern int __init pci_swiotlb_detect_override(void);
-extern int __init pci_swiotlb_detect_4gb(void);
-extern void __init pci_swiotlb_init(void);
-extern void __init pci_swiotlb_late_init(void);
-#else
-#define swiotlb 0
-static inline int pci_swiotlb_detect_override(void)
-{
-	return 0;
-}
-static inline int pci_swiotlb_detect_4gb(void)
-{
-	return 0;
-}
-static inline void pci_swiotlb_init(void)
-{
-}
-static inline void pci_swiotlb_late_init(void)
-{
-}
-#endif
-#endif /* _ASM_X86_SWIOTLB_H */
diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h
index 66b4ddde77430..e5a90b42e4dde 100644
--- a/arch/x86/include/asm/xen/swiotlb-xen.h
+++ b/arch/x86/include/asm/xen/swiotlb-xen.h
@@ -3,10 +3,8 @@
 #define _ASM_X86_SWIOTLB_XEN_H
 
 #ifdef CONFIG_SWIOTLB_XEN
-extern int __init pci_xen_swiotlb_detect(void);
 extern int pci_xen_swiotlb_init_late(void);
 #else
-#define pci_xen_swiotlb_detect NULL
 static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
 #endif
 
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index c41ef42adbe8a..e17b7e92a3fa3 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -68,7 +68,6 @@ obj-y			+= bootflag.o e820.o
 obj-y			+= pci-dma.o quirks.o topology.o kdebugfs.o
 obj-y			+= alternative.o i8253.o hw_breakpoint.o
 obj-y			+= tsc.o tsc_msr.o io_delay.o rtc.o
-obj-y			+= pci-iommu_table.o
 obj-y			+= resource.o
 obj-y			+= irqflags.o
 obj-y			+= static_call.o
@@ -134,7 +133,6 @@ obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
 
 obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
 
-obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
 obj-$(CONFIG_OF)			+= devicetree.o
 obj-$(CONFIG_UPROBES)			+= uprobes.o
 
diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
index ed837383de5c8..194d54eed5376 100644
--- a/arch/x86/kernel/amd_gart_64.c
+++ b/arch/x86/kernel/amd_gart_64.c
@@ -38,11 +38,9 @@
 #include <asm/iommu.h>
 #include <asm/gart.h>
 #include <asm/set_memory.h>
-#include <asm/swiotlb.h>
 #include <asm/dma.h>
 #include <asm/amd_nb.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
 
 static unsigned long iommu_bus_base;	/* GART remapping area (physical) */
 static unsigned long iommu_size;	/* size of remapping area bytes */
@@ -808,7 +806,7 @@ int __init gart_iommu_init(void)
 	flush_gart();
 	dma_ops = &gart_dma_ops;
 	x86_platform.iommu_shutdown = gart_iommu_shutdown;
-	swiotlb = 0;
+	x86_swiotlb_enable = false;
 
 	return 0;
 }
@@ -842,4 +840,3 @@ void __init gart_parse_options(char *p)
 		}
 	}
 }
-IOMMU_INIT_POST(gart_iommu_hole_init);
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index af3ba08b684b5..7a5630d904b23 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -392,7 +392,7 @@ void __init early_gart_iommu_check(void)
 
 static int __initdata printed_gart_size_msg;
 
-int __init gart_iommu_hole_init(void)
+void __init gart_iommu_hole_init(void)
 {
 	u32 agp_aper_base = 0, agp_aper_order = 0;
 	u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0;
@@ -401,11 +401,11 @@ int __init gart_iommu_hole_init(void)
 	int i, node;
 
 	if (!amd_gart_present())
-		return -ENODEV;
+		return;
 
 	if (gart_iommu_aperture_disabled || !fix_aperture ||
 	    !early_pci_allowed())
-		return -ENODEV;
+		return;
 
 	pr_info("Checking aperture...\n");
 
@@ -491,10 +491,8 @@ int __init gart_iommu_hole_init(void)
 			 * and fixed up the northbridge
 			 */
 			exclude_from_core(last_aper_base, last_aper_order);
-
-			return 1;
 		}
-		return 0;
+		return;
 	}
 
 	if (!fallback_aper_force) {
@@ -527,7 +525,7 @@ int __init gart_iommu_hole_init(void)
 			panic("Not enough memory for aperture");
 		}
 	} else {
-		return 0;
+		return;
 	}
 
 	/*
@@ -561,6 +559,4 @@ int __init gart_iommu_hole_init(void)
 	}
 
 	set_up_gart_resume(aper_order, aper_alloc);
-
-	return 1;
 }
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index de234e7a8962e..df96926421be0 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -7,13 +7,16 @@
 #include <linux/memblock.h>
 #include <linux/gfp.h>
 #include <linux/pci.h>
+#include <linux/amd-iommu.h>
 
 #include <asm/proto.h>
 #include <asm/dma.h>
 #include <asm/iommu.h>
 #include <asm/gart.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
+
+#include <xen/xen.h>
+#include <xen/swiotlb-xen.h>
 
 static bool disable_dac_quirk __read_mostly;
 
@@ -34,24 +37,83 @@ int no_iommu __read_mostly;
 /* Set this to 1 if there is a HW IOMMU in the system */
 int iommu_detected __read_mostly = 0;
 
-extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
+#ifdef CONFIG_SWIOTLB
+bool x86_swiotlb_enable;
+
+static void __init pci_swiotlb_detect(void)
+{
+	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
+	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
+		x86_swiotlb_enable = true;
+
+	/*
+	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
+	 * devices that can't support DMA to encrypted memory.
+	 */
+	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
+		x86_swiotlb_enable = true;
+
+	if (swiotlb_force == SWIOTLB_FORCE)
+		x86_swiotlb_enable = true;
+}
+#else
+static inline void __init pci_swiotlb_detect(void)
+{
+}
+#endif /* CONFIG_SWIOTLB */
+
+#ifdef CONFIG_SWIOTLB_XEN
+static bool xen_swiotlb;
+
+static void __init pci_xen_swiotlb_init(void)
+{
+	if (!xen_initial_domain() && !x86_swiotlb_enable &&
+	    swiotlb_force != SWIOTLB_FORCE)
+		return;
+	x86_swiotlb_enable = true;
+	xen_swiotlb = true;
+	xen_swiotlb_init_early();
+	dma_ops = &xen_swiotlb_dma_ops;
+	if (IS_ENABLED(CONFIG_PCI))
+		pci_request_acs();
+}
+
+int pci_xen_swiotlb_init_late(void)
+{
+	int rc;
+
+	if (xen_swiotlb)
+		return 0;
+
+	rc = xen_swiotlb_init();
+	if (rc)
+		return rc;
+
+	/* XXX: this switches the dma ops under live devices! */
+	dma_ops = &xen_swiotlb_dma_ops;
+	if (IS_ENABLED(CONFIG_PCI))
+		pci_request_acs();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
+#else
+static inline void __init pci_xen_swiotlb_init(void)
+{
+}
+#endif /* CONFIG_SWIOTLB_XEN */
 
 void __init pci_iommu_alloc(void)
 {
-	struct iommu_table_entry *p;
-
-	sort_iommu_table(__iommu_table, __iommu_table_end);
-	check_iommu_entries(__iommu_table, __iommu_table_end);
-
-	for (p = __iommu_table; p < __iommu_table_end; p++) {
-		if (p && p->detect && p->detect() > 0) {
-			p->flags |= IOMMU_DETECTED;
-			if (p->early_init)
-				p->early_init();
-			if (p->flags & IOMMU_FINISH_IF_DETECTED)
-				break;
-		}
+	if (xen_pv_domain()) {
+		pci_xen_swiotlb_init();
+		return;
 	}
+	pci_swiotlb_detect();
+	gart_iommu_hole_init();
+	amd_iommu_detect();
+	detect_intel_iommu();
+	if (x86_swiotlb_enable)
+		swiotlb_init(0);
 }
 
 /*
@@ -102,7 +164,7 @@ static __init int iommu_setup(char *p)
 		}
 #ifdef CONFIG_SWIOTLB
 		if (!strncmp(p, "soft", 4))
-			swiotlb = 1;
+			x86_swiotlb_enable = true;
 #endif
 		if (!strncmp(p, "pt", 2))
 			iommu_set_default_passthrough(true);
@@ -121,14 +183,17 @@ early_param("iommu", iommu_setup);
 
 static int __init pci_iommu_init(void)
 {
-	struct iommu_table_entry *p;
-
 	x86_init.iommu.iommu_init();
 
-	for (p = __iommu_table; p < __iommu_table_end; p++) {
-		if (p && (p->flags & IOMMU_DETECTED) && p->late_init)
-			p->late_init();
+#ifdef CONFIG_SWIOTLB
+	/* An IOMMU turned us off. */
+	if (x86_swiotlb_enable) {
+		pr_info("PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
+		swiotlb_print_info();
+	} else {
+		swiotlb_exit();
 	}
+#endif
 
 	return 0;
 }
diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
deleted file mode 100644
index 42e92ec62973b..0000000000000
--- a/arch/x86/kernel/pci-iommu_table.c
+++ /dev/null
@@ -1,77 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/dma-mapping.h>
-#include <asm/iommu_table.h>
-#include <linux/string.h>
-#include <linux/kallsyms.h>
-
-static struct iommu_table_entry * __init
-find_dependents_of(struct iommu_table_entry *start,
-		   struct iommu_table_entry *finish,
-		   struct iommu_table_entry *q)
-{
-	struct iommu_table_entry *p;
-
-	if (!q)
-		return NULL;
-
-	for (p = start; p < finish; p++)
-		if (p->detect == q->depend)
-			return p;
-
-	return NULL;
-}
-
-
-void __init sort_iommu_table(struct iommu_table_entry *start,
-			     struct iommu_table_entry *finish) {
-
-	struct iommu_table_entry *p, *q, tmp;
-
-	for (p = start; p < finish; p++) {
-again:
-		q = find_dependents_of(start, finish, p);
-		/* We are bit sneaky here. We use the memory address to figure
-		 * out if the node we depend on is past our point, if so, swap.
-		 */
-		if (q > p) {
-			tmp = *p;
-			memmove(p, q, sizeof(*p));
-			*q = tmp;
-			goto again;
-		}
-	}
-
-}
-
-#ifdef DEBUG
-void __init check_iommu_entries(struct iommu_table_entry *start,
-				struct iommu_table_entry *finish)
-{
-	struct iommu_table_entry *p, *q, *x;
-
-	/* Simple cyclic dependency checker. */
-	for (p = start; p < finish; p++) {
-		q = find_dependents_of(start, finish, p);
-		x = find_dependents_of(start, finish, q);
-		if (p == x) {
-			printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %pS depends on %pS and vice-versa. BREAKING IT.\n",
-			       p->detect, q->detect);
-			/* Heavy handed way..*/
-			x->depend = NULL;
-		}
-	}
-
-	for (p = start; p < finish; p++) {
-		q = find_dependents_of(p, finish, p);
-		if (q && q > p) {
-			printk(KERN_ERR "EXECUTION ORDER INVALID! %pS should be called before %pS!\n",
-			       p->detect, q->detect);
-		}
-	}
-}
-#else
-void __init check_iommu_entries(struct iommu_table_entry *start,
-				       struct iommu_table_entry *finish)
-{
-}
-#endif
diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
deleted file mode 100644
index 814ab46a0dada..0000000000000
--- a/arch/x86/kernel/pci-swiotlb.c
+++ /dev/null
@@ -1,77 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/pci.h>
-#include <linux/cache.h>
-#include <linux/init.h>
-#include <linux/swiotlb.h>
-#include <linux/memblock.h>
-#include <linux/dma-direct.h>
-#include <linux/cc_platform.h>
-
-#include <asm/iommu.h>
-#include <asm/swiotlb.h>
-#include <asm/dma.h>
-#include <asm/xen/swiotlb-xen.h>
-#include <asm/iommu_table.h>
-
-int swiotlb __read_mostly;
-
-/*
- * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
- *
- * This returns non-zero if we are forced to use swiotlb (by the boot
- * option).
- */
-int __init pci_swiotlb_detect_override(void)
-{
-	if (swiotlb_force == SWIOTLB_FORCE)
-		swiotlb = 1;
-
-	return swiotlb;
-}
-IOMMU_INIT_FINISH(pci_swiotlb_detect_override,
-		  pci_xen_swiotlb_detect,
-		  pci_swiotlb_init,
-		  pci_swiotlb_late_init);
-
-/*
- * If 4GB or more detected (and iommu=off not set) or if SME is active
- * then set swiotlb to 1 and return 1.
- */
-int __init pci_swiotlb_detect_4gb(void)
-{
-	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
-	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
-		swiotlb = 1;
-
-	/*
-	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
-	 * devices that can't support DMA to encrypted memory.
-	 */
-	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
-		swiotlb = 1;
-
-	return swiotlb;
-}
-IOMMU_INIT(pci_swiotlb_detect_4gb,
-	   pci_swiotlb_detect_override,
-	   pci_swiotlb_init,
-	   pci_swiotlb_late_init);
-
-void __init pci_swiotlb_init(void)
-{
-	if (swiotlb)
-		swiotlb_init(0);
-}
-
-void __init pci_swiotlb_late_init(void)
-{
-	/* An IOMMU turned us off. */
-	if (!swiotlb)
-		swiotlb_exit();
-	else {
-		printk(KERN_INFO "PCI-DMA: "
-		       "Using software bounce buffering for IO (SWIOTLB)\n");
-		swiotlb_print_info();
-	}
-}
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index f9af561c3cd4f..0c1154a1c4032 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -24,7 +24,6 @@
 #include <asm/processor.h>
 #include <asm/bootparam.h>
 #include <asm/pgalloc.h>
-#include <asm/swiotlb.h>
 #include <asm/fixmap.h>
 #include <asm/proto.h>
 #include <asm/setup.h>
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 7fda7f27e7620..f5f6dc2e80072 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -315,18 +315,6 @@ SECTIONS
 		*(.altinstr_replacement)
 	}
 
-	/*
-	 * struct iommu_table_entry entries are injected in this section.
-	 * It is an array of IOMMUs which during run time gets sorted depending
-	 * on its dependency order. After rootfs_initcall is complete
-	 * this section can be safely removed.
-	 */
-	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
-		__iommu_table = .;
-		*(.iommu_table)
-		__iommu_table_end = .;
-	}
-
 	. = ALIGN(8);
 	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
 		__apicdrivers = .;
diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
index 4953260e281c3..3c5b52fbe4a7f 100644
--- a/arch/x86/xen/Makefile
+++ b/arch/x86/xen/Makefile
@@ -47,6 +47,4 @@ obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
 
 obj-$(CONFIG_XEN_PV_DOM0)	+= vga.o
 
-obj-$(CONFIG_SWIOTLB_XEN)	+= pci-swiotlb-xen.o
-
 obj-$(CONFIG_XEN_EFI)		+= efi.o
diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
deleted file mode 100644
index 46df59aeaa06a..0000000000000
--- a/arch/x86/xen/pci-swiotlb-xen.c
+++ /dev/null
@@ -1,96 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-/* Glue code to lib/swiotlb-xen.c */
-
-#include <linux/dma-map-ops.h>
-#include <linux/pci.h>
-#include <xen/swiotlb-xen.h>
-
-#include <asm/xen/hypervisor.h>
-#include <xen/xen.h>
-#include <asm/iommu_table.h>
-
-
-#include <asm/xen/swiotlb-xen.h>
-#ifdef CONFIG_X86_64
-#include <asm/iommu.h>
-#include <asm/dma.h>
-#endif
-#include <linux/export.h>
-
-static int xen_swiotlb __read_mostly;
-
-/*
- * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
- *
- * This returns non-zero if we are forced to use xen_swiotlb (by the boot
- * option).
- */
-int __init pci_xen_swiotlb_detect(void)
-{
-
-	if (!xen_pv_domain())
-		return 0;
-
-	/* If running as PV guest, either iommu=soft, or swiotlb=force will
-	 * activate this IOMMU. If running as PV privileged, activate it
-	 * irregardless.
-	 */
-	if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
-		xen_swiotlb = 1;
-
-	/* If we are running under Xen, we MUST disable the native SWIOTLB.
-	 * Don't worry about swiotlb_force flag activating the native, as
-	 * the 'swiotlb' flag is the only one turning it on. */
-	swiotlb = 0;
-
-#ifdef CONFIG_X86_64
-	/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
-	 * (so no iommu=X command line over-writes).
-	 * Considering that PV guests do not want the *native SWIOTLB* but
-	 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
-	 */
-	if (max_pfn > MAX_DMA32_PFN)
-		no_iommu = 1;
-#endif
-	return xen_swiotlb;
-}
-
-static void __init pci_xen_swiotlb_init(void)
-{
-	if (xen_swiotlb) {
-		xen_swiotlb_init_early();
-		dma_ops = &xen_swiotlb_dma_ops;
-
-#ifdef CONFIG_PCI
-		/* Make sure ACS will be enabled */
-		pci_request_acs();
-#endif
-	}
-}
-
-int pci_xen_swiotlb_init_late(void)
-{
-	int rc;
-
-	if (xen_swiotlb)
-		return 0;
-
-	rc = xen_swiotlb_init();
-	if (rc)
-		return rc;
-
-	dma_ops = &xen_swiotlb_dma_ops;
-#ifdef CONFIG_PCI
-	/* Make sure ACS will be enabled */
-	pci_request_acs();
-#endif
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
-
-IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
-		  NULL,
-		  pci_xen_swiotlb_init,
-		  NULL);
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index b4a798c7b347f..1a3ad58ba8465 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -27,7 +27,6 @@
 #include <asm/apic.h>
 #include <asm/gart.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
 #include <asm/io_apic.h>
 #include <asm/irq_remapping.h>
 #include <asm/set_memory.h>
@@ -3257,11 +3256,6 @@ __setup("ivrs_ioapic",		parse_ivrs_ioapic);
 __setup("ivrs_hpet",		parse_ivrs_hpet);
 __setup("ivrs_acpihid",		parse_ivrs_acpihid);
 
-IOMMU_INIT_FINISH(amd_iommu_detect,
-		  gart_iommu_hole_init,
-		  NULL,
-		  NULL);
-
 bool amd_iommu_v2_supported(void)
 {
 	return amd_iommu_v2_present;
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index a1ada7bff44e6..b47220ac09eaa 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -1840,7 +1840,10 @@ void amd_iommu_domain_update(struct protection_domain *domain)
 
 static void __init amd_iommu_init_dma_ops(void)
 {
-	swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
+	if (iommu_default_passthrough() || sme_me_mask)
+		x86_swiotlb_enable = true;
+	else
+		x86_swiotlb_enable = false;
 }
 
 int __init amd_iommu_init_api(void)
diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
index 4de960834a1b2..592c1e1a5d4b9 100644
--- a/drivers/iommu/intel/dmar.c
+++ b/drivers/iommu/intel/dmar.c
@@ -30,7 +30,6 @@
 #include <linux/numa.h>
 #include <linux/limits.h>
 #include <asm/irq_remapping.h>
-#include <asm/iommu_table.h>
 #include <trace/events/intel_iommu.h>
 
 #include "../irq_remapping.h"
@@ -912,7 +911,7 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)
 	return 0;
 }
 
-int __init detect_intel_iommu(void)
+void __init detect_intel_iommu(void)
 {
 	int ret;
 	struct dmar_res_callback validate_drhd_cb = {
@@ -945,8 +944,6 @@ int __init detect_intel_iommu(void)
 		dmar_tbl = NULL;
 	}
 	up_write(&dmar_global_lock);
-
-	return ret ? ret : 1;
 }
 
 static void unmap_iommu(struct intel_iommu *iommu)
@@ -2164,7 +2161,6 @@ static int __init dmar_free_unused_resources(void)
 }
 
 late_initcall(dmar_free_unused_resources);
-IOMMU_INIT_POST(detect_intel_iommu);
 
 /*
  * DMAR Hotplug Support
diff --git a/include/linux/dmar.h b/include/linux/dmar.h
index 45e903d847335..cbd714a198a0a 100644
--- a/include/linux/dmar.h
+++ b/include/linux/dmar.h
@@ -121,7 +121,7 @@ extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
 				 u16 segment, struct dmar_dev_scope *devices,
 				 int count);
 /* Intel IOMMU detection */
-extern int detect_intel_iommu(void);
+void detect_intel_iommu(void);
 extern int enable_drhd_fault_handling(void);
 extern int dmar_device_add(acpi_handle handle);
 extern int dmar_device_remove(acpi_handle handle);
@@ -197,6 +197,10 @@ static inline bool dmar_platform_optin(void)
 	return false;
 }
 
+static inline void detect_intel_iommu(void)
+{
+}
+
 #endif /* CONFIG_DMAR_TABLE */
 
 struct irte {
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 07/15] x86: remove the IOMMU table infrastructure
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

The IOMMU table tries to separate the different IOMMUs into different
backends, but actually requires various cross calls.

Rewrite the code to do the generic swiotlb/swiotlb-xen setup directly
in pci-dma.c and then just call into the IOMMU drivers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/ia64/include/asm/iommu_table.h    |   7 --
 arch/x86/include/asm/dma-mapping.h     |   1 -
 arch/x86/include/asm/gart.h            |   5 +-
 arch/x86/include/asm/iommu.h           |   6 ++
 arch/x86/include/asm/iommu_table.h     | 102 -----------------------
 arch/x86/include/asm/swiotlb.h         |  30 -------
 arch/x86/include/asm/xen/swiotlb-xen.h |   2 -
 arch/x86/kernel/Makefile               |   2 -
 arch/x86/kernel/amd_gart_64.c          |   5 +-
 arch/x86/kernel/aperture_64.c          |  14 ++--
 arch/x86/kernel/pci-dma.c              | 107 ++++++++++++++++++++-----
 arch/x86/kernel/pci-iommu_table.c      |  77 ------------------
 arch/x86/kernel/pci-swiotlb.c          |  77 ------------------
 arch/x86/kernel/tboot.c                |   1 -
 arch/x86/kernel/vmlinux.lds.S          |  12 ---
 arch/x86/xen/Makefile                  |   2 -
 arch/x86/xen/pci-swiotlb-xen.c         |  96 ----------------------
 drivers/iommu/amd/init.c               |   6 --
 drivers/iommu/amd/iommu.c              |   5 +-
 drivers/iommu/intel/dmar.c             |   6 +-
 include/linux/dmar.h                   |   6 +-
 21 files changed, 110 insertions(+), 459 deletions(-)
 delete mode 100644 arch/ia64/include/asm/iommu_table.h
 delete mode 100644 arch/x86/include/asm/iommu_table.h
 delete mode 100644 arch/x86/include/asm/swiotlb.h
 delete mode 100644 arch/x86/kernel/pci-iommu_table.c
 delete mode 100644 arch/x86/kernel/pci-swiotlb.c
 delete mode 100644 arch/x86/xen/pci-swiotlb-xen.c

diff --git a/arch/ia64/include/asm/iommu_table.h b/arch/ia64/include/asm/iommu_table.h
deleted file mode 100644
index cc96116ac276a..0000000000000
--- a/arch/ia64/include/asm/iommu_table.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_IA64_IOMMU_TABLE_H
-#define _ASM_IA64_IOMMU_TABLE_H
-
-#define IOMMU_INIT_POST(_detect)
-
-#endif /* _ASM_IA64_IOMMU_TABLE_H */
diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index bb1654fe0ce74..256fd8115223d 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -9,7 +9,6 @@
 
 #include <linux/scatterlist.h>
 #include <asm/io.h>
-#include <asm/swiotlb.h>
 
 extern int iommu_merge;
 extern int panic_on_overflow;
diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
index 3185565743459..5af8088a10df6 100644
--- a/arch/x86/include/asm/gart.h
+++ b/arch/x86/include/asm/gart.h
@@ -38,7 +38,7 @@ extern int gart_iommu_aperture_disabled;
 extern void early_gart_iommu_check(void);
 extern int gart_iommu_init(void);
 extern void __init gart_parse_options(char *);
-extern int gart_iommu_hole_init(void);
+void gart_iommu_hole_init(void);
 
 #else
 #define gart_iommu_aperture            0
@@ -51,9 +51,8 @@ static inline void early_gart_iommu_check(void)
 static inline void gart_parse_options(char *options)
 {
 }
-static inline int gart_iommu_hole_init(void)
+static inline void gart_iommu_hole_init(void)
 {
-	return -ENODEV;
 }
 #endif
 
diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
index bf1ed2ddc74bd..dba89ed40d38d 100644
--- a/arch/x86/include/asm/iommu.h
+++ b/arch/x86/include/asm/iommu.h
@@ -9,6 +9,12 @@
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
 
+#ifdef CONFIG_SWIOTLB
+extern bool x86_swiotlb_enable;
+#else
+#define x86_swiotlb_enable false
+#endif
+
 /* 10 seconds */
 #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
 
diff --git a/arch/x86/include/asm/iommu_table.h b/arch/x86/include/asm/iommu_table.h
deleted file mode 100644
index 1fb3fd1a83c25..0000000000000
--- a/arch/x86/include/asm/iommu_table.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_X86_IOMMU_TABLE_H
-#define _ASM_X86_IOMMU_TABLE_H
-
-#include <asm/swiotlb.h>
-
-/*
- * History lesson:
- * The execution chain of IOMMUs in 2.6.36 looks as so:
- *
- *            [xen-swiotlb]
- *                 |
- *         +----[swiotlb *]--+
- *        /         |         \
- *       /          |          \
- *    [GART]     [Calgary]  [Intel VT-d]
- *     /
- *    /
- * [AMD-Vi]
- *
- * *: if SWIOTLB detected 'iommu=soft'/'swiotlb=force' it would skip
- * over the rest of IOMMUs and unconditionally initialize the SWIOTLB.
- * Also it would surreptitiously initialize set the swiotlb=1 if there were
- * more than 4GB and if the user did not pass in 'iommu=off'. The swiotlb
- * flag would be turned off by all IOMMUs except the Calgary one.
- *
- * The IOMMU_INIT* macros allow a similar tree (or more complex if desired)
- * to be built by defining who we depend on.
- *
- * And all that needs to be done is to use one of the macros in the IOMMU
- * and the pci-dma.c will take care of the rest.
- */
-
-struct iommu_table_entry {
-	initcall_t	detect;
-	initcall_t	depend;
-	void		(*early_init)(void); /* No memory allocate available. */
-	void		(*late_init)(void); /* Yes, can allocate memory. */
-#define IOMMU_FINISH_IF_DETECTED (1<<0)
-#define IOMMU_DETECTED		 (1<<1)
-	int		flags;
-};
-/*
- * Macro fills out an entry in the .iommu_table that is equivalent
- * to the fields that 'struct iommu_table_entry' has. The entries
- * that are put in the .iommu_table section are not put in any order
- * hence during boot-time we will have to resort them based on
- * dependency. */
-
-
-#define __IOMMU_INIT(_detect, _depend, _early_init, _late_init, _finish)\
-	static const struct iommu_table_entry				\
-		__iommu_entry_##_detect __used				\
-	__attribute__ ((unused, __section__(".iommu_table"),		\
-			aligned((sizeof(void *)))))	\
-	= {_detect, _depend, _early_init, _late_init,			\
-	   _finish ? IOMMU_FINISH_IF_DETECTED : 0}
-/*
- * The simplest IOMMU definition. Provide the detection routine
- * and it will be run after the SWIOTLB and the other IOMMUs
- * that utilize this macro. If the IOMMU is detected (ie, the
- * detect routine returns a positive value), the other IOMMUs
- * are also checked. You can use IOMMU_INIT_POST_FINISH if you prefer
- * to stop detecting the other IOMMUs after yours has been detected.
- */
-#define IOMMU_INIT_POST(_detect)					\
-	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 0)
-
-#define IOMMU_INIT_POST_FINISH(detect)					\
-	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 1)
-
-/*
- * A more sophisticated version of IOMMU_INIT. This variant requires:
- *  a). A detection routine function.
- *  b). The name of the detection routine we depend on to get called
- *      before us.
- *  c). The init routine which gets called if the detection routine
- *      returns a positive value from the pci_iommu_alloc. This means
- *      no presence of a memory allocator.
- *  d). Similar to the 'init', except that this gets called from pci_iommu_init
- *      where we do have a memory allocator.
- *
- * The standard IOMMU_INIT differs from the IOMMU_INIT_FINISH variant
- * in that the former will continue detecting other IOMMUs in the call
- * list after the detection routine returns a positive number, while the
- * latter will stop the execution chain upon first successful detection.
- * Both variants will still call the 'init' and 'late_init' functions if
- * they are set.
- */
-#define IOMMU_INIT_FINISH(_detect, _depend, _init, _late_init)		\
-	__IOMMU_INIT(_detect, _depend, _init, _late_init, 1)
-
-#define IOMMU_INIT(_detect, _depend, _init, _late_init)			\
-	__IOMMU_INIT(_detect, _depend, _init, _late_init, 0)
-
-void sort_iommu_table(struct iommu_table_entry *start,
-		      struct iommu_table_entry *finish);
-
-void check_iommu_entries(struct iommu_table_entry *start,
-			 struct iommu_table_entry *finish);
-
-#endif /* _ASM_X86_IOMMU_TABLE_H */
diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
deleted file mode 100644
index ff6c92eff035a..0000000000000
--- a/arch/x86/include/asm/swiotlb.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_X86_SWIOTLB_H
-#define _ASM_X86_SWIOTLB_H
-
-#include <linux/swiotlb.h>
-
-#ifdef CONFIG_SWIOTLB
-extern int swiotlb;
-extern int __init pci_swiotlb_detect_override(void);
-extern int __init pci_swiotlb_detect_4gb(void);
-extern void __init pci_swiotlb_init(void);
-extern void __init pci_swiotlb_late_init(void);
-#else
-#define swiotlb 0
-static inline int pci_swiotlb_detect_override(void)
-{
-	return 0;
-}
-static inline int pci_swiotlb_detect_4gb(void)
-{
-	return 0;
-}
-static inline void pci_swiotlb_init(void)
-{
-}
-static inline void pci_swiotlb_late_init(void)
-{
-}
-#endif
-#endif /* _ASM_X86_SWIOTLB_H */
diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h
index 66b4ddde77430..e5a90b42e4dde 100644
--- a/arch/x86/include/asm/xen/swiotlb-xen.h
+++ b/arch/x86/include/asm/xen/swiotlb-xen.h
@@ -3,10 +3,8 @@
 #define _ASM_X86_SWIOTLB_XEN_H
 
 #ifdef CONFIG_SWIOTLB_XEN
-extern int __init pci_xen_swiotlb_detect(void);
 extern int pci_xen_swiotlb_init_late(void);
 #else
-#define pci_xen_swiotlb_detect NULL
 static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
 #endif
 
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index c41ef42adbe8a..e17b7e92a3fa3 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -68,7 +68,6 @@ obj-y			+= bootflag.o e820.o
 obj-y			+= pci-dma.o quirks.o topology.o kdebugfs.o
 obj-y			+= alternative.o i8253.o hw_breakpoint.o
 obj-y			+= tsc.o tsc_msr.o io_delay.o rtc.o
-obj-y			+= pci-iommu_table.o
 obj-y			+= resource.o
 obj-y			+= irqflags.o
 obj-y			+= static_call.o
@@ -134,7 +133,6 @@ obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
 
 obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
 
-obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
 obj-$(CONFIG_OF)			+= devicetree.o
 obj-$(CONFIG_UPROBES)			+= uprobes.o
 
diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
index ed837383de5c8..194d54eed5376 100644
--- a/arch/x86/kernel/amd_gart_64.c
+++ b/arch/x86/kernel/amd_gart_64.c
@@ -38,11 +38,9 @@
 #include <asm/iommu.h>
 #include <asm/gart.h>
 #include <asm/set_memory.h>
-#include <asm/swiotlb.h>
 #include <asm/dma.h>
 #include <asm/amd_nb.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
 
 static unsigned long iommu_bus_base;	/* GART remapping area (physical) */
 static unsigned long iommu_size;	/* size of remapping area bytes */
@@ -808,7 +806,7 @@ int __init gart_iommu_init(void)
 	flush_gart();
 	dma_ops = &gart_dma_ops;
 	x86_platform.iommu_shutdown = gart_iommu_shutdown;
-	swiotlb = 0;
+	x86_swiotlb_enable = false;
 
 	return 0;
 }
@@ -842,4 +840,3 @@ void __init gart_parse_options(char *p)
 		}
 	}
 }
-IOMMU_INIT_POST(gart_iommu_hole_init);
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index af3ba08b684b5..7a5630d904b23 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -392,7 +392,7 @@ void __init early_gart_iommu_check(void)
 
 static int __initdata printed_gart_size_msg;
 
-int __init gart_iommu_hole_init(void)
+void __init gart_iommu_hole_init(void)
 {
 	u32 agp_aper_base = 0, agp_aper_order = 0;
 	u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0;
@@ -401,11 +401,11 @@ int __init gart_iommu_hole_init(void)
 	int i, node;
 
 	if (!amd_gart_present())
-		return -ENODEV;
+		return;
 
 	if (gart_iommu_aperture_disabled || !fix_aperture ||
 	    !early_pci_allowed())
-		return -ENODEV;
+		return;
 
 	pr_info("Checking aperture...\n");
 
@@ -491,10 +491,8 @@ int __init gart_iommu_hole_init(void)
 			 * and fixed up the northbridge
 			 */
 			exclude_from_core(last_aper_base, last_aper_order);
-
-			return 1;
 		}
-		return 0;
+		return;
 	}
 
 	if (!fallback_aper_force) {
@@ -527,7 +525,7 @@ int __init gart_iommu_hole_init(void)
 			panic("Not enough memory for aperture");
 		}
 	} else {
-		return 0;
+		return;
 	}
 
 	/*
@@ -561,6 +559,4 @@ int __init gart_iommu_hole_init(void)
 	}
 
 	set_up_gart_resume(aper_order, aper_alloc);
-
-	return 1;
 }
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index de234e7a8962e..df96926421be0 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -7,13 +7,16 @@
 #include <linux/memblock.h>
 #include <linux/gfp.h>
 #include <linux/pci.h>
+#include <linux/amd-iommu.h>
 
 #include <asm/proto.h>
 #include <asm/dma.h>
 #include <asm/iommu.h>
 #include <asm/gart.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
+
+#include <xen/xen.h>
+#include <xen/swiotlb-xen.h>
 
 static bool disable_dac_quirk __read_mostly;
 
@@ -34,24 +37,83 @@ int no_iommu __read_mostly;
 /* Set this to 1 if there is a HW IOMMU in the system */
 int iommu_detected __read_mostly = 0;
 
-extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
+#ifdef CONFIG_SWIOTLB
+bool x86_swiotlb_enable;
+
+static void __init pci_swiotlb_detect(void)
+{
+	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
+	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
+		x86_swiotlb_enable = true;
+
+	/*
+	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
+	 * devices that can't support DMA to encrypted memory.
+	 */
+	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
+		x86_swiotlb_enable = true;
+
+	if (swiotlb_force == SWIOTLB_FORCE)
+		x86_swiotlb_enable = true;
+}
+#else
+static inline void __init pci_swiotlb_detect(void)
+{
+}
+#endif /* CONFIG_SWIOTLB */
+
+#ifdef CONFIG_SWIOTLB_XEN
+static bool xen_swiotlb;
+
+static void __init pci_xen_swiotlb_init(void)
+{
+	if (!xen_initial_domain() && !x86_swiotlb_enable &&
+	    swiotlb_force != SWIOTLB_FORCE)
+		return;
+	x86_swiotlb_enable = true;
+	xen_swiotlb = true;
+	xen_swiotlb_init_early();
+	dma_ops = &xen_swiotlb_dma_ops;
+	if (IS_ENABLED(CONFIG_PCI))
+		pci_request_acs();
+}
+
+int pci_xen_swiotlb_init_late(void)
+{
+	int rc;
+
+	if (xen_swiotlb)
+		return 0;
+
+	rc = xen_swiotlb_init();
+	if (rc)
+		return rc;
+
+	/* XXX: this switches the dma ops under live devices! */
+	dma_ops = &xen_swiotlb_dma_ops;
+	if (IS_ENABLED(CONFIG_PCI))
+		pci_request_acs();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
+#else
+static inline void __init pci_xen_swiotlb_init(void)
+{
+}
+#endif /* CONFIG_SWIOTLB_XEN */
 
 void __init pci_iommu_alloc(void)
 {
-	struct iommu_table_entry *p;
-
-	sort_iommu_table(__iommu_table, __iommu_table_end);
-	check_iommu_entries(__iommu_table, __iommu_table_end);
-
-	for (p = __iommu_table; p < __iommu_table_end; p++) {
-		if (p && p->detect && p->detect() > 0) {
-			p->flags |= IOMMU_DETECTED;
-			if (p->early_init)
-				p->early_init();
-			if (p->flags & IOMMU_FINISH_IF_DETECTED)
-				break;
-		}
+	if (xen_pv_domain()) {
+		pci_xen_swiotlb_init();
+		return;
 	}
+	pci_swiotlb_detect();
+	gart_iommu_hole_init();
+	amd_iommu_detect();
+	detect_intel_iommu();
+	if (x86_swiotlb_enable)
+		swiotlb_init(0);
 }
 
 /*
@@ -102,7 +164,7 @@ static __init int iommu_setup(char *p)
 		}
 #ifdef CONFIG_SWIOTLB
 		if (!strncmp(p, "soft", 4))
-			swiotlb = 1;
+			x86_swiotlb_enable = true;
 #endif
 		if (!strncmp(p, "pt", 2))
 			iommu_set_default_passthrough(true);
@@ -121,14 +183,17 @@ early_param("iommu", iommu_setup);
 
 static int __init pci_iommu_init(void)
 {
-	struct iommu_table_entry *p;
-
 	x86_init.iommu.iommu_init();
 
-	for (p = __iommu_table; p < __iommu_table_end; p++) {
-		if (p && (p->flags & IOMMU_DETECTED) && p->late_init)
-			p->late_init();
+#ifdef CONFIG_SWIOTLB
+	/* An IOMMU turned us off. */
+	if (x86_swiotlb_enable) {
+		pr_info("PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
+		swiotlb_print_info();
+	} else {
+		swiotlb_exit();
 	}
+#endif
 
 	return 0;
 }
diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
deleted file mode 100644
index 42e92ec62973b..0000000000000
--- a/arch/x86/kernel/pci-iommu_table.c
+++ /dev/null
@@ -1,77 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/dma-mapping.h>
-#include <asm/iommu_table.h>
-#include <linux/string.h>
-#include <linux/kallsyms.h>
-
-static struct iommu_table_entry * __init
-find_dependents_of(struct iommu_table_entry *start,
-		   struct iommu_table_entry *finish,
-		   struct iommu_table_entry *q)
-{
-	struct iommu_table_entry *p;
-
-	if (!q)
-		return NULL;
-
-	for (p = start; p < finish; p++)
-		if (p->detect == q->depend)
-			return p;
-
-	return NULL;
-}
-
-
-void __init sort_iommu_table(struct iommu_table_entry *start,
-			     struct iommu_table_entry *finish) {
-
-	struct iommu_table_entry *p, *q, tmp;
-
-	for (p = start; p < finish; p++) {
-again:
-		q = find_dependents_of(start, finish, p);
-		/* We are bit sneaky here. We use the memory address to figure
-		 * out if the node we depend on is past our point, if so, swap.
-		 */
-		if (q > p) {
-			tmp = *p;
-			memmove(p, q, sizeof(*p));
-			*q = tmp;
-			goto again;
-		}
-	}
-
-}
-
-#ifdef DEBUG
-void __init check_iommu_entries(struct iommu_table_entry *start,
-				struct iommu_table_entry *finish)
-{
-	struct iommu_table_entry *p, *q, *x;
-
-	/* Simple cyclic dependency checker. */
-	for (p = start; p < finish; p++) {
-		q = find_dependents_of(start, finish, p);
-		x = find_dependents_of(start, finish, q);
-		if (p == x) {
-			printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %pS depends on %pS and vice-versa. BREAKING IT.\n",
-			       p->detect, q->detect);
-			/* Heavy handed way..*/
-			x->depend = NULL;
-		}
-	}
-
-	for (p = start; p < finish; p++) {
-		q = find_dependents_of(p, finish, p);
-		if (q && q > p) {
-			printk(KERN_ERR "EXECUTION ORDER INVALID! %pS should be called before %pS!\n",
-			       p->detect, q->detect);
-		}
-	}
-}
-#else
-void __init check_iommu_entries(struct iommu_table_entry *start,
-				       struct iommu_table_entry *finish)
-{
-}
-#endif
diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
deleted file mode 100644
index 814ab46a0dada..0000000000000
--- a/arch/x86/kernel/pci-swiotlb.c
+++ /dev/null
@@ -1,77 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/pci.h>
-#include <linux/cache.h>
-#include <linux/init.h>
-#include <linux/swiotlb.h>
-#include <linux/memblock.h>
-#include <linux/dma-direct.h>
-#include <linux/cc_platform.h>
-
-#include <asm/iommu.h>
-#include <asm/swiotlb.h>
-#include <asm/dma.h>
-#include <asm/xen/swiotlb-xen.h>
-#include <asm/iommu_table.h>
-
-int swiotlb __read_mostly;
-
-/*
- * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
- *
- * This returns non-zero if we are forced to use swiotlb (by the boot
- * option).
- */
-int __init pci_swiotlb_detect_override(void)
-{
-	if (swiotlb_force == SWIOTLB_FORCE)
-		swiotlb = 1;
-
-	return swiotlb;
-}
-IOMMU_INIT_FINISH(pci_swiotlb_detect_override,
-		  pci_xen_swiotlb_detect,
-		  pci_swiotlb_init,
-		  pci_swiotlb_late_init);
-
-/*
- * If 4GB or more detected (and iommu=off not set) or if SME is active
- * then set swiotlb to 1 and return 1.
- */
-int __init pci_swiotlb_detect_4gb(void)
-{
-	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
-	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
-		swiotlb = 1;
-
-	/*
-	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
-	 * devices that can't support DMA to encrypted memory.
-	 */
-	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
-		swiotlb = 1;
-
-	return swiotlb;
-}
-IOMMU_INIT(pci_swiotlb_detect_4gb,
-	   pci_swiotlb_detect_override,
-	   pci_swiotlb_init,
-	   pci_swiotlb_late_init);
-
-void __init pci_swiotlb_init(void)
-{
-	if (swiotlb)
-		swiotlb_init(0);
-}
-
-void __init pci_swiotlb_late_init(void)
-{
-	/* An IOMMU turned us off. */
-	if (!swiotlb)
-		swiotlb_exit();
-	else {
-		printk(KERN_INFO "PCI-DMA: "
-		       "Using software bounce buffering for IO (SWIOTLB)\n");
-		swiotlb_print_info();
-	}
-}
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index f9af561c3cd4f..0c1154a1c4032 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -24,7 +24,6 @@
 #include <asm/processor.h>
 #include <asm/bootparam.h>
 #include <asm/pgalloc.h>
-#include <asm/swiotlb.h>
 #include <asm/fixmap.h>
 #include <asm/proto.h>
 #include <asm/setup.h>
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 7fda7f27e7620..f5f6dc2e80072 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -315,18 +315,6 @@ SECTIONS
 		*(.altinstr_replacement)
 	}
 
-	/*
-	 * struct iommu_table_entry entries are injected in this section.
-	 * It is an array of IOMMUs which during run time gets sorted depending
-	 * on its dependency order. After rootfs_initcall is complete
-	 * this section can be safely removed.
-	 */
-	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
-		__iommu_table = .;
-		*(.iommu_table)
-		__iommu_table_end = .;
-	}
-
 	. = ALIGN(8);
 	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
 		__apicdrivers = .;
diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
index 4953260e281c3..3c5b52fbe4a7f 100644
--- a/arch/x86/xen/Makefile
+++ b/arch/x86/xen/Makefile
@@ -47,6 +47,4 @@ obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
 
 obj-$(CONFIG_XEN_PV_DOM0)	+= vga.o
 
-obj-$(CONFIG_SWIOTLB_XEN)	+= pci-swiotlb-xen.o
-
 obj-$(CONFIG_XEN_EFI)		+= efi.o
diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
deleted file mode 100644
index 46df59aeaa06a..0000000000000
--- a/arch/x86/xen/pci-swiotlb-xen.c
+++ /dev/null
@@ -1,96 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-/* Glue code to lib/swiotlb-xen.c */
-
-#include <linux/dma-map-ops.h>
-#include <linux/pci.h>
-#include <xen/swiotlb-xen.h>
-
-#include <asm/xen/hypervisor.h>
-#include <xen/xen.h>
-#include <asm/iommu_table.h>
-
-
-#include <asm/xen/swiotlb-xen.h>
-#ifdef CONFIG_X86_64
-#include <asm/iommu.h>
-#include <asm/dma.h>
-#endif
-#include <linux/export.h>
-
-static int xen_swiotlb __read_mostly;
-
-/*
- * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
- *
- * This returns non-zero if we are forced to use xen_swiotlb (by the boot
- * option).
- */
-int __init pci_xen_swiotlb_detect(void)
-{
-
-	if (!xen_pv_domain())
-		return 0;
-
-	/* If running as PV guest, either iommu=soft, or swiotlb=force will
-	 * activate this IOMMU. If running as PV privileged, activate it
-	 * irregardless.
-	 */
-	if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
-		xen_swiotlb = 1;
-
-	/* If we are running under Xen, we MUST disable the native SWIOTLB.
-	 * Don't worry about swiotlb_force flag activating the native, as
-	 * the 'swiotlb' flag is the only one turning it on. */
-	swiotlb = 0;
-
-#ifdef CONFIG_X86_64
-	/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
-	 * (so no iommu=X command line over-writes).
-	 * Considering that PV guests do not want the *native SWIOTLB* but
-	 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
-	 */
-	if (max_pfn > MAX_DMA32_PFN)
-		no_iommu = 1;
-#endif
-	return xen_swiotlb;
-}
-
-static void __init pci_xen_swiotlb_init(void)
-{
-	if (xen_swiotlb) {
-		xen_swiotlb_init_early();
-		dma_ops = &xen_swiotlb_dma_ops;
-
-#ifdef CONFIG_PCI
-		/* Make sure ACS will be enabled */
-		pci_request_acs();
-#endif
-	}
-}
-
-int pci_xen_swiotlb_init_late(void)
-{
-	int rc;
-
-	if (xen_swiotlb)
-		return 0;
-
-	rc = xen_swiotlb_init();
-	if (rc)
-		return rc;
-
-	dma_ops = &xen_swiotlb_dma_ops;
-#ifdef CONFIG_PCI
-	/* Make sure ACS will be enabled */
-	pci_request_acs();
-#endif
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
-
-IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
-		  NULL,
-		  pci_xen_swiotlb_init,
-		  NULL);
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index b4a798c7b347f..1a3ad58ba8465 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -27,7 +27,6 @@
 #include <asm/apic.h>
 #include <asm/gart.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
 #include <asm/io_apic.h>
 #include <asm/irq_remapping.h>
 #include <asm/set_memory.h>
@@ -3257,11 +3256,6 @@ __setup("ivrs_ioapic",		parse_ivrs_ioapic);
 __setup("ivrs_hpet",		parse_ivrs_hpet);
 __setup("ivrs_acpihid",		parse_ivrs_acpihid);
 
-IOMMU_INIT_FINISH(amd_iommu_detect,
-		  gart_iommu_hole_init,
-		  NULL,
-		  NULL);
-
 bool amd_iommu_v2_supported(void)
 {
 	return amd_iommu_v2_present;
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index a1ada7bff44e6..b47220ac09eaa 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -1840,7 +1840,10 @@ void amd_iommu_domain_update(struct protection_domain *domain)
 
 static void __init amd_iommu_init_dma_ops(void)
 {
-	swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
+	if (iommu_default_passthrough() || sme_me_mask)
+		x86_swiotlb_enable = true;
+	else
+		x86_swiotlb_enable = false;
 }
 
 int __init amd_iommu_init_api(void)
diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
index 4de960834a1b2..592c1e1a5d4b9 100644
--- a/drivers/iommu/intel/dmar.c
+++ b/drivers/iommu/intel/dmar.c
@@ -30,7 +30,6 @@
 #include <linux/numa.h>
 #include <linux/limits.h>
 #include <asm/irq_remapping.h>
-#include <asm/iommu_table.h>
 #include <trace/events/intel_iommu.h>
 
 #include "../irq_remapping.h"
@@ -912,7 +911,7 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)
 	return 0;
 }
 
-int __init detect_intel_iommu(void)
+void __init detect_intel_iommu(void)
 {
 	int ret;
 	struct dmar_res_callback validate_drhd_cb = {
@@ -945,8 +944,6 @@ int __init detect_intel_iommu(void)
 		dmar_tbl = NULL;
 	}
 	up_write(&dmar_global_lock);
-
-	return ret ? ret : 1;
 }
 
 static void unmap_iommu(struct intel_iommu *iommu)
@@ -2164,7 +2161,6 @@ static int __init dmar_free_unused_resources(void)
 }
 
 late_initcall(dmar_free_unused_resources);
-IOMMU_INIT_POST(detect_intel_iommu);
 
 /*
  * DMAR Hotplug Support
diff --git a/include/linux/dmar.h b/include/linux/dmar.h
index 45e903d847335..cbd714a198a0a 100644
--- a/include/linux/dmar.h
+++ b/include/linux/dmar.h
@@ -121,7 +121,7 @@ extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
 				 u16 segment, struct dmar_dev_scope *devices,
 				 int count);
 /* Intel IOMMU detection */
-extern int detect_intel_iommu(void);
+void detect_intel_iommu(void);
 extern int enable_drhd_fault_handling(void);
 extern int dmar_device_add(acpi_handle handle);
 extern int dmar_device_remove(acpi_handle handle);
@@ -197,6 +197,10 @@ static inline bool dmar_platform_optin(void)
 	return false;
 }
 
+static inline void detect_intel_iommu(void)
+{
+}
+
 #endif /* CONFIG_DMAR_TABLE */
 
 struct irte {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 07/15] x86: remove the IOMMU table infrastructure
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

The IOMMU table tries to separate the different IOMMUs into different
backends, but actually requires various cross calls.

Rewrite the code to do the generic swiotlb/swiotlb-xen setup directly
in pci-dma.c and then just call into the IOMMU drivers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/ia64/include/asm/iommu_table.h    |   7 --
 arch/x86/include/asm/dma-mapping.h     |   1 -
 arch/x86/include/asm/gart.h            |   5 +-
 arch/x86/include/asm/iommu.h           |   6 ++
 arch/x86/include/asm/iommu_table.h     | 102 -----------------------
 arch/x86/include/asm/swiotlb.h         |  30 -------
 arch/x86/include/asm/xen/swiotlb-xen.h |   2 -
 arch/x86/kernel/Makefile               |   2 -
 arch/x86/kernel/amd_gart_64.c          |   5 +-
 arch/x86/kernel/aperture_64.c          |  14 ++--
 arch/x86/kernel/pci-dma.c              | 107 ++++++++++++++++++++-----
 arch/x86/kernel/pci-iommu_table.c      |  77 ------------------
 arch/x86/kernel/pci-swiotlb.c          |  77 ------------------
 arch/x86/kernel/tboot.c                |   1 -
 arch/x86/kernel/vmlinux.lds.S          |  12 ---
 arch/x86/xen/Makefile                  |   2 -
 arch/x86/xen/pci-swiotlb-xen.c         |  96 ----------------------
 drivers/iommu/amd/init.c               |   6 --
 drivers/iommu/amd/iommu.c              |   5 +-
 drivers/iommu/intel/dmar.c             |   6 +-
 include/linux/dmar.h                   |   6 +-
 21 files changed, 110 insertions(+), 459 deletions(-)
 delete mode 100644 arch/ia64/include/asm/iommu_table.h
 delete mode 100644 arch/x86/include/asm/iommu_table.h
 delete mode 100644 arch/x86/include/asm/swiotlb.h
 delete mode 100644 arch/x86/kernel/pci-iommu_table.c
 delete mode 100644 arch/x86/kernel/pci-swiotlb.c
 delete mode 100644 arch/x86/xen/pci-swiotlb-xen.c

diff --git a/arch/ia64/include/asm/iommu_table.h b/arch/ia64/include/asm/iommu_table.h
deleted file mode 100644
index cc96116ac276a..0000000000000
--- a/arch/ia64/include/asm/iommu_table.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_IA64_IOMMU_TABLE_H
-#define _ASM_IA64_IOMMU_TABLE_H
-
-#define IOMMU_INIT_POST(_detect)
-
-#endif /* _ASM_IA64_IOMMU_TABLE_H */
diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index bb1654fe0ce74..256fd8115223d 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -9,7 +9,6 @@
 
 #include <linux/scatterlist.h>
 #include <asm/io.h>
-#include <asm/swiotlb.h>
 
 extern int iommu_merge;
 extern int panic_on_overflow;
diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
index 3185565743459..5af8088a10df6 100644
--- a/arch/x86/include/asm/gart.h
+++ b/arch/x86/include/asm/gart.h
@@ -38,7 +38,7 @@ extern int gart_iommu_aperture_disabled;
 extern void early_gart_iommu_check(void);
 extern int gart_iommu_init(void);
 extern void __init gart_parse_options(char *);
-extern int gart_iommu_hole_init(void);
+void gart_iommu_hole_init(void);
 
 #else
 #define gart_iommu_aperture            0
@@ -51,9 +51,8 @@ static inline void early_gart_iommu_check(void)
 static inline void gart_parse_options(char *options)
 {
 }
-static inline int gart_iommu_hole_init(void)
+static inline void gart_iommu_hole_init(void)
 {
-	return -ENODEV;
 }
 #endif
 
diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
index bf1ed2ddc74bd..dba89ed40d38d 100644
--- a/arch/x86/include/asm/iommu.h
+++ b/arch/x86/include/asm/iommu.h
@@ -9,6 +9,12 @@
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
 
+#ifdef CONFIG_SWIOTLB
+extern bool x86_swiotlb_enable;
+#else
+#define x86_swiotlb_enable false
+#endif
+
 /* 10 seconds */
 #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
 
diff --git a/arch/x86/include/asm/iommu_table.h b/arch/x86/include/asm/iommu_table.h
deleted file mode 100644
index 1fb3fd1a83c25..0000000000000
--- a/arch/x86/include/asm/iommu_table.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_X86_IOMMU_TABLE_H
-#define _ASM_X86_IOMMU_TABLE_H
-
-#include <asm/swiotlb.h>
-
-/*
- * History lesson:
- * The execution chain of IOMMUs in 2.6.36 looks as so:
- *
- *            [xen-swiotlb]
- *                 |
- *         +----[swiotlb *]--+
- *        /         |         \
- *       /          |          \
- *    [GART]     [Calgary]  [Intel VT-d]
- *     /
- *    /
- * [AMD-Vi]
- *
- * *: if SWIOTLB detected 'iommu=soft'/'swiotlb=force' it would skip
- * over the rest of IOMMUs and unconditionally initialize the SWIOTLB.
- * Also it would surreptitiously initialize set the swiotlb=1 if there were
- * more than 4GB and if the user did not pass in 'iommu=off'. The swiotlb
- * flag would be turned off by all IOMMUs except the Calgary one.
- *
- * The IOMMU_INIT* macros allow a similar tree (or more complex if desired)
- * to be built by defining who we depend on.
- *
- * And all that needs to be done is to use one of the macros in the IOMMU
- * and the pci-dma.c will take care of the rest.
- */
-
-struct iommu_table_entry {
-	initcall_t	detect;
-	initcall_t	depend;
-	void		(*early_init)(void); /* No memory allocate available. */
-	void		(*late_init)(void); /* Yes, can allocate memory. */
-#define IOMMU_FINISH_IF_DETECTED (1<<0)
-#define IOMMU_DETECTED		 (1<<1)
-	int		flags;
-};
-/*
- * Macro fills out an entry in the .iommu_table that is equivalent
- * to the fields that 'struct iommu_table_entry' has. The entries
- * that are put in the .iommu_table section are not put in any order
- * hence during boot-time we will have to resort them based on
- * dependency. */
-
-
-#define __IOMMU_INIT(_detect, _depend, _early_init, _late_init, _finish)\
-	static const struct iommu_table_entry				\
-		__iommu_entry_##_detect __used				\
-	__attribute__ ((unused, __section__(".iommu_table"),		\
-			aligned((sizeof(void *)))))	\
-	= {_detect, _depend, _early_init, _late_init,			\
-	   _finish ? IOMMU_FINISH_IF_DETECTED : 0}
-/*
- * The simplest IOMMU definition. Provide the detection routine
- * and it will be run after the SWIOTLB and the other IOMMUs
- * that utilize this macro. If the IOMMU is detected (ie, the
- * detect routine returns a positive value), the other IOMMUs
- * are also checked. You can use IOMMU_INIT_POST_FINISH if you prefer
- * to stop detecting the other IOMMUs after yours has been detected.
- */
-#define IOMMU_INIT_POST(_detect)					\
-	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 0)
-
-#define IOMMU_INIT_POST_FINISH(detect)					\
-	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 1)
-
-/*
- * A more sophisticated version of IOMMU_INIT. This variant requires:
- *  a). A detection routine function.
- *  b). The name of the detection routine we depend on to get called
- *      before us.
- *  c). The init routine which gets called if the detection routine
- *      returns a positive value from the pci_iommu_alloc. This means
- *      no presence of a memory allocator.
- *  d). Similar to the 'init', except that this gets called from pci_iommu_init
- *      where we do have a memory allocator.
- *
- * The standard IOMMU_INIT differs from the IOMMU_INIT_FINISH variant
- * in that the former will continue detecting other IOMMUs in the call
- * list after the detection routine returns a positive number, while the
- * latter will stop the execution chain upon first successful detection.
- * Both variants will still call the 'init' and 'late_init' functions if
- * they are set.
- */
-#define IOMMU_INIT_FINISH(_detect, _depend, _init, _late_init)		\
-	__IOMMU_INIT(_detect, _depend, _init, _late_init, 1)
-
-#define IOMMU_INIT(_detect, _depend, _init, _late_init)			\
-	__IOMMU_INIT(_detect, _depend, _init, _late_init, 0)
-
-void sort_iommu_table(struct iommu_table_entry *start,
-		      struct iommu_table_entry *finish);
-
-void check_iommu_entries(struct iommu_table_entry *start,
-			 struct iommu_table_entry *finish);
-
-#endif /* _ASM_X86_IOMMU_TABLE_H */
diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
deleted file mode 100644
index ff6c92eff035a..0000000000000
--- a/arch/x86/include/asm/swiotlb.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_X86_SWIOTLB_H
-#define _ASM_X86_SWIOTLB_H
-
-#include <linux/swiotlb.h>
-
-#ifdef CONFIG_SWIOTLB
-extern int swiotlb;
-extern int __init pci_swiotlb_detect_override(void);
-extern int __init pci_swiotlb_detect_4gb(void);
-extern void __init pci_swiotlb_init(void);
-extern void __init pci_swiotlb_late_init(void);
-#else
-#define swiotlb 0
-static inline int pci_swiotlb_detect_override(void)
-{
-	return 0;
-}
-static inline int pci_swiotlb_detect_4gb(void)
-{
-	return 0;
-}
-static inline void pci_swiotlb_init(void)
-{
-}
-static inline void pci_swiotlb_late_init(void)
-{
-}
-#endif
-#endif /* _ASM_X86_SWIOTLB_H */
diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h
index 66b4ddde77430..e5a90b42e4dde 100644
--- a/arch/x86/include/asm/xen/swiotlb-xen.h
+++ b/arch/x86/include/asm/xen/swiotlb-xen.h
@@ -3,10 +3,8 @@
 #define _ASM_X86_SWIOTLB_XEN_H
 
 #ifdef CONFIG_SWIOTLB_XEN
-extern int __init pci_xen_swiotlb_detect(void);
 extern int pci_xen_swiotlb_init_late(void);
 #else
-#define pci_xen_swiotlb_detect NULL
 static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
 #endif
 
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index c41ef42adbe8a..e17b7e92a3fa3 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -68,7 +68,6 @@ obj-y			+= bootflag.o e820.o
 obj-y			+= pci-dma.o quirks.o topology.o kdebugfs.o
 obj-y			+= alternative.o i8253.o hw_breakpoint.o
 obj-y			+= tsc.o tsc_msr.o io_delay.o rtc.o
-obj-y			+= pci-iommu_table.o
 obj-y			+= resource.o
 obj-y			+= irqflags.o
 obj-y			+= static_call.o
@@ -134,7 +133,6 @@ obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
 
 obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
 
-obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
 obj-$(CONFIG_OF)			+= devicetree.o
 obj-$(CONFIG_UPROBES)			+= uprobes.o
 
diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
index ed837383de5c8..194d54eed5376 100644
--- a/arch/x86/kernel/amd_gart_64.c
+++ b/arch/x86/kernel/amd_gart_64.c
@@ -38,11 +38,9 @@
 #include <asm/iommu.h>
 #include <asm/gart.h>
 #include <asm/set_memory.h>
-#include <asm/swiotlb.h>
 #include <asm/dma.h>
 #include <asm/amd_nb.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
 
 static unsigned long iommu_bus_base;	/* GART remapping area (physical) */
 static unsigned long iommu_size;	/* size of remapping area bytes */
@@ -808,7 +806,7 @@ int __init gart_iommu_init(void)
 	flush_gart();
 	dma_ops = &gart_dma_ops;
 	x86_platform.iommu_shutdown = gart_iommu_shutdown;
-	swiotlb = 0;
+	x86_swiotlb_enable = false;
 
 	return 0;
 }
@@ -842,4 +840,3 @@ void __init gart_parse_options(char *p)
 		}
 	}
 }
-IOMMU_INIT_POST(gart_iommu_hole_init);
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index af3ba08b684b5..7a5630d904b23 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -392,7 +392,7 @@ void __init early_gart_iommu_check(void)
 
 static int __initdata printed_gart_size_msg;
 
-int __init gart_iommu_hole_init(void)
+void __init gart_iommu_hole_init(void)
 {
 	u32 agp_aper_base = 0, agp_aper_order = 0;
 	u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0;
@@ -401,11 +401,11 @@ int __init gart_iommu_hole_init(void)
 	int i, node;
 
 	if (!amd_gart_present())
-		return -ENODEV;
+		return;
 
 	if (gart_iommu_aperture_disabled || !fix_aperture ||
 	    !early_pci_allowed())
-		return -ENODEV;
+		return;
 
 	pr_info("Checking aperture...\n");
 
@@ -491,10 +491,8 @@ int __init gart_iommu_hole_init(void)
 			 * and fixed up the northbridge
 			 */
 			exclude_from_core(last_aper_base, last_aper_order);
-
-			return 1;
 		}
-		return 0;
+		return;
 	}
 
 	if (!fallback_aper_force) {
@@ -527,7 +525,7 @@ int __init gart_iommu_hole_init(void)
 			panic("Not enough memory for aperture");
 		}
 	} else {
-		return 0;
+		return;
 	}
 
 	/*
@@ -561,6 +559,4 @@ int __init gart_iommu_hole_init(void)
 	}
 
 	set_up_gart_resume(aper_order, aper_alloc);
-
-	return 1;
 }
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index de234e7a8962e..df96926421be0 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -7,13 +7,16 @@
 #include <linux/memblock.h>
 #include <linux/gfp.h>
 #include <linux/pci.h>
+#include <linux/amd-iommu.h>
 
 #include <asm/proto.h>
 #include <asm/dma.h>
 #include <asm/iommu.h>
 #include <asm/gart.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
+
+#include <xen/xen.h>
+#include <xen/swiotlb-xen.h>
 
 static bool disable_dac_quirk __read_mostly;
 
@@ -34,24 +37,83 @@ int no_iommu __read_mostly;
 /* Set this to 1 if there is a HW IOMMU in the system */
 int iommu_detected __read_mostly = 0;
 
-extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
+#ifdef CONFIG_SWIOTLB
+bool x86_swiotlb_enable;
+
+static void __init pci_swiotlb_detect(void)
+{
+	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
+	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
+		x86_swiotlb_enable = true;
+
+	/*
+	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
+	 * devices that can't support DMA to encrypted memory.
+	 */
+	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
+		x86_swiotlb_enable = true;
+
+	if (swiotlb_force = SWIOTLB_FORCE)
+		x86_swiotlb_enable = true;
+}
+#else
+static inline void __init pci_swiotlb_detect(void)
+{
+}
+#endif /* CONFIG_SWIOTLB */
+
+#ifdef CONFIG_SWIOTLB_XEN
+static bool xen_swiotlb;
+
+static void __init pci_xen_swiotlb_init(void)
+{
+	if (!xen_initial_domain() && !x86_swiotlb_enable &&
+	    swiotlb_force != SWIOTLB_FORCE)
+		return;
+	x86_swiotlb_enable = true;
+	xen_swiotlb = true;
+	xen_swiotlb_init_early();
+	dma_ops = &xen_swiotlb_dma_ops;
+	if (IS_ENABLED(CONFIG_PCI))
+		pci_request_acs();
+}
+
+int pci_xen_swiotlb_init_late(void)
+{
+	int rc;
+
+	if (xen_swiotlb)
+		return 0;
+
+	rc = xen_swiotlb_init();
+	if (rc)
+		return rc;
+
+	/* XXX: this switches the dma ops under live devices! */
+	dma_ops = &xen_swiotlb_dma_ops;
+	if (IS_ENABLED(CONFIG_PCI))
+		pci_request_acs();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
+#else
+static inline void __init pci_xen_swiotlb_init(void)
+{
+}
+#endif /* CONFIG_SWIOTLB_XEN */
 
 void __init pci_iommu_alloc(void)
 {
-	struct iommu_table_entry *p;
-
-	sort_iommu_table(__iommu_table, __iommu_table_end);
-	check_iommu_entries(__iommu_table, __iommu_table_end);
-
-	for (p = __iommu_table; p < __iommu_table_end; p++) {
-		if (p && p->detect && p->detect() > 0) {
-			p->flags |= IOMMU_DETECTED;
-			if (p->early_init)
-				p->early_init();
-			if (p->flags & IOMMU_FINISH_IF_DETECTED)
-				break;
-		}
+	if (xen_pv_domain()) {
+		pci_xen_swiotlb_init();
+		return;
 	}
+	pci_swiotlb_detect();
+	gart_iommu_hole_init();
+	amd_iommu_detect();
+	detect_intel_iommu();
+	if (x86_swiotlb_enable)
+		swiotlb_init(0);
 }
 
 /*
@@ -102,7 +164,7 @@ static __init int iommu_setup(char *p)
 		}
 #ifdef CONFIG_SWIOTLB
 		if (!strncmp(p, "soft", 4))
-			swiotlb = 1;
+			x86_swiotlb_enable = true;
 #endif
 		if (!strncmp(p, "pt", 2))
 			iommu_set_default_passthrough(true);
@@ -121,14 +183,17 @@ early_param("iommu", iommu_setup);
 
 static int __init pci_iommu_init(void)
 {
-	struct iommu_table_entry *p;
-
 	x86_init.iommu.iommu_init();
 
-	for (p = __iommu_table; p < __iommu_table_end; p++) {
-		if (p && (p->flags & IOMMU_DETECTED) && p->late_init)
-			p->late_init();
+#ifdef CONFIG_SWIOTLB
+	/* An IOMMU turned us off. */
+	if (x86_swiotlb_enable) {
+		pr_info("PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
+		swiotlb_print_info();
+	} else {
+		swiotlb_exit();
 	}
+#endif
 
 	return 0;
 }
diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
deleted file mode 100644
index 42e92ec62973b..0000000000000
--- a/arch/x86/kernel/pci-iommu_table.c
+++ /dev/null
@@ -1,77 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/dma-mapping.h>
-#include <asm/iommu_table.h>
-#include <linux/string.h>
-#include <linux/kallsyms.h>
-
-static struct iommu_table_entry * __init
-find_dependents_of(struct iommu_table_entry *start,
-		   struct iommu_table_entry *finish,
-		   struct iommu_table_entry *q)
-{
-	struct iommu_table_entry *p;
-
-	if (!q)
-		return NULL;
-
-	for (p = start; p < finish; p++)
-		if (p->detect = q->depend)
-			return p;
-
-	return NULL;
-}
-
-
-void __init sort_iommu_table(struct iommu_table_entry *start,
-			     struct iommu_table_entry *finish) {
-
-	struct iommu_table_entry *p, *q, tmp;
-
-	for (p = start; p < finish; p++) {
-again:
-		q = find_dependents_of(start, finish, p);
-		/* We are bit sneaky here. We use the memory address to figure
-		 * out if the node we depend on is past our point, if so, swap.
-		 */
-		if (q > p) {
-			tmp = *p;
-			memmove(p, q, sizeof(*p));
-			*q = tmp;
-			goto again;
-		}
-	}
-
-}
-
-#ifdef DEBUG
-void __init check_iommu_entries(struct iommu_table_entry *start,
-				struct iommu_table_entry *finish)
-{
-	struct iommu_table_entry *p, *q, *x;
-
-	/* Simple cyclic dependency checker. */
-	for (p = start; p < finish; p++) {
-		q = find_dependents_of(start, finish, p);
-		x = find_dependents_of(start, finish, q);
-		if (p = x) {
-			printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %pS depends on %pS and vice-versa. BREAKING IT.\n",
-			       p->detect, q->detect);
-			/* Heavy handed way..*/
-			x->depend = NULL;
-		}
-	}
-
-	for (p = start; p < finish; p++) {
-		q = find_dependents_of(p, finish, p);
-		if (q && q > p) {
-			printk(KERN_ERR "EXECUTION ORDER INVALID! %pS should be called before %pS!\n",
-			       p->detect, q->detect);
-		}
-	}
-}
-#else
-void __init check_iommu_entries(struct iommu_table_entry *start,
-				       struct iommu_table_entry *finish)
-{
-}
-#endif
diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
deleted file mode 100644
index 814ab46a0dada..0000000000000
--- a/arch/x86/kernel/pci-swiotlb.c
+++ /dev/null
@@ -1,77 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/pci.h>
-#include <linux/cache.h>
-#include <linux/init.h>
-#include <linux/swiotlb.h>
-#include <linux/memblock.h>
-#include <linux/dma-direct.h>
-#include <linux/cc_platform.h>
-
-#include <asm/iommu.h>
-#include <asm/swiotlb.h>
-#include <asm/dma.h>
-#include <asm/xen/swiotlb-xen.h>
-#include <asm/iommu_table.h>
-
-int swiotlb __read_mostly;
-
-/*
- * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
- *
- * This returns non-zero if we are forced to use swiotlb (by the boot
- * option).
- */
-int __init pci_swiotlb_detect_override(void)
-{
-	if (swiotlb_force = SWIOTLB_FORCE)
-		swiotlb = 1;
-
-	return swiotlb;
-}
-IOMMU_INIT_FINISH(pci_swiotlb_detect_override,
-		  pci_xen_swiotlb_detect,
-		  pci_swiotlb_init,
-		  pci_swiotlb_late_init);
-
-/*
- * If 4GB or more detected (and iommu=off not set) or if SME is active
- * then set swiotlb to 1 and return 1.
- */
-int __init pci_swiotlb_detect_4gb(void)
-{
-	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
-	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
-		swiotlb = 1;
-
-	/*
-	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
-	 * devices that can't support DMA to encrypted memory.
-	 */
-	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
-		swiotlb = 1;
-
-	return swiotlb;
-}
-IOMMU_INIT(pci_swiotlb_detect_4gb,
-	   pci_swiotlb_detect_override,
-	   pci_swiotlb_init,
-	   pci_swiotlb_late_init);
-
-void __init pci_swiotlb_init(void)
-{
-	if (swiotlb)
-		swiotlb_init(0);
-}
-
-void __init pci_swiotlb_late_init(void)
-{
-	/* An IOMMU turned us off. */
-	if (!swiotlb)
-		swiotlb_exit();
-	else {
-		printk(KERN_INFO "PCI-DMA: "
-		       "Using software bounce buffering for IO (SWIOTLB)\n");
-		swiotlb_print_info();
-	}
-}
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index f9af561c3cd4f..0c1154a1c4032 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -24,7 +24,6 @@
 #include <asm/processor.h>
 #include <asm/bootparam.h>
 #include <asm/pgalloc.h>
-#include <asm/swiotlb.h>
 #include <asm/fixmap.h>
 #include <asm/proto.h>
 #include <asm/setup.h>
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 7fda7f27e7620..f5f6dc2e80072 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -315,18 +315,6 @@ SECTIONS
 		*(.altinstr_replacement)
 	}
 
-	/*
-	 * struct iommu_table_entry entries are injected in this section.
-	 * It is an array of IOMMUs which during run time gets sorted depending
-	 * on its dependency order. After rootfs_initcall is complete
-	 * this section can be safely removed.
-	 */
-	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
-		__iommu_table = .;
-		*(.iommu_table)
-		__iommu_table_end = .;
-	}
-
 	. = ALIGN(8);
 	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
 		__apicdrivers = .;
diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
index 4953260e281c3..3c5b52fbe4a7f 100644
--- a/arch/x86/xen/Makefile
+++ b/arch/x86/xen/Makefile
@@ -47,6 +47,4 @@ obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
 
 obj-$(CONFIG_XEN_PV_DOM0)	+= vga.o
 
-obj-$(CONFIG_SWIOTLB_XEN)	+= pci-swiotlb-xen.o
-
 obj-$(CONFIG_XEN_EFI)		+= efi.o
diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
deleted file mode 100644
index 46df59aeaa06a..0000000000000
--- a/arch/x86/xen/pci-swiotlb-xen.c
+++ /dev/null
@@ -1,96 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-/* Glue code to lib/swiotlb-xen.c */
-
-#include <linux/dma-map-ops.h>
-#include <linux/pci.h>
-#include <xen/swiotlb-xen.h>
-
-#include <asm/xen/hypervisor.h>
-#include <xen/xen.h>
-#include <asm/iommu_table.h>
-
-
-#include <asm/xen/swiotlb-xen.h>
-#ifdef CONFIG_X86_64
-#include <asm/iommu.h>
-#include <asm/dma.h>
-#endif
-#include <linux/export.h>
-
-static int xen_swiotlb __read_mostly;
-
-/*
- * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
- *
- * This returns non-zero if we are forced to use xen_swiotlb (by the boot
- * option).
- */
-int __init pci_xen_swiotlb_detect(void)
-{
-
-	if (!xen_pv_domain())
-		return 0;
-
-	/* If running as PV guest, either iommu=soft, or swiotlb=force will
-	 * activate this IOMMU. If running as PV privileged, activate it
-	 * irregardless.
-	 */
-	if (xen_initial_domain() || swiotlb || swiotlb_force = SWIOTLB_FORCE)
-		xen_swiotlb = 1;
-
-	/* If we are running under Xen, we MUST disable the native SWIOTLB.
-	 * Don't worry about swiotlb_force flag activating the native, as
-	 * the 'swiotlb' flag is the only one turning it on. */
-	swiotlb = 0;
-
-#ifdef CONFIG_X86_64
-	/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu = 0
-	 * (so no iommu=X command line over-writes).
-	 * Considering that PV guests do not want the *native SWIOTLB* but
-	 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
-	 */
-	if (max_pfn > MAX_DMA32_PFN)
-		no_iommu = 1;
-#endif
-	return xen_swiotlb;
-}
-
-static void __init pci_xen_swiotlb_init(void)
-{
-	if (xen_swiotlb) {
-		xen_swiotlb_init_early();
-		dma_ops = &xen_swiotlb_dma_ops;
-
-#ifdef CONFIG_PCI
-		/* Make sure ACS will be enabled */
-		pci_request_acs();
-#endif
-	}
-}
-
-int pci_xen_swiotlb_init_late(void)
-{
-	int rc;
-
-	if (xen_swiotlb)
-		return 0;
-
-	rc = xen_swiotlb_init();
-	if (rc)
-		return rc;
-
-	dma_ops = &xen_swiotlb_dma_ops;
-#ifdef CONFIG_PCI
-	/* Make sure ACS will be enabled */
-	pci_request_acs();
-#endif
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
-
-IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
-		  NULL,
-		  pci_xen_swiotlb_init,
-		  NULL);
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index b4a798c7b347f..1a3ad58ba8465 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -27,7 +27,6 @@
 #include <asm/apic.h>
 #include <asm/gart.h>
 #include <asm/x86_init.h>
-#include <asm/iommu_table.h>
 #include <asm/io_apic.h>
 #include <asm/irq_remapping.h>
 #include <asm/set_memory.h>
@@ -3257,11 +3256,6 @@ __setup("ivrs_ioapic",		parse_ivrs_ioapic);
 __setup("ivrs_hpet",		parse_ivrs_hpet);
 __setup("ivrs_acpihid",		parse_ivrs_acpihid);
 
-IOMMU_INIT_FINISH(amd_iommu_detect,
-		  gart_iommu_hole_init,
-		  NULL,
-		  NULL);
-
 bool amd_iommu_v2_supported(void)
 {
 	return amd_iommu_v2_present;
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index a1ada7bff44e6..b47220ac09eaa 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -1840,7 +1840,10 @@ void amd_iommu_domain_update(struct protection_domain *domain)
 
 static void __init amd_iommu_init_dma_ops(void)
 {
-	swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
+	if (iommu_default_passthrough() || sme_me_mask)
+		x86_swiotlb_enable = true;
+	else
+		x86_swiotlb_enable = false;
 }
 
 int __init amd_iommu_init_api(void)
diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
index 4de960834a1b2..592c1e1a5d4b9 100644
--- a/drivers/iommu/intel/dmar.c
+++ b/drivers/iommu/intel/dmar.c
@@ -30,7 +30,6 @@
 #include <linux/numa.h>
 #include <linux/limits.h>
 #include <asm/irq_remapping.h>
-#include <asm/iommu_table.h>
 #include <trace/events/intel_iommu.h>
 
 #include "../irq_remapping.h"
@@ -912,7 +911,7 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)
 	return 0;
 }
 
-int __init detect_intel_iommu(void)
+void __init detect_intel_iommu(void)
 {
 	int ret;
 	struct dmar_res_callback validate_drhd_cb = {
@@ -945,8 +944,6 @@ int __init detect_intel_iommu(void)
 		dmar_tbl = NULL;
 	}
 	up_write(&dmar_global_lock);
-
-	return ret ? ret : 1;
 }
 
 static void unmap_iommu(struct intel_iommu *iommu)
@@ -2164,7 +2161,6 @@ static int __init dmar_free_unused_resources(void)
 }
 
 late_initcall(dmar_free_unused_resources);
-IOMMU_INIT_POST(detect_intel_iommu);
 
 /*
  * DMAR Hotplug Support
diff --git a/include/linux/dmar.h b/include/linux/dmar.h
index 45e903d847335..cbd714a198a0a 100644
--- a/include/linux/dmar.h
+++ b/include/linux/dmar.h
@@ -121,7 +121,7 @@ extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
 				 u16 segment, struct dmar_dev_scope *devices,
 				 int count);
 /* Intel IOMMU detection */
-extern int detect_intel_iommu(void);
+void detect_intel_iommu(void);
 extern int enable_drhd_fault_handling(void);
 extern int dmar_device_add(acpi_handle handle);
 extern int dmar_device_remove(acpi_handle handle);
@@ -197,6 +197,10 @@ static inline bool dmar_platform_optin(void)
 	return false;
 }
 
+static inline void detect_intel_iommu(void)
+{
+}
+
 #endif /* CONFIG_DMAR_TABLE */
 
 struct irte {
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 08/15] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Move enabling SWIOTLB_FORCE for guest memory encryption into common code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/kernel/cpu/mshyperv.c | 8 --------
 arch/x86/kernel/pci-dma.c      | 8 ++++++++
 arch/x86/mm/mem_encrypt_amd.c  | 3 ---
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 4b67094215bba..5b8f2c3571601 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -337,14 +337,6 @@ static void __init ms_hyperv_init_platform(void)
 			swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary;
 #endif
 		}
-
-#ifdef CONFIG_SWIOTLB
-		/*
-		 * Enable swiotlb force mode in Isolation VM to
-		 * use swiotlb bounce buffer for dma transaction.
-		 */
-		swiotlb_force = SWIOTLB_FORCE;
-#endif
 		/* Isolation VMs are unenlightened SEV-based VMs, thus this check: */
 		if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
 			if (hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE)
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index df96926421be0..04140e20ef1a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -53,6 +53,14 @@ static void __init pci_swiotlb_detect(void)
 	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
 		x86_swiotlb_enable = true;
 
+	/*
+	 * Guest with guest memory encryption currently perform all DMA through
+	 * bounce buffers as the hypervisor can't access arbitrary VM memory
+	 * that is not explicitly shared with it.
+	 */
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
+		swiotlb_force = SWIOTLB_FORCE;
+
 	if (swiotlb_force == SWIOTLB_FORCE)
 		x86_swiotlb_enable = true;
 }
diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c
index 6169053c28541..d732d727d3dee 100644
--- a/arch/x86/mm/mem_encrypt_amd.c
+++ b/arch/x86/mm/mem_encrypt_amd.c
@@ -432,9 +432,6 @@ void __init sme_early_init(void)
 	for (i = 0; i < ARRAY_SIZE(protection_map); i++)
 		protection_map[i] = pgprot_encrypted(protection_map[i]);
 
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
 	x86_platform.guest.enc_status_change_prepare = amd_enc_status_change_prepare;
 	x86_platform.guest.enc_status_change_finish  = amd_enc_status_change_finish;
 	x86_platform.guest.enc_tlb_flush_required    = amd_enc_tlb_flush_required;
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 08/15] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Move enabling SWIOTLB_FORCE for guest memory encryption into common code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/kernel/cpu/mshyperv.c | 8 --------
 arch/x86/kernel/pci-dma.c      | 8 ++++++++
 arch/x86/mm/mem_encrypt_amd.c  | 3 ---
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 4b67094215bba..5b8f2c3571601 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -337,14 +337,6 @@ static void __init ms_hyperv_init_platform(void)
 			swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary;
 #endif
 		}
-
-#ifdef CONFIG_SWIOTLB
-		/*
-		 * Enable swiotlb force mode in Isolation VM to
-		 * use swiotlb bounce buffer for dma transaction.
-		 */
-		swiotlb_force = SWIOTLB_FORCE;
-#endif
 		/* Isolation VMs are unenlightened SEV-based VMs, thus this check: */
 		if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
 			if (hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE)
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index df96926421be0..04140e20ef1a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -53,6 +53,14 @@ static void __init pci_swiotlb_detect(void)
 	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
 		x86_swiotlb_enable = true;
 
+	/*
+	 * Guest with guest memory encryption currently perform all DMA through
+	 * bounce buffers as the hypervisor can't access arbitrary VM memory
+	 * that is not explicitly shared with it.
+	 */
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
+		swiotlb_force = SWIOTLB_FORCE;
+
 	if (swiotlb_force == SWIOTLB_FORCE)
 		x86_swiotlb_enable = true;
 }
diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c
index 6169053c28541..d732d727d3dee 100644
--- a/arch/x86/mm/mem_encrypt_amd.c
+++ b/arch/x86/mm/mem_encrypt_amd.c
@@ -432,9 +432,6 @@ void __init sme_early_init(void)
 	for (i = 0; i < ARRAY_SIZE(protection_map); i++)
 		protection_map[i] = pgprot_encrypted(protection_map[i]);
 
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
 	x86_platform.guest.enc_status_change_prepare = amd_enc_status_change_prepare;
 	x86_platform.guest.enc_status_change_finish  = amd_enc_status_change_finish;
 	x86_platform.guest.enc_tlb_flush_required    = amd_enc_tlb_flush_required;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 08/15] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Move enabling SWIOTLB_FORCE for guest memory encryption into common code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/kernel/cpu/mshyperv.c | 8 --------
 arch/x86/kernel/pci-dma.c      | 8 ++++++++
 arch/x86/mm/mem_encrypt_amd.c  | 3 ---
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 4b67094215bba..5b8f2c3571601 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -337,14 +337,6 @@ static void __init ms_hyperv_init_platform(void)
 			swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary;
 #endif
 		}
-
-#ifdef CONFIG_SWIOTLB
-		/*
-		 * Enable swiotlb force mode in Isolation VM to
-		 * use swiotlb bounce buffer for dma transaction.
-		 */
-		swiotlb_force = SWIOTLB_FORCE;
-#endif
 		/* Isolation VMs are unenlightened SEV-based VMs, thus this check: */
 		if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
 			if (hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE)
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index df96926421be0..04140e20ef1a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -53,6 +53,14 @@ static void __init pci_swiotlb_detect(void)
 	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
 		x86_swiotlb_enable = true;
 
+	/*
+	 * Guest with guest memory encryption currently perform all DMA through
+	 * bounce buffers as the hypervisor can't access arbitrary VM memory
+	 * that is not explicitly shared with it.
+	 */
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
+		swiotlb_force = SWIOTLB_FORCE;
+
 	if (swiotlb_force == SWIOTLB_FORCE)
 		x86_swiotlb_enable = true;
 }
diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c
index 6169053c28541..d732d727d3dee 100644
--- a/arch/x86/mm/mem_encrypt_amd.c
+++ b/arch/x86/mm/mem_encrypt_amd.c
@@ -432,9 +432,6 @@ void __init sme_early_init(void)
 	for (i = 0; i < ARRAY_SIZE(protection_map); i++)
 		protection_map[i] = pgprot_encrypted(protection_map[i]);
 
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
 	x86_platform.guest.enc_status_change_prepare = amd_enc_status_change_prepare;
 	x86_platform.guest.enc_status_change_finish  = amd_enc_status_change_finish;
 	x86_platform.guest.enc_tlb_flush_required    = amd_enc_tlb_flush_required;
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 08/15] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Move enabling SWIOTLB_FORCE for guest memory encryption into common code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/kernel/cpu/mshyperv.c | 8 --------
 arch/x86/kernel/pci-dma.c      | 8 ++++++++
 arch/x86/mm/mem_encrypt_amd.c  | 3 ---
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 4b67094215bba..5b8f2c3571601 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -337,14 +337,6 @@ static void __init ms_hyperv_init_platform(void)
 			swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary;
 #endif
 		}
-
-#ifdef CONFIG_SWIOTLB
-		/*
-		 * Enable swiotlb force mode in Isolation VM to
-		 * use swiotlb bounce buffer for dma transaction.
-		 */
-		swiotlb_force = SWIOTLB_FORCE;
-#endif
 		/* Isolation VMs are unenlightened SEV-based VMs, thus this check: */
 		if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
 			if (hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE)
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index df96926421be0..04140e20ef1a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -53,6 +53,14 @@ static void __init pci_swiotlb_detect(void)
 	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
 		x86_swiotlb_enable = true;
 
+	/*
+	 * Guest with guest memory encryption currently perform all DMA through
+	 * bounce buffers as the hypervisor can't access arbitrary VM memory
+	 * that is not explicitly shared with it.
+	 */
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
+		swiotlb_force = SWIOTLB_FORCE;
+
 	if (swiotlb_force == SWIOTLB_FORCE)
 		x86_swiotlb_enable = true;
 }
diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c
index 6169053c28541..d732d727d3dee 100644
--- a/arch/x86/mm/mem_encrypt_amd.c
+++ b/arch/x86/mm/mem_encrypt_amd.c
@@ -432,9 +432,6 @@ void __init sme_early_init(void)
 	for (i = 0; i < ARRAY_SIZE(protection_map); i++)
 		protection_map[i] = pgprot_encrypted(protection_map[i]);
 
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
 	x86_platform.guest.enc_status_change_prepare = amd_enc_status_change_prepare;
 	x86_platform.guest.enc_status_change_finish  = amd_enc_status_change_finish;
 	x86_platform.guest.enc_tlb_flush_required    = amd_enc_tlb_flush_required;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 08/15] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

Move enabling SWIOTLB_FORCE for guest memory encryption into common code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/kernel/cpu/mshyperv.c | 8 --------
 arch/x86/kernel/pci-dma.c      | 8 ++++++++
 arch/x86/mm/mem_encrypt_amd.c  | 3 ---
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 4b67094215bba..5b8f2c3571601 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -337,14 +337,6 @@ static void __init ms_hyperv_init_platform(void)
 			swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary;
 #endif
 		}
-
-#ifdef CONFIG_SWIOTLB
-		/*
-		 * Enable swiotlb force mode in Isolation VM to
-		 * use swiotlb bounce buffer for dma transaction.
-		 */
-		swiotlb_force = SWIOTLB_FORCE;
-#endif
 		/* Isolation VMs are unenlightened SEV-based VMs, thus this check: */
 		if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
 			if (hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE)
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index df96926421be0..04140e20ef1a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -53,6 +53,14 @@ static void __init pci_swiotlb_detect(void)
 	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
 		x86_swiotlb_enable = true;
 
+	/*
+	 * Guest with guest memory encryption currently perform all DMA through
+	 * bounce buffers as the hypervisor can't access arbitrary VM memory
+	 * that is not explicitly shared with it.
+	 */
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
+		swiotlb_force = SWIOTLB_FORCE;
+
 	if (swiotlb_force == SWIOTLB_FORCE)
 		x86_swiotlb_enable = true;
 }
diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c
index 6169053c28541..d732d727d3dee 100644
--- a/arch/x86/mm/mem_encrypt_amd.c
+++ b/arch/x86/mm/mem_encrypt_amd.c
@@ -432,9 +432,6 @@ void __init sme_early_init(void)
 	for (i = 0; i < ARRAY_SIZE(protection_map); i++)
 		protection_map[i] = pgprot_encrypted(protection_map[i]);
 
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
 	x86_platform.guest.enc_status_change_prepare = amd_enc_status_change_prepare;
 	x86_platform.guest.enc_status_change_finish  = amd_enc_status_change_finish;
 	x86_platform.guest.enc_tlb_flush_required    = amd_enc_tlb_flush_required;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 08/15] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Move enabling SWIOTLB_FORCE for guest memory encryption into common code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/kernel/cpu/mshyperv.c | 8 --------
 arch/x86/kernel/pci-dma.c      | 8 ++++++++
 arch/x86/mm/mem_encrypt_amd.c  | 3 ---
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 4b67094215bba..5b8f2c3571601 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -337,14 +337,6 @@ static void __init ms_hyperv_init_platform(void)
 			swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary;
 #endif
 		}
-
-#ifdef CONFIG_SWIOTLB
-		/*
-		 * Enable swiotlb force mode in Isolation VM to
-		 * use swiotlb bounce buffer for dma transaction.
-		 */
-		swiotlb_force = SWIOTLB_FORCE;
-#endif
 		/* Isolation VMs are unenlightened SEV-based VMs, thus this check: */
 		if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
 			if (hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE)
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index df96926421be0..04140e20ef1a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -53,6 +53,14 @@ static void __init pci_swiotlb_detect(void)
 	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
 		x86_swiotlb_enable = true;
 
+	/*
+	 * Guest with guest memory encryption currently perform all DMA through
+	 * bounce buffers as the hypervisor can't access arbitrary VM memory
+	 * that is not explicitly shared with it.
+	 */
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
+		swiotlb_force = SWIOTLB_FORCE;
+
 	if (swiotlb_force = SWIOTLB_FORCE)
 		x86_swiotlb_enable = true;
 }
diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c
index 6169053c28541..d732d727d3dee 100644
--- a/arch/x86/mm/mem_encrypt_amd.c
+++ b/arch/x86/mm/mem_encrypt_amd.c
@@ -432,9 +432,6 @@ void __init sme_early_init(void)
 	for (i = 0; i < ARRAY_SIZE(protection_map); i++)
 		protection_map[i] = pgprot_encrypted(protection_map[i]);
 
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
 	x86_platform.guest.enc_status_change_prepare = amd_enc_status_change_prepare;
 	x86_platform.guest.enc_status_change_finish  = amd_enc_status_change_finish;
 	x86_platform.guest.enc_tlb_flush_required    = amd_enc_tlb_flush_required;
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Pass a bool to pass if swiotlb needs to be enabled based on the
addressing needs and replace the verbose argument with a set of
flags, including one to force enable bounce buffering.

Note that this patch removes the possibility to force xen-swiotlb
use using swiotlb=force on the command line on x86 (arm and arm64
never supported that), but this interface will be restored shortly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/mm/init.c                     |  6 +----
 arch/arm64/mm/init.c                   |  6 +----
 arch/ia64/mm/init.c                    |  4 +--
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/sibyte/common/dma.c          |  2 +-
 arch/powerpc/mm/mem.c                  |  3 ++-
 arch/powerpc/platforms/pseries/setup.c |  3 ---
 arch/riscv/mm/init.c                   |  8 +-----
 arch/s390/mm/init.c                    |  3 +--
 arch/x86/kernel/pci-dma.c              | 15 ++++++-----
 drivers/xen/swiotlb-xen.c              |  4 +--
 include/linux/swiotlb.h                | 15 ++++++-----
 include/trace/events/swiotlb.h         | 29 ++++++++-------------
 kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
 15 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index fe249ea919083..ce64bdb55a16b 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -271,11 +271,7 @@ static void __init free_highpages(void)
 void __init mem_init(void)
 {
 #ifdef CONFIG_ARM_LPAE
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > arm_dma_pfn_limit)
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
 #endif
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 8ac25f19084e8..7b6ea4d6733d6 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -398,11 +398,7 @@ void __init bootmem_init(void)
  */
 void __init mem_init(void)
 {
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
-		swiotlb_init(1);
-	else if (!xen_swiotlb_detect())
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE);
 
 	/* this will put all unused low memory onto the freelists */
 	memblock_free_all();
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index 5d165607bf354..3c3e15b22608f 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -437,9 +437,7 @@ mem_init (void)
 		if (iommu_detected)
 			break;
 #endif
-#ifdef CONFIG_SWIOTLB
-		swiotlb_init(1);
-#endif
+		swiotlb_init(true, SWIOTLB_VERBOSE);
 	} while (0);
 
 #ifdef CONFIG_FLATMEM
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index fb7547e217263..9fbba6a8fa4c5 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
 #endif
 
 	swiotlb_adjust_size(swiotlbsize);
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index 364f2f27c8723..8220a1bc0db64 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
index eb47a94f3583e..c5c2c782aff68 100644
--- a/arch/mips/sibyte/common/dma.c
+++ b/arch/mips/sibyte/common/dma.c
@@ -10,5 +10,5 @@
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8e301cd8925b2..e1519e2edc656 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -17,6 +17,7 @@
 #include <linux/suspend.h>
 #include <linux/dma-direct.h>
 
+#include <asm/swiotlb.h>
 #include <asm/machdep.h>
 #include <asm/rtas.h>
 #include <asm/kasan.h>
@@ -251,7 +252,7 @@ void __init mem_init(void)
 	if (is_secure_guest())
 		svm_swiotlb_init();
 	else
-		swiotlb_init(0);
+		swiotlb_init(ppc_swiotlb_enable, 0);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 069d7b3bb142e..c6e06d91b6602 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
 	}
 
 	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
-		ppc_swiotlb_enable = 1;
 }
 
 static void pseries_panic(char *str)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 9535bea8688c0..181ffd322eafa 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -120,13 +120,7 @@ void __init mem_init(void)
 	BUG_ON(!mem_map);
 #endif /* CONFIG_FLATMEM */
 
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(dma32_phys_limit))
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
-#endif
+	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
 	memblock_free_all();
 
 	print_vm_layout();
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 86ffd0d51fd59..6fb6bf64326f9 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -185,8 +185,7 @@ static void pv_init(void)
 		return;
 
 	/* make sure bounce buffers are shared */
-	swiotlb_force = SWIOTLB_FORCE;
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
 	swiotlb_update_mem_attributes();
 }
 
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 04140e20ef1a3..a705a199bf8a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
 
 #ifdef CONFIG_SWIOTLB
 bool x86_swiotlb_enable;
+static unsigned int x86_swiotlb_flags;
 
 static void __init pci_swiotlb_detect(void)
 {
@@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
 	 * bounce buffers as the hypervisor can't access arbitrary VM memory
 	 * that is not explicitly shared with it.
 	 */
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
+		x86_swiotlb_flags |= SWIOTLB_FORCE;
+	}
 }
 #else
 static inline void __init pci_swiotlb_detect(void)
 {
 }
+#define x86_swiotlb_flags 0
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
@@ -75,8 +76,7 @@ static bool xen_swiotlb;
 
 static void __init pci_xen_swiotlb_init(void)
 {
-	if (!xen_initial_domain() && !x86_swiotlb_enable &&
-	    swiotlb_force != SWIOTLB_FORCE)
+	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
 	xen_swiotlb = true;
@@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
 	gart_iommu_hole_init();
 	amd_iommu_detect();
 	detect_intel_iommu();
-	if (x86_swiotlb_enable)
-		swiotlb_init(0);
+	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
 }
 
 /*
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 485cd06ed39e7..c2da3eb4826e8 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
 		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
 	}
 
-	if (swiotlb_init_with_tbl(start, nslabs, true))
+	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
 		panic("Cannot allocate SWIOTLB buffer");
 }
 #endif /* CONFIG_X86 */
@@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	/*
 	 * Oh well, have to allocate and map a bounce buffer.
 	 */
-	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+	trace_swiotlb_bounced(dev, dev_addr, size);
 
 	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
 	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index b48b26bfa0edb..ae0407173e845 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -13,11 +13,8 @@ struct device;
 struct page;
 struct scatterlist;
 
-enum swiotlb_force {
-	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc. */
-	SWIOTLB_FORCE,		/* swiotlb=force */
-	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
-};
+#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
+#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
@@ -36,8 +33,7 @@ enum swiotlb_force {
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-extern void swiotlb_init(int verbose);
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 int swiotlb_init_late(size_t size);
@@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
 	return mem && mem->force_bounce;
 }
 
+void swiotlb_init(bool addressing_limited, unsigned int flags);
 void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
 bool is_swiotlb_active(struct device *dev);
 void __init swiotlb_adjust_size(unsigned long size);
 #else
-#define swiotlb_force SWIOTLB_NO_FORCE
+static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
+{
+}
 static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
 {
 	return false;
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index 705be43b71ab0..da05c9ebd224a 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -8,20 +8,15 @@
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(swiotlb_bounced,
-
-	TP_PROTO(struct device *dev,
-		 dma_addr_t dev_addr,
-		 size_t size,
-		 enum swiotlb_force swiotlb_force),
-
-	TP_ARGS(dev, dev_addr, size, swiotlb_force),
+	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
+	TP_ARGS(dev, dev_addr, size),
 
 	TP_STRUCT__entry(
-		__string(	dev_name,	dev_name(dev)		)
-		__field(	u64,	dma_mask			)
-		__field(	dma_addr_t,	dev_addr		)
-		__field(	size_t,	size				)
-		__field(	enum swiotlb_force,	swiotlb_force	)
+		__string(dev_name, dev_name(dev))
+		__field(u64, dma_mask)
+		__field(dma_addr_t, dev_addr)
+		__field(size_t, size)
+		__field(bool, force)
 	),
 
 	TP_fast_assign(
@@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
 		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
 		__entry->dev_addr = dev_addr;
 		__entry->size = size;
-		__entry->swiotlb_force = swiotlb_force;
+		__entry->force = is_swiotlb_force_bounce(dev);
 	),
 
-	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
-		"size=%zu %s",
+	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
 		__get_str(dev_name),
 		__entry->dma_mask,
 		(unsigned long long)__entry->dev_addr,
 		__entry->size,
-		__print_symbolic(__entry->swiotlb_force,
-			{ SWIOTLB_NORMAL,	"NORMAL" },
-			{ SWIOTLB_FORCE,	"FORCE" },
-			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
+		__entry->force ? "FORCE" : "NORMAL")
 );
 
 #endif /*  _TRACE_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 9a4fe6e48a074..86e877a96b828 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -62,7 +62,8 @@
 
 #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
 
-enum swiotlb_force swiotlb_force;
+static bool swiotlb_force_bounce;
+static bool swiotlb_force_disable;
 
 struct io_tlb_mem io_tlb_default_mem;
 
@@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
 	if (*str == ',')
 		++str;
 	if (!strcmp(str, "force"))
-		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_force_bounce = true;
 	else if (!strcmp(str, "noforce"))
-		swiotlb_force = SWIOTLB_NO_FORCE;
+		swiotlb_force_disable = true;
 
 	return 0;
 }
@@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		mem->force_bounce = true;
 
 	spin_lock_init(&mem->lock);
@@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
+int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
+		unsigned int flags)
 {
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	size_t alloc_size;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
 
-	if (verbose)
+	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
 	return 0;
 }
@@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void  __init
-swiotlb_init(int verbose)
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 {
 	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	void *tlb;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (!addressing_limit && !swiotlb_force_bounce)
+		return;
+	if (swiotlb_force_disable)
 		return;
 
 	/* Get IO TLB memory from the low pages */
 	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
+	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
 
@@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
 	unsigned int order;
 	int rc = 0;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/*
@@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long bytes = nslabs << IO_TLB_SHIFT;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		return;
 
 	if (!mem->nslabs)
@@ -704,8 +708,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
 	phys_addr_t swiotlb_addr;
 	dma_addr_t dma_addr;
 
-	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
-			      swiotlb_force);
+	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
 
 	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
 			attrs);
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Pass a bool to pass if swiotlb needs to be enabled based on the
addressing needs and replace the verbose argument with a set of
flags, including one to force enable bounce buffering.

Note that this patch removes the possibility to force xen-swiotlb
use using swiotlb=force on the command line on x86 (arm and arm64
never supported that), but this interface will be restored shortly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/mm/init.c                     |  6 +----
 arch/arm64/mm/init.c                   |  6 +----
 arch/ia64/mm/init.c                    |  4 +--
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/sibyte/common/dma.c          |  2 +-
 arch/powerpc/mm/mem.c                  |  3 ++-
 arch/powerpc/platforms/pseries/setup.c |  3 ---
 arch/riscv/mm/init.c                   |  8 +-----
 arch/s390/mm/init.c                    |  3 +--
 arch/x86/kernel/pci-dma.c              | 15 ++++++-----
 drivers/xen/swiotlb-xen.c              |  4 +--
 include/linux/swiotlb.h                | 15 ++++++-----
 include/trace/events/swiotlb.h         | 29 ++++++++-------------
 kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
 15 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index fe249ea919083..ce64bdb55a16b 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -271,11 +271,7 @@ static void __init free_highpages(void)
 void __init mem_init(void)
 {
 #ifdef CONFIG_ARM_LPAE
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > arm_dma_pfn_limit)
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
 #endif
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 8ac25f19084e8..7b6ea4d6733d6 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -398,11 +398,7 @@ void __init bootmem_init(void)
  */
 void __init mem_init(void)
 {
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
-		swiotlb_init(1);
-	else if (!xen_swiotlb_detect())
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE);
 
 	/* this will put all unused low memory onto the freelists */
 	memblock_free_all();
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index 5d165607bf354..3c3e15b22608f 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -437,9 +437,7 @@ mem_init (void)
 		if (iommu_detected)
 			break;
 #endif
-#ifdef CONFIG_SWIOTLB
-		swiotlb_init(1);
-#endif
+		swiotlb_init(true, SWIOTLB_VERBOSE);
 	} while (0);
 
 #ifdef CONFIG_FLATMEM
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index fb7547e217263..9fbba6a8fa4c5 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
 #endif
 
 	swiotlb_adjust_size(swiotlbsize);
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index 364f2f27c8723..8220a1bc0db64 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
index eb47a94f3583e..c5c2c782aff68 100644
--- a/arch/mips/sibyte/common/dma.c
+++ b/arch/mips/sibyte/common/dma.c
@@ -10,5 +10,5 @@
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8e301cd8925b2..e1519e2edc656 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -17,6 +17,7 @@
 #include <linux/suspend.h>
 #include <linux/dma-direct.h>
 
+#include <asm/swiotlb.h>
 #include <asm/machdep.h>
 #include <asm/rtas.h>
 #include <asm/kasan.h>
@@ -251,7 +252,7 @@ void __init mem_init(void)
 	if (is_secure_guest())
 		svm_swiotlb_init();
 	else
-		swiotlb_init(0);
+		swiotlb_init(ppc_swiotlb_enable, 0);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 069d7b3bb142e..c6e06d91b6602 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
 	}
 
 	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
-		ppc_swiotlb_enable = 1;
 }
 
 static void pseries_panic(char *str)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 9535bea8688c0..181ffd322eafa 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -120,13 +120,7 @@ void __init mem_init(void)
 	BUG_ON(!mem_map);
 #endif /* CONFIG_FLATMEM */
 
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(dma32_phys_limit))
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
-#endif
+	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
 	memblock_free_all();
 
 	print_vm_layout();
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 86ffd0d51fd59..6fb6bf64326f9 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -185,8 +185,7 @@ static void pv_init(void)
 		return;
 
 	/* make sure bounce buffers are shared */
-	swiotlb_force = SWIOTLB_FORCE;
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
 	swiotlb_update_mem_attributes();
 }
 
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 04140e20ef1a3..a705a199bf8a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
 
 #ifdef CONFIG_SWIOTLB
 bool x86_swiotlb_enable;
+static unsigned int x86_swiotlb_flags;
 
 static void __init pci_swiotlb_detect(void)
 {
@@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
 	 * bounce buffers as the hypervisor can't access arbitrary VM memory
 	 * that is not explicitly shared with it.
 	 */
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
+		x86_swiotlb_flags |= SWIOTLB_FORCE;
+	}
 }
 #else
 static inline void __init pci_swiotlb_detect(void)
 {
 }
+#define x86_swiotlb_flags 0
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
@@ -75,8 +76,7 @@ static bool xen_swiotlb;
 
 static void __init pci_xen_swiotlb_init(void)
 {
-	if (!xen_initial_domain() && !x86_swiotlb_enable &&
-	    swiotlb_force != SWIOTLB_FORCE)
+	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
 	xen_swiotlb = true;
@@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
 	gart_iommu_hole_init();
 	amd_iommu_detect();
 	detect_intel_iommu();
-	if (x86_swiotlb_enable)
-		swiotlb_init(0);
+	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
 }
 
 /*
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 485cd06ed39e7..c2da3eb4826e8 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
 		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
 	}
 
-	if (swiotlb_init_with_tbl(start, nslabs, true))
+	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
 		panic("Cannot allocate SWIOTLB buffer");
 }
 #endif /* CONFIG_X86 */
@@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	/*
 	 * Oh well, have to allocate and map a bounce buffer.
 	 */
-	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+	trace_swiotlb_bounced(dev, dev_addr, size);
 
 	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
 	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index b48b26bfa0edb..ae0407173e845 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -13,11 +13,8 @@ struct device;
 struct page;
 struct scatterlist;
 
-enum swiotlb_force {
-	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc. */
-	SWIOTLB_FORCE,		/* swiotlb=force */
-	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
-};
+#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
+#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
@@ -36,8 +33,7 @@ enum swiotlb_force {
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-extern void swiotlb_init(int verbose);
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 int swiotlb_init_late(size_t size);
@@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
 	return mem && mem->force_bounce;
 }
 
+void swiotlb_init(bool addressing_limited, unsigned int flags);
 void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
 bool is_swiotlb_active(struct device *dev);
 void __init swiotlb_adjust_size(unsigned long size);
 #else
-#define swiotlb_force SWIOTLB_NO_FORCE
+static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
+{
+}
 static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
 {
 	return false;
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index 705be43b71ab0..da05c9ebd224a 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -8,20 +8,15 @@
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(swiotlb_bounced,
-
-	TP_PROTO(struct device *dev,
-		 dma_addr_t dev_addr,
-		 size_t size,
-		 enum swiotlb_force swiotlb_force),
-
-	TP_ARGS(dev, dev_addr, size, swiotlb_force),
+	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
+	TP_ARGS(dev, dev_addr, size),
 
 	TP_STRUCT__entry(
-		__string(	dev_name,	dev_name(dev)		)
-		__field(	u64,	dma_mask			)
-		__field(	dma_addr_t,	dev_addr		)
-		__field(	size_t,	size				)
-		__field(	enum swiotlb_force,	swiotlb_force	)
+		__string(dev_name, dev_name(dev))
+		__field(u64, dma_mask)
+		__field(dma_addr_t, dev_addr)
+		__field(size_t, size)
+		__field(bool, force)
 	),
 
 	TP_fast_assign(
@@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
 		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
 		__entry->dev_addr = dev_addr;
 		__entry->size = size;
-		__entry->swiotlb_force = swiotlb_force;
+		__entry->force = is_swiotlb_force_bounce(dev);
 	),
 
-	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
-		"size=%zu %s",
+	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
 		__get_str(dev_name),
 		__entry->dma_mask,
 		(unsigned long long)__entry->dev_addr,
 		__entry->size,
-		__print_symbolic(__entry->swiotlb_force,
-			{ SWIOTLB_NORMAL,	"NORMAL" },
-			{ SWIOTLB_FORCE,	"FORCE" },
-			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
+		__entry->force ? "FORCE" : "NORMAL")
 );
 
 #endif /*  _TRACE_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 9a4fe6e48a074..86e877a96b828 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -62,7 +62,8 @@
 
 #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
 
-enum swiotlb_force swiotlb_force;
+static bool swiotlb_force_bounce;
+static bool swiotlb_force_disable;
 
 struct io_tlb_mem io_tlb_default_mem;
 
@@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
 	if (*str == ',')
 		++str;
 	if (!strcmp(str, "force"))
-		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_force_bounce = true;
 	else if (!strcmp(str, "noforce"))
-		swiotlb_force = SWIOTLB_NO_FORCE;
+		swiotlb_force_disable = true;
 
 	return 0;
 }
@@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		mem->force_bounce = true;
 
 	spin_lock_init(&mem->lock);
@@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
+int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
+		unsigned int flags)
 {
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	size_t alloc_size;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
 
-	if (verbose)
+	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
 	return 0;
 }
@@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void  __init
-swiotlb_init(int verbose)
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 {
 	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	void *tlb;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (!addressing_limit && !swiotlb_force_bounce)
+		return;
+	if (swiotlb_force_disable)
 		return;
 
 	/* Get IO TLB memory from the low pages */
 	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
+	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
 
@@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
 	unsigned int order;
 	int rc = 0;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/*
@@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long bytes = nslabs << IO_TLB_SHIFT;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		return;
 
 	if (!mem->nslabs)
@@ -704,8 +708,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
 	phys_addr_t swiotlb_addr;
 	dma_addr_t dma_addr;
 
-	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
-			      swiotlb_force);
+	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
 
 	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
 			attrs);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Pass a bool to pass if swiotlb needs to be enabled based on the
addressing needs and replace the verbose argument with a set of
flags, including one to force enable bounce buffering.

Note that this patch removes the possibility to force xen-swiotlb
use using swiotlb=force on the command line on x86 (arm and arm64
never supported that), but this interface will be restored shortly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/mm/init.c                     |  6 +----
 arch/arm64/mm/init.c                   |  6 +----
 arch/ia64/mm/init.c                    |  4 +--
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/sibyte/common/dma.c          |  2 +-
 arch/powerpc/mm/mem.c                  |  3 ++-
 arch/powerpc/platforms/pseries/setup.c |  3 ---
 arch/riscv/mm/init.c                   |  8 +-----
 arch/s390/mm/init.c                    |  3 +--
 arch/x86/kernel/pci-dma.c              | 15 ++++++-----
 drivers/xen/swiotlb-xen.c              |  4 +--
 include/linux/swiotlb.h                | 15 ++++++-----
 include/trace/events/swiotlb.h         | 29 ++++++++-------------
 kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
 15 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index fe249ea919083..ce64bdb55a16b 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -271,11 +271,7 @@ static void __init free_highpages(void)
 void __init mem_init(void)
 {
 #ifdef CONFIG_ARM_LPAE
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > arm_dma_pfn_limit)
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
 #endif
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 8ac25f19084e8..7b6ea4d6733d6 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -398,11 +398,7 @@ void __init bootmem_init(void)
  */
 void __init mem_init(void)
 {
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
-		swiotlb_init(1);
-	else if (!xen_swiotlb_detect())
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE);
 
 	/* this will put all unused low memory onto the freelists */
 	memblock_free_all();
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index 5d165607bf354..3c3e15b22608f 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -437,9 +437,7 @@ mem_init (void)
 		if (iommu_detected)
 			break;
 #endif
-#ifdef CONFIG_SWIOTLB
-		swiotlb_init(1);
-#endif
+		swiotlb_init(true, SWIOTLB_VERBOSE);
 	} while (0);
 
 #ifdef CONFIG_FLATMEM
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index fb7547e217263..9fbba6a8fa4c5 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
 #endif
 
 	swiotlb_adjust_size(swiotlbsize);
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index 364f2f27c8723..8220a1bc0db64 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
index eb47a94f3583e..c5c2c782aff68 100644
--- a/arch/mips/sibyte/common/dma.c
+++ b/arch/mips/sibyte/common/dma.c
@@ -10,5 +10,5 @@
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8e301cd8925b2..e1519e2edc656 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -17,6 +17,7 @@
 #include <linux/suspend.h>
 #include <linux/dma-direct.h>
 
+#include <asm/swiotlb.h>
 #include <asm/machdep.h>
 #include <asm/rtas.h>
 #include <asm/kasan.h>
@@ -251,7 +252,7 @@ void __init mem_init(void)
 	if (is_secure_guest())
 		svm_swiotlb_init();
 	else
-		swiotlb_init(0);
+		swiotlb_init(ppc_swiotlb_enable, 0);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 069d7b3bb142e..c6e06d91b6602 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
 	}
 
 	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
-		ppc_swiotlb_enable = 1;
 }
 
 static void pseries_panic(char *str)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 9535bea8688c0..181ffd322eafa 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -120,13 +120,7 @@ void __init mem_init(void)
 	BUG_ON(!mem_map);
 #endif /* CONFIG_FLATMEM */
 
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(dma32_phys_limit))
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
-#endif
+	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
 	memblock_free_all();
 
 	print_vm_layout();
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 86ffd0d51fd59..6fb6bf64326f9 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -185,8 +185,7 @@ static void pv_init(void)
 		return;
 
 	/* make sure bounce buffers are shared */
-	swiotlb_force = SWIOTLB_FORCE;
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
 	swiotlb_update_mem_attributes();
 }
 
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 04140e20ef1a3..a705a199bf8a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
 
 #ifdef CONFIG_SWIOTLB
 bool x86_swiotlb_enable;
+static unsigned int x86_swiotlb_flags;
 
 static void __init pci_swiotlb_detect(void)
 {
@@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
 	 * bounce buffers as the hypervisor can't access arbitrary VM memory
 	 * that is not explicitly shared with it.
 	 */
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
+		x86_swiotlb_flags |= SWIOTLB_FORCE;
+	}
 }
 #else
 static inline void __init pci_swiotlb_detect(void)
 {
 }
+#define x86_swiotlb_flags 0
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
@@ -75,8 +76,7 @@ static bool xen_swiotlb;
 
 static void __init pci_xen_swiotlb_init(void)
 {
-	if (!xen_initial_domain() && !x86_swiotlb_enable &&
-	    swiotlb_force != SWIOTLB_FORCE)
+	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
 	xen_swiotlb = true;
@@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
 	gart_iommu_hole_init();
 	amd_iommu_detect();
 	detect_intel_iommu();
-	if (x86_swiotlb_enable)
-		swiotlb_init(0);
+	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
 }
 
 /*
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 485cd06ed39e7..c2da3eb4826e8 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
 		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
 	}
 
-	if (swiotlb_init_with_tbl(start, nslabs, true))
+	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
 		panic("Cannot allocate SWIOTLB buffer");
 }
 #endif /* CONFIG_X86 */
@@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	/*
 	 * Oh well, have to allocate and map a bounce buffer.
 	 */
-	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+	trace_swiotlb_bounced(dev, dev_addr, size);
 
 	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
 	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index b48b26bfa0edb..ae0407173e845 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -13,11 +13,8 @@ struct device;
 struct page;
 struct scatterlist;
 
-enum swiotlb_force {
-	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc. */
-	SWIOTLB_FORCE,		/* swiotlb=force */
-	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
-};
+#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
+#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
@@ -36,8 +33,7 @@ enum swiotlb_force {
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-extern void swiotlb_init(int verbose);
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 int swiotlb_init_late(size_t size);
@@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
 	return mem && mem->force_bounce;
 }
 
+void swiotlb_init(bool addressing_limited, unsigned int flags);
 void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
 bool is_swiotlb_active(struct device *dev);
 void __init swiotlb_adjust_size(unsigned long size);
 #else
-#define swiotlb_force SWIOTLB_NO_FORCE
+static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
+{
+}
 static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
 {
 	return false;
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index 705be43b71ab0..da05c9ebd224a 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -8,20 +8,15 @@
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(swiotlb_bounced,
-
-	TP_PROTO(struct device *dev,
-		 dma_addr_t dev_addr,
-		 size_t size,
-		 enum swiotlb_force swiotlb_force),
-
-	TP_ARGS(dev, dev_addr, size, swiotlb_force),
+	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
+	TP_ARGS(dev, dev_addr, size),
 
 	TP_STRUCT__entry(
-		__string(	dev_name,	dev_name(dev)		)
-		__field(	u64,	dma_mask			)
-		__field(	dma_addr_t,	dev_addr		)
-		__field(	size_t,	size				)
-		__field(	enum swiotlb_force,	swiotlb_force	)
+		__string(dev_name, dev_name(dev))
+		__field(u64, dma_mask)
+		__field(dma_addr_t, dev_addr)
+		__field(size_t, size)
+		__field(bool, force)
 	),
 
 	TP_fast_assign(
@@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
 		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
 		__entry->dev_addr = dev_addr;
 		__entry->size = size;
-		__entry->swiotlb_force = swiotlb_force;
+		__entry->force = is_swiotlb_force_bounce(dev);
 	),
 
-	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
-		"size=%zu %s",
+	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
 		__get_str(dev_name),
 		__entry->dma_mask,
 		(unsigned long long)__entry->dev_addr,
 		__entry->size,
-		__print_symbolic(__entry->swiotlb_force,
-			{ SWIOTLB_NORMAL,	"NORMAL" },
-			{ SWIOTLB_FORCE,	"FORCE" },
-			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
+		__entry->force ? "FORCE" : "NORMAL")
 );
 
 #endif /*  _TRACE_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 9a4fe6e48a074..86e877a96b828 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -62,7 +62,8 @@
 
 #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
 
-enum swiotlb_force swiotlb_force;
+static bool swiotlb_force_bounce;
+static bool swiotlb_force_disable;
 
 struct io_tlb_mem io_tlb_default_mem;
 
@@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
 	if (*str == ',')
 		++str;
 	if (!strcmp(str, "force"))
-		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_force_bounce = true;
 	else if (!strcmp(str, "noforce"))
-		swiotlb_force = SWIOTLB_NO_FORCE;
+		swiotlb_force_disable = true;
 
 	return 0;
 }
@@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		mem->force_bounce = true;
 
 	spin_lock_init(&mem->lock);
@@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
+int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
+		unsigned int flags)
 {
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	size_t alloc_size;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
 
-	if (verbose)
+	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
 	return 0;
 }
@@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void  __init
-swiotlb_init(int verbose)
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 {
 	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	void *tlb;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (!addressing_limit && !swiotlb_force_bounce)
+		return;
+	if (swiotlb_force_disable)
 		return;
 
 	/* Get IO TLB memory from the low pages */
 	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
+	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
 
@@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
 	unsigned int order;
 	int rc = 0;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/*
@@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long bytes = nslabs << IO_TLB_SHIFT;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		return;
 
 	if (!mem->nslabs)
@@ -704,8 +708,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
 	phys_addr_t swiotlb_addr;
 	dma_addr_t dma_addr;
 
-	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
-			      swiotlb_force);
+	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
 
 	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
 			attrs);
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Pass a bool to pass if swiotlb needs to be enabled based on the
addressing needs and replace the verbose argument with a set of
flags, including one to force enable bounce buffering.

Note that this patch removes the possibility to force xen-swiotlb
use using swiotlb=force on the command line on x86 (arm and arm64
never supported that), but this interface will be restored shortly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/mm/init.c                     |  6 +----
 arch/arm64/mm/init.c                   |  6 +----
 arch/ia64/mm/init.c                    |  4 +--
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/sibyte/common/dma.c          |  2 +-
 arch/powerpc/mm/mem.c                  |  3 ++-
 arch/powerpc/platforms/pseries/setup.c |  3 ---
 arch/riscv/mm/init.c                   |  8 +-----
 arch/s390/mm/init.c                    |  3 +--
 arch/x86/kernel/pci-dma.c              | 15 ++++++-----
 drivers/xen/swiotlb-xen.c              |  4 +--
 include/linux/swiotlb.h                | 15 ++++++-----
 include/trace/events/swiotlb.h         | 29 ++++++++-------------
 kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
 15 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index fe249ea919083..ce64bdb55a16b 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -271,11 +271,7 @@ static void __init free_highpages(void)
 void __init mem_init(void)
 {
 #ifdef CONFIG_ARM_LPAE
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > arm_dma_pfn_limit)
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
 #endif
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 8ac25f19084e8..7b6ea4d6733d6 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -398,11 +398,7 @@ void __init bootmem_init(void)
  */
 void __init mem_init(void)
 {
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
-		swiotlb_init(1);
-	else if (!xen_swiotlb_detect())
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE);
 
 	/* this will put all unused low memory onto the freelists */
 	memblock_free_all();
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index 5d165607bf354..3c3e15b22608f 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -437,9 +437,7 @@ mem_init (void)
 		if (iommu_detected)
 			break;
 #endif
-#ifdef CONFIG_SWIOTLB
-		swiotlb_init(1);
-#endif
+		swiotlb_init(true, SWIOTLB_VERBOSE);
 	} while (0);
 
 #ifdef CONFIG_FLATMEM
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index fb7547e217263..9fbba6a8fa4c5 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
 #endif
 
 	swiotlb_adjust_size(swiotlbsize);
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index 364f2f27c8723..8220a1bc0db64 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
index eb47a94f3583e..c5c2c782aff68 100644
--- a/arch/mips/sibyte/common/dma.c
+++ b/arch/mips/sibyte/common/dma.c
@@ -10,5 +10,5 @@
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8e301cd8925b2..e1519e2edc656 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -17,6 +17,7 @@
 #include <linux/suspend.h>
 #include <linux/dma-direct.h>
 
+#include <asm/swiotlb.h>
 #include <asm/machdep.h>
 #include <asm/rtas.h>
 #include <asm/kasan.h>
@@ -251,7 +252,7 @@ void __init mem_init(void)
 	if (is_secure_guest())
 		svm_swiotlb_init();
 	else
-		swiotlb_init(0);
+		swiotlb_init(ppc_swiotlb_enable, 0);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 069d7b3bb142e..c6e06d91b6602 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
 	}
 
 	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
-		ppc_swiotlb_enable = 1;
 }
 
 static void pseries_panic(char *str)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 9535bea8688c0..181ffd322eafa 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -120,13 +120,7 @@ void __init mem_init(void)
 	BUG_ON(!mem_map);
 #endif /* CONFIG_FLATMEM */
 
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(dma32_phys_limit))
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
-#endif
+	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
 	memblock_free_all();
 
 	print_vm_layout();
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 86ffd0d51fd59..6fb6bf64326f9 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -185,8 +185,7 @@ static void pv_init(void)
 		return;
 
 	/* make sure bounce buffers are shared */
-	swiotlb_force = SWIOTLB_FORCE;
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
 	swiotlb_update_mem_attributes();
 }
 
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 04140e20ef1a3..a705a199bf8a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
 
 #ifdef CONFIG_SWIOTLB
 bool x86_swiotlb_enable;
+static unsigned int x86_swiotlb_flags;
 
 static void __init pci_swiotlb_detect(void)
 {
@@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
 	 * bounce buffers as the hypervisor can't access arbitrary VM memory
 	 * that is not explicitly shared with it.
 	 */
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
+		x86_swiotlb_flags |= SWIOTLB_FORCE;
+	}
 }
 #else
 static inline void __init pci_swiotlb_detect(void)
 {
 }
+#define x86_swiotlb_flags 0
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
@@ -75,8 +76,7 @@ static bool xen_swiotlb;
 
 static void __init pci_xen_swiotlb_init(void)
 {
-	if (!xen_initial_domain() && !x86_swiotlb_enable &&
-	    swiotlb_force != SWIOTLB_FORCE)
+	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
 	xen_swiotlb = true;
@@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
 	gart_iommu_hole_init();
 	amd_iommu_detect();
 	detect_intel_iommu();
-	if (x86_swiotlb_enable)
-		swiotlb_init(0);
+	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
 }
 
 /*
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 485cd06ed39e7..c2da3eb4826e8 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
 		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
 	}
 
-	if (swiotlb_init_with_tbl(start, nslabs, true))
+	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
 		panic("Cannot allocate SWIOTLB buffer");
 }
 #endif /* CONFIG_X86 */
@@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	/*
 	 * Oh well, have to allocate and map a bounce buffer.
 	 */
-	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+	trace_swiotlb_bounced(dev, dev_addr, size);
 
 	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
 	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index b48b26bfa0edb..ae0407173e845 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -13,11 +13,8 @@ struct device;
 struct page;
 struct scatterlist;
 
-enum swiotlb_force {
-	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc. */
-	SWIOTLB_FORCE,		/* swiotlb=force */
-	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
-};
+#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
+#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
@@ -36,8 +33,7 @@ enum swiotlb_force {
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-extern void swiotlb_init(int verbose);
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 int swiotlb_init_late(size_t size);
@@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
 	return mem && mem->force_bounce;
 }
 
+void swiotlb_init(bool addressing_limited, unsigned int flags);
 void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
 bool is_swiotlb_active(struct device *dev);
 void __init swiotlb_adjust_size(unsigned long size);
 #else
-#define swiotlb_force SWIOTLB_NO_FORCE
+static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
+{
+}
 static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
 {
 	return false;
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index 705be43b71ab0..da05c9ebd224a 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -8,20 +8,15 @@
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(swiotlb_bounced,
-
-	TP_PROTO(struct device *dev,
-		 dma_addr_t dev_addr,
-		 size_t size,
-		 enum swiotlb_force swiotlb_force),
-
-	TP_ARGS(dev, dev_addr, size, swiotlb_force),
+	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
+	TP_ARGS(dev, dev_addr, size),
 
 	TP_STRUCT__entry(
-		__string(	dev_name,	dev_name(dev)		)
-		__field(	u64,	dma_mask			)
-		__field(	dma_addr_t,	dev_addr		)
-		__field(	size_t,	size				)
-		__field(	enum swiotlb_force,	swiotlb_force	)
+		__string(dev_name, dev_name(dev))
+		__field(u64, dma_mask)
+		__field(dma_addr_t, dev_addr)
+		__field(size_t, size)
+		__field(bool, force)
 	),
 
 	TP_fast_assign(
@@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
 		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
 		__entry->dev_addr = dev_addr;
 		__entry->size = size;
-		__entry->swiotlb_force = swiotlb_force;
+		__entry->force = is_swiotlb_force_bounce(dev);
 	),
 
-	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
-		"size=%zu %s",
+	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
 		__get_str(dev_name),
 		__entry->dma_mask,
 		(unsigned long long)__entry->dev_addr,
 		__entry->size,
-		__print_symbolic(__entry->swiotlb_force,
-			{ SWIOTLB_NORMAL,	"NORMAL" },
-			{ SWIOTLB_FORCE,	"FORCE" },
-			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
+		__entry->force ? "FORCE" : "NORMAL")
 );
 
 #endif /*  _TRACE_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 9a4fe6e48a074..86e877a96b828 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -62,7 +62,8 @@
 
 #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
 
-enum swiotlb_force swiotlb_force;
+static bool swiotlb_force_bounce;
+static bool swiotlb_force_disable;
 
 struct io_tlb_mem io_tlb_default_mem;
 
@@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
 	if (*str == ',')
 		++str;
 	if (!strcmp(str, "force"))
-		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_force_bounce = true;
 	else if (!strcmp(str, "noforce"))
-		swiotlb_force = SWIOTLB_NO_FORCE;
+		swiotlb_force_disable = true;
 
 	return 0;
 }
@@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		mem->force_bounce = true;
 
 	spin_lock_init(&mem->lock);
@@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
+int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
+		unsigned int flags)
 {
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	size_t alloc_size;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
 
-	if (verbose)
+	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
 	return 0;
 }
@@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void  __init
-swiotlb_init(int verbose)
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 {
 	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	void *tlb;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (!addressing_limit && !swiotlb_force_bounce)
+		return;
+	if (swiotlb_force_disable)
 		return;
 
 	/* Get IO TLB memory from the low pages */
 	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
+	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
 
@@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
 	unsigned int order;
 	int rc = 0;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/*
@@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long bytes = nslabs << IO_TLB_SHIFT;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		return;
 
 	if (!mem->nslabs)
@@ -704,8 +708,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
 	phys_addr_t swiotlb_addr;
 	dma_addr_t dma_addr;
 
-	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
-			      swiotlb_force);
+	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
 
 	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
 			attrs);
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

Pass a bool to pass if swiotlb needs to be enabled based on the
addressing needs and replace the verbose argument with a set of
flags, including one to force enable bounce buffering.

Note that this patch removes the possibility to force xen-swiotlb
use using swiotlb=force on the command line on x86 (arm and arm64
never supported that), but this interface will be restored shortly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/mm/init.c                     |  6 +----
 arch/arm64/mm/init.c                   |  6 +----
 arch/ia64/mm/init.c                    |  4 +--
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/sibyte/common/dma.c          |  2 +-
 arch/powerpc/mm/mem.c                  |  3 ++-
 arch/powerpc/platforms/pseries/setup.c |  3 ---
 arch/riscv/mm/init.c                   |  8 +-----
 arch/s390/mm/init.c                    |  3 +--
 arch/x86/kernel/pci-dma.c              | 15 ++++++-----
 drivers/xen/swiotlb-xen.c              |  4 +--
 include/linux/swiotlb.h                | 15 ++++++-----
 include/trace/events/swiotlb.h         | 29 ++++++++-------------
 kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
 15 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index fe249ea919083..ce64bdb55a16b 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -271,11 +271,7 @@ static void __init free_highpages(void)
 void __init mem_init(void)
 {
 #ifdef CONFIG_ARM_LPAE
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > arm_dma_pfn_limit)
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
 #endif
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 8ac25f19084e8..7b6ea4d6733d6 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -398,11 +398,7 @@ void __init bootmem_init(void)
  */
 void __init mem_init(void)
 {
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
-		swiotlb_init(1);
-	else if (!xen_swiotlb_detect())
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE);
 
 	/* this will put all unused low memory onto the freelists */
 	memblock_free_all();
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index 5d165607bf354..3c3e15b22608f 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -437,9 +437,7 @@ mem_init (void)
 		if (iommu_detected)
 			break;
 #endif
-#ifdef CONFIG_SWIOTLB
-		swiotlb_init(1);
-#endif
+		swiotlb_init(true, SWIOTLB_VERBOSE);
 	} while (0);
 
 #ifdef CONFIG_FLATMEM
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index fb7547e217263..9fbba6a8fa4c5 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
 #endif
 
 	swiotlb_adjust_size(swiotlbsize);
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index 364f2f27c8723..8220a1bc0db64 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
index eb47a94f3583e..c5c2c782aff68 100644
--- a/arch/mips/sibyte/common/dma.c
+++ b/arch/mips/sibyte/common/dma.c
@@ -10,5 +10,5 @@
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8e301cd8925b2..e1519e2edc656 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -17,6 +17,7 @@
 #include <linux/suspend.h>
 #include <linux/dma-direct.h>
 
+#include <asm/swiotlb.h>
 #include <asm/machdep.h>
 #include <asm/rtas.h>
 #include <asm/kasan.h>
@@ -251,7 +252,7 @@ void __init mem_init(void)
 	if (is_secure_guest())
 		svm_swiotlb_init();
 	else
-		swiotlb_init(0);
+		swiotlb_init(ppc_swiotlb_enable, 0);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 069d7b3bb142e..c6e06d91b6602 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
 	}
 
 	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
-		ppc_swiotlb_enable = 1;
 }
 
 static void pseries_panic(char *str)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 9535bea8688c0..181ffd322eafa 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -120,13 +120,7 @@ void __init mem_init(void)
 	BUG_ON(!mem_map);
 #endif /* CONFIG_FLATMEM */
 
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(dma32_phys_limit))
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
-#endif
+	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
 	memblock_free_all();
 
 	print_vm_layout();
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 86ffd0d51fd59..6fb6bf64326f9 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -185,8 +185,7 @@ static void pv_init(void)
 		return;
 
 	/* make sure bounce buffers are shared */
-	swiotlb_force = SWIOTLB_FORCE;
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
 	swiotlb_update_mem_attributes();
 }
 
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 04140e20ef1a3..a705a199bf8a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
 
 #ifdef CONFIG_SWIOTLB
 bool x86_swiotlb_enable;
+static unsigned int x86_swiotlb_flags;
 
 static void __init pci_swiotlb_detect(void)
 {
@@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
 	 * bounce buffers as the hypervisor can't access arbitrary VM memory
 	 * that is not explicitly shared with it.
 	 */
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
+		x86_swiotlb_flags |= SWIOTLB_FORCE;
+	}
 }
 #else
 static inline void __init pci_swiotlb_detect(void)
 {
 }
+#define x86_swiotlb_flags 0
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
@@ -75,8 +76,7 @@ static bool xen_swiotlb;
 
 static void __init pci_xen_swiotlb_init(void)
 {
-	if (!xen_initial_domain() && !x86_swiotlb_enable &&
-	    swiotlb_force != SWIOTLB_FORCE)
+	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
 	xen_swiotlb = true;
@@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
 	gart_iommu_hole_init();
 	amd_iommu_detect();
 	detect_intel_iommu();
-	if (x86_swiotlb_enable)
-		swiotlb_init(0);
+	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
 }
 
 /*
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 485cd06ed39e7..c2da3eb4826e8 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
 		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
 	}
 
-	if (swiotlb_init_with_tbl(start, nslabs, true))
+	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
 		panic("Cannot allocate SWIOTLB buffer");
 }
 #endif /* CONFIG_X86 */
@@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	/*
 	 * Oh well, have to allocate and map a bounce buffer.
 	 */
-	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+	trace_swiotlb_bounced(dev, dev_addr, size);
 
 	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
 	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index b48b26bfa0edb..ae0407173e845 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -13,11 +13,8 @@ struct device;
 struct page;
 struct scatterlist;
 
-enum swiotlb_force {
-	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc. */
-	SWIOTLB_FORCE,		/* swiotlb=force */
-	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
-};
+#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
+#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
@@ -36,8 +33,7 @@ enum swiotlb_force {
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-extern void swiotlb_init(int verbose);
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 int swiotlb_init_late(size_t size);
@@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
 	return mem && mem->force_bounce;
 }
 
+void swiotlb_init(bool addressing_limited, unsigned int flags);
 void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
 bool is_swiotlb_active(struct device *dev);
 void __init swiotlb_adjust_size(unsigned long size);
 #else
-#define swiotlb_force SWIOTLB_NO_FORCE
+static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
+{
+}
 static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
 {
 	return false;
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index 705be43b71ab0..da05c9ebd224a 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -8,20 +8,15 @@
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(swiotlb_bounced,
-
-	TP_PROTO(struct device *dev,
-		 dma_addr_t dev_addr,
-		 size_t size,
-		 enum swiotlb_force swiotlb_force),
-
-	TP_ARGS(dev, dev_addr, size, swiotlb_force),
+	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
+	TP_ARGS(dev, dev_addr, size),
 
 	TP_STRUCT__entry(
-		__string(	dev_name,	dev_name(dev)		)
-		__field(	u64,	dma_mask			)
-		__field(	dma_addr_t,	dev_addr		)
-		__field(	size_t,	size				)
-		__field(	enum swiotlb_force,	swiotlb_force	)
+		__string(dev_name, dev_name(dev))
+		__field(u64, dma_mask)
+		__field(dma_addr_t, dev_addr)
+		__field(size_t, size)
+		__field(bool, force)
 	),
 
 	TP_fast_assign(
@@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
 		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
 		__entry->dev_addr = dev_addr;
 		__entry->size = size;
-		__entry->swiotlb_force = swiotlb_force;
+		__entry->force = is_swiotlb_force_bounce(dev);
 	),
 
-	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
-		"size=%zu %s",
+	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
 		__get_str(dev_name),
 		__entry->dma_mask,
 		(unsigned long long)__entry->dev_addr,
 		__entry->size,
-		__print_symbolic(__entry->swiotlb_force,
-			{ SWIOTLB_NORMAL,	"NORMAL" },
-			{ SWIOTLB_FORCE,	"FORCE" },
-			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
+		__entry->force ? "FORCE" : "NORMAL")
 );
 
 #endif /*  _TRACE_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 9a4fe6e48a074..86e877a96b828 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -62,7 +62,8 @@
 
 #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
 
-enum swiotlb_force swiotlb_force;
+static bool swiotlb_force_bounce;
+static bool swiotlb_force_disable;
 
 struct io_tlb_mem io_tlb_default_mem;
 
@@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
 	if (*str == ',')
 		++str;
 	if (!strcmp(str, "force"))
-		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_force_bounce = true;
 	else if (!strcmp(str, "noforce"))
-		swiotlb_force = SWIOTLB_NO_FORCE;
+		swiotlb_force_disable = true;
 
 	return 0;
 }
@@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		mem->force_bounce = true;
 
 	spin_lock_init(&mem->lock);
@@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
+int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
+		unsigned int flags)
 {
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	size_t alloc_size;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
 
-	if (verbose)
+	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
 	return 0;
 }
@@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void  __init
-swiotlb_init(int verbose)
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 {
 	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	void *tlb;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (!addressing_limit && !swiotlb_force_bounce)
+		return;
+	if (swiotlb_force_disable)
 		return;
 
 	/* Get IO TLB memory from the low pages */
 	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
+	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
 
@@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
 	unsigned int order;
 	int rc = 0;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/*
@@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long bytes = nslabs << IO_TLB_SHIFT;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		return;
 
 	if (!mem->nslabs)
@@ -704,8 +708,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
 	phys_addr_t swiotlb_addr;
 	dma_addr_t dma_addr;
 
-	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
-			      swiotlb_force);
+	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
 
 	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
 			attrs);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Pass a bool to pass if swiotlb needs to be enabled based on the
addressing needs and replace the verbose argument with a set of
flags, including one to force enable bounce buffering.

Note that this patch removes the possibility to force xen-swiotlb
use using swiotlb=force on the command line on x86 (arm and arm64
never supported that), but this interface will be restored shortly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/mm/init.c                     |  6 +----
 arch/arm64/mm/init.c                   |  6 +----
 arch/ia64/mm/init.c                    |  4 +--
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/sibyte/common/dma.c          |  2 +-
 arch/powerpc/mm/mem.c                  |  3 ++-
 arch/powerpc/platforms/pseries/setup.c |  3 ---
 arch/riscv/mm/init.c                   |  8 +-----
 arch/s390/mm/init.c                    |  3 +--
 arch/x86/kernel/pci-dma.c              | 15 ++++++-----
 drivers/xen/swiotlb-xen.c              |  4 +--
 include/linux/swiotlb.h                | 15 ++++++-----
 include/trace/events/swiotlb.h         | 29 ++++++++-------------
 kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
 15 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index fe249ea919083..ce64bdb55a16b 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -271,11 +271,7 @@ static void __init free_highpages(void)
 void __init mem_init(void)
 {
 #ifdef CONFIG_ARM_LPAE
-	if (swiotlb_force = SWIOTLB_FORCE ||
-	    max_pfn > arm_dma_pfn_limit)
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
 #endif
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 8ac25f19084e8..7b6ea4d6733d6 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -398,11 +398,7 @@ void __init bootmem_init(void)
  */
 void __init mem_init(void)
 {
-	if (swiotlb_force = SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
-		swiotlb_init(1);
-	else if (!xen_swiotlb_detect())
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE);
 
 	/* this will put all unused low memory onto the freelists */
 	memblock_free_all();
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index 5d165607bf354..3c3e15b22608f 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -437,9 +437,7 @@ mem_init (void)
 		if (iommu_detected)
 			break;
 #endif
-#ifdef CONFIG_SWIOTLB
-		swiotlb_init(1);
-#endif
+		swiotlb_init(true, SWIOTLB_VERBOSE);
 	} while (0);
 
 #ifdef CONFIG_FLATMEM
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index fb7547e217263..9fbba6a8fa4c5 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
 #endif
 
 	swiotlb_adjust_size(swiotlbsize);
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index 364f2f27c8723..8220a1bc0db64 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
index eb47a94f3583e..c5c2c782aff68 100644
--- a/arch/mips/sibyte/common/dma.c
+++ b/arch/mips/sibyte/common/dma.c
@@ -10,5 +10,5 @@
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8e301cd8925b2..e1519e2edc656 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -17,6 +17,7 @@
 #include <linux/suspend.h>
 #include <linux/dma-direct.h>
 
+#include <asm/swiotlb.h>
 #include <asm/machdep.h>
 #include <asm/rtas.h>
 #include <asm/kasan.h>
@@ -251,7 +252,7 @@ void __init mem_init(void)
 	if (is_secure_guest())
 		svm_swiotlb_init();
 	else
-		swiotlb_init(0);
+		swiotlb_init(ppc_swiotlb_enable, 0);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 069d7b3bb142e..c6e06d91b6602 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
 	}
 
 	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
-
-	if (swiotlb_force = SWIOTLB_FORCE)
-		ppc_swiotlb_enable = 1;
 }
 
 static void pseries_panic(char *str)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 9535bea8688c0..181ffd322eafa 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -120,13 +120,7 @@ void __init mem_init(void)
 	BUG_ON(!mem_map);
 #endif /* CONFIG_FLATMEM */
 
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_force = SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(dma32_phys_limit))
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
-#endif
+	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
 	memblock_free_all();
 
 	print_vm_layout();
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 86ffd0d51fd59..6fb6bf64326f9 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -185,8 +185,7 @@ static void pv_init(void)
 		return;
 
 	/* make sure bounce buffers are shared */
-	swiotlb_force = SWIOTLB_FORCE;
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
 	swiotlb_update_mem_attributes();
 }
 
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 04140e20ef1a3..a705a199bf8a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
 
 #ifdef CONFIG_SWIOTLB
 bool x86_swiotlb_enable;
+static unsigned int x86_swiotlb_flags;
 
 static void __init pci_swiotlb_detect(void)
 {
@@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
 	 * bounce buffers as the hypervisor can't access arbitrary VM memory
 	 * that is not explicitly shared with it.
 	 */
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
-	if (swiotlb_force = SWIOTLB_FORCE)
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
+		x86_swiotlb_flags |= SWIOTLB_FORCE;
+	}
 }
 #else
 static inline void __init pci_swiotlb_detect(void)
 {
 }
+#define x86_swiotlb_flags 0
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
@@ -75,8 +76,7 @@ static bool xen_swiotlb;
 
 static void __init pci_xen_swiotlb_init(void)
 {
-	if (!xen_initial_domain() && !x86_swiotlb_enable &&
-	    swiotlb_force != SWIOTLB_FORCE)
+	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
 	xen_swiotlb = true;
@@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
 	gart_iommu_hole_init();
 	amd_iommu_detect();
 	detect_intel_iommu();
-	if (x86_swiotlb_enable)
-		swiotlb_init(0);
+	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
 }
 
 /*
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 485cd06ed39e7..c2da3eb4826e8 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
 		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
 	}
 
-	if (swiotlb_init_with_tbl(start, nslabs, true))
+	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
 		panic("Cannot allocate SWIOTLB buffer");
 }
 #endif /* CONFIG_X86 */
@@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	/*
 	 * Oh well, have to allocate and map a bounce buffer.
 	 */
-	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+	trace_swiotlb_bounced(dev, dev_addr, size);
 
 	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
 	if (map = (phys_addr_t)DMA_MAPPING_ERROR)
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index b48b26bfa0edb..ae0407173e845 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -13,11 +13,8 @@ struct device;
 struct page;
 struct scatterlist;
 
-enum swiotlb_force {
-	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc. */
-	SWIOTLB_FORCE,		/* swiotlb=force */
-	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
-};
+#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
+#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
@@ -36,8 +33,7 @@ enum swiotlb_force {
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-extern void swiotlb_init(int verbose);
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 int swiotlb_init_late(size_t size);
@@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
 	return mem && mem->force_bounce;
 }
 
+void swiotlb_init(bool addressing_limited, unsigned int flags);
 void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
 bool is_swiotlb_active(struct device *dev);
 void __init swiotlb_adjust_size(unsigned long size);
 #else
-#define swiotlb_force SWIOTLB_NO_FORCE
+static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
+{
+}
 static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
 {
 	return false;
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index 705be43b71ab0..da05c9ebd224a 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -8,20 +8,15 @@
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(swiotlb_bounced,
-
-	TP_PROTO(struct device *dev,
-		 dma_addr_t dev_addr,
-		 size_t size,
-		 enum swiotlb_force swiotlb_force),
-
-	TP_ARGS(dev, dev_addr, size, swiotlb_force),
+	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
+	TP_ARGS(dev, dev_addr, size),
 
 	TP_STRUCT__entry(
-		__string(	dev_name,	dev_name(dev)		)
-		__field(	u64,	dma_mask			)
-		__field(	dma_addr_t,	dev_addr		)
-		__field(	size_t,	size				)
-		__field(	enum swiotlb_force,	swiotlb_force	)
+		__string(dev_name, dev_name(dev))
+		__field(u64, dma_mask)
+		__field(dma_addr_t, dev_addr)
+		__field(size_t, size)
+		__field(bool, force)
 	),
 
 	TP_fast_assign(
@@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
 		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
 		__entry->dev_addr = dev_addr;
 		__entry->size = size;
-		__entry->swiotlb_force = swiotlb_force;
+		__entry->force = is_swiotlb_force_bounce(dev);
 	),
 
-	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
-		"size=%zu %s",
+	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
 		__get_str(dev_name),
 		__entry->dma_mask,
 		(unsigned long long)__entry->dev_addr,
 		__entry->size,
-		__print_symbolic(__entry->swiotlb_force,
-			{ SWIOTLB_NORMAL,	"NORMAL" },
-			{ SWIOTLB_FORCE,	"FORCE" },
-			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
+		__entry->force ? "FORCE" : "NORMAL")
 );
 
 #endif /*  _TRACE_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 9a4fe6e48a074..86e877a96b828 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -62,7 +62,8 @@
 
 #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
 
-enum swiotlb_force swiotlb_force;
+static bool swiotlb_force_bounce;
+static bool swiotlb_force_disable;
 
 struct io_tlb_mem io_tlb_default_mem;
 
@@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
 	if (*str = ',')
 		++str;
 	if (!strcmp(str, "force"))
-		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_force_bounce = true;
 	else if (!strcmp(str, "noforce"))
-		swiotlb_force = SWIOTLB_NO_FORCE;
+		swiotlb_force_disable = true;
 
 	return 0;
 }
@@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force = SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		mem->force_bounce = true;
 
 	spin_lock_init(&mem->lock);
@@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
+int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
+		unsigned int flags)
 {
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	size_t alloc_size;
 
-	if (swiotlb_force = SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
 
-	if (verbose)
+	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
 	return 0;
 }
@@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void  __init
-swiotlb_init(int verbose)
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 {
 	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	void *tlb;
 
-	if (swiotlb_force = SWIOTLB_NO_FORCE)
+	if (!addressing_limit && !swiotlb_force_bounce)
+		return;
+	if (swiotlb_force_disable)
 		return;
 
 	/* Get IO TLB memory from the low pages */
 	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
+	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
 
@@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
 	unsigned int order;
 	int rc = 0;
 
-	if (swiotlb_force = SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/*
@@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long bytes = nslabs << IO_TLB_SHIFT;
 
-	if (swiotlb_force = SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
-	if (swiotlb_force = SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		return;
 
 	if (!mem->nslabs)
@@ -704,8 +708,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
 	phys_addr_t swiotlb_addr;
 	dma_addr_t dma_addr;
 
-	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
-			      swiotlb_force);
+	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
 
 	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
 			attrs);
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Power SVM wants to allocate a swiotlb buffer that is not restricted to
low memory for the trusted hypervisor scheme.  Consolidate the support
for this into the swiotlb_init interface by adding a new flag.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/powerpc/include/asm/svm.h       |  4 ----
 arch/powerpc/include/asm/swiotlb.h   |  1 +
 arch/powerpc/kernel/dma-swiotlb.c    |  1 +
 arch/powerpc/mm/mem.c                |  5 +----
 arch/powerpc/platforms/pseries/svm.c | 26 +-------------------------
 include/linux/swiotlb.h              |  1 +
 kernel/dma/swiotlb.c                 | 11 +++++++++--
 7 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/arch/powerpc/include/asm/svm.h b/arch/powerpc/include/asm/svm.h
index 7546402d796af..85580b30aba48 100644
--- a/arch/powerpc/include/asm/svm.h
+++ b/arch/powerpc/include/asm/svm.h
@@ -15,8 +15,6 @@ static inline bool is_secure_guest(void)
 	return mfmsr() & MSR_S;
 }
 
-void __init svm_swiotlb_init(void);
-
 void dtl_cache_ctor(void *addr);
 #define get_dtl_cache_ctor()	(is_secure_guest() ? dtl_cache_ctor : NULL)
 
@@ -27,8 +25,6 @@ static inline bool is_secure_guest(void)
 	return false;
 }
 
-static inline void svm_swiotlb_init(void) {}
-
 #define get_dtl_cache_ctor() NULL
 
 #endif /* CONFIG_PPC_SVM */
diff --git a/arch/powerpc/include/asm/swiotlb.h b/arch/powerpc/include/asm/swiotlb.h
index 3c1a1cd161286..4203b5e0a88ed 100644
--- a/arch/powerpc/include/asm/swiotlb.h
+++ b/arch/powerpc/include/asm/swiotlb.h
@@ -9,6 +9,7 @@
 #include <linux/swiotlb.h>
 
 extern unsigned int ppc_swiotlb_enable;
+extern unsigned int ppc_swiotlb_flags;
 
 #ifdef CONFIG_SWIOTLB
 void swiotlb_detect_4g(void);
diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c
index fc7816126a401..ba256c37bcc0f 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -10,6 +10,7 @@
 #include <asm/swiotlb.h>
 
 unsigned int ppc_swiotlb_enable;
+unsigned int ppc_swiotlb_flags;
 
 void __init swiotlb_detect_4g(void)
 {
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index e1519e2edc656..a4d65418c30a9 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -249,10 +249,7 @@ void __init mem_init(void)
 	 * back to to-down.
 	 */
 	memblock_set_bottom_up(true);
-	if (is_secure_guest())
-		svm_swiotlb_init();
-	else
-		swiotlb_init(ppc_swiotlb_enable, 0);
+	swiotlb_init(ppc_swiotlb_enable, ppc_swiotlb_flags);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
index c5228f4969eb2..3b4045d508ec8 100644
--- a/arch/powerpc/platforms/pseries/svm.c
+++ b/arch/powerpc/platforms/pseries/svm.c
@@ -28,7 +28,7 @@ static int __init init_svm(void)
 	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
 	 * otherwise.
 	 */
-	swiotlb_force = SWIOTLB_FORCE;
+	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
 
 	/* Share the SWIOTLB buffer with the host. */
 	swiotlb_update_mem_attributes();
@@ -37,30 +37,6 @@ static int __init init_svm(void)
 }
 machine_early_initcall(pseries, init_svm);
 
-/*
- * Initialize SWIOTLB. Essentially the same as swiotlb_init(), except that it
- * can allocate the buffer anywhere in memory. Since the hypervisor doesn't have
- * any addressing limitation, we don't need to allocate it in low addresses.
- */
-void __init svm_swiotlb_init(void)
-{
-	unsigned char *vstart;
-	unsigned long bytes, io_tlb_nslabs;
-
-	io_tlb_nslabs = (swiotlb_size_or_default() >> IO_TLB_SHIFT);
-	io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
-
-	bytes = io_tlb_nslabs << IO_TLB_SHIFT;
-
-	vstart = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE);
-	if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, false))
-		return;
-
-
-	memblock_free(vstart, PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
-	panic("SVM: Cannot allocate SWIOTLB buffer");
-}
-
 int set_memory_encrypted(unsigned long addr, int numpages)
 {
 	if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index ae0407173e845..eabdd89987027 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -15,6 +15,7 @@ struct scatterlist;
 
 #define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
 #define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
+#define SWIOTLB_ANY	(1 << 2) /* allow any memory for the buffer */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 86e877a96b828..f6e091424af3d 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -266,8 +266,15 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	if (swiotlb_force_disable)
 		return;
 
-	/* Get IO TLB memory from the low pages */
-	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+	/*
+	 * By default allocate the bounce buffer memory from low memory, but
+	 * allow to pick a location everywhere for hypervisors with guest
+	 * memory encryption.
+	 */
+	if (flags & SWIOTLB_ANY)
+		tlb = memblock_alloc(bytes, PAGE_SIZE);
+	else
+		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Power SVM wants to allocate a swiotlb buffer that is not restricted to
low memory for the trusted hypervisor scheme.  Consolidate the support
for this into the swiotlb_init interface by adding a new flag.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/powerpc/include/asm/svm.h       |  4 ----
 arch/powerpc/include/asm/swiotlb.h   |  1 +
 arch/powerpc/kernel/dma-swiotlb.c    |  1 +
 arch/powerpc/mm/mem.c                |  5 +----
 arch/powerpc/platforms/pseries/svm.c | 26 +-------------------------
 include/linux/swiotlb.h              |  1 +
 kernel/dma/swiotlb.c                 | 11 +++++++++--
 7 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/arch/powerpc/include/asm/svm.h b/arch/powerpc/include/asm/svm.h
index 7546402d796af..85580b30aba48 100644
--- a/arch/powerpc/include/asm/svm.h
+++ b/arch/powerpc/include/asm/svm.h
@@ -15,8 +15,6 @@ static inline bool is_secure_guest(void)
 	return mfmsr() & MSR_S;
 }
 
-void __init svm_swiotlb_init(void);
-
 void dtl_cache_ctor(void *addr);
 #define get_dtl_cache_ctor()	(is_secure_guest() ? dtl_cache_ctor : NULL)
 
@@ -27,8 +25,6 @@ static inline bool is_secure_guest(void)
 	return false;
 }
 
-static inline void svm_swiotlb_init(void) {}
-
 #define get_dtl_cache_ctor() NULL
 
 #endif /* CONFIG_PPC_SVM */
diff --git a/arch/powerpc/include/asm/swiotlb.h b/arch/powerpc/include/asm/swiotlb.h
index 3c1a1cd161286..4203b5e0a88ed 100644
--- a/arch/powerpc/include/asm/swiotlb.h
+++ b/arch/powerpc/include/asm/swiotlb.h
@@ -9,6 +9,7 @@
 #include <linux/swiotlb.h>
 
 extern unsigned int ppc_swiotlb_enable;
+extern unsigned int ppc_swiotlb_flags;
 
 #ifdef CONFIG_SWIOTLB
 void swiotlb_detect_4g(void);
diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c
index fc7816126a401..ba256c37bcc0f 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -10,6 +10,7 @@
 #include <asm/swiotlb.h>
 
 unsigned int ppc_swiotlb_enable;
+unsigned int ppc_swiotlb_flags;
 
 void __init swiotlb_detect_4g(void)
 {
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index e1519e2edc656..a4d65418c30a9 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -249,10 +249,7 @@ void __init mem_init(void)
 	 * back to to-down.
 	 */
 	memblock_set_bottom_up(true);
-	if (is_secure_guest())
-		svm_swiotlb_init();
-	else
-		swiotlb_init(ppc_swiotlb_enable, 0);
+	swiotlb_init(ppc_swiotlb_enable, ppc_swiotlb_flags);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
index c5228f4969eb2..3b4045d508ec8 100644
--- a/arch/powerpc/platforms/pseries/svm.c
+++ b/arch/powerpc/platforms/pseries/svm.c
@@ -28,7 +28,7 @@ static int __init init_svm(void)
 	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
 	 * otherwise.
 	 */
-	swiotlb_force = SWIOTLB_FORCE;
+	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
 
 	/* Share the SWIOTLB buffer with the host. */
 	swiotlb_update_mem_attributes();
@@ -37,30 +37,6 @@ static int __init init_svm(void)
 }
 machine_early_initcall(pseries, init_svm);
 
-/*
- * Initialize SWIOTLB. Essentially the same as swiotlb_init(), except that it
- * can allocate the buffer anywhere in memory. Since the hypervisor doesn't have
- * any addressing limitation, we don't need to allocate it in low addresses.
- */
-void __init svm_swiotlb_init(void)
-{
-	unsigned char *vstart;
-	unsigned long bytes, io_tlb_nslabs;
-
-	io_tlb_nslabs = (swiotlb_size_or_default() >> IO_TLB_SHIFT);
-	io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
-
-	bytes = io_tlb_nslabs << IO_TLB_SHIFT;
-
-	vstart = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE);
-	if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, false))
-		return;
-
-
-	memblock_free(vstart, PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
-	panic("SVM: Cannot allocate SWIOTLB buffer");
-}
-
 int set_memory_encrypted(unsigned long addr, int numpages)
 {
 	if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index ae0407173e845..eabdd89987027 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -15,6 +15,7 @@ struct scatterlist;
 
 #define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
 #define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
+#define SWIOTLB_ANY	(1 << 2) /* allow any memory for the buffer */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 86e877a96b828..f6e091424af3d 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -266,8 +266,15 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	if (swiotlb_force_disable)
 		return;
 
-	/* Get IO TLB memory from the low pages */
-	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+	/*
+	 * By default allocate the bounce buffer memory from low memory, but
+	 * allow to pick a location everywhere for hypervisors with guest
+	 * memory encryption.
+	 */
+	if (flags & SWIOTLB_ANY)
+		tlb = memblock_alloc(bytes, PAGE_SIZE);
+	else
+		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Power SVM wants to allocate a swiotlb buffer that is not restricted to
low memory for the trusted hypervisor scheme.  Consolidate the support
for this into the swiotlb_init interface by adding a new flag.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/powerpc/include/asm/svm.h       |  4 ----
 arch/powerpc/include/asm/swiotlb.h   |  1 +
 arch/powerpc/kernel/dma-swiotlb.c    |  1 +
 arch/powerpc/mm/mem.c                |  5 +----
 arch/powerpc/platforms/pseries/svm.c | 26 +-------------------------
 include/linux/swiotlb.h              |  1 +
 kernel/dma/swiotlb.c                 | 11 +++++++++--
 7 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/arch/powerpc/include/asm/svm.h b/arch/powerpc/include/asm/svm.h
index 7546402d796af..85580b30aba48 100644
--- a/arch/powerpc/include/asm/svm.h
+++ b/arch/powerpc/include/asm/svm.h
@@ -15,8 +15,6 @@ static inline bool is_secure_guest(void)
 	return mfmsr() & MSR_S;
 }
 
-void __init svm_swiotlb_init(void);
-
 void dtl_cache_ctor(void *addr);
 #define get_dtl_cache_ctor()	(is_secure_guest() ? dtl_cache_ctor : NULL)
 
@@ -27,8 +25,6 @@ static inline bool is_secure_guest(void)
 	return false;
 }
 
-static inline void svm_swiotlb_init(void) {}
-
 #define get_dtl_cache_ctor() NULL
 
 #endif /* CONFIG_PPC_SVM */
diff --git a/arch/powerpc/include/asm/swiotlb.h b/arch/powerpc/include/asm/swiotlb.h
index 3c1a1cd161286..4203b5e0a88ed 100644
--- a/arch/powerpc/include/asm/swiotlb.h
+++ b/arch/powerpc/include/asm/swiotlb.h
@@ -9,6 +9,7 @@
 #include <linux/swiotlb.h>
 
 extern unsigned int ppc_swiotlb_enable;
+extern unsigned int ppc_swiotlb_flags;
 
 #ifdef CONFIG_SWIOTLB
 void swiotlb_detect_4g(void);
diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c
index fc7816126a401..ba256c37bcc0f 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -10,6 +10,7 @@
 #include <asm/swiotlb.h>
 
 unsigned int ppc_swiotlb_enable;
+unsigned int ppc_swiotlb_flags;
 
 void __init swiotlb_detect_4g(void)
 {
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index e1519e2edc656..a4d65418c30a9 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -249,10 +249,7 @@ void __init mem_init(void)
 	 * back to to-down.
 	 */
 	memblock_set_bottom_up(true);
-	if (is_secure_guest())
-		svm_swiotlb_init();
-	else
-		swiotlb_init(ppc_swiotlb_enable, 0);
+	swiotlb_init(ppc_swiotlb_enable, ppc_swiotlb_flags);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
index c5228f4969eb2..3b4045d508ec8 100644
--- a/arch/powerpc/platforms/pseries/svm.c
+++ b/arch/powerpc/platforms/pseries/svm.c
@@ -28,7 +28,7 @@ static int __init init_svm(void)
 	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
 	 * otherwise.
 	 */
-	swiotlb_force = SWIOTLB_FORCE;
+	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
 
 	/* Share the SWIOTLB buffer with the host. */
 	swiotlb_update_mem_attributes();
@@ -37,30 +37,6 @@ static int __init init_svm(void)
 }
 machine_early_initcall(pseries, init_svm);
 
-/*
- * Initialize SWIOTLB. Essentially the same as swiotlb_init(), except that it
- * can allocate the buffer anywhere in memory. Since the hypervisor doesn't have
- * any addressing limitation, we don't need to allocate it in low addresses.
- */
-void __init svm_swiotlb_init(void)
-{
-	unsigned char *vstart;
-	unsigned long bytes, io_tlb_nslabs;
-
-	io_tlb_nslabs = (swiotlb_size_or_default() >> IO_TLB_SHIFT);
-	io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
-
-	bytes = io_tlb_nslabs << IO_TLB_SHIFT;
-
-	vstart = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE);
-	if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, false))
-		return;
-
-
-	memblock_free(vstart, PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
-	panic("SVM: Cannot allocate SWIOTLB buffer");
-}
-
 int set_memory_encrypted(unsigned long addr, int numpages)
 {
 	if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index ae0407173e845..eabdd89987027 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -15,6 +15,7 @@ struct scatterlist;
 
 #define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
 #define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
+#define SWIOTLB_ANY	(1 << 2) /* allow any memory for the buffer */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 86e877a96b828..f6e091424af3d 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -266,8 +266,15 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	if (swiotlb_force_disable)
 		return;
 
-	/* Get IO TLB memory from the low pages */
-	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+	/*
+	 * By default allocate the bounce buffer memory from low memory, but
+	 * allow to pick a location everywhere for hypervisors with guest
+	 * memory encryption.
+	 */
+	if (flags & SWIOTLB_ANY)
+		tlb = memblock_alloc(bytes, PAGE_SIZE);
+	else
+		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Power SVM wants to allocate a swiotlb buffer that is not restricted to
low memory for the trusted hypervisor scheme.  Consolidate the support
for this into the swiotlb_init interface by adding a new flag.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/powerpc/include/asm/svm.h       |  4 ----
 arch/powerpc/include/asm/swiotlb.h   |  1 +
 arch/powerpc/kernel/dma-swiotlb.c    |  1 +
 arch/powerpc/mm/mem.c                |  5 +----
 arch/powerpc/platforms/pseries/svm.c | 26 +-------------------------
 include/linux/swiotlb.h              |  1 +
 kernel/dma/swiotlb.c                 | 11 +++++++++--
 7 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/arch/powerpc/include/asm/svm.h b/arch/powerpc/include/asm/svm.h
index 7546402d796af..85580b30aba48 100644
--- a/arch/powerpc/include/asm/svm.h
+++ b/arch/powerpc/include/asm/svm.h
@@ -15,8 +15,6 @@ static inline bool is_secure_guest(void)
 	return mfmsr() & MSR_S;
 }
 
-void __init svm_swiotlb_init(void);
-
 void dtl_cache_ctor(void *addr);
 #define get_dtl_cache_ctor()	(is_secure_guest() ? dtl_cache_ctor : NULL)
 
@@ -27,8 +25,6 @@ static inline bool is_secure_guest(void)
 	return false;
 }
 
-static inline void svm_swiotlb_init(void) {}
-
 #define get_dtl_cache_ctor() NULL
 
 #endif /* CONFIG_PPC_SVM */
diff --git a/arch/powerpc/include/asm/swiotlb.h b/arch/powerpc/include/asm/swiotlb.h
index 3c1a1cd161286..4203b5e0a88ed 100644
--- a/arch/powerpc/include/asm/swiotlb.h
+++ b/arch/powerpc/include/asm/swiotlb.h
@@ -9,6 +9,7 @@
 #include <linux/swiotlb.h>
 
 extern unsigned int ppc_swiotlb_enable;
+extern unsigned int ppc_swiotlb_flags;
 
 #ifdef CONFIG_SWIOTLB
 void swiotlb_detect_4g(void);
diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c
index fc7816126a401..ba256c37bcc0f 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -10,6 +10,7 @@
 #include <asm/swiotlb.h>
 
 unsigned int ppc_swiotlb_enable;
+unsigned int ppc_swiotlb_flags;
 
 void __init swiotlb_detect_4g(void)
 {
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index e1519e2edc656..a4d65418c30a9 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -249,10 +249,7 @@ void __init mem_init(void)
 	 * back to to-down.
 	 */
 	memblock_set_bottom_up(true);
-	if (is_secure_guest())
-		svm_swiotlb_init();
-	else
-		swiotlb_init(ppc_swiotlb_enable, 0);
+	swiotlb_init(ppc_swiotlb_enable, ppc_swiotlb_flags);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
index c5228f4969eb2..3b4045d508ec8 100644
--- a/arch/powerpc/platforms/pseries/svm.c
+++ b/arch/powerpc/platforms/pseries/svm.c
@@ -28,7 +28,7 @@ static int __init init_svm(void)
 	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
 	 * otherwise.
 	 */
-	swiotlb_force = SWIOTLB_FORCE;
+	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
 
 	/* Share the SWIOTLB buffer with the host. */
 	swiotlb_update_mem_attributes();
@@ -37,30 +37,6 @@ static int __init init_svm(void)
 }
 machine_early_initcall(pseries, init_svm);
 
-/*
- * Initialize SWIOTLB. Essentially the same as swiotlb_init(), except that it
- * can allocate the buffer anywhere in memory. Since the hypervisor doesn't have
- * any addressing limitation, we don't need to allocate it in low addresses.
- */
-void __init svm_swiotlb_init(void)
-{
-	unsigned char *vstart;
-	unsigned long bytes, io_tlb_nslabs;
-
-	io_tlb_nslabs = (swiotlb_size_or_default() >> IO_TLB_SHIFT);
-	io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
-
-	bytes = io_tlb_nslabs << IO_TLB_SHIFT;
-
-	vstart = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE);
-	if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, false))
-		return;
-
-
-	memblock_free(vstart, PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
-	panic("SVM: Cannot allocate SWIOTLB buffer");
-}
-
 int set_memory_encrypted(unsigned long addr, int numpages)
 {
 	if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index ae0407173e845..eabdd89987027 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -15,6 +15,7 @@ struct scatterlist;
 
 #define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
 #define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
+#define SWIOTLB_ANY	(1 << 2) /* allow any memory for the buffer */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 86e877a96b828..f6e091424af3d 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -266,8 +266,15 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	if (swiotlb_force_disable)
 		return;
 
-	/* Get IO TLB memory from the low pages */
-	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+	/*
+	 * By default allocate the bounce buffer memory from low memory, but
+	 * allow to pick a location everywhere for hypervisors with guest
+	 * memory encryption.
+	 */
+	if (flags & SWIOTLB_ANY)
+		tlb = memblock_alloc(bytes, PAGE_SIZE);
+	else
+		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

Power SVM wants to allocate a swiotlb buffer that is not restricted to
low memory for the trusted hypervisor scheme.  Consolidate the support
for this into the swiotlb_init interface by adding a new flag.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/powerpc/include/asm/svm.h       |  4 ----
 arch/powerpc/include/asm/swiotlb.h   |  1 +
 arch/powerpc/kernel/dma-swiotlb.c    |  1 +
 arch/powerpc/mm/mem.c                |  5 +----
 arch/powerpc/platforms/pseries/svm.c | 26 +-------------------------
 include/linux/swiotlb.h              |  1 +
 kernel/dma/swiotlb.c                 | 11 +++++++++--
 7 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/arch/powerpc/include/asm/svm.h b/arch/powerpc/include/asm/svm.h
index 7546402d796af..85580b30aba48 100644
--- a/arch/powerpc/include/asm/svm.h
+++ b/arch/powerpc/include/asm/svm.h
@@ -15,8 +15,6 @@ static inline bool is_secure_guest(void)
 	return mfmsr() & MSR_S;
 }
 
-void __init svm_swiotlb_init(void);
-
 void dtl_cache_ctor(void *addr);
 #define get_dtl_cache_ctor()	(is_secure_guest() ? dtl_cache_ctor : NULL)
 
@@ -27,8 +25,6 @@ static inline bool is_secure_guest(void)
 	return false;
 }
 
-static inline void svm_swiotlb_init(void) {}
-
 #define get_dtl_cache_ctor() NULL
 
 #endif /* CONFIG_PPC_SVM */
diff --git a/arch/powerpc/include/asm/swiotlb.h b/arch/powerpc/include/asm/swiotlb.h
index 3c1a1cd161286..4203b5e0a88ed 100644
--- a/arch/powerpc/include/asm/swiotlb.h
+++ b/arch/powerpc/include/asm/swiotlb.h
@@ -9,6 +9,7 @@
 #include <linux/swiotlb.h>
 
 extern unsigned int ppc_swiotlb_enable;
+extern unsigned int ppc_swiotlb_flags;
 
 #ifdef CONFIG_SWIOTLB
 void swiotlb_detect_4g(void);
diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c
index fc7816126a401..ba256c37bcc0f 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -10,6 +10,7 @@
 #include <asm/swiotlb.h>
 
 unsigned int ppc_swiotlb_enable;
+unsigned int ppc_swiotlb_flags;
 
 void __init swiotlb_detect_4g(void)
 {
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index e1519e2edc656..a4d65418c30a9 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -249,10 +249,7 @@ void __init mem_init(void)
 	 * back to to-down.
 	 */
 	memblock_set_bottom_up(true);
-	if (is_secure_guest())
-		svm_swiotlb_init();
-	else
-		swiotlb_init(ppc_swiotlb_enable, 0);
+	swiotlb_init(ppc_swiotlb_enable, ppc_swiotlb_flags);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
index c5228f4969eb2..3b4045d508ec8 100644
--- a/arch/powerpc/platforms/pseries/svm.c
+++ b/arch/powerpc/platforms/pseries/svm.c
@@ -28,7 +28,7 @@ static int __init init_svm(void)
 	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
 	 * otherwise.
 	 */
-	swiotlb_force = SWIOTLB_FORCE;
+	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
 
 	/* Share the SWIOTLB buffer with the host. */
 	swiotlb_update_mem_attributes();
@@ -37,30 +37,6 @@ static int __init init_svm(void)
 }
 machine_early_initcall(pseries, init_svm);
 
-/*
- * Initialize SWIOTLB. Essentially the same as swiotlb_init(), except that it
- * can allocate the buffer anywhere in memory. Since the hypervisor doesn't have
- * any addressing limitation, we don't need to allocate it in low addresses.
- */
-void __init svm_swiotlb_init(void)
-{
-	unsigned char *vstart;
-	unsigned long bytes, io_tlb_nslabs;
-
-	io_tlb_nslabs = (swiotlb_size_or_default() >> IO_TLB_SHIFT);
-	io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
-
-	bytes = io_tlb_nslabs << IO_TLB_SHIFT;
-
-	vstart = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE);
-	if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, false))
-		return;
-
-
-	memblock_free(vstart, PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
-	panic("SVM: Cannot allocate SWIOTLB buffer");
-}
-
 int set_memory_encrypted(unsigned long addr, int numpages)
 {
 	if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index ae0407173e845..eabdd89987027 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -15,6 +15,7 @@ struct scatterlist;
 
 #define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
 #define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
+#define SWIOTLB_ANY	(1 << 2) /* allow any memory for the buffer */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 86e877a96b828..f6e091424af3d 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -266,8 +266,15 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	if (swiotlb_force_disable)
 		return;
 
-	/* Get IO TLB memory from the low pages */
-	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+	/*
+	 * By default allocate the bounce buffer memory from low memory, but
+	 * allow to pick a location everywhere for hypervisors with guest
+	 * memory encryption.
+	 */
+	if (flags & SWIOTLB_ANY)
+		tlb = memblock_alloc(bytes, PAGE_SIZE);
+	else
+		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Power SVM wants to allocate a swiotlb buffer that is not restricted to
low memory for the trusted hypervisor scheme.  Consolidate the support
for this into the swiotlb_init interface by adding a new flag.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/powerpc/include/asm/svm.h       |  4 ----
 arch/powerpc/include/asm/swiotlb.h   |  1 +
 arch/powerpc/kernel/dma-swiotlb.c    |  1 +
 arch/powerpc/mm/mem.c                |  5 +----
 arch/powerpc/platforms/pseries/svm.c | 26 +-------------------------
 include/linux/swiotlb.h              |  1 +
 kernel/dma/swiotlb.c                 | 11 +++++++++--
 7 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/arch/powerpc/include/asm/svm.h b/arch/powerpc/include/asm/svm.h
index 7546402d796af..85580b30aba48 100644
--- a/arch/powerpc/include/asm/svm.h
+++ b/arch/powerpc/include/asm/svm.h
@@ -15,8 +15,6 @@ static inline bool is_secure_guest(void)
 	return mfmsr() & MSR_S;
 }
 
-void __init svm_swiotlb_init(void);
-
 void dtl_cache_ctor(void *addr);
 #define get_dtl_cache_ctor()	(is_secure_guest() ? dtl_cache_ctor : NULL)
 
@@ -27,8 +25,6 @@ static inline bool is_secure_guest(void)
 	return false;
 }
 
-static inline void svm_swiotlb_init(void) {}
-
 #define get_dtl_cache_ctor() NULL
 
 #endif /* CONFIG_PPC_SVM */
diff --git a/arch/powerpc/include/asm/swiotlb.h b/arch/powerpc/include/asm/swiotlb.h
index 3c1a1cd161286..4203b5e0a88ed 100644
--- a/arch/powerpc/include/asm/swiotlb.h
+++ b/arch/powerpc/include/asm/swiotlb.h
@@ -9,6 +9,7 @@
 #include <linux/swiotlb.h>
 
 extern unsigned int ppc_swiotlb_enable;
+extern unsigned int ppc_swiotlb_flags;
 
 #ifdef CONFIG_SWIOTLB
 void swiotlb_detect_4g(void);
diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c
index fc7816126a401..ba256c37bcc0f 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -10,6 +10,7 @@
 #include <asm/swiotlb.h>
 
 unsigned int ppc_swiotlb_enable;
+unsigned int ppc_swiotlb_flags;
 
 void __init swiotlb_detect_4g(void)
 {
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index e1519e2edc656..a4d65418c30a9 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -249,10 +249,7 @@ void __init mem_init(void)
 	 * back to to-down.
 	 */
 	memblock_set_bottom_up(true);
-	if (is_secure_guest())
-		svm_swiotlb_init();
-	else
-		swiotlb_init(ppc_swiotlb_enable, 0);
+	swiotlb_init(ppc_swiotlb_enable, ppc_swiotlb_flags);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
index c5228f4969eb2..3b4045d508ec8 100644
--- a/arch/powerpc/platforms/pseries/svm.c
+++ b/arch/powerpc/platforms/pseries/svm.c
@@ -28,7 +28,7 @@ static int __init init_svm(void)
 	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
 	 * otherwise.
 	 */
-	swiotlb_force = SWIOTLB_FORCE;
+	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
 
 	/* Share the SWIOTLB buffer with the host. */
 	swiotlb_update_mem_attributes();
@@ -37,30 +37,6 @@ static int __init init_svm(void)
 }
 machine_early_initcall(pseries, init_svm);
 
-/*
- * Initialize SWIOTLB. Essentially the same as swiotlb_init(), except that it
- * can allocate the buffer anywhere in memory. Since the hypervisor doesn't have
- * any addressing limitation, we don't need to allocate it in low addresses.
- */
-void __init svm_swiotlb_init(void)
-{
-	unsigned char *vstart;
-	unsigned long bytes, io_tlb_nslabs;
-
-	io_tlb_nslabs = (swiotlb_size_or_default() >> IO_TLB_SHIFT);
-	io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
-
-	bytes = io_tlb_nslabs << IO_TLB_SHIFT;
-
-	vstart = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE);
-	if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, false))
-		return;
-
-
-	memblock_free(vstart, PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
-	panic("SVM: Cannot allocate SWIOTLB buffer");
-}
-
 int set_memory_encrypted(unsigned long addr, int numpages)
 {
 	if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index ae0407173e845..eabdd89987027 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -15,6 +15,7 @@ struct scatterlist;
 
 #define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
 #define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
+#define SWIOTLB_ANY	(1 << 2) /* allow any memory for the buffer */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 86e877a96b828..f6e091424af3d 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -266,8 +266,15 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	if (swiotlb_force_disable)
 		return;
 
-	/* Get IO TLB memory from the low pages */
-	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+	/*
+	 * By default allocate the bounce buffer memory from low memory, but
+	 * allow to pick a location everywhere for hypervisors with guest
+	 * memory encryption.
+	 */
+	if (flags & SWIOTLB_ANY)
+		tlb = memblock_alloc(bytes, PAGE_SIZE);
+	else
+		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 11/15] swiotlb: pass a gfp_mask argument to swiotlb_init_late
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Let the caller chose a zone to allocate from.  This will be used
later on by the xen-swiotlb initialization on arm.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/pci/sta2x11-fixup.c | 2 +-
 include/linux/swiotlb.h      | 2 +-
 kernel/dma/swiotlb.c         | 7 ++-----
 3 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index e0c039a75b2db..c7e6faf59a861 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_init_late(size))
+		if (swiotlb_init_late(size, GFP_DMA))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index eabdd89987027..ee655f2e4d28b 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -37,7 +37,7 @@ struct scatterlist;
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-int swiotlb_init_late(size_t size);
+int swiotlb_init_late(size_t size, gfp_t gfp_mask);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index f6e091424af3d..119187afc65ec 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -292,7 +292,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int swiotlb_init_late(size_t size)
+int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 {
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
@@ -303,15 +303,12 @@ int swiotlb_init_late(size_t size)
 	if (swiotlb_force_disable)
 		return 0;
 
-	/*
-	 * Get IO TLB memory from the low pages
-	 */
 	order = get_order(nslabs << IO_TLB_SHIFT);
 	nslabs = SLABS_PER_PAGE << order;
 	bytes = nslabs << IO_TLB_SHIFT;
 
 	while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
-		vstart = (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN,
+		vstart = (void *)__get_free_pages(gfp_mask | __GFP_NOWARN,
 						  order);
 		if (vstart)
 			break;
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 11/15] swiotlb: pass a gfp_mask argument to swiotlb_init_late
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Let the caller chose a zone to allocate from.  This will be used
later on by the xen-swiotlb initialization on arm.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/pci/sta2x11-fixup.c | 2 +-
 include/linux/swiotlb.h      | 2 +-
 kernel/dma/swiotlb.c         | 7 ++-----
 3 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index e0c039a75b2db..c7e6faf59a861 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_init_late(size))
+		if (swiotlb_init_late(size, GFP_DMA))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index eabdd89987027..ee655f2e4d28b 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -37,7 +37,7 @@ struct scatterlist;
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-int swiotlb_init_late(size_t size);
+int swiotlb_init_late(size_t size, gfp_t gfp_mask);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index f6e091424af3d..119187afc65ec 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -292,7 +292,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int swiotlb_init_late(size_t size)
+int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 {
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
@@ -303,15 +303,12 @@ int swiotlb_init_late(size_t size)
 	if (swiotlb_force_disable)
 		return 0;
 
-	/*
-	 * Get IO TLB memory from the low pages
-	 */
 	order = get_order(nslabs << IO_TLB_SHIFT);
 	nslabs = SLABS_PER_PAGE << order;
 	bytes = nslabs << IO_TLB_SHIFT;
 
 	while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
-		vstart = (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN,
+		vstart = (void *)__get_free_pages(gfp_mask | __GFP_NOWARN,
 						  order);
 		if (vstart)
 			break;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 11/15] swiotlb: pass a gfp_mask argument to swiotlb_init_late
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Let the caller chose a zone to allocate from.  This will be used
later on by the xen-swiotlb initialization on arm.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/pci/sta2x11-fixup.c | 2 +-
 include/linux/swiotlb.h      | 2 +-
 kernel/dma/swiotlb.c         | 7 ++-----
 3 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index e0c039a75b2db..c7e6faf59a861 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_init_late(size))
+		if (swiotlb_init_late(size, GFP_DMA))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index eabdd89987027..ee655f2e4d28b 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -37,7 +37,7 @@ struct scatterlist;
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-int swiotlb_init_late(size_t size);
+int swiotlb_init_late(size_t size, gfp_t gfp_mask);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index f6e091424af3d..119187afc65ec 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -292,7 +292,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int swiotlb_init_late(size_t size)
+int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 {
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
@@ -303,15 +303,12 @@ int swiotlb_init_late(size_t size)
 	if (swiotlb_force_disable)
 		return 0;
 
-	/*
-	 * Get IO TLB memory from the low pages
-	 */
 	order = get_order(nslabs << IO_TLB_SHIFT);
 	nslabs = SLABS_PER_PAGE << order;
 	bytes = nslabs << IO_TLB_SHIFT;
 
 	while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
-		vstart = (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN,
+		vstart = (void *)__get_free_pages(gfp_mask | __GFP_NOWARN,
 						  order);
 		if (vstart)
 			break;
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 11/15] swiotlb: pass a gfp_mask argument to swiotlb_init_late
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Let the caller chose a zone to allocate from.  This will be used
later on by the xen-swiotlb initialization on arm.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/pci/sta2x11-fixup.c | 2 +-
 include/linux/swiotlb.h      | 2 +-
 kernel/dma/swiotlb.c         | 7 ++-----
 3 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index e0c039a75b2db..c7e6faf59a861 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_init_late(size))
+		if (swiotlb_init_late(size, GFP_DMA))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index eabdd89987027..ee655f2e4d28b 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -37,7 +37,7 @@ struct scatterlist;
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-int swiotlb_init_late(size_t size);
+int swiotlb_init_late(size_t size, gfp_t gfp_mask);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index f6e091424af3d..119187afc65ec 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -292,7 +292,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int swiotlb_init_late(size_t size)
+int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 {
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
@@ -303,15 +303,12 @@ int swiotlb_init_late(size_t size)
 	if (swiotlb_force_disable)
 		return 0;
 
-	/*
-	 * Get IO TLB memory from the low pages
-	 */
 	order = get_order(nslabs << IO_TLB_SHIFT);
 	nslabs = SLABS_PER_PAGE << order;
 	bytes = nslabs << IO_TLB_SHIFT;
 
 	while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
-		vstart = (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN,
+		vstart = (void *)__get_free_pages(gfp_mask | __GFP_NOWARN,
 						  order);
 		if (vstart)
 			break;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 11/15] swiotlb: pass a gfp_mask argument to swiotlb_init_late
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

Let the caller chose a zone to allocate from.  This will be used
later on by the xen-swiotlb initialization on arm.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/pci/sta2x11-fixup.c | 2 +-
 include/linux/swiotlb.h      | 2 +-
 kernel/dma/swiotlb.c         | 7 ++-----
 3 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index e0c039a75b2db..c7e6faf59a861 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_init_late(size))
+		if (swiotlb_init_late(size, GFP_DMA))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index eabdd89987027..ee655f2e4d28b 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -37,7 +37,7 @@ struct scatterlist;
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-int swiotlb_init_late(size_t size);
+int swiotlb_init_late(size_t size, gfp_t gfp_mask);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index f6e091424af3d..119187afc65ec 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -292,7 +292,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int swiotlb_init_late(size_t size)
+int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 {
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
@@ -303,15 +303,12 @@ int swiotlb_init_late(size_t size)
 	if (swiotlb_force_disable)
 		return 0;
 
-	/*
-	 * Get IO TLB memory from the low pages
-	 */
 	order = get_order(nslabs << IO_TLB_SHIFT);
 	nslabs = SLABS_PER_PAGE << order;
 	bytes = nslabs << IO_TLB_SHIFT;
 
 	while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
-		vstart = (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN,
+		vstart = (void *)__get_free_pages(gfp_mask | __GFP_NOWARN,
 						  order);
 		if (vstart)
 			break;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 11/15] swiotlb: pass a gfp_mask argument to swiotlb_init_late
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Let the caller chose a zone to allocate from.  This will be used
later on by the xen-swiotlb initialization on arm.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/pci/sta2x11-fixup.c | 2 +-
 include/linux/swiotlb.h      | 2 +-
 kernel/dma/swiotlb.c         | 7 ++-----
 3 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index e0c039a75b2db..c7e6faf59a861 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_init_late(size))
+		if (swiotlb_init_late(size, GFP_DMA))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index eabdd89987027..ee655f2e4d28b 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -37,7 +37,7 @@ struct scatterlist;
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-int swiotlb_init_late(size_t size);
+int swiotlb_init_late(size_t size, gfp_t gfp_mask);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index f6e091424af3d..119187afc65ec 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -292,7 +292,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int swiotlb_init_late(size_t size)
+int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 {
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
@@ -303,15 +303,12 @@ int swiotlb_init_late(size_t size)
 	if (swiotlb_force_disable)
 		return 0;
 
-	/*
-	 * Get IO TLB memory from the low pages
-	 */
 	order = get_order(nslabs << IO_TLB_SHIFT);
 	nslabs = SLABS_PER_PAGE << order;
 	bytes = nslabs << IO_TLB_SHIFT;
 
 	while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
-		vstart = (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN,
+		vstart = (void *)__get_free_pages(gfp_mask | __GFP_NOWARN,
 						  order);
 		if (vstart)
 			break;
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

To shared more code between swiotlb and xen-swiotlb, offer a
swiotlb_init_remap interface and add a remap callback to
swiotlb_init_late that will allow Xen to remap the buffer the
buffer without duplicating much of the logic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/pci/sta2x11-fixup.c |  2 +-
 include/linux/swiotlb.h      |  5 ++++-
 kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
 3 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index c7e6faf59a861..7368afc039987 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_init_late(size, GFP_DMA))
+		if (swiotlb_init_late(size, GFP_DMA, NULL))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index ee655f2e4d28b..7b50c82f84ce9 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -36,8 +36,11 @@ struct scatterlist;
 
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+	int (*remap)(void *tlb, unsigned long nslabs));
+int swiotlb_init_late(size_t size, gfp_t gfp_mask,
+	int (*remap)(void *tlb, unsigned long nslabs));
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-int swiotlb_init_late(size_t size, gfp_t gfp_mask);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 119187afc65ec..d5fe8f5e08300 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void __init swiotlb_init(bool addressing_limit, unsigned int flags)
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+		int (*remap)(void *tlb, unsigned long nslabs))
 {
-	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
+	unsigned long nslabs = default_nslabs;
+	size_t bytes;
 	void *tlb;
 
 	if (!addressing_limit && !swiotlb_force_bounce)
@@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	 * allow to pick a location everywhere for hypervisors with guest
 	 * memory encryption.
 	 */
+retry:
+	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	if (flags & SWIOTLB_ANY)
 		tlb = memblock_alloc(bytes, PAGE_SIZE);
 	else
 		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
+	if (remap && remap(tlb, nslabs) < 0) {
+		memblock_free(tlb, PAGE_ALIGN(bytes));
+
+		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
+		if (nslabs < IO_TLB_MIN_SLABS)
+			panic("%s: Failed to remap %zu bytes\n",
+			      __func__, bytes);
+		goto retry;
+	}
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
@@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	pr_warn("Cannot allocate buffer");
 }
 
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
+{
+	return swiotlb_init_remap(addressing_limit, flags, NULL);
+}
+
 /*
  * Systems with larger DMA zones (those that don't support ISA) can
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int swiotlb_init_late(size_t size, gfp_t gfp_mask)
+int swiotlb_init_late(size_t size, gfp_t gfp_mask,
+		int (*remap)(void *tlb, unsigned long nslabs))
 {
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
@@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 	if (swiotlb_force_disable)
 		return 0;
 
+retry:
 	order = get_order(nslabs << IO_TLB_SHIFT);
 	nslabs = SLABS_PER_PAGE << order;
 	bytes = nslabs << IO_TLB_SHIFT;
@@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 			(PAGE_SIZE << order) >> 20);
 		nslabs = SLABS_PER_PAGE << order;
 	}
+	if (remap)
+		rc = remap(vstart, nslabs);
+	if (rc) {
+		free_pages((unsigned long)vstart, order);
+ 
+		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
+		if (nslabs < IO_TLB_MIN_SLABS)
+			return rc;
+		goto retry;
+	}
 	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
 	if (rc)
 		free_pages((unsigned long)vstart, order);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

To shared more code between swiotlb and xen-swiotlb, offer a
swiotlb_init_remap interface and add a remap callback to
swiotlb_init_late that will allow Xen to remap the buffer the
buffer without duplicating much of the logic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/pci/sta2x11-fixup.c |  2 +-
 include/linux/swiotlb.h      |  5 ++++-
 kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
 3 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index c7e6faf59a861..7368afc039987 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_init_late(size, GFP_DMA))
+		if (swiotlb_init_late(size, GFP_DMA, NULL))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index ee655f2e4d28b..7b50c82f84ce9 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -36,8 +36,11 @@ struct scatterlist;
 
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+	int (*remap)(void *tlb, unsigned long nslabs));
+int swiotlb_init_late(size_t size, gfp_t gfp_mask,
+	int (*remap)(void *tlb, unsigned long nslabs));
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-int swiotlb_init_late(size_t size, gfp_t gfp_mask);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 119187afc65ec..d5fe8f5e08300 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void __init swiotlb_init(bool addressing_limit, unsigned int flags)
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+		int (*remap)(void *tlb, unsigned long nslabs))
 {
-	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
+	unsigned long nslabs = default_nslabs;
+	size_t bytes;
 	void *tlb;
 
 	if (!addressing_limit && !swiotlb_force_bounce)
@@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	 * allow to pick a location everywhere for hypervisors with guest
 	 * memory encryption.
 	 */
+retry:
+	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	if (flags & SWIOTLB_ANY)
 		tlb = memblock_alloc(bytes, PAGE_SIZE);
 	else
 		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
+	if (remap && remap(tlb, nslabs) < 0) {
+		memblock_free(tlb, PAGE_ALIGN(bytes));
+
+		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
+		if (nslabs < IO_TLB_MIN_SLABS)
+			panic("%s: Failed to remap %zu bytes\n",
+			      __func__, bytes);
+		goto retry;
+	}
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
@@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	pr_warn("Cannot allocate buffer");
 }
 
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
+{
+	return swiotlb_init_remap(addressing_limit, flags, NULL);
+}
+
 /*
  * Systems with larger DMA zones (those that don't support ISA) can
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int swiotlb_init_late(size_t size, gfp_t gfp_mask)
+int swiotlb_init_late(size_t size, gfp_t gfp_mask,
+		int (*remap)(void *tlb, unsigned long nslabs))
 {
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
@@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 	if (swiotlb_force_disable)
 		return 0;
 
+retry:
 	order = get_order(nslabs << IO_TLB_SHIFT);
 	nslabs = SLABS_PER_PAGE << order;
 	bytes = nslabs << IO_TLB_SHIFT;
@@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 			(PAGE_SIZE << order) >> 20);
 		nslabs = SLABS_PER_PAGE << order;
 	}
+	if (remap)
+		rc = remap(vstart, nslabs);
+	if (rc) {
+		free_pages((unsigned long)vstart, order);
+ 
+		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
+		if (nslabs < IO_TLB_MIN_SLABS)
+			return rc;
+		goto retry;
+	}
 	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
 	if (rc)
 		free_pages((unsigned long)vstart, order);
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

To shared more code between swiotlb and xen-swiotlb, offer a
swiotlb_init_remap interface and add a remap callback to
swiotlb_init_late that will allow Xen to remap the buffer the
buffer without duplicating much of the logic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/pci/sta2x11-fixup.c |  2 +-
 include/linux/swiotlb.h      |  5 ++++-
 kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
 3 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index c7e6faf59a861..7368afc039987 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_init_late(size, GFP_DMA))
+		if (swiotlb_init_late(size, GFP_DMA, NULL))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index ee655f2e4d28b..7b50c82f84ce9 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -36,8 +36,11 @@ struct scatterlist;
 
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+	int (*remap)(void *tlb, unsigned long nslabs));
+int swiotlb_init_late(size_t size, gfp_t gfp_mask,
+	int (*remap)(void *tlb, unsigned long nslabs));
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-int swiotlb_init_late(size_t size, gfp_t gfp_mask);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 119187afc65ec..d5fe8f5e08300 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void __init swiotlb_init(bool addressing_limit, unsigned int flags)
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+		int (*remap)(void *tlb, unsigned long nslabs))
 {
-	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
+	unsigned long nslabs = default_nslabs;
+	size_t bytes;
 	void *tlb;
 
 	if (!addressing_limit && !swiotlb_force_bounce)
@@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	 * allow to pick a location everywhere for hypervisors with guest
 	 * memory encryption.
 	 */
+retry:
+	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	if (flags & SWIOTLB_ANY)
 		tlb = memblock_alloc(bytes, PAGE_SIZE);
 	else
 		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
+	if (remap && remap(tlb, nslabs) < 0) {
+		memblock_free(tlb, PAGE_ALIGN(bytes));
+
+		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
+		if (nslabs < IO_TLB_MIN_SLABS)
+			panic("%s: Failed to remap %zu bytes\n",
+			      __func__, bytes);
+		goto retry;
+	}
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
@@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	pr_warn("Cannot allocate buffer");
 }
 
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
+{
+	return swiotlb_init_remap(addressing_limit, flags, NULL);
+}
+
 /*
  * Systems with larger DMA zones (those that don't support ISA) can
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int swiotlb_init_late(size_t size, gfp_t gfp_mask)
+int swiotlb_init_late(size_t size, gfp_t gfp_mask,
+		int (*remap)(void *tlb, unsigned long nslabs))
 {
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
@@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 	if (swiotlb_force_disable)
 		return 0;
 
+retry:
 	order = get_order(nslabs << IO_TLB_SHIFT);
 	nslabs = SLABS_PER_PAGE << order;
 	bytes = nslabs << IO_TLB_SHIFT;
@@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 			(PAGE_SIZE << order) >> 20);
 		nslabs = SLABS_PER_PAGE << order;
 	}
+	if (remap)
+		rc = remap(vstart, nslabs);
+	if (rc) {
+		free_pages((unsigned long)vstart, order);
+ 
+		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
+		if (nslabs < IO_TLB_MIN_SLABS)
+			return rc;
+		goto retry;
+	}
 	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
 	if (rc)
 		free_pages((unsigned long)vstart, order);
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

To shared more code between swiotlb and xen-swiotlb, offer a
swiotlb_init_remap interface and add a remap callback to
swiotlb_init_late that will allow Xen to remap the buffer the
buffer without duplicating much of the logic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/pci/sta2x11-fixup.c |  2 +-
 include/linux/swiotlb.h      |  5 ++++-
 kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
 3 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index c7e6faf59a861..7368afc039987 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_init_late(size, GFP_DMA))
+		if (swiotlb_init_late(size, GFP_DMA, NULL))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index ee655f2e4d28b..7b50c82f84ce9 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -36,8 +36,11 @@ struct scatterlist;
 
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+	int (*remap)(void *tlb, unsigned long nslabs));
+int swiotlb_init_late(size_t size, gfp_t gfp_mask,
+	int (*remap)(void *tlb, unsigned long nslabs));
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-int swiotlb_init_late(size_t size, gfp_t gfp_mask);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 119187afc65ec..d5fe8f5e08300 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void __init swiotlb_init(bool addressing_limit, unsigned int flags)
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+		int (*remap)(void *tlb, unsigned long nslabs))
 {
-	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
+	unsigned long nslabs = default_nslabs;
+	size_t bytes;
 	void *tlb;
 
 	if (!addressing_limit && !swiotlb_force_bounce)
@@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	 * allow to pick a location everywhere for hypervisors with guest
 	 * memory encryption.
 	 */
+retry:
+	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	if (flags & SWIOTLB_ANY)
 		tlb = memblock_alloc(bytes, PAGE_SIZE);
 	else
 		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
+	if (remap && remap(tlb, nslabs) < 0) {
+		memblock_free(tlb, PAGE_ALIGN(bytes));
+
+		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
+		if (nslabs < IO_TLB_MIN_SLABS)
+			panic("%s: Failed to remap %zu bytes\n",
+			      __func__, bytes);
+		goto retry;
+	}
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
@@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	pr_warn("Cannot allocate buffer");
 }
 
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
+{
+	return swiotlb_init_remap(addressing_limit, flags, NULL);
+}
+
 /*
  * Systems with larger DMA zones (those that don't support ISA) can
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int swiotlb_init_late(size_t size, gfp_t gfp_mask)
+int swiotlb_init_late(size_t size, gfp_t gfp_mask,
+		int (*remap)(void *tlb, unsigned long nslabs))
 {
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
@@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 	if (swiotlb_force_disable)
 		return 0;
 
+retry:
 	order = get_order(nslabs << IO_TLB_SHIFT);
 	nslabs = SLABS_PER_PAGE << order;
 	bytes = nslabs << IO_TLB_SHIFT;
@@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 			(PAGE_SIZE << order) >> 20);
 		nslabs = SLABS_PER_PAGE << order;
 	}
+	if (remap)
+		rc = remap(vstart, nslabs);
+	if (rc) {
+		free_pages((unsigned long)vstart, order);
+ 
+		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
+		if (nslabs < IO_TLB_MIN_SLABS)
+			return rc;
+		goto retry;
+	}
 	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
 	if (rc)
 		free_pages((unsigned long)vstart, order);
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

To shared more code between swiotlb and xen-swiotlb, offer a
swiotlb_init_remap interface and add a remap callback to
swiotlb_init_late that will allow Xen to remap the buffer the
buffer without duplicating much of the logic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/pci/sta2x11-fixup.c |  2 +-
 include/linux/swiotlb.h      |  5 ++++-
 kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
 3 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index c7e6faf59a861..7368afc039987 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_init_late(size, GFP_DMA))
+		if (swiotlb_init_late(size, GFP_DMA, NULL))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index ee655f2e4d28b..7b50c82f84ce9 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -36,8 +36,11 @@ struct scatterlist;
 
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+	int (*remap)(void *tlb, unsigned long nslabs));
+int swiotlb_init_late(size_t size, gfp_t gfp_mask,
+	int (*remap)(void *tlb, unsigned long nslabs));
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-int swiotlb_init_late(size_t size, gfp_t gfp_mask);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 119187afc65ec..d5fe8f5e08300 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void __init swiotlb_init(bool addressing_limit, unsigned int flags)
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+		int (*remap)(void *tlb, unsigned long nslabs))
 {
-	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
+	unsigned long nslabs = default_nslabs;
+	size_t bytes;
 	void *tlb;
 
 	if (!addressing_limit && !swiotlb_force_bounce)
@@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	 * allow to pick a location everywhere for hypervisors with guest
 	 * memory encryption.
 	 */
+retry:
+	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	if (flags & SWIOTLB_ANY)
 		tlb = memblock_alloc(bytes, PAGE_SIZE);
 	else
 		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
+	if (remap && remap(tlb, nslabs) < 0) {
+		memblock_free(tlb, PAGE_ALIGN(bytes));
+
+		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
+		if (nslabs < IO_TLB_MIN_SLABS)
+			panic("%s: Failed to remap %zu bytes\n",
+			      __func__, bytes);
+		goto retry;
+	}
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
@@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	pr_warn("Cannot allocate buffer");
 }
 
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
+{
+	return swiotlb_init_remap(addressing_limit, flags, NULL);
+}
+
 /*
  * Systems with larger DMA zones (those that don't support ISA) can
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int swiotlb_init_late(size_t size, gfp_t gfp_mask)
+int swiotlb_init_late(size_t size, gfp_t gfp_mask,
+		int (*remap)(void *tlb, unsigned long nslabs))
 {
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
@@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 	if (swiotlb_force_disable)
 		return 0;
 
+retry:
 	order = get_order(nslabs << IO_TLB_SHIFT);
 	nslabs = SLABS_PER_PAGE << order;
 	bytes = nslabs << IO_TLB_SHIFT;
@@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 			(PAGE_SIZE << order) >> 20);
 		nslabs = SLABS_PER_PAGE << order;
 	}
+	if (remap)
+		rc = remap(vstart, nslabs);
+	if (rc) {
+		free_pages((unsigned long)vstart, order);
+ 
+		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
+		if (nslabs < IO_TLB_MIN_SLABS)
+			return rc;
+		goto retry;
+	}
 	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
 	if (rc)
 		free_pages((unsigned long)vstart, order);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

To shared more code between swiotlb and xen-swiotlb, offer a
swiotlb_init_remap interface and add a remap callback to
swiotlb_init_late that will allow Xen to remap the buffer the
buffer without duplicating much of the logic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/pci/sta2x11-fixup.c |  2 +-
 include/linux/swiotlb.h      |  5 ++++-
 kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
 3 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
index c7e6faf59a861..7368afc039987 100644
--- a/arch/x86/pci/sta2x11-fixup.c
+++ b/arch/x86/pci/sta2x11-fixup.c
@@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
 		int size = STA2X11_SWIOTLB_SIZE;
 		/* First instance: register your own swiotlb area */
 		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
-		if (swiotlb_init_late(size, GFP_DMA))
+		if (swiotlb_init_late(size, GFP_DMA, NULL))
 			dev_emerg(&pdev->dev, "init swiotlb failed\n");
 	}
 	list_add(&instance->list, &sta2x11_instance_list);
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index ee655f2e4d28b..7b50c82f84ce9 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -36,8 +36,11 @@ struct scatterlist;
 
 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+	int (*remap)(void *tlb, unsigned long nslabs));
+int swiotlb_init_late(size_t size, gfp_t gfp_mask,
+	int (*remap)(void *tlb, unsigned long nslabs));
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
-int swiotlb_init_late(size_t size, gfp_t gfp_mask);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 119187afc65ec..d5fe8f5e08300 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void __init swiotlb_init(bool addressing_limit, unsigned int flags)
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+		int (*remap)(void *tlb, unsigned long nslabs))
 {
-	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
+	unsigned long nslabs = default_nslabs;
+	size_t bytes;
 	void *tlb;
 
 	if (!addressing_limit && !swiotlb_force_bounce)
@@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	 * allow to pick a location everywhere for hypervisors with guest
 	 * memory encryption.
 	 */
+retry:
+	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	if (flags & SWIOTLB_ANY)
 		tlb = memblock_alloc(bytes, PAGE_SIZE);
 	else
 		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
+	if (remap && remap(tlb, nslabs) < 0) {
+		memblock_free(tlb, PAGE_ALIGN(bytes));
+
+		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
+		if (nslabs < IO_TLB_MIN_SLABS)
+			panic("%s: Failed to remap %zu bytes\n",
+			      __func__, bytes);
+		goto retry;
+	}
 	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
@@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 	pr_warn("Cannot allocate buffer");
 }
 
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
+{
+	return swiotlb_init_remap(addressing_limit, flags, NULL);
+}
+
 /*
  * Systems with larger DMA zones (those that don't support ISA) can
  * initialize the swiotlb later using the slab allocator if needed.
  * This should be just like above, but with some error catching.
  */
-int swiotlb_init_late(size_t size, gfp_t gfp_mask)
+int swiotlb_init_late(size_t size, gfp_t gfp_mask,
+		int (*remap)(void *tlb, unsigned long nslabs))
 {
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
@@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 	if (swiotlb_force_disable)
 		return 0;
 
+retry:
 	order = get_order(nslabs << IO_TLB_SHIFT);
 	nslabs = SLABS_PER_PAGE << order;
 	bytes = nslabs << IO_TLB_SHIFT;
@@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
 			(PAGE_SIZE << order) >> 20);
 		nslabs = SLABS_PER_PAGE << order;
 	}
+	if (remap)
+		rc = remap(vstart, nslabs);
+	if (rc) {
+		free_pages((unsigned long)vstart, order);
+ 
+		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
+		if (nslabs < IO_TLB_MIN_SLABS)
+			return rc;
+		goto retry;
+	}
 	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
 	if (rc)
 		free_pages((unsigned long)vstart, order);
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 13/15] swiotlb: merge swiotlb-xen initialization into swiotlb
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Reuse the generic swiotlb initialization for xen-swiotlb.  For ARM/ARM64
this works trivially, while for x86 xen_swiotlb_fixup needs to be passed
as the remap argument to swiotlb_init_remap/swiotlb_init_late.

Note that the lower bound of the swiotlb size is changed to the smaller
IO_TLB_MIN_SLABS based value with this patch, but that is fine as the
2MB value used in Xen before was just an optimization and is not the
hard lower bound.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 arch/arm/xen/mm.c               |  21 +++---
 arch/x86/include/asm/xen/page.h |   5 --
 arch/x86/kernel/pci-dma.c       |  20 ++---
 drivers/xen/swiotlb-xen.c       | 128 +-------------------------------
 include/xen/arm/page.h          |   1 -
 include/xen/swiotlb-xen.h       |   8 +-
 6 files changed, 28 insertions(+), 155 deletions(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index 28c2070602535..ff05a7899cb86 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -23,22 +23,20 @@
 #include <asm/xen/hypercall.h>
 #include <asm/xen/interface.h>
 
-unsigned long xen_get_swiotlb_free_pages(unsigned int order)
+static gfp_t xen_swiotlb_gfp(void)
 {
 	phys_addr_t base;
-	gfp_t flags = __GFP_NOWARN|__GFP_KSWAPD_RECLAIM;
 	u64 i;
 
 	for_each_mem_range(i, &base, NULL) {
 		if (base < (phys_addr_t)0xffffffff) {
 			if (IS_ENABLED(CONFIG_ZONE_DMA32))
-				flags |= __GFP_DMA32;
-			else
-				flags |= __GFP_DMA;
-			break;
+				return __GFP_DMA32;
+			return __GFP_DMA;
 		}
 	}
-	return __get_free_pages(flags, order);
+
+	return GFP_KERNEL;
 }
 
 static bool hypercall_cflush = false;
@@ -140,10 +138,13 @@ static int __init xen_mm_init(void)
 	if (!xen_swiotlb_detect())
 		return 0;
 
-	rc = xen_swiotlb_init();
 	/* we can work with the default swiotlb */
-	if (rc < 0 && rc != -EEXIST)
-		return rc;
+	if (!io_tlb_default_mem.nslabs) {
+		rc = swiotlb_init_late(swiotlb_size_or_default(),
+				       xen_swiotlb_gfp(), NULL);
+		if (rc < 0)
+			return rc;
+	}
 
 	cflush.op = 0;
 	cflush.a.dev_bus_addr = 0;
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index e989bc2269f54..1fc67df500145 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -357,9 +357,4 @@ static inline bool xen_arch_need_swiotlb(struct device *dev,
 	return false;
 }
 
-static inline unsigned long xen_get_swiotlb_free_pages(unsigned int order)
-{
-	return __get_free_pages(__GFP_NOWARN, order);
-}
-
 #endif /* _ASM_X86_XEN_PAGE_H */
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index a705a199bf8a3..30bbe4abb5d61 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -72,15 +72,13 @@ static inline void __init pci_swiotlb_detect(void)
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
-static bool xen_swiotlb;
-
 static void __init pci_xen_swiotlb_init(void)
 {
 	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
-	xen_swiotlb = true;
-	xen_swiotlb_init_early();
+	x86_swiotlb_flags |= SWIOTLB_ANY;
+	swiotlb_init_remap(true, x86_swiotlb_flags, xen_swiotlb_fixup);
 	dma_ops = &xen_swiotlb_dma_ops;
 	if (IS_ENABLED(CONFIG_PCI))
 		pci_request_acs();
@@ -88,14 +86,16 @@ static void __init pci_xen_swiotlb_init(void)
 
 int pci_xen_swiotlb_init_late(void)
 {
-	int rc;
-
-	if (xen_swiotlb)
+	if (dma_ops == &xen_swiotlb_dma_ops)
 		return 0;
 
-	rc = xen_swiotlb_init();
-	if (rc)
-		return rc;
+	/* we can work with the default swiotlb */
+	if (!io_tlb_default_mem.nslabs) {
+		int rc = swiotlb_init_late(swiotlb_size_or_default(),
+					   GFP_KERNEL, xen_swiotlb_fixup);
+		if (rc < 0)
+			return rc;
+	}
 
 	/* XXX: this switches the dma ops under live devices! */
 	dma_ops = &xen_swiotlb_dma_ops;
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index c2da3eb4826e8..df8085b50df10 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -104,7 +104,7 @@ static int is_xen_swiotlb_buffer(struct device *dev, dma_addr_t dma_addr)
 	return 0;
 }
 
-static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
+int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
 {
 	int rc;
 	unsigned int order = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT);
@@ -130,132 +130,6 @@ static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
 	return 0;
 }
 
-enum xen_swiotlb_err {
-	XEN_SWIOTLB_UNKNOWN = 0,
-	XEN_SWIOTLB_ENOMEM,
-	XEN_SWIOTLB_EFIXUP
-};
-
-static const char *xen_swiotlb_error(enum xen_swiotlb_err err)
-{
-	switch (err) {
-	case XEN_SWIOTLB_ENOMEM:
-		return "Cannot allocate Xen-SWIOTLB buffer\n";
-	case XEN_SWIOTLB_EFIXUP:
-		return "Failed to get contiguous memory for DMA from Xen!\n"\
-		    "You either: don't have the permissions, do not have"\
-		    " enough free memory under 4GB, or the hypervisor memory"\
-		    " is too fragmented!";
-	default:
-		break;
-	}
-	return "";
-}
-
-int xen_swiotlb_init(void)
-{
-	enum xen_swiotlb_err m_ret = XEN_SWIOTLB_UNKNOWN;
-	unsigned long bytes = swiotlb_size_or_default();
-	unsigned long nslabs = bytes >> IO_TLB_SHIFT;
-	unsigned int order, repeat = 3;
-	int rc = -ENOMEM;
-	char *start;
-
-	if (io_tlb_default_mem.nslabs) {
-		pr_warn("swiotlb buffer already initialized\n");
-		return -EEXIST;
-	}
-
-retry:
-	m_ret = XEN_SWIOTLB_ENOMEM;
-	order = get_order(bytes);
-
-	/*
-	 * Get IO TLB memory from any location.
-	 */
-#define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT))
-#define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
-	while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
-		start = (void *)xen_get_swiotlb_free_pages(order);
-		if (start)
-			break;
-		order--;
-	}
-	if (!start)
-		goto exit;
-	if (order != get_order(bytes)) {
-		pr_warn("Warning: only able to allocate %ld MB for software IO TLB\n",
-			(PAGE_SIZE << order) >> 20);
-		nslabs = SLABS_PER_PAGE << order;
-		bytes = nslabs << IO_TLB_SHIFT;
-	}
-
-	/*
-	 * And replace that memory with pages under 4GB.
-	 */
-	rc = xen_swiotlb_fixup(start, nslabs);
-	if (rc) {
-		free_pages((unsigned long)start, order);
-		m_ret = XEN_SWIOTLB_EFIXUP;
-		goto error;
-	}
-	rc = swiotlb_late_init_with_tbl(start, nslabs);
-	if (rc)
-		return rc;
-	return 0;
-error:
-	if (nslabs > 1024 && repeat--) {
-		/* Min is 2MB */
-		nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
-		bytes = nslabs << IO_TLB_SHIFT;
-		pr_info("Lowering to %luMB\n", bytes >> 20);
-		goto retry;
-	}
-exit:
-	pr_err("%s (rc:%d)\n", xen_swiotlb_error(m_ret), rc);
-	return rc;
-}
-
-#ifdef CONFIG_X86
-void __init xen_swiotlb_init_early(void)
-{
-	unsigned long bytes = swiotlb_size_or_default();
-	unsigned long nslabs = bytes >> IO_TLB_SHIFT;
-	unsigned int repeat = 3;
-	char *start;
-	int rc;
-
-retry:
-	/*
-	 * Get IO TLB memory from any location.
-	 */
-	start = memblock_alloc(PAGE_ALIGN(bytes),
-			       IO_TLB_SEGSIZE << IO_TLB_SHIFT);
-	if (!start)
-		panic("%s: Failed to allocate %lu bytes\n",
-		      __func__, PAGE_ALIGN(bytes));
-
-	/*
-	 * And replace that memory with pages under 4GB.
-	 */
-	rc = xen_swiotlb_fixup(start, nslabs);
-	if (rc) {
-		memblock_free(start, PAGE_ALIGN(bytes));
-		if (nslabs > 1024 && repeat--) {
-			/* Min is 2MB */
-			nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
-			bytes = nslabs << IO_TLB_SHIFT;
-			pr_info("Lowering to %luMB\n", bytes >> 20);
-			goto retry;
-		}
-		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
-	}
-
-	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
-		panic("Cannot allocate SWIOTLB buffer");
-}
-#endif /* CONFIG_X86 */
-
 static void *
 xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
 			   dma_addr_t *dma_handle, gfp_t flags,
diff --git a/include/xen/arm/page.h b/include/xen/arm/page.h
index ac1b654705631..7e199c6656b90 100644
--- a/include/xen/arm/page.h
+++ b/include/xen/arm/page.h
@@ -115,6 +115,5 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
 bool xen_arch_need_swiotlb(struct device *dev,
 			   phys_addr_t phys,
 			   dma_addr_t dev_addr);
-unsigned long xen_get_swiotlb_free_pages(unsigned int order);
 
 #endif /* _ASM_ARM_XEN_PAGE_H */
diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h
index b3e647f86e3e2..590ceb923f0c8 100644
--- a/include/xen/swiotlb-xen.h
+++ b/include/xen/swiotlb-xen.h
@@ -10,8 +10,12 @@ void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle,
 void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,
 			     size_t size, enum dma_data_direction dir);
 
-int xen_swiotlb_init(void);
-void __init xen_swiotlb_init_early(void);
+#ifdef CONFIG_SWIOTLB_XEN
+int xen_swiotlb_fixup(void *buf, unsigned long nslabs);
+#else
+#define xen_swiotlb_fixup NULL
+#endif
+
 extern const struct dma_map_ops xen_swiotlb_dma_ops;
 
 #endif /* __LINUX_SWIOTLB_XEN_H */
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 13/15] swiotlb: merge swiotlb-xen initialization into swiotlb
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Reuse the generic swiotlb initialization for xen-swiotlb.  For ARM/ARM64
this works trivially, while for x86 xen_swiotlb_fixup needs to be passed
as the remap argument to swiotlb_init_remap/swiotlb_init_late.

Note that the lower bound of the swiotlb size is changed to the smaller
IO_TLB_MIN_SLABS based value with this patch, but that is fine as the
2MB value used in Xen before was just an optimization and is not the
hard lower bound.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 arch/arm/xen/mm.c               |  21 +++---
 arch/x86/include/asm/xen/page.h |   5 --
 arch/x86/kernel/pci-dma.c       |  20 ++---
 drivers/xen/swiotlb-xen.c       | 128 +-------------------------------
 include/xen/arm/page.h          |   1 -
 include/xen/swiotlb-xen.h       |   8 +-
 6 files changed, 28 insertions(+), 155 deletions(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index 28c2070602535..ff05a7899cb86 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -23,22 +23,20 @@
 #include <asm/xen/hypercall.h>
 #include <asm/xen/interface.h>
 
-unsigned long xen_get_swiotlb_free_pages(unsigned int order)
+static gfp_t xen_swiotlb_gfp(void)
 {
 	phys_addr_t base;
-	gfp_t flags = __GFP_NOWARN|__GFP_KSWAPD_RECLAIM;
 	u64 i;
 
 	for_each_mem_range(i, &base, NULL) {
 		if (base < (phys_addr_t)0xffffffff) {
 			if (IS_ENABLED(CONFIG_ZONE_DMA32))
-				flags |= __GFP_DMA32;
-			else
-				flags |= __GFP_DMA;
-			break;
+				return __GFP_DMA32;
+			return __GFP_DMA;
 		}
 	}
-	return __get_free_pages(flags, order);
+
+	return GFP_KERNEL;
 }
 
 static bool hypercall_cflush = false;
@@ -140,10 +138,13 @@ static int __init xen_mm_init(void)
 	if (!xen_swiotlb_detect())
 		return 0;
 
-	rc = xen_swiotlb_init();
 	/* we can work with the default swiotlb */
-	if (rc < 0 && rc != -EEXIST)
-		return rc;
+	if (!io_tlb_default_mem.nslabs) {
+		rc = swiotlb_init_late(swiotlb_size_or_default(),
+				       xen_swiotlb_gfp(), NULL);
+		if (rc < 0)
+			return rc;
+	}
 
 	cflush.op = 0;
 	cflush.a.dev_bus_addr = 0;
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index e989bc2269f54..1fc67df500145 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -357,9 +357,4 @@ static inline bool xen_arch_need_swiotlb(struct device *dev,
 	return false;
 }
 
-static inline unsigned long xen_get_swiotlb_free_pages(unsigned int order)
-{
-	return __get_free_pages(__GFP_NOWARN, order);
-}
-
 #endif /* _ASM_X86_XEN_PAGE_H */
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index a705a199bf8a3..30bbe4abb5d61 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -72,15 +72,13 @@ static inline void __init pci_swiotlb_detect(void)
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
-static bool xen_swiotlb;
-
 static void __init pci_xen_swiotlb_init(void)
 {
 	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
-	xen_swiotlb = true;
-	xen_swiotlb_init_early();
+	x86_swiotlb_flags |= SWIOTLB_ANY;
+	swiotlb_init_remap(true, x86_swiotlb_flags, xen_swiotlb_fixup);
 	dma_ops = &xen_swiotlb_dma_ops;
 	if (IS_ENABLED(CONFIG_PCI))
 		pci_request_acs();
@@ -88,14 +86,16 @@ static void __init pci_xen_swiotlb_init(void)
 
 int pci_xen_swiotlb_init_late(void)
 {
-	int rc;
-
-	if (xen_swiotlb)
+	if (dma_ops == &xen_swiotlb_dma_ops)
 		return 0;
 
-	rc = xen_swiotlb_init();
-	if (rc)
-		return rc;
+	/* we can work with the default swiotlb */
+	if (!io_tlb_default_mem.nslabs) {
+		int rc = swiotlb_init_late(swiotlb_size_or_default(),
+					   GFP_KERNEL, xen_swiotlb_fixup);
+		if (rc < 0)
+			return rc;
+	}
 
 	/* XXX: this switches the dma ops under live devices! */
 	dma_ops = &xen_swiotlb_dma_ops;
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index c2da3eb4826e8..df8085b50df10 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -104,7 +104,7 @@ static int is_xen_swiotlb_buffer(struct device *dev, dma_addr_t dma_addr)
 	return 0;
 }
 
-static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
+int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
 {
 	int rc;
 	unsigned int order = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT);
@@ -130,132 +130,6 @@ static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
 	return 0;
 }
 
-enum xen_swiotlb_err {
-	XEN_SWIOTLB_UNKNOWN = 0,
-	XEN_SWIOTLB_ENOMEM,
-	XEN_SWIOTLB_EFIXUP
-};
-
-static const char *xen_swiotlb_error(enum xen_swiotlb_err err)
-{
-	switch (err) {
-	case XEN_SWIOTLB_ENOMEM:
-		return "Cannot allocate Xen-SWIOTLB buffer\n";
-	case XEN_SWIOTLB_EFIXUP:
-		return "Failed to get contiguous memory for DMA from Xen!\n"\
-		    "You either: don't have the permissions, do not have"\
-		    " enough free memory under 4GB, or the hypervisor memory"\
-		    " is too fragmented!";
-	default:
-		break;
-	}
-	return "";
-}
-
-int xen_swiotlb_init(void)
-{
-	enum xen_swiotlb_err m_ret = XEN_SWIOTLB_UNKNOWN;
-	unsigned long bytes = swiotlb_size_or_default();
-	unsigned long nslabs = bytes >> IO_TLB_SHIFT;
-	unsigned int order, repeat = 3;
-	int rc = -ENOMEM;
-	char *start;
-
-	if (io_tlb_default_mem.nslabs) {
-		pr_warn("swiotlb buffer already initialized\n");
-		return -EEXIST;
-	}
-
-retry:
-	m_ret = XEN_SWIOTLB_ENOMEM;
-	order = get_order(bytes);
-
-	/*
-	 * Get IO TLB memory from any location.
-	 */
-#define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT))
-#define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
-	while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
-		start = (void *)xen_get_swiotlb_free_pages(order);
-		if (start)
-			break;
-		order--;
-	}
-	if (!start)
-		goto exit;
-	if (order != get_order(bytes)) {
-		pr_warn("Warning: only able to allocate %ld MB for software IO TLB\n",
-			(PAGE_SIZE << order) >> 20);
-		nslabs = SLABS_PER_PAGE << order;
-		bytes = nslabs << IO_TLB_SHIFT;
-	}
-
-	/*
-	 * And replace that memory with pages under 4GB.
-	 */
-	rc = xen_swiotlb_fixup(start, nslabs);
-	if (rc) {
-		free_pages((unsigned long)start, order);
-		m_ret = XEN_SWIOTLB_EFIXUP;
-		goto error;
-	}
-	rc = swiotlb_late_init_with_tbl(start, nslabs);
-	if (rc)
-		return rc;
-	return 0;
-error:
-	if (nslabs > 1024 && repeat--) {
-		/* Min is 2MB */
-		nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
-		bytes = nslabs << IO_TLB_SHIFT;
-		pr_info("Lowering to %luMB\n", bytes >> 20);
-		goto retry;
-	}
-exit:
-	pr_err("%s (rc:%d)\n", xen_swiotlb_error(m_ret), rc);
-	return rc;
-}
-
-#ifdef CONFIG_X86
-void __init xen_swiotlb_init_early(void)
-{
-	unsigned long bytes = swiotlb_size_or_default();
-	unsigned long nslabs = bytes >> IO_TLB_SHIFT;
-	unsigned int repeat = 3;
-	char *start;
-	int rc;
-
-retry:
-	/*
-	 * Get IO TLB memory from any location.
-	 */
-	start = memblock_alloc(PAGE_ALIGN(bytes),
-			       IO_TLB_SEGSIZE << IO_TLB_SHIFT);
-	if (!start)
-		panic("%s: Failed to allocate %lu bytes\n",
-		      __func__, PAGE_ALIGN(bytes));
-
-	/*
-	 * And replace that memory with pages under 4GB.
-	 */
-	rc = xen_swiotlb_fixup(start, nslabs);
-	if (rc) {
-		memblock_free(start, PAGE_ALIGN(bytes));
-		if (nslabs > 1024 && repeat--) {
-			/* Min is 2MB */
-			nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
-			bytes = nslabs << IO_TLB_SHIFT;
-			pr_info("Lowering to %luMB\n", bytes >> 20);
-			goto retry;
-		}
-		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
-	}
-
-	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
-		panic("Cannot allocate SWIOTLB buffer");
-}
-#endif /* CONFIG_X86 */
-
 static void *
 xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
 			   dma_addr_t *dma_handle, gfp_t flags,
diff --git a/include/xen/arm/page.h b/include/xen/arm/page.h
index ac1b654705631..7e199c6656b90 100644
--- a/include/xen/arm/page.h
+++ b/include/xen/arm/page.h
@@ -115,6 +115,5 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
 bool xen_arch_need_swiotlb(struct device *dev,
 			   phys_addr_t phys,
 			   dma_addr_t dev_addr);
-unsigned long xen_get_swiotlb_free_pages(unsigned int order);
 
 #endif /* _ASM_ARM_XEN_PAGE_H */
diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h
index b3e647f86e3e2..590ceb923f0c8 100644
--- a/include/xen/swiotlb-xen.h
+++ b/include/xen/swiotlb-xen.h
@@ -10,8 +10,12 @@ void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle,
 void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,
 			     size_t size, enum dma_data_direction dir);
 
-int xen_swiotlb_init(void);
-void __init xen_swiotlb_init_early(void);
+#ifdef CONFIG_SWIOTLB_XEN
+int xen_swiotlb_fixup(void *buf, unsigned long nslabs);
+#else
+#define xen_swiotlb_fixup NULL
+#endif
+
 extern const struct dma_map_ops xen_swiotlb_dma_ops;
 
 #endif /* __LINUX_SWIOTLB_XEN_H */
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 13/15] swiotlb: merge swiotlb-xen initialization into swiotlb
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Reuse the generic swiotlb initialization for xen-swiotlb.  For ARM/ARM64
this works trivially, while for x86 xen_swiotlb_fixup needs to be passed
as the remap argument to swiotlb_init_remap/swiotlb_init_late.

Note that the lower bound of the swiotlb size is changed to the smaller
IO_TLB_MIN_SLABS based value with this patch, but that is fine as the
2MB value used in Xen before was just an optimization and is not the
hard lower bound.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 arch/arm/xen/mm.c               |  21 +++---
 arch/x86/include/asm/xen/page.h |   5 --
 arch/x86/kernel/pci-dma.c       |  20 ++---
 drivers/xen/swiotlb-xen.c       | 128 +-------------------------------
 include/xen/arm/page.h          |   1 -
 include/xen/swiotlb-xen.h       |   8 +-
 6 files changed, 28 insertions(+), 155 deletions(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index 28c2070602535..ff05a7899cb86 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -23,22 +23,20 @@
 #include <asm/xen/hypercall.h>
 #include <asm/xen/interface.h>
 
-unsigned long xen_get_swiotlb_free_pages(unsigned int order)
+static gfp_t xen_swiotlb_gfp(void)
 {
 	phys_addr_t base;
-	gfp_t flags = __GFP_NOWARN|__GFP_KSWAPD_RECLAIM;
 	u64 i;
 
 	for_each_mem_range(i, &base, NULL) {
 		if (base < (phys_addr_t)0xffffffff) {
 			if (IS_ENABLED(CONFIG_ZONE_DMA32))
-				flags |= __GFP_DMA32;
-			else
-				flags |= __GFP_DMA;
-			break;
+				return __GFP_DMA32;
+			return __GFP_DMA;
 		}
 	}
-	return __get_free_pages(flags, order);
+
+	return GFP_KERNEL;
 }
 
 static bool hypercall_cflush = false;
@@ -140,10 +138,13 @@ static int __init xen_mm_init(void)
 	if (!xen_swiotlb_detect())
 		return 0;
 
-	rc = xen_swiotlb_init();
 	/* we can work with the default swiotlb */
-	if (rc < 0 && rc != -EEXIST)
-		return rc;
+	if (!io_tlb_default_mem.nslabs) {
+		rc = swiotlb_init_late(swiotlb_size_or_default(),
+				       xen_swiotlb_gfp(), NULL);
+		if (rc < 0)
+			return rc;
+	}
 
 	cflush.op = 0;
 	cflush.a.dev_bus_addr = 0;
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index e989bc2269f54..1fc67df500145 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -357,9 +357,4 @@ static inline bool xen_arch_need_swiotlb(struct device *dev,
 	return false;
 }
 
-static inline unsigned long xen_get_swiotlb_free_pages(unsigned int order)
-{
-	return __get_free_pages(__GFP_NOWARN, order);
-}
-
 #endif /* _ASM_X86_XEN_PAGE_H */
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index a705a199bf8a3..30bbe4abb5d61 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -72,15 +72,13 @@ static inline void __init pci_swiotlb_detect(void)
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
-static bool xen_swiotlb;
-
 static void __init pci_xen_swiotlb_init(void)
 {
 	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
-	xen_swiotlb = true;
-	xen_swiotlb_init_early();
+	x86_swiotlb_flags |= SWIOTLB_ANY;
+	swiotlb_init_remap(true, x86_swiotlb_flags, xen_swiotlb_fixup);
 	dma_ops = &xen_swiotlb_dma_ops;
 	if (IS_ENABLED(CONFIG_PCI))
 		pci_request_acs();
@@ -88,14 +86,16 @@ static void __init pci_xen_swiotlb_init(void)
 
 int pci_xen_swiotlb_init_late(void)
 {
-	int rc;
-
-	if (xen_swiotlb)
+	if (dma_ops == &xen_swiotlb_dma_ops)
 		return 0;
 
-	rc = xen_swiotlb_init();
-	if (rc)
-		return rc;
+	/* we can work with the default swiotlb */
+	if (!io_tlb_default_mem.nslabs) {
+		int rc = swiotlb_init_late(swiotlb_size_or_default(),
+					   GFP_KERNEL, xen_swiotlb_fixup);
+		if (rc < 0)
+			return rc;
+	}
 
 	/* XXX: this switches the dma ops under live devices! */
 	dma_ops = &xen_swiotlb_dma_ops;
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index c2da3eb4826e8..df8085b50df10 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -104,7 +104,7 @@ static int is_xen_swiotlb_buffer(struct device *dev, dma_addr_t dma_addr)
 	return 0;
 }
 
-static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
+int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
 {
 	int rc;
 	unsigned int order = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT);
@@ -130,132 +130,6 @@ static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
 	return 0;
 }
 
-enum xen_swiotlb_err {
-	XEN_SWIOTLB_UNKNOWN = 0,
-	XEN_SWIOTLB_ENOMEM,
-	XEN_SWIOTLB_EFIXUP
-};
-
-static const char *xen_swiotlb_error(enum xen_swiotlb_err err)
-{
-	switch (err) {
-	case XEN_SWIOTLB_ENOMEM:
-		return "Cannot allocate Xen-SWIOTLB buffer\n";
-	case XEN_SWIOTLB_EFIXUP:
-		return "Failed to get contiguous memory for DMA from Xen!\n"\
-		    "You either: don't have the permissions, do not have"\
-		    " enough free memory under 4GB, or the hypervisor memory"\
-		    " is too fragmented!";
-	default:
-		break;
-	}
-	return "";
-}
-
-int xen_swiotlb_init(void)
-{
-	enum xen_swiotlb_err m_ret = XEN_SWIOTLB_UNKNOWN;
-	unsigned long bytes = swiotlb_size_or_default();
-	unsigned long nslabs = bytes >> IO_TLB_SHIFT;
-	unsigned int order, repeat = 3;
-	int rc = -ENOMEM;
-	char *start;
-
-	if (io_tlb_default_mem.nslabs) {
-		pr_warn("swiotlb buffer already initialized\n");
-		return -EEXIST;
-	}
-
-retry:
-	m_ret = XEN_SWIOTLB_ENOMEM;
-	order = get_order(bytes);
-
-	/*
-	 * Get IO TLB memory from any location.
-	 */
-#define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT))
-#define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
-	while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
-		start = (void *)xen_get_swiotlb_free_pages(order);
-		if (start)
-			break;
-		order--;
-	}
-	if (!start)
-		goto exit;
-	if (order != get_order(bytes)) {
-		pr_warn("Warning: only able to allocate %ld MB for software IO TLB\n",
-			(PAGE_SIZE << order) >> 20);
-		nslabs = SLABS_PER_PAGE << order;
-		bytes = nslabs << IO_TLB_SHIFT;
-	}
-
-	/*
-	 * And replace that memory with pages under 4GB.
-	 */
-	rc = xen_swiotlb_fixup(start, nslabs);
-	if (rc) {
-		free_pages((unsigned long)start, order);
-		m_ret = XEN_SWIOTLB_EFIXUP;
-		goto error;
-	}
-	rc = swiotlb_late_init_with_tbl(start, nslabs);
-	if (rc)
-		return rc;
-	return 0;
-error:
-	if (nslabs > 1024 && repeat--) {
-		/* Min is 2MB */
-		nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
-		bytes = nslabs << IO_TLB_SHIFT;
-		pr_info("Lowering to %luMB\n", bytes >> 20);
-		goto retry;
-	}
-exit:
-	pr_err("%s (rc:%d)\n", xen_swiotlb_error(m_ret), rc);
-	return rc;
-}
-
-#ifdef CONFIG_X86
-void __init xen_swiotlb_init_early(void)
-{
-	unsigned long bytes = swiotlb_size_or_default();
-	unsigned long nslabs = bytes >> IO_TLB_SHIFT;
-	unsigned int repeat = 3;
-	char *start;
-	int rc;
-
-retry:
-	/*
-	 * Get IO TLB memory from any location.
-	 */
-	start = memblock_alloc(PAGE_ALIGN(bytes),
-			       IO_TLB_SEGSIZE << IO_TLB_SHIFT);
-	if (!start)
-		panic("%s: Failed to allocate %lu bytes\n",
-		      __func__, PAGE_ALIGN(bytes));
-
-	/*
-	 * And replace that memory with pages under 4GB.
-	 */
-	rc = xen_swiotlb_fixup(start, nslabs);
-	if (rc) {
-		memblock_free(start, PAGE_ALIGN(bytes));
-		if (nslabs > 1024 && repeat--) {
-			/* Min is 2MB */
-			nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
-			bytes = nslabs << IO_TLB_SHIFT;
-			pr_info("Lowering to %luMB\n", bytes >> 20);
-			goto retry;
-		}
-		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
-	}
-
-	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
-		panic("Cannot allocate SWIOTLB buffer");
-}
-#endif /* CONFIG_X86 */
-
 static void *
 xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
 			   dma_addr_t *dma_handle, gfp_t flags,
diff --git a/include/xen/arm/page.h b/include/xen/arm/page.h
index ac1b654705631..7e199c6656b90 100644
--- a/include/xen/arm/page.h
+++ b/include/xen/arm/page.h
@@ -115,6 +115,5 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
 bool xen_arch_need_swiotlb(struct device *dev,
 			   phys_addr_t phys,
 			   dma_addr_t dev_addr);
-unsigned long xen_get_swiotlb_free_pages(unsigned int order);
 
 #endif /* _ASM_ARM_XEN_PAGE_H */
diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h
index b3e647f86e3e2..590ceb923f0c8 100644
--- a/include/xen/swiotlb-xen.h
+++ b/include/xen/swiotlb-xen.h
@@ -10,8 +10,12 @@ void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle,
 void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,
 			     size_t size, enum dma_data_direction dir);
 
-int xen_swiotlb_init(void);
-void __init xen_swiotlb_init_early(void);
+#ifdef CONFIG_SWIOTLB_XEN
+int xen_swiotlb_fixup(void *buf, unsigned long nslabs);
+#else
+#define xen_swiotlb_fixup NULL
+#endif
+
 extern const struct dma_map_ops xen_swiotlb_dma_ops;
 
 #endif /* __LINUX_SWIOTLB_XEN_H */
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 13/15] swiotlb: merge swiotlb-xen initialization into swiotlb
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Reuse the generic swiotlb initialization for xen-swiotlb.  For ARM/ARM64
this works trivially, while for x86 xen_swiotlb_fixup needs to be passed
as the remap argument to swiotlb_init_remap/swiotlb_init_late.

Note that the lower bound of the swiotlb size is changed to the smaller
IO_TLB_MIN_SLABS based value with this patch, but that is fine as the
2MB value used in Xen before was just an optimization and is not the
hard lower bound.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 arch/arm/xen/mm.c               |  21 +++---
 arch/x86/include/asm/xen/page.h |   5 --
 arch/x86/kernel/pci-dma.c       |  20 ++---
 drivers/xen/swiotlb-xen.c       | 128 +-------------------------------
 include/xen/arm/page.h          |   1 -
 include/xen/swiotlb-xen.h       |   8 +-
 6 files changed, 28 insertions(+), 155 deletions(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index 28c2070602535..ff05a7899cb86 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -23,22 +23,20 @@
 #include <asm/xen/hypercall.h>
 #include <asm/xen/interface.h>
 
-unsigned long xen_get_swiotlb_free_pages(unsigned int order)
+static gfp_t xen_swiotlb_gfp(void)
 {
 	phys_addr_t base;
-	gfp_t flags = __GFP_NOWARN|__GFP_KSWAPD_RECLAIM;
 	u64 i;
 
 	for_each_mem_range(i, &base, NULL) {
 		if (base < (phys_addr_t)0xffffffff) {
 			if (IS_ENABLED(CONFIG_ZONE_DMA32))
-				flags |= __GFP_DMA32;
-			else
-				flags |= __GFP_DMA;
-			break;
+				return __GFP_DMA32;
+			return __GFP_DMA;
 		}
 	}
-	return __get_free_pages(flags, order);
+
+	return GFP_KERNEL;
 }
 
 static bool hypercall_cflush = false;
@@ -140,10 +138,13 @@ static int __init xen_mm_init(void)
 	if (!xen_swiotlb_detect())
 		return 0;
 
-	rc = xen_swiotlb_init();
 	/* we can work with the default swiotlb */
-	if (rc < 0 && rc != -EEXIST)
-		return rc;
+	if (!io_tlb_default_mem.nslabs) {
+		rc = swiotlb_init_late(swiotlb_size_or_default(),
+				       xen_swiotlb_gfp(), NULL);
+		if (rc < 0)
+			return rc;
+	}
 
 	cflush.op = 0;
 	cflush.a.dev_bus_addr = 0;
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index e989bc2269f54..1fc67df500145 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -357,9 +357,4 @@ static inline bool xen_arch_need_swiotlb(struct device *dev,
 	return false;
 }
 
-static inline unsigned long xen_get_swiotlb_free_pages(unsigned int order)
-{
-	return __get_free_pages(__GFP_NOWARN, order);
-}
-
 #endif /* _ASM_X86_XEN_PAGE_H */
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index a705a199bf8a3..30bbe4abb5d61 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -72,15 +72,13 @@ static inline void __init pci_swiotlb_detect(void)
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
-static bool xen_swiotlb;
-
 static void __init pci_xen_swiotlb_init(void)
 {
 	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
-	xen_swiotlb = true;
-	xen_swiotlb_init_early();
+	x86_swiotlb_flags |= SWIOTLB_ANY;
+	swiotlb_init_remap(true, x86_swiotlb_flags, xen_swiotlb_fixup);
 	dma_ops = &xen_swiotlb_dma_ops;
 	if (IS_ENABLED(CONFIG_PCI))
 		pci_request_acs();
@@ -88,14 +86,16 @@ static void __init pci_xen_swiotlb_init(void)
 
 int pci_xen_swiotlb_init_late(void)
 {
-	int rc;
-
-	if (xen_swiotlb)
+	if (dma_ops == &xen_swiotlb_dma_ops)
 		return 0;
 
-	rc = xen_swiotlb_init();
-	if (rc)
-		return rc;
+	/* we can work with the default swiotlb */
+	if (!io_tlb_default_mem.nslabs) {
+		int rc = swiotlb_init_late(swiotlb_size_or_default(),
+					   GFP_KERNEL, xen_swiotlb_fixup);
+		if (rc < 0)
+			return rc;
+	}
 
 	/* XXX: this switches the dma ops under live devices! */
 	dma_ops = &xen_swiotlb_dma_ops;
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index c2da3eb4826e8..df8085b50df10 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -104,7 +104,7 @@ static int is_xen_swiotlb_buffer(struct device *dev, dma_addr_t dma_addr)
 	return 0;
 }
 
-static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
+int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
 {
 	int rc;
 	unsigned int order = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT);
@@ -130,132 +130,6 @@ static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
 	return 0;
 }
 
-enum xen_swiotlb_err {
-	XEN_SWIOTLB_UNKNOWN = 0,
-	XEN_SWIOTLB_ENOMEM,
-	XEN_SWIOTLB_EFIXUP
-};
-
-static const char *xen_swiotlb_error(enum xen_swiotlb_err err)
-{
-	switch (err) {
-	case XEN_SWIOTLB_ENOMEM:
-		return "Cannot allocate Xen-SWIOTLB buffer\n";
-	case XEN_SWIOTLB_EFIXUP:
-		return "Failed to get contiguous memory for DMA from Xen!\n"\
-		    "You either: don't have the permissions, do not have"\
-		    " enough free memory under 4GB, or the hypervisor memory"\
-		    " is too fragmented!";
-	default:
-		break;
-	}
-	return "";
-}
-
-int xen_swiotlb_init(void)
-{
-	enum xen_swiotlb_err m_ret = XEN_SWIOTLB_UNKNOWN;
-	unsigned long bytes = swiotlb_size_or_default();
-	unsigned long nslabs = bytes >> IO_TLB_SHIFT;
-	unsigned int order, repeat = 3;
-	int rc = -ENOMEM;
-	char *start;
-
-	if (io_tlb_default_mem.nslabs) {
-		pr_warn("swiotlb buffer already initialized\n");
-		return -EEXIST;
-	}
-
-retry:
-	m_ret = XEN_SWIOTLB_ENOMEM;
-	order = get_order(bytes);
-
-	/*
-	 * Get IO TLB memory from any location.
-	 */
-#define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT))
-#define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
-	while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
-		start = (void *)xen_get_swiotlb_free_pages(order);
-		if (start)
-			break;
-		order--;
-	}
-	if (!start)
-		goto exit;
-	if (order != get_order(bytes)) {
-		pr_warn("Warning: only able to allocate %ld MB for software IO TLB\n",
-			(PAGE_SIZE << order) >> 20);
-		nslabs = SLABS_PER_PAGE << order;
-		bytes = nslabs << IO_TLB_SHIFT;
-	}
-
-	/*
-	 * And replace that memory with pages under 4GB.
-	 */
-	rc = xen_swiotlb_fixup(start, nslabs);
-	if (rc) {
-		free_pages((unsigned long)start, order);
-		m_ret = XEN_SWIOTLB_EFIXUP;
-		goto error;
-	}
-	rc = swiotlb_late_init_with_tbl(start, nslabs);
-	if (rc)
-		return rc;
-	return 0;
-error:
-	if (nslabs > 1024 && repeat--) {
-		/* Min is 2MB */
-		nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
-		bytes = nslabs << IO_TLB_SHIFT;
-		pr_info("Lowering to %luMB\n", bytes >> 20);
-		goto retry;
-	}
-exit:
-	pr_err("%s (rc:%d)\n", xen_swiotlb_error(m_ret), rc);
-	return rc;
-}
-
-#ifdef CONFIG_X86
-void __init xen_swiotlb_init_early(void)
-{
-	unsigned long bytes = swiotlb_size_or_default();
-	unsigned long nslabs = bytes >> IO_TLB_SHIFT;
-	unsigned int repeat = 3;
-	char *start;
-	int rc;
-
-retry:
-	/*
-	 * Get IO TLB memory from any location.
-	 */
-	start = memblock_alloc(PAGE_ALIGN(bytes),
-			       IO_TLB_SEGSIZE << IO_TLB_SHIFT);
-	if (!start)
-		panic("%s: Failed to allocate %lu bytes\n",
-		      __func__, PAGE_ALIGN(bytes));
-
-	/*
-	 * And replace that memory with pages under 4GB.
-	 */
-	rc = xen_swiotlb_fixup(start, nslabs);
-	if (rc) {
-		memblock_free(start, PAGE_ALIGN(bytes));
-		if (nslabs > 1024 && repeat--) {
-			/* Min is 2MB */
-			nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
-			bytes = nslabs << IO_TLB_SHIFT;
-			pr_info("Lowering to %luMB\n", bytes >> 20);
-			goto retry;
-		}
-		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
-	}
-
-	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
-		panic("Cannot allocate SWIOTLB buffer");
-}
-#endif /* CONFIG_X86 */
-
 static void *
 xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
 			   dma_addr_t *dma_handle, gfp_t flags,
diff --git a/include/xen/arm/page.h b/include/xen/arm/page.h
index ac1b654705631..7e199c6656b90 100644
--- a/include/xen/arm/page.h
+++ b/include/xen/arm/page.h
@@ -115,6 +115,5 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
 bool xen_arch_need_swiotlb(struct device *dev,
 			   phys_addr_t phys,
 			   dma_addr_t dev_addr);
-unsigned long xen_get_swiotlb_free_pages(unsigned int order);
 
 #endif /* _ASM_ARM_XEN_PAGE_H */
diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h
index b3e647f86e3e2..590ceb923f0c8 100644
--- a/include/xen/swiotlb-xen.h
+++ b/include/xen/swiotlb-xen.h
@@ -10,8 +10,12 @@ void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle,
 void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,
 			     size_t size, enum dma_data_direction dir);
 
-int xen_swiotlb_init(void);
-void __init xen_swiotlb_init_early(void);
+#ifdef CONFIG_SWIOTLB_XEN
+int xen_swiotlb_fixup(void *buf, unsigned long nslabs);
+#else
+#define xen_swiotlb_fixup NULL
+#endif
+
 extern const struct dma_map_ops xen_swiotlb_dma_ops;
 
 #endif /* __LINUX_SWIOTLB_XEN_H */
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 13/15] swiotlb: merge swiotlb-xen initialization into swiotlb
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

Reuse the generic swiotlb initialization for xen-swiotlb.  For ARM/ARM64
this works trivially, while for x86 xen_swiotlb_fixup needs to be passed
as the remap argument to swiotlb_init_remap/swiotlb_init_late.

Note that the lower bound of the swiotlb size is changed to the smaller
IO_TLB_MIN_SLABS based value with this patch, but that is fine as the
2MB value used in Xen before was just an optimization and is not the
hard lower bound.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 arch/arm/xen/mm.c               |  21 +++---
 arch/x86/include/asm/xen/page.h |   5 --
 arch/x86/kernel/pci-dma.c       |  20 ++---
 drivers/xen/swiotlb-xen.c       | 128 +-------------------------------
 include/xen/arm/page.h          |   1 -
 include/xen/swiotlb-xen.h       |   8 +-
 6 files changed, 28 insertions(+), 155 deletions(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index 28c2070602535..ff05a7899cb86 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -23,22 +23,20 @@
 #include <asm/xen/hypercall.h>
 #include <asm/xen/interface.h>
 
-unsigned long xen_get_swiotlb_free_pages(unsigned int order)
+static gfp_t xen_swiotlb_gfp(void)
 {
 	phys_addr_t base;
-	gfp_t flags = __GFP_NOWARN|__GFP_KSWAPD_RECLAIM;
 	u64 i;
 
 	for_each_mem_range(i, &base, NULL) {
 		if (base < (phys_addr_t)0xffffffff) {
 			if (IS_ENABLED(CONFIG_ZONE_DMA32))
-				flags |= __GFP_DMA32;
-			else
-				flags |= __GFP_DMA;
-			break;
+				return __GFP_DMA32;
+			return __GFP_DMA;
 		}
 	}
-	return __get_free_pages(flags, order);
+
+	return GFP_KERNEL;
 }
 
 static bool hypercall_cflush = false;
@@ -140,10 +138,13 @@ static int __init xen_mm_init(void)
 	if (!xen_swiotlb_detect())
 		return 0;
 
-	rc = xen_swiotlb_init();
 	/* we can work with the default swiotlb */
-	if (rc < 0 && rc != -EEXIST)
-		return rc;
+	if (!io_tlb_default_mem.nslabs) {
+		rc = swiotlb_init_late(swiotlb_size_or_default(),
+				       xen_swiotlb_gfp(), NULL);
+		if (rc < 0)
+			return rc;
+	}
 
 	cflush.op = 0;
 	cflush.a.dev_bus_addr = 0;
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index e989bc2269f54..1fc67df500145 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -357,9 +357,4 @@ static inline bool xen_arch_need_swiotlb(struct device *dev,
 	return false;
 }
 
-static inline unsigned long xen_get_swiotlb_free_pages(unsigned int order)
-{
-	return __get_free_pages(__GFP_NOWARN, order);
-}
-
 #endif /* _ASM_X86_XEN_PAGE_H */
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index a705a199bf8a3..30bbe4abb5d61 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -72,15 +72,13 @@ static inline void __init pci_swiotlb_detect(void)
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
-static bool xen_swiotlb;
-
 static void __init pci_xen_swiotlb_init(void)
 {
 	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
-	xen_swiotlb = true;
-	xen_swiotlb_init_early();
+	x86_swiotlb_flags |= SWIOTLB_ANY;
+	swiotlb_init_remap(true, x86_swiotlb_flags, xen_swiotlb_fixup);
 	dma_ops = &xen_swiotlb_dma_ops;
 	if (IS_ENABLED(CONFIG_PCI))
 		pci_request_acs();
@@ -88,14 +86,16 @@ static void __init pci_xen_swiotlb_init(void)
 
 int pci_xen_swiotlb_init_late(void)
 {
-	int rc;
-
-	if (xen_swiotlb)
+	if (dma_ops == &xen_swiotlb_dma_ops)
 		return 0;
 
-	rc = xen_swiotlb_init();
-	if (rc)
-		return rc;
+	/* we can work with the default swiotlb */
+	if (!io_tlb_default_mem.nslabs) {
+		int rc = swiotlb_init_late(swiotlb_size_or_default(),
+					   GFP_KERNEL, xen_swiotlb_fixup);
+		if (rc < 0)
+			return rc;
+	}
 
 	/* XXX: this switches the dma ops under live devices! */
 	dma_ops = &xen_swiotlb_dma_ops;
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index c2da3eb4826e8..df8085b50df10 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -104,7 +104,7 @@ static int is_xen_swiotlb_buffer(struct device *dev, dma_addr_t dma_addr)
 	return 0;
 }
 
-static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
+int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
 {
 	int rc;
 	unsigned int order = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT);
@@ -130,132 +130,6 @@ static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
 	return 0;
 }
 
-enum xen_swiotlb_err {
-	XEN_SWIOTLB_UNKNOWN = 0,
-	XEN_SWIOTLB_ENOMEM,
-	XEN_SWIOTLB_EFIXUP
-};
-
-static const char *xen_swiotlb_error(enum xen_swiotlb_err err)
-{
-	switch (err) {
-	case XEN_SWIOTLB_ENOMEM:
-		return "Cannot allocate Xen-SWIOTLB buffer\n";
-	case XEN_SWIOTLB_EFIXUP:
-		return "Failed to get contiguous memory for DMA from Xen!\n"\
-		    "You either: don't have the permissions, do not have"\
-		    " enough free memory under 4GB, or the hypervisor memory"\
-		    " is too fragmented!";
-	default:
-		break;
-	}
-	return "";
-}
-
-int xen_swiotlb_init(void)
-{
-	enum xen_swiotlb_err m_ret = XEN_SWIOTLB_UNKNOWN;
-	unsigned long bytes = swiotlb_size_or_default();
-	unsigned long nslabs = bytes >> IO_TLB_SHIFT;
-	unsigned int order, repeat = 3;
-	int rc = -ENOMEM;
-	char *start;
-
-	if (io_tlb_default_mem.nslabs) {
-		pr_warn("swiotlb buffer already initialized\n");
-		return -EEXIST;
-	}
-
-retry:
-	m_ret = XEN_SWIOTLB_ENOMEM;
-	order = get_order(bytes);
-
-	/*
-	 * Get IO TLB memory from any location.
-	 */
-#define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT))
-#define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
-	while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
-		start = (void *)xen_get_swiotlb_free_pages(order);
-		if (start)
-			break;
-		order--;
-	}
-	if (!start)
-		goto exit;
-	if (order != get_order(bytes)) {
-		pr_warn("Warning: only able to allocate %ld MB for software IO TLB\n",
-			(PAGE_SIZE << order) >> 20);
-		nslabs = SLABS_PER_PAGE << order;
-		bytes = nslabs << IO_TLB_SHIFT;
-	}
-
-	/*
-	 * And replace that memory with pages under 4GB.
-	 */
-	rc = xen_swiotlb_fixup(start, nslabs);
-	if (rc) {
-		free_pages((unsigned long)start, order);
-		m_ret = XEN_SWIOTLB_EFIXUP;
-		goto error;
-	}
-	rc = swiotlb_late_init_with_tbl(start, nslabs);
-	if (rc)
-		return rc;
-	return 0;
-error:
-	if (nslabs > 1024 && repeat--) {
-		/* Min is 2MB */
-		nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
-		bytes = nslabs << IO_TLB_SHIFT;
-		pr_info("Lowering to %luMB\n", bytes >> 20);
-		goto retry;
-	}
-exit:
-	pr_err("%s (rc:%d)\n", xen_swiotlb_error(m_ret), rc);
-	return rc;
-}
-
-#ifdef CONFIG_X86
-void __init xen_swiotlb_init_early(void)
-{
-	unsigned long bytes = swiotlb_size_or_default();
-	unsigned long nslabs = bytes >> IO_TLB_SHIFT;
-	unsigned int repeat = 3;
-	char *start;
-	int rc;
-
-retry:
-	/*
-	 * Get IO TLB memory from any location.
-	 */
-	start = memblock_alloc(PAGE_ALIGN(bytes),
-			       IO_TLB_SEGSIZE << IO_TLB_SHIFT);
-	if (!start)
-		panic("%s: Failed to allocate %lu bytes\n",
-		      __func__, PAGE_ALIGN(bytes));
-
-	/*
-	 * And replace that memory with pages under 4GB.
-	 */
-	rc = xen_swiotlb_fixup(start, nslabs);
-	if (rc) {
-		memblock_free(start, PAGE_ALIGN(bytes));
-		if (nslabs > 1024 && repeat--) {
-			/* Min is 2MB */
-			nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
-			bytes = nslabs << IO_TLB_SHIFT;
-			pr_info("Lowering to %luMB\n", bytes >> 20);
-			goto retry;
-		}
-		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
-	}
-
-	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
-		panic("Cannot allocate SWIOTLB buffer");
-}
-#endif /* CONFIG_X86 */
-
 static void *
 xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
 			   dma_addr_t *dma_handle, gfp_t flags,
diff --git a/include/xen/arm/page.h b/include/xen/arm/page.h
index ac1b654705631..7e199c6656b90 100644
--- a/include/xen/arm/page.h
+++ b/include/xen/arm/page.h
@@ -115,6 +115,5 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
 bool xen_arch_need_swiotlb(struct device *dev,
 			   phys_addr_t phys,
 			   dma_addr_t dev_addr);
-unsigned long xen_get_swiotlb_free_pages(unsigned int order);
 
 #endif /* _ASM_ARM_XEN_PAGE_H */
diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h
index b3e647f86e3e2..590ceb923f0c8 100644
--- a/include/xen/swiotlb-xen.h
+++ b/include/xen/swiotlb-xen.h
@@ -10,8 +10,12 @@ void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle,
 void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,
 			     size_t size, enum dma_data_direction dir);
 
-int xen_swiotlb_init(void);
-void __init xen_swiotlb_init_early(void);
+#ifdef CONFIG_SWIOTLB_XEN
+int xen_swiotlb_fixup(void *buf, unsigned long nslabs);
+#else
+#define xen_swiotlb_fixup NULL
+#endif
+
 extern const struct dma_map_ops xen_swiotlb_dma_ops;
 
 #endif /* __LINUX_SWIOTLB_XEN_H */
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 13/15] swiotlb: merge swiotlb-xen initialization into swiotlb
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Reuse the generic swiotlb initialization for xen-swiotlb.  For ARM/ARM64
this works trivially, while for x86 xen_swiotlb_fixup needs to be passed
as the remap argument to swiotlb_init_remap/swiotlb_init_late.

Note that the lower bound of the swiotlb size is changed to the smaller
IO_TLB_MIN_SLABS based value with this patch, but that is fine as the
2MB value used in Xen before was just an optimization and is not the
hard lower bound.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 arch/arm/xen/mm.c               |  21 +++---
 arch/x86/include/asm/xen/page.h |   5 --
 arch/x86/kernel/pci-dma.c       |  20 ++---
 drivers/xen/swiotlb-xen.c       | 128 +-------------------------------
 include/xen/arm/page.h          |   1 -
 include/xen/swiotlb-xen.h       |   8 +-
 6 files changed, 28 insertions(+), 155 deletions(-)

diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index 28c2070602535..ff05a7899cb86 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -23,22 +23,20 @@
 #include <asm/xen/hypercall.h>
 #include <asm/xen/interface.h>
 
-unsigned long xen_get_swiotlb_free_pages(unsigned int order)
+static gfp_t xen_swiotlb_gfp(void)
 {
 	phys_addr_t base;
-	gfp_t flags = __GFP_NOWARN|__GFP_KSWAPD_RECLAIM;
 	u64 i;
 
 	for_each_mem_range(i, &base, NULL) {
 		if (base < (phys_addr_t)0xffffffff) {
 			if (IS_ENABLED(CONFIG_ZONE_DMA32))
-				flags |= __GFP_DMA32;
-			else
-				flags |= __GFP_DMA;
-			break;
+				return __GFP_DMA32;
+			return __GFP_DMA;
 		}
 	}
-	return __get_free_pages(flags, order);
+
+	return GFP_KERNEL;
 }
 
 static bool hypercall_cflush = false;
@@ -140,10 +138,13 @@ static int __init xen_mm_init(void)
 	if (!xen_swiotlb_detect())
 		return 0;
 
-	rc = xen_swiotlb_init();
 	/* we can work with the default swiotlb */
-	if (rc < 0 && rc != -EEXIST)
-		return rc;
+	if (!io_tlb_default_mem.nslabs) {
+		rc = swiotlb_init_late(swiotlb_size_or_default(),
+				       xen_swiotlb_gfp(), NULL);
+		if (rc < 0)
+			return rc;
+	}
 
 	cflush.op = 0;
 	cflush.a.dev_bus_addr = 0;
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index e989bc2269f54..1fc67df500145 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -357,9 +357,4 @@ static inline bool xen_arch_need_swiotlb(struct device *dev,
 	return false;
 }
 
-static inline unsigned long xen_get_swiotlb_free_pages(unsigned int order)
-{
-	return __get_free_pages(__GFP_NOWARN, order);
-}
-
 #endif /* _ASM_X86_XEN_PAGE_H */
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index a705a199bf8a3..30bbe4abb5d61 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -72,15 +72,13 @@ static inline void __init pci_swiotlb_detect(void)
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
-static bool xen_swiotlb;
-
 static void __init pci_xen_swiotlb_init(void)
 {
 	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
-	xen_swiotlb = true;
-	xen_swiotlb_init_early();
+	x86_swiotlb_flags |= SWIOTLB_ANY;
+	swiotlb_init_remap(true, x86_swiotlb_flags, xen_swiotlb_fixup);
 	dma_ops = &xen_swiotlb_dma_ops;
 	if (IS_ENABLED(CONFIG_PCI))
 		pci_request_acs();
@@ -88,14 +86,16 @@ static void __init pci_xen_swiotlb_init(void)
 
 int pci_xen_swiotlb_init_late(void)
 {
-	int rc;
-
-	if (xen_swiotlb)
+	if (dma_ops = &xen_swiotlb_dma_ops)
 		return 0;
 
-	rc = xen_swiotlb_init();
-	if (rc)
-		return rc;
+	/* we can work with the default swiotlb */
+	if (!io_tlb_default_mem.nslabs) {
+		int rc = swiotlb_init_late(swiotlb_size_or_default(),
+					   GFP_KERNEL, xen_swiotlb_fixup);
+		if (rc < 0)
+			return rc;
+	}
 
 	/* XXX: this switches the dma ops under live devices! */
 	dma_ops = &xen_swiotlb_dma_ops;
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index c2da3eb4826e8..df8085b50df10 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -104,7 +104,7 @@ static int is_xen_swiotlb_buffer(struct device *dev, dma_addr_t dma_addr)
 	return 0;
 }
 
-static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
+int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
 {
 	int rc;
 	unsigned int order = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT);
@@ -130,132 +130,6 @@ static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
 	return 0;
 }
 
-enum xen_swiotlb_err {
-	XEN_SWIOTLB_UNKNOWN = 0,
-	XEN_SWIOTLB_ENOMEM,
-	XEN_SWIOTLB_EFIXUP
-};
-
-static const char *xen_swiotlb_error(enum xen_swiotlb_err err)
-{
-	switch (err) {
-	case XEN_SWIOTLB_ENOMEM:
-		return "Cannot allocate Xen-SWIOTLB buffer\n";
-	case XEN_SWIOTLB_EFIXUP:
-		return "Failed to get contiguous memory for DMA from Xen!\n"\
-		    "You either: don't have the permissions, do not have"\
-		    " enough free memory under 4GB, or the hypervisor memory"\
-		    " is too fragmented!";
-	default:
-		break;
-	}
-	return "";
-}
-
-int xen_swiotlb_init(void)
-{
-	enum xen_swiotlb_err m_ret = XEN_SWIOTLB_UNKNOWN;
-	unsigned long bytes = swiotlb_size_or_default();
-	unsigned long nslabs = bytes >> IO_TLB_SHIFT;
-	unsigned int order, repeat = 3;
-	int rc = -ENOMEM;
-	char *start;
-
-	if (io_tlb_default_mem.nslabs) {
-		pr_warn("swiotlb buffer already initialized\n");
-		return -EEXIST;
-	}
-
-retry:
-	m_ret = XEN_SWIOTLB_ENOMEM;
-	order = get_order(bytes);
-
-	/*
-	 * Get IO TLB memory from any location.
-	 */
-#define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT))
-#define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
-	while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
-		start = (void *)xen_get_swiotlb_free_pages(order);
-		if (start)
-			break;
-		order--;
-	}
-	if (!start)
-		goto exit;
-	if (order != get_order(bytes)) {
-		pr_warn("Warning: only able to allocate %ld MB for software IO TLB\n",
-			(PAGE_SIZE << order) >> 20);
-		nslabs = SLABS_PER_PAGE << order;
-		bytes = nslabs << IO_TLB_SHIFT;
-	}
-
-	/*
-	 * And replace that memory with pages under 4GB.
-	 */
-	rc = xen_swiotlb_fixup(start, nslabs);
-	if (rc) {
-		free_pages((unsigned long)start, order);
-		m_ret = XEN_SWIOTLB_EFIXUP;
-		goto error;
-	}
-	rc = swiotlb_late_init_with_tbl(start, nslabs);
-	if (rc)
-		return rc;
-	return 0;
-error:
-	if (nslabs > 1024 && repeat--) {
-		/* Min is 2MB */
-		nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
-		bytes = nslabs << IO_TLB_SHIFT;
-		pr_info("Lowering to %luMB\n", bytes >> 20);
-		goto retry;
-	}
-exit:
-	pr_err("%s (rc:%d)\n", xen_swiotlb_error(m_ret), rc);
-	return rc;
-}
-
-#ifdef CONFIG_X86
-void __init xen_swiotlb_init_early(void)
-{
-	unsigned long bytes = swiotlb_size_or_default();
-	unsigned long nslabs = bytes >> IO_TLB_SHIFT;
-	unsigned int repeat = 3;
-	char *start;
-	int rc;
-
-retry:
-	/*
-	 * Get IO TLB memory from any location.
-	 */
-	start = memblock_alloc(PAGE_ALIGN(bytes),
-			       IO_TLB_SEGSIZE << IO_TLB_SHIFT);
-	if (!start)
-		panic("%s: Failed to allocate %lu bytes\n",
-		      __func__, PAGE_ALIGN(bytes));
-
-	/*
-	 * And replace that memory with pages under 4GB.
-	 */
-	rc = xen_swiotlb_fixup(start, nslabs);
-	if (rc) {
-		memblock_free(start, PAGE_ALIGN(bytes));
-		if (nslabs > 1024 && repeat--) {
-			/* Min is 2MB */
-			nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
-			bytes = nslabs << IO_TLB_SHIFT;
-			pr_info("Lowering to %luMB\n", bytes >> 20);
-			goto retry;
-		}
-		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
-	}
-
-	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
-		panic("Cannot allocate SWIOTLB buffer");
-}
-#endif /* CONFIG_X86 */
-
 static void *
 xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
 			   dma_addr_t *dma_handle, gfp_t flags,
diff --git a/include/xen/arm/page.h b/include/xen/arm/page.h
index ac1b654705631..7e199c6656b90 100644
--- a/include/xen/arm/page.h
+++ b/include/xen/arm/page.h
@@ -115,6 +115,5 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
 bool xen_arch_need_swiotlb(struct device *dev,
 			   phys_addr_t phys,
 			   dma_addr_t dev_addr);
-unsigned long xen_get_swiotlb_free_pages(unsigned int order);
 
 #endif /* _ASM_ARM_XEN_PAGE_H */
diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h
index b3e647f86e3e2..590ceb923f0c8 100644
--- a/include/xen/swiotlb-xen.h
+++ b/include/xen/swiotlb-xen.h
@@ -10,8 +10,12 @@ void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle,
 void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,
 			     size_t size, enum dma_data_direction dir);
 
-int xen_swiotlb_init(void);
-void __init xen_swiotlb_init_early(void);
+#ifdef CONFIG_SWIOTLB_XEN
+int xen_swiotlb_fixup(void *buf, unsigned long nslabs);
+#else
+#define xen_swiotlb_fixup NULL
+#endif
+
 extern const struct dma_map_ops xen_swiotlb_dma_ops;
 
 #endif /* __LINUX_SWIOTLB_XEN_H */
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 14/15] swiotlb: remove swiotlb_init_with_tbl and swiotlb_init_late_with_tbl
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

No users left.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/swiotlb.h |  2 --
 kernel/dma/swiotlb.c    | 77 +++++++++++------------------------------
 2 files changed, 20 insertions(+), 59 deletions(-)

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 7b50c82f84ce9..7ed35dd3de6e7 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -34,13 +34,11 @@ struct scatterlist;
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 	int (*remap)(void *tlb, unsigned long nslabs));
 int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 	int (*remap)(void *tlb, unsigned long nslabs));
-extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index d5fe8f5e08300..c54fc40ebb493 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -225,33 +225,6 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
-		unsigned int flags)
-{
-	struct io_tlb_mem *mem = &io_tlb_default_mem;
-	size_t alloc_size;
-
-	if (swiotlb_force_disable)
-		return 0;
-
-	/* protect against double initialization */
-	if (WARN_ON_ONCE(mem->nslabs))
-		return -ENOMEM;
-
-	alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
-	mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
-	if (!mem->slots)
-		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
-		      __func__, alloc_size, PAGE_SIZE);
-
-	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
-
-	if (flags & SWIOTLB_VERBOSE)
-		swiotlb_print_info();
-	return 0;
-}
-
 /*
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
@@ -259,7 +232,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		int (*remap)(void *tlb, unsigned long nslabs))
 {
+	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long nslabs = default_nslabs;
+	size_t alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
 	size_t bytes;
 	void *tlb;
 
@@ -280,7 +255,8 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 	else
 		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
-		goto fail;
+		panic("%s: failed to allocate tlb structure\n", __func__);
+
 	if (remap && remap(tlb, nslabs) < 0) {
 		memblock_free(tlb, PAGE_ALIGN(bytes));
 
@@ -290,14 +266,17 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 			      __func__, bytes);
 		goto retry;
 	}
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
-		goto fail_free_mem;
-	return;
 
-fail_free_mem:
-	memblock_free(tlb, bytes);
-fail:
-	pr_warn("Cannot allocate buffer");
+	mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
+	if (!mem->slots)
+		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
+		      __func__, alloc_size, PAGE_SIZE);
+
+	swiotlb_init_io_tlb_mem(mem, __pa(tlb), default_nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
+
+	if (flags & SWIOTLB_VERBOSE)
+		swiotlb_print_info();
 }
 
 void __init swiotlb_init(bool addressing_limit, unsigned int flags)
@@ -313,6 +292,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 		int (*remap)(void *tlb, unsigned long nslabs))
 {
+	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
 	unsigned char *vstart = NULL;
@@ -353,33 +333,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 			return rc;
 		goto retry;
 	}
-	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
-	if (rc)
-		free_pages((unsigned long)vstart, order);
-
-	return rc;
-}
-
-int
-swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
-{
-	struct io_tlb_mem *mem = &io_tlb_default_mem;
-	unsigned long bytes = nslabs << IO_TLB_SHIFT;
-
-	if (swiotlb_force_disable)
-		return 0;
-
-	/* protect against double initialization */
-	if (WARN_ON_ONCE(mem->nslabs))
-		return -ENOMEM;
 
 	mem->slots = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
 		get_order(array_size(sizeof(*mem->slots), nslabs)));
-	if (!mem->slots)
+	if (!mem->slots) {
+		free_pages((unsigned long)vstart, order);
 		return -ENOMEM;
+	}
 
-	set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT);
-	swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
+	set_memory_decrypted((unsigned long)vstart, bytes >> PAGE_SHIFT);
+	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
 
 	swiotlb_print_info();
 	return 0;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 14/15] swiotlb: remove swiotlb_init_with_tbl and swiotlb_init_late_with_tbl
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

No users left.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/swiotlb.h |  2 --
 kernel/dma/swiotlb.c    | 77 +++++++++++------------------------------
 2 files changed, 20 insertions(+), 59 deletions(-)

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 7b50c82f84ce9..7ed35dd3de6e7 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -34,13 +34,11 @@ struct scatterlist;
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 	int (*remap)(void *tlb, unsigned long nslabs));
 int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 	int (*remap)(void *tlb, unsigned long nslabs));
-extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index d5fe8f5e08300..c54fc40ebb493 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -225,33 +225,6 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
-		unsigned int flags)
-{
-	struct io_tlb_mem *mem = &io_tlb_default_mem;
-	size_t alloc_size;
-
-	if (swiotlb_force_disable)
-		return 0;
-
-	/* protect against double initialization */
-	if (WARN_ON_ONCE(mem->nslabs))
-		return -ENOMEM;
-
-	alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
-	mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
-	if (!mem->slots)
-		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
-		      __func__, alloc_size, PAGE_SIZE);
-
-	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
-
-	if (flags & SWIOTLB_VERBOSE)
-		swiotlb_print_info();
-	return 0;
-}
-
 /*
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
@@ -259,7 +232,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		int (*remap)(void *tlb, unsigned long nslabs))
 {
+	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long nslabs = default_nslabs;
+	size_t alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
 	size_t bytes;
 	void *tlb;
 
@@ -280,7 +255,8 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 	else
 		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
-		goto fail;
+		panic("%s: failed to allocate tlb structure\n", __func__);
+
 	if (remap && remap(tlb, nslabs) < 0) {
 		memblock_free(tlb, PAGE_ALIGN(bytes));
 
@@ -290,14 +266,17 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 			      __func__, bytes);
 		goto retry;
 	}
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
-		goto fail_free_mem;
-	return;
 
-fail_free_mem:
-	memblock_free(tlb, bytes);
-fail:
-	pr_warn("Cannot allocate buffer");
+	mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
+	if (!mem->slots)
+		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
+		      __func__, alloc_size, PAGE_SIZE);
+
+	swiotlb_init_io_tlb_mem(mem, __pa(tlb), default_nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
+
+	if (flags & SWIOTLB_VERBOSE)
+		swiotlb_print_info();
 }
 
 void __init swiotlb_init(bool addressing_limit, unsigned int flags)
@@ -313,6 +292,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 		int (*remap)(void *tlb, unsigned long nslabs))
 {
+	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
 	unsigned char *vstart = NULL;
@@ -353,33 +333,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 			return rc;
 		goto retry;
 	}
-	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
-	if (rc)
-		free_pages((unsigned long)vstart, order);
-
-	return rc;
-}
-
-int
-swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
-{
-	struct io_tlb_mem *mem = &io_tlb_default_mem;
-	unsigned long bytes = nslabs << IO_TLB_SHIFT;
-
-	if (swiotlb_force_disable)
-		return 0;
-
-	/* protect against double initialization */
-	if (WARN_ON_ONCE(mem->nslabs))
-		return -ENOMEM;
 
 	mem->slots = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
 		get_order(array_size(sizeof(*mem->slots), nslabs)));
-	if (!mem->slots)
+	if (!mem->slots) {
+		free_pages((unsigned long)vstart, order);
 		return -ENOMEM;
+	}
 
-	set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT);
-	swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
+	set_memory_decrypted((unsigned long)vstart, bytes >> PAGE_SHIFT);
+	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
 
 	swiotlb_print_info();
 	return 0;
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 14/15] swiotlb: remove swiotlb_init_with_tbl and swiotlb_init_late_with_tbl
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

No users left.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/swiotlb.h |  2 --
 kernel/dma/swiotlb.c    | 77 +++++++++++------------------------------
 2 files changed, 20 insertions(+), 59 deletions(-)

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 7b50c82f84ce9..7ed35dd3de6e7 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -34,13 +34,11 @@ struct scatterlist;
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 	int (*remap)(void *tlb, unsigned long nslabs));
 int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 	int (*remap)(void *tlb, unsigned long nslabs));
-extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index d5fe8f5e08300..c54fc40ebb493 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -225,33 +225,6 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
-		unsigned int flags)
-{
-	struct io_tlb_mem *mem = &io_tlb_default_mem;
-	size_t alloc_size;
-
-	if (swiotlb_force_disable)
-		return 0;
-
-	/* protect against double initialization */
-	if (WARN_ON_ONCE(mem->nslabs))
-		return -ENOMEM;
-
-	alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
-	mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
-	if (!mem->slots)
-		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
-		      __func__, alloc_size, PAGE_SIZE);
-
-	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
-
-	if (flags & SWIOTLB_VERBOSE)
-		swiotlb_print_info();
-	return 0;
-}
-
 /*
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
@@ -259,7 +232,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		int (*remap)(void *tlb, unsigned long nslabs))
 {
+	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long nslabs = default_nslabs;
+	size_t alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
 	size_t bytes;
 	void *tlb;
 
@@ -280,7 +255,8 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 	else
 		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
-		goto fail;
+		panic("%s: failed to allocate tlb structure\n", __func__);
+
 	if (remap && remap(tlb, nslabs) < 0) {
 		memblock_free(tlb, PAGE_ALIGN(bytes));
 
@@ -290,14 +266,17 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 			      __func__, bytes);
 		goto retry;
 	}
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
-		goto fail_free_mem;
-	return;
 
-fail_free_mem:
-	memblock_free(tlb, bytes);
-fail:
-	pr_warn("Cannot allocate buffer");
+	mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
+	if (!mem->slots)
+		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
+		      __func__, alloc_size, PAGE_SIZE);
+
+	swiotlb_init_io_tlb_mem(mem, __pa(tlb), default_nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
+
+	if (flags & SWIOTLB_VERBOSE)
+		swiotlb_print_info();
 }
 
 void __init swiotlb_init(bool addressing_limit, unsigned int flags)
@@ -313,6 +292,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 		int (*remap)(void *tlb, unsigned long nslabs))
 {
+	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
 	unsigned char *vstart = NULL;
@@ -353,33 +333,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 			return rc;
 		goto retry;
 	}
-	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
-	if (rc)
-		free_pages((unsigned long)vstart, order);
-
-	return rc;
-}
-
-int
-swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
-{
-	struct io_tlb_mem *mem = &io_tlb_default_mem;
-	unsigned long bytes = nslabs << IO_TLB_SHIFT;
-
-	if (swiotlb_force_disable)
-		return 0;
-
-	/* protect against double initialization */
-	if (WARN_ON_ONCE(mem->nslabs))
-		return -ENOMEM;
 
 	mem->slots = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
 		get_order(array_size(sizeof(*mem->slots), nslabs)));
-	if (!mem->slots)
+	if (!mem->slots) {
+		free_pages((unsigned long)vstart, order);
 		return -ENOMEM;
+	}
 
-	set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT);
-	swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
+	set_memory_decrypted((unsigned long)vstart, bytes >> PAGE_SHIFT);
+	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
 
 	swiotlb_print_info();
 	return 0;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 14/15] swiotlb: remove swiotlb_init_with_tbl and swiotlb_init_late_with_tbl
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

No users left.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/swiotlb.h |  2 --
 kernel/dma/swiotlb.c    | 77 +++++++++++------------------------------
 2 files changed, 20 insertions(+), 59 deletions(-)

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 7b50c82f84ce9..7ed35dd3de6e7 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -34,13 +34,11 @@ struct scatterlist;
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 	int (*remap)(void *tlb, unsigned long nslabs));
 int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 	int (*remap)(void *tlb, unsigned long nslabs));
-extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index d5fe8f5e08300..c54fc40ebb493 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -225,33 +225,6 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
-		unsigned int flags)
-{
-	struct io_tlb_mem *mem = &io_tlb_default_mem;
-	size_t alloc_size;
-
-	if (swiotlb_force_disable)
-		return 0;
-
-	/* protect against double initialization */
-	if (WARN_ON_ONCE(mem->nslabs))
-		return -ENOMEM;
-
-	alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
-	mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
-	if (!mem->slots)
-		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
-		      __func__, alloc_size, PAGE_SIZE);
-
-	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
-
-	if (flags & SWIOTLB_VERBOSE)
-		swiotlb_print_info();
-	return 0;
-}
-
 /*
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
@@ -259,7 +232,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		int (*remap)(void *tlb, unsigned long nslabs))
 {
+	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long nslabs = default_nslabs;
+	size_t alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
 	size_t bytes;
 	void *tlb;
 
@@ -280,7 +255,8 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 	else
 		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
-		goto fail;
+		panic("%s: failed to allocate tlb structure\n", __func__);
+
 	if (remap && remap(tlb, nslabs) < 0) {
 		memblock_free(tlb, PAGE_ALIGN(bytes));
 
@@ -290,14 +266,17 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 			      __func__, bytes);
 		goto retry;
 	}
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
-		goto fail_free_mem;
-	return;
 
-fail_free_mem:
-	memblock_free(tlb, bytes);
-fail:
-	pr_warn("Cannot allocate buffer");
+	mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
+	if (!mem->slots)
+		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
+		      __func__, alloc_size, PAGE_SIZE);
+
+	swiotlb_init_io_tlb_mem(mem, __pa(tlb), default_nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
+
+	if (flags & SWIOTLB_VERBOSE)
+		swiotlb_print_info();
 }
 
 void __init swiotlb_init(bool addressing_limit, unsigned int flags)
@@ -313,6 +292,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 		int (*remap)(void *tlb, unsigned long nslabs))
 {
+	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
 	unsigned char *vstart = NULL;
@@ -353,33 +333,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 			return rc;
 		goto retry;
 	}
-	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
-	if (rc)
-		free_pages((unsigned long)vstart, order);
-
-	return rc;
-}
-
-int
-swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
-{
-	struct io_tlb_mem *mem = &io_tlb_default_mem;
-	unsigned long bytes = nslabs << IO_TLB_SHIFT;
-
-	if (swiotlb_force_disable)
-		return 0;
-
-	/* protect against double initialization */
-	if (WARN_ON_ONCE(mem->nslabs))
-		return -ENOMEM;
 
 	mem->slots = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
 		get_order(array_size(sizeof(*mem->slots), nslabs)));
-	if (!mem->slots)
+	if (!mem->slots) {
+		free_pages((unsigned long)vstart, order);
 		return -ENOMEM;
+	}
 
-	set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT);
-	swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
+	set_memory_decrypted((unsigned long)vstart, bytes >> PAGE_SHIFT);
+	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
 
 	swiotlb_print_info();
 	return 0;
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 14/15] swiotlb: remove swiotlb_init_with_tbl and swiotlb_init_late_with_tbl
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

No users left.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/swiotlb.h |  2 --
 kernel/dma/swiotlb.c    | 77 +++++++++++------------------------------
 2 files changed, 20 insertions(+), 59 deletions(-)

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 7b50c82f84ce9..7ed35dd3de6e7 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -34,13 +34,11 @@ struct scatterlist;
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 	int (*remap)(void *tlb, unsigned long nslabs));
 int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 	int (*remap)(void *tlb, unsigned long nslabs));
-extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index d5fe8f5e08300..c54fc40ebb493 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -225,33 +225,6 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
-		unsigned int flags)
-{
-	struct io_tlb_mem *mem = &io_tlb_default_mem;
-	size_t alloc_size;
-
-	if (swiotlb_force_disable)
-		return 0;
-
-	/* protect against double initialization */
-	if (WARN_ON_ONCE(mem->nslabs))
-		return -ENOMEM;
-
-	alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
-	mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
-	if (!mem->slots)
-		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
-		      __func__, alloc_size, PAGE_SIZE);
-
-	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
-
-	if (flags & SWIOTLB_VERBOSE)
-		swiotlb_print_info();
-	return 0;
-}
-
 /*
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
@@ -259,7 +232,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		int (*remap)(void *tlb, unsigned long nslabs))
 {
+	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long nslabs = default_nslabs;
+	size_t alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
 	size_t bytes;
 	void *tlb;
 
@@ -280,7 +255,8 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 	else
 		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
-		goto fail;
+		panic("%s: failed to allocate tlb structure\n", __func__);
+
 	if (remap && remap(tlb, nslabs) < 0) {
 		memblock_free(tlb, PAGE_ALIGN(bytes));
 
@@ -290,14 +266,17 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 			      __func__, bytes);
 		goto retry;
 	}
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
-		goto fail_free_mem;
-	return;
 
-fail_free_mem:
-	memblock_free(tlb, bytes);
-fail:
-	pr_warn("Cannot allocate buffer");
+	mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
+	if (!mem->slots)
+		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
+		      __func__, alloc_size, PAGE_SIZE);
+
+	swiotlb_init_io_tlb_mem(mem, __pa(tlb), default_nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
+
+	if (flags & SWIOTLB_VERBOSE)
+		swiotlb_print_info();
 }
 
 void __init swiotlb_init(bool addressing_limit, unsigned int flags)
@@ -313,6 +292,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 		int (*remap)(void *tlb, unsigned long nslabs))
 {
+	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
 	unsigned char *vstart = NULL;
@@ -353,33 +333,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 			return rc;
 		goto retry;
 	}
-	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
-	if (rc)
-		free_pages((unsigned long)vstart, order);
-
-	return rc;
-}
-
-int
-swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
-{
-	struct io_tlb_mem *mem = &io_tlb_default_mem;
-	unsigned long bytes = nslabs << IO_TLB_SHIFT;
-
-	if (swiotlb_force_disable)
-		return 0;
-
-	/* protect against double initialization */
-	if (WARN_ON_ONCE(mem->nslabs))
-		return -ENOMEM;
 
 	mem->slots = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
 		get_order(array_size(sizeof(*mem->slots), nslabs)));
-	if (!mem->slots)
+	if (!mem->slots) {
+		free_pages((unsigned long)vstart, order);
 		return -ENOMEM;
+	}
 
-	set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT);
-	swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
+	set_memory_decrypted((unsigned long)vstart, bytes >> PAGE_SHIFT);
+	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
 
 	swiotlb_print_info();
 	return 0;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 14/15] swiotlb: remove swiotlb_init_with_tbl and swiotlb_init_late_with_tbl
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

No users left.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/swiotlb.h |  2 --
 kernel/dma/swiotlb.c    | 77 +++++++++++------------------------------
 2 files changed, 20 insertions(+), 59 deletions(-)

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 7b50c82f84ce9..7ed35dd3de6e7 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -34,13 +34,11 @@ struct scatterlist;
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 	int (*remap)(void *tlb, unsigned long nslabs));
 int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 	int (*remap)(void *tlb, unsigned long nslabs));
-extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 extern void __init swiotlb_update_mem_attributes(void);
 
 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index d5fe8f5e08300..c54fc40ebb493 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -225,33 +225,6 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
-		unsigned int flags)
-{
-	struct io_tlb_mem *mem = &io_tlb_default_mem;
-	size_t alloc_size;
-
-	if (swiotlb_force_disable)
-		return 0;
-
-	/* protect against double initialization */
-	if (WARN_ON_ONCE(mem->nslabs))
-		return -ENOMEM;
-
-	alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
-	mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
-	if (!mem->slots)
-		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
-		      __func__, alloc_size, PAGE_SIZE);
-
-	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
-
-	if (flags & SWIOTLB_VERBOSE)
-		swiotlb_print_info();
-	return 0;
-}
-
 /*
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
@@ -259,7 +232,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		int (*remap)(void *tlb, unsigned long nslabs))
 {
+	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long nslabs = default_nslabs;
+	size_t alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
 	size_t bytes;
 	void *tlb;
 
@@ -280,7 +255,8 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 	else
 		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
-		goto fail;
+		panic("%s: failed to allocate tlb structure\n", __func__);
+
 	if (remap && remap(tlb, nslabs) < 0) {
 		memblock_free(tlb, PAGE_ALIGN(bytes));
 
@@ -290,14 +266,17 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 			      __func__, bytes);
 		goto retry;
 	}
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
-		goto fail_free_mem;
-	return;
 
-fail_free_mem:
-	memblock_free(tlb, bytes);
-fail:
-	pr_warn("Cannot allocate buffer");
+	mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
+	if (!mem->slots)
+		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
+		      __func__, alloc_size, PAGE_SIZE);
+
+	swiotlb_init_io_tlb_mem(mem, __pa(tlb), default_nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
+
+	if (flags & SWIOTLB_VERBOSE)
+		swiotlb_print_info();
 }
 
 void __init swiotlb_init(bool addressing_limit, unsigned int flags)
@@ -313,6 +292,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 		int (*remap)(void *tlb, unsigned long nslabs))
 {
+	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
 	unsigned long bytes;
 	unsigned char *vstart = NULL;
@@ -353,33 +333,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 			return rc;
 		goto retry;
 	}
-	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
-	if (rc)
-		free_pages((unsigned long)vstart, order);
-
-	return rc;
-}
-
-int
-swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
-{
-	struct io_tlb_mem *mem = &io_tlb_default_mem;
-	unsigned long bytes = nslabs << IO_TLB_SHIFT;
-
-	if (swiotlb_force_disable)
-		return 0;
-
-	/* protect against double initialization */
-	if (WARN_ON_ONCE(mem->nslabs))
-		return -ENOMEM;
 
 	mem->slots = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
 		get_order(array_size(sizeof(*mem->slots), nslabs)));
-	if (!mem->slots)
+	if (!mem->slots) {
+		free_pages((unsigned long)vstart, order);
 		return -ENOMEM;
+	}
 
-	set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT);
-	swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true);
+	set_memory_decrypted((unsigned long)vstart, bytes >> PAGE_SHIFT);
+	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
 
 	swiotlb_print_info();
 	return 0;
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 15/15] x86: remove cruft from <asm/dma-mapping.h>
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  5:05   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

<asm/dma-mapping.h> gets pulled in by all drivers using the DMA API.
Remove x86 internal variables and unnecessary includes from it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/include/asm/dma-mapping.h | 11 -----------
 arch/x86/include/asm/iommu.h       |  2 ++
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index 256fd8115223d..1c66708e30623 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -2,17 +2,6 @@
 #ifndef _ASM_X86_DMA_MAPPING_H
 #define _ASM_X86_DMA_MAPPING_H
 
-/*
- * IOMMU interface. See Documentation/core-api/dma-api-howto.rst and
- * Documentation/core-api/dma-api.rst for documentation.
- */
-
-#include <linux/scatterlist.h>
-#include <asm/io.h>
-
-extern int iommu_merge;
-extern int panic_on_overflow;
-
 extern const struct dma_map_ops *dma_ops;
 
 static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
index dba89ed40d38d..0bef44d30a278 100644
--- a/arch/x86/include/asm/iommu.h
+++ b/arch/x86/include/asm/iommu.h
@@ -8,6 +8,8 @@
 
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
+extern int iommu_merge;
+extern int panic_on_overflow;
 
 #ifdef CONFIG_SWIOTLB
 extern bool x86_swiotlb_enable;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 15/15] x86: remove cruft from <asm/dma-mapping.h>
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

<asm/dma-mapping.h> gets pulled in by all drivers using the DMA API.
Remove x86 internal variables and unnecessary includes from it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/include/asm/dma-mapping.h | 11 -----------
 arch/x86/include/asm/iommu.h       |  2 ++
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index 256fd8115223d..1c66708e30623 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -2,17 +2,6 @@
 #ifndef _ASM_X86_DMA_MAPPING_H
 #define _ASM_X86_DMA_MAPPING_H
 
-/*
- * IOMMU interface. See Documentation/core-api/dma-api-howto.rst and
- * Documentation/core-api/dma-api.rst for documentation.
- */
-
-#include <linux/scatterlist.h>
-#include <asm/io.h>
-
-extern int iommu_merge;
-extern int panic_on_overflow;
-
 extern const struct dma_map_ops *dma_ops;
 
 static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
index dba89ed40d38d..0bef44d30a278 100644
--- a/arch/x86/include/asm/iommu.h
+++ b/arch/x86/include/asm/iommu.h
@@ -8,6 +8,8 @@
 
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
+extern int iommu_merge;
+extern int panic_on_overflow;
 
 #ifdef CONFIG_SWIOTLB
 extern bool x86_swiotlb_enable;
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 15/15] x86: remove cruft from <asm/dma-mapping.h>
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

<asm/dma-mapping.h> gets pulled in by all drivers using the DMA API.
Remove x86 internal variables and unnecessary includes from it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/include/asm/dma-mapping.h | 11 -----------
 arch/x86/include/asm/iommu.h       |  2 ++
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index 256fd8115223d..1c66708e30623 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -2,17 +2,6 @@
 #ifndef _ASM_X86_DMA_MAPPING_H
 #define _ASM_X86_DMA_MAPPING_H
 
-/*
- * IOMMU interface. See Documentation/core-api/dma-api-howto.rst and
- * Documentation/core-api/dma-api.rst for documentation.
- */
-
-#include <linux/scatterlist.h>
-#include <asm/io.h>
-
-extern int iommu_merge;
-extern int panic_on_overflow;
-
 extern const struct dma_map_ops *dma_ops;
 
 static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
index dba89ed40d38d..0bef44d30a278 100644
--- a/arch/x86/include/asm/iommu.h
+++ b/arch/x86/include/asm/iommu.h
@@ -8,6 +8,8 @@
 
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
+extern int iommu_merge;
+extern int panic_on_overflow;
 
 #ifdef CONFIG_SWIOTLB
 extern bool x86_swiotlb_enable;
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 15/15] x86: remove cruft from <asm/dma-mapping.h>
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

<asm/dma-mapping.h> gets pulled in by all drivers using the DMA API.
Remove x86 internal variables and unnecessary includes from it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/include/asm/dma-mapping.h | 11 -----------
 arch/x86/include/asm/iommu.h       |  2 ++
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index 256fd8115223d..1c66708e30623 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -2,17 +2,6 @@
 #ifndef _ASM_X86_DMA_MAPPING_H
 #define _ASM_X86_DMA_MAPPING_H
 
-/*
- * IOMMU interface. See Documentation/core-api/dma-api-howto.rst and
- * Documentation/core-api/dma-api.rst for documentation.
- */
-
-#include <linux/scatterlist.h>
-#include <asm/io.h>
-
-extern int iommu_merge;
-extern int panic_on_overflow;
-
 extern const struct dma_map_ops *dma_ops;
 
 static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
index dba89ed40d38d..0bef44d30a278 100644
--- a/arch/x86/include/asm/iommu.h
+++ b/arch/x86/include/asm/iommu.h
@@ -8,6 +8,8 @@
 
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
+extern int iommu_merge;
+extern int panic_on_overflow;
 
 #ifdef CONFIG_SWIOTLB
 extern bool x86_swiotlb_enable;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 15/15] x86: remove cruft from <asm/dma-mapping.h>
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

<asm/dma-mapping.h> gets pulled in by all drivers using the DMA API.
Remove x86 internal variables and unnecessary includes from it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/include/asm/dma-mapping.h | 11 -----------
 arch/x86/include/asm/iommu.h       |  2 ++
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index 256fd8115223d..1c66708e30623 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -2,17 +2,6 @@
 #ifndef _ASM_X86_DMA_MAPPING_H
 #define _ASM_X86_DMA_MAPPING_H
 
-/*
- * IOMMU interface. See Documentation/core-api/dma-api-howto.rst and
- * Documentation/core-api/dma-api.rst for documentation.
- */
-
-#include <linux/scatterlist.h>
-#include <asm/io.h>
-
-extern int iommu_merge;
-extern int panic_on_overflow;
-
 extern const struct dma_map_ops *dma_ops;
 
 static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
index dba89ed40d38d..0bef44d30a278 100644
--- a/arch/x86/include/asm/iommu.h
+++ b/arch/x86/include/asm/iommu.h
@@ -8,6 +8,8 @@
 
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
+extern int iommu_merge;
+extern int panic_on_overflow;
 
 #ifdef CONFIG_SWIOTLB
 extern bool x86_swiotlb_enable;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 15/15] x86: remove cruft from <asm/dma-mapping.h>
@ 2022-04-04  5:05   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-04  5:05 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

<asm/dma-mapping.h> gets pulled in by all drivers using the DMA API.
Remove x86 internal variables and unnecessary includes from it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/include/asm/dma-mapping.h | 11 -----------
 arch/x86/include/asm/iommu.h       |  2 ++
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index 256fd8115223d..1c66708e30623 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -2,17 +2,6 @@
 #ifndef _ASM_X86_DMA_MAPPING_H
 #define _ASM_X86_DMA_MAPPING_H
 
-/*
- * IOMMU interface. See Documentation/core-api/dma-api-howto.rst and
- * Documentation/core-api/dma-api.rst for documentation.
- */
-
-#include <linux/scatterlist.h>
-#include <asm/io.h>
-
-extern int iommu_merge;
-extern int panic_on_overflow;
-
 extern const struct dma_map_ops *dma_ops;
 
 static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
index dba89ed40d38d..0bef44d30a278 100644
--- a/arch/x86/include/asm/iommu.h
+++ b/arch/x86/include/asm/iommu.h
@@ -8,6 +8,8 @@
 
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
+extern int iommu_merge;
+extern int panic_on_overflow;
 
 #ifdef CONFIG_SWIOTLB
 extern bool x86_swiotlb_enable;
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* Re: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
       [not found] ` <67c1784af6f24f3e871ddfb1478e821c@FR3P281MB0843.DEUP281.PROD.OUTLOOK.COM>
                       ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  6:19     ` Alan Robinson
  0 siblings, 0 replies; 197+ messages in thread
From: Alan Robinson @ 2022-04-04  6:19 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

Hi Christoph,

On Mon, Apr 04, 2022 at 05:05:56AM +0000, Christoph Hellwig wrote:
> From: Christoph Hellwig <hch@lst.de>
> Subject: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap
>  the buffer
> 
> To shared more code between swiotlb and xen-swiotlb, offer a
> swiotlb_init_remap interface and add a remap callback to
> swiotlb_init_late that will allow Xen to remap the buffer the

s/the buffer//

> buffer without duplicating much of the logic.

Alan

> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/x86/pci/sta2x11-fixup.c |  2 +-
>  include/linux/swiotlb.h      |  5 ++++-
>  kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
>  3 files changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
> index c7e6faf59a861..7368afc039987 100644
> --- a/arch/x86/pci/sta2x11-fixup.c
> +++ b/arch/x86/pci/sta2x11-fixup.c
> @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
>  		int size = STA2X11_SWIOTLB_SIZE;
>  		/* First instance: register your own swiotlb area */
>  		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
> -		if (swiotlb_init_late(size, GFP_DMA))
> +		if (swiotlb_init_late(size, GFP_DMA, NULL))
>  			dev_emerg(&pdev->dev, "init swiotlb failed\n");
>  	}
>  	list_add(&instance->list, &sta2x11_instance_list);
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index ee655f2e4d28b..7b50c82f84ce9 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -36,8 +36,11 @@ struct scatterlist;
>  
>  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +	int (*remap)(void *tlb, unsigned long nslabs));
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +	int (*remap)(void *tlb, unsigned long nslabs));
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask);
>  extern void __init swiotlb_update_mem_attributes(void);
>  
>  phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 119187afc65ec..d5fe8f5e08300 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
> -	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
> +	unsigned long nslabs = default_nslabs;
> +	size_t bytes;
>  	void *tlb;
>  
>  	if (!addressing_limit && !swiotlb_force_bounce)
> @@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	 * allow to pick a location everywhere for hypervisors with guest
>  	 * memory encryption.
>  	 */
> +retry:
> +	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	if (flags & SWIOTLB_ANY)
>  		tlb = memblock_alloc(bytes, PAGE_SIZE);
>  	else
>  		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> +	if (remap && remap(tlb, nslabs) < 0) {
> +		memblock_free(tlb, PAGE_ALIGN(bytes));
> +
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			panic("%s: Failed to remap %zu bytes\n",
> +			      __func__, bytes);
> +		goto retry;
> +	}
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> @@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	pr_warn("Cannot allocate buffer");
>  }
>  
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +{
> +	return swiotlb_init_remap(addressing_limit, flags, NULL);
> +}
> +
>  /*
>   * Systems with larger DMA zones (those that don't support ISA) can
>   * initialize the swiotlb later using the slab allocator if needed.
>   * This should be just like above, but with some error catching.
>   */
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask)
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
>  	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
>  	unsigned long bytes;
> @@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  	if (swiotlb_force_disable)
>  		return 0;
>  
> +retry:
>  	order = get_order(nslabs << IO_TLB_SHIFT);
>  	nslabs = SLABS_PER_PAGE << order;
>  	bytes = nslabs << IO_TLB_SHIFT;
> @@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  			(PAGE_SIZE << order) >> 20);
>  		nslabs = SLABS_PER_PAGE << order;
>  	}
> +	if (remap)
> +		rc = remap(vstart, nslabs);
> +	if (rc) {
> +		free_pages((unsigned long)vstart, order);
> + 
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			return rc;
> +		goto retry;
> +	}
>  	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
>  	if (rc)
>  		free_pages((unsigned long)vstart, order);
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  6:19     ` Alan Robinson
  0 siblings, 0 replies; 197+ messages in thread
From: Alan Robinson @ 2022-04-04  6:19 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

Hi Christoph,

On Mon, Apr 04, 2022 at 05:05:56AM +0000, Christoph Hellwig wrote:
> From: Christoph Hellwig <hch@lst.de>
> Subject: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap
>  the buffer
> 
> To shared more code between swiotlb and xen-swiotlb, offer a
> swiotlb_init_remap interface and add a remap callback to
> swiotlb_init_late that will allow Xen to remap the buffer the

s/the buffer//

> buffer without duplicating much of the logic.

Alan

> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/x86/pci/sta2x11-fixup.c |  2 +-
>  include/linux/swiotlb.h      |  5 ++++-
>  kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
>  3 files changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
> index c7e6faf59a861..7368afc039987 100644
> --- a/arch/x86/pci/sta2x11-fixup.c
> +++ b/arch/x86/pci/sta2x11-fixup.c
> @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
>  		int size = STA2X11_SWIOTLB_SIZE;
>  		/* First instance: register your own swiotlb area */
>  		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
> -		if (swiotlb_init_late(size, GFP_DMA))
> +		if (swiotlb_init_late(size, GFP_DMA, NULL))
>  			dev_emerg(&pdev->dev, "init swiotlb failed\n");
>  	}
>  	list_add(&instance->list, &sta2x11_instance_list);
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index ee655f2e4d28b..7b50c82f84ce9 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -36,8 +36,11 @@ struct scatterlist;
>  
>  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +	int (*remap)(void *tlb, unsigned long nslabs));
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +	int (*remap)(void *tlb, unsigned long nslabs));
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask);
>  extern void __init swiotlb_update_mem_attributes(void);
>  
>  phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 119187afc65ec..d5fe8f5e08300 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
> -	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
> +	unsigned long nslabs = default_nslabs;
> +	size_t bytes;
>  	void *tlb;
>  
>  	if (!addressing_limit && !swiotlb_force_bounce)
> @@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	 * allow to pick a location everywhere for hypervisors with guest
>  	 * memory encryption.
>  	 */
> +retry:
> +	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	if (flags & SWIOTLB_ANY)
>  		tlb = memblock_alloc(bytes, PAGE_SIZE);
>  	else
>  		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> +	if (remap && remap(tlb, nslabs) < 0) {
> +		memblock_free(tlb, PAGE_ALIGN(bytes));
> +
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			panic("%s: Failed to remap %zu bytes\n",
> +			      __func__, bytes);
> +		goto retry;
> +	}
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> @@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	pr_warn("Cannot allocate buffer");
>  }
>  
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +{
> +	return swiotlb_init_remap(addressing_limit, flags, NULL);
> +}
> +
>  /*
>   * Systems with larger DMA zones (those that don't support ISA) can
>   * initialize the swiotlb later using the slab allocator if needed.
>   * This should be just like above, but with some error catching.
>   */
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask)
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
>  	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
>  	unsigned long bytes;
> @@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  	if (swiotlb_force_disable)
>  		return 0;
>  
> +retry:
>  	order = get_order(nslabs << IO_TLB_SHIFT);
>  	nslabs = SLABS_PER_PAGE << order;
>  	bytes = nslabs << IO_TLB_SHIFT;
> @@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  			(PAGE_SIZE << order) >> 20);
>  		nslabs = SLABS_PER_PAGE << order;
>  	}
> +	if (remap)
> +		rc = remap(vstart, nslabs);
> +	if (rc) {
> +		free_pages((unsigned long)vstart, order);
> + 
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			return rc;
> +		goto retry;
> +	}
>  	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
>  	if (rc)
>  		free_pages((unsigned long)vstart, order);
> -- 
> 2.30.2
> 

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  6:19     ` Alan Robinson
  0 siblings, 0 replies; 197+ messages in thread
From: Alan Robinson @ 2022-04-04  6:19 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

Hi Christoph,

On Mon, Apr 04, 2022 at 05:05:56AM +0000, Christoph Hellwig wrote:
> From: Christoph Hellwig <hch@lst.de>
> Subject: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap
>  the buffer
> 
> To shared more code between swiotlb and xen-swiotlb, offer a
> swiotlb_init_remap interface and add a remap callback to
> swiotlb_init_late that will allow Xen to remap the buffer the

s/the buffer//

> buffer without duplicating much of the logic.

Alan

> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/x86/pci/sta2x11-fixup.c |  2 +-
>  include/linux/swiotlb.h      |  5 ++++-
>  kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
>  3 files changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
> index c7e6faf59a861..7368afc039987 100644
> --- a/arch/x86/pci/sta2x11-fixup.c
> +++ b/arch/x86/pci/sta2x11-fixup.c
> @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
>  		int size = STA2X11_SWIOTLB_SIZE;
>  		/* First instance: register your own swiotlb area */
>  		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
> -		if (swiotlb_init_late(size, GFP_DMA))
> +		if (swiotlb_init_late(size, GFP_DMA, NULL))
>  			dev_emerg(&pdev->dev, "init swiotlb failed\n");
>  	}
>  	list_add(&instance->list, &sta2x11_instance_list);
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index ee655f2e4d28b..7b50c82f84ce9 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -36,8 +36,11 @@ struct scatterlist;
>  
>  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +	int (*remap)(void *tlb, unsigned long nslabs));
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +	int (*remap)(void *tlb, unsigned long nslabs));
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask);
>  extern void __init swiotlb_update_mem_attributes(void);
>  
>  phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 119187afc65ec..d5fe8f5e08300 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
> -	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
> +	unsigned long nslabs = default_nslabs;
> +	size_t bytes;
>  	void *tlb;
>  
>  	if (!addressing_limit && !swiotlb_force_bounce)
> @@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	 * allow to pick a location everywhere for hypervisors with guest
>  	 * memory encryption.
>  	 */
> +retry:
> +	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	if (flags & SWIOTLB_ANY)
>  		tlb = memblock_alloc(bytes, PAGE_SIZE);
>  	else
>  		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> +	if (remap && remap(tlb, nslabs) < 0) {
> +		memblock_free(tlb, PAGE_ALIGN(bytes));
> +
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			panic("%s: Failed to remap %zu bytes\n",
> +			      __func__, bytes);
> +		goto retry;
> +	}
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> @@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	pr_warn("Cannot allocate buffer");
>  }
>  
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +{
> +	return swiotlb_init_remap(addressing_limit, flags, NULL);
> +}
> +
>  /*
>   * Systems with larger DMA zones (those that don't support ISA) can
>   * initialize the swiotlb later using the slab allocator if needed.
>   * This should be just like above, but with some error catching.
>   */
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask)
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
>  	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
>  	unsigned long bytes;
> @@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  	if (swiotlb_force_disable)
>  		return 0;
>  
> +retry:
>  	order = get_order(nslabs << IO_TLB_SHIFT);
>  	nslabs = SLABS_PER_PAGE << order;
>  	bytes = nslabs << IO_TLB_SHIFT;
> @@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  			(PAGE_SIZE << order) >> 20);
>  		nslabs = SLABS_PER_PAGE << order;
>  	}
> +	if (remap)
> +		rc = remap(vstart, nslabs);
> +	if (rc) {
> +		free_pages((unsigned long)vstart, order);
> + 
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			return rc;
> +		goto retry;
> +	}
>  	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
>  	if (rc)
>  		free_pages((unsigned long)vstart, order);
> -- 
> 2.30.2
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  6:19     ` Alan Robinson
  0 siblings, 0 replies; 197+ messages in thread
From: Alan Robinson @ 2022-04-04  6:19 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Joerg Roedel,
	Konrad Rzeszutek Wilk, tboot-devel, xen-devel, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, linuxppc-dev, linux-mips, iommu,
	Robin Murphy, Lu Baolu

Hi Christoph,

On Mon, Apr 04, 2022 at 05:05:56AM +0000, Christoph Hellwig wrote:
> From: Christoph Hellwig <hch@lst.de>
> Subject: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap
>  the buffer
> 
> To shared more code between swiotlb and xen-swiotlb, offer a
> swiotlb_init_remap interface and add a remap callback to
> swiotlb_init_late that will allow Xen to remap the buffer the

s/the buffer//

> buffer without duplicating much of the logic.

Alan

> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/x86/pci/sta2x11-fixup.c |  2 +-
>  include/linux/swiotlb.h      |  5 ++++-
>  kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
>  3 files changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
> index c7e6faf59a861..7368afc039987 100644
> --- a/arch/x86/pci/sta2x11-fixup.c
> +++ b/arch/x86/pci/sta2x11-fixup.c
> @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
>  		int size = STA2X11_SWIOTLB_SIZE;
>  		/* First instance: register your own swiotlb area */
>  		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
> -		if (swiotlb_init_late(size, GFP_DMA))
> +		if (swiotlb_init_late(size, GFP_DMA, NULL))
>  			dev_emerg(&pdev->dev, "init swiotlb failed\n");
>  	}
>  	list_add(&instance->list, &sta2x11_instance_list);
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index ee655f2e4d28b..7b50c82f84ce9 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -36,8 +36,11 @@ struct scatterlist;
>  
>  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +	int (*remap)(void *tlb, unsigned long nslabs));
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +	int (*remap)(void *tlb, unsigned long nslabs));
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask);
>  extern void __init swiotlb_update_mem_attributes(void);
>  
>  phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 119187afc65ec..d5fe8f5e08300 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
> -	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
> +	unsigned long nslabs = default_nslabs;
> +	size_t bytes;
>  	void *tlb;
>  
>  	if (!addressing_limit && !swiotlb_force_bounce)
> @@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	 * allow to pick a location everywhere for hypervisors with guest
>  	 * memory encryption.
>  	 */
> +retry:
> +	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	if (flags & SWIOTLB_ANY)
>  		tlb = memblock_alloc(bytes, PAGE_SIZE);
>  	else
>  		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> +	if (remap && remap(tlb, nslabs) < 0) {
> +		memblock_free(tlb, PAGE_ALIGN(bytes));
> +
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			panic("%s: Failed to remap %zu bytes\n",
> +			      __func__, bytes);
> +		goto retry;
> +	}
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> @@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	pr_warn("Cannot allocate buffer");
>  }
>  
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +{
> +	return swiotlb_init_remap(addressing_limit, flags, NULL);
> +}
> +
>  /*
>   * Systems with larger DMA zones (those that don't support ISA) can
>   * initialize the swiotlb later using the slab allocator if needed.
>   * This should be just like above, but with some error catching.
>   */
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask)
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
>  	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
>  	unsigned long bytes;
> @@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  	if (swiotlb_force_disable)
>  		return 0;
>  
> +retry:
>  	order = get_order(nslabs << IO_TLB_SHIFT);
>  	nslabs = SLABS_PER_PAGE << order;
>  	bytes = nslabs << IO_TLB_SHIFT;
> @@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  			(PAGE_SIZE << order) >> 20);
>  		nslabs = SLABS_PER_PAGE << order;
>  	}
> +	if (remap)
> +		rc = remap(vstart, nslabs);
> +	if (rc) {
> +		free_pages((unsigned long)vstart, order);
> + 
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			return rc;
> +		goto retry;
> +	}
>  	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
>  	if (rc)
>  		free_pages((unsigned long)vstart, order);
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  6:19     ` Alan Robinson
  0 siblings, 0 replies; 197+ messages in thread
From: Alan Robinson @ 2022-04-04  6:19 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Konrad Rzeszutek Wilk,
	tboot-devel, xen-devel, David Woodhouse, Tom Lendacky,
	Anshuman Khandual, Boris Ostrovsky, linux-arm-kernel,
	Juergen Gross, linuxppc-dev, linux-mips, iommu, Robin Murphy

Hi Christoph,

On Mon, Apr 04, 2022 at 05:05:56AM +0000, Christoph Hellwig wrote:
> From: Christoph Hellwig <hch@lst.de>
> Subject: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap
>  the buffer
> 
> To shared more code between swiotlb and xen-swiotlb, offer a
> swiotlb_init_remap interface and add a remap callback to
> swiotlb_init_late that will allow Xen to remap the buffer the

s/the buffer//

> buffer without duplicating much of the logic.

Alan

> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/x86/pci/sta2x11-fixup.c |  2 +-
>  include/linux/swiotlb.h      |  5 ++++-
>  kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
>  3 files changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
> index c7e6faf59a861..7368afc039987 100644
> --- a/arch/x86/pci/sta2x11-fixup.c
> +++ b/arch/x86/pci/sta2x11-fixup.c
> @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
>  		int size = STA2X11_SWIOTLB_SIZE;
>  		/* First instance: register your own swiotlb area */
>  		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
> -		if (swiotlb_init_late(size, GFP_DMA))
> +		if (swiotlb_init_late(size, GFP_DMA, NULL))
>  			dev_emerg(&pdev->dev, "init swiotlb failed\n");
>  	}
>  	list_add(&instance->list, &sta2x11_instance_list);
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index ee655f2e4d28b..7b50c82f84ce9 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -36,8 +36,11 @@ struct scatterlist;
>  
>  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +	int (*remap)(void *tlb, unsigned long nslabs));
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +	int (*remap)(void *tlb, unsigned long nslabs));
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask);
>  extern void __init swiotlb_update_mem_attributes(void);
>  
>  phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 119187afc65ec..d5fe8f5e08300 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
> -	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
> +	unsigned long nslabs = default_nslabs;
> +	size_t bytes;
>  	void *tlb;
>  
>  	if (!addressing_limit && !swiotlb_force_bounce)
> @@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	 * allow to pick a location everywhere for hypervisors with guest
>  	 * memory encryption.
>  	 */
> +retry:
> +	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	if (flags & SWIOTLB_ANY)
>  		tlb = memblock_alloc(bytes, PAGE_SIZE);
>  	else
>  		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> +	if (remap && remap(tlb, nslabs) < 0) {
> +		memblock_free(tlb, PAGE_ALIGN(bytes));
> +
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			panic("%s: Failed to remap %zu bytes\n",
> +			      __func__, bytes);
> +		goto retry;
> +	}
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> @@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	pr_warn("Cannot allocate buffer");
>  }
>  
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +{
> +	return swiotlb_init_remap(addressing_limit, flags, NULL);
> +}
> +
>  /*
>   * Systems with larger DMA zones (those that don't support ISA) can
>   * initialize the swiotlb later using the slab allocator if needed.
>   * This should be just like above, but with some error catching.
>   */
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask)
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
>  	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
>  	unsigned long bytes;
> @@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  	if (swiotlb_force_disable)
>  		return 0;
>  
> +retry:
>  	order = get_order(nslabs << IO_TLB_SHIFT);
>  	nslabs = SLABS_PER_PAGE << order;
>  	bytes = nslabs << IO_TLB_SHIFT;
> @@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  			(PAGE_SIZE << order) >> 20);
>  		nslabs = SLABS_PER_PAGE << order;
>  	}
> +	if (remap)
> +		rc = remap(vstart, nslabs);
> +	if (rc) {
> +		free_pages((unsigned long)vstart, order);
> + 
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			return rc;
> +		goto retry;
> +	}
>  	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
>  	if (rc)
>  		free_pages((unsigned long)vstart, order);
> -- 
> 2.30.2
> 
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  6:19     ` Alan Robinson
  0 siblings, 0 replies; 197+ messages in thread
From: Alan Robinson @ 2022-04-04  6:19 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

Hi Christoph,

On Mon, Apr 04, 2022 at 05:05:56AM +0000, Christoph Hellwig wrote:
> From: Christoph Hellwig <hch@lst.de>
> Subject: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap
>  the buffer
> 
> To shared more code between swiotlb and xen-swiotlb, offer a
> swiotlb_init_remap interface and add a remap callback to
> swiotlb_init_late that will allow Xen to remap the buffer the

s/the buffer//

> buffer without duplicating much of the logic.

Alan

> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/x86/pci/sta2x11-fixup.c |  2 +-
>  include/linux/swiotlb.h      |  5 ++++-
>  kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
>  3 files changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
> index c7e6faf59a861..7368afc039987 100644
> --- a/arch/x86/pci/sta2x11-fixup.c
> +++ b/arch/x86/pci/sta2x11-fixup.c
> @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
>  		int size = STA2X11_SWIOTLB_SIZE;
>  		/* First instance: register your own swiotlb area */
>  		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
> -		if (swiotlb_init_late(size, GFP_DMA))
> +		if (swiotlb_init_late(size, GFP_DMA, NULL))
>  			dev_emerg(&pdev->dev, "init swiotlb failed\n");
>  	}
>  	list_add(&instance->list, &sta2x11_instance_list);
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index ee655f2e4d28b..7b50c82f84ce9 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -36,8 +36,11 @@ struct scatterlist;
>  
>  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +	int (*remap)(void *tlb, unsigned long nslabs));
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +	int (*remap)(void *tlb, unsigned long nslabs));
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask);
>  extern void __init swiotlb_update_mem_attributes(void);
>  
>  phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 119187afc65ec..d5fe8f5e08300 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
> -	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
> +	unsigned long nslabs = default_nslabs;
> +	size_t bytes;
>  	void *tlb;
>  
>  	if (!addressing_limit && !swiotlb_force_bounce)
> @@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	 * allow to pick a location everywhere for hypervisors with guest
>  	 * memory encryption.
>  	 */
> +retry:
> +	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	if (flags & SWIOTLB_ANY)
>  		tlb = memblock_alloc(bytes, PAGE_SIZE);
>  	else
>  		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> +	if (remap && remap(tlb, nslabs) < 0) {
> +		memblock_free(tlb, PAGE_ALIGN(bytes));
> +
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			panic("%s: Failed to remap %zu bytes\n",
> +			      __func__, bytes);
> +		goto retry;
> +	}
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> @@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	pr_warn("Cannot allocate buffer");
>  }
>  
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +{
> +	return swiotlb_init_remap(addressing_limit, flags, NULL);
> +}
> +
>  /*
>   * Systems with larger DMA zones (those that don't support ISA) can
>   * initialize the swiotlb later using the slab allocator if needed.
>   * This should be just like above, but with some error catching.
>   */
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask)
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
>  	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
>  	unsigned long bytes;
> @@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  	if (swiotlb_force_disable)
>  		return 0;
>  
> +retry:
>  	order = get_order(nslabs << IO_TLB_SHIFT);
>  	nslabs = SLABS_PER_PAGE << order;
>  	bytes = nslabs << IO_TLB_SHIFT;
> @@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  			(PAGE_SIZE << order) >> 20);
>  		nslabs = SLABS_PER_PAGE << order;
>  	}
> +	if (remap)
> +		rc = remap(vstart, nslabs);
> +	if (rc) {
> +		free_pages((unsigned long)vstart, order);
> + 
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			return rc;
> +		goto retry;
> +	}
>  	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
>  	if (rc)
>  		free_pages((unsigned long)vstart, order);
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
  2022-04-04  5:05   ` Christoph Hellwig
                       ` (3 preceding siblings ...)
  (?)
@ 2022-04-04  7:09     ` Dongli Zhang
  -1 siblings, 0 replies; 197+ messages in thread
From: Dongli Zhang @ 2022-04-04  7:09 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel



On 4/3/22 10:05 PM, Christoph Hellwig wrote:
> To shared more code between swiotlb and xen-swiotlb, offer a
> swiotlb_init_remap interface and add a remap callback to
> swiotlb_init_late that will allow Xen to remap the buffer the
> buffer without duplicating much of the logic.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/x86/pci/sta2x11-fixup.c |  2 +-
>  include/linux/swiotlb.h      |  5 ++++-
>  kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
>  3 files changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
> index c7e6faf59a861..7368afc039987 100644
> --- a/arch/x86/pci/sta2x11-fixup.c
> +++ b/arch/x86/pci/sta2x11-fixup.c
> @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
>  		int size = STA2X11_SWIOTLB_SIZE;
>  		/* First instance: register your own swiotlb area */
>  		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
> -		if (swiotlb_init_late(size, GFP_DMA))
> +		if (swiotlb_init_late(size, GFP_DMA, NULL))
>  			dev_emerg(&pdev->dev, "init swiotlb failed\n");
>  	}
>  	list_add(&instance->list, &sta2x11_instance_list);
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index ee655f2e4d28b..7b50c82f84ce9 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -36,8 +36,11 @@ struct scatterlist;
>  
>  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +	int (*remap)(void *tlb, unsigned long nslabs));
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +	int (*remap)(void *tlb, unsigned long nslabs));
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask);
>  extern void __init swiotlb_update_mem_attributes(void);
>  
>  phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 119187afc65ec..d5fe8f5e08300 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
> -	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
> +	unsigned long nslabs = default_nslabs;
> +	size_t bytes;
>  	void *tlb;
>  
>  	if (!addressing_limit && !swiotlb_force_bounce)
> @@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	 * allow to pick a location everywhere for hypervisors with guest
>  	 * memory encryption.
>  	 */
> +retry:
> +	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	if (flags & SWIOTLB_ANY)
>  		tlb = memblock_alloc(bytes, PAGE_SIZE);
>  	else
>  		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> +	if (remap && remap(tlb, nslabs) < 0) {
> +		memblock_free(tlb, PAGE_ALIGN(bytes));
> +
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			panic("%s: Failed to remap %zu bytes\n",
> +			      __func__, bytes);
> +		goto retry;
> +	}
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> @@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	pr_warn("Cannot allocate buffer");
>  }
>  
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +{
> +	return swiotlb_init_remap(addressing_limit, flags, NULL);
> +}
> +
>  /*
>   * Systems with larger DMA zones (those that don't support ISA) can
>   * initialize the swiotlb later using the slab allocator if needed.
>   * This should be just like above, but with some error catching.
>   */
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask)
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
>  	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
>  	unsigned long bytes;
> @@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  	if (swiotlb_force_disable)
>  		return 0;
>  
> +retry:
>  	order = get_order(nslabs << IO_TLB_SHIFT);
>  	nslabs = SLABS_PER_PAGE << order;
>  	bytes = nslabs << IO_TLB_SHIFT;
> @@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  			(PAGE_SIZE << order) >> 20);
>  		nslabs = SLABS_PER_PAGE << order;
>  	}
> +	if (remap)
> +		rc = remap(vstart, nslabs);
> +	if (rc) {
> +		free_pages((unsigned long)vstart, order);
> + 

"warning: 1 line adds whitespace errors." above when I was applying the patch
for test.

Dongli Zhang

> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			return rc;
> +		goto retry;
> +	}
>  	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
>  	if (rc)
>  		free_pages((unsigned long)vstart, order);
> 
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  7:09     ` Dongli Zhang
  0 siblings, 0 replies; 197+ messages in thread
From: Dongli Zhang @ 2022-04-04  7:09 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci



On 4/3/22 10:05 PM, Christoph Hellwig wrote:
> To shared more code between swiotlb and xen-swiotlb, offer a
> swiotlb_init_remap interface and add a remap callback to
> swiotlb_init_late that will allow Xen to remap the buffer the
> buffer without duplicating much of the logic.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/x86/pci/sta2x11-fixup.c |  2 +-
>  include/linux/swiotlb.h      |  5 ++++-
>  kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
>  3 files changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
> index c7e6faf59a861..7368afc039987 100644
> --- a/arch/x86/pci/sta2x11-fixup.c
> +++ b/arch/x86/pci/sta2x11-fixup.c
> @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
>  		int size = STA2X11_SWIOTLB_SIZE;
>  		/* First instance: register your own swiotlb area */
>  		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
> -		if (swiotlb_init_late(size, GFP_DMA))
> +		if (swiotlb_init_late(size, GFP_DMA, NULL))
>  			dev_emerg(&pdev->dev, "init swiotlb failed\n");
>  	}
>  	list_add(&instance->list, &sta2x11_instance_list);
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index ee655f2e4d28b..7b50c82f84ce9 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -36,8 +36,11 @@ struct scatterlist;
>  
>  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +	int (*remap)(void *tlb, unsigned long nslabs));
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +	int (*remap)(void *tlb, unsigned long nslabs));
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask);
>  extern void __init swiotlb_update_mem_attributes(void);
>  
>  phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 119187afc65ec..d5fe8f5e08300 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
> -	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
> +	unsigned long nslabs = default_nslabs;
> +	size_t bytes;
>  	void *tlb;
>  
>  	if (!addressing_limit && !swiotlb_force_bounce)
> @@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	 * allow to pick a location everywhere for hypervisors with guest
>  	 * memory encryption.
>  	 */
> +retry:
> +	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	if (flags & SWIOTLB_ANY)
>  		tlb = memblock_alloc(bytes, PAGE_SIZE);
>  	else
>  		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> +	if (remap && remap(tlb, nslabs) < 0) {
> +		memblock_free(tlb, PAGE_ALIGN(bytes));
> +
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			panic("%s: Failed to remap %zu bytes\n",
> +			      __func__, bytes);
> +		goto retry;
> +	}
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> @@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	pr_warn("Cannot allocate buffer");
>  }
>  
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +{
> +	return swiotlb_init_remap(addressing_limit, flags, NULL);
> +}
> +
>  /*
>   * Systems with larger DMA zones (those that don't support ISA) can
>   * initialize the swiotlb later using the slab allocator if needed.
>   * This should be just like above, but with some error catching.
>   */
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask)
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
>  	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
>  	unsigned long bytes;
> @@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  	if (swiotlb_force_disable)
>  		return 0;
>  
> +retry:
>  	order = get_order(nslabs << IO_TLB_SHIFT);
>  	nslabs = SLABS_PER_PAGE << order;
>  	bytes = nslabs << IO_TLB_SHIFT;
> @@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  			(PAGE_SIZE << order) >> 20);
>  		nslabs = SLABS_PER_PAGE << order;
>  	}
> +	if (remap)
> +		rc = remap(vstart, nslabs);
> +	if (rc) {
> +		free_pages((unsigned long)vstart, order);
> + 

"warning: 1 line adds whitespace errors." above when I was applying the patch
for test.

Dongli Zhang

> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			return rc;
> +		goto retry;
> +	}
>  	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
>  	if (rc)
>  		free_pages((unsigned long)vstart, order);
> 

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  7:09     ` Dongli Zhang
  0 siblings, 0 replies; 197+ messages in thread
From: Dongli Zhang @ 2022-04-04  7:09 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci



On 4/3/22 10:05 PM, Christoph Hellwig wrote:
> To shared more code between swiotlb and xen-swiotlb, offer a
> swiotlb_init_remap interface and add a remap callback to
> swiotlb_init_late that will allow Xen to remap the buffer the
> buffer without duplicating much of the logic.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/x86/pci/sta2x11-fixup.c |  2 +-
>  include/linux/swiotlb.h      |  5 ++++-
>  kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
>  3 files changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
> index c7e6faf59a861..7368afc039987 100644
> --- a/arch/x86/pci/sta2x11-fixup.c
> +++ b/arch/x86/pci/sta2x11-fixup.c
> @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
>  		int size = STA2X11_SWIOTLB_SIZE;
>  		/* First instance: register your own swiotlb area */
>  		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
> -		if (swiotlb_init_late(size, GFP_DMA))
> +		if (swiotlb_init_late(size, GFP_DMA, NULL))
>  			dev_emerg(&pdev->dev, "init swiotlb failed\n");
>  	}
>  	list_add(&instance->list, &sta2x11_instance_list);
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index ee655f2e4d28b..7b50c82f84ce9 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -36,8 +36,11 @@ struct scatterlist;
>  
>  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +	int (*remap)(void *tlb, unsigned long nslabs));
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +	int (*remap)(void *tlb, unsigned long nslabs));
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask);
>  extern void __init swiotlb_update_mem_attributes(void);
>  
>  phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 119187afc65ec..d5fe8f5e08300 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
> -	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
> +	unsigned long nslabs = default_nslabs;
> +	size_t bytes;
>  	void *tlb;
>  
>  	if (!addressing_limit && !swiotlb_force_bounce)
> @@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	 * allow to pick a location everywhere for hypervisors with guest
>  	 * memory encryption.
>  	 */
> +retry:
> +	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	if (flags & SWIOTLB_ANY)
>  		tlb = memblock_alloc(bytes, PAGE_SIZE);
>  	else
>  		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> +	if (remap && remap(tlb, nslabs) < 0) {
> +		memblock_free(tlb, PAGE_ALIGN(bytes));
> +
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			panic("%s: Failed to remap %zu bytes\n",
> +			      __func__, bytes);
> +		goto retry;
> +	}
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> @@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	pr_warn("Cannot allocate buffer");
>  }
>  
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +{
> +	return swiotlb_init_remap(addressing_limit, flags, NULL);
> +}
> +
>  /*
>   * Systems with larger DMA zones (those that don't support ISA) can
>   * initialize the swiotlb later using the slab allocator if needed.
>   * This should be just like above, but with some error catching.
>   */
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask)
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
>  	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
>  	unsigned long bytes;
> @@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  	if (swiotlb_force_disable)
>  		return 0;
>  
> +retry:
>  	order = get_order(nslabs << IO_TLB_SHIFT);
>  	nslabs = SLABS_PER_PAGE << order;
>  	bytes = nslabs << IO_TLB_SHIFT;
> @@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  			(PAGE_SIZE << order) >> 20);
>  		nslabs = SLABS_PER_PAGE << order;
>  	}
> +	if (remap)
> +		rc = remap(vstart, nslabs);
> +	if (rc) {
> +		free_pages((unsigned long)vstart, order);
> + 

"warning: 1 line adds whitespace errors." above when I was applying the patch
for test.

Dongli Zhang

> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			return rc;
> +		goto retry;
> +	}
>  	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
>  	if (rc)
>  		free_pages((unsigned long)vstart, order);
> 

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  7:09     ` Dongli Zhang
  0 siblings, 0 replies; 197+ messages in thread
From: Dongli Zhang @ 2022-04-04  7:09 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu



On 4/3/22 10:05 PM, Christoph Hellwig wrote:
> To shared more code between swiotlb and xen-swiotlb, offer a
> swiotlb_init_remap interface and add a remap callback to
> swiotlb_init_late that will allow Xen to remap the buffer the
> buffer without duplicating much of the logic.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/x86/pci/sta2x11-fixup.c |  2 +-
>  include/linux/swiotlb.h      |  5 ++++-
>  kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
>  3 files changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
> index c7e6faf59a861..7368afc039987 100644
> --- a/arch/x86/pci/sta2x11-fixup.c
> +++ b/arch/x86/pci/sta2x11-fixup.c
> @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
>  		int size = STA2X11_SWIOTLB_SIZE;
>  		/* First instance: register your own swiotlb area */
>  		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
> -		if (swiotlb_init_late(size, GFP_DMA))
> +		if (swiotlb_init_late(size, GFP_DMA, NULL))
>  			dev_emerg(&pdev->dev, "init swiotlb failed\n");
>  	}
>  	list_add(&instance->list, &sta2x11_instance_list);
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index ee655f2e4d28b..7b50c82f84ce9 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -36,8 +36,11 @@ struct scatterlist;
>  
>  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +	int (*remap)(void *tlb, unsigned long nslabs));
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +	int (*remap)(void *tlb, unsigned long nslabs));
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask);
>  extern void __init swiotlb_update_mem_attributes(void);
>  
>  phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 119187afc65ec..d5fe8f5e08300 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
> -	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
> +	unsigned long nslabs = default_nslabs;
> +	size_t bytes;
>  	void *tlb;
>  
>  	if (!addressing_limit && !swiotlb_force_bounce)
> @@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	 * allow to pick a location everywhere for hypervisors with guest
>  	 * memory encryption.
>  	 */
> +retry:
> +	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	if (flags & SWIOTLB_ANY)
>  		tlb = memblock_alloc(bytes, PAGE_SIZE);
>  	else
>  		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> +	if (remap && remap(tlb, nslabs) < 0) {
> +		memblock_free(tlb, PAGE_ALIGN(bytes));
> +
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			panic("%s: Failed to remap %zu bytes\n",
> +			      __func__, bytes);
> +		goto retry;
> +	}
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> @@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	pr_warn("Cannot allocate buffer");
>  }
>  
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +{
> +	return swiotlb_init_remap(addressing_limit, flags, NULL);
> +}
> +
>  /*
>   * Systems with larger DMA zones (those that don't support ISA) can
>   * initialize the swiotlb later using the slab allocator if needed.
>   * This should be just like above, but with some error catching.
>   */
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask)
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
>  	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
>  	unsigned long bytes;
> @@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  	if (swiotlb_force_disable)
>  		return 0;
>  
> +retry:
>  	order = get_order(nslabs << IO_TLB_SHIFT);
>  	nslabs = SLABS_PER_PAGE << order;
>  	bytes = nslabs << IO_TLB_SHIFT;
> @@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  			(PAGE_SIZE << order) >> 20);
>  		nslabs = SLABS_PER_PAGE << order;
>  	}
> +	if (remap)
> +		rc = remap(vstart, nslabs);
> +	if (rc) {
> +		free_pages((unsigned long)vstart, order);
> + 

"warning: 1 line adds whitespace errors." above when I was applying the patch
for test.

Dongli Zhang

> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			return rc;
> +		goto retry;
> +	}
>  	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
>  	if (rc)
>  		free_pages((unsigned long)vstart, order);
> 

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  7:09     ` Dongli Zhang
  0 siblings, 0 replies; 197+ messages in thread
From: Dongli Zhang @ 2022-04-04  7:09 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci



On 4/3/22 10:05 PM, Christoph Hellwig wrote:
> To shared more code between swiotlb and xen-swiotlb, offer a
> swiotlb_init_remap interface and add a remap callback to
> swiotlb_init_late that will allow Xen to remap the buffer the
> buffer without duplicating much of the logic.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/x86/pci/sta2x11-fixup.c |  2 +-
>  include/linux/swiotlb.h      |  5 ++++-
>  kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
>  3 files changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
> index c7e6faf59a861..7368afc039987 100644
> --- a/arch/x86/pci/sta2x11-fixup.c
> +++ b/arch/x86/pci/sta2x11-fixup.c
> @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
>  		int size = STA2X11_SWIOTLB_SIZE;
>  		/* First instance: register your own swiotlb area */
>  		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
> -		if (swiotlb_init_late(size, GFP_DMA))
> +		if (swiotlb_init_late(size, GFP_DMA, NULL))
>  			dev_emerg(&pdev->dev, "init swiotlb failed\n");
>  	}
>  	list_add(&instance->list, &sta2x11_instance_list);
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index ee655f2e4d28b..7b50c82f84ce9 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -36,8 +36,11 @@ struct scatterlist;
>  
>  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +	int (*remap)(void *tlb, unsigned long nslabs));
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +	int (*remap)(void *tlb, unsigned long nslabs));
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask);
>  extern void __init swiotlb_update_mem_attributes(void);
>  
>  phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 119187afc65ec..d5fe8f5e08300 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
> -	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
> +	unsigned long nslabs = default_nslabs;
> +	size_t bytes;
>  	void *tlb;
>  
>  	if (!addressing_limit && !swiotlb_force_bounce)
> @@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	 * allow to pick a location everywhere for hypervisors with guest
>  	 * memory encryption.
>  	 */
> +retry:
> +	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	if (flags & SWIOTLB_ANY)
>  		tlb = memblock_alloc(bytes, PAGE_SIZE);
>  	else
>  		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> +	if (remap && remap(tlb, nslabs) < 0) {
> +		memblock_free(tlb, PAGE_ALIGN(bytes));
> +
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			panic("%s: Failed to remap %zu bytes\n",
> +			      __func__, bytes);
> +		goto retry;
> +	}
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> @@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	pr_warn("Cannot allocate buffer");
>  }
>  
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +{
> +	return swiotlb_init_remap(addressing_limit, flags, NULL);
> +}
> +
>  /*
>   * Systems with larger DMA zones (those that don't support ISA) can
>   * initialize the swiotlb later using the slab allocator if needed.
>   * This should be just like above, but with some error catching.
>   */
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask)
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
>  	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
>  	unsigned long bytes;
> @@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  	if (swiotlb_force_disable)
>  		return 0;
>  
> +retry:
>  	order = get_order(nslabs << IO_TLB_SHIFT);
>  	nslabs = SLABS_PER_PAGE << order;
>  	bytes = nslabs << IO_TLB_SHIFT;
> @@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  			(PAGE_SIZE << order) >> 20);
>  		nslabs = SLABS_PER_PAGE << order;
>  	}
> +	if (remap)
> +		rc = remap(vstart, nslabs);
> +	if (rc) {
> +		free_pages((unsigned long)vstart, order);
> + 

"warning: 1 line adds whitespace errors." above when I was applying the patch
for test.

Dongli Zhang

> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			return rc;
> +		goto retry;
> +	}
>  	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
>  	if (rc)
>  		free_pages((unsigned long)vstart, order);
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer
@ 2022-04-04  7:09     ` Dongli Zhang
  0 siblings, 0 replies; 197+ messages in thread
From: Dongli Zhang @ 2022-04-04  7:09 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel



On 4/3/22 10:05 PM, Christoph Hellwig wrote:
> To shared more code between swiotlb and xen-swiotlb, offer a
> swiotlb_init_remap interface and add a remap callback to
> swiotlb_init_late that will allow Xen to remap the buffer the
> buffer without duplicating much of the logic.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/x86/pci/sta2x11-fixup.c |  2 +-
>  include/linux/swiotlb.h      |  5 ++++-
>  kernel/dma/swiotlb.c         | 36 +++++++++++++++++++++++++++++++++---
>  3 files changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c
> index c7e6faf59a861..7368afc039987 100644
> --- a/arch/x86/pci/sta2x11-fixup.c
> +++ b/arch/x86/pci/sta2x11-fixup.c
> @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev)
>  		int size = STA2X11_SWIOTLB_SIZE;
>  		/* First instance: register your own swiotlb area */
>  		dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size);
> -		if (swiotlb_init_late(size, GFP_DMA))
> +		if (swiotlb_init_late(size, GFP_DMA, NULL))
>  			dev_emerg(&pdev->dev, "init swiotlb failed\n");
>  	}
>  	list_add(&instance->list, &sta2x11_instance_list);
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index ee655f2e4d28b..7b50c82f84ce9 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -36,8 +36,11 @@ struct scatterlist;
>  
>  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +	int (*remap)(void *tlb, unsigned long nslabs));
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +	int (*remap)(void *tlb, unsigned long nslabs));
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask);
>  extern void __init swiotlb_update_mem_attributes(void);
>  
>  phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 119187afc65ec..d5fe8f5e08300 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -256,9 +256,11 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
> -	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
> +	unsigned long nslabs = default_nslabs;
> +	size_t bytes;
>  	void *tlb;
>  
>  	if (!addressing_limit && !swiotlb_force_bounce)
> @@ -271,12 +273,23 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	 * allow to pick a location everywhere for hypervisors with guest
>  	 * memory encryption.
>  	 */
> +retry:
> +	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	if (flags & SWIOTLB_ANY)
>  		tlb = memblock_alloc(bytes, PAGE_SIZE);
>  	else
>  		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> +	if (remap && remap(tlb, nslabs) < 0) {
> +		memblock_free(tlb, PAGE_ALIGN(bytes));
> +
> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			panic("%s: Failed to remap %zu bytes\n",
> +			      __func__, bytes);
> +		goto retry;
> +	}
>  	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> @@ -287,12 +300,18 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  	pr_warn("Cannot allocate buffer");
>  }
>  
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
> +{
> +	return swiotlb_init_remap(addressing_limit, flags, NULL);
> +}
> +
>  /*
>   * Systems with larger DMA zones (those that don't support ISA) can
>   * initialize the swiotlb later using the slab allocator if needed.
>   * This should be just like above, but with some error catching.
>   */
> -int swiotlb_init_late(size_t size, gfp_t gfp_mask)
> +int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> +		int (*remap)(void *tlb, unsigned long nslabs))
>  {
>  	unsigned long nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
>  	unsigned long bytes;
> @@ -303,6 +322,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  	if (swiotlb_force_disable)
>  		return 0;
>  
> +retry:
>  	order = get_order(nslabs << IO_TLB_SHIFT);
>  	nslabs = SLABS_PER_PAGE << order;
>  	bytes = nslabs << IO_TLB_SHIFT;
> @@ -323,6 +343,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
>  			(PAGE_SIZE << order) >> 20);
>  		nslabs = SLABS_PER_PAGE << order;
>  	}
> +	if (remap)
> +		rc = remap(vstart, nslabs);
> +	if (rc) {
> +		free_pages((unsigned long)vstart, order);
> + 

"warning: 1 line adds whitespace errors." above when I was applying the patch
for test.

Dongli Zhang

> +		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> +		if (nslabs < IO_TLB_MIN_SLABS)
> +			return rc;
> +		goto retry;
> +	}
>  	rc = swiotlb_late_init_with_tbl(vstart, nslabs);
>  	if (rc)
>  		free_pages((unsigned long)vstart, order);
> 

^ permalink raw reply	[flat|nested] 197+ messages in thread

* RE: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
  2022-04-04  5:05   ` Christoph Hellwig
                       ` (3 preceding siblings ...)
  (?)
@ 2022-04-04 17:00     ` Michael Kelley (LINUX) via iommu
  -1 siblings, 0 replies; 197+ messages in thread
From: Michael Kelley (LINUX) @ 2022-04-04 17:00 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

From: Christoph Hellwig <hch@lst.de> Sent: Sunday, April 3, 2022 10:06 PM
> 
> Pass a bool to pass if swiotlb needs to be enabled based on the

Wording problems.  I'm not sure what you meant to say.

> addressing needs and replace the verbose argument with a set of
> flags, including one to force enable bounce buffering.
> 
> Note that this patch removes the possibility to force xen-swiotlb
> use using swiotlb=force on the command line on x86 (arm and arm64
> never supported that), but this interface will be restored shortly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/arm/mm/init.c                     |  6 +----
>  arch/arm64/mm/init.c                   |  6 +----
>  arch/ia64/mm/init.c                    |  4 +--
>  arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
>  arch/mips/loongson64/dma.c             |  2 +-
>  arch/mips/sibyte/common/dma.c          |  2 +-
>  arch/powerpc/mm/mem.c                  |  3 ++-
>  arch/powerpc/platforms/pseries/setup.c |  3 ---
>  arch/riscv/mm/init.c                   |  8 +-----
>  arch/s390/mm/init.c                    |  3 +--
>  arch/x86/kernel/pci-dma.c              | 15 ++++++-----
>  drivers/xen/swiotlb-xen.c              |  4 +--
>  include/linux/swiotlb.h                | 15 ++++++-----
>  include/trace/events/swiotlb.h         | 29 ++++++++-------------
>  kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
>  15 files changed, 55 insertions(+), 82 deletions(-)
> 
> diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
> index fe249ea919083..ce64bdb55a16b 100644
> --- a/arch/arm/mm/init.c
> +++ b/arch/arm/mm/init.c
> @@ -271,11 +271,7 @@ static void __init free_highpages(void)
>  void __init mem_init(void)
>  {
>  #ifdef CONFIG_ARM_LPAE
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > arm_dma_pfn_limit)
> -		swiotlb_init(1);
> -	else
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
>  #endif
> 
>  	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 8ac25f19084e8..7b6ea4d6733d6 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -398,11 +398,7 @@ void __init bootmem_init(void)
>   */
>  void __init mem_init(void)
>  {
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
> -		swiotlb_init(1);
> -	else if (!xen_swiotlb_detect())
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit),
> SWIOTLB_VERBOSE);
> 
>  	/* this will put all unused low memory onto the freelists */
>  	memblock_free_all();
> diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
> index 5d165607bf354..3c3e15b22608f 100644
> --- a/arch/ia64/mm/init.c
> +++ b/arch/ia64/mm/init.c
> @@ -437,9 +437,7 @@ mem_init (void)
>  		if (iommu_detected)
>  			break;
>  #endif
> -#ifdef CONFIG_SWIOTLB
> -		swiotlb_init(1);
> -#endif
> +		swiotlb_init(true, SWIOTLB_VERBOSE);
>  	} while (0);
> 
>  #ifdef CONFIG_FLATMEM
> diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-
> octeon.c
> index fb7547e217263..9fbba6a8fa4c5 100644
> --- a/arch/mips/cavium-octeon/dma-octeon.c
> +++ b/arch/mips/cavium-octeon/dma-octeon.c
> @@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
>  #endif
> 
>  	swiotlb_adjust_size(swiotlbsize);
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
> index 364f2f27c8723..8220a1bc0db64 100644
> --- a/arch/mips/loongson64/dma.c
> +++ b/arch/mips/loongson64/dma.c
> @@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t
> daddr)
> 
>  void __init plat_swiotlb_setup(void)
>  {
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
> index eb47a94f3583e..c5c2c782aff68 100644
> --- a/arch/mips/sibyte/common/dma.c
> +++ b/arch/mips/sibyte/common/dma.c
> @@ -10,5 +10,5 @@
> 
>  void __init plat_swiotlb_setup(void)
>  {
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
> index 8e301cd8925b2..e1519e2edc656 100644
> --- a/arch/powerpc/mm/mem.c
> +++ b/arch/powerpc/mm/mem.c
> @@ -17,6 +17,7 @@
>  #include <linux/suspend.h>
>  #include <linux/dma-direct.h>
> 
> +#include <asm/swiotlb.h>
>  #include <asm/machdep.h>
>  #include <asm/rtas.h>
>  #include <asm/kasan.h>
> @@ -251,7 +252,7 @@ void __init mem_init(void)
>  	if (is_secure_guest())
>  		svm_swiotlb_init();
>  	else
> -		swiotlb_init(0);
> +		swiotlb_init(ppc_swiotlb_enable, 0);
>  #endif
> 
>  	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
> diff --git a/arch/powerpc/platforms/pseries/setup.c
> b/arch/powerpc/platforms/pseries/setup.c
> index 069d7b3bb142e..c6e06d91b6602 100644
> --- a/arch/powerpc/platforms/pseries/setup.c
> +++ b/arch/powerpc/platforms/pseries/setup.c
> @@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
>  	}
> 
>  	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
> -
> -	if (swiotlb_force == SWIOTLB_FORCE)
> -		ppc_swiotlb_enable = 1;
>  }
> 
>  static void pseries_panic(char *str)
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 9535bea8688c0..181ffd322eafa 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -120,13 +120,7 @@ void __init mem_init(void)
>  	BUG_ON(!mem_map);
>  #endif /* CONFIG_FLATMEM */
> 
> -#ifdef CONFIG_SWIOTLB
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > PFN_DOWN(dma32_phys_limit))
> -		swiotlb_init(1);
> -	else
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> -#endif
> +	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
>  	memblock_free_all();
> 
>  	print_vm_layout();
> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
> index 86ffd0d51fd59..6fb6bf64326f9 100644
> --- a/arch/s390/mm/init.c
> +++ b/arch/s390/mm/init.c
> @@ -185,8 +185,7 @@ static void pv_init(void)
>  		return;
> 
>  	/* make sure bounce buffers are shared */
> -	swiotlb_force = SWIOTLB_FORCE;
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
>  	swiotlb_update_mem_attributes();
>  }
> 
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index 04140e20ef1a3..a705a199bf8a3 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
> 
>  #ifdef CONFIG_SWIOTLB
>  bool x86_swiotlb_enable;
> +static unsigned int x86_swiotlb_flags;
> 
>  static void __init pci_swiotlb_detect(void)
>  {
> @@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
>  	 * bounce buffers as the hypervisor can't access arbitrary VM memory
>  	 * that is not explicitly shared with it.
>  	 */
> -	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
> -		swiotlb_force = SWIOTLB_FORCE;
> -
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
>  		x86_swiotlb_enable = true;
> +		x86_swiotlb_flags |= SWIOTLB_FORCE;
> +	}
>  }
>  #else
>  static inline void __init pci_swiotlb_detect(void)
>  {
>  }
> +#define x86_swiotlb_flags 0
>  #endif /* CONFIG_SWIOTLB */
> 
>  #ifdef CONFIG_SWIOTLB_XEN
> @@ -75,8 +76,7 @@ static bool xen_swiotlb;
> 
>  static void __init pci_xen_swiotlb_init(void)
>  {
> -	if (!xen_initial_domain() && !x86_swiotlb_enable &&
> -	    swiotlb_force != SWIOTLB_FORCE)
> +	if (!xen_initial_domain() && !x86_swiotlb_enable)
>  		return;
>  	x86_swiotlb_enable = true;
>  	xen_swiotlb = true;
> @@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
>  	gart_iommu_hole_init();
>  	amd_iommu_detect();
>  	detect_intel_iommu();
> -	if (x86_swiotlb_enable)
> -		swiotlb_init(0);
> +	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
>  }
> 
>  /*
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 485cd06ed39e7..c2da3eb4826e8 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
>  		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
>  	}
> 
> -	if (swiotlb_init_with_tbl(start, nslabs, true))
> +	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
>  		panic("Cannot allocate SWIOTLB buffer");
>  }
>  #endif /* CONFIG_X86 */
> @@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev,
> struct page *page,
>  	/*
>  	 * Oh well, have to allocate and map a bounce buffer.
>  	 */
> -	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
> +	trace_swiotlb_bounced(dev, dev_addr, size);
> 
>  	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
>  	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index b48b26bfa0edb..ae0407173e845 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -13,11 +13,8 @@ struct device;
>  struct page;
>  struct scatterlist;
> 
> -enum swiotlb_force {
> -	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc.
> */
> -	SWIOTLB_FORCE,		/* swiotlb=force */
> -	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
> -};
> +#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
> +#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
> 
>  /*
>   * Maximum allowable number of contiguous slabs to map,
> @@ -36,8 +33,7 @@ enum swiotlb_force {
>  /* default to 64MB */
>  #define IO_TLB_DEFAULT_SIZE (64UL<<20)
> 
> -extern void swiotlb_init(int verbose);
> -int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
> +int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
>  int swiotlb_init_late(size_t size);
> @@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device
> *dev)
>  	return mem && mem->force_bounce;
>  }
> 
> +void swiotlb_init(bool addressing_limited, unsigned int flags);
>  void __init swiotlb_exit(void);
>  unsigned int swiotlb_max_segment(void);
>  size_t swiotlb_max_mapping_size(struct device *dev);
>  bool is_swiotlb_active(struct device *dev);
>  void __init swiotlb_adjust_size(unsigned long size);
>  #else
> -#define swiotlb_force SWIOTLB_NO_FORCE
> +static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
> +{
> +}
>  static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
>  {
>  	return false;
> diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
> index 705be43b71ab0..da05c9ebd224a 100644
> --- a/include/trace/events/swiotlb.h
> +++ b/include/trace/events/swiotlb.h
> @@ -8,20 +8,15 @@
>  #include <linux/tracepoint.h>
> 
>  TRACE_EVENT(swiotlb_bounced,
> -
> -	TP_PROTO(struct device *dev,
> -		 dma_addr_t dev_addr,
> -		 size_t size,
> -		 enum swiotlb_force swiotlb_force),
> -
> -	TP_ARGS(dev, dev_addr, size, swiotlb_force),
> +	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
> +	TP_ARGS(dev, dev_addr, size),
> 
>  	TP_STRUCT__entry(
> -		__string(	dev_name,	dev_name(dev)		)
> -		__field(	u64,	dma_mask			)
> -		__field(	dma_addr_t,	dev_addr		)
> -		__field(	size_t,	size				)
> -		__field(	enum swiotlb_force,	swiotlb_force	)
> +		__string(dev_name, dev_name(dev))
> +		__field(u64, dma_mask)
> +		__field(dma_addr_t, dev_addr)
> +		__field(size_t, size)
> +		__field(bool, force)
>  	),
> 
>  	TP_fast_assign(
> @@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
>  		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
>  		__entry->dev_addr = dev_addr;
>  		__entry->size = size;
> -		__entry->swiotlb_force = swiotlb_force;
> +		__entry->force = is_swiotlb_force_bounce(dev);
>  	),
> 
> -	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
> -		"size=%zu %s",
> +	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
>  		__get_str(dev_name),
>  		__entry->dma_mask,
>  		(unsigned long long)__entry->dev_addr,
>  		__entry->size,
> -		__print_symbolic(__entry->swiotlb_force,
> -			{ SWIOTLB_NORMAL,	"NORMAL" },
> -			{ SWIOTLB_FORCE,	"FORCE" },
> -			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
> +		__entry->force ? "FORCE" : "NORMAL")
>  );
> 
>  #endif /*  _TRACE_SWIOTLB_H */
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 9a4fe6e48a074..86e877a96b828 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -62,7 +62,8 @@
> 
>  #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
> 
> -enum swiotlb_force swiotlb_force;
> +static bool swiotlb_force_bounce;
> +static bool swiotlb_force_disable;
> 
>  struct io_tlb_mem io_tlb_default_mem;
> 
> @@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
>  	if (*str == ',')
>  		++str;
>  	if (!strcmp(str, "force"))
> -		swiotlb_force = SWIOTLB_FORCE;
> +		swiotlb_force_bounce = true;
>  	else if (!strcmp(str, "noforce"))
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +		swiotlb_force_disable = true;
> 
>  	return 0;
>  }
> @@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem,
> phys_addr_t start,
>  	mem->index = 0;
>  	mem->late_alloc = late_alloc;
> 
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (swiotlb_force_bounce)
>  		mem->force_bounce = true;
> 
>  	spin_lock_init(&mem->lock);
> @@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem
> *mem, phys_addr_t start,
>  	return;
>  }
> 
> -int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
> +int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
> +		unsigned int flags)
>  {
>  	struct io_tlb_mem *mem = &io_tlb_default_mem;
>  	size_t alloc_size;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/* protect against double initialization */
> @@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
> int verbose)
>  		      __func__, alloc_size, PAGE_SIZE);
> 
>  	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
> +	mem->force_bounce = flags & SWIOTLB_FORCE;
> 
> -	if (verbose)
> +	if (flags & SWIOTLB_VERBOSE)
>  		swiotlb_print_info();
>  	return 0;
>  }
> @@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long
> nslabs, int verbose)
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void  __init
> -swiotlb_init(int verbose)
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  {
>  	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	void *tlb;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (!addressing_limit && !swiotlb_force_bounce)
> +		return;
> +	if (swiotlb_force_disable)
>  		return;
> 
>  	/* Get IO TLB memory from the low pages */
>  	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> -	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
> +	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> 
> @@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
>  	unsigned int order;
>  	int rc = 0;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/*
> @@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
>  	struct io_tlb_mem *mem = &io_tlb_default_mem;
>  	unsigned long bytes = nslabs << IO_TLB_SHIFT;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/* protect against double initialization */
> @@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
>  	unsigned long tbl_vaddr;
>  	size_t tbl_size, slots_size;
> 
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (swiotlb_force_bounce)
>  		return;
> 
>  	if (!mem->nslabs)
> @@ -704,8 +708,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t
> paddr, size_t size,
>  	phys_addr_t swiotlb_addr;
>  	dma_addr_t dma_addr;
> 
> -	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
> -			      swiotlb_force);
> +	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
> 
>  	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
>  			attrs);
> --
> 2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* RE: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-04-04 17:00     ` Michael Kelley (LINUX) via iommu
  0 siblings, 0 replies; 197+ messages in thread
From: Michael Kelley (LINUX) via iommu @ 2022-04-04 17:00 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

From: Christoph Hellwig <hch@lst.de> Sent: Sunday, April 3, 2022 10:06 PM
> 
> Pass a bool to pass if swiotlb needs to be enabled based on the

Wording problems.  I'm not sure what you meant to say.

> addressing needs and replace the verbose argument with a set of
> flags, including one to force enable bounce buffering.
> 
> Note that this patch removes the possibility to force xen-swiotlb
> use using swiotlb=force on the command line on x86 (arm and arm64
> never supported that), but this interface will be restored shortly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/arm/mm/init.c                     |  6 +----
>  arch/arm64/mm/init.c                   |  6 +----
>  arch/ia64/mm/init.c                    |  4 +--
>  arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
>  arch/mips/loongson64/dma.c             |  2 +-
>  arch/mips/sibyte/common/dma.c          |  2 +-
>  arch/powerpc/mm/mem.c                  |  3 ++-
>  arch/powerpc/platforms/pseries/setup.c |  3 ---
>  arch/riscv/mm/init.c                   |  8 +-----
>  arch/s390/mm/init.c                    |  3 +--
>  arch/x86/kernel/pci-dma.c              | 15 ++++++-----
>  drivers/xen/swiotlb-xen.c              |  4 +--
>  include/linux/swiotlb.h                | 15 ++++++-----
>  include/trace/events/swiotlb.h         | 29 ++++++++-------------
>  kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
>  15 files changed, 55 insertions(+), 82 deletions(-)
> 
> diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
> index fe249ea919083..ce64bdb55a16b 100644
> --- a/arch/arm/mm/init.c
> +++ b/arch/arm/mm/init.c
> @@ -271,11 +271,7 @@ static void __init free_highpages(void)
>  void __init mem_init(void)
>  {
>  #ifdef CONFIG_ARM_LPAE
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > arm_dma_pfn_limit)
> -		swiotlb_init(1);
> -	else
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
>  #endif
> 
>  	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 8ac25f19084e8..7b6ea4d6733d6 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -398,11 +398,7 @@ void __init bootmem_init(void)
>   */
>  void __init mem_init(void)
>  {
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
> -		swiotlb_init(1);
> -	else if (!xen_swiotlb_detect())
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit),
> SWIOTLB_VERBOSE);
> 
>  	/* this will put all unused low memory onto the freelists */
>  	memblock_free_all();
> diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
> index 5d165607bf354..3c3e15b22608f 100644
> --- a/arch/ia64/mm/init.c
> +++ b/arch/ia64/mm/init.c
> @@ -437,9 +437,7 @@ mem_init (void)
>  		if (iommu_detected)
>  			break;
>  #endif
> -#ifdef CONFIG_SWIOTLB
> -		swiotlb_init(1);
> -#endif
> +		swiotlb_init(true, SWIOTLB_VERBOSE);
>  	} while (0);
> 
>  #ifdef CONFIG_FLATMEM
> diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-
> octeon.c
> index fb7547e217263..9fbba6a8fa4c5 100644
> --- a/arch/mips/cavium-octeon/dma-octeon.c
> +++ b/arch/mips/cavium-octeon/dma-octeon.c
> @@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
>  #endif
> 
>  	swiotlb_adjust_size(swiotlbsize);
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
> index 364f2f27c8723..8220a1bc0db64 100644
> --- a/arch/mips/loongson64/dma.c
> +++ b/arch/mips/loongson64/dma.c
> @@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t
> daddr)
> 
>  void __init plat_swiotlb_setup(void)
>  {
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
> index eb47a94f3583e..c5c2c782aff68 100644
> --- a/arch/mips/sibyte/common/dma.c
> +++ b/arch/mips/sibyte/common/dma.c
> @@ -10,5 +10,5 @@
> 
>  void __init plat_swiotlb_setup(void)
>  {
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
> index 8e301cd8925b2..e1519e2edc656 100644
> --- a/arch/powerpc/mm/mem.c
> +++ b/arch/powerpc/mm/mem.c
> @@ -17,6 +17,7 @@
>  #include <linux/suspend.h>
>  #include <linux/dma-direct.h>
> 
> +#include <asm/swiotlb.h>
>  #include <asm/machdep.h>
>  #include <asm/rtas.h>
>  #include <asm/kasan.h>
> @@ -251,7 +252,7 @@ void __init mem_init(void)
>  	if (is_secure_guest())
>  		svm_swiotlb_init();
>  	else
> -		swiotlb_init(0);
> +		swiotlb_init(ppc_swiotlb_enable, 0);
>  #endif
> 
>  	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
> diff --git a/arch/powerpc/platforms/pseries/setup.c
> b/arch/powerpc/platforms/pseries/setup.c
> index 069d7b3bb142e..c6e06d91b6602 100644
> --- a/arch/powerpc/platforms/pseries/setup.c
> +++ b/arch/powerpc/platforms/pseries/setup.c
> @@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
>  	}
> 
>  	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
> -
> -	if (swiotlb_force == SWIOTLB_FORCE)
> -		ppc_swiotlb_enable = 1;
>  }
> 
>  static void pseries_panic(char *str)
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 9535bea8688c0..181ffd322eafa 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -120,13 +120,7 @@ void __init mem_init(void)
>  	BUG_ON(!mem_map);
>  #endif /* CONFIG_FLATMEM */
> 
> -#ifdef CONFIG_SWIOTLB
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > PFN_DOWN(dma32_phys_limit))
> -		swiotlb_init(1);
> -	else
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> -#endif
> +	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
>  	memblock_free_all();
> 
>  	print_vm_layout();
> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
> index 86ffd0d51fd59..6fb6bf64326f9 100644
> --- a/arch/s390/mm/init.c
> +++ b/arch/s390/mm/init.c
> @@ -185,8 +185,7 @@ static void pv_init(void)
>  		return;
> 
>  	/* make sure bounce buffers are shared */
> -	swiotlb_force = SWIOTLB_FORCE;
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
>  	swiotlb_update_mem_attributes();
>  }
> 
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index 04140e20ef1a3..a705a199bf8a3 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
> 
>  #ifdef CONFIG_SWIOTLB
>  bool x86_swiotlb_enable;
> +static unsigned int x86_swiotlb_flags;
> 
>  static void __init pci_swiotlb_detect(void)
>  {
> @@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
>  	 * bounce buffers as the hypervisor can't access arbitrary VM memory
>  	 * that is not explicitly shared with it.
>  	 */
> -	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
> -		swiotlb_force = SWIOTLB_FORCE;
> -
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
>  		x86_swiotlb_enable = true;
> +		x86_swiotlb_flags |= SWIOTLB_FORCE;
> +	}
>  }
>  #else
>  static inline void __init pci_swiotlb_detect(void)
>  {
>  }
> +#define x86_swiotlb_flags 0
>  #endif /* CONFIG_SWIOTLB */
> 
>  #ifdef CONFIG_SWIOTLB_XEN
> @@ -75,8 +76,7 @@ static bool xen_swiotlb;
> 
>  static void __init pci_xen_swiotlb_init(void)
>  {
> -	if (!xen_initial_domain() && !x86_swiotlb_enable &&
> -	    swiotlb_force != SWIOTLB_FORCE)
> +	if (!xen_initial_domain() && !x86_swiotlb_enable)
>  		return;
>  	x86_swiotlb_enable = true;
>  	xen_swiotlb = true;
> @@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
>  	gart_iommu_hole_init();
>  	amd_iommu_detect();
>  	detect_intel_iommu();
> -	if (x86_swiotlb_enable)
> -		swiotlb_init(0);
> +	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
>  }
> 
>  /*
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 485cd06ed39e7..c2da3eb4826e8 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
>  		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
>  	}
> 
> -	if (swiotlb_init_with_tbl(start, nslabs, true))
> +	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
>  		panic("Cannot allocate SWIOTLB buffer");
>  }
>  #endif /* CONFIG_X86 */
> @@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev,
> struct page *page,
>  	/*
>  	 * Oh well, have to allocate and map a bounce buffer.
>  	 */
> -	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
> +	trace_swiotlb_bounced(dev, dev_addr, size);
> 
>  	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
>  	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index b48b26bfa0edb..ae0407173e845 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -13,11 +13,8 @@ struct device;
>  struct page;
>  struct scatterlist;
> 
> -enum swiotlb_force {
> -	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc.
> */
> -	SWIOTLB_FORCE,		/* swiotlb=force */
> -	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
> -};
> +#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
> +#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
> 
>  /*
>   * Maximum allowable number of contiguous slabs to map,
> @@ -36,8 +33,7 @@ enum swiotlb_force {
>  /* default to 64MB */
>  #define IO_TLB_DEFAULT_SIZE (64UL<<20)
> 
> -extern void swiotlb_init(int verbose);
> -int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
> +int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
>  int swiotlb_init_late(size_t size);
> @@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device
> *dev)
>  	return mem && mem->force_bounce;
>  }
> 
> +void swiotlb_init(bool addressing_limited, unsigned int flags);
>  void __init swiotlb_exit(void);
>  unsigned int swiotlb_max_segment(void);
>  size_t swiotlb_max_mapping_size(struct device *dev);
>  bool is_swiotlb_active(struct device *dev);
>  void __init swiotlb_adjust_size(unsigned long size);
>  #else
> -#define swiotlb_force SWIOTLB_NO_FORCE
> +static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
> +{
> +}
>  static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
>  {
>  	return false;
> diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
> index 705be43b71ab0..da05c9ebd224a 100644
> --- a/include/trace/events/swiotlb.h
> +++ b/include/trace/events/swiotlb.h
> @@ -8,20 +8,15 @@
>  #include <linux/tracepoint.h>
> 
>  TRACE_EVENT(swiotlb_bounced,
> -
> -	TP_PROTO(struct device *dev,
> -		 dma_addr_t dev_addr,
> -		 size_t size,
> -		 enum swiotlb_force swiotlb_force),
> -
> -	TP_ARGS(dev, dev_addr, size, swiotlb_force),
> +	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
> +	TP_ARGS(dev, dev_addr, size),
> 
>  	TP_STRUCT__entry(
> -		__string(	dev_name,	dev_name(dev)		)
> -		__field(	u64,	dma_mask			)
> -		__field(	dma_addr_t,	dev_addr		)
> -		__field(	size_t,	size				)
> -		__field(	enum swiotlb_force,	swiotlb_force	)
> +		__string(dev_name, dev_name(dev))
> +		__field(u64, dma_mask)
> +		__field(dma_addr_t, dev_addr)
> +		__field(size_t, size)
> +		__field(bool, force)
>  	),
> 
>  	TP_fast_assign(
> @@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
>  		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
>  		__entry->dev_addr = dev_addr;
>  		__entry->size = size;
> -		__entry->swiotlb_force = swiotlb_force;
> +		__entry->force = is_swiotlb_force_bounce(dev);
>  	),
> 
> -	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
> -		"size=%zu %s",
> +	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
>  		__get_str(dev_name),
>  		__entry->dma_mask,
>  		(unsigned long long)__entry->dev_addr,
>  		__entry->size,
> -		__print_symbolic(__entry->swiotlb_force,
> -			{ SWIOTLB_NORMAL,	"NORMAL" },
> -			{ SWIOTLB_FORCE,	"FORCE" },
> -			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
> +		__entry->force ? "FORCE" : "NORMAL")
>  );
> 
>  #endif /*  _TRACE_SWIOTLB_H */
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 9a4fe6e48a074..86e877a96b828 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -62,7 +62,8 @@
> 
>  #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
> 
> -enum swiotlb_force swiotlb_force;
> +static bool swiotlb_force_bounce;
> +static bool swiotlb_force_disable;
> 
>  struct io_tlb_mem io_tlb_default_mem;
> 
> @@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
>  	if (*str == ',')
>  		++str;
>  	if (!strcmp(str, "force"))
> -		swiotlb_force = SWIOTLB_FORCE;
> +		swiotlb_force_bounce = true;
>  	else if (!strcmp(str, "noforce"))
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +		swiotlb_force_disable = true;
> 
>  	return 0;
>  }
> @@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem,
> phys_addr_t start,
>  	mem->index = 0;
>  	mem->late_alloc = late_alloc;
> 
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (swiotlb_force_bounce)
>  		mem->force_bounce = true;
> 
>  	spin_lock_init(&mem->lock);
> @@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem
> *mem, phys_addr_t start,
>  	return;
>  }
> 
> -int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
> +int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
> +		unsigned int flags)
>  {
>  	struct io_tlb_mem *mem = &io_tlb_default_mem;
>  	size_t alloc_size;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/* protect against double initialization */
> @@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
> int verbose)
>  		      __func__, alloc_size, PAGE_SIZE);
> 
>  	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
> +	mem->force_bounce = flags & SWIOTLB_FORCE;
> 
> -	if (verbose)
> +	if (flags & SWIOTLB_VERBOSE)
>  		swiotlb_print_info();
>  	return 0;
>  }
> @@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long
> nslabs, int verbose)
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void  __init
> -swiotlb_init(int verbose)
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  {
>  	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	void *tlb;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (!addressing_limit && !swiotlb_force_bounce)
> +		return;
> +	if (swiotlb_force_disable)
>  		return;
> 
>  	/* Get IO TLB memory from the low pages */
>  	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> -	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
> +	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> 
> @@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
>  	unsigned int order;
>  	int rc = 0;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/*
> @@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
>  	struct io_tlb_mem *mem = &io_tlb_default_mem;
>  	unsigned long bytes = nslabs << IO_TLB_SHIFT;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/* protect against double initialization */
> @@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
>  	unsigned long tbl_vaddr;
>  	size_t tbl_size, slots_size;
> 
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (swiotlb_force_bounce)
>  		return;
> 
>  	if (!mem->nslabs)
> @@ -704,8 +708,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t
> paddr, size_t size,
>  	phys_addr_t swiotlb_addr;
>  	dma_addr_t dma_addr;
> 
> -	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
> -			      swiotlb_force);
> +	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
> 
>  	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
>  			attrs);
> --
> 2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* RE: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-04-04 17:00     ` Michael Kelley (LINUX) via iommu
  0 siblings, 0 replies; 197+ messages in thread
From: Michael Kelley (LINUX) @ 2022-04-04 17:00 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

From: Christoph Hellwig <hch@lst.de> Sent: Sunday, April 3, 2022 10:06 PM
> 
> Pass a bool to pass if swiotlb needs to be enabled based on the

Wording problems.  I'm not sure what you meant to say.

> addressing needs and replace the verbose argument with a set of
> flags, including one to force enable bounce buffering.
> 
> Note that this patch removes the possibility to force xen-swiotlb
> use using swiotlb=force on the command line on x86 (arm and arm64
> never supported that), but this interface will be restored shortly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/arm/mm/init.c                     |  6 +----
>  arch/arm64/mm/init.c                   |  6 +----
>  arch/ia64/mm/init.c                    |  4 +--
>  arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
>  arch/mips/loongson64/dma.c             |  2 +-
>  arch/mips/sibyte/common/dma.c          |  2 +-
>  arch/powerpc/mm/mem.c                  |  3 ++-
>  arch/powerpc/platforms/pseries/setup.c |  3 ---
>  arch/riscv/mm/init.c                   |  8 +-----
>  arch/s390/mm/init.c                    |  3 +--
>  arch/x86/kernel/pci-dma.c              | 15 ++++++-----
>  drivers/xen/swiotlb-xen.c              |  4 +--
>  include/linux/swiotlb.h                | 15 ++++++-----
>  include/trace/events/swiotlb.h         | 29 ++++++++-------------
>  kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
>  15 files changed, 55 insertions(+), 82 deletions(-)
> 
> diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
> index fe249ea919083..ce64bdb55a16b 100644
> --- a/arch/arm/mm/init.c
> +++ b/arch/arm/mm/init.c
> @@ -271,11 +271,7 @@ static void __init free_highpages(void)
>  void __init mem_init(void)
>  {
>  #ifdef CONFIG_ARM_LPAE
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > arm_dma_pfn_limit)
> -		swiotlb_init(1);
> -	else
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
>  #endif
> 
>  	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 8ac25f19084e8..7b6ea4d6733d6 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -398,11 +398,7 @@ void __init bootmem_init(void)
>   */
>  void __init mem_init(void)
>  {
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
> -		swiotlb_init(1);
> -	else if (!xen_swiotlb_detect())
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit),
> SWIOTLB_VERBOSE);
> 
>  	/* this will put all unused low memory onto the freelists */
>  	memblock_free_all();
> diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
> index 5d165607bf354..3c3e15b22608f 100644
> --- a/arch/ia64/mm/init.c
> +++ b/arch/ia64/mm/init.c
> @@ -437,9 +437,7 @@ mem_init (void)
>  		if (iommu_detected)
>  			break;
>  #endif
> -#ifdef CONFIG_SWIOTLB
> -		swiotlb_init(1);
> -#endif
> +		swiotlb_init(true, SWIOTLB_VERBOSE);
>  	} while (0);
> 
>  #ifdef CONFIG_FLATMEM
> diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-
> octeon.c
> index fb7547e217263..9fbba6a8fa4c5 100644
> --- a/arch/mips/cavium-octeon/dma-octeon.c
> +++ b/arch/mips/cavium-octeon/dma-octeon.c
> @@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
>  #endif
> 
>  	swiotlb_adjust_size(swiotlbsize);
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
> index 364f2f27c8723..8220a1bc0db64 100644
> --- a/arch/mips/loongson64/dma.c
> +++ b/arch/mips/loongson64/dma.c
> @@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t
> daddr)
> 
>  void __init plat_swiotlb_setup(void)
>  {
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
> index eb47a94f3583e..c5c2c782aff68 100644
> --- a/arch/mips/sibyte/common/dma.c
> +++ b/arch/mips/sibyte/common/dma.c
> @@ -10,5 +10,5 @@
> 
>  void __init plat_swiotlb_setup(void)
>  {
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
> index 8e301cd8925b2..e1519e2edc656 100644
> --- a/arch/powerpc/mm/mem.c
> +++ b/arch/powerpc/mm/mem.c
> @@ -17,6 +17,7 @@
>  #include <linux/suspend.h>
>  #include <linux/dma-direct.h>
> 
> +#include <asm/swiotlb.h>
>  #include <asm/machdep.h>
>  #include <asm/rtas.h>
>  #include <asm/kasan.h>
> @@ -251,7 +252,7 @@ void __init mem_init(void)
>  	if (is_secure_guest())
>  		svm_swiotlb_init();
>  	else
> -		swiotlb_init(0);
> +		swiotlb_init(ppc_swiotlb_enable, 0);
>  #endif
> 
>  	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
> diff --git a/arch/powerpc/platforms/pseries/setup.c
> b/arch/powerpc/platforms/pseries/setup.c
> index 069d7b3bb142e..c6e06d91b6602 100644
> --- a/arch/powerpc/platforms/pseries/setup.c
> +++ b/arch/powerpc/platforms/pseries/setup.c
> @@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
>  	}
> 
>  	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
> -
> -	if (swiotlb_force == SWIOTLB_FORCE)
> -		ppc_swiotlb_enable = 1;
>  }
> 
>  static void pseries_panic(char *str)
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 9535bea8688c0..181ffd322eafa 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -120,13 +120,7 @@ void __init mem_init(void)
>  	BUG_ON(!mem_map);
>  #endif /* CONFIG_FLATMEM */
> 
> -#ifdef CONFIG_SWIOTLB
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > PFN_DOWN(dma32_phys_limit))
> -		swiotlb_init(1);
> -	else
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> -#endif
> +	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
>  	memblock_free_all();
> 
>  	print_vm_layout();
> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
> index 86ffd0d51fd59..6fb6bf64326f9 100644
> --- a/arch/s390/mm/init.c
> +++ b/arch/s390/mm/init.c
> @@ -185,8 +185,7 @@ static void pv_init(void)
>  		return;
> 
>  	/* make sure bounce buffers are shared */
> -	swiotlb_force = SWIOTLB_FORCE;
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
>  	swiotlb_update_mem_attributes();
>  }
> 
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index 04140e20ef1a3..a705a199bf8a3 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
> 
>  #ifdef CONFIG_SWIOTLB
>  bool x86_swiotlb_enable;
> +static unsigned int x86_swiotlb_flags;
> 
>  static void __init pci_swiotlb_detect(void)
>  {
> @@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
>  	 * bounce buffers as the hypervisor can't access arbitrary VM memory
>  	 * that is not explicitly shared with it.
>  	 */
> -	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
> -		swiotlb_force = SWIOTLB_FORCE;
> -
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
>  		x86_swiotlb_enable = true;
> +		x86_swiotlb_flags |= SWIOTLB_FORCE;
> +	}
>  }
>  #else
>  static inline void __init pci_swiotlb_detect(void)
>  {
>  }
> +#define x86_swiotlb_flags 0
>  #endif /* CONFIG_SWIOTLB */
> 
>  #ifdef CONFIG_SWIOTLB_XEN
> @@ -75,8 +76,7 @@ static bool xen_swiotlb;
> 
>  static void __init pci_xen_swiotlb_init(void)
>  {
> -	if (!xen_initial_domain() && !x86_swiotlb_enable &&
> -	    swiotlb_force != SWIOTLB_FORCE)
> +	if (!xen_initial_domain() && !x86_swiotlb_enable)
>  		return;
>  	x86_swiotlb_enable = true;
>  	xen_swiotlb = true;
> @@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
>  	gart_iommu_hole_init();
>  	amd_iommu_detect();
>  	detect_intel_iommu();
> -	if (x86_swiotlb_enable)
> -		swiotlb_init(0);
> +	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
>  }
> 
>  /*
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 485cd06ed39e7..c2da3eb4826e8 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
>  		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
>  	}
> 
> -	if (swiotlb_init_with_tbl(start, nslabs, true))
> +	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
>  		panic("Cannot allocate SWIOTLB buffer");
>  }
>  #endif /* CONFIG_X86 */
> @@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev,
> struct page *page,
>  	/*
>  	 * Oh well, have to allocate and map a bounce buffer.
>  	 */
> -	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
> +	trace_swiotlb_bounced(dev, dev_addr, size);
> 
>  	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
>  	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index b48b26bfa0edb..ae0407173e845 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -13,11 +13,8 @@ struct device;
>  struct page;
>  struct scatterlist;
> 
> -enum swiotlb_force {
> -	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc.
> */
> -	SWIOTLB_FORCE,		/* swiotlb=force */
> -	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
> -};
> +#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
> +#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
> 
>  /*
>   * Maximum allowable number of contiguous slabs to map,
> @@ -36,8 +33,7 @@ enum swiotlb_force {
>  /* default to 64MB */
>  #define IO_TLB_DEFAULT_SIZE (64UL<<20)
> 
> -extern void swiotlb_init(int verbose);
> -int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
> +int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
>  int swiotlb_init_late(size_t size);
> @@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device
> *dev)
>  	return mem && mem->force_bounce;
>  }
> 
> +void swiotlb_init(bool addressing_limited, unsigned int flags);
>  void __init swiotlb_exit(void);
>  unsigned int swiotlb_max_segment(void);
>  size_t swiotlb_max_mapping_size(struct device *dev);
>  bool is_swiotlb_active(struct device *dev);
>  void __init swiotlb_adjust_size(unsigned long size);
>  #else
> -#define swiotlb_force SWIOTLB_NO_FORCE
> +static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
> +{
> +}
>  static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
>  {
>  	return false;
> diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
> index 705be43b71ab0..da05c9ebd224a 100644
> --- a/include/trace/events/swiotlb.h
> +++ b/include/trace/events/swiotlb.h
> @@ -8,20 +8,15 @@
>  #include <linux/tracepoint.h>
> 
>  TRACE_EVENT(swiotlb_bounced,
> -
> -	TP_PROTO(struct device *dev,
> -		 dma_addr_t dev_addr,
> -		 size_t size,
> -		 enum swiotlb_force swiotlb_force),
> -
> -	TP_ARGS(dev, dev_addr, size, swiotlb_force),
> +	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
> +	TP_ARGS(dev, dev_addr, size),
> 
>  	TP_STRUCT__entry(
> -		__string(	dev_name,	dev_name(dev)		)
> -		__field(	u64,	dma_mask			)
> -		__field(	dma_addr_t,	dev_addr		)
> -		__field(	size_t,	size				)
> -		__field(	enum swiotlb_force,	swiotlb_force	)
> +		__string(dev_name, dev_name(dev))
> +		__field(u64, dma_mask)
> +		__field(dma_addr_t, dev_addr)
> +		__field(size_t, size)
> +		__field(bool, force)
>  	),
> 
>  	TP_fast_assign(
> @@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
>  		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
>  		__entry->dev_addr = dev_addr;
>  		__entry->size = size;
> -		__entry->swiotlb_force = swiotlb_force;
> +		__entry->force = is_swiotlb_force_bounce(dev);
>  	),
> 
> -	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
> -		"size=%zu %s",
> +	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
>  		__get_str(dev_name),
>  		__entry->dma_mask,
>  		(unsigned long long)__entry->dev_addr,
>  		__entry->size,
> -		__print_symbolic(__entry->swiotlb_force,
> -			{ SWIOTLB_NORMAL,	"NORMAL" },
> -			{ SWIOTLB_FORCE,	"FORCE" },
> -			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
> +		__entry->force ? "FORCE" : "NORMAL")
>  );
> 
>  #endif /*  _TRACE_SWIOTLB_H */
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 9a4fe6e48a074..86e877a96b828 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -62,7 +62,8 @@
> 
>  #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
> 
> -enum swiotlb_force swiotlb_force;
> +static bool swiotlb_force_bounce;
> +static bool swiotlb_force_disable;
> 
>  struct io_tlb_mem io_tlb_default_mem;
> 
> @@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
>  	if (*str == ',')
>  		++str;
>  	if (!strcmp(str, "force"))
> -		swiotlb_force = SWIOTLB_FORCE;
> +		swiotlb_force_bounce = true;
>  	else if (!strcmp(str, "noforce"))
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +		swiotlb_force_disable = true;
> 
>  	return 0;
>  }
> @@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem,
> phys_addr_t start,
>  	mem->index = 0;
>  	mem->late_alloc = late_alloc;
> 
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (swiotlb_force_bounce)
>  		mem->force_bounce = true;
> 
>  	spin_lock_init(&mem->lock);
> @@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem
> *mem, phys_addr_t start,
>  	return;
>  }
> 
> -int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
> +int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
> +		unsigned int flags)
>  {
>  	struct io_tlb_mem *mem = &io_tlb_default_mem;
>  	size_t alloc_size;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/* protect against double initialization */
> @@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
> int verbose)
>  		      __func__, alloc_size, PAGE_SIZE);
> 
>  	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
> +	mem->force_bounce = flags & SWIOTLB_FORCE;
> 
> -	if (verbose)
> +	if (flags & SWIOTLB_VERBOSE)
>  		swiotlb_print_info();
>  	return 0;
>  }
> @@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long
> nslabs, int verbose)
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void  __init
> -swiotlb_init(int verbose)
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  {
>  	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	void *tlb;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (!addressing_limit && !swiotlb_force_bounce)
> +		return;
> +	if (swiotlb_force_disable)
>  		return;
> 
>  	/* Get IO TLB memory from the low pages */
>  	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> -	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
> +	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> 
> @@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
>  	unsigned int order;
>  	int rc = 0;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/*
> @@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
>  	struct io_tlb_mem *mem = &io_tlb_default_mem;
>  	unsigned long bytes = nslabs << IO_TLB_SHIFT;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/* protect against double initialization */
> @@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
>  	unsigned long tbl_vaddr;
>  	size_t tbl_size, slots_size;
> 
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (swiotlb_force_bounce)
>  		return;
> 
>  	if (!mem->nslabs)
> @@ -704,8 +708,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t
> paddr, size_t size,
>  	phys_addr_t swiotlb_addr;
>  	dma_addr_t dma_addr;
> 
> -	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
> -			      swiotlb_force);
> +	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
> 
>  	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
>  			attrs);
> --
> 2.30.2


^ permalink raw reply	[flat|nested] 197+ messages in thread

* RE: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-04-04 17:00     ` Michael Kelley (LINUX) via iommu
  0 siblings, 0 replies; 197+ messages in thread
From: Michael Kelley (LINUX) @ 2022-04-04 17:00 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

From: Christoph Hellwig <hch@lst.de> Sent: Sunday, April 3, 2022 10:06 PM
> 
> Pass a bool to pass if swiotlb needs to be enabled based on the

Wording problems.  I'm not sure what you meant to say.

> addressing needs and replace the verbose argument with a set of
> flags, including one to force enable bounce buffering.
> 
> Note that this patch removes the possibility to force xen-swiotlb
> use using swiotlb=force on the command line on x86 (arm and arm64
> never supported that), but this interface will be restored shortly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/arm/mm/init.c                     |  6 +----
>  arch/arm64/mm/init.c                   |  6 +----
>  arch/ia64/mm/init.c                    |  4 +--
>  arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
>  arch/mips/loongson64/dma.c             |  2 +-
>  arch/mips/sibyte/common/dma.c          |  2 +-
>  arch/powerpc/mm/mem.c                  |  3 ++-
>  arch/powerpc/platforms/pseries/setup.c |  3 ---
>  arch/riscv/mm/init.c                   |  8 +-----
>  arch/s390/mm/init.c                    |  3 +--
>  arch/x86/kernel/pci-dma.c              | 15 ++++++-----
>  drivers/xen/swiotlb-xen.c              |  4 +--
>  include/linux/swiotlb.h                | 15 ++++++-----
>  include/trace/events/swiotlb.h         | 29 ++++++++-------------
>  kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
>  15 files changed, 55 insertions(+), 82 deletions(-)
> 
> diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
> index fe249ea919083..ce64bdb55a16b 100644
> --- a/arch/arm/mm/init.c
> +++ b/arch/arm/mm/init.c
> @@ -271,11 +271,7 @@ static void __init free_highpages(void)
>  void __init mem_init(void)
>  {
>  #ifdef CONFIG_ARM_LPAE
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > arm_dma_pfn_limit)
> -		swiotlb_init(1);
> -	else
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
>  #endif
> 
>  	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 8ac25f19084e8..7b6ea4d6733d6 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -398,11 +398,7 @@ void __init bootmem_init(void)
>   */
>  void __init mem_init(void)
>  {
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
> -		swiotlb_init(1);
> -	else if (!xen_swiotlb_detect())
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit),
> SWIOTLB_VERBOSE);
> 
>  	/* this will put all unused low memory onto the freelists */
>  	memblock_free_all();
> diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
> index 5d165607bf354..3c3e15b22608f 100644
> --- a/arch/ia64/mm/init.c
> +++ b/arch/ia64/mm/init.c
> @@ -437,9 +437,7 @@ mem_init (void)
>  		if (iommu_detected)
>  			break;
>  #endif
> -#ifdef CONFIG_SWIOTLB
> -		swiotlb_init(1);
> -#endif
> +		swiotlb_init(true, SWIOTLB_VERBOSE);
>  	} while (0);
> 
>  #ifdef CONFIG_FLATMEM
> diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-
> octeon.c
> index fb7547e217263..9fbba6a8fa4c5 100644
> --- a/arch/mips/cavium-octeon/dma-octeon.c
> +++ b/arch/mips/cavium-octeon/dma-octeon.c
> @@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
>  #endif
> 
>  	swiotlb_adjust_size(swiotlbsize);
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
> index 364f2f27c8723..8220a1bc0db64 100644
> --- a/arch/mips/loongson64/dma.c
> +++ b/arch/mips/loongson64/dma.c
> @@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t
> daddr)
> 
>  void __init plat_swiotlb_setup(void)
>  {
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
> index eb47a94f3583e..c5c2c782aff68 100644
> --- a/arch/mips/sibyte/common/dma.c
> +++ b/arch/mips/sibyte/common/dma.c
> @@ -10,5 +10,5 @@
> 
>  void __init plat_swiotlb_setup(void)
>  {
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
> index 8e301cd8925b2..e1519e2edc656 100644
> --- a/arch/powerpc/mm/mem.c
> +++ b/arch/powerpc/mm/mem.c
> @@ -17,6 +17,7 @@
>  #include <linux/suspend.h>
>  #include <linux/dma-direct.h>
> 
> +#include <asm/swiotlb.h>
>  #include <asm/machdep.h>
>  #include <asm/rtas.h>
>  #include <asm/kasan.h>
> @@ -251,7 +252,7 @@ void __init mem_init(void)
>  	if (is_secure_guest())
>  		svm_swiotlb_init();
>  	else
> -		swiotlb_init(0);
> +		swiotlb_init(ppc_swiotlb_enable, 0);
>  #endif
> 
>  	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
> diff --git a/arch/powerpc/platforms/pseries/setup.c
> b/arch/powerpc/platforms/pseries/setup.c
> index 069d7b3bb142e..c6e06d91b6602 100644
> --- a/arch/powerpc/platforms/pseries/setup.c
> +++ b/arch/powerpc/platforms/pseries/setup.c
> @@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
>  	}
> 
>  	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
> -
> -	if (swiotlb_force == SWIOTLB_FORCE)
> -		ppc_swiotlb_enable = 1;
>  }
> 
>  static void pseries_panic(char *str)
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 9535bea8688c0..181ffd322eafa 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -120,13 +120,7 @@ void __init mem_init(void)
>  	BUG_ON(!mem_map);
>  #endif /* CONFIG_FLATMEM */
> 
> -#ifdef CONFIG_SWIOTLB
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > PFN_DOWN(dma32_phys_limit))
> -		swiotlb_init(1);
> -	else
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> -#endif
> +	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
>  	memblock_free_all();
> 
>  	print_vm_layout();
> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
> index 86ffd0d51fd59..6fb6bf64326f9 100644
> --- a/arch/s390/mm/init.c
> +++ b/arch/s390/mm/init.c
> @@ -185,8 +185,7 @@ static void pv_init(void)
>  		return;
> 
>  	/* make sure bounce buffers are shared */
> -	swiotlb_force = SWIOTLB_FORCE;
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
>  	swiotlb_update_mem_attributes();
>  }
> 
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index 04140e20ef1a3..a705a199bf8a3 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
> 
>  #ifdef CONFIG_SWIOTLB
>  bool x86_swiotlb_enable;
> +static unsigned int x86_swiotlb_flags;
> 
>  static void __init pci_swiotlb_detect(void)
>  {
> @@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
>  	 * bounce buffers as the hypervisor can't access arbitrary VM memory
>  	 * that is not explicitly shared with it.
>  	 */
> -	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
> -		swiotlb_force = SWIOTLB_FORCE;
> -
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
>  		x86_swiotlb_enable = true;
> +		x86_swiotlb_flags |= SWIOTLB_FORCE;
> +	}
>  }
>  #else
>  static inline void __init pci_swiotlb_detect(void)
>  {
>  }
> +#define x86_swiotlb_flags 0
>  #endif /* CONFIG_SWIOTLB */
> 
>  #ifdef CONFIG_SWIOTLB_XEN
> @@ -75,8 +76,7 @@ static bool xen_swiotlb;
> 
>  static void __init pci_xen_swiotlb_init(void)
>  {
> -	if (!xen_initial_domain() && !x86_swiotlb_enable &&
> -	    swiotlb_force != SWIOTLB_FORCE)
> +	if (!xen_initial_domain() && !x86_swiotlb_enable)
>  		return;
>  	x86_swiotlb_enable = true;
>  	xen_swiotlb = true;
> @@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
>  	gart_iommu_hole_init();
>  	amd_iommu_detect();
>  	detect_intel_iommu();
> -	if (x86_swiotlb_enable)
> -		swiotlb_init(0);
> +	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
>  }
> 
>  /*
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 485cd06ed39e7..c2da3eb4826e8 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
>  		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
>  	}
> 
> -	if (swiotlb_init_with_tbl(start, nslabs, true))
> +	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
>  		panic("Cannot allocate SWIOTLB buffer");
>  }
>  #endif /* CONFIG_X86 */
> @@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev,
> struct page *page,
>  	/*
>  	 * Oh well, have to allocate and map a bounce buffer.
>  	 */
> -	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
> +	trace_swiotlb_bounced(dev, dev_addr, size);
> 
>  	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
>  	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index b48b26bfa0edb..ae0407173e845 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -13,11 +13,8 @@ struct device;
>  struct page;
>  struct scatterlist;
> 
> -enum swiotlb_force {
> -	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc.
> */
> -	SWIOTLB_FORCE,		/* swiotlb=force */
> -	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
> -};
> +#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
> +#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
> 
>  /*
>   * Maximum allowable number of contiguous slabs to map,
> @@ -36,8 +33,7 @@ enum swiotlb_force {
>  /* default to 64MB */
>  #define IO_TLB_DEFAULT_SIZE (64UL<<20)
> 
> -extern void swiotlb_init(int verbose);
> -int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
> +int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
>  int swiotlb_init_late(size_t size);
> @@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device
> *dev)
>  	return mem && mem->force_bounce;
>  }
> 
> +void swiotlb_init(bool addressing_limited, unsigned int flags);
>  void __init swiotlb_exit(void);
>  unsigned int swiotlb_max_segment(void);
>  size_t swiotlb_max_mapping_size(struct device *dev);
>  bool is_swiotlb_active(struct device *dev);
>  void __init swiotlb_adjust_size(unsigned long size);
>  #else
> -#define swiotlb_force SWIOTLB_NO_FORCE
> +static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
> +{
> +}
>  static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
>  {
>  	return false;
> diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
> index 705be43b71ab0..da05c9ebd224a 100644
> --- a/include/trace/events/swiotlb.h
> +++ b/include/trace/events/swiotlb.h
> @@ -8,20 +8,15 @@
>  #include <linux/tracepoint.h>
> 
>  TRACE_EVENT(swiotlb_bounced,
> -
> -	TP_PROTO(struct device *dev,
> -		 dma_addr_t dev_addr,
> -		 size_t size,
> -		 enum swiotlb_force swiotlb_force),
> -
> -	TP_ARGS(dev, dev_addr, size, swiotlb_force),
> +	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
> +	TP_ARGS(dev, dev_addr, size),
> 
>  	TP_STRUCT__entry(
> -		__string(	dev_name,	dev_name(dev)		)
> -		__field(	u64,	dma_mask			)
> -		__field(	dma_addr_t,	dev_addr		)
> -		__field(	size_t,	size				)
> -		__field(	enum swiotlb_force,	swiotlb_force	)
> +		__string(dev_name, dev_name(dev))
> +		__field(u64, dma_mask)
> +		__field(dma_addr_t, dev_addr)
> +		__field(size_t, size)
> +		__field(bool, force)
>  	),
> 
>  	TP_fast_assign(
> @@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
>  		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
>  		__entry->dev_addr = dev_addr;
>  		__entry->size = size;
> -		__entry->swiotlb_force = swiotlb_force;
> +		__entry->force = is_swiotlb_force_bounce(dev);
>  	),
> 
> -	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
> -		"size=%zu %s",
> +	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
>  		__get_str(dev_name),
>  		__entry->dma_mask,
>  		(unsigned long long)__entry->dev_addr,
>  		__entry->size,
> -		__print_symbolic(__entry->swiotlb_force,
> -			{ SWIOTLB_NORMAL,	"NORMAL" },
> -			{ SWIOTLB_FORCE,	"FORCE" },
> -			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
> +		__entry->force ? "FORCE" : "NORMAL")
>  );
> 
>  #endif /*  _TRACE_SWIOTLB_H */
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 9a4fe6e48a074..86e877a96b828 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -62,7 +62,8 @@
> 
>  #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
> 
> -enum swiotlb_force swiotlb_force;
> +static bool swiotlb_force_bounce;
> +static bool swiotlb_force_disable;
> 
>  struct io_tlb_mem io_tlb_default_mem;
> 
> @@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
>  	if (*str == ',')
>  		++str;
>  	if (!strcmp(str, "force"))
> -		swiotlb_force = SWIOTLB_FORCE;
> +		swiotlb_force_bounce = true;
>  	else if (!strcmp(str, "noforce"))
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +		swiotlb_force_disable = true;
> 
>  	return 0;
>  }
> @@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem,
> phys_addr_t start,
>  	mem->index = 0;
>  	mem->late_alloc = late_alloc;
> 
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (swiotlb_force_bounce)
>  		mem->force_bounce = true;
> 
>  	spin_lock_init(&mem->lock);
> @@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem
> *mem, phys_addr_t start,
>  	return;
>  }
> 
> -int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
> +int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
> +		unsigned int flags)
>  {
>  	struct io_tlb_mem *mem = &io_tlb_default_mem;
>  	size_t alloc_size;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/* protect against double initialization */
> @@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
> int verbose)
>  		      __func__, alloc_size, PAGE_SIZE);
> 
>  	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
> +	mem->force_bounce = flags & SWIOTLB_FORCE;
> 
> -	if (verbose)
> +	if (flags & SWIOTLB_VERBOSE)
>  		swiotlb_print_info();
>  	return 0;
>  }
> @@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long
> nslabs, int verbose)
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void  __init
> -swiotlb_init(int verbose)
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  {
>  	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	void *tlb;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (!addressing_limit && !swiotlb_force_bounce)
> +		return;
> +	if (swiotlb_force_disable)
>  		return;
> 
>  	/* Get IO TLB memory from the low pages */
>  	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> -	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
> +	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> 
> @@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
>  	unsigned int order;
>  	int rc = 0;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/*
> @@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
>  	struct io_tlb_mem *mem = &io_tlb_default_mem;
>  	unsigned long bytes = nslabs << IO_TLB_SHIFT;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/* protect against double initialization */
> @@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
>  	unsigned long tbl_vaddr;
>  	size_t tbl_size, slots_size;
> 
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (swiotlb_force_bounce)
>  		return;
> 
>  	if (!mem->nslabs)
> @@ -704,8 +708,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t
> paddr, size_t size,
>  	phys_addr_t swiotlb_addr;
>  	dma_addr_t dma_addr;
> 
> -	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
> -			      swiotlb_force);
> +	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
> 
>  	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
>  			attrs);
> --
> 2.30.2


^ permalink raw reply	[flat|nested] 197+ messages in thread

* RE: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-04-04 17:00     ` Michael Kelley (LINUX) via iommu
  0 siblings, 0 replies; 197+ messages in thread
From: Michael Kelley (LINUX) @ 2022-04-04 17:00 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

From: Christoph Hellwig <hch@lst.de> Sent: Sunday, April 3, 2022 10:06 PM
> 
> Pass a bool to pass if swiotlb needs to be enabled based on the

Wording problems.  I'm not sure what you meant to say.

> addressing needs and replace the verbose argument with a set of
> flags, including one to force enable bounce buffering.
> 
> Note that this patch removes the possibility to force xen-swiotlb
> use using swiotlb=force on the command line on x86 (arm and arm64
> never supported that), but this interface will be restored shortly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/arm/mm/init.c                     |  6 +----
>  arch/arm64/mm/init.c                   |  6 +----
>  arch/ia64/mm/init.c                    |  4 +--
>  arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
>  arch/mips/loongson64/dma.c             |  2 +-
>  arch/mips/sibyte/common/dma.c          |  2 +-
>  arch/powerpc/mm/mem.c                  |  3 ++-
>  arch/powerpc/platforms/pseries/setup.c |  3 ---
>  arch/riscv/mm/init.c                   |  8 +-----
>  arch/s390/mm/init.c                    |  3 +--
>  arch/x86/kernel/pci-dma.c              | 15 ++++++-----
>  drivers/xen/swiotlb-xen.c              |  4 +--
>  include/linux/swiotlb.h                | 15 ++++++-----
>  include/trace/events/swiotlb.h         | 29 ++++++++-------------
>  kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
>  15 files changed, 55 insertions(+), 82 deletions(-)
> 
> diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
> index fe249ea919083..ce64bdb55a16b 100644
> --- a/arch/arm/mm/init.c
> +++ b/arch/arm/mm/init.c
> @@ -271,11 +271,7 @@ static void __init free_highpages(void)
>  void __init mem_init(void)
>  {
>  #ifdef CONFIG_ARM_LPAE
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > arm_dma_pfn_limit)
> -		swiotlb_init(1);
> -	else
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
>  #endif
> 
>  	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 8ac25f19084e8..7b6ea4d6733d6 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -398,11 +398,7 @@ void __init bootmem_init(void)
>   */
>  void __init mem_init(void)
>  {
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
> -		swiotlb_init(1);
> -	else if (!xen_swiotlb_detect())
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit),
> SWIOTLB_VERBOSE);
> 
>  	/* this will put all unused low memory onto the freelists */
>  	memblock_free_all();
> diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
> index 5d165607bf354..3c3e15b22608f 100644
> --- a/arch/ia64/mm/init.c
> +++ b/arch/ia64/mm/init.c
> @@ -437,9 +437,7 @@ mem_init (void)
>  		if (iommu_detected)
>  			break;
>  #endif
> -#ifdef CONFIG_SWIOTLB
> -		swiotlb_init(1);
> -#endif
> +		swiotlb_init(true, SWIOTLB_VERBOSE);
>  	} while (0);
> 
>  #ifdef CONFIG_FLATMEM
> diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-
> octeon.c
> index fb7547e217263..9fbba6a8fa4c5 100644
> --- a/arch/mips/cavium-octeon/dma-octeon.c
> +++ b/arch/mips/cavium-octeon/dma-octeon.c
> @@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
>  #endif
> 
>  	swiotlb_adjust_size(swiotlbsize);
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
> index 364f2f27c8723..8220a1bc0db64 100644
> --- a/arch/mips/loongson64/dma.c
> +++ b/arch/mips/loongson64/dma.c
> @@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t
> daddr)
> 
>  void __init plat_swiotlb_setup(void)
>  {
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
> index eb47a94f3583e..c5c2c782aff68 100644
> --- a/arch/mips/sibyte/common/dma.c
> +++ b/arch/mips/sibyte/common/dma.c
> @@ -10,5 +10,5 @@
> 
>  void __init plat_swiotlb_setup(void)
>  {
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
> index 8e301cd8925b2..e1519e2edc656 100644
> --- a/arch/powerpc/mm/mem.c
> +++ b/arch/powerpc/mm/mem.c
> @@ -17,6 +17,7 @@
>  #include <linux/suspend.h>
>  #include <linux/dma-direct.h>
> 
> +#include <asm/swiotlb.h>
>  #include <asm/machdep.h>
>  #include <asm/rtas.h>
>  #include <asm/kasan.h>
> @@ -251,7 +252,7 @@ void __init mem_init(void)
>  	if (is_secure_guest())
>  		svm_swiotlb_init();
>  	else
> -		swiotlb_init(0);
> +		swiotlb_init(ppc_swiotlb_enable, 0);
>  #endif
> 
>  	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
> diff --git a/arch/powerpc/platforms/pseries/setup.c
> b/arch/powerpc/platforms/pseries/setup.c
> index 069d7b3bb142e..c6e06d91b6602 100644
> --- a/arch/powerpc/platforms/pseries/setup.c
> +++ b/arch/powerpc/platforms/pseries/setup.c
> @@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
>  	}
> 
>  	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
> -
> -	if (swiotlb_force == SWIOTLB_FORCE)
> -		ppc_swiotlb_enable = 1;
>  }
> 
>  static void pseries_panic(char *str)
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 9535bea8688c0..181ffd322eafa 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -120,13 +120,7 @@ void __init mem_init(void)
>  	BUG_ON(!mem_map);
>  #endif /* CONFIG_FLATMEM */
> 
> -#ifdef CONFIG_SWIOTLB
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > PFN_DOWN(dma32_phys_limit))
> -		swiotlb_init(1);
> -	else
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> -#endif
> +	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
>  	memblock_free_all();
> 
>  	print_vm_layout();
> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
> index 86ffd0d51fd59..6fb6bf64326f9 100644
> --- a/arch/s390/mm/init.c
> +++ b/arch/s390/mm/init.c
> @@ -185,8 +185,7 @@ static void pv_init(void)
>  		return;
> 
>  	/* make sure bounce buffers are shared */
> -	swiotlb_force = SWIOTLB_FORCE;
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
>  	swiotlb_update_mem_attributes();
>  }
> 
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index 04140e20ef1a3..a705a199bf8a3 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
> 
>  #ifdef CONFIG_SWIOTLB
>  bool x86_swiotlb_enable;
> +static unsigned int x86_swiotlb_flags;
> 
>  static void __init pci_swiotlb_detect(void)
>  {
> @@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
>  	 * bounce buffers as the hypervisor can't access arbitrary VM memory
>  	 * that is not explicitly shared with it.
>  	 */
> -	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
> -		swiotlb_force = SWIOTLB_FORCE;
> -
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
>  		x86_swiotlb_enable = true;
> +		x86_swiotlb_flags |= SWIOTLB_FORCE;
> +	}
>  }
>  #else
>  static inline void __init pci_swiotlb_detect(void)
>  {
>  }
> +#define x86_swiotlb_flags 0
>  #endif /* CONFIG_SWIOTLB */
> 
>  #ifdef CONFIG_SWIOTLB_XEN
> @@ -75,8 +76,7 @@ static bool xen_swiotlb;
> 
>  static void __init pci_xen_swiotlb_init(void)
>  {
> -	if (!xen_initial_domain() && !x86_swiotlb_enable &&
> -	    swiotlb_force != SWIOTLB_FORCE)
> +	if (!xen_initial_domain() && !x86_swiotlb_enable)
>  		return;
>  	x86_swiotlb_enable = true;
>  	xen_swiotlb = true;
> @@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
>  	gart_iommu_hole_init();
>  	amd_iommu_detect();
>  	detect_intel_iommu();
> -	if (x86_swiotlb_enable)
> -		swiotlb_init(0);
> +	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
>  }
> 
>  /*
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 485cd06ed39e7..c2da3eb4826e8 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
>  		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
>  	}
> 
> -	if (swiotlb_init_with_tbl(start, nslabs, true))
> +	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
>  		panic("Cannot allocate SWIOTLB buffer");
>  }
>  #endif /* CONFIG_X86 */
> @@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev,
> struct page *page,
>  	/*
>  	 * Oh well, have to allocate and map a bounce buffer.
>  	 */
> -	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
> +	trace_swiotlb_bounced(dev, dev_addr, size);
> 
>  	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
>  	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index b48b26bfa0edb..ae0407173e845 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -13,11 +13,8 @@ struct device;
>  struct page;
>  struct scatterlist;
> 
> -enum swiotlb_force {
> -	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc.
> */
> -	SWIOTLB_FORCE,		/* swiotlb=force */
> -	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
> -};
> +#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
> +#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
> 
>  /*
>   * Maximum allowable number of contiguous slabs to map,
> @@ -36,8 +33,7 @@ enum swiotlb_force {
>  /* default to 64MB */
>  #define IO_TLB_DEFAULT_SIZE (64UL<<20)
> 
> -extern void swiotlb_init(int verbose);
> -int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
> +int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
>  int swiotlb_init_late(size_t size);
> @@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device
> *dev)
>  	return mem && mem->force_bounce;
>  }
> 
> +void swiotlb_init(bool addressing_limited, unsigned int flags);
>  void __init swiotlb_exit(void);
>  unsigned int swiotlb_max_segment(void);
>  size_t swiotlb_max_mapping_size(struct device *dev);
>  bool is_swiotlb_active(struct device *dev);
>  void __init swiotlb_adjust_size(unsigned long size);
>  #else
> -#define swiotlb_force SWIOTLB_NO_FORCE
> +static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
> +{
> +}
>  static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
>  {
>  	return false;
> diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
> index 705be43b71ab0..da05c9ebd224a 100644
> --- a/include/trace/events/swiotlb.h
> +++ b/include/trace/events/swiotlb.h
> @@ -8,20 +8,15 @@
>  #include <linux/tracepoint.h>
> 
>  TRACE_EVENT(swiotlb_bounced,
> -
> -	TP_PROTO(struct device *dev,
> -		 dma_addr_t dev_addr,
> -		 size_t size,
> -		 enum swiotlb_force swiotlb_force),
> -
> -	TP_ARGS(dev, dev_addr, size, swiotlb_force),
> +	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
> +	TP_ARGS(dev, dev_addr, size),
> 
>  	TP_STRUCT__entry(
> -		__string(	dev_name,	dev_name(dev)		)
> -		__field(	u64,	dma_mask			)
> -		__field(	dma_addr_t,	dev_addr		)
> -		__field(	size_t,	size				)
> -		__field(	enum swiotlb_force,	swiotlb_force	)
> +		__string(dev_name, dev_name(dev))
> +		__field(u64, dma_mask)
> +		__field(dma_addr_t, dev_addr)
> +		__field(size_t, size)
> +		__field(bool, force)
>  	),
> 
>  	TP_fast_assign(
> @@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
>  		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
>  		__entry->dev_addr = dev_addr;
>  		__entry->size = size;
> -		__entry->swiotlb_force = swiotlb_force;
> +		__entry->force = is_swiotlb_force_bounce(dev);
>  	),
> 
> -	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
> -		"size=%zu %s",
> +	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
>  		__get_str(dev_name),
>  		__entry->dma_mask,
>  		(unsigned long long)__entry->dev_addr,
>  		__entry->size,
> -		__print_symbolic(__entry->swiotlb_force,
> -			{ SWIOTLB_NORMAL,	"NORMAL" },
> -			{ SWIOTLB_FORCE,	"FORCE" },
> -			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
> +		__entry->force ? "FORCE" : "NORMAL")
>  );
> 
>  #endif /*  _TRACE_SWIOTLB_H */
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 9a4fe6e48a074..86e877a96b828 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -62,7 +62,8 @@
> 
>  #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
> 
> -enum swiotlb_force swiotlb_force;
> +static bool swiotlb_force_bounce;
> +static bool swiotlb_force_disable;
> 
>  struct io_tlb_mem io_tlb_default_mem;
> 
> @@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
>  	if (*str == ',')
>  		++str;
>  	if (!strcmp(str, "force"))
> -		swiotlb_force = SWIOTLB_FORCE;
> +		swiotlb_force_bounce = true;
>  	else if (!strcmp(str, "noforce"))
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +		swiotlb_force_disable = true;
> 
>  	return 0;
>  }
> @@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem,
> phys_addr_t start,
>  	mem->index = 0;
>  	mem->late_alloc = late_alloc;
> 
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (swiotlb_force_bounce)
>  		mem->force_bounce = true;
> 
>  	spin_lock_init(&mem->lock);
> @@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem
> *mem, phys_addr_t start,
>  	return;
>  }
> 
> -int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
> +int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
> +		unsigned int flags)
>  {
>  	struct io_tlb_mem *mem = &io_tlb_default_mem;
>  	size_t alloc_size;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/* protect against double initialization */
> @@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
> int verbose)
>  		      __func__, alloc_size, PAGE_SIZE);
> 
>  	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
> +	mem->force_bounce = flags & SWIOTLB_FORCE;
> 
> -	if (verbose)
> +	if (flags & SWIOTLB_VERBOSE)
>  		swiotlb_print_info();
>  	return 0;
>  }
> @@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long
> nslabs, int verbose)
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void  __init
> -swiotlb_init(int verbose)
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  {
>  	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	void *tlb;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (!addressing_limit && !swiotlb_force_bounce)
> +		return;
> +	if (swiotlb_force_disable)
>  		return;
> 
>  	/* Get IO TLB memory from the low pages */
>  	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> -	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
> +	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> 
> @@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
>  	unsigned int order;
>  	int rc = 0;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/*
> @@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
>  	struct io_tlb_mem *mem = &io_tlb_default_mem;
>  	unsigned long bytes = nslabs << IO_TLB_SHIFT;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/* protect against double initialization */
> @@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
>  	unsigned long tbl_vaddr;
>  	size_t tbl_size, slots_size;
> 
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (swiotlb_force_bounce)
>  		return;
> 
>  	if (!mem->nslabs)
> @@ -704,8 +708,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t
> paddr, size_t size,
>  	phys_addr_t swiotlb_addr;
>  	dma_addr_t dma_addr;
> 
> -	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
> -			      swiotlb_force);
> +	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
> 
>  	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
>  			attrs);
> --
> 2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* RE: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-04-04 17:00     ` Michael Kelley (LINUX) via iommu
  0 siblings, 0 replies; 197+ messages in thread
From: Michael Kelley (LINUX) @ 2022-04-04 17:00 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

From: Christoph Hellwig <hch@lst.de> Sent: Sunday, April 3, 2022 10:06 PM
> 
> Pass a bool to pass if swiotlb needs to be enabled based on the

Wording problems.  I'm not sure what you meant to say.

> addressing needs and replace the verbose argument with a set of
> flags, including one to force enable bounce buffering.
> 
> Note that this patch removes the possibility to force xen-swiotlb
> use using swiotlb=force on the command line on x86 (arm and arm64
> never supported that), but this interface will be restored shortly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/arm/mm/init.c                     |  6 +----
>  arch/arm64/mm/init.c                   |  6 +----
>  arch/ia64/mm/init.c                    |  4 +--
>  arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
>  arch/mips/loongson64/dma.c             |  2 +-
>  arch/mips/sibyte/common/dma.c          |  2 +-
>  arch/powerpc/mm/mem.c                  |  3 ++-
>  arch/powerpc/platforms/pseries/setup.c |  3 ---
>  arch/riscv/mm/init.c                   |  8 +-----
>  arch/s390/mm/init.c                    |  3 +--
>  arch/x86/kernel/pci-dma.c              | 15 ++++++-----
>  drivers/xen/swiotlb-xen.c              |  4 +--
>  include/linux/swiotlb.h                | 15 ++++++-----
>  include/trace/events/swiotlb.h         | 29 ++++++++-------------
>  kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
>  15 files changed, 55 insertions(+), 82 deletions(-)
> 
> diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
> index fe249ea919083..ce64bdb55a16b 100644
> --- a/arch/arm/mm/init.c
> +++ b/arch/arm/mm/init.c
> @@ -271,11 +271,7 @@ static void __init free_highpages(void)
>  void __init mem_init(void)
>  {
>  #ifdef CONFIG_ARM_LPAE
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > arm_dma_pfn_limit)
> -		swiotlb_init(1);
> -	else
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
>  #endif
> 
>  	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 8ac25f19084e8..7b6ea4d6733d6 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -398,11 +398,7 @@ void __init bootmem_init(void)
>   */
>  void __init mem_init(void)
>  {
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
> -		swiotlb_init(1);
> -	else if (!xen_swiotlb_detect())
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit),
> SWIOTLB_VERBOSE);
> 
>  	/* this will put all unused low memory onto the freelists */
>  	memblock_free_all();
> diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
> index 5d165607bf354..3c3e15b22608f 100644
> --- a/arch/ia64/mm/init.c
> +++ b/arch/ia64/mm/init.c
> @@ -437,9 +437,7 @@ mem_init (void)
>  		if (iommu_detected)
>  			break;
>  #endif
> -#ifdef CONFIG_SWIOTLB
> -		swiotlb_init(1);
> -#endif
> +		swiotlb_init(true, SWIOTLB_VERBOSE);
>  	} while (0);
> 
>  #ifdef CONFIG_FLATMEM
> diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-
> octeon.c
> index fb7547e217263..9fbba6a8fa4c5 100644
> --- a/arch/mips/cavium-octeon/dma-octeon.c
> +++ b/arch/mips/cavium-octeon/dma-octeon.c
> @@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
>  #endif
> 
>  	swiotlb_adjust_size(swiotlbsize);
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
> index 364f2f27c8723..8220a1bc0db64 100644
> --- a/arch/mips/loongson64/dma.c
> +++ b/arch/mips/loongson64/dma.c
> @@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t
> daddr)
> 
>  void __init plat_swiotlb_setup(void)
>  {
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
> index eb47a94f3583e..c5c2c782aff68 100644
> --- a/arch/mips/sibyte/common/dma.c
> +++ b/arch/mips/sibyte/common/dma.c
> @@ -10,5 +10,5 @@
> 
>  void __init plat_swiotlb_setup(void)
>  {
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_VERBOSE);
>  }
> diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
> index 8e301cd8925b2..e1519e2edc656 100644
> --- a/arch/powerpc/mm/mem.c
> +++ b/arch/powerpc/mm/mem.c
> @@ -17,6 +17,7 @@
>  #include <linux/suspend.h>
>  #include <linux/dma-direct.h>
> 
> +#include <asm/swiotlb.h>
>  #include <asm/machdep.h>
>  #include <asm/rtas.h>
>  #include <asm/kasan.h>
> @@ -251,7 +252,7 @@ void __init mem_init(void)
>  	if (is_secure_guest())
>  		svm_swiotlb_init();
>  	else
> -		swiotlb_init(0);
> +		swiotlb_init(ppc_swiotlb_enable, 0);
>  #endif
> 
>  	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
> diff --git a/arch/powerpc/platforms/pseries/setup.c
> b/arch/powerpc/platforms/pseries/setup.c
> index 069d7b3bb142e..c6e06d91b6602 100644
> --- a/arch/powerpc/platforms/pseries/setup.c
> +++ b/arch/powerpc/platforms/pseries/setup.c
> @@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
>  	}
> 
>  	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
> -
> -	if (swiotlb_force == SWIOTLB_FORCE)
> -		ppc_swiotlb_enable = 1;
>  }
> 
>  static void pseries_panic(char *str)
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 9535bea8688c0..181ffd322eafa 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -120,13 +120,7 @@ void __init mem_init(void)
>  	BUG_ON(!mem_map);
>  #endif /* CONFIG_FLATMEM */
> 
> -#ifdef CONFIG_SWIOTLB
> -	if (swiotlb_force == SWIOTLB_FORCE ||
> -	    max_pfn > PFN_DOWN(dma32_phys_limit))
> -		swiotlb_init(1);
> -	else
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> -#endif
> +	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
>  	memblock_free_all();
> 
>  	print_vm_layout();
> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
> index 86ffd0d51fd59..6fb6bf64326f9 100644
> --- a/arch/s390/mm/init.c
> +++ b/arch/s390/mm/init.c
> @@ -185,8 +185,7 @@ static void pv_init(void)
>  		return;
> 
>  	/* make sure bounce buffers are shared */
> -	swiotlb_force = SWIOTLB_FORCE;
> -	swiotlb_init(1);
> +	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
>  	swiotlb_update_mem_attributes();
>  }
> 
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index 04140e20ef1a3..a705a199bf8a3 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
> 
>  #ifdef CONFIG_SWIOTLB
>  bool x86_swiotlb_enable;
> +static unsigned int x86_swiotlb_flags;
> 
>  static void __init pci_swiotlb_detect(void)
>  {
> @@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
>  	 * bounce buffers as the hypervisor can't access arbitrary VM memory
>  	 * that is not explicitly shared with it.
>  	 */
> -	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
> -		swiotlb_force = SWIOTLB_FORCE;
> -
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
>  		x86_swiotlb_enable = true;
> +		x86_swiotlb_flags |= SWIOTLB_FORCE;
> +	}
>  }
>  #else
>  static inline void __init pci_swiotlb_detect(void)
>  {
>  }
> +#define x86_swiotlb_flags 0
>  #endif /* CONFIG_SWIOTLB */
> 
>  #ifdef CONFIG_SWIOTLB_XEN
> @@ -75,8 +76,7 @@ static bool xen_swiotlb;
> 
>  static void __init pci_xen_swiotlb_init(void)
>  {
> -	if (!xen_initial_domain() && !x86_swiotlb_enable &&
> -	    swiotlb_force != SWIOTLB_FORCE)
> +	if (!xen_initial_domain() && !x86_swiotlb_enable)
>  		return;
>  	x86_swiotlb_enable = true;
>  	xen_swiotlb = true;
> @@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
>  	gart_iommu_hole_init();
>  	amd_iommu_detect();
>  	detect_intel_iommu();
> -	if (x86_swiotlb_enable)
> -		swiotlb_init(0);
> +	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
>  }
> 
>  /*
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 485cd06ed39e7..c2da3eb4826e8 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
>  		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
>  	}
> 
> -	if (swiotlb_init_with_tbl(start, nslabs, true))
> +	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
>  		panic("Cannot allocate SWIOTLB buffer");
>  }
>  #endif /* CONFIG_X86 */
> @@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev,
> struct page *page,
>  	/*
>  	 * Oh well, have to allocate and map a bounce buffer.
>  	 */
> -	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
> +	trace_swiotlb_bounced(dev, dev_addr, size);
> 
>  	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
>  	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
> diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
> index b48b26bfa0edb..ae0407173e845 100644
> --- a/include/linux/swiotlb.h
> +++ b/include/linux/swiotlb.h
> @@ -13,11 +13,8 @@ struct device;
>  struct page;
>  struct scatterlist;
> 
> -enum swiotlb_force {
> -	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc.
> */
> -	SWIOTLB_FORCE,		/* swiotlb=force */
> -	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
> -};
> +#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
> +#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
> 
>  /*
>   * Maximum allowable number of contiguous slabs to map,
> @@ -36,8 +33,7 @@ enum swiotlb_force {
>  /* default to 64MB */
>  #define IO_TLB_DEFAULT_SIZE (64UL<<20)
> 
> -extern void swiotlb_init(int verbose);
> -int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
> +int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
>  unsigned long swiotlb_size_or_default(void);
>  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
>  int swiotlb_init_late(size_t size);
> @@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device
> *dev)
>  	return mem && mem->force_bounce;
>  }
> 
> +void swiotlb_init(bool addressing_limited, unsigned int flags);
>  void __init swiotlb_exit(void);
>  unsigned int swiotlb_max_segment(void);
>  size_t swiotlb_max_mapping_size(struct device *dev);
>  bool is_swiotlb_active(struct device *dev);
>  void __init swiotlb_adjust_size(unsigned long size);
>  #else
> -#define swiotlb_force SWIOTLB_NO_FORCE
> +static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
> +{
> +}
>  static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
>  {
>  	return false;
> diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
> index 705be43b71ab0..da05c9ebd224a 100644
> --- a/include/trace/events/swiotlb.h
> +++ b/include/trace/events/swiotlb.h
> @@ -8,20 +8,15 @@
>  #include <linux/tracepoint.h>
> 
>  TRACE_EVENT(swiotlb_bounced,
> -
> -	TP_PROTO(struct device *dev,
> -		 dma_addr_t dev_addr,
> -		 size_t size,
> -		 enum swiotlb_force swiotlb_force),
> -
> -	TP_ARGS(dev, dev_addr, size, swiotlb_force),
> +	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
> +	TP_ARGS(dev, dev_addr, size),
> 
>  	TP_STRUCT__entry(
> -		__string(	dev_name,	dev_name(dev)		)
> -		__field(	u64,	dma_mask			)
> -		__field(	dma_addr_t,	dev_addr		)
> -		__field(	size_t,	size				)
> -		__field(	enum swiotlb_force,	swiotlb_force	)
> +		__string(dev_name, dev_name(dev))
> +		__field(u64, dma_mask)
> +		__field(dma_addr_t, dev_addr)
> +		__field(size_t, size)
> +		__field(bool, force)
>  	),
> 
>  	TP_fast_assign(
> @@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
>  		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
>  		__entry->dev_addr = dev_addr;
>  		__entry->size = size;
> -		__entry->swiotlb_force = swiotlb_force;
> +		__entry->force = is_swiotlb_force_bounce(dev);
>  	),
> 
> -	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
> -		"size=%zu %s",
> +	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
>  		__get_str(dev_name),
>  		__entry->dma_mask,
>  		(unsigned long long)__entry->dev_addr,
>  		__entry->size,
> -		__print_symbolic(__entry->swiotlb_force,
> -			{ SWIOTLB_NORMAL,	"NORMAL" },
> -			{ SWIOTLB_FORCE,	"FORCE" },
> -			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
> +		__entry->force ? "FORCE" : "NORMAL")
>  );
> 
>  #endif /*  _TRACE_SWIOTLB_H */
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 9a4fe6e48a074..86e877a96b828 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -62,7 +62,8 @@
> 
>  #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
> 
> -enum swiotlb_force swiotlb_force;
> +static bool swiotlb_force_bounce;
> +static bool swiotlb_force_disable;
> 
>  struct io_tlb_mem io_tlb_default_mem;
> 
> @@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
>  	if (*str == ',')
>  		++str;
>  	if (!strcmp(str, "force"))
> -		swiotlb_force = SWIOTLB_FORCE;
> +		swiotlb_force_bounce = true;
>  	else if (!strcmp(str, "noforce"))
> -		swiotlb_force = SWIOTLB_NO_FORCE;
> +		swiotlb_force_disable = true;
> 
>  	return 0;
>  }
> @@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem,
> phys_addr_t start,
>  	mem->index = 0;
>  	mem->late_alloc = late_alloc;
> 
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (swiotlb_force_bounce)
>  		mem->force_bounce = true;
> 
>  	spin_lock_init(&mem->lock);
> @@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem
> *mem, phys_addr_t start,
>  	return;
>  }
> 
> -int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
> +int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
> +		unsigned int flags)
>  {
>  	struct io_tlb_mem *mem = &io_tlb_default_mem;
>  	size_t alloc_size;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/* protect against double initialization */
> @@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
> int verbose)
>  		      __func__, alloc_size, PAGE_SIZE);
> 
>  	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
> +	mem->force_bounce = flags & SWIOTLB_FORCE;
> 
> -	if (verbose)
> +	if (flags & SWIOTLB_VERBOSE)
>  		swiotlb_print_info();
>  	return 0;
>  }
> @@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long
> nslabs, int verbose)
>   * Statically reserve bounce buffer space and initialize bounce buffer data
>   * structures for the software IO TLB used to implement the DMA API.
>   */
> -void  __init
> -swiotlb_init(int verbose)
> +void __init swiotlb_init(bool addressing_limit, unsigned int flags)
>  {
>  	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
>  	void *tlb;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (!addressing_limit && !swiotlb_force_bounce)
> +		return;
> +	if (swiotlb_force_disable)
>  		return;
> 
>  	/* Get IO TLB memory from the low pages */
>  	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
>  	if (!tlb)
>  		goto fail;
> -	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
> +	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
>  		goto fail_free_mem;
>  	return;
> 
> @@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
>  	unsigned int order;
>  	int rc = 0;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/*
> @@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
>  	struct io_tlb_mem *mem = &io_tlb_default_mem;
>  	unsigned long bytes = nslabs << IO_TLB_SHIFT;
> 
> -	if (swiotlb_force == SWIOTLB_NO_FORCE)
> +	if (swiotlb_force_disable)
>  		return 0;
> 
>  	/* protect against double initialization */
> @@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
>  	unsigned long tbl_vaddr;
>  	size_t tbl_size, slots_size;
> 
> -	if (swiotlb_force == SWIOTLB_FORCE)
> +	if (swiotlb_force_bounce)
>  		return;
> 
>  	if (!mem->nslabs)
> @@ -704,8 +708,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t
> paddr, size_t size,
>  	phys_addr_t swiotlb_addr;
>  	dma_addr_t dma_addr;
> 
> -	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
> -			      swiotlb_force);
> +	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
> 
>  	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
>  			attrs);
> --
> 2.30.2

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-05 20:06   ` Boris Ostrovsky
  -1 siblings, 0 replies; 197+ messages in thread
From: Boris Ostrovsky @ 2022-04-05 20:06 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci


On 4/4/22 1:05 AM, Christoph Hellwig wrote:
> Hi all,
>
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
>
> Git tree:
>
>      git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
>
> Gitweb:
>
>      http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup




Tested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>



_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-05 20:06   ` Boris Ostrovsky
  0 siblings, 0 replies; 197+ messages in thread
From: Boris Ostrovsky @ 2022-04-05 20:06 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, linux-riscv, David Woodhouse,
	linux-arm-kernel


On 4/4/22 1:05 AM, Christoph Hellwig wrote:
> Hi all,
>
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
>
> Git tree:
>
>      git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
>
> Gitweb:
>
>      http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup




Tested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>


_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-05 20:06   ` Boris Ostrovsky
  0 siblings, 0 replies; 197+ messages in thread
From: Boris Ostrovsky @ 2022-04-05 20:06 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, linux-riscv,
	David Woodhouse, linux-arm-kernel, Lu Baolu


On 4/4/22 1:05 AM, Christoph Hellwig wrote:
> Hi all,
>
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
>
> Git tree:
>
>      git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
>
> Gitweb:
>
>      http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup




Tested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>



^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-05 20:06   ` Boris Ostrovsky
  0 siblings, 0 replies; 197+ messages in thread
From: Boris Ostrovsky @ 2022-04-05 20:06 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci


On 4/4/22 1:05 AM, Christoph Hellwig wrote:
> Hi all,
>
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
>
> Git tree:
>
>      git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
>
> Gitweb:
>
>      http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup




Tested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-05 20:06   ` Boris Ostrovsky
  0 siblings, 0 replies; 197+ messages in thread
From: Boris Ostrovsky @ 2022-04-05 20:06 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci


On 4/4/22 1:05 AM, Christoph Hellwig wrote:
> Hi all,
>
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
>
> Git tree:
>
>      git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
>
> Gitweb:
>
>      http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup




Tested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>



^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-05 20:06   ` Boris Ostrovsky
  0 siblings, 0 replies; 197+ messages in thread
From: Boris Ostrovsky @ 2022-04-05 20:06 UTC (permalink / raw)
  To: Christoph Hellwig, iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci


On 4/4/22 1:05 AM, Christoph Hellwig wrote:
> Hi all,
>
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
>
> Git tree:
>
>      git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
>
> Gitweb:
>
>      http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup




Tested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>


^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 07/15] x86: remove the IOMMU table infrastructure
  2022-04-04  5:05   ` Christoph Hellwig
                       ` (3 preceding siblings ...)
  (?)
@ 2022-04-07  0:20     ` Konrad Rzeszutek Wilk
  -1 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:20 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Mon, Apr 04, 2022 at 07:05:51AM +0200, Christoph Hellwig wrote:
> The IOMMU table tries to separate the different IOMMUs into different
> backends, but actually requires various cross calls.
> 
> Rewrite the code to do the generic swiotlb/swiotlb-xen setup directly
> in pci-dma.c and then just call into the IOMMU drivers.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Hey Christoph,

There is a bit of background behind this - this whole IOMMU table
dynamic was done as at that point of time the pci_iommu_alloc was getting
way to unwieldy - and there needed to be a more 'structured' way with
dependencies.

Hence this creation... But as Christoph points out - it has gotten out
of hand. So smashing it back to a more simplistic mechanism is good.

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!

> ---
>  arch/ia64/include/asm/iommu_table.h    |   7 --
>  arch/x86/include/asm/dma-mapping.h     |   1 -
>  arch/x86/include/asm/gart.h            |   5 +-
>  arch/x86/include/asm/iommu.h           |   6 ++
>  arch/x86/include/asm/iommu_table.h     | 102 -----------------------
>  arch/x86/include/asm/swiotlb.h         |  30 -------
>  arch/x86/include/asm/xen/swiotlb-xen.h |   2 -
>  arch/x86/kernel/Makefile               |   2 -
>  arch/x86/kernel/amd_gart_64.c          |   5 +-
>  arch/x86/kernel/aperture_64.c          |  14 ++--
>  arch/x86/kernel/pci-dma.c              | 107 ++++++++++++++++++++-----
>  arch/x86/kernel/pci-iommu_table.c      |  77 ------------------
>  arch/x86/kernel/pci-swiotlb.c          |  77 ------------------
>  arch/x86/kernel/tboot.c                |   1 -
>  arch/x86/kernel/vmlinux.lds.S          |  12 ---
>  arch/x86/xen/Makefile                  |   2 -
>  arch/x86/xen/pci-swiotlb-xen.c         |  96 ----------------------
>  drivers/iommu/amd/init.c               |   6 --
>  drivers/iommu/amd/iommu.c              |   5 +-
>  drivers/iommu/intel/dmar.c             |   6 +-
>  include/linux/dmar.h                   |   6 +-
>  21 files changed, 110 insertions(+), 459 deletions(-)
>  delete mode 100644 arch/ia64/include/asm/iommu_table.h
>  delete mode 100644 arch/x86/include/asm/iommu_table.h
>  delete mode 100644 arch/x86/include/asm/swiotlb.h
>  delete mode 100644 arch/x86/kernel/pci-iommu_table.c
>  delete mode 100644 arch/x86/kernel/pci-swiotlb.c
>  delete mode 100644 arch/x86/xen/pci-swiotlb-xen.c
> 
> diff --git a/arch/ia64/include/asm/iommu_table.h b/arch/ia64/include/asm/iommu_table.h
> deleted file mode 100644
> index cc96116ac276a..0000000000000
> --- a/arch/ia64/include/asm/iommu_table.h
> +++ /dev/null
> @@ -1,7 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_IA64_IOMMU_TABLE_H
> -#define _ASM_IA64_IOMMU_TABLE_H
> -
> -#define IOMMU_INIT_POST(_detect)
> -
> -#endif /* _ASM_IA64_IOMMU_TABLE_H */
> diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
> index bb1654fe0ce74..256fd8115223d 100644
> --- a/arch/x86/include/asm/dma-mapping.h
> +++ b/arch/x86/include/asm/dma-mapping.h
> @@ -9,7 +9,6 @@
>  
>  #include <linux/scatterlist.h>
>  #include <asm/io.h>
> -#include <asm/swiotlb.h>
>  
>  extern int iommu_merge;
>  extern int panic_on_overflow;
> diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
> index 3185565743459..5af8088a10df6 100644
> --- a/arch/x86/include/asm/gart.h
> +++ b/arch/x86/include/asm/gart.h
> @@ -38,7 +38,7 @@ extern int gart_iommu_aperture_disabled;
>  extern void early_gart_iommu_check(void);
>  extern int gart_iommu_init(void);
>  extern void __init gart_parse_options(char *);
> -extern int gart_iommu_hole_init(void);
> +void gart_iommu_hole_init(void);
>  
>  #else
>  #define gart_iommu_aperture            0
> @@ -51,9 +51,8 @@ static inline void early_gart_iommu_check(void)
>  static inline void gart_parse_options(char *options)
>  {
>  }
> -static inline int gart_iommu_hole_init(void)
> +static inline void gart_iommu_hole_init(void)
>  {
> -	return -ENODEV;
>  }
>  #endif
>  
> diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
> index bf1ed2ddc74bd..dba89ed40d38d 100644
> --- a/arch/x86/include/asm/iommu.h
> +++ b/arch/x86/include/asm/iommu.h
> @@ -9,6 +9,12 @@
>  extern int force_iommu, no_iommu;
>  extern int iommu_detected;
>  
> +#ifdef CONFIG_SWIOTLB
> +extern bool x86_swiotlb_enable;
> +#else
> +#define x86_swiotlb_enable false
> +#endif
> +
>  /* 10 seconds */
>  #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
>  
> diff --git a/arch/x86/include/asm/iommu_table.h b/arch/x86/include/asm/iommu_table.h
> deleted file mode 100644
> index 1fb3fd1a83c25..0000000000000
> --- a/arch/x86/include/asm/iommu_table.h
> +++ /dev/null
> @@ -1,102 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_X86_IOMMU_TABLE_H
> -#define _ASM_X86_IOMMU_TABLE_H
> -
> -#include <asm/swiotlb.h>
> -
> -/*
> - * History lesson:
> - * The execution chain of IOMMUs in 2.6.36 looks as so:
> - *
> - *            [xen-swiotlb]
> - *                 |
> - *         +----[swiotlb *]--+
> - *        /         |         \
> - *       /          |          \
> - *    [GART]     [Calgary]  [Intel VT-d]
> - *     /
> - *    /
> - * [AMD-Vi]
> - *
> - * *: if SWIOTLB detected 'iommu=soft'/'swiotlb=force' it would skip
> - * over the rest of IOMMUs and unconditionally initialize the SWIOTLB.
> - * Also it would surreptitiously initialize set the swiotlb=1 if there were
> - * more than 4GB and if the user did not pass in 'iommu=off'. The swiotlb
> - * flag would be turned off by all IOMMUs except the Calgary one.
> - *
> - * The IOMMU_INIT* macros allow a similar tree (or more complex if desired)
> - * to be built by defining who we depend on.
> - *
> - * And all that needs to be done is to use one of the macros in the IOMMU
> - * and the pci-dma.c will take care of the rest.
> - */
> -
> -struct iommu_table_entry {
> -	initcall_t	detect;
> -	initcall_t	depend;
> -	void		(*early_init)(void); /* No memory allocate available. */
> -	void		(*late_init)(void); /* Yes, can allocate memory. */
> -#define IOMMU_FINISH_IF_DETECTED (1<<0)
> -#define IOMMU_DETECTED		 (1<<1)
> -	int		flags;
> -};
> -/*
> - * Macro fills out an entry in the .iommu_table that is equivalent
> - * to the fields that 'struct iommu_table_entry' has. The entries
> - * that are put in the .iommu_table section are not put in any order
> - * hence during boot-time we will have to resort them based on
> - * dependency. */
> -
> -
> -#define __IOMMU_INIT(_detect, _depend, _early_init, _late_init, _finish)\
> -	static const struct iommu_table_entry				\
> -		__iommu_entry_##_detect __used				\
> -	__attribute__ ((unused, __section__(".iommu_table"),		\
> -			aligned((sizeof(void *)))))	\
> -	= {_detect, _depend, _early_init, _late_init,			\
> -	   _finish ? IOMMU_FINISH_IF_DETECTED : 0}
> -/*
> - * The simplest IOMMU definition. Provide the detection routine
> - * and it will be run after the SWIOTLB and the other IOMMUs
> - * that utilize this macro. If the IOMMU is detected (ie, the
> - * detect routine returns a positive value), the other IOMMUs
> - * are also checked. You can use IOMMU_INIT_POST_FINISH if you prefer
> - * to stop detecting the other IOMMUs after yours has been detected.
> - */
> -#define IOMMU_INIT_POST(_detect)					\
> -	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 0)
> -
> -#define IOMMU_INIT_POST_FINISH(detect)					\
> -	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 1)
> -
> -/*
> - * A more sophisticated version of IOMMU_INIT. This variant requires:
> - *  a). A detection routine function.
> - *  b). The name of the detection routine we depend on to get called
> - *      before us.
> - *  c). The init routine which gets called if the detection routine
> - *      returns a positive value from the pci_iommu_alloc. This means
> - *      no presence of a memory allocator.
> - *  d). Similar to the 'init', except that this gets called from pci_iommu_init
> - *      where we do have a memory allocator.
> - *
> - * The standard IOMMU_INIT differs from the IOMMU_INIT_FINISH variant
> - * in that the former will continue detecting other IOMMUs in the call
> - * list after the detection routine returns a positive number, while the
> - * latter will stop the execution chain upon first successful detection.
> - * Both variants will still call the 'init' and 'late_init' functions if
> - * they are set.
> - */
> -#define IOMMU_INIT_FINISH(_detect, _depend, _init, _late_init)		\
> -	__IOMMU_INIT(_detect, _depend, _init, _late_init, 1)
> -
> -#define IOMMU_INIT(_detect, _depend, _init, _late_init)			\
> -	__IOMMU_INIT(_detect, _depend, _init, _late_init, 0)
> -
> -void sort_iommu_table(struct iommu_table_entry *start,
> -		      struct iommu_table_entry *finish);
> -
> -void check_iommu_entries(struct iommu_table_entry *start,
> -			 struct iommu_table_entry *finish);
> -
> -#endif /* _ASM_X86_IOMMU_TABLE_H */
> diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
> deleted file mode 100644
> index ff6c92eff035a..0000000000000
> --- a/arch/x86/include/asm/swiotlb.h
> +++ /dev/null
> @@ -1,30 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_X86_SWIOTLB_H
> -#define _ASM_X86_SWIOTLB_H
> -
> -#include <linux/swiotlb.h>
> -
> -#ifdef CONFIG_SWIOTLB
> -extern int swiotlb;
> -extern int __init pci_swiotlb_detect_override(void);
> -extern int __init pci_swiotlb_detect_4gb(void);
> -extern void __init pci_swiotlb_init(void);
> -extern void __init pci_swiotlb_late_init(void);
> -#else
> -#define swiotlb 0
> -static inline int pci_swiotlb_detect_override(void)
> -{
> -	return 0;
> -}
> -static inline int pci_swiotlb_detect_4gb(void)
> -{
> -	return 0;
> -}
> -static inline void pci_swiotlb_init(void)
> -{
> -}
> -static inline void pci_swiotlb_late_init(void)
> -{
> -}
> -#endif
> -#endif /* _ASM_X86_SWIOTLB_H */
> diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h
> index 66b4ddde77430..e5a90b42e4dde 100644
> --- a/arch/x86/include/asm/xen/swiotlb-xen.h
> +++ b/arch/x86/include/asm/xen/swiotlb-xen.h
> @@ -3,10 +3,8 @@
>  #define _ASM_X86_SWIOTLB_XEN_H
>  
>  #ifdef CONFIG_SWIOTLB_XEN
> -extern int __init pci_xen_swiotlb_detect(void);
>  extern int pci_xen_swiotlb_init_late(void);
>  #else
> -#define pci_xen_swiotlb_detect NULL
>  static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
>  #endif
>  
> diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
> index c41ef42adbe8a..e17b7e92a3fa3 100644
> --- a/arch/x86/kernel/Makefile
> +++ b/arch/x86/kernel/Makefile
> @@ -68,7 +68,6 @@ obj-y			+= bootflag.o e820.o
>  obj-y			+= pci-dma.o quirks.o topology.o kdebugfs.o
>  obj-y			+= alternative.o i8253.o hw_breakpoint.o
>  obj-y			+= tsc.o tsc_msr.o io_delay.o rtc.o
> -obj-y			+= pci-iommu_table.o
>  obj-y			+= resource.o
>  obj-y			+= irqflags.o
>  obj-y			+= static_call.o
> @@ -134,7 +133,6 @@ obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
>  
>  obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
>  
> -obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
>  obj-$(CONFIG_OF)			+= devicetree.o
>  obj-$(CONFIG_UPROBES)			+= uprobes.o
>  
> diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
> index ed837383de5c8..194d54eed5376 100644
> --- a/arch/x86/kernel/amd_gart_64.c
> +++ b/arch/x86/kernel/amd_gart_64.c
> @@ -38,11 +38,9 @@
>  #include <asm/iommu.h>
>  #include <asm/gart.h>
>  #include <asm/set_memory.h>
> -#include <asm/swiotlb.h>
>  #include <asm/dma.h>
>  #include <asm/amd_nb.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
>  
>  static unsigned long iommu_bus_base;	/* GART remapping area (physical) */
>  static unsigned long iommu_size;	/* size of remapping area bytes */
> @@ -808,7 +806,7 @@ int __init gart_iommu_init(void)
>  	flush_gart();
>  	dma_ops = &gart_dma_ops;
>  	x86_platform.iommu_shutdown = gart_iommu_shutdown;
> -	swiotlb = 0;
> +	x86_swiotlb_enable = false;
>  
>  	return 0;
>  }
> @@ -842,4 +840,3 @@ void __init gart_parse_options(char *p)
>  		}
>  	}
>  }
> -IOMMU_INIT_POST(gart_iommu_hole_init);
> diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
> index af3ba08b684b5..7a5630d904b23 100644
> --- a/arch/x86/kernel/aperture_64.c
> +++ b/arch/x86/kernel/aperture_64.c
> @@ -392,7 +392,7 @@ void __init early_gart_iommu_check(void)
>  
>  static int __initdata printed_gart_size_msg;
>  
> -int __init gart_iommu_hole_init(void)
> +void __init gart_iommu_hole_init(void)
>  {
>  	u32 agp_aper_base = 0, agp_aper_order = 0;
>  	u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0;
> @@ -401,11 +401,11 @@ int __init gart_iommu_hole_init(void)
>  	int i, node;
>  
>  	if (!amd_gart_present())
> -		return -ENODEV;
> +		return;
>  
>  	if (gart_iommu_aperture_disabled || !fix_aperture ||
>  	    !early_pci_allowed())
> -		return -ENODEV;
> +		return;
>  
>  	pr_info("Checking aperture...\n");
>  
> @@ -491,10 +491,8 @@ int __init gart_iommu_hole_init(void)
>  			 * and fixed up the northbridge
>  			 */
>  			exclude_from_core(last_aper_base, last_aper_order);
> -
> -			return 1;
>  		}
> -		return 0;
> +		return;
>  	}
>  
>  	if (!fallback_aper_force) {
> @@ -527,7 +525,7 @@ int __init gart_iommu_hole_init(void)
>  			panic("Not enough memory for aperture");
>  		}
>  	} else {
> -		return 0;
> +		return;
>  	}
>  
>  	/*
> @@ -561,6 +559,4 @@ int __init gart_iommu_hole_init(void)
>  	}
>  
>  	set_up_gart_resume(aper_order, aper_alloc);
> -
> -	return 1;
>  }
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index de234e7a8962e..df96926421be0 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -7,13 +7,16 @@
>  #include <linux/memblock.h>
>  #include <linux/gfp.h>
>  #include <linux/pci.h>
> +#include <linux/amd-iommu.h>
>  
>  #include <asm/proto.h>
>  #include <asm/dma.h>
>  #include <asm/iommu.h>
>  #include <asm/gart.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
> +
> +#include <xen/xen.h>
> +#include <xen/swiotlb-xen.h>
>  
>  static bool disable_dac_quirk __read_mostly;
>  
> @@ -34,24 +37,83 @@ int no_iommu __read_mostly;
>  /* Set this to 1 if there is a HW IOMMU in the system */
>  int iommu_detected __read_mostly = 0;
>  
> -extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
> +#ifdef CONFIG_SWIOTLB
> +bool x86_swiotlb_enable;
> +
> +static void __init pci_swiotlb_detect(void)
> +{
> +	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
> +	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
> +		x86_swiotlb_enable = true;
> +
> +	/*
> +	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
> +	 * devices that can't support DMA to encrypted memory.
> +	 */
> +	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
> +		x86_swiotlb_enable = true;
> +
> +	if (swiotlb_force == SWIOTLB_FORCE)
> +		x86_swiotlb_enable = true;
> +}
> +#else
> +static inline void __init pci_swiotlb_detect(void)
> +{
> +}
> +#endif /* CONFIG_SWIOTLB */
> +
> +#ifdef CONFIG_SWIOTLB_XEN
> +static bool xen_swiotlb;
> +
> +static void __init pci_xen_swiotlb_init(void)
> +{
> +	if (!xen_initial_domain() && !x86_swiotlb_enable &&
> +	    swiotlb_force != SWIOTLB_FORCE)
> +		return;
> +	x86_swiotlb_enable = true;
> +	xen_swiotlb = true;
> +	xen_swiotlb_init_early();
> +	dma_ops = &xen_swiotlb_dma_ops;
> +	if (IS_ENABLED(CONFIG_PCI))
> +		pci_request_acs();
> +}
> +
> +int pci_xen_swiotlb_init_late(void)
> +{
> +	int rc;
> +
> +	if (xen_swiotlb)
> +		return 0;
> +
> +	rc = xen_swiotlb_init();
> +	if (rc)
> +		return rc;
> +
> +	/* XXX: this switches the dma ops under live devices! */
> +	dma_ops = &xen_swiotlb_dma_ops;
> +	if (IS_ENABLED(CONFIG_PCI))
> +		pci_request_acs();
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
> +#else
> +static inline void __init pci_xen_swiotlb_init(void)
> +{
> +}
> +#endif /* CONFIG_SWIOTLB_XEN */
>  
>  void __init pci_iommu_alloc(void)
>  {
> -	struct iommu_table_entry *p;
> -
> -	sort_iommu_table(__iommu_table, __iommu_table_end);
> -	check_iommu_entries(__iommu_table, __iommu_table_end);
> -
> -	for (p = __iommu_table; p < __iommu_table_end; p++) {
> -		if (p && p->detect && p->detect() > 0) {
> -			p->flags |= IOMMU_DETECTED;
> -			if (p->early_init)
> -				p->early_init();
> -			if (p->flags & IOMMU_FINISH_IF_DETECTED)
> -				break;
> -		}
> +	if (xen_pv_domain()) {
> +		pci_xen_swiotlb_init();
> +		return;
>  	}
> +	pci_swiotlb_detect();
> +	gart_iommu_hole_init();
> +	amd_iommu_detect();
> +	detect_intel_iommu();
> +	if (x86_swiotlb_enable)
> +		swiotlb_init(0);
>  }
>  
>  /*
> @@ -102,7 +164,7 @@ static __init int iommu_setup(char *p)
>  		}
>  #ifdef CONFIG_SWIOTLB
>  		if (!strncmp(p, "soft", 4))
> -			swiotlb = 1;
> +			x86_swiotlb_enable = true;
>  #endif
>  		if (!strncmp(p, "pt", 2))
>  			iommu_set_default_passthrough(true);
> @@ -121,14 +183,17 @@ early_param("iommu", iommu_setup);
>  
>  static int __init pci_iommu_init(void)
>  {
> -	struct iommu_table_entry *p;
> -
>  	x86_init.iommu.iommu_init();
>  
> -	for (p = __iommu_table; p < __iommu_table_end; p++) {
> -		if (p && (p->flags & IOMMU_DETECTED) && p->late_init)
> -			p->late_init();
> +#ifdef CONFIG_SWIOTLB
> +	/* An IOMMU turned us off. */
> +	if (x86_swiotlb_enable) {
> +		pr_info("PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
> +		swiotlb_print_info();
> +	} else {
> +		swiotlb_exit();
>  	}
> +#endif
>  
>  	return 0;
>  }
> diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
> deleted file mode 100644
> index 42e92ec62973b..0000000000000
> --- a/arch/x86/kernel/pci-iommu_table.c
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -#include <linux/dma-mapping.h>
> -#include <asm/iommu_table.h>
> -#include <linux/string.h>
> -#include <linux/kallsyms.h>
> -
> -static struct iommu_table_entry * __init
> -find_dependents_of(struct iommu_table_entry *start,
> -		   struct iommu_table_entry *finish,
> -		   struct iommu_table_entry *q)
> -{
> -	struct iommu_table_entry *p;
> -
> -	if (!q)
> -		return NULL;
> -
> -	for (p = start; p < finish; p++)
> -		if (p->detect == q->depend)
> -			return p;
> -
> -	return NULL;
> -}
> -
> -
> -void __init sort_iommu_table(struct iommu_table_entry *start,
> -			     struct iommu_table_entry *finish) {
> -
> -	struct iommu_table_entry *p, *q, tmp;
> -
> -	for (p = start; p < finish; p++) {
> -again:
> -		q = find_dependents_of(start, finish, p);
> -		/* We are bit sneaky here. We use the memory address to figure
> -		 * out if the node we depend on is past our point, if so, swap.
> -		 */
> -		if (q > p) {
> -			tmp = *p;
> -			memmove(p, q, sizeof(*p));
> -			*q = tmp;
> -			goto again;
> -		}
> -	}
> -
> -}
> -
> -#ifdef DEBUG
> -void __init check_iommu_entries(struct iommu_table_entry *start,
> -				struct iommu_table_entry *finish)
> -{
> -	struct iommu_table_entry *p, *q, *x;
> -
> -	/* Simple cyclic dependency checker. */
> -	for (p = start; p < finish; p++) {
> -		q = find_dependents_of(start, finish, p);
> -		x = find_dependents_of(start, finish, q);
> -		if (p == x) {
> -			printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %pS depends on %pS and vice-versa. BREAKING IT.\n",
> -			       p->detect, q->detect);
> -			/* Heavy handed way..*/
> -			x->depend = NULL;
> -		}
> -	}
> -
> -	for (p = start; p < finish; p++) {
> -		q = find_dependents_of(p, finish, p);
> -		if (q && q > p) {
> -			printk(KERN_ERR "EXECUTION ORDER INVALID! %pS should be called before %pS!\n",
> -			       p->detect, q->detect);
> -		}
> -	}
> -}
> -#else
> -void __init check_iommu_entries(struct iommu_table_entry *start,
> -				       struct iommu_table_entry *finish)
> -{
> -}
> -#endif
> diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
> deleted file mode 100644
> index 814ab46a0dada..0000000000000
> --- a/arch/x86/kernel/pci-swiotlb.c
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -
> -#include <linux/pci.h>
> -#include <linux/cache.h>
> -#include <linux/init.h>
> -#include <linux/swiotlb.h>
> -#include <linux/memblock.h>
> -#include <linux/dma-direct.h>
> -#include <linux/cc_platform.h>
> -
> -#include <asm/iommu.h>
> -#include <asm/swiotlb.h>
> -#include <asm/dma.h>
> -#include <asm/xen/swiotlb-xen.h>
> -#include <asm/iommu_table.h>
> -
> -int swiotlb __read_mostly;
> -
> -/*
> - * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
> - *
> - * This returns non-zero if we are forced to use swiotlb (by the boot
> - * option).
> - */
> -int __init pci_swiotlb_detect_override(void)
> -{
> -	if (swiotlb_force == SWIOTLB_FORCE)
> -		swiotlb = 1;
> -
> -	return swiotlb;
> -}
> -IOMMU_INIT_FINISH(pci_swiotlb_detect_override,
> -		  pci_xen_swiotlb_detect,
> -		  pci_swiotlb_init,
> -		  pci_swiotlb_late_init);
> -
> -/*
> - * If 4GB or more detected (and iommu=off not set) or if SME is active
> - * then set swiotlb to 1 and return 1.
> - */
> -int __init pci_swiotlb_detect_4gb(void)
> -{
> -	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
> -	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
> -		swiotlb = 1;
> -
> -	/*
> -	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
> -	 * devices that can't support DMA to encrypted memory.
> -	 */
> -	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
> -		swiotlb = 1;
> -
> -	return swiotlb;
> -}
> -IOMMU_INIT(pci_swiotlb_detect_4gb,
> -	   pci_swiotlb_detect_override,
> -	   pci_swiotlb_init,
> -	   pci_swiotlb_late_init);
> -
> -void __init pci_swiotlb_init(void)
> -{
> -	if (swiotlb)
> -		swiotlb_init(0);
> -}
> -
> -void __init pci_swiotlb_late_init(void)
> -{
> -	/* An IOMMU turned us off. */
> -	if (!swiotlb)
> -		swiotlb_exit();
> -	else {
> -		printk(KERN_INFO "PCI-DMA: "
> -		       "Using software bounce buffering for IO (SWIOTLB)\n");
> -		swiotlb_print_info();
> -	}
> -}
> diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
> index f9af561c3cd4f..0c1154a1c4032 100644
> --- a/arch/x86/kernel/tboot.c
> +++ b/arch/x86/kernel/tboot.c
> @@ -24,7 +24,6 @@
>  #include <asm/processor.h>
>  #include <asm/bootparam.h>
>  #include <asm/pgalloc.h>
> -#include <asm/swiotlb.h>
>  #include <asm/fixmap.h>
>  #include <asm/proto.h>
>  #include <asm/setup.h>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index 7fda7f27e7620..f5f6dc2e80072 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -315,18 +315,6 @@ SECTIONS
>  		*(.altinstr_replacement)
>  	}
>  
> -	/*
> -	 * struct iommu_table_entry entries are injected in this section.
> -	 * It is an array of IOMMUs which during run time gets sorted depending
> -	 * on its dependency order. After rootfs_initcall is complete
> -	 * this section can be safely removed.
> -	 */
> -	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
> -		__iommu_table = .;
> -		*(.iommu_table)
> -		__iommu_table_end = .;
> -	}
> -
>  	. = ALIGN(8);
>  	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
>  		__apicdrivers = .;
> diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
> index 4953260e281c3..3c5b52fbe4a7f 100644
> --- a/arch/x86/xen/Makefile
> +++ b/arch/x86/xen/Makefile
> @@ -47,6 +47,4 @@ obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
>  
>  obj-$(CONFIG_XEN_PV_DOM0)	+= vga.o
>  
> -obj-$(CONFIG_SWIOTLB_XEN)	+= pci-swiotlb-xen.o
> -
>  obj-$(CONFIG_XEN_EFI)		+= efi.o
> diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
> deleted file mode 100644
> index 46df59aeaa06a..0000000000000
> --- a/arch/x86/xen/pci-swiotlb-xen.c
> +++ /dev/null
> @@ -1,96 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -
> -/* Glue code to lib/swiotlb-xen.c */
> -
> -#include <linux/dma-map-ops.h>
> -#include <linux/pci.h>
> -#include <xen/swiotlb-xen.h>
> -
> -#include <asm/xen/hypervisor.h>
> -#include <xen/xen.h>
> -#include <asm/iommu_table.h>
> -
> -
> -#include <asm/xen/swiotlb-xen.h>
> -#ifdef CONFIG_X86_64
> -#include <asm/iommu.h>
> -#include <asm/dma.h>
> -#endif
> -#include <linux/export.h>
> -
> -static int xen_swiotlb __read_mostly;
> -
> -/*
> - * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
> - *
> - * This returns non-zero if we are forced to use xen_swiotlb (by the boot
> - * option).
> - */
> -int __init pci_xen_swiotlb_detect(void)
> -{
> -
> -	if (!xen_pv_domain())
> -		return 0;
> -
> -	/* If running as PV guest, either iommu=soft, or swiotlb=force will
> -	 * activate this IOMMU. If running as PV privileged, activate it
> -	 * irregardless.
> -	 */
> -	if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
> -		xen_swiotlb = 1;
> -
> -	/* If we are running under Xen, we MUST disable the native SWIOTLB.
> -	 * Don't worry about swiotlb_force flag activating the native, as
> -	 * the 'swiotlb' flag is the only one turning it on. */
> -	swiotlb = 0;
> -
> -#ifdef CONFIG_X86_64
> -	/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
> -	 * (so no iommu=X command line over-writes).
> -	 * Considering that PV guests do not want the *native SWIOTLB* but
> -	 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
> -	 */
> -	if (max_pfn > MAX_DMA32_PFN)
> -		no_iommu = 1;
> -#endif
> -	return xen_swiotlb;
> -}
> -
> -static void __init pci_xen_swiotlb_init(void)
> -{
> -	if (xen_swiotlb) {
> -		xen_swiotlb_init_early();
> -		dma_ops = &xen_swiotlb_dma_ops;
> -
> -#ifdef CONFIG_PCI
> -		/* Make sure ACS will be enabled */
> -		pci_request_acs();
> -#endif
> -	}
> -}
> -
> -int pci_xen_swiotlb_init_late(void)
> -{
> -	int rc;
> -
> -	if (xen_swiotlb)
> -		return 0;
> -
> -	rc = xen_swiotlb_init();
> -	if (rc)
> -		return rc;
> -
> -	dma_ops = &xen_swiotlb_dma_ops;
> -#ifdef CONFIG_PCI
> -	/* Make sure ACS will be enabled */
> -	pci_request_acs();
> -#endif
> -
> -	return 0;
> -}
> -EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
> -
> -IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
> -		  NULL,
> -		  pci_xen_swiotlb_init,
> -		  NULL);
> diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> index b4a798c7b347f..1a3ad58ba8465 100644
> --- a/drivers/iommu/amd/init.c
> +++ b/drivers/iommu/amd/init.c
> @@ -27,7 +27,6 @@
>  #include <asm/apic.h>
>  #include <asm/gart.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
>  #include <asm/io_apic.h>
>  #include <asm/irq_remapping.h>
>  #include <asm/set_memory.h>
> @@ -3257,11 +3256,6 @@ __setup("ivrs_ioapic",		parse_ivrs_ioapic);
>  __setup("ivrs_hpet",		parse_ivrs_hpet);
>  __setup("ivrs_acpihid",		parse_ivrs_acpihid);
>  
> -IOMMU_INIT_FINISH(amd_iommu_detect,
> -		  gart_iommu_hole_init,
> -		  NULL,
> -		  NULL);
> -
>  bool amd_iommu_v2_supported(void)
>  {
>  	return amd_iommu_v2_present;
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index a1ada7bff44e6..b47220ac09eaa 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -1840,7 +1840,10 @@ void amd_iommu_domain_update(struct protection_domain *domain)
>  
>  static void __init amd_iommu_init_dma_ops(void)
>  {
> -	swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
> +	if (iommu_default_passthrough() || sme_me_mask)
> +		x86_swiotlb_enable = true;
> +	else
> +		x86_swiotlb_enable = false;
>  }
>  
>  int __init amd_iommu_init_api(void)
> diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
> index 4de960834a1b2..592c1e1a5d4b9 100644
> --- a/drivers/iommu/intel/dmar.c
> +++ b/drivers/iommu/intel/dmar.c
> @@ -30,7 +30,6 @@
>  #include <linux/numa.h>
>  #include <linux/limits.h>
>  #include <asm/irq_remapping.h>
> -#include <asm/iommu_table.h>
>  #include <trace/events/intel_iommu.h>
>  
>  #include "../irq_remapping.h"
> @@ -912,7 +911,7 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)
>  	return 0;
>  }
>  
> -int __init detect_intel_iommu(void)
> +void __init detect_intel_iommu(void)
>  {
>  	int ret;
>  	struct dmar_res_callback validate_drhd_cb = {
> @@ -945,8 +944,6 @@ int __init detect_intel_iommu(void)
>  		dmar_tbl = NULL;
>  	}
>  	up_write(&dmar_global_lock);
> -
> -	return ret ? ret : 1;
>  }
>  
>  static void unmap_iommu(struct intel_iommu *iommu)
> @@ -2164,7 +2161,6 @@ static int __init dmar_free_unused_resources(void)
>  }
>  
>  late_initcall(dmar_free_unused_resources);
> -IOMMU_INIT_POST(detect_intel_iommu);
>  
>  /*
>   * DMAR Hotplug Support
> diff --git a/include/linux/dmar.h b/include/linux/dmar.h
> index 45e903d847335..cbd714a198a0a 100644
> --- a/include/linux/dmar.h
> +++ b/include/linux/dmar.h
> @@ -121,7 +121,7 @@ extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
>  				 u16 segment, struct dmar_dev_scope *devices,
>  				 int count);
>  /* Intel IOMMU detection */
> -extern int detect_intel_iommu(void);
> +void detect_intel_iommu(void);
>  extern int enable_drhd_fault_handling(void);
>  extern int dmar_device_add(acpi_handle handle);
>  extern int dmar_device_remove(acpi_handle handle);
> @@ -197,6 +197,10 @@ static inline bool dmar_platform_optin(void)
>  	return false;
>  }
>  
> +static inline void detect_intel_iommu(void)
> +{
> +}
> +
>  #endif /* CONFIG_DMAR_TABLE */
>  
>  struct irte {
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 07/15] x86: remove the IOMMU table infrastructure
@ 2022-04-07  0:20     ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:20 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Mon, Apr 04, 2022 at 07:05:51AM +0200, Christoph Hellwig wrote:
> The IOMMU table tries to separate the different IOMMUs into different
> backends, but actually requires various cross calls.
> 
> Rewrite the code to do the generic swiotlb/swiotlb-xen setup directly
> in pci-dma.c and then just call into the IOMMU drivers.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Hey Christoph,

There is a bit of background behind this - this whole IOMMU table
dynamic was done as at that point of time the pci_iommu_alloc was getting
way to unwieldy - and there needed to be a more 'structured' way with
dependencies.

Hence this creation... But as Christoph points out - it has gotten out
of hand. So smashing it back to a more simplistic mechanism is good.

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!

> ---
>  arch/ia64/include/asm/iommu_table.h    |   7 --
>  arch/x86/include/asm/dma-mapping.h     |   1 -
>  arch/x86/include/asm/gart.h            |   5 +-
>  arch/x86/include/asm/iommu.h           |   6 ++
>  arch/x86/include/asm/iommu_table.h     | 102 -----------------------
>  arch/x86/include/asm/swiotlb.h         |  30 -------
>  arch/x86/include/asm/xen/swiotlb-xen.h |   2 -
>  arch/x86/kernel/Makefile               |   2 -
>  arch/x86/kernel/amd_gart_64.c          |   5 +-
>  arch/x86/kernel/aperture_64.c          |  14 ++--
>  arch/x86/kernel/pci-dma.c              | 107 ++++++++++++++++++++-----
>  arch/x86/kernel/pci-iommu_table.c      |  77 ------------------
>  arch/x86/kernel/pci-swiotlb.c          |  77 ------------------
>  arch/x86/kernel/tboot.c                |   1 -
>  arch/x86/kernel/vmlinux.lds.S          |  12 ---
>  arch/x86/xen/Makefile                  |   2 -
>  arch/x86/xen/pci-swiotlb-xen.c         |  96 ----------------------
>  drivers/iommu/amd/init.c               |   6 --
>  drivers/iommu/amd/iommu.c              |   5 +-
>  drivers/iommu/intel/dmar.c             |   6 +-
>  include/linux/dmar.h                   |   6 +-
>  21 files changed, 110 insertions(+), 459 deletions(-)
>  delete mode 100644 arch/ia64/include/asm/iommu_table.h
>  delete mode 100644 arch/x86/include/asm/iommu_table.h
>  delete mode 100644 arch/x86/include/asm/swiotlb.h
>  delete mode 100644 arch/x86/kernel/pci-iommu_table.c
>  delete mode 100644 arch/x86/kernel/pci-swiotlb.c
>  delete mode 100644 arch/x86/xen/pci-swiotlb-xen.c
> 
> diff --git a/arch/ia64/include/asm/iommu_table.h b/arch/ia64/include/asm/iommu_table.h
> deleted file mode 100644
> index cc96116ac276a..0000000000000
> --- a/arch/ia64/include/asm/iommu_table.h
> +++ /dev/null
> @@ -1,7 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_IA64_IOMMU_TABLE_H
> -#define _ASM_IA64_IOMMU_TABLE_H
> -
> -#define IOMMU_INIT_POST(_detect)
> -
> -#endif /* _ASM_IA64_IOMMU_TABLE_H */
> diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
> index bb1654fe0ce74..256fd8115223d 100644
> --- a/arch/x86/include/asm/dma-mapping.h
> +++ b/arch/x86/include/asm/dma-mapping.h
> @@ -9,7 +9,6 @@
>  
>  #include <linux/scatterlist.h>
>  #include <asm/io.h>
> -#include <asm/swiotlb.h>
>  
>  extern int iommu_merge;
>  extern int panic_on_overflow;
> diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
> index 3185565743459..5af8088a10df6 100644
> --- a/arch/x86/include/asm/gart.h
> +++ b/arch/x86/include/asm/gart.h
> @@ -38,7 +38,7 @@ extern int gart_iommu_aperture_disabled;
>  extern void early_gart_iommu_check(void);
>  extern int gart_iommu_init(void);
>  extern void __init gart_parse_options(char *);
> -extern int gart_iommu_hole_init(void);
> +void gart_iommu_hole_init(void);
>  
>  #else
>  #define gart_iommu_aperture            0
> @@ -51,9 +51,8 @@ static inline void early_gart_iommu_check(void)
>  static inline void gart_parse_options(char *options)
>  {
>  }
> -static inline int gart_iommu_hole_init(void)
> +static inline void gart_iommu_hole_init(void)
>  {
> -	return -ENODEV;
>  }
>  #endif
>  
> diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
> index bf1ed2ddc74bd..dba89ed40d38d 100644
> --- a/arch/x86/include/asm/iommu.h
> +++ b/arch/x86/include/asm/iommu.h
> @@ -9,6 +9,12 @@
>  extern int force_iommu, no_iommu;
>  extern int iommu_detected;
>  
> +#ifdef CONFIG_SWIOTLB
> +extern bool x86_swiotlb_enable;
> +#else
> +#define x86_swiotlb_enable false
> +#endif
> +
>  /* 10 seconds */
>  #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
>  
> diff --git a/arch/x86/include/asm/iommu_table.h b/arch/x86/include/asm/iommu_table.h
> deleted file mode 100644
> index 1fb3fd1a83c25..0000000000000
> --- a/arch/x86/include/asm/iommu_table.h
> +++ /dev/null
> @@ -1,102 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_X86_IOMMU_TABLE_H
> -#define _ASM_X86_IOMMU_TABLE_H
> -
> -#include <asm/swiotlb.h>
> -
> -/*
> - * History lesson:
> - * The execution chain of IOMMUs in 2.6.36 looks as so:
> - *
> - *            [xen-swiotlb]
> - *                 |
> - *         +----[swiotlb *]--+
> - *        /         |         \
> - *       /          |          \
> - *    [GART]     [Calgary]  [Intel VT-d]
> - *     /
> - *    /
> - * [AMD-Vi]
> - *
> - * *: if SWIOTLB detected 'iommu=soft'/'swiotlb=force' it would skip
> - * over the rest of IOMMUs and unconditionally initialize the SWIOTLB.
> - * Also it would surreptitiously initialize set the swiotlb=1 if there were
> - * more than 4GB and if the user did not pass in 'iommu=off'. The swiotlb
> - * flag would be turned off by all IOMMUs except the Calgary one.
> - *
> - * The IOMMU_INIT* macros allow a similar tree (or more complex if desired)
> - * to be built by defining who we depend on.
> - *
> - * And all that needs to be done is to use one of the macros in the IOMMU
> - * and the pci-dma.c will take care of the rest.
> - */
> -
> -struct iommu_table_entry {
> -	initcall_t	detect;
> -	initcall_t	depend;
> -	void		(*early_init)(void); /* No memory allocate available. */
> -	void		(*late_init)(void); /* Yes, can allocate memory. */
> -#define IOMMU_FINISH_IF_DETECTED (1<<0)
> -#define IOMMU_DETECTED		 (1<<1)
> -	int		flags;
> -};
> -/*
> - * Macro fills out an entry in the .iommu_table that is equivalent
> - * to the fields that 'struct iommu_table_entry' has. The entries
> - * that are put in the .iommu_table section are not put in any order
> - * hence during boot-time we will have to resort them based on
> - * dependency. */
> -
> -
> -#define __IOMMU_INIT(_detect, _depend, _early_init, _late_init, _finish)\
> -	static const struct iommu_table_entry				\
> -		__iommu_entry_##_detect __used				\
> -	__attribute__ ((unused, __section__(".iommu_table"),		\
> -			aligned((sizeof(void *)))))	\
> -	= {_detect, _depend, _early_init, _late_init,			\
> -	   _finish ? IOMMU_FINISH_IF_DETECTED : 0}
> -/*
> - * The simplest IOMMU definition. Provide the detection routine
> - * and it will be run after the SWIOTLB and the other IOMMUs
> - * that utilize this macro. If the IOMMU is detected (ie, the
> - * detect routine returns a positive value), the other IOMMUs
> - * are also checked. You can use IOMMU_INIT_POST_FINISH if you prefer
> - * to stop detecting the other IOMMUs after yours has been detected.
> - */
> -#define IOMMU_INIT_POST(_detect)					\
> -	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 0)
> -
> -#define IOMMU_INIT_POST_FINISH(detect)					\
> -	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 1)
> -
> -/*
> - * A more sophisticated version of IOMMU_INIT. This variant requires:
> - *  a). A detection routine function.
> - *  b). The name of the detection routine we depend on to get called
> - *      before us.
> - *  c). The init routine which gets called if the detection routine
> - *      returns a positive value from the pci_iommu_alloc. This means
> - *      no presence of a memory allocator.
> - *  d). Similar to the 'init', except that this gets called from pci_iommu_init
> - *      where we do have a memory allocator.
> - *
> - * The standard IOMMU_INIT differs from the IOMMU_INIT_FINISH variant
> - * in that the former will continue detecting other IOMMUs in the call
> - * list after the detection routine returns a positive number, while the
> - * latter will stop the execution chain upon first successful detection.
> - * Both variants will still call the 'init' and 'late_init' functions if
> - * they are set.
> - */
> -#define IOMMU_INIT_FINISH(_detect, _depend, _init, _late_init)		\
> -	__IOMMU_INIT(_detect, _depend, _init, _late_init, 1)
> -
> -#define IOMMU_INIT(_detect, _depend, _init, _late_init)			\
> -	__IOMMU_INIT(_detect, _depend, _init, _late_init, 0)
> -
> -void sort_iommu_table(struct iommu_table_entry *start,
> -		      struct iommu_table_entry *finish);
> -
> -void check_iommu_entries(struct iommu_table_entry *start,
> -			 struct iommu_table_entry *finish);
> -
> -#endif /* _ASM_X86_IOMMU_TABLE_H */
> diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
> deleted file mode 100644
> index ff6c92eff035a..0000000000000
> --- a/arch/x86/include/asm/swiotlb.h
> +++ /dev/null
> @@ -1,30 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_X86_SWIOTLB_H
> -#define _ASM_X86_SWIOTLB_H
> -
> -#include <linux/swiotlb.h>
> -
> -#ifdef CONFIG_SWIOTLB
> -extern int swiotlb;
> -extern int __init pci_swiotlb_detect_override(void);
> -extern int __init pci_swiotlb_detect_4gb(void);
> -extern void __init pci_swiotlb_init(void);
> -extern void __init pci_swiotlb_late_init(void);
> -#else
> -#define swiotlb 0
> -static inline int pci_swiotlb_detect_override(void)
> -{
> -	return 0;
> -}
> -static inline int pci_swiotlb_detect_4gb(void)
> -{
> -	return 0;
> -}
> -static inline void pci_swiotlb_init(void)
> -{
> -}
> -static inline void pci_swiotlb_late_init(void)
> -{
> -}
> -#endif
> -#endif /* _ASM_X86_SWIOTLB_H */
> diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h
> index 66b4ddde77430..e5a90b42e4dde 100644
> --- a/arch/x86/include/asm/xen/swiotlb-xen.h
> +++ b/arch/x86/include/asm/xen/swiotlb-xen.h
> @@ -3,10 +3,8 @@
>  #define _ASM_X86_SWIOTLB_XEN_H
>  
>  #ifdef CONFIG_SWIOTLB_XEN
> -extern int __init pci_xen_swiotlb_detect(void);
>  extern int pci_xen_swiotlb_init_late(void);
>  #else
> -#define pci_xen_swiotlb_detect NULL
>  static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
>  #endif
>  
> diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
> index c41ef42adbe8a..e17b7e92a3fa3 100644
> --- a/arch/x86/kernel/Makefile
> +++ b/arch/x86/kernel/Makefile
> @@ -68,7 +68,6 @@ obj-y			+= bootflag.o e820.o
>  obj-y			+= pci-dma.o quirks.o topology.o kdebugfs.o
>  obj-y			+= alternative.o i8253.o hw_breakpoint.o
>  obj-y			+= tsc.o tsc_msr.o io_delay.o rtc.o
> -obj-y			+= pci-iommu_table.o
>  obj-y			+= resource.o
>  obj-y			+= irqflags.o
>  obj-y			+= static_call.o
> @@ -134,7 +133,6 @@ obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
>  
>  obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
>  
> -obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
>  obj-$(CONFIG_OF)			+= devicetree.o
>  obj-$(CONFIG_UPROBES)			+= uprobes.o
>  
> diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
> index ed837383de5c8..194d54eed5376 100644
> --- a/arch/x86/kernel/amd_gart_64.c
> +++ b/arch/x86/kernel/amd_gart_64.c
> @@ -38,11 +38,9 @@
>  #include <asm/iommu.h>
>  #include <asm/gart.h>
>  #include <asm/set_memory.h>
> -#include <asm/swiotlb.h>
>  #include <asm/dma.h>
>  #include <asm/amd_nb.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
>  
>  static unsigned long iommu_bus_base;	/* GART remapping area (physical) */
>  static unsigned long iommu_size;	/* size of remapping area bytes */
> @@ -808,7 +806,7 @@ int __init gart_iommu_init(void)
>  	flush_gart();
>  	dma_ops = &gart_dma_ops;
>  	x86_platform.iommu_shutdown = gart_iommu_shutdown;
> -	swiotlb = 0;
> +	x86_swiotlb_enable = false;
>  
>  	return 0;
>  }
> @@ -842,4 +840,3 @@ void __init gart_parse_options(char *p)
>  		}
>  	}
>  }
> -IOMMU_INIT_POST(gart_iommu_hole_init);
> diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
> index af3ba08b684b5..7a5630d904b23 100644
> --- a/arch/x86/kernel/aperture_64.c
> +++ b/arch/x86/kernel/aperture_64.c
> @@ -392,7 +392,7 @@ void __init early_gart_iommu_check(void)
>  
>  static int __initdata printed_gart_size_msg;
>  
> -int __init gart_iommu_hole_init(void)
> +void __init gart_iommu_hole_init(void)
>  {
>  	u32 agp_aper_base = 0, agp_aper_order = 0;
>  	u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0;
> @@ -401,11 +401,11 @@ int __init gart_iommu_hole_init(void)
>  	int i, node;
>  
>  	if (!amd_gart_present())
> -		return -ENODEV;
> +		return;
>  
>  	if (gart_iommu_aperture_disabled || !fix_aperture ||
>  	    !early_pci_allowed())
> -		return -ENODEV;
> +		return;
>  
>  	pr_info("Checking aperture...\n");
>  
> @@ -491,10 +491,8 @@ int __init gart_iommu_hole_init(void)
>  			 * and fixed up the northbridge
>  			 */
>  			exclude_from_core(last_aper_base, last_aper_order);
> -
> -			return 1;
>  		}
> -		return 0;
> +		return;
>  	}
>  
>  	if (!fallback_aper_force) {
> @@ -527,7 +525,7 @@ int __init gart_iommu_hole_init(void)
>  			panic("Not enough memory for aperture");
>  		}
>  	} else {
> -		return 0;
> +		return;
>  	}
>  
>  	/*
> @@ -561,6 +559,4 @@ int __init gart_iommu_hole_init(void)
>  	}
>  
>  	set_up_gart_resume(aper_order, aper_alloc);
> -
> -	return 1;
>  }
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index de234e7a8962e..df96926421be0 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -7,13 +7,16 @@
>  #include <linux/memblock.h>
>  #include <linux/gfp.h>
>  #include <linux/pci.h>
> +#include <linux/amd-iommu.h>
>  
>  #include <asm/proto.h>
>  #include <asm/dma.h>
>  #include <asm/iommu.h>
>  #include <asm/gart.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
> +
> +#include <xen/xen.h>
> +#include <xen/swiotlb-xen.h>
>  
>  static bool disable_dac_quirk __read_mostly;
>  
> @@ -34,24 +37,83 @@ int no_iommu __read_mostly;
>  /* Set this to 1 if there is a HW IOMMU in the system */
>  int iommu_detected __read_mostly = 0;
>  
> -extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
> +#ifdef CONFIG_SWIOTLB
> +bool x86_swiotlb_enable;
> +
> +static void __init pci_swiotlb_detect(void)
> +{
> +	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
> +	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
> +		x86_swiotlb_enable = true;
> +
> +	/*
> +	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
> +	 * devices that can't support DMA to encrypted memory.
> +	 */
> +	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
> +		x86_swiotlb_enable = true;
> +
> +	if (swiotlb_force == SWIOTLB_FORCE)
> +		x86_swiotlb_enable = true;
> +}
> +#else
> +static inline void __init pci_swiotlb_detect(void)
> +{
> +}
> +#endif /* CONFIG_SWIOTLB */
> +
> +#ifdef CONFIG_SWIOTLB_XEN
> +static bool xen_swiotlb;
> +
> +static void __init pci_xen_swiotlb_init(void)
> +{
> +	if (!xen_initial_domain() && !x86_swiotlb_enable &&
> +	    swiotlb_force != SWIOTLB_FORCE)
> +		return;
> +	x86_swiotlb_enable = true;
> +	xen_swiotlb = true;
> +	xen_swiotlb_init_early();
> +	dma_ops = &xen_swiotlb_dma_ops;
> +	if (IS_ENABLED(CONFIG_PCI))
> +		pci_request_acs();
> +}
> +
> +int pci_xen_swiotlb_init_late(void)
> +{
> +	int rc;
> +
> +	if (xen_swiotlb)
> +		return 0;
> +
> +	rc = xen_swiotlb_init();
> +	if (rc)
> +		return rc;
> +
> +	/* XXX: this switches the dma ops under live devices! */
> +	dma_ops = &xen_swiotlb_dma_ops;
> +	if (IS_ENABLED(CONFIG_PCI))
> +		pci_request_acs();
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
> +#else
> +static inline void __init pci_xen_swiotlb_init(void)
> +{
> +}
> +#endif /* CONFIG_SWIOTLB_XEN */
>  
>  void __init pci_iommu_alloc(void)
>  {
> -	struct iommu_table_entry *p;
> -
> -	sort_iommu_table(__iommu_table, __iommu_table_end);
> -	check_iommu_entries(__iommu_table, __iommu_table_end);
> -
> -	for (p = __iommu_table; p < __iommu_table_end; p++) {
> -		if (p && p->detect && p->detect() > 0) {
> -			p->flags |= IOMMU_DETECTED;
> -			if (p->early_init)
> -				p->early_init();
> -			if (p->flags & IOMMU_FINISH_IF_DETECTED)
> -				break;
> -		}
> +	if (xen_pv_domain()) {
> +		pci_xen_swiotlb_init();
> +		return;
>  	}
> +	pci_swiotlb_detect();
> +	gart_iommu_hole_init();
> +	amd_iommu_detect();
> +	detect_intel_iommu();
> +	if (x86_swiotlb_enable)
> +		swiotlb_init(0);
>  }
>  
>  /*
> @@ -102,7 +164,7 @@ static __init int iommu_setup(char *p)
>  		}
>  #ifdef CONFIG_SWIOTLB
>  		if (!strncmp(p, "soft", 4))
> -			swiotlb = 1;
> +			x86_swiotlb_enable = true;
>  #endif
>  		if (!strncmp(p, "pt", 2))
>  			iommu_set_default_passthrough(true);
> @@ -121,14 +183,17 @@ early_param("iommu", iommu_setup);
>  
>  static int __init pci_iommu_init(void)
>  {
> -	struct iommu_table_entry *p;
> -
>  	x86_init.iommu.iommu_init();
>  
> -	for (p = __iommu_table; p < __iommu_table_end; p++) {
> -		if (p && (p->flags & IOMMU_DETECTED) && p->late_init)
> -			p->late_init();
> +#ifdef CONFIG_SWIOTLB
> +	/* An IOMMU turned us off. */
> +	if (x86_swiotlb_enable) {
> +		pr_info("PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
> +		swiotlb_print_info();
> +	} else {
> +		swiotlb_exit();
>  	}
> +#endif
>  
>  	return 0;
>  }
> diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
> deleted file mode 100644
> index 42e92ec62973b..0000000000000
> --- a/arch/x86/kernel/pci-iommu_table.c
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -#include <linux/dma-mapping.h>
> -#include <asm/iommu_table.h>
> -#include <linux/string.h>
> -#include <linux/kallsyms.h>
> -
> -static struct iommu_table_entry * __init
> -find_dependents_of(struct iommu_table_entry *start,
> -		   struct iommu_table_entry *finish,
> -		   struct iommu_table_entry *q)
> -{
> -	struct iommu_table_entry *p;
> -
> -	if (!q)
> -		return NULL;
> -
> -	for (p = start; p < finish; p++)
> -		if (p->detect == q->depend)
> -			return p;
> -
> -	return NULL;
> -}
> -
> -
> -void __init sort_iommu_table(struct iommu_table_entry *start,
> -			     struct iommu_table_entry *finish) {
> -
> -	struct iommu_table_entry *p, *q, tmp;
> -
> -	for (p = start; p < finish; p++) {
> -again:
> -		q = find_dependents_of(start, finish, p);
> -		/* We are bit sneaky here. We use the memory address to figure
> -		 * out if the node we depend on is past our point, if so, swap.
> -		 */
> -		if (q > p) {
> -			tmp = *p;
> -			memmove(p, q, sizeof(*p));
> -			*q = tmp;
> -			goto again;
> -		}
> -	}
> -
> -}
> -
> -#ifdef DEBUG
> -void __init check_iommu_entries(struct iommu_table_entry *start,
> -				struct iommu_table_entry *finish)
> -{
> -	struct iommu_table_entry *p, *q, *x;
> -
> -	/* Simple cyclic dependency checker. */
> -	for (p = start; p < finish; p++) {
> -		q = find_dependents_of(start, finish, p);
> -		x = find_dependents_of(start, finish, q);
> -		if (p == x) {
> -			printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %pS depends on %pS and vice-versa. BREAKING IT.\n",
> -			       p->detect, q->detect);
> -			/* Heavy handed way..*/
> -			x->depend = NULL;
> -		}
> -	}
> -
> -	for (p = start; p < finish; p++) {
> -		q = find_dependents_of(p, finish, p);
> -		if (q && q > p) {
> -			printk(KERN_ERR "EXECUTION ORDER INVALID! %pS should be called before %pS!\n",
> -			       p->detect, q->detect);
> -		}
> -	}
> -}
> -#else
> -void __init check_iommu_entries(struct iommu_table_entry *start,
> -				       struct iommu_table_entry *finish)
> -{
> -}
> -#endif
> diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
> deleted file mode 100644
> index 814ab46a0dada..0000000000000
> --- a/arch/x86/kernel/pci-swiotlb.c
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -
> -#include <linux/pci.h>
> -#include <linux/cache.h>
> -#include <linux/init.h>
> -#include <linux/swiotlb.h>
> -#include <linux/memblock.h>
> -#include <linux/dma-direct.h>
> -#include <linux/cc_platform.h>
> -
> -#include <asm/iommu.h>
> -#include <asm/swiotlb.h>
> -#include <asm/dma.h>
> -#include <asm/xen/swiotlb-xen.h>
> -#include <asm/iommu_table.h>
> -
> -int swiotlb __read_mostly;
> -
> -/*
> - * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
> - *
> - * This returns non-zero if we are forced to use swiotlb (by the boot
> - * option).
> - */
> -int __init pci_swiotlb_detect_override(void)
> -{
> -	if (swiotlb_force == SWIOTLB_FORCE)
> -		swiotlb = 1;
> -
> -	return swiotlb;
> -}
> -IOMMU_INIT_FINISH(pci_swiotlb_detect_override,
> -		  pci_xen_swiotlb_detect,
> -		  pci_swiotlb_init,
> -		  pci_swiotlb_late_init);
> -
> -/*
> - * If 4GB or more detected (and iommu=off not set) or if SME is active
> - * then set swiotlb to 1 and return 1.
> - */
> -int __init pci_swiotlb_detect_4gb(void)
> -{
> -	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
> -	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
> -		swiotlb = 1;
> -
> -	/*
> -	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
> -	 * devices that can't support DMA to encrypted memory.
> -	 */
> -	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
> -		swiotlb = 1;
> -
> -	return swiotlb;
> -}
> -IOMMU_INIT(pci_swiotlb_detect_4gb,
> -	   pci_swiotlb_detect_override,
> -	   pci_swiotlb_init,
> -	   pci_swiotlb_late_init);
> -
> -void __init pci_swiotlb_init(void)
> -{
> -	if (swiotlb)
> -		swiotlb_init(0);
> -}
> -
> -void __init pci_swiotlb_late_init(void)
> -{
> -	/* An IOMMU turned us off. */
> -	if (!swiotlb)
> -		swiotlb_exit();
> -	else {
> -		printk(KERN_INFO "PCI-DMA: "
> -		       "Using software bounce buffering for IO (SWIOTLB)\n");
> -		swiotlb_print_info();
> -	}
> -}
> diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
> index f9af561c3cd4f..0c1154a1c4032 100644
> --- a/arch/x86/kernel/tboot.c
> +++ b/arch/x86/kernel/tboot.c
> @@ -24,7 +24,6 @@
>  #include <asm/processor.h>
>  #include <asm/bootparam.h>
>  #include <asm/pgalloc.h>
> -#include <asm/swiotlb.h>
>  #include <asm/fixmap.h>
>  #include <asm/proto.h>
>  #include <asm/setup.h>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index 7fda7f27e7620..f5f6dc2e80072 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -315,18 +315,6 @@ SECTIONS
>  		*(.altinstr_replacement)
>  	}
>  
> -	/*
> -	 * struct iommu_table_entry entries are injected in this section.
> -	 * It is an array of IOMMUs which during run time gets sorted depending
> -	 * on its dependency order. After rootfs_initcall is complete
> -	 * this section can be safely removed.
> -	 */
> -	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
> -		__iommu_table = .;
> -		*(.iommu_table)
> -		__iommu_table_end = .;
> -	}
> -
>  	. = ALIGN(8);
>  	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
>  		__apicdrivers = .;
> diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
> index 4953260e281c3..3c5b52fbe4a7f 100644
> --- a/arch/x86/xen/Makefile
> +++ b/arch/x86/xen/Makefile
> @@ -47,6 +47,4 @@ obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
>  
>  obj-$(CONFIG_XEN_PV_DOM0)	+= vga.o
>  
> -obj-$(CONFIG_SWIOTLB_XEN)	+= pci-swiotlb-xen.o
> -
>  obj-$(CONFIG_XEN_EFI)		+= efi.o
> diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
> deleted file mode 100644
> index 46df59aeaa06a..0000000000000
> --- a/arch/x86/xen/pci-swiotlb-xen.c
> +++ /dev/null
> @@ -1,96 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -
> -/* Glue code to lib/swiotlb-xen.c */
> -
> -#include <linux/dma-map-ops.h>
> -#include <linux/pci.h>
> -#include <xen/swiotlb-xen.h>
> -
> -#include <asm/xen/hypervisor.h>
> -#include <xen/xen.h>
> -#include <asm/iommu_table.h>
> -
> -
> -#include <asm/xen/swiotlb-xen.h>
> -#ifdef CONFIG_X86_64
> -#include <asm/iommu.h>
> -#include <asm/dma.h>
> -#endif
> -#include <linux/export.h>
> -
> -static int xen_swiotlb __read_mostly;
> -
> -/*
> - * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
> - *
> - * This returns non-zero if we are forced to use xen_swiotlb (by the boot
> - * option).
> - */
> -int __init pci_xen_swiotlb_detect(void)
> -{
> -
> -	if (!xen_pv_domain())
> -		return 0;
> -
> -	/* If running as PV guest, either iommu=soft, or swiotlb=force will
> -	 * activate this IOMMU. If running as PV privileged, activate it
> -	 * irregardless.
> -	 */
> -	if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
> -		xen_swiotlb = 1;
> -
> -	/* If we are running under Xen, we MUST disable the native SWIOTLB.
> -	 * Don't worry about swiotlb_force flag activating the native, as
> -	 * the 'swiotlb' flag is the only one turning it on. */
> -	swiotlb = 0;
> -
> -#ifdef CONFIG_X86_64
> -	/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
> -	 * (so no iommu=X command line over-writes).
> -	 * Considering that PV guests do not want the *native SWIOTLB* but
> -	 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
> -	 */
> -	if (max_pfn > MAX_DMA32_PFN)
> -		no_iommu = 1;
> -#endif
> -	return xen_swiotlb;
> -}
> -
> -static void __init pci_xen_swiotlb_init(void)
> -{
> -	if (xen_swiotlb) {
> -		xen_swiotlb_init_early();
> -		dma_ops = &xen_swiotlb_dma_ops;
> -
> -#ifdef CONFIG_PCI
> -		/* Make sure ACS will be enabled */
> -		pci_request_acs();
> -#endif
> -	}
> -}
> -
> -int pci_xen_swiotlb_init_late(void)
> -{
> -	int rc;
> -
> -	if (xen_swiotlb)
> -		return 0;
> -
> -	rc = xen_swiotlb_init();
> -	if (rc)
> -		return rc;
> -
> -	dma_ops = &xen_swiotlb_dma_ops;
> -#ifdef CONFIG_PCI
> -	/* Make sure ACS will be enabled */
> -	pci_request_acs();
> -#endif
> -
> -	return 0;
> -}
> -EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
> -
> -IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
> -		  NULL,
> -		  pci_xen_swiotlb_init,
> -		  NULL);
> diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> index b4a798c7b347f..1a3ad58ba8465 100644
> --- a/drivers/iommu/amd/init.c
> +++ b/drivers/iommu/amd/init.c
> @@ -27,7 +27,6 @@
>  #include <asm/apic.h>
>  #include <asm/gart.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
>  #include <asm/io_apic.h>
>  #include <asm/irq_remapping.h>
>  #include <asm/set_memory.h>
> @@ -3257,11 +3256,6 @@ __setup("ivrs_ioapic",		parse_ivrs_ioapic);
>  __setup("ivrs_hpet",		parse_ivrs_hpet);
>  __setup("ivrs_acpihid",		parse_ivrs_acpihid);
>  
> -IOMMU_INIT_FINISH(amd_iommu_detect,
> -		  gart_iommu_hole_init,
> -		  NULL,
> -		  NULL);
> -
>  bool amd_iommu_v2_supported(void)
>  {
>  	return amd_iommu_v2_present;
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index a1ada7bff44e6..b47220ac09eaa 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -1840,7 +1840,10 @@ void amd_iommu_domain_update(struct protection_domain *domain)
>  
>  static void __init amd_iommu_init_dma_ops(void)
>  {
> -	swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
> +	if (iommu_default_passthrough() || sme_me_mask)
> +		x86_swiotlb_enable = true;
> +	else
> +		x86_swiotlb_enable = false;
>  }
>  
>  int __init amd_iommu_init_api(void)
> diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
> index 4de960834a1b2..592c1e1a5d4b9 100644
> --- a/drivers/iommu/intel/dmar.c
> +++ b/drivers/iommu/intel/dmar.c
> @@ -30,7 +30,6 @@
>  #include <linux/numa.h>
>  #include <linux/limits.h>
>  #include <asm/irq_remapping.h>
> -#include <asm/iommu_table.h>
>  #include <trace/events/intel_iommu.h>
>  
>  #include "../irq_remapping.h"
> @@ -912,7 +911,7 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)
>  	return 0;
>  }
>  
> -int __init detect_intel_iommu(void)
> +void __init detect_intel_iommu(void)
>  {
>  	int ret;
>  	struct dmar_res_callback validate_drhd_cb = {
> @@ -945,8 +944,6 @@ int __init detect_intel_iommu(void)
>  		dmar_tbl = NULL;
>  	}
>  	up_write(&dmar_global_lock);
> -
> -	return ret ? ret : 1;
>  }
>  
>  static void unmap_iommu(struct intel_iommu *iommu)
> @@ -2164,7 +2161,6 @@ static int __init dmar_free_unused_resources(void)
>  }
>  
>  late_initcall(dmar_free_unused_resources);
> -IOMMU_INIT_POST(detect_intel_iommu);
>  
>  /*
>   * DMAR Hotplug Support
> diff --git a/include/linux/dmar.h b/include/linux/dmar.h
> index 45e903d847335..cbd714a198a0a 100644
> --- a/include/linux/dmar.h
> +++ b/include/linux/dmar.h
> @@ -121,7 +121,7 @@ extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
>  				 u16 segment, struct dmar_dev_scope *devices,
>  				 int count);
>  /* Intel IOMMU detection */
> -extern int detect_intel_iommu(void);
> +void detect_intel_iommu(void);
>  extern int enable_drhd_fault_handling(void);
>  extern int dmar_device_add(acpi_handle handle);
>  extern int dmar_device_remove(acpi_handle handle);
> @@ -197,6 +197,10 @@ static inline bool dmar_platform_optin(void)
>  	return false;
>  }
>  
> +static inline void detect_intel_iommu(void)
> +{
> +}
> +
>  #endif /* CONFIG_DMAR_TABLE */
>  
>  struct irte {
> -- 
> 2.30.2
> 

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 07/15] x86: remove the IOMMU table infrastructure
@ 2022-04-07  0:20     ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:20 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, linux-hyperv, Anshuman Khandual, Robin Murphy, x86,
	linux-mips, linuxppc-dev, iommu, tboot-devel, linux-pci,
	xen-devel, Boris Ostrovsky, David Woodhouse, linux-riscv,
	linux-arm-kernel

On Mon, Apr 04, 2022 at 07:05:51AM +0200, Christoph Hellwig wrote:
> The IOMMU table tries to separate the different IOMMUs into different
> backends, but actually requires various cross calls.
> 
> Rewrite the code to do the generic swiotlb/swiotlb-xen setup directly
> in pci-dma.c and then just call into the IOMMU drivers.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Hey Christoph,

There is a bit of background behind this - this whole IOMMU table
dynamic was done as at that point of time the pci_iommu_alloc was getting
way to unwieldy - and there needed to be a more 'structured' way with
dependencies.

Hence this creation... But as Christoph points out - it has gotten out
of hand. So smashing it back to a more simplistic mechanism is good.

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!

> ---
>  arch/ia64/include/asm/iommu_table.h    |   7 --
>  arch/x86/include/asm/dma-mapping.h     |   1 -
>  arch/x86/include/asm/gart.h            |   5 +-
>  arch/x86/include/asm/iommu.h           |   6 ++
>  arch/x86/include/asm/iommu_table.h     | 102 -----------------------
>  arch/x86/include/asm/swiotlb.h         |  30 -------
>  arch/x86/include/asm/xen/swiotlb-xen.h |   2 -
>  arch/x86/kernel/Makefile               |   2 -
>  arch/x86/kernel/amd_gart_64.c          |   5 +-
>  arch/x86/kernel/aperture_64.c          |  14 ++--
>  arch/x86/kernel/pci-dma.c              | 107 ++++++++++++++++++++-----
>  arch/x86/kernel/pci-iommu_table.c      |  77 ------------------
>  arch/x86/kernel/pci-swiotlb.c          |  77 ------------------
>  arch/x86/kernel/tboot.c                |   1 -
>  arch/x86/kernel/vmlinux.lds.S          |  12 ---
>  arch/x86/xen/Makefile                  |   2 -
>  arch/x86/xen/pci-swiotlb-xen.c         |  96 ----------------------
>  drivers/iommu/amd/init.c               |   6 --
>  drivers/iommu/amd/iommu.c              |   5 +-
>  drivers/iommu/intel/dmar.c             |   6 +-
>  include/linux/dmar.h                   |   6 +-
>  21 files changed, 110 insertions(+), 459 deletions(-)
>  delete mode 100644 arch/ia64/include/asm/iommu_table.h
>  delete mode 100644 arch/x86/include/asm/iommu_table.h
>  delete mode 100644 arch/x86/include/asm/swiotlb.h
>  delete mode 100644 arch/x86/kernel/pci-iommu_table.c
>  delete mode 100644 arch/x86/kernel/pci-swiotlb.c
>  delete mode 100644 arch/x86/xen/pci-swiotlb-xen.c
> 
> diff --git a/arch/ia64/include/asm/iommu_table.h b/arch/ia64/include/asm/iommu_table.h
> deleted file mode 100644
> index cc96116ac276a..0000000000000
> --- a/arch/ia64/include/asm/iommu_table.h
> +++ /dev/null
> @@ -1,7 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_IA64_IOMMU_TABLE_H
> -#define _ASM_IA64_IOMMU_TABLE_H
> -
> -#define IOMMU_INIT_POST(_detect)
> -
> -#endif /* _ASM_IA64_IOMMU_TABLE_H */
> diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
> index bb1654fe0ce74..256fd8115223d 100644
> --- a/arch/x86/include/asm/dma-mapping.h
> +++ b/arch/x86/include/asm/dma-mapping.h
> @@ -9,7 +9,6 @@
>  
>  #include <linux/scatterlist.h>
>  #include <asm/io.h>
> -#include <asm/swiotlb.h>
>  
>  extern int iommu_merge;
>  extern int panic_on_overflow;
> diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
> index 3185565743459..5af8088a10df6 100644
> --- a/arch/x86/include/asm/gart.h
> +++ b/arch/x86/include/asm/gart.h
> @@ -38,7 +38,7 @@ extern int gart_iommu_aperture_disabled;
>  extern void early_gart_iommu_check(void);
>  extern int gart_iommu_init(void);
>  extern void __init gart_parse_options(char *);
> -extern int gart_iommu_hole_init(void);
> +void gart_iommu_hole_init(void);
>  
>  #else
>  #define gart_iommu_aperture            0
> @@ -51,9 +51,8 @@ static inline void early_gart_iommu_check(void)
>  static inline void gart_parse_options(char *options)
>  {
>  }
> -static inline int gart_iommu_hole_init(void)
> +static inline void gart_iommu_hole_init(void)
>  {
> -	return -ENODEV;
>  }
>  #endif
>  
> diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
> index bf1ed2ddc74bd..dba89ed40d38d 100644
> --- a/arch/x86/include/asm/iommu.h
> +++ b/arch/x86/include/asm/iommu.h
> @@ -9,6 +9,12 @@
>  extern int force_iommu, no_iommu;
>  extern int iommu_detected;
>  
> +#ifdef CONFIG_SWIOTLB
> +extern bool x86_swiotlb_enable;
> +#else
> +#define x86_swiotlb_enable false
> +#endif
> +
>  /* 10 seconds */
>  #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
>  
> diff --git a/arch/x86/include/asm/iommu_table.h b/arch/x86/include/asm/iommu_table.h
> deleted file mode 100644
> index 1fb3fd1a83c25..0000000000000
> --- a/arch/x86/include/asm/iommu_table.h
> +++ /dev/null
> @@ -1,102 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_X86_IOMMU_TABLE_H
> -#define _ASM_X86_IOMMU_TABLE_H
> -
> -#include <asm/swiotlb.h>
> -
> -/*
> - * History lesson:
> - * The execution chain of IOMMUs in 2.6.36 looks as so:
> - *
> - *            [xen-swiotlb]
> - *                 |
> - *         +----[swiotlb *]--+
> - *        /         |         \
> - *       /          |          \
> - *    [GART]     [Calgary]  [Intel VT-d]
> - *     /
> - *    /
> - * [AMD-Vi]
> - *
> - * *: if SWIOTLB detected 'iommu=soft'/'swiotlb=force' it would skip
> - * over the rest of IOMMUs and unconditionally initialize the SWIOTLB.
> - * Also it would surreptitiously initialize set the swiotlb=1 if there were
> - * more than 4GB and if the user did not pass in 'iommu=off'. The swiotlb
> - * flag would be turned off by all IOMMUs except the Calgary one.
> - *
> - * The IOMMU_INIT* macros allow a similar tree (or more complex if desired)
> - * to be built by defining who we depend on.
> - *
> - * And all that needs to be done is to use one of the macros in the IOMMU
> - * and the pci-dma.c will take care of the rest.
> - */
> -
> -struct iommu_table_entry {
> -	initcall_t	detect;
> -	initcall_t	depend;
> -	void		(*early_init)(void); /* No memory allocate available. */
> -	void		(*late_init)(void); /* Yes, can allocate memory. */
> -#define IOMMU_FINISH_IF_DETECTED (1<<0)
> -#define IOMMU_DETECTED		 (1<<1)
> -	int		flags;
> -};
> -/*
> - * Macro fills out an entry in the .iommu_table that is equivalent
> - * to the fields that 'struct iommu_table_entry' has. The entries
> - * that are put in the .iommu_table section are not put in any order
> - * hence during boot-time we will have to resort them based on
> - * dependency. */
> -
> -
> -#define __IOMMU_INIT(_detect, _depend, _early_init, _late_init, _finish)\
> -	static const struct iommu_table_entry				\
> -		__iommu_entry_##_detect __used				\
> -	__attribute__ ((unused, __section__(".iommu_table"),		\
> -			aligned((sizeof(void *)))))	\
> -	= {_detect, _depend, _early_init, _late_init,			\
> -	   _finish ? IOMMU_FINISH_IF_DETECTED : 0}
> -/*
> - * The simplest IOMMU definition. Provide the detection routine
> - * and it will be run after the SWIOTLB and the other IOMMUs
> - * that utilize this macro. If the IOMMU is detected (ie, the
> - * detect routine returns a positive value), the other IOMMUs
> - * are also checked. You can use IOMMU_INIT_POST_FINISH if you prefer
> - * to stop detecting the other IOMMUs after yours has been detected.
> - */
> -#define IOMMU_INIT_POST(_detect)					\
> -	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 0)
> -
> -#define IOMMU_INIT_POST_FINISH(detect)					\
> -	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 1)
> -
> -/*
> - * A more sophisticated version of IOMMU_INIT. This variant requires:
> - *  a). A detection routine function.
> - *  b). The name of the detection routine we depend on to get called
> - *      before us.
> - *  c). The init routine which gets called if the detection routine
> - *      returns a positive value from the pci_iommu_alloc. This means
> - *      no presence of a memory allocator.
> - *  d). Similar to the 'init', except that this gets called from pci_iommu_init
> - *      where we do have a memory allocator.
> - *
> - * The standard IOMMU_INIT differs from the IOMMU_INIT_FINISH variant
> - * in that the former will continue detecting other IOMMUs in the call
> - * list after the detection routine returns a positive number, while the
> - * latter will stop the execution chain upon first successful detection.
> - * Both variants will still call the 'init' and 'late_init' functions if
> - * they are set.
> - */
> -#define IOMMU_INIT_FINISH(_detect, _depend, _init, _late_init)		\
> -	__IOMMU_INIT(_detect, _depend, _init, _late_init, 1)
> -
> -#define IOMMU_INIT(_detect, _depend, _init, _late_init)			\
> -	__IOMMU_INIT(_detect, _depend, _init, _late_init, 0)
> -
> -void sort_iommu_table(struct iommu_table_entry *start,
> -		      struct iommu_table_entry *finish);
> -
> -void check_iommu_entries(struct iommu_table_entry *start,
> -			 struct iommu_table_entry *finish);
> -
> -#endif /* _ASM_X86_IOMMU_TABLE_H */
> diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
> deleted file mode 100644
> index ff6c92eff035a..0000000000000
> --- a/arch/x86/include/asm/swiotlb.h
> +++ /dev/null
> @@ -1,30 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_X86_SWIOTLB_H
> -#define _ASM_X86_SWIOTLB_H
> -
> -#include <linux/swiotlb.h>
> -
> -#ifdef CONFIG_SWIOTLB
> -extern int swiotlb;
> -extern int __init pci_swiotlb_detect_override(void);
> -extern int __init pci_swiotlb_detect_4gb(void);
> -extern void __init pci_swiotlb_init(void);
> -extern void __init pci_swiotlb_late_init(void);
> -#else
> -#define swiotlb 0
> -static inline int pci_swiotlb_detect_override(void)
> -{
> -	return 0;
> -}
> -static inline int pci_swiotlb_detect_4gb(void)
> -{
> -	return 0;
> -}
> -static inline void pci_swiotlb_init(void)
> -{
> -}
> -static inline void pci_swiotlb_late_init(void)
> -{
> -}
> -#endif
> -#endif /* _ASM_X86_SWIOTLB_H */
> diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h
> index 66b4ddde77430..e5a90b42e4dde 100644
> --- a/arch/x86/include/asm/xen/swiotlb-xen.h
> +++ b/arch/x86/include/asm/xen/swiotlb-xen.h
> @@ -3,10 +3,8 @@
>  #define _ASM_X86_SWIOTLB_XEN_H
>  
>  #ifdef CONFIG_SWIOTLB_XEN
> -extern int __init pci_xen_swiotlb_detect(void);
>  extern int pci_xen_swiotlb_init_late(void);
>  #else
> -#define pci_xen_swiotlb_detect NULL
>  static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
>  #endif
>  
> diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
> index c41ef42adbe8a..e17b7e92a3fa3 100644
> --- a/arch/x86/kernel/Makefile
> +++ b/arch/x86/kernel/Makefile
> @@ -68,7 +68,6 @@ obj-y			+= bootflag.o e820.o
>  obj-y			+= pci-dma.o quirks.o topology.o kdebugfs.o
>  obj-y			+= alternative.o i8253.o hw_breakpoint.o
>  obj-y			+= tsc.o tsc_msr.o io_delay.o rtc.o
> -obj-y			+= pci-iommu_table.o
>  obj-y			+= resource.o
>  obj-y			+= irqflags.o
>  obj-y			+= static_call.o
> @@ -134,7 +133,6 @@ obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
>  
>  obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
>  
> -obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
>  obj-$(CONFIG_OF)			+= devicetree.o
>  obj-$(CONFIG_UPROBES)			+= uprobes.o
>  
> diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
> index ed837383de5c8..194d54eed5376 100644
> --- a/arch/x86/kernel/amd_gart_64.c
> +++ b/arch/x86/kernel/amd_gart_64.c
> @@ -38,11 +38,9 @@
>  #include <asm/iommu.h>
>  #include <asm/gart.h>
>  #include <asm/set_memory.h>
> -#include <asm/swiotlb.h>
>  #include <asm/dma.h>
>  #include <asm/amd_nb.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
>  
>  static unsigned long iommu_bus_base;	/* GART remapping area (physical) */
>  static unsigned long iommu_size;	/* size of remapping area bytes */
> @@ -808,7 +806,7 @@ int __init gart_iommu_init(void)
>  	flush_gart();
>  	dma_ops = &gart_dma_ops;
>  	x86_platform.iommu_shutdown = gart_iommu_shutdown;
> -	swiotlb = 0;
> +	x86_swiotlb_enable = false;
>  
>  	return 0;
>  }
> @@ -842,4 +840,3 @@ void __init gart_parse_options(char *p)
>  		}
>  	}
>  }
> -IOMMU_INIT_POST(gart_iommu_hole_init);
> diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
> index af3ba08b684b5..7a5630d904b23 100644
> --- a/arch/x86/kernel/aperture_64.c
> +++ b/arch/x86/kernel/aperture_64.c
> @@ -392,7 +392,7 @@ void __init early_gart_iommu_check(void)
>  
>  static int __initdata printed_gart_size_msg;
>  
> -int __init gart_iommu_hole_init(void)
> +void __init gart_iommu_hole_init(void)
>  {
>  	u32 agp_aper_base = 0, agp_aper_order = 0;
>  	u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0;
> @@ -401,11 +401,11 @@ int __init gart_iommu_hole_init(void)
>  	int i, node;
>  
>  	if (!amd_gart_present())
> -		return -ENODEV;
> +		return;
>  
>  	if (gart_iommu_aperture_disabled || !fix_aperture ||
>  	    !early_pci_allowed())
> -		return -ENODEV;
> +		return;
>  
>  	pr_info("Checking aperture...\n");
>  
> @@ -491,10 +491,8 @@ int __init gart_iommu_hole_init(void)
>  			 * and fixed up the northbridge
>  			 */
>  			exclude_from_core(last_aper_base, last_aper_order);
> -
> -			return 1;
>  		}
> -		return 0;
> +		return;
>  	}
>  
>  	if (!fallback_aper_force) {
> @@ -527,7 +525,7 @@ int __init gart_iommu_hole_init(void)
>  			panic("Not enough memory for aperture");
>  		}
>  	} else {
> -		return 0;
> +		return;
>  	}
>  
>  	/*
> @@ -561,6 +559,4 @@ int __init gart_iommu_hole_init(void)
>  	}
>  
>  	set_up_gart_resume(aper_order, aper_alloc);
> -
> -	return 1;
>  }
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index de234e7a8962e..df96926421be0 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -7,13 +7,16 @@
>  #include <linux/memblock.h>
>  #include <linux/gfp.h>
>  #include <linux/pci.h>
> +#include <linux/amd-iommu.h>
>  
>  #include <asm/proto.h>
>  #include <asm/dma.h>
>  #include <asm/iommu.h>
>  #include <asm/gart.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
> +
> +#include <xen/xen.h>
> +#include <xen/swiotlb-xen.h>
>  
>  static bool disable_dac_quirk __read_mostly;
>  
> @@ -34,24 +37,83 @@ int no_iommu __read_mostly;
>  /* Set this to 1 if there is a HW IOMMU in the system */
>  int iommu_detected __read_mostly = 0;
>  
> -extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
> +#ifdef CONFIG_SWIOTLB
> +bool x86_swiotlb_enable;
> +
> +static void __init pci_swiotlb_detect(void)
> +{
> +	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
> +	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
> +		x86_swiotlb_enable = true;
> +
> +	/*
> +	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
> +	 * devices that can't support DMA to encrypted memory.
> +	 */
> +	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
> +		x86_swiotlb_enable = true;
> +
> +	if (swiotlb_force == SWIOTLB_FORCE)
> +		x86_swiotlb_enable = true;
> +}
> +#else
> +static inline void __init pci_swiotlb_detect(void)
> +{
> +}
> +#endif /* CONFIG_SWIOTLB */
> +
> +#ifdef CONFIG_SWIOTLB_XEN
> +static bool xen_swiotlb;
> +
> +static void __init pci_xen_swiotlb_init(void)
> +{
> +	if (!xen_initial_domain() && !x86_swiotlb_enable &&
> +	    swiotlb_force != SWIOTLB_FORCE)
> +		return;
> +	x86_swiotlb_enable = true;
> +	xen_swiotlb = true;
> +	xen_swiotlb_init_early();
> +	dma_ops = &xen_swiotlb_dma_ops;
> +	if (IS_ENABLED(CONFIG_PCI))
> +		pci_request_acs();
> +}
> +
> +int pci_xen_swiotlb_init_late(void)
> +{
> +	int rc;
> +
> +	if (xen_swiotlb)
> +		return 0;
> +
> +	rc = xen_swiotlb_init();
> +	if (rc)
> +		return rc;
> +
> +	/* XXX: this switches the dma ops under live devices! */
> +	dma_ops = &xen_swiotlb_dma_ops;
> +	if (IS_ENABLED(CONFIG_PCI))
> +		pci_request_acs();
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
> +#else
> +static inline void __init pci_xen_swiotlb_init(void)
> +{
> +}
> +#endif /* CONFIG_SWIOTLB_XEN */
>  
>  void __init pci_iommu_alloc(void)
>  {
> -	struct iommu_table_entry *p;
> -
> -	sort_iommu_table(__iommu_table, __iommu_table_end);
> -	check_iommu_entries(__iommu_table, __iommu_table_end);
> -
> -	for (p = __iommu_table; p < __iommu_table_end; p++) {
> -		if (p && p->detect && p->detect() > 0) {
> -			p->flags |= IOMMU_DETECTED;
> -			if (p->early_init)
> -				p->early_init();
> -			if (p->flags & IOMMU_FINISH_IF_DETECTED)
> -				break;
> -		}
> +	if (xen_pv_domain()) {
> +		pci_xen_swiotlb_init();
> +		return;
>  	}
> +	pci_swiotlb_detect();
> +	gart_iommu_hole_init();
> +	amd_iommu_detect();
> +	detect_intel_iommu();
> +	if (x86_swiotlb_enable)
> +		swiotlb_init(0);
>  }
>  
>  /*
> @@ -102,7 +164,7 @@ static __init int iommu_setup(char *p)
>  		}
>  #ifdef CONFIG_SWIOTLB
>  		if (!strncmp(p, "soft", 4))
> -			swiotlb = 1;
> +			x86_swiotlb_enable = true;
>  #endif
>  		if (!strncmp(p, "pt", 2))
>  			iommu_set_default_passthrough(true);
> @@ -121,14 +183,17 @@ early_param("iommu", iommu_setup);
>  
>  static int __init pci_iommu_init(void)
>  {
> -	struct iommu_table_entry *p;
> -
>  	x86_init.iommu.iommu_init();
>  
> -	for (p = __iommu_table; p < __iommu_table_end; p++) {
> -		if (p && (p->flags & IOMMU_DETECTED) && p->late_init)
> -			p->late_init();
> +#ifdef CONFIG_SWIOTLB
> +	/* An IOMMU turned us off. */
> +	if (x86_swiotlb_enable) {
> +		pr_info("PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
> +		swiotlb_print_info();
> +	} else {
> +		swiotlb_exit();
>  	}
> +#endif
>  
>  	return 0;
>  }
> diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
> deleted file mode 100644
> index 42e92ec62973b..0000000000000
> --- a/arch/x86/kernel/pci-iommu_table.c
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -#include <linux/dma-mapping.h>
> -#include <asm/iommu_table.h>
> -#include <linux/string.h>
> -#include <linux/kallsyms.h>
> -
> -static struct iommu_table_entry * __init
> -find_dependents_of(struct iommu_table_entry *start,
> -		   struct iommu_table_entry *finish,
> -		   struct iommu_table_entry *q)
> -{
> -	struct iommu_table_entry *p;
> -
> -	if (!q)
> -		return NULL;
> -
> -	for (p = start; p < finish; p++)
> -		if (p->detect == q->depend)
> -			return p;
> -
> -	return NULL;
> -}
> -
> -
> -void __init sort_iommu_table(struct iommu_table_entry *start,
> -			     struct iommu_table_entry *finish) {
> -
> -	struct iommu_table_entry *p, *q, tmp;
> -
> -	for (p = start; p < finish; p++) {
> -again:
> -		q = find_dependents_of(start, finish, p);
> -		/* We are bit sneaky here. We use the memory address to figure
> -		 * out if the node we depend on is past our point, if so, swap.
> -		 */
> -		if (q > p) {
> -			tmp = *p;
> -			memmove(p, q, sizeof(*p));
> -			*q = tmp;
> -			goto again;
> -		}
> -	}
> -
> -}
> -
> -#ifdef DEBUG
> -void __init check_iommu_entries(struct iommu_table_entry *start,
> -				struct iommu_table_entry *finish)
> -{
> -	struct iommu_table_entry *p, *q, *x;
> -
> -	/* Simple cyclic dependency checker. */
> -	for (p = start; p < finish; p++) {
> -		q = find_dependents_of(start, finish, p);
> -		x = find_dependents_of(start, finish, q);
> -		if (p == x) {
> -			printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %pS depends on %pS and vice-versa. BREAKING IT.\n",
> -			       p->detect, q->detect);
> -			/* Heavy handed way..*/
> -			x->depend = NULL;
> -		}
> -	}
> -
> -	for (p = start; p < finish; p++) {
> -		q = find_dependents_of(p, finish, p);
> -		if (q && q > p) {
> -			printk(KERN_ERR "EXECUTION ORDER INVALID! %pS should be called before %pS!\n",
> -			       p->detect, q->detect);
> -		}
> -	}
> -}
> -#else
> -void __init check_iommu_entries(struct iommu_table_entry *start,
> -				       struct iommu_table_entry *finish)
> -{
> -}
> -#endif
> diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
> deleted file mode 100644
> index 814ab46a0dada..0000000000000
> --- a/arch/x86/kernel/pci-swiotlb.c
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -
> -#include <linux/pci.h>
> -#include <linux/cache.h>
> -#include <linux/init.h>
> -#include <linux/swiotlb.h>
> -#include <linux/memblock.h>
> -#include <linux/dma-direct.h>
> -#include <linux/cc_platform.h>
> -
> -#include <asm/iommu.h>
> -#include <asm/swiotlb.h>
> -#include <asm/dma.h>
> -#include <asm/xen/swiotlb-xen.h>
> -#include <asm/iommu_table.h>
> -
> -int swiotlb __read_mostly;
> -
> -/*
> - * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
> - *
> - * This returns non-zero if we are forced to use swiotlb (by the boot
> - * option).
> - */
> -int __init pci_swiotlb_detect_override(void)
> -{
> -	if (swiotlb_force == SWIOTLB_FORCE)
> -		swiotlb = 1;
> -
> -	return swiotlb;
> -}
> -IOMMU_INIT_FINISH(pci_swiotlb_detect_override,
> -		  pci_xen_swiotlb_detect,
> -		  pci_swiotlb_init,
> -		  pci_swiotlb_late_init);
> -
> -/*
> - * If 4GB or more detected (and iommu=off not set) or if SME is active
> - * then set swiotlb to 1 and return 1.
> - */
> -int __init pci_swiotlb_detect_4gb(void)
> -{
> -	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
> -	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
> -		swiotlb = 1;
> -
> -	/*
> -	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
> -	 * devices that can't support DMA to encrypted memory.
> -	 */
> -	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
> -		swiotlb = 1;
> -
> -	return swiotlb;
> -}
> -IOMMU_INIT(pci_swiotlb_detect_4gb,
> -	   pci_swiotlb_detect_override,
> -	   pci_swiotlb_init,
> -	   pci_swiotlb_late_init);
> -
> -void __init pci_swiotlb_init(void)
> -{
> -	if (swiotlb)
> -		swiotlb_init(0);
> -}
> -
> -void __init pci_swiotlb_late_init(void)
> -{
> -	/* An IOMMU turned us off. */
> -	if (!swiotlb)
> -		swiotlb_exit();
> -	else {
> -		printk(KERN_INFO "PCI-DMA: "
> -		       "Using software bounce buffering for IO (SWIOTLB)\n");
> -		swiotlb_print_info();
> -	}
> -}
> diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
> index f9af561c3cd4f..0c1154a1c4032 100644
> --- a/arch/x86/kernel/tboot.c
> +++ b/arch/x86/kernel/tboot.c
> @@ -24,7 +24,6 @@
>  #include <asm/processor.h>
>  #include <asm/bootparam.h>
>  #include <asm/pgalloc.h>
> -#include <asm/swiotlb.h>
>  #include <asm/fixmap.h>
>  #include <asm/proto.h>
>  #include <asm/setup.h>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index 7fda7f27e7620..f5f6dc2e80072 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -315,18 +315,6 @@ SECTIONS
>  		*(.altinstr_replacement)
>  	}
>  
> -	/*
> -	 * struct iommu_table_entry entries are injected in this section.
> -	 * It is an array of IOMMUs which during run time gets sorted depending
> -	 * on its dependency order. After rootfs_initcall is complete
> -	 * this section can be safely removed.
> -	 */
> -	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
> -		__iommu_table = .;
> -		*(.iommu_table)
> -		__iommu_table_end = .;
> -	}
> -
>  	. = ALIGN(8);
>  	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
>  		__apicdrivers = .;
> diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
> index 4953260e281c3..3c5b52fbe4a7f 100644
> --- a/arch/x86/xen/Makefile
> +++ b/arch/x86/xen/Makefile
> @@ -47,6 +47,4 @@ obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
>  
>  obj-$(CONFIG_XEN_PV_DOM0)	+= vga.o
>  
> -obj-$(CONFIG_SWIOTLB_XEN)	+= pci-swiotlb-xen.o
> -
>  obj-$(CONFIG_XEN_EFI)		+= efi.o
> diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
> deleted file mode 100644
> index 46df59aeaa06a..0000000000000
> --- a/arch/x86/xen/pci-swiotlb-xen.c
> +++ /dev/null
> @@ -1,96 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -
> -/* Glue code to lib/swiotlb-xen.c */
> -
> -#include <linux/dma-map-ops.h>
> -#include <linux/pci.h>
> -#include <xen/swiotlb-xen.h>
> -
> -#include <asm/xen/hypervisor.h>
> -#include <xen/xen.h>
> -#include <asm/iommu_table.h>
> -
> -
> -#include <asm/xen/swiotlb-xen.h>
> -#ifdef CONFIG_X86_64
> -#include <asm/iommu.h>
> -#include <asm/dma.h>
> -#endif
> -#include <linux/export.h>
> -
> -static int xen_swiotlb __read_mostly;
> -
> -/*
> - * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
> - *
> - * This returns non-zero if we are forced to use xen_swiotlb (by the boot
> - * option).
> - */
> -int __init pci_xen_swiotlb_detect(void)
> -{
> -
> -	if (!xen_pv_domain())
> -		return 0;
> -
> -	/* If running as PV guest, either iommu=soft, or swiotlb=force will
> -	 * activate this IOMMU. If running as PV privileged, activate it
> -	 * irregardless.
> -	 */
> -	if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
> -		xen_swiotlb = 1;
> -
> -	/* If we are running under Xen, we MUST disable the native SWIOTLB.
> -	 * Don't worry about swiotlb_force flag activating the native, as
> -	 * the 'swiotlb' flag is the only one turning it on. */
> -	swiotlb = 0;
> -
> -#ifdef CONFIG_X86_64
> -	/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
> -	 * (so no iommu=X command line over-writes).
> -	 * Considering that PV guests do not want the *native SWIOTLB* but
> -	 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
> -	 */
> -	if (max_pfn > MAX_DMA32_PFN)
> -		no_iommu = 1;
> -#endif
> -	return xen_swiotlb;
> -}
> -
> -static void __init pci_xen_swiotlb_init(void)
> -{
> -	if (xen_swiotlb) {
> -		xen_swiotlb_init_early();
> -		dma_ops = &xen_swiotlb_dma_ops;
> -
> -#ifdef CONFIG_PCI
> -		/* Make sure ACS will be enabled */
> -		pci_request_acs();
> -#endif
> -	}
> -}
> -
> -int pci_xen_swiotlb_init_late(void)
> -{
> -	int rc;
> -
> -	if (xen_swiotlb)
> -		return 0;
> -
> -	rc = xen_swiotlb_init();
> -	if (rc)
> -		return rc;
> -
> -	dma_ops = &xen_swiotlb_dma_ops;
> -#ifdef CONFIG_PCI
> -	/* Make sure ACS will be enabled */
> -	pci_request_acs();
> -#endif
> -
> -	return 0;
> -}
> -EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
> -
> -IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
> -		  NULL,
> -		  pci_xen_swiotlb_init,
> -		  NULL);
> diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> index b4a798c7b347f..1a3ad58ba8465 100644
> --- a/drivers/iommu/amd/init.c
> +++ b/drivers/iommu/amd/init.c
> @@ -27,7 +27,6 @@
>  #include <asm/apic.h>
>  #include <asm/gart.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
>  #include <asm/io_apic.h>
>  #include <asm/irq_remapping.h>
>  #include <asm/set_memory.h>
> @@ -3257,11 +3256,6 @@ __setup("ivrs_ioapic",		parse_ivrs_ioapic);
>  __setup("ivrs_hpet",		parse_ivrs_hpet);
>  __setup("ivrs_acpihid",		parse_ivrs_acpihid);
>  
> -IOMMU_INIT_FINISH(amd_iommu_detect,
> -		  gart_iommu_hole_init,
> -		  NULL,
> -		  NULL);
> -
>  bool amd_iommu_v2_supported(void)
>  {
>  	return amd_iommu_v2_present;
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index a1ada7bff44e6..b47220ac09eaa 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -1840,7 +1840,10 @@ void amd_iommu_domain_update(struct protection_domain *domain)
>  
>  static void __init amd_iommu_init_dma_ops(void)
>  {
> -	swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
> +	if (iommu_default_passthrough() || sme_me_mask)
> +		x86_swiotlb_enable = true;
> +	else
> +		x86_swiotlb_enable = false;
>  }
>  
>  int __init amd_iommu_init_api(void)
> diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
> index 4de960834a1b2..592c1e1a5d4b9 100644
> --- a/drivers/iommu/intel/dmar.c
> +++ b/drivers/iommu/intel/dmar.c
> @@ -30,7 +30,6 @@
>  #include <linux/numa.h>
>  #include <linux/limits.h>
>  #include <asm/irq_remapping.h>
> -#include <asm/iommu_table.h>
>  #include <trace/events/intel_iommu.h>
>  
>  #include "../irq_remapping.h"
> @@ -912,7 +911,7 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)
>  	return 0;
>  }
>  
> -int __init detect_intel_iommu(void)
> +void __init detect_intel_iommu(void)
>  {
>  	int ret;
>  	struct dmar_res_callback validate_drhd_cb = {
> @@ -945,8 +944,6 @@ int __init detect_intel_iommu(void)
>  		dmar_tbl = NULL;
>  	}
>  	up_write(&dmar_global_lock);
> -
> -	return ret ? ret : 1;
>  }
>  
>  static void unmap_iommu(struct intel_iommu *iommu)
> @@ -2164,7 +2161,6 @@ static int __init dmar_free_unused_resources(void)
>  }
>  
>  late_initcall(dmar_free_unused_resources);
> -IOMMU_INIT_POST(detect_intel_iommu);
>  
>  /*
>   * DMAR Hotplug Support
> diff --git a/include/linux/dmar.h b/include/linux/dmar.h
> index 45e903d847335..cbd714a198a0a 100644
> --- a/include/linux/dmar.h
> +++ b/include/linux/dmar.h
> @@ -121,7 +121,7 @@ extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
>  				 u16 segment, struct dmar_dev_scope *devices,
>  				 int count);
>  /* Intel IOMMU detection */
> -extern int detect_intel_iommu(void);
> +void detect_intel_iommu(void);
>  extern int enable_drhd_fault_handling(void);
>  extern int dmar_device_add(acpi_handle handle);
>  extern int dmar_device_remove(acpi_handle handle);
> @@ -197,6 +197,10 @@ static inline bool dmar_platform_optin(void)
>  	return false;
>  }
>  
> +static inline void detect_intel_iommu(void)
> +{
> +}
> +
>  #endif /* CONFIG_DMAR_TABLE */
>  
>  struct irte {
> -- 
> 2.30.2
> 

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 07/15] x86: remove the IOMMU table infrastructure
@ 2022-04-07  0:20     ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:20 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Mon, Apr 04, 2022 at 07:05:51AM +0200, Christoph Hellwig wrote:
> The IOMMU table tries to separate the different IOMMUs into different
> backends, but actually requires various cross calls.
> 
> Rewrite the code to do the generic swiotlb/swiotlb-xen setup directly
> in pci-dma.c and then just call into the IOMMU drivers.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Hey Christoph,

There is a bit of background behind this - this whole IOMMU table
dynamic was done as at that point of time the pci_iommu_alloc was getting
way to unwieldy - and there needed to be a more 'structured' way with
dependencies.

Hence this creation... But as Christoph points out - it has gotten out
of hand. So smashing it back to a more simplistic mechanism is good.

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!

> ---
>  arch/ia64/include/asm/iommu_table.h    |   7 --
>  arch/x86/include/asm/dma-mapping.h     |   1 -
>  arch/x86/include/asm/gart.h            |   5 +-
>  arch/x86/include/asm/iommu.h           |   6 ++
>  arch/x86/include/asm/iommu_table.h     | 102 -----------------------
>  arch/x86/include/asm/swiotlb.h         |  30 -------
>  arch/x86/include/asm/xen/swiotlb-xen.h |   2 -
>  arch/x86/kernel/Makefile               |   2 -
>  arch/x86/kernel/amd_gart_64.c          |   5 +-
>  arch/x86/kernel/aperture_64.c          |  14 ++--
>  arch/x86/kernel/pci-dma.c              | 107 ++++++++++++++++++++-----
>  arch/x86/kernel/pci-iommu_table.c      |  77 ------------------
>  arch/x86/kernel/pci-swiotlb.c          |  77 ------------------
>  arch/x86/kernel/tboot.c                |   1 -
>  arch/x86/kernel/vmlinux.lds.S          |  12 ---
>  arch/x86/xen/Makefile                  |   2 -
>  arch/x86/xen/pci-swiotlb-xen.c         |  96 ----------------------
>  drivers/iommu/amd/init.c               |   6 --
>  drivers/iommu/amd/iommu.c              |   5 +-
>  drivers/iommu/intel/dmar.c             |   6 +-
>  include/linux/dmar.h                   |   6 +-
>  21 files changed, 110 insertions(+), 459 deletions(-)
>  delete mode 100644 arch/ia64/include/asm/iommu_table.h
>  delete mode 100644 arch/x86/include/asm/iommu_table.h
>  delete mode 100644 arch/x86/include/asm/swiotlb.h
>  delete mode 100644 arch/x86/kernel/pci-iommu_table.c
>  delete mode 100644 arch/x86/kernel/pci-swiotlb.c
>  delete mode 100644 arch/x86/xen/pci-swiotlb-xen.c
> 
> diff --git a/arch/ia64/include/asm/iommu_table.h b/arch/ia64/include/asm/iommu_table.h
> deleted file mode 100644
> index cc96116ac276a..0000000000000
> --- a/arch/ia64/include/asm/iommu_table.h
> +++ /dev/null
> @@ -1,7 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_IA64_IOMMU_TABLE_H
> -#define _ASM_IA64_IOMMU_TABLE_H
> -
> -#define IOMMU_INIT_POST(_detect)
> -
> -#endif /* _ASM_IA64_IOMMU_TABLE_H */
> diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
> index bb1654fe0ce74..256fd8115223d 100644
> --- a/arch/x86/include/asm/dma-mapping.h
> +++ b/arch/x86/include/asm/dma-mapping.h
> @@ -9,7 +9,6 @@
>  
>  #include <linux/scatterlist.h>
>  #include <asm/io.h>
> -#include <asm/swiotlb.h>
>  
>  extern int iommu_merge;
>  extern int panic_on_overflow;
> diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
> index 3185565743459..5af8088a10df6 100644
> --- a/arch/x86/include/asm/gart.h
> +++ b/arch/x86/include/asm/gart.h
> @@ -38,7 +38,7 @@ extern int gart_iommu_aperture_disabled;
>  extern void early_gart_iommu_check(void);
>  extern int gart_iommu_init(void);
>  extern void __init gart_parse_options(char *);
> -extern int gart_iommu_hole_init(void);
> +void gart_iommu_hole_init(void);
>  
>  #else
>  #define gart_iommu_aperture            0
> @@ -51,9 +51,8 @@ static inline void early_gart_iommu_check(void)
>  static inline void gart_parse_options(char *options)
>  {
>  }
> -static inline int gart_iommu_hole_init(void)
> +static inline void gart_iommu_hole_init(void)
>  {
> -	return -ENODEV;
>  }
>  #endif
>  
> diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
> index bf1ed2ddc74bd..dba89ed40d38d 100644
> --- a/arch/x86/include/asm/iommu.h
> +++ b/arch/x86/include/asm/iommu.h
> @@ -9,6 +9,12 @@
>  extern int force_iommu, no_iommu;
>  extern int iommu_detected;
>  
> +#ifdef CONFIG_SWIOTLB
> +extern bool x86_swiotlb_enable;
> +#else
> +#define x86_swiotlb_enable false
> +#endif
> +
>  /* 10 seconds */
>  #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
>  
> diff --git a/arch/x86/include/asm/iommu_table.h b/arch/x86/include/asm/iommu_table.h
> deleted file mode 100644
> index 1fb3fd1a83c25..0000000000000
> --- a/arch/x86/include/asm/iommu_table.h
> +++ /dev/null
> @@ -1,102 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_X86_IOMMU_TABLE_H
> -#define _ASM_X86_IOMMU_TABLE_H
> -
> -#include <asm/swiotlb.h>
> -
> -/*
> - * History lesson:
> - * The execution chain of IOMMUs in 2.6.36 looks as so:
> - *
> - *            [xen-swiotlb]
> - *                 |
> - *         +----[swiotlb *]--+
> - *        /         |         \
> - *       /          |          \
> - *    [GART]     [Calgary]  [Intel VT-d]
> - *     /
> - *    /
> - * [AMD-Vi]
> - *
> - * *: if SWIOTLB detected 'iommu=soft'/'swiotlb=force' it would skip
> - * over the rest of IOMMUs and unconditionally initialize the SWIOTLB.
> - * Also it would surreptitiously initialize set the swiotlb=1 if there were
> - * more than 4GB and if the user did not pass in 'iommu=off'. The swiotlb
> - * flag would be turned off by all IOMMUs except the Calgary one.
> - *
> - * The IOMMU_INIT* macros allow a similar tree (or more complex if desired)
> - * to be built by defining who we depend on.
> - *
> - * And all that needs to be done is to use one of the macros in the IOMMU
> - * and the pci-dma.c will take care of the rest.
> - */
> -
> -struct iommu_table_entry {
> -	initcall_t	detect;
> -	initcall_t	depend;
> -	void		(*early_init)(void); /* No memory allocate available. */
> -	void		(*late_init)(void); /* Yes, can allocate memory. */
> -#define IOMMU_FINISH_IF_DETECTED (1<<0)
> -#define IOMMU_DETECTED		 (1<<1)
> -	int		flags;
> -};
> -/*
> - * Macro fills out an entry in the .iommu_table that is equivalent
> - * to the fields that 'struct iommu_table_entry' has. The entries
> - * that are put in the .iommu_table section are not put in any order
> - * hence during boot-time we will have to resort them based on
> - * dependency. */
> -
> -
> -#define __IOMMU_INIT(_detect, _depend, _early_init, _late_init, _finish)\
> -	static const struct iommu_table_entry				\
> -		__iommu_entry_##_detect __used				\
> -	__attribute__ ((unused, __section__(".iommu_table"),		\
> -			aligned((sizeof(void *)))))	\
> -	= {_detect, _depend, _early_init, _late_init,			\
> -	   _finish ? IOMMU_FINISH_IF_DETECTED : 0}
> -/*
> - * The simplest IOMMU definition. Provide the detection routine
> - * and it will be run after the SWIOTLB and the other IOMMUs
> - * that utilize this macro. If the IOMMU is detected (ie, the
> - * detect routine returns a positive value), the other IOMMUs
> - * are also checked. You can use IOMMU_INIT_POST_FINISH if you prefer
> - * to stop detecting the other IOMMUs after yours has been detected.
> - */
> -#define IOMMU_INIT_POST(_detect)					\
> -	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 0)
> -
> -#define IOMMU_INIT_POST_FINISH(detect)					\
> -	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 1)
> -
> -/*
> - * A more sophisticated version of IOMMU_INIT. This variant requires:
> - *  a). A detection routine function.
> - *  b). The name of the detection routine we depend on to get called
> - *      before us.
> - *  c). The init routine which gets called if the detection routine
> - *      returns a positive value from the pci_iommu_alloc. This means
> - *      no presence of a memory allocator.
> - *  d). Similar to the 'init', except that this gets called from pci_iommu_init
> - *      where we do have a memory allocator.
> - *
> - * The standard IOMMU_INIT differs from the IOMMU_INIT_FINISH variant
> - * in that the former will continue detecting other IOMMUs in the call
> - * list after the detection routine returns a positive number, while the
> - * latter will stop the execution chain upon first successful detection.
> - * Both variants will still call the 'init' and 'late_init' functions if
> - * they are set.
> - */
> -#define IOMMU_INIT_FINISH(_detect, _depend, _init, _late_init)		\
> -	__IOMMU_INIT(_detect, _depend, _init, _late_init, 1)
> -
> -#define IOMMU_INIT(_detect, _depend, _init, _late_init)			\
> -	__IOMMU_INIT(_detect, _depend, _init, _late_init, 0)
> -
> -void sort_iommu_table(struct iommu_table_entry *start,
> -		      struct iommu_table_entry *finish);
> -
> -void check_iommu_entries(struct iommu_table_entry *start,
> -			 struct iommu_table_entry *finish);
> -
> -#endif /* _ASM_X86_IOMMU_TABLE_H */
> diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
> deleted file mode 100644
> index ff6c92eff035a..0000000000000
> --- a/arch/x86/include/asm/swiotlb.h
> +++ /dev/null
> @@ -1,30 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_X86_SWIOTLB_H
> -#define _ASM_X86_SWIOTLB_H
> -
> -#include <linux/swiotlb.h>
> -
> -#ifdef CONFIG_SWIOTLB
> -extern int swiotlb;
> -extern int __init pci_swiotlb_detect_override(void);
> -extern int __init pci_swiotlb_detect_4gb(void);
> -extern void __init pci_swiotlb_init(void);
> -extern void __init pci_swiotlb_late_init(void);
> -#else
> -#define swiotlb 0
> -static inline int pci_swiotlb_detect_override(void)
> -{
> -	return 0;
> -}
> -static inline int pci_swiotlb_detect_4gb(void)
> -{
> -	return 0;
> -}
> -static inline void pci_swiotlb_init(void)
> -{
> -}
> -static inline void pci_swiotlb_late_init(void)
> -{
> -}
> -#endif
> -#endif /* _ASM_X86_SWIOTLB_H */
> diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h
> index 66b4ddde77430..e5a90b42e4dde 100644
> --- a/arch/x86/include/asm/xen/swiotlb-xen.h
> +++ b/arch/x86/include/asm/xen/swiotlb-xen.h
> @@ -3,10 +3,8 @@
>  #define _ASM_X86_SWIOTLB_XEN_H
>  
>  #ifdef CONFIG_SWIOTLB_XEN
> -extern int __init pci_xen_swiotlb_detect(void);
>  extern int pci_xen_swiotlb_init_late(void);
>  #else
> -#define pci_xen_swiotlb_detect NULL
>  static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
>  #endif
>  
> diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
> index c41ef42adbe8a..e17b7e92a3fa3 100644
> --- a/arch/x86/kernel/Makefile
> +++ b/arch/x86/kernel/Makefile
> @@ -68,7 +68,6 @@ obj-y			+= bootflag.o e820.o
>  obj-y			+= pci-dma.o quirks.o topology.o kdebugfs.o
>  obj-y			+= alternative.o i8253.o hw_breakpoint.o
>  obj-y			+= tsc.o tsc_msr.o io_delay.o rtc.o
> -obj-y			+= pci-iommu_table.o
>  obj-y			+= resource.o
>  obj-y			+= irqflags.o
>  obj-y			+= static_call.o
> @@ -134,7 +133,6 @@ obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
>  
>  obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
>  
> -obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
>  obj-$(CONFIG_OF)			+= devicetree.o
>  obj-$(CONFIG_UPROBES)			+= uprobes.o
>  
> diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
> index ed837383de5c8..194d54eed5376 100644
> --- a/arch/x86/kernel/amd_gart_64.c
> +++ b/arch/x86/kernel/amd_gart_64.c
> @@ -38,11 +38,9 @@
>  #include <asm/iommu.h>
>  #include <asm/gart.h>
>  #include <asm/set_memory.h>
> -#include <asm/swiotlb.h>
>  #include <asm/dma.h>
>  #include <asm/amd_nb.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
>  
>  static unsigned long iommu_bus_base;	/* GART remapping area (physical) */
>  static unsigned long iommu_size;	/* size of remapping area bytes */
> @@ -808,7 +806,7 @@ int __init gart_iommu_init(void)
>  	flush_gart();
>  	dma_ops = &gart_dma_ops;
>  	x86_platform.iommu_shutdown = gart_iommu_shutdown;
> -	swiotlb = 0;
> +	x86_swiotlb_enable = false;
>  
>  	return 0;
>  }
> @@ -842,4 +840,3 @@ void __init gart_parse_options(char *p)
>  		}
>  	}
>  }
> -IOMMU_INIT_POST(gart_iommu_hole_init);
> diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
> index af3ba08b684b5..7a5630d904b23 100644
> --- a/arch/x86/kernel/aperture_64.c
> +++ b/arch/x86/kernel/aperture_64.c
> @@ -392,7 +392,7 @@ void __init early_gart_iommu_check(void)
>  
>  static int __initdata printed_gart_size_msg;
>  
> -int __init gart_iommu_hole_init(void)
> +void __init gart_iommu_hole_init(void)
>  {
>  	u32 agp_aper_base = 0, agp_aper_order = 0;
>  	u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0;
> @@ -401,11 +401,11 @@ int __init gart_iommu_hole_init(void)
>  	int i, node;
>  
>  	if (!amd_gart_present())
> -		return -ENODEV;
> +		return;
>  
>  	if (gart_iommu_aperture_disabled || !fix_aperture ||
>  	    !early_pci_allowed())
> -		return -ENODEV;
> +		return;
>  
>  	pr_info("Checking aperture...\n");
>  
> @@ -491,10 +491,8 @@ int __init gart_iommu_hole_init(void)
>  			 * and fixed up the northbridge
>  			 */
>  			exclude_from_core(last_aper_base, last_aper_order);
> -
> -			return 1;
>  		}
> -		return 0;
> +		return;
>  	}
>  
>  	if (!fallback_aper_force) {
> @@ -527,7 +525,7 @@ int __init gart_iommu_hole_init(void)
>  			panic("Not enough memory for aperture");
>  		}
>  	} else {
> -		return 0;
> +		return;
>  	}
>  
>  	/*
> @@ -561,6 +559,4 @@ int __init gart_iommu_hole_init(void)
>  	}
>  
>  	set_up_gart_resume(aper_order, aper_alloc);
> -
> -	return 1;
>  }
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index de234e7a8962e..df96926421be0 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -7,13 +7,16 @@
>  #include <linux/memblock.h>
>  #include <linux/gfp.h>
>  #include <linux/pci.h>
> +#include <linux/amd-iommu.h>
>  
>  #include <asm/proto.h>
>  #include <asm/dma.h>
>  #include <asm/iommu.h>
>  #include <asm/gart.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
> +
> +#include <xen/xen.h>
> +#include <xen/swiotlb-xen.h>
>  
>  static bool disable_dac_quirk __read_mostly;
>  
> @@ -34,24 +37,83 @@ int no_iommu __read_mostly;
>  /* Set this to 1 if there is a HW IOMMU in the system */
>  int iommu_detected __read_mostly = 0;
>  
> -extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
> +#ifdef CONFIG_SWIOTLB
> +bool x86_swiotlb_enable;
> +
> +static void __init pci_swiotlb_detect(void)
> +{
> +	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
> +	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
> +		x86_swiotlb_enable = true;
> +
> +	/*
> +	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
> +	 * devices that can't support DMA to encrypted memory.
> +	 */
> +	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
> +		x86_swiotlb_enable = true;
> +
> +	if (swiotlb_force == SWIOTLB_FORCE)
> +		x86_swiotlb_enable = true;
> +}
> +#else
> +static inline void __init pci_swiotlb_detect(void)
> +{
> +}
> +#endif /* CONFIG_SWIOTLB */
> +
> +#ifdef CONFIG_SWIOTLB_XEN
> +static bool xen_swiotlb;
> +
> +static void __init pci_xen_swiotlb_init(void)
> +{
> +	if (!xen_initial_domain() && !x86_swiotlb_enable &&
> +	    swiotlb_force != SWIOTLB_FORCE)
> +		return;
> +	x86_swiotlb_enable = true;
> +	xen_swiotlb = true;
> +	xen_swiotlb_init_early();
> +	dma_ops = &xen_swiotlb_dma_ops;
> +	if (IS_ENABLED(CONFIG_PCI))
> +		pci_request_acs();
> +}
> +
> +int pci_xen_swiotlb_init_late(void)
> +{
> +	int rc;
> +
> +	if (xen_swiotlb)
> +		return 0;
> +
> +	rc = xen_swiotlb_init();
> +	if (rc)
> +		return rc;
> +
> +	/* XXX: this switches the dma ops under live devices! */
> +	dma_ops = &xen_swiotlb_dma_ops;
> +	if (IS_ENABLED(CONFIG_PCI))
> +		pci_request_acs();
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
> +#else
> +static inline void __init pci_xen_swiotlb_init(void)
> +{
> +}
> +#endif /* CONFIG_SWIOTLB_XEN */
>  
>  void __init pci_iommu_alloc(void)
>  {
> -	struct iommu_table_entry *p;
> -
> -	sort_iommu_table(__iommu_table, __iommu_table_end);
> -	check_iommu_entries(__iommu_table, __iommu_table_end);
> -
> -	for (p = __iommu_table; p < __iommu_table_end; p++) {
> -		if (p && p->detect && p->detect() > 0) {
> -			p->flags |= IOMMU_DETECTED;
> -			if (p->early_init)
> -				p->early_init();
> -			if (p->flags & IOMMU_FINISH_IF_DETECTED)
> -				break;
> -		}
> +	if (xen_pv_domain()) {
> +		pci_xen_swiotlb_init();
> +		return;
>  	}
> +	pci_swiotlb_detect();
> +	gart_iommu_hole_init();
> +	amd_iommu_detect();
> +	detect_intel_iommu();
> +	if (x86_swiotlb_enable)
> +		swiotlb_init(0);
>  }
>  
>  /*
> @@ -102,7 +164,7 @@ static __init int iommu_setup(char *p)
>  		}
>  #ifdef CONFIG_SWIOTLB
>  		if (!strncmp(p, "soft", 4))
> -			swiotlb = 1;
> +			x86_swiotlb_enable = true;
>  #endif
>  		if (!strncmp(p, "pt", 2))
>  			iommu_set_default_passthrough(true);
> @@ -121,14 +183,17 @@ early_param("iommu", iommu_setup);
>  
>  static int __init pci_iommu_init(void)
>  {
> -	struct iommu_table_entry *p;
> -
>  	x86_init.iommu.iommu_init();
>  
> -	for (p = __iommu_table; p < __iommu_table_end; p++) {
> -		if (p && (p->flags & IOMMU_DETECTED) && p->late_init)
> -			p->late_init();
> +#ifdef CONFIG_SWIOTLB
> +	/* An IOMMU turned us off. */
> +	if (x86_swiotlb_enable) {
> +		pr_info("PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
> +		swiotlb_print_info();
> +	} else {
> +		swiotlb_exit();
>  	}
> +#endif
>  
>  	return 0;
>  }
> diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
> deleted file mode 100644
> index 42e92ec62973b..0000000000000
> --- a/arch/x86/kernel/pci-iommu_table.c
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -#include <linux/dma-mapping.h>
> -#include <asm/iommu_table.h>
> -#include <linux/string.h>
> -#include <linux/kallsyms.h>
> -
> -static struct iommu_table_entry * __init
> -find_dependents_of(struct iommu_table_entry *start,
> -		   struct iommu_table_entry *finish,
> -		   struct iommu_table_entry *q)
> -{
> -	struct iommu_table_entry *p;
> -
> -	if (!q)
> -		return NULL;
> -
> -	for (p = start; p < finish; p++)
> -		if (p->detect == q->depend)
> -			return p;
> -
> -	return NULL;
> -}
> -
> -
> -void __init sort_iommu_table(struct iommu_table_entry *start,
> -			     struct iommu_table_entry *finish) {
> -
> -	struct iommu_table_entry *p, *q, tmp;
> -
> -	for (p = start; p < finish; p++) {
> -again:
> -		q = find_dependents_of(start, finish, p);
> -		/* We are bit sneaky here. We use the memory address to figure
> -		 * out if the node we depend on is past our point, if so, swap.
> -		 */
> -		if (q > p) {
> -			tmp = *p;
> -			memmove(p, q, sizeof(*p));
> -			*q = tmp;
> -			goto again;
> -		}
> -	}
> -
> -}
> -
> -#ifdef DEBUG
> -void __init check_iommu_entries(struct iommu_table_entry *start,
> -				struct iommu_table_entry *finish)
> -{
> -	struct iommu_table_entry *p, *q, *x;
> -
> -	/* Simple cyclic dependency checker. */
> -	for (p = start; p < finish; p++) {
> -		q = find_dependents_of(start, finish, p);
> -		x = find_dependents_of(start, finish, q);
> -		if (p == x) {
> -			printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %pS depends on %pS and vice-versa. BREAKING IT.\n",
> -			       p->detect, q->detect);
> -			/* Heavy handed way..*/
> -			x->depend = NULL;
> -		}
> -	}
> -
> -	for (p = start; p < finish; p++) {
> -		q = find_dependents_of(p, finish, p);
> -		if (q && q > p) {
> -			printk(KERN_ERR "EXECUTION ORDER INVALID! %pS should be called before %pS!\n",
> -			       p->detect, q->detect);
> -		}
> -	}
> -}
> -#else
> -void __init check_iommu_entries(struct iommu_table_entry *start,
> -				       struct iommu_table_entry *finish)
> -{
> -}
> -#endif
> diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
> deleted file mode 100644
> index 814ab46a0dada..0000000000000
> --- a/arch/x86/kernel/pci-swiotlb.c
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -
> -#include <linux/pci.h>
> -#include <linux/cache.h>
> -#include <linux/init.h>
> -#include <linux/swiotlb.h>
> -#include <linux/memblock.h>
> -#include <linux/dma-direct.h>
> -#include <linux/cc_platform.h>
> -
> -#include <asm/iommu.h>
> -#include <asm/swiotlb.h>
> -#include <asm/dma.h>
> -#include <asm/xen/swiotlb-xen.h>
> -#include <asm/iommu_table.h>
> -
> -int swiotlb __read_mostly;
> -
> -/*
> - * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
> - *
> - * This returns non-zero if we are forced to use swiotlb (by the boot
> - * option).
> - */
> -int __init pci_swiotlb_detect_override(void)
> -{
> -	if (swiotlb_force == SWIOTLB_FORCE)
> -		swiotlb = 1;
> -
> -	return swiotlb;
> -}
> -IOMMU_INIT_FINISH(pci_swiotlb_detect_override,
> -		  pci_xen_swiotlb_detect,
> -		  pci_swiotlb_init,
> -		  pci_swiotlb_late_init);
> -
> -/*
> - * If 4GB or more detected (and iommu=off not set) or if SME is active
> - * then set swiotlb to 1 and return 1.
> - */
> -int __init pci_swiotlb_detect_4gb(void)
> -{
> -	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
> -	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
> -		swiotlb = 1;
> -
> -	/*
> -	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
> -	 * devices that can't support DMA to encrypted memory.
> -	 */
> -	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
> -		swiotlb = 1;
> -
> -	return swiotlb;
> -}
> -IOMMU_INIT(pci_swiotlb_detect_4gb,
> -	   pci_swiotlb_detect_override,
> -	   pci_swiotlb_init,
> -	   pci_swiotlb_late_init);
> -
> -void __init pci_swiotlb_init(void)
> -{
> -	if (swiotlb)
> -		swiotlb_init(0);
> -}
> -
> -void __init pci_swiotlb_late_init(void)
> -{
> -	/* An IOMMU turned us off. */
> -	if (!swiotlb)
> -		swiotlb_exit();
> -	else {
> -		printk(KERN_INFO "PCI-DMA: "
> -		       "Using software bounce buffering for IO (SWIOTLB)\n");
> -		swiotlb_print_info();
> -	}
> -}
> diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
> index f9af561c3cd4f..0c1154a1c4032 100644
> --- a/arch/x86/kernel/tboot.c
> +++ b/arch/x86/kernel/tboot.c
> @@ -24,7 +24,6 @@
>  #include <asm/processor.h>
>  #include <asm/bootparam.h>
>  #include <asm/pgalloc.h>
> -#include <asm/swiotlb.h>
>  #include <asm/fixmap.h>
>  #include <asm/proto.h>
>  #include <asm/setup.h>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index 7fda7f27e7620..f5f6dc2e80072 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -315,18 +315,6 @@ SECTIONS
>  		*(.altinstr_replacement)
>  	}
>  
> -	/*
> -	 * struct iommu_table_entry entries are injected in this section.
> -	 * It is an array of IOMMUs which during run time gets sorted depending
> -	 * on its dependency order. After rootfs_initcall is complete
> -	 * this section can be safely removed.
> -	 */
> -	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
> -		__iommu_table = .;
> -		*(.iommu_table)
> -		__iommu_table_end = .;
> -	}
> -
>  	. = ALIGN(8);
>  	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
>  		__apicdrivers = .;
> diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
> index 4953260e281c3..3c5b52fbe4a7f 100644
> --- a/arch/x86/xen/Makefile
> +++ b/arch/x86/xen/Makefile
> @@ -47,6 +47,4 @@ obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
>  
>  obj-$(CONFIG_XEN_PV_DOM0)	+= vga.o
>  
> -obj-$(CONFIG_SWIOTLB_XEN)	+= pci-swiotlb-xen.o
> -
>  obj-$(CONFIG_XEN_EFI)		+= efi.o
> diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
> deleted file mode 100644
> index 46df59aeaa06a..0000000000000
> --- a/arch/x86/xen/pci-swiotlb-xen.c
> +++ /dev/null
> @@ -1,96 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -
> -/* Glue code to lib/swiotlb-xen.c */
> -
> -#include <linux/dma-map-ops.h>
> -#include <linux/pci.h>
> -#include <xen/swiotlb-xen.h>
> -
> -#include <asm/xen/hypervisor.h>
> -#include <xen/xen.h>
> -#include <asm/iommu_table.h>
> -
> -
> -#include <asm/xen/swiotlb-xen.h>
> -#ifdef CONFIG_X86_64
> -#include <asm/iommu.h>
> -#include <asm/dma.h>
> -#endif
> -#include <linux/export.h>
> -
> -static int xen_swiotlb __read_mostly;
> -
> -/*
> - * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
> - *
> - * This returns non-zero if we are forced to use xen_swiotlb (by the boot
> - * option).
> - */
> -int __init pci_xen_swiotlb_detect(void)
> -{
> -
> -	if (!xen_pv_domain())
> -		return 0;
> -
> -	/* If running as PV guest, either iommu=soft, or swiotlb=force will
> -	 * activate this IOMMU. If running as PV privileged, activate it
> -	 * irregardless.
> -	 */
> -	if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
> -		xen_swiotlb = 1;
> -
> -	/* If we are running under Xen, we MUST disable the native SWIOTLB.
> -	 * Don't worry about swiotlb_force flag activating the native, as
> -	 * the 'swiotlb' flag is the only one turning it on. */
> -	swiotlb = 0;
> -
> -#ifdef CONFIG_X86_64
> -	/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
> -	 * (so no iommu=X command line over-writes).
> -	 * Considering that PV guests do not want the *native SWIOTLB* but
> -	 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
> -	 */
> -	if (max_pfn > MAX_DMA32_PFN)
> -		no_iommu = 1;
> -#endif
> -	return xen_swiotlb;
> -}
> -
> -static void __init pci_xen_swiotlb_init(void)
> -{
> -	if (xen_swiotlb) {
> -		xen_swiotlb_init_early();
> -		dma_ops = &xen_swiotlb_dma_ops;
> -
> -#ifdef CONFIG_PCI
> -		/* Make sure ACS will be enabled */
> -		pci_request_acs();
> -#endif
> -	}
> -}
> -
> -int pci_xen_swiotlb_init_late(void)
> -{
> -	int rc;
> -
> -	if (xen_swiotlb)
> -		return 0;
> -
> -	rc = xen_swiotlb_init();
> -	if (rc)
> -		return rc;
> -
> -	dma_ops = &xen_swiotlb_dma_ops;
> -#ifdef CONFIG_PCI
> -	/* Make sure ACS will be enabled */
> -	pci_request_acs();
> -#endif
> -
> -	return 0;
> -}
> -EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
> -
> -IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
> -		  NULL,
> -		  pci_xen_swiotlb_init,
> -		  NULL);
> diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> index b4a798c7b347f..1a3ad58ba8465 100644
> --- a/drivers/iommu/amd/init.c
> +++ b/drivers/iommu/amd/init.c
> @@ -27,7 +27,6 @@
>  #include <asm/apic.h>
>  #include <asm/gart.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
>  #include <asm/io_apic.h>
>  #include <asm/irq_remapping.h>
>  #include <asm/set_memory.h>
> @@ -3257,11 +3256,6 @@ __setup("ivrs_ioapic",		parse_ivrs_ioapic);
>  __setup("ivrs_hpet",		parse_ivrs_hpet);
>  __setup("ivrs_acpihid",		parse_ivrs_acpihid);
>  
> -IOMMU_INIT_FINISH(amd_iommu_detect,
> -		  gart_iommu_hole_init,
> -		  NULL,
> -		  NULL);
> -
>  bool amd_iommu_v2_supported(void)
>  {
>  	return amd_iommu_v2_present;
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index a1ada7bff44e6..b47220ac09eaa 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -1840,7 +1840,10 @@ void amd_iommu_domain_update(struct protection_domain *domain)
>  
>  static void __init amd_iommu_init_dma_ops(void)
>  {
> -	swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
> +	if (iommu_default_passthrough() || sme_me_mask)
> +		x86_swiotlb_enable = true;
> +	else
> +		x86_swiotlb_enable = false;
>  }
>  
>  int __init amd_iommu_init_api(void)
> diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
> index 4de960834a1b2..592c1e1a5d4b9 100644
> --- a/drivers/iommu/intel/dmar.c
> +++ b/drivers/iommu/intel/dmar.c
> @@ -30,7 +30,6 @@
>  #include <linux/numa.h>
>  #include <linux/limits.h>
>  #include <asm/irq_remapping.h>
> -#include <asm/iommu_table.h>
>  #include <trace/events/intel_iommu.h>
>  
>  #include "../irq_remapping.h"
> @@ -912,7 +911,7 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)
>  	return 0;
>  }
>  
> -int __init detect_intel_iommu(void)
> +void __init detect_intel_iommu(void)
>  {
>  	int ret;
>  	struct dmar_res_callback validate_drhd_cb = {
> @@ -945,8 +944,6 @@ int __init detect_intel_iommu(void)
>  		dmar_tbl = NULL;
>  	}
>  	up_write(&dmar_global_lock);
> -
> -	return ret ? ret : 1;
>  }
>  
>  static void unmap_iommu(struct intel_iommu *iommu)
> @@ -2164,7 +2161,6 @@ static int __init dmar_free_unused_resources(void)
>  }
>  
>  late_initcall(dmar_free_unused_resources);
> -IOMMU_INIT_POST(detect_intel_iommu);
>  
>  /*
>   * DMAR Hotplug Support
> diff --git a/include/linux/dmar.h b/include/linux/dmar.h
> index 45e903d847335..cbd714a198a0a 100644
> --- a/include/linux/dmar.h
> +++ b/include/linux/dmar.h
> @@ -121,7 +121,7 @@ extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
>  				 u16 segment, struct dmar_dev_scope *devices,
>  				 int count);
>  /* Intel IOMMU detection */
> -extern int detect_intel_iommu(void);
> +void detect_intel_iommu(void);
>  extern int enable_drhd_fault_handling(void);
>  extern int dmar_device_add(acpi_handle handle);
>  extern int dmar_device_remove(acpi_handle handle);
> @@ -197,6 +197,10 @@ static inline bool dmar_platform_optin(void)
>  	return false;
>  }
>  
> +static inline void detect_intel_iommu(void)
> +{
> +}
> +
>  #endif /* CONFIG_DMAR_TABLE */
>  
>  struct irte {
> -- 
> 2.30.2
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 07/15] x86: remove the IOMMU table infrastructure
@ 2022-04-07  0:20     ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:20 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, linux-hyperv, Anshuman Khandual, Robin Murphy,
	Joerg Roedel, x86, linux-mips, linuxppc-dev, iommu, tboot-devel,
	linux-pci, xen-devel, Boris Ostrovsky, David Woodhouse,
	linux-riscv, linux-arm-kernel, Lu Baolu

On Mon, Apr 04, 2022 at 07:05:51AM +0200, Christoph Hellwig wrote:
> The IOMMU table tries to separate the different IOMMUs into different
> backends, but actually requires various cross calls.
> 
> Rewrite the code to do the generic swiotlb/swiotlb-xen setup directly
> in pci-dma.c and then just call into the IOMMU drivers.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Hey Christoph,

There is a bit of background behind this - this whole IOMMU table
dynamic was done as at that point of time the pci_iommu_alloc was getting
way to unwieldy - and there needed to be a more 'structured' way with
dependencies.

Hence this creation... But as Christoph points out - it has gotten out
of hand. So smashing it back to a more simplistic mechanism is good.

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!

> ---
>  arch/ia64/include/asm/iommu_table.h    |   7 --
>  arch/x86/include/asm/dma-mapping.h     |   1 -
>  arch/x86/include/asm/gart.h            |   5 +-
>  arch/x86/include/asm/iommu.h           |   6 ++
>  arch/x86/include/asm/iommu_table.h     | 102 -----------------------
>  arch/x86/include/asm/swiotlb.h         |  30 -------
>  arch/x86/include/asm/xen/swiotlb-xen.h |   2 -
>  arch/x86/kernel/Makefile               |   2 -
>  arch/x86/kernel/amd_gart_64.c          |   5 +-
>  arch/x86/kernel/aperture_64.c          |  14 ++--
>  arch/x86/kernel/pci-dma.c              | 107 ++++++++++++++++++++-----
>  arch/x86/kernel/pci-iommu_table.c      |  77 ------------------
>  arch/x86/kernel/pci-swiotlb.c          |  77 ------------------
>  arch/x86/kernel/tboot.c                |   1 -
>  arch/x86/kernel/vmlinux.lds.S          |  12 ---
>  arch/x86/xen/Makefile                  |   2 -
>  arch/x86/xen/pci-swiotlb-xen.c         |  96 ----------------------
>  drivers/iommu/amd/init.c               |   6 --
>  drivers/iommu/amd/iommu.c              |   5 +-
>  drivers/iommu/intel/dmar.c             |   6 +-
>  include/linux/dmar.h                   |   6 +-
>  21 files changed, 110 insertions(+), 459 deletions(-)
>  delete mode 100644 arch/ia64/include/asm/iommu_table.h
>  delete mode 100644 arch/x86/include/asm/iommu_table.h
>  delete mode 100644 arch/x86/include/asm/swiotlb.h
>  delete mode 100644 arch/x86/kernel/pci-iommu_table.c
>  delete mode 100644 arch/x86/kernel/pci-swiotlb.c
>  delete mode 100644 arch/x86/xen/pci-swiotlb-xen.c
> 
> diff --git a/arch/ia64/include/asm/iommu_table.h b/arch/ia64/include/asm/iommu_table.h
> deleted file mode 100644
> index cc96116ac276a..0000000000000
> --- a/arch/ia64/include/asm/iommu_table.h
> +++ /dev/null
> @@ -1,7 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_IA64_IOMMU_TABLE_H
> -#define _ASM_IA64_IOMMU_TABLE_H
> -
> -#define IOMMU_INIT_POST(_detect)
> -
> -#endif /* _ASM_IA64_IOMMU_TABLE_H */
> diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
> index bb1654fe0ce74..256fd8115223d 100644
> --- a/arch/x86/include/asm/dma-mapping.h
> +++ b/arch/x86/include/asm/dma-mapping.h
> @@ -9,7 +9,6 @@
>  
>  #include <linux/scatterlist.h>
>  #include <asm/io.h>
> -#include <asm/swiotlb.h>
>  
>  extern int iommu_merge;
>  extern int panic_on_overflow;
> diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
> index 3185565743459..5af8088a10df6 100644
> --- a/arch/x86/include/asm/gart.h
> +++ b/arch/x86/include/asm/gart.h
> @@ -38,7 +38,7 @@ extern int gart_iommu_aperture_disabled;
>  extern void early_gart_iommu_check(void);
>  extern int gart_iommu_init(void);
>  extern void __init gart_parse_options(char *);
> -extern int gart_iommu_hole_init(void);
> +void gart_iommu_hole_init(void);
>  
>  #else
>  #define gart_iommu_aperture            0
> @@ -51,9 +51,8 @@ static inline void early_gart_iommu_check(void)
>  static inline void gart_parse_options(char *options)
>  {
>  }
> -static inline int gart_iommu_hole_init(void)
> +static inline void gart_iommu_hole_init(void)
>  {
> -	return -ENODEV;
>  }
>  #endif
>  
> diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
> index bf1ed2ddc74bd..dba89ed40d38d 100644
> --- a/arch/x86/include/asm/iommu.h
> +++ b/arch/x86/include/asm/iommu.h
> @@ -9,6 +9,12 @@
>  extern int force_iommu, no_iommu;
>  extern int iommu_detected;
>  
> +#ifdef CONFIG_SWIOTLB
> +extern bool x86_swiotlb_enable;
> +#else
> +#define x86_swiotlb_enable false
> +#endif
> +
>  /* 10 seconds */
>  #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
>  
> diff --git a/arch/x86/include/asm/iommu_table.h b/arch/x86/include/asm/iommu_table.h
> deleted file mode 100644
> index 1fb3fd1a83c25..0000000000000
> --- a/arch/x86/include/asm/iommu_table.h
> +++ /dev/null
> @@ -1,102 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_X86_IOMMU_TABLE_H
> -#define _ASM_X86_IOMMU_TABLE_H
> -
> -#include <asm/swiotlb.h>
> -
> -/*
> - * History lesson:
> - * The execution chain of IOMMUs in 2.6.36 looks as so:
> - *
> - *            [xen-swiotlb]
> - *                 |
> - *         +----[swiotlb *]--+
> - *        /         |         \
> - *       /          |          \
> - *    [GART]     [Calgary]  [Intel VT-d]
> - *     /
> - *    /
> - * [AMD-Vi]
> - *
> - * *: if SWIOTLB detected 'iommu=soft'/'swiotlb=force' it would skip
> - * over the rest of IOMMUs and unconditionally initialize the SWIOTLB.
> - * Also it would surreptitiously initialize set the swiotlb=1 if there were
> - * more than 4GB and if the user did not pass in 'iommu=off'. The swiotlb
> - * flag would be turned off by all IOMMUs except the Calgary one.
> - *
> - * The IOMMU_INIT* macros allow a similar tree (or more complex if desired)
> - * to be built by defining who we depend on.
> - *
> - * And all that needs to be done is to use one of the macros in the IOMMU
> - * and the pci-dma.c will take care of the rest.
> - */
> -
> -struct iommu_table_entry {
> -	initcall_t	detect;
> -	initcall_t	depend;
> -	void		(*early_init)(void); /* No memory allocate available. */
> -	void		(*late_init)(void); /* Yes, can allocate memory. */
> -#define IOMMU_FINISH_IF_DETECTED (1<<0)
> -#define IOMMU_DETECTED		 (1<<1)
> -	int		flags;
> -};
> -/*
> - * Macro fills out an entry in the .iommu_table that is equivalent
> - * to the fields that 'struct iommu_table_entry' has. The entries
> - * that are put in the .iommu_table section are not put in any order
> - * hence during boot-time we will have to resort them based on
> - * dependency. */
> -
> -
> -#define __IOMMU_INIT(_detect, _depend, _early_init, _late_init, _finish)\
> -	static const struct iommu_table_entry				\
> -		__iommu_entry_##_detect __used				\
> -	__attribute__ ((unused, __section__(".iommu_table"),		\
> -			aligned((sizeof(void *)))))	\
> -	= {_detect, _depend, _early_init, _late_init,			\
> -	   _finish ? IOMMU_FINISH_IF_DETECTED : 0}
> -/*
> - * The simplest IOMMU definition. Provide the detection routine
> - * and it will be run after the SWIOTLB and the other IOMMUs
> - * that utilize this macro. If the IOMMU is detected (ie, the
> - * detect routine returns a positive value), the other IOMMUs
> - * are also checked. You can use IOMMU_INIT_POST_FINISH if you prefer
> - * to stop detecting the other IOMMUs after yours has been detected.
> - */
> -#define IOMMU_INIT_POST(_detect)					\
> -	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 0)
> -
> -#define IOMMU_INIT_POST_FINISH(detect)					\
> -	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 1)
> -
> -/*
> - * A more sophisticated version of IOMMU_INIT. This variant requires:
> - *  a). A detection routine function.
> - *  b). The name of the detection routine we depend on to get called
> - *      before us.
> - *  c). The init routine which gets called if the detection routine
> - *      returns a positive value from the pci_iommu_alloc. This means
> - *      no presence of a memory allocator.
> - *  d). Similar to the 'init', except that this gets called from pci_iommu_init
> - *      where we do have a memory allocator.
> - *
> - * The standard IOMMU_INIT differs from the IOMMU_INIT_FINISH variant
> - * in that the former will continue detecting other IOMMUs in the call
> - * list after the detection routine returns a positive number, while the
> - * latter will stop the execution chain upon first successful detection.
> - * Both variants will still call the 'init' and 'late_init' functions if
> - * they are set.
> - */
> -#define IOMMU_INIT_FINISH(_detect, _depend, _init, _late_init)		\
> -	__IOMMU_INIT(_detect, _depend, _init, _late_init, 1)
> -
> -#define IOMMU_INIT(_detect, _depend, _init, _late_init)			\
> -	__IOMMU_INIT(_detect, _depend, _init, _late_init, 0)
> -
> -void sort_iommu_table(struct iommu_table_entry *start,
> -		      struct iommu_table_entry *finish);
> -
> -void check_iommu_entries(struct iommu_table_entry *start,
> -			 struct iommu_table_entry *finish);
> -
> -#endif /* _ASM_X86_IOMMU_TABLE_H */
> diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
> deleted file mode 100644
> index ff6c92eff035a..0000000000000
> --- a/arch/x86/include/asm/swiotlb.h
> +++ /dev/null
> @@ -1,30 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_X86_SWIOTLB_H
> -#define _ASM_X86_SWIOTLB_H
> -
> -#include <linux/swiotlb.h>
> -
> -#ifdef CONFIG_SWIOTLB
> -extern int swiotlb;
> -extern int __init pci_swiotlb_detect_override(void);
> -extern int __init pci_swiotlb_detect_4gb(void);
> -extern void __init pci_swiotlb_init(void);
> -extern void __init pci_swiotlb_late_init(void);
> -#else
> -#define swiotlb 0
> -static inline int pci_swiotlb_detect_override(void)
> -{
> -	return 0;
> -}
> -static inline int pci_swiotlb_detect_4gb(void)
> -{
> -	return 0;
> -}
> -static inline void pci_swiotlb_init(void)
> -{
> -}
> -static inline void pci_swiotlb_late_init(void)
> -{
> -}
> -#endif
> -#endif /* _ASM_X86_SWIOTLB_H */
> diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h
> index 66b4ddde77430..e5a90b42e4dde 100644
> --- a/arch/x86/include/asm/xen/swiotlb-xen.h
> +++ b/arch/x86/include/asm/xen/swiotlb-xen.h
> @@ -3,10 +3,8 @@
>  #define _ASM_X86_SWIOTLB_XEN_H
>  
>  #ifdef CONFIG_SWIOTLB_XEN
> -extern int __init pci_xen_swiotlb_detect(void);
>  extern int pci_xen_swiotlb_init_late(void);
>  #else
> -#define pci_xen_swiotlb_detect NULL
>  static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
>  #endif
>  
> diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
> index c41ef42adbe8a..e17b7e92a3fa3 100644
> --- a/arch/x86/kernel/Makefile
> +++ b/arch/x86/kernel/Makefile
> @@ -68,7 +68,6 @@ obj-y			+= bootflag.o e820.o
>  obj-y			+= pci-dma.o quirks.o topology.o kdebugfs.o
>  obj-y			+= alternative.o i8253.o hw_breakpoint.o
>  obj-y			+= tsc.o tsc_msr.o io_delay.o rtc.o
> -obj-y			+= pci-iommu_table.o
>  obj-y			+= resource.o
>  obj-y			+= irqflags.o
>  obj-y			+= static_call.o
> @@ -134,7 +133,6 @@ obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
>  
>  obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
>  
> -obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
>  obj-$(CONFIG_OF)			+= devicetree.o
>  obj-$(CONFIG_UPROBES)			+= uprobes.o
>  
> diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
> index ed837383de5c8..194d54eed5376 100644
> --- a/arch/x86/kernel/amd_gart_64.c
> +++ b/arch/x86/kernel/amd_gart_64.c
> @@ -38,11 +38,9 @@
>  #include <asm/iommu.h>
>  #include <asm/gart.h>
>  #include <asm/set_memory.h>
> -#include <asm/swiotlb.h>
>  #include <asm/dma.h>
>  #include <asm/amd_nb.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
>  
>  static unsigned long iommu_bus_base;	/* GART remapping area (physical) */
>  static unsigned long iommu_size;	/* size of remapping area bytes */
> @@ -808,7 +806,7 @@ int __init gart_iommu_init(void)
>  	flush_gart();
>  	dma_ops = &gart_dma_ops;
>  	x86_platform.iommu_shutdown = gart_iommu_shutdown;
> -	swiotlb = 0;
> +	x86_swiotlb_enable = false;
>  
>  	return 0;
>  }
> @@ -842,4 +840,3 @@ void __init gart_parse_options(char *p)
>  		}
>  	}
>  }
> -IOMMU_INIT_POST(gart_iommu_hole_init);
> diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
> index af3ba08b684b5..7a5630d904b23 100644
> --- a/arch/x86/kernel/aperture_64.c
> +++ b/arch/x86/kernel/aperture_64.c
> @@ -392,7 +392,7 @@ void __init early_gart_iommu_check(void)
>  
>  static int __initdata printed_gart_size_msg;
>  
> -int __init gart_iommu_hole_init(void)
> +void __init gart_iommu_hole_init(void)
>  {
>  	u32 agp_aper_base = 0, agp_aper_order = 0;
>  	u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0;
> @@ -401,11 +401,11 @@ int __init gart_iommu_hole_init(void)
>  	int i, node;
>  
>  	if (!amd_gart_present())
> -		return -ENODEV;
> +		return;
>  
>  	if (gart_iommu_aperture_disabled || !fix_aperture ||
>  	    !early_pci_allowed())
> -		return -ENODEV;
> +		return;
>  
>  	pr_info("Checking aperture...\n");
>  
> @@ -491,10 +491,8 @@ int __init gart_iommu_hole_init(void)
>  			 * and fixed up the northbridge
>  			 */
>  			exclude_from_core(last_aper_base, last_aper_order);
> -
> -			return 1;
>  		}
> -		return 0;
> +		return;
>  	}
>  
>  	if (!fallback_aper_force) {
> @@ -527,7 +525,7 @@ int __init gart_iommu_hole_init(void)
>  			panic("Not enough memory for aperture");
>  		}
>  	} else {
> -		return 0;
> +		return;
>  	}
>  
>  	/*
> @@ -561,6 +559,4 @@ int __init gart_iommu_hole_init(void)
>  	}
>  
>  	set_up_gart_resume(aper_order, aper_alloc);
> -
> -	return 1;
>  }
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index de234e7a8962e..df96926421be0 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -7,13 +7,16 @@
>  #include <linux/memblock.h>
>  #include <linux/gfp.h>
>  #include <linux/pci.h>
> +#include <linux/amd-iommu.h>
>  
>  #include <asm/proto.h>
>  #include <asm/dma.h>
>  #include <asm/iommu.h>
>  #include <asm/gart.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
> +
> +#include <xen/xen.h>
> +#include <xen/swiotlb-xen.h>
>  
>  static bool disable_dac_quirk __read_mostly;
>  
> @@ -34,24 +37,83 @@ int no_iommu __read_mostly;
>  /* Set this to 1 if there is a HW IOMMU in the system */
>  int iommu_detected __read_mostly = 0;
>  
> -extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
> +#ifdef CONFIG_SWIOTLB
> +bool x86_swiotlb_enable;
> +
> +static void __init pci_swiotlb_detect(void)
> +{
> +	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
> +	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
> +		x86_swiotlb_enable = true;
> +
> +	/*
> +	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
> +	 * devices that can't support DMA to encrypted memory.
> +	 */
> +	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
> +		x86_swiotlb_enable = true;
> +
> +	if (swiotlb_force == SWIOTLB_FORCE)
> +		x86_swiotlb_enable = true;
> +}
> +#else
> +static inline void __init pci_swiotlb_detect(void)
> +{
> +}
> +#endif /* CONFIG_SWIOTLB */
> +
> +#ifdef CONFIG_SWIOTLB_XEN
> +static bool xen_swiotlb;
> +
> +static void __init pci_xen_swiotlb_init(void)
> +{
> +	if (!xen_initial_domain() && !x86_swiotlb_enable &&
> +	    swiotlb_force != SWIOTLB_FORCE)
> +		return;
> +	x86_swiotlb_enable = true;
> +	xen_swiotlb = true;
> +	xen_swiotlb_init_early();
> +	dma_ops = &xen_swiotlb_dma_ops;
> +	if (IS_ENABLED(CONFIG_PCI))
> +		pci_request_acs();
> +}
> +
> +int pci_xen_swiotlb_init_late(void)
> +{
> +	int rc;
> +
> +	if (xen_swiotlb)
> +		return 0;
> +
> +	rc = xen_swiotlb_init();
> +	if (rc)
> +		return rc;
> +
> +	/* XXX: this switches the dma ops under live devices! */
> +	dma_ops = &xen_swiotlb_dma_ops;
> +	if (IS_ENABLED(CONFIG_PCI))
> +		pci_request_acs();
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
> +#else
> +static inline void __init pci_xen_swiotlb_init(void)
> +{
> +}
> +#endif /* CONFIG_SWIOTLB_XEN */
>  
>  void __init pci_iommu_alloc(void)
>  {
> -	struct iommu_table_entry *p;
> -
> -	sort_iommu_table(__iommu_table, __iommu_table_end);
> -	check_iommu_entries(__iommu_table, __iommu_table_end);
> -
> -	for (p = __iommu_table; p < __iommu_table_end; p++) {
> -		if (p && p->detect && p->detect() > 0) {
> -			p->flags |= IOMMU_DETECTED;
> -			if (p->early_init)
> -				p->early_init();
> -			if (p->flags & IOMMU_FINISH_IF_DETECTED)
> -				break;
> -		}
> +	if (xen_pv_domain()) {
> +		pci_xen_swiotlb_init();
> +		return;
>  	}
> +	pci_swiotlb_detect();
> +	gart_iommu_hole_init();
> +	amd_iommu_detect();
> +	detect_intel_iommu();
> +	if (x86_swiotlb_enable)
> +		swiotlb_init(0);
>  }
>  
>  /*
> @@ -102,7 +164,7 @@ static __init int iommu_setup(char *p)
>  		}
>  #ifdef CONFIG_SWIOTLB
>  		if (!strncmp(p, "soft", 4))
> -			swiotlb = 1;
> +			x86_swiotlb_enable = true;
>  #endif
>  		if (!strncmp(p, "pt", 2))
>  			iommu_set_default_passthrough(true);
> @@ -121,14 +183,17 @@ early_param("iommu", iommu_setup);
>  
>  static int __init pci_iommu_init(void)
>  {
> -	struct iommu_table_entry *p;
> -
>  	x86_init.iommu.iommu_init();
>  
> -	for (p = __iommu_table; p < __iommu_table_end; p++) {
> -		if (p && (p->flags & IOMMU_DETECTED) && p->late_init)
> -			p->late_init();
> +#ifdef CONFIG_SWIOTLB
> +	/* An IOMMU turned us off. */
> +	if (x86_swiotlb_enable) {
> +		pr_info("PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
> +		swiotlb_print_info();
> +	} else {
> +		swiotlb_exit();
>  	}
> +#endif
>  
>  	return 0;
>  }
> diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
> deleted file mode 100644
> index 42e92ec62973b..0000000000000
> --- a/arch/x86/kernel/pci-iommu_table.c
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -#include <linux/dma-mapping.h>
> -#include <asm/iommu_table.h>
> -#include <linux/string.h>
> -#include <linux/kallsyms.h>
> -
> -static struct iommu_table_entry * __init
> -find_dependents_of(struct iommu_table_entry *start,
> -		   struct iommu_table_entry *finish,
> -		   struct iommu_table_entry *q)
> -{
> -	struct iommu_table_entry *p;
> -
> -	if (!q)
> -		return NULL;
> -
> -	for (p = start; p < finish; p++)
> -		if (p->detect == q->depend)
> -			return p;
> -
> -	return NULL;
> -}
> -
> -
> -void __init sort_iommu_table(struct iommu_table_entry *start,
> -			     struct iommu_table_entry *finish) {
> -
> -	struct iommu_table_entry *p, *q, tmp;
> -
> -	for (p = start; p < finish; p++) {
> -again:
> -		q = find_dependents_of(start, finish, p);
> -		/* We are bit sneaky here. We use the memory address to figure
> -		 * out if the node we depend on is past our point, if so, swap.
> -		 */
> -		if (q > p) {
> -			tmp = *p;
> -			memmove(p, q, sizeof(*p));
> -			*q = tmp;
> -			goto again;
> -		}
> -	}
> -
> -}
> -
> -#ifdef DEBUG
> -void __init check_iommu_entries(struct iommu_table_entry *start,
> -				struct iommu_table_entry *finish)
> -{
> -	struct iommu_table_entry *p, *q, *x;
> -
> -	/* Simple cyclic dependency checker. */
> -	for (p = start; p < finish; p++) {
> -		q = find_dependents_of(start, finish, p);
> -		x = find_dependents_of(start, finish, q);
> -		if (p == x) {
> -			printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %pS depends on %pS and vice-versa. BREAKING IT.\n",
> -			       p->detect, q->detect);
> -			/* Heavy handed way..*/
> -			x->depend = NULL;
> -		}
> -	}
> -
> -	for (p = start; p < finish; p++) {
> -		q = find_dependents_of(p, finish, p);
> -		if (q && q > p) {
> -			printk(KERN_ERR "EXECUTION ORDER INVALID! %pS should be called before %pS!\n",
> -			       p->detect, q->detect);
> -		}
> -	}
> -}
> -#else
> -void __init check_iommu_entries(struct iommu_table_entry *start,
> -				       struct iommu_table_entry *finish)
> -{
> -}
> -#endif
> diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
> deleted file mode 100644
> index 814ab46a0dada..0000000000000
> --- a/arch/x86/kernel/pci-swiotlb.c
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -
> -#include <linux/pci.h>
> -#include <linux/cache.h>
> -#include <linux/init.h>
> -#include <linux/swiotlb.h>
> -#include <linux/memblock.h>
> -#include <linux/dma-direct.h>
> -#include <linux/cc_platform.h>
> -
> -#include <asm/iommu.h>
> -#include <asm/swiotlb.h>
> -#include <asm/dma.h>
> -#include <asm/xen/swiotlb-xen.h>
> -#include <asm/iommu_table.h>
> -
> -int swiotlb __read_mostly;
> -
> -/*
> - * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
> - *
> - * This returns non-zero if we are forced to use swiotlb (by the boot
> - * option).
> - */
> -int __init pci_swiotlb_detect_override(void)
> -{
> -	if (swiotlb_force == SWIOTLB_FORCE)
> -		swiotlb = 1;
> -
> -	return swiotlb;
> -}
> -IOMMU_INIT_FINISH(pci_swiotlb_detect_override,
> -		  pci_xen_swiotlb_detect,
> -		  pci_swiotlb_init,
> -		  pci_swiotlb_late_init);
> -
> -/*
> - * If 4GB or more detected (and iommu=off not set) or if SME is active
> - * then set swiotlb to 1 and return 1.
> - */
> -int __init pci_swiotlb_detect_4gb(void)
> -{
> -	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
> -	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
> -		swiotlb = 1;
> -
> -	/*
> -	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
> -	 * devices that can't support DMA to encrypted memory.
> -	 */
> -	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
> -		swiotlb = 1;
> -
> -	return swiotlb;
> -}
> -IOMMU_INIT(pci_swiotlb_detect_4gb,
> -	   pci_swiotlb_detect_override,
> -	   pci_swiotlb_init,
> -	   pci_swiotlb_late_init);
> -
> -void __init pci_swiotlb_init(void)
> -{
> -	if (swiotlb)
> -		swiotlb_init(0);
> -}
> -
> -void __init pci_swiotlb_late_init(void)
> -{
> -	/* An IOMMU turned us off. */
> -	if (!swiotlb)
> -		swiotlb_exit();
> -	else {
> -		printk(KERN_INFO "PCI-DMA: "
> -		       "Using software bounce buffering for IO (SWIOTLB)\n");
> -		swiotlb_print_info();
> -	}
> -}
> diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
> index f9af561c3cd4f..0c1154a1c4032 100644
> --- a/arch/x86/kernel/tboot.c
> +++ b/arch/x86/kernel/tboot.c
> @@ -24,7 +24,6 @@
>  #include <asm/processor.h>
>  #include <asm/bootparam.h>
>  #include <asm/pgalloc.h>
> -#include <asm/swiotlb.h>
>  #include <asm/fixmap.h>
>  #include <asm/proto.h>
>  #include <asm/setup.h>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index 7fda7f27e7620..f5f6dc2e80072 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -315,18 +315,6 @@ SECTIONS
>  		*(.altinstr_replacement)
>  	}
>  
> -	/*
> -	 * struct iommu_table_entry entries are injected in this section.
> -	 * It is an array of IOMMUs which during run time gets sorted depending
> -	 * on its dependency order. After rootfs_initcall is complete
> -	 * this section can be safely removed.
> -	 */
> -	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
> -		__iommu_table = .;
> -		*(.iommu_table)
> -		__iommu_table_end = .;
> -	}
> -
>  	. = ALIGN(8);
>  	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
>  		__apicdrivers = .;
> diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
> index 4953260e281c3..3c5b52fbe4a7f 100644
> --- a/arch/x86/xen/Makefile
> +++ b/arch/x86/xen/Makefile
> @@ -47,6 +47,4 @@ obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
>  
>  obj-$(CONFIG_XEN_PV_DOM0)	+= vga.o
>  
> -obj-$(CONFIG_SWIOTLB_XEN)	+= pci-swiotlb-xen.o
> -
>  obj-$(CONFIG_XEN_EFI)		+= efi.o
> diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
> deleted file mode 100644
> index 46df59aeaa06a..0000000000000
> --- a/arch/x86/xen/pci-swiotlb-xen.c
> +++ /dev/null
> @@ -1,96 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -
> -/* Glue code to lib/swiotlb-xen.c */
> -
> -#include <linux/dma-map-ops.h>
> -#include <linux/pci.h>
> -#include <xen/swiotlb-xen.h>
> -
> -#include <asm/xen/hypervisor.h>
> -#include <xen/xen.h>
> -#include <asm/iommu_table.h>
> -
> -
> -#include <asm/xen/swiotlb-xen.h>
> -#ifdef CONFIG_X86_64
> -#include <asm/iommu.h>
> -#include <asm/dma.h>
> -#endif
> -#include <linux/export.h>
> -
> -static int xen_swiotlb __read_mostly;
> -
> -/*
> - * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
> - *
> - * This returns non-zero if we are forced to use xen_swiotlb (by the boot
> - * option).
> - */
> -int __init pci_xen_swiotlb_detect(void)
> -{
> -
> -	if (!xen_pv_domain())
> -		return 0;
> -
> -	/* If running as PV guest, either iommu=soft, or swiotlb=force will
> -	 * activate this IOMMU. If running as PV privileged, activate it
> -	 * irregardless.
> -	 */
> -	if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
> -		xen_swiotlb = 1;
> -
> -	/* If we are running under Xen, we MUST disable the native SWIOTLB.
> -	 * Don't worry about swiotlb_force flag activating the native, as
> -	 * the 'swiotlb' flag is the only one turning it on. */
> -	swiotlb = 0;
> -
> -#ifdef CONFIG_X86_64
> -	/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
> -	 * (so no iommu=X command line over-writes).
> -	 * Considering that PV guests do not want the *native SWIOTLB* but
> -	 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
> -	 */
> -	if (max_pfn > MAX_DMA32_PFN)
> -		no_iommu = 1;
> -#endif
> -	return xen_swiotlb;
> -}
> -
> -static void __init pci_xen_swiotlb_init(void)
> -{
> -	if (xen_swiotlb) {
> -		xen_swiotlb_init_early();
> -		dma_ops = &xen_swiotlb_dma_ops;
> -
> -#ifdef CONFIG_PCI
> -		/* Make sure ACS will be enabled */
> -		pci_request_acs();
> -#endif
> -	}
> -}
> -
> -int pci_xen_swiotlb_init_late(void)
> -{
> -	int rc;
> -
> -	if (xen_swiotlb)
> -		return 0;
> -
> -	rc = xen_swiotlb_init();
> -	if (rc)
> -		return rc;
> -
> -	dma_ops = &xen_swiotlb_dma_ops;
> -#ifdef CONFIG_PCI
> -	/* Make sure ACS will be enabled */
> -	pci_request_acs();
> -#endif
> -
> -	return 0;
> -}
> -EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
> -
> -IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
> -		  NULL,
> -		  pci_xen_swiotlb_init,
> -		  NULL);
> diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> index b4a798c7b347f..1a3ad58ba8465 100644
> --- a/drivers/iommu/amd/init.c
> +++ b/drivers/iommu/amd/init.c
> @@ -27,7 +27,6 @@
>  #include <asm/apic.h>
>  #include <asm/gart.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
>  #include <asm/io_apic.h>
>  #include <asm/irq_remapping.h>
>  #include <asm/set_memory.h>
> @@ -3257,11 +3256,6 @@ __setup("ivrs_ioapic",		parse_ivrs_ioapic);
>  __setup("ivrs_hpet",		parse_ivrs_hpet);
>  __setup("ivrs_acpihid",		parse_ivrs_acpihid);
>  
> -IOMMU_INIT_FINISH(amd_iommu_detect,
> -		  gart_iommu_hole_init,
> -		  NULL,
> -		  NULL);
> -
>  bool amd_iommu_v2_supported(void)
>  {
>  	return amd_iommu_v2_present;
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index a1ada7bff44e6..b47220ac09eaa 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -1840,7 +1840,10 @@ void amd_iommu_domain_update(struct protection_domain *domain)
>  
>  static void __init amd_iommu_init_dma_ops(void)
>  {
> -	swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
> +	if (iommu_default_passthrough() || sme_me_mask)
> +		x86_swiotlb_enable = true;
> +	else
> +		x86_swiotlb_enable = false;
>  }
>  
>  int __init amd_iommu_init_api(void)
> diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
> index 4de960834a1b2..592c1e1a5d4b9 100644
> --- a/drivers/iommu/intel/dmar.c
> +++ b/drivers/iommu/intel/dmar.c
> @@ -30,7 +30,6 @@
>  #include <linux/numa.h>
>  #include <linux/limits.h>
>  #include <asm/irq_remapping.h>
> -#include <asm/iommu_table.h>
>  #include <trace/events/intel_iommu.h>
>  
>  #include "../irq_remapping.h"
> @@ -912,7 +911,7 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)
>  	return 0;
>  }
>  
> -int __init detect_intel_iommu(void)
> +void __init detect_intel_iommu(void)
>  {
>  	int ret;
>  	struct dmar_res_callback validate_drhd_cb = {
> @@ -945,8 +944,6 @@ int __init detect_intel_iommu(void)
>  		dmar_tbl = NULL;
>  	}
>  	up_write(&dmar_global_lock);
> -
> -	return ret ? ret : 1;
>  }
>  
>  static void unmap_iommu(struct intel_iommu *iommu)
> @@ -2164,7 +2161,6 @@ static int __init dmar_free_unused_resources(void)
>  }
>  
>  late_initcall(dmar_free_unused_resources);
> -IOMMU_INIT_POST(detect_intel_iommu);
>  
>  /*
>   * DMAR Hotplug Support
> diff --git a/include/linux/dmar.h b/include/linux/dmar.h
> index 45e903d847335..cbd714a198a0a 100644
> --- a/include/linux/dmar.h
> +++ b/include/linux/dmar.h
> @@ -121,7 +121,7 @@ extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
>  				 u16 segment, struct dmar_dev_scope *devices,
>  				 int count);
>  /* Intel IOMMU detection */
> -extern int detect_intel_iommu(void);
> +void detect_intel_iommu(void);
>  extern int enable_drhd_fault_handling(void);
>  extern int dmar_device_add(acpi_handle handle);
>  extern int dmar_device_remove(acpi_handle handle);
> @@ -197,6 +197,10 @@ static inline bool dmar_platform_optin(void)
>  	return false;
>  }
>  
> +static inline void detect_intel_iommu(void)
> +{
> +}
> +
>  #endif /* CONFIG_DMAR_TABLE */
>  
>  struct irte {
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 07/15] x86: remove the IOMMU table infrastructure
@ 2022-04-07  0:20     ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:20 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Mon, Apr 04, 2022 at 07:05:51AM +0200, Christoph Hellwig wrote:
> The IOMMU table tries to separate the different IOMMUs into different
> backends, but actually requires various cross calls.
> 
> Rewrite the code to do the generic swiotlb/swiotlb-xen setup directly
> in pci-dma.c and then just call into the IOMMU drivers.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Hey Christoph,

There is a bit of background behind this - this whole IOMMU table
dynamic was done as at that point of time the pci_iommu_alloc was getting
way to unwieldy - and there needed to be a more 'structured' way with
dependencies.

Hence this creation... But as Christoph points out - it has gotten out
of hand. So smashing it back to a more simplistic mechanism is good.

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!

> ---
>  arch/ia64/include/asm/iommu_table.h    |   7 --
>  arch/x86/include/asm/dma-mapping.h     |   1 -
>  arch/x86/include/asm/gart.h            |   5 +-
>  arch/x86/include/asm/iommu.h           |   6 ++
>  arch/x86/include/asm/iommu_table.h     | 102 -----------------------
>  arch/x86/include/asm/swiotlb.h         |  30 -------
>  arch/x86/include/asm/xen/swiotlb-xen.h |   2 -
>  arch/x86/kernel/Makefile               |   2 -
>  arch/x86/kernel/amd_gart_64.c          |   5 +-
>  arch/x86/kernel/aperture_64.c          |  14 ++--
>  arch/x86/kernel/pci-dma.c              | 107 ++++++++++++++++++++-----
>  arch/x86/kernel/pci-iommu_table.c      |  77 ------------------
>  arch/x86/kernel/pci-swiotlb.c          |  77 ------------------
>  arch/x86/kernel/tboot.c                |   1 -
>  arch/x86/kernel/vmlinux.lds.S          |  12 ---
>  arch/x86/xen/Makefile                  |   2 -
>  arch/x86/xen/pci-swiotlb-xen.c         |  96 ----------------------
>  drivers/iommu/amd/init.c               |   6 --
>  drivers/iommu/amd/iommu.c              |   5 +-
>  drivers/iommu/intel/dmar.c             |   6 +-
>  include/linux/dmar.h                   |   6 +-
>  21 files changed, 110 insertions(+), 459 deletions(-)
>  delete mode 100644 arch/ia64/include/asm/iommu_table.h
>  delete mode 100644 arch/x86/include/asm/iommu_table.h
>  delete mode 100644 arch/x86/include/asm/swiotlb.h
>  delete mode 100644 arch/x86/kernel/pci-iommu_table.c
>  delete mode 100644 arch/x86/kernel/pci-swiotlb.c
>  delete mode 100644 arch/x86/xen/pci-swiotlb-xen.c
> 
> diff --git a/arch/ia64/include/asm/iommu_table.h b/arch/ia64/include/asm/iommu_table.h
> deleted file mode 100644
> index cc96116ac276a..0000000000000
> --- a/arch/ia64/include/asm/iommu_table.h
> +++ /dev/null
> @@ -1,7 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_IA64_IOMMU_TABLE_H
> -#define _ASM_IA64_IOMMU_TABLE_H
> -
> -#define IOMMU_INIT_POST(_detect)
> -
> -#endif /* _ASM_IA64_IOMMU_TABLE_H */
> diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
> index bb1654fe0ce74..256fd8115223d 100644
> --- a/arch/x86/include/asm/dma-mapping.h
> +++ b/arch/x86/include/asm/dma-mapping.h
> @@ -9,7 +9,6 @@
>  
>  #include <linux/scatterlist.h>
>  #include <asm/io.h>
> -#include <asm/swiotlb.h>
>  
>  extern int iommu_merge;
>  extern int panic_on_overflow;
> diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
> index 3185565743459..5af8088a10df6 100644
> --- a/arch/x86/include/asm/gart.h
> +++ b/arch/x86/include/asm/gart.h
> @@ -38,7 +38,7 @@ extern int gart_iommu_aperture_disabled;
>  extern void early_gart_iommu_check(void);
>  extern int gart_iommu_init(void);
>  extern void __init gart_parse_options(char *);
> -extern int gart_iommu_hole_init(void);
> +void gart_iommu_hole_init(void);
>  
>  #else
>  #define gart_iommu_aperture            0
> @@ -51,9 +51,8 @@ static inline void early_gart_iommu_check(void)
>  static inline void gart_parse_options(char *options)
>  {
>  }
> -static inline int gart_iommu_hole_init(void)
> +static inline void gart_iommu_hole_init(void)
>  {
> -	return -ENODEV;
>  }
>  #endif
>  
> diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
> index bf1ed2ddc74bd..dba89ed40d38d 100644
> --- a/arch/x86/include/asm/iommu.h
> +++ b/arch/x86/include/asm/iommu.h
> @@ -9,6 +9,12 @@
>  extern int force_iommu, no_iommu;
>  extern int iommu_detected;
>  
> +#ifdef CONFIG_SWIOTLB
> +extern bool x86_swiotlb_enable;
> +#else
> +#define x86_swiotlb_enable false
> +#endif
> +
>  /* 10 seconds */
>  #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
>  
> diff --git a/arch/x86/include/asm/iommu_table.h b/arch/x86/include/asm/iommu_table.h
> deleted file mode 100644
> index 1fb3fd1a83c25..0000000000000
> --- a/arch/x86/include/asm/iommu_table.h
> +++ /dev/null
> @@ -1,102 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_X86_IOMMU_TABLE_H
> -#define _ASM_X86_IOMMU_TABLE_H
> -
> -#include <asm/swiotlb.h>
> -
> -/*
> - * History lesson:
> - * The execution chain of IOMMUs in 2.6.36 looks as so:
> - *
> - *            [xen-swiotlb]
> - *                 |
> - *         +----[swiotlb *]--+
> - *        /         |         \
> - *       /          |          \
> - *    [GART]     [Calgary]  [Intel VT-d]
> - *     /
> - *    /
> - * [AMD-Vi]
> - *
> - * *: if SWIOTLB detected 'iommu=soft'/'swiotlb=force' it would skip
> - * over the rest of IOMMUs and unconditionally initialize the SWIOTLB.
> - * Also it would surreptitiously initialize set the swiotlb=1 if there were
> - * more than 4GB and if the user did not pass in 'iommu=off'. The swiotlb
> - * flag would be turned off by all IOMMUs except the Calgary one.
> - *
> - * The IOMMU_INIT* macros allow a similar tree (or more complex if desired)
> - * to be built by defining who we depend on.
> - *
> - * And all that needs to be done is to use one of the macros in the IOMMU
> - * and the pci-dma.c will take care of the rest.
> - */
> -
> -struct iommu_table_entry {
> -	initcall_t	detect;
> -	initcall_t	depend;
> -	void		(*early_init)(void); /* No memory allocate available. */
> -	void		(*late_init)(void); /* Yes, can allocate memory. */
> -#define IOMMU_FINISH_IF_DETECTED (1<<0)
> -#define IOMMU_DETECTED		 (1<<1)
> -	int		flags;
> -};
> -/*
> - * Macro fills out an entry in the .iommu_table that is equivalent
> - * to the fields that 'struct iommu_table_entry' has. The entries
> - * that are put in the .iommu_table section are not put in any order
> - * hence during boot-time we will have to resort them based on
> - * dependency. */
> -
> -
> -#define __IOMMU_INIT(_detect, _depend, _early_init, _late_init, _finish)\
> -	static const struct iommu_table_entry				\
> -		__iommu_entry_##_detect __used				\
> -	__attribute__ ((unused, __section__(".iommu_table"),		\
> -			aligned((sizeof(void *)))))	\
> -	= {_detect, _depend, _early_init, _late_init,			\
> -	   _finish ? IOMMU_FINISH_IF_DETECTED : 0}
> -/*
> - * The simplest IOMMU definition. Provide the detection routine
> - * and it will be run after the SWIOTLB and the other IOMMUs
> - * that utilize this macro. If the IOMMU is detected (ie, the
> - * detect routine returns a positive value), the other IOMMUs
> - * are also checked. You can use IOMMU_INIT_POST_FINISH if you prefer
> - * to stop detecting the other IOMMUs after yours has been detected.
> - */
> -#define IOMMU_INIT_POST(_detect)					\
> -	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 0)
> -
> -#define IOMMU_INIT_POST_FINISH(detect)					\
> -	__IOMMU_INIT(_detect, pci_swiotlb_detect_4gb,  NULL, NULL, 1)
> -
> -/*
> - * A more sophisticated version of IOMMU_INIT. This variant requires:
> - *  a). A detection routine function.
> - *  b). The name of the detection routine we depend on to get called
> - *      before us.
> - *  c). The init routine which gets called if the detection routine
> - *      returns a positive value from the pci_iommu_alloc. This means
> - *      no presence of a memory allocator.
> - *  d). Similar to the 'init', except that this gets called from pci_iommu_init
> - *      where we do have a memory allocator.
> - *
> - * The standard IOMMU_INIT differs from the IOMMU_INIT_FINISH variant
> - * in that the former will continue detecting other IOMMUs in the call
> - * list after the detection routine returns a positive number, while the
> - * latter will stop the execution chain upon first successful detection.
> - * Both variants will still call the 'init' and 'late_init' functions if
> - * they are set.
> - */
> -#define IOMMU_INIT_FINISH(_detect, _depend, _init, _late_init)		\
> -	__IOMMU_INIT(_detect, _depend, _init, _late_init, 1)
> -
> -#define IOMMU_INIT(_detect, _depend, _init, _late_init)			\
> -	__IOMMU_INIT(_detect, _depend, _init, _late_init, 0)
> -
> -void sort_iommu_table(struct iommu_table_entry *start,
> -		      struct iommu_table_entry *finish);
> -
> -void check_iommu_entries(struct iommu_table_entry *start,
> -			 struct iommu_table_entry *finish);
> -
> -#endif /* _ASM_X86_IOMMU_TABLE_H */
> diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
> deleted file mode 100644
> index ff6c92eff035a..0000000000000
> --- a/arch/x86/include/asm/swiotlb.h
> +++ /dev/null
> @@ -1,30 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef _ASM_X86_SWIOTLB_H
> -#define _ASM_X86_SWIOTLB_H
> -
> -#include <linux/swiotlb.h>
> -
> -#ifdef CONFIG_SWIOTLB
> -extern int swiotlb;
> -extern int __init pci_swiotlb_detect_override(void);
> -extern int __init pci_swiotlb_detect_4gb(void);
> -extern void __init pci_swiotlb_init(void);
> -extern void __init pci_swiotlb_late_init(void);
> -#else
> -#define swiotlb 0
> -static inline int pci_swiotlb_detect_override(void)
> -{
> -	return 0;
> -}
> -static inline int pci_swiotlb_detect_4gb(void)
> -{
> -	return 0;
> -}
> -static inline void pci_swiotlb_init(void)
> -{
> -}
> -static inline void pci_swiotlb_late_init(void)
> -{
> -}
> -#endif
> -#endif /* _ASM_X86_SWIOTLB_H */
> diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h
> index 66b4ddde77430..e5a90b42e4dde 100644
> --- a/arch/x86/include/asm/xen/swiotlb-xen.h
> +++ b/arch/x86/include/asm/xen/swiotlb-xen.h
> @@ -3,10 +3,8 @@
>  #define _ASM_X86_SWIOTLB_XEN_H
>  
>  #ifdef CONFIG_SWIOTLB_XEN
> -extern int __init pci_xen_swiotlb_detect(void);
>  extern int pci_xen_swiotlb_init_late(void);
>  #else
> -#define pci_xen_swiotlb_detect NULL
>  static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
>  #endif
>  
> diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
> index c41ef42adbe8a..e17b7e92a3fa3 100644
> --- a/arch/x86/kernel/Makefile
> +++ b/arch/x86/kernel/Makefile
> @@ -68,7 +68,6 @@ obj-y			+= bootflag.o e820.o
>  obj-y			+= pci-dma.o quirks.o topology.o kdebugfs.o
>  obj-y			+= alternative.o i8253.o hw_breakpoint.o
>  obj-y			+= tsc.o tsc_msr.o io_delay.o rtc.o
> -obj-y			+= pci-iommu_table.o
>  obj-y			+= resource.o
>  obj-y			+= irqflags.o
>  obj-y			+= static_call.o
> @@ -134,7 +133,6 @@ obj-$(CONFIG_PCSPKR_PLATFORM)	+= pcspeaker.o
>  
>  obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
>  
> -obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
>  obj-$(CONFIG_OF)			+= devicetree.o
>  obj-$(CONFIG_UPROBES)			+= uprobes.o
>  
> diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
> index ed837383de5c8..194d54eed5376 100644
> --- a/arch/x86/kernel/amd_gart_64.c
> +++ b/arch/x86/kernel/amd_gart_64.c
> @@ -38,11 +38,9 @@
>  #include <asm/iommu.h>
>  #include <asm/gart.h>
>  #include <asm/set_memory.h>
> -#include <asm/swiotlb.h>
>  #include <asm/dma.h>
>  #include <asm/amd_nb.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
>  
>  static unsigned long iommu_bus_base;	/* GART remapping area (physical) */
>  static unsigned long iommu_size;	/* size of remapping area bytes */
> @@ -808,7 +806,7 @@ int __init gart_iommu_init(void)
>  	flush_gart();
>  	dma_ops = &gart_dma_ops;
>  	x86_platform.iommu_shutdown = gart_iommu_shutdown;
> -	swiotlb = 0;
> +	x86_swiotlb_enable = false;
>  
>  	return 0;
>  }
> @@ -842,4 +840,3 @@ void __init gart_parse_options(char *p)
>  		}
>  	}
>  }
> -IOMMU_INIT_POST(gart_iommu_hole_init);
> diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
> index af3ba08b684b5..7a5630d904b23 100644
> --- a/arch/x86/kernel/aperture_64.c
> +++ b/arch/x86/kernel/aperture_64.c
> @@ -392,7 +392,7 @@ void __init early_gart_iommu_check(void)
>  
>  static int __initdata printed_gart_size_msg;
>  
> -int __init gart_iommu_hole_init(void)
> +void __init gart_iommu_hole_init(void)
>  {
>  	u32 agp_aper_base = 0, agp_aper_order = 0;
>  	u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0;
> @@ -401,11 +401,11 @@ int __init gart_iommu_hole_init(void)
>  	int i, node;
>  
>  	if (!amd_gart_present())
> -		return -ENODEV;
> +		return;
>  
>  	if (gart_iommu_aperture_disabled || !fix_aperture ||
>  	    !early_pci_allowed())
> -		return -ENODEV;
> +		return;
>  
>  	pr_info("Checking aperture...\n");
>  
> @@ -491,10 +491,8 @@ int __init gart_iommu_hole_init(void)
>  			 * and fixed up the northbridge
>  			 */
>  			exclude_from_core(last_aper_base, last_aper_order);
> -
> -			return 1;
>  		}
> -		return 0;
> +		return;
>  	}
>  
>  	if (!fallback_aper_force) {
> @@ -527,7 +525,7 @@ int __init gart_iommu_hole_init(void)
>  			panic("Not enough memory for aperture");
>  		}
>  	} else {
> -		return 0;
> +		return;
>  	}
>  
>  	/*
> @@ -561,6 +559,4 @@ int __init gart_iommu_hole_init(void)
>  	}
>  
>  	set_up_gart_resume(aper_order, aper_alloc);
> -
> -	return 1;
>  }
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index de234e7a8962e..df96926421be0 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -7,13 +7,16 @@
>  #include <linux/memblock.h>
>  #include <linux/gfp.h>
>  #include <linux/pci.h>
> +#include <linux/amd-iommu.h>
>  
>  #include <asm/proto.h>
>  #include <asm/dma.h>
>  #include <asm/iommu.h>
>  #include <asm/gart.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
> +
> +#include <xen/xen.h>
> +#include <xen/swiotlb-xen.h>
>  
>  static bool disable_dac_quirk __read_mostly;
>  
> @@ -34,24 +37,83 @@ int no_iommu __read_mostly;
>  /* Set this to 1 if there is a HW IOMMU in the system */
>  int iommu_detected __read_mostly = 0;
>  
> -extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
> +#ifdef CONFIG_SWIOTLB
> +bool x86_swiotlb_enable;
> +
> +static void __init pci_swiotlb_detect(void)
> +{
> +	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
> +	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
> +		x86_swiotlb_enable = true;
> +
> +	/*
> +	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
> +	 * devices that can't support DMA to encrypted memory.
> +	 */
> +	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
> +		x86_swiotlb_enable = true;
> +
> +	if (swiotlb_force = SWIOTLB_FORCE)
> +		x86_swiotlb_enable = true;
> +}
> +#else
> +static inline void __init pci_swiotlb_detect(void)
> +{
> +}
> +#endif /* CONFIG_SWIOTLB */
> +
> +#ifdef CONFIG_SWIOTLB_XEN
> +static bool xen_swiotlb;
> +
> +static void __init pci_xen_swiotlb_init(void)
> +{
> +	if (!xen_initial_domain() && !x86_swiotlb_enable &&
> +	    swiotlb_force != SWIOTLB_FORCE)
> +		return;
> +	x86_swiotlb_enable = true;
> +	xen_swiotlb = true;
> +	xen_swiotlb_init_early();
> +	dma_ops = &xen_swiotlb_dma_ops;
> +	if (IS_ENABLED(CONFIG_PCI))
> +		pci_request_acs();
> +}
> +
> +int pci_xen_swiotlb_init_late(void)
> +{
> +	int rc;
> +
> +	if (xen_swiotlb)
> +		return 0;
> +
> +	rc = xen_swiotlb_init();
> +	if (rc)
> +		return rc;
> +
> +	/* XXX: this switches the dma ops under live devices! */
> +	dma_ops = &xen_swiotlb_dma_ops;
> +	if (IS_ENABLED(CONFIG_PCI))
> +		pci_request_acs();
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
> +#else
> +static inline void __init pci_xen_swiotlb_init(void)
> +{
> +}
> +#endif /* CONFIG_SWIOTLB_XEN */
>  
>  void __init pci_iommu_alloc(void)
>  {
> -	struct iommu_table_entry *p;
> -
> -	sort_iommu_table(__iommu_table, __iommu_table_end);
> -	check_iommu_entries(__iommu_table, __iommu_table_end);
> -
> -	for (p = __iommu_table; p < __iommu_table_end; p++) {
> -		if (p && p->detect && p->detect() > 0) {
> -			p->flags |= IOMMU_DETECTED;
> -			if (p->early_init)
> -				p->early_init();
> -			if (p->flags & IOMMU_FINISH_IF_DETECTED)
> -				break;
> -		}
> +	if (xen_pv_domain()) {
> +		pci_xen_swiotlb_init();
> +		return;
>  	}
> +	pci_swiotlb_detect();
> +	gart_iommu_hole_init();
> +	amd_iommu_detect();
> +	detect_intel_iommu();
> +	if (x86_swiotlb_enable)
> +		swiotlb_init(0);
>  }
>  
>  /*
> @@ -102,7 +164,7 @@ static __init int iommu_setup(char *p)
>  		}
>  #ifdef CONFIG_SWIOTLB
>  		if (!strncmp(p, "soft", 4))
> -			swiotlb = 1;
> +			x86_swiotlb_enable = true;
>  #endif
>  		if (!strncmp(p, "pt", 2))
>  			iommu_set_default_passthrough(true);
> @@ -121,14 +183,17 @@ early_param("iommu", iommu_setup);
>  
>  static int __init pci_iommu_init(void)
>  {
> -	struct iommu_table_entry *p;
> -
>  	x86_init.iommu.iommu_init();
>  
> -	for (p = __iommu_table; p < __iommu_table_end; p++) {
> -		if (p && (p->flags & IOMMU_DETECTED) && p->late_init)
> -			p->late_init();
> +#ifdef CONFIG_SWIOTLB
> +	/* An IOMMU turned us off. */
> +	if (x86_swiotlb_enable) {
> +		pr_info("PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
> +		swiotlb_print_info();
> +	} else {
> +		swiotlb_exit();
>  	}
> +#endif
>  
>  	return 0;
>  }
> diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
> deleted file mode 100644
> index 42e92ec62973b..0000000000000
> --- a/arch/x86/kernel/pci-iommu_table.c
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -#include <linux/dma-mapping.h>
> -#include <asm/iommu_table.h>
> -#include <linux/string.h>
> -#include <linux/kallsyms.h>
> -
> -static struct iommu_table_entry * __init
> -find_dependents_of(struct iommu_table_entry *start,
> -		   struct iommu_table_entry *finish,
> -		   struct iommu_table_entry *q)
> -{
> -	struct iommu_table_entry *p;
> -
> -	if (!q)
> -		return NULL;
> -
> -	for (p = start; p < finish; p++)
> -		if (p->detect = q->depend)
> -			return p;
> -
> -	return NULL;
> -}
> -
> -
> -void __init sort_iommu_table(struct iommu_table_entry *start,
> -			     struct iommu_table_entry *finish) {
> -
> -	struct iommu_table_entry *p, *q, tmp;
> -
> -	for (p = start; p < finish; p++) {
> -again:
> -		q = find_dependents_of(start, finish, p);
> -		/* We are bit sneaky here. We use the memory address to figure
> -		 * out if the node we depend on is past our point, if so, swap.
> -		 */
> -		if (q > p) {
> -			tmp = *p;
> -			memmove(p, q, sizeof(*p));
> -			*q = tmp;
> -			goto again;
> -		}
> -	}
> -
> -}
> -
> -#ifdef DEBUG
> -void __init check_iommu_entries(struct iommu_table_entry *start,
> -				struct iommu_table_entry *finish)
> -{
> -	struct iommu_table_entry *p, *q, *x;
> -
> -	/* Simple cyclic dependency checker. */
> -	for (p = start; p < finish; p++) {
> -		q = find_dependents_of(start, finish, p);
> -		x = find_dependents_of(start, finish, q);
> -		if (p = x) {
> -			printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %pS depends on %pS and vice-versa. BREAKING IT.\n",
> -			       p->detect, q->detect);
> -			/* Heavy handed way..*/
> -			x->depend = NULL;
> -		}
> -	}
> -
> -	for (p = start; p < finish; p++) {
> -		q = find_dependents_of(p, finish, p);
> -		if (q && q > p) {
> -			printk(KERN_ERR "EXECUTION ORDER INVALID! %pS should be called before %pS!\n",
> -			       p->detect, q->detect);
> -		}
> -	}
> -}
> -#else
> -void __init check_iommu_entries(struct iommu_table_entry *start,
> -				       struct iommu_table_entry *finish)
> -{
> -}
> -#endif
> diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
> deleted file mode 100644
> index 814ab46a0dada..0000000000000
> --- a/arch/x86/kernel/pci-swiotlb.c
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -
> -#include <linux/pci.h>
> -#include <linux/cache.h>
> -#include <linux/init.h>
> -#include <linux/swiotlb.h>
> -#include <linux/memblock.h>
> -#include <linux/dma-direct.h>
> -#include <linux/cc_platform.h>
> -
> -#include <asm/iommu.h>
> -#include <asm/swiotlb.h>
> -#include <asm/dma.h>
> -#include <asm/xen/swiotlb-xen.h>
> -#include <asm/iommu_table.h>
> -
> -int swiotlb __read_mostly;
> -
> -/*
> - * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
> - *
> - * This returns non-zero if we are forced to use swiotlb (by the boot
> - * option).
> - */
> -int __init pci_swiotlb_detect_override(void)
> -{
> -	if (swiotlb_force = SWIOTLB_FORCE)
> -		swiotlb = 1;
> -
> -	return swiotlb;
> -}
> -IOMMU_INIT_FINISH(pci_swiotlb_detect_override,
> -		  pci_xen_swiotlb_detect,
> -		  pci_swiotlb_init,
> -		  pci_swiotlb_late_init);
> -
> -/*
> - * If 4GB or more detected (and iommu=off not set) or if SME is active
> - * then set swiotlb to 1 and return 1.
> - */
> -int __init pci_swiotlb_detect_4gb(void)
> -{
> -	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
> -	if (!no_iommu && max_possible_pfn > MAX_DMA32_PFN)
> -		swiotlb = 1;
> -
> -	/*
> -	 * Set swiotlb to 1 so that bounce buffers are allocated and used for
> -	 * devices that can't support DMA to encrypted memory.
> -	 */
> -	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
> -		swiotlb = 1;
> -
> -	return swiotlb;
> -}
> -IOMMU_INIT(pci_swiotlb_detect_4gb,
> -	   pci_swiotlb_detect_override,
> -	   pci_swiotlb_init,
> -	   pci_swiotlb_late_init);
> -
> -void __init pci_swiotlb_init(void)
> -{
> -	if (swiotlb)
> -		swiotlb_init(0);
> -}
> -
> -void __init pci_swiotlb_late_init(void)
> -{
> -	/* An IOMMU turned us off. */
> -	if (!swiotlb)
> -		swiotlb_exit();
> -	else {
> -		printk(KERN_INFO "PCI-DMA: "
> -		       "Using software bounce buffering for IO (SWIOTLB)\n");
> -		swiotlb_print_info();
> -	}
> -}
> diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
> index f9af561c3cd4f..0c1154a1c4032 100644
> --- a/arch/x86/kernel/tboot.c
> +++ b/arch/x86/kernel/tboot.c
> @@ -24,7 +24,6 @@
>  #include <asm/processor.h>
>  #include <asm/bootparam.h>
>  #include <asm/pgalloc.h>
> -#include <asm/swiotlb.h>
>  #include <asm/fixmap.h>
>  #include <asm/proto.h>
>  #include <asm/setup.h>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index 7fda7f27e7620..f5f6dc2e80072 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -315,18 +315,6 @@ SECTIONS
>  		*(.altinstr_replacement)
>  	}
>  
> -	/*
> -	 * struct iommu_table_entry entries are injected in this section.
> -	 * It is an array of IOMMUs which during run time gets sorted depending
> -	 * on its dependency order. After rootfs_initcall is complete
> -	 * this section can be safely removed.
> -	 */
> -	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
> -		__iommu_table = .;
> -		*(.iommu_table)
> -		__iommu_table_end = .;
> -	}
> -
>  	. = ALIGN(8);
>  	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
>  		__apicdrivers = .;
> diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
> index 4953260e281c3..3c5b52fbe4a7f 100644
> --- a/arch/x86/xen/Makefile
> +++ b/arch/x86/xen/Makefile
> @@ -47,6 +47,4 @@ obj-$(CONFIG_XEN_DEBUG_FS)	+= debugfs.o
>  
>  obj-$(CONFIG_XEN_PV_DOM0)	+= vga.o
>  
> -obj-$(CONFIG_SWIOTLB_XEN)	+= pci-swiotlb-xen.o
> -
>  obj-$(CONFIG_XEN_EFI)		+= efi.o
> diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
> deleted file mode 100644
> index 46df59aeaa06a..0000000000000
> --- a/arch/x86/xen/pci-swiotlb-xen.c
> +++ /dev/null
> @@ -1,96 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -
> -/* Glue code to lib/swiotlb-xen.c */
> -
> -#include <linux/dma-map-ops.h>
> -#include <linux/pci.h>
> -#include <xen/swiotlb-xen.h>
> -
> -#include <asm/xen/hypervisor.h>
> -#include <xen/xen.h>
> -#include <asm/iommu_table.h>
> -
> -
> -#include <asm/xen/swiotlb-xen.h>
> -#ifdef CONFIG_X86_64
> -#include <asm/iommu.h>
> -#include <asm/dma.h>
> -#endif
> -#include <linux/export.h>
> -
> -static int xen_swiotlb __read_mostly;
> -
> -/*
> - * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
> - *
> - * This returns non-zero if we are forced to use xen_swiotlb (by the boot
> - * option).
> - */
> -int __init pci_xen_swiotlb_detect(void)
> -{
> -
> -	if (!xen_pv_domain())
> -		return 0;
> -
> -	/* If running as PV guest, either iommu=soft, or swiotlb=force will
> -	 * activate this IOMMU. If running as PV privileged, activate it
> -	 * irregardless.
> -	 */
> -	if (xen_initial_domain() || swiotlb || swiotlb_force = SWIOTLB_FORCE)
> -		xen_swiotlb = 1;
> -
> -	/* If we are running under Xen, we MUST disable the native SWIOTLB.
> -	 * Don't worry about swiotlb_force flag activating the native, as
> -	 * the 'swiotlb' flag is the only one turning it on. */
> -	swiotlb = 0;
> -
> -#ifdef CONFIG_X86_64
> -	/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu = 0
> -	 * (so no iommu=X command line over-writes).
> -	 * Considering that PV guests do not want the *native SWIOTLB* but
> -	 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
> -	 */
> -	if (max_pfn > MAX_DMA32_PFN)
> -		no_iommu = 1;
> -#endif
> -	return xen_swiotlb;
> -}
> -
> -static void __init pci_xen_swiotlb_init(void)
> -{
> -	if (xen_swiotlb) {
> -		xen_swiotlb_init_early();
> -		dma_ops = &xen_swiotlb_dma_ops;
> -
> -#ifdef CONFIG_PCI
> -		/* Make sure ACS will be enabled */
> -		pci_request_acs();
> -#endif
> -	}
> -}
> -
> -int pci_xen_swiotlb_init_late(void)
> -{
> -	int rc;
> -
> -	if (xen_swiotlb)
> -		return 0;
> -
> -	rc = xen_swiotlb_init();
> -	if (rc)
> -		return rc;
> -
> -	dma_ops = &xen_swiotlb_dma_ops;
> -#ifdef CONFIG_PCI
> -	/* Make sure ACS will be enabled */
> -	pci_request_acs();
> -#endif
> -
> -	return 0;
> -}
> -EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
> -
> -IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
> -		  NULL,
> -		  pci_xen_swiotlb_init,
> -		  NULL);
> diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> index b4a798c7b347f..1a3ad58ba8465 100644
> --- a/drivers/iommu/amd/init.c
> +++ b/drivers/iommu/amd/init.c
> @@ -27,7 +27,6 @@
>  #include <asm/apic.h>
>  #include <asm/gart.h>
>  #include <asm/x86_init.h>
> -#include <asm/iommu_table.h>
>  #include <asm/io_apic.h>
>  #include <asm/irq_remapping.h>
>  #include <asm/set_memory.h>
> @@ -3257,11 +3256,6 @@ __setup("ivrs_ioapic",		parse_ivrs_ioapic);
>  __setup("ivrs_hpet",		parse_ivrs_hpet);
>  __setup("ivrs_acpihid",		parse_ivrs_acpihid);
>  
> -IOMMU_INIT_FINISH(amd_iommu_detect,
> -		  gart_iommu_hole_init,
> -		  NULL,
> -		  NULL);
> -
>  bool amd_iommu_v2_supported(void)
>  {
>  	return amd_iommu_v2_present;
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index a1ada7bff44e6..b47220ac09eaa 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -1840,7 +1840,10 @@ void amd_iommu_domain_update(struct protection_domain *domain)
>  
>  static void __init amd_iommu_init_dma_ops(void)
>  {
> -	swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
> +	if (iommu_default_passthrough() || sme_me_mask)
> +		x86_swiotlb_enable = true;
> +	else
> +		x86_swiotlb_enable = false;
>  }
>  
>  int __init amd_iommu_init_api(void)
> diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
> index 4de960834a1b2..592c1e1a5d4b9 100644
> --- a/drivers/iommu/intel/dmar.c
> +++ b/drivers/iommu/intel/dmar.c
> @@ -30,7 +30,6 @@
>  #include <linux/numa.h>
>  #include <linux/limits.h>
>  #include <asm/irq_remapping.h>
> -#include <asm/iommu_table.h>
>  #include <trace/events/intel_iommu.h>
>  
>  #include "../irq_remapping.h"
> @@ -912,7 +911,7 @@ dmar_validate_one_drhd(struct acpi_dmar_header *entry, void *arg)
>  	return 0;
>  }
>  
> -int __init detect_intel_iommu(void)
> +void __init detect_intel_iommu(void)
>  {
>  	int ret;
>  	struct dmar_res_callback validate_drhd_cb = {
> @@ -945,8 +944,6 @@ int __init detect_intel_iommu(void)
>  		dmar_tbl = NULL;
>  	}
>  	up_write(&dmar_global_lock);
> -
> -	return ret ? ret : 1;
>  }
>  
>  static void unmap_iommu(struct intel_iommu *iommu)
> @@ -2164,7 +2161,6 @@ static int __init dmar_free_unused_resources(void)
>  }
>  
>  late_initcall(dmar_free_unused_resources);
> -IOMMU_INIT_POST(detect_intel_iommu);
>  
>  /*
>   * DMAR Hotplug Support
> diff --git a/include/linux/dmar.h b/include/linux/dmar.h
> index 45e903d847335..cbd714a198a0a 100644
> --- a/include/linux/dmar.h
> +++ b/include/linux/dmar.h
> @@ -121,7 +121,7 @@ extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
>  				 u16 segment, struct dmar_dev_scope *devices,
>  				 int count);
>  /* Intel IOMMU detection */
> -extern int detect_intel_iommu(void);
> +void detect_intel_iommu(void);
>  extern int enable_drhd_fault_handling(void);
>  extern int dmar_device_add(acpi_handle handle);
>  extern int dmar_device_remove(acpi_handle handle);
> @@ -197,6 +197,10 @@ static inline bool dmar_platform_optin(void)
>  	return false;
>  }
>  
> +static inline void detect_intel_iommu(void)
> +{
> +}
> +
>  #endif /* CONFIG_DMAR_TABLE */
>  
>  struct irte {
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
  2022-04-04  5:05   ` Christoph Hellwig
                       ` (3 preceding siblings ...)
  (?)
@ 2022-04-07  0:25     ` Konrad Rzeszutek Wilk
  -1 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

> diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
> index c5228f4969eb2..3b4045d508ec8 100644
> --- a/arch/powerpc/platforms/pseries/svm.c
> +++ b/arch/powerpc/platforms/pseries/svm.c
> @@ -28,7 +28,7 @@ static int __init init_svm(void)
>  	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
>  	 * otherwise.
>  	 */
> -	swiotlb_force = SWIOTLB_FORCE;
> +	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;

This is the only place you set the ppc_swiotlb_flags.. so I wonder why
the '|=' instead of just '=' ?

Either way:
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-07  0:25     ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

> diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
> index c5228f4969eb2..3b4045d508ec8 100644
> --- a/arch/powerpc/platforms/pseries/svm.c
> +++ b/arch/powerpc/platforms/pseries/svm.c
> @@ -28,7 +28,7 @@ static int __init init_svm(void)
>  	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
>  	 * otherwise.
>  	 */
> -	swiotlb_force = SWIOTLB_FORCE;
> +	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;

This is the only place you set the ppc_swiotlb_flags.. so I wonder why
the '|=' instead of just '=' ?

Either way:
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-07  0:25     ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, linux-hyperv, Anshuman Khandual, Robin Murphy,
	Joerg Roedel, x86, linux-mips, linuxppc-dev, iommu, tboot-devel,
	linux-pci, xen-devel, Boris Ostrovsky, David Woodhouse,
	linux-riscv, linux-arm-kernel, Lu Baolu

> diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
> index c5228f4969eb2..3b4045d508ec8 100644
> --- a/arch/powerpc/platforms/pseries/svm.c
> +++ b/arch/powerpc/platforms/pseries/svm.c
> @@ -28,7 +28,7 @@ static int __init init_svm(void)
>  	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
>  	 * otherwise.
>  	 */
> -	swiotlb_force = SWIOTLB_FORCE;
> +	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;

This is the only place you set the ppc_swiotlb_flags.. so I wonder why
the '|=' instead of just '=' ?

Either way:
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-07  0:25     ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, linux-hyperv, Anshuman Khandual, Robin Murphy, x86,
	linux-mips, linuxppc-dev, iommu, tboot-devel, linux-pci,
	xen-devel, Boris Ostrovsky, David Woodhouse, linux-riscv,
	linux-arm-kernel

> diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
> index c5228f4969eb2..3b4045d508ec8 100644
> --- a/arch/powerpc/platforms/pseries/svm.c
> +++ b/arch/powerpc/platforms/pseries/svm.c
> @@ -28,7 +28,7 @@ static int __init init_svm(void)
>  	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
>  	 * otherwise.
>  	 */
> -	swiotlb_force = SWIOTLB_FORCE;
> +	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;

This is the only place you set the ppc_swiotlb_flags.. so I wonder why
the '|=' instead of just '=' ?

Either way:
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-07  0:25     ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

> diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
> index c5228f4969eb2..3b4045d508ec8 100644
> --- a/arch/powerpc/platforms/pseries/svm.c
> +++ b/arch/powerpc/platforms/pseries/svm.c
> @@ -28,7 +28,7 @@ static int __init init_svm(void)
>  	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
>  	 * otherwise.
>  	 */
> -	swiotlb_force = SWIOTLB_FORCE;
> +	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;

This is the only place you set the ppc_swiotlb_flags.. so I wonder why
the '|=' instead of just '=' ?

Either way:
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-07  0:25     ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

> diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
> index c5228f4969eb2..3b4045d508ec8 100644
> --- a/arch/powerpc/platforms/pseries/svm.c
> +++ b/arch/powerpc/platforms/pseries/svm.c
> @@ -28,7 +28,7 @@ static int __init init_svm(void)
>  	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
>  	 * otherwise.
>  	 */
> -	swiotlb_force = SWIOTLB_FORCE;
> +	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;

This is the only place you set the ppc_swiotlb_flags.. so I wonder why
the '|=' instead of just '=' ?

Either way:
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-07  0:31   ` Konrad Rzeszutek Wilk
  -1 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:31 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Mon, Apr 04, 2022 at 07:05:44AM +0200, Christoph Hellwig wrote:
> Hi all,
> 
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
> 
> Git tree:
> 
>     git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
> 
> Gitweb:
> 
>     http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup
> 
> Changes since v7:
>  - rebased to Linux 5.18-rc1
>  - better document the lower bound swiotlb size for xen-swiotlb
>  - improve the nslabs calculation for the retry case in
>    swiotlb_init_remap and swiotlb_init_late

Hey Christoph,

Feel free to tack on

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

on them if you would like.

Thank you for doing the spring cleaning of this codebase!

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-07  0:31   ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:31 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Mon, Apr 04, 2022 at 07:05:44AM +0200, Christoph Hellwig wrote:
> Hi all,
> 
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
> 
> Git tree:
> 
>     git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
> 
> Gitweb:
> 
>     http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup
> 
> Changes since v7:
>  - rebased to Linux 5.18-rc1
>  - better document the lower bound swiotlb size for xen-swiotlb
>  - improve the nslabs calculation for the retry case in
>    swiotlb_init_remap and swiotlb_init_late

Hey Christoph,

Feel free to tack on

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

on them if you would like.

Thank you for doing the spring cleaning of this codebase!

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-07  0:31   ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:31 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, linux-hyperv, Anshuman Khandual, Robin Murphy,
	Joerg Roedel, x86, linux-mips, linuxppc-dev, iommu, tboot-devel,
	linux-pci, xen-devel, Boris Ostrovsky, David Woodhouse,
	linux-riscv, linux-arm-kernel, Lu Baolu

On Mon, Apr 04, 2022 at 07:05:44AM +0200, Christoph Hellwig wrote:
> Hi all,
> 
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
> 
> Git tree:
> 
>     git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
> 
> Gitweb:
> 
>     http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup
> 
> Changes since v7:
>  - rebased to Linux 5.18-rc1
>  - better document the lower bound swiotlb size for xen-swiotlb
>  - improve the nslabs calculation for the retry case in
>    swiotlb_init_remap and swiotlb_init_late

Hey Christoph,

Feel free to tack on

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

on them if you would like.

Thank you for doing the spring cleaning of this codebase!

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-07  0:31   ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:31 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, linux-hyperv, Anshuman Khandual, Robin Murphy, x86,
	linux-mips, linuxppc-dev, iommu, tboot-devel, linux-pci,
	xen-devel, Boris Ostrovsky, David Woodhouse, linux-riscv,
	linux-arm-kernel

On Mon, Apr 04, 2022 at 07:05:44AM +0200, Christoph Hellwig wrote:
> Hi all,
> 
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
> 
> Git tree:
> 
>     git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
> 
> Gitweb:
> 
>     http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup
> 
> Changes since v7:
>  - rebased to Linux 5.18-rc1
>  - better document the lower bound swiotlb size for xen-swiotlb
>  - improve the nslabs calculation for the retry case in
>    swiotlb_init_remap and swiotlb_init_late

Hey Christoph,

Feel free to tack on

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

on them if you would like.

Thank you for doing the spring cleaning of this codebase!
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-07  0:31   ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:31 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Mon, Apr 04, 2022 at 07:05:44AM +0200, Christoph Hellwig wrote:
> Hi all,
> 
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
> 
> Git tree:
> 
>     git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
> 
> Gitweb:
> 
>     http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup
> 
> Changes since v7:
>  - rebased to Linux 5.18-rc1
>  - better document the lower bound swiotlb size for xen-swiotlb
>  - improve the nslabs calculation for the retry case in
>    swiotlb_init_remap and swiotlb_init_late

Hey Christoph,

Feel free to tack on

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

on them if you would like.

Thank you for doing the spring cleaning of this codebase!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-07  0:31   ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 197+ messages in thread
From: Konrad Rzeszutek Wilk @ 2022-04-07  0:31 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky, Stefano Stabellini,
	Boris Ostrovsky, Juergen Gross, Joerg Roedel, David Woodhouse,
	Lu Baolu, Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Mon, Apr 04, 2022 at 07:05:44AM +0200, Christoph Hellwig wrote:
> Hi all,
> 
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
> 
> Git tree:
> 
>     git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
> 
> Gitweb:
> 
>     http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup
> 
> Changes since v7:
>  - rebased to Linux 5.18-rc1
>  - better document the lower bound swiotlb size for xen-swiotlb
>  - improve the nslabs calculation for the retry case in
>    swiotlb_init_remap and swiotlb_init_late

Hey Christoph,

Feel free to tack on

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

on them if you would like.

Thank you for doing the spring cleaning of this codebase!

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
  2022-04-07  0:25     ` Konrad Rzeszutek Wilk
                         ` (3 preceding siblings ...)
  (?)
@ 2022-04-12  6:21       ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-12  6:21 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

On Wed, Apr 06, 2022 at 08:25:32PM -0400, Konrad Rzeszutek Wilk wrote:
> > diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
> > index c5228f4969eb2..3b4045d508ec8 100644
> > --- a/arch/powerpc/platforms/pseries/svm.c
> > +++ b/arch/powerpc/platforms/pseries/svm.c
> > @@ -28,7 +28,7 @@ static int __init init_svm(void)
> >  	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
> >  	 * otherwise.
> >  	 */
> > -	swiotlb_force = SWIOTLB_FORCE;
> > +	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
> 
> This is the only place you set the ppc_swiotlb_flags.. so I wonder why
> the '|=' instead of just '=' ?

Preparing for setting others and not clobbering the value.

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-12  6:21       ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-12  6:21 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: linux-hyperv, linux-ia64, linux-pci, linux-riscv,
	Christoph Hellwig, linux-s390, Stefano Stabellini, x86,
	tboot-devel, xen-devel, David Woodhouse, Tom Lendacky,
	Anshuman Khandual, Boris Ostrovsky, linux-arm-kernel,
	Juergen Gross, linuxppc-dev, linux-mips, iommu, Robin Murphy

On Wed, Apr 06, 2022 at 08:25:32PM -0400, Konrad Rzeszutek Wilk wrote:
> > diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
> > index c5228f4969eb2..3b4045d508ec8 100644
> > --- a/arch/powerpc/platforms/pseries/svm.c
> > +++ b/arch/powerpc/platforms/pseries/svm.c
> > @@ -28,7 +28,7 @@ static int __init init_svm(void)
> >  	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
> >  	 * otherwise.
> >  	 */
> > -	swiotlb_force = SWIOTLB_FORCE;
> > +	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
> 
> This is the only place you set the ppc_swiotlb_flags.. so I wonder why
> the '|=' instead of just '=' ?

Preparing for setting others and not clobbering the value.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-12  6:21       ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-12  6:21 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

On Wed, Apr 06, 2022 at 08:25:32PM -0400, Konrad Rzeszutek Wilk wrote:
> > diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
> > index c5228f4969eb2..3b4045d508ec8 100644
> > --- a/arch/powerpc/platforms/pseries/svm.c
> > +++ b/arch/powerpc/platforms/pseries/svm.c
> > @@ -28,7 +28,7 @@ static int __init init_svm(void)
> >  	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
> >  	 * otherwise.
> >  	 */
> > -	swiotlb_force = SWIOTLB_FORCE;
> > +	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
> 
> This is the only place you set the ppc_swiotlb_flags.. so I wonder why
> the '|=' instead of just '=' ?

Preparing for setting others and not clobbering the value.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-12  6:21       ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-12  6:21 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: linux-hyperv, linux-ia64, linux-pci, linux-riscv,
	Christoph Hellwig, linux-s390, Stefano Stabellini, Joerg Roedel,
	x86, tboot-devel, xen-devel, David Woodhouse, Tom Lendacky,
	Anshuman Khandual, Boris Ostrovsky, linux-arm-kernel,
	Juergen Gross, linuxppc-dev, linux-mips, iommu, Robin Murphy,
	Lu Baolu

On Wed, Apr 06, 2022 at 08:25:32PM -0400, Konrad Rzeszutek Wilk wrote:
> > diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
> > index c5228f4969eb2..3b4045d508ec8 100644
> > --- a/arch/powerpc/platforms/pseries/svm.c
> > +++ b/arch/powerpc/platforms/pseries/svm.c
> > @@ -28,7 +28,7 @@ static int __init init_svm(void)
> >  	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
> >  	 * otherwise.
> >  	 */
> > -	swiotlb_force = SWIOTLB_FORCE;
> > +	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
> 
> This is the only place you set the ppc_swiotlb_flags.. so I wonder why
> the '|=' instead of just '=' ?

Preparing for setting others and not clobbering the value.

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-12  6:21       ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-12  6:21 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

On Wed, Apr 06, 2022 at 08:25:32PM -0400, Konrad Rzeszutek Wilk wrote:
> > diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
> > index c5228f4969eb2..3b4045d508ec8 100644
> > --- a/arch/powerpc/platforms/pseries/svm.c
> > +++ b/arch/powerpc/platforms/pseries/svm.c
> > @@ -28,7 +28,7 @@ static int __init init_svm(void)
> >  	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
> >  	 * otherwise.
> >  	 */
> > -	swiotlb_force = SWIOTLB_FORCE;
> > +	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
> 
> This is the only place you set the ppc_swiotlb_flags.. so I wonder why
> the '|=' instead of just '=' ?

Preparing for setting others and not clobbering the value.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
@ 2022-04-12  6:21       ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-12  6:21 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

On Wed, Apr 06, 2022 at 08:25:32PM -0400, Konrad Rzeszutek Wilk wrote:
> > diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
> > index c5228f4969eb2..3b4045d508ec8 100644
> > --- a/arch/powerpc/platforms/pseries/svm.c
> > +++ b/arch/powerpc/platforms/pseries/svm.c
> > @@ -28,7 +28,7 @@ static int __init init_svm(void)
> >  	 * need to use the SWIOTLB buffer for DMA even if dma_capable() says
> >  	 * otherwise.
> >  	 */
> > -	swiotlb_force = SWIOTLB_FORCE;
> > +	ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
> 
> This is the only place you set the ppc_swiotlb_flags.. so I wonder why
> the '|=' instead of just '=' ?

Preparing for setting others and not clobbering the value.

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
  2022-04-04  5:05 ` Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-04-13  6:20   ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-13  6:20 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

On Mon, Apr 04, 2022 at 07:05:44AM +0200, Christoph Hellwig wrote:
> Hi all,
> 
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
> 
> Git tree:
> 
>     git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
> 
> Gitweb:
> 
>     http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup

I've updated the git tree above with the commit message nitpicks and
received reviews.  I plan to pull the patches into the dma-mapping
tree after -rc3 is released, so if any involved maintainer is not happy
with the result, please speak up now.

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-13  6:20   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-13  6:20 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

On Mon, Apr 04, 2022 at 07:05:44AM +0200, Christoph Hellwig wrote:
> Hi all,
> 
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
> 
> Git tree:
> 
>     git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
> 
> Gitweb:
> 
>     http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup

I've updated the git tree above with the commit message nitpicks and
received reviews.  I plan to pull the patches into the dma-mapping
tree after -rc3 is released, so if any involved maintainer is not happy
with the result, please speak up now.

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-13  6:20   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-13  6:20 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

On Mon, Apr 04, 2022 at 07:05:44AM +0200, Christoph Hellwig wrote:
> Hi all,
> 
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
> 
> Git tree:
> 
>     git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
> 
> Gitweb:
> 
>     http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup

I've updated the git tree above with the commit message nitpicks and
received reviews.  I plan to pull the patches into the dma-mapping
tree after -rc3 is released, so if any involved maintainer is not happy
with the result, please speak up now.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-13  6:20   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-13  6:20 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

On Mon, Apr 04, 2022 at 07:05:44AM +0200, Christoph Hellwig wrote:
> Hi all,
> 
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
> 
> Git tree:
> 
>     git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
> 
> Gitweb:
> 
>     http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup

I've updated the git tree above with the commit message nitpicks and
received reviews.  I plan to pull the patches into the dma-mapping
tree after -rc3 is released, so if any involved maintainer is not happy
with the result, please speak up now.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-13  6:20   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-13  6:20 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

On Mon, Apr 04, 2022 at 07:05:44AM +0200, Christoph Hellwig wrote:
> Hi all,
> 
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
> 
> Git tree:
> 
>     git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
> 
> Gitweb:
> 
>     http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup

I've updated the git tree above with the commit message nitpicks and
received reviews.  I plan to pull the patches into the dma-mapping
tree after -rc3 is released, so if any involved maintainer is not happy
with the result, please speak up now.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: cleanup swiotlb initialization v8
@ 2022-04-13  6:20   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-04-13  6:20 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

On Mon, Apr 04, 2022 at 07:05:44AM +0200, Christoph Hellwig wrote:
> Hi all,
> 
> this series tries to clean up the swiotlb initialization, including
> that of swiotlb-xen.  To get there is also removes the x86 iommu table
> infrastructure that massively obsfucates the initialization path.
> 
> Git tree:
> 
>     git://git.infradead.org/users/hch/misc.git swiotlb-init-cleanup
> 
> Gitweb:
> 
>     http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/swiotlb-init-cleanup

I've updated the git tree above with the commit message nitpicks and
received reviews.  I plan to pull the patches into the dma-mapping
tree after -rc3 is released, so if any involved maintainer is not happy
with the result, please speak up now.

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
  2022-04-04  5:05   ` Christoph Hellwig
                       ` (3 preceding siblings ...)
  (?)
@ 2022-06-01 17:25     ` Nathan Chancellor
  -1 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 17:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

Hi Christoph,

On Mon, Apr 04, 2022 at 07:05:53AM +0200, Christoph Hellwig wrote:
> Pass a bool to pass if swiotlb needs to be enabled based on the
> addressing needs and replace the verbose argument with a set of
> flags, including one to force enable bounce buffering.
> 
> Note that this patch removes the possibility to force xen-swiotlb
> use using swiotlb=force on the command line on x86 (arm and arm64
> never supported that), but this interface will be restored shortly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

I bisected a performance regression in WSL2 to this change as commit
c6af2aa9ffc9 ("swiotlb: make the swiotlb_init interface more useful") in
mainline (bisect log below). I initially noticed it because accessing the
Windows filesystem through the /mnt/c mount is about 40x slower if I am doing
my math right based on the benchmarks below.

Before:

$ uname -r; and hyperfine "ls -l /mnt/c/Users/natec/Downloads"
5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708
Benchmark 1: ls -l /mnt/c/Users/natec/Downloads
  Time (mean ± σ):     564.5 ms ±  24.1 ms    [User: 2.5 ms, System: 130.3 ms]
  Range (min … max):   510.2 ms … 588.0 ms    10 runs

After

$ uname -r; and hyperfine "ls -l /mnt/c/Users/natec/Downloads"
5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9
Benchmark 1: ls -l /mnt/c/Users/natec/Downloads
  Time (mean ± σ):     23.282 s ±  1.220 s    [User: 0.013 s, System: 0.101 s]
  Range (min … max):   21.793 s … 25.317 s    10 runs

I do see 'swiotlb=force' on the cmdline:

$ cat /proc/cmdline
initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0

/mnt/c appears to be a 9p mount, not sure if that is relevant here:

$ mount &| grep /mnt/c
drvfs on /mnt/c type 9p (rw,noatime,dirsync,aname=drvfs;path=C:\;uid=1000;gid=1000;symlinkroot=/mnt/,mmap,access=client,msize=262144,trans=virtio)

If there is any other information I can provide, please let me know.

Cheers,
Nathan

# bad: [700170bf6b4d773e328fa54ebb70ba444007c702] Merge tag 'nfs-for-5.19-1' of git://git.linux-nfs.org/projects/anna/linux-nfs
# good: [4b0986a3613c92f4ec1bdc7f60ec66fea135991f] Linux 5.18
git bisect start '700170bf6b4d773e328fa54ebb70ba444007c702' 'v5.18'
# good: [86c87bea6b42100c67418af690919c44de6ede6e] Merge tag 'devicetree-for-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux
git bisect good 86c87bea6b42100c67418af690919c44de6ede6e
# bad: [ae862183285cbb2ef9032770d98ffa9becffe9d5] Merge tag 'arm-dt-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
git bisect bad ae862183285cbb2ef9032770d98ffa9becffe9d5
# good: [2518f226c60d8e04d18ba4295500a5b0b8ac7659] Merge tag 'drm-next-2022-05-25' of git://anongit.freedesktop.org/drm/drm
git bisect good 2518f226c60d8e04d18ba4295500a5b0b8ac7659
# bad: [babf0bb978e3c9fce6c4eba6b744c8754fd43d8e] Merge tag 'xfs-5.19-for-linus' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
git bisect bad babf0bb978e3c9fce6c4eba6b744c8754fd43d8e
# good: [beed983621fbdfd291e6e3a0cdc4d10517e60af8] ASoC: Intel: avs: Machine board registration
git bisect good beed983621fbdfd291e6e3a0cdc4d10517e60af8
# good: [fbe86daca0ba878b04fa241b85e26e54d17d4229] Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
git bisect good fbe86daca0ba878b04fa241b85e26e54d17d4229
# good: [166afc45ed5523298541fd0297f9ad585cc2708c] Merge tag 'reflink-speedups-5.19_2022-04-28' of git://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-5.19-for-next
git bisect good 166afc45ed5523298541fd0297f9ad585cc2708c
# bad: [e375780b631a5fc2a61a3b4fa12429255361a31e] Merge tag 'fsnotify_for_v5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
git bisect bad e375780b631a5fc2a61a3b4fa12429255361a31e
# bad: [4a37f3dd9a83186cb88d44808ab35b78375082c9] dma-direct: don't over-decrypt memory
git bisect bad 4a37f3dd9a83186cb88d44808ab35b78375082c9
# bad: [742519538e6b07250c8085bbff4bd358bc03bf16] swiotlb: pass a gfp_mask argument to swiotlb_init_late
git bisect bad 742519538e6b07250c8085bbff4bd358bc03bf16
# good: [9bbe7a7fc126e3d14fefa4b035854aba080926d9] arm/xen: don't check for xen_initial_domain() in xen_create_contiguous_region
git bisect good 9bbe7a7fc126e3d14fefa4b035854aba080926d9
# good: [a3e230926708125205ffd06d3dc2175a8263ae7e] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled
git bisect good a3e230926708125205ffd06d3dc2175a8263ae7e
# bad: [8ba2ed1be90fc210126f68186564707478552c95] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
git bisect bad 8ba2ed1be90fc210126f68186564707478552c95
# bad: [c6af2aa9ffc9763826607bc2664ef3ea4475ed18] swiotlb: make the swiotlb_init interface more useful
git bisect bad c6af2aa9ffc9763826607bc2664ef3ea4475ed18
# first bad commit: [c6af2aa9ffc9763826607bc2664ef3ea4475ed18] swiotlb: make the swiotlb_init interface more useful

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:25     ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 17:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

Hi Christoph,

On Mon, Apr 04, 2022 at 07:05:53AM +0200, Christoph Hellwig wrote:
> Pass a bool to pass if swiotlb needs to be enabled based on the
> addressing needs and replace the verbose argument with a set of
> flags, including one to force enable bounce buffering.
> 
> Note that this patch removes the possibility to force xen-swiotlb
> use using swiotlb=force on the command line on x86 (arm and arm64
> never supported that), but this interface will be restored shortly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

I bisected a performance regression in WSL2 to this change as commit
c6af2aa9ffc9 ("swiotlb: make the swiotlb_init interface more useful") in
mainline (bisect log below). I initially noticed it because accessing the
Windows filesystem through the /mnt/c mount is about 40x slower if I am doing
my math right based on the benchmarks below.

Before:

$ uname -r; and hyperfine "ls -l /mnt/c/Users/natec/Downloads"
5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708
Benchmark 1: ls -l /mnt/c/Users/natec/Downloads
  Time (mean ± σ):     564.5 ms ±  24.1 ms    [User: 2.5 ms, System: 130.3 ms]
  Range (min … max):   510.2 ms … 588.0 ms    10 runs

After

$ uname -r; and hyperfine "ls -l /mnt/c/Users/natec/Downloads"
5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9
Benchmark 1: ls -l /mnt/c/Users/natec/Downloads
  Time (mean ± σ):     23.282 s ±  1.220 s    [User: 0.013 s, System: 0.101 s]
  Range (min … max):   21.793 s … 25.317 s    10 runs

I do see 'swiotlb=force' on the cmdline:

$ cat /proc/cmdline
initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0

/mnt/c appears to be a 9p mount, not sure if that is relevant here:

$ mount &| grep /mnt/c
drvfs on /mnt/c type 9p (rw,noatime,dirsync,aname=drvfs;path=C:\;uid=1000;gid=1000;symlinkroot=/mnt/,mmap,access=client,msize=262144,trans=virtio)

If there is any other information I can provide, please let me know.

Cheers,
Nathan

# bad: [700170bf6b4d773e328fa54ebb70ba444007c702] Merge tag 'nfs-for-5.19-1' of git://git.linux-nfs.org/projects/anna/linux-nfs
# good: [4b0986a3613c92f4ec1bdc7f60ec66fea135991f] Linux 5.18
git bisect start '700170bf6b4d773e328fa54ebb70ba444007c702' 'v5.18'
# good: [86c87bea6b42100c67418af690919c44de6ede6e] Merge tag 'devicetree-for-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux
git bisect good 86c87bea6b42100c67418af690919c44de6ede6e
# bad: [ae862183285cbb2ef9032770d98ffa9becffe9d5] Merge tag 'arm-dt-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
git bisect bad ae862183285cbb2ef9032770d98ffa9becffe9d5
# good: [2518f226c60d8e04d18ba4295500a5b0b8ac7659] Merge tag 'drm-next-2022-05-25' of git://anongit.freedesktop.org/drm/drm
git bisect good 2518f226c60d8e04d18ba4295500a5b0b8ac7659
# bad: [babf0bb978e3c9fce6c4eba6b744c8754fd43d8e] Merge tag 'xfs-5.19-for-linus' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
git bisect bad babf0bb978e3c9fce6c4eba6b744c8754fd43d8e
# good: [beed983621fbdfd291e6e3a0cdc4d10517e60af8] ASoC: Intel: avs: Machine board registration
git bisect good beed983621fbdfd291e6e3a0cdc4d10517e60af8
# good: [fbe86daca0ba878b04fa241b85e26e54d17d4229] Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
git bisect good fbe86daca0ba878b04fa241b85e26e54d17d4229
# good: [166afc45ed5523298541fd0297f9ad585cc2708c] Merge tag 'reflink-speedups-5.19_2022-04-28' of git://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-5.19-for-next
git bisect good 166afc45ed5523298541fd0297f9ad585cc2708c
# bad: [e375780b631a5fc2a61a3b4fa12429255361a31e] Merge tag 'fsnotify_for_v5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
git bisect bad e375780b631a5fc2a61a3b4fa12429255361a31e
# bad: [4a37f3dd9a83186cb88d44808ab35b78375082c9] dma-direct: don't over-decrypt memory
git bisect bad 4a37f3dd9a83186cb88d44808ab35b78375082c9
# bad: [742519538e6b07250c8085bbff4bd358bc03bf16] swiotlb: pass a gfp_mask argument to swiotlb_init_late
git bisect bad 742519538e6b07250c8085bbff4bd358bc03bf16
# good: [9bbe7a7fc126e3d14fefa4b035854aba080926d9] arm/xen: don't check for xen_initial_domain() in xen_create_contiguous_region
git bisect good 9bbe7a7fc126e3d14fefa4b035854aba080926d9
# good: [a3e230926708125205ffd06d3dc2175a8263ae7e] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled
git bisect good a3e230926708125205ffd06d3dc2175a8263ae7e
# bad: [8ba2ed1be90fc210126f68186564707478552c95] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
git bisect bad 8ba2ed1be90fc210126f68186564707478552c95
# bad: [c6af2aa9ffc9763826607bc2664ef3ea4475ed18] swiotlb: make the swiotlb_init interface more useful
git bisect bad c6af2aa9ffc9763826607bc2664ef3ea4475ed18
# first bad commit: [c6af2aa9ffc9763826607bc2664ef3ea4475ed18] swiotlb: make the swiotlb_init interface more useful

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:25     ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 17:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Joerg Roedel,
	Konrad Rzeszutek Wilk, tboot-devel, xen-devel, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, linuxppc-dev, linux-mips, iommu,
	Robin Murphy, Lu Baolu

Hi Christoph,

On Mon, Apr 04, 2022 at 07:05:53AM +0200, Christoph Hellwig wrote:
> Pass a bool to pass if swiotlb needs to be enabled based on the
> addressing needs and replace the verbose argument with a set of
> flags, including one to force enable bounce buffering.
> 
> Note that this patch removes the possibility to force xen-swiotlb
> use using swiotlb=force on the command line on x86 (arm and arm64
> never supported that), but this interface will be restored shortly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

I bisected a performance regression in WSL2 to this change as commit
c6af2aa9ffc9 ("swiotlb: make the swiotlb_init interface more useful") in
mainline (bisect log below). I initially noticed it because accessing the
Windows filesystem through the /mnt/c mount is about 40x slower if I am doing
my math right based on the benchmarks below.

Before:

$ uname -r; and hyperfine "ls -l /mnt/c/Users/natec/Downloads"
5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708
Benchmark 1: ls -l /mnt/c/Users/natec/Downloads
  Time (mean ± σ):     564.5 ms ±  24.1 ms    [User: 2.5 ms, System: 130.3 ms]
  Range (min … max):   510.2 ms … 588.0 ms    10 runs

After

$ uname -r; and hyperfine "ls -l /mnt/c/Users/natec/Downloads"
5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9
Benchmark 1: ls -l /mnt/c/Users/natec/Downloads
  Time (mean ± σ):     23.282 s ±  1.220 s    [User: 0.013 s, System: 0.101 s]
  Range (min … max):   21.793 s … 25.317 s    10 runs

I do see 'swiotlb=force' on the cmdline:

$ cat /proc/cmdline
initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0

/mnt/c appears to be a 9p mount, not sure if that is relevant here:

$ mount &| grep /mnt/c
drvfs on /mnt/c type 9p (rw,noatime,dirsync,aname=drvfs;path=C:\;uid=1000;gid=1000;symlinkroot=/mnt/,mmap,access=client,msize=262144,trans=virtio)

If there is any other information I can provide, please let me know.

Cheers,
Nathan

# bad: [700170bf6b4d773e328fa54ebb70ba444007c702] Merge tag 'nfs-for-5.19-1' of git://git.linux-nfs.org/projects/anna/linux-nfs
# good: [4b0986a3613c92f4ec1bdc7f60ec66fea135991f] Linux 5.18
git bisect start '700170bf6b4d773e328fa54ebb70ba444007c702' 'v5.18'
# good: [86c87bea6b42100c67418af690919c44de6ede6e] Merge tag 'devicetree-for-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux
git bisect good 86c87bea6b42100c67418af690919c44de6ede6e
# bad: [ae862183285cbb2ef9032770d98ffa9becffe9d5] Merge tag 'arm-dt-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
git bisect bad ae862183285cbb2ef9032770d98ffa9becffe9d5
# good: [2518f226c60d8e04d18ba4295500a5b0b8ac7659] Merge tag 'drm-next-2022-05-25' of git://anongit.freedesktop.org/drm/drm
git bisect good 2518f226c60d8e04d18ba4295500a5b0b8ac7659
# bad: [babf0bb978e3c9fce6c4eba6b744c8754fd43d8e] Merge tag 'xfs-5.19-for-linus' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
git bisect bad babf0bb978e3c9fce6c4eba6b744c8754fd43d8e
# good: [beed983621fbdfd291e6e3a0cdc4d10517e60af8] ASoC: Intel: avs: Machine board registration
git bisect good beed983621fbdfd291e6e3a0cdc4d10517e60af8
# good: [fbe86daca0ba878b04fa241b85e26e54d17d4229] Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
git bisect good fbe86daca0ba878b04fa241b85e26e54d17d4229
# good: [166afc45ed5523298541fd0297f9ad585cc2708c] Merge tag 'reflink-speedups-5.19_2022-04-28' of git://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-5.19-for-next
git bisect good 166afc45ed5523298541fd0297f9ad585cc2708c
# bad: [e375780b631a5fc2a61a3b4fa12429255361a31e] Merge tag 'fsnotify_for_v5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
git bisect bad e375780b631a5fc2a61a3b4fa12429255361a31e
# bad: [4a37f3dd9a83186cb88d44808ab35b78375082c9] dma-direct: don't over-decrypt memory
git bisect bad 4a37f3dd9a83186cb88d44808ab35b78375082c9
# bad: [742519538e6b07250c8085bbff4bd358bc03bf16] swiotlb: pass a gfp_mask argument to swiotlb_init_late
git bisect bad 742519538e6b07250c8085bbff4bd358bc03bf16
# good: [9bbe7a7fc126e3d14fefa4b035854aba080926d9] arm/xen: don't check for xen_initial_domain() in xen_create_contiguous_region
git bisect good 9bbe7a7fc126e3d14fefa4b035854aba080926d9
# good: [a3e230926708125205ffd06d3dc2175a8263ae7e] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled
git bisect good a3e230926708125205ffd06d3dc2175a8263ae7e
# bad: [8ba2ed1be90fc210126f68186564707478552c95] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
git bisect bad 8ba2ed1be90fc210126f68186564707478552c95
# bad: [c6af2aa9ffc9763826607bc2664ef3ea4475ed18] swiotlb: make the swiotlb_init interface more useful
git bisect bad c6af2aa9ffc9763826607bc2664ef3ea4475ed18
# first bad commit: [c6af2aa9ffc9763826607bc2664ef3ea4475ed18] swiotlb: make the swiotlb_init interface more useful

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:25     ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 17:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Konrad Rzeszutek Wilk,
	tboot-devel, xen-devel, David Woodhouse, Tom Lendacky,
	Anshuman Khandual, Boris Ostrovsky, linux-arm-kernel,
	Juergen Gross, linuxppc-dev, linux-mips, iommu, Robin Murphy

Hi Christoph,

On Mon, Apr 04, 2022 at 07:05:53AM +0200, Christoph Hellwig wrote:
> Pass a bool to pass if swiotlb needs to be enabled based on the
> addressing needs and replace the verbose argument with a set of
> flags, including one to force enable bounce buffering.
> 
> Note that this patch removes the possibility to force xen-swiotlb
> use using swiotlb=force on the command line on x86 (arm and arm64
> never supported that), but this interface will be restored shortly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

I bisected a performance regression in WSL2 to this change as commit
c6af2aa9ffc9 ("swiotlb: make the swiotlb_init interface more useful") in
mainline (bisect log below). I initially noticed it because accessing the
Windows filesystem through the /mnt/c mount is about 40x slower if I am doing
my math right based on the benchmarks below.

Before:

$ uname -r; and hyperfine "ls -l /mnt/c/Users/natec/Downloads"
5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708
Benchmark 1: ls -l /mnt/c/Users/natec/Downloads
  Time (mean ± σ):     564.5 ms ±  24.1 ms    [User: 2.5 ms, System: 130.3 ms]
  Range (min … max):   510.2 ms … 588.0 ms    10 runs

After

$ uname -r; and hyperfine "ls -l /mnt/c/Users/natec/Downloads"
5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9
Benchmark 1: ls -l /mnt/c/Users/natec/Downloads
  Time (mean ± σ):     23.282 s ±  1.220 s    [User: 0.013 s, System: 0.101 s]
  Range (min … max):   21.793 s … 25.317 s    10 runs

I do see 'swiotlb=force' on the cmdline:

$ cat /proc/cmdline
initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0

/mnt/c appears to be a 9p mount, not sure if that is relevant here:

$ mount &| grep /mnt/c
drvfs on /mnt/c type 9p (rw,noatime,dirsync,aname=drvfs;path=C:\;uid=1000;gid=1000;symlinkroot=/mnt/,mmap,access=client,msize=262144,trans=virtio)

If there is any other information I can provide, please let me know.

Cheers,
Nathan

# bad: [700170bf6b4d773e328fa54ebb70ba444007c702] Merge tag 'nfs-for-5.19-1' of git://git.linux-nfs.org/projects/anna/linux-nfs
# good: [4b0986a3613c92f4ec1bdc7f60ec66fea135991f] Linux 5.18
git bisect start '700170bf6b4d773e328fa54ebb70ba444007c702' 'v5.18'
# good: [86c87bea6b42100c67418af690919c44de6ede6e] Merge tag 'devicetree-for-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux
git bisect good 86c87bea6b42100c67418af690919c44de6ede6e
# bad: [ae862183285cbb2ef9032770d98ffa9becffe9d5] Merge tag 'arm-dt-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
git bisect bad ae862183285cbb2ef9032770d98ffa9becffe9d5
# good: [2518f226c60d8e04d18ba4295500a5b0b8ac7659] Merge tag 'drm-next-2022-05-25' of git://anongit.freedesktop.org/drm/drm
git bisect good 2518f226c60d8e04d18ba4295500a5b0b8ac7659
# bad: [babf0bb978e3c9fce6c4eba6b744c8754fd43d8e] Merge tag 'xfs-5.19-for-linus' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
git bisect bad babf0bb978e3c9fce6c4eba6b744c8754fd43d8e
# good: [beed983621fbdfd291e6e3a0cdc4d10517e60af8] ASoC: Intel: avs: Machine board registration
git bisect good beed983621fbdfd291e6e3a0cdc4d10517e60af8
# good: [fbe86daca0ba878b04fa241b85e26e54d17d4229] Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
git bisect good fbe86daca0ba878b04fa241b85e26e54d17d4229
# good: [166afc45ed5523298541fd0297f9ad585cc2708c] Merge tag 'reflink-speedups-5.19_2022-04-28' of git://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-5.19-for-next
git bisect good 166afc45ed5523298541fd0297f9ad585cc2708c
# bad: [e375780b631a5fc2a61a3b4fa12429255361a31e] Merge tag 'fsnotify_for_v5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
git bisect bad e375780b631a5fc2a61a3b4fa12429255361a31e
# bad: [4a37f3dd9a83186cb88d44808ab35b78375082c9] dma-direct: don't over-decrypt memory
git bisect bad 4a37f3dd9a83186cb88d44808ab35b78375082c9
# bad: [742519538e6b07250c8085bbff4bd358bc03bf16] swiotlb: pass a gfp_mask argument to swiotlb_init_late
git bisect bad 742519538e6b07250c8085bbff4bd358bc03bf16
# good: [9bbe7a7fc126e3d14fefa4b035854aba080926d9] arm/xen: don't check for xen_initial_domain() in xen_create_contiguous_region
git bisect good 9bbe7a7fc126e3d14fefa4b035854aba080926d9
# good: [a3e230926708125205ffd06d3dc2175a8263ae7e] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled
git bisect good a3e230926708125205ffd06d3dc2175a8263ae7e
# bad: [8ba2ed1be90fc210126f68186564707478552c95] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
git bisect bad 8ba2ed1be90fc210126f68186564707478552c95
# bad: [c6af2aa9ffc9763826607bc2664ef3ea4475ed18] swiotlb: make the swiotlb_init interface more useful
git bisect bad c6af2aa9ffc9763826607bc2664ef3ea4475ed18
# first bad commit: [c6af2aa9ffc9763826607bc2664ef3ea4475ed18] swiotlb: make the swiotlb_init interface more useful
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:25     ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 17:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

Hi Christoph,

On Mon, Apr 04, 2022 at 07:05:53AM +0200, Christoph Hellwig wrote:
> Pass a bool to pass if swiotlb needs to be enabled based on the
> addressing needs and replace the verbose argument with a set of
> flags, including one to force enable bounce buffering.
> 
> Note that this patch removes the possibility to force xen-swiotlb
> use using swiotlb=force on the command line on x86 (arm and arm64
> never supported that), but this interface will be restored shortly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

I bisected a performance regression in WSL2 to this change as commit
c6af2aa9ffc9 ("swiotlb: make the swiotlb_init interface more useful") in
mainline (bisect log below). I initially noticed it because accessing the
Windows filesystem through the /mnt/c mount is about 40x slower if I am doing
my math right based on the benchmarks below.

Before:

$ uname -r; and hyperfine "ls -l /mnt/c/Users/natec/Downloads"
5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708
Benchmark 1: ls -l /mnt/c/Users/natec/Downloads
  Time (mean ± σ):     564.5 ms ±  24.1 ms    [User: 2.5 ms, System: 130.3 ms]
  Range (min … max):   510.2 ms … 588.0 ms    10 runs

After

$ uname -r; and hyperfine "ls -l /mnt/c/Users/natec/Downloads"
5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9
Benchmark 1: ls -l /mnt/c/Users/natec/Downloads
  Time (mean ± σ):     23.282 s ±  1.220 s    [User: 0.013 s, System: 0.101 s]
  Range (min … max):   21.793 s … 25.317 s    10 runs

I do see 'swiotlb=force' on the cmdline:

$ cat /proc/cmdline
initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0

/mnt/c appears to be a 9p mount, not sure if that is relevant here:

$ mount &| grep /mnt/c
drvfs on /mnt/c type 9p (rw,noatime,dirsync,aname=drvfs;path=C:\;uid=1000;gid=1000;symlinkroot=/mnt/,mmap,access=client,msize=262144,trans=virtio)

If there is any other information I can provide, please let me know.

Cheers,
Nathan

# bad: [700170bf6b4d773e328fa54ebb70ba444007c702] Merge tag 'nfs-for-5.19-1' of git://git.linux-nfs.org/projects/anna/linux-nfs
# good: [4b0986a3613c92f4ec1bdc7f60ec66fea135991f] Linux 5.18
git bisect start '700170bf6b4d773e328fa54ebb70ba444007c702' 'v5.18'
# good: [86c87bea6b42100c67418af690919c44de6ede6e] Merge tag 'devicetree-for-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux
git bisect good 86c87bea6b42100c67418af690919c44de6ede6e
# bad: [ae862183285cbb2ef9032770d98ffa9becffe9d5] Merge tag 'arm-dt-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
git bisect bad ae862183285cbb2ef9032770d98ffa9becffe9d5
# good: [2518f226c60d8e04d18ba4295500a5b0b8ac7659] Merge tag 'drm-next-2022-05-25' of git://anongit.freedesktop.org/drm/drm
git bisect good 2518f226c60d8e04d18ba4295500a5b0b8ac7659
# bad: [babf0bb978e3c9fce6c4eba6b744c8754fd43d8e] Merge tag 'xfs-5.19-for-linus' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
git bisect bad babf0bb978e3c9fce6c4eba6b744c8754fd43d8e
# good: [beed983621fbdfd291e6e3a0cdc4d10517e60af8] ASoC: Intel: avs: Machine board registration
git bisect good beed983621fbdfd291e6e3a0cdc4d10517e60af8
# good: [fbe86daca0ba878b04fa241b85e26e54d17d4229] Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
git bisect good fbe86daca0ba878b04fa241b85e26e54d17d4229
# good: [166afc45ed5523298541fd0297f9ad585cc2708c] Merge tag 'reflink-speedups-5.19_2022-04-28' of git://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-5.19-for-next
git bisect good 166afc45ed5523298541fd0297f9ad585cc2708c
# bad: [e375780b631a5fc2a61a3b4fa12429255361a31e] Merge tag 'fsnotify_for_v5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
git bisect bad e375780b631a5fc2a61a3b4fa12429255361a31e
# bad: [4a37f3dd9a83186cb88d44808ab35b78375082c9] dma-direct: don't over-decrypt memory
git bisect bad 4a37f3dd9a83186cb88d44808ab35b78375082c9
# bad: [742519538e6b07250c8085bbff4bd358bc03bf16] swiotlb: pass a gfp_mask argument to swiotlb_init_late
git bisect bad 742519538e6b07250c8085bbff4bd358bc03bf16
# good: [9bbe7a7fc126e3d14fefa4b035854aba080926d9] arm/xen: don't check for xen_initial_domain() in xen_create_contiguous_region
git bisect good 9bbe7a7fc126e3d14fefa4b035854aba080926d9
# good: [a3e230926708125205ffd06d3dc2175a8263ae7e] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled
git bisect good a3e230926708125205ffd06d3dc2175a8263ae7e
# bad: [8ba2ed1be90fc210126f68186564707478552c95] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
git bisect bad 8ba2ed1be90fc210126f68186564707478552c95
# bad: [c6af2aa9ffc9763826607bc2664ef3ea4475ed18] swiotlb: make the swiotlb_init interface more useful
git bisect bad c6af2aa9ffc9763826607bc2664ef3ea4475ed18
# first bad commit: [c6af2aa9ffc9763826607bc2664ef3ea4475ed18] swiotlb: make the swiotlb_init interface more useful

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:25     ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 17:25 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

Hi Christoph,

On Mon, Apr 04, 2022 at 07:05:53AM +0200, Christoph Hellwig wrote:
> Pass a bool to pass if swiotlb needs to be enabled based on the
> addressing needs and replace the verbose argument with a set of
> flags, including one to force enable bounce buffering.
> 
> Note that this patch removes the possibility to force xen-swiotlb
> use using swiotlb=force on the command line on x86 (arm and arm64
> never supported that), but this interface will be restored shortly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

I bisected a performance regression in WSL2 to this change as commit
c6af2aa9ffc9 ("swiotlb: make the swiotlb_init interface more useful") in
mainline (bisect log below). I initially noticed it because accessing the
Windows filesystem through the /mnt/c mount is about 40x slower if I am doing
my math right based on the benchmarks below.

Before:

$ uname -r; and hyperfine "ls -l /mnt/c/Users/natec/Downloads"
5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708
Benchmark 1: ls -l /mnt/c/Users/natec/Downloads
  Time (mean ± σ):     564.5 ms ±  24.1 ms    [User: 2.5 ms, System: 130.3 ms]
  Range (min … max):   510.2 ms … 588.0 ms    10 runs

After

$ uname -r; and hyperfine "ls -l /mnt/c/Users/natec/Downloads"
5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9
Benchmark 1: ls -l /mnt/c/Users/natec/Downloads
  Time (mean ± σ):     23.282 s ±  1.220 s    [User: 0.013 s, System: 0.101 s]
  Range (min … max):   21.793 s … 25.317 s    10 runs

I do see 'swiotlb=force' on the cmdline:

$ cat /proc/cmdline
initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0

/mnt/c appears to be a 9p mount, not sure if that is relevant here:

$ mount &| grep /mnt/c
drvfs on /mnt/c type 9p (rw,noatime,dirsync,aname=drvfs;path=C:\;uid\x1000;gid\x1000;symlinkroot=/mnt/,mmap,access=client,msize&2144,trans=virtio)

If there is any other information I can provide, please let me know.

Cheers,
Nathan

# bad: [700170bf6b4d773e328fa54ebb70ba444007c702] Merge tag 'nfs-for-5.19-1' of git://git.linux-nfs.org/projects/anna/linux-nfs
# good: [4b0986a3613c92f4ec1bdc7f60ec66fea135991f] Linux 5.18
git bisect start '700170bf6b4d773e328fa54ebb70ba444007c702' 'v5.18'
# good: [86c87bea6b42100c67418af690919c44de6ede6e] Merge tag 'devicetree-for-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux
git bisect good 86c87bea6b42100c67418af690919c44de6ede6e
# bad: [ae862183285cbb2ef9032770d98ffa9becffe9d5] Merge tag 'arm-dt-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
git bisect bad ae862183285cbb2ef9032770d98ffa9becffe9d5
# good: [2518f226c60d8e04d18ba4295500a5b0b8ac7659] Merge tag 'drm-next-2022-05-25' of git://anongit.freedesktop.org/drm/drm
git bisect good 2518f226c60d8e04d18ba4295500a5b0b8ac7659
# bad: [babf0bb978e3c9fce6c4eba6b744c8754fd43d8e] Merge tag 'xfs-5.19-for-linus' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
git bisect bad babf0bb978e3c9fce6c4eba6b744c8754fd43d8e
# good: [beed983621fbdfd291e6e3a0cdc4d10517e60af8] ASoC: Intel: avs: Machine board registration
git bisect good beed983621fbdfd291e6e3a0cdc4d10517e60af8
# good: [fbe86daca0ba878b04fa241b85e26e54d17d4229] Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
git bisect good fbe86daca0ba878b04fa241b85e26e54d17d4229
# good: [166afc45ed5523298541fd0297f9ad585cc2708c] Merge tag 'reflink-speedups-5.19_2022-04-28' of git://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-5.19-for-next
git bisect good 166afc45ed5523298541fd0297f9ad585cc2708c
# bad: [e375780b631a5fc2a61a3b4fa12429255361a31e] Merge tag 'fsnotify_for_v5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
git bisect bad e375780b631a5fc2a61a3b4fa12429255361a31e
# bad: [4a37f3dd9a83186cb88d44808ab35b78375082c9] dma-direct: don't over-decrypt memory
git bisect bad 4a37f3dd9a83186cb88d44808ab35b78375082c9
# bad: [742519538e6b07250c8085bbff4bd358bc03bf16] swiotlb: pass a gfp_mask argument to swiotlb_init_late
git bisect bad 742519538e6b07250c8085bbff4bd358bc03bf16
# good: [9bbe7a7fc126e3d14fefa4b035854aba080926d9] arm/xen: don't check for xen_initial_domain() in xen_create_contiguous_region
git bisect good 9bbe7a7fc126e3d14fefa4b035854aba080926d9
# good: [a3e230926708125205ffd06d3dc2175a8263ae7e] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled
git bisect good a3e230926708125205ffd06d3dc2175a8263ae7e
# bad: [8ba2ed1be90fc210126f68186564707478552c95] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
git bisect bad 8ba2ed1be90fc210126f68186564707478552c95
# bad: [c6af2aa9ffc9763826607bc2664ef3ea4475ed18] swiotlb: make the swiotlb_init interface more useful
git bisect bad c6af2aa9ffc9763826607bc2664ef3ea4475ed18
# first bad commit: [c6af2aa9ffc9763826607bc2664ef3ea4475ed18] swiotlb: make the swiotlb_init interface more useful

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
  2022-06-01 17:25     ` Nathan Chancellor
                         ` (3 preceding siblings ...)
  (?)
@ 2022-06-01 17:34       ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 17:34 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

Can you send me the full dmesg and the content of
/sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?

Thanks!

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:34       ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 17:34 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

Can you send me the full dmesg and the content of
/sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?

Thanks!

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:34       ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 17:34 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	Christoph Hellwig, linux-s390, Stefano Stabellini,
	Konrad Rzeszutek Wilk, tboot-devel, xen-devel, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, linuxppc-dev, linux-mips, iommu,
	Robin Murphy

Can you send me the full dmesg and the content of
/sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?

Thanks!
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:34       ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 17:34 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

Can you send me the full dmesg and the content of
/sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?

Thanks!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:34       ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 17:34 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	Christoph Hellwig, linux-s390, Stefano Stabellini, Joerg Roedel,
	Konrad Rzeszutek Wilk, tboot-devel, xen-devel, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, linuxppc-dev, linux-mips, iommu,
	Robin Murphy, Lu Baolu

Can you send me the full dmesg and the content of
/sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?

Thanks!

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:34       ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 17:34 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

Can you send me the full dmesg and the content of
/sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?

Thanks!

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
  2022-06-01 17:34       ` Christoph Hellwig
                           ` (2 preceding siblings ...)
  (?)
@ 2022-06-01 17:46         ` Nathan Chancellor
  -1 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 17:46 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> Can you send me the full dmesg and the content of
> /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?

Sure thing, they are attached! If there is anything else I can provide
or test, I am more than happy to do so.

Cheers,
Nathan

[-- Attachment #2: good.log --]
[-- Type: text/plain, Size: 34692 bytes --]

# cat /sys/kernel/debug/swiotlb/io_tlb_nslabs
32768

# dmesg
[    0.000000] Linux version 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 (nathan@dev-arch.thelio-3990X) (gcc (GCC) 12.1.0, GNU ld (GNU Binutils) 2.38) #1 SMP PREEMPT_DYNAMIC Wed Jun 1 10:38:34 MST 2022
[    0.000000] Command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 1776
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000e0fff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000001fffff] ACPI data
[    0.000000] BIOS-e820: [mem 0x0000000000200000-0x00000000f7ffffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000100000000-0x0000000407ffffff] usable
[    0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '115200')
[    0.000000] printk: bootconsole [uart8250] enabled
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI not present or invalid.
[    0.000000] Hypervisor detected: Microsoft Hyper-V
[    0.000000] Hyper-V: privilege flags low 0xae7f, high 0x3b8030, hints 0xc2c, misc 0xe0bed7b6
[    0.000000] Hyper-V: Host Build 10.0.22000.708-0-0
[    0.000000] Hyper-V: Nested features: 0x4a0000
[    0.000000] Hyper-V: LAPIC Timer Frequency: 0x1e8480
[    0.000000] Hyper-V: Using hypercall for remote TLB flush
[    0.000000] clocksource: hyperv_clocksource_tsc_page: mask: 0xffffffffffffffff max_cycles: 0x24e6a1710, max_idle_ns: 440795202120 ns
[    0.000005] tsc: Detected 3800.008 MHz processor
[    0.001901] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.004593] e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.006806] last_pfn = 0x408000 max_arch_pfn = 0x400000000
[    0.009042] x86/PAT: Configuration [0-7]: WB  WC  UC- UC  WB  WP  UC- WT  
[    0.011760] last_pfn = 0xf8000 max_arch_pfn = 0x400000000
[    0.013959] Using GB pages for direct mapping
[    0.015749] RAMDISK: [mem 0x0371f000-0x03779fff]
[    0.017616] ACPI: Early table checksum verification disabled
[    0.019854] ACPI: RSDP 0x00000000000E0000 000024 (v02 VRTUAL)
[    0.022162] ACPI: XSDT 0x0000000000100000 000044 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.025624] ACPI: FACP 0x0000000000101000 000114 (v06 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.029022] ACPI: DSDT 0x00000000001011B8 01E184 (v02 MSFTVM DSDT01   00000001 MSFT 05000000)
[    0.032413] ACPI: FACS 0x0000000000101114 000040
[    0.034280] ACPI: OEM0 0x0000000000101154 000064 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.037699] ACPI: SRAT 0x000000000011F33C 000330 (v02 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.041089] ACPI: APIC 0x000000000011F66C 000088 (v04 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.044475] ACPI: Reserving FACP table memory at [mem 0x101000-0x101113]
[    0.047159] ACPI: Reserving DSDT table memory at [mem 0x1011b8-0x11f33b]
[    0.049905] ACPI: Reserving FACS table memory at [mem 0x101114-0x101153]
[    0.052693] ACPI: Reserving OEM0 table memory at [mem 0x101154-0x1011b7]
[    0.055404] ACPI: Reserving SRAT table memory at [mem 0x11f33c-0x11f66b]
[    0.058040] ACPI: Reserving APIC table memory at [mem 0x11f66c-0x11f6f3]
[    0.061078] Zone ranges:
[    0.062074]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.066106]   DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
[    0.068763]   Normal   [mem 0x0000000100000000-0x0000000407ffffff]
[    0.071235]   Device   empty
[    0.072384] Movable zone start for each node
[    0.074058] Early memory node ranges
[    0.075515]   node   0: [mem 0x0000000000001000-0x000000000009ffff]
[    0.077979]   node   0: [mem 0x0000000000200000-0x00000000f7ffffff]
[    0.080483]   node   0: [mem 0x0000000100000000-0x0000000407ffffff]
[    0.082980] Initmem setup node 0 [mem 0x0000000000001000-0x0000000407ffffff]
[    0.085954] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.085972] On node 0, zone DMA: 352 pages in unavailable ranges
[    0.098043] ACPI: LAPIC_NMI (acpi_id[0x01] dfl dfl lint[0x1])
[    0.102995] IOAPIC[0]: apic_id 8, version 17, address 0xfec00000, GSI 0-23
[    0.105726] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[    0.108349] ACPI: Using ACPI (MADT) for SMP configuration information
[    0.110909] smpboot: Allowing 8 CPUs, 0 hotplug CPUs
[    0.112902] [mem 0xf8000000-0xffffffff] available for PCI devices
[    0.115315] Booting paravirtualized kernel on Hyper-V
[    0.117347] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.126056] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:8 nr_node_ids:1
[    0.129513] percpu: Embedded 53 pages/cpu s178408 r8192 d30488 u262144
[    0.132139] pcpu-alloc: s178408 r8192 d30488 u262144 alloc=1*2097152
[    0.134679] pcpu-alloc: [0] 0 1 2 3 4 5 6 7 
[    0.136341] Hyper-V: PV spinlocks enabled
[    0.137917] PV qspinlock hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.140833] Built 1 zonelists, mobility grouping on.  Total pages: 4127749
[    0.143636] Kernel command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.151440] Dentry cache hash table entries: 2097152 (order: 12, 16777216 bytes, linear)
[    0.155808] Inode-cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.159017] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.184685] Memory: 4126096K/16775804K available (18449K kernel code, 2647K rwdata, 3952K rodata, 1536K init, 2448K bss, 392692K reserved, 0K cma-reserved)
[    0.190358] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
[    0.192969] ftrace: allocating 51788 entries in 203 pages
[    0.201434] ftrace: allocated 203 pages with 5 groups
[    0.204349] Dynamic Preempt: none
[    0.205846] rcu: Preemptible hierarchical RCU implementation.
[    0.208162] rcu: 	RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=8.
[    0.210799] 	Trampoline variant of Tasks RCU enabled.
[    0.212756] 	Rude variant of Tasks RCU enabled.
[    0.214541] 	Tracing variant of Tasks RCU enabled.
[    0.216404] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.219393] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=8
[    0.225278] Using NULL legacy PIC
[    0.226573] NR_IRQS: 16640, nr_irqs: 488, preallocated irqs: 0
[    0.229131] random: crng init done (trusting CPU's manufacturer)
[    0.231548] Console: colour dummy device 80x25
[    0.233276] ACPI: Core revision 20211217
[    0.234931] Failed to register legacy timer interrupt
[    0.236944] APIC: Switch to symmetric I/O mode setup
[    0.238947] Hyper-V: enabling crash_kexec_post_notifiers
[    0.241016] Hyper-V: Using IPI hypercalls
[    0.242591] Hyper-V: Using enlightened APIC (xapic mode)
[    0.242680] clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    0.248870] Calibrating delay loop (skipped), value calculated using timer frequency.. 7600.01 BogoMIPS (lpj=38000080)
[    0.253092] pid_max: default: 32768 minimum: 301
[    0.254926] LSM: Security Framework initializing
[    0.256750] Mount-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.258867] Mountpoint-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.258867] x86/cpu: User Mode Instruction Prevention (UMIP) activated
[    0.258867] Last level iTLB entries: 4KB 1024, 2MB 1024, 4MB 512
[    0.258867] Last level dTLB entries: 4KB 2048, 2MB 2048, 4MB 1024, 1GB 0
[    0.258867] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.258867] Spectre V2 : Mitigation: Retpolines
[    0.258867] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
[    0.258867] Spectre V2 : mitigation: Enabling conditional Indirect Branch Prediction Barrier
[    0.258867] Spectre V2 : User space: Mitigation: STIBP via prctl
[    0.258867] Speculative Store Bypass: Mitigation: Speculative Store Bypass disabled via prctl
[    0.258867] Freeing SMP alternatives memory: 56K
[    0.258867] smpboot: CPU0: AMD Ryzen 9 3900X 12-Core Processor (family: 0x17, model: 0x71, stepping: 0x0)
[    0.258867] cblist_init_generic: Setting adjustable number of callback queues.
[    0.258867] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.258867] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.258895] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.261292] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[    0.263817] ... version:                0
[    0.265391] ... bit width:              48
[    0.267068] ... generic registers:      6
[    0.268634] ... value mask:             0000ffffffffffff
[    0.268871] ... max period:             00007fffffffffff
[    0.270991] ... fixed-purpose events:   0
[    0.272571] ... event mask:             000000000000003f
[    0.274695] rcu: Hierarchical SRCU implementation.
[    0.276947] smp: Bringing up secondary CPUs ...
[    0.278794] x86: Booting SMP configuration:
[    0.278872] .... node  #0, CPUs:      #1 #2 #3 #4 #5 #6 #7
[    0.279525] smp: Brought up 1 node, 8 CPUs
[    0.282814] smpboot: Max logical packages: 1
[    0.284479] smpboot: Total of 8 processors activated (60800.12 BogoMIPS)
[    0.298895] node 0 deferred pages initialised in 10ms
[    0.300921] devtmpfs: initialized
[    0.300921] x86/mm: Memory block size: 128MB
[    0.302426] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.308889] futex hash table entries: 2048 (order: 5, 131072 bytes, linear)
[    0.312151] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.314571] thermal_sys: Registered thermal governor 'step_wise'
[    0.314572] thermal_sys: Registered thermal governor 'user_space'
[    0.316961] cpuidle: using governor menu
[    0.318916] PCI: Fatal: No config space access function found
[    0.322206] kprobes: kprobe jump-optimization is enabled. All kprobes are optimized if possible.
[    0.322206] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[    0.322206] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[    0.328925] raid6: skipped pq benchmark and selected avx2x4
[    0.331164] raid6: using avx2x2 recovery algorithm
[    0.331164] ACPI: Added _OSI(Module Device)
[    0.331164] ACPI: Added _OSI(Processor Device)
[    0.332457] ACPI: Added _OSI(3.0 _SCP Extensions)
[    0.334283] ACPI: Added _OSI(Processor Aggregator Device)
[    0.336463] ACPI: Added _OSI(Linux-Dell-Video)
[    0.338283] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[    0.348871] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)
[    0.355075] ACPI: 1 ACPI AML tables successfully acquired and loaded
[    0.358946] ACPI: Interpreter enabled
[    0.360583] ACPI: PM: (supports S0 S5)
[    0.362198] ACPI: Using IOAPIC for interrupt routing
[    0.364304] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
[    0.368017] ACPI: Enabled 1 GPEs in block 00 to 0F
[    0.369481] iommu: Default domain type: Translated 
[    0.371449] iommu: DMA domain TLB invalidation policy: lazy mode 
[    0.373937] SCSI subsystem initialized
[    0.375541] ACPI: bus type USB registered
[    0.377164] usbcore: registered new interface driver usbfs
[    0.378875] usbcore: registered new interface driver hub
[    0.380985] usbcore: registered new device driver usb
[    0.383023] hv_vmbus: Vmbus version:5.2
[    0.383023] PCI: Using ACPI for IRQ routing
[    0.383023] PCI: System does not support PCI
[    0.389034] clocksource: Switched to clocksource tsc-early
[    0.389075] hv_vmbus: Unknown GUID: c376c1c3-d276-48d2-90a9-c04748072c60
[    0.394146] hv_vmbus: Unknown GUID: 6e382d18-3336-4f4b-acc4-2b7703d4df4a
[    0.396909] hv_vmbus: Unknown GUID: dde9cbc0-5060-4436-9448-ea1254a5d177
[    0.399744] VFS: Disk quotas dquot_6.6.0
[    0.401370] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.404186] FS-Cache: Loaded
[    0.405386] pnp: PnP ACPI init
[    0.406693] pnp: PnP ACPI: found 3 devices
[    0.412166] NET: Registered PF_INET protocol family
[    0.414416] IP idents hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.418515] tcp_listen_portaddr_hash hash table entries: 8192 (order: 5, 131072 bytes, linear)
[    0.422058] TCP established hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.425602] TCP bind hash table entries: 65536 (order: 8, 1048576 bytes, linear)
[    0.428661] TCP: Hash tables configured (established 131072 bind 65536)
[    0.431375] UDP hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.434579] UDP-Lite hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.437587] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.440120] RPC: Registered named UNIX socket transport module.
[    0.442979] RPC: Registered udp transport module.
[    0.445120] RPC: Registered tcp transport module.
[    0.447250] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.449989] PCI: CLS 0 bytes, default 64
[    0.451619] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[    0.451654] Trying to unpack rootfs image as initramfs...
[    0.454256] software IO TLB: mapped [mem 0x00000000f4000000-0x00000000f8000000] (64MB)
[    0.456463] Freeing initrd memory: 364K
[    0.541510] kvm: no hardware support for 'kvm_intel'
[    0.543867] SVM: TSC scaling supported
[    0.545319] kvm: Nested Virtualization enabled
[    0.547040] SVM: kvm: Nested Paging enabled
[    0.548653] SVM: kvm: Hyper-V enlightened NPT TLB flush enabled
[    0.550967] SVM: kvm: Hyper-V Direct TLB Flush enabled
[    0.552946] SVM: Virtual VMLOAD VMSAVE supported
[    0.618969] Initialise system trusted keyrings
[    0.620900] workingset: timestamp_bits=46 max_order=22 bucket_order=0
[    0.624053] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.626726] NFS: Registering the id_resolver key type
[    0.628690] Key type id_resolver registered
[    0.630376] Key type id_legacy registered
[    0.631915] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.634537] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    0.637515] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[    0.640546] Key type cifs.idmap registered
[    0.642255] fuse: init (API version 7.36)
[    0.643973] SGI XFS with ACLs, security attributes, realtime, scrub, repair, quota, no debug enabled
[    0.647888] 9p: Installing v9fs 9p2000 file system support
[    0.650100] ceph: loaded (mds proto 32)
[    0.653965] NET: Registered PF_ALG protocol family
[    0.655832] xor: automatically using best checksumming function   avx       
[    0.658591] Key type asymmetric registered
[    0.660227] Asymmetric key parser 'x509' registered
[    0.662151] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[    0.665489] hv_vmbus: registering driver hv_pci
[    0.667566] hv_pci b440727e-7525-4d9c-a556-d52029b00086: PCI VMBus probing: Using version 0x10004
[    0.671953] hv_pci b440727e-7525-4d9c-a556-d52029b00086: PCI host bridge to bus 7525:00
[    0.675135] pci_bus 7525:00: root bus resource [mem 0x9ffe00000-0x9ffe02fff window]
[    0.678177] pci_bus 7525:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.682285] pci 7525:00:00.0: [1af4:1043] type 00 class 0x010000
[    0.686012] pci 7525:00:00.0: reg 0x10: [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.689489] pci 7525:00:00.0: reg 0x18: [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.693005] pci 7525:00:00.0: reg 0x20: [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.698805] pci_bus 7525:00: busn_res: [bus 00-ff] end is updated to 00
[    0.701529] pci 7525:00:00.0: BAR 0: assigned [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.705034] pci 7525:00:00.0: BAR 2: assigned [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.708415] pci 7525:00:00.0: BAR 4: assigned [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.712037] hv_pci 121abb12-7ab2-45ff-b4ee-e85a1067c860: PCI VMBus probing: Using version 0x10004
[    0.716192] hv_pci 121abb12-7ab2-45ff-b4ee-e85a1067c860: PCI host bridge to bus 7ab2:00
[    0.719504] pci_bus 7ab2:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.723020] pci 7ab2:00:00.0: [1414:008e] type 00 class 0x030200
[    0.729607] pci_bus 7ab2:00: busn_res: [bus 00-ff] end is updated to 00
[    0.732348] hv_pci 0c573a50-ca5d-42a9-9657-3920a455151c: PCI VMBus probing: Using version 0x10004
[    0.736748] hv_pci 0c573a50-ca5d-42a9-9657-3920a455151c: PCI host bridge to bus ca5d:00
[    0.739875] pci_bus ca5d:00: root bus resource [mem 0x9ffe04000-0x9ffe06fff window]
[    0.742859] pci_bus ca5d:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.746939] pci ca5d:00:00.0: [1af4:1049] type 00 class 0x010000
[    0.750206] pci ca5d:00:00.0: reg 0x10: [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.753516] pci ca5d:00:00.0: reg 0x18: [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.756826] pci ca5d:00:00.0: reg 0x20: [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.763185] pci_bus ca5d:00: busn_res: [bus 00-ff] end is updated to 00
[    0.765793] pci ca5d:00:00.0: BAR 0: assigned [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.769223] pci ca5d:00:00.0: BAR 2: assigned [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.772634] pci ca5d:00:00.0: BAR 4: assigned [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.784382] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.787110] 00:00: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    0.790429] 00:01: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[    0.829682] Non-volatile memory driver v1.3
[    0.831440] printk: console [hvc0] enabled
[    0.833112] printk: bootconsole [uart8250] disabled
[    0.836997] brd: module loaded
[    0.838058] loop: module loaded
[    0.838265] hv_vmbus: registering driver hv_storvsc
[    0.838832] wireguard: WireGuard 1.0.0 loaded. See www.wireguard.com for information.
[    0.839306] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
[    0.839681] tun: Universal TUN/TAP device driver, 1.6
[    0.839972] PPP generic driver version 2.4.2
[    0.840236] scsi host0: storvsc_host_t
[    0.840302] PPP BSD Compression module registered
[    0.840692] PPP Deflate Compression module registered
[    0.841134] PPP MPPE Compression module registered
[    0.841392] NET: Registered PF_PPPOX protocol family
[    0.841654] usbcore: registered new interface driver cdc_ether
[    0.841957] usbcore: registered new interface driver cdc_ncm
[    0.842276] hv_vmbus: registering driver hv_netvsc
[    0.842639] VFIO - User Level meta-driver version: 0.3
[    0.843061] usbcore: registered new interface driver cdc_acm
[    0.843378] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[    0.843756] usbcore: registered new interface driver ch341
[    0.843966] usbserial: USB Serial support registered for ch341-uart
[    0.844287] usbcore: registered new interface driver cp210x
[    0.844545] usbserial: USB Serial support registered for cp210x
[    0.844853] usbcore: registered new interface driver ftdi_sio
[    0.845182] usbserial: USB Serial support registered for FTDI USB Serial Device
[    0.845673] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.846016] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 1
[    0.846374] vhci_hcd: created sysfs vhci_hcd.0
[    0.846742] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.18
[    0.847077] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.847418] usb usb1: Product: USB/IP Virtual Host Controller
[    0.847660] usb usb1: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 vhci_hcd
[    0.847995] usb usb1: SerialNumber: vhci_hcd.0
[    0.848335] hub 1-0:1.0: USB hub found
[    0.848536] hub 1-0:1.0: 8 ports detected
[    0.848976] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.849254] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 2
[    0.849621] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[    0.850102] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.18
[    0.850427] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.850718] usb usb2: Product: USB/IP Virtual Host Controller
[    0.850961] usb usb2: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 vhci_hcd
[    0.851300] usb usb2: SerialNumber: vhci_hcd.0
[    0.851614] hub 2-0:1.0: USB hub found
[    0.851810] hub 2-0:1.0: 8 ports detected
[    0.852249] hv_vmbus: registering driver hyperv_keyboard
[    0.852593] rtc_cmos 00:02: RTC can wake from S4
[    0.854483] rtc_cmos 00:02: registered as rtc0
[    0.854995] rtc_cmos 00:02: setting system clock to 2022-06-01T17:39:04 UTC (1654105144)
[    0.855309] rtc_cmos 00:02: alarms up to one month, 114 bytes nvram
[    0.855718] device-mapper: ioctl: 4.46.0-ioctl (2022-02-22) initialised: dm-devel@redhat.com
[    0.856172] device-mapper: raid: Loading target version 1.15.1
[    0.856511] usbcore: registered new interface driver usbhid
[    0.856703] usbhid: USB HID core driver
[    0.856901] hv_utils: Registering HyperV Utility Driver
[    0.857113] hv_vmbus: registering driver hv_utils
[    0.857333] hv_vmbus: registering driver hv_balloon
[    0.857338] hv_utils: cannot register PTP clock: 0
[    0.857607] drop_monitor: Initializing network drop monitor service
[    0.858067] hv_utils: TimeSync IC version 4.0
[    0.858073] hv_balloon: Using Dynamic Memory protocol version 2.0
[    0.858248] Mirror/redirect action on
[    0.859029] Free page reporting enabled
[    0.859197] hv_balloon: Cold memory discard hint enabled
[    0.859770] IPVS: Registered protocols (TCP, UDP)
[    0.860029] IPVS: Connection hash table configured (size=4096, memory=64Kbytes)
[    0.860395] IPVS: ipvs loaded.
[    0.860546] IPVS: [rr] scheduler registered.
[    0.860743] IPVS: [wrr] scheduler registered.
[    0.860937] IPVS: [sh] scheduler registered.
[    0.861159] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    0.861418] ipt_CLUSTERIP: ClusterIP Version 0.8 loaded successfully
[    0.861666] Initializing XFRM netlink socket
[    0.861903] NET: Registered PF_INET6 protocol family
[    0.862439] Segment Routing with IPv6
[    0.862619] In-situ OAM (IOAM) with IPv6
[    0.862791] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    0.863092] NET: Registered PF_PACKET protocol family
[    0.863332] Bridge firewalling registered
[    0.863488] 8021q: 802.1Q VLAN Support v1.8
[    0.863653] sctp: Hash tables configured (bind 256/256)
[    0.863885] 9pnet: Installing 9P2000 support
[    0.875420] Key type dns_resolver registered
[    0.875693] Key type ceph registered
[    0.875979] libceph: loaded (mon/osd proto 15/24)
[    0.876260] NET: Registered PF_VSOCK protocol family
[    0.876540] hv_vmbus: registering driver hv_sock
[    0.876769] IPI shorthand broadcast: enabled
[    0.876968] sched_clock: Marking stable (856497151, 19750700)->(930661400, -54413549)
[    0.877527] registered taskstats version 1
[    0.878008] Loading compiled-in X.509 certificates
[    0.878392] Btrfs loaded, crc32c=crc32c-generic, zoned=no, fsverity=no
[    0.883871] Freeing unused kernel image (initmem) memory: 1536K
[    0.958961] Write protecting the kernel read-only data: 24576k
[    0.959743] Freeing unused kernel image (text/rodata gap) memory: 2028K
[    0.960146] Freeing unused kernel image (rodata/data gap) memory: 144K
[    0.960406] Run /init as init process
[    0.960549]   with arguments:
[    0.960690]     /init
[    0.960790]   with environment:
[    0.960931]     HOME=/
[    0.961046]     TERM=linux
[    0.963320] scsi 0:0:0:0: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    0.964110] sd 0:0:0:0: Attached scsi generic sg0 type 0
[    0.964747] sd 0:0:0:0: [sda] 641944 512-byte logical blocks: (329 MB/313 MiB)
[    0.965293] sd 0:0:0:0: [sda] Write Protect is on
[    0.965554] sd 0:0:0:0: [sda] Mode Sense: 0f 00 80 00
[    0.965967] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[    1.459424] EXT4-fs (sda): mounted filesystem without journal. Quota mode: none.
[    1.677905] hv_pci 75e234e6-9a41-4c1d-8ac8-5d395d071dd2: PCI VMBus probing: Using version 0x10004
[    1.678919] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    1.679926] hv_pci 75e234e6-9a41-4c1d-8ac8-5d395d071dd2: PCI host bridge to bus 9a41:00
[    1.680478] pci_bus 9a41:00: root bus resource [mem 0xa00000000-0xc00001fff window]
[    1.680783] pci_bus 9a41:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.682091] pci 9a41:00:00.0: [1af4:105a] type 00 class 0x088000
[    1.684295] pci 9a41:00:00.0: reg 0x10: [mem 0xc00000000-0xc00000fff 64bit]
[    1.686271] pci 9a41:00:00.0: reg 0x18: [mem 0xc00001000-0xc00001fff 64bit]
[    1.688288] pci 9a41:00:00.0: reg 0x20: [mem 0xa00000000-0xbffffffff 64bit]
[    1.693245] pci_bus 9a41:00: busn_res: [bus 00-ff] end is updated to 00
[    1.693513] pci 9a41:00:00.0: BAR 4: assigned [mem 0xa00000000-0xbffffffff 64bit]
[    1.695391] pci 9a41:00:00.0: BAR 0: assigned [mem 0xc00000000-0xc00000fff 64bit]
[    1.697251] pci 9a41:00:00.0: BAR 2: assigned [mem 0xc00001000-0xc00001fff 64bit]
[    1.712810] virtiofs virtio2: Cache len: 0x200000000 @ 0xa00000000
[    1.713702] clocksource: Switched to clocksource tsc
[    1.739139] sd 0:0:0:0: [sda] Attached SCSI disk
[    1.778098] memmap_init_zone_device initialised 2097152 pages in 10ms
[    1.779673] WSL2: SetEphemeralPortRange is a no-op : range (0, 0)
[    1.848936] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    2.479025] scsi 0:0:0:1: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.479872] sd 0:0:0:1: Attached scsi generic sg1 type 0
[    2.480323] sd 0:0:0:1: [sdb] 2097160 512-byte logical blocks: (1.07 GB/1.00 GiB)
[    2.480417] scsi 0:0:0:2: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.480787] sd 0:0:0:1: [sdb] 4096-byte physical blocks
[    2.481485] sd 0:0:0:2: Attached scsi generic sg2 type 0
[    2.481508] sd 0:0:0:1: [sdb] Write Protect is off
[    2.482052] sd 0:0:0:2: [sdc] 536870912 512-byte logical blocks: (275 GB/256 GiB)
[    2.482106] sd 0:0:0:1: [sdb] Mode Sense: 0f 00 00 00
[    2.482522] sd 0:0:0:2: [sdc] 4096-byte physical blocks
[    2.482915] sd 0:0:0:1: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.483103] sd 0:0:0:2: [sdc] Write Protect is off
[    2.483857] sd 0:0:0:2: [sdc] Mode Sense: 0f 00 00 00
[    2.484274] sd 0:0:0:2: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.485716] sd 0:0:0:1: [sdb] Attached SCSI disk
[    2.491559] sd 0:0:0:2: [sdc] Attached SCSI disk
[    2.500504] EXT4-fs (sdc): recovery complete
[    2.501459] EXT4-fs (sdc): mounted filesystem with ordered data mode. Quota mode: none.
[    2.522816] Adding 1048576k swap on /dev/sdb.  Priority:-2 extents:1 across:1048576k 
[    2.681998] hv_pci 218ee01d-fcab-4f07-9ea0-57e00b7600be: PCI VMBus probing: Using version 0x10004
[    2.683056] 9pnet_virtio: no channels available for device drvfs
[    2.683289] hv_pci 218ee01d-fcab-4f07-9ea0-57e00b7600be: PCI host bridge to bus fcab:00
[    2.683349] init: (1) WARNING: mount: waiting for virtio device...
[    2.683645] pci_bus fcab:00: root bus resource [mem 0x9ffe08000-0x9ffe0afff window]
[    2.684167] pci_bus fcab:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.685517] pci fcab:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.686817] pci fcab:00:00.0: reg 0x10: [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.687677] pci fcab:00:00.0: reg 0x18: [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.688539] pci fcab:00:00.0: reg 0x20: [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.692528] pci_bus fcab:00: busn_res: [bus 00-ff] end is updated to 00
[    2.692830] pci fcab:00:00.0: BAR 0: assigned [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.693631] pci fcab:00:00.0: BAR 2: assigned [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.694374] pci fcab:00:00.0: BAR 4: assigned [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.788379] hv_pci 5767d560-6512-42aa-bddc-89eca93e4c84: PCI VMBus probing: Using version 0x10004
[    2.789471] 9pnet_virtio: no channels available for device drvfs
[    2.789751] hv_pci 5767d560-6512-42aa-bddc-89eca93e4c84: PCI host bridge to bus 6512:00
[    2.789774] init: (1) WARNING: mount: waiting for virtio device...
[    2.790068] pci_bus 6512:00: root bus resource [mem 0x9ffe0c000-0x9ffe0efff window]
[    2.790613] pci_bus 6512:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.791858] pci 6512:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.792992] pci 6512:00:00.0: reg 0x10: [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.793834] pci 6512:00:00.0: reg 0x18: [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.794694] pci 6512:00:00.0: reg 0x20: [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.798621] pci_bus 6512:00: busn_res: [bus 00-ff] end is updated to 00
[    2.798961] pci 6512:00:00.0: BAR 0: assigned [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.799695] pci 6512:00:00.0: BAR 2: assigned [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.800416] pci 6512:00:00.0: BAR 4: assigned [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.895193] hv_pci 4fae7a25-5e7f-42d1-8a8f-7e1eb4128529: PCI VMBus probing: Using version 0x10004
[    2.896654] hv_pci 4fae7a25-5e7f-42d1-8a8f-7e1eb4128529: PCI host bridge to bus 5e7f:00
[    2.897036] pci_bus 5e7f:00: root bus resource [mem 0x9ffe10000-0x9ffe12fff window]
[    2.897405] pci_bus 5e7f:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.898729] pci 5e7f:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.900002] pci 5e7f:00:00.0: reg 0x10: [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.900885] pci 5e7f:00:00.0: reg 0x18: [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.901753] pci 5e7f:00:00.0: reg 0x20: [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    2.905797] pci_bus 5e7f:00: busn_res: [bus 00-ff] end is updated to 00
[    2.906134] pci 5e7f:00:00.0: BAR 0: assigned [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.906894] pci 5e7f:00:00.0: BAR 2: assigned [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.907627] pci 5e7f:00:00.0: BAR 4: assigned [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    3.077268] hv_pci 98cd7659-96ca-4b6a-95f7-0896075bc081: PCI VMBus probing: Using version 0x10004
[    3.078351] 9pnet_virtio: no channels available for device drvfs
[    3.078666] init: (1) WARNING: mount: waiting for virtio device...
[    3.078865] hv_pci 98cd7659-96ca-4b6a-95f7-0896075bc081: PCI host bridge to bus 96ca:00
[    3.079411] pci_bus 96ca:00: root bus resource [mem 0x9ffe14000-0x9ffe16fff window]
[    3.079774] pci_bus 96ca:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.081309] pci 96ca:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.082647] pci 96ca:00:00.0: reg 0x10: [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.083650] pci 96ca:00:00.0: reg 0x18: [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.084634] pci 96ca:00:00.0: reg 0x20: [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.088677] pci_bus 96ca:00: busn_res: [bus 00-ff] end is updated to 00
[    3.089026] pci 96ca:00:00.0: BAR 0: assigned [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.089905] pci 96ca:00:00.0: BAR 2: assigned [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.090676] pci 96ca:00:00.0: BAR 4: assigned [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.183923] hv_pci d00b62d9-165b-4f27-8533-5d0402fb00d8: PCI VMBus probing: Using version 0x10004
[    3.185457] hv_pci d00b62d9-165b-4f27-8533-5d0402fb00d8: PCI host bridge to bus 165b:00
[    3.185861] pci_bus 165b:00: root bus resource [mem 0x9ffe18000-0x9ffe1afff window]
[    3.185908] 9pnet_virtio: no channels available for device drvfs
[    3.186186] pci_bus 165b:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.186580] init: (1) WARNING: mount: waiting for virtio device...
[    3.187888] pci 165b:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.189081] pci 165b:00:00.0: reg 0x10: [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.189964] pci 165b:00:00.0: reg 0x18: [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.190841] pci 165b:00:00.0: reg 0x20: [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.194800] pci_bus 165b:00: busn_res: [bus 00-ff] end is updated to 00
[    3.195067] pci 165b:00:00.0: BAR 0: assigned [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.195787] pci 165b:00:00.0: BAR 2: assigned [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.196517] pci 165b:00:00.0: BAR 4: assigned [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.292120] hv_pci ff437ee8-6a13-4119-800a-411d24b930e4: PCI VMBus probing: Using version 0x10004
[    3.293643] hv_pci ff437ee8-6a13-4119-800a-411d24b930e4: PCI host bridge to bus 6a13:00
[    3.294135] pci_bus 6a13:00: root bus resource [mem 0x9ffe1c000-0x9ffe1efff window]
[    3.294500] pci_bus 6a13:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.295857] pci 6a13:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.297136] pci 6a13:00:00.0: reg 0x10: [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.298009] pci 6a13:00:00.0: reg 0x18: [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.298981] pci 6a13:00:00.0: reg 0x20: [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[    3.303144] pci_bus 6a13:00: busn_res: [bus 00-ff] end is updated to 00
[    3.303421] pci 6a13:00:00.0: BAR 0: assigned [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.304141] pci 6a13:00:00.0: BAR 2: assigned [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.304851] pci 6a13:00:00.0: BAR 4: assigned [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[   49.723597] hv_balloon: Max. dynamic memory size: 16384 MB

[-- Attachment #3: bad.log --]
[-- Type: text/plain, Size: 34554 bytes --]

# cat /sys/kernel/debug/swiotlb/io_tlb_nslabs
32768

# dmesg
[    0.000000] Linux version 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 (nathan@dev-arch.thelio-3990X) (gcc (GCC) 12.1.0, GNU ld (GNU Binutils) 2.38) #1 SMP PREEMPT_DYNAMIC Wed Jun 1 10:41:21 MST 2022
[    0.000000] Command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 1776
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000e0fff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000001fffff] ACPI data
[    0.000000] BIOS-e820: [mem 0x0000000000200000-0x00000000f7ffffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000100000000-0x0000000407ffffff] usable
[    0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '115200')
[    0.000000] printk: bootconsole [uart8250] enabled
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI not present or invalid.
[    0.000000] Hypervisor detected: Microsoft Hyper-V
[    0.000000] Hyper-V: privilege flags low 0xae7f, high 0x3b8030, hints 0xc2c, misc 0xe0bed7b6
[    0.000000] Hyper-V: Host Build 10.0.22000.708-0-0
[    0.000000] Hyper-V: Nested features: 0x4a0000
[    0.000000] Hyper-V: LAPIC Timer Frequency: 0x1e8480
[    0.000000] Hyper-V: Using hypercall for remote TLB flush
[    0.000000] clocksource: hyperv_clocksource_tsc_page: mask: 0xffffffffffffffff max_cycles: 0x24e6a1710, max_idle_ns: 440795202120 ns
[    0.000003] tsc: Detected 3800.008 MHz processor
[    0.001844] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.004500] e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.006752] last_pfn = 0x408000 max_arch_pfn = 0x400000000
[    0.008928] x86/PAT: Configuration [0-7]: WB  WC  UC- UC  WB  WP  UC- WT  
[    0.011617] last_pfn = 0xf8000 max_arch_pfn = 0x400000000
[    0.013721] Using GB pages for direct mapping
[    0.015504] RAMDISK: [mem 0x0371f000-0x03779fff]
[    0.017288] ACPI: Early table checksum verification disabled
[    0.019511] ACPI: RSDP 0x00000000000E0000 000024 (v02 VRTUAL)
[    0.021806] ACPI: XSDT 0x0000000000100000 000044 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.025255] ACPI: FACP 0x0000000000101000 000114 (v06 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.028644] ACPI: DSDT 0x00000000001011B8 01E184 (v02 MSFTVM DSDT01   00000001 MSFT 05000000)
[    0.032074] ACPI: FACS 0x0000000000101114 000040
[    0.033876] ACPI: OEM0 0x0000000000101154 000064 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.037335] ACPI: SRAT 0x000000000011F33C 000330 (v02 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.040839] ACPI: APIC 0x000000000011F66C 000088 (v04 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.044205] ACPI: Reserving FACP table memory at [mem 0x101000-0x101113]
[    0.046856] ACPI: Reserving DSDT table memory at [mem 0x1011b8-0x11f33b]
[    0.049526] ACPI: Reserving FACS table memory at [mem 0x101114-0x101153]
[    0.052323] ACPI: Reserving OEM0 table memory at [mem 0x101154-0x1011b7]
[    0.054916] ACPI: Reserving SRAT table memory at [mem 0x11f33c-0x11f66b]
[    0.057563] ACPI: Reserving APIC table memory at [mem 0x11f66c-0x11f6f3]
[    0.060644] Zone ranges:
[    0.061621]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.064031]   DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
[    0.066551]   Normal   [mem 0x0000000100000000-0x0000000407ffffff]
[    0.069096]   Device   empty
[    0.070236] Movable zone start for each node
[    0.071880] Early memory node ranges
[    0.073323]   node   0: [mem 0x0000000000001000-0x000000000009ffff]
[    0.075736]   node   0: [mem 0x0000000000200000-0x00000000f7ffffff]
[    0.078260]   node   0: [mem 0x0000000100000000-0x0000000407ffffff]
[    0.080698] Initmem setup node 0 [mem 0x0000000000001000-0x0000000407ffffff]
[    0.083706] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.083724] On node 0, zone DMA: 352 pages in unavailable ranges
[    0.095850] ACPI: LAPIC_NMI (acpi_id[0x01] dfl dfl lint[0x1])
[    0.100817] IOAPIC[0]: apic_id 8, version 17, address 0xfec00000, GSI 0-23
[    0.103601] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[    0.106156] ACPI: Using ACPI (MADT) for SMP configuration information
[    0.108743] smpboot: Allowing 8 CPUs, 0 hotplug CPUs
[    0.110810] [mem 0xf8000000-0xffffffff] available for PCI devices
[    0.113193] Booting paravirtualized kernel on Hyper-V
[    0.115221] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.124086] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:8 nr_node_ids:1
[    0.127620] percpu: Embedded 53 pages/cpu s178408 r8192 d30488 u262144
[    0.130204] pcpu-alloc: s178408 r8192 d30488 u262144 alloc=1*2097152
[    0.132746] pcpu-alloc: [0] 0 1 2 3 4 5 6 7 
[    0.134452] Hyper-V: PV spinlocks enabled
[    0.136082] PV qspinlock hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.138923] Built 1 zonelists, mobility grouping on.  Total pages: 4127749
[    0.141669] Kernel command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.149809] Dentry cache hash table entries: 2097152 (order: 12, 16777216 bytes, linear)
[    0.154232] Inode-cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.157400] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.182296] Memory: 4126096K/16775804K available (18449K kernel code, 2647K rwdata, 3952K rodata, 1536K init, 2448K bss, 392692K reserved, 0K cma-reserved)
[    0.188084] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
[    0.190824] ftrace: allocating 51788 entries in 203 pages
[    0.199397] ftrace: allocated 203 pages with 5 groups
[    0.202320] Dynamic Preempt: none
[    0.203777] rcu: Preemptible hierarchical RCU implementation.
[    0.206055] rcu: 	RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=8.
[    0.208807] 	Trampoline variant of Tasks RCU enabled.
[    0.210844] 	Rude variant of Tasks RCU enabled.
[    0.213292] 	Tracing variant of Tasks RCU enabled.
[    0.215445] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.218380] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=8
[    0.224306] Using NULL legacy PIC
[    0.225589] NR_IRQS: 16640, nr_irqs: 488, preallocated irqs: 0
[    0.228245] random: crng init done (trusting CPU's manufacturer)
[    0.230636] Console: colour dummy device 80x25
[    0.232438] ACPI: Core revision 20211217
[    0.234033] Failed to register legacy timer interrupt
[    0.236047] APIC: Switch to symmetric I/O mode setup
[    0.238014] Hyper-V: enabling crash_kexec_post_notifiers
[    0.240107] Hyper-V: Using IPI hypercalls
[    0.241666] Hyper-V: Using enlightened APIC (xapic mode)
[    0.241757] clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    0.247930] Calibrating delay loop (skipped), value calculated using timer frequency.. 7600.01 BogoMIPS (lpj=38000080)
[    0.252067] pid_max: default: 32768 minimum: 301
[    0.253895] LSM: Security Framework initializing
[    0.255751] Mount-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.257927] Mountpoint-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.257927] x86/cpu: User Mode Instruction Prevention (UMIP) activated
[    0.257927] Last level iTLB entries: 4KB 1024, 2MB 1024, 4MB 512
[    0.257927] Last level dTLB entries: 4KB 2048, 2MB 2048, 4MB 1024, 1GB 0
[    0.257927] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.257927] Spectre V2 : Mitigation: Retpolines
[    0.257927] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
[    0.257927] Spectre V2 : mitigation: Enabling conditional Indirect Branch Prediction Barrier
[    0.257927] Spectre V2 : User space: Mitigation: STIBP via prctl
[    0.257927] Speculative Store Bypass: Mitigation: Speculative Store Bypass disabled via prctl
[    0.257927] Freeing SMP alternatives memory: 56K
[    0.257927] smpboot: CPU0: AMD Ryzen 9 3900X 12-Core Processor (family: 0x17, model: 0x71, stepping: 0x0)
[    0.257927] cblist_init_generic: Setting adjustable number of callback queues.
[    0.257927] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.257927] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.257953] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.260344] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[    0.262870] ... version:                0
[    0.264433] ... bit width:              48
[    0.266024] ... generic registers:      6
[    0.267586] ... value mask:             0000ffffffffffff
[    0.267931] ... max period:             00007fffffffffff
[    0.269978] ... fixed-purpose events:   0
[    0.271549] ... event mask:             000000000000003f
[    0.273693] rcu: Hierarchical SRCU implementation.
[    0.275947] smp: Bringing up secondary CPUs ...
[    0.277746] x86: Booting SMP configuration:
[    0.277931] .... node  #0, CPUs:      #1 #2 #3 #4 #5 #6 #7
[    0.278598] smp: Brought up 1 node, 8 CPUs
[    0.281786] smpboot: Max logical packages: 1
[    0.283442] smpboot: Total of 8 processors activated (60800.12 BogoMIPS)
[    0.297948] node 0 deferred pages initialised in 10ms
[    0.300095] devtmpfs: initialized
[    0.300095] x86/mm: Memory block size: 128MB
[    0.301372] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.307950] futex hash table entries: 2048 (order: 5, 131072 bytes, linear)
[    0.311117] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.313590] thermal_sys: Registered thermal governor 'step_wise'
[    0.313591] thermal_sys: Registered thermal governor 'user_space'
[    0.315970] cpuidle: using governor menu
[    0.317983] PCI: Fatal: No config space access function found
[    0.321181] kprobes: kprobe jump-optimization is enabled. All kprobes are optimized if possible.
[    0.321181] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[    0.321181] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[    0.327982] raid6: skipped pq benchmark and selected avx2x4
[    0.330080] raid6: using avx2x2 recovery algorithm
[    0.331916] ACPI: Added _OSI(Module Device)
[    0.337945] ACPI: Added _OSI(Processor Device)
[    0.339664] ACPI: Added _OSI(3.0 _SCP Extensions)
[    0.341472] ACPI: Added _OSI(Processor Aggregator Device)
[    0.343581] ACPI: Added _OSI(Linux-Dell-Video)
[    0.345290] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[    0.347310] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)
[    0.351846] ACPI: 1 ACPI AML tables successfully acquired and loaded
[    0.354878] ACPI: Interpreter enabled
[    0.357948] ACPI: PM: (supports S0 S5)
[    0.359386] ACPI: Using IOAPIC for interrupt routing
[    0.361295] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
[    0.364875] ACPI: Enabled 1 GPEs in block 00 to 0F
[    0.367281] iommu: Default domain type: Translated 
[    0.367930] iommu: DMA domain TLB invalidation policy: lazy mode 
[    0.370342] SCSI subsystem initialized
[    0.371819] ACPI: bus type USB registered
[    0.373384] usbcore: registered new interface driver usbfs
[    0.375508] usbcore: registered new interface driver hub
[    0.377556] usbcore: registered new device driver usb
[    0.378007] hv_vmbus: Vmbus version:5.2
[    0.379525] PCI: Using ACPI for IRQ routing
[    0.381148] PCI: System does not support PCI
[    0.382985] hv_vmbus: Unknown GUID: c376c1c3-d276-48d2-90a9-c04748072c60
[    0.385656] hv_vmbus: Unknown GUID: 6e382d18-3336-4f4b-acc4-2b7703d4df4a
[    0.385656] hv_vmbus: Unknown GUID: dde9cbc0-5060-4436-9448-ea1254a5d177
[    0.385656] clocksource: Switched to clocksource tsc-early
[    0.395132] VFS: Disk quotas dquot_6.6.0
[    0.398629] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.401503] FS-Cache: Loaded
[    0.402695] pnp: PnP ACPI init
[    0.403992] pnp: PnP ACPI: found 3 devices
[    0.409671] NET: Registered PF_INET protocol family
[    0.411938] IP idents hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.416026] tcp_listen_portaddr_hash hash table entries: 8192 (order: 5, 131072 bytes, linear)
[    0.419575] TCP established hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.423230] TCP bind hash table entries: 65536 (order: 8, 1048576 bytes, linear)
[    0.426347] TCP: Hash tables configured (established 131072 bind 65536)
[    0.429190] UDP hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.432209] UDP-Lite hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.435648] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.438375] RPC: Registered named UNIX socket transport module.
[    0.440789] RPC: Registered udp transport module.
[    0.442671] RPC: Registered tcp transport module.
[    0.444673] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.447332] PCI: CLS 0 bytes, default 64
[    0.448993] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[    0.449028] Trying to unpack rootfs image as initramfs...
[    0.451710] software IO TLB: mapped [mem 0x00000000f4000000-0x00000000f8000000] (64MB)
[    0.454079] Freeing initrd memory: 364K
[    0.541430] kvm: no hardware support for 'kvm_intel'
[    0.543753] SVM: TSC scaling supported
[    0.545214] kvm: Nested Virtualization enabled
[    0.546939] SVM: kvm: Nested Paging enabled
[    0.548655] SVM: kvm: Hyper-V enlightened NPT TLB flush enabled
[    0.550982] SVM: kvm: Hyper-V Direct TLB Flush enabled
[    0.553055] SVM: Virtual VMLOAD VMSAVE supported
[    0.619230] Initialise system trusted keyrings
[    0.621148] workingset: timestamp_bits=46 max_order=22 bucket_order=0
[    0.624304] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.626917] NFS: Registering the id_resolver key type
[    0.628911] Key type id_resolver registered
[    0.630622] Key type id_legacy registered
[    0.632252] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.635096] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    0.638073] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[    0.641200] Key type cifs.idmap registered
[    0.642865] fuse: init (API version 7.36)
[    0.644622] SGI XFS with ACLs, security attributes, realtime, scrub, repair, quota, no debug enabled
[    0.648593] 9p: Installing v9fs 9p2000 file system support
[    0.650987] ceph: loaded (mds proto 32)
[    0.654860] NET: Registered PF_ALG protocol family
[    0.656711] xor: automatically using best checksumming function   avx       
[    0.659472] Key type asymmetric registered
[    0.661072] Asymmetric key parser 'x509' registered
[    0.662976] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[    0.666333] hv_vmbus: registering driver hv_pci
[    0.668465] hv_pci a154a52e-df93-4a32-a470-37362af9092a: PCI VMBus probing: Using version 0x10004
[    0.672862] hv_pci a154a52e-df93-4a32-a470-37362af9092a: PCI host bridge to bus df93:00
[    0.675963] pci_bus df93:00: root bus resource [mem 0x9ffe00000-0x9ffe02fff window]
[    0.678965] pci_bus df93:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.683016] pci df93:00:00.0: [1af4:1043] type 00 class 0x010000
[    0.686425] pci df93:00:00.0: reg 0x10: [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.689851] pci df93:00:00.0: reg 0x18: [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.693249] pci df93:00:00.0: reg 0x20: [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.698971] pci_bus df93:00: busn_res: [bus 00-ff] end is updated to 00
[    0.701554] pci df93:00:00.0: BAR 0: assigned [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.704894] pci df93:00:00.0: BAR 2: assigned [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.708243] pci df93:00:00.0: BAR 4: assigned [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.711877] hv_pci ca66d0fe-4477-439b-9d67-02d7bd2dcb05: PCI VMBus probing: Using version 0x10004
[    0.716001] hv_pci ca66d0fe-4477-439b-9d67-02d7bd2dcb05: PCI host bridge to bus 4477:00
[    0.719136] pci_bus 4477:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.722586] pci 4477:00:00.0: [1414:008e] type 00 class 0x030200
[    0.729016] pci_bus 4477:00: busn_res: [bus 00-ff] end is updated to 00
[    0.731822] hv_pci c42c9658-a709-40bd-8d72-5ee9b78e28ca: PCI VMBus probing: Using version 0x10004
[    0.736240] hv_pci c42c9658-a709-40bd-8d72-5ee9b78e28ca: PCI host bridge to bus a709:00
[    0.739381] pci_bus a709:00: root bus resource [mem 0x9ffe04000-0x9ffe06fff window]
[    0.742368] pci_bus a709:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.746437] pci a709:00:00.0: [1af4:1049] type 00 class 0x010000
[    0.749663] pci a709:00:00.0: reg 0x10: [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.752975] pci a709:00:00.0: reg 0x18: [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.756273] pci a709:00:00.0: reg 0x20: [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.762929] pci_bus a709:00: busn_res: [bus 00-ff] end is updated to 00
[    0.765585] pci a709:00:00.0: BAR 0: assigned [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.769014] pci a709:00:00.0: BAR 2: assigned [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.772436] pci a709:00:00.0: BAR 4: assigned [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.784024] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.786788] 00:00: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    0.790004] 00:01: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[    0.828478] Non-volatile memory driver v1.3
[    0.830180] printk: console [hvc0] enabled
[    0.831804] printk: bootconsole [uart8250] disabled
[    0.835700] brd: module loaded
[    0.836692] loop: module loaded
[    0.836890] hv_vmbus: registering driver hv_storvsc
[    0.837466] wireguard: WireGuard 1.0.0 loaded. See www.wireguard.com for information.
[    0.837853] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
[    0.838217] scsi host0: storvsc_host_t
[    0.838399] tun: Universal TUN/TAP device driver, 1.6
[    0.838812] PPP generic driver version 2.4.2
[    0.839159] PPP BSD Compression module registered
[    0.839395] PPP Deflate Compression module registered
[    0.839781] PPP MPPE Compression module registered
[    0.840046] NET: Registered PF_PPPOX protocol family
[    0.840326] usbcore: registered new interface driver cdc_ether
[    0.840687] usbcore: registered new interface driver cdc_ncm
[    0.841009] hv_vmbus: registering driver hv_netvsc
[    0.841331] VFIO - User Level meta-driver version: 0.3
[    0.841707] usbcore: registered new interface driver cdc_acm
[    0.841999] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[    0.842346] usbcore: registered new interface driver ch341
[    0.842613] usbserial: USB Serial support registered for ch341-uart
[    0.842907] usbcore: registered new interface driver cp210x
[    0.843226] usbserial: USB Serial support registered for cp210x
[    0.843574] usbcore: registered new interface driver ftdi_sio
[    0.843874] usbserial: USB Serial support registered for FTDI USB Serial Device
[    0.844325] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.844630] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 1
[    0.844968] vhci_hcd: created sysfs vhci_hcd.0
[    0.845394] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.18
[    0.845749] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.846033] usb usb1: Product: USB/IP Virtual Host Controller
[    0.846274] usb usb1: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 vhci_hcd
[    0.846606] usb usb1: SerialNumber: vhci_hcd.0
[    0.846887] hub 1-0:1.0: USB hub found
[    0.847077] hub 1-0:1.0: 8 ports detected
[    0.847565] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.847828] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 2
[    0.848246] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[    0.848690] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.18
[    0.848997] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.849279] usb usb2: Product: USB/IP Virtual Host Controller
[    0.849523] usb usb2: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 vhci_hcd
[    0.849855] usb usb2: SerialNumber: vhci_hcd.0
[    0.850138] hub 2-0:1.0: USB hub found
[    0.850333] hub 2-0:1.0: 8 ports detected
[    0.850772] hv_vmbus: registering driver hyperv_keyboard
[    0.851119] rtc_cmos 00:02: RTC can wake from S4
[    0.853017] rtc_cmos 00:02: registered as rtc0
[    0.853536] rtc_cmos 00:02: setting system clock to 2022-06-01T17:41:59 UTC (1654105319)
[    0.853854] rtc_cmos 00:02: alarms up to one month, 114 bytes nvram
[    0.854249] device-mapper: ioctl: 4.46.0-ioctl (2022-02-22) initialised: dm-devel@redhat.com
[    0.854710] device-mapper: raid: Loading target version 1.15.1
[    0.855003] usbcore: registered new interface driver usbhid
[    0.855198] usbhid: USB HID core driver
[    0.855394] hv_utils: Registering HyperV Utility Driver
[    0.855608] hv_vmbus: registering driver hv_utils
[    0.855910] hv_vmbus: registering driver hv_balloon
[    0.855914] hv_utils: cannot register PTP clock: 0
[    0.856165] drop_monitor: Initializing network drop monitor service
[    0.856597] hv_balloon: Using Dynamic Memory protocol version 2.0
[    0.856611] hv_utils: TimeSync IC version 4.0
[    0.856742] Mirror/redirect action on
[    0.857542] Free page reporting enabled
[    0.857744] hv_balloon: Cold memory discard hint enabled
[    0.858304] IPVS: Registered protocols (TCP, UDP)
[    0.858534] IPVS: Connection hash table configured (size=4096, memory=64Kbytes)
[    0.858872] IPVS: ipvs loaded.
[    0.859018] IPVS: [rr] scheduler registered.
[    0.859213] IPVS: [wrr] scheduler registered.
[    0.859405] IPVS: [sh] scheduler registered.
[    0.859622] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    0.860047] ipt_CLUSTERIP: ClusterIP Version 0.8 loaded successfully
[    0.860293] Initializing XFRM netlink socket
[    0.860522] NET: Registered PF_INET6 protocol family
[    0.861019] Segment Routing with IPv6
[    0.861193] In-situ OAM (IOAM) with IPv6
[    0.861362] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    0.861655] NET: Registered PF_PACKET protocol family
[    0.861875] Bridge firewalling registered
[    0.862024] 8021q: 802.1Q VLAN Support v1.8
[    0.862189] sctp: Hash tables configured (bind 256/256)
[    0.862419] 9pnet: Installing 9P2000 support
[    0.874428] Key type dns_resolver registered
[    0.874663] Key type ceph registered
[    0.874921] libceph: loaded (mon/osd proto 15/24)
[    0.875208] NET: Registered PF_VSOCK protocol family
[    0.875419] hv_vmbus: registering driver hv_sock
[    0.875644] IPI shorthand broadcast: enabled
[    0.875840] sched_clock: Marking stable (855501109, 19696300)->(934890300, -59692891)
[    0.876403] registered taskstats version 1
[    0.876928] Loading compiled-in X.509 certificates
[    0.877333] Btrfs loaded, crc32c=crc32c-generic, zoned=no, fsverity=no
[    0.882685] Freeing unused kernel image (initmem) memory: 1536K
[    0.918057] Write protecting the kernel read-only data: 24576k
[    0.918975] Freeing unused kernel image (text/rodata gap) memory: 2028K
[    0.919393] Freeing unused kernel image (rodata/data gap) memory: 144K
[    0.919654] Run /init as init process
[    0.919798]   with arguments:
[    0.919940]     /init
[    0.920047]   with environment:
[    0.920190]     HOME=/
[    0.920286]     TERM=linux
[    0.922620] scsi 0:0:0:0: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    0.923252] sd 0:0:0:0: Attached scsi generic sg0 type 0
[    0.923893] sd 0:0:0:0: [sda] 641944 512-byte logical blocks: (329 MB/313 MiB)
[    0.924490] sd 0:0:0:0: [sda] Write Protect is on
[    0.924760] sd 0:0:0:0: [sda] Mode Sense: 0f 00 80 00
[    0.925199] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[    1.538410] EXT4-fs (sda): mounted filesystem without journal. Quota mode: none.
[    1.640080] hv_pci 88309164-1127-4233-9560-6e0cad455d8f: PCI VMBus probing: Using version 0x10004
[    1.642187] hv_pci 88309164-1127-4233-9560-6e0cad455d8f: PCI host bridge to bus 1127:00
[    1.642548] pci_bus 1127:00: root bus resource [mem 0xa00000000-0xc00001fff window]
[    1.642895] pci_bus 1127:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.644287] pci 1127:00:00.0: [1af4:105a] type 00 class 0x088000
[    1.647194] pci 1127:00:00.0: reg 0x10: [mem 0xc00000000-0xc00000fff 64bit]
[    1.649501] pci 1127:00:00.0: reg 0x18: [mem 0xc00001000-0xc00001fff 64bit]
[    1.651514] pci 1127:00:00.0: reg 0x20: [mem 0xa00000000-0xbffffffff 64bit]
[    1.656603] pci_bus 1127:00: busn_res: [bus 00-ff] end is updated to 00
[    1.656902] pci 1127:00:00.0: BAR 4: assigned [mem 0xa00000000-0xbffffffff 64bit]
[    1.658754] pci 1127:00:00.0: BAR 0: assigned [mem 0xc00000000-0xc00000fff 64bit]
[    1.660797] pci 1127:00:00.0: BAR 2: assigned [mem 0xc00001000-0xc00001fff 64bit]
[    1.676734] virtiofs virtio2: Cache len: 0x200000000 @ 0xa00000000
[    1.687964] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    1.688537] clocksource: Switched to clocksource tsc
[    1.718131] sd 0:0:0:0: [sda] Attached SCSI disk
[    1.737024] memmap_init_zone_device initialised 2097152 pages in 10ms
[    1.738457] WSL2: SetEphemeralPortRange is a no-op : range (0, 0)
[    1.847973] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    2.418129] scsi 0:0:0:1: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.418887] sd 0:0:0:1: Attached scsi generic sg1 type 0
[    2.419446] scsi 0:0:0:2: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.419498] sd 0:0:0:1: [sdb] 2097160 512-byte logical blocks: (1.07 GB/1.00 GiB)
[    2.420146] sd 0:0:0:2: Attached scsi generic sg2 type 0
[    2.420236] sd 0:0:0:1: [sdb] 4096-byte physical blocks
[    2.420789] sd 0:0:0:2: [sdc] 536870912 512-byte logical blocks: (275 GB/256 GiB)
[    2.420849] sd 0:0:0:1: [sdb] Write Protect is off
[    2.421225] sd 0:0:0:2: [sdc] 4096-byte physical blocks
[    2.421541] sd 0:0:0:1: [sdb] Mode Sense: 0f 00 00 00
[    2.421888] sd 0:0:0:2: [sdc] Write Protect is off
[    2.422260] sd 0:0:0:1: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.422392] sd 0:0:0:2: [sdc] Mode Sense: 0f 00 00 00
[    2.423302] sd 0:0:0:2: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.424840] sd 0:0:0:1: [sdb] Attached SCSI disk
[    2.426063] sd 0:0:0:2: [sdc] Attached SCSI disk
[    2.444484] EXT4-fs (sdc): recovery complete
[    2.445457] EXT4-fs (sdc): mounted filesystem with ordered data mode. Quota mode: none.
[    2.459372] Adding 1048576k swap on /dev/sdb.  Priority:-2 extents:1 across:1048576k 
[    2.649008] hv_pci aed388e8-de3a-45a5-bb0c-ee534e806689: PCI VMBus probing: Using version 0x10004
[    2.650439] hv_pci aed388e8-de3a-45a5-bb0c-ee534e806689: PCI host bridge to bus de3a:00
[    2.650756] pci_bus de3a:00: root bus resource [mem 0x9ffe08000-0x9ffe0afff window]
[    2.651045] pci_bus de3a:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.652320] pci de3a:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.653496] pci de3a:00:00.0: reg 0x10: [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.654363] pci de3a:00:00.0: reg 0x18: [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.655227] pci de3a:00:00.0: reg 0x20: [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.659234] pci_bus de3a:00: busn_res: [bus 00-ff] end is updated to 00
[    2.659501] pci de3a:00:00.0: BAR 0: assigned [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.660251] pci de3a:00:00.0: BAR 2: assigned [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.660989] pci de3a:00:00.0: BAR 4: assigned [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.663932] 9pnet_virtio: no channels available for device drvfs
[    2.664237] init: (1) WARNING: mount: waiting for virtio device...
[    2.770766] hv_pci 81d9a8d7-9fce-46b7-9ff9-b146da3089e4: PCI VMBus probing: Using version 0x10004
[    2.772061] hv_pci 81d9a8d7-9fce-46b7-9ff9-b146da3089e4: PCI host bridge to bus 9fce:00
[    2.772372] pci_bus 9fce:00: root bus resource [mem 0x9ffe0c000-0x9ffe0efff window]
[    2.772664] pci_bus 9fce:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.773910] pci 9fce:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.775050] pci 9fce:00:00.0: reg 0x10: [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.775911] pci 9fce:00:00.0: reg 0x18: [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.776761] pci 9fce:00:00.0: reg 0x20: [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.780694] pci_bus 9fce:00: busn_res: [bus 00-ff] end is updated to 00
[    2.780986] pci 9fce:00:00.0: BAR 0: assigned [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.781703] pci 9fce:00:00.0: BAR 2: assigned [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.781986] 9pnet_virtio: no channels available for device drvfs
[    2.782311] init: (1) WARNING: mount: waiting for virtio device...
[    2.782471] pci 9fce:00:00.0: BAR 4: assigned [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.898491] hv_pci 86858b54-a9ff-42c1-85be-12646bde6957: PCI VMBus probing: Using version 0x10004
[    2.899831] hv_pci 86858b54-a9ff-42c1-85be-12646bde6957: PCI host bridge to bus a9ff:00
[    2.900148] pci_bus a9ff:00: root bus resource [mem 0x9ffe10000-0x9ffe12fff window]
[    2.900437] pci_bus a9ff:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.901684] pci a9ff:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.902856] pci a9ff:00:00.0: reg 0x10: [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.903716] pci a9ff:00:00.0: reg 0x18: [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.904609] pci a9ff:00:00.0: reg 0x20: [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    2.908519] pci_bus a9ff:00: busn_res: [bus 00-ff] end is updated to 00
[    2.908842] pci a9ff:00:00.0: BAR 0: assigned [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.909600] pci a9ff:00:00.0: BAR 2: assigned [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.910335] pci a9ff:00:00.0: BAR 4: assigned [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    3.009967] hv_pci 14a6c250-2f5e-4544-972d-e4af992a128a: PCI VMBus probing: Using version 0x10004
[    3.011462] hv_pci 14a6c250-2f5e-4544-972d-e4af992a128a: PCI host bridge to bus 2f5e:00
[    3.011804] pci_bus 2f5e:00: root bus resource [mem 0x9ffe14000-0x9ffe16fff window]
[    3.012172] pci_bus 2f5e:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.013562] pci 2f5e:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.014756] pci 2f5e:00:00.0: reg 0x10: [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.015633] pci 2f5e:00:00.0: reg 0x18: [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.016516] pci 2f5e:00:00.0: reg 0x20: [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.020834] pci_bus 2f5e:00: busn_res: [bus 00-ff] end is updated to 00
[    3.021157] pci 2f5e:00:00.0: BAR 0: assigned [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.022095] pci 2f5e:00:00.0: BAR 2: assigned [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.022867] pci 2f5e:00:00.0: BAR 4: assigned [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.030227] 9pnet_virtio: no channels available for device drvfs
[    3.030578] init: (1) WARNING: mount: waiting for virtio device...
[    3.143192] hv_pci ed843176-e057-48d4-ab94-623a027b1629: PCI VMBus probing: Using version 0x10004
[    3.144600] hv_pci ed843176-e057-48d4-ab94-623a027b1629: PCI host bridge to bus e057:00
[    3.144927] pci_bus e057:00: root bus resource [mem 0x9ffe18000-0x9ffe1afff window]
[    3.145222] pci_bus e057:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.146529] pci e057:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.147766] pci e057:00:00.0: reg 0x10: [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.148685] pci e057:00:00.0: reg 0x18: [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.149556] pci e057:00:00.0: reg 0x20: [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.153686] pci_bus e057:00: busn_res: [bus 00-ff] end is updated to 00
[    3.154060] pci e057:00:00.0: BAR 0: assigned [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.154855] pci e057:00:00.0: BAR 2: assigned [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.155592] pci e057:00:00.0: BAR 4: assigned [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.188714] hv_pci c963c476-4546-43da-a32c-7e4ddeb55d93: PCI VMBus probing: Using version 0x10004
[    3.190328] hv_pci c963c476-4546-43da-a32c-7e4ddeb55d93: PCI host bridge to bus 4546:00
[    3.190732] pci_bus 4546:00: root bus resource [mem 0x9ffe1c000-0x9ffe1efff window]
[    3.191104] pci_bus 4546:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.192578] pci 4546:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.193870] pci 4546:00:00.0: reg 0x10: [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.194935] pci 4546:00:00.0: reg 0x18: [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.196022] pci 4546:00:00.0: reg 0x20: [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[    3.200503] pci_bus 4546:00: busn_res: [bus 00-ff] end is updated to 00
[    3.200855] pci 4546:00:00.0: BAR 0: assigned [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.201736] pci 4546:00:00.0: BAR 2: assigned [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.202501] pci 4546:00:00.0: BAR 4: assigned [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[   49.723721] hv_balloon: Max. dynamic memory size: 16384 MB

[-- Attachment #4: Type: text/plain, Size: 161 bytes --]

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:46         ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 17:46 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Konrad Rzeszutek Wilk,
	tboot-devel, xen-devel, David Woodhouse, Tom Lendacky,
	Anshuman Khandual, Boris Ostrovsky, linux-arm-kernel,
	Juergen Gross, linuxppc-dev, linux-mips, iommu, Robin Murphy

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> Can you send me the full dmesg and the content of
> /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?

Sure thing, they are attached! If there is anything else I can provide
or test, I am more than happy to do so.

Cheers,
Nathan

[-- Attachment #2: good.log --]
[-- Type: text/plain, Size: 34692 bytes --]

# cat /sys/kernel/debug/swiotlb/io_tlb_nslabs
32768

# dmesg
[    0.000000] Linux version 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 (nathan@dev-arch.thelio-3990X) (gcc (GCC) 12.1.0, GNU ld (GNU Binutils) 2.38) #1 SMP PREEMPT_DYNAMIC Wed Jun 1 10:38:34 MST 2022
[    0.000000] Command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 1776
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000e0fff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000001fffff] ACPI data
[    0.000000] BIOS-e820: [mem 0x0000000000200000-0x00000000f7ffffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000100000000-0x0000000407ffffff] usable
[    0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '115200')
[    0.000000] printk: bootconsole [uart8250] enabled
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI not present or invalid.
[    0.000000] Hypervisor detected: Microsoft Hyper-V
[    0.000000] Hyper-V: privilege flags low 0xae7f, high 0x3b8030, hints 0xc2c, misc 0xe0bed7b6
[    0.000000] Hyper-V: Host Build 10.0.22000.708-0-0
[    0.000000] Hyper-V: Nested features: 0x4a0000
[    0.000000] Hyper-V: LAPIC Timer Frequency: 0x1e8480
[    0.000000] Hyper-V: Using hypercall for remote TLB flush
[    0.000000] clocksource: hyperv_clocksource_tsc_page: mask: 0xffffffffffffffff max_cycles: 0x24e6a1710, max_idle_ns: 440795202120 ns
[    0.000005] tsc: Detected 3800.008 MHz processor
[    0.001901] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.004593] e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.006806] last_pfn = 0x408000 max_arch_pfn = 0x400000000
[    0.009042] x86/PAT: Configuration [0-7]: WB  WC  UC- UC  WB  WP  UC- WT  
[    0.011760] last_pfn = 0xf8000 max_arch_pfn = 0x400000000
[    0.013959] Using GB pages for direct mapping
[    0.015749] RAMDISK: [mem 0x0371f000-0x03779fff]
[    0.017616] ACPI: Early table checksum verification disabled
[    0.019854] ACPI: RSDP 0x00000000000E0000 000024 (v02 VRTUAL)
[    0.022162] ACPI: XSDT 0x0000000000100000 000044 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.025624] ACPI: FACP 0x0000000000101000 000114 (v06 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.029022] ACPI: DSDT 0x00000000001011B8 01E184 (v02 MSFTVM DSDT01   00000001 MSFT 05000000)
[    0.032413] ACPI: FACS 0x0000000000101114 000040
[    0.034280] ACPI: OEM0 0x0000000000101154 000064 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.037699] ACPI: SRAT 0x000000000011F33C 000330 (v02 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.041089] ACPI: APIC 0x000000000011F66C 000088 (v04 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.044475] ACPI: Reserving FACP table memory at [mem 0x101000-0x101113]
[    0.047159] ACPI: Reserving DSDT table memory at [mem 0x1011b8-0x11f33b]
[    0.049905] ACPI: Reserving FACS table memory at [mem 0x101114-0x101153]
[    0.052693] ACPI: Reserving OEM0 table memory at [mem 0x101154-0x1011b7]
[    0.055404] ACPI: Reserving SRAT table memory at [mem 0x11f33c-0x11f66b]
[    0.058040] ACPI: Reserving APIC table memory at [mem 0x11f66c-0x11f6f3]
[    0.061078] Zone ranges:
[    0.062074]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.066106]   DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
[    0.068763]   Normal   [mem 0x0000000100000000-0x0000000407ffffff]
[    0.071235]   Device   empty
[    0.072384] Movable zone start for each node
[    0.074058] Early memory node ranges
[    0.075515]   node   0: [mem 0x0000000000001000-0x000000000009ffff]
[    0.077979]   node   0: [mem 0x0000000000200000-0x00000000f7ffffff]
[    0.080483]   node   0: [mem 0x0000000100000000-0x0000000407ffffff]
[    0.082980] Initmem setup node 0 [mem 0x0000000000001000-0x0000000407ffffff]
[    0.085954] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.085972] On node 0, zone DMA: 352 pages in unavailable ranges
[    0.098043] ACPI: LAPIC_NMI (acpi_id[0x01] dfl dfl lint[0x1])
[    0.102995] IOAPIC[0]: apic_id 8, version 17, address 0xfec00000, GSI 0-23
[    0.105726] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[    0.108349] ACPI: Using ACPI (MADT) for SMP configuration information
[    0.110909] smpboot: Allowing 8 CPUs, 0 hotplug CPUs
[    0.112902] [mem 0xf8000000-0xffffffff] available for PCI devices
[    0.115315] Booting paravirtualized kernel on Hyper-V
[    0.117347] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.126056] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:8 nr_node_ids:1
[    0.129513] percpu: Embedded 53 pages/cpu s178408 r8192 d30488 u262144
[    0.132139] pcpu-alloc: s178408 r8192 d30488 u262144 alloc=1*2097152
[    0.134679] pcpu-alloc: [0] 0 1 2 3 4 5 6 7 
[    0.136341] Hyper-V: PV spinlocks enabled
[    0.137917] PV qspinlock hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.140833] Built 1 zonelists, mobility grouping on.  Total pages: 4127749
[    0.143636] Kernel command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.151440] Dentry cache hash table entries: 2097152 (order: 12, 16777216 bytes, linear)
[    0.155808] Inode-cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.159017] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.184685] Memory: 4126096K/16775804K available (18449K kernel code, 2647K rwdata, 3952K rodata, 1536K init, 2448K bss, 392692K reserved, 0K cma-reserved)
[    0.190358] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
[    0.192969] ftrace: allocating 51788 entries in 203 pages
[    0.201434] ftrace: allocated 203 pages with 5 groups
[    0.204349] Dynamic Preempt: none
[    0.205846] rcu: Preemptible hierarchical RCU implementation.
[    0.208162] rcu: 	RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=8.
[    0.210799] 	Trampoline variant of Tasks RCU enabled.
[    0.212756] 	Rude variant of Tasks RCU enabled.
[    0.214541] 	Tracing variant of Tasks RCU enabled.
[    0.216404] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.219393] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=8
[    0.225278] Using NULL legacy PIC
[    0.226573] NR_IRQS: 16640, nr_irqs: 488, preallocated irqs: 0
[    0.229131] random: crng init done (trusting CPU's manufacturer)
[    0.231548] Console: colour dummy device 80x25
[    0.233276] ACPI: Core revision 20211217
[    0.234931] Failed to register legacy timer interrupt
[    0.236944] APIC: Switch to symmetric I/O mode setup
[    0.238947] Hyper-V: enabling crash_kexec_post_notifiers
[    0.241016] Hyper-V: Using IPI hypercalls
[    0.242591] Hyper-V: Using enlightened APIC (xapic mode)
[    0.242680] clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    0.248870] Calibrating delay loop (skipped), value calculated using timer frequency.. 7600.01 BogoMIPS (lpj=38000080)
[    0.253092] pid_max: default: 32768 minimum: 301
[    0.254926] LSM: Security Framework initializing
[    0.256750] Mount-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.258867] Mountpoint-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.258867] x86/cpu: User Mode Instruction Prevention (UMIP) activated
[    0.258867] Last level iTLB entries: 4KB 1024, 2MB 1024, 4MB 512
[    0.258867] Last level dTLB entries: 4KB 2048, 2MB 2048, 4MB 1024, 1GB 0
[    0.258867] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.258867] Spectre V2 : Mitigation: Retpolines
[    0.258867] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
[    0.258867] Spectre V2 : mitigation: Enabling conditional Indirect Branch Prediction Barrier
[    0.258867] Spectre V2 : User space: Mitigation: STIBP via prctl
[    0.258867] Speculative Store Bypass: Mitigation: Speculative Store Bypass disabled via prctl
[    0.258867] Freeing SMP alternatives memory: 56K
[    0.258867] smpboot: CPU0: AMD Ryzen 9 3900X 12-Core Processor (family: 0x17, model: 0x71, stepping: 0x0)
[    0.258867] cblist_init_generic: Setting adjustable number of callback queues.
[    0.258867] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.258867] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.258895] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.261292] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[    0.263817] ... version:                0
[    0.265391] ... bit width:              48
[    0.267068] ... generic registers:      6
[    0.268634] ... value mask:             0000ffffffffffff
[    0.268871] ... max period:             00007fffffffffff
[    0.270991] ... fixed-purpose events:   0
[    0.272571] ... event mask:             000000000000003f
[    0.274695] rcu: Hierarchical SRCU implementation.
[    0.276947] smp: Bringing up secondary CPUs ...
[    0.278794] x86: Booting SMP configuration:
[    0.278872] .... node  #0, CPUs:      #1 #2 #3 #4 #5 #6 #7
[    0.279525] smp: Brought up 1 node, 8 CPUs
[    0.282814] smpboot: Max logical packages: 1
[    0.284479] smpboot: Total of 8 processors activated (60800.12 BogoMIPS)
[    0.298895] node 0 deferred pages initialised in 10ms
[    0.300921] devtmpfs: initialized
[    0.300921] x86/mm: Memory block size: 128MB
[    0.302426] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.308889] futex hash table entries: 2048 (order: 5, 131072 bytes, linear)
[    0.312151] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.314571] thermal_sys: Registered thermal governor 'step_wise'
[    0.314572] thermal_sys: Registered thermal governor 'user_space'
[    0.316961] cpuidle: using governor menu
[    0.318916] PCI: Fatal: No config space access function found
[    0.322206] kprobes: kprobe jump-optimization is enabled. All kprobes are optimized if possible.
[    0.322206] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[    0.322206] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[    0.328925] raid6: skipped pq benchmark and selected avx2x4
[    0.331164] raid6: using avx2x2 recovery algorithm
[    0.331164] ACPI: Added _OSI(Module Device)
[    0.331164] ACPI: Added _OSI(Processor Device)
[    0.332457] ACPI: Added _OSI(3.0 _SCP Extensions)
[    0.334283] ACPI: Added _OSI(Processor Aggregator Device)
[    0.336463] ACPI: Added _OSI(Linux-Dell-Video)
[    0.338283] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[    0.348871] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)
[    0.355075] ACPI: 1 ACPI AML tables successfully acquired and loaded
[    0.358946] ACPI: Interpreter enabled
[    0.360583] ACPI: PM: (supports S0 S5)
[    0.362198] ACPI: Using IOAPIC for interrupt routing
[    0.364304] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
[    0.368017] ACPI: Enabled 1 GPEs in block 00 to 0F
[    0.369481] iommu: Default domain type: Translated 
[    0.371449] iommu: DMA domain TLB invalidation policy: lazy mode 
[    0.373937] SCSI subsystem initialized
[    0.375541] ACPI: bus type USB registered
[    0.377164] usbcore: registered new interface driver usbfs
[    0.378875] usbcore: registered new interface driver hub
[    0.380985] usbcore: registered new device driver usb
[    0.383023] hv_vmbus: Vmbus version:5.2
[    0.383023] PCI: Using ACPI for IRQ routing
[    0.383023] PCI: System does not support PCI
[    0.389034] clocksource: Switched to clocksource tsc-early
[    0.389075] hv_vmbus: Unknown GUID: c376c1c3-d276-48d2-90a9-c04748072c60
[    0.394146] hv_vmbus: Unknown GUID: 6e382d18-3336-4f4b-acc4-2b7703d4df4a
[    0.396909] hv_vmbus: Unknown GUID: dde9cbc0-5060-4436-9448-ea1254a5d177
[    0.399744] VFS: Disk quotas dquot_6.6.0
[    0.401370] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.404186] FS-Cache: Loaded
[    0.405386] pnp: PnP ACPI init
[    0.406693] pnp: PnP ACPI: found 3 devices
[    0.412166] NET: Registered PF_INET protocol family
[    0.414416] IP idents hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.418515] tcp_listen_portaddr_hash hash table entries: 8192 (order: 5, 131072 bytes, linear)
[    0.422058] TCP established hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.425602] TCP bind hash table entries: 65536 (order: 8, 1048576 bytes, linear)
[    0.428661] TCP: Hash tables configured (established 131072 bind 65536)
[    0.431375] UDP hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.434579] UDP-Lite hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.437587] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.440120] RPC: Registered named UNIX socket transport module.
[    0.442979] RPC: Registered udp transport module.
[    0.445120] RPC: Registered tcp transport module.
[    0.447250] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.449989] PCI: CLS 0 bytes, default 64
[    0.451619] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[    0.451654] Trying to unpack rootfs image as initramfs...
[    0.454256] software IO TLB: mapped [mem 0x00000000f4000000-0x00000000f8000000] (64MB)
[    0.456463] Freeing initrd memory: 364K
[    0.541510] kvm: no hardware support for 'kvm_intel'
[    0.543867] SVM: TSC scaling supported
[    0.545319] kvm: Nested Virtualization enabled
[    0.547040] SVM: kvm: Nested Paging enabled
[    0.548653] SVM: kvm: Hyper-V enlightened NPT TLB flush enabled
[    0.550967] SVM: kvm: Hyper-V Direct TLB Flush enabled
[    0.552946] SVM: Virtual VMLOAD VMSAVE supported
[    0.618969] Initialise system trusted keyrings
[    0.620900] workingset: timestamp_bits=46 max_order=22 bucket_order=0
[    0.624053] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.626726] NFS: Registering the id_resolver key type
[    0.628690] Key type id_resolver registered
[    0.630376] Key type id_legacy registered
[    0.631915] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.634537] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    0.637515] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[    0.640546] Key type cifs.idmap registered
[    0.642255] fuse: init (API version 7.36)
[    0.643973] SGI XFS with ACLs, security attributes, realtime, scrub, repair, quota, no debug enabled
[    0.647888] 9p: Installing v9fs 9p2000 file system support
[    0.650100] ceph: loaded (mds proto 32)
[    0.653965] NET: Registered PF_ALG protocol family
[    0.655832] xor: automatically using best checksumming function   avx       
[    0.658591] Key type asymmetric registered
[    0.660227] Asymmetric key parser 'x509' registered
[    0.662151] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[    0.665489] hv_vmbus: registering driver hv_pci
[    0.667566] hv_pci b440727e-7525-4d9c-a556-d52029b00086: PCI VMBus probing: Using version 0x10004
[    0.671953] hv_pci b440727e-7525-4d9c-a556-d52029b00086: PCI host bridge to bus 7525:00
[    0.675135] pci_bus 7525:00: root bus resource [mem 0x9ffe00000-0x9ffe02fff window]
[    0.678177] pci_bus 7525:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.682285] pci 7525:00:00.0: [1af4:1043] type 00 class 0x010000
[    0.686012] pci 7525:00:00.0: reg 0x10: [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.689489] pci 7525:00:00.0: reg 0x18: [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.693005] pci 7525:00:00.0: reg 0x20: [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.698805] pci_bus 7525:00: busn_res: [bus 00-ff] end is updated to 00
[    0.701529] pci 7525:00:00.0: BAR 0: assigned [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.705034] pci 7525:00:00.0: BAR 2: assigned [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.708415] pci 7525:00:00.0: BAR 4: assigned [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.712037] hv_pci 121abb12-7ab2-45ff-b4ee-e85a1067c860: PCI VMBus probing: Using version 0x10004
[    0.716192] hv_pci 121abb12-7ab2-45ff-b4ee-e85a1067c860: PCI host bridge to bus 7ab2:00
[    0.719504] pci_bus 7ab2:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.723020] pci 7ab2:00:00.0: [1414:008e] type 00 class 0x030200
[    0.729607] pci_bus 7ab2:00: busn_res: [bus 00-ff] end is updated to 00
[    0.732348] hv_pci 0c573a50-ca5d-42a9-9657-3920a455151c: PCI VMBus probing: Using version 0x10004
[    0.736748] hv_pci 0c573a50-ca5d-42a9-9657-3920a455151c: PCI host bridge to bus ca5d:00
[    0.739875] pci_bus ca5d:00: root bus resource [mem 0x9ffe04000-0x9ffe06fff window]
[    0.742859] pci_bus ca5d:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.746939] pci ca5d:00:00.0: [1af4:1049] type 00 class 0x010000
[    0.750206] pci ca5d:00:00.0: reg 0x10: [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.753516] pci ca5d:00:00.0: reg 0x18: [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.756826] pci ca5d:00:00.0: reg 0x20: [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.763185] pci_bus ca5d:00: busn_res: [bus 00-ff] end is updated to 00
[    0.765793] pci ca5d:00:00.0: BAR 0: assigned [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.769223] pci ca5d:00:00.0: BAR 2: assigned [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.772634] pci ca5d:00:00.0: BAR 4: assigned [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.784382] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.787110] 00:00: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    0.790429] 00:01: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[    0.829682] Non-volatile memory driver v1.3
[    0.831440] printk: console [hvc0] enabled
[    0.833112] printk: bootconsole [uart8250] disabled
[    0.836997] brd: module loaded
[    0.838058] loop: module loaded
[    0.838265] hv_vmbus: registering driver hv_storvsc
[    0.838832] wireguard: WireGuard 1.0.0 loaded. See www.wireguard.com for information.
[    0.839306] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
[    0.839681] tun: Universal TUN/TAP device driver, 1.6
[    0.839972] PPP generic driver version 2.4.2
[    0.840236] scsi host0: storvsc_host_t
[    0.840302] PPP BSD Compression module registered
[    0.840692] PPP Deflate Compression module registered
[    0.841134] PPP MPPE Compression module registered
[    0.841392] NET: Registered PF_PPPOX protocol family
[    0.841654] usbcore: registered new interface driver cdc_ether
[    0.841957] usbcore: registered new interface driver cdc_ncm
[    0.842276] hv_vmbus: registering driver hv_netvsc
[    0.842639] VFIO - User Level meta-driver version: 0.3
[    0.843061] usbcore: registered new interface driver cdc_acm
[    0.843378] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[    0.843756] usbcore: registered new interface driver ch341
[    0.843966] usbserial: USB Serial support registered for ch341-uart
[    0.844287] usbcore: registered new interface driver cp210x
[    0.844545] usbserial: USB Serial support registered for cp210x
[    0.844853] usbcore: registered new interface driver ftdi_sio
[    0.845182] usbserial: USB Serial support registered for FTDI USB Serial Device
[    0.845673] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.846016] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 1
[    0.846374] vhci_hcd: created sysfs vhci_hcd.0
[    0.846742] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.18
[    0.847077] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.847418] usb usb1: Product: USB/IP Virtual Host Controller
[    0.847660] usb usb1: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 vhci_hcd
[    0.847995] usb usb1: SerialNumber: vhci_hcd.0
[    0.848335] hub 1-0:1.0: USB hub found
[    0.848536] hub 1-0:1.0: 8 ports detected
[    0.848976] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.849254] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 2
[    0.849621] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[    0.850102] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.18
[    0.850427] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.850718] usb usb2: Product: USB/IP Virtual Host Controller
[    0.850961] usb usb2: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 vhci_hcd
[    0.851300] usb usb2: SerialNumber: vhci_hcd.0
[    0.851614] hub 2-0:1.0: USB hub found
[    0.851810] hub 2-0:1.0: 8 ports detected
[    0.852249] hv_vmbus: registering driver hyperv_keyboard
[    0.852593] rtc_cmos 00:02: RTC can wake from S4
[    0.854483] rtc_cmos 00:02: registered as rtc0
[    0.854995] rtc_cmos 00:02: setting system clock to 2022-06-01T17:39:04 UTC (1654105144)
[    0.855309] rtc_cmos 00:02: alarms up to one month, 114 bytes nvram
[    0.855718] device-mapper: ioctl: 4.46.0-ioctl (2022-02-22) initialised: dm-devel@redhat.com
[    0.856172] device-mapper: raid: Loading target version 1.15.1
[    0.856511] usbcore: registered new interface driver usbhid
[    0.856703] usbhid: USB HID core driver
[    0.856901] hv_utils: Registering HyperV Utility Driver
[    0.857113] hv_vmbus: registering driver hv_utils
[    0.857333] hv_vmbus: registering driver hv_balloon
[    0.857338] hv_utils: cannot register PTP clock: 0
[    0.857607] drop_monitor: Initializing network drop monitor service
[    0.858067] hv_utils: TimeSync IC version 4.0
[    0.858073] hv_balloon: Using Dynamic Memory protocol version 2.0
[    0.858248] Mirror/redirect action on
[    0.859029] Free page reporting enabled
[    0.859197] hv_balloon: Cold memory discard hint enabled
[    0.859770] IPVS: Registered protocols (TCP, UDP)
[    0.860029] IPVS: Connection hash table configured (size=4096, memory=64Kbytes)
[    0.860395] IPVS: ipvs loaded.
[    0.860546] IPVS: [rr] scheduler registered.
[    0.860743] IPVS: [wrr] scheduler registered.
[    0.860937] IPVS: [sh] scheduler registered.
[    0.861159] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    0.861418] ipt_CLUSTERIP: ClusterIP Version 0.8 loaded successfully
[    0.861666] Initializing XFRM netlink socket
[    0.861903] NET: Registered PF_INET6 protocol family
[    0.862439] Segment Routing with IPv6
[    0.862619] In-situ OAM (IOAM) with IPv6
[    0.862791] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    0.863092] NET: Registered PF_PACKET protocol family
[    0.863332] Bridge firewalling registered
[    0.863488] 8021q: 802.1Q VLAN Support v1.8
[    0.863653] sctp: Hash tables configured (bind 256/256)
[    0.863885] 9pnet: Installing 9P2000 support
[    0.875420] Key type dns_resolver registered
[    0.875693] Key type ceph registered
[    0.875979] libceph: loaded (mon/osd proto 15/24)
[    0.876260] NET: Registered PF_VSOCK protocol family
[    0.876540] hv_vmbus: registering driver hv_sock
[    0.876769] IPI shorthand broadcast: enabled
[    0.876968] sched_clock: Marking stable (856497151, 19750700)->(930661400, -54413549)
[    0.877527] registered taskstats version 1
[    0.878008] Loading compiled-in X.509 certificates
[    0.878392] Btrfs loaded, crc32c=crc32c-generic, zoned=no, fsverity=no
[    0.883871] Freeing unused kernel image (initmem) memory: 1536K
[    0.958961] Write protecting the kernel read-only data: 24576k
[    0.959743] Freeing unused kernel image (text/rodata gap) memory: 2028K
[    0.960146] Freeing unused kernel image (rodata/data gap) memory: 144K
[    0.960406] Run /init as init process
[    0.960549]   with arguments:
[    0.960690]     /init
[    0.960790]   with environment:
[    0.960931]     HOME=/
[    0.961046]     TERM=linux
[    0.963320] scsi 0:0:0:0: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    0.964110] sd 0:0:0:0: Attached scsi generic sg0 type 0
[    0.964747] sd 0:0:0:0: [sda] 641944 512-byte logical blocks: (329 MB/313 MiB)
[    0.965293] sd 0:0:0:0: [sda] Write Protect is on
[    0.965554] sd 0:0:0:0: [sda] Mode Sense: 0f 00 80 00
[    0.965967] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[    1.459424] EXT4-fs (sda): mounted filesystem without journal. Quota mode: none.
[    1.677905] hv_pci 75e234e6-9a41-4c1d-8ac8-5d395d071dd2: PCI VMBus probing: Using version 0x10004
[    1.678919] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    1.679926] hv_pci 75e234e6-9a41-4c1d-8ac8-5d395d071dd2: PCI host bridge to bus 9a41:00
[    1.680478] pci_bus 9a41:00: root bus resource [mem 0xa00000000-0xc00001fff window]
[    1.680783] pci_bus 9a41:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.682091] pci 9a41:00:00.0: [1af4:105a] type 00 class 0x088000
[    1.684295] pci 9a41:00:00.0: reg 0x10: [mem 0xc00000000-0xc00000fff 64bit]
[    1.686271] pci 9a41:00:00.0: reg 0x18: [mem 0xc00001000-0xc00001fff 64bit]
[    1.688288] pci 9a41:00:00.0: reg 0x20: [mem 0xa00000000-0xbffffffff 64bit]
[    1.693245] pci_bus 9a41:00: busn_res: [bus 00-ff] end is updated to 00
[    1.693513] pci 9a41:00:00.0: BAR 4: assigned [mem 0xa00000000-0xbffffffff 64bit]
[    1.695391] pci 9a41:00:00.0: BAR 0: assigned [mem 0xc00000000-0xc00000fff 64bit]
[    1.697251] pci 9a41:00:00.0: BAR 2: assigned [mem 0xc00001000-0xc00001fff 64bit]
[    1.712810] virtiofs virtio2: Cache len: 0x200000000 @ 0xa00000000
[    1.713702] clocksource: Switched to clocksource tsc
[    1.739139] sd 0:0:0:0: [sda] Attached SCSI disk
[    1.778098] memmap_init_zone_device initialised 2097152 pages in 10ms
[    1.779673] WSL2: SetEphemeralPortRange is a no-op : range (0, 0)
[    1.848936] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    2.479025] scsi 0:0:0:1: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.479872] sd 0:0:0:1: Attached scsi generic sg1 type 0
[    2.480323] sd 0:0:0:1: [sdb] 2097160 512-byte logical blocks: (1.07 GB/1.00 GiB)
[    2.480417] scsi 0:0:0:2: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.480787] sd 0:0:0:1: [sdb] 4096-byte physical blocks
[    2.481485] sd 0:0:0:2: Attached scsi generic sg2 type 0
[    2.481508] sd 0:0:0:1: [sdb] Write Protect is off
[    2.482052] sd 0:0:0:2: [sdc] 536870912 512-byte logical blocks: (275 GB/256 GiB)
[    2.482106] sd 0:0:0:1: [sdb] Mode Sense: 0f 00 00 00
[    2.482522] sd 0:0:0:2: [sdc] 4096-byte physical blocks
[    2.482915] sd 0:0:0:1: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.483103] sd 0:0:0:2: [sdc] Write Protect is off
[    2.483857] sd 0:0:0:2: [sdc] Mode Sense: 0f 00 00 00
[    2.484274] sd 0:0:0:2: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.485716] sd 0:0:0:1: [sdb] Attached SCSI disk
[    2.491559] sd 0:0:0:2: [sdc] Attached SCSI disk
[    2.500504] EXT4-fs (sdc): recovery complete
[    2.501459] EXT4-fs (sdc): mounted filesystem with ordered data mode. Quota mode: none.
[    2.522816] Adding 1048576k swap on /dev/sdb.  Priority:-2 extents:1 across:1048576k 
[    2.681998] hv_pci 218ee01d-fcab-4f07-9ea0-57e00b7600be: PCI VMBus probing: Using version 0x10004
[    2.683056] 9pnet_virtio: no channels available for device drvfs
[    2.683289] hv_pci 218ee01d-fcab-4f07-9ea0-57e00b7600be: PCI host bridge to bus fcab:00
[    2.683349] init: (1) WARNING: mount: waiting for virtio device...
[    2.683645] pci_bus fcab:00: root bus resource [mem 0x9ffe08000-0x9ffe0afff window]
[    2.684167] pci_bus fcab:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.685517] pci fcab:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.686817] pci fcab:00:00.0: reg 0x10: [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.687677] pci fcab:00:00.0: reg 0x18: [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.688539] pci fcab:00:00.0: reg 0x20: [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.692528] pci_bus fcab:00: busn_res: [bus 00-ff] end is updated to 00
[    2.692830] pci fcab:00:00.0: BAR 0: assigned [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.693631] pci fcab:00:00.0: BAR 2: assigned [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.694374] pci fcab:00:00.0: BAR 4: assigned [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.788379] hv_pci 5767d560-6512-42aa-bddc-89eca93e4c84: PCI VMBus probing: Using version 0x10004
[    2.789471] 9pnet_virtio: no channels available for device drvfs
[    2.789751] hv_pci 5767d560-6512-42aa-bddc-89eca93e4c84: PCI host bridge to bus 6512:00
[    2.789774] init: (1) WARNING: mount: waiting for virtio device...
[    2.790068] pci_bus 6512:00: root bus resource [mem 0x9ffe0c000-0x9ffe0efff window]
[    2.790613] pci_bus 6512:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.791858] pci 6512:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.792992] pci 6512:00:00.0: reg 0x10: [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.793834] pci 6512:00:00.0: reg 0x18: [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.794694] pci 6512:00:00.0: reg 0x20: [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.798621] pci_bus 6512:00: busn_res: [bus 00-ff] end is updated to 00
[    2.798961] pci 6512:00:00.0: BAR 0: assigned [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.799695] pci 6512:00:00.0: BAR 2: assigned [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.800416] pci 6512:00:00.0: BAR 4: assigned [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.895193] hv_pci 4fae7a25-5e7f-42d1-8a8f-7e1eb4128529: PCI VMBus probing: Using version 0x10004
[    2.896654] hv_pci 4fae7a25-5e7f-42d1-8a8f-7e1eb4128529: PCI host bridge to bus 5e7f:00
[    2.897036] pci_bus 5e7f:00: root bus resource [mem 0x9ffe10000-0x9ffe12fff window]
[    2.897405] pci_bus 5e7f:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.898729] pci 5e7f:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.900002] pci 5e7f:00:00.0: reg 0x10: [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.900885] pci 5e7f:00:00.0: reg 0x18: [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.901753] pci 5e7f:00:00.0: reg 0x20: [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    2.905797] pci_bus 5e7f:00: busn_res: [bus 00-ff] end is updated to 00
[    2.906134] pci 5e7f:00:00.0: BAR 0: assigned [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.906894] pci 5e7f:00:00.0: BAR 2: assigned [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.907627] pci 5e7f:00:00.0: BAR 4: assigned [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    3.077268] hv_pci 98cd7659-96ca-4b6a-95f7-0896075bc081: PCI VMBus probing: Using version 0x10004
[    3.078351] 9pnet_virtio: no channels available for device drvfs
[    3.078666] init: (1) WARNING: mount: waiting for virtio device...
[    3.078865] hv_pci 98cd7659-96ca-4b6a-95f7-0896075bc081: PCI host bridge to bus 96ca:00
[    3.079411] pci_bus 96ca:00: root bus resource [mem 0x9ffe14000-0x9ffe16fff window]
[    3.079774] pci_bus 96ca:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.081309] pci 96ca:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.082647] pci 96ca:00:00.0: reg 0x10: [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.083650] pci 96ca:00:00.0: reg 0x18: [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.084634] pci 96ca:00:00.0: reg 0x20: [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.088677] pci_bus 96ca:00: busn_res: [bus 00-ff] end is updated to 00
[    3.089026] pci 96ca:00:00.0: BAR 0: assigned [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.089905] pci 96ca:00:00.0: BAR 2: assigned [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.090676] pci 96ca:00:00.0: BAR 4: assigned [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.183923] hv_pci d00b62d9-165b-4f27-8533-5d0402fb00d8: PCI VMBus probing: Using version 0x10004
[    3.185457] hv_pci d00b62d9-165b-4f27-8533-5d0402fb00d8: PCI host bridge to bus 165b:00
[    3.185861] pci_bus 165b:00: root bus resource [mem 0x9ffe18000-0x9ffe1afff window]
[    3.185908] 9pnet_virtio: no channels available for device drvfs
[    3.186186] pci_bus 165b:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.186580] init: (1) WARNING: mount: waiting for virtio device...
[    3.187888] pci 165b:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.189081] pci 165b:00:00.0: reg 0x10: [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.189964] pci 165b:00:00.0: reg 0x18: [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.190841] pci 165b:00:00.0: reg 0x20: [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.194800] pci_bus 165b:00: busn_res: [bus 00-ff] end is updated to 00
[    3.195067] pci 165b:00:00.0: BAR 0: assigned [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.195787] pci 165b:00:00.0: BAR 2: assigned [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.196517] pci 165b:00:00.0: BAR 4: assigned [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.292120] hv_pci ff437ee8-6a13-4119-800a-411d24b930e4: PCI VMBus probing: Using version 0x10004
[    3.293643] hv_pci ff437ee8-6a13-4119-800a-411d24b930e4: PCI host bridge to bus 6a13:00
[    3.294135] pci_bus 6a13:00: root bus resource [mem 0x9ffe1c000-0x9ffe1efff window]
[    3.294500] pci_bus 6a13:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.295857] pci 6a13:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.297136] pci 6a13:00:00.0: reg 0x10: [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.298009] pci 6a13:00:00.0: reg 0x18: [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.298981] pci 6a13:00:00.0: reg 0x20: [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[    3.303144] pci_bus 6a13:00: busn_res: [bus 00-ff] end is updated to 00
[    3.303421] pci 6a13:00:00.0: BAR 0: assigned [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.304141] pci 6a13:00:00.0: BAR 2: assigned [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.304851] pci 6a13:00:00.0: BAR 4: assigned [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[   49.723597] hv_balloon: Max. dynamic memory size: 16384 MB

[-- Attachment #3: bad.log --]
[-- Type: text/plain, Size: 34554 bytes --]

# cat /sys/kernel/debug/swiotlb/io_tlb_nslabs
32768

# dmesg
[    0.000000] Linux version 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 (nathan@dev-arch.thelio-3990X) (gcc (GCC) 12.1.0, GNU ld (GNU Binutils) 2.38) #1 SMP PREEMPT_DYNAMIC Wed Jun 1 10:41:21 MST 2022
[    0.000000] Command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 1776
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000e0fff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000001fffff] ACPI data
[    0.000000] BIOS-e820: [mem 0x0000000000200000-0x00000000f7ffffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000100000000-0x0000000407ffffff] usable
[    0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '115200')
[    0.000000] printk: bootconsole [uart8250] enabled
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI not present or invalid.
[    0.000000] Hypervisor detected: Microsoft Hyper-V
[    0.000000] Hyper-V: privilege flags low 0xae7f, high 0x3b8030, hints 0xc2c, misc 0xe0bed7b6
[    0.000000] Hyper-V: Host Build 10.0.22000.708-0-0
[    0.000000] Hyper-V: Nested features: 0x4a0000
[    0.000000] Hyper-V: LAPIC Timer Frequency: 0x1e8480
[    0.000000] Hyper-V: Using hypercall for remote TLB flush
[    0.000000] clocksource: hyperv_clocksource_tsc_page: mask: 0xffffffffffffffff max_cycles: 0x24e6a1710, max_idle_ns: 440795202120 ns
[    0.000003] tsc: Detected 3800.008 MHz processor
[    0.001844] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.004500] e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.006752] last_pfn = 0x408000 max_arch_pfn = 0x400000000
[    0.008928] x86/PAT: Configuration [0-7]: WB  WC  UC- UC  WB  WP  UC- WT  
[    0.011617] last_pfn = 0xf8000 max_arch_pfn = 0x400000000
[    0.013721] Using GB pages for direct mapping
[    0.015504] RAMDISK: [mem 0x0371f000-0x03779fff]
[    0.017288] ACPI: Early table checksum verification disabled
[    0.019511] ACPI: RSDP 0x00000000000E0000 000024 (v02 VRTUAL)
[    0.021806] ACPI: XSDT 0x0000000000100000 000044 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.025255] ACPI: FACP 0x0000000000101000 000114 (v06 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.028644] ACPI: DSDT 0x00000000001011B8 01E184 (v02 MSFTVM DSDT01   00000001 MSFT 05000000)
[    0.032074] ACPI: FACS 0x0000000000101114 000040
[    0.033876] ACPI: OEM0 0x0000000000101154 000064 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.037335] ACPI: SRAT 0x000000000011F33C 000330 (v02 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.040839] ACPI: APIC 0x000000000011F66C 000088 (v04 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.044205] ACPI: Reserving FACP table memory at [mem 0x101000-0x101113]
[    0.046856] ACPI: Reserving DSDT table memory at [mem 0x1011b8-0x11f33b]
[    0.049526] ACPI: Reserving FACS table memory at [mem 0x101114-0x101153]
[    0.052323] ACPI: Reserving OEM0 table memory at [mem 0x101154-0x1011b7]
[    0.054916] ACPI: Reserving SRAT table memory at [mem 0x11f33c-0x11f66b]
[    0.057563] ACPI: Reserving APIC table memory at [mem 0x11f66c-0x11f6f3]
[    0.060644] Zone ranges:
[    0.061621]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.064031]   DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
[    0.066551]   Normal   [mem 0x0000000100000000-0x0000000407ffffff]
[    0.069096]   Device   empty
[    0.070236] Movable zone start for each node
[    0.071880] Early memory node ranges
[    0.073323]   node   0: [mem 0x0000000000001000-0x000000000009ffff]
[    0.075736]   node   0: [mem 0x0000000000200000-0x00000000f7ffffff]
[    0.078260]   node   0: [mem 0x0000000100000000-0x0000000407ffffff]
[    0.080698] Initmem setup node 0 [mem 0x0000000000001000-0x0000000407ffffff]
[    0.083706] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.083724] On node 0, zone DMA: 352 pages in unavailable ranges
[    0.095850] ACPI: LAPIC_NMI (acpi_id[0x01] dfl dfl lint[0x1])
[    0.100817] IOAPIC[0]: apic_id 8, version 17, address 0xfec00000, GSI 0-23
[    0.103601] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[    0.106156] ACPI: Using ACPI (MADT) for SMP configuration information
[    0.108743] smpboot: Allowing 8 CPUs, 0 hotplug CPUs
[    0.110810] [mem 0xf8000000-0xffffffff] available for PCI devices
[    0.113193] Booting paravirtualized kernel on Hyper-V
[    0.115221] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.124086] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:8 nr_node_ids:1
[    0.127620] percpu: Embedded 53 pages/cpu s178408 r8192 d30488 u262144
[    0.130204] pcpu-alloc: s178408 r8192 d30488 u262144 alloc=1*2097152
[    0.132746] pcpu-alloc: [0] 0 1 2 3 4 5 6 7 
[    0.134452] Hyper-V: PV spinlocks enabled
[    0.136082] PV qspinlock hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.138923] Built 1 zonelists, mobility grouping on.  Total pages: 4127749
[    0.141669] Kernel command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.149809] Dentry cache hash table entries: 2097152 (order: 12, 16777216 bytes, linear)
[    0.154232] Inode-cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.157400] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.182296] Memory: 4126096K/16775804K available (18449K kernel code, 2647K rwdata, 3952K rodata, 1536K init, 2448K bss, 392692K reserved, 0K cma-reserved)
[    0.188084] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
[    0.190824] ftrace: allocating 51788 entries in 203 pages
[    0.199397] ftrace: allocated 203 pages with 5 groups
[    0.202320] Dynamic Preempt: none
[    0.203777] rcu: Preemptible hierarchical RCU implementation.
[    0.206055] rcu: 	RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=8.
[    0.208807] 	Trampoline variant of Tasks RCU enabled.
[    0.210844] 	Rude variant of Tasks RCU enabled.
[    0.213292] 	Tracing variant of Tasks RCU enabled.
[    0.215445] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.218380] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=8
[    0.224306] Using NULL legacy PIC
[    0.225589] NR_IRQS: 16640, nr_irqs: 488, preallocated irqs: 0
[    0.228245] random: crng init done (trusting CPU's manufacturer)
[    0.230636] Console: colour dummy device 80x25
[    0.232438] ACPI: Core revision 20211217
[    0.234033] Failed to register legacy timer interrupt
[    0.236047] APIC: Switch to symmetric I/O mode setup
[    0.238014] Hyper-V: enabling crash_kexec_post_notifiers
[    0.240107] Hyper-V: Using IPI hypercalls
[    0.241666] Hyper-V: Using enlightened APIC (xapic mode)
[    0.241757] clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    0.247930] Calibrating delay loop (skipped), value calculated using timer frequency.. 7600.01 BogoMIPS (lpj=38000080)
[    0.252067] pid_max: default: 32768 minimum: 301
[    0.253895] LSM: Security Framework initializing
[    0.255751] Mount-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.257927] Mountpoint-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.257927] x86/cpu: User Mode Instruction Prevention (UMIP) activated
[    0.257927] Last level iTLB entries: 4KB 1024, 2MB 1024, 4MB 512
[    0.257927] Last level dTLB entries: 4KB 2048, 2MB 2048, 4MB 1024, 1GB 0
[    0.257927] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.257927] Spectre V2 : Mitigation: Retpolines
[    0.257927] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
[    0.257927] Spectre V2 : mitigation: Enabling conditional Indirect Branch Prediction Barrier
[    0.257927] Spectre V2 : User space: Mitigation: STIBP via prctl
[    0.257927] Speculative Store Bypass: Mitigation: Speculative Store Bypass disabled via prctl
[    0.257927] Freeing SMP alternatives memory: 56K
[    0.257927] smpboot: CPU0: AMD Ryzen 9 3900X 12-Core Processor (family: 0x17, model: 0x71, stepping: 0x0)
[    0.257927] cblist_init_generic: Setting adjustable number of callback queues.
[    0.257927] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.257927] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.257953] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.260344] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[    0.262870] ... version:                0
[    0.264433] ... bit width:              48
[    0.266024] ... generic registers:      6
[    0.267586] ... value mask:             0000ffffffffffff
[    0.267931] ... max period:             00007fffffffffff
[    0.269978] ... fixed-purpose events:   0
[    0.271549] ... event mask:             000000000000003f
[    0.273693] rcu: Hierarchical SRCU implementation.
[    0.275947] smp: Bringing up secondary CPUs ...
[    0.277746] x86: Booting SMP configuration:
[    0.277931] .... node  #0, CPUs:      #1 #2 #3 #4 #5 #6 #7
[    0.278598] smp: Brought up 1 node, 8 CPUs
[    0.281786] smpboot: Max logical packages: 1
[    0.283442] smpboot: Total of 8 processors activated (60800.12 BogoMIPS)
[    0.297948] node 0 deferred pages initialised in 10ms
[    0.300095] devtmpfs: initialized
[    0.300095] x86/mm: Memory block size: 128MB
[    0.301372] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.307950] futex hash table entries: 2048 (order: 5, 131072 bytes, linear)
[    0.311117] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.313590] thermal_sys: Registered thermal governor 'step_wise'
[    0.313591] thermal_sys: Registered thermal governor 'user_space'
[    0.315970] cpuidle: using governor menu
[    0.317983] PCI: Fatal: No config space access function found
[    0.321181] kprobes: kprobe jump-optimization is enabled. All kprobes are optimized if possible.
[    0.321181] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[    0.321181] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[    0.327982] raid6: skipped pq benchmark and selected avx2x4
[    0.330080] raid6: using avx2x2 recovery algorithm
[    0.331916] ACPI: Added _OSI(Module Device)
[    0.337945] ACPI: Added _OSI(Processor Device)
[    0.339664] ACPI: Added _OSI(3.0 _SCP Extensions)
[    0.341472] ACPI: Added _OSI(Processor Aggregator Device)
[    0.343581] ACPI: Added _OSI(Linux-Dell-Video)
[    0.345290] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[    0.347310] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)
[    0.351846] ACPI: 1 ACPI AML tables successfully acquired and loaded
[    0.354878] ACPI: Interpreter enabled
[    0.357948] ACPI: PM: (supports S0 S5)
[    0.359386] ACPI: Using IOAPIC for interrupt routing
[    0.361295] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
[    0.364875] ACPI: Enabled 1 GPEs in block 00 to 0F
[    0.367281] iommu: Default domain type: Translated 
[    0.367930] iommu: DMA domain TLB invalidation policy: lazy mode 
[    0.370342] SCSI subsystem initialized
[    0.371819] ACPI: bus type USB registered
[    0.373384] usbcore: registered new interface driver usbfs
[    0.375508] usbcore: registered new interface driver hub
[    0.377556] usbcore: registered new device driver usb
[    0.378007] hv_vmbus: Vmbus version:5.2
[    0.379525] PCI: Using ACPI for IRQ routing
[    0.381148] PCI: System does not support PCI
[    0.382985] hv_vmbus: Unknown GUID: c376c1c3-d276-48d2-90a9-c04748072c60
[    0.385656] hv_vmbus: Unknown GUID: 6e382d18-3336-4f4b-acc4-2b7703d4df4a
[    0.385656] hv_vmbus: Unknown GUID: dde9cbc0-5060-4436-9448-ea1254a5d177
[    0.385656] clocksource: Switched to clocksource tsc-early
[    0.395132] VFS: Disk quotas dquot_6.6.0
[    0.398629] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.401503] FS-Cache: Loaded
[    0.402695] pnp: PnP ACPI init
[    0.403992] pnp: PnP ACPI: found 3 devices
[    0.409671] NET: Registered PF_INET protocol family
[    0.411938] IP idents hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.416026] tcp_listen_portaddr_hash hash table entries: 8192 (order: 5, 131072 bytes, linear)
[    0.419575] TCP established hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.423230] TCP bind hash table entries: 65536 (order: 8, 1048576 bytes, linear)
[    0.426347] TCP: Hash tables configured (established 131072 bind 65536)
[    0.429190] UDP hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.432209] UDP-Lite hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.435648] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.438375] RPC: Registered named UNIX socket transport module.
[    0.440789] RPC: Registered udp transport module.
[    0.442671] RPC: Registered tcp transport module.
[    0.444673] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.447332] PCI: CLS 0 bytes, default 64
[    0.448993] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[    0.449028] Trying to unpack rootfs image as initramfs...
[    0.451710] software IO TLB: mapped [mem 0x00000000f4000000-0x00000000f8000000] (64MB)
[    0.454079] Freeing initrd memory: 364K
[    0.541430] kvm: no hardware support for 'kvm_intel'
[    0.543753] SVM: TSC scaling supported
[    0.545214] kvm: Nested Virtualization enabled
[    0.546939] SVM: kvm: Nested Paging enabled
[    0.548655] SVM: kvm: Hyper-V enlightened NPT TLB flush enabled
[    0.550982] SVM: kvm: Hyper-V Direct TLB Flush enabled
[    0.553055] SVM: Virtual VMLOAD VMSAVE supported
[    0.619230] Initialise system trusted keyrings
[    0.621148] workingset: timestamp_bits=46 max_order=22 bucket_order=0
[    0.624304] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.626917] NFS: Registering the id_resolver key type
[    0.628911] Key type id_resolver registered
[    0.630622] Key type id_legacy registered
[    0.632252] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.635096] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    0.638073] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[    0.641200] Key type cifs.idmap registered
[    0.642865] fuse: init (API version 7.36)
[    0.644622] SGI XFS with ACLs, security attributes, realtime, scrub, repair, quota, no debug enabled
[    0.648593] 9p: Installing v9fs 9p2000 file system support
[    0.650987] ceph: loaded (mds proto 32)
[    0.654860] NET: Registered PF_ALG protocol family
[    0.656711] xor: automatically using best checksumming function   avx       
[    0.659472] Key type asymmetric registered
[    0.661072] Asymmetric key parser 'x509' registered
[    0.662976] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[    0.666333] hv_vmbus: registering driver hv_pci
[    0.668465] hv_pci a154a52e-df93-4a32-a470-37362af9092a: PCI VMBus probing: Using version 0x10004
[    0.672862] hv_pci a154a52e-df93-4a32-a470-37362af9092a: PCI host bridge to bus df93:00
[    0.675963] pci_bus df93:00: root bus resource [mem 0x9ffe00000-0x9ffe02fff window]
[    0.678965] pci_bus df93:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.683016] pci df93:00:00.0: [1af4:1043] type 00 class 0x010000
[    0.686425] pci df93:00:00.0: reg 0x10: [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.689851] pci df93:00:00.0: reg 0x18: [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.693249] pci df93:00:00.0: reg 0x20: [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.698971] pci_bus df93:00: busn_res: [bus 00-ff] end is updated to 00
[    0.701554] pci df93:00:00.0: BAR 0: assigned [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.704894] pci df93:00:00.0: BAR 2: assigned [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.708243] pci df93:00:00.0: BAR 4: assigned [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.711877] hv_pci ca66d0fe-4477-439b-9d67-02d7bd2dcb05: PCI VMBus probing: Using version 0x10004
[    0.716001] hv_pci ca66d0fe-4477-439b-9d67-02d7bd2dcb05: PCI host bridge to bus 4477:00
[    0.719136] pci_bus 4477:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.722586] pci 4477:00:00.0: [1414:008e] type 00 class 0x030200
[    0.729016] pci_bus 4477:00: busn_res: [bus 00-ff] end is updated to 00
[    0.731822] hv_pci c42c9658-a709-40bd-8d72-5ee9b78e28ca: PCI VMBus probing: Using version 0x10004
[    0.736240] hv_pci c42c9658-a709-40bd-8d72-5ee9b78e28ca: PCI host bridge to bus a709:00
[    0.739381] pci_bus a709:00: root bus resource [mem 0x9ffe04000-0x9ffe06fff window]
[    0.742368] pci_bus a709:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.746437] pci a709:00:00.0: [1af4:1049] type 00 class 0x010000
[    0.749663] pci a709:00:00.0: reg 0x10: [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.752975] pci a709:00:00.0: reg 0x18: [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.756273] pci a709:00:00.0: reg 0x20: [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.762929] pci_bus a709:00: busn_res: [bus 00-ff] end is updated to 00
[    0.765585] pci a709:00:00.0: BAR 0: assigned [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.769014] pci a709:00:00.0: BAR 2: assigned [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.772436] pci a709:00:00.0: BAR 4: assigned [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.784024] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.786788] 00:00: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    0.790004] 00:01: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[    0.828478] Non-volatile memory driver v1.3
[    0.830180] printk: console [hvc0] enabled
[    0.831804] printk: bootconsole [uart8250] disabled
[    0.835700] brd: module loaded
[    0.836692] loop: module loaded
[    0.836890] hv_vmbus: registering driver hv_storvsc
[    0.837466] wireguard: WireGuard 1.0.0 loaded. See www.wireguard.com for information.
[    0.837853] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
[    0.838217] scsi host0: storvsc_host_t
[    0.838399] tun: Universal TUN/TAP device driver, 1.6
[    0.838812] PPP generic driver version 2.4.2
[    0.839159] PPP BSD Compression module registered
[    0.839395] PPP Deflate Compression module registered
[    0.839781] PPP MPPE Compression module registered
[    0.840046] NET: Registered PF_PPPOX protocol family
[    0.840326] usbcore: registered new interface driver cdc_ether
[    0.840687] usbcore: registered new interface driver cdc_ncm
[    0.841009] hv_vmbus: registering driver hv_netvsc
[    0.841331] VFIO - User Level meta-driver version: 0.3
[    0.841707] usbcore: registered new interface driver cdc_acm
[    0.841999] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[    0.842346] usbcore: registered new interface driver ch341
[    0.842613] usbserial: USB Serial support registered for ch341-uart
[    0.842907] usbcore: registered new interface driver cp210x
[    0.843226] usbserial: USB Serial support registered for cp210x
[    0.843574] usbcore: registered new interface driver ftdi_sio
[    0.843874] usbserial: USB Serial support registered for FTDI USB Serial Device
[    0.844325] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.844630] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 1
[    0.844968] vhci_hcd: created sysfs vhci_hcd.0
[    0.845394] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.18
[    0.845749] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.846033] usb usb1: Product: USB/IP Virtual Host Controller
[    0.846274] usb usb1: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 vhci_hcd
[    0.846606] usb usb1: SerialNumber: vhci_hcd.0
[    0.846887] hub 1-0:1.0: USB hub found
[    0.847077] hub 1-0:1.0: 8 ports detected
[    0.847565] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.847828] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 2
[    0.848246] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[    0.848690] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.18
[    0.848997] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.849279] usb usb2: Product: USB/IP Virtual Host Controller
[    0.849523] usb usb2: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 vhci_hcd
[    0.849855] usb usb2: SerialNumber: vhci_hcd.0
[    0.850138] hub 2-0:1.0: USB hub found
[    0.850333] hub 2-0:1.0: 8 ports detected
[    0.850772] hv_vmbus: registering driver hyperv_keyboard
[    0.851119] rtc_cmos 00:02: RTC can wake from S4
[    0.853017] rtc_cmos 00:02: registered as rtc0
[    0.853536] rtc_cmos 00:02: setting system clock to 2022-06-01T17:41:59 UTC (1654105319)
[    0.853854] rtc_cmos 00:02: alarms up to one month, 114 bytes nvram
[    0.854249] device-mapper: ioctl: 4.46.0-ioctl (2022-02-22) initialised: dm-devel@redhat.com
[    0.854710] device-mapper: raid: Loading target version 1.15.1
[    0.855003] usbcore: registered new interface driver usbhid
[    0.855198] usbhid: USB HID core driver
[    0.855394] hv_utils: Registering HyperV Utility Driver
[    0.855608] hv_vmbus: registering driver hv_utils
[    0.855910] hv_vmbus: registering driver hv_balloon
[    0.855914] hv_utils: cannot register PTP clock: 0
[    0.856165] drop_monitor: Initializing network drop monitor service
[    0.856597] hv_balloon: Using Dynamic Memory protocol version 2.0
[    0.856611] hv_utils: TimeSync IC version 4.0
[    0.856742] Mirror/redirect action on
[    0.857542] Free page reporting enabled
[    0.857744] hv_balloon: Cold memory discard hint enabled
[    0.858304] IPVS: Registered protocols (TCP, UDP)
[    0.858534] IPVS: Connection hash table configured (size=4096, memory=64Kbytes)
[    0.858872] IPVS: ipvs loaded.
[    0.859018] IPVS: [rr] scheduler registered.
[    0.859213] IPVS: [wrr] scheduler registered.
[    0.859405] IPVS: [sh] scheduler registered.
[    0.859622] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    0.860047] ipt_CLUSTERIP: ClusterIP Version 0.8 loaded successfully
[    0.860293] Initializing XFRM netlink socket
[    0.860522] NET: Registered PF_INET6 protocol family
[    0.861019] Segment Routing with IPv6
[    0.861193] In-situ OAM (IOAM) with IPv6
[    0.861362] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    0.861655] NET: Registered PF_PACKET protocol family
[    0.861875] Bridge firewalling registered
[    0.862024] 8021q: 802.1Q VLAN Support v1.8
[    0.862189] sctp: Hash tables configured (bind 256/256)
[    0.862419] 9pnet: Installing 9P2000 support
[    0.874428] Key type dns_resolver registered
[    0.874663] Key type ceph registered
[    0.874921] libceph: loaded (mon/osd proto 15/24)
[    0.875208] NET: Registered PF_VSOCK protocol family
[    0.875419] hv_vmbus: registering driver hv_sock
[    0.875644] IPI shorthand broadcast: enabled
[    0.875840] sched_clock: Marking stable (855501109, 19696300)->(934890300, -59692891)
[    0.876403] registered taskstats version 1
[    0.876928] Loading compiled-in X.509 certificates
[    0.877333] Btrfs loaded, crc32c=crc32c-generic, zoned=no, fsverity=no
[    0.882685] Freeing unused kernel image (initmem) memory: 1536K
[    0.918057] Write protecting the kernel read-only data: 24576k
[    0.918975] Freeing unused kernel image (text/rodata gap) memory: 2028K
[    0.919393] Freeing unused kernel image (rodata/data gap) memory: 144K
[    0.919654] Run /init as init process
[    0.919798]   with arguments:
[    0.919940]     /init
[    0.920047]   with environment:
[    0.920190]     HOME=/
[    0.920286]     TERM=linux
[    0.922620] scsi 0:0:0:0: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    0.923252] sd 0:0:0:0: Attached scsi generic sg0 type 0
[    0.923893] sd 0:0:0:0: [sda] 641944 512-byte logical blocks: (329 MB/313 MiB)
[    0.924490] sd 0:0:0:0: [sda] Write Protect is on
[    0.924760] sd 0:0:0:0: [sda] Mode Sense: 0f 00 80 00
[    0.925199] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[    1.538410] EXT4-fs (sda): mounted filesystem without journal. Quota mode: none.
[    1.640080] hv_pci 88309164-1127-4233-9560-6e0cad455d8f: PCI VMBus probing: Using version 0x10004
[    1.642187] hv_pci 88309164-1127-4233-9560-6e0cad455d8f: PCI host bridge to bus 1127:00
[    1.642548] pci_bus 1127:00: root bus resource [mem 0xa00000000-0xc00001fff window]
[    1.642895] pci_bus 1127:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.644287] pci 1127:00:00.0: [1af4:105a] type 00 class 0x088000
[    1.647194] pci 1127:00:00.0: reg 0x10: [mem 0xc00000000-0xc00000fff 64bit]
[    1.649501] pci 1127:00:00.0: reg 0x18: [mem 0xc00001000-0xc00001fff 64bit]
[    1.651514] pci 1127:00:00.0: reg 0x20: [mem 0xa00000000-0xbffffffff 64bit]
[    1.656603] pci_bus 1127:00: busn_res: [bus 00-ff] end is updated to 00
[    1.656902] pci 1127:00:00.0: BAR 4: assigned [mem 0xa00000000-0xbffffffff 64bit]
[    1.658754] pci 1127:00:00.0: BAR 0: assigned [mem 0xc00000000-0xc00000fff 64bit]
[    1.660797] pci 1127:00:00.0: BAR 2: assigned [mem 0xc00001000-0xc00001fff 64bit]
[    1.676734] virtiofs virtio2: Cache len: 0x200000000 @ 0xa00000000
[    1.687964] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    1.688537] clocksource: Switched to clocksource tsc
[    1.718131] sd 0:0:0:0: [sda] Attached SCSI disk
[    1.737024] memmap_init_zone_device initialised 2097152 pages in 10ms
[    1.738457] WSL2: SetEphemeralPortRange is a no-op : range (0, 0)
[    1.847973] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    2.418129] scsi 0:0:0:1: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.418887] sd 0:0:0:1: Attached scsi generic sg1 type 0
[    2.419446] scsi 0:0:0:2: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.419498] sd 0:0:0:1: [sdb] 2097160 512-byte logical blocks: (1.07 GB/1.00 GiB)
[    2.420146] sd 0:0:0:2: Attached scsi generic sg2 type 0
[    2.420236] sd 0:0:0:1: [sdb] 4096-byte physical blocks
[    2.420789] sd 0:0:0:2: [sdc] 536870912 512-byte logical blocks: (275 GB/256 GiB)
[    2.420849] sd 0:0:0:1: [sdb] Write Protect is off
[    2.421225] sd 0:0:0:2: [sdc] 4096-byte physical blocks
[    2.421541] sd 0:0:0:1: [sdb] Mode Sense: 0f 00 00 00
[    2.421888] sd 0:0:0:2: [sdc] Write Protect is off
[    2.422260] sd 0:0:0:1: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.422392] sd 0:0:0:2: [sdc] Mode Sense: 0f 00 00 00
[    2.423302] sd 0:0:0:2: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.424840] sd 0:0:0:1: [sdb] Attached SCSI disk
[    2.426063] sd 0:0:0:2: [sdc] Attached SCSI disk
[    2.444484] EXT4-fs (sdc): recovery complete
[    2.445457] EXT4-fs (sdc): mounted filesystem with ordered data mode. Quota mode: none.
[    2.459372] Adding 1048576k swap on /dev/sdb.  Priority:-2 extents:1 across:1048576k 
[    2.649008] hv_pci aed388e8-de3a-45a5-bb0c-ee534e806689: PCI VMBus probing: Using version 0x10004
[    2.650439] hv_pci aed388e8-de3a-45a5-bb0c-ee534e806689: PCI host bridge to bus de3a:00
[    2.650756] pci_bus de3a:00: root bus resource [mem 0x9ffe08000-0x9ffe0afff window]
[    2.651045] pci_bus de3a:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.652320] pci de3a:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.653496] pci de3a:00:00.0: reg 0x10: [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.654363] pci de3a:00:00.0: reg 0x18: [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.655227] pci de3a:00:00.0: reg 0x20: [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.659234] pci_bus de3a:00: busn_res: [bus 00-ff] end is updated to 00
[    2.659501] pci de3a:00:00.0: BAR 0: assigned [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.660251] pci de3a:00:00.0: BAR 2: assigned [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.660989] pci de3a:00:00.0: BAR 4: assigned [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.663932] 9pnet_virtio: no channels available for device drvfs
[    2.664237] init: (1) WARNING: mount: waiting for virtio device...
[    2.770766] hv_pci 81d9a8d7-9fce-46b7-9ff9-b146da3089e4: PCI VMBus probing: Using version 0x10004
[    2.772061] hv_pci 81d9a8d7-9fce-46b7-9ff9-b146da3089e4: PCI host bridge to bus 9fce:00
[    2.772372] pci_bus 9fce:00: root bus resource [mem 0x9ffe0c000-0x9ffe0efff window]
[    2.772664] pci_bus 9fce:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.773910] pci 9fce:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.775050] pci 9fce:00:00.0: reg 0x10: [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.775911] pci 9fce:00:00.0: reg 0x18: [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.776761] pci 9fce:00:00.0: reg 0x20: [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.780694] pci_bus 9fce:00: busn_res: [bus 00-ff] end is updated to 00
[    2.780986] pci 9fce:00:00.0: BAR 0: assigned [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.781703] pci 9fce:00:00.0: BAR 2: assigned [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.781986] 9pnet_virtio: no channels available for device drvfs
[    2.782311] init: (1) WARNING: mount: waiting for virtio device...
[    2.782471] pci 9fce:00:00.0: BAR 4: assigned [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.898491] hv_pci 86858b54-a9ff-42c1-85be-12646bde6957: PCI VMBus probing: Using version 0x10004
[    2.899831] hv_pci 86858b54-a9ff-42c1-85be-12646bde6957: PCI host bridge to bus a9ff:00
[    2.900148] pci_bus a9ff:00: root bus resource [mem 0x9ffe10000-0x9ffe12fff window]
[    2.900437] pci_bus a9ff:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.901684] pci a9ff:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.902856] pci a9ff:00:00.0: reg 0x10: [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.903716] pci a9ff:00:00.0: reg 0x18: [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.904609] pci a9ff:00:00.0: reg 0x20: [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    2.908519] pci_bus a9ff:00: busn_res: [bus 00-ff] end is updated to 00
[    2.908842] pci a9ff:00:00.0: BAR 0: assigned [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.909600] pci a9ff:00:00.0: BAR 2: assigned [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.910335] pci a9ff:00:00.0: BAR 4: assigned [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    3.009967] hv_pci 14a6c250-2f5e-4544-972d-e4af992a128a: PCI VMBus probing: Using version 0x10004
[    3.011462] hv_pci 14a6c250-2f5e-4544-972d-e4af992a128a: PCI host bridge to bus 2f5e:00
[    3.011804] pci_bus 2f5e:00: root bus resource [mem 0x9ffe14000-0x9ffe16fff window]
[    3.012172] pci_bus 2f5e:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.013562] pci 2f5e:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.014756] pci 2f5e:00:00.0: reg 0x10: [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.015633] pci 2f5e:00:00.0: reg 0x18: [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.016516] pci 2f5e:00:00.0: reg 0x20: [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.020834] pci_bus 2f5e:00: busn_res: [bus 00-ff] end is updated to 00
[    3.021157] pci 2f5e:00:00.0: BAR 0: assigned [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.022095] pci 2f5e:00:00.0: BAR 2: assigned [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.022867] pci 2f5e:00:00.0: BAR 4: assigned [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.030227] 9pnet_virtio: no channels available for device drvfs
[    3.030578] init: (1) WARNING: mount: waiting for virtio device...
[    3.143192] hv_pci ed843176-e057-48d4-ab94-623a027b1629: PCI VMBus probing: Using version 0x10004
[    3.144600] hv_pci ed843176-e057-48d4-ab94-623a027b1629: PCI host bridge to bus e057:00
[    3.144927] pci_bus e057:00: root bus resource [mem 0x9ffe18000-0x9ffe1afff window]
[    3.145222] pci_bus e057:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.146529] pci e057:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.147766] pci e057:00:00.0: reg 0x10: [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.148685] pci e057:00:00.0: reg 0x18: [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.149556] pci e057:00:00.0: reg 0x20: [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.153686] pci_bus e057:00: busn_res: [bus 00-ff] end is updated to 00
[    3.154060] pci e057:00:00.0: BAR 0: assigned [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.154855] pci e057:00:00.0: BAR 2: assigned [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.155592] pci e057:00:00.0: BAR 4: assigned [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.188714] hv_pci c963c476-4546-43da-a32c-7e4ddeb55d93: PCI VMBus probing: Using version 0x10004
[    3.190328] hv_pci c963c476-4546-43da-a32c-7e4ddeb55d93: PCI host bridge to bus 4546:00
[    3.190732] pci_bus 4546:00: root bus resource [mem 0x9ffe1c000-0x9ffe1efff window]
[    3.191104] pci_bus 4546:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.192578] pci 4546:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.193870] pci 4546:00:00.0: reg 0x10: [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.194935] pci 4546:00:00.0: reg 0x18: [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.196022] pci 4546:00:00.0: reg 0x20: [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[    3.200503] pci_bus 4546:00: busn_res: [bus 00-ff] end is updated to 00
[    3.200855] pci 4546:00:00.0: BAR 0: assigned [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.201736] pci 4546:00:00.0: BAR 2: assigned [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.202501] pci 4546:00:00.0: BAR 4: assigned [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[   49.723721] hv_balloon: Max. dynamic memory size: 16384 MB

[-- Attachment #4: Type: text/plain, Size: 156 bytes --]

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:46         ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 17:46 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Joerg Roedel,
	Konrad Rzeszutek Wilk, tboot-devel, xen-devel, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, linuxppc-dev, linux-mips, iommu,
	Robin Murphy, Lu Baolu

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> Can you send me the full dmesg and the content of
> /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?

Sure thing, they are attached! If there is anything else I can provide
or test, I am more than happy to do so.

Cheers,
Nathan

[-- Attachment #2: good.log --]
[-- Type: text/plain, Size: 34692 bytes --]

# cat /sys/kernel/debug/swiotlb/io_tlb_nslabs
32768

# dmesg
[    0.000000] Linux version 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 (nathan@dev-arch.thelio-3990X) (gcc (GCC) 12.1.0, GNU ld (GNU Binutils) 2.38) #1 SMP PREEMPT_DYNAMIC Wed Jun 1 10:38:34 MST 2022
[    0.000000] Command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 1776
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000e0fff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000001fffff] ACPI data
[    0.000000] BIOS-e820: [mem 0x0000000000200000-0x00000000f7ffffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000100000000-0x0000000407ffffff] usable
[    0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '115200')
[    0.000000] printk: bootconsole [uart8250] enabled
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI not present or invalid.
[    0.000000] Hypervisor detected: Microsoft Hyper-V
[    0.000000] Hyper-V: privilege flags low 0xae7f, high 0x3b8030, hints 0xc2c, misc 0xe0bed7b6
[    0.000000] Hyper-V: Host Build 10.0.22000.708-0-0
[    0.000000] Hyper-V: Nested features: 0x4a0000
[    0.000000] Hyper-V: LAPIC Timer Frequency: 0x1e8480
[    0.000000] Hyper-V: Using hypercall for remote TLB flush
[    0.000000] clocksource: hyperv_clocksource_tsc_page: mask: 0xffffffffffffffff max_cycles: 0x24e6a1710, max_idle_ns: 440795202120 ns
[    0.000005] tsc: Detected 3800.008 MHz processor
[    0.001901] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.004593] e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.006806] last_pfn = 0x408000 max_arch_pfn = 0x400000000
[    0.009042] x86/PAT: Configuration [0-7]: WB  WC  UC- UC  WB  WP  UC- WT  
[    0.011760] last_pfn = 0xf8000 max_arch_pfn = 0x400000000
[    0.013959] Using GB pages for direct mapping
[    0.015749] RAMDISK: [mem 0x0371f000-0x03779fff]
[    0.017616] ACPI: Early table checksum verification disabled
[    0.019854] ACPI: RSDP 0x00000000000E0000 000024 (v02 VRTUAL)
[    0.022162] ACPI: XSDT 0x0000000000100000 000044 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.025624] ACPI: FACP 0x0000000000101000 000114 (v06 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.029022] ACPI: DSDT 0x00000000001011B8 01E184 (v02 MSFTVM DSDT01   00000001 MSFT 05000000)
[    0.032413] ACPI: FACS 0x0000000000101114 000040
[    0.034280] ACPI: OEM0 0x0000000000101154 000064 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.037699] ACPI: SRAT 0x000000000011F33C 000330 (v02 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.041089] ACPI: APIC 0x000000000011F66C 000088 (v04 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.044475] ACPI: Reserving FACP table memory at [mem 0x101000-0x101113]
[    0.047159] ACPI: Reserving DSDT table memory at [mem 0x1011b8-0x11f33b]
[    0.049905] ACPI: Reserving FACS table memory at [mem 0x101114-0x101153]
[    0.052693] ACPI: Reserving OEM0 table memory at [mem 0x101154-0x1011b7]
[    0.055404] ACPI: Reserving SRAT table memory at [mem 0x11f33c-0x11f66b]
[    0.058040] ACPI: Reserving APIC table memory at [mem 0x11f66c-0x11f6f3]
[    0.061078] Zone ranges:
[    0.062074]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.066106]   DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
[    0.068763]   Normal   [mem 0x0000000100000000-0x0000000407ffffff]
[    0.071235]   Device   empty
[    0.072384] Movable zone start for each node
[    0.074058] Early memory node ranges
[    0.075515]   node   0: [mem 0x0000000000001000-0x000000000009ffff]
[    0.077979]   node   0: [mem 0x0000000000200000-0x00000000f7ffffff]
[    0.080483]   node   0: [mem 0x0000000100000000-0x0000000407ffffff]
[    0.082980] Initmem setup node 0 [mem 0x0000000000001000-0x0000000407ffffff]
[    0.085954] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.085972] On node 0, zone DMA: 352 pages in unavailable ranges
[    0.098043] ACPI: LAPIC_NMI (acpi_id[0x01] dfl dfl lint[0x1])
[    0.102995] IOAPIC[0]: apic_id 8, version 17, address 0xfec00000, GSI 0-23
[    0.105726] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[    0.108349] ACPI: Using ACPI (MADT) for SMP configuration information
[    0.110909] smpboot: Allowing 8 CPUs, 0 hotplug CPUs
[    0.112902] [mem 0xf8000000-0xffffffff] available for PCI devices
[    0.115315] Booting paravirtualized kernel on Hyper-V
[    0.117347] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.126056] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:8 nr_node_ids:1
[    0.129513] percpu: Embedded 53 pages/cpu s178408 r8192 d30488 u262144
[    0.132139] pcpu-alloc: s178408 r8192 d30488 u262144 alloc=1*2097152
[    0.134679] pcpu-alloc: [0] 0 1 2 3 4 5 6 7 
[    0.136341] Hyper-V: PV spinlocks enabled
[    0.137917] PV qspinlock hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.140833] Built 1 zonelists, mobility grouping on.  Total pages: 4127749
[    0.143636] Kernel command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.151440] Dentry cache hash table entries: 2097152 (order: 12, 16777216 bytes, linear)
[    0.155808] Inode-cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.159017] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.184685] Memory: 4126096K/16775804K available (18449K kernel code, 2647K rwdata, 3952K rodata, 1536K init, 2448K bss, 392692K reserved, 0K cma-reserved)
[    0.190358] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
[    0.192969] ftrace: allocating 51788 entries in 203 pages
[    0.201434] ftrace: allocated 203 pages with 5 groups
[    0.204349] Dynamic Preempt: none
[    0.205846] rcu: Preemptible hierarchical RCU implementation.
[    0.208162] rcu: 	RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=8.
[    0.210799] 	Trampoline variant of Tasks RCU enabled.
[    0.212756] 	Rude variant of Tasks RCU enabled.
[    0.214541] 	Tracing variant of Tasks RCU enabled.
[    0.216404] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.219393] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=8
[    0.225278] Using NULL legacy PIC
[    0.226573] NR_IRQS: 16640, nr_irqs: 488, preallocated irqs: 0
[    0.229131] random: crng init done (trusting CPU's manufacturer)
[    0.231548] Console: colour dummy device 80x25
[    0.233276] ACPI: Core revision 20211217
[    0.234931] Failed to register legacy timer interrupt
[    0.236944] APIC: Switch to symmetric I/O mode setup
[    0.238947] Hyper-V: enabling crash_kexec_post_notifiers
[    0.241016] Hyper-V: Using IPI hypercalls
[    0.242591] Hyper-V: Using enlightened APIC (xapic mode)
[    0.242680] clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    0.248870] Calibrating delay loop (skipped), value calculated using timer frequency.. 7600.01 BogoMIPS (lpj=38000080)
[    0.253092] pid_max: default: 32768 minimum: 301
[    0.254926] LSM: Security Framework initializing
[    0.256750] Mount-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.258867] Mountpoint-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.258867] x86/cpu: User Mode Instruction Prevention (UMIP) activated
[    0.258867] Last level iTLB entries: 4KB 1024, 2MB 1024, 4MB 512
[    0.258867] Last level dTLB entries: 4KB 2048, 2MB 2048, 4MB 1024, 1GB 0
[    0.258867] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.258867] Spectre V2 : Mitigation: Retpolines
[    0.258867] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
[    0.258867] Spectre V2 : mitigation: Enabling conditional Indirect Branch Prediction Barrier
[    0.258867] Spectre V2 : User space: Mitigation: STIBP via prctl
[    0.258867] Speculative Store Bypass: Mitigation: Speculative Store Bypass disabled via prctl
[    0.258867] Freeing SMP alternatives memory: 56K
[    0.258867] smpboot: CPU0: AMD Ryzen 9 3900X 12-Core Processor (family: 0x17, model: 0x71, stepping: 0x0)
[    0.258867] cblist_init_generic: Setting adjustable number of callback queues.
[    0.258867] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.258867] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.258895] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.261292] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[    0.263817] ... version:                0
[    0.265391] ... bit width:              48
[    0.267068] ... generic registers:      6
[    0.268634] ... value mask:             0000ffffffffffff
[    0.268871] ... max period:             00007fffffffffff
[    0.270991] ... fixed-purpose events:   0
[    0.272571] ... event mask:             000000000000003f
[    0.274695] rcu: Hierarchical SRCU implementation.
[    0.276947] smp: Bringing up secondary CPUs ...
[    0.278794] x86: Booting SMP configuration:
[    0.278872] .... node  #0, CPUs:      #1 #2 #3 #4 #5 #6 #7
[    0.279525] smp: Brought up 1 node, 8 CPUs
[    0.282814] smpboot: Max logical packages: 1
[    0.284479] smpboot: Total of 8 processors activated (60800.12 BogoMIPS)
[    0.298895] node 0 deferred pages initialised in 10ms
[    0.300921] devtmpfs: initialized
[    0.300921] x86/mm: Memory block size: 128MB
[    0.302426] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.308889] futex hash table entries: 2048 (order: 5, 131072 bytes, linear)
[    0.312151] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.314571] thermal_sys: Registered thermal governor 'step_wise'
[    0.314572] thermal_sys: Registered thermal governor 'user_space'
[    0.316961] cpuidle: using governor menu
[    0.318916] PCI: Fatal: No config space access function found
[    0.322206] kprobes: kprobe jump-optimization is enabled. All kprobes are optimized if possible.
[    0.322206] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[    0.322206] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[    0.328925] raid6: skipped pq benchmark and selected avx2x4
[    0.331164] raid6: using avx2x2 recovery algorithm
[    0.331164] ACPI: Added _OSI(Module Device)
[    0.331164] ACPI: Added _OSI(Processor Device)
[    0.332457] ACPI: Added _OSI(3.0 _SCP Extensions)
[    0.334283] ACPI: Added _OSI(Processor Aggregator Device)
[    0.336463] ACPI: Added _OSI(Linux-Dell-Video)
[    0.338283] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[    0.348871] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)
[    0.355075] ACPI: 1 ACPI AML tables successfully acquired and loaded
[    0.358946] ACPI: Interpreter enabled
[    0.360583] ACPI: PM: (supports S0 S5)
[    0.362198] ACPI: Using IOAPIC for interrupt routing
[    0.364304] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
[    0.368017] ACPI: Enabled 1 GPEs in block 00 to 0F
[    0.369481] iommu: Default domain type: Translated 
[    0.371449] iommu: DMA domain TLB invalidation policy: lazy mode 
[    0.373937] SCSI subsystem initialized
[    0.375541] ACPI: bus type USB registered
[    0.377164] usbcore: registered new interface driver usbfs
[    0.378875] usbcore: registered new interface driver hub
[    0.380985] usbcore: registered new device driver usb
[    0.383023] hv_vmbus: Vmbus version:5.2
[    0.383023] PCI: Using ACPI for IRQ routing
[    0.383023] PCI: System does not support PCI
[    0.389034] clocksource: Switched to clocksource tsc-early
[    0.389075] hv_vmbus: Unknown GUID: c376c1c3-d276-48d2-90a9-c04748072c60
[    0.394146] hv_vmbus: Unknown GUID: 6e382d18-3336-4f4b-acc4-2b7703d4df4a
[    0.396909] hv_vmbus: Unknown GUID: dde9cbc0-5060-4436-9448-ea1254a5d177
[    0.399744] VFS: Disk quotas dquot_6.6.0
[    0.401370] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.404186] FS-Cache: Loaded
[    0.405386] pnp: PnP ACPI init
[    0.406693] pnp: PnP ACPI: found 3 devices
[    0.412166] NET: Registered PF_INET protocol family
[    0.414416] IP idents hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.418515] tcp_listen_portaddr_hash hash table entries: 8192 (order: 5, 131072 bytes, linear)
[    0.422058] TCP established hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.425602] TCP bind hash table entries: 65536 (order: 8, 1048576 bytes, linear)
[    0.428661] TCP: Hash tables configured (established 131072 bind 65536)
[    0.431375] UDP hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.434579] UDP-Lite hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.437587] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.440120] RPC: Registered named UNIX socket transport module.
[    0.442979] RPC: Registered udp transport module.
[    0.445120] RPC: Registered tcp transport module.
[    0.447250] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.449989] PCI: CLS 0 bytes, default 64
[    0.451619] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[    0.451654] Trying to unpack rootfs image as initramfs...
[    0.454256] software IO TLB: mapped [mem 0x00000000f4000000-0x00000000f8000000] (64MB)
[    0.456463] Freeing initrd memory: 364K
[    0.541510] kvm: no hardware support for 'kvm_intel'
[    0.543867] SVM: TSC scaling supported
[    0.545319] kvm: Nested Virtualization enabled
[    0.547040] SVM: kvm: Nested Paging enabled
[    0.548653] SVM: kvm: Hyper-V enlightened NPT TLB flush enabled
[    0.550967] SVM: kvm: Hyper-V Direct TLB Flush enabled
[    0.552946] SVM: Virtual VMLOAD VMSAVE supported
[    0.618969] Initialise system trusted keyrings
[    0.620900] workingset: timestamp_bits=46 max_order=22 bucket_order=0
[    0.624053] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.626726] NFS: Registering the id_resolver key type
[    0.628690] Key type id_resolver registered
[    0.630376] Key type id_legacy registered
[    0.631915] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.634537] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    0.637515] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[    0.640546] Key type cifs.idmap registered
[    0.642255] fuse: init (API version 7.36)
[    0.643973] SGI XFS with ACLs, security attributes, realtime, scrub, repair, quota, no debug enabled
[    0.647888] 9p: Installing v9fs 9p2000 file system support
[    0.650100] ceph: loaded (mds proto 32)
[    0.653965] NET: Registered PF_ALG protocol family
[    0.655832] xor: automatically using best checksumming function   avx       
[    0.658591] Key type asymmetric registered
[    0.660227] Asymmetric key parser 'x509' registered
[    0.662151] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[    0.665489] hv_vmbus: registering driver hv_pci
[    0.667566] hv_pci b440727e-7525-4d9c-a556-d52029b00086: PCI VMBus probing: Using version 0x10004
[    0.671953] hv_pci b440727e-7525-4d9c-a556-d52029b00086: PCI host bridge to bus 7525:00
[    0.675135] pci_bus 7525:00: root bus resource [mem 0x9ffe00000-0x9ffe02fff window]
[    0.678177] pci_bus 7525:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.682285] pci 7525:00:00.0: [1af4:1043] type 00 class 0x010000
[    0.686012] pci 7525:00:00.0: reg 0x10: [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.689489] pci 7525:00:00.0: reg 0x18: [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.693005] pci 7525:00:00.0: reg 0x20: [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.698805] pci_bus 7525:00: busn_res: [bus 00-ff] end is updated to 00
[    0.701529] pci 7525:00:00.0: BAR 0: assigned [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.705034] pci 7525:00:00.0: BAR 2: assigned [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.708415] pci 7525:00:00.0: BAR 4: assigned [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.712037] hv_pci 121abb12-7ab2-45ff-b4ee-e85a1067c860: PCI VMBus probing: Using version 0x10004
[    0.716192] hv_pci 121abb12-7ab2-45ff-b4ee-e85a1067c860: PCI host bridge to bus 7ab2:00
[    0.719504] pci_bus 7ab2:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.723020] pci 7ab2:00:00.0: [1414:008e] type 00 class 0x030200
[    0.729607] pci_bus 7ab2:00: busn_res: [bus 00-ff] end is updated to 00
[    0.732348] hv_pci 0c573a50-ca5d-42a9-9657-3920a455151c: PCI VMBus probing: Using version 0x10004
[    0.736748] hv_pci 0c573a50-ca5d-42a9-9657-3920a455151c: PCI host bridge to bus ca5d:00
[    0.739875] pci_bus ca5d:00: root bus resource [mem 0x9ffe04000-0x9ffe06fff window]
[    0.742859] pci_bus ca5d:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.746939] pci ca5d:00:00.0: [1af4:1049] type 00 class 0x010000
[    0.750206] pci ca5d:00:00.0: reg 0x10: [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.753516] pci ca5d:00:00.0: reg 0x18: [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.756826] pci ca5d:00:00.0: reg 0x20: [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.763185] pci_bus ca5d:00: busn_res: [bus 00-ff] end is updated to 00
[    0.765793] pci ca5d:00:00.0: BAR 0: assigned [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.769223] pci ca5d:00:00.0: BAR 2: assigned [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.772634] pci ca5d:00:00.0: BAR 4: assigned [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.784382] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.787110] 00:00: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    0.790429] 00:01: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[    0.829682] Non-volatile memory driver v1.3
[    0.831440] printk: console [hvc0] enabled
[    0.833112] printk: bootconsole [uart8250] disabled
[    0.836997] brd: module loaded
[    0.838058] loop: module loaded
[    0.838265] hv_vmbus: registering driver hv_storvsc
[    0.838832] wireguard: WireGuard 1.0.0 loaded. See www.wireguard.com for information.
[    0.839306] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
[    0.839681] tun: Universal TUN/TAP device driver, 1.6
[    0.839972] PPP generic driver version 2.4.2
[    0.840236] scsi host0: storvsc_host_t
[    0.840302] PPP BSD Compression module registered
[    0.840692] PPP Deflate Compression module registered
[    0.841134] PPP MPPE Compression module registered
[    0.841392] NET: Registered PF_PPPOX protocol family
[    0.841654] usbcore: registered new interface driver cdc_ether
[    0.841957] usbcore: registered new interface driver cdc_ncm
[    0.842276] hv_vmbus: registering driver hv_netvsc
[    0.842639] VFIO - User Level meta-driver version: 0.3
[    0.843061] usbcore: registered new interface driver cdc_acm
[    0.843378] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[    0.843756] usbcore: registered new interface driver ch341
[    0.843966] usbserial: USB Serial support registered for ch341-uart
[    0.844287] usbcore: registered new interface driver cp210x
[    0.844545] usbserial: USB Serial support registered for cp210x
[    0.844853] usbcore: registered new interface driver ftdi_sio
[    0.845182] usbserial: USB Serial support registered for FTDI USB Serial Device
[    0.845673] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.846016] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 1
[    0.846374] vhci_hcd: created sysfs vhci_hcd.0
[    0.846742] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.18
[    0.847077] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.847418] usb usb1: Product: USB/IP Virtual Host Controller
[    0.847660] usb usb1: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 vhci_hcd
[    0.847995] usb usb1: SerialNumber: vhci_hcd.0
[    0.848335] hub 1-0:1.0: USB hub found
[    0.848536] hub 1-0:1.0: 8 ports detected
[    0.848976] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.849254] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 2
[    0.849621] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[    0.850102] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.18
[    0.850427] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.850718] usb usb2: Product: USB/IP Virtual Host Controller
[    0.850961] usb usb2: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 vhci_hcd
[    0.851300] usb usb2: SerialNumber: vhci_hcd.0
[    0.851614] hub 2-0:1.0: USB hub found
[    0.851810] hub 2-0:1.0: 8 ports detected
[    0.852249] hv_vmbus: registering driver hyperv_keyboard
[    0.852593] rtc_cmos 00:02: RTC can wake from S4
[    0.854483] rtc_cmos 00:02: registered as rtc0
[    0.854995] rtc_cmos 00:02: setting system clock to 2022-06-01T17:39:04 UTC (1654105144)
[    0.855309] rtc_cmos 00:02: alarms up to one month, 114 bytes nvram
[    0.855718] device-mapper: ioctl: 4.46.0-ioctl (2022-02-22) initialised: dm-devel@redhat.com
[    0.856172] device-mapper: raid: Loading target version 1.15.1
[    0.856511] usbcore: registered new interface driver usbhid
[    0.856703] usbhid: USB HID core driver
[    0.856901] hv_utils: Registering HyperV Utility Driver
[    0.857113] hv_vmbus: registering driver hv_utils
[    0.857333] hv_vmbus: registering driver hv_balloon
[    0.857338] hv_utils: cannot register PTP clock: 0
[    0.857607] drop_monitor: Initializing network drop monitor service
[    0.858067] hv_utils: TimeSync IC version 4.0
[    0.858073] hv_balloon: Using Dynamic Memory protocol version 2.0
[    0.858248] Mirror/redirect action on
[    0.859029] Free page reporting enabled
[    0.859197] hv_balloon: Cold memory discard hint enabled
[    0.859770] IPVS: Registered protocols (TCP, UDP)
[    0.860029] IPVS: Connection hash table configured (size=4096, memory=64Kbytes)
[    0.860395] IPVS: ipvs loaded.
[    0.860546] IPVS: [rr] scheduler registered.
[    0.860743] IPVS: [wrr] scheduler registered.
[    0.860937] IPVS: [sh] scheduler registered.
[    0.861159] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    0.861418] ipt_CLUSTERIP: ClusterIP Version 0.8 loaded successfully
[    0.861666] Initializing XFRM netlink socket
[    0.861903] NET: Registered PF_INET6 protocol family
[    0.862439] Segment Routing with IPv6
[    0.862619] In-situ OAM (IOAM) with IPv6
[    0.862791] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    0.863092] NET: Registered PF_PACKET protocol family
[    0.863332] Bridge firewalling registered
[    0.863488] 8021q: 802.1Q VLAN Support v1.8
[    0.863653] sctp: Hash tables configured (bind 256/256)
[    0.863885] 9pnet: Installing 9P2000 support
[    0.875420] Key type dns_resolver registered
[    0.875693] Key type ceph registered
[    0.875979] libceph: loaded (mon/osd proto 15/24)
[    0.876260] NET: Registered PF_VSOCK protocol family
[    0.876540] hv_vmbus: registering driver hv_sock
[    0.876769] IPI shorthand broadcast: enabled
[    0.876968] sched_clock: Marking stable (856497151, 19750700)->(930661400, -54413549)
[    0.877527] registered taskstats version 1
[    0.878008] Loading compiled-in X.509 certificates
[    0.878392] Btrfs loaded, crc32c=crc32c-generic, zoned=no, fsverity=no
[    0.883871] Freeing unused kernel image (initmem) memory: 1536K
[    0.958961] Write protecting the kernel read-only data: 24576k
[    0.959743] Freeing unused kernel image (text/rodata gap) memory: 2028K
[    0.960146] Freeing unused kernel image (rodata/data gap) memory: 144K
[    0.960406] Run /init as init process
[    0.960549]   with arguments:
[    0.960690]     /init
[    0.960790]   with environment:
[    0.960931]     HOME=/
[    0.961046]     TERM=linux
[    0.963320] scsi 0:0:0:0: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    0.964110] sd 0:0:0:0: Attached scsi generic sg0 type 0
[    0.964747] sd 0:0:0:0: [sda] 641944 512-byte logical blocks: (329 MB/313 MiB)
[    0.965293] sd 0:0:0:0: [sda] Write Protect is on
[    0.965554] sd 0:0:0:0: [sda] Mode Sense: 0f 00 80 00
[    0.965967] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[    1.459424] EXT4-fs (sda): mounted filesystem without journal. Quota mode: none.
[    1.677905] hv_pci 75e234e6-9a41-4c1d-8ac8-5d395d071dd2: PCI VMBus probing: Using version 0x10004
[    1.678919] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    1.679926] hv_pci 75e234e6-9a41-4c1d-8ac8-5d395d071dd2: PCI host bridge to bus 9a41:00
[    1.680478] pci_bus 9a41:00: root bus resource [mem 0xa00000000-0xc00001fff window]
[    1.680783] pci_bus 9a41:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.682091] pci 9a41:00:00.0: [1af4:105a] type 00 class 0x088000
[    1.684295] pci 9a41:00:00.0: reg 0x10: [mem 0xc00000000-0xc00000fff 64bit]
[    1.686271] pci 9a41:00:00.0: reg 0x18: [mem 0xc00001000-0xc00001fff 64bit]
[    1.688288] pci 9a41:00:00.0: reg 0x20: [mem 0xa00000000-0xbffffffff 64bit]
[    1.693245] pci_bus 9a41:00: busn_res: [bus 00-ff] end is updated to 00
[    1.693513] pci 9a41:00:00.0: BAR 4: assigned [mem 0xa00000000-0xbffffffff 64bit]
[    1.695391] pci 9a41:00:00.0: BAR 0: assigned [mem 0xc00000000-0xc00000fff 64bit]
[    1.697251] pci 9a41:00:00.0: BAR 2: assigned [mem 0xc00001000-0xc00001fff 64bit]
[    1.712810] virtiofs virtio2: Cache len: 0x200000000 @ 0xa00000000
[    1.713702] clocksource: Switched to clocksource tsc
[    1.739139] sd 0:0:0:0: [sda] Attached SCSI disk
[    1.778098] memmap_init_zone_device initialised 2097152 pages in 10ms
[    1.779673] WSL2: SetEphemeralPortRange is a no-op : range (0, 0)
[    1.848936] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    2.479025] scsi 0:0:0:1: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.479872] sd 0:0:0:1: Attached scsi generic sg1 type 0
[    2.480323] sd 0:0:0:1: [sdb] 2097160 512-byte logical blocks: (1.07 GB/1.00 GiB)
[    2.480417] scsi 0:0:0:2: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.480787] sd 0:0:0:1: [sdb] 4096-byte physical blocks
[    2.481485] sd 0:0:0:2: Attached scsi generic sg2 type 0
[    2.481508] sd 0:0:0:1: [sdb] Write Protect is off
[    2.482052] sd 0:0:0:2: [sdc] 536870912 512-byte logical blocks: (275 GB/256 GiB)
[    2.482106] sd 0:0:0:1: [sdb] Mode Sense: 0f 00 00 00
[    2.482522] sd 0:0:0:2: [sdc] 4096-byte physical blocks
[    2.482915] sd 0:0:0:1: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.483103] sd 0:0:0:2: [sdc] Write Protect is off
[    2.483857] sd 0:0:0:2: [sdc] Mode Sense: 0f 00 00 00
[    2.484274] sd 0:0:0:2: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.485716] sd 0:0:0:1: [sdb] Attached SCSI disk
[    2.491559] sd 0:0:0:2: [sdc] Attached SCSI disk
[    2.500504] EXT4-fs (sdc): recovery complete
[    2.501459] EXT4-fs (sdc): mounted filesystem with ordered data mode. Quota mode: none.
[    2.522816] Adding 1048576k swap on /dev/sdb.  Priority:-2 extents:1 across:1048576k 
[    2.681998] hv_pci 218ee01d-fcab-4f07-9ea0-57e00b7600be: PCI VMBus probing: Using version 0x10004
[    2.683056] 9pnet_virtio: no channels available for device drvfs
[    2.683289] hv_pci 218ee01d-fcab-4f07-9ea0-57e00b7600be: PCI host bridge to bus fcab:00
[    2.683349] init: (1) WARNING: mount: waiting for virtio device...
[    2.683645] pci_bus fcab:00: root bus resource [mem 0x9ffe08000-0x9ffe0afff window]
[    2.684167] pci_bus fcab:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.685517] pci fcab:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.686817] pci fcab:00:00.0: reg 0x10: [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.687677] pci fcab:00:00.0: reg 0x18: [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.688539] pci fcab:00:00.0: reg 0x20: [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.692528] pci_bus fcab:00: busn_res: [bus 00-ff] end is updated to 00
[    2.692830] pci fcab:00:00.0: BAR 0: assigned [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.693631] pci fcab:00:00.0: BAR 2: assigned [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.694374] pci fcab:00:00.0: BAR 4: assigned [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.788379] hv_pci 5767d560-6512-42aa-bddc-89eca93e4c84: PCI VMBus probing: Using version 0x10004
[    2.789471] 9pnet_virtio: no channels available for device drvfs
[    2.789751] hv_pci 5767d560-6512-42aa-bddc-89eca93e4c84: PCI host bridge to bus 6512:00
[    2.789774] init: (1) WARNING: mount: waiting for virtio device...
[    2.790068] pci_bus 6512:00: root bus resource [mem 0x9ffe0c000-0x9ffe0efff window]
[    2.790613] pci_bus 6512:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.791858] pci 6512:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.792992] pci 6512:00:00.0: reg 0x10: [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.793834] pci 6512:00:00.0: reg 0x18: [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.794694] pci 6512:00:00.0: reg 0x20: [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.798621] pci_bus 6512:00: busn_res: [bus 00-ff] end is updated to 00
[    2.798961] pci 6512:00:00.0: BAR 0: assigned [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.799695] pci 6512:00:00.0: BAR 2: assigned [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.800416] pci 6512:00:00.0: BAR 4: assigned [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.895193] hv_pci 4fae7a25-5e7f-42d1-8a8f-7e1eb4128529: PCI VMBus probing: Using version 0x10004
[    2.896654] hv_pci 4fae7a25-5e7f-42d1-8a8f-7e1eb4128529: PCI host bridge to bus 5e7f:00
[    2.897036] pci_bus 5e7f:00: root bus resource [mem 0x9ffe10000-0x9ffe12fff window]
[    2.897405] pci_bus 5e7f:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.898729] pci 5e7f:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.900002] pci 5e7f:00:00.0: reg 0x10: [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.900885] pci 5e7f:00:00.0: reg 0x18: [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.901753] pci 5e7f:00:00.0: reg 0x20: [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    2.905797] pci_bus 5e7f:00: busn_res: [bus 00-ff] end is updated to 00
[    2.906134] pci 5e7f:00:00.0: BAR 0: assigned [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.906894] pci 5e7f:00:00.0: BAR 2: assigned [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.907627] pci 5e7f:00:00.0: BAR 4: assigned [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    3.077268] hv_pci 98cd7659-96ca-4b6a-95f7-0896075bc081: PCI VMBus probing: Using version 0x10004
[    3.078351] 9pnet_virtio: no channels available for device drvfs
[    3.078666] init: (1) WARNING: mount: waiting for virtio device...
[    3.078865] hv_pci 98cd7659-96ca-4b6a-95f7-0896075bc081: PCI host bridge to bus 96ca:00
[    3.079411] pci_bus 96ca:00: root bus resource [mem 0x9ffe14000-0x9ffe16fff window]
[    3.079774] pci_bus 96ca:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.081309] pci 96ca:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.082647] pci 96ca:00:00.0: reg 0x10: [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.083650] pci 96ca:00:00.0: reg 0x18: [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.084634] pci 96ca:00:00.0: reg 0x20: [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.088677] pci_bus 96ca:00: busn_res: [bus 00-ff] end is updated to 00
[    3.089026] pci 96ca:00:00.0: BAR 0: assigned [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.089905] pci 96ca:00:00.0: BAR 2: assigned [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.090676] pci 96ca:00:00.0: BAR 4: assigned [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.183923] hv_pci d00b62d9-165b-4f27-8533-5d0402fb00d8: PCI VMBus probing: Using version 0x10004
[    3.185457] hv_pci d00b62d9-165b-4f27-8533-5d0402fb00d8: PCI host bridge to bus 165b:00
[    3.185861] pci_bus 165b:00: root bus resource [mem 0x9ffe18000-0x9ffe1afff window]
[    3.185908] 9pnet_virtio: no channels available for device drvfs
[    3.186186] pci_bus 165b:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.186580] init: (1) WARNING: mount: waiting for virtio device...
[    3.187888] pci 165b:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.189081] pci 165b:00:00.0: reg 0x10: [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.189964] pci 165b:00:00.0: reg 0x18: [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.190841] pci 165b:00:00.0: reg 0x20: [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.194800] pci_bus 165b:00: busn_res: [bus 00-ff] end is updated to 00
[    3.195067] pci 165b:00:00.0: BAR 0: assigned [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.195787] pci 165b:00:00.0: BAR 2: assigned [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.196517] pci 165b:00:00.0: BAR 4: assigned [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.292120] hv_pci ff437ee8-6a13-4119-800a-411d24b930e4: PCI VMBus probing: Using version 0x10004
[    3.293643] hv_pci ff437ee8-6a13-4119-800a-411d24b930e4: PCI host bridge to bus 6a13:00
[    3.294135] pci_bus 6a13:00: root bus resource [mem 0x9ffe1c000-0x9ffe1efff window]
[    3.294500] pci_bus 6a13:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.295857] pci 6a13:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.297136] pci 6a13:00:00.0: reg 0x10: [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.298009] pci 6a13:00:00.0: reg 0x18: [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.298981] pci 6a13:00:00.0: reg 0x20: [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[    3.303144] pci_bus 6a13:00: busn_res: [bus 00-ff] end is updated to 00
[    3.303421] pci 6a13:00:00.0: BAR 0: assigned [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.304141] pci 6a13:00:00.0: BAR 2: assigned [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.304851] pci 6a13:00:00.0: BAR 4: assigned [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[   49.723597] hv_balloon: Max. dynamic memory size: 16384 MB

[-- Attachment #3: bad.log --]
[-- Type: text/plain, Size: 34554 bytes --]

# cat /sys/kernel/debug/swiotlb/io_tlb_nslabs
32768

# dmesg
[    0.000000] Linux version 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 (nathan@dev-arch.thelio-3990X) (gcc (GCC) 12.1.0, GNU ld (GNU Binutils) 2.38) #1 SMP PREEMPT_DYNAMIC Wed Jun 1 10:41:21 MST 2022
[    0.000000] Command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 1776
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000e0fff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000001fffff] ACPI data
[    0.000000] BIOS-e820: [mem 0x0000000000200000-0x00000000f7ffffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000100000000-0x0000000407ffffff] usable
[    0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '115200')
[    0.000000] printk: bootconsole [uart8250] enabled
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI not present or invalid.
[    0.000000] Hypervisor detected: Microsoft Hyper-V
[    0.000000] Hyper-V: privilege flags low 0xae7f, high 0x3b8030, hints 0xc2c, misc 0xe0bed7b6
[    0.000000] Hyper-V: Host Build 10.0.22000.708-0-0
[    0.000000] Hyper-V: Nested features: 0x4a0000
[    0.000000] Hyper-V: LAPIC Timer Frequency: 0x1e8480
[    0.000000] Hyper-V: Using hypercall for remote TLB flush
[    0.000000] clocksource: hyperv_clocksource_tsc_page: mask: 0xffffffffffffffff max_cycles: 0x24e6a1710, max_idle_ns: 440795202120 ns
[    0.000003] tsc: Detected 3800.008 MHz processor
[    0.001844] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.004500] e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.006752] last_pfn = 0x408000 max_arch_pfn = 0x400000000
[    0.008928] x86/PAT: Configuration [0-7]: WB  WC  UC- UC  WB  WP  UC- WT  
[    0.011617] last_pfn = 0xf8000 max_arch_pfn = 0x400000000
[    0.013721] Using GB pages for direct mapping
[    0.015504] RAMDISK: [mem 0x0371f000-0x03779fff]
[    0.017288] ACPI: Early table checksum verification disabled
[    0.019511] ACPI: RSDP 0x00000000000E0000 000024 (v02 VRTUAL)
[    0.021806] ACPI: XSDT 0x0000000000100000 000044 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.025255] ACPI: FACP 0x0000000000101000 000114 (v06 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.028644] ACPI: DSDT 0x00000000001011B8 01E184 (v02 MSFTVM DSDT01   00000001 MSFT 05000000)
[    0.032074] ACPI: FACS 0x0000000000101114 000040
[    0.033876] ACPI: OEM0 0x0000000000101154 000064 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.037335] ACPI: SRAT 0x000000000011F33C 000330 (v02 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.040839] ACPI: APIC 0x000000000011F66C 000088 (v04 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.044205] ACPI: Reserving FACP table memory at [mem 0x101000-0x101113]
[    0.046856] ACPI: Reserving DSDT table memory at [mem 0x1011b8-0x11f33b]
[    0.049526] ACPI: Reserving FACS table memory at [mem 0x101114-0x101153]
[    0.052323] ACPI: Reserving OEM0 table memory at [mem 0x101154-0x1011b7]
[    0.054916] ACPI: Reserving SRAT table memory at [mem 0x11f33c-0x11f66b]
[    0.057563] ACPI: Reserving APIC table memory at [mem 0x11f66c-0x11f6f3]
[    0.060644] Zone ranges:
[    0.061621]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.064031]   DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
[    0.066551]   Normal   [mem 0x0000000100000000-0x0000000407ffffff]
[    0.069096]   Device   empty
[    0.070236] Movable zone start for each node
[    0.071880] Early memory node ranges
[    0.073323]   node   0: [mem 0x0000000000001000-0x000000000009ffff]
[    0.075736]   node   0: [mem 0x0000000000200000-0x00000000f7ffffff]
[    0.078260]   node   0: [mem 0x0000000100000000-0x0000000407ffffff]
[    0.080698] Initmem setup node 0 [mem 0x0000000000001000-0x0000000407ffffff]
[    0.083706] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.083724] On node 0, zone DMA: 352 pages in unavailable ranges
[    0.095850] ACPI: LAPIC_NMI (acpi_id[0x01] dfl dfl lint[0x1])
[    0.100817] IOAPIC[0]: apic_id 8, version 17, address 0xfec00000, GSI 0-23
[    0.103601] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[    0.106156] ACPI: Using ACPI (MADT) for SMP configuration information
[    0.108743] smpboot: Allowing 8 CPUs, 0 hotplug CPUs
[    0.110810] [mem 0xf8000000-0xffffffff] available for PCI devices
[    0.113193] Booting paravirtualized kernel on Hyper-V
[    0.115221] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.124086] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:8 nr_node_ids:1
[    0.127620] percpu: Embedded 53 pages/cpu s178408 r8192 d30488 u262144
[    0.130204] pcpu-alloc: s178408 r8192 d30488 u262144 alloc=1*2097152
[    0.132746] pcpu-alloc: [0] 0 1 2 3 4 5 6 7 
[    0.134452] Hyper-V: PV spinlocks enabled
[    0.136082] PV qspinlock hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.138923] Built 1 zonelists, mobility grouping on.  Total pages: 4127749
[    0.141669] Kernel command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.149809] Dentry cache hash table entries: 2097152 (order: 12, 16777216 bytes, linear)
[    0.154232] Inode-cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.157400] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.182296] Memory: 4126096K/16775804K available (18449K kernel code, 2647K rwdata, 3952K rodata, 1536K init, 2448K bss, 392692K reserved, 0K cma-reserved)
[    0.188084] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
[    0.190824] ftrace: allocating 51788 entries in 203 pages
[    0.199397] ftrace: allocated 203 pages with 5 groups
[    0.202320] Dynamic Preempt: none
[    0.203777] rcu: Preemptible hierarchical RCU implementation.
[    0.206055] rcu: 	RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=8.
[    0.208807] 	Trampoline variant of Tasks RCU enabled.
[    0.210844] 	Rude variant of Tasks RCU enabled.
[    0.213292] 	Tracing variant of Tasks RCU enabled.
[    0.215445] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.218380] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=8
[    0.224306] Using NULL legacy PIC
[    0.225589] NR_IRQS: 16640, nr_irqs: 488, preallocated irqs: 0
[    0.228245] random: crng init done (trusting CPU's manufacturer)
[    0.230636] Console: colour dummy device 80x25
[    0.232438] ACPI: Core revision 20211217
[    0.234033] Failed to register legacy timer interrupt
[    0.236047] APIC: Switch to symmetric I/O mode setup
[    0.238014] Hyper-V: enabling crash_kexec_post_notifiers
[    0.240107] Hyper-V: Using IPI hypercalls
[    0.241666] Hyper-V: Using enlightened APIC (xapic mode)
[    0.241757] clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    0.247930] Calibrating delay loop (skipped), value calculated using timer frequency.. 7600.01 BogoMIPS (lpj=38000080)
[    0.252067] pid_max: default: 32768 minimum: 301
[    0.253895] LSM: Security Framework initializing
[    0.255751] Mount-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.257927] Mountpoint-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.257927] x86/cpu: User Mode Instruction Prevention (UMIP) activated
[    0.257927] Last level iTLB entries: 4KB 1024, 2MB 1024, 4MB 512
[    0.257927] Last level dTLB entries: 4KB 2048, 2MB 2048, 4MB 1024, 1GB 0
[    0.257927] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.257927] Spectre V2 : Mitigation: Retpolines
[    0.257927] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
[    0.257927] Spectre V2 : mitigation: Enabling conditional Indirect Branch Prediction Barrier
[    0.257927] Spectre V2 : User space: Mitigation: STIBP via prctl
[    0.257927] Speculative Store Bypass: Mitigation: Speculative Store Bypass disabled via prctl
[    0.257927] Freeing SMP alternatives memory: 56K
[    0.257927] smpboot: CPU0: AMD Ryzen 9 3900X 12-Core Processor (family: 0x17, model: 0x71, stepping: 0x0)
[    0.257927] cblist_init_generic: Setting adjustable number of callback queues.
[    0.257927] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.257927] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.257953] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.260344] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[    0.262870] ... version:                0
[    0.264433] ... bit width:              48
[    0.266024] ... generic registers:      6
[    0.267586] ... value mask:             0000ffffffffffff
[    0.267931] ... max period:             00007fffffffffff
[    0.269978] ... fixed-purpose events:   0
[    0.271549] ... event mask:             000000000000003f
[    0.273693] rcu: Hierarchical SRCU implementation.
[    0.275947] smp: Bringing up secondary CPUs ...
[    0.277746] x86: Booting SMP configuration:
[    0.277931] .... node  #0, CPUs:      #1 #2 #3 #4 #5 #6 #7
[    0.278598] smp: Brought up 1 node, 8 CPUs
[    0.281786] smpboot: Max logical packages: 1
[    0.283442] smpboot: Total of 8 processors activated (60800.12 BogoMIPS)
[    0.297948] node 0 deferred pages initialised in 10ms
[    0.300095] devtmpfs: initialized
[    0.300095] x86/mm: Memory block size: 128MB
[    0.301372] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.307950] futex hash table entries: 2048 (order: 5, 131072 bytes, linear)
[    0.311117] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.313590] thermal_sys: Registered thermal governor 'step_wise'
[    0.313591] thermal_sys: Registered thermal governor 'user_space'
[    0.315970] cpuidle: using governor menu
[    0.317983] PCI: Fatal: No config space access function found
[    0.321181] kprobes: kprobe jump-optimization is enabled. All kprobes are optimized if possible.
[    0.321181] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[    0.321181] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[    0.327982] raid6: skipped pq benchmark and selected avx2x4
[    0.330080] raid6: using avx2x2 recovery algorithm
[    0.331916] ACPI: Added _OSI(Module Device)
[    0.337945] ACPI: Added _OSI(Processor Device)
[    0.339664] ACPI: Added _OSI(3.0 _SCP Extensions)
[    0.341472] ACPI: Added _OSI(Processor Aggregator Device)
[    0.343581] ACPI: Added _OSI(Linux-Dell-Video)
[    0.345290] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[    0.347310] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)
[    0.351846] ACPI: 1 ACPI AML tables successfully acquired and loaded
[    0.354878] ACPI: Interpreter enabled
[    0.357948] ACPI: PM: (supports S0 S5)
[    0.359386] ACPI: Using IOAPIC for interrupt routing
[    0.361295] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
[    0.364875] ACPI: Enabled 1 GPEs in block 00 to 0F
[    0.367281] iommu: Default domain type: Translated 
[    0.367930] iommu: DMA domain TLB invalidation policy: lazy mode 
[    0.370342] SCSI subsystem initialized
[    0.371819] ACPI: bus type USB registered
[    0.373384] usbcore: registered new interface driver usbfs
[    0.375508] usbcore: registered new interface driver hub
[    0.377556] usbcore: registered new device driver usb
[    0.378007] hv_vmbus: Vmbus version:5.2
[    0.379525] PCI: Using ACPI for IRQ routing
[    0.381148] PCI: System does not support PCI
[    0.382985] hv_vmbus: Unknown GUID: c376c1c3-d276-48d2-90a9-c04748072c60
[    0.385656] hv_vmbus: Unknown GUID: 6e382d18-3336-4f4b-acc4-2b7703d4df4a
[    0.385656] hv_vmbus: Unknown GUID: dde9cbc0-5060-4436-9448-ea1254a5d177
[    0.385656] clocksource: Switched to clocksource tsc-early
[    0.395132] VFS: Disk quotas dquot_6.6.0
[    0.398629] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.401503] FS-Cache: Loaded
[    0.402695] pnp: PnP ACPI init
[    0.403992] pnp: PnP ACPI: found 3 devices
[    0.409671] NET: Registered PF_INET protocol family
[    0.411938] IP idents hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.416026] tcp_listen_portaddr_hash hash table entries: 8192 (order: 5, 131072 bytes, linear)
[    0.419575] TCP established hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.423230] TCP bind hash table entries: 65536 (order: 8, 1048576 bytes, linear)
[    0.426347] TCP: Hash tables configured (established 131072 bind 65536)
[    0.429190] UDP hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.432209] UDP-Lite hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.435648] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.438375] RPC: Registered named UNIX socket transport module.
[    0.440789] RPC: Registered udp transport module.
[    0.442671] RPC: Registered tcp transport module.
[    0.444673] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.447332] PCI: CLS 0 bytes, default 64
[    0.448993] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[    0.449028] Trying to unpack rootfs image as initramfs...
[    0.451710] software IO TLB: mapped [mem 0x00000000f4000000-0x00000000f8000000] (64MB)
[    0.454079] Freeing initrd memory: 364K
[    0.541430] kvm: no hardware support for 'kvm_intel'
[    0.543753] SVM: TSC scaling supported
[    0.545214] kvm: Nested Virtualization enabled
[    0.546939] SVM: kvm: Nested Paging enabled
[    0.548655] SVM: kvm: Hyper-V enlightened NPT TLB flush enabled
[    0.550982] SVM: kvm: Hyper-V Direct TLB Flush enabled
[    0.553055] SVM: Virtual VMLOAD VMSAVE supported
[    0.619230] Initialise system trusted keyrings
[    0.621148] workingset: timestamp_bits=46 max_order=22 bucket_order=0
[    0.624304] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.626917] NFS: Registering the id_resolver key type
[    0.628911] Key type id_resolver registered
[    0.630622] Key type id_legacy registered
[    0.632252] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.635096] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    0.638073] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[    0.641200] Key type cifs.idmap registered
[    0.642865] fuse: init (API version 7.36)
[    0.644622] SGI XFS with ACLs, security attributes, realtime, scrub, repair, quota, no debug enabled
[    0.648593] 9p: Installing v9fs 9p2000 file system support
[    0.650987] ceph: loaded (mds proto 32)
[    0.654860] NET: Registered PF_ALG protocol family
[    0.656711] xor: automatically using best checksumming function   avx       
[    0.659472] Key type asymmetric registered
[    0.661072] Asymmetric key parser 'x509' registered
[    0.662976] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[    0.666333] hv_vmbus: registering driver hv_pci
[    0.668465] hv_pci a154a52e-df93-4a32-a470-37362af9092a: PCI VMBus probing: Using version 0x10004
[    0.672862] hv_pci a154a52e-df93-4a32-a470-37362af9092a: PCI host bridge to bus df93:00
[    0.675963] pci_bus df93:00: root bus resource [mem 0x9ffe00000-0x9ffe02fff window]
[    0.678965] pci_bus df93:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.683016] pci df93:00:00.0: [1af4:1043] type 00 class 0x010000
[    0.686425] pci df93:00:00.0: reg 0x10: [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.689851] pci df93:00:00.0: reg 0x18: [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.693249] pci df93:00:00.0: reg 0x20: [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.698971] pci_bus df93:00: busn_res: [bus 00-ff] end is updated to 00
[    0.701554] pci df93:00:00.0: BAR 0: assigned [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.704894] pci df93:00:00.0: BAR 2: assigned [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.708243] pci df93:00:00.0: BAR 4: assigned [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.711877] hv_pci ca66d0fe-4477-439b-9d67-02d7bd2dcb05: PCI VMBus probing: Using version 0x10004
[    0.716001] hv_pci ca66d0fe-4477-439b-9d67-02d7bd2dcb05: PCI host bridge to bus 4477:00
[    0.719136] pci_bus 4477:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.722586] pci 4477:00:00.0: [1414:008e] type 00 class 0x030200
[    0.729016] pci_bus 4477:00: busn_res: [bus 00-ff] end is updated to 00
[    0.731822] hv_pci c42c9658-a709-40bd-8d72-5ee9b78e28ca: PCI VMBus probing: Using version 0x10004
[    0.736240] hv_pci c42c9658-a709-40bd-8d72-5ee9b78e28ca: PCI host bridge to bus a709:00
[    0.739381] pci_bus a709:00: root bus resource [mem 0x9ffe04000-0x9ffe06fff window]
[    0.742368] pci_bus a709:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.746437] pci a709:00:00.0: [1af4:1049] type 00 class 0x010000
[    0.749663] pci a709:00:00.0: reg 0x10: [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.752975] pci a709:00:00.0: reg 0x18: [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.756273] pci a709:00:00.0: reg 0x20: [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.762929] pci_bus a709:00: busn_res: [bus 00-ff] end is updated to 00
[    0.765585] pci a709:00:00.0: BAR 0: assigned [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.769014] pci a709:00:00.0: BAR 2: assigned [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.772436] pci a709:00:00.0: BAR 4: assigned [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.784024] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.786788] 00:00: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    0.790004] 00:01: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[    0.828478] Non-volatile memory driver v1.3
[    0.830180] printk: console [hvc0] enabled
[    0.831804] printk: bootconsole [uart8250] disabled
[    0.835700] brd: module loaded
[    0.836692] loop: module loaded
[    0.836890] hv_vmbus: registering driver hv_storvsc
[    0.837466] wireguard: WireGuard 1.0.0 loaded. See www.wireguard.com for information.
[    0.837853] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
[    0.838217] scsi host0: storvsc_host_t
[    0.838399] tun: Universal TUN/TAP device driver, 1.6
[    0.838812] PPP generic driver version 2.4.2
[    0.839159] PPP BSD Compression module registered
[    0.839395] PPP Deflate Compression module registered
[    0.839781] PPP MPPE Compression module registered
[    0.840046] NET: Registered PF_PPPOX protocol family
[    0.840326] usbcore: registered new interface driver cdc_ether
[    0.840687] usbcore: registered new interface driver cdc_ncm
[    0.841009] hv_vmbus: registering driver hv_netvsc
[    0.841331] VFIO - User Level meta-driver version: 0.3
[    0.841707] usbcore: registered new interface driver cdc_acm
[    0.841999] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[    0.842346] usbcore: registered new interface driver ch341
[    0.842613] usbserial: USB Serial support registered for ch341-uart
[    0.842907] usbcore: registered new interface driver cp210x
[    0.843226] usbserial: USB Serial support registered for cp210x
[    0.843574] usbcore: registered new interface driver ftdi_sio
[    0.843874] usbserial: USB Serial support registered for FTDI USB Serial Device
[    0.844325] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.844630] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 1
[    0.844968] vhci_hcd: created sysfs vhci_hcd.0
[    0.845394] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.18
[    0.845749] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.846033] usb usb1: Product: USB/IP Virtual Host Controller
[    0.846274] usb usb1: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 vhci_hcd
[    0.846606] usb usb1: SerialNumber: vhci_hcd.0
[    0.846887] hub 1-0:1.0: USB hub found
[    0.847077] hub 1-0:1.0: 8 ports detected
[    0.847565] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.847828] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 2
[    0.848246] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[    0.848690] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.18
[    0.848997] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.849279] usb usb2: Product: USB/IP Virtual Host Controller
[    0.849523] usb usb2: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 vhci_hcd
[    0.849855] usb usb2: SerialNumber: vhci_hcd.0
[    0.850138] hub 2-0:1.0: USB hub found
[    0.850333] hub 2-0:1.0: 8 ports detected
[    0.850772] hv_vmbus: registering driver hyperv_keyboard
[    0.851119] rtc_cmos 00:02: RTC can wake from S4
[    0.853017] rtc_cmos 00:02: registered as rtc0
[    0.853536] rtc_cmos 00:02: setting system clock to 2022-06-01T17:41:59 UTC (1654105319)
[    0.853854] rtc_cmos 00:02: alarms up to one month, 114 bytes nvram
[    0.854249] device-mapper: ioctl: 4.46.0-ioctl (2022-02-22) initialised: dm-devel@redhat.com
[    0.854710] device-mapper: raid: Loading target version 1.15.1
[    0.855003] usbcore: registered new interface driver usbhid
[    0.855198] usbhid: USB HID core driver
[    0.855394] hv_utils: Registering HyperV Utility Driver
[    0.855608] hv_vmbus: registering driver hv_utils
[    0.855910] hv_vmbus: registering driver hv_balloon
[    0.855914] hv_utils: cannot register PTP clock: 0
[    0.856165] drop_monitor: Initializing network drop monitor service
[    0.856597] hv_balloon: Using Dynamic Memory protocol version 2.0
[    0.856611] hv_utils: TimeSync IC version 4.0
[    0.856742] Mirror/redirect action on
[    0.857542] Free page reporting enabled
[    0.857744] hv_balloon: Cold memory discard hint enabled
[    0.858304] IPVS: Registered protocols (TCP, UDP)
[    0.858534] IPVS: Connection hash table configured (size=4096, memory=64Kbytes)
[    0.858872] IPVS: ipvs loaded.
[    0.859018] IPVS: [rr] scheduler registered.
[    0.859213] IPVS: [wrr] scheduler registered.
[    0.859405] IPVS: [sh] scheduler registered.
[    0.859622] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    0.860047] ipt_CLUSTERIP: ClusterIP Version 0.8 loaded successfully
[    0.860293] Initializing XFRM netlink socket
[    0.860522] NET: Registered PF_INET6 protocol family
[    0.861019] Segment Routing with IPv6
[    0.861193] In-situ OAM (IOAM) with IPv6
[    0.861362] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    0.861655] NET: Registered PF_PACKET protocol family
[    0.861875] Bridge firewalling registered
[    0.862024] 8021q: 802.1Q VLAN Support v1.8
[    0.862189] sctp: Hash tables configured (bind 256/256)
[    0.862419] 9pnet: Installing 9P2000 support
[    0.874428] Key type dns_resolver registered
[    0.874663] Key type ceph registered
[    0.874921] libceph: loaded (mon/osd proto 15/24)
[    0.875208] NET: Registered PF_VSOCK protocol family
[    0.875419] hv_vmbus: registering driver hv_sock
[    0.875644] IPI shorthand broadcast: enabled
[    0.875840] sched_clock: Marking stable (855501109, 19696300)->(934890300, -59692891)
[    0.876403] registered taskstats version 1
[    0.876928] Loading compiled-in X.509 certificates
[    0.877333] Btrfs loaded, crc32c=crc32c-generic, zoned=no, fsverity=no
[    0.882685] Freeing unused kernel image (initmem) memory: 1536K
[    0.918057] Write protecting the kernel read-only data: 24576k
[    0.918975] Freeing unused kernel image (text/rodata gap) memory: 2028K
[    0.919393] Freeing unused kernel image (rodata/data gap) memory: 144K
[    0.919654] Run /init as init process
[    0.919798]   with arguments:
[    0.919940]     /init
[    0.920047]   with environment:
[    0.920190]     HOME=/
[    0.920286]     TERM=linux
[    0.922620] scsi 0:0:0:0: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    0.923252] sd 0:0:0:0: Attached scsi generic sg0 type 0
[    0.923893] sd 0:0:0:0: [sda] 641944 512-byte logical blocks: (329 MB/313 MiB)
[    0.924490] sd 0:0:0:0: [sda] Write Protect is on
[    0.924760] sd 0:0:0:0: [sda] Mode Sense: 0f 00 80 00
[    0.925199] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[    1.538410] EXT4-fs (sda): mounted filesystem without journal. Quota mode: none.
[    1.640080] hv_pci 88309164-1127-4233-9560-6e0cad455d8f: PCI VMBus probing: Using version 0x10004
[    1.642187] hv_pci 88309164-1127-4233-9560-6e0cad455d8f: PCI host bridge to bus 1127:00
[    1.642548] pci_bus 1127:00: root bus resource [mem 0xa00000000-0xc00001fff window]
[    1.642895] pci_bus 1127:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.644287] pci 1127:00:00.0: [1af4:105a] type 00 class 0x088000
[    1.647194] pci 1127:00:00.0: reg 0x10: [mem 0xc00000000-0xc00000fff 64bit]
[    1.649501] pci 1127:00:00.0: reg 0x18: [mem 0xc00001000-0xc00001fff 64bit]
[    1.651514] pci 1127:00:00.0: reg 0x20: [mem 0xa00000000-0xbffffffff 64bit]
[    1.656603] pci_bus 1127:00: busn_res: [bus 00-ff] end is updated to 00
[    1.656902] pci 1127:00:00.0: BAR 4: assigned [mem 0xa00000000-0xbffffffff 64bit]
[    1.658754] pci 1127:00:00.0: BAR 0: assigned [mem 0xc00000000-0xc00000fff 64bit]
[    1.660797] pci 1127:00:00.0: BAR 2: assigned [mem 0xc00001000-0xc00001fff 64bit]
[    1.676734] virtiofs virtio2: Cache len: 0x200000000 @ 0xa00000000
[    1.687964] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    1.688537] clocksource: Switched to clocksource tsc
[    1.718131] sd 0:0:0:0: [sda] Attached SCSI disk
[    1.737024] memmap_init_zone_device initialised 2097152 pages in 10ms
[    1.738457] WSL2: SetEphemeralPortRange is a no-op : range (0, 0)
[    1.847973] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    2.418129] scsi 0:0:0:1: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.418887] sd 0:0:0:1: Attached scsi generic sg1 type 0
[    2.419446] scsi 0:0:0:2: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.419498] sd 0:0:0:1: [sdb] 2097160 512-byte logical blocks: (1.07 GB/1.00 GiB)
[    2.420146] sd 0:0:0:2: Attached scsi generic sg2 type 0
[    2.420236] sd 0:0:0:1: [sdb] 4096-byte physical blocks
[    2.420789] sd 0:0:0:2: [sdc] 536870912 512-byte logical blocks: (275 GB/256 GiB)
[    2.420849] sd 0:0:0:1: [sdb] Write Protect is off
[    2.421225] sd 0:0:0:2: [sdc] 4096-byte physical blocks
[    2.421541] sd 0:0:0:1: [sdb] Mode Sense: 0f 00 00 00
[    2.421888] sd 0:0:0:2: [sdc] Write Protect is off
[    2.422260] sd 0:0:0:1: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.422392] sd 0:0:0:2: [sdc] Mode Sense: 0f 00 00 00
[    2.423302] sd 0:0:0:2: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.424840] sd 0:0:0:1: [sdb] Attached SCSI disk
[    2.426063] sd 0:0:0:2: [sdc] Attached SCSI disk
[    2.444484] EXT4-fs (sdc): recovery complete
[    2.445457] EXT4-fs (sdc): mounted filesystem with ordered data mode. Quota mode: none.
[    2.459372] Adding 1048576k swap on /dev/sdb.  Priority:-2 extents:1 across:1048576k 
[    2.649008] hv_pci aed388e8-de3a-45a5-bb0c-ee534e806689: PCI VMBus probing: Using version 0x10004
[    2.650439] hv_pci aed388e8-de3a-45a5-bb0c-ee534e806689: PCI host bridge to bus de3a:00
[    2.650756] pci_bus de3a:00: root bus resource [mem 0x9ffe08000-0x9ffe0afff window]
[    2.651045] pci_bus de3a:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.652320] pci de3a:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.653496] pci de3a:00:00.0: reg 0x10: [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.654363] pci de3a:00:00.0: reg 0x18: [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.655227] pci de3a:00:00.0: reg 0x20: [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.659234] pci_bus de3a:00: busn_res: [bus 00-ff] end is updated to 00
[    2.659501] pci de3a:00:00.0: BAR 0: assigned [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.660251] pci de3a:00:00.0: BAR 2: assigned [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.660989] pci de3a:00:00.0: BAR 4: assigned [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.663932] 9pnet_virtio: no channels available for device drvfs
[    2.664237] init: (1) WARNING: mount: waiting for virtio device...
[    2.770766] hv_pci 81d9a8d7-9fce-46b7-9ff9-b146da3089e4: PCI VMBus probing: Using version 0x10004
[    2.772061] hv_pci 81d9a8d7-9fce-46b7-9ff9-b146da3089e4: PCI host bridge to bus 9fce:00
[    2.772372] pci_bus 9fce:00: root bus resource [mem 0x9ffe0c000-0x9ffe0efff window]
[    2.772664] pci_bus 9fce:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.773910] pci 9fce:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.775050] pci 9fce:00:00.0: reg 0x10: [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.775911] pci 9fce:00:00.0: reg 0x18: [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.776761] pci 9fce:00:00.0: reg 0x20: [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.780694] pci_bus 9fce:00: busn_res: [bus 00-ff] end is updated to 00
[    2.780986] pci 9fce:00:00.0: BAR 0: assigned [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.781703] pci 9fce:00:00.0: BAR 2: assigned [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.781986] 9pnet_virtio: no channels available for device drvfs
[    2.782311] init: (1) WARNING: mount: waiting for virtio device...
[    2.782471] pci 9fce:00:00.0: BAR 4: assigned [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.898491] hv_pci 86858b54-a9ff-42c1-85be-12646bde6957: PCI VMBus probing: Using version 0x10004
[    2.899831] hv_pci 86858b54-a9ff-42c1-85be-12646bde6957: PCI host bridge to bus a9ff:00
[    2.900148] pci_bus a9ff:00: root bus resource [mem 0x9ffe10000-0x9ffe12fff window]
[    2.900437] pci_bus a9ff:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.901684] pci a9ff:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.902856] pci a9ff:00:00.0: reg 0x10: [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.903716] pci a9ff:00:00.0: reg 0x18: [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.904609] pci a9ff:00:00.0: reg 0x20: [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    2.908519] pci_bus a9ff:00: busn_res: [bus 00-ff] end is updated to 00
[    2.908842] pci a9ff:00:00.0: BAR 0: assigned [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.909600] pci a9ff:00:00.0: BAR 2: assigned [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.910335] pci a9ff:00:00.0: BAR 4: assigned [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    3.009967] hv_pci 14a6c250-2f5e-4544-972d-e4af992a128a: PCI VMBus probing: Using version 0x10004
[    3.011462] hv_pci 14a6c250-2f5e-4544-972d-e4af992a128a: PCI host bridge to bus 2f5e:00
[    3.011804] pci_bus 2f5e:00: root bus resource [mem 0x9ffe14000-0x9ffe16fff window]
[    3.012172] pci_bus 2f5e:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.013562] pci 2f5e:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.014756] pci 2f5e:00:00.0: reg 0x10: [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.015633] pci 2f5e:00:00.0: reg 0x18: [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.016516] pci 2f5e:00:00.0: reg 0x20: [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.020834] pci_bus 2f5e:00: busn_res: [bus 00-ff] end is updated to 00
[    3.021157] pci 2f5e:00:00.0: BAR 0: assigned [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.022095] pci 2f5e:00:00.0: BAR 2: assigned [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.022867] pci 2f5e:00:00.0: BAR 4: assigned [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.030227] 9pnet_virtio: no channels available for device drvfs
[    3.030578] init: (1) WARNING: mount: waiting for virtio device...
[    3.143192] hv_pci ed843176-e057-48d4-ab94-623a027b1629: PCI VMBus probing: Using version 0x10004
[    3.144600] hv_pci ed843176-e057-48d4-ab94-623a027b1629: PCI host bridge to bus e057:00
[    3.144927] pci_bus e057:00: root bus resource [mem 0x9ffe18000-0x9ffe1afff window]
[    3.145222] pci_bus e057:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.146529] pci e057:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.147766] pci e057:00:00.0: reg 0x10: [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.148685] pci e057:00:00.0: reg 0x18: [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.149556] pci e057:00:00.0: reg 0x20: [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.153686] pci_bus e057:00: busn_res: [bus 00-ff] end is updated to 00
[    3.154060] pci e057:00:00.0: BAR 0: assigned [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.154855] pci e057:00:00.0: BAR 2: assigned [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.155592] pci e057:00:00.0: BAR 4: assigned [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.188714] hv_pci c963c476-4546-43da-a32c-7e4ddeb55d93: PCI VMBus probing: Using version 0x10004
[    3.190328] hv_pci c963c476-4546-43da-a32c-7e4ddeb55d93: PCI host bridge to bus 4546:00
[    3.190732] pci_bus 4546:00: root bus resource [mem 0x9ffe1c000-0x9ffe1efff window]
[    3.191104] pci_bus 4546:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.192578] pci 4546:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.193870] pci 4546:00:00.0: reg 0x10: [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.194935] pci 4546:00:00.0: reg 0x18: [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.196022] pci 4546:00:00.0: reg 0x20: [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[    3.200503] pci_bus 4546:00: busn_res: [bus 00-ff] end is updated to 00
[    3.200855] pci 4546:00:00.0: BAR 0: assigned [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.201736] pci 4546:00:00.0: BAR 2: assigned [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.202501] pci 4546:00:00.0: BAR 4: assigned [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[   49.723721] hv_balloon: Max. dynamic memory size: 16384 MB

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:46         ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 17:46 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> Can you send me the full dmesg and the content of
> /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?

Sure thing, they are attached! If there is anything else I can provide
or test, I am more than happy to do so.

Cheers,
Nathan

[-- Attachment #2: good.log --]
[-- Type: text/plain, Size: 34692 bytes --]

# cat /sys/kernel/debug/swiotlb/io_tlb_nslabs
32768

# dmesg
[    0.000000] Linux version 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 (nathan@dev-arch.thelio-3990X) (gcc (GCC) 12.1.0, GNU ld (GNU Binutils) 2.38) #1 SMP PREEMPT_DYNAMIC Wed Jun 1 10:38:34 MST 2022
[    0.000000] Command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 1776
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000e0fff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000001fffff] ACPI data
[    0.000000] BIOS-e820: [mem 0x0000000000200000-0x00000000f7ffffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000100000000-0x0000000407ffffff] usable
[    0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '115200')
[    0.000000] printk: bootconsole [uart8250] enabled
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI not present or invalid.
[    0.000000] Hypervisor detected: Microsoft Hyper-V
[    0.000000] Hyper-V: privilege flags low 0xae7f, high 0x3b8030, hints 0xc2c, misc 0xe0bed7b6
[    0.000000] Hyper-V: Host Build 10.0.22000.708-0-0
[    0.000000] Hyper-V: Nested features: 0x4a0000
[    0.000000] Hyper-V: LAPIC Timer Frequency: 0x1e8480
[    0.000000] Hyper-V: Using hypercall for remote TLB flush
[    0.000000] clocksource: hyperv_clocksource_tsc_page: mask: 0xffffffffffffffff max_cycles: 0x24e6a1710, max_idle_ns: 440795202120 ns
[    0.000005] tsc: Detected 3800.008 MHz processor
[    0.001901] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.004593] e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.006806] last_pfn = 0x408000 max_arch_pfn = 0x400000000
[    0.009042] x86/PAT: Configuration [0-7]: WB  WC  UC- UC  WB  WP  UC- WT  
[    0.011760] last_pfn = 0xf8000 max_arch_pfn = 0x400000000
[    0.013959] Using GB pages for direct mapping
[    0.015749] RAMDISK: [mem 0x0371f000-0x03779fff]
[    0.017616] ACPI: Early table checksum verification disabled
[    0.019854] ACPI: RSDP 0x00000000000E0000 000024 (v02 VRTUAL)
[    0.022162] ACPI: XSDT 0x0000000000100000 000044 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.025624] ACPI: FACP 0x0000000000101000 000114 (v06 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.029022] ACPI: DSDT 0x00000000001011B8 01E184 (v02 MSFTVM DSDT01   00000001 MSFT 05000000)
[    0.032413] ACPI: FACS 0x0000000000101114 000040
[    0.034280] ACPI: OEM0 0x0000000000101154 000064 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.037699] ACPI: SRAT 0x000000000011F33C 000330 (v02 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.041089] ACPI: APIC 0x000000000011F66C 000088 (v04 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.044475] ACPI: Reserving FACP table memory at [mem 0x101000-0x101113]
[    0.047159] ACPI: Reserving DSDT table memory at [mem 0x1011b8-0x11f33b]
[    0.049905] ACPI: Reserving FACS table memory at [mem 0x101114-0x101153]
[    0.052693] ACPI: Reserving OEM0 table memory at [mem 0x101154-0x1011b7]
[    0.055404] ACPI: Reserving SRAT table memory at [mem 0x11f33c-0x11f66b]
[    0.058040] ACPI: Reserving APIC table memory at [mem 0x11f66c-0x11f6f3]
[    0.061078] Zone ranges:
[    0.062074]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.066106]   DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
[    0.068763]   Normal   [mem 0x0000000100000000-0x0000000407ffffff]
[    0.071235]   Device   empty
[    0.072384] Movable zone start for each node
[    0.074058] Early memory node ranges
[    0.075515]   node   0: [mem 0x0000000000001000-0x000000000009ffff]
[    0.077979]   node   0: [mem 0x0000000000200000-0x00000000f7ffffff]
[    0.080483]   node   0: [mem 0x0000000100000000-0x0000000407ffffff]
[    0.082980] Initmem setup node 0 [mem 0x0000000000001000-0x0000000407ffffff]
[    0.085954] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.085972] On node 0, zone DMA: 352 pages in unavailable ranges
[    0.098043] ACPI: LAPIC_NMI (acpi_id[0x01] dfl dfl lint[0x1])
[    0.102995] IOAPIC[0]: apic_id 8, version 17, address 0xfec00000, GSI 0-23
[    0.105726] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[    0.108349] ACPI: Using ACPI (MADT) for SMP configuration information
[    0.110909] smpboot: Allowing 8 CPUs, 0 hotplug CPUs
[    0.112902] [mem 0xf8000000-0xffffffff] available for PCI devices
[    0.115315] Booting paravirtualized kernel on Hyper-V
[    0.117347] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.126056] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:8 nr_node_ids:1
[    0.129513] percpu: Embedded 53 pages/cpu s178408 r8192 d30488 u262144
[    0.132139] pcpu-alloc: s178408 r8192 d30488 u262144 alloc=1*2097152
[    0.134679] pcpu-alloc: [0] 0 1 2 3 4 5 6 7 
[    0.136341] Hyper-V: PV spinlocks enabled
[    0.137917] PV qspinlock hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.140833] Built 1 zonelists, mobility grouping on.  Total pages: 4127749
[    0.143636] Kernel command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.151440] Dentry cache hash table entries: 2097152 (order: 12, 16777216 bytes, linear)
[    0.155808] Inode-cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.159017] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.184685] Memory: 4126096K/16775804K available (18449K kernel code, 2647K rwdata, 3952K rodata, 1536K init, 2448K bss, 392692K reserved, 0K cma-reserved)
[    0.190358] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
[    0.192969] ftrace: allocating 51788 entries in 203 pages
[    0.201434] ftrace: allocated 203 pages with 5 groups
[    0.204349] Dynamic Preempt: none
[    0.205846] rcu: Preemptible hierarchical RCU implementation.
[    0.208162] rcu: 	RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=8.
[    0.210799] 	Trampoline variant of Tasks RCU enabled.
[    0.212756] 	Rude variant of Tasks RCU enabled.
[    0.214541] 	Tracing variant of Tasks RCU enabled.
[    0.216404] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.219393] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=8
[    0.225278] Using NULL legacy PIC
[    0.226573] NR_IRQS: 16640, nr_irqs: 488, preallocated irqs: 0
[    0.229131] random: crng init done (trusting CPU's manufacturer)
[    0.231548] Console: colour dummy device 80x25
[    0.233276] ACPI: Core revision 20211217
[    0.234931] Failed to register legacy timer interrupt
[    0.236944] APIC: Switch to symmetric I/O mode setup
[    0.238947] Hyper-V: enabling crash_kexec_post_notifiers
[    0.241016] Hyper-V: Using IPI hypercalls
[    0.242591] Hyper-V: Using enlightened APIC (xapic mode)
[    0.242680] clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    0.248870] Calibrating delay loop (skipped), value calculated using timer frequency.. 7600.01 BogoMIPS (lpj=38000080)
[    0.253092] pid_max: default: 32768 minimum: 301
[    0.254926] LSM: Security Framework initializing
[    0.256750] Mount-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.258867] Mountpoint-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.258867] x86/cpu: User Mode Instruction Prevention (UMIP) activated
[    0.258867] Last level iTLB entries: 4KB 1024, 2MB 1024, 4MB 512
[    0.258867] Last level dTLB entries: 4KB 2048, 2MB 2048, 4MB 1024, 1GB 0
[    0.258867] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.258867] Spectre V2 : Mitigation: Retpolines
[    0.258867] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
[    0.258867] Spectre V2 : mitigation: Enabling conditional Indirect Branch Prediction Barrier
[    0.258867] Spectre V2 : User space: Mitigation: STIBP via prctl
[    0.258867] Speculative Store Bypass: Mitigation: Speculative Store Bypass disabled via prctl
[    0.258867] Freeing SMP alternatives memory: 56K
[    0.258867] smpboot: CPU0: AMD Ryzen 9 3900X 12-Core Processor (family: 0x17, model: 0x71, stepping: 0x0)
[    0.258867] cblist_init_generic: Setting adjustable number of callback queues.
[    0.258867] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.258867] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.258895] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.261292] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[    0.263817] ... version:                0
[    0.265391] ... bit width:              48
[    0.267068] ... generic registers:      6
[    0.268634] ... value mask:             0000ffffffffffff
[    0.268871] ... max period:             00007fffffffffff
[    0.270991] ... fixed-purpose events:   0
[    0.272571] ... event mask:             000000000000003f
[    0.274695] rcu: Hierarchical SRCU implementation.
[    0.276947] smp: Bringing up secondary CPUs ...
[    0.278794] x86: Booting SMP configuration:
[    0.278872] .... node  #0, CPUs:      #1 #2 #3 #4 #5 #6 #7
[    0.279525] smp: Brought up 1 node, 8 CPUs
[    0.282814] smpboot: Max logical packages: 1
[    0.284479] smpboot: Total of 8 processors activated (60800.12 BogoMIPS)
[    0.298895] node 0 deferred pages initialised in 10ms
[    0.300921] devtmpfs: initialized
[    0.300921] x86/mm: Memory block size: 128MB
[    0.302426] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.308889] futex hash table entries: 2048 (order: 5, 131072 bytes, linear)
[    0.312151] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.314571] thermal_sys: Registered thermal governor 'step_wise'
[    0.314572] thermal_sys: Registered thermal governor 'user_space'
[    0.316961] cpuidle: using governor menu
[    0.318916] PCI: Fatal: No config space access function found
[    0.322206] kprobes: kprobe jump-optimization is enabled. All kprobes are optimized if possible.
[    0.322206] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[    0.322206] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[    0.328925] raid6: skipped pq benchmark and selected avx2x4
[    0.331164] raid6: using avx2x2 recovery algorithm
[    0.331164] ACPI: Added _OSI(Module Device)
[    0.331164] ACPI: Added _OSI(Processor Device)
[    0.332457] ACPI: Added _OSI(3.0 _SCP Extensions)
[    0.334283] ACPI: Added _OSI(Processor Aggregator Device)
[    0.336463] ACPI: Added _OSI(Linux-Dell-Video)
[    0.338283] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[    0.348871] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)
[    0.355075] ACPI: 1 ACPI AML tables successfully acquired and loaded
[    0.358946] ACPI: Interpreter enabled
[    0.360583] ACPI: PM: (supports S0 S5)
[    0.362198] ACPI: Using IOAPIC for interrupt routing
[    0.364304] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
[    0.368017] ACPI: Enabled 1 GPEs in block 00 to 0F
[    0.369481] iommu: Default domain type: Translated 
[    0.371449] iommu: DMA domain TLB invalidation policy: lazy mode 
[    0.373937] SCSI subsystem initialized
[    0.375541] ACPI: bus type USB registered
[    0.377164] usbcore: registered new interface driver usbfs
[    0.378875] usbcore: registered new interface driver hub
[    0.380985] usbcore: registered new device driver usb
[    0.383023] hv_vmbus: Vmbus version:5.2
[    0.383023] PCI: Using ACPI for IRQ routing
[    0.383023] PCI: System does not support PCI
[    0.389034] clocksource: Switched to clocksource tsc-early
[    0.389075] hv_vmbus: Unknown GUID: c376c1c3-d276-48d2-90a9-c04748072c60
[    0.394146] hv_vmbus: Unknown GUID: 6e382d18-3336-4f4b-acc4-2b7703d4df4a
[    0.396909] hv_vmbus: Unknown GUID: dde9cbc0-5060-4436-9448-ea1254a5d177
[    0.399744] VFS: Disk quotas dquot_6.6.0
[    0.401370] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.404186] FS-Cache: Loaded
[    0.405386] pnp: PnP ACPI init
[    0.406693] pnp: PnP ACPI: found 3 devices
[    0.412166] NET: Registered PF_INET protocol family
[    0.414416] IP idents hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.418515] tcp_listen_portaddr_hash hash table entries: 8192 (order: 5, 131072 bytes, linear)
[    0.422058] TCP established hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.425602] TCP bind hash table entries: 65536 (order: 8, 1048576 bytes, linear)
[    0.428661] TCP: Hash tables configured (established 131072 bind 65536)
[    0.431375] UDP hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.434579] UDP-Lite hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.437587] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.440120] RPC: Registered named UNIX socket transport module.
[    0.442979] RPC: Registered udp transport module.
[    0.445120] RPC: Registered tcp transport module.
[    0.447250] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.449989] PCI: CLS 0 bytes, default 64
[    0.451619] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[    0.451654] Trying to unpack rootfs image as initramfs...
[    0.454256] software IO TLB: mapped [mem 0x00000000f4000000-0x00000000f8000000] (64MB)
[    0.456463] Freeing initrd memory: 364K
[    0.541510] kvm: no hardware support for 'kvm_intel'
[    0.543867] SVM: TSC scaling supported
[    0.545319] kvm: Nested Virtualization enabled
[    0.547040] SVM: kvm: Nested Paging enabled
[    0.548653] SVM: kvm: Hyper-V enlightened NPT TLB flush enabled
[    0.550967] SVM: kvm: Hyper-V Direct TLB Flush enabled
[    0.552946] SVM: Virtual VMLOAD VMSAVE supported
[    0.618969] Initialise system trusted keyrings
[    0.620900] workingset: timestamp_bits=46 max_order=22 bucket_order=0
[    0.624053] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.626726] NFS: Registering the id_resolver key type
[    0.628690] Key type id_resolver registered
[    0.630376] Key type id_legacy registered
[    0.631915] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.634537] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    0.637515] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[    0.640546] Key type cifs.idmap registered
[    0.642255] fuse: init (API version 7.36)
[    0.643973] SGI XFS with ACLs, security attributes, realtime, scrub, repair, quota, no debug enabled
[    0.647888] 9p: Installing v9fs 9p2000 file system support
[    0.650100] ceph: loaded (mds proto 32)
[    0.653965] NET: Registered PF_ALG protocol family
[    0.655832] xor: automatically using best checksumming function   avx       
[    0.658591] Key type asymmetric registered
[    0.660227] Asymmetric key parser 'x509' registered
[    0.662151] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[    0.665489] hv_vmbus: registering driver hv_pci
[    0.667566] hv_pci b440727e-7525-4d9c-a556-d52029b00086: PCI VMBus probing: Using version 0x10004
[    0.671953] hv_pci b440727e-7525-4d9c-a556-d52029b00086: PCI host bridge to bus 7525:00
[    0.675135] pci_bus 7525:00: root bus resource [mem 0x9ffe00000-0x9ffe02fff window]
[    0.678177] pci_bus 7525:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.682285] pci 7525:00:00.0: [1af4:1043] type 00 class 0x010000
[    0.686012] pci 7525:00:00.0: reg 0x10: [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.689489] pci 7525:00:00.0: reg 0x18: [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.693005] pci 7525:00:00.0: reg 0x20: [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.698805] pci_bus 7525:00: busn_res: [bus 00-ff] end is updated to 00
[    0.701529] pci 7525:00:00.0: BAR 0: assigned [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.705034] pci 7525:00:00.0: BAR 2: assigned [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.708415] pci 7525:00:00.0: BAR 4: assigned [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.712037] hv_pci 121abb12-7ab2-45ff-b4ee-e85a1067c860: PCI VMBus probing: Using version 0x10004
[    0.716192] hv_pci 121abb12-7ab2-45ff-b4ee-e85a1067c860: PCI host bridge to bus 7ab2:00
[    0.719504] pci_bus 7ab2:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.723020] pci 7ab2:00:00.0: [1414:008e] type 00 class 0x030200
[    0.729607] pci_bus 7ab2:00: busn_res: [bus 00-ff] end is updated to 00
[    0.732348] hv_pci 0c573a50-ca5d-42a9-9657-3920a455151c: PCI VMBus probing: Using version 0x10004
[    0.736748] hv_pci 0c573a50-ca5d-42a9-9657-3920a455151c: PCI host bridge to bus ca5d:00
[    0.739875] pci_bus ca5d:00: root bus resource [mem 0x9ffe04000-0x9ffe06fff window]
[    0.742859] pci_bus ca5d:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.746939] pci ca5d:00:00.0: [1af4:1049] type 00 class 0x010000
[    0.750206] pci ca5d:00:00.0: reg 0x10: [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.753516] pci ca5d:00:00.0: reg 0x18: [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.756826] pci ca5d:00:00.0: reg 0x20: [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.763185] pci_bus ca5d:00: busn_res: [bus 00-ff] end is updated to 00
[    0.765793] pci ca5d:00:00.0: BAR 0: assigned [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.769223] pci ca5d:00:00.0: BAR 2: assigned [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.772634] pci ca5d:00:00.0: BAR 4: assigned [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.784382] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.787110] 00:00: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    0.790429] 00:01: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[    0.829682] Non-volatile memory driver v1.3
[    0.831440] printk: console [hvc0] enabled
[    0.833112] printk: bootconsole [uart8250] disabled
[    0.836997] brd: module loaded
[    0.838058] loop: module loaded
[    0.838265] hv_vmbus: registering driver hv_storvsc
[    0.838832] wireguard: WireGuard 1.0.0 loaded. See www.wireguard.com for information.
[    0.839306] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
[    0.839681] tun: Universal TUN/TAP device driver, 1.6
[    0.839972] PPP generic driver version 2.4.2
[    0.840236] scsi host0: storvsc_host_t
[    0.840302] PPP BSD Compression module registered
[    0.840692] PPP Deflate Compression module registered
[    0.841134] PPP MPPE Compression module registered
[    0.841392] NET: Registered PF_PPPOX protocol family
[    0.841654] usbcore: registered new interface driver cdc_ether
[    0.841957] usbcore: registered new interface driver cdc_ncm
[    0.842276] hv_vmbus: registering driver hv_netvsc
[    0.842639] VFIO - User Level meta-driver version: 0.3
[    0.843061] usbcore: registered new interface driver cdc_acm
[    0.843378] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[    0.843756] usbcore: registered new interface driver ch341
[    0.843966] usbserial: USB Serial support registered for ch341-uart
[    0.844287] usbcore: registered new interface driver cp210x
[    0.844545] usbserial: USB Serial support registered for cp210x
[    0.844853] usbcore: registered new interface driver ftdi_sio
[    0.845182] usbserial: USB Serial support registered for FTDI USB Serial Device
[    0.845673] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.846016] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 1
[    0.846374] vhci_hcd: created sysfs vhci_hcd.0
[    0.846742] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.18
[    0.847077] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.847418] usb usb1: Product: USB/IP Virtual Host Controller
[    0.847660] usb usb1: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 vhci_hcd
[    0.847995] usb usb1: SerialNumber: vhci_hcd.0
[    0.848335] hub 1-0:1.0: USB hub found
[    0.848536] hub 1-0:1.0: 8 ports detected
[    0.848976] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.849254] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 2
[    0.849621] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[    0.850102] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.18
[    0.850427] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.850718] usb usb2: Product: USB/IP Virtual Host Controller
[    0.850961] usb usb2: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 vhci_hcd
[    0.851300] usb usb2: SerialNumber: vhci_hcd.0
[    0.851614] hub 2-0:1.0: USB hub found
[    0.851810] hub 2-0:1.0: 8 ports detected
[    0.852249] hv_vmbus: registering driver hyperv_keyboard
[    0.852593] rtc_cmos 00:02: RTC can wake from S4
[    0.854483] rtc_cmos 00:02: registered as rtc0
[    0.854995] rtc_cmos 00:02: setting system clock to 2022-06-01T17:39:04 UTC (1654105144)
[    0.855309] rtc_cmos 00:02: alarms up to one month, 114 bytes nvram
[    0.855718] device-mapper: ioctl: 4.46.0-ioctl (2022-02-22) initialised: dm-devel@redhat.com
[    0.856172] device-mapper: raid: Loading target version 1.15.1
[    0.856511] usbcore: registered new interface driver usbhid
[    0.856703] usbhid: USB HID core driver
[    0.856901] hv_utils: Registering HyperV Utility Driver
[    0.857113] hv_vmbus: registering driver hv_utils
[    0.857333] hv_vmbus: registering driver hv_balloon
[    0.857338] hv_utils: cannot register PTP clock: 0
[    0.857607] drop_monitor: Initializing network drop monitor service
[    0.858067] hv_utils: TimeSync IC version 4.0
[    0.858073] hv_balloon: Using Dynamic Memory protocol version 2.0
[    0.858248] Mirror/redirect action on
[    0.859029] Free page reporting enabled
[    0.859197] hv_balloon: Cold memory discard hint enabled
[    0.859770] IPVS: Registered protocols (TCP, UDP)
[    0.860029] IPVS: Connection hash table configured (size=4096, memory=64Kbytes)
[    0.860395] IPVS: ipvs loaded.
[    0.860546] IPVS: [rr] scheduler registered.
[    0.860743] IPVS: [wrr] scheduler registered.
[    0.860937] IPVS: [sh] scheduler registered.
[    0.861159] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    0.861418] ipt_CLUSTERIP: ClusterIP Version 0.8 loaded successfully
[    0.861666] Initializing XFRM netlink socket
[    0.861903] NET: Registered PF_INET6 protocol family
[    0.862439] Segment Routing with IPv6
[    0.862619] In-situ OAM (IOAM) with IPv6
[    0.862791] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    0.863092] NET: Registered PF_PACKET protocol family
[    0.863332] Bridge firewalling registered
[    0.863488] 8021q: 802.1Q VLAN Support v1.8
[    0.863653] sctp: Hash tables configured (bind 256/256)
[    0.863885] 9pnet: Installing 9P2000 support
[    0.875420] Key type dns_resolver registered
[    0.875693] Key type ceph registered
[    0.875979] libceph: loaded (mon/osd proto 15/24)
[    0.876260] NET: Registered PF_VSOCK protocol family
[    0.876540] hv_vmbus: registering driver hv_sock
[    0.876769] IPI shorthand broadcast: enabled
[    0.876968] sched_clock: Marking stable (856497151, 19750700)->(930661400, -54413549)
[    0.877527] registered taskstats version 1
[    0.878008] Loading compiled-in X.509 certificates
[    0.878392] Btrfs loaded, crc32c=crc32c-generic, zoned=no, fsverity=no
[    0.883871] Freeing unused kernel image (initmem) memory: 1536K
[    0.958961] Write protecting the kernel read-only data: 24576k
[    0.959743] Freeing unused kernel image (text/rodata gap) memory: 2028K
[    0.960146] Freeing unused kernel image (rodata/data gap) memory: 144K
[    0.960406] Run /init as init process
[    0.960549]   with arguments:
[    0.960690]     /init
[    0.960790]   with environment:
[    0.960931]     HOME=/
[    0.961046]     TERM=linux
[    0.963320] scsi 0:0:0:0: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    0.964110] sd 0:0:0:0: Attached scsi generic sg0 type 0
[    0.964747] sd 0:0:0:0: [sda] 641944 512-byte logical blocks: (329 MB/313 MiB)
[    0.965293] sd 0:0:0:0: [sda] Write Protect is on
[    0.965554] sd 0:0:0:0: [sda] Mode Sense: 0f 00 80 00
[    0.965967] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[    1.459424] EXT4-fs (sda): mounted filesystem without journal. Quota mode: none.
[    1.677905] hv_pci 75e234e6-9a41-4c1d-8ac8-5d395d071dd2: PCI VMBus probing: Using version 0x10004
[    1.678919] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    1.679926] hv_pci 75e234e6-9a41-4c1d-8ac8-5d395d071dd2: PCI host bridge to bus 9a41:00
[    1.680478] pci_bus 9a41:00: root bus resource [mem 0xa00000000-0xc00001fff window]
[    1.680783] pci_bus 9a41:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.682091] pci 9a41:00:00.0: [1af4:105a] type 00 class 0x088000
[    1.684295] pci 9a41:00:00.0: reg 0x10: [mem 0xc00000000-0xc00000fff 64bit]
[    1.686271] pci 9a41:00:00.0: reg 0x18: [mem 0xc00001000-0xc00001fff 64bit]
[    1.688288] pci 9a41:00:00.0: reg 0x20: [mem 0xa00000000-0xbffffffff 64bit]
[    1.693245] pci_bus 9a41:00: busn_res: [bus 00-ff] end is updated to 00
[    1.693513] pci 9a41:00:00.0: BAR 4: assigned [mem 0xa00000000-0xbffffffff 64bit]
[    1.695391] pci 9a41:00:00.0: BAR 0: assigned [mem 0xc00000000-0xc00000fff 64bit]
[    1.697251] pci 9a41:00:00.0: BAR 2: assigned [mem 0xc00001000-0xc00001fff 64bit]
[    1.712810] virtiofs virtio2: Cache len: 0x200000000 @ 0xa00000000
[    1.713702] clocksource: Switched to clocksource tsc
[    1.739139] sd 0:0:0:0: [sda] Attached SCSI disk
[    1.778098] memmap_init_zone_device initialised 2097152 pages in 10ms
[    1.779673] WSL2: SetEphemeralPortRange is a no-op : range (0, 0)
[    1.848936] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    2.479025] scsi 0:0:0:1: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.479872] sd 0:0:0:1: Attached scsi generic sg1 type 0
[    2.480323] sd 0:0:0:1: [sdb] 2097160 512-byte logical blocks: (1.07 GB/1.00 GiB)
[    2.480417] scsi 0:0:0:2: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.480787] sd 0:0:0:1: [sdb] 4096-byte physical blocks
[    2.481485] sd 0:0:0:2: Attached scsi generic sg2 type 0
[    2.481508] sd 0:0:0:1: [sdb] Write Protect is off
[    2.482052] sd 0:0:0:2: [sdc] 536870912 512-byte logical blocks: (275 GB/256 GiB)
[    2.482106] sd 0:0:0:1: [sdb] Mode Sense: 0f 00 00 00
[    2.482522] sd 0:0:0:2: [sdc] 4096-byte physical blocks
[    2.482915] sd 0:0:0:1: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.483103] sd 0:0:0:2: [sdc] Write Protect is off
[    2.483857] sd 0:0:0:2: [sdc] Mode Sense: 0f 00 00 00
[    2.484274] sd 0:0:0:2: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.485716] sd 0:0:0:1: [sdb] Attached SCSI disk
[    2.491559] sd 0:0:0:2: [sdc] Attached SCSI disk
[    2.500504] EXT4-fs (sdc): recovery complete
[    2.501459] EXT4-fs (sdc): mounted filesystem with ordered data mode. Quota mode: none.
[    2.522816] Adding 1048576k swap on /dev/sdb.  Priority:-2 extents:1 across:1048576k 
[    2.681998] hv_pci 218ee01d-fcab-4f07-9ea0-57e00b7600be: PCI VMBus probing: Using version 0x10004
[    2.683056] 9pnet_virtio: no channels available for device drvfs
[    2.683289] hv_pci 218ee01d-fcab-4f07-9ea0-57e00b7600be: PCI host bridge to bus fcab:00
[    2.683349] init: (1) WARNING: mount: waiting for virtio device...
[    2.683645] pci_bus fcab:00: root bus resource [mem 0x9ffe08000-0x9ffe0afff window]
[    2.684167] pci_bus fcab:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.685517] pci fcab:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.686817] pci fcab:00:00.0: reg 0x10: [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.687677] pci fcab:00:00.0: reg 0x18: [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.688539] pci fcab:00:00.0: reg 0x20: [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.692528] pci_bus fcab:00: busn_res: [bus 00-ff] end is updated to 00
[    2.692830] pci fcab:00:00.0: BAR 0: assigned [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.693631] pci fcab:00:00.0: BAR 2: assigned [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.694374] pci fcab:00:00.0: BAR 4: assigned [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.788379] hv_pci 5767d560-6512-42aa-bddc-89eca93e4c84: PCI VMBus probing: Using version 0x10004
[    2.789471] 9pnet_virtio: no channels available for device drvfs
[    2.789751] hv_pci 5767d560-6512-42aa-bddc-89eca93e4c84: PCI host bridge to bus 6512:00
[    2.789774] init: (1) WARNING: mount: waiting for virtio device...
[    2.790068] pci_bus 6512:00: root bus resource [mem 0x9ffe0c000-0x9ffe0efff window]
[    2.790613] pci_bus 6512:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.791858] pci 6512:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.792992] pci 6512:00:00.0: reg 0x10: [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.793834] pci 6512:00:00.0: reg 0x18: [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.794694] pci 6512:00:00.0: reg 0x20: [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.798621] pci_bus 6512:00: busn_res: [bus 00-ff] end is updated to 00
[    2.798961] pci 6512:00:00.0: BAR 0: assigned [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.799695] pci 6512:00:00.0: BAR 2: assigned [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.800416] pci 6512:00:00.0: BAR 4: assigned [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.895193] hv_pci 4fae7a25-5e7f-42d1-8a8f-7e1eb4128529: PCI VMBus probing: Using version 0x10004
[    2.896654] hv_pci 4fae7a25-5e7f-42d1-8a8f-7e1eb4128529: PCI host bridge to bus 5e7f:00
[    2.897036] pci_bus 5e7f:00: root bus resource [mem 0x9ffe10000-0x9ffe12fff window]
[    2.897405] pci_bus 5e7f:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.898729] pci 5e7f:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.900002] pci 5e7f:00:00.0: reg 0x10: [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.900885] pci 5e7f:00:00.0: reg 0x18: [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.901753] pci 5e7f:00:00.0: reg 0x20: [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    2.905797] pci_bus 5e7f:00: busn_res: [bus 00-ff] end is updated to 00
[    2.906134] pci 5e7f:00:00.0: BAR 0: assigned [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.906894] pci 5e7f:00:00.0: BAR 2: assigned [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.907627] pci 5e7f:00:00.0: BAR 4: assigned [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    3.077268] hv_pci 98cd7659-96ca-4b6a-95f7-0896075bc081: PCI VMBus probing: Using version 0x10004
[    3.078351] 9pnet_virtio: no channels available for device drvfs
[    3.078666] init: (1) WARNING: mount: waiting for virtio device...
[    3.078865] hv_pci 98cd7659-96ca-4b6a-95f7-0896075bc081: PCI host bridge to bus 96ca:00
[    3.079411] pci_bus 96ca:00: root bus resource [mem 0x9ffe14000-0x9ffe16fff window]
[    3.079774] pci_bus 96ca:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.081309] pci 96ca:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.082647] pci 96ca:00:00.0: reg 0x10: [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.083650] pci 96ca:00:00.0: reg 0x18: [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.084634] pci 96ca:00:00.0: reg 0x20: [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.088677] pci_bus 96ca:00: busn_res: [bus 00-ff] end is updated to 00
[    3.089026] pci 96ca:00:00.0: BAR 0: assigned [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.089905] pci 96ca:00:00.0: BAR 2: assigned [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.090676] pci 96ca:00:00.0: BAR 4: assigned [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.183923] hv_pci d00b62d9-165b-4f27-8533-5d0402fb00d8: PCI VMBus probing: Using version 0x10004
[    3.185457] hv_pci d00b62d9-165b-4f27-8533-5d0402fb00d8: PCI host bridge to bus 165b:00
[    3.185861] pci_bus 165b:00: root bus resource [mem 0x9ffe18000-0x9ffe1afff window]
[    3.185908] 9pnet_virtio: no channels available for device drvfs
[    3.186186] pci_bus 165b:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.186580] init: (1) WARNING: mount: waiting for virtio device...
[    3.187888] pci 165b:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.189081] pci 165b:00:00.0: reg 0x10: [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.189964] pci 165b:00:00.0: reg 0x18: [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.190841] pci 165b:00:00.0: reg 0x20: [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.194800] pci_bus 165b:00: busn_res: [bus 00-ff] end is updated to 00
[    3.195067] pci 165b:00:00.0: BAR 0: assigned [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.195787] pci 165b:00:00.0: BAR 2: assigned [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.196517] pci 165b:00:00.0: BAR 4: assigned [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.292120] hv_pci ff437ee8-6a13-4119-800a-411d24b930e4: PCI VMBus probing: Using version 0x10004
[    3.293643] hv_pci ff437ee8-6a13-4119-800a-411d24b930e4: PCI host bridge to bus 6a13:00
[    3.294135] pci_bus 6a13:00: root bus resource [mem 0x9ffe1c000-0x9ffe1efff window]
[    3.294500] pci_bus 6a13:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.295857] pci 6a13:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.297136] pci 6a13:00:00.0: reg 0x10: [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.298009] pci 6a13:00:00.0: reg 0x18: [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.298981] pci 6a13:00:00.0: reg 0x20: [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[    3.303144] pci_bus 6a13:00: busn_res: [bus 00-ff] end is updated to 00
[    3.303421] pci 6a13:00:00.0: BAR 0: assigned [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.304141] pci 6a13:00:00.0: BAR 2: assigned [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.304851] pci 6a13:00:00.0: BAR 4: assigned [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[   49.723597] hv_balloon: Max. dynamic memory size: 16384 MB

[-- Attachment #3: bad.log --]
[-- Type: text/plain, Size: 34554 bytes --]

# cat /sys/kernel/debug/swiotlb/io_tlb_nslabs
32768

# dmesg
[    0.000000] Linux version 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 (nathan@dev-arch.thelio-3990X) (gcc (GCC) 12.1.0, GNU ld (GNU Binutils) 2.38) #1 SMP PREEMPT_DYNAMIC Wed Jun 1 10:41:21 MST 2022
[    0.000000] Command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 1776
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000e0fff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000001fffff] ACPI data
[    0.000000] BIOS-e820: [mem 0x0000000000200000-0x00000000f7ffffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000100000000-0x0000000407ffffff] usable
[    0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '115200')
[    0.000000] printk: bootconsole [uart8250] enabled
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI not present or invalid.
[    0.000000] Hypervisor detected: Microsoft Hyper-V
[    0.000000] Hyper-V: privilege flags low 0xae7f, high 0x3b8030, hints 0xc2c, misc 0xe0bed7b6
[    0.000000] Hyper-V: Host Build 10.0.22000.708-0-0
[    0.000000] Hyper-V: Nested features: 0x4a0000
[    0.000000] Hyper-V: LAPIC Timer Frequency: 0x1e8480
[    0.000000] Hyper-V: Using hypercall for remote TLB flush
[    0.000000] clocksource: hyperv_clocksource_tsc_page: mask: 0xffffffffffffffff max_cycles: 0x24e6a1710, max_idle_ns: 440795202120 ns
[    0.000003] tsc: Detected 3800.008 MHz processor
[    0.001844] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.004500] e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.006752] last_pfn = 0x408000 max_arch_pfn = 0x400000000
[    0.008928] x86/PAT: Configuration [0-7]: WB  WC  UC- UC  WB  WP  UC- WT  
[    0.011617] last_pfn = 0xf8000 max_arch_pfn = 0x400000000
[    0.013721] Using GB pages for direct mapping
[    0.015504] RAMDISK: [mem 0x0371f000-0x03779fff]
[    0.017288] ACPI: Early table checksum verification disabled
[    0.019511] ACPI: RSDP 0x00000000000E0000 000024 (v02 VRTUAL)
[    0.021806] ACPI: XSDT 0x0000000000100000 000044 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.025255] ACPI: FACP 0x0000000000101000 000114 (v06 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.028644] ACPI: DSDT 0x00000000001011B8 01E184 (v02 MSFTVM DSDT01   00000001 MSFT 05000000)
[    0.032074] ACPI: FACS 0x0000000000101114 000040
[    0.033876] ACPI: OEM0 0x0000000000101154 000064 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.037335] ACPI: SRAT 0x000000000011F33C 000330 (v02 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.040839] ACPI: APIC 0x000000000011F66C 000088 (v04 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.044205] ACPI: Reserving FACP table memory at [mem 0x101000-0x101113]
[    0.046856] ACPI: Reserving DSDT table memory at [mem 0x1011b8-0x11f33b]
[    0.049526] ACPI: Reserving FACS table memory at [mem 0x101114-0x101153]
[    0.052323] ACPI: Reserving OEM0 table memory at [mem 0x101154-0x1011b7]
[    0.054916] ACPI: Reserving SRAT table memory at [mem 0x11f33c-0x11f66b]
[    0.057563] ACPI: Reserving APIC table memory at [mem 0x11f66c-0x11f6f3]
[    0.060644] Zone ranges:
[    0.061621]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.064031]   DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
[    0.066551]   Normal   [mem 0x0000000100000000-0x0000000407ffffff]
[    0.069096]   Device   empty
[    0.070236] Movable zone start for each node
[    0.071880] Early memory node ranges
[    0.073323]   node   0: [mem 0x0000000000001000-0x000000000009ffff]
[    0.075736]   node   0: [mem 0x0000000000200000-0x00000000f7ffffff]
[    0.078260]   node   0: [mem 0x0000000100000000-0x0000000407ffffff]
[    0.080698] Initmem setup node 0 [mem 0x0000000000001000-0x0000000407ffffff]
[    0.083706] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.083724] On node 0, zone DMA: 352 pages in unavailable ranges
[    0.095850] ACPI: LAPIC_NMI (acpi_id[0x01] dfl dfl lint[0x1])
[    0.100817] IOAPIC[0]: apic_id 8, version 17, address 0xfec00000, GSI 0-23
[    0.103601] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[    0.106156] ACPI: Using ACPI (MADT) for SMP configuration information
[    0.108743] smpboot: Allowing 8 CPUs, 0 hotplug CPUs
[    0.110810] [mem 0xf8000000-0xffffffff] available for PCI devices
[    0.113193] Booting paravirtualized kernel on Hyper-V
[    0.115221] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.124086] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:8 nr_node_ids:1
[    0.127620] percpu: Embedded 53 pages/cpu s178408 r8192 d30488 u262144
[    0.130204] pcpu-alloc: s178408 r8192 d30488 u262144 alloc=1*2097152
[    0.132746] pcpu-alloc: [0] 0 1 2 3 4 5 6 7 
[    0.134452] Hyper-V: PV spinlocks enabled
[    0.136082] PV qspinlock hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.138923] Built 1 zonelists, mobility grouping on.  Total pages: 4127749
[    0.141669] Kernel command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.149809] Dentry cache hash table entries: 2097152 (order: 12, 16777216 bytes, linear)
[    0.154232] Inode-cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.157400] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.182296] Memory: 4126096K/16775804K available (18449K kernel code, 2647K rwdata, 3952K rodata, 1536K init, 2448K bss, 392692K reserved, 0K cma-reserved)
[    0.188084] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
[    0.190824] ftrace: allocating 51788 entries in 203 pages
[    0.199397] ftrace: allocated 203 pages with 5 groups
[    0.202320] Dynamic Preempt: none
[    0.203777] rcu: Preemptible hierarchical RCU implementation.
[    0.206055] rcu: 	RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=8.
[    0.208807] 	Trampoline variant of Tasks RCU enabled.
[    0.210844] 	Rude variant of Tasks RCU enabled.
[    0.213292] 	Tracing variant of Tasks RCU enabled.
[    0.215445] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.218380] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=8
[    0.224306] Using NULL legacy PIC
[    0.225589] NR_IRQS: 16640, nr_irqs: 488, preallocated irqs: 0
[    0.228245] random: crng init done (trusting CPU's manufacturer)
[    0.230636] Console: colour dummy device 80x25
[    0.232438] ACPI: Core revision 20211217
[    0.234033] Failed to register legacy timer interrupt
[    0.236047] APIC: Switch to symmetric I/O mode setup
[    0.238014] Hyper-V: enabling crash_kexec_post_notifiers
[    0.240107] Hyper-V: Using IPI hypercalls
[    0.241666] Hyper-V: Using enlightened APIC (xapic mode)
[    0.241757] clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    0.247930] Calibrating delay loop (skipped), value calculated using timer frequency.. 7600.01 BogoMIPS (lpj=38000080)
[    0.252067] pid_max: default: 32768 minimum: 301
[    0.253895] LSM: Security Framework initializing
[    0.255751] Mount-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.257927] Mountpoint-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.257927] x86/cpu: User Mode Instruction Prevention (UMIP) activated
[    0.257927] Last level iTLB entries: 4KB 1024, 2MB 1024, 4MB 512
[    0.257927] Last level dTLB entries: 4KB 2048, 2MB 2048, 4MB 1024, 1GB 0
[    0.257927] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.257927] Spectre V2 : Mitigation: Retpolines
[    0.257927] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
[    0.257927] Spectre V2 : mitigation: Enabling conditional Indirect Branch Prediction Barrier
[    0.257927] Spectre V2 : User space: Mitigation: STIBP via prctl
[    0.257927] Speculative Store Bypass: Mitigation: Speculative Store Bypass disabled via prctl
[    0.257927] Freeing SMP alternatives memory: 56K
[    0.257927] smpboot: CPU0: AMD Ryzen 9 3900X 12-Core Processor (family: 0x17, model: 0x71, stepping: 0x0)
[    0.257927] cblist_init_generic: Setting adjustable number of callback queues.
[    0.257927] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.257927] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.257953] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.260344] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[    0.262870] ... version:                0
[    0.264433] ... bit width:              48
[    0.266024] ... generic registers:      6
[    0.267586] ... value mask:             0000ffffffffffff
[    0.267931] ... max period:             00007fffffffffff
[    0.269978] ... fixed-purpose events:   0
[    0.271549] ... event mask:             000000000000003f
[    0.273693] rcu: Hierarchical SRCU implementation.
[    0.275947] smp: Bringing up secondary CPUs ...
[    0.277746] x86: Booting SMP configuration:
[    0.277931] .... node  #0, CPUs:      #1 #2 #3 #4 #5 #6 #7
[    0.278598] smp: Brought up 1 node, 8 CPUs
[    0.281786] smpboot: Max logical packages: 1
[    0.283442] smpboot: Total of 8 processors activated (60800.12 BogoMIPS)
[    0.297948] node 0 deferred pages initialised in 10ms
[    0.300095] devtmpfs: initialized
[    0.300095] x86/mm: Memory block size: 128MB
[    0.301372] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.307950] futex hash table entries: 2048 (order: 5, 131072 bytes, linear)
[    0.311117] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.313590] thermal_sys: Registered thermal governor 'step_wise'
[    0.313591] thermal_sys: Registered thermal governor 'user_space'
[    0.315970] cpuidle: using governor menu
[    0.317983] PCI: Fatal: No config space access function found
[    0.321181] kprobes: kprobe jump-optimization is enabled. All kprobes are optimized if possible.
[    0.321181] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[    0.321181] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[    0.327982] raid6: skipped pq benchmark and selected avx2x4
[    0.330080] raid6: using avx2x2 recovery algorithm
[    0.331916] ACPI: Added _OSI(Module Device)
[    0.337945] ACPI: Added _OSI(Processor Device)
[    0.339664] ACPI: Added _OSI(3.0 _SCP Extensions)
[    0.341472] ACPI: Added _OSI(Processor Aggregator Device)
[    0.343581] ACPI: Added _OSI(Linux-Dell-Video)
[    0.345290] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[    0.347310] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)
[    0.351846] ACPI: 1 ACPI AML tables successfully acquired and loaded
[    0.354878] ACPI: Interpreter enabled
[    0.357948] ACPI: PM: (supports S0 S5)
[    0.359386] ACPI: Using IOAPIC for interrupt routing
[    0.361295] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
[    0.364875] ACPI: Enabled 1 GPEs in block 00 to 0F
[    0.367281] iommu: Default domain type: Translated 
[    0.367930] iommu: DMA domain TLB invalidation policy: lazy mode 
[    0.370342] SCSI subsystem initialized
[    0.371819] ACPI: bus type USB registered
[    0.373384] usbcore: registered new interface driver usbfs
[    0.375508] usbcore: registered new interface driver hub
[    0.377556] usbcore: registered new device driver usb
[    0.378007] hv_vmbus: Vmbus version:5.2
[    0.379525] PCI: Using ACPI for IRQ routing
[    0.381148] PCI: System does not support PCI
[    0.382985] hv_vmbus: Unknown GUID: c376c1c3-d276-48d2-90a9-c04748072c60
[    0.385656] hv_vmbus: Unknown GUID: 6e382d18-3336-4f4b-acc4-2b7703d4df4a
[    0.385656] hv_vmbus: Unknown GUID: dde9cbc0-5060-4436-9448-ea1254a5d177
[    0.385656] clocksource: Switched to clocksource tsc-early
[    0.395132] VFS: Disk quotas dquot_6.6.0
[    0.398629] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.401503] FS-Cache: Loaded
[    0.402695] pnp: PnP ACPI init
[    0.403992] pnp: PnP ACPI: found 3 devices
[    0.409671] NET: Registered PF_INET protocol family
[    0.411938] IP idents hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.416026] tcp_listen_portaddr_hash hash table entries: 8192 (order: 5, 131072 bytes, linear)
[    0.419575] TCP established hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.423230] TCP bind hash table entries: 65536 (order: 8, 1048576 bytes, linear)
[    0.426347] TCP: Hash tables configured (established 131072 bind 65536)
[    0.429190] UDP hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.432209] UDP-Lite hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.435648] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.438375] RPC: Registered named UNIX socket transport module.
[    0.440789] RPC: Registered udp transport module.
[    0.442671] RPC: Registered tcp transport module.
[    0.444673] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.447332] PCI: CLS 0 bytes, default 64
[    0.448993] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[    0.449028] Trying to unpack rootfs image as initramfs...
[    0.451710] software IO TLB: mapped [mem 0x00000000f4000000-0x00000000f8000000] (64MB)
[    0.454079] Freeing initrd memory: 364K
[    0.541430] kvm: no hardware support for 'kvm_intel'
[    0.543753] SVM: TSC scaling supported
[    0.545214] kvm: Nested Virtualization enabled
[    0.546939] SVM: kvm: Nested Paging enabled
[    0.548655] SVM: kvm: Hyper-V enlightened NPT TLB flush enabled
[    0.550982] SVM: kvm: Hyper-V Direct TLB Flush enabled
[    0.553055] SVM: Virtual VMLOAD VMSAVE supported
[    0.619230] Initialise system trusted keyrings
[    0.621148] workingset: timestamp_bits=46 max_order=22 bucket_order=0
[    0.624304] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.626917] NFS: Registering the id_resolver key type
[    0.628911] Key type id_resolver registered
[    0.630622] Key type id_legacy registered
[    0.632252] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.635096] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    0.638073] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[    0.641200] Key type cifs.idmap registered
[    0.642865] fuse: init (API version 7.36)
[    0.644622] SGI XFS with ACLs, security attributes, realtime, scrub, repair, quota, no debug enabled
[    0.648593] 9p: Installing v9fs 9p2000 file system support
[    0.650987] ceph: loaded (mds proto 32)
[    0.654860] NET: Registered PF_ALG protocol family
[    0.656711] xor: automatically using best checksumming function   avx       
[    0.659472] Key type asymmetric registered
[    0.661072] Asymmetric key parser 'x509' registered
[    0.662976] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[    0.666333] hv_vmbus: registering driver hv_pci
[    0.668465] hv_pci a154a52e-df93-4a32-a470-37362af9092a: PCI VMBus probing: Using version 0x10004
[    0.672862] hv_pci a154a52e-df93-4a32-a470-37362af9092a: PCI host bridge to bus df93:00
[    0.675963] pci_bus df93:00: root bus resource [mem 0x9ffe00000-0x9ffe02fff window]
[    0.678965] pci_bus df93:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.683016] pci df93:00:00.0: [1af4:1043] type 00 class 0x010000
[    0.686425] pci df93:00:00.0: reg 0x10: [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.689851] pci df93:00:00.0: reg 0x18: [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.693249] pci df93:00:00.0: reg 0x20: [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.698971] pci_bus df93:00: busn_res: [bus 00-ff] end is updated to 00
[    0.701554] pci df93:00:00.0: BAR 0: assigned [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.704894] pci df93:00:00.0: BAR 2: assigned [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.708243] pci df93:00:00.0: BAR 4: assigned [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.711877] hv_pci ca66d0fe-4477-439b-9d67-02d7bd2dcb05: PCI VMBus probing: Using version 0x10004
[    0.716001] hv_pci ca66d0fe-4477-439b-9d67-02d7bd2dcb05: PCI host bridge to bus 4477:00
[    0.719136] pci_bus 4477:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.722586] pci 4477:00:00.0: [1414:008e] type 00 class 0x030200
[    0.729016] pci_bus 4477:00: busn_res: [bus 00-ff] end is updated to 00
[    0.731822] hv_pci c42c9658-a709-40bd-8d72-5ee9b78e28ca: PCI VMBus probing: Using version 0x10004
[    0.736240] hv_pci c42c9658-a709-40bd-8d72-5ee9b78e28ca: PCI host bridge to bus a709:00
[    0.739381] pci_bus a709:00: root bus resource [mem 0x9ffe04000-0x9ffe06fff window]
[    0.742368] pci_bus a709:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.746437] pci a709:00:00.0: [1af4:1049] type 00 class 0x010000
[    0.749663] pci a709:00:00.0: reg 0x10: [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.752975] pci a709:00:00.0: reg 0x18: [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.756273] pci a709:00:00.0: reg 0x20: [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.762929] pci_bus a709:00: busn_res: [bus 00-ff] end is updated to 00
[    0.765585] pci a709:00:00.0: BAR 0: assigned [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.769014] pci a709:00:00.0: BAR 2: assigned [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.772436] pci a709:00:00.0: BAR 4: assigned [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.784024] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.786788] 00:00: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    0.790004] 00:01: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[    0.828478] Non-volatile memory driver v1.3
[    0.830180] printk: console [hvc0] enabled
[    0.831804] printk: bootconsole [uart8250] disabled
[    0.835700] brd: module loaded
[    0.836692] loop: module loaded
[    0.836890] hv_vmbus: registering driver hv_storvsc
[    0.837466] wireguard: WireGuard 1.0.0 loaded. See www.wireguard.com for information.
[    0.837853] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
[    0.838217] scsi host0: storvsc_host_t
[    0.838399] tun: Universal TUN/TAP device driver, 1.6
[    0.838812] PPP generic driver version 2.4.2
[    0.839159] PPP BSD Compression module registered
[    0.839395] PPP Deflate Compression module registered
[    0.839781] PPP MPPE Compression module registered
[    0.840046] NET: Registered PF_PPPOX protocol family
[    0.840326] usbcore: registered new interface driver cdc_ether
[    0.840687] usbcore: registered new interface driver cdc_ncm
[    0.841009] hv_vmbus: registering driver hv_netvsc
[    0.841331] VFIO - User Level meta-driver version: 0.3
[    0.841707] usbcore: registered new interface driver cdc_acm
[    0.841999] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[    0.842346] usbcore: registered new interface driver ch341
[    0.842613] usbserial: USB Serial support registered for ch341-uart
[    0.842907] usbcore: registered new interface driver cp210x
[    0.843226] usbserial: USB Serial support registered for cp210x
[    0.843574] usbcore: registered new interface driver ftdi_sio
[    0.843874] usbserial: USB Serial support registered for FTDI USB Serial Device
[    0.844325] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.844630] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 1
[    0.844968] vhci_hcd: created sysfs vhci_hcd.0
[    0.845394] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.18
[    0.845749] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.846033] usb usb1: Product: USB/IP Virtual Host Controller
[    0.846274] usb usb1: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 vhci_hcd
[    0.846606] usb usb1: SerialNumber: vhci_hcd.0
[    0.846887] hub 1-0:1.0: USB hub found
[    0.847077] hub 1-0:1.0: 8 ports detected
[    0.847565] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.847828] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 2
[    0.848246] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[    0.848690] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.18
[    0.848997] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.849279] usb usb2: Product: USB/IP Virtual Host Controller
[    0.849523] usb usb2: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 vhci_hcd
[    0.849855] usb usb2: SerialNumber: vhci_hcd.0
[    0.850138] hub 2-0:1.0: USB hub found
[    0.850333] hub 2-0:1.0: 8 ports detected
[    0.850772] hv_vmbus: registering driver hyperv_keyboard
[    0.851119] rtc_cmos 00:02: RTC can wake from S4
[    0.853017] rtc_cmos 00:02: registered as rtc0
[    0.853536] rtc_cmos 00:02: setting system clock to 2022-06-01T17:41:59 UTC (1654105319)
[    0.853854] rtc_cmos 00:02: alarms up to one month, 114 bytes nvram
[    0.854249] device-mapper: ioctl: 4.46.0-ioctl (2022-02-22) initialised: dm-devel@redhat.com
[    0.854710] device-mapper: raid: Loading target version 1.15.1
[    0.855003] usbcore: registered new interface driver usbhid
[    0.855198] usbhid: USB HID core driver
[    0.855394] hv_utils: Registering HyperV Utility Driver
[    0.855608] hv_vmbus: registering driver hv_utils
[    0.855910] hv_vmbus: registering driver hv_balloon
[    0.855914] hv_utils: cannot register PTP clock: 0
[    0.856165] drop_monitor: Initializing network drop monitor service
[    0.856597] hv_balloon: Using Dynamic Memory protocol version 2.0
[    0.856611] hv_utils: TimeSync IC version 4.0
[    0.856742] Mirror/redirect action on
[    0.857542] Free page reporting enabled
[    0.857744] hv_balloon: Cold memory discard hint enabled
[    0.858304] IPVS: Registered protocols (TCP, UDP)
[    0.858534] IPVS: Connection hash table configured (size=4096, memory=64Kbytes)
[    0.858872] IPVS: ipvs loaded.
[    0.859018] IPVS: [rr] scheduler registered.
[    0.859213] IPVS: [wrr] scheduler registered.
[    0.859405] IPVS: [sh] scheduler registered.
[    0.859622] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    0.860047] ipt_CLUSTERIP: ClusterIP Version 0.8 loaded successfully
[    0.860293] Initializing XFRM netlink socket
[    0.860522] NET: Registered PF_INET6 protocol family
[    0.861019] Segment Routing with IPv6
[    0.861193] In-situ OAM (IOAM) with IPv6
[    0.861362] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    0.861655] NET: Registered PF_PACKET protocol family
[    0.861875] Bridge firewalling registered
[    0.862024] 8021q: 802.1Q VLAN Support v1.8
[    0.862189] sctp: Hash tables configured (bind 256/256)
[    0.862419] 9pnet: Installing 9P2000 support
[    0.874428] Key type dns_resolver registered
[    0.874663] Key type ceph registered
[    0.874921] libceph: loaded (mon/osd proto 15/24)
[    0.875208] NET: Registered PF_VSOCK protocol family
[    0.875419] hv_vmbus: registering driver hv_sock
[    0.875644] IPI shorthand broadcast: enabled
[    0.875840] sched_clock: Marking stable (855501109, 19696300)->(934890300, -59692891)
[    0.876403] registered taskstats version 1
[    0.876928] Loading compiled-in X.509 certificates
[    0.877333] Btrfs loaded, crc32c=crc32c-generic, zoned=no, fsverity=no
[    0.882685] Freeing unused kernel image (initmem) memory: 1536K
[    0.918057] Write protecting the kernel read-only data: 24576k
[    0.918975] Freeing unused kernel image (text/rodata gap) memory: 2028K
[    0.919393] Freeing unused kernel image (rodata/data gap) memory: 144K
[    0.919654] Run /init as init process
[    0.919798]   with arguments:
[    0.919940]     /init
[    0.920047]   with environment:
[    0.920190]     HOME=/
[    0.920286]     TERM=linux
[    0.922620] scsi 0:0:0:0: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    0.923252] sd 0:0:0:0: Attached scsi generic sg0 type 0
[    0.923893] sd 0:0:0:0: [sda] 641944 512-byte logical blocks: (329 MB/313 MiB)
[    0.924490] sd 0:0:0:0: [sda] Write Protect is on
[    0.924760] sd 0:0:0:0: [sda] Mode Sense: 0f 00 80 00
[    0.925199] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[    1.538410] EXT4-fs (sda): mounted filesystem without journal. Quota mode: none.
[    1.640080] hv_pci 88309164-1127-4233-9560-6e0cad455d8f: PCI VMBus probing: Using version 0x10004
[    1.642187] hv_pci 88309164-1127-4233-9560-6e0cad455d8f: PCI host bridge to bus 1127:00
[    1.642548] pci_bus 1127:00: root bus resource [mem 0xa00000000-0xc00001fff window]
[    1.642895] pci_bus 1127:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.644287] pci 1127:00:00.0: [1af4:105a] type 00 class 0x088000
[    1.647194] pci 1127:00:00.0: reg 0x10: [mem 0xc00000000-0xc00000fff 64bit]
[    1.649501] pci 1127:00:00.0: reg 0x18: [mem 0xc00001000-0xc00001fff 64bit]
[    1.651514] pci 1127:00:00.0: reg 0x20: [mem 0xa00000000-0xbffffffff 64bit]
[    1.656603] pci_bus 1127:00: busn_res: [bus 00-ff] end is updated to 00
[    1.656902] pci 1127:00:00.0: BAR 4: assigned [mem 0xa00000000-0xbffffffff 64bit]
[    1.658754] pci 1127:00:00.0: BAR 0: assigned [mem 0xc00000000-0xc00000fff 64bit]
[    1.660797] pci 1127:00:00.0: BAR 2: assigned [mem 0xc00001000-0xc00001fff 64bit]
[    1.676734] virtiofs virtio2: Cache len: 0x200000000 @ 0xa00000000
[    1.687964] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    1.688537] clocksource: Switched to clocksource tsc
[    1.718131] sd 0:0:0:0: [sda] Attached SCSI disk
[    1.737024] memmap_init_zone_device initialised 2097152 pages in 10ms
[    1.738457] WSL2: SetEphemeralPortRange is a no-op : range (0, 0)
[    1.847973] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    2.418129] scsi 0:0:0:1: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.418887] sd 0:0:0:1: Attached scsi generic sg1 type 0
[    2.419446] scsi 0:0:0:2: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.419498] sd 0:0:0:1: [sdb] 2097160 512-byte logical blocks: (1.07 GB/1.00 GiB)
[    2.420146] sd 0:0:0:2: Attached scsi generic sg2 type 0
[    2.420236] sd 0:0:0:1: [sdb] 4096-byte physical blocks
[    2.420789] sd 0:0:0:2: [sdc] 536870912 512-byte logical blocks: (275 GB/256 GiB)
[    2.420849] sd 0:0:0:1: [sdb] Write Protect is off
[    2.421225] sd 0:0:0:2: [sdc] 4096-byte physical blocks
[    2.421541] sd 0:0:0:1: [sdb] Mode Sense: 0f 00 00 00
[    2.421888] sd 0:0:0:2: [sdc] Write Protect is off
[    2.422260] sd 0:0:0:1: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.422392] sd 0:0:0:2: [sdc] Mode Sense: 0f 00 00 00
[    2.423302] sd 0:0:0:2: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.424840] sd 0:0:0:1: [sdb] Attached SCSI disk
[    2.426063] sd 0:0:0:2: [sdc] Attached SCSI disk
[    2.444484] EXT4-fs (sdc): recovery complete
[    2.445457] EXT4-fs (sdc): mounted filesystem with ordered data mode. Quota mode: none.
[    2.459372] Adding 1048576k swap on /dev/sdb.  Priority:-2 extents:1 across:1048576k 
[    2.649008] hv_pci aed388e8-de3a-45a5-bb0c-ee534e806689: PCI VMBus probing: Using version 0x10004
[    2.650439] hv_pci aed388e8-de3a-45a5-bb0c-ee534e806689: PCI host bridge to bus de3a:00
[    2.650756] pci_bus de3a:00: root bus resource [mem 0x9ffe08000-0x9ffe0afff window]
[    2.651045] pci_bus de3a:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.652320] pci de3a:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.653496] pci de3a:00:00.0: reg 0x10: [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.654363] pci de3a:00:00.0: reg 0x18: [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.655227] pci de3a:00:00.0: reg 0x20: [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.659234] pci_bus de3a:00: busn_res: [bus 00-ff] end is updated to 00
[    2.659501] pci de3a:00:00.0: BAR 0: assigned [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.660251] pci de3a:00:00.0: BAR 2: assigned [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.660989] pci de3a:00:00.0: BAR 4: assigned [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.663932] 9pnet_virtio: no channels available for device drvfs
[    2.664237] init: (1) WARNING: mount: waiting for virtio device...
[    2.770766] hv_pci 81d9a8d7-9fce-46b7-9ff9-b146da3089e4: PCI VMBus probing: Using version 0x10004
[    2.772061] hv_pci 81d9a8d7-9fce-46b7-9ff9-b146da3089e4: PCI host bridge to bus 9fce:00
[    2.772372] pci_bus 9fce:00: root bus resource [mem 0x9ffe0c000-0x9ffe0efff window]
[    2.772664] pci_bus 9fce:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.773910] pci 9fce:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.775050] pci 9fce:00:00.0: reg 0x10: [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.775911] pci 9fce:00:00.0: reg 0x18: [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.776761] pci 9fce:00:00.0: reg 0x20: [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.780694] pci_bus 9fce:00: busn_res: [bus 00-ff] end is updated to 00
[    2.780986] pci 9fce:00:00.0: BAR 0: assigned [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.781703] pci 9fce:00:00.0: BAR 2: assigned [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.781986] 9pnet_virtio: no channels available for device drvfs
[    2.782311] init: (1) WARNING: mount: waiting for virtio device...
[    2.782471] pci 9fce:00:00.0: BAR 4: assigned [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.898491] hv_pci 86858b54-a9ff-42c1-85be-12646bde6957: PCI VMBus probing: Using version 0x10004
[    2.899831] hv_pci 86858b54-a9ff-42c1-85be-12646bde6957: PCI host bridge to bus a9ff:00
[    2.900148] pci_bus a9ff:00: root bus resource [mem 0x9ffe10000-0x9ffe12fff window]
[    2.900437] pci_bus a9ff:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.901684] pci a9ff:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.902856] pci a9ff:00:00.0: reg 0x10: [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.903716] pci a9ff:00:00.0: reg 0x18: [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.904609] pci a9ff:00:00.0: reg 0x20: [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    2.908519] pci_bus a9ff:00: busn_res: [bus 00-ff] end is updated to 00
[    2.908842] pci a9ff:00:00.0: BAR 0: assigned [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.909600] pci a9ff:00:00.0: BAR 2: assigned [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.910335] pci a9ff:00:00.0: BAR 4: assigned [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    3.009967] hv_pci 14a6c250-2f5e-4544-972d-e4af992a128a: PCI VMBus probing: Using version 0x10004
[    3.011462] hv_pci 14a6c250-2f5e-4544-972d-e4af992a128a: PCI host bridge to bus 2f5e:00
[    3.011804] pci_bus 2f5e:00: root bus resource [mem 0x9ffe14000-0x9ffe16fff window]
[    3.012172] pci_bus 2f5e:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.013562] pci 2f5e:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.014756] pci 2f5e:00:00.0: reg 0x10: [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.015633] pci 2f5e:00:00.0: reg 0x18: [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.016516] pci 2f5e:00:00.0: reg 0x20: [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.020834] pci_bus 2f5e:00: busn_res: [bus 00-ff] end is updated to 00
[    3.021157] pci 2f5e:00:00.0: BAR 0: assigned [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.022095] pci 2f5e:00:00.0: BAR 2: assigned [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.022867] pci 2f5e:00:00.0: BAR 4: assigned [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.030227] 9pnet_virtio: no channels available for device drvfs
[    3.030578] init: (1) WARNING: mount: waiting for virtio device...
[    3.143192] hv_pci ed843176-e057-48d4-ab94-623a027b1629: PCI VMBus probing: Using version 0x10004
[    3.144600] hv_pci ed843176-e057-48d4-ab94-623a027b1629: PCI host bridge to bus e057:00
[    3.144927] pci_bus e057:00: root bus resource [mem 0x9ffe18000-0x9ffe1afff window]
[    3.145222] pci_bus e057:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.146529] pci e057:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.147766] pci e057:00:00.0: reg 0x10: [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.148685] pci e057:00:00.0: reg 0x18: [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.149556] pci e057:00:00.0: reg 0x20: [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.153686] pci_bus e057:00: busn_res: [bus 00-ff] end is updated to 00
[    3.154060] pci e057:00:00.0: BAR 0: assigned [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.154855] pci e057:00:00.0: BAR 2: assigned [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.155592] pci e057:00:00.0: BAR 4: assigned [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.188714] hv_pci c963c476-4546-43da-a32c-7e4ddeb55d93: PCI VMBus probing: Using version 0x10004
[    3.190328] hv_pci c963c476-4546-43da-a32c-7e4ddeb55d93: PCI host bridge to bus 4546:00
[    3.190732] pci_bus 4546:00: root bus resource [mem 0x9ffe1c000-0x9ffe1efff window]
[    3.191104] pci_bus 4546:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.192578] pci 4546:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.193870] pci 4546:00:00.0: reg 0x10: [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.194935] pci 4546:00:00.0: reg 0x18: [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.196022] pci 4546:00:00.0: reg 0x20: [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[    3.200503] pci_bus 4546:00: busn_res: [bus 00-ff] end is updated to 00
[    3.200855] pci 4546:00:00.0: BAR 0: assigned [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.201736] pci 4546:00:00.0: BAR 2: assigned [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.202501] pci 4546:00:00.0: BAR 4: assigned [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[   49.723721] hv_balloon: Max. dynamic memory size: 16384 MB

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:46         ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 17:46 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> Can you send me the full dmesg and the content of
> /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?

Sure thing, they are attached! If there is anything else I can provide
or test, I am more than happy to do so.

Cheers,
Nathan

[-- Attachment #2: good.log --]
[-- Type: text/plain, Size: 34692 bytes --]

# cat /sys/kernel/debug/swiotlb/io_tlb_nslabs
32768

# dmesg
[    0.000000] Linux version 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 (nathan@dev-arch.thelio-3990X) (gcc (GCC) 12.1.0, GNU ld (GNU Binutils) 2.38) #1 SMP PREEMPT_DYNAMIC Wed Jun 1 10:38:34 MST 2022
[    0.000000] Command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 1776
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000e0fff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000001fffff] ACPI data
[    0.000000] BIOS-e820: [mem 0x0000000000200000-0x00000000f7ffffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000100000000-0x0000000407ffffff] usable
[    0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '115200')
[    0.000000] printk: bootconsole [uart8250] enabled
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI not present or invalid.
[    0.000000] Hypervisor detected: Microsoft Hyper-V
[    0.000000] Hyper-V: privilege flags low 0xae7f, high 0x3b8030, hints 0xc2c, misc 0xe0bed7b6
[    0.000000] Hyper-V: Host Build 10.0.22000.708-0-0
[    0.000000] Hyper-V: Nested features: 0x4a0000
[    0.000000] Hyper-V: LAPIC Timer Frequency: 0x1e8480
[    0.000000] Hyper-V: Using hypercall for remote TLB flush
[    0.000000] clocksource: hyperv_clocksource_tsc_page: mask: 0xffffffffffffffff max_cycles: 0x24e6a1710, max_idle_ns: 440795202120 ns
[    0.000005] tsc: Detected 3800.008 MHz processor
[    0.001901] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.004593] e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.006806] last_pfn = 0x408000 max_arch_pfn = 0x400000000
[    0.009042] x86/PAT: Configuration [0-7]: WB  WC  UC- UC  WB  WP  UC- WT  
[    0.011760] last_pfn = 0xf8000 max_arch_pfn = 0x400000000
[    0.013959] Using GB pages for direct mapping
[    0.015749] RAMDISK: [mem 0x0371f000-0x03779fff]
[    0.017616] ACPI: Early table checksum verification disabled
[    0.019854] ACPI: RSDP 0x00000000000E0000 000024 (v02 VRTUAL)
[    0.022162] ACPI: XSDT 0x0000000000100000 000044 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.025624] ACPI: FACP 0x0000000000101000 000114 (v06 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.029022] ACPI: DSDT 0x00000000001011B8 01E184 (v02 MSFTVM DSDT01   00000001 MSFT 05000000)
[    0.032413] ACPI: FACS 0x0000000000101114 000040
[    0.034280] ACPI: OEM0 0x0000000000101154 000064 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.037699] ACPI: SRAT 0x000000000011F33C 000330 (v02 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.041089] ACPI: APIC 0x000000000011F66C 000088 (v04 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.044475] ACPI: Reserving FACP table memory at [mem 0x101000-0x101113]
[    0.047159] ACPI: Reserving DSDT table memory at [mem 0x1011b8-0x11f33b]
[    0.049905] ACPI: Reserving FACS table memory at [mem 0x101114-0x101153]
[    0.052693] ACPI: Reserving OEM0 table memory at [mem 0x101154-0x1011b7]
[    0.055404] ACPI: Reserving SRAT table memory at [mem 0x11f33c-0x11f66b]
[    0.058040] ACPI: Reserving APIC table memory at [mem 0x11f66c-0x11f6f3]
[    0.061078] Zone ranges:
[    0.062074]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.066106]   DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
[    0.068763]   Normal   [mem 0x0000000100000000-0x0000000407ffffff]
[    0.071235]   Device   empty
[    0.072384] Movable zone start for each node
[    0.074058] Early memory node ranges
[    0.075515]   node   0: [mem 0x0000000000001000-0x000000000009ffff]
[    0.077979]   node   0: [mem 0x0000000000200000-0x00000000f7ffffff]
[    0.080483]   node   0: [mem 0x0000000100000000-0x0000000407ffffff]
[    0.082980] Initmem setup node 0 [mem 0x0000000000001000-0x0000000407ffffff]
[    0.085954] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.085972] On node 0, zone DMA: 352 pages in unavailable ranges
[    0.098043] ACPI: LAPIC_NMI (acpi_id[0x01] dfl dfl lint[0x1])
[    0.102995] IOAPIC[0]: apic_id 8, version 17, address 0xfec00000, GSI 0-23
[    0.105726] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[    0.108349] ACPI: Using ACPI (MADT) for SMP configuration information
[    0.110909] smpboot: Allowing 8 CPUs, 0 hotplug CPUs
[    0.112902] [mem 0xf8000000-0xffffffff] available for PCI devices
[    0.115315] Booting paravirtualized kernel on Hyper-V
[    0.117347] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.126056] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:8 nr_node_ids:1
[    0.129513] percpu: Embedded 53 pages/cpu s178408 r8192 d30488 u262144
[    0.132139] pcpu-alloc: s178408 r8192 d30488 u262144 alloc=1*2097152
[    0.134679] pcpu-alloc: [0] 0 1 2 3 4 5 6 7 
[    0.136341] Hyper-V: PV spinlocks enabled
[    0.137917] PV qspinlock hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.140833] Built 1 zonelists, mobility grouping on.  Total pages: 4127749
[    0.143636] Kernel command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.151440] Dentry cache hash table entries: 2097152 (order: 12, 16777216 bytes, linear)
[    0.155808] Inode-cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.159017] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.184685] Memory: 4126096K/16775804K available (18449K kernel code, 2647K rwdata, 3952K rodata, 1536K init, 2448K bss, 392692K reserved, 0K cma-reserved)
[    0.190358] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
[    0.192969] ftrace: allocating 51788 entries in 203 pages
[    0.201434] ftrace: allocated 203 pages with 5 groups
[    0.204349] Dynamic Preempt: none
[    0.205846] rcu: Preemptible hierarchical RCU implementation.
[    0.208162] rcu: 	RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=8.
[    0.210799] 	Trampoline variant of Tasks RCU enabled.
[    0.212756] 	Rude variant of Tasks RCU enabled.
[    0.214541] 	Tracing variant of Tasks RCU enabled.
[    0.216404] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.219393] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=8
[    0.225278] Using NULL legacy PIC
[    0.226573] NR_IRQS: 16640, nr_irqs: 488, preallocated irqs: 0
[    0.229131] random: crng init done (trusting CPU's manufacturer)
[    0.231548] Console: colour dummy device 80x25
[    0.233276] ACPI: Core revision 20211217
[    0.234931] Failed to register legacy timer interrupt
[    0.236944] APIC: Switch to symmetric I/O mode setup
[    0.238947] Hyper-V: enabling crash_kexec_post_notifiers
[    0.241016] Hyper-V: Using IPI hypercalls
[    0.242591] Hyper-V: Using enlightened APIC (xapic mode)
[    0.242680] clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    0.248870] Calibrating delay loop (skipped), value calculated using timer frequency.. 7600.01 BogoMIPS (lpj=38000080)
[    0.253092] pid_max: default: 32768 minimum: 301
[    0.254926] LSM: Security Framework initializing
[    0.256750] Mount-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.258867] Mountpoint-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.258867] x86/cpu: User Mode Instruction Prevention (UMIP) activated
[    0.258867] Last level iTLB entries: 4KB 1024, 2MB 1024, 4MB 512
[    0.258867] Last level dTLB entries: 4KB 2048, 2MB 2048, 4MB 1024, 1GB 0
[    0.258867] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.258867] Spectre V2 : Mitigation: Retpolines
[    0.258867] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
[    0.258867] Spectre V2 : mitigation: Enabling conditional Indirect Branch Prediction Barrier
[    0.258867] Spectre V2 : User space: Mitigation: STIBP via prctl
[    0.258867] Speculative Store Bypass: Mitigation: Speculative Store Bypass disabled via prctl
[    0.258867] Freeing SMP alternatives memory: 56K
[    0.258867] smpboot: CPU0: AMD Ryzen 9 3900X 12-Core Processor (family: 0x17, model: 0x71, stepping: 0x0)
[    0.258867] cblist_init_generic: Setting adjustable number of callback queues.
[    0.258867] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.258867] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.258895] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.261292] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[    0.263817] ... version:                0
[    0.265391] ... bit width:              48
[    0.267068] ... generic registers:      6
[    0.268634] ... value mask:             0000ffffffffffff
[    0.268871] ... max period:             00007fffffffffff
[    0.270991] ... fixed-purpose events:   0
[    0.272571] ... event mask:             000000000000003f
[    0.274695] rcu: Hierarchical SRCU implementation.
[    0.276947] smp: Bringing up secondary CPUs ...
[    0.278794] x86: Booting SMP configuration:
[    0.278872] .... node  #0, CPUs:      #1 #2 #3 #4 #5 #6 #7
[    0.279525] smp: Brought up 1 node, 8 CPUs
[    0.282814] smpboot: Max logical packages: 1
[    0.284479] smpboot: Total of 8 processors activated (60800.12 BogoMIPS)
[    0.298895] node 0 deferred pages initialised in 10ms
[    0.300921] devtmpfs: initialized
[    0.300921] x86/mm: Memory block size: 128MB
[    0.302426] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.308889] futex hash table entries: 2048 (order: 5, 131072 bytes, linear)
[    0.312151] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.314571] thermal_sys: Registered thermal governor 'step_wise'
[    0.314572] thermal_sys: Registered thermal governor 'user_space'
[    0.316961] cpuidle: using governor menu
[    0.318916] PCI: Fatal: No config space access function found
[    0.322206] kprobes: kprobe jump-optimization is enabled. All kprobes are optimized if possible.
[    0.322206] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[    0.322206] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[    0.328925] raid6: skipped pq benchmark and selected avx2x4
[    0.331164] raid6: using avx2x2 recovery algorithm
[    0.331164] ACPI: Added _OSI(Module Device)
[    0.331164] ACPI: Added _OSI(Processor Device)
[    0.332457] ACPI: Added _OSI(3.0 _SCP Extensions)
[    0.334283] ACPI: Added _OSI(Processor Aggregator Device)
[    0.336463] ACPI: Added _OSI(Linux-Dell-Video)
[    0.338283] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[    0.348871] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)
[    0.355075] ACPI: 1 ACPI AML tables successfully acquired and loaded
[    0.358946] ACPI: Interpreter enabled
[    0.360583] ACPI: PM: (supports S0 S5)
[    0.362198] ACPI: Using IOAPIC for interrupt routing
[    0.364304] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
[    0.368017] ACPI: Enabled 1 GPEs in block 00 to 0F
[    0.369481] iommu: Default domain type: Translated 
[    0.371449] iommu: DMA domain TLB invalidation policy: lazy mode 
[    0.373937] SCSI subsystem initialized
[    0.375541] ACPI: bus type USB registered
[    0.377164] usbcore: registered new interface driver usbfs
[    0.378875] usbcore: registered new interface driver hub
[    0.380985] usbcore: registered new device driver usb
[    0.383023] hv_vmbus: Vmbus version:5.2
[    0.383023] PCI: Using ACPI for IRQ routing
[    0.383023] PCI: System does not support PCI
[    0.389034] clocksource: Switched to clocksource tsc-early
[    0.389075] hv_vmbus: Unknown GUID: c376c1c3-d276-48d2-90a9-c04748072c60
[    0.394146] hv_vmbus: Unknown GUID: 6e382d18-3336-4f4b-acc4-2b7703d4df4a
[    0.396909] hv_vmbus: Unknown GUID: dde9cbc0-5060-4436-9448-ea1254a5d177
[    0.399744] VFS: Disk quotas dquot_6.6.0
[    0.401370] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.404186] FS-Cache: Loaded
[    0.405386] pnp: PnP ACPI init
[    0.406693] pnp: PnP ACPI: found 3 devices
[    0.412166] NET: Registered PF_INET protocol family
[    0.414416] IP idents hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.418515] tcp_listen_portaddr_hash hash table entries: 8192 (order: 5, 131072 bytes, linear)
[    0.422058] TCP established hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.425602] TCP bind hash table entries: 65536 (order: 8, 1048576 bytes, linear)
[    0.428661] TCP: Hash tables configured (established 131072 bind 65536)
[    0.431375] UDP hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.434579] UDP-Lite hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.437587] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.440120] RPC: Registered named UNIX socket transport module.
[    0.442979] RPC: Registered udp transport module.
[    0.445120] RPC: Registered tcp transport module.
[    0.447250] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.449989] PCI: CLS 0 bytes, default 64
[    0.451619] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[    0.451654] Trying to unpack rootfs image as initramfs...
[    0.454256] software IO TLB: mapped [mem 0x00000000f4000000-0x00000000f8000000] (64MB)
[    0.456463] Freeing initrd memory: 364K
[    0.541510] kvm: no hardware support for 'kvm_intel'
[    0.543867] SVM: TSC scaling supported
[    0.545319] kvm: Nested Virtualization enabled
[    0.547040] SVM: kvm: Nested Paging enabled
[    0.548653] SVM: kvm: Hyper-V enlightened NPT TLB flush enabled
[    0.550967] SVM: kvm: Hyper-V Direct TLB Flush enabled
[    0.552946] SVM: Virtual VMLOAD VMSAVE supported
[    0.618969] Initialise system trusted keyrings
[    0.620900] workingset: timestamp_bits=46 max_order=22 bucket_order=0
[    0.624053] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.626726] NFS: Registering the id_resolver key type
[    0.628690] Key type id_resolver registered
[    0.630376] Key type id_legacy registered
[    0.631915] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.634537] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    0.637515] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[    0.640546] Key type cifs.idmap registered
[    0.642255] fuse: init (API version 7.36)
[    0.643973] SGI XFS with ACLs, security attributes, realtime, scrub, repair, quota, no debug enabled
[    0.647888] 9p: Installing v9fs 9p2000 file system support
[    0.650100] ceph: loaded (mds proto 32)
[    0.653965] NET: Registered PF_ALG protocol family
[    0.655832] xor: automatically using best checksumming function   avx       
[    0.658591] Key type asymmetric registered
[    0.660227] Asymmetric key parser 'x509' registered
[    0.662151] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[    0.665489] hv_vmbus: registering driver hv_pci
[    0.667566] hv_pci b440727e-7525-4d9c-a556-d52029b00086: PCI VMBus probing: Using version 0x10004
[    0.671953] hv_pci b440727e-7525-4d9c-a556-d52029b00086: PCI host bridge to bus 7525:00
[    0.675135] pci_bus 7525:00: root bus resource [mem 0x9ffe00000-0x9ffe02fff window]
[    0.678177] pci_bus 7525:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.682285] pci 7525:00:00.0: [1af4:1043] type 00 class 0x010000
[    0.686012] pci 7525:00:00.0: reg 0x10: [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.689489] pci 7525:00:00.0: reg 0x18: [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.693005] pci 7525:00:00.0: reg 0x20: [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.698805] pci_bus 7525:00: busn_res: [bus 00-ff] end is updated to 00
[    0.701529] pci 7525:00:00.0: BAR 0: assigned [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.705034] pci 7525:00:00.0: BAR 2: assigned [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.708415] pci 7525:00:00.0: BAR 4: assigned [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.712037] hv_pci 121abb12-7ab2-45ff-b4ee-e85a1067c860: PCI VMBus probing: Using version 0x10004
[    0.716192] hv_pci 121abb12-7ab2-45ff-b4ee-e85a1067c860: PCI host bridge to bus 7ab2:00
[    0.719504] pci_bus 7ab2:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.723020] pci 7ab2:00:00.0: [1414:008e] type 00 class 0x030200
[    0.729607] pci_bus 7ab2:00: busn_res: [bus 00-ff] end is updated to 00
[    0.732348] hv_pci 0c573a50-ca5d-42a9-9657-3920a455151c: PCI VMBus probing: Using version 0x10004
[    0.736748] hv_pci 0c573a50-ca5d-42a9-9657-3920a455151c: PCI host bridge to bus ca5d:00
[    0.739875] pci_bus ca5d:00: root bus resource [mem 0x9ffe04000-0x9ffe06fff window]
[    0.742859] pci_bus ca5d:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.746939] pci ca5d:00:00.0: [1af4:1049] type 00 class 0x010000
[    0.750206] pci ca5d:00:00.0: reg 0x10: [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.753516] pci ca5d:00:00.0: reg 0x18: [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.756826] pci ca5d:00:00.0: reg 0x20: [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.763185] pci_bus ca5d:00: busn_res: [bus 00-ff] end is updated to 00
[    0.765793] pci ca5d:00:00.0: BAR 0: assigned [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.769223] pci ca5d:00:00.0: BAR 2: assigned [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.772634] pci ca5d:00:00.0: BAR 4: assigned [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.784382] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.787110] 00:00: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    0.790429] 00:01: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[    0.829682] Non-volatile memory driver v1.3
[    0.831440] printk: console [hvc0] enabled
[    0.833112] printk: bootconsole [uart8250] disabled
[    0.836997] brd: module loaded
[    0.838058] loop: module loaded
[    0.838265] hv_vmbus: registering driver hv_storvsc
[    0.838832] wireguard: WireGuard 1.0.0 loaded. See www.wireguard.com for information.
[    0.839306] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
[    0.839681] tun: Universal TUN/TAP device driver, 1.6
[    0.839972] PPP generic driver version 2.4.2
[    0.840236] scsi host0: storvsc_host_t
[    0.840302] PPP BSD Compression module registered
[    0.840692] PPP Deflate Compression module registered
[    0.841134] PPP MPPE Compression module registered
[    0.841392] NET: Registered PF_PPPOX protocol family
[    0.841654] usbcore: registered new interface driver cdc_ether
[    0.841957] usbcore: registered new interface driver cdc_ncm
[    0.842276] hv_vmbus: registering driver hv_netvsc
[    0.842639] VFIO - User Level meta-driver version: 0.3
[    0.843061] usbcore: registered new interface driver cdc_acm
[    0.843378] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[    0.843756] usbcore: registered new interface driver ch341
[    0.843966] usbserial: USB Serial support registered for ch341-uart
[    0.844287] usbcore: registered new interface driver cp210x
[    0.844545] usbserial: USB Serial support registered for cp210x
[    0.844853] usbcore: registered new interface driver ftdi_sio
[    0.845182] usbserial: USB Serial support registered for FTDI USB Serial Device
[    0.845673] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.846016] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 1
[    0.846374] vhci_hcd: created sysfs vhci_hcd.0
[    0.846742] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.18
[    0.847077] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.847418] usb usb1: Product: USB/IP Virtual Host Controller
[    0.847660] usb usb1: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 vhci_hcd
[    0.847995] usb usb1: SerialNumber: vhci_hcd.0
[    0.848335] hub 1-0:1.0: USB hub found
[    0.848536] hub 1-0:1.0: 8 ports detected
[    0.848976] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.849254] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 2
[    0.849621] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[    0.850102] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.18
[    0.850427] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.850718] usb usb2: Product: USB/IP Virtual Host Controller
[    0.850961] usb usb2: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00008-ga3e230926708 vhci_hcd
[    0.851300] usb usb2: SerialNumber: vhci_hcd.0
[    0.851614] hub 2-0:1.0: USB hub found
[    0.851810] hub 2-0:1.0: 8 ports detected
[    0.852249] hv_vmbus: registering driver hyperv_keyboard
[    0.852593] rtc_cmos 00:02: RTC can wake from S4
[    0.854483] rtc_cmos 00:02: registered as rtc0
[    0.854995] rtc_cmos 00:02: setting system clock to 2022-06-01T17:39:04 UTC (1654105144)
[    0.855309] rtc_cmos 00:02: alarms up to one month, 114 bytes nvram
[    0.855718] device-mapper: ioctl: 4.46.0-ioctl (2022-02-22) initialised: dm-devel@redhat.com
[    0.856172] device-mapper: raid: Loading target version 1.15.1
[    0.856511] usbcore: registered new interface driver usbhid
[    0.856703] usbhid: USB HID core driver
[    0.856901] hv_utils: Registering HyperV Utility Driver
[    0.857113] hv_vmbus: registering driver hv_utils
[    0.857333] hv_vmbus: registering driver hv_balloon
[    0.857338] hv_utils: cannot register PTP clock: 0
[    0.857607] drop_monitor: Initializing network drop monitor service
[    0.858067] hv_utils: TimeSync IC version 4.0
[    0.858073] hv_balloon: Using Dynamic Memory protocol version 2.0
[    0.858248] Mirror/redirect action on
[    0.859029] Free page reporting enabled
[    0.859197] hv_balloon: Cold memory discard hint enabled
[    0.859770] IPVS: Registered protocols (TCP, UDP)
[    0.860029] IPVS: Connection hash table configured (size=4096, memory=64Kbytes)
[    0.860395] IPVS: ipvs loaded.
[    0.860546] IPVS: [rr] scheduler registered.
[    0.860743] IPVS: [wrr] scheduler registered.
[    0.860937] IPVS: [sh] scheduler registered.
[    0.861159] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    0.861418] ipt_CLUSTERIP: ClusterIP Version 0.8 loaded successfully
[    0.861666] Initializing XFRM netlink socket
[    0.861903] NET: Registered PF_INET6 protocol family
[    0.862439] Segment Routing with IPv6
[    0.862619] In-situ OAM (IOAM) with IPv6
[    0.862791] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    0.863092] NET: Registered PF_PACKET protocol family
[    0.863332] Bridge firewalling registered
[    0.863488] 8021q: 802.1Q VLAN Support v1.8
[    0.863653] sctp: Hash tables configured (bind 256/256)
[    0.863885] 9pnet: Installing 9P2000 support
[    0.875420] Key type dns_resolver registered
[    0.875693] Key type ceph registered
[    0.875979] libceph: loaded (mon/osd proto 15/24)
[    0.876260] NET: Registered PF_VSOCK protocol family
[    0.876540] hv_vmbus: registering driver hv_sock
[    0.876769] IPI shorthand broadcast: enabled
[    0.876968] sched_clock: Marking stable (856497151, 19750700)->(930661400, -54413549)
[    0.877527] registered taskstats version 1
[    0.878008] Loading compiled-in X.509 certificates
[    0.878392] Btrfs loaded, crc32c=crc32c-generic, zoned=no, fsverity=no
[    0.883871] Freeing unused kernel image (initmem) memory: 1536K
[    0.958961] Write protecting the kernel read-only data: 24576k
[    0.959743] Freeing unused kernel image (text/rodata gap) memory: 2028K
[    0.960146] Freeing unused kernel image (rodata/data gap) memory: 144K
[    0.960406] Run /init as init process
[    0.960549]   with arguments:
[    0.960690]     /init
[    0.960790]   with environment:
[    0.960931]     HOME=/
[    0.961046]     TERM=linux
[    0.963320] scsi 0:0:0:0: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    0.964110] sd 0:0:0:0: Attached scsi generic sg0 type 0
[    0.964747] sd 0:0:0:0: [sda] 641944 512-byte logical blocks: (329 MB/313 MiB)
[    0.965293] sd 0:0:0:0: [sda] Write Protect is on
[    0.965554] sd 0:0:0:0: [sda] Mode Sense: 0f 00 80 00
[    0.965967] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[    1.459424] EXT4-fs (sda): mounted filesystem without journal. Quota mode: none.
[    1.677905] hv_pci 75e234e6-9a41-4c1d-8ac8-5d395d071dd2: PCI VMBus probing: Using version 0x10004
[    1.678919] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    1.679926] hv_pci 75e234e6-9a41-4c1d-8ac8-5d395d071dd2: PCI host bridge to bus 9a41:00
[    1.680478] pci_bus 9a41:00: root bus resource [mem 0xa00000000-0xc00001fff window]
[    1.680783] pci_bus 9a41:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.682091] pci 9a41:00:00.0: [1af4:105a] type 00 class 0x088000
[    1.684295] pci 9a41:00:00.0: reg 0x10: [mem 0xc00000000-0xc00000fff 64bit]
[    1.686271] pci 9a41:00:00.0: reg 0x18: [mem 0xc00001000-0xc00001fff 64bit]
[    1.688288] pci 9a41:00:00.0: reg 0x20: [mem 0xa00000000-0xbffffffff 64bit]
[    1.693245] pci_bus 9a41:00: busn_res: [bus 00-ff] end is updated to 00
[    1.693513] pci 9a41:00:00.0: BAR 4: assigned [mem 0xa00000000-0xbffffffff 64bit]
[    1.695391] pci 9a41:00:00.0: BAR 0: assigned [mem 0xc00000000-0xc00000fff 64bit]
[    1.697251] pci 9a41:00:00.0: BAR 2: assigned [mem 0xc00001000-0xc00001fff 64bit]
[    1.712810] virtiofs virtio2: Cache len: 0x200000000 @ 0xa00000000
[    1.713702] clocksource: Switched to clocksource tsc
[    1.739139] sd 0:0:0:0: [sda] Attached SCSI disk
[    1.778098] memmap_init_zone_device initialised 2097152 pages in 10ms
[    1.779673] WSL2: SetEphemeralPortRange is a no-op : range (0, 0)
[    1.848936] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    2.479025] scsi 0:0:0:1: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.479872] sd 0:0:0:1: Attached scsi generic sg1 type 0
[    2.480323] sd 0:0:0:1: [sdb] 2097160 512-byte logical blocks: (1.07 GB/1.00 GiB)
[    2.480417] scsi 0:0:0:2: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.480787] sd 0:0:0:1: [sdb] 4096-byte physical blocks
[    2.481485] sd 0:0:0:2: Attached scsi generic sg2 type 0
[    2.481508] sd 0:0:0:1: [sdb] Write Protect is off
[    2.482052] sd 0:0:0:2: [sdc] 536870912 512-byte logical blocks: (275 GB/256 GiB)
[    2.482106] sd 0:0:0:1: [sdb] Mode Sense: 0f 00 00 00
[    2.482522] sd 0:0:0:2: [sdc] 4096-byte physical blocks
[    2.482915] sd 0:0:0:1: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.483103] sd 0:0:0:2: [sdc] Write Protect is off
[    2.483857] sd 0:0:0:2: [sdc] Mode Sense: 0f 00 00 00
[    2.484274] sd 0:0:0:2: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.485716] sd 0:0:0:1: [sdb] Attached SCSI disk
[    2.491559] sd 0:0:0:2: [sdc] Attached SCSI disk
[    2.500504] EXT4-fs (sdc): recovery complete
[    2.501459] EXT4-fs (sdc): mounted filesystem with ordered data mode. Quota mode: none.
[    2.522816] Adding 1048576k swap on /dev/sdb.  Priority:-2 extents:1 across:1048576k 
[    2.681998] hv_pci 218ee01d-fcab-4f07-9ea0-57e00b7600be: PCI VMBus probing: Using version 0x10004
[    2.683056] 9pnet_virtio: no channels available for device drvfs
[    2.683289] hv_pci 218ee01d-fcab-4f07-9ea0-57e00b7600be: PCI host bridge to bus fcab:00
[    2.683349] init: (1) WARNING: mount: waiting for virtio device...
[    2.683645] pci_bus fcab:00: root bus resource [mem 0x9ffe08000-0x9ffe0afff window]
[    2.684167] pci_bus fcab:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.685517] pci fcab:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.686817] pci fcab:00:00.0: reg 0x10: [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.687677] pci fcab:00:00.0: reg 0x18: [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.688539] pci fcab:00:00.0: reg 0x20: [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.692528] pci_bus fcab:00: busn_res: [bus 00-ff] end is updated to 00
[    2.692830] pci fcab:00:00.0: BAR 0: assigned [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.693631] pci fcab:00:00.0: BAR 2: assigned [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.694374] pci fcab:00:00.0: BAR 4: assigned [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.788379] hv_pci 5767d560-6512-42aa-bddc-89eca93e4c84: PCI VMBus probing: Using version 0x10004
[    2.789471] 9pnet_virtio: no channels available for device drvfs
[    2.789751] hv_pci 5767d560-6512-42aa-bddc-89eca93e4c84: PCI host bridge to bus 6512:00
[    2.789774] init: (1) WARNING: mount: waiting for virtio device...
[    2.790068] pci_bus 6512:00: root bus resource [mem 0x9ffe0c000-0x9ffe0efff window]
[    2.790613] pci_bus 6512:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.791858] pci 6512:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.792992] pci 6512:00:00.0: reg 0x10: [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.793834] pci 6512:00:00.0: reg 0x18: [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.794694] pci 6512:00:00.0: reg 0x20: [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.798621] pci_bus 6512:00: busn_res: [bus 00-ff] end is updated to 00
[    2.798961] pci 6512:00:00.0: BAR 0: assigned [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.799695] pci 6512:00:00.0: BAR 2: assigned [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.800416] pci 6512:00:00.0: BAR 4: assigned [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.895193] hv_pci 4fae7a25-5e7f-42d1-8a8f-7e1eb4128529: PCI VMBus probing: Using version 0x10004
[    2.896654] hv_pci 4fae7a25-5e7f-42d1-8a8f-7e1eb4128529: PCI host bridge to bus 5e7f:00
[    2.897036] pci_bus 5e7f:00: root bus resource [mem 0x9ffe10000-0x9ffe12fff window]
[    2.897405] pci_bus 5e7f:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.898729] pci 5e7f:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.900002] pci 5e7f:00:00.0: reg 0x10: [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.900885] pci 5e7f:00:00.0: reg 0x18: [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.901753] pci 5e7f:00:00.0: reg 0x20: [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    2.905797] pci_bus 5e7f:00: busn_res: [bus 00-ff] end is updated to 00
[    2.906134] pci 5e7f:00:00.0: BAR 0: assigned [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.906894] pci 5e7f:00:00.0: BAR 2: assigned [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.907627] pci 5e7f:00:00.0: BAR 4: assigned [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    3.077268] hv_pci 98cd7659-96ca-4b6a-95f7-0896075bc081: PCI VMBus probing: Using version 0x10004
[    3.078351] 9pnet_virtio: no channels available for device drvfs
[    3.078666] init: (1) WARNING: mount: waiting for virtio device...
[    3.078865] hv_pci 98cd7659-96ca-4b6a-95f7-0896075bc081: PCI host bridge to bus 96ca:00
[    3.079411] pci_bus 96ca:00: root bus resource [mem 0x9ffe14000-0x9ffe16fff window]
[    3.079774] pci_bus 96ca:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.081309] pci 96ca:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.082647] pci 96ca:00:00.0: reg 0x10: [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.083650] pci 96ca:00:00.0: reg 0x18: [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.084634] pci 96ca:00:00.0: reg 0x20: [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.088677] pci_bus 96ca:00: busn_res: [bus 00-ff] end is updated to 00
[    3.089026] pci 96ca:00:00.0: BAR 0: assigned [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.089905] pci 96ca:00:00.0: BAR 2: assigned [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.090676] pci 96ca:00:00.0: BAR 4: assigned [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.183923] hv_pci d00b62d9-165b-4f27-8533-5d0402fb00d8: PCI VMBus probing: Using version 0x10004
[    3.185457] hv_pci d00b62d9-165b-4f27-8533-5d0402fb00d8: PCI host bridge to bus 165b:00
[    3.185861] pci_bus 165b:00: root bus resource [mem 0x9ffe18000-0x9ffe1afff window]
[    3.185908] 9pnet_virtio: no channels available for device drvfs
[    3.186186] pci_bus 165b:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.186580] init: (1) WARNING: mount: waiting for virtio device...
[    3.187888] pci 165b:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.189081] pci 165b:00:00.0: reg 0x10: [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.189964] pci 165b:00:00.0: reg 0x18: [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.190841] pci 165b:00:00.0: reg 0x20: [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.194800] pci_bus 165b:00: busn_res: [bus 00-ff] end is updated to 00
[    3.195067] pci 165b:00:00.0: BAR 0: assigned [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.195787] pci 165b:00:00.0: BAR 2: assigned [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.196517] pci 165b:00:00.0: BAR 4: assigned [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.292120] hv_pci ff437ee8-6a13-4119-800a-411d24b930e4: PCI VMBus probing: Using version 0x10004
[    3.293643] hv_pci ff437ee8-6a13-4119-800a-411d24b930e4: PCI host bridge to bus 6a13:00
[    3.294135] pci_bus 6a13:00: root bus resource [mem 0x9ffe1c000-0x9ffe1efff window]
[    3.294500] pci_bus 6a13:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.295857] pci 6a13:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.297136] pci 6a13:00:00.0: reg 0x10: [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.298009] pci 6a13:00:00.0: reg 0x18: [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.298981] pci 6a13:00:00.0: reg 0x20: [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[    3.303144] pci_bus 6a13:00: busn_res: [bus 00-ff] end is updated to 00
[    3.303421] pci 6a13:00:00.0: BAR 0: assigned [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.304141] pci 6a13:00:00.0: BAR 2: assigned [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.304851] pci 6a13:00:00.0: BAR 4: assigned [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[   49.723597] hv_balloon: Max. dynamic memory size: 16384 MB

[-- Attachment #3: bad.log --]
[-- Type: text/plain, Size: 34554 bytes --]

# cat /sys/kernel/debug/swiotlb/io_tlb_nslabs
32768

# dmesg
[    0.000000] Linux version 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 (nathan@dev-arch.thelio-3990X) (gcc (GCC) 12.1.0, GNU ld (GNU Binutils) 2.38) #1 SMP PREEMPT_DYNAMIC Wed Jun 1 10:41:21 MST 2022
[    0.000000] Command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 1776
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000e0fff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000001fffff] ACPI data
[    0.000000] BIOS-e820: [mem 0x0000000000200000-0x00000000f7ffffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000100000000-0x0000000407ffffff] usable
[    0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '115200')
[    0.000000] printk: bootconsole [uart8250] enabled
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI not present or invalid.
[    0.000000] Hypervisor detected: Microsoft Hyper-V
[    0.000000] Hyper-V: privilege flags low 0xae7f, high 0x3b8030, hints 0xc2c, misc 0xe0bed7b6
[    0.000000] Hyper-V: Host Build 10.0.22000.708-0-0
[    0.000000] Hyper-V: Nested features: 0x4a0000
[    0.000000] Hyper-V: LAPIC Timer Frequency: 0x1e8480
[    0.000000] Hyper-V: Using hypercall for remote TLB flush
[    0.000000] clocksource: hyperv_clocksource_tsc_page: mask: 0xffffffffffffffff max_cycles: 0x24e6a1710, max_idle_ns: 440795202120 ns
[    0.000003] tsc: Detected 3800.008 MHz processor
[    0.001844] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.004500] e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.006752] last_pfn = 0x408000 max_arch_pfn = 0x400000000
[    0.008928] x86/PAT: Configuration [0-7]: WB  WC  UC- UC  WB  WP  UC- WT  
[    0.011617] last_pfn = 0xf8000 max_arch_pfn = 0x400000000
[    0.013721] Using GB pages for direct mapping
[    0.015504] RAMDISK: [mem 0x0371f000-0x03779fff]
[    0.017288] ACPI: Early table checksum verification disabled
[    0.019511] ACPI: RSDP 0x00000000000E0000 000024 (v02 VRTUAL)
[    0.021806] ACPI: XSDT 0x0000000000100000 000044 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.025255] ACPI: FACP 0x0000000000101000 000114 (v06 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.028644] ACPI: DSDT 0x00000000001011B8 01E184 (v02 MSFTVM DSDT01   00000001 MSFT 05000000)
[    0.032074] ACPI: FACS 0x0000000000101114 000040
[    0.033876] ACPI: OEM0 0x0000000000101154 000064 (v01 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.037335] ACPI: SRAT 0x000000000011F33C 000330 (v02 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.040839] ACPI: APIC 0x000000000011F66C 000088 (v04 VRTUAL MICROSFT 00000001 MSFT 00000001)
[    0.044205] ACPI: Reserving FACP table memory at [mem 0x101000-0x101113]
[    0.046856] ACPI: Reserving DSDT table memory at [mem 0x1011b8-0x11f33b]
[    0.049526] ACPI: Reserving FACS table memory at [mem 0x101114-0x101153]
[    0.052323] ACPI: Reserving OEM0 table memory at [mem 0x101154-0x1011b7]
[    0.054916] ACPI: Reserving SRAT table memory at [mem 0x11f33c-0x11f66b]
[    0.057563] ACPI: Reserving APIC table memory at [mem 0x11f66c-0x11f6f3]
[    0.060644] Zone ranges:
[    0.061621]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.064031]   DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
[    0.066551]   Normal   [mem 0x0000000100000000-0x0000000407ffffff]
[    0.069096]   Device   empty
[    0.070236] Movable zone start for each node
[    0.071880] Early memory node ranges
[    0.073323]   node   0: [mem 0x0000000000001000-0x000000000009ffff]
[    0.075736]   node   0: [mem 0x0000000000200000-0x00000000f7ffffff]
[    0.078260]   node   0: [mem 0x0000000100000000-0x0000000407ffffff]
[    0.080698] Initmem setup node 0 [mem 0x0000000000001000-0x0000000407ffffff]
[    0.083706] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.083724] On node 0, zone DMA: 352 pages in unavailable ranges
[    0.095850] ACPI: LAPIC_NMI (acpi_id[0x01] dfl dfl lint[0x1])
[    0.100817] IOAPIC[0]: apic_id 8, version 17, address 0xfec00000, GSI 0-23
[    0.103601] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[    0.106156] ACPI: Using ACPI (MADT) for SMP configuration information
[    0.108743] smpboot: Allowing 8 CPUs, 0 hotplug CPUs
[    0.110810] [mem 0xf8000000-0xffffffff] available for PCI devices
[    0.113193] Booting paravirtualized kernel on Hyper-V
[    0.115221] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.124086] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:8 nr_node_ids:1
[    0.127620] percpu: Embedded 53 pages/cpu s178408 r8192 d30488 u262144
[    0.130204] pcpu-alloc: s178408 r8192 d30488 u262144 alloc=1*2097152
[    0.132746] pcpu-alloc: [0] 0 1 2 3 4 5 6 7 
[    0.134452] Hyper-V: PV spinlocks enabled
[    0.136082] PV qspinlock hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.138923] Built 1 zonelists, mobility grouping on.  Total pages: 4127749
[    0.141669] Kernel command line: initrd=\initrd.img panic=-1 nr_cpus=8 swiotlb=force earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0
[    0.149809] Dentry cache hash table entries: 2097152 (order: 12, 16777216 bytes, linear)
[    0.154232] Inode-cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.157400] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.182296] Memory: 4126096K/16775804K available (18449K kernel code, 2647K rwdata, 3952K rodata, 1536K init, 2448K bss, 392692K reserved, 0K cma-reserved)
[    0.188084] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
[    0.190824] ftrace: allocating 51788 entries in 203 pages
[    0.199397] ftrace: allocated 203 pages with 5 groups
[    0.202320] Dynamic Preempt: none
[    0.203777] rcu: Preemptible hierarchical RCU implementation.
[    0.206055] rcu: 	RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=8.
[    0.208807] 	Trampoline variant of Tasks RCU enabled.
[    0.210844] 	Rude variant of Tasks RCU enabled.
[    0.213292] 	Tracing variant of Tasks RCU enabled.
[    0.215445] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[    0.218380] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=8
[    0.224306] Using NULL legacy PIC
[    0.225589] NR_IRQS: 16640, nr_irqs: 488, preallocated irqs: 0
[    0.228245] random: crng init done (trusting CPU's manufacturer)
[    0.230636] Console: colour dummy device 80x25
[    0.232438] ACPI: Core revision 20211217
[    0.234033] Failed to register legacy timer interrupt
[    0.236047] APIC: Switch to symmetric I/O mode setup
[    0.238014] Hyper-V: enabling crash_kexec_post_notifiers
[    0.240107] Hyper-V: Using IPI hypercalls
[    0.241666] Hyper-V: Using enlightened APIC (xapic mode)
[    0.241757] clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    0.247930] Calibrating delay loop (skipped), value calculated using timer frequency.. 7600.01 BogoMIPS (lpj=38000080)
[    0.252067] pid_max: default: 32768 minimum: 301
[    0.253895] LSM: Security Framework initializing
[    0.255751] Mount-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.257927] Mountpoint-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.257927] x86/cpu: User Mode Instruction Prevention (UMIP) activated
[    0.257927] Last level iTLB entries: 4KB 1024, 2MB 1024, 4MB 512
[    0.257927] Last level dTLB entries: 4KB 2048, 2MB 2048, 4MB 1024, 1GB 0
[    0.257927] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.257927] Spectre V2 : Mitigation: Retpolines
[    0.257927] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
[    0.257927] Spectre V2 : mitigation: Enabling conditional Indirect Branch Prediction Barrier
[    0.257927] Spectre V2 : User space: Mitigation: STIBP via prctl
[    0.257927] Speculative Store Bypass: Mitigation: Speculative Store Bypass disabled via prctl
[    0.257927] Freeing SMP alternatives memory: 56K
[    0.257927] smpboot: CPU0: AMD Ryzen 9 3900X 12-Core Processor (family: 0x17, model: 0x71, stepping: 0x0)
[    0.257927] cblist_init_generic: Setting adjustable number of callback queues.
[    0.257927] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.257927] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.257953] cblist_init_generic: Setting shift to 3 and lim to 1.
[    0.260344] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[    0.262870] ... version:                0
[    0.264433] ... bit width:              48
[    0.266024] ... generic registers:      6
[    0.267586] ... value mask:             0000ffffffffffff
[    0.267931] ... max period:             00007fffffffffff
[    0.269978] ... fixed-purpose events:   0
[    0.271549] ... event mask:             000000000000003f
[    0.273693] rcu: Hierarchical SRCU implementation.
[    0.275947] smp: Bringing up secondary CPUs ...
[    0.277746] x86: Booting SMP configuration:
[    0.277931] .... node  #0, CPUs:      #1 #2 #3 #4 #5 #6 #7
[    0.278598] smp: Brought up 1 node, 8 CPUs
[    0.281786] smpboot: Max logical packages: 1
[    0.283442] smpboot: Total of 8 processors activated (60800.12 BogoMIPS)
[    0.297948] node 0 deferred pages initialised in 10ms
[    0.300095] devtmpfs: initialized
[    0.300095] x86/mm: Memory block size: 128MB
[    0.301372] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.307950] futex hash table entries: 2048 (order: 5, 131072 bytes, linear)
[    0.311117] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.313590] thermal_sys: Registered thermal governor 'step_wise'
[    0.313591] thermal_sys: Registered thermal governor 'user_space'
[    0.315970] cpuidle: using governor menu
[    0.317983] PCI: Fatal: No config space access function found
[    0.321181] kprobes: kprobe jump-optimization is enabled. All kprobes are optimized if possible.
[    0.321181] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[    0.321181] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[    0.327982] raid6: skipped pq benchmark and selected avx2x4
[    0.330080] raid6: using avx2x2 recovery algorithm
[    0.331916] ACPI: Added _OSI(Module Device)
[    0.337945] ACPI: Added _OSI(Processor Device)
[    0.339664] ACPI: Added _OSI(3.0 _SCP Extensions)
[    0.341472] ACPI: Added _OSI(Processor Aggregator Device)
[    0.343581] ACPI: Added _OSI(Linux-Dell-Video)
[    0.345290] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[    0.347310] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)
[    0.351846] ACPI: 1 ACPI AML tables successfully acquired and loaded
[    0.354878] ACPI: Interpreter enabled
[    0.357948] ACPI: PM: (supports S0 S5)
[    0.359386] ACPI: Using IOAPIC for interrupt routing
[    0.361295] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
[    0.364875] ACPI: Enabled 1 GPEs in block 00 to 0F
[    0.367281] iommu: Default domain type: Translated 
[    0.367930] iommu: DMA domain TLB invalidation policy: lazy mode 
[    0.370342] SCSI subsystem initialized
[    0.371819] ACPI: bus type USB registered
[    0.373384] usbcore: registered new interface driver usbfs
[    0.375508] usbcore: registered new interface driver hub
[    0.377556] usbcore: registered new device driver usb
[    0.378007] hv_vmbus: Vmbus version:5.2
[    0.379525] PCI: Using ACPI for IRQ routing
[    0.381148] PCI: System does not support PCI
[    0.382985] hv_vmbus: Unknown GUID: c376c1c3-d276-48d2-90a9-c04748072c60
[    0.385656] hv_vmbus: Unknown GUID: 6e382d18-3336-4f4b-acc4-2b7703d4df4a
[    0.385656] hv_vmbus: Unknown GUID: dde9cbc0-5060-4436-9448-ea1254a5d177
[    0.385656] clocksource: Switched to clocksource tsc-early
[    0.395132] VFS: Disk quotas dquot_6.6.0
[    0.398629] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.401503] FS-Cache: Loaded
[    0.402695] pnp: PnP ACPI init
[    0.403992] pnp: PnP ACPI: found 3 devices
[    0.409671] NET: Registered PF_INET protocol family
[    0.411938] IP idents hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.416026] tcp_listen_portaddr_hash hash table entries: 8192 (order: 5, 131072 bytes, linear)
[    0.419575] TCP established hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.423230] TCP bind hash table entries: 65536 (order: 8, 1048576 bytes, linear)
[    0.426347] TCP: Hash tables configured (established 131072 bind 65536)
[    0.429190] UDP hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.432209] UDP-Lite hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.435648] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.438375] RPC: Registered named UNIX socket transport module.
[    0.440789] RPC: Registered udp transport module.
[    0.442671] RPC: Registered tcp transport module.
[    0.444673] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.447332] PCI: CLS 0 bytes, default 64
[    0.448993] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[    0.449028] Trying to unpack rootfs image as initramfs...
[    0.451710] software IO TLB: mapped [mem 0x00000000f4000000-0x00000000f8000000] (64MB)
[    0.454079] Freeing initrd memory: 364K
[    0.541430] kvm: no hardware support for 'kvm_intel'
[    0.543753] SVM: TSC scaling supported
[    0.545214] kvm: Nested Virtualization enabled
[    0.546939] SVM: kvm: Nested Paging enabled
[    0.548655] SVM: kvm: Hyper-V enlightened NPT TLB flush enabled
[    0.550982] SVM: kvm: Hyper-V Direct TLB Flush enabled
[    0.553055] SVM: Virtual VMLOAD VMSAVE supported
[    0.619230] Initialise system trusted keyrings
[    0.621148] workingset: timestamp_bits=46 max_order=22 bucket_order=0
[    0.624304] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.626917] NFS: Registering the id_resolver key type
[    0.628911] Key type id_resolver registered
[    0.630622] Key type id_legacy registered
[    0.632252] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.635096] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    0.638073] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[    0.641200] Key type cifs.idmap registered
[    0.642865] fuse: init (API version 7.36)
[    0.644622] SGI XFS with ACLs, security attributes, realtime, scrub, repair, quota, no debug enabled
[    0.648593] 9p: Installing v9fs 9p2000 file system support
[    0.650987] ceph: loaded (mds proto 32)
[    0.654860] NET: Registered PF_ALG protocol family
[    0.656711] xor: automatically using best checksumming function   avx       
[    0.659472] Key type asymmetric registered
[    0.661072] Asymmetric key parser 'x509' registered
[    0.662976] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[    0.666333] hv_vmbus: registering driver hv_pci
[    0.668465] hv_pci a154a52e-df93-4a32-a470-37362af9092a: PCI VMBus probing: Using version 0x10004
[    0.672862] hv_pci a154a52e-df93-4a32-a470-37362af9092a: PCI host bridge to bus df93:00
[    0.675963] pci_bus df93:00: root bus resource [mem 0x9ffe00000-0x9ffe02fff window]
[    0.678965] pci_bus df93:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.683016] pci df93:00:00.0: [1af4:1043] type 00 class 0x010000
[    0.686425] pci df93:00:00.0: reg 0x10: [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.689851] pci df93:00:00.0: reg 0x18: [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.693249] pci df93:00:00.0: reg 0x20: [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.698971] pci_bus df93:00: busn_res: [bus 00-ff] end is updated to 00
[    0.701554] pci df93:00:00.0: BAR 0: assigned [mem 0x9ffe00000-0x9ffe00fff 64bit]
[    0.704894] pci df93:00:00.0: BAR 2: assigned [mem 0x9ffe01000-0x9ffe01fff 64bit]
[    0.708243] pci df93:00:00.0: BAR 4: assigned [mem 0x9ffe02000-0x9ffe02fff 64bit]
[    0.711877] hv_pci ca66d0fe-4477-439b-9d67-02d7bd2dcb05: PCI VMBus probing: Using version 0x10004
[    0.716001] hv_pci ca66d0fe-4477-439b-9d67-02d7bd2dcb05: PCI host bridge to bus 4477:00
[    0.719136] pci_bus 4477:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.722586] pci 4477:00:00.0: [1414:008e] type 00 class 0x030200
[    0.729016] pci_bus 4477:00: busn_res: [bus 00-ff] end is updated to 00
[    0.731822] hv_pci c42c9658-a709-40bd-8d72-5ee9b78e28ca: PCI VMBus probing: Using version 0x10004
[    0.736240] hv_pci c42c9658-a709-40bd-8d72-5ee9b78e28ca: PCI host bridge to bus a709:00
[    0.739381] pci_bus a709:00: root bus resource [mem 0x9ffe04000-0x9ffe06fff window]
[    0.742368] pci_bus a709:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.746437] pci a709:00:00.0: [1af4:1049] type 00 class 0x010000
[    0.749663] pci a709:00:00.0: reg 0x10: [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.752975] pci a709:00:00.0: reg 0x18: [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.756273] pci a709:00:00.0: reg 0x20: [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.762929] pci_bus a709:00: busn_res: [bus 00-ff] end is updated to 00
[    0.765585] pci a709:00:00.0: BAR 0: assigned [mem 0x9ffe04000-0x9ffe04fff 64bit]
[    0.769014] pci a709:00:00.0: BAR 2: assigned [mem 0x9ffe05000-0x9ffe05fff 64bit]
[    0.772436] pci a709:00:00.0: BAR 4: assigned [mem 0x9ffe06000-0x9ffe06fff 64bit]
[    0.784024] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.786788] 00:00: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    0.790004] 00:01: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[    0.828478] Non-volatile memory driver v1.3
[    0.830180] printk: console [hvc0] enabled
[    0.831804] printk: bootconsole [uart8250] disabled
[    0.835700] brd: module loaded
[    0.836692] loop: module loaded
[    0.836890] hv_vmbus: registering driver hv_storvsc
[    0.837466] wireguard: WireGuard 1.0.0 loaded. See www.wireguard.com for information.
[    0.837853] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
[    0.838217] scsi host0: storvsc_host_t
[    0.838399] tun: Universal TUN/TAP device driver, 1.6
[    0.838812] PPP generic driver version 2.4.2
[    0.839159] PPP BSD Compression module registered
[    0.839395] PPP Deflate Compression module registered
[    0.839781] PPP MPPE Compression module registered
[    0.840046] NET: Registered PF_PPPOX protocol family
[    0.840326] usbcore: registered new interface driver cdc_ether
[    0.840687] usbcore: registered new interface driver cdc_ncm
[    0.841009] hv_vmbus: registering driver hv_netvsc
[    0.841331] VFIO - User Level meta-driver version: 0.3
[    0.841707] usbcore: registered new interface driver cdc_acm
[    0.841999] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[    0.842346] usbcore: registered new interface driver ch341
[    0.842613] usbserial: USB Serial support registered for ch341-uart
[    0.842907] usbcore: registered new interface driver cp210x
[    0.843226] usbserial: USB Serial support registered for cp210x
[    0.843574] usbcore: registered new interface driver ftdi_sio
[    0.843874] usbserial: USB Serial support registered for FTDI USB Serial Device
[    0.844325] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.844630] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 1
[    0.844968] vhci_hcd: created sysfs vhci_hcd.0
[    0.845394] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.18
[    0.845749] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.846033] usb usb1: Product: USB/IP Virtual Host Controller
[    0.846274] usb usb1: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 vhci_hcd
[    0.846606] usb usb1: SerialNumber: vhci_hcd.0
[    0.846887] hub 1-0:1.0: USB hub found
[    0.847077] hub 1-0:1.0: 8 ports detected
[    0.847565] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[    0.847828] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 2
[    0.848246] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[    0.848690] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.18
[    0.848997] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.849279] usb usb2: Product: USB/IP Virtual Host Controller
[    0.849523] usb usb2: Manufacturer: Linux 5.18.0-rc3-microsoft-standard-WSL2-00009-gc6af2aa9ffc9 vhci_hcd
[    0.849855] usb usb2: SerialNumber: vhci_hcd.0
[    0.850138] hub 2-0:1.0: USB hub found
[    0.850333] hub 2-0:1.0: 8 ports detected
[    0.850772] hv_vmbus: registering driver hyperv_keyboard
[    0.851119] rtc_cmos 00:02: RTC can wake from S4
[    0.853017] rtc_cmos 00:02: registered as rtc0
[    0.853536] rtc_cmos 00:02: setting system clock to 2022-06-01T17:41:59 UTC (1654105319)
[    0.853854] rtc_cmos 00:02: alarms up to one month, 114 bytes nvram
[    0.854249] device-mapper: ioctl: 4.46.0-ioctl (2022-02-22) initialised: dm-devel@redhat.com
[    0.854710] device-mapper: raid: Loading target version 1.15.1
[    0.855003] usbcore: registered new interface driver usbhid
[    0.855198] usbhid: USB HID core driver
[    0.855394] hv_utils: Registering HyperV Utility Driver
[    0.855608] hv_vmbus: registering driver hv_utils
[    0.855910] hv_vmbus: registering driver hv_balloon
[    0.855914] hv_utils: cannot register PTP clock: 0
[    0.856165] drop_monitor: Initializing network drop monitor service
[    0.856597] hv_balloon: Using Dynamic Memory protocol version 2.0
[    0.856611] hv_utils: TimeSync IC version 4.0
[    0.856742] Mirror/redirect action on
[    0.857542] Free page reporting enabled
[    0.857744] hv_balloon: Cold memory discard hint enabled
[    0.858304] IPVS: Registered protocols (TCP, UDP)
[    0.858534] IPVS: Connection hash table configured (size=4096, memory=64Kbytes)
[    0.858872] IPVS: ipvs loaded.
[    0.859018] IPVS: [rr] scheduler registered.
[    0.859213] IPVS: [wrr] scheduler registered.
[    0.859405] IPVS: [sh] scheduler registered.
[    0.859622] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    0.860047] ipt_CLUSTERIP: ClusterIP Version 0.8 loaded successfully
[    0.860293] Initializing XFRM netlink socket
[    0.860522] NET: Registered PF_INET6 protocol family
[    0.861019] Segment Routing with IPv6
[    0.861193] In-situ OAM (IOAM) with IPv6
[    0.861362] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    0.861655] NET: Registered PF_PACKET protocol family
[    0.861875] Bridge firewalling registered
[    0.862024] 8021q: 802.1Q VLAN Support v1.8
[    0.862189] sctp: Hash tables configured (bind 256/256)
[    0.862419] 9pnet: Installing 9P2000 support
[    0.874428] Key type dns_resolver registered
[    0.874663] Key type ceph registered
[    0.874921] libceph: loaded (mon/osd proto 15/24)
[    0.875208] NET: Registered PF_VSOCK protocol family
[    0.875419] hv_vmbus: registering driver hv_sock
[    0.875644] IPI shorthand broadcast: enabled
[    0.875840] sched_clock: Marking stable (855501109, 19696300)->(934890300, -59692891)
[    0.876403] registered taskstats version 1
[    0.876928] Loading compiled-in X.509 certificates
[    0.877333] Btrfs loaded, crc32c=crc32c-generic, zoned=no, fsverity=no
[    0.882685] Freeing unused kernel image (initmem) memory: 1536K
[    0.918057] Write protecting the kernel read-only data: 24576k
[    0.918975] Freeing unused kernel image (text/rodata gap) memory: 2028K
[    0.919393] Freeing unused kernel image (rodata/data gap) memory: 144K
[    0.919654] Run /init as init process
[    0.919798]   with arguments:
[    0.919940]     /init
[    0.920047]   with environment:
[    0.920190]     HOME=/
[    0.920286]     TERM=linux
[    0.922620] scsi 0:0:0:0: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    0.923252] sd 0:0:0:0: Attached scsi generic sg0 type 0
[    0.923893] sd 0:0:0:0: [sda] 641944 512-byte logical blocks: (329 MB/313 MiB)
[    0.924490] sd 0:0:0:0: [sda] Write Protect is on
[    0.924760] sd 0:0:0:0: [sda] Mode Sense: 0f 00 80 00
[    0.925199] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[    1.538410] EXT4-fs (sda): mounted filesystem without journal. Quota mode: none.
[    1.640080] hv_pci 88309164-1127-4233-9560-6e0cad455d8f: PCI VMBus probing: Using version 0x10004
[    1.642187] hv_pci 88309164-1127-4233-9560-6e0cad455d8f: PCI host bridge to bus 1127:00
[    1.642548] pci_bus 1127:00: root bus resource [mem 0xa00000000-0xc00001fff window]
[    1.642895] pci_bus 1127:00: No busn resource found for root bus, will use [bus 00-ff]
[    1.644287] pci 1127:00:00.0: [1af4:105a] type 00 class 0x088000
[    1.647194] pci 1127:00:00.0: reg 0x10: [mem 0xc00000000-0xc00000fff 64bit]
[    1.649501] pci 1127:00:00.0: reg 0x18: [mem 0xc00001000-0xc00001fff 64bit]
[    1.651514] pci 1127:00:00.0: reg 0x20: [mem 0xa00000000-0xbffffffff 64bit]
[    1.656603] pci_bus 1127:00: busn_res: [bus 00-ff] end is updated to 00
[    1.656902] pci 1127:00:00.0: BAR 4: assigned [mem 0xa00000000-0xbffffffff 64bit]
[    1.658754] pci 1127:00:00.0: BAR 0: assigned [mem 0xc00000000-0xc00000fff 64bit]
[    1.660797] pci 1127:00:00.0: BAR 2: assigned [mem 0xc00001000-0xc00001fff 64bit]
[    1.676734] virtiofs virtio2: Cache len: 0x200000000 @ 0xa00000000
[    1.687964] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x6d8cbf8869f, max_idle_ns: 881590921691 ns
[    1.688537] clocksource: Switched to clocksource tsc
[    1.718131] sd 0:0:0:0: [sda] Attached SCSI disk
[    1.737024] memmap_init_zone_device initialised 2097152 pages in 10ms
[    1.738457] WSL2: SetEphemeralPortRange is a no-op : range (0, 0)
[    1.847973] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    2.418129] scsi 0:0:0:1: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.418887] sd 0:0:0:1: Attached scsi generic sg1 type 0
[    2.419446] scsi 0:0:0:2: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 5
[    2.419498] sd 0:0:0:1: [sdb] 2097160 512-byte logical blocks: (1.07 GB/1.00 GiB)
[    2.420146] sd 0:0:0:2: Attached scsi generic sg2 type 0
[    2.420236] sd 0:0:0:1: [sdb] 4096-byte physical blocks
[    2.420789] sd 0:0:0:2: [sdc] 536870912 512-byte logical blocks: (275 GB/256 GiB)
[    2.420849] sd 0:0:0:1: [sdb] Write Protect is off
[    2.421225] sd 0:0:0:2: [sdc] 4096-byte physical blocks
[    2.421541] sd 0:0:0:1: [sdb] Mode Sense: 0f 00 00 00
[    2.421888] sd 0:0:0:2: [sdc] Write Protect is off
[    2.422260] sd 0:0:0:1: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.422392] sd 0:0:0:2: [sdc] Mode Sense: 0f 00 00 00
[    2.423302] sd 0:0:0:2: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.424840] sd 0:0:0:1: [sdb] Attached SCSI disk
[    2.426063] sd 0:0:0:2: [sdc] Attached SCSI disk
[    2.444484] EXT4-fs (sdc): recovery complete
[    2.445457] EXT4-fs (sdc): mounted filesystem with ordered data mode. Quota mode: none.
[    2.459372] Adding 1048576k swap on /dev/sdb.  Priority:-2 extents:1 across:1048576k 
[    2.649008] hv_pci aed388e8-de3a-45a5-bb0c-ee534e806689: PCI VMBus probing: Using version 0x10004
[    2.650439] hv_pci aed388e8-de3a-45a5-bb0c-ee534e806689: PCI host bridge to bus de3a:00
[    2.650756] pci_bus de3a:00: root bus resource [mem 0x9ffe08000-0x9ffe0afff window]
[    2.651045] pci_bus de3a:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.652320] pci de3a:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.653496] pci de3a:00:00.0: reg 0x10: [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.654363] pci de3a:00:00.0: reg 0x18: [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.655227] pci de3a:00:00.0: reg 0x20: [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.659234] pci_bus de3a:00: busn_res: [bus 00-ff] end is updated to 00
[    2.659501] pci de3a:00:00.0: BAR 0: assigned [mem 0x9ffe08000-0x9ffe08fff 64bit]
[    2.660251] pci de3a:00:00.0: BAR 2: assigned [mem 0x9ffe09000-0x9ffe09fff 64bit]
[    2.660989] pci de3a:00:00.0: BAR 4: assigned [mem 0x9ffe0a000-0x9ffe0afff 64bit]
[    2.663932] 9pnet_virtio: no channels available for device drvfs
[    2.664237] init: (1) WARNING: mount: waiting for virtio device...
[    2.770766] hv_pci 81d9a8d7-9fce-46b7-9ff9-b146da3089e4: PCI VMBus probing: Using version 0x10004
[    2.772061] hv_pci 81d9a8d7-9fce-46b7-9ff9-b146da3089e4: PCI host bridge to bus 9fce:00
[    2.772372] pci_bus 9fce:00: root bus resource [mem 0x9ffe0c000-0x9ffe0efff window]
[    2.772664] pci_bus 9fce:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.773910] pci 9fce:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.775050] pci 9fce:00:00.0: reg 0x10: [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.775911] pci 9fce:00:00.0: reg 0x18: [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.776761] pci 9fce:00:00.0: reg 0x20: [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.780694] pci_bus 9fce:00: busn_res: [bus 00-ff] end is updated to 00
[    2.780986] pci 9fce:00:00.0: BAR 0: assigned [mem 0x9ffe0c000-0x9ffe0cfff 64bit]
[    2.781703] pci 9fce:00:00.0: BAR 2: assigned [mem 0x9ffe0d000-0x9ffe0dfff 64bit]
[    2.781986] 9pnet_virtio: no channels available for device drvfs
[    2.782311] init: (1) WARNING: mount: waiting for virtio device...
[    2.782471] pci 9fce:00:00.0: BAR 4: assigned [mem 0x9ffe0e000-0x9ffe0efff 64bit]
[    2.898491] hv_pci 86858b54-a9ff-42c1-85be-12646bde6957: PCI VMBus probing: Using version 0x10004
[    2.899831] hv_pci 86858b54-a9ff-42c1-85be-12646bde6957: PCI host bridge to bus a9ff:00
[    2.900148] pci_bus a9ff:00: root bus resource [mem 0x9ffe10000-0x9ffe12fff window]
[    2.900437] pci_bus a9ff:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.901684] pci a9ff:00:00.0: [1af4:1049] type 00 class 0x010000
[    2.902856] pci a9ff:00:00.0: reg 0x10: [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.903716] pci a9ff:00:00.0: reg 0x18: [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.904609] pci a9ff:00:00.0: reg 0x20: [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    2.908519] pci_bus a9ff:00: busn_res: [bus 00-ff] end is updated to 00
[    2.908842] pci a9ff:00:00.0: BAR 0: assigned [mem 0x9ffe10000-0x9ffe10fff 64bit]
[    2.909600] pci a9ff:00:00.0: BAR 2: assigned [mem 0x9ffe11000-0x9ffe11fff 64bit]
[    2.910335] pci a9ff:00:00.0: BAR 4: assigned [mem 0x9ffe12000-0x9ffe12fff 64bit]
[    3.009967] hv_pci 14a6c250-2f5e-4544-972d-e4af992a128a: PCI VMBus probing: Using version 0x10004
[    3.011462] hv_pci 14a6c250-2f5e-4544-972d-e4af992a128a: PCI host bridge to bus 2f5e:00
[    3.011804] pci_bus 2f5e:00: root bus resource [mem 0x9ffe14000-0x9ffe16fff window]
[    3.012172] pci_bus 2f5e:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.013562] pci 2f5e:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.014756] pci 2f5e:00:00.0: reg 0x10: [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.015633] pci 2f5e:00:00.0: reg 0x18: [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.016516] pci 2f5e:00:00.0: reg 0x20: [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.020834] pci_bus 2f5e:00: busn_res: [bus 00-ff] end is updated to 00
[    3.021157] pci 2f5e:00:00.0: BAR 0: assigned [mem 0x9ffe14000-0x9ffe14fff 64bit]
[    3.022095] pci 2f5e:00:00.0: BAR 2: assigned [mem 0x9ffe15000-0x9ffe15fff 64bit]
[    3.022867] pci 2f5e:00:00.0: BAR 4: assigned [mem 0x9ffe16000-0x9ffe16fff 64bit]
[    3.030227] 9pnet_virtio: no channels available for device drvfs
[    3.030578] init: (1) WARNING: mount: waiting for virtio device...
[    3.143192] hv_pci ed843176-e057-48d4-ab94-623a027b1629: PCI VMBus probing: Using version 0x10004
[    3.144600] hv_pci ed843176-e057-48d4-ab94-623a027b1629: PCI host bridge to bus e057:00
[    3.144927] pci_bus e057:00: root bus resource [mem 0x9ffe18000-0x9ffe1afff window]
[    3.145222] pci_bus e057:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.146529] pci e057:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.147766] pci e057:00:00.0: reg 0x10: [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.148685] pci e057:00:00.0: reg 0x18: [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.149556] pci e057:00:00.0: reg 0x20: [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.153686] pci_bus e057:00: busn_res: [bus 00-ff] end is updated to 00
[    3.154060] pci e057:00:00.0: BAR 0: assigned [mem 0x9ffe18000-0x9ffe18fff 64bit]
[    3.154855] pci e057:00:00.0: BAR 2: assigned [mem 0x9ffe19000-0x9ffe19fff 64bit]
[    3.155592] pci e057:00:00.0: BAR 4: assigned [mem 0x9ffe1a000-0x9ffe1afff 64bit]
[    3.188714] hv_pci c963c476-4546-43da-a32c-7e4ddeb55d93: PCI VMBus probing: Using version 0x10004
[    3.190328] hv_pci c963c476-4546-43da-a32c-7e4ddeb55d93: PCI host bridge to bus 4546:00
[    3.190732] pci_bus 4546:00: root bus resource [mem 0x9ffe1c000-0x9ffe1efff window]
[    3.191104] pci_bus 4546:00: No busn resource found for root bus, will use [bus 00-ff]
[    3.192578] pci 4546:00:00.0: [1af4:1049] type 00 class 0x010000
[    3.193870] pci 4546:00:00.0: reg 0x10: [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.194935] pci 4546:00:00.0: reg 0x18: [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.196022] pci 4546:00:00.0: reg 0x20: [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[    3.200503] pci_bus 4546:00: busn_res: [bus 00-ff] end is updated to 00
[    3.200855] pci 4546:00:00.0: BAR 0: assigned [mem 0x9ffe1c000-0x9ffe1cfff 64bit]
[    3.201736] pci 4546:00:00.0: BAR 2: assigned [mem 0x9ffe1d000-0x9ffe1dfff 64bit]
[    3.202501] pci 4546:00:00.0: BAR 4: assigned [mem 0x9ffe1e000-0x9ffe1efff 64bit]
[   49.723721] hv_balloon: Max. dynamic memory size: 16384 MB

[-- Attachment #4: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
  2022-06-01 17:46         ` Nathan Chancellor
                             ` (3 preceding siblings ...)
  (?)
@ 2022-06-01 17:57           ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 17:57 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > Can you send me the full dmesg and the content of
> > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> 
> Sure thing, they are attached! If there is anything else I can provide
> or test, I am more than happy to do so.

Nothing interesting.  But the performance numbers almost look like
swiotlb=force got ignored before (even if I can't explain why).
Do you get a similar performance with the new kernel without
swiotlb=force as the old one with that argument by any chance?


^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:57           ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 17:57 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > Can you send me the full dmesg and the content of
> > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> 
> Sure thing, they are attached! If there is anything else I can provide
> or test, I am more than happy to do so.

Nothing interesting.  But the performance numbers almost look like
swiotlb=force got ignored before (even if I can't explain why).
Do you get a similar performance with the new kernel without
swiotlb=force as the old one with that argument by any chance?


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:57           ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 17:57 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	Christoph Hellwig, linux-s390, Stefano Stabellini, Joerg Roedel,
	Konrad Rzeszutek Wilk, tboot-devel, xen-devel, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, linuxppc-dev, linux-mips, iommu,
	Robin Murphy, Lu Baolu

On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > Can you send me the full dmesg and the content of
> > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> 
> Sure thing, they are attached! If there is anything else I can provide
> or test, I am more than happy to do so.

Nothing interesting.  But the performance numbers almost look like
swiotlb=force got ignored before (even if I can't explain why).
Do you get a similar performance with the new kernel without
swiotlb=force as the old one with that argument by any chance?


^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:57           ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 17:57 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	Christoph Hellwig, linux-s390, Stefano Stabellini,
	Konrad Rzeszutek Wilk, tboot-devel, xen-devel, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, linuxppc-dev, linux-mips, iommu,
	Robin Murphy

On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > Can you send me the full dmesg and the content of
> > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> 
> Sure thing, they are attached! If there is anything else I can provide
> or test, I am more than happy to do so.

Nothing interesting.  But the performance numbers almost look like
swiotlb=force got ignored before (even if I can't explain why).
Do you get a similar performance with the new kernel without
swiotlb=force as the old one with that argument by any chance?

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:57           ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 17:57 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > Can you send me the full dmesg and the content of
> > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> 
> Sure thing, they are attached! If there is anything else I can provide
> or test, I am more than happy to do so.

Nothing interesting.  But the performance numbers almost look like
swiotlb=force got ignored before (even if I can't explain why).
Do you get a similar performance with the new kernel without
swiotlb=force as the old one with that argument by any chance?


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 17:57           ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 17:57 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > Can you send me the full dmesg and the content of
> > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> 
> Sure thing, they are attached! If there is anything else I can provide
> or test, I am more than happy to do so.

Nothing interesting.  But the performance numbers almost look like
swiotlb=force got ignored before (even if I can't explain why).
Do you get a similar performance with the new kernel without
swiotlb=force as the old one with that argument by any chance?

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
  2022-06-01 17:57           ` Christoph Hellwig
                               ` (3 preceding siblings ...)
  (?)
@ 2022-06-01 18:11             ` Nathan Chancellor
  -1 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 18:11 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > Can you send me the full dmesg and the content of
> > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > 
> > Sure thing, they are attached! If there is anything else I can provide
> > or test, I am more than happy to do so.
> 
> Nothing interesting.  But the performance numbers almost look like
> swiotlb=force got ignored before (even if I can't explain why).

I was able to get my performance back with this diff but I don't know if
this is a hack or a proper fix in the context of the series.

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dfa1de89dc94..0bfb2fe3d8c5 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -276,7 +276,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
+	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
 
 	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();

> Do you get a similar performance with the new kernel without
> swiotlb=force as the old one with that argument by any chance?

I'll see if I can test that, as I am not sure I have control over those
cmdline arguments.

Cheers,
Nathan

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:11             ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 18:11 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > Can you send me the full dmesg and the content of
> > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > 
> > Sure thing, they are attached! If there is anything else I can provide
> > or test, I am more than happy to do so.
> 
> Nothing interesting.  But the performance numbers almost look like
> swiotlb=force got ignored before (even if I can't explain why).

I was able to get my performance back with this diff but I don't know if
this is a hack or a proper fix in the context of the series.

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dfa1de89dc94..0bfb2fe3d8c5 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -276,7 +276,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
+	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
 
 	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();

> Do you get a similar performance with the new kernel without
> swiotlb=force as the old one with that argument by any chance?

I'll see if I can test that, as I am not sure I have control over those
cmdline arguments.

Cheers,
Nathan

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:11             ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 18:11 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Konrad Rzeszutek Wilk,
	tboot-devel, xen-devel, David Woodhouse, Tom Lendacky,
	Anshuman Khandual, Boris Ostrovsky, linux-arm-kernel,
	Juergen Gross, linuxppc-dev, linux-mips, iommu, Robin Murphy

On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > Can you send me the full dmesg and the content of
> > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > 
> > Sure thing, they are attached! If there is anything else I can provide
> > or test, I am more than happy to do so.
> 
> Nothing interesting.  But the performance numbers almost look like
> swiotlb=force got ignored before (even if I can't explain why).

I was able to get my performance back with this diff but I don't know if
this is a hack or a proper fix in the context of the series.

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dfa1de89dc94..0bfb2fe3d8c5 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -276,7 +276,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
+	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
 
 	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();

> Do you get a similar performance with the new kernel without
> swiotlb=force as the old one with that argument by any chance?

I'll see if I can test that, as I am not sure I have control over those
cmdline arguments.

Cheers,
Nathan
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:11             ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 18:11 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Joerg Roedel,
	Konrad Rzeszutek Wilk, tboot-devel, xen-devel, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, linuxppc-dev, linux-mips, iommu,
	Robin Murphy, Lu Baolu

On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > Can you send me the full dmesg and the content of
> > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > 
> > Sure thing, they are attached! If there is anything else I can provide
> > or test, I am more than happy to do so.
> 
> Nothing interesting.  But the performance numbers almost look like
> swiotlb=force got ignored before (even if I can't explain why).

I was able to get my performance back with this diff but I don't know if
this is a hack or a proper fix in the context of the series.

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dfa1de89dc94..0bfb2fe3d8c5 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -276,7 +276,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
+	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
 
 	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();

> Do you get a similar performance with the new kernel without
> swiotlb=force as the old one with that argument by any chance?

I'll see if I can test that, as I am not sure I have control over those
cmdline arguments.

Cheers,
Nathan

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:11             ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 18:11 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > Can you send me the full dmesg and the content of
> > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > 
> > Sure thing, they are attached! If there is anything else I can provide
> > or test, I am more than happy to do so.
> 
> Nothing interesting.  But the performance numbers almost look like
> swiotlb=force got ignored before (even if I can't explain why).

I was able to get my performance back with this diff but I don't know if
this is a hack or a proper fix in the context of the series.

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dfa1de89dc94..0bfb2fe3d8c5 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -276,7 +276,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
+	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
 
 	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();

> Do you get a similar performance with the new kernel without
> swiotlb=force as the old one with that argument by any chance?

I'll see if I can test that, as I am not sure I have control over those
cmdline arguments.

Cheers,
Nathan

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:11             ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 18:11 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > Can you send me the full dmesg and the content of
> > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > 
> > Sure thing, they are attached! If there is anything else I can provide
> > or test, I am more than happy to do so.
> 
> Nothing interesting.  But the performance numbers almost look like
> swiotlb=force got ignored before (even if I can't explain why).

I was able to get my performance back with this diff but I don't know if
this is a hack or a proper fix in the context of the series.

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dfa1de89dc94..0bfb2fe3d8c5 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -276,7 +276,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
+	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
 
 	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();

> Do you get a similar performance with the new kernel without
> swiotlb=force as the old one with that argument by any chance?

I'll see if I can test that, as I am not sure I have control over those
cmdline arguments.

Cheers,
Nathan

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
  2022-06-01 18:11             ` Nathan Chancellor
                                 ` (3 preceding siblings ...)
  (?)
@ 2022-06-01 18:21               ` Christoph Hellwig
  -1 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 18:21 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 11:11:57AM -0700, Nathan Chancellor wrote:
> On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> > On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > > Can you send me the full dmesg and the content of
> > > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > > 
> > > Sure thing, they are attached! If there is anything else I can provide
> > > or test, I am more than happy to do so.
> > 
> > Nothing interesting.  But the performance numbers almost look like
> > swiotlb=force got ignored before (even if I can't explain why).
> 
> I was able to get my performance back with this diff but I don't know if
> this is a hack or a proper fix in the context of the series.

This looks good, but needs a little tweak.  I'd go for this variant of
it:


diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dfa1de89dc944..cb50f8d383606 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -192,7 +192,7 @@ void __init swiotlb_update_mem_attributes(void)
 }
 
 static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
-				    unsigned long nslabs, bool late_alloc)
+		unsigned long nslabs, unsigned int flags, bool late_alloc)
 {
 	void *vaddr = phys_to_virt(start);
 	unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
@@ -203,8 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force_bounce)
-		mem->force_bounce = true;
+	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
 
 	spin_lock_init(&mem->lock);
 	for (i = 0; i < mem->nslabs; i++) {
@@ -275,8 +274,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
 		      __func__, alloc_size, PAGE_SIZE);
 
-	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
+	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);
 
 	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
@@ -348,7 +346,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 
 	set_memory_decrypted((unsigned long)vstart,
 			     (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
-	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
+	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);
 
 	swiotlb_print_info();
 	return 0;
@@ -835,8 +833,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
 
 		set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
 				     rmem->size >> PAGE_SHIFT);
-		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false);
-		mem->force_bounce = true;
+		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, SWIOTLB_FORCE,
+				false);
 		mem->for_alloc = true;
 
 		rmem->priv = mem;


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:21               ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 18:21 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 11:11:57AM -0700, Nathan Chancellor wrote:
> On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> > On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > > Can you send me the full dmesg and the content of
> > > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > > 
> > > Sure thing, they are attached! If there is anything else I can provide
> > > or test, I am more than happy to do so.
> > 
> > Nothing interesting.  But the performance numbers almost look like
> > swiotlb=force got ignored before (even if I can't explain why).
> 
> I was able to get my performance back with this diff but I don't know if
> this is a hack or a proper fix in the context of the series.

This looks good, but needs a little tweak.  I'd go for this variant of
it:


diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dfa1de89dc944..cb50f8d383606 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -192,7 +192,7 @@ void __init swiotlb_update_mem_attributes(void)
 }
 
 static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
-				    unsigned long nslabs, bool late_alloc)
+		unsigned long nslabs, unsigned int flags, bool late_alloc)
 {
 	void *vaddr = phys_to_virt(start);
 	unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
@@ -203,8 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force_bounce)
-		mem->force_bounce = true;
+	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
 
 	spin_lock_init(&mem->lock);
 	for (i = 0; i < mem->nslabs; i++) {
@@ -275,8 +274,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
 		      __func__, alloc_size, PAGE_SIZE);
 
-	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
+	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);
 
 	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
@@ -348,7 +346,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 
 	set_memory_decrypted((unsigned long)vstart,
 			     (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
-	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
+	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);
 
 	swiotlb_print_info();
 	return 0;
@@ -835,8 +833,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
 
 		set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
 				     rmem->size >> PAGE_SHIFT);
-		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false);
-		mem->force_bounce = true;
+		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, SWIOTLB_FORCE,
+				false);
 		mem->for_alloc = true;
 
 		rmem->priv = mem;


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:21               ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 18:21 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	Christoph Hellwig, linux-s390, Stefano Stabellini, Joerg Roedel,
	Konrad Rzeszutek Wilk, tboot-devel, xen-devel, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, linuxppc-dev, linux-mips, iommu,
	Robin Murphy, Lu Baolu

On Wed, Jun 01, 2022 at 11:11:57AM -0700, Nathan Chancellor wrote:
> On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> > On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > > Can you send me the full dmesg and the content of
> > > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > > 
> > > Sure thing, they are attached! If there is anything else I can provide
> > > or test, I am more than happy to do so.
> > 
> > Nothing interesting.  But the performance numbers almost look like
> > swiotlb=force got ignored before (even if I can't explain why).
> 
> I was able to get my performance back with this diff but I don't know if
> this is a hack or a proper fix in the context of the series.

This looks good, but needs a little tweak.  I'd go for this variant of
it:


diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dfa1de89dc944..cb50f8d383606 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -192,7 +192,7 @@ void __init swiotlb_update_mem_attributes(void)
 }
 
 static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
-				    unsigned long nslabs, bool late_alloc)
+		unsigned long nslabs, unsigned int flags, bool late_alloc)
 {
 	void *vaddr = phys_to_virt(start);
 	unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
@@ -203,8 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force_bounce)
-		mem->force_bounce = true;
+	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
 
 	spin_lock_init(&mem->lock);
 	for (i = 0; i < mem->nslabs; i++) {
@@ -275,8 +274,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
 		      __func__, alloc_size, PAGE_SIZE);
 
-	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
+	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);
 
 	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
@@ -348,7 +346,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 
 	set_memory_decrypted((unsigned long)vstart,
 			     (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
-	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
+	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);
 
 	swiotlb_print_info();
 	return 0;
@@ -835,8 +833,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
 
 		set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
 				     rmem->size >> PAGE_SHIFT);
-		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false);
-		mem->force_bounce = true;
+		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, SWIOTLB_FORCE,
+				false);
 		mem->for_alloc = true;
 
 		rmem->priv = mem;


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:21               ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 18:21 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	Christoph Hellwig, linux-s390, Stefano Stabellini,
	Konrad Rzeszutek Wilk, tboot-devel, xen-devel, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, linuxppc-dev, linux-mips, iommu,
	Robin Murphy

On Wed, Jun 01, 2022 at 11:11:57AM -0700, Nathan Chancellor wrote:
> On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> > On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > > Can you send me the full dmesg and the content of
> > > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > > 
> > > Sure thing, they are attached! If there is anything else I can provide
> > > or test, I am more than happy to do so.
> > 
> > Nothing interesting.  But the performance numbers almost look like
> > swiotlb=force got ignored before (even if I can't explain why).
> 
> I was able to get my performance back with this diff but I don't know if
> this is a hack or a proper fix in the context of the series.

This looks good, but needs a little tweak.  I'd go for this variant of
it:


diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dfa1de89dc944..cb50f8d383606 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -192,7 +192,7 @@ void __init swiotlb_update_mem_attributes(void)
 }
 
 static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
-				    unsigned long nslabs, bool late_alloc)
+		unsigned long nslabs, unsigned int flags, bool late_alloc)
 {
 	void *vaddr = phys_to_virt(start);
 	unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
@@ -203,8 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force_bounce)
-		mem->force_bounce = true;
+	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
 
 	spin_lock_init(&mem->lock);
 	for (i = 0; i < mem->nslabs; i++) {
@@ -275,8 +274,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
 		      __func__, alloc_size, PAGE_SIZE);
 
-	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
+	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);
 
 	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
@@ -348,7 +346,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 
 	set_memory_decrypted((unsigned long)vstart,
 			     (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
-	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
+	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);
 
 	swiotlb_print_info();
 	return 0;
@@ -835,8 +833,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
 
 		set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
 				     rmem->size >> PAGE_SHIFT);
-		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false);
-		mem->force_bounce = true;
+		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, SWIOTLB_FORCE,
+				false);
 		mem->for_alloc = true;
 
 		rmem->priv = mem;

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:21               ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 18:21 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 11:11:57AM -0700, Nathan Chancellor wrote:
> On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> > On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > > Can you send me the full dmesg and the content of
> > > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > > 
> > > Sure thing, they are attached! If there is anything else I can provide
> > > or test, I am more than happy to do so.
> > 
> > Nothing interesting.  But the performance numbers almost look like
> > swiotlb=force got ignored before (even if I can't explain why).
> 
> I was able to get my performance back with this diff but I don't know if
> this is a hack or a proper fix in the context of the series.

This looks good, but needs a little tweak.  I'd go for this variant of
it:


diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dfa1de89dc944..cb50f8d383606 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -192,7 +192,7 @@ void __init swiotlb_update_mem_attributes(void)
 }
 
 static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
-				    unsigned long nslabs, bool late_alloc)
+		unsigned long nslabs, unsigned int flags, bool late_alloc)
 {
 	void *vaddr = phys_to_virt(start);
 	unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
@@ -203,8 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force_bounce)
-		mem->force_bounce = true;
+	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
 
 	spin_lock_init(&mem->lock);
 	for (i = 0; i < mem->nslabs; i++) {
@@ -275,8 +274,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
 		      __func__, alloc_size, PAGE_SIZE);
 
-	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
+	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);
 
 	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
@@ -348,7 +346,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 
 	set_memory_decrypted((unsigned long)vstart,
 			     (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
-	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
+	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);
 
 	swiotlb_print_info();
 	return 0;
@@ -835,8 +833,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
 
 		set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
 				     rmem->size >> PAGE_SHIFT);
-		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false);
-		mem->force_bounce = true;
+		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, SWIOTLB_FORCE,
+				false);
 		mem->for_alloc = true;
 
 		rmem->priv = mem;


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:21               ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-06-01 18:21 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Christoph Hellwig, iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 11:11:57AM -0700, Nathan Chancellor wrote:
> On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> > On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > > Can you send me the full dmesg and the content of
> > > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > > 
> > > Sure thing, they are attached! If there is anything else I can provide
> > > or test, I am more than happy to do so.
> > 
> > Nothing interesting.  But the performance numbers almost look like
> > swiotlb=force got ignored before (even if I can't explain why).
> 
> I was able to get my performance back with this diff but I don't know if
> this is a hack or a proper fix in the context of the series.

This looks good, but needs a little tweak.  I'd go for this variant of
it:


diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dfa1de89dc944..cb50f8d383606 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -192,7 +192,7 @@ void __init swiotlb_update_mem_attributes(void)
 }
 
 static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
-				    unsigned long nslabs, bool late_alloc)
+		unsigned long nslabs, unsigned int flags, bool late_alloc)
 {
 	void *vaddr = phys_to_virt(start);
 	unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
@@ -203,8 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force_bounce)
-		mem->force_bounce = true;
+	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
 
 	spin_lock_init(&mem->lock);
 	for (i = 0; i < mem->nslabs; i++) {
@@ -275,8 +274,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
 		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
 		      __func__, alloc_size, PAGE_SIZE);
 
-	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
-	mem->force_bounce = flags & SWIOTLB_FORCE;
+	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);
 
 	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
@@ -348,7 +346,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 
 	set_memory_decrypted((unsigned long)vstart,
 			     (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
-	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
+	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);
 
 	swiotlb_print_info();
 	return 0;
@@ -835,8 +833,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
 
 		set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
 				     rmem->size >> PAGE_SHIFT);
-		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false);
-		mem->force_bounce = true;
+		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, SWIOTLB_FORCE,
+				false);
 		mem->for_alloc = true;
 
 		rmem->priv = mem;

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
  2022-06-01 18:21               ` Christoph Hellwig
                                   ` (3 preceding siblings ...)
  (?)
@ 2022-06-01 18:40                 ` Nathan Chancellor
  -1 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 18:40 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 08:21:41PM +0200, Christoph Hellwig wrote:
> On Wed, Jun 01, 2022 at 11:11:57AM -0700, Nathan Chancellor wrote:
> > On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> > > On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > > > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > > > Can you send me the full dmesg and the content of
> > > > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > > > 
> > > > Sure thing, they are attached! If there is anything else I can provide
> > > > or test, I am more than happy to do so.
> > > 
> > > Nothing interesting.  But the performance numbers almost look like
> > > swiotlb=force got ignored before (even if I can't explain why).
> > 
> > I was able to get my performance back with this diff but I don't know if
> > this is a hack or a proper fix in the context of the series.
> 
> This looks good, but needs a little tweak.  I'd go for this variant of
> it:

Tested-by: Nathan Chancellor <nathan@kernel.org>

Thanks a lot for the quick fix!

> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index dfa1de89dc944..cb50f8d383606 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -192,7 +192,7 @@ void __init swiotlb_update_mem_attributes(void)
>  }
>  
>  static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
> -				    unsigned long nslabs, bool late_alloc)
> +		unsigned long nslabs, unsigned int flags, bool late_alloc)
>  {
>  	void *vaddr = phys_to_virt(start);
>  	unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
> @@ -203,8 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
>  	mem->index = 0;
>  	mem->late_alloc = late_alloc;
>  
> -	if (swiotlb_force_bounce)
> -		mem->force_bounce = true;
> +	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
>  
>  	spin_lock_init(&mem->lock);
>  	for (i = 0; i < mem->nslabs; i++) {
> @@ -275,8 +274,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
>  		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
>  		      __func__, alloc_size, PAGE_SIZE);
>  
> -	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
> -	mem->force_bounce = flags & SWIOTLB_FORCE;
> +	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);
>  
>  	if (flags & SWIOTLB_VERBOSE)
>  		swiotlb_print_info();
> @@ -348,7 +346,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
>  
>  	set_memory_decrypted((unsigned long)vstart,
>  			     (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
> -	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
> +	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);
>  
>  	swiotlb_print_info();
>  	return 0;
> @@ -835,8 +833,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
>  
>  		set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
>  				     rmem->size >> PAGE_SHIFT);
> -		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false);
> -		mem->force_bounce = true;
> +		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, SWIOTLB_FORCE,
> +				false);
>  		mem->for_alloc = true;
>  
>  		rmem->priv = mem;
> 

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:40                 ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 18:40 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Konrad Rzeszutek Wilk,
	tboot-devel, xen-devel, David Woodhouse, Tom Lendacky,
	Anshuman Khandual, Boris Ostrovsky, linux-arm-kernel,
	Juergen Gross, linuxppc-dev, linux-mips, iommu, Robin Murphy

On Wed, Jun 01, 2022 at 08:21:41PM +0200, Christoph Hellwig wrote:
> On Wed, Jun 01, 2022 at 11:11:57AM -0700, Nathan Chancellor wrote:
> > On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> > > On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > > > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > > > Can you send me the full dmesg and the content of
> > > > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > > > 
> > > > Sure thing, they are attached! If there is anything else I can provide
> > > > or test, I am more than happy to do so.
> > > 
> > > Nothing interesting.  But the performance numbers almost look like
> > > swiotlb=force got ignored before (even if I can't explain why).
> > 
> > I was able to get my performance back with this diff but I don't know if
> > this is a hack or a proper fix in the context of the series.
> 
> This looks good, but needs a little tweak.  I'd go for this variant of
> it:

Tested-by: Nathan Chancellor <nathan@kernel.org>

Thanks a lot for the quick fix!

> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index dfa1de89dc944..cb50f8d383606 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -192,7 +192,7 @@ void __init swiotlb_update_mem_attributes(void)
>  }
>  
>  static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
> -				    unsigned long nslabs, bool late_alloc)
> +		unsigned long nslabs, unsigned int flags, bool late_alloc)
>  {
>  	void *vaddr = phys_to_virt(start);
>  	unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
> @@ -203,8 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
>  	mem->index = 0;
>  	mem->late_alloc = late_alloc;
>  
> -	if (swiotlb_force_bounce)
> -		mem->force_bounce = true;
> +	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
>  
>  	spin_lock_init(&mem->lock);
>  	for (i = 0; i < mem->nslabs; i++) {
> @@ -275,8 +274,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
>  		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
>  		      __func__, alloc_size, PAGE_SIZE);
>  
> -	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
> -	mem->force_bounce = flags & SWIOTLB_FORCE;
> +	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);
>  
>  	if (flags & SWIOTLB_VERBOSE)
>  		swiotlb_print_info();
> @@ -348,7 +346,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
>  
>  	set_memory_decrypted((unsigned long)vstart,
>  			     (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
> -	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
> +	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);
>  
>  	swiotlb_print_info();
>  	return 0;
> @@ -835,8 +833,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
>  
>  		set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
>  				     rmem->size >> PAGE_SHIFT);
> -		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false);
> -		mem->force_bounce = true;
> +		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, SWIOTLB_FORCE,
> +				false);
>  		mem->for_alloc = true;
>  
>  		rmem->priv = mem;
> 

Cheers,
Nathan
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:40                 ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 18:40 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 08:21:41PM +0200, Christoph Hellwig wrote:
> On Wed, Jun 01, 2022 at 11:11:57AM -0700, Nathan Chancellor wrote:
> > On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> > > On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > > > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > > > Can you send me the full dmesg and the content of
> > > > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > > > 
> > > > Sure thing, they are attached! If there is anything else I can provide
> > > > or test, I am more than happy to do so.
> > > 
> > > Nothing interesting.  But the performance numbers almost look like
> > > swiotlb=force got ignored before (even if I can't explain why).
> > 
> > I was able to get my performance back with this diff but I don't know if
> > this is a hack or a proper fix in the context of the series.
> 
> This looks good, but needs a little tweak.  I'd go for this variant of
> it:

Tested-by: Nathan Chancellor <nathan@kernel.org>

Thanks a lot for the quick fix!

> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index dfa1de89dc944..cb50f8d383606 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -192,7 +192,7 @@ void __init swiotlb_update_mem_attributes(void)
>  }
>  
>  static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
> -				    unsigned long nslabs, bool late_alloc)
> +		unsigned long nslabs, unsigned int flags, bool late_alloc)
>  {
>  	void *vaddr = phys_to_virt(start);
>  	unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
> @@ -203,8 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
>  	mem->index = 0;
>  	mem->late_alloc = late_alloc;
>  
> -	if (swiotlb_force_bounce)
> -		mem->force_bounce = true;
> +	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
>  
>  	spin_lock_init(&mem->lock);
>  	for (i = 0; i < mem->nslabs; i++) {
> @@ -275,8 +274,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
>  		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
>  		      __func__, alloc_size, PAGE_SIZE);
>  
> -	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
> -	mem->force_bounce = flags & SWIOTLB_FORCE;
> +	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);
>  
>  	if (flags & SWIOTLB_VERBOSE)
>  		swiotlb_print_info();
> @@ -348,7 +346,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
>  
>  	set_memory_decrypted((unsigned long)vstart,
>  			     (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
> -	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
> +	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);
>  
>  	swiotlb_print_info();
>  	return 0;
> @@ -835,8 +833,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
>  
>  		set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
>  				     rmem->size >> PAGE_SHIFT);
> -		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false);
> -		mem->force_bounce = true;
> +		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, SWIOTLB_FORCE,
> +				false);
>  		mem->for_alloc = true;
>  
>  		rmem->priv = mem;
> 

Cheers,
Nathan

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:40                 ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 18:40 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-hyperv, x86, linux-ia64, linux-pci, linux-riscv,
	linux-s390, Stefano Stabellini, Joerg Roedel,
	Konrad Rzeszutek Wilk, tboot-devel, xen-devel, David Woodhouse,
	Tom Lendacky, Anshuman Khandual, Boris Ostrovsky,
	linux-arm-kernel, Juergen Gross, linuxppc-dev, linux-mips, iommu,
	Robin Murphy, Lu Baolu

On Wed, Jun 01, 2022 at 08:21:41PM +0200, Christoph Hellwig wrote:
> On Wed, Jun 01, 2022 at 11:11:57AM -0700, Nathan Chancellor wrote:
> > On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> > > On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > > > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > > > Can you send me the full dmesg and the content of
> > > > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > > > 
> > > > Sure thing, they are attached! If there is anything else I can provide
> > > > or test, I am more than happy to do so.
> > > 
> > > Nothing interesting.  But the performance numbers almost look like
> > > swiotlb=force got ignored before (even if I can't explain why).
> > 
> > I was able to get my performance back with this diff but I don't know if
> > this is a hack or a proper fix in the context of the series.
> 
> This looks good, but needs a little tweak.  I'd go for this variant of
> it:

Tested-by: Nathan Chancellor <nathan@kernel.org>

Thanks a lot for the quick fix!

> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index dfa1de89dc944..cb50f8d383606 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -192,7 +192,7 @@ void __init swiotlb_update_mem_attributes(void)
>  }
>  
>  static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
> -				    unsigned long nslabs, bool late_alloc)
> +		unsigned long nslabs, unsigned int flags, bool late_alloc)
>  {
>  	void *vaddr = phys_to_virt(start);
>  	unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
> @@ -203,8 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
>  	mem->index = 0;
>  	mem->late_alloc = late_alloc;
>  
> -	if (swiotlb_force_bounce)
> -		mem->force_bounce = true;
> +	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
>  
>  	spin_lock_init(&mem->lock);
>  	for (i = 0; i < mem->nslabs; i++) {
> @@ -275,8 +274,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
>  		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
>  		      __func__, alloc_size, PAGE_SIZE);
>  
> -	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
> -	mem->force_bounce = flags & SWIOTLB_FORCE;
> +	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);
>  
>  	if (flags & SWIOTLB_VERBOSE)
>  		swiotlb_print_info();
> @@ -348,7 +346,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
>  
>  	set_memory_decrypted((unsigned long)vstart,
>  			     (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
> -	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
> +	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);
>  
>  	swiotlb_print_info();
>  	return 0;
> @@ -835,8 +833,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
>  
>  		set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
>  				     rmem->size >> PAGE_SHIFT);
> -		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false);
> -		mem->force_bounce = true;
> +		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, SWIOTLB_FORCE,
> +				false);
>  		mem->for_alloc = true;
>  
>  		rmem->priv = mem;
> 

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:40                 ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 18:40 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 08:21:41PM +0200, Christoph Hellwig wrote:
> On Wed, Jun 01, 2022 at 11:11:57AM -0700, Nathan Chancellor wrote:
> > On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> > > On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > > > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > > > Can you send me the full dmesg and the content of
> > > > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > > > 
> > > > Sure thing, they are attached! If there is anything else I can provide
> > > > or test, I am more than happy to do so.
> > > 
> > > Nothing interesting.  But the performance numbers almost look like
> > > swiotlb=force got ignored before (even if I can't explain why).
> > 
> > I was able to get my performance back with this diff but I don't know if
> > this is a hack or a proper fix in the context of the series.
> 
> This looks good, but needs a little tweak.  I'd go for this variant of
> it:

Tested-by: Nathan Chancellor <nathan@kernel.org>

Thanks a lot for the quick fix!

> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index dfa1de89dc944..cb50f8d383606 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -192,7 +192,7 @@ void __init swiotlb_update_mem_attributes(void)
>  }
>  
>  static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
> -				    unsigned long nslabs, bool late_alloc)
> +		unsigned long nslabs, unsigned int flags, bool late_alloc)
>  {
>  	void *vaddr = phys_to_virt(start);
>  	unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
> @@ -203,8 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
>  	mem->index = 0;
>  	mem->late_alloc = late_alloc;
>  
> -	if (swiotlb_force_bounce)
> -		mem->force_bounce = true;
> +	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
>  
>  	spin_lock_init(&mem->lock);
>  	for (i = 0; i < mem->nslabs; i++) {
> @@ -275,8 +274,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
>  		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
>  		      __func__, alloc_size, PAGE_SIZE);
>  
> -	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
> -	mem->force_bounce = flags & SWIOTLB_FORCE;
> +	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);
>  
>  	if (flags & SWIOTLB_VERBOSE)
>  		swiotlb_print_info();
> @@ -348,7 +346,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
>  
>  	set_memory_decrypted((unsigned long)vstart,
>  			     (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
> -	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
> +	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);
>  
>  	swiotlb_print_info();
>  	return 0;
> @@ -835,8 +833,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
>  
>  		set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
>  				     rmem->size >> PAGE_SHIFT);
> -		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false);
> -		mem->force_bounce = true;
> +		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, SWIOTLB_FORCE,
> +				false);
>  		mem->for_alloc = true;
>  
>  		rmem->priv = mem;
> 

Cheers,
Nathan

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 197+ messages in thread

* Re: [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-06-01 18:40                 ` Nathan Chancellor
  0 siblings, 0 replies; 197+ messages in thread
From: Nathan Chancellor @ 2022-06-01 18:40 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu, x86, Anshuman Khandual, Tom Lendacky,
	Konrad Rzeszutek Wilk, Stefano Stabellini, Boris Ostrovsky,
	Juergen Gross, Joerg Roedel, David Woodhouse, Lu Baolu,
	Robin Murphy, linux-arm-kernel, xen-devel, linux-ia64,
	linux-mips, linuxppc-dev, linux-riscv, linux-s390, linux-hyperv,
	tboot-devel, linux-pci

On Wed, Jun 01, 2022 at 08:21:41PM +0200, Christoph Hellwig wrote:
> On Wed, Jun 01, 2022 at 11:11:57AM -0700, Nathan Chancellor wrote:
> > On Wed, Jun 01, 2022 at 07:57:43PM +0200, Christoph Hellwig wrote:
> > > On Wed, Jun 01, 2022 at 10:46:54AM -0700, Nathan Chancellor wrote:
> > > > On Wed, Jun 01, 2022 at 07:34:41PM +0200, Christoph Hellwig wrote:
> > > > > Can you send me the full dmesg and the content of
> > > > > /sys/kernel/debug/swiotlb/io_tlb_nslabs for a good and a bad boot?
> > > > 
> > > > Sure thing, they are attached! If there is anything else I can provide
> > > > or test, I am more than happy to do so.
> > > 
> > > Nothing interesting.  But the performance numbers almost look like
> > > swiotlb=force got ignored before (even if I can't explain why).
> > 
> > I was able to get my performance back with this diff but I don't know if
> > this is a hack or a proper fix in the context of the series.
> 
> This looks good, but needs a little tweak.  I'd go for this variant of
> it:

Tested-by: Nathan Chancellor <nathan@kernel.org>

Thanks a lot for the quick fix!

> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index dfa1de89dc944..cb50f8d383606 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -192,7 +192,7 @@ void __init swiotlb_update_mem_attributes(void)
>  }
>  
>  static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
> -				    unsigned long nslabs, bool late_alloc)
> +		unsigned long nslabs, unsigned int flags, bool late_alloc)
>  {
>  	void *vaddr = phys_to_virt(start);
>  	unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
> @@ -203,8 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
>  	mem->index = 0;
>  	mem->late_alloc = late_alloc;
>  
> -	if (swiotlb_force_bounce)
> -		mem->force_bounce = true;
> +	mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
>  
>  	spin_lock_init(&mem->lock);
>  	for (i = 0; i < mem->nslabs; i++) {
> @@ -275,8 +274,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
>  		panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
>  		      __func__, alloc_size, PAGE_SIZE);
>  
> -	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
> -	mem->force_bounce = flags & SWIOTLB_FORCE;
> +	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);
>  
>  	if (flags & SWIOTLB_VERBOSE)
>  		swiotlb_print_info();
> @@ -348,7 +346,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
>  
>  	set_memory_decrypted((unsigned long)vstart,
>  			     (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
> -	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
> +	swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);
>  
>  	swiotlb_print_info();
>  	return 0;
> @@ -835,8 +833,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
>  
>  		set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
>  				     rmem->size >> PAGE_SHIFT);
> -		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false);
> -		mem->force_bounce = true;
> +		swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, SWIOTLB_FORCE,
> +				false);
>  		mem->for_alloc = true;
>  
>  		rmem->priv = mem;
> 

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 197+ messages in thread

* [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
  2022-03-14  7:31 cleanup swiotlb initialization v5 Christoph Hellwig
                     ` (3 preceding siblings ...)
  (?)
@ 2022-03-14  7:31   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-03-14  7:31 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Pass a bool to pass if swiotlb needs to be enabled based on the
addressing needs and replace the verbose argument with a set of
flags, including one to force enable bounce buffering.

Note that this patch removes the possibility to force xen-swiotlb
use using swiotlb=force on the command line on x86 (arm and arm64
never supported that), but this interface will be restored shortly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/mm/init.c                     |  6 +----
 arch/arm64/mm/init.c                   |  6 +----
 arch/ia64/mm/init.c                    |  4 +--
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/sibyte/common/dma.c          |  2 +-
 arch/powerpc/mm/mem.c                  |  3 ++-
 arch/powerpc/platforms/pseries/setup.c |  3 ---
 arch/riscv/mm/init.c                   |  8 +-----
 arch/s390/mm/init.c                    |  3 +--
 arch/x86/kernel/pci-dma.c              | 15 ++++++-----
 drivers/xen/swiotlb-xen.c              |  4 +--
 include/linux/swiotlb.h                | 15 ++++++-----
 include/trace/events/swiotlb.h         | 29 ++++++++-------------
 kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
 15 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 6d0cb0f7bc54b..73f30d278b565 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -312,11 +312,7 @@ static void __init free_highpages(void)
 void __init mem_init(void)
 {
 #ifdef CONFIG_ARM_LPAE
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > arm_dma_pfn_limit)
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
 #endif
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index db63cc885771a..52102adda3d28 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -373,11 +373,7 @@ void __init bootmem_init(void)
  */
 void __init mem_init(void)
 {
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
-		swiotlb_init(1);
-	else if (!xen_swiotlb_detect())
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE);
 
 	/* this will put all unused low memory onto the freelists */
 	memblock_free_all();
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index 5d165607bf354..3c3e15b22608f 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -437,9 +437,7 @@ mem_init (void)
 		if (iommu_detected)
 			break;
 #endif
-#ifdef CONFIG_SWIOTLB
-		swiotlb_init(1);
-#endif
+		swiotlb_init(true, SWIOTLB_VERBOSE);
 	} while (0);
 
 #ifdef CONFIG_FLATMEM
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index fb7547e217263..9fbba6a8fa4c5 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
 #endif
 
 	swiotlb_adjust_size(swiotlbsize);
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index 364f2f27c8723..8220a1bc0db64 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
index eb47a94f3583e..c5c2c782aff68 100644
--- a/arch/mips/sibyte/common/dma.c
+++ b/arch/mips/sibyte/common/dma.c
@@ -10,5 +10,5 @@
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8e301cd8925b2..e1519e2edc656 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -17,6 +17,7 @@
 #include <linux/suspend.h>
 #include <linux/dma-direct.h>
 
+#include <asm/swiotlb.h>
 #include <asm/machdep.h>
 #include <asm/rtas.h>
 #include <asm/kasan.h>
@@ -251,7 +252,7 @@ void __init mem_init(void)
 	if (is_secure_guest())
 		svm_swiotlb_init();
 	else
-		swiotlb_init(0);
+		swiotlb_init(ppc_swiotlb_enable, 0);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 83a04d967a59f..45d637ab58261 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
 	}
 
 	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
-		ppc_swiotlb_enable = 1;
 }
 
 static void pseries_panic(char *str)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index cf4d018b7d668..e2c97b4ea2b48 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -118,13 +118,7 @@ void __init mem_init(void)
 	BUG_ON(!mem_map);
 #endif /* CONFIG_FLATMEM */
 
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(dma32_phys_limit))
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
-#endif
+	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
 	high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
 	memblock_free_all();
 
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 86ffd0d51fd59..6fb6bf64326f9 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -185,8 +185,7 @@ static void pv_init(void)
 		return;
 
 	/* make sure bounce buffers are shared */
-	swiotlb_force = SWIOTLB_FORCE;
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
 	swiotlb_update_mem_attributes();
 }
 
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 04140e20ef1a3..a705a199bf8a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
 
 #ifdef CONFIG_SWIOTLB
 bool x86_swiotlb_enable;
+static unsigned int x86_swiotlb_flags;
 
 static void __init pci_swiotlb_detect(void)
 {
@@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
 	 * bounce buffers as the hypervisor can't access arbitrary VM memory
 	 * that is not explicitly shared with it.
 	 */
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
+		x86_swiotlb_flags |= SWIOTLB_FORCE;
+	}
 }
 #else
 static inline void __init pci_swiotlb_detect(void)
 {
 }
+#define x86_swiotlb_flags 0
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
@@ -75,8 +76,7 @@ static bool xen_swiotlb;
 
 static void __init pci_xen_swiotlb_init(void)
 {
-	if (!xen_initial_domain() && !x86_swiotlb_enable &&
-	    swiotlb_force != SWIOTLB_FORCE)
+	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
 	xen_swiotlb = true;
@@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
 	gart_iommu_hole_init();
 	amd_iommu_detect();
 	detect_intel_iommu();
-	if (x86_swiotlb_enable)
-		swiotlb_init(0);
+	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
 }
 
 /*
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 485cd06ed39e7..c2da3eb4826e8 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
 		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
 	}
 
-	if (swiotlb_init_with_tbl(start, nslabs, true))
+	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
 		panic("Cannot allocate SWIOTLB buffer");
 }
 #endif /* CONFIG_X86 */
@@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	/*
 	 * Oh well, have to allocate and map a bounce buffer.
 	 */
-	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+	trace_swiotlb_bounced(dev, dev_addr, size);
 
 	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
 	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index b48b26bfa0edb..ae0407173e845 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -13,11 +13,8 @@ struct device;
 struct page;
 struct scatterlist;
 
-enum swiotlb_force {
-	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc. */
-	SWIOTLB_FORCE,		/* swiotlb=force */
-	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
-};
+#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
+#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
@@ -36,8 +33,7 @@ enum swiotlb_force {
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-extern void swiotlb_init(int verbose);
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 int swiotlb_init_late(size_t size);
@@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
 	return mem && mem->force_bounce;
 }
 
+void swiotlb_init(bool addressing_limited, unsigned int flags);
 void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
 bool is_swiotlb_active(struct device *dev);
 void __init swiotlb_adjust_size(unsigned long size);
 #else
-#define swiotlb_force SWIOTLB_NO_FORCE
+static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
+{
+}
 static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
 {
 	return false;
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index 705be43b71ab0..da05c9ebd224a 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -8,20 +8,15 @@
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(swiotlb_bounced,
-
-	TP_PROTO(struct device *dev,
-		 dma_addr_t dev_addr,
-		 size_t size,
-		 enum swiotlb_force swiotlb_force),
-
-	TP_ARGS(dev, dev_addr, size, swiotlb_force),
+	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
+	TP_ARGS(dev, dev_addr, size),
 
 	TP_STRUCT__entry(
-		__string(	dev_name,	dev_name(dev)		)
-		__field(	u64,	dma_mask			)
-		__field(	dma_addr_t,	dev_addr		)
-		__field(	size_t,	size				)
-		__field(	enum swiotlb_force,	swiotlb_force	)
+		__string(dev_name, dev_name(dev))
+		__field(u64, dma_mask)
+		__field(dma_addr_t, dev_addr)
+		__field(size_t, size)
+		__field(bool, force)
 	),
 
 	TP_fast_assign(
@@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
 		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
 		__entry->dev_addr = dev_addr;
 		__entry->size = size;
-		__entry->swiotlb_force = swiotlb_force;
+		__entry->force = is_swiotlb_force_bounce(dev);
 	),
 
-	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
-		"size=%zu %s",
+	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
 		__get_str(dev_name),
 		__entry->dma_mask,
 		(unsigned long long)__entry->dev_addr,
 		__entry->size,
-		__print_symbolic(__entry->swiotlb_force,
-			{ SWIOTLB_NORMAL,	"NORMAL" },
-			{ SWIOTLB_FORCE,	"FORCE" },
-			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
+		__entry->force ? "FORCE" : "NORMAL")
 );
 
 #endif /*  _TRACE_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 14e08fa9621c2..5ac6e128d4279 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -62,7 +62,8 @@
 
 #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
 
-enum swiotlb_force swiotlb_force;
+static bool swiotlb_force_bounce;
+static bool swiotlb_force_disable;
 
 struct io_tlb_mem io_tlb_default_mem;
 
@@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
 	if (*str == ',')
 		++str;
 	if (!strcmp(str, "force"))
-		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_force_bounce = true;
 	else if (!strcmp(str, "noforce"))
-		swiotlb_force = SWIOTLB_NO_FORCE;
+		swiotlb_force_disable = true;
 
 	return 0;
 }
@@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		mem->force_bounce = true;
 
 	spin_lock_init(&mem->lock);
@@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
+int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
+		unsigned int flags)
 {
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	size_t alloc_size;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
 
-	if (verbose)
+	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
 	return 0;
 }
@@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void  __init
-swiotlb_init(int verbose)
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 {
 	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	void *tlb;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (!addressing_limit && !swiotlb_force_bounce)
+		return;
+	if (swiotlb_force_disable)
 		return;
 
 	/* Get IO TLB memory from the low pages */
 	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
+	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
 
@@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
 	unsigned int order;
 	int rc = 0;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/*
@@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long bytes = nslabs << IO_TLB_SHIFT;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		return;
 
 	if (!mem->nslabs)
@@ -699,8 +703,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
 	phys_addr_t swiotlb_addr;
 	dma_addr_t dma_addr;
 
-	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
-			      swiotlb_force);
+	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
 
 	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
 			attrs);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-03-14  7:31   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-03-14  7:31 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, x86, linux-mips, linuxppc-dev, tboot-devel,
	linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel

Pass a bool to pass if swiotlb needs to be enabled based on the
addressing needs and replace the verbose argument with a set of
flags, including one to force enable bounce buffering.

Note that this patch removes the possibility to force xen-swiotlb
use using swiotlb=force on the command line on x86 (arm and arm64
never supported that), but this interface will be restored shortly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/mm/init.c                     |  6 +----
 arch/arm64/mm/init.c                   |  6 +----
 arch/ia64/mm/init.c                    |  4 +--
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/sibyte/common/dma.c          |  2 +-
 arch/powerpc/mm/mem.c                  |  3 ++-
 arch/powerpc/platforms/pseries/setup.c |  3 ---
 arch/riscv/mm/init.c                   |  8 +-----
 arch/s390/mm/init.c                    |  3 +--
 arch/x86/kernel/pci-dma.c              | 15 ++++++-----
 drivers/xen/swiotlb-xen.c              |  4 +--
 include/linux/swiotlb.h                | 15 ++++++-----
 include/trace/events/swiotlb.h         | 29 ++++++++-------------
 kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
 15 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 6d0cb0f7bc54b..73f30d278b565 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -312,11 +312,7 @@ static void __init free_highpages(void)
 void __init mem_init(void)
 {
 #ifdef CONFIG_ARM_LPAE
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > arm_dma_pfn_limit)
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
 #endif
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index db63cc885771a..52102adda3d28 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -373,11 +373,7 @@ void __init bootmem_init(void)
  */
 void __init mem_init(void)
 {
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
-		swiotlb_init(1);
-	else if (!xen_swiotlb_detect())
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE);
 
 	/* this will put all unused low memory onto the freelists */
 	memblock_free_all();
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index 5d165607bf354..3c3e15b22608f 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -437,9 +437,7 @@ mem_init (void)
 		if (iommu_detected)
 			break;
 #endif
-#ifdef CONFIG_SWIOTLB
-		swiotlb_init(1);
-#endif
+		swiotlb_init(true, SWIOTLB_VERBOSE);
 	} while (0);
 
 #ifdef CONFIG_FLATMEM
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index fb7547e217263..9fbba6a8fa4c5 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
 #endif
 
 	swiotlb_adjust_size(swiotlbsize);
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index 364f2f27c8723..8220a1bc0db64 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
index eb47a94f3583e..c5c2c782aff68 100644
--- a/arch/mips/sibyte/common/dma.c
+++ b/arch/mips/sibyte/common/dma.c
@@ -10,5 +10,5 @@
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8e301cd8925b2..e1519e2edc656 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -17,6 +17,7 @@
 #include <linux/suspend.h>
 #include <linux/dma-direct.h>
 
+#include <asm/swiotlb.h>
 #include <asm/machdep.h>
 #include <asm/rtas.h>
 #include <asm/kasan.h>
@@ -251,7 +252,7 @@ void __init mem_init(void)
 	if (is_secure_guest())
 		svm_swiotlb_init();
 	else
-		swiotlb_init(0);
+		swiotlb_init(ppc_swiotlb_enable, 0);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 83a04d967a59f..45d637ab58261 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
 	}
 
 	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
-		ppc_swiotlb_enable = 1;
 }
 
 static void pseries_panic(char *str)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index cf4d018b7d668..e2c97b4ea2b48 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -118,13 +118,7 @@ void __init mem_init(void)
 	BUG_ON(!mem_map);
 #endif /* CONFIG_FLATMEM */
 
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(dma32_phys_limit))
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
-#endif
+	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
 	high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
 	memblock_free_all();
 
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 86ffd0d51fd59..6fb6bf64326f9 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -185,8 +185,7 @@ static void pv_init(void)
 		return;
 
 	/* make sure bounce buffers are shared */
-	swiotlb_force = SWIOTLB_FORCE;
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
 	swiotlb_update_mem_attributes();
 }
 
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 04140e20ef1a3..a705a199bf8a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
 
 #ifdef CONFIG_SWIOTLB
 bool x86_swiotlb_enable;
+static unsigned int x86_swiotlb_flags;
 
 static void __init pci_swiotlb_detect(void)
 {
@@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
 	 * bounce buffers as the hypervisor can't access arbitrary VM memory
 	 * that is not explicitly shared with it.
 	 */
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
+		x86_swiotlb_flags |= SWIOTLB_FORCE;
+	}
 }
 #else
 static inline void __init pci_swiotlb_detect(void)
 {
 }
+#define x86_swiotlb_flags 0
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
@@ -75,8 +76,7 @@ static bool xen_swiotlb;
 
 static void __init pci_xen_swiotlb_init(void)
 {
-	if (!xen_initial_domain() && !x86_swiotlb_enable &&
-	    swiotlb_force != SWIOTLB_FORCE)
+	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
 	xen_swiotlb = true;
@@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
 	gart_iommu_hole_init();
 	amd_iommu_detect();
 	detect_intel_iommu();
-	if (x86_swiotlb_enable)
-		swiotlb_init(0);
+	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
 }
 
 /*
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 485cd06ed39e7..c2da3eb4826e8 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
 		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
 	}
 
-	if (swiotlb_init_with_tbl(start, nslabs, true))
+	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
 		panic("Cannot allocate SWIOTLB buffer");
 }
 #endif /* CONFIG_X86 */
@@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	/*
 	 * Oh well, have to allocate and map a bounce buffer.
 	 */
-	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+	trace_swiotlb_bounced(dev, dev_addr, size);
 
 	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
 	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index b48b26bfa0edb..ae0407173e845 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -13,11 +13,8 @@ struct device;
 struct page;
 struct scatterlist;
 
-enum swiotlb_force {
-	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc. */
-	SWIOTLB_FORCE,		/* swiotlb=force */
-	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
-};
+#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
+#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
@@ -36,8 +33,7 @@ enum swiotlb_force {
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-extern void swiotlb_init(int verbose);
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 int swiotlb_init_late(size_t size);
@@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
 	return mem && mem->force_bounce;
 }
 
+void swiotlb_init(bool addressing_limited, unsigned int flags);
 void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
 bool is_swiotlb_active(struct device *dev);
 void __init swiotlb_adjust_size(unsigned long size);
 #else
-#define swiotlb_force SWIOTLB_NO_FORCE
+static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
+{
+}
 static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
 {
 	return false;
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index 705be43b71ab0..da05c9ebd224a 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -8,20 +8,15 @@
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(swiotlb_bounced,
-
-	TP_PROTO(struct device *dev,
-		 dma_addr_t dev_addr,
-		 size_t size,
-		 enum swiotlb_force swiotlb_force),
-
-	TP_ARGS(dev, dev_addr, size, swiotlb_force),
+	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
+	TP_ARGS(dev, dev_addr, size),
 
 	TP_STRUCT__entry(
-		__string(	dev_name,	dev_name(dev)		)
-		__field(	u64,	dma_mask			)
-		__field(	dma_addr_t,	dev_addr		)
-		__field(	size_t,	size				)
-		__field(	enum swiotlb_force,	swiotlb_force	)
+		__string(dev_name, dev_name(dev))
+		__field(u64, dma_mask)
+		__field(dma_addr_t, dev_addr)
+		__field(size_t, size)
+		__field(bool, force)
 	),
 
 	TP_fast_assign(
@@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
 		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
 		__entry->dev_addr = dev_addr;
 		__entry->size = size;
-		__entry->swiotlb_force = swiotlb_force;
+		__entry->force = is_swiotlb_force_bounce(dev);
 	),
 
-	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
-		"size=%zu %s",
+	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
 		__get_str(dev_name),
 		__entry->dma_mask,
 		(unsigned long long)__entry->dev_addr,
 		__entry->size,
-		__print_symbolic(__entry->swiotlb_force,
-			{ SWIOTLB_NORMAL,	"NORMAL" },
-			{ SWIOTLB_FORCE,	"FORCE" },
-			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
+		__entry->force ? "FORCE" : "NORMAL")
 );
 
 #endif /*  _TRACE_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 14e08fa9621c2..5ac6e128d4279 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -62,7 +62,8 @@
 
 #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
 
-enum swiotlb_force swiotlb_force;
+static bool swiotlb_force_bounce;
+static bool swiotlb_force_disable;
 
 struct io_tlb_mem io_tlb_default_mem;
 
@@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
 	if (*str == ',')
 		++str;
 	if (!strcmp(str, "force"))
-		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_force_bounce = true;
 	else if (!strcmp(str, "noforce"))
-		swiotlb_force = SWIOTLB_NO_FORCE;
+		swiotlb_force_disable = true;
 
 	return 0;
 }
@@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		mem->force_bounce = true;
 
 	spin_lock_init(&mem->lock);
@@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
+int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
+		unsigned int flags)
 {
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	size_t alloc_size;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
 
-	if (verbose)
+	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
 	return 0;
 }
@@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void  __init
-swiotlb_init(int verbose)
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 {
 	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	void *tlb;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (!addressing_limit && !swiotlb_force_bounce)
+		return;
+	if (swiotlb_force_disable)
 		return;
 
 	/* Get IO TLB memory from the low pages */
 	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
+	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
 
@@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
 	unsigned int order;
 	int rc = 0;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/*
@@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long bytes = nslabs << IO_TLB_SHIFT;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		return;
 
 	if (!mem->nslabs)
@@ -699,8 +703,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
 	phys_addr_t swiotlb_addr;
 	dma_addr_t dma_addr;
 
-	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
-			      swiotlb_force);
+	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
 
 	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
 			attrs);
-- 
2.30.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-03-14  7:31   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-03-14  7:31 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Pass a bool to pass if swiotlb needs to be enabled based on the
addressing needs and replace the verbose argument with a set of
flags, including one to force enable bounce buffering.

Note that this patch removes the possibility to force xen-swiotlb
use using swiotlb=force on the command line on x86 (arm and arm64
never supported that), but this interface will be restored shortly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/mm/init.c                     |  6 +----
 arch/arm64/mm/init.c                   |  6 +----
 arch/ia64/mm/init.c                    |  4 +--
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/sibyte/common/dma.c          |  2 +-
 arch/powerpc/mm/mem.c                  |  3 ++-
 arch/powerpc/platforms/pseries/setup.c |  3 ---
 arch/riscv/mm/init.c                   |  8 +-----
 arch/s390/mm/init.c                    |  3 +--
 arch/x86/kernel/pci-dma.c              | 15 ++++++-----
 drivers/xen/swiotlb-xen.c              |  4 +--
 include/linux/swiotlb.h                | 15 ++++++-----
 include/trace/events/swiotlb.h         | 29 ++++++++-------------
 kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
 15 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 6d0cb0f7bc54b..73f30d278b565 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -312,11 +312,7 @@ static void __init free_highpages(void)
 void __init mem_init(void)
 {
 #ifdef CONFIG_ARM_LPAE
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > arm_dma_pfn_limit)
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
 #endif
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index db63cc885771a..52102adda3d28 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -373,11 +373,7 @@ void __init bootmem_init(void)
  */
 void __init mem_init(void)
 {
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
-		swiotlb_init(1);
-	else if (!xen_swiotlb_detect())
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE);
 
 	/* this will put all unused low memory onto the freelists */
 	memblock_free_all();
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index 5d165607bf354..3c3e15b22608f 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -437,9 +437,7 @@ mem_init (void)
 		if (iommu_detected)
 			break;
 #endif
-#ifdef CONFIG_SWIOTLB
-		swiotlb_init(1);
-#endif
+		swiotlb_init(true, SWIOTLB_VERBOSE);
 	} while (0);
 
 #ifdef CONFIG_FLATMEM
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index fb7547e217263..9fbba6a8fa4c5 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
 #endif
 
 	swiotlb_adjust_size(swiotlbsize);
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index 364f2f27c8723..8220a1bc0db64 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
index eb47a94f3583e..c5c2c782aff68 100644
--- a/arch/mips/sibyte/common/dma.c
+++ b/arch/mips/sibyte/common/dma.c
@@ -10,5 +10,5 @@
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8e301cd8925b2..e1519e2edc656 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -17,6 +17,7 @@
 #include <linux/suspend.h>
 #include <linux/dma-direct.h>
 
+#include <asm/swiotlb.h>
 #include <asm/machdep.h>
 #include <asm/rtas.h>
 #include <asm/kasan.h>
@@ -251,7 +252,7 @@ void __init mem_init(void)
 	if (is_secure_guest())
 		svm_swiotlb_init();
 	else
-		swiotlb_init(0);
+		swiotlb_init(ppc_swiotlb_enable, 0);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 83a04d967a59f..45d637ab58261 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
 	}
 
 	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
-		ppc_swiotlb_enable = 1;
 }
 
 static void pseries_panic(char *str)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index cf4d018b7d668..e2c97b4ea2b48 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -118,13 +118,7 @@ void __init mem_init(void)
 	BUG_ON(!mem_map);
 #endif /* CONFIG_FLATMEM */
 
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(dma32_phys_limit))
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
-#endif
+	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
 	high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
 	memblock_free_all();
 
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 86ffd0d51fd59..6fb6bf64326f9 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -185,8 +185,7 @@ static void pv_init(void)
 		return;
 
 	/* make sure bounce buffers are shared */
-	swiotlb_force = SWIOTLB_FORCE;
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
 	swiotlb_update_mem_attributes();
 }
 
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 04140e20ef1a3..a705a199bf8a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
 
 #ifdef CONFIG_SWIOTLB
 bool x86_swiotlb_enable;
+static unsigned int x86_swiotlb_flags;
 
 static void __init pci_swiotlb_detect(void)
 {
@@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
 	 * bounce buffers as the hypervisor can't access arbitrary VM memory
 	 * that is not explicitly shared with it.
 	 */
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
+		x86_swiotlb_flags |= SWIOTLB_FORCE;
+	}
 }
 #else
 static inline void __init pci_swiotlb_detect(void)
 {
 }
+#define x86_swiotlb_flags 0
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
@@ -75,8 +76,7 @@ static bool xen_swiotlb;
 
 static void __init pci_xen_swiotlb_init(void)
 {
-	if (!xen_initial_domain() && !x86_swiotlb_enable &&
-	    swiotlb_force != SWIOTLB_FORCE)
+	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
 	xen_swiotlb = true;
@@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
 	gart_iommu_hole_init();
 	amd_iommu_detect();
 	detect_intel_iommu();
-	if (x86_swiotlb_enable)
-		swiotlb_init(0);
+	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
 }
 
 /*
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 485cd06ed39e7..c2da3eb4826e8 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
 		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
 	}
 
-	if (swiotlb_init_with_tbl(start, nslabs, true))
+	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
 		panic("Cannot allocate SWIOTLB buffer");
 }
 #endif /* CONFIG_X86 */
@@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	/*
 	 * Oh well, have to allocate and map a bounce buffer.
 	 */
-	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+	trace_swiotlb_bounced(dev, dev_addr, size);
 
 	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
 	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index b48b26bfa0edb..ae0407173e845 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -13,11 +13,8 @@ struct device;
 struct page;
 struct scatterlist;
 
-enum swiotlb_force {
-	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc. */
-	SWIOTLB_FORCE,		/* swiotlb=force */
-	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
-};
+#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
+#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
@@ -36,8 +33,7 @@ enum swiotlb_force {
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-extern void swiotlb_init(int verbose);
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 int swiotlb_init_late(size_t size);
@@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
 	return mem && mem->force_bounce;
 }
 
+void swiotlb_init(bool addressing_limited, unsigned int flags);
 void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
 bool is_swiotlb_active(struct device *dev);
 void __init swiotlb_adjust_size(unsigned long size);
 #else
-#define swiotlb_force SWIOTLB_NO_FORCE
+static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
+{
+}
 static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
 {
 	return false;
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index 705be43b71ab0..da05c9ebd224a 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -8,20 +8,15 @@
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(swiotlb_bounced,
-
-	TP_PROTO(struct device *dev,
-		 dma_addr_t dev_addr,
-		 size_t size,
-		 enum swiotlb_force swiotlb_force),
-
-	TP_ARGS(dev, dev_addr, size, swiotlb_force),
+	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
+	TP_ARGS(dev, dev_addr, size),
 
 	TP_STRUCT__entry(
-		__string(	dev_name,	dev_name(dev)		)
-		__field(	u64,	dma_mask			)
-		__field(	dma_addr_t,	dev_addr		)
-		__field(	size_t,	size				)
-		__field(	enum swiotlb_force,	swiotlb_force	)
+		__string(dev_name, dev_name(dev))
+		__field(u64, dma_mask)
+		__field(dma_addr_t, dev_addr)
+		__field(size_t, size)
+		__field(bool, force)
 	),
 
 	TP_fast_assign(
@@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
 		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
 		__entry->dev_addr = dev_addr;
 		__entry->size = size;
-		__entry->swiotlb_force = swiotlb_force;
+		__entry->force = is_swiotlb_force_bounce(dev);
 	),
 
-	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
-		"size=%zu %s",
+	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
 		__get_str(dev_name),
 		__entry->dma_mask,
 		(unsigned long long)__entry->dev_addr,
 		__entry->size,
-		__print_symbolic(__entry->swiotlb_force,
-			{ SWIOTLB_NORMAL,	"NORMAL" },
-			{ SWIOTLB_FORCE,	"FORCE" },
-			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
+		__entry->force ? "FORCE" : "NORMAL")
 );
 
 #endif /*  _TRACE_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 14e08fa9621c2..5ac6e128d4279 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -62,7 +62,8 @@
 
 #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
 
-enum swiotlb_force swiotlb_force;
+static bool swiotlb_force_bounce;
+static bool swiotlb_force_disable;
 
 struct io_tlb_mem io_tlb_default_mem;
 
@@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
 	if (*str == ',')
 		++str;
 	if (!strcmp(str, "force"))
-		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_force_bounce = true;
 	else if (!strcmp(str, "noforce"))
-		swiotlb_force = SWIOTLB_NO_FORCE;
+		swiotlb_force_disable = true;
 
 	return 0;
 }
@@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		mem->force_bounce = true;
 
 	spin_lock_init(&mem->lock);
@@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
+int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
+		unsigned int flags)
 {
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	size_t alloc_size;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
 
-	if (verbose)
+	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
 	return 0;
 }
@@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void  __init
-swiotlb_init(int verbose)
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 {
 	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	void *tlb;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (!addressing_limit && !swiotlb_force_bounce)
+		return;
+	if (swiotlb_force_disable)
 		return;
 
 	/* Get IO TLB memory from the low pages */
 	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
+	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
 
@@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
 	unsigned int order;
 	int rc = 0;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/*
@@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long bytes = nslabs << IO_TLB_SHIFT;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		return;
 
 	if (!mem->nslabs)
@@ -699,8 +703,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
 	phys_addr_t swiotlb_addr;
 	dma_addr_t dma_addr;
 
-	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
-			      swiotlb_force);
+	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
 
 	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
 			attrs);
-- 
2.30.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-03-14  7:31   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-03-14  7:31 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Pass a bool to pass if swiotlb needs to be enabled based on the
addressing needs and replace the verbose argument with a set of
flags, including one to force enable bounce buffering.

Note that this patch removes the possibility to force xen-swiotlb
use using swiotlb=force on the command line on x86 (arm and arm64
never supported that), but this interface will be restored shortly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/mm/init.c                     |  6 +----
 arch/arm64/mm/init.c                   |  6 +----
 arch/ia64/mm/init.c                    |  4 +--
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/sibyte/common/dma.c          |  2 +-
 arch/powerpc/mm/mem.c                  |  3 ++-
 arch/powerpc/platforms/pseries/setup.c |  3 ---
 arch/riscv/mm/init.c                   |  8 +-----
 arch/s390/mm/init.c                    |  3 +--
 arch/x86/kernel/pci-dma.c              | 15 ++++++-----
 drivers/xen/swiotlb-xen.c              |  4 +--
 include/linux/swiotlb.h                | 15 ++++++-----
 include/trace/events/swiotlb.h         | 29 ++++++++-------------
 kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
 15 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 6d0cb0f7bc54b..73f30d278b565 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -312,11 +312,7 @@ static void __init free_highpages(void)
 void __init mem_init(void)
 {
 #ifdef CONFIG_ARM_LPAE
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > arm_dma_pfn_limit)
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
 #endif
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index db63cc885771a..52102adda3d28 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -373,11 +373,7 @@ void __init bootmem_init(void)
  */
 void __init mem_init(void)
 {
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
-		swiotlb_init(1);
-	else if (!xen_swiotlb_detect())
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE);
 
 	/* this will put all unused low memory onto the freelists */
 	memblock_free_all();
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index 5d165607bf354..3c3e15b22608f 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -437,9 +437,7 @@ mem_init (void)
 		if (iommu_detected)
 			break;
 #endif
-#ifdef CONFIG_SWIOTLB
-		swiotlb_init(1);
-#endif
+		swiotlb_init(true, SWIOTLB_VERBOSE);
 	} while (0);
 
 #ifdef CONFIG_FLATMEM
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index fb7547e217263..9fbba6a8fa4c5 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
 #endif
 
 	swiotlb_adjust_size(swiotlbsize);
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index 364f2f27c8723..8220a1bc0db64 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
index eb47a94f3583e..c5c2c782aff68 100644
--- a/arch/mips/sibyte/common/dma.c
+++ b/arch/mips/sibyte/common/dma.c
@@ -10,5 +10,5 @@
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8e301cd8925b2..e1519e2edc656 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -17,6 +17,7 @@
 #include <linux/suspend.h>
 #include <linux/dma-direct.h>
 
+#include <asm/swiotlb.h>
 #include <asm/machdep.h>
 #include <asm/rtas.h>
 #include <asm/kasan.h>
@@ -251,7 +252,7 @@ void __init mem_init(void)
 	if (is_secure_guest())
 		svm_swiotlb_init();
 	else
-		swiotlb_init(0);
+		swiotlb_init(ppc_swiotlb_enable, 0);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 83a04d967a59f..45d637ab58261 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
 	}
 
 	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
-		ppc_swiotlb_enable = 1;
 }
 
 static void pseries_panic(char *str)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index cf4d018b7d668..e2c97b4ea2b48 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -118,13 +118,7 @@ void __init mem_init(void)
 	BUG_ON(!mem_map);
 #endif /* CONFIG_FLATMEM */
 
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(dma32_phys_limit))
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
-#endif
+	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
 	high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
 	memblock_free_all();
 
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 86ffd0d51fd59..6fb6bf64326f9 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -185,8 +185,7 @@ static void pv_init(void)
 		return;
 
 	/* make sure bounce buffers are shared */
-	swiotlb_force = SWIOTLB_FORCE;
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
 	swiotlb_update_mem_attributes();
 }
 
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 04140e20ef1a3..a705a199bf8a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
 
 #ifdef CONFIG_SWIOTLB
 bool x86_swiotlb_enable;
+static unsigned int x86_swiotlb_flags;
 
 static void __init pci_swiotlb_detect(void)
 {
@@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
 	 * bounce buffers as the hypervisor can't access arbitrary VM memory
 	 * that is not explicitly shared with it.
 	 */
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
+		x86_swiotlb_flags |= SWIOTLB_FORCE;
+	}
 }
 #else
 static inline void __init pci_swiotlb_detect(void)
 {
 }
+#define x86_swiotlb_flags 0
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
@@ -75,8 +76,7 @@ static bool xen_swiotlb;
 
 static void __init pci_xen_swiotlb_init(void)
 {
-	if (!xen_initial_domain() && !x86_swiotlb_enable &&
-	    swiotlb_force != SWIOTLB_FORCE)
+	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
 	xen_swiotlb = true;
@@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
 	gart_iommu_hole_init();
 	amd_iommu_detect();
 	detect_intel_iommu();
-	if (x86_swiotlb_enable)
-		swiotlb_init(0);
+	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
 }
 
 /*
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 485cd06ed39e7..c2da3eb4826e8 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
 		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
 	}
 
-	if (swiotlb_init_with_tbl(start, nslabs, true))
+	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
 		panic("Cannot allocate SWIOTLB buffer");
 }
 #endif /* CONFIG_X86 */
@@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	/*
 	 * Oh well, have to allocate and map a bounce buffer.
 	 */
-	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+	trace_swiotlb_bounced(dev, dev_addr, size);
 
 	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
 	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index b48b26bfa0edb..ae0407173e845 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -13,11 +13,8 @@ struct device;
 struct page;
 struct scatterlist;
 
-enum swiotlb_force {
-	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc. */
-	SWIOTLB_FORCE,		/* swiotlb=force */
-	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
-};
+#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
+#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
@@ -36,8 +33,7 @@ enum swiotlb_force {
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-extern void swiotlb_init(int verbose);
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 int swiotlb_init_late(size_t size);
@@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
 	return mem && mem->force_bounce;
 }
 
+void swiotlb_init(bool addressing_limited, unsigned int flags);
 void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
 bool is_swiotlb_active(struct device *dev);
 void __init swiotlb_adjust_size(unsigned long size);
 #else
-#define swiotlb_force SWIOTLB_NO_FORCE
+static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
+{
+}
 static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
 {
 	return false;
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index 705be43b71ab0..da05c9ebd224a 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -8,20 +8,15 @@
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(swiotlb_bounced,
-
-	TP_PROTO(struct device *dev,
-		 dma_addr_t dev_addr,
-		 size_t size,
-		 enum swiotlb_force swiotlb_force),
-
-	TP_ARGS(dev, dev_addr, size, swiotlb_force),
+	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
+	TP_ARGS(dev, dev_addr, size),
 
 	TP_STRUCT__entry(
-		__string(	dev_name,	dev_name(dev)		)
-		__field(	u64,	dma_mask			)
-		__field(	dma_addr_t,	dev_addr		)
-		__field(	size_t,	size				)
-		__field(	enum swiotlb_force,	swiotlb_force	)
+		__string(dev_name, dev_name(dev))
+		__field(u64, dma_mask)
+		__field(dma_addr_t, dev_addr)
+		__field(size_t, size)
+		__field(bool, force)
 	),
 
 	TP_fast_assign(
@@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
 		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
 		__entry->dev_addr = dev_addr;
 		__entry->size = size;
-		__entry->swiotlb_force = swiotlb_force;
+		__entry->force = is_swiotlb_force_bounce(dev);
 	),
 
-	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
-		"size=%zu %s",
+	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
 		__get_str(dev_name),
 		__entry->dma_mask,
 		(unsigned long long)__entry->dev_addr,
 		__entry->size,
-		__print_symbolic(__entry->swiotlb_force,
-			{ SWIOTLB_NORMAL,	"NORMAL" },
-			{ SWIOTLB_FORCE,	"FORCE" },
-			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
+		__entry->force ? "FORCE" : "NORMAL")
 );
 
 #endif /*  _TRACE_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 14e08fa9621c2..5ac6e128d4279 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -62,7 +62,8 @@
 
 #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
 
-enum swiotlb_force swiotlb_force;
+static bool swiotlb_force_bounce;
+static bool swiotlb_force_disable;
 
 struct io_tlb_mem io_tlb_default_mem;
 
@@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
 	if (*str == ',')
 		++str;
 	if (!strcmp(str, "force"))
-		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_force_bounce = true;
 	else if (!strcmp(str, "noforce"))
-		swiotlb_force = SWIOTLB_NO_FORCE;
+		swiotlb_force_disable = true;
 
 	return 0;
 }
@@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		mem->force_bounce = true;
 
 	spin_lock_init(&mem->lock);
@@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
+int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
+		unsigned int flags)
 {
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	size_t alloc_size;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
 
-	if (verbose)
+	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
 	return 0;
 }
@@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void  __init
-swiotlb_init(int verbose)
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 {
 	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	void *tlb;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (!addressing_limit && !swiotlb_force_bounce)
+		return;
+	if (swiotlb_force_disable)
 		return;
 
 	/* Get IO TLB memory from the low pages */
 	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
+	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
 
@@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
 	unsigned int order;
 	int rc = 0;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/*
@@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long bytes = nslabs << IO_TLB_SHIFT;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		return;
 
 	if (!mem->nslabs)
@@ -699,8 +703,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
 	phys_addr_t swiotlb_addr;
 	dma_addr_t dma_addr;
 
-	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
-			      swiotlb_force);
+	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
 
 	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
 			attrs);
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-03-14  7:31   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-03-14  7:31 UTC (permalink / raw)
  To: iommu
  Cc: Juergen Gross, Tom Lendacky, linux-s390, Stefano Stabellini,
	linux-ia64, Anshuman Khandual, Konrad Rzeszutek Wilk,
	Robin Murphy, Joerg Roedel, x86, linux-mips, linuxppc-dev,
	tboot-devel, linux-hyperv, linux-pci, xen-devel, Boris Ostrovsky,
	David Woodhouse, linux-riscv, linux-arm-kernel, Lu Baolu

Pass a bool to pass if swiotlb needs to be enabled based on the
addressing needs and replace the verbose argument with a set of
flags, including one to force enable bounce buffering.

Note that this patch removes the possibility to force xen-swiotlb
use using swiotlb=force on the command line on x86 (arm and arm64
never supported that), but this interface will be restored shortly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/mm/init.c                     |  6 +----
 arch/arm64/mm/init.c                   |  6 +----
 arch/ia64/mm/init.c                    |  4 +--
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/sibyte/common/dma.c          |  2 +-
 arch/powerpc/mm/mem.c                  |  3 ++-
 arch/powerpc/platforms/pseries/setup.c |  3 ---
 arch/riscv/mm/init.c                   |  8 +-----
 arch/s390/mm/init.c                    |  3 +--
 arch/x86/kernel/pci-dma.c              | 15 ++++++-----
 drivers/xen/swiotlb-xen.c              |  4 +--
 include/linux/swiotlb.h                | 15 ++++++-----
 include/trace/events/swiotlb.h         | 29 ++++++++-------------
 kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
 15 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 6d0cb0f7bc54b..73f30d278b565 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -312,11 +312,7 @@ static void __init free_highpages(void)
 void __init mem_init(void)
 {
 #ifdef CONFIG_ARM_LPAE
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > arm_dma_pfn_limit)
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
 #endif
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index db63cc885771a..52102adda3d28 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -373,11 +373,7 @@ void __init bootmem_init(void)
  */
 void __init mem_init(void)
 {
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
-		swiotlb_init(1);
-	else if (!xen_swiotlb_detect())
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE);
 
 	/* this will put all unused low memory onto the freelists */
 	memblock_free_all();
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index 5d165607bf354..3c3e15b22608f 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -437,9 +437,7 @@ mem_init (void)
 		if (iommu_detected)
 			break;
 #endif
-#ifdef CONFIG_SWIOTLB
-		swiotlb_init(1);
-#endif
+		swiotlb_init(true, SWIOTLB_VERBOSE);
 	} while (0);
 
 #ifdef CONFIG_FLATMEM
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index fb7547e217263..9fbba6a8fa4c5 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
 #endif
 
 	swiotlb_adjust_size(swiotlbsize);
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index 364f2f27c8723..8220a1bc0db64 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
index eb47a94f3583e..c5c2c782aff68 100644
--- a/arch/mips/sibyte/common/dma.c
+++ b/arch/mips/sibyte/common/dma.c
@@ -10,5 +10,5 @@
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8e301cd8925b2..e1519e2edc656 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -17,6 +17,7 @@
 #include <linux/suspend.h>
 #include <linux/dma-direct.h>
 
+#include <asm/swiotlb.h>
 #include <asm/machdep.h>
 #include <asm/rtas.h>
 #include <asm/kasan.h>
@@ -251,7 +252,7 @@ void __init mem_init(void)
 	if (is_secure_guest())
 		svm_swiotlb_init();
 	else
-		swiotlb_init(0);
+		swiotlb_init(ppc_swiotlb_enable, 0);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 83a04d967a59f..45d637ab58261 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
 	}
 
 	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
-		ppc_swiotlb_enable = 1;
 }
 
 static void pseries_panic(char *str)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index cf4d018b7d668..e2c97b4ea2b48 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -118,13 +118,7 @@ void __init mem_init(void)
 	BUG_ON(!mem_map);
 #endif /* CONFIG_FLATMEM */
 
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_force == SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(dma32_phys_limit))
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
-#endif
+	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
 	high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
 	memblock_free_all();
 
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 86ffd0d51fd59..6fb6bf64326f9 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -185,8 +185,7 @@ static void pv_init(void)
 		return;
 
 	/* make sure bounce buffers are shared */
-	swiotlb_force = SWIOTLB_FORCE;
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
 	swiotlb_update_mem_attributes();
 }
 
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 04140e20ef1a3..a705a199bf8a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
 
 #ifdef CONFIG_SWIOTLB
 bool x86_swiotlb_enable;
+static unsigned int x86_swiotlb_flags;
 
 static void __init pci_swiotlb_detect(void)
 {
@@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
 	 * bounce buffers as the hypervisor can't access arbitrary VM memory
 	 * that is not explicitly shared with it.
 	 */
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
+		x86_swiotlb_flags |= SWIOTLB_FORCE;
+	}
 }
 #else
 static inline void __init pci_swiotlb_detect(void)
 {
 }
+#define x86_swiotlb_flags 0
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
@@ -75,8 +76,7 @@ static bool xen_swiotlb;
 
 static void __init pci_xen_swiotlb_init(void)
 {
-	if (!xen_initial_domain() && !x86_swiotlb_enable &&
-	    swiotlb_force != SWIOTLB_FORCE)
+	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
 	xen_swiotlb = true;
@@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
 	gart_iommu_hole_init();
 	amd_iommu_detect();
 	detect_intel_iommu();
-	if (x86_swiotlb_enable)
-		swiotlb_init(0);
+	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
 }
 
 /*
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 485cd06ed39e7..c2da3eb4826e8 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
 		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
 	}
 
-	if (swiotlb_init_with_tbl(start, nslabs, true))
+	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
 		panic("Cannot allocate SWIOTLB buffer");
 }
 #endif /* CONFIG_X86 */
@@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	/*
 	 * Oh well, have to allocate and map a bounce buffer.
 	 */
-	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+	trace_swiotlb_bounced(dev, dev_addr, size);
 
 	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
 	if (map == (phys_addr_t)DMA_MAPPING_ERROR)
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index b48b26bfa0edb..ae0407173e845 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -13,11 +13,8 @@ struct device;
 struct page;
 struct scatterlist;
 
-enum swiotlb_force {
-	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc. */
-	SWIOTLB_FORCE,		/* swiotlb=force */
-	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
-};
+#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
+#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
@@ -36,8 +33,7 @@ enum swiotlb_force {
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-extern void swiotlb_init(int verbose);
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 int swiotlb_init_late(size_t size);
@@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
 	return mem && mem->force_bounce;
 }
 
+void swiotlb_init(bool addressing_limited, unsigned int flags);
 void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
 bool is_swiotlb_active(struct device *dev);
 void __init swiotlb_adjust_size(unsigned long size);
 #else
-#define swiotlb_force SWIOTLB_NO_FORCE
+static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
+{
+}
 static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
 {
 	return false;
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index 705be43b71ab0..da05c9ebd224a 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -8,20 +8,15 @@
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(swiotlb_bounced,
-
-	TP_PROTO(struct device *dev,
-		 dma_addr_t dev_addr,
-		 size_t size,
-		 enum swiotlb_force swiotlb_force),
-
-	TP_ARGS(dev, dev_addr, size, swiotlb_force),
+	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
+	TP_ARGS(dev, dev_addr, size),
 
 	TP_STRUCT__entry(
-		__string(	dev_name,	dev_name(dev)		)
-		__field(	u64,	dma_mask			)
-		__field(	dma_addr_t,	dev_addr		)
-		__field(	size_t,	size				)
-		__field(	enum swiotlb_force,	swiotlb_force	)
+		__string(dev_name, dev_name(dev))
+		__field(u64, dma_mask)
+		__field(dma_addr_t, dev_addr)
+		__field(size_t, size)
+		__field(bool, force)
 	),
 
 	TP_fast_assign(
@@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
 		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
 		__entry->dev_addr = dev_addr;
 		__entry->size = size;
-		__entry->swiotlb_force = swiotlb_force;
+		__entry->force = is_swiotlb_force_bounce(dev);
 	),
 
-	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
-		"size=%zu %s",
+	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
 		__get_str(dev_name),
 		__entry->dma_mask,
 		(unsigned long long)__entry->dev_addr,
 		__entry->size,
-		__print_symbolic(__entry->swiotlb_force,
-			{ SWIOTLB_NORMAL,	"NORMAL" },
-			{ SWIOTLB_FORCE,	"FORCE" },
-			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
+		__entry->force ? "FORCE" : "NORMAL")
 );
 
 #endif /*  _TRACE_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 14e08fa9621c2..5ac6e128d4279 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -62,7 +62,8 @@
 
 #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
 
-enum swiotlb_force swiotlb_force;
+static bool swiotlb_force_bounce;
+static bool swiotlb_force_disable;
 
 struct io_tlb_mem io_tlb_default_mem;
 
@@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
 	if (*str == ',')
 		++str;
 	if (!strcmp(str, "force"))
-		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_force_bounce = true;
 	else if (!strcmp(str, "noforce"))
-		swiotlb_force = SWIOTLB_NO_FORCE;
+		swiotlb_force_disable = true;
 
 	return 0;
 }
@@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		mem->force_bounce = true;
 
 	spin_lock_init(&mem->lock);
@@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
+int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
+		unsigned int flags)
 {
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	size_t alloc_size;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
 
-	if (verbose)
+	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
 	return 0;
 }
@@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void  __init
-swiotlb_init(int verbose)
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 {
 	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	void *tlb;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (!addressing_limit && !swiotlb_force_bounce)
+		return;
+	if (swiotlb_force_disable)
 		return;
 
 	/* Get IO TLB memory from the low pages */
 	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
+	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
 
@@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
 	unsigned int order;
 	int rc = 0;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/*
@@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long bytes = nslabs << IO_TLB_SHIFT;
 
-	if (swiotlb_force == SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
-	if (swiotlb_force == SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		return;
 
 	if (!mem->nslabs)
@@ -699,8 +703,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
 	phys_addr_t swiotlb_addr;
 	dma_addr_t dma_addr;
 
-	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
-			      swiotlb_force);
+	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
 
 	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
 			attrs);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 197+ messages in thread

* [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful
@ 2022-03-14  7:31   ` Christoph Hellwig
  0 siblings, 0 replies; 197+ messages in thread
From: Christoph Hellwig @ 2022-03-14  7:31 UTC (permalink / raw)
  To: iommu
  Cc: x86, Anshuman Khandual, Tom Lendacky, Konrad Rzeszutek Wilk,
	Stefano Stabellini, Boris Ostrovsky, Juergen Gross, Joerg Roedel,
	David Woodhouse, Lu Baolu, Robin Murphy, linux-arm-kernel,
	xen-devel, linux-ia64, linux-mips, linuxppc-dev, linux-riscv,
	linux-s390, linux-hyperv, tboot-devel, linux-pci

Pass a bool to pass if swiotlb needs to be enabled based on the
addressing needs and replace the verbose argument with a set of
flags, including one to force enable bounce buffering.

Note that this patch removes the possibility to force xen-swiotlb
use using swiotlb=force on the command line on x86 (arm and arm64
never supported that), but this interface will be restored shortly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/mm/init.c                     |  6 +----
 arch/arm64/mm/init.c                   |  6 +----
 arch/ia64/mm/init.c                    |  4 +--
 arch/mips/cavium-octeon/dma-octeon.c   |  2 +-
 arch/mips/loongson64/dma.c             |  2 +-
 arch/mips/sibyte/common/dma.c          |  2 +-
 arch/powerpc/mm/mem.c                  |  3 ++-
 arch/powerpc/platforms/pseries/setup.c |  3 ---
 arch/riscv/mm/init.c                   |  8 +-----
 arch/s390/mm/init.c                    |  3 +--
 arch/x86/kernel/pci-dma.c              | 15 ++++++-----
 drivers/xen/swiotlb-xen.c              |  4 +--
 include/linux/swiotlb.h                | 15 ++++++-----
 include/trace/events/swiotlb.h         | 29 ++++++++-------------
 kernel/dma/swiotlb.c                   | 35 ++++++++++++++------------
 15 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 6d0cb0f7bc54b..73f30d278b565 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -312,11 +312,7 @@ static void __init free_highpages(void)
 void __init mem_init(void)
 {
 #ifdef CONFIG_ARM_LPAE
-	if (swiotlb_force = SWIOTLB_FORCE ||
-	    max_pfn > arm_dma_pfn_limit)
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
 #endif
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index db63cc885771a..52102adda3d28 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -373,11 +373,7 @@ void __init bootmem_init(void)
  */
 void __init mem_init(void)
 {
-	if (swiotlb_force = SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(arm64_dma_phys_limit))
-		swiotlb_init(1);
-	else if (!xen_swiotlb_detect())
-		swiotlb_force = SWIOTLB_NO_FORCE;
+	swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE);
 
 	/* this will put all unused low memory onto the freelists */
 	memblock_free_all();
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
index 5d165607bf354..3c3e15b22608f 100644
--- a/arch/ia64/mm/init.c
+++ b/arch/ia64/mm/init.c
@@ -437,9 +437,7 @@ mem_init (void)
 		if (iommu_detected)
 			break;
 #endif
-#ifdef CONFIG_SWIOTLB
-		swiotlb_init(1);
-#endif
+		swiotlb_init(true, SWIOTLB_VERBOSE);
 	} while (0);
 
 #ifdef CONFIG_FLATMEM
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index fb7547e217263..9fbba6a8fa4c5 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -235,5 +235,5 @@ void __init plat_swiotlb_setup(void)
 #endif
 
 	swiotlb_adjust_size(swiotlbsize);
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index 364f2f27c8723..8220a1bc0db64 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -24,5 +24,5 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/mips/sibyte/common/dma.c b/arch/mips/sibyte/common/dma.c
index eb47a94f3583e..c5c2c782aff68 100644
--- a/arch/mips/sibyte/common/dma.c
+++ b/arch/mips/sibyte/common/dma.c
@@ -10,5 +10,5 @@
 
 void __init plat_swiotlb_setup(void)
 {
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_VERBOSE);
 }
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8e301cd8925b2..e1519e2edc656 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -17,6 +17,7 @@
 #include <linux/suspend.h>
 #include <linux/dma-direct.h>
 
+#include <asm/swiotlb.h>
 #include <asm/machdep.h>
 #include <asm/rtas.h>
 #include <asm/kasan.h>
@@ -251,7 +252,7 @@ void __init mem_init(void)
 	if (is_secure_guest())
 		svm_swiotlb_init();
 	else
-		swiotlb_init(0);
+		swiotlb_init(ppc_swiotlb_enable, 0);
 #endif
 
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 83a04d967a59f..45d637ab58261 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -838,9 +838,6 @@ static void __init pSeries_setup_arch(void)
 	}
 
 	ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
-
-	if (swiotlb_force = SWIOTLB_FORCE)
-		ppc_swiotlb_enable = 1;
 }
 
 static void pseries_panic(char *str)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index cf4d018b7d668..e2c97b4ea2b48 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -118,13 +118,7 @@ void __init mem_init(void)
 	BUG_ON(!mem_map);
 #endif /* CONFIG_FLATMEM */
 
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_force = SWIOTLB_FORCE ||
-	    max_pfn > PFN_DOWN(dma32_phys_limit))
-		swiotlb_init(1);
-	else
-		swiotlb_force = SWIOTLB_NO_FORCE;
-#endif
+	swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE);
 	high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
 	memblock_free_all();
 
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 86ffd0d51fd59..6fb6bf64326f9 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -185,8 +185,7 @@ static void pv_init(void)
 		return;
 
 	/* make sure bounce buffers are shared */
-	swiotlb_force = SWIOTLB_FORCE;
-	swiotlb_init(1);
+	swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
 	swiotlb_update_mem_attributes();
 }
 
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 04140e20ef1a3..a705a199bf8a3 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -39,6 +39,7 @@ int iommu_detected __read_mostly = 0;
 
 #ifdef CONFIG_SWIOTLB
 bool x86_swiotlb_enable;
+static unsigned int x86_swiotlb_flags;
 
 static void __init pci_swiotlb_detect(void)
 {
@@ -58,16 +59,16 @@ static void __init pci_swiotlb_detect(void)
 	 * bounce buffers as the hypervisor can't access arbitrary VM memory
 	 * that is not explicitly shared with it.
 	 */
-	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-		swiotlb_force = SWIOTLB_FORCE;
-
-	if (swiotlb_force = SWIOTLB_FORCE)
+	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
+		x86_swiotlb_flags |= SWIOTLB_FORCE;
+	}
 }
 #else
 static inline void __init pci_swiotlb_detect(void)
 {
 }
+#define x86_swiotlb_flags 0
 #endif /* CONFIG_SWIOTLB */
 
 #ifdef CONFIG_SWIOTLB_XEN
@@ -75,8 +76,7 @@ static bool xen_swiotlb;
 
 static void __init pci_xen_swiotlb_init(void)
 {
-	if (!xen_initial_domain() && !x86_swiotlb_enable &&
-	    swiotlb_force != SWIOTLB_FORCE)
+	if (!xen_initial_domain() && !x86_swiotlb_enable)
 		return;
 	x86_swiotlb_enable = true;
 	xen_swiotlb = true;
@@ -120,8 +120,7 @@ void __init pci_iommu_alloc(void)
 	gart_iommu_hole_init();
 	amd_iommu_detect();
 	detect_intel_iommu();
-	if (x86_swiotlb_enable)
-		swiotlb_init(0);
+	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
 }
 
 /*
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 485cd06ed39e7..c2da3eb4826e8 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -251,7 +251,7 @@ void __init xen_swiotlb_init_early(void)
 		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
 	}
 
-	if (swiotlb_init_with_tbl(start, nslabs, true))
+	if (swiotlb_init_with_tbl(start, nslabs, SWIOTLB_VERBOSE))
 		panic("Cannot allocate SWIOTLB buffer");
 }
 #endif /* CONFIG_X86 */
@@ -376,7 +376,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
 	/*
 	 * Oh well, have to allocate and map a bounce buffer.
 	 */
-	trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
+	trace_swiotlb_bounced(dev, dev_addr, size);
 
 	map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs);
 	if (map = (phys_addr_t)DMA_MAPPING_ERROR)
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index b48b26bfa0edb..ae0407173e845 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -13,11 +13,8 @@ struct device;
 struct page;
 struct scatterlist;
 
-enum swiotlb_force {
-	SWIOTLB_NORMAL,		/* Default - depending on HW DMA mask etc. */
-	SWIOTLB_FORCE,		/* swiotlb=force */
-	SWIOTLB_NO_FORCE,	/* swiotlb=noforce */
-};
+#define SWIOTLB_VERBOSE	(1 << 0) /* verbose initialization */
+#define SWIOTLB_FORCE	(1 << 1) /* force bounce buffering */
 
 /*
  * Maximum allowable number of contiguous slabs to map,
@@ -36,8 +33,7 @@ enum swiotlb_force {
 /* default to 64MB */
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
-extern void swiotlb_init(int verbose);
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, unsigned int flags);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 int swiotlb_init_late(size_t size);
@@ -126,13 +122,16 @@ static inline bool is_swiotlb_force_bounce(struct device *dev)
 	return mem && mem->force_bounce;
 }
 
+void swiotlb_init(bool addressing_limited, unsigned int flags);
 void __init swiotlb_exit(void);
 unsigned int swiotlb_max_segment(void);
 size_t swiotlb_max_mapping_size(struct device *dev);
 bool is_swiotlb_active(struct device *dev);
 void __init swiotlb_adjust_size(unsigned long size);
 #else
-#define swiotlb_force SWIOTLB_NO_FORCE
+static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
+{
+}
 static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
 {
 	return false;
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index 705be43b71ab0..da05c9ebd224a 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -8,20 +8,15 @@
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(swiotlb_bounced,
-
-	TP_PROTO(struct device *dev,
-		 dma_addr_t dev_addr,
-		 size_t size,
-		 enum swiotlb_force swiotlb_force),
-
-	TP_ARGS(dev, dev_addr, size, swiotlb_force),
+	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
+	TP_ARGS(dev, dev_addr, size),
 
 	TP_STRUCT__entry(
-		__string(	dev_name,	dev_name(dev)		)
-		__field(	u64,	dma_mask			)
-		__field(	dma_addr_t,	dev_addr		)
-		__field(	size_t,	size				)
-		__field(	enum swiotlb_force,	swiotlb_force	)
+		__string(dev_name, dev_name(dev))
+		__field(u64, dma_mask)
+		__field(dma_addr_t, dev_addr)
+		__field(size_t, size)
+		__field(bool, force)
 	),
 
 	TP_fast_assign(
@@ -29,19 +24,15 @@ TRACE_EVENT(swiotlb_bounced,
 		__entry->dma_mask = (dev->dma_mask ? *dev->dma_mask : 0);
 		__entry->dev_addr = dev_addr;
 		__entry->size = size;
-		__entry->swiotlb_force = swiotlb_force;
+		__entry->force = is_swiotlb_force_bounce(dev);
 	),
 
-	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx "
-		"size=%zu %s",
+	TP_printk("dev_name: %s dma_mask=%llx dev_addr=%llx size=%zu %s",
 		__get_str(dev_name),
 		__entry->dma_mask,
 		(unsigned long long)__entry->dev_addr,
 		__entry->size,
-		__print_symbolic(__entry->swiotlb_force,
-			{ SWIOTLB_NORMAL,	"NORMAL" },
-			{ SWIOTLB_FORCE,	"FORCE" },
-			{ SWIOTLB_NO_FORCE,	"NO_FORCE" }))
+		__entry->force ? "FORCE" : "NORMAL")
 );
 
 #endif /*  _TRACE_SWIOTLB_H */
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 14e08fa9621c2..5ac6e128d4279 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -62,7 +62,8 @@
 
 #define INVALID_PHYS_ADDR (~(phys_addr_t)0)
 
-enum swiotlb_force swiotlb_force;
+static bool swiotlb_force_bounce;
+static bool swiotlb_force_disable;
 
 struct io_tlb_mem io_tlb_default_mem;
 
@@ -81,9 +82,9 @@ setup_io_tlb_npages(char *str)
 	if (*str = ',')
 		++str;
 	if (!strcmp(str, "force"))
-		swiotlb_force = SWIOTLB_FORCE;
+		swiotlb_force_bounce = true;
 	else if (!strcmp(str, "noforce"))
-		swiotlb_force = SWIOTLB_NO_FORCE;
+		swiotlb_force_disable = true;
 
 	return 0;
 }
@@ -202,7 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	mem->index = 0;
 	mem->late_alloc = late_alloc;
 
-	if (swiotlb_force = SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		mem->force_bounce = true;
 
 	spin_lock_init(&mem->lock);
@@ -224,12 +225,13 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
 	return;
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
+int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs,
+		unsigned int flags)
 {
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	size_t alloc_size;
 
-	if (swiotlb_force = SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -243,8 +245,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 		      __func__, alloc_size, PAGE_SIZE);
 
 	swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
+	mem->force_bounce = flags & SWIOTLB_FORCE;
 
-	if (verbose)
+	if (flags & SWIOTLB_VERBOSE)
 		swiotlb_print_info();
 	return 0;
 }
@@ -253,20 +256,21 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
-void  __init
-swiotlb_init(int verbose)
+void __init swiotlb_init(bool addressing_limit, unsigned int flags)
 {
 	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
 	void *tlb;
 
-	if (swiotlb_force = SWIOTLB_NO_FORCE)
+	if (!addressing_limit && !swiotlb_force_bounce)
+		return;
+	if (swiotlb_force_disable)
 		return;
 
 	/* Get IO TLB memory from the low pages */
 	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
 	if (!tlb)
 		goto fail;
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
+	if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))
 		goto fail_free_mem;
 	return;
 
@@ -289,7 +293,7 @@ int swiotlb_init_late(size_t size)
 	unsigned int order;
 	int rc = 0;
 
-	if (swiotlb_force = SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/*
@@ -328,7 +332,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
 	struct io_tlb_mem *mem = &io_tlb_default_mem;
 	unsigned long bytes = nslabs << IO_TLB_SHIFT;
 
-	if (swiotlb_force = SWIOTLB_NO_FORCE)
+	if (swiotlb_force_disable)
 		return 0;
 
 	/* protect against double initialization */
@@ -353,7 +357,7 @@ void __init swiotlb_exit(void)
 	unsigned long tbl_vaddr;
 	size_t tbl_size, slots_size;
 
-	if (swiotlb_force = SWIOTLB_FORCE)
+	if (swiotlb_force_bounce)
 		return;
 
 	if (!mem->nslabs)
@@ -699,8 +703,7 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
 	phys_addr_t swiotlb_addr;
 	dma_addr_t dma_addr;
 
-	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
-			      swiotlb_force);
+	trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size);
 
 	swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir,
 			attrs);
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 197+ messages in thread

end of thread, other threads:[~2022-06-01 18:41 UTC | newest]

Thread overview: 197+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-04  5:05 cleanup swiotlb initialization v8 Christoph Hellwig
2022-04-04  5:05 ` Christoph Hellwig
2022-04-04  5:05 ` Christoph Hellwig
2022-04-04  5:05 ` Christoph Hellwig
2022-04-04  5:05 ` Christoph Hellwig
2022-04-04  5:05 ` Christoph Hellwig
2022-04-04  5:05 ` [PATCH 01/15] dma-direct: use is_swiotlb_active in dma_direct_map_page Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05 ` [PATCH 02/15] swiotlb: make swiotlb_exit a no-op if SWIOTLB_FORCE is set Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05 ` [PATCH 03/15] swiotlb: simplify swiotlb_max_segment Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05 ` [PATCH 04/15] swiotlb: rename swiotlb_late_init_with_default_size Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05 ` [PATCH 05/15] arm/xen: don't check for xen_initial_domain() in xen_create_contiguous_region Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05 ` [PATCH 06/15] MIPS/octeon: use swiotlb_init instead of open coding it Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05 ` [PATCH 07/15] x86: remove the IOMMU table infrastructure Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-07  0:20   ` Konrad Rzeszutek Wilk
2022-04-07  0:20     ` Konrad Rzeszutek Wilk
2022-04-07  0:20     ` Konrad Rzeszutek Wilk
2022-04-07  0:20     ` Konrad Rzeszutek Wilk
2022-04-07  0:20     ` Konrad Rzeszutek Wilk
2022-04-07  0:20     ` Konrad Rzeszutek Wilk
2022-04-04  5:05 ` [PATCH 08/15] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05 ` [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04 17:00   ` Michael Kelley (LINUX)
2022-04-04 17:00     ` Michael Kelley (LINUX)
2022-04-04 17:00     ` Michael Kelley (LINUX)
2022-04-04 17:00     ` Michael Kelley (LINUX)
2022-04-04 17:00     ` Michael Kelley (LINUX)
2022-04-04 17:00     ` Michael Kelley (LINUX) via iommu
2022-06-01 17:25   ` Nathan Chancellor
2022-06-01 17:25     ` Nathan Chancellor
2022-06-01 17:25     ` Nathan Chancellor
2022-06-01 17:25     ` Nathan Chancellor
2022-06-01 17:25     ` Nathan Chancellor
2022-06-01 17:25     ` Nathan Chancellor
2022-06-01 17:34     ` Christoph Hellwig
2022-06-01 17:34       ` Christoph Hellwig
2022-06-01 17:34       ` Christoph Hellwig
2022-06-01 17:34       ` Christoph Hellwig
2022-06-01 17:34       ` Christoph Hellwig
2022-06-01 17:34       ` Christoph Hellwig
2022-06-01 17:46       ` Nathan Chancellor
2022-06-01 17:46         ` Nathan Chancellor
2022-06-01 17:46         ` Nathan Chancellor
2022-06-01 17:46         ` Nathan Chancellor
2022-06-01 17:46         ` Nathan Chancellor
2022-06-01 17:57         ` Christoph Hellwig
2022-06-01 17:57           ` Christoph Hellwig
2022-06-01 17:57           ` Christoph Hellwig
2022-06-01 17:57           ` Christoph Hellwig
2022-06-01 17:57           ` Christoph Hellwig
2022-06-01 17:57           ` Christoph Hellwig
2022-06-01 18:11           ` Nathan Chancellor
2022-06-01 18:11             ` Nathan Chancellor
2022-06-01 18:11             ` Nathan Chancellor
2022-06-01 18:11             ` Nathan Chancellor
2022-06-01 18:11             ` Nathan Chancellor
2022-06-01 18:11             ` Nathan Chancellor
2022-06-01 18:21             ` Christoph Hellwig
2022-06-01 18:21               ` Christoph Hellwig
2022-06-01 18:21               ` Christoph Hellwig
2022-06-01 18:21               ` Christoph Hellwig
2022-06-01 18:21               ` Christoph Hellwig
2022-06-01 18:21               ` Christoph Hellwig
2022-06-01 18:40               ` Nathan Chancellor
2022-06-01 18:40                 ` Nathan Chancellor
2022-06-01 18:40                 ` Nathan Chancellor
2022-06-01 18:40                 ` Nathan Chancellor
2022-06-01 18:40                 ` Nathan Chancellor
2022-06-01 18:40                 ` Nathan Chancellor
2022-04-04  5:05 ` [PATCH 10/15] swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-07  0:25   ` Konrad Rzeszutek Wilk
2022-04-07  0:25     ` Konrad Rzeszutek Wilk
2022-04-07  0:25     ` Konrad Rzeszutek Wilk
2022-04-07  0:25     ` Konrad Rzeszutek Wilk
2022-04-07  0:25     ` Konrad Rzeszutek Wilk
2022-04-07  0:25     ` Konrad Rzeszutek Wilk
2022-04-12  6:21     ` Christoph Hellwig
2022-04-12  6:21       ` Christoph Hellwig
2022-04-12  6:21       ` Christoph Hellwig
2022-04-12  6:21       ` Christoph Hellwig
2022-04-12  6:21       ` Christoph Hellwig
2022-04-12  6:21       ` Christoph Hellwig
2022-04-04  5:05 ` [PATCH 11/15] swiotlb: pass a gfp_mask argument to swiotlb_init_late Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05 ` [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  7:09   ` Dongli Zhang
2022-04-04  7:09     ` Dongli Zhang
2022-04-04  7:09     ` Dongli Zhang
2022-04-04  7:09     ` Dongli Zhang
2022-04-04  7:09     ` Dongli Zhang
2022-04-04  7:09     ` Dongli Zhang
2022-04-04  5:05 ` [PATCH 13/15] swiotlb: merge swiotlb-xen initialization into swiotlb Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05 ` [PATCH 14/15] swiotlb: remove swiotlb_init_with_tbl and swiotlb_init_late_with_tbl Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05 ` [PATCH 15/15] x86: remove cruft from <asm/dma-mapping.h> Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
2022-04-04  5:05   ` Christoph Hellwig
     [not found] ` <67c1784af6f24f3e871ddfb1478e821c@FR3P281MB0843.DEUP281.PROD.OUTLOOK.COM>
2022-04-04  6:19   ` [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer Alan Robinson
2022-04-04  6:19     ` Alan Robinson
2022-04-04  6:19     ` Alan Robinson
2022-04-04  6:19     ` Alan Robinson
2022-04-04  6:19     ` Alan Robinson
2022-04-04  6:19     ` Alan Robinson
2022-04-05 20:06 ` cleanup swiotlb initialization v8 Boris Ostrovsky
2022-04-05 20:06   ` Boris Ostrovsky
2022-04-05 20:06   ` Boris Ostrovsky
2022-04-05 20:06   ` Boris Ostrovsky
2022-04-05 20:06   ` Boris Ostrovsky
2022-04-05 20:06   ` Boris Ostrovsky
2022-04-07  0:31 ` Konrad Rzeszutek Wilk
2022-04-07  0:31   ` Konrad Rzeszutek Wilk
2022-04-07  0:31   ` Konrad Rzeszutek Wilk
2022-04-07  0:31   ` Konrad Rzeszutek Wilk
2022-04-07  0:31   ` Konrad Rzeszutek Wilk
2022-04-07  0:31   ` Konrad Rzeszutek Wilk
2022-04-13  6:20 ` Christoph Hellwig
2022-04-13  6:20   ` Christoph Hellwig
2022-04-13  6:20   ` Christoph Hellwig
2022-04-13  6:20   ` Christoph Hellwig
2022-04-13  6:20   ` Christoph Hellwig
2022-04-13  6:20   ` Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2022-03-14  7:31 cleanup swiotlb initialization v5 Christoph Hellwig
2022-03-14  7:31 ` [PATCH 09/15] swiotlb: make the swiotlb_init interface more useful Christoph Hellwig
2022-03-14  7:31   ` Christoph Hellwig
2022-03-14  7:31   ` Christoph Hellwig
2022-03-14  7:31   ` Christoph Hellwig
2022-03-14  7:31   ` Christoph Hellwig
2022-03-14  7:31   ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.