@@ -26,6 +26,14 @@ impl IommuFd {
2626 Ok ( IommuFd { iommufd } )
2727 }
2828
29+ pub fn destroy_iommu_object ( & self , id : u32 ) -> Result < ( ) > {
30+ let destroy_data = iommu_destroy {
31+ size : std:: mem:: size_of :: < iommu_destroy > ( ) as u32 ,
32+ id,
33+ } ;
34+ iommufd_syscall:: destroy_iommu_object ( self , & destroy_data)
35+ }
36+
2937 pub fn alloc_iommu_ioas ( & self , alloc_data : & mut iommu_ioas_alloc ) -> Result < ( ) > {
3038 iommufd_syscall:: alloc_iommu_ioas ( self , alloc_data)
3139 }
@@ -44,6 +52,7 @@ impl AsRawFd for IommuFd {
4452 }
4553}
4654
55+ ioctl_io_nr ! ( IOMMU_DESTROY , IOMMUFD_TYPE as u32 , IOMMUFD_CMD_DESTROY ) ;
4756ioctl_io_nr ! (
4857 IOMMU_IOAS_ALLOC ,
4958 IOMMUFD_TYPE as u32 ,
@@ -64,6 +73,23 @@ pub(crate) mod iommufd_syscall {
6473 use super :: * ;
6574 use vmm_sys_util:: ioctl:: { ioctl_with_mut_ref, ioctl_with_ref} ;
6675
76+ pub ( crate ) fn destroy_iommu_object (
77+ iommufd : & IommuFd ,
78+ destroy_data : & iommu_destroy ,
79+ ) -> Result < ( ) > {
80+ // SAFETY:
81+ // 1. The file descriptor provided by 'iommufd' is valid and open.
82+ // 2. The 'destroy_data' points to initialized memory with expected data structure,
83+ // and remains valid for the duration of sysca
84+ // 3. The return value is checked.
85+ let ret = unsafe { ioctl_with_ref ( iommufd, IOMMU_DESTROY ( ) , destroy_data) } ;
86+ if ret < 0 {
87+ Err ( IommufdError :: IommuDestroy ( SysError :: last ( ) ) )
88+ } else {
89+ Ok ( ( ) )
90+ }
91+ }
92+
6793 pub ( crate ) fn alloc_iommu_ioas (
6894 iommufd : & IommuFd ,
6995 alloc_data : & mut iommu_ioas_alloc ,
@@ -115,6 +141,7 @@ mod tests {
115141
116142 #[ test]
117143 fn test_iommufd_ioctl_code ( ) {
144+ assert_eq ! ( IOMMU_DESTROY ( ) , 15232 ) ;
118145 assert_eq ! ( IOMMU_IOAS_ALLOC ( ) , 15233 ) ;
119146 assert_eq ! ( IOMMU_IOAS_MAP ( ) , 15237 ) ;
120147 assert_eq ! ( IOMMU_IOAS_UNMAP ( ) , 15238 ) ;
0 commit comments