github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/sentry/devices/accel/accel.go (about) 1 // Copyright 2023 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package accel implements proxying for hardware accelerators. 16 package accel 17 18 import ( 19 "github.com/nicocha30/gvisor-ligolo/pkg/context" 20 "github.com/nicocha30/gvisor-ligolo/pkg/errors/linuxerr" 21 "github.com/nicocha30/gvisor-ligolo/pkg/sentry/arch" 22 "github.com/nicocha30/gvisor-ligolo/pkg/sentry/vfs" 23 "github.com/nicocha30/gvisor-ligolo/pkg/usermem" 24 "github.com/nicocha30/gvisor-ligolo/pkg/waiter" 25 ) 26 27 // accelFD implements vfs.FileDescriptionImpl for /dev/accel[0-9]+. 28 // 29 // accelFD is not savable; we do not implement save/restore of accelerator 30 // state. 31 type accelFD struct { 32 vfsfd vfs.FileDescription 33 vfs.FileDescriptionDefaultImpl 34 vfs.DentryMetadataFileDescriptionImpl 35 vfs.NoLockFD 36 37 hostFD int32 38 } 39 40 // Release implements vfs.FileDescriptionImpl.Release. 41 func (fd *accelFD) Release(context.Context) { 42 } 43 44 // EventRegister implements waiter.Waitable.EventRegister. 45 func (fd *accelFD) EventRegister(e *waiter.Entry) error { 46 return nil 47 } 48 49 // EventUnregister implements waiter.Waitable.EventUnregister. 50 func (fd *accelFD) EventUnregister(e *waiter.Entry) { 51 } 52 53 // Readiness implements waiter.Waitable.Readiness. 54 func (fd *accelFD) Readiness(mask waiter.EventMask) waiter.EventMask { 55 return waiter.EventErr 56 } 57 58 // Epollable implements vfs.FileDescriptionImpl.Epollable. 59 func (fd *accelFD) Epollable() bool { 60 return true 61 } 62 63 // Ioctl implements vfs.FileDescriptionImpl.Ioctl. 64 func (fd *accelFD) Ioctl(ctx context.Context, uio usermem.IO, sysno uintptr, args arch.SyscallArguments) (uintptr, error) { 65 return 0, linuxerr.ENOSYS 66 }