This is an archive of the discontinued LLVM Phabricator instance.

[scudo] Split the code paths in quarantineOrDeallocateChunk()
AcceptedPublic

Authored by Chia-hungDuan on Sep 1 2023, 9:21 PM.

Details

Reviewers
cferris
Summary

Move block untagging logic to another function and sink untagged pointer
to quarantineOrDeallocateChunk().

Diff Detail

Event Timeline

Chia-hungDuan created this revision.Sep 1 2023, 9:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2023, 9:21 PM
Herald added subscribers: yaneury, Enna1. · View Herald Transcript
Chia-hungDuan requested review of this revision.Sep 1 2023, 9:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2023, 9:21 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
cferris requested changes to this revision.Sep 20 2023, 5:45 PM
cferris added inline comments.
compiler-rt/lib/scudo/standalone/combined.h
1175–1176

it might be better if you move this into the else down below. Since the first if sets this unconditionally, I think it would be easier to follow to have it set in both the if and else.

1178

I don't think this initializing is necessary since BlockBegin is set in both the if and else statement below.

1210–1216

The Quarantine code path looks like it's kind of odd.

I think it would make this code a lot more readable if the qurantine case was moved to the location of the BypassQuarantine bool init.

It would look like this:

if (!BypassQuarantine) {
  NewHeader.State = Chunk::State::Quarantined;
  bool UnlockRequired;
  auto *TSD = TSDRegistry.getTSDAndLock(&UnlockRequired);
  Quarantine.put(&TSD->getQuarantineCache(),
                   QuarantineCallback(*this, TSD->getCache()), Ptr, Size);
  if (UnlockRequired)
      TSD->unlock();
  return;
}

I think you might need to call unTagBlock if memory tagging is enabled in the quarantine path.

Right now this new change does some extra work when in the quarantine path, but if you split it out then that won't happen. And adding the unTagBlock call might also do some extra work though so I'm not sure what's the best way to handle this.

It might be better to do that in a follow-on though. I'll leave that up to you, or since it's my suggestion, I can also do this.

This revision now requires changes to proceed.Sep 20 2023, 5:45 PM
Chia-hungDuan marked 2 inline comments as done.

Address review comments

compiler-rt/lib/scudo/standalone/combined.h
1210–1216

I agree with the code motion of quarantine block. As we discussed, we may also want to config quarantine by compilation flag. Thus I'm planning to do the code motion with the config change in a later CL.

I've fixed the part that we did more work in quarantine path. Now it should be the same logic as before.

cferris accepted this revision.Sep 26 2023, 6:20 PM

LGTM.

This revision is now accepted and ready to land.Sep 26 2023, 6:20 PM