Skip to content

Commit

Permalink
pkg/fuzzer/queue: refactor DynamicSource
Browse files Browse the repository at this point in the history
Use a simpler implementation.
Don't assume the nested Source may be nil.
  • Loading branch information
a-nogikh authored and dvyukov committed May 16, 2024
1 parent dc6371a commit ad5321c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
23 changes: 11 additions & 12 deletions pkg/fuzzer/queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,24 +343,23 @@ func (pq *PriorityQueue) Next() *Request {
return pq.ops.Pop()
}

type DynamicSource struct {
value atomic.Pointer[wrapSource]
type DynamicSourceCtl struct {
value atomic.Pointer[Source]
}

type wrapSource struct {
source Source
// DynamicSource is assumed never to point to nil.
func DynamicSource(source Source) *DynamicSourceCtl {
var ret DynamicSourceCtl
ret.Store(source)
return &ret
}

func (ds *DynamicSource) Store(source Source) {
ds.value.Store(&wrapSource{source})
func (ds *DynamicSourceCtl) Store(source Source) {
ds.value.Store(&source)
}

func (ds *DynamicSource) Next() *Request {
val := ds.value.Load()
if val == nil || val.source == nil {
return nil
}
return val.source.Next()
func (ds *DynamicSourceCtl) Next() *Request {
return (*ds.value.Load()).Next()
}

// Deduplicator() keeps track of the previously run requests to avoid re-running them.
Expand Down
19 changes: 9 additions & 10 deletions syz-manager/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ type RPCServer struct {
checker *vminfo.Checker
port int

infoDone bool
checkDone atomic.Bool
checkFailures int

checkerSource *queue.DynamicSource
baseSource *queue.DynamicSource
infoDone bool
checkDone atomic.Bool
checkFailures int
baseSource *queue.DynamicSourceCtl
enabledFeatures flatrpc.Feature
setupFeatures flatrpc.Feature
modules []cover.KernelModule
Expand Down Expand Up @@ -100,14 +98,15 @@ type RPCManagerView interface {
}

func startRPCServer(mgr *Manager) (*RPCServer, error) {
var baseSource queue.DynamicSource
checker := vminfo.New(mgr.cfg)
baseSource := queue.DynamicSource(checker)
serv := &RPCServer{
mgr: mgr,
cfg: mgr.cfg,
target: mgr.target,
checker: vminfo.New(mgr.cfg),
baseSource: &baseSource,
execSource: queue.Retry(&baseSource),
checker: checker,
baseSource: baseSource,
execSource: queue.Retry(baseSource),
statExecs: mgr.statExecs,
statExecRetries: stats.Create("exec retries",
"Number of times a test program was restarted because the first run failed",
Expand Down
4 changes: 2 additions & 2 deletions tools/syz-runtest/runtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func main() {
pending: make(map[string]map[int64]bool),
}
mgr.checkFiles = mgr.checker.RequiredFiles()
mgr.source = queue.DynamicSource(mgr.checker)
s, err := rpctype.NewRPCServer(cfg.RPC, "Manager", mgr)
if err != nil {
log.Fatalf("failed to create rpc server: %v", err)
Expand Down Expand Up @@ -96,7 +97,6 @@ func main() {
}()
}
checkResult := <-mgr.checkResultC
mgr.source.Store(mgr.checker)
calls, _, features, err := mgr.checker.Run(checkResult.Files, checkResult.Features)
if err != nil {
log.Fatalf("failed to detect enabled syscalls: %v", err)
Expand Down Expand Up @@ -146,7 +146,7 @@ type Manager struct {
vmStop chan bool
port int
debug bool
source queue.DynamicSource
source *queue.DynamicSourceCtl

reqMu sync.Mutex
reqSeq int64
Expand Down

0 comments on commit ad5321c

Please sign in to comment.