Merge "[MTE] Add SYNC compat feature & disable for system apps." am: 284195e759

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1548867

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Iab3c497819e9d5e07daf53bc6a641eca2150f1ba
This commit is contained in:
Mitch Phillips
2021-01-21 21:16:56 +00:00
committed by Automerger Merge Worker

View File

@@ -110,7 +110,6 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.ProcessMap; import com.android.internal.app.ProcessMap;
import com.android.internal.app.procstats.ProcessStats; import com.android.internal.app.procstats.ProcessStats;
import com.android.internal.os.RuntimeInit;
import com.android.internal.os.Zygote; import com.android.internal.os.Zygote;
import com.android.internal.util.ArrayUtils; import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FrameworkStatsLog; import com.android.internal.util.FrameworkStatsLog;
@@ -349,12 +348,23 @@ public final class ProcessList {
private static final long NATIVE_HEAP_POINTER_TAGGING = 135754954; // This is a bug id. private static final long NATIVE_HEAP_POINTER_TAGGING = 135754954; // This is a bug id.
/** /**
* Enable memory tag checks in non-system apps. This flag will only have an effect on * Enable asynchronous (ASYNC) memory tag checking in this process. This
* hardware supporting the ARM Memory Tagging Extension (MTE). * flag will only have an effect on hardware supporting the ARM Memory
* Tagging Extension (MTE).
*/ */
@ChangeId @ChangeId
@Disabled @Disabled
private static final long NATIVE_MEMORY_TAGGING = 135772972; // This is a bug id. private static final long NATIVE_MEMTAG_ASYNC = 135772972; // This is a bug id.
/**
* Enable synchronous (SYNC) memory tag checking in this process. This flag
* will only have an effect on hardware supporting the ARM Memory Tagging
* Extension (MTE). If both NATIVE_MEMTAG_ASYNC and this option is selected,
* this option takes preference and MTE is enabled in SYNC mode.
*/
@ChangeId
@Disabled
private static final long NATIVE_MEMTAG_SYNC = 177438394; // This is a bug id.
/** /**
* Enable sampled memory bug detection in the app. * Enable sampled memory bug detection in the app.
@@ -1677,23 +1687,23 @@ public final class ProcessList {
return gidArray; return gidArray;
} }
private boolean shouldEnableMemoryTagging(ProcessRecord app) { // Returns the memory tagging level to be enabled. If memory tagging isn't
// requested, returns zero.
private int getMemtagLevel(ProcessRecord app) {
// Ensure the hardware + kernel actually supports MTE. // Ensure the hardware + kernel actually supports MTE.
if (!Zygote.nativeSupportsMemoryTagging()) { if (!Zygote.nativeSupportsMemoryTagging()) {
return false; return 0;
} }
// Enable MTE for system apps if supported. if (mPlatformCompat.isChangeEnabled(NATIVE_MEMTAG_SYNC, app.info)) {
if ((app.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { return Zygote.MEMORY_TAG_LEVEL_SYNC;
return true;
} }
// Enable MTE if the compat feature is enabled. if (mPlatformCompat.isChangeEnabled(NATIVE_MEMTAG_ASYNC, app.info)) {
if (mPlatformCompat.isChangeEnabled(NATIVE_MEMORY_TAGGING, app.info)) { return Zygote.MEMORY_TAG_LEVEL_ASYNC;
return true;
} }
return false; return 0;
} }
private boolean shouldEnableTaggedPointers(ProcessRecord app) { private boolean shouldEnableTaggedPointers(ProcessRecord app) {
@@ -1717,8 +1727,9 @@ public final class ProcessList {
private int decideTaggingLevel(ProcessRecord app) { private int decideTaggingLevel(ProcessRecord app) {
// Check MTE support first, as it should take precedence over TBI. // Check MTE support first, as it should take precedence over TBI.
if (shouldEnableMemoryTagging(app)) { int memtagLevel = getMemtagLevel(app);
return Zygote.MEMORY_TAG_LEVEL_ASYNC; if (memtagLevel != 0) {
return memtagLevel;
} }
if (shouldEnableTaggedPointers(app)) { if (shouldEnableTaggedPointers(app)) {