Skip to content

Commit fa07ebf

Browse files
Merge pull request #40 from WorksButNotTested/arm64-crash
Fix
2 parents 806769a + 98029fc commit fa07ebf

File tree

4 files changed

+22
-43
lines changed

4 files changed

+22
-43
lines changed

accel/tcg/cpu-exec.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,6 @@ void afl_forkserver(CPUState *cpu) {
656656

657657
}
658658

659-
// Flush translation cache just before fork server starts.
660-
tb_flush_sync();
661-
662659
/* All right, let's await orders... */
663660

664661
while (1) {

accel/tcg/translate-all.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,44 +1537,6 @@ void tb_flush(CPUState *cpu)
15371537
}
15381538
}
15391539

1540-
/*
1541-
* If we call tb_flush, from inside cpu_exec, then it will queue do_tb_flush to
1542-
* run asyncronously. Since we wish to do this when we start the forkserver to
1543-
* flush any translated blocks which may have been translated before the
1544-
* configuration from environment variables has been parsed, this will cause the
1545-
* flush to be deferred and instead performed after the fork server is running
1546-
* resulting in the flush occurring repeatedly rather than just the once, with
1547-
* the obvious resulting performance overhead.
1548-
*
1549-
* However, we know that the fork server should be initialized when the target
1550-
* application has only a single thread (since the fork syscall will only clone
1551-
* the calling thread into the child process). Therefore, we don't need any
1552-
* synchronization with respect to any other VCPUs and can therefore perform the
1553-
* flush synchronously instead.
1554-
*/
1555-
void tb_flush_sync(void)
1556-
{
1557-
CPUState *cpu = NULL;
1558-
size_t num_cpus = 0;
1559-
1560-
if (!tcg_enabled()) {
1561-
return;
1562-
}
1563-
1564-
CPU_FOREACH(cpu) {
1565-
num_cpus++;
1566-
}
1567-
1568-
if (num_cpus != 1) {
1569-
fprintf(stderr, "Warning: More than one VCPU when attempting to flush "
1570-
"translation block cache. Skipping since we can't do it synchronously.");
1571-
return;
1572-
}
1573-
1574-
unsigned tb_flush_count = qatomic_mb_read(&tb_ctx.tb_flush_count);
1575-
do_tb_flush(cpu, RUN_ON_CPU_HOST_INT(tb_flush_count));
1576-
}
1577-
15781540
/*
15791541
* Formerly ifdef DEBUG_TB_CHECK. These debug functions are user-mode-only,
15801542
* so in order to prevent bit rot we compile them unconditionally in user-mode,

accel/tcg/translator.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,28 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,
9494
}
9595

9696
if (db->pc_next == afl_entry_point) {
97-
afl_setup();
97+
static bool first = true;
98+
/*
99+
* We guard this section since we flush the translation cache after
100+
* we load the configuration, which in turn means we will need to
101+
* re-translate our block. If we were to perform this flush every
102+
* time (rather than just when our configuration is first loaded),
103+
* we would just end up translation this block repeatedly.
104+
*/
105+
if (first) {
106+
afl_setup();
107+
/*
108+
* We flush the translation cache here since we may already have
109+
* translated some blocks and included instrumentation in them
110+
* before we have processed the configuration from the
111+
* environment variables which configures which ranges to
112+
* include and exclude. Therefore we may have some blocks in our
113+
* cache which are incorrectly instrumented and cause some
114+
* fuzzing stability or performance problems.
115+
*/
116+
tb_flush(cpu);
117+
first = false;
118+
}
98119
gen_helper_afl_entry_routine(cpu_env);
99120
}
100121

include/exec/exec-all.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@ void tb_invalidate_phys_range(target_ulong start, target_ulong end);
533533
void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs);
534534
#endif
535535
void tb_flush(CPUState *cpu);
536-
void tb_flush_sync(void);
537536
void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr);
538537
TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc,
539538
target_ulong cs_base, uint32_t flags,

0 commit comments

Comments
 (0)