mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Implement ioctl command VFIO_SET_IOMMU.
PiperOrigin-RevId: 616200912
This commit is contained in:
@@ -30,5 +30,6 @@ const (
|
||||
// IOCTLs for VFIO file descriptor from include/uapi/linux/vfio.h.
|
||||
var (
|
||||
VFIO_CHECK_EXTENSION = IO(VFIO_TYPE, VFIO_BASE+1)
|
||||
VFIO_SET_IOMMU = IO(VFIO_TYPE, VFIO_BASE+2)
|
||||
VFIO_GROUP_SET_CONTAINER = IO(VFIO_TYPE, VFIO_BASE+4)
|
||||
)
|
||||
|
||||
@@ -61,6 +61,10 @@ func Filters() seccomp.SyscallRules {
|
||||
seccomp.NonNegativeFD{},
|
||||
seccomp.EqualTo(linux.VFIO_CHECK_EXTENSION),
|
||||
},
|
||||
seccomp.PerArg{
|
||||
seccomp.NonNegativeFD{},
|
||||
seccomp.EqualTo(linux.VFIO_SET_IOMMU),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -88,6 +88,8 @@ func (fd *vfioFd) Ioctl(ctx context.Context, uio usermem.IO, sysno uintptr, args
|
||||
switch cmd {
|
||||
case linux.VFIO_CHECK_EXTENSION:
|
||||
return fd.checkExtension(extension(args[2].Int()))
|
||||
case linux.VFIO_SET_IOMMU:
|
||||
return fd.setIOMMU(extension(args[2].Int()))
|
||||
}
|
||||
return 0, linuxerr.ENOSYS
|
||||
}
|
||||
@@ -107,6 +109,21 @@ func (fd *vfioFd) checkExtension(ext extension) (uintptr, error) {
|
||||
return 0, linuxerr.EINVAL
|
||||
}
|
||||
|
||||
// Set the iommu to the given type. The type must be supported by an iommu
|
||||
// driver as verified by calling VFIO_CHECK_EXTENSION using the same type.
|
||||
func (fd *vfioFd) setIOMMU(ext extension) (uintptr, error) {
|
||||
switch ext {
|
||||
case linux.VFIO_TYPE1_IOMMU, linux.VFIO_SPAPR_TCE_IOMMU, linux.VFIO_TYPE1v2_IOMMU:
|
||||
ret, err := ioctlInvoke[int32](fd.hostFd, linux.VFIO_SET_IOMMU, int32(ext))
|
||||
if err != nil {
|
||||
log.Warningf("set the IOMMU group to %s: %v", ext, err)
|
||||
return 0, err
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
return 0, linuxerr.EINVAL
|
||||
}
|
||||
|
||||
// VFIO extension.
|
||||
type extension int32
|
||||
|
||||
|
||||
Reference in New Issue
Block a user