The auxiliary device registration was using a hardcoded ID of 0, which caused probe() to fail on multi-GPU systems with:
sysfs: cannot create duplicate filename '/bus/auxiliary/devices/NovaCore.nova-drm.0' Fix this by using an atomic counter to generate unique IDs for each GPU's aux device registration. The TODO item to eventually use XArray for recycling aux device IDs is retained, but for now, this works very nicely. This has the side effect of making debugfs[1] work on multi-GPU systems. [1] https://lore.kernel.org/[email protected] Reviewed-by: Gary Guo <[email protected]> Signed-off-by: John Hubbard <[email protected]> --- drivers/gpu/nova-core/driver.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs index 4ff07b643db6..52729799725b 100644 --- a/drivers/gpu/nova-core/driver.rs +++ b/drivers/gpu/nova-core/driver.rs @@ -1,5 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 +use core::sync::atomic::{ + AtomicU32, + Ordering, // +}; + use kernel::{ auxiliary, device::Core, @@ -21,6 +26,9 @@ Spec, // }; +/// Counter for generating unique auxiliary device IDs. +static AUXILIARY_ID_COUNTER: AtomicU32 = AtomicU32::new(0); + #[pin_data] pub(crate) struct NovaCore { #[pin] @@ -84,12 +92,17 @@ fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, E // other threads of execution. unsafe { pdev.dma_set_mask_and_coherent(spec.chipset().arch().dma_mask())? }; + // TODO[XARR]: Use XArray for proper ID allocation/recycling. Until then, use a simple + // atomic counter which never recycles IDs. A unique ID is required for multi-GPU + // systems, because without it, probe() would fail for all but the first GPU. + let aux_id = AUXILIARY_ID_COUNTER.fetch_add(1, Ordering::Relaxed); + Ok(try_pin_init!(Self { gpu <- Gpu::new(pdev, devres_bar.clone(), devres_bar.access(pdev.as_ref())?, spec), _reg <- auxiliary::Registration::new( pdev.as_ref(), c"nova-drm", - 0, // TODO[XARR]: Once it lands, use XArray; for now we don't use the ID. + aux_id, crate::MODULE_NAME ), })) -- 2.53.0
