diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-06-28 15:48:43 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-07-01 09:13:47 +0000 |
| commit | 714041c90b9b0efe7fb63d39fa6b0aa643f2450c (patch) | |
| tree | 7f808952cf73868d27cd06ce59ef0a3b5818425d | |
| parent | a7b22031cdbe8555ef6d4a086bd11dbc9feea4fd (diff) | |
vm: refactor vm.Multiplex arguments
Introduce a MultiplexConfig structure that contains optional parameters.
Include a Scale parameter to control the intended slowdown.
| -rw-r--r-- | vm/adb/adb.go | 35 | ||||
| -rwxr-xr-x | vm/isolated/isolated.go | 11 | ||||
| -rw-r--r-- | vm/qemu/qemu.go | 6 | ||||
| -rw-r--r-- | vm/vmimpl/vmimpl.go | 31 | ||||
| -rw-r--r-- | vm/vmware/vmware.go | 25 |
5 files changed, 75 insertions, 33 deletions
diff --git a/vm/adb/adb.go b/vm/adb/adb.go index ed9fa56b7..ad0347342 100644 --- a/vm/adb/adb.go +++ b/vm/adb/adb.go @@ -22,6 +22,7 @@ import ( "github.com/google/syzkaller/pkg/log" "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/pkg/report" + "github.com/google/syzkaller/sys/targets" "github.com/google/syzkaller/vm/vmimpl" ) @@ -57,12 +58,13 @@ type Pool struct { } type instance struct { - cfg *Config - adbBin string - device string - console string - closed chan bool - debug bool + cfg *Config + adbBin string + device string + console string + closed chan bool + debug bool + timeouts targets.Timeouts } var ( @@ -131,12 +133,13 @@ func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) { return nil, err } inst := &instance{ - cfg: pool.cfg, - adbBin: pool.cfg.Adb, - device: device.Serial, - console: device.Console, - closed: make(chan bool), - debug: pool.env.Debug, + cfg: pool.cfg, + adbBin: pool.cfg.Adb, + device: device.Serial, + console: device.Console, + closed: make(chan bool), + debug: pool.env.Debug, + timeouts: pool.env.Timeouts, } closeInst := inst defer func() { @@ -552,7 +555,13 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin merger.Add("console", tty) merger.Add("adb", adbRpipe) - return vmimpl.Multiplex(adb, merger, tty, timeout, stop, inst.closed, inst.debug) + return vmimpl.Multiplex(adb, merger, timeout, vmimpl.MultiplexConfig{ + Console: tty, + Stop: stop, + Close: inst.closed, + Debug: inst.debug, + Scale: inst.timeouts.Scale, + }) } func (inst *instance) Diagnose(rep *report.Report) ([]byte, bool) { diff --git a/vm/isolated/isolated.go b/vm/isolated/isolated.go index 51a995b72..1201a6ac8 100755 --- a/vm/isolated/isolated.go +++ b/vm/isolated/isolated.go @@ -17,6 +17,7 @@ import ( "github.com/google/syzkaller/pkg/log" "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/pkg/report" + "github.com/google/syzkaller/sys/targets" "github.com/google/syzkaller/vm/vmimpl" ) @@ -53,6 +54,7 @@ type instance struct { sshUser string sshKey string forwardPort int + timeouts targets.Timeouts } func ctor(env *vmimpl.Env) (vmimpl.Pool, error) { @@ -109,6 +111,7 @@ func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) { debug: pool.env.Debug, sshUser: pool.env.SSHUser, sshKey: pool.env.SSHKey, + timeouts: pool.env.Timeouts, } closeInst := inst defer func() { @@ -357,7 +360,13 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin merger.Add("dmesg", dmesg) merger.Add("ssh", rpipe) - return vmimpl.Multiplex(cmd, merger, dmesg, timeout, stop, inst.closed, inst.debug) + return vmimpl.Multiplex(cmd, merger, timeout, vmimpl.MultiplexConfig{ + Console: dmesg, + Stop: stop, + Close: inst.closed, + Debug: inst.debug, + Scale: inst.timeouts.Scale, + }) } func (inst *instance) readPstoreContents() ([]byte, error) { diff --git a/vm/qemu/qemu.go b/vm/qemu/qemu.go index 3a5e9f8a6..e12d8d7c6 100644 --- a/vm/qemu/qemu.go +++ b/vm/qemu/qemu.go @@ -672,7 +672,11 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin return nil, nil, err } wpipe.Close() - return vmimpl.Multiplex(cmd, inst.merger, nil, timeout, stop, nil, inst.debug) + return vmimpl.Multiplex(cmd, inst.merger, timeout, vmimpl.MultiplexConfig{ + Stop: stop, + Debug: inst.debug, + Scale: inst.timeouts.Scale, + }) } func (inst *instance) Info() ([]byte, error) { diff --git a/vm/vmimpl/vmimpl.go b/vm/vmimpl/vmimpl.go index 00a815314..a38ca0d8b 100644 --- a/vm/vmimpl/vmimpl.go +++ b/vm/vmimpl/vmimpl.go @@ -148,8 +148,19 @@ var ( var WaitForOutputTimeout = 10 * time.Second -func Multiplex(cmd *exec.Cmd, merger *OutputMerger, console io.Closer, timeout time.Duration, - stop, closed <-chan bool, debug bool) (<-chan []byte, <-chan error, error) { +type MultiplexConfig struct { + Console io.Closer + Stop <-chan bool + Close <-chan bool + Debug bool + Scale time.Duration +} + +func Multiplex(cmd *exec.Cmd, merger *OutputMerger, timeout time.Duration, config MultiplexConfig) ( + <-chan []byte, <-chan error, error) { + if config.Scale <= 0 { + panic("slowdown must be set") + } errc := make(chan error, 1) signal := func(err error) { select { @@ -161,10 +172,10 @@ func Multiplex(cmd *exec.Cmd, merger *OutputMerger, console io.Closer, timeout t select { case <-time.After(timeout): signal(ErrTimeout) - case <-stop: + case <-config.Stop: signal(ErrTimeout) - case <-closed: - if debug { + case <-config.Close: + if config.Debug { log.Logf(0, "instance closed") } signal(fmt.Errorf("instance closed")) @@ -172,10 +183,10 @@ func Multiplex(cmd *exec.Cmd, merger *OutputMerger, console io.Closer, timeout t cmd.Process.Kill() // Once the command has exited, we might want to let the full console // output accumulate before we abort the console connection too. - time.Sleep(WaitForOutputTimeout) - if console != nil { + time.Sleep(WaitForOutputTimeout * config.Scale) + if config.Console != nil { // Only wait for the merger if we're able to control the console stream. - console.Close() + config.Console.Close() merger.Wait() } if cmdErr := cmd.Wait(); cmdErr == nil { @@ -187,8 +198,8 @@ func Multiplex(cmd *exec.Cmd, merger *OutputMerger, console io.Closer, timeout t return } cmd.Process.Kill() - if console != nil { - console.Close() + if config.Console != nil { + config.Console.Close() merger.Wait() } cmd.Wait() diff --git a/vm/vmware/vmware.go b/vm/vmware/vmware.go index 4c05bac12..f2b3431c0 100644 --- a/vm/vmware/vmware.go +++ b/vm/vmware/vmware.go @@ -18,6 +18,7 @@ import ( "github.com/google/syzkaller/pkg/log" "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/pkg/report" + "github.com/google/syzkaller/sys/targets" "github.com/google/syzkaller/vm/vmimpl" ) @@ -45,6 +46,7 @@ type instance struct { sshuser string sshkey string forwardPort int + timeouts targets.Timeouts } func ctor(env *vmimpl.Env) (vmimpl.Pool, error) { @@ -82,13 +84,14 @@ func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) { sshkey := pool.env.SSHKey sshuser := pool.env.SSHUser inst := &instance{ - cfg: pool.cfg, - debug: pool.env.Debug, - baseVMX: pool.cfg.BaseVMX, - vmx: vmx, - sshkey: sshkey, - sshuser: sshuser, - closed: make(chan bool), + cfg: pool.cfg, + debug: pool.env.Debug, + baseVMX: pool.cfg.BaseVMX, + vmx: vmx, + sshkey: sshkey, + sshuser: sshuser, + closed: make(chan bool), + timeouts: pool.env.Timeouts, } if err := inst.clone(); err != nil { return nil, err @@ -215,7 +218,13 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin merger.Add("dmesg", dmesg) merger.Add("ssh", rpipe) - return vmimpl.Multiplex(cmd, merger, dmesg, timeout, stop, inst.closed, inst.debug) + return vmimpl.Multiplex(cmd, merger, timeout, vmimpl.MultiplexConfig{ + Console: dmesg, + Stop: stop, + Close: inst.closed, + Debug: inst.debug, + Scale: inst.timeouts.Scale, + }) } func (inst *instance) Diagnose(rep *report.Report) ([]byte, bool) { |
