Skip to content

Commit

Permalink
[MTE] Fix tests after crrev.com/c/4495526
Browse files Browse the repository at this point in the history
crrev.com/c/4495526 broke tests because it disabled MTE when tests were expecting sync MTE.

(cherry picked from commit a413841)

Bug: 1448009
Change-Id: Ifabb91c37a885920860b1116ed9dd5b7be699c75
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4570311
Reviewed-by: Bartek Nowierski <bartekn@chromium.org>
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1151240}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4597036
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/5790@{#438}
Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
  • Loading branch information
Keishi Hattori authored and Chromium LUCI CQ committed Jun 7, 2023
1 parent 87a3a8c commit 8def4dc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
56 changes: 32 additions & 24 deletions base/allocator/partition_alloc_support.cc
Expand Up @@ -1175,34 +1175,42 @@ void PartitionAllocSupport::ReconfigureAfterFeatureListInit(
.Get()
: base::features::AlternateBucketDistributionMode::kDefault;

bool enable_memory_tagging = false;
#if PA_CONFIG(HAS_MEMORY_TAGGING)
bool enable_memory_tagging = ShouldEnableMemoryTagging(process_type);
// If synchronous mode is enabled from startup it means this is a test and
// memory tagging should be enabled.
if (partition_alloc::internal::GetMemoryTaggingModeForCurrentThread() ==
partition_alloc::TagViolationReportingMode::kSynchronous) {
enable_memory_tagging = true;
} else {
enable_memory_tagging = ShouldEnableMemoryTagging(process_type);
#if BUILDFLAG(IS_ANDROID)
if (enable_memory_tagging) {
partition_alloc::TagViolationReportingMode reporting_mode;
switch (base::features::kMemtagModeParam.Get()) {
case base::features::MemtagMode::kSync:
reporting_mode =
partition_alloc::TagViolationReportingMode::kSynchronous;
break;
case base::features::MemtagMode::kAsync:
reporting_mode =
partition_alloc::TagViolationReportingMode::kAsynchronous;
break;
if (enable_memory_tagging) {
partition_alloc::TagViolationReportingMode reporting_mode;
switch (base::features::kMemtagModeParam.Get()) {
case base::features::MemtagMode::kSync:
reporting_mode =
partition_alloc::TagViolationReportingMode::kSynchronous;
break;
case base::features::MemtagMode::kAsync:
reporting_mode =
partition_alloc::TagViolationReportingMode::kAsynchronous;
break;
}
partition_alloc::internal::ChangeMemoryTaggingModeForAllThreadsPerProcess(
reporting_mode);
CHECK_EQ(
partition_alloc::internal::GetMemoryTaggingModeForCurrentThread(),
reporting_mode);
} else if (base::CPU::GetInstanceNoAllocation().has_mte()) {
partition_alloc::internal::ChangeMemoryTaggingModeForAllThreadsPerProcess(
partition_alloc::TagViolationReportingMode::kDisabled);
CHECK_EQ(
partition_alloc::internal::GetMemoryTaggingModeForCurrentThread(),
partition_alloc::TagViolationReportingMode::kDisabled);
}
partition_alloc::internal::ChangeMemoryTaggingModeForAllThreadsPerProcess(
reporting_mode);
CHECK_EQ(partition_alloc::internal::GetMemoryTaggingModeForCurrentThread(),
reporting_mode);
} else if (base::CPU::GetInstanceNoAllocation().has_mte()) {
partition_alloc::internal::ChangeMemoryTaggingModeForAllThreadsPerProcess(
partition_alloc::TagViolationReportingMode::kDisabled);
CHECK_EQ(partition_alloc::internal::GetMemoryTaggingModeForCurrentThread(),
partition_alloc::TagViolationReportingMode::kDisabled);
}
#endif // BUILDFLAG(IS_ANDROID)
#else // PA_CONFIG(HAS_MEMORY_TAGGING)
bool enable_memory_tagging = false;
}
#endif // PA_CONFIG(HAS_MEMORY_TAGGING)

allocator_shim::ConfigurePartitions(
Expand Down
15 changes: 9 additions & 6 deletions base/allocator/partition_allocator/pointers/raw_ptr_unittest.cc
Expand Up @@ -1510,18 +1510,21 @@ void HandleOOM(size_t unused_size) {
LOG(FATAL) << "Out of memory";
}

static constexpr partition_alloc::PartitionOptions kOpts = {
.cookie = partition_alloc::PartitionOptions::Cookie::kAllowed,
.backup_ref_ptr = partition_alloc::PartitionOptions::BackupRefPtr::kEnabled,
};

class BackupRefPtrTest : public testing::Test {
protected:
void SetUp() override {
// TODO(bartekn): Avoid using PartitionAlloc API directly. Switch to
// new/delete once PartitionAlloc Everywhere is fully enabled.
partition_alloc::PartitionAllocGlobalInit(HandleOOM);
allocator_.init(kOpts);
allocator_.init(
{.cookie = partition_alloc::PartitionOptions::Cookie::kAllowed,
.backup_ref_ptr =
partition_alloc::PartitionOptions::BackupRefPtr::kEnabled,
.memory_tagging =
base::CPU::GetInstanceNoAllocation().has_mte()
? partition_alloc::PartitionOptions::MemoryTagging::kEnabled
: partition_alloc::PartitionOptions::MemoryTagging::
kDisabled});
}

partition_alloc::PartitionAllocator allocator_;
Expand Down
Expand Up @@ -59,7 +59,10 @@ class PartitionAllocPCScanTestBase : public testing::Test {
allocator_.init(PartitionOptions{
.aligned_alloc = PartitionOptions::AlignedAlloc::kAllowed,
.quarantine = PartitionOptions::Quarantine::kAllowed,
});
.memory_tagging =
base::CPU::GetInstanceNoAllocation().has_mte()
? partition_alloc::PartitionOptions::MemoryTagging::kEnabled
: partition_alloc::PartitionOptions::MemoryTagging::kDisabled});
allocator_.root()->UncapEmptySlotSpanMemoryForTesting();
allocator_.root()->SwitchToDenserBucketDistribution();

Expand Down

0 comments on commit 8def4dc

Please sign in to comment.