FAILED: patch "[PATCH] IB/hfi1: Resolve the credit-return buffer through the send" failed to apply to 5.10-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 975396b9e5a4028e649f4b9a6a5ca5dfb76a824b
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026092207-spotless-rambling-6fce@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 975396b9e5a4028e649f4b9a6a5ca5dfb76a824b Mon Sep 17 00:00:00 2001
From: Shuhei Takeshita <[email protected]>
Date: Sun, 9 Aug 2026 12:27:42 +0900
Subject: [PATCH] IB/hfi1: Resolve the credit-return buffer through the send
context's node
hfi1_file_mmap()'s PIO_CRED case derives this context's credit-return page offset, and the DMA handle for it, from dd->cr_base[uctxt->numa_id]. uctxt->numa_id is the node of whichever CPU the process happened to be running on, but the entry itself lives in the credit-return allocation of the send context's own node:
sc->hw_free = &sc->dd->cr_base[sc->node].va[gc].cr[index];
and user send contexts are allocated with sc_alloc(dd, SC_USER, ..., dd->node), the HFI-local node. On a multi-socket host with the process running off that node the two allocations differ, so the subtraction produces an offset into an unrelated buffer and the DMA handle belongs to the wrong allocation.
Use the send context's own node for all three references. The continuation lines are reindented at the same time; they mixed spaces and tabs.
drivers/infiniband/hw/hfi1/file_ops.c +4 -4
@@ -382,10 +382,10 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)* of enabled contexts > 64 and 128 respectively). */ cr_page_offset = ((u64 )uctxt->sc->hw_free - - (u64 )dd->cr_base[uctxt->numa_id].va) & -PAGE_MASK ; - memvirt = dd->cr_base[uctxt->numa_id].va + cr_page_offset; - memdma = dd->cr_base[uctxt->numa_id].dma + cr_page_offset; + (u64 )dd->cr_base[uctxt->sc->node].va) & +PAGE_MASK ; + memvirt = dd->cr_base[uctxt->sc->node].va + cr_page_offset; + memdma = dd->cr_base[uctxt->sc->node].dma + cr_page_offset; memlen =PAGE_SIZE ; flags &= ~VM_MAYWRITE ; flags |=VM_DONTCOPY |VM_DONTEXPAND ;
Sasha Levin
maintainerPATCH 1/2 IB/hfi1: Use dma_mmap_coherent for matching buffers
From: Dean Luick <[email protected]>
[ Upstream commit 1ec82317a1daac78c04b0c15af89018ccf9fa2b7 ]
For memory allocated with dma_alloc_coherent(), use dma_mmap_coherent() to mmap it into user space.
Stable-dep-of: 975396b9e5a4 ("IB/hfi1: Resolve the credit-return buffer through the send context's node")
--- drivers/infiniband/hw/hfi1/file_ops.c | 81 +++++++++++++++++++-------- 1 file changed, 57 insertions(+), 24 deletions(-)
drivers/infiniband/hw/hfi1/file_ops.c +57 -24
@@ -347,6 +347,17 @@ static ssize_t hfi1_write_iter(struct kiocb *kiocb, struct iov_iter *from)return reqs; } +static inline void mmap_cdbg (u16 ctxt,u8 subctxt,u8 type,u8 mapio,u8 vmf, +u64 memaddr,void *memvirt,dma_addr_t memdma, +ssize_t memlen,struct vm_area_struct *vma) +{ +hfi1_cdbg (PROC , +"%u:%u type:%u io/vf/dma:%d/%d/%d, addr:0x%llx, len:%lu(%lu), flags:0x%lx" , + ctxt, subctxt, type, mapio, vmf, !!memdma, + memaddr ?: (u64 )memvirt, memlen, + vma->vm_end - vma->vm_start, vma->vm_flags); +} +static int hfi1_file_mmap (struct file *fp,struct vm_area_struct *vma) {struct hfi1_filedata *fd = fp->private_data;
@@ -356,6 +367,7 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)u64 token = vma->vm_pgoff <<PAGE_SHIFT , memaddr =0 ;void *memvirt =NULL ; +dma_addr_t memdma =0 ;u8 subctxt, mapio =0 , vmf =0 , type;ssize_t memlen =0 ;int ret =0 ;
@@ -375,6 +387,11 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) goto done; } +/* +* vm_pgoff is used as a buffer selector cookie. Always mmap from +* the beginning. +*/ + vma->vm_pgoff =0 ; flags = vma->vm_flags;switch (type) {
@@ -396,7 +413,8 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) vma->vm_page_prot =pgprot_writecombine (vma->vm_page_prot); mapio =1 ;break ; -case PIO_CRED : +case PIO_CRED : { +u64 cr_page_offset;if (flags &VM_WRITE ) { ret = -EPERM ; goto done;
@@ -406,10 +424,11 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)* second or third page allocated for credit returns (if number * of enabled contexts > 64 and 128 respectively). */ - memvirt = dd->cr_base[uctxt->numa_id].va; - memaddr =virt_to_phys (memvirt) + - (((u64 )uctxt->sc->hw_free - - (u64 )dd->cr_base[uctxt->numa_id].va) &PAGE_MASK ); + cr_page_offset = ((u64 )uctxt->sc->hw_free - + (u64 )dd->cr_base[uctxt->numa_id].va) & +PAGE_MASK ; + memvirt = dd->cr_base[uctxt->numa_id].va + cr_page_offset; + memdma = dd->cr_base[uctxt->numa_id].dma + cr_page_offset; memlen =PAGE_SIZE ; flags &= ~VM_MAYWRITE ; flags |=VM_DONTCOPY |VM_DONTEXPAND ;
@@ -419,14 +438,16 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)* memory been flagged as non-cached? */ /* vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); */ - mapio =1 ;break ; + }case RCV_HDRQ : memlen =rcvhdrq_size (uctxt); memvirt = uctxt->rcvhdrq; + memdma = uctxt->rcvhdrq_dma;break ;case RCV_EGRBUF : { -unsigned long addr; +unsigned long vm_start_save; +unsigned long vm_end_save;int i;/* * The RcvEgr buffer need to be handled differently
@@ -445,24 +466,34 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) goto done; } vma->vm_flags &= ~VM_MAYWRITE ; - addr = vma->vm_start; +/* +* Mmap multiple separate allocations into a single vma. From +* here, dma_mmap_coherent() calls dma_direct_mmap(), which +* requires the mmap to exactly fill the vma starting at +* vma_start. Adjust the vma start and end for each eager +* buffer segment mapped. Restore the originals when done. +*/ + vm_start_save = vma->vm_start; + vm_end_save = vma->vm_end; + vma->vm_end = vma->vm_start;for (i =0 ; i < uctxt->egrbufs.numbufs; i++) { memlen = uctxt->egrbufs.buffers[i].len; memvirt = uctxt->egrbufs.buffers[i].addr; - ret =remap_pfn_range ( - vma, addr, -/* -* virt_to_pfn() does the same, but -* it's not available on x86_64 -* when CONFIG_MMU is enabled. -*/ -PFN_DOWN (__pa (memvirt)), - memlen, - vma->vm_page_prot); -if (ret <0 ) + memdma = uctxt->egrbufs.buffers[i].dma; + vma->vm_end += memlen; +mmap_cdbg (ctxt, subctxt, type, mapio, vmf, memaddr, + memvirt, memdma, memlen, vma); + ret =dma_mmap_coherent (&dd->pcidev->dev, vma, + memvirt, memdma, memlen); +if (ret <0 ) { + vma->vm_start = vm_start_save; + vma->vm_end = vm_end_save; goto done; - addr += memlen; + } + vma->vm_start += memlen; } + vma->vm_start = vm_start_save; + vma->vm_end = vm_end_save; ret =0 ; goto done; }
@@ -522,6 +553,7 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) } memlen =PAGE_SIZE ; memvirt = (void *)hfi1_rcvhdrtail_kvaddr (uctxt); + memdma = uctxt->rcvhdrqtailaddr_dma; flags &= ~VM_MAYWRITE ;break ;case SUBCTXT_UREGS :
@@ -570,14 +602,15 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma) } vma->vm_flags = flags; -hfi1_cdbg (PROC , -"%u:%u type:%u io/vf:%d/%d, addr:0x%llx, len:%lu(%lu), flags:0x%lx\n" , - ctxt, subctxt, type, mapio, vmf, memaddr, memlen, - vma->vm_end - vma->vm_start, vma->vm_flags); +mmap_cdbg (ctxt, subctxt, type, mapio, vmf, memaddr, memvirt, memdma, + memlen, vma);if (vmf) { vma->vm_pgoff =PFN_DOWN (memaddr); vma->vm_ops = &vm_ops; ret =0 ; + }else if (memdma) { + ret =dma_mmap_coherent (&dd->pcidev->dev, vma, + memvirt, memdma, memlen); }else if (mapio) { ret = io_remap_pfn_range(vma, vma->vm_start, PFN_DOWN(memaddr),
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 IB/hfi1: Resolve the credit-return buffer through the send context's node
From: Shuhei Takeshita <[email protected]>
[ Upstream commit 975396b9e5a4028e649f4b9a6a5ca5dfb76a824b ]
hfi1_file_mmap()'s PIO_CRED case derives this context's credit-return page offset, and the DMA handle for it, from dd->cr_base[uctxt->numa_id]. uctxt->numa_id is the node of whichever CPU the process happened to be running on, but the entry itself lives in the credit-return allocation of the send context's own node:
sc->hw_free = &sc->dd->cr_base[sc->node].va[gc].cr[index];
and user send contexts are allocated with sc_alloc(dd, SC_USER, ..., dd->node), the HFI-local node. On a multi-socket host with the process running off that node the two allocations differ, so the subtraction produces an offset into an unrelated buffer and the DMA handle belongs to the wrong allocation.
Use the send context's own node for all three references. The continuation lines are reindented at the same time; they mixed spaces and tabs.
--- drivers/infiniband/hw/hfi1/file_ops.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/infiniband/hw/hfi1/file_ops.c +4 -4
@@ -425,10 +425,10 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)* of enabled contexts > 64 and 128 respectively). */ cr_page_offset = ((u64 )uctxt->sc->hw_free - - (u64 )dd->cr_base[uctxt->numa_id].va) & -PAGE_MASK ; - memvirt = dd->cr_base[uctxt->numa_id].va + cr_page_offset; - memdma = dd->cr_base[uctxt->numa_id].dma + cr_page_offset; + (u64 )dd->cr_base[uctxt->sc->node].va) & +PAGE_MASK ; + memvirt = dd->cr_base[uctxt->sc->node].va + cr_page_offset; + memdma = dd->cr_base[uctxt->sc->node].dma + cr_page_offset; memlen =PAGE_SIZE ; flags &= ~VM_MAYWRITE ; flags |=VM_DONTCOPY |VM_DONTEXPAND ;
Signature · 1 line
2.53.0