diff --git a/rust/kernel/drm/gpuvm.rs b/rust/kernel/drm/gpuvm.rs index 47fd4fbc17ebe8..764b48fcae57c0 100644 --- a/rust/kernel/drm/gpuvm.rs +++ b/rust/kernel/drm/gpuvm.rs @@ -7,7 +7,6 @@ #![allow(missing_docs)] use crate::{ - alloc::flags::*, bindings, drm::{device, drv}, error::{ @@ -91,28 +90,24 @@ impl OpMap { self.0.gem.offset } pub fn object(&self) -> &::Object { - // SAFETY: The GEM object is only ever passed as a Driver object below, so - // the type must be correct. - let p = unsafe { - <::Object as IntoGEMObject>::from_gem_obj(self.0.gem.obj) - }; + let p = <::Object as IntoGEMObject>::from_gem_obj(self.0.gem.obj); // SAFETY: The GEM object has an active reference for the lifetime of this op unsafe { &*p } } pub fn map_and_link_va( &mut self, gpuvm: &mut UpdatingGpuVm<'_, T>, - gpuva: Pin>>, + gpuva: Pin>>, gpuvmbo: &ARef>, - ) -> Result<(), Pin>>> { + ) -> Result<(), Pin>>> { // SAFETY: We are handing off the GpuVa ownership and it will not be moved. - let p = Box::leak(unsafe { Pin::into_inner_unchecked(gpuva) }); + let p = KBox::leak(unsafe { Pin::into_inner_unchecked(gpuva) }); // SAFETY: These C functions are called with the correct invariants unsafe { bindings::drm_gpuva_init_from_op(&mut p.gpuva, &mut self.0); if bindings::drm_gpuva_insert(gpuvm.0.gpuvm() as *mut _, &mut p.gpuva) != 0 { // EEXIST, return the GpuVa to the caller as an error - return Err(Pin::new_unchecked(Box::from_raw(p))); + return Err(Pin::new_unchecked(KBox::from_raw(p))); }; // SAFETY: This takes a new reference to the gpuvmbo. bindings::drm_gpuva_link(&mut p.gpuva, &gpuvmbo.bo as *const _ as *mut _); @@ -131,7 +126,7 @@ impl OpUnMap { // SAFETY: The GpuVa object reference is valid per the op_unmap contract Some(unsafe { &*p }) } - pub fn unmap_and_unlink_va(&mut self) -> Option>>> { + pub fn unmap_and_unlink_va(&mut self) -> Option>>> { if self.0.va.is_null() { return None; } @@ -148,7 +143,7 @@ impl OpUnMap { // so clear the pointer self.0.va = core::ptr::null_mut(); // SAFETY: The GpuVa object reference is valid per the op_unmap contract - Some(unsafe { Pin::new_unchecked(Box::from_raw(p)) }) + Some(unsafe { Pin::new_unchecked(KBox::from_raw(p)) }) } } @@ -183,11 +178,11 @@ pub struct GpuVa { unsafe impl init::Zeroable for bindings::drm_gpuva {} impl GpuVa { - pub fn new(inner: impl PinInit) -> Result>>> + pub fn new(inner: impl PinInit) -> Result>>> where Error: From, { - Box::try_pin_init( + KBox::try_pin_init( try_pin_init!(Self { gpuva <- init::zeroed(), inner <- inner, @@ -284,12 +279,12 @@ pub(super) unsafe extern "C" fn vm_free_callback( }; // SAFETY: p is guaranteed to be valid for drm_gpuvm objects using this callback. - unsafe { drop(Box::from_raw(p)) }; + unsafe { drop(KBox::from_raw(p)) }; } pub(super) unsafe extern "C" fn vm_bo_alloc_callback() -> *mut bindings::drm_gpuvm_bo { - let obj: Result>>> = Box::try_pin_init( + let obj: Result>>> = KBox::try_pin_init( try_pin_init!(GpuVmBo:: { bo <- init::default(), inner <- T::GpuVmBo::new(), @@ -302,7 +297,7 @@ pub(super) unsafe extern "C" fn vm_bo_alloc_callback() -> *mut b Ok(obj) => // SAFETY: The DRM core will keep this object pinned unsafe { - let p = Box::leak(Pin::into_inner_unchecked(obj)); + let p = KBox::leak(Pin::into_inner_unchecked(obj)); &mut p.bo }, Err(_) => core::ptr::null_mut(), @@ -316,7 +311,7 @@ pub(super) unsafe extern "C" fn vm_bo_free_callback( let p = unsafe { crate::container_of!(raw_vm_bo, GpuVmBo, bo) as *mut GpuVmBo }; // SAFETY: p is guaranteed to be valid for drm_gpuvm_bo objects using this callback. - unsafe { drop(Box::from_raw(p)) }; + unsafe { drop(KBox::from_raw(p)) }; } pub(super) unsafe extern "C" fn step_map_callback( @@ -402,7 +397,7 @@ impl GpuVm { where Error: From, { - let obj: Pin> = Box::try_pin_init( + let obj: Pin> = KBox::try_pin_init( try_pin_init!(Self { // SAFETY: drm_gpuvm_init cannot fail and always initializes the member gpuvm <- unsafe { @@ -413,7 +408,7 @@ impl GpuVm { Opaque::raw_get(slot), name.as_char_ptr(), 0, - dev.raw_mut(), + dev.as_raw(), r_obj.gem_obj() as *const _ as *mut _, range.start, range.end - range.start, @@ -437,7 +432,7 @@ impl GpuVm { // SAFETY: We never move out of the object let vm_ref = unsafe { - ARef::from_raw(NonNull::new_unchecked(Box::leak( + ARef::from_raw(NonNull::new_unchecked(KBox::leak( Pin::into_inner_unchecked(obj), ))) }; @@ -455,7 +450,7 @@ impl GpuVm { let mut guard = ManuallyDrop::new(LockedGpuVm { gpuvm: self, // vm_exec needs to be pinned, so stick it in a Box. - vm_exec: Box::init( + vm_exec: KBox::init( init!(bindings::drm_gpuvm_exec { vm: self.gpuvm() as *mut _, flags: bindings::BINDINGS_DRM_EXEC_INTERRUPTIBLE_WAIT, @@ -505,7 +500,7 @@ unsafe impl AlwaysRefCounted for GpuVm { pub struct LockedGpuVm<'a, 'b, T: DriverGpuVm> { gpuvm: &'a GpuVm, - vm_exec: Box, + vm_exec: KBox, obj: Option<&'b ::Object>, } @@ -652,8 +647,6 @@ impl DerefMut for UpdatingGpuVm<'_, T> { } } -impl core::ops::Receiver for UpdatingGpuVm<'_, T> {} - // SAFETY: All our trait methods take locks unsafe impl Sync for GpuVm {} // SAFETY: All our trait methods take locks