Re: [PATCH v20 5/8] rust: rename `AlwaysRefCounted` to `RefCounted`.

[email protected]
Newsgroups org.freedesktop.lists.dri-devel,org.kernel.vger.linux-pci
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The `GpuVm` and `GpuVmBo` types in the DRM GPUVM subsystem were not updated to reflect the `AlwaysRefCounted` and `RefCounted` trait split, resulting in a compilation failure.
--

--- Patch [5]: [PATCH v20 5/8] rust: rename `AlwaysRefCounted` to `RefCounted`. ---
commit 7d343e09ba4b06050b444e30c1113ca349f25a78
Author: Oliver Mangold <[email protected]>

rust: rename AlwaysRefCounted to RefCounted.

This commit splits the AlwaysRefCounted trait into RefCounted and a new 
marker trait AlwaysRefCounted. It updates several subsystems to implement 
the new RefCounted trait while preserving the AlwaysRefCounted marker where 
appropriate.

> diff --git a/rust/kernel/sync/aref.rs b/rust/kernel/sync/aref.rs
> index 3bd5eb8a1a526..ea5a16b8163a6 100644
> --- a/rust/kernel/sync/aref.rs
> +++ b/rust/kernel/sync/aref.rs
[ ... ]
> @@ -45,9 +43,8 @@
>  /// at least until matching decrements are performed.
>  ///
>  /// Implementers must also ensure that all instances are reference-counted. (Otherwise they
> -/// won't be able to honour the requirement that [`AlwaysRefCounted::inc_ref`] keep the object
> -/// alive.)
> -pub unsafe trait AlwaysRefCounted {
> +/// won't be able to honour the requirement that [`RefCounted::inc_ref`] keep the object alive.)
> +pub unsafe trait RefCounted {
>      /// Increments the reference count on the object.
>      fn inc_ref(&self);

[Severity: Low]
Did this patch miss updating the DRM GPUVM subsystem? 

When CONFIG_RUST_DRM_GPUVM is enabled, the build fails because GpuVm and 
GpuVmBo are still trying to implement inc_ref() and dec_ref() under the 
AlwaysRefCounted trait instead of RefCounted.

For example, in rust/kernel/drm/gpuvm/mod.rs:

unsafe impl<T: DriverGpuVm> AlwaysRefCounted for GpuVm<T> {
    fn inc_ref(&self) {
        // SAFETY: By type invariants, the allocation is managed by the refcount in self.vm.
        unsafe { bindings::drm_gpuvm_get(self.vm.get()) };
    }
    ...
}

And similarly in rust/kernel/drm/gpuvm/vm_bo.rs for GpuVmBo:

unsafe impl<T: DriverGpuVm> AlwaysRefCounted for GpuVmBo<T> {
    fn inc_ref(&self) {
        // SAFETY: By type invariants, the allocation is managed by the refcount in self.inner.
        unsafe { bindings::drm_gpuvm_bo_get(self.inner.get()) };
    }
    ...
}

Should these implementations be updated to use the new RefCounted trait to 
match the changes made to the other subsystems?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.