From 285d48232eb3d07817d31f6a4315acf111e9feb5 Mon Sep 17 00:00:00 2001 From: Keishi Hattori Date: Wed, 7 Jun 2023 14:21:25 +0000 Subject: [PATCH] [MTE] Add MemoryTaggingDogfood synthetic Finch 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 592865e4f01239dcf2cc676770ccdf93fcb65818) Bug: 1448009 Change-Id: Id879838c67d8c8bdec98b4562a54c71ae635ed8b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4583313 Commit-Queue: Keishi Hattori Reviewed-by: Bartek Nowierski Cr-Original-Commit-Position: refs/heads/main@{#1152574} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4596638 Auto-Submit: Keishi Hattori Commit-Queue: Rubber Stamper Bot-Commit: Rubber Stamper Cr-Commit-Position: refs/branch-heads/5790@{#447} Cr-Branched-From: 1d71a337b1f6e707a13ae074dca1e2c34905eb9f-refs/heads/main@{#1148114} --- base/allocator/partition_alloc_support.cc | 21 +++++++++--- .../partition_alloc_support_unittest.cc | 32 +++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/base/allocator/partition_alloc_support.cc b/base/allocator/partition_alloc_support.cc index a19f2ac0228ba..e3d2341009337 100644 --- a/base/allocator/partition_alloc_support.cc +++ b/base/allocator/partition_alloc_support.cc @@ -423,6 +423,17 @@ std::map 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; } @@ -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; } @@ -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(); diff --git a/base/allocator/partition_alloc_support_unittest.cc b/base/allocator/partition_alloc_support_unittest.cc index 591297a143de6..2080e2219f994 100644 --- a/base/allocator/partition_alloc_support_unittest.cc +++ b/base/allocator/partition_alloc_support_unittest.cc @@ -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" @@ -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