git: a12a9c6c5976 - main - LinuxKPI: be more verbose on _bus_dmamap_load_phys failures if debug is on

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Tue, 01 Apr 2025 14:39:12 UTC
The branch main has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=a12a9c6c59764b876f06355f9f857e0018188d91

commit a12a9c6c59764b876f06355f9f857e0018188d91
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2025-03-29 14:31:18 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2025-04-01 14:37:28 +0000

    LinuxKPI: be more verbose on _bus_dmamap_load_phys failures if debug is on
    
    With the [k]malloc adjustments in switching skbuff from using a tunable
    and conditional contigmalloc with boundries to using __kmalloc as allocator
    should just work.  The allocations are now physically contiguous and
    nseg=1 should be fine even if we have to bounce.
    
    The problem now coming back is that busdma bounce code cannot deal with
    larger contiguous nseg=1 allocations.  I originally found that on arm64
    more than two years ago but I am also seeing it for amd64 now.
    
    Improve the debugging beyond the dump_stack() call and print the busdma
    error (so we know if it is EFBIG or else), print the physical address
    so we can see better if we should bounce and print the length so we
    have an idea on what lengths we are failing.  D45813 has some
    observations and rtw88 seems to be a good driver to test with.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
    Reviewed by:    dumbbell
    Differential Revision: https://reviews.freebsd.org/D49569
---
 sys/compat/linuxkpi/common/src/linux_pci.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c
index a9942a657dce..fa5e3c71fad0 100644
--- a/sys/compat/linuxkpi/common/src/linux_pci.c
+++ b/sys/compat/linuxkpi/common/src/linux_pci.c
@@ -1471,14 +1471,19 @@ linux_dma_map_phys_common(struct device *dev, vm_paddr_t phys, size_t len,
 	}
 
 	nseg = -1;
-	if (_bus_dmamap_load_phys(obj->dmat, obj->dmamap, phys, len,
-	    BUS_DMA_NOWAIT, &seg, &nseg) != 0) {
+	error = _bus_dmamap_load_phys(obj->dmat, obj->dmamap, phys, len,
+	    BUS_DMA_NOWAIT, &seg, &nseg);
+	if (error != 0) {
 		bus_dmamap_destroy(obj->dmat, obj->dmamap);
 		DMA_PRIV_UNLOCK(priv);
 		uma_zfree(linux_dma_obj_zone, obj);
 		counter_u64_add(lkpi_pci_nseg1_fail, 1);
-		if (linuxkpi_debug)
+		if (linuxkpi_debug) {
+			device_printf(dev->bsddev, "%s: _bus_dmamap_load_phys "
+			    "error %d, phys %#018jx len %zu\n", __func__,
+			    error, (uintmax_t)phys, len);
 			dump_stack();
+		}
 		return (0);
 	}