Update tpuproxy package for a more consistent gVisor naming convention.

PiperOrigin-RevId: 620321751
This commit is contained in:
Jing Chen
2024-03-29 13:13:39 -07:00
committed by gVisor bot
parent 88ee65f3a8
commit 32afe881c5
4 changed files with 40 additions and 40 deletions
+6 -6
View File
@@ -101,23 +101,23 @@ func (dev *vfioDevice) Open(ctx context.Context, mnt *vfs.Mount, d *vfs.Dentry,
dev.mu.Lock()
defer dev.mu.Unlock()
name := fmt.Sprintf("vfio/%s", filepath.Base(VFIOPath))
hostFd, err := client.OpenAt(ctx, name, opts.Flags)
hostFD, err := client.OpenAt(ctx, name, opts.Flags)
if err != nil {
ctx.Warningf("failed to open host file %s: %v", name, err)
return nil, err
}
fd := &vfioFd{
hostFd: int32(hostFd),
fd := &vfioFD{
hostFD: int32(hostFD),
device: dev,
}
if err := fd.vfsfd.Init(fd, opts.Flags, mnt, d, &vfs.FileDescriptionOptions{
UseDentryMetadata: true,
}); err != nil {
unix.Close(hostFd)
unix.Close(hostFD)
return nil, err
}
if err := fdnotifier.AddFD(int32(hostFd), &fd.queue); err != nil {
unix.Close(hostFd)
if err := fdnotifier.AddFD(int32(hostFD), &fd.queue); err != nil {
unix.Close(hostFD)
return nil, err
}
fd.memmapFile.fd = fd
+5 -5
View File
@@ -122,20 +122,20 @@ func (fd *tpuFD) Ioctl(ctx context.Context, uio usermem.IO, sysno uintptr, args
}
func (fd *tpuFD) setContainer(ctx context.Context, t *kernel.Task, arg hostarch.Addr) (uintptr, error) {
var vfioContainerFd int32
if _, err := primitive.CopyInt32In(t, arg, &vfioContainerFd); err != nil {
var vfioContainerFD int32
if _, err := primitive.CopyInt32In(t, arg, &vfioContainerFD); err != nil {
return 0, err
}
vfioContainerFile, _ := t.FDTable().Get(vfioContainerFd)
vfioContainerFile, _ := t.FDTable().Get(vfioContainerFD)
if vfioContainerFile == nil {
return 0, linuxerr.EBADF
}
defer vfioContainerFile.DecRef(ctx)
vfioContainer, ok := vfioContainerFile.Impl().(*vfioFd)
vfioContainer, ok := vfioContainerFile.Impl().(*vfioFD)
if !ok {
return 0, linuxerr.EINVAL
}
return IOCTLInvokePtrArg[uint32](fd.hostFD, linux.VFIO_GROUP_SET_CONTAINER, &vfioContainer.hostFd)
return IOCTLInvokePtrArg[uint32](fd.hostFD, linux.VFIO_GROUP_SET_CONTAINER, &vfioContainer.hostFD)
}
// It will be the caller's responsibility to call the returned cleanup function.
+21 -21
View File
@@ -35,29 +35,29 @@ import (
)
// deviceFD implements vfs.FileDescriptionImpl for /dev/vfio/vfio.
type vfioFd struct {
type vfioFD struct {
vfsfd vfs.FileDescription
vfs.FileDescriptionDefaultImpl
vfs.DentryMetadataFileDescriptionImpl
vfs.NoLockFD
hostFd int32
hostFD int32
device *vfioDevice
queue waiter.Queue
memmapFile vfioFDMemmapFile
}
// Release implements vfs.FileDescriptionImpl.Release.
func (fd *vfioFd) Release(context.Context) {
fdnotifier.RemoveFD(fd.hostFd)
func (fd *vfioFD) Release(context.Context) {
fdnotifier.RemoveFD(fd.hostFD)
fd.queue.Notify(waiter.EventHUp)
unix.Close(int(fd.hostFd))
unix.Close(int(fd.hostFD))
}
// EventRegister implements waiter.Waitable.EventRegister.
func (fd *vfioFd) EventRegister(e *waiter.Entry) error {
func (fd *vfioFD) EventRegister(e *waiter.Entry) error {
fd.queue.EventRegister(e)
if err := fdnotifier.UpdateFD(fd.hostFd); err != nil {
if err := fdnotifier.UpdateFD(fd.hostFD); err != nil {
fd.queue.EventUnregister(e)
return err
}
@@ -65,25 +65,25 @@ func (fd *vfioFd) EventRegister(e *waiter.Entry) error {
}
// EventUnregister implements waiter.Waitable.EventUnregister.
func (fd *vfioFd) EventUnregister(e *waiter.Entry) {
func (fd *vfioFD) EventUnregister(e *waiter.Entry) {
fd.queue.EventUnregister(e)
if err := fdnotifier.UpdateFD(fd.hostFd); err != nil {
if err := fdnotifier.UpdateFD(fd.hostFD); err != nil {
panic(fmt.Sprint("UpdateFD:", err))
}
}
// Readiness implements waiter.Waitable.Readiness.
func (fd *vfioFd) Readiness(mask waiter.EventMask) waiter.EventMask {
return fdnotifier.NonBlockingPoll(fd.hostFd, mask)
func (fd *vfioFD) Readiness(mask waiter.EventMask) waiter.EventMask {
return fdnotifier.NonBlockingPoll(fd.hostFD, mask)
}
// Epollable implements vfs.FileDescriptionImpl.Epollable.
func (fd *vfioFd) Epollable() bool {
func (fd *vfioFD) Epollable() bool {
return true
}
// Ioctl implements vfs.FileDescriptionImpl.Ioctl.
func (fd *vfioFd) Ioctl(ctx context.Context, uio usermem.IO, sysno uintptr, args arch.SyscallArguments) (uintptr, error) {
func (fd *vfioFD) Ioctl(ctx context.Context, uio usermem.IO, sysno uintptr, args arch.SyscallArguments) (uintptr, error) {
cmd := args[1].Uint()
t := kernel.TaskFromContext(ctx)
if t == nil {
@@ -104,10 +104,10 @@ func (fd *vfioFd) Ioctl(ctx context.Context, uio usermem.IO, sysno uintptr, args
// checkExtension returns a positive integer when the given VFIO extension
// is supported, otherwise, it returns 0.
func (fd *vfioFd) checkExtension(ext extension) (uintptr, error) {
func (fd *vfioFD) checkExtension(ext extension) (uintptr, error) {
switch ext {
case linux.VFIO_TYPE1_IOMMU, linux.VFIO_SPAPR_TCE_IOMMU, linux.VFIO_TYPE1v2_IOMMU:
ret, err := IOCTLInvoke[uint32, int32](fd.hostFd, linux.VFIO_CHECK_EXTENSION, int32(ext))
ret, err := IOCTLInvoke[uint32, int32](fd.hostFD, linux.VFIO_CHECK_EXTENSION, int32(ext))
if err != nil {
log.Warningf("check VFIO extension %s: %v", ext, err)
return 0, err
@@ -119,10 +119,10 @@ func (fd *vfioFd) checkExtension(ext extension) (uintptr, error) {
// 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) {
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[uint32, int32](fd.hostFd, linux.VFIO_SET_IOMMU, int32(ext))
ret, err := IOCTLInvoke[uint32, 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
@@ -132,7 +132,7 @@ func (fd *vfioFd) setIOMMU(ext extension) (uintptr, error) {
return 0, linuxerr.EINVAL
}
func (fd *vfioFd) iommuMapDma(ctx context.Context, t *kernel.Task, arg hostarch.Addr) (uintptr, error) {
func (fd *vfioFD) iommuMapDma(ctx context.Context, t *kernel.Task, arg hostarch.Addr) (uintptr, error) {
var dmaMap linux.VFIOIommuType1DmaMap
if _, err := dmaMap.CopyIn(t, arg); err != nil {
return 0, err
@@ -190,7 +190,7 @@ func (fd *vfioFd) iommuMapDma(ctx context.Context, t *kernel.Task, arg hostarch.
}
// Replace Vaddr with the host's virtual address.
dmaMap.Vaddr = uint64(m)
n, err := IOCTLInvokePtrArg[uint32](fd.hostFd, linux.VFIO_IOMMU_MAP_DMA, &dmaMap)
n, err := IOCTLInvokePtrArg[uint32](fd.hostFD, linux.VFIO_IOMMU_MAP_DMA, &dmaMap)
if err != nil {
return n, err
}
@@ -211,7 +211,7 @@ func (fd *vfioFd) iommuMapDma(ctx context.Context, t *kernel.Task, arg hostarch.
return n, nil
}
func (fd *vfioFd) iommuUnmapDma(ctx context.Context, t *kernel.Task, arg hostarch.Addr) (uintptr, error) {
func (fd *vfioFD) iommuUnmapDma(ctx context.Context, t *kernel.Task, arg hostarch.Addr) (uintptr, error) {
var dmaUnmap linux.VFIOIommuType1DmaUnmap
if _, err := dmaUnmap.CopyIn(t, arg); err != nil {
return 0, err
@@ -221,7 +221,7 @@ func (fd *vfioFd) iommuUnmapDma(ctx context.Context, t *kernel.Task, arg hostarc
// gVisor working with TPU.
return 0, linuxerr.ENOSYS
}
n, err := IOCTLInvokePtrArg[uint32](fd.hostFd, linux.VFIO_IOMMU_MAP_DMA, &dmaUnmap)
n, err := IOCTLInvokePtrArg[uint32](fd.hostFD, linux.VFIO_IOMMU_MAP_DMA, &dmaUnmap)
if err != nil {
return 0, nil
}
+8 -8
View File
@@ -25,26 +25,26 @@ import (
)
// ConfigureMMap implements vfs.FileDescriptionImpl.ConfigureMMap.
func (fd *vfioFd) ConfigureMMap(ctx context.Context, opts *memmap.MMapOpts) error {
func (fd *vfioFD) ConfigureMMap(ctx context.Context, opts *memmap.MMapOpts) error {
return vfs.GenericConfigureMMap(&fd.vfsfd, fd, opts)
}
// AddMapping implements memmap.Mappable.AddMapping.
func (fd *vfioFd) AddMapping(ctx context.Context, ms memmap.MappingSpace, ar hostarch.AddrRange, offset uint64, writable bool) error {
func (fd *vfioFD) AddMapping(ctx context.Context, ms memmap.MappingSpace, ar hostarch.AddrRange, offset uint64, writable bool) error {
return nil
}
// RemoveMapping implements memmap.Mappable.RemoveMapping.
func (fd *vfioFd) RemoveMapping(ctx context.Context, ms memmap.MappingSpace, ar hostarch.AddrRange, offset uint64, writable bool) {
func (fd *vfioFD) RemoveMapping(ctx context.Context, ms memmap.MappingSpace, ar hostarch.AddrRange, offset uint64, writable bool) {
}
// CopyMapping implements memmap.Mappable.CopyMapping.
func (fd *vfioFd) CopyMapping(ctx context.Context, ms memmap.MappingSpace, srcAR, dstAR hostarch.AddrRange, offset uint64, writable bool) error {
func (fd *vfioFD) CopyMapping(ctx context.Context, ms memmap.MappingSpace, srcAR, dstAR hostarch.AddrRange, offset uint64, writable bool) error {
return nil
}
// Translate implements memmap.Mappable.Translate.
func (fd *vfioFd) Translate(ctx context.Context, required, optional memmap.MappableRange, at hostarch.AccessType) ([]memmap.Translation, error) {
func (fd *vfioFD) Translate(ctx context.Context, required, optional memmap.MappableRange, at hostarch.AccessType) ([]memmap.Translation, error) {
return []memmap.Translation{
{
Source: optional,
@@ -56,12 +56,12 @@ func (fd *vfioFd) Translate(ctx context.Context, required, optional memmap.Mappa
}
// InvalidateUnsavable implements memmap.Mappable.InvalidateUnsavable.
func (fd *vfioFd) InvalidateUnsavable(ctx context.Context) error {
func (fd *vfioFD) InvalidateUnsavable(ctx context.Context) error {
return nil
}
type vfioFDMemmapFile struct {
fd *vfioFd
fd *vfioFD
}
// IncRef implements memmap.File.IncRef.
@@ -80,5 +80,5 @@ func (mf *vfioFDMemmapFile) MapInternal(fr memmap.FileRange, at hostarch.AccessT
// FD implements memmap.File.FD.
func (mf *vfioFDMemmapFile) FD() int {
return int(mf.fd.hostFd)
return int(mf.fd.hostFD)
}