diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-07-05 15:41:55 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-07-11 09:03:37 +0000 |
| commit | 6ca1eb5a578bb1421ad0f3dbde675eb34647e6d7 (patch) | |
| tree | 935c35d1225bcd55b0d413796168c758734af0f9 /pkg/rpcserver | |
| parent | fc2b083017012b4afbd9324fc6525e34a19aa0b3 (diff) | |
all: transition to instance.Pool
Rely on instance.Pool to perform fuzzing and do bug reproductions.
Extract the reproduction queue logic to separate testable class.
Diffstat (limited to 'pkg/rpcserver')
| -rw-r--r-- | pkg/rpcserver/rpcserver.go | 61 | ||||
| -rw-r--r-- | pkg/rpcserver/runner.go | 21 |
2 files changed, 31 insertions, 51 deletions
diff --git a/pkg/rpcserver/rpcserver.go b/pkg/rpcserver/rpcserver.go index 0ad15c040..a6cae67cd 100644 --- a/pkg/rpcserver/rpcserver.go +++ b/pkg/rpcserver/rpcserver.go @@ -8,7 +8,6 @@ import ( "context" "errors" "fmt" - "maps" "math/rand" "slices" "sort" @@ -28,6 +27,7 @@ import ( "github.com/google/syzkaller/pkg/vminfo" "github.com/google/syzkaller/prog" "github.com/google/syzkaller/sys/targets" + "github.com/google/syzkaller/vm/dispatcher" ) type Config struct { @@ -77,7 +77,6 @@ type Server struct { mu sync.Mutex runners map[string]*Runner - info map[string]VMState execSource queue.Source triagedCorpus atomic.Bool statVMRestarts *stats.Val @@ -144,7 +143,6 @@ func newImpl(ctx context.Context, cfg *Config, mgr Manager) (*Server, error) { sysTarget: sysTarget, timeouts: sysTarget.Timeouts(cfg.Slowdown), runners: make(map[string]*Runner), - info: make(map[string]VMState), checker: checker, baseSource: baseSource, execSource: queue.Retry(baseSource), @@ -183,44 +181,6 @@ func (serv *Server) Close() error { return serv.serv.Close() } -const ( - StateOffline = iota - StateBooting - StateFuzzing - StateStopping -) - -type VMState struct { - State int - Timestamp time.Time -} - -func (serv *Server) VMState() map[string]VMState { - serv.mu.Lock() - defer serv.mu.Unlock() - return maps.Clone(serv.info) -} - -func (serv *Server) MachineInfo(name string) []byte { - serv.mu.Lock() - runner := serv.runners[name] - serv.mu.Unlock() - if runner == nil || !runner.Alive() { - return []byte("VM is not alive") - } - return runner.MachineInfo() -} - -func (serv *Server) RunnerStatus(name string) []byte { - serv.mu.Lock() - runner := serv.runners[name] - serv.mu.Unlock() - if runner == nil || !runner.Alive() { - return []byte("VM is not alive") - } - return runner.QueryStatus() -} - func (serv *Server) handleConn(conn *flatrpc.Conn) { connectReq, err := flatrpc.Recv[*flatrpc.ConnectRequestRaw](conn) if err != nil { @@ -232,7 +192,7 @@ func (serv *Server) handleConn(conn *flatrpc.Conn) { if serv.cfg.VMLess { // There is no VM loop, so minic what it would do. - serv.CreateInstance(name, nil) + serv.CreateInstance(name, nil, nil) defer func() { serv.StopFuzzing(name) serv.ShutdownInstance(name, true) @@ -271,10 +231,6 @@ func (serv *Server) handleConn(conn *flatrpc.Conn) { return } - serv.mu.Lock() - serv.info[name] = VMState{StateFuzzing, time.Now()} - serv.mu.Unlock() - if serv.triagedCorpus.Load() { if err := runner.SendCorpusTriaged(); err != nil { log.Logf(2, "%v", err) @@ -435,7 +391,7 @@ func (serv *Server) printMachineCheck(checkFilesInfo []*flatrpc.FileInfo, enable log.Logf(0, "machine check:\n%s", buf.Bytes()) } -func (serv *Server) CreateInstance(name string, injectExec chan<- bool) { +func (serv *Server) CreateInstance(name string, injectExec chan<- bool, updInfo dispatcher.UpdateInfo) { runner := &Runner{ source: serv.execSource, cover: serv.cfg.Cover, @@ -451,14 +407,14 @@ func (serv *Server) CreateInstance(name string, injectExec chan<- bool) { rnd: rand.New(rand.NewSource(time.Now().UnixNano())), stats: serv.runnerStats, procs: serv.cfg.Procs, + updInfo: updInfo, } serv.mu.Lock() + defer serv.mu.Unlock() if serv.runners[name] != nil { panic(fmt.Sprintf("duplicate instance %s", name)) } serv.runners[name] = runner - serv.info[name] = VMState{StateBooting, time.Now()} - serv.mu.Unlock() } // stopInstance prevents further request exchange requests. @@ -466,8 +422,12 @@ func (serv *Server) CreateInstance(name string, injectExec chan<- bool) { func (serv *Server) StopFuzzing(name string) { serv.mu.Lock() runner := serv.runners[name] - serv.info[name] = VMState{StateStopping, time.Now()} serv.mu.Unlock() + if runner.updInfo != nil { + runner.updInfo(func(info *dispatcher.Info) { + info.Status = "fuzzing is stopped" + }) + } runner.Stop() } @@ -475,7 +435,6 @@ func (serv *Server) ShutdownInstance(name string, crashed bool) ([]ExecRecord, [ serv.mu.Lock() runner := serv.runners[name] delete(serv.runners, name) - serv.info[name] = VMState{StateOffline, time.Now()} serv.mu.Unlock() return runner.Shutdown(crashed), runner.MachineInfo() } diff --git a/pkg/rpcserver/runner.go b/pkg/rpcserver/runner.go index 06fa6a581..c45598b9c 100644 --- a/pkg/rpcserver/runner.go +++ b/pkg/rpcserver/runner.go @@ -20,6 +20,7 @@ import ( "github.com/google/syzkaller/pkg/stats" "github.com/google/syzkaller/prog" "github.com/google/syzkaller/sys/targets" + "github.com/google/syzkaller/vm/dispatcher" ) type Runner struct { @@ -40,6 +41,7 @@ type Runner struct { executing map[int64]bool lastExec *LastExecuting rnd *rand.Rand + updInfo dispatcher.UpdateInfo // The mutex protects all the fields below. mu sync.Mutex @@ -78,6 +80,12 @@ type handshakeResult struct { } func (runner *Runner) Handshake(conn *flatrpc.Conn, cfg *handshakeConfig) error { + if runner.updInfo != nil { + runner.updInfo(func(info *dispatcher.Info) { + info.Status = "handshake" + }) + } + connectReply := &flatrpc.ConnectReply{ Debug: runner.debug, Cover: runner.cover, @@ -115,10 +123,23 @@ func (runner *Runner) Handshake(conn *flatrpc.Conn, cfg *handshakeConfig) error runner.machineInfo = ret.MachineInfo runner.canonicalizer = ret.Canonicalizer runner.mu.Unlock() + + if runner.updInfo != nil { + runner.updInfo(func(info *dispatcher.Info) { + info.MachineInfo = runner.MachineInfo + info.DetailedStatus = runner.QueryStatus + }) + } return nil } func (runner *Runner) ConnectionLoop() error { + if runner.updInfo != nil { + runner.updInfo(func(info *dispatcher.Info) { + info.Status = "executing" + }) + } + runner.mu.Lock() stopped := runner.stopped if !stopped { |
