Skip to content

Commit

Permalink
Add various debug prints
Browse files Browse the repository at this point in the history
  • Loading branch information
derpsteb committed Jan 18, 2024
1 parent 61a2738 commit 1bc75a2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pkg/abi/nvgpu/classes.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ type NV_CHANNEL_ALLOC_PARAMS struct {
ECCErrorNotifierMem NV_MEMORY_DESC_PARAMS
ProcessID uint32
SubProcessID uint32
// IV used for CPU-side encryption / GPU-side decryption.
EncryptIv [3]uint32
// IV used for CPU-side decryption / GPU-side encryption.
DecryptIv [3]uint32
// Nonce used CPU-side signing / GPU-side signature verification.
HmacNonce [8]uint32
}

// NVB0B5_ALLOCATION_PARAMETERS is the alloc param type for TURING_DMA_COPY_A,
Expand Down
36 changes: 34 additions & 2 deletions pkg/sentry/devices/nvproxy/uvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package nvproxy

import (
"fmt"
"os"

"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/abi/nvgpu"
Expand Down Expand Up @@ -163,18 +164,35 @@ func uvmIoctlNoParams(ui *uvmIoctlState) (uintptr, error) {
return uvmIoctlInvoke[byte](ui, nil)
}

func uvmIoctlSimple[Params any, PParams marshalPtr[Params]](ui *uvmIoctlState) (uintptr, error) {
func uvmIoctlSimple[Params any, PParams marshalPtr[Params]](ui *uvmIoctlState) (foo uintptr, retErr error) {
var ioctlParams Params
if _, err := (PParams)(&ioctlParams).CopyIn(ui.t, ui.ioctlParamsAddr); err != nil {
return 0, err
}

n, err := uvmIoctlInvoke(ui, &ioctlParams)
if err != nil {
return n, err
}
if _, err := (PParams)(&ioctlParams).CopyOut(ui.t, ui.ioctlParamsAddr); err != nil {
return n, err
}

castedOut, ok := any(ioctlParams).(nvgpu.UVM_VALIDATE_VA_RANGE_PARAMS)
if ok {
ui.ctx.Debugf("UVM_VALIDATE_VA Out: 0x%x, 0x%x, 0x%x", castedOut.Base, castedOut.Length, castedOut.RMStatus)

if castedOut.Length == 0x3ab000 {
ui.ctx.Debugf("sleeping for 1hr")
var foo string
fmt.Scanf("reading text %s\n", &foo)
}
// data, err := os.ReadFile("/proc/self/maps")
// if err == nil {
// ui.ctx.Debugf("%s", data)
// }
// ui.ctx.Debugf("ReadFile: %s", err)
}
return n, nil
}

Expand Down Expand Up @@ -245,7 +263,12 @@ type hasRMCtrlFDPtr[T any] interface {
nvgpu.HasRMCtrlFD
}

func uvmIoctlHasRMCtrlFD[Params any, PParams hasRMCtrlFDPtr[Params]](ui *uvmIoctlState) (uintptr, error) {
func uvmIoctlHasRMCtrlFD[Params any, PParams hasRMCtrlFDPtr[Params]](ui *uvmIoctlState) (tmp uintptr, retErr error) {
fmt.Fprintf(os.Stderr, "uvmIoctlHasRMCtrlFD\n")
defer func(){
fmt.Fprintf(os.Stderr, "uvmIoctlHasRMCtrlFD retErr: %s\n", retErr)
}()

var ioctlParams Params
if _, err := (PParams)(&ioctlParams).CopyIn(ui.t, ui.ioctlParamsAddr); err != nil {
return 0, err
Expand All @@ -260,6 +283,11 @@ func uvmIoctlHasRMCtrlFD[Params any, PParams hasRMCtrlFDPtr[Params]](ui *uvmIoct
if _, err := (PParams)(&ioctlParams).CopyOut(ui.t, ui.ioctlParamsAddr); err != nil {
return n, err
}

// tmpSlice := make([]byte, 64)
// _ = (PParams)(&ioctlParams).MarshalBytes(tmpSlice)
// fmt.Fprintf(os.Stderr, "HELLOFROMVUM: 0x%x, 0x%x\n", tmpSlice[0:16], tmpSlice[36:40])

return n, nil
}

Expand All @@ -286,5 +314,9 @@ func uvmIoctlHasRMCtrlFD[Params any, PParams hasRMCtrlFDPtr[Params]](ui *uvmIoct
return n, err
}

// tmpSlice := make([]byte, 64)
// _ = (PParams)(&outIoctlParams).MarshalBytes(tmpSlice)
// fmt.Fprintf(os.Stderr, "HELLOFROMVUM: 0x%x, 0x%x\n", tmpSlice[0:16], tmpSlice[36:40])

return n, nil
}
4 changes: 4 additions & 0 deletions pkg/sentry/kernel/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,10 @@ type Task struct {
sessionKeyring *auth.Key
}

func (t *Task) LogPrefix() string {
return (t.logPrefix.Load()).(string)
}

// Task related metrics
var (
// syscallCounter is a metric that tracks how many syscalls the sentry has
Expand Down
6 changes: 5 additions & 1 deletion pkg/sentry/platform/ptrace/subprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ func (t *thread) syscall(regs *arch.Registers) (uintptr, error) {
func (t *thread) syscallIgnoreInterrupt(
initRegs *arch.Registers,
sysno uintptr,
args ...arch.SyscallArgument) (uintptr, error) {
args ...arch.SyscallArgument,
) (uintptr, error) {
for {
regs := createSyscallRegs(initRegs, sysno, args...)
rval, err := t.syscall(&regs)
Expand Down Expand Up @@ -639,6 +640,9 @@ func (s *subprocess) MapFile(addr hostarch.Addr, f memmap.File, fr memmap.FileRa
if precommit {
flags |= unix.MAP_POPULATE
}

fmt.Printf("subprocess.MapFile: addr %x, prot %x, flags %x\n", addr, at.Prot(), flags)

_, err := s.syscall(
unix.SYS_MMAP,
arch.SyscallArgument{Value: uintptr(addr)},
Expand Down
3 changes: 3 additions & 0 deletions pkg/sentry/syscalls/linux/sys_mmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package linux

import (
"bytes"
"fmt"

"gvisor.dev/gvisor/pkg/abi/linux"
"gvisor.dev/gvisor/pkg/errors/linuxerr"
Expand Down Expand Up @@ -47,6 +48,8 @@ func Mmap(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *
anon := flags&linux.MAP_ANONYMOUS != 0
map32bit := flags&linux.MAP_32BIT != 0

fmt.Printf("mmap entry: addr 0x%x, prot 0x%x, flags 0x%x\n", args[0].Pointer(), prot, flags)

// Require exactly one of MAP_PRIVATE and MAP_SHARED.
if private == shared {
return 0, nil, linuxerr.EINVAL
Expand Down

0 comments on commit 1bc75a2

Please sign in to comment.