Skip to content

Commit

Permalink
Merge pull request #150 from comparch-security/fix-evict
Browse files Browse the repository at this point in the history
Permission needs to be elevated during eviction
  • Loading branch information
wsong83 authored Sep 15, 2024
2 parents 9eefce6 + 95e7534 commit 6a640b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cache/coherence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class OuterCohPortT : public OPUC<Policy, EnMT, Extra...>
hit = cache->hit(addr, &ai, &s, &w, XactPrio::probe, true);
if(hit) {
std::tie(meta, data) = cache->access_line(ai, s, w); meta->lock();
if(!meta->match(addr)) { // cache line is invalidated potentially by a simultaneous acquire
if(!cache->check_mt_state(ai, s, XactPrio::probe) || !meta->match(addr)) { // cache line is invalidated potentially by a simultaneous acquire
meta->unlock(); meta = nullptr; data = nullptr;
cache->reset_mt_state(ai, s, XactPrio::probe); continue; // redo the hit check
}
Expand Down Expand Up @@ -254,6 +254,7 @@ class InnerCohPortUncached : public InnerCohPortBase
// evict a block due to conflict
auto addr = meta->addr(s);
assert(cache->hit(addr));
if constexpr (EnMT && Policy::evict_need_lock()) cache->set_mt_state(ai, s, XactPrio::evict);
auto sync = Policy::writeback_need_sync(meta);
if(sync.first) {
auto [phit, pwb] = probe_req(addr, meta, data, sync.second, delay); // sync if necessary
Expand All @@ -263,6 +264,7 @@ class InnerCohPortUncached : public InnerCohPortBase
if(writeback.first) outer->writeback_req(addr, meta, data, writeback.second, delay); // writeback if dirty
Policy::meta_after_evict(meta);
cache->hook_manage(addr, ai, s, w, true, true, writeback.first, meta, data, delay);
if constexpr (EnMT && Policy::evict_need_lock()) cache->reset_mt_state(ai, s, XactPrio::evict);
}

virtual std::tuple<bool, CMMetadataBase *, CMDataBase *, uint32_t, uint32_t, uint32_t>
Expand Down Expand Up @@ -344,6 +346,7 @@ class InnerCohPortUncached : public InnerCohPortBase
auto [probe, probe_cmd] = Policy::flush_need_sync(cmd, meta);
if(!hit) return;

if constexpr (EnMT && Policy::evict_need_lock()) cache->set_mt_state(ai, s, XactPrio::evict);
if(probe) {
auto [phit, pwb] = probe_req(addr, meta, data, probe_cmd, delay); // sync if necessary
if(pwb) cache->hook_write(addr, ai, s, w, true, false, meta, data, delay); // a write occurred during the probe
Expand All @@ -355,7 +358,10 @@ class InnerCohPortUncached : public InnerCohPortBase
Policy::meta_after_flush(cmd, meta, cache);
cache->hook_manage(addr, ai, s, w, hit, coh::is_evict(cmd), writeback.first, meta, data, delay);

if constexpr (EnMT) { meta->unlock(); cache->reset_mt_state(ai, s, XactPrio::flush); }
if constexpr (EnMT) {
if constexpr (Policy::evict_need_lock()) cache->reset_mt_state(ai, s, XactPrio::evict);
meta->unlock(); cache->reset_mt_state(ai, s, XactPrio::flush);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions cache/mi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ struct MIPolicy : public CohPolicyBase
{
constexpr static __always_inline bool is_uncached() { return uncached; }

constexpr static __always_inline bool evict_need_lock() { return !(uncached || isL1); }

static __always_inline coh_cmd_t cmd_for_outer_acquire(coh_cmd_t cmd) { return coh::cmd_for_write(); }

static __always_inline std::pair<bool, coh_cmd_t> access_need_sync(coh_cmd_t cmd, const CMMetadataBase *meta) {
Expand Down

0 comments on commit 6a640b9

Please sign in to comment.