Skip to content

Commit ad00083

Browse files
committed
all: make proc restart frequency configurable
Instead of always using the default value of 600, make it possible to set it via the manager config. For now in the experimental list of features.
1 parent e12e5ba commit ad00083

File tree

7 files changed

+91
-37
lines changed

7 files changed

+91
-37
lines changed

executor/executor_runner.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class ProcOpts
9090
uint32 slowdown = 0;
9191
uint32 syscall_timeout_ms = 0;
9292
uint32 program_timeout_ms = 0;
93+
uint32 proc_restart_freq = 0;
9394

9495
private:
9596
friend std::ostream& operator<<(std::ostream& ss, const ProcOpts& opts)
@@ -98,7 +99,8 @@ class ProcOpts
9899
<< " is_kernel_64_bit=" << opts.is_kernel_64_bit
99100
<< " slowdown=" << opts.slowdown
100101
<< " syscall_timeout_ms=" << opts.syscall_timeout_ms
101-
<< " program_timeout_ms=" << opts.program_timeout_ms;
102+
<< " program_timeout_ms=" << opts.program_timeout_ms
103+
<< " proc_restart_freq=" << opts.proc_restart_freq;
102104
return ss;
103105
}
104106
};
@@ -140,8 +142,7 @@ class Proc
140142
wait_end_ = current_time_ms();
141143
// Restart every once in a while to not let too much state accumulate.
142144
// Also request if request type differs as it affects program timeout.
143-
constexpr uint64 kRestartEvery = 600;
144-
if (state_ == State::Idle && ((corpus_triaged_ && restarting_ == 0 && freshness_ >= kRestartEvery) ||
145+
if (state_ == State::Idle && ((corpus_triaged_ && restarting_ == 0 && freshness_ >= opts_.proc_restart_freq) ||
145146
req_type_ != msg.type ||
146147
exec_env_ != msg.exec_opts->env_flags() || sandbox_arg_ != msg.exec_opts->sandbox_arg()))
147148
Restart();
@@ -662,17 +663,20 @@ class Runner
662663
if (conn_reply.debug)
663664
flag_debug = true;
664665
debug("connected to manager: procs=%d cover_edges=%d kernel_64_bit=%d slowdown=%d syscall_timeout=%u"
665-
" program_timeout=%u features=0x%llx\n",
666+
" program_timeout=%u proc_restart_freq=%d features=0x%llx\n",
666667
conn_reply.procs, conn_reply.cover_edges, conn_reply.kernel_64_bit,
667668
conn_reply.slowdown, conn_reply.syscall_timeout_ms,
668-
conn_reply.program_timeout_ms, static_cast<uint64>(conn_reply.features));
669+
conn_reply.program_timeout_ms, conn_reply.proc_restart_freq, static_cast<uint64>(conn_reply.features));
669670
leak_frames_ = conn_reply.leak_frames;
670671

671672
proc_opts_.use_cover_edges = conn_reply.cover_edges;
672673
proc_opts_.is_kernel_64_bit = is_kernel_64_bit = conn_reply.kernel_64_bit;
673674
proc_opts_.slowdown = conn_reply.slowdown;
674675
proc_opts_.syscall_timeout_ms = conn_reply.syscall_timeout_ms;
675676
proc_opts_.program_timeout_ms = conn_reply.program_timeout_ms;
677+
proc_opts_.proc_restart_freq = conn_reply.proc_restart_freq;
678+
if (proc_opts_.proc_restart_freq == 0)
679+
fail("invalid proc_restart_freq value");
676680
if (conn_reply.cover)
677681
max_signal_.emplace();
678682

pkg/flatrpc/flatrpc.fbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ table ConnectReplyRaw {
5757
slowdown :int32;
5858
syscall_timeout_ms :int32;
5959
program_timeout_ms :int32;
60+
proc_restart_freq :int32;
6061
leak_frames :[string];
6162
race_frames :[string];
6263
// Fuzzer sets up these features and returns results in InfoRequest.features.

pkg/flatrpc/flatrpc.go

Lines changed: 31 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/flatrpc/flatrpc.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ struct ConnectReplyRawT : public flatbuffers::NativeTable {
10361036
int32_t slowdown = 0;
10371037
int32_t syscall_timeout_ms = 0;
10381038
int32_t program_timeout_ms = 0;
1039+
int32_t proc_restart_freq = 0;
10391040
std::vector<std::string> leak_frames{};
10401041
std::vector<std::string> race_frames{};
10411042
rpc::Feature features = static_cast<rpc::Feature>(0);
@@ -1054,10 +1055,11 @@ struct ConnectReplyRaw FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
10541055
VT_SLOWDOWN = 14,
10551056
VT_SYSCALL_TIMEOUT_MS = 16,
10561057
VT_PROGRAM_TIMEOUT_MS = 18,
1057-
VT_LEAK_FRAMES = 20,
1058-
VT_RACE_FRAMES = 22,
1059-
VT_FEATURES = 24,
1060-
VT_FILES = 26
1058+
VT_PROC_RESTART_FREQ = 20,
1059+
VT_LEAK_FRAMES = 22,
1060+
VT_RACE_FRAMES = 24,
1061+
VT_FEATURES = 26,
1062+
VT_FILES = 28
10611063
};
10621064
bool debug() const {
10631065
return GetField<uint8_t>(VT_DEBUG, 0) != 0;
@@ -1083,6 +1085,9 @@ struct ConnectReplyRaw FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
10831085
int32_t program_timeout_ms() const {
10841086
return GetField<int32_t>(VT_PROGRAM_TIMEOUT_MS, 0);
10851087
}
1088+
int32_t proc_restart_freq() const {
1089+
return GetField<int32_t>(VT_PROC_RESTART_FREQ, 0);
1090+
}
10861091
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *leak_frames() const {
10871092
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(VT_LEAK_FRAMES);
10881093
}
@@ -1105,6 +1110,7 @@ struct ConnectReplyRaw FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
11051110
VerifyField<int32_t>(verifier, VT_SLOWDOWN, 4) &&
11061111
VerifyField<int32_t>(verifier, VT_SYSCALL_TIMEOUT_MS, 4) &&
11071112
VerifyField<int32_t>(verifier, VT_PROGRAM_TIMEOUT_MS, 4) &&
1113+
VerifyField<int32_t>(verifier, VT_PROC_RESTART_FREQ, 4) &&
11081114
VerifyOffset(verifier, VT_LEAK_FRAMES) &&
11091115
verifier.VerifyVector(leak_frames()) &&
11101116
verifier.VerifyVectorOfStrings(leak_frames()) &&
@@ -1150,6 +1156,9 @@ struct ConnectReplyRawBuilder {
11501156
void add_program_timeout_ms(int32_t program_timeout_ms) {
11511157
fbb_.AddElement<int32_t>(ConnectReplyRaw::VT_PROGRAM_TIMEOUT_MS, program_timeout_ms, 0);
11521158
}
1159+
void add_proc_restart_freq(int32_t proc_restart_freq) {
1160+
fbb_.AddElement<int32_t>(ConnectReplyRaw::VT_PROC_RESTART_FREQ, proc_restart_freq, 0);
1161+
}
11531162
void add_leak_frames(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> leak_frames) {
11541163
fbb_.AddOffset(ConnectReplyRaw::VT_LEAK_FRAMES, leak_frames);
11551164
}
@@ -1183,6 +1192,7 @@ inline flatbuffers::Offset<ConnectReplyRaw> CreateConnectReplyRaw(
11831192
int32_t slowdown = 0,
11841193
int32_t syscall_timeout_ms = 0,
11851194
int32_t program_timeout_ms = 0,
1195+
int32_t proc_restart_freq = 0,
11861196
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> leak_frames = 0,
11871197
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> race_frames = 0,
11881198
rpc::Feature features = static_cast<rpc::Feature>(0),
@@ -1192,6 +1202,7 @@ inline flatbuffers::Offset<ConnectReplyRaw> CreateConnectReplyRaw(
11921202
builder_.add_files(files);
11931203
builder_.add_race_frames(race_frames);
11941204
builder_.add_leak_frames(leak_frames);
1205+
builder_.add_proc_restart_freq(proc_restart_freq);
11951206
builder_.add_program_timeout_ms(program_timeout_ms);
11961207
builder_.add_syscall_timeout_ms(syscall_timeout_ms);
11971208
builder_.add_slowdown(slowdown);
@@ -1213,6 +1224,7 @@ inline flatbuffers::Offset<ConnectReplyRaw> CreateConnectReplyRawDirect(
12131224
int32_t slowdown = 0,
12141225
int32_t syscall_timeout_ms = 0,
12151226
int32_t program_timeout_ms = 0,
1227+
int32_t proc_restart_freq = 0,
12161228
const std::vector<flatbuffers::Offset<flatbuffers::String>> *leak_frames = nullptr,
12171229
const std::vector<flatbuffers::Offset<flatbuffers::String>> *race_frames = nullptr,
12181230
rpc::Feature features = static_cast<rpc::Feature>(0),
@@ -1230,6 +1242,7 @@ inline flatbuffers::Offset<ConnectReplyRaw> CreateConnectReplyRawDirect(
12301242
slowdown,
12311243
syscall_timeout_ms,
12321244
program_timeout_ms,
1245+
proc_restart_freq,
12331246
leak_frames__,
12341247
race_frames__,
12351248
features,
@@ -3052,6 +3065,7 @@ inline void ConnectReplyRaw::UnPackTo(ConnectReplyRawT *_o, const flatbuffers::r
30523065
{ auto _e = slowdown(); _o->slowdown = _e; }
30533066
{ auto _e = syscall_timeout_ms(); _o->syscall_timeout_ms = _e; }
30543067
{ auto _e = program_timeout_ms(); _o->program_timeout_ms = _e; }
3068+
{ auto _e = proc_restart_freq(); _o->proc_restart_freq = _e; }
30553069
{ auto _e = leak_frames(); if (_e) { _o->leak_frames.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->leak_frames[_i] = _e->Get(_i)->str(); } } }
30563070
{ auto _e = race_frames(); if (_e) { _o->race_frames.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->race_frames[_i] = _e->Get(_i)->str(); } } }
30573071
{ auto _e = features(); _o->features = _e; }
@@ -3074,6 +3088,7 @@ inline flatbuffers::Offset<ConnectReplyRaw> CreateConnectReplyRaw(flatbuffers::F
30743088
auto _slowdown = _o->slowdown;
30753089
auto _syscall_timeout_ms = _o->syscall_timeout_ms;
30763090
auto _program_timeout_ms = _o->program_timeout_ms;
3091+
auto _proc_restart_freq = _o->proc_restart_freq;
30773092
auto _leak_frames = _o->leak_frames.size() ? _fbb.CreateVectorOfStrings(_o->leak_frames) : 0;
30783093
auto _race_frames = _o->race_frames.size() ? _fbb.CreateVectorOfStrings(_o->race_frames) : 0;
30793094
auto _features = _o->features;
@@ -3088,6 +3103,7 @@ inline flatbuffers::Offset<ConnectReplyRaw> CreateConnectReplyRaw(flatbuffers::F
30883103
_slowdown,
30893104
_syscall_timeout_ms,
30903105
_program_timeout_ms,
3106+
_proc_restart_freq,
30913107
_leak_frames,
30923108
_race_frames,
30933109
_features,

pkg/mgrconfig/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ type Experimental struct {
255255
// with an empty Filter, but non-empty weight.
256256
// E.g. "focus_areas": [ {"filter": {"files": ["^net"]}, "weight": 10.0}, {"weight": 1.0} ].
257257
FocusAreas []FocusArea `json:"focus_areas,omitempty"`
258+
259+
// The number of executions per proc before it's restarted.
260+
// Lower values may improve bug reproduction rates, but they slow down fuzzing considerably.
261+
// The default value is 600.
262+
ProcRestartFreq int `json:"proc_restart_freq,omitempty"`
258263
}
259264

260265
type FocusArea struct {

pkg/rpcserver/rpcserver.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ type Config struct {
4747
FilterSignal bool
4848
PrintMachineCheck bool
4949
// Abort early on syz-executor not replying to requests and print extra debugging information.
50-
DebugTimeouts bool
51-
Procs int
52-
Slowdown int
53-
pcBase uint64
54-
localModules []*vminfo.KernelModule
50+
DebugTimeouts bool
51+
Procs int
52+
Slowdown int
53+
ProcRestartFreq int
54+
pcBase uint64
55+
localModules []*vminfo.KernelModule
5556

5657
// RPCServer closes the channel once the machine check has begun. Used for fault injection during testing.
5758
machineCheckStarted chan struct{}
@@ -184,6 +185,7 @@ func New(cfg *RemoteConfig) (Server, error) {
184185
PrintMachineCheck: true,
185186
Procs: cfg.Procs,
186187
Slowdown: cfg.Timeouts.Slowdown,
188+
ProcRestartFreq: cfg.Experimental.ProcRestartFreq,
187189
pcBase: pcBase,
188190
localModules: cfg.LocalModules,
189191
}, cfg.Manager), nil
@@ -328,12 +330,18 @@ func (serv *server) handleConn(ctx context.Context, conn *flatrpc.Conn) error {
328330
return nil
329331
}
330332

333+
const defaultProcRestartFreq = 600
334+
331335
func (serv *server) handleRunnerConn(ctx context.Context, runner *Runner, conn *flatrpc.Conn) error {
332336
opts := &handshakeConfig{
333-
VMLess: serv.cfg.VMLess,
334-
Files: serv.checker.RequiredFiles(),
335-
Timeouts: serv.timeouts,
336-
Callback: serv.handleMachineInfo,
337+
VMLess: serv.cfg.VMLess,
338+
Files: serv.checker.RequiredFiles(),
339+
Timeouts: serv.timeouts,
340+
Callback: serv.handleMachineInfo,
341+
ProcRestartFreq: defaultProcRestartFreq,
342+
}
343+
if serv.cfg.ProcRestartFreq != 0 {
344+
opts.ProcRestartFreq = serv.cfg.ProcRestartFreq
337345
}
338346
opts.LeakFrames, opts.RaceFrames = serv.mgr.BugFrames()
339347
if serv.checkDone.Load() {

0 commit comments

Comments
 (0)