linux/drivers/infiniband/hw/hfi1
Shuhei Takeshita 62f0f34fbd IB/hfi1: Fix the PIO_CRED credit-return mmap
hfi1_file_mmap()'s PIO_CRED case must hand user space the single
credit-return page that holds this context's entry.  That page is the
second or third page of the per-node credit-return allocation once the
hardware send context index reaches 64 or 128, so the failure below is
intermittent: when the entry lands on the first page the offset is zero
and everything works.

Two things are wrong.

First, cr_page_offset is a byte offset but .va is a struct
credit_return *, so adding it is pointer arithmetic and scales the offset
by sizeof(struct credit_return) == 64.  memvirt then lands 256 KiB or
512 KiB past a 10240-byte allocation.  With an IOMMU translating, that
address is inside the vmalloc range but in no vm_area, so
dma_mmap_coherent() -> iommu_dma_mmap() finds no pages, vmalloc_to_pfn()
returns page_to_pfn(NULL), and remap_pfn_range() installs a frame above
MAXPHYADDR.  The first user read then takes:

  psm2_ep_open_pr: Corrupted page table at address 7a14d007e000
  PGD 800000013886a067 P4D 800000013886a067 PUD 13886b067 PMD 13886c067
                                            PTE 800049168e911235
  Oops: Bad pagetable: 000d [#1] SMP PTI

Second, and still wrong once the arithmetic is corrected,
dma_mmap_coherent() describes a whole coherent buffer and selects the
page within it with vma->vm_pgoff.  Offsetting cpu_addr has no effect:
for a vmap'd allocation iommu_dma_mmap() uses cpu_addr only to locate the
vm_area and then maps pages[vm_pgoff], which hfi1_file_mmap() has just
set to 0.  User space therefore always receives the first credit-return
page, every credit read is for the wrong context, and send PIO stalls
forever.

Use the DMA API as intended: pass the base of the allocation with its
full length and select the page with vm_pgoff.  A separate length is
needed because memlen must keep describing the VMA for the existing size
check.  The dma-direct path stays correct as well, since dma_direct_mmap()
adds the same vm_pgoff to the base pfn.

Tested on a Dell T7610 (Xeon E5-2650 v2, Intel IOMMU in DMA-FQ mode)
against a Threadripper PRO 3995WX peer, both Omni-Path 100.  Before this
change psm2_ep_open() Oopses the kernel; with only the arithmetic
corrected psm2_ep_open() succeeds but any transfer that uses send PIO
hangs, PSM2_SDMA=2 (send PIO disabled) completing normally while
PSM2_SDMA=0 (send PIO only) hangs every time.  With this change send PIO,
send DMA and the default mixed mode all work.

Fixes: 1ec82317a1 ("IB/hfi1: Use dma_mmap_coherent for matching buffers")
Cc: stable@vger.kernel.org
Signed-off-by: Shuhei Takeshita <jyohuku.alterego@gmail.com>
Link: https://patch.msgid.link/20260809032743.2671579-3-jyohuku.alterego@gmail.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
2026-09-01 09:27:41 -04:00
..
affinity.c Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
affinity.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
aspm.c RDMA/hfi1: Remove opa_vnic 2026-03-10 07:51:30 -04:00
aspm.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
chip_registers.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
chip.c RDMA/hfi1: Create workqueues before device initialization 2026-07-13 07:41:24 -04:00
chip.h RDMA/hfi1: Drop device data from hfi1_validate_rcvhdrcnt() 2026-07-13 07:41:24 -04:00
common.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
debugfs.c hfi1: get rid of redundant debugfs_file_{get,put}() 2025-07-09 13:30:28 +02:00
debugfs.h hfi1: get rid of redundant debugfs_file_{get,put}() 2025-07-09 13:30:28 +02:00
device.c RDMA/hfi1: Remove unused non-user-accessible device class 2026-07-06 02:10:33 -04:00
device.h RDMA/hfi1: Remove unused non-user-accessible device class 2026-07-06 02:10:33 -04:00
driver.c RDMA/hfi1: Remove opa_vnic 2026-03-10 07:51:30 -04:00
efivar.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
efivar.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
eprom.c IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
eprom.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
exp_rcv.c IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
exp_rcv.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
fault.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
fault.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
file_ops.c IB/hfi1: Fix the PIO_CRED credit-return mmap 2026-09-01 09:27:41 -04:00
firmware.c IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
hfi.h RDMA/hfi1: Create workqueues before device initialization 2026-07-13 07:41:24 -04:00
init.c RDMA/hfi1: Align probe error unwinding with device removal 2026-07-13 07:41:25 -04:00
intr.c IB/hfi1: Remove unused hfi1_format_hwerrors 2024-12-17 09:31:31 -05:00
iowait.c RDMA/hw/hfi1/iowait: Demote half-completed kernel-doc and fix formatting issue in another 2021-01-28 15:42:26 -04:00
iowait.h kernel-wide: add explicity||explicitly to spelling.txt 2025-01-12 20:21:06 -08:00
ipoib_main.c IB/hfi1: Remove generic .ndo_get_stats64 2024-05-05 17:10:38 +03:00
ipoib_rx.c IB/hfi1: Use skb_put_data() instead of skb_put/memcpy pair 2022-09-27 10:43:10 -03:00
ipoib_tx.c IB/hfi1: Remove open coded reference to skb frag offset 2023-09-18 14:24:15 +03:00
ipoib.h IB/hfi1: Fix alloc failure with larger txqueuelen 2022-01-28 11:12:15 -04:00
Kconfig RDMA/hfi1: Depend on !UML 2022-07-18 13:40:38 +03:00
mad.c RDMA/hfi1: Remove opa_vnic 2026-03-10 07:51:30 -04:00
mad.h IB/hfi1: Avoid -Wflex-array-member-not-at-end warning 2025-04-07 15:13:29 -03:00
Makefile RDMA/hfi1: Remove opa_vnic 2026-03-10 07:51:30 -04:00
mmu_rb.c RDMA/hfi1: Constify struct mmu_rb_ops 2024-06-26 10:53:29 -03:00
mmu_rb.h RDMA/hfi1: Constify struct mmu_rb_ops 2024-06-26 10:53:29 -03:00
msix.c RDMA/hfi1: Remove opa_vnic 2026-03-10 07:51:30 -04:00
msix.h RDMA/hfi1: Convert to SPDX identifier 2021-08-25 14:56:48 -03:00
netdev_rx.c RDMA/hfi1: Remove opa_vnic 2026-03-10 07:51:30 -04:00
netdev.h RDMA/hfi1: Remove opa_vnic 2026-03-10 07:51:30 -04:00
opa_compat.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
opfn.c hfi1: WQ_PERCPU added to alloc_workqueue users 2025-11-06 02:23:23 -05:00
opfn.h IB/hfi1: Make opfn.h self sufficient 2019-04-24 11:31:49 -03:00
pcie.c RDMA/hfi1: Allocate device data after PCI initialization 2026-07-13 07:41:25 -04:00
pin_system.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
pinning.h RDMA/hfi1: Move user SDMA system memory pinning code to its own file 2023-08-22 17:31:45 +03:00
pio_copy.c IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
pio.c IB/hfi1: Fix potential use-after-free in PIO and SDMA map teardown 2026-04-28 11:15:49 -03:00
pio.h IB/hfi1: Remove unused sc_drop and sdma_all_idle 2025-05-06 14:30:13 -03:00
platform.c IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
platform.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
qp.c RDMA: Remove outdated comments referencing hfi1_destroy_qp() 2026-03-30 13:47:44 -04:00
qp.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
qsfp.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
qsfp.h RDMA/hfi1: Remove unused one_qsfp_write 2025-02-24 10:05:39 -05:00
rc.c IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
rc.h IB/hfi1: Delay the release of destination mr for TID RDMA WRITE DATA 2019-04-03 15:27:30 -03:00
ruc.c IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
sdma_txreq.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
sdma.c RDMA/hfi1: Use sysfs_emit() for cpumask show helper 2026-07-22 15:38:37 -04:00
sdma.h IB/hfi1: Remove unused sc_drop and sdma_all_idle 2025-05-06 14:30:13 -03:00
sysfs.c sysfs: treewide: switch back to attribute_group::bin_attrs 2025-06-17 10:44:15 +02:00
tid_rdma.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
tid_rdma.h IB/hfi1: Calculate flow weight based on QP MTU for TID RDMA 2019-11-06 13:15:36 -04:00
trace_ctxts.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
trace_dbg.h tracing/treewide: Remove second parameter of __assign_str() 2024-05-22 20:14:47 -04:00
trace_ibhdrs.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
trace_iowait.h IB/hfi1: Add static trace for iowait 2018-09-30 19:21:12 -06:00
trace_misc.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
trace_mmu.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
trace_rc.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
trace_rx.h tracing/treewide: Remove second parameter of __assign_str() 2024-05-22 20:14:47 -04:00
trace_tid.h tracing/treewide: Remove second parameter of __assign_str() 2024-05-22 20:14:47 -04:00
trace_tx.h tracing/treewide: Remove second parameter of __assign_str() 2024-05-22 20:14:47 -04:00
trace.c IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
trace.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
uc.c IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
ud.c IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
user_exp_rcv.c IB/hfi1: kzalloc to kzalloc_flex 2026-03-10 14:04:09 -04:00
user_exp_rcv.h IB/hfi1: kzalloc to kzalloc_flex 2026-03-10 14:04:09 -04:00
user_pages.c IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
user_sdma.c RDMA/hfi1: Propagate sdma_txinit_ahg() errors 2026-07-20 09:00:39 -04:00
user_sdma.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
verbs_txreq.c IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
verbs_txreq.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00
verbs.c RDMA/hfi1: Remove opa_vnic 2026-03-10 07:51:30 -04:00
verbs.h IB: Use capital "OR" for multiple licenses in SPDX 2023-09-11 14:14:00 +03:00