Skip to content

Commit

Permalink
[MTE] Add MemoryTaggingDogfood synthetic Finch
Browse files Browse the repository at this point in the history
MemoryTaggingDogfood synthetic Finch group will be:
- unset if kPartitionAllocMemoryTagging is not enabled
- Disabled if MTE bootloader flag is disabled (or MTE is not available)
- Enabled if MTE is enabled

(cherry picked from commit 592865e)

Bug: 1448009
Change-Id: Id879838c67d8c8bdec98b4562a54c71ae635ed8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4583313
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Reviewed-by: Bartek Nowierski <bartekn@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1152574}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4596638
Auto-Submit: Keishi Hattori <keishi@chromium.org>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/5790@{#447}
Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
  • Loading branch information
Keishi Hattori authored and Chromium LUCI CQ committed Jun 7, 2023
1 parent 8a3af13 commit 285d482
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
21 changes: 17 additions & 4 deletions base/allocator/partition_alloc_support.cc
Expand Up @@ -423,6 +423,17 @@ std::map<std::string, std::string> ProposeSyntheticFinchTrials() {
trials.emplace(base::features::kRendererLiveBRPSyntheticTrialName, "Control");
#endif

#if PA_CONFIG(HAS_MEMORY_TAGGING)
if (base::FeatureList::IsEnabled(
base::features::kPartitionAllocMemoryTagging)) {
if (base::CPU::GetInstanceNoAllocation().has_mte()) {
trials.emplace("MemoryTaggingDogfood", "Enabled");
} else {
trials.emplace("MemoryTaggingDogfood", "Disabled");
}
}
#endif

return trials;
}

Expand Down Expand Up @@ -891,6 +902,12 @@ void PartitionAllocSupport::ReconfigureForTests() {
// static
bool PartitionAllocSupport::ShouldEnableMemoryTagging(
const std::string& process_type) {
// Check kPartitionAllocMemoryTagging first so the Feature is activated even
// when mte bootloader flag is disabled.
if (!base::FeatureList::IsEnabled(
base::features::kPartitionAllocMemoryTagging)) {
return false;
}
if (!base::CPU::GetInstanceNoAllocation().has_mte()) {
return false;
}
Expand All @@ -900,10 +917,6 @@ bool PartitionAllocSupport::ShouldEnableMemoryTagging(
base::features::kKillPartitionAllocMemoryTagging)) {
return false;
}
if (!base::FeatureList::IsEnabled(
base::features::kPartitionAllocMemoryTagging)) {
return false;
}
switch (base::features::kMemoryTaggingEnabledProcessesParam.Get()) {
case base::features::MemoryTaggingEnabledProcesses::kBrowserOnly:
return process_type.empty();
Expand Down
32 changes: 32 additions & 0 deletions base/allocator/partition_alloc_support_unittest.cc
Expand Up @@ -10,6 +10,7 @@

#include "base/allocator/partition_alloc_features.h"
#include "base/allocator/partition_allocator/dangling_raw_ptr_checks.h"
#include "base/allocator/partition_allocator/partition_alloc_base/cpu.h"
#include "base/allocator/partition_allocator/partition_alloc_buildflags.h"
#include "base/feature_list.h"
#include "base/task/single_thread_task_runner.h"
Expand Down Expand Up @@ -419,5 +420,36 @@ TEST(PartitionAllocSupportTest,
#endif
}

#if PA_CONFIG(HAS_MEMORY_TAGGING)
TEST(PartitionAllocSupportTest,
ProposeSyntheticFinchTrials_MemoryTaggingDogfood) {
{
test::ScopedFeatureList scope;
scope.InitWithFeatures({}, {features::kPartitionAllocMemoryTagging});

auto trials = ProposeSyntheticFinchTrials();

auto group_iter = trials.find("MemoryTaggingDogfood");
EXPECT_EQ(group_iter, trials.end());
}

{
test::ScopedFeatureList scope;
scope.InitWithFeatures({features::kPartitionAllocMemoryTagging}, {});

auto trials = ProposeSyntheticFinchTrials();

std::string expectation =
partition_alloc::internal::base::CPU::GetInstanceNoAllocation()
.has_mte()
? "Enabled"
: "Disabled";
auto group_iter = trials.find("MemoryTaggingDogfood");
EXPECT_NE(group_iter, trials.end());
EXPECT_EQ(group_iter->second, expectation);
}
}
#endif

} // namespace allocator
} // namespace base

0 comments on commit 285d482

Please sign in to comment.