gralloc: Read debug properties in allocator process
This change resolves selinux denials caused by system processes
reading vendor debug properties via gralloc. The debug properties
are read and parsed in the allocator process, then propagated
through the BufferManager
CRs-Fixed: 2619084
Change-Id: I5175a7848cdcd2671bd16ee11721066a921f3d79
diff --git a/gralloc/QtiAllocator.cpp b/gralloc/QtiAllocator.cpp
index 529889f..1a04237 100644
--- a/gralloc/QtiAllocator.cpp
+++ b/gralloc/QtiAllocator.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -30,6 +30,7 @@
#define DEBUG 0
#include "QtiAllocator.h"
+#include <cutils/properties.h>
#include <log/log.h>
#include <vendor/qti/hardware/display/mapper/3.0/IQtiMapper.h>
#include <vendor/qti/hardware/display/mapper/4.0/IQtiMapper.h>
@@ -40,6 +41,26 @@
#include "QtiMapper4.h"
#include "gr_utils.h"
+static void get_properties(gralloc::GrallocProperties *props) {
+ char property[PROPERTY_VALUE_MAX];
+ property_get("vendor.gralloc.use_system_heap_for_sensors", property, "1");
+ if (!(strncmp(property, "0", PROPERTY_VALUE_MAX))) {
+ props->use_system_heap_for_sensors = false;
+ }
+
+ property_get("vendor.gralloc.disable_ubwc", property, "0");
+ if (!(strncmp(property, "1", PROPERTY_VALUE_MAX)) ||
+ !(strncmp(property, "true", PROPERTY_VALUE_MAX))) {
+ props->ubwc_disable = true;
+ }
+
+ property_get("vendor.gralloc.disable_ahardware_buffer", property, "0");
+ if (!(strncmp(property, "1", PROPERTY_VALUE_MAX)) ||
+ !(strncmp(property, "true", PROPERTY_VALUE_MAX))) {
+ props->ahardware_buffer_disable = true;
+ }
+}
+
namespace vendor {
namespace qti {
namespace hardware {
@@ -54,7 +75,10 @@
using gralloc::Error;
QtiAllocator::QtiAllocator() {
+ gralloc::GrallocProperties properties;
+ get_properties(&properties);
buf_mgr_ = BufferManager::GetInstance();
+ buf_mgr_->SetGrallocDebugProperties(properties);
}
// Methods from ::android::hardware::graphics::allocator::V2_0::IAllocator follow.
diff --git a/gralloc/gr_adreno_info.cpp b/gralloc/gr_adreno_info.cpp
index d33f7db..924020a 100644
--- a/gralloc/gr_adreno_info.cpp
+++ b/gralloc/gr_adreno_info.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2018, 2020 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2020, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -77,21 +77,6 @@
} else {
ALOGE(" Failed to load libadreno_utils.so");
}
-
- // Check if the overriding property debug.gralloc.gfx_ubwc_disable
- // that disables UBWC allocations for the graphics stack is set
- char property[PROPERTY_VALUE_MAX];
- property_get(DISABLE_UBWC_PROP, property, "0");
- if (!(strncmp(property, "1", PROPERTY_VALUE_MAX)) ||
- !(strncmp(property, "true", PROPERTY_VALUE_MAX))) {
- gfx_ubwc_disable_ = true;
- }
-
- property_get(DISABLE_AHARDWAREBUFFER_PROP, property, "0");
- if (!(strncmp(property, "1", PROPERTY_VALUE_MAX)) ||
- !(strncmp(property, "true", PROPERTY_VALUE_MAX))) {
- gfx_ahardware_buffer_disable_ = true;
- }
}
AdrenoMemInfo::~AdrenoMemInfo() {
@@ -100,6 +85,11 @@
}
}
+void AdrenoMemInfo::AdrenoSetProperties(gralloc::GrallocProperties props) {
+ gfx_ubwc_disable_ = props.ubwc_disable;
+ gfx_ahardware_buffer_disable_ = props.ahardware_buffer_disable;
+}
+
void AdrenoMemInfo::AlignUnCompressedRGB(int width, int height, int format, int tile_enabled,
unsigned int *aligned_w, unsigned int *aligned_h) {
*aligned_w = (unsigned int)ALIGN(width, 32);
diff --git a/gralloc/gr_adreno_info.h b/gralloc/gr_adreno_info.h
index 436e0c0..6c9c3e3 100644
--- a/gralloc/gr_adreno_info.h
+++ b/gralloc/gr_adreno_info.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2020, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -32,6 +32,8 @@
#include <media/msm_media_info.h>
+#include "gr_utils.h"
+
namespace gralloc {
// Adreno Pixel Formats
@@ -190,6 +192,8 @@
*/
bool AdrenoSizeAPIAvaliable();
+ void AdrenoSetProperties(gralloc::GrallocProperties props);
+
static AdrenoMemInfo *GetInstance();
private:
diff --git a/gralloc/gr_allocator.cpp b/gralloc/gr_allocator.cpp
index 6421157..a807319 100644
--- a/gralloc/gr_allocator.cpp
+++ b/gralloc/gr_allocator.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2020, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -92,11 +92,6 @@
bool Allocator::Init() {
ion_allocator_ = new IonAlloc();
- char property[PROPERTY_VALUE_MAX];
- property_get(USE_SYSTEM_HEAP_FOR_SENSORS, property, "1");
- if (!(strncmp(property, "0", PROPERTY_VALUE_MAX))) {
- use_system_heap_for_sensors_ = false;
- }
if (!ion_allocator_->Init()) {
return false;
@@ -111,6 +106,10 @@
}
}
+void Allocator::SetProperties(gralloc::GrallocProperties props) {
+ use_system_heap_for_sensors_ = props.use_system_heap_for_sensors;
+}
+
int Allocator::AllocateMem(AllocData *alloc_data, uint64_t usage, int format) {
int ret;
alloc_data->uncached = UseUncached(format, usage);
diff --git a/gralloc/gr_allocator.h b/gralloc/gr_allocator.h
index 630151a..8a9ba64 100644
--- a/gralloc/gr_allocator.h
+++ b/gralloc/gr_allocator.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2018, 2020, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -44,6 +44,7 @@
Allocator();
~Allocator();
bool Init();
+ void SetProperties(gralloc::GrallocProperties props);
int MapBuffer(void **base, unsigned int size, unsigned int offset, int fd);
int ImportBuffer(int fd);
int FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd, int handle);
diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp
index 65b3864..b7554b0 100644
--- a/gralloc/gr_buf_mgr.cpp
+++ b/gralloc/gr_buf_mgr.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2018 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2018, 2020 The Linux Foundation. All rights reserved.
* Not a Contribution
*
* Copyright (C) 2010 The Android Open Source Project
@@ -32,6 +32,7 @@
#include <utility>
#include <vector>
+#include "gr_adreno_info.h"
#include "gr_buf_descriptor.h"
#include "gr_priv_handle.h"
#include "gr_utils.h"
@@ -381,6 +382,11 @@
}
}
+void BufferManager::SetGrallocDebugProperties(gralloc::GrallocProperties props) {
+ allocator_->SetProperties(props);
+ AdrenoMemInfo::GetInstance()->AdrenoSetProperties(props);
+}
+
Error BufferManager::FreeBuffer(std::shared_ptr<Buffer> buf) {
auto hnd = buf->handle;
ALOGD_IF(DEBUG, "FreeBuffer handle:%p", hnd);
diff --git a/gralloc/gr_buf_mgr.h b/gralloc/gr_buf_mgr.h
index e2daa12..9c5794c 100644
--- a/gralloc/gr_buf_mgr.h
+++ b/gralloc/gr_buf_mgr.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2018, 2020 The Linux Foundation. All rights reserved.
* Not a Contribution
*
* Copyright (C) 2008 The Android Open Source Project
@@ -56,6 +56,7 @@
Error FlushBuffer(const private_handle_t *handle);
Error RereadBuffer(const private_handle_t *handle);
Error GetAllHandles(std::vector<const private_handle_t *> *out_handle_list);
+ void SetGrallocDebugProperties(gralloc::GrallocProperties props);
private:
BufferManager();
diff --git a/gralloc/gr_utils.h b/gralloc/gr_utils.h
index f2efdda..e21f92b 100644
--- a/gralloc/gr_utils.h
+++ b/gralloc/gr_utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2016,2018-2019, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2016,2018-2020, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -63,6 +63,12 @@
uint64_t usage;
};
+struct GrallocProperties {
+ bool use_system_heap_for_sensors = true;
+ bool ubwc_disable = false;
+ bool ahardware_buffer_disable = false;
+};
+
template <class Type1, class Type2>
inline Type1 ALIGN(Type1 x, Type2 align) {
return (Type1)((x + (Type1)align - 1) & ~((Type1)align - 1));
diff --git a/libqdutils/qd_utils.cpp b/libqdutils/qd_utils.cpp
index 5fff1cb..9e8cad7 100644
--- a/libqdutils/qd_utils.cpp
+++ b/libqdutils/qd_utils.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2018 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013, 2018, 2020, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -84,91 +84,6 @@
return -1;
}
-static int querySDEInfoDRM(HWQueryType type, int *value) {
- char property[PROPERTY_VALUE_MAX] = {0};
-
- // TODO(user): If future targets don't support WB UBWC, add separate
- // properties in target specific system.prop and have clients like WFD
- // directly rely on those.
- switch(type) {
- case HAS_UBWC:
- case HAS_WB_UBWC: // WFD stack still uses this
- *value = 1;
- property_get(DISABLE_UBWC_PROP, property, "0");
- if(!(strncmp(property, "1", PROPERTY_VALUE_MAX)) ||
- !(strncmp(property, "true", PROPERTY_VALUE_MAX))) {
- *value = 0;
- }
- break;
- default:
- ALOGE("Invalid query type %d", type);
- return -EINVAL;
- }
-
- return 0;
-}
-
-static int querySDEInfoFB(HWQueryType type, int *value) {
- FILE *fileptr = NULL;
- const char *featureName;
- char stringBuffer[MAX_STRING_LENGTH];
- uint32_t tokenCount = 0;
- const uint32_t maxCount = 10;
- char *tokens[maxCount] = { NULL };
-
- switch(type) {
- case HAS_UBWC:
- featureName = "ubwc";
- break;
- case HAS_WB_UBWC:
- featureName = "wb_ubwc";
- break;
- default:
- ALOGE("Invalid query type %d", type);
- return -EINVAL;
- }
-
- fileptr = fopen("/sys/devices/virtual/graphics/fb0/mdp/caps", "rb");
- if (!fileptr) {
- ALOGE("File '%s' not found", stringBuffer);
- return -EINVAL;
- }
-
- size_t len = MAX_STRING_LENGTH;
- ssize_t read;
- char *line = stringBuffer;
- while ((read = getline(&line, &len, fileptr)) != -1) {
- // parse the line and update information accordingly
- if (parseLine(line, tokens, maxCount, &tokenCount)) {
- continue;
- }
-
- if (strncmp(tokens[0], "features", strlen("features"))) {
- continue;
- }
-
- for (uint32_t i = 0; i < tokenCount; i++) {
- if (!strncmp(tokens[i], featureName, strlen(featureName))) {
- *value = 1;
- }
- }
- }
- fclose(fileptr);
-
- return 0;
-}
-
-int querySDEInfo(HWQueryType type, int *value) {
- if (!value) {
- return -EINVAL;
- }
-
- if (getDriverType() == DriverType::DRM) {
- return querySDEInfoDRM(type, value);
- }
-
- return querySDEInfoFB(type, value);
-}
bool isDPConnected() {
char connectPath[MAX_FRAME_BUFFER_NAME_SIZE];
diff --git a/libqdutils/qd_utils.h b/libqdutils/qd_utils.h
index d83f273..0b0816a 100644
--- a/libqdutils/qd_utils.h
+++ b/libqdutils/qd_utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013, 2017 The Linux Foundation. All rights reserved.
+ * Copyright (C) 2013, 2017, 2020 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -58,7 +58,6 @@
MAX_STRING_LENGTH = 1024,
};
-int querySDEInfo(HWQueryType type, int *value);
int getEdidRawData(char *buffer);
int getHDMINode(void);
bool isDPConnected();