Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/abi/linux/vfio.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ 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)
VFIO_GROUP_UNSET_CONTAINER = IO(VFIO_TYPE, VFIO_BASE+5)
VFIO_GROUP_GET_DEVICE_FD = IO(VFIO_TYPE, VFIO_BASE+6)
VFIO_DEVICE_GET_INFO = IO(VFIO_TYPE, VFIO_BASE+7)
VFIO_DEVICE_GET_REGION_INFO = IO(VFIO_TYPE, VFIO_BASE+8)
Expand Down
4 changes: 4 additions & 0 deletions pkg/sentry/devices/tpuproxy/seccomp_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func Filters() seccomp.SyscallRules {
seccomp.NonNegativeFD{},
seccomp.EqualTo(linux.VFIO_GROUP_SET_CONTAINER),
},
seccomp.PerArg{
seccomp.NonNegativeFD{},
seccomp.EqualTo(linux.VFIO_GROUP_UNSET_CONTAINER),
},
seccomp.PerArg{
seccomp.NonNegativeFD{},
seccomp.EqualTo(linux.VFIO_IOMMU_MAP_DMA),
Expand Down
5 changes: 4 additions & 1 deletion pkg/sentry/devices/tpuproxy/vfio/pci_device_fd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"gvisor.dev/gvisor/pkg/errors/linuxerr"
"gvisor.dev/gvisor/pkg/fdnotifier"
"gvisor.dev/gvisor/pkg/hostarch"
"gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/marshal/primitive"
"gvisor.dev/gvisor/pkg/sentry/arch"
"gvisor.dev/gvisor/pkg/sentry/devices/tpuproxy/util"
Expand Down Expand Up @@ -67,7 +68,9 @@ func (fd *pciDeviceFD) Release(context.Context) {
}
fdnotifier.RemoveFD(fd.hostFD)
fd.queue.Notify(waiter.EventHUp)
unix.Close(int(fd.hostFD))
if err := unix.Close(int(fd.hostFD)); err != nil {
log.Warningf("close(%d) pciDeviceFD failed: %v", fd.hostFD, err)
}
}

// EventRegister implements waiter.Waitable.EventRegister.
Expand Down
8 changes: 7 additions & 1 deletion pkg/sentry/devices/tpuproxy/vfio/tpu_fd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"gvisor.dev/gvisor/pkg/errors/linuxerr"
"gvisor.dev/gvisor/pkg/fdnotifier"
"gvisor.dev/gvisor/pkg/hostarch"
"gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/marshal/primitive"
"gvisor.dev/gvisor/pkg/sentry/arch"
"gvisor.dev/gvisor/pkg/sentry/devices/tpuproxy/util"
Expand Down Expand Up @@ -80,7 +81,9 @@ func (fd *tpuFD) Release(context.Context) {
}
fdnotifier.RemoveFD(fd.hostFD)
fd.queue.Notify(waiter.EventHUp)
unix.Close(int(fd.hostFD))
if err := unix.Close(int(fd.hostFD)); err != nil {
log.Warningf("close(%d) tpuFD failed: %v", fd.hostFD, err)
}
}

// EventRegister implements waiter.Waitable.EventRegister.
Expand Down Expand Up @@ -134,6 +137,8 @@ func (fd *tpuFD) Ioctl(ctx context.Context, uio usermem.IO, sysno uintptr, args
switch cmd {
case linux.VFIO_GROUP_SET_CONTAINER:
return fd.setContainer(ctx, t, args[2].Pointer())
case linux.VFIO_GROUP_UNSET_CONTAINER:
return util.IOCTLInvoke[uint32, uintptr](fd.hostFD, linux.VFIO_GROUP_UNSET_CONTAINER, 0)
case linux.VFIO_GROUP_GET_DEVICE_FD:
ret, cleanup, err := fd.getPciDeviceFd(t, args[2].Pointer())
defer cleanup()
Expand Down Expand Up @@ -194,6 +199,7 @@ func (fd *tpuFD) getPciDeviceFd(t *kernel.Task, arg hostarch.Addr) (uintptr, fun
if err := fdnotifier.AddFD(int32(hostFD), &fd.queue); err != nil {
return 0, cleanup, err
}
defer pciDevFD.vfsfd.DecRef(t)
newFD, err := t.NewFDFrom(0, &pciDevFD.vfsfd, kernel.FDFlags{})
if err != nil {
return 0, cleanup, err
Expand Down
4 changes: 3 additions & 1 deletion pkg/sentry/devices/tpuproxy/vfio/vfio_fd.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ func (fd *vfioFD) Release(context.Context) {
fd.unpinRange(DevAddrRange{0, ^uint64(0)})
fdnotifier.RemoveFD(fd.hostFD)
fd.queue.Notify(waiter.EventHUp)
unix.Close(int(fd.hostFD))
if err := unix.Close(int(fd.hostFD)); err != nil {
log.Warningf("close(%d) vfioFD failed: %v", fd.hostFD, err)
}
}

// EventRegister implements waiter.Waitable.EventRegister.
Expand Down
Loading