kernel-open: widen the GPU's DMA mask while the probe's 32-bit lease holds

nv_rs_rmapi_gpu_negotiate_dma asked nv_rs_pci_negotiate_dma for a new mask, which refuses any change while a DMA
lease exists, and every GPU keeps its probe's 32-bit lease for its lifetime: the mask stayed at 32 bits. With the
strict IOMMU DMA path (#16) each client system-memory page is mapped with dma_map_page, so on a host with memory
above 4 GiB every such page goes through swiotlb. The GPU's semaphore writes land in the bounce buffer, the CPU
never sees them and libcuda spins at context creation (seen on a V100 with plain master on an 8 GB host: 26,624
swiotlb slabs in use during the hang).

nv_rs_pci_widen_dma raises the mask under the same lock and never lowers it, so every address handed out under the
old mask stays valid. nv_rs_rmapi_gpu_negotiate_dma uses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kamil Skowron
2026-12-01 09:57:19 +01:00
parent b455e03f6f
commit 74ce0e545d
3 changed files with 25 additions and 3 deletions

View File

@ -267,6 +267,23 @@ int nv_rs_pci_dma_acquire(struct nv_rs_pci *p, unsigned int bits)
mutex_unlock(&p->access);
return error;
}
/* Raises the device's DMA mask while DMA leases exist: every address already handed out stays valid under a wider
* mask, so this is safe where nv_rs_pci_negotiate_dma (any change, no leases) is not. A GPU's probe keeps a 32-bit
* lease for its lifetime; a GPU run by GSP-RM (GA10x) widens it before its first system-memory DMA, or every page
* above 4 GiB would be bounced through swiotlb and the GPU's writes would never reach the page the CPU reads. */
int nv_rs_pci_widen_dma(struct nv_rs_pci *p, unsigned int bits)
{
int error = 0;
if (!p || bits < 32 || bits > 64) return -EINVAL;
mutex_lock(&p->access);
if (nv_rs_pci_is_removed(p)) error = -ENODEV;
else if (p->dma_bits < bits) {
error = dma_set_mask_and_coherent(&p->pdev->dev, DMA_BIT_MASK(bits));
if (!error) p->dma_bits = bits;
}
mutex_unlock(&p->access);
return error;
}
void nv_rs_pci_dma_release(struct nv_rs_pci *p)
{
if (!p) return;

View File

@ -23,6 +23,7 @@ int nv_rs_pci_power_get(struct nv_rs_pci *pci);
void nv_rs_pci_power_put(struct nv_rs_pci *pci);
int nv_rs_pci_negotiate_dma(struct nv_rs_pci *pci, unsigned int bits);
int nv_rs_pci_dma_acquire(struct nv_rs_pci *pci, unsigned int bits);
int nv_rs_pci_widen_dma(struct nv_rs_pci *pci, unsigned int bits);
void nv_rs_pci_dma_release(struct nv_rs_pci *pci);
int nv_rs_pci_bus_master(struct nv_rs_pci *pci, bool enable);
/* Process-context metadata lookup only; acquires/releases the target PCI ref.

View File

@ -520,8 +520,12 @@ static bool nv_rs_rmapi_gpu_device_live(u32 gpu_id, struct device *dev)
return live;
}
/* Negotiate the device DMA mask through the PCI adapter's access lock so active
* DMA leases and `dma_bits` bookkeeping stay consistent across callers. */
/* Raise the device DMA mask through the PCI adapter's access lock so active
* DMA leases and `dma_bits` bookkeeping stay consistent across callers. Widening
* only: the GPU's probe holds a 32-bit lease for its lifetime, so a plain
* renegotiation fails, and every page above 4 GiB that the DMA API then maps for
* the GPU is bounced through swiotlb (the GPU's writes never reach the page the
* CPU reads: libcuda waits forever at context creation). */
void nv_rs_rmapi_gpu_negotiate_dma(u32 gpu_id, unsigned int bits)
{
unsigned long flags;
@ -539,7 +543,7 @@ void nv_rs_rmapi_gpu_negotiate_dma(u32 gpu_id, unsigned int bits)
}
spin_unlock_irqrestore(&nv_rs_rmapi_gpu_dev_lock, flags);
if (pci) {
(void)nv_rs_pci_negotiate_dma(pci, bits);
(void)nv_rs_pci_widen_dma(pci, bits);
nv_rs_pci_put(pci);
}
}