Skip to content

Commit d2e4ab7

Browse files
committed
(lib/model) fix: exit step early before initialisation
Check `is_initialised` early, before trying to acquire any locks. This means that if we take casemate steps before pgtables are enabled, we keep going and do not try perform any atomic operations later on (namely the Casemate internal locks).
1 parent a0efe98 commit d2e4ab7

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/lib/include/casemate-impl/sync.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@ void init_sm_lock(void);
55
void lock_sm(void);
66
void unlock_sm(void);
77

8+
#define LOAD_RLX(L) \
9+
*((volatile typeof(L)*)&L)
10+
11+
#define STORE_RLX(L, V) \
12+
*((volatile typeof(L)*)(&L)) = V
13+
814
#endif /* CASEMATE_SYNC_H */

src/lib/src/model.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,9 +1711,6 @@ void step(struct casemate_model_step trans)
17111711
touched_watchpoint = false;
17121712
traced_current_trans = false;
17131713

1714-
if (!is_initialised)
1715-
goto out;
1716-
17171714
if (!opts()->enable_checking)
17181715
goto out;
17191716

@@ -1757,6 +1754,9 @@ void step(struct casemate_model_step trans)
17571754

17581755
void casemate_model_step(struct casemate_model_step trans)
17591756
{
1757+
if (!LOAD_RLX(is_initialised))
1758+
return;
1759+
17601760
lock_sm();
17611761
step(trans);
17621762
unlock_sm();

src/lib/src/utilities/blobs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void initialise_ghost_ptes_memory(phys_addr_t phys, u64 size) {
1212
the_ghost_state->memory.blobs_backing[i].valid = false;
1313
the_ghost_state->memory.ordered_blob_list[i] = 0xDEADDEADDEADDEAD;
1414
}
15-
is_initialised = true;
15+
STORE_RLX(is_initialised, true);
1616
GHOST_LOG_CONTEXT_EXIT();
1717
}
1818

0 commit comments

Comments
 (0)