Skip to content

Commit 523c82f

Browse files
manninglucasgvisor-bot
authored andcommitted
Fix restore logic in PRead.
This regression was introduced in commit 8482715. The `isRestored()` block in PRead should have been `!isRestored()` PiperOrigin-RevId: 740973182
1 parent 5a21467 commit 523c82f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

pkg/sentry/devices/tpuproxy/vfio/pci_device_fd.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -288,25 +288,26 @@ func (fd *pciDeviceFD) PRead(ctx context.Context, dst usermem.IOSequence, offset
288288
if offset < 0 {
289289
return 0, linuxerr.EINVAL
290290
}
291-
buf := make([]byte, dst.NumBytes())
292291
if fd.isRestored() {
293-
_, err := unix.Pread(int(fd.hostFD), buf, offset)
294-
if err != nil {
295-
return 0, err
296-
}
292+
return int64(dst.NumBytes()), nil
293+
}
294+
buf := make([]byte, dst.NumBytes())
295+
_, err := unix.Pread(int(fd.hostFD), buf, offset)
296+
if err != nil {
297+
return 0, err
297298
}
298299
n, err := dst.CopyOut(ctx, buf)
299300
return int64(n), err
300301
}
301302

302303
// PWrite implements vfs.FileDescriptionImpl.PWrite.
303304
func (fd *pciDeviceFD) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error) {
304-
if fd.isRestored() {
305-
return src.NumBytes(), nil
306-
}
307305
if offset < 0 {
308306
return 0, linuxerr.EINVAL
309307
}
308+
if fd.isRestored() {
309+
return src.NumBytes(), nil
310+
}
310311
buf := make([]byte, src.NumBytes())
311312
_, err := src.CopyIn(ctx, buf)
312313
if err != nil {

0 commit comments

Comments
 (0)