Implement VFIO-PCI TPU device's Pread and Pwrite to enable bus master at host.

PiperOrigin-RevId: 618998464
This commit is contained in:
Jing Chen
2024-03-25 16:50:53 -07:00
committed by gVisor bot
parent 5c1687045f
commit f94df6d1bf
2 changed files with 30 additions and 0 deletions
@@ -52,6 +52,8 @@ func Filters() seccomp.SyscallRules {
seccomp.AnyValue{},
seccomp.EqualTo(0),
},
unix.SYS_PREAD64: seccomp.MatchAll{},
unix.SYS_PWRITE64: seccomp.MatchAll{},
unix.SYS_IOCTL: seccomp.Or{
seccomp.PerArg{
seccomp.NonNegativeFD{},
+28
View File
@@ -393,3 +393,31 @@ func (fd *pciDeviceFD) vfioSetIrqs(ctx context.Context, t *kernel.Task, arg host
// No data type is specified or multiple data types are specified.
return 0, linuxerr.EINVAL
}
// PRead implements vfs.FileDescriptionImpl.PRead.
func (fd *pciDeviceFD) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.ReadOptions) (int64, error) {
if offset < 0 {
return 0, linuxerr.EINVAL
}
buf := make([]byte, dst.NumBytes())
_, err := unix.Pread(int(fd.hostFD), buf, offset)
if err != nil {
return 0, err
}
n, err := dst.CopyOut(ctx, buf)
return int64(n), err
}
// PWrite implements vfs.FileDescriptionImpl.PWrite.
func (fd *pciDeviceFD) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error) {
if offset < 0 {
return 0, linuxerr.EINVAL
}
buf := make([]byte, src.NumBytes())
_, err := src.CopyIn(ctx, buf)
if err != nil {
return 0, err
}
n, err := unix.Pwrite(int(fd.hostFD), buf, offset)
return int64(n), err
}