From ffee6eff293002057c3f5c393abd9833b1a2ca8a Mon Sep 17 00:00:00 2001 From: Adam Shih Date: Mon, 13 Feb 2023 12:48:47 +0800 Subject: [PATCH 1/7] create led dump Bug: 240530709 Test: adb bugreport Change-Id: I115e8bcaac0dd6fd20b63dd2d117d968aaa227bc --- led/Android.bp | 18 ++++++++++++++++++ led/dump_led.cpp | 24 ++++++++++++++++++++++++ led/led.mk | 3 +++ led/sepolicy/dump_led.te | 9 +++++++++ led/sepolicy/file.te | 2 ++ led/sepolicy/file_contexts | 4 ++++ 6 files changed, 60 insertions(+) create mode 100644 led/Android.bp create mode 100644 led/dump_led.cpp create mode 100644 led/led.mk create mode 100644 led/sepolicy/dump_led.te create mode 100644 led/sepolicy/file.te create mode 100644 led/sepolicy/file_contexts diff --git a/led/Android.bp b/led/Android.bp new file mode 100644 index 0000000..6e15ac5 --- /dev/null +++ b/led/Android.bp @@ -0,0 +1,18 @@ +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +cc_binary { + name: "dump_led", + srcs: ["dump_led.cpp"], + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + ], + shared_libs: [ + "libdump", + ], + vendor: true, + relative_install_path: "dump", +} diff --git a/led/dump_led.cpp b/led/dump_led.cpp new file mode 100644 index 0000000..7ce4846 --- /dev/null +++ b/led/dump_led.cpp @@ -0,0 +1,24 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +int main() { + dumpFileContent("Green LED Brightness", "/sys/class/leds/green/brightness"); + dumpFileContent("Green LED Max Brightness", "/sys/class/leds/green/max_brightness"); + dumpFileContent("LED Calibration Data", "/mnt/vendor/persist/led/led_calibration_LUT.txt"); + return 0; +} diff --git a/led/led.mk b/led/led.mk new file mode 100644 index 0000000..81d0f33 --- /dev/null +++ b/led/led.mk @@ -0,0 +1,3 @@ +BOARD_VENDOR_SEPOLICY_DIRS += device/google/gs-common/led/sepolicy + +PRODUCT_PACKAGES_DEBUG += dump_led diff --git a/led/sepolicy/dump_led.te b/led/sepolicy/dump_led.te new file mode 100644 index 0000000..b1ba1ef --- /dev/null +++ b/led/sepolicy/dump_led.te @@ -0,0 +1,9 @@ +pixel_bugreport(dump_led) + +allow dump_led mnt_vendor_file:dir search; +allow dump_led persist_file:dir search; +allow dump_led persist_leds_file:dir search; +allow dump_led persist_leds_file:file r_file_perms; +allow dump_led sysfs_leds:dir search; +allow dump_led sysfs_leds:file r_file_perms; + diff --git a/led/sepolicy/file.te b/led/sepolicy/file.te new file mode 100644 index 0000000..7fda883 --- /dev/null +++ b/led/sepolicy/file.te @@ -0,0 +1,2 @@ +type persist_leds_file, file_type, vendor_persist_type; + diff --git a/led/sepolicy/file_contexts b/led/sepolicy/file_contexts new file mode 100644 index 0000000..1b006cf --- /dev/null +++ b/led/sepolicy/file_contexts @@ -0,0 +1,4 @@ +/vendor/bin/dump/dump_led u:object_r:dump_led_exec:s0 + +/mnt/vendor/persist/led(/.*)? u:object_r:persist_leds_file:s0 + From 02b8df5191557e7a3fb3a3286b853277c927e393 Mon Sep 17 00:00:00 2001 From: Darren Hsu Date: Mon, 13 Feb 2023 22:30:22 +0800 Subject: [PATCH 2/7] powerstats: include sleep duration for core down state Bug: 263276734 Test: dumpsys android.hardware.power.stats.IPowerStats/default Change-Id: Ia9c1ed8c7ca68d03e73da35674ac299d7cf22045 Signed-off-by: Darren Hsu --- .../CpupmStateResidencyDataProvider.cpp | 40 +++++++++++++++++-- .../include/CpupmStateResidencyDataProvider.h | 12 +++++- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/powerstats/CpupmStateResidencyDataProvider.cpp b/powerstats/CpupmStateResidencyDataProvider.cpp index c963f78..2adae54 100644 --- a/powerstats/CpupmStateResidencyDataProvider.cpp +++ b/powerstats/CpupmStateResidencyDataProvider.cpp @@ -34,8 +34,14 @@ namespace power { namespace stats { CpupmStateResidencyDataProvider::CpupmStateResidencyDataProvider( - const std::string &path, const Config &config) - : mPath(std::move(path)), mConfig(std::move(config)) {} + const std::string &path, + const Config &config, + const std::string &sleepPath, + const SleepConfig &sleepConfig) + : mPath(std::move(path)), + mConfig(std::move(config)), + mSleepPath(std::move(sleepPath)), + mSleepConfig(std::move(sleepConfig)) {} int32_t CpupmStateResidencyDataProvider::matchState(char const *line) { for (int32_t i = 0; i < mConfig.states.size(); i++) { @@ -78,6 +84,12 @@ bool CpupmStateResidencyDataProvider::getStateResidencies( return false; } + std::unique_ptr sleepFp(fopen(mSleepPath.c_str(), "r"), fclose); + if (!sleepFp) { + PLOG(ERROR) << __func__ << ":Failed to open file " << mSleepPath; + return false; + } + for (int32_t i = 0; i < mConfig.entities.size(); i++) { std::vector stateResidencies(mConfig.states.size()); for (int32_t j = 0; j < stateResidencies.size(); j++) { @@ -90,9 +102,29 @@ bool CpupmStateResidencyDataProvider::getStateResidencies( char *line = nullptr; int32_t temp, entityIndex, stateId = -1; - uint64_t duration, count; + uint64_t duration, count, sleepDurationMs = 0; auto it = residencies->end(); + int32_t sleepIndex = 0; + // Parse state for sleep duration + while (getline(&line, &len, sleepFp.get()) != -1) { + std::string trimedLine = Trim(std::string(line)); + if (StartsWith(trimedLine, mSleepConfig[sleepIndex])) { + if (sleepIndex < mSleepConfig.size() - 1) { + sleepIndex++; + continue; + } else { + std::vector parts = Split(trimedLine, " "); + if (parts.size() == 2) { + ParseUint(parts[1], &sleepDurationMs); + sleepDurationMs /= NS_TO_MS; + } + break; + } + } + } + + // Parse state for CPUPM entities while (getline(&line, &len, fp.get()) != -1) { temp = matchState(line); // Assign new id only when a new valid state is encountered. @@ -109,7 +141,7 @@ bool CpupmStateResidencyDataProvider::getStateResidencies( it = residencies->find(mConfig.entities[entityIndex].first); if (it != residencies->end()) { if (parseState(line, &duration, &count)) { - it->second[stateId].totalTimeInStateMs = duration / US_TO_MS; + it->second[stateId].totalTimeInStateMs = duration / US_TO_MS + sleepDurationMs; it->second[stateId].totalStateEntryCount = count; } else { LOG(ERROR) << "Failed to parse duration and count from [" << std::string(line) diff --git a/powerstats/include/CpupmStateResidencyDataProvider.h b/powerstats/include/CpupmStateResidencyDataProvider.h index c04e11e..be8ee46 100644 --- a/powerstats/include/CpupmStateResidencyDataProvider.h +++ b/powerstats/include/CpupmStateResidencyDataProvider.h @@ -34,10 +34,16 @@ class CpupmStateResidencyDataProvider : public PowerStats::IStateResidencyDataPr std::vector> states; }; + typedef std::vector SleepConfig; + /* * path - path to cpupm sysfs node. */ - CpupmStateResidencyDataProvider(const std::string &path, const Config &config); + CpupmStateResidencyDataProvider( + const std::string &path, + const Config &config, + const std::string &sleepPath, + const SleepConfig &sleepConfig); ~CpupmStateResidencyDataProvider() = default; /* @@ -58,9 +64,13 @@ class CpupmStateResidencyDataProvider : public PowerStats::IStateResidencyDataPr // A constant to represent the number of microseconds in one millisecond. const uint64_t US_TO_MS = 1000; + // A constant to represent the number of nanoseconds in one millisecond. + const uint64_t NS_TO_MS = 1000000; const std::string mPath; const Config mConfig; + const std::string mSleepPath; + const SleepConfig mSleepConfig; }; } // namespace stats From 4e59f9be6e0249d4288a58c33447bf73db2a7b62 Mon Sep 17 00:00:00 2001 From: Randall Huang Date: Mon, 13 Feb 2023 16:27:33 +0800 Subject: [PATCH 3/7] storage: fix vold selinux error Bug: 264483567 Test: boot to home Change-Id: I015cf889fb84d6029aa1eb492949553f3ab528a9 Signed-off-by: Randall Huang --- storage/sepolicy/vold.te | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 storage/sepolicy/vold.te diff --git a/storage/sepolicy/vold.te b/storage/sepolicy/vold.te new file mode 100644 index 0000000..1d743b5 --- /dev/null +++ b/storage/sepolicy/vold.te @@ -0,0 +1,4 @@ +allow vold sysfs_scsi_devices_0000:file rw_file_perms; + +dontaudit vold dumpstate:fifo_file rw_file_perms; +dontaudit vold dumpstate:fd use ; From e20414a2d6f7e1fe2df9bc98265c323d878aff78 Mon Sep 17 00:00:00 2001 From: Randall Huang Date: Mon, 13 Feb 2023 17:33:12 +0800 Subject: [PATCH 4/7] Storage: fix hal_health_storage_default selinux error Bug: 264490032 Test: atest VtsHalHealthStorageTargetTest Change-Id: I953e9425f890863d2cdd10aed1efbdc1e31845c9 Signed-off-by: Randall Huang --- storage/sepolicy/hal_health_storage_default.te | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 storage/sepolicy/hal_health_storage_default.te diff --git a/storage/sepolicy/hal_health_storage_default.te b/storage/sepolicy/hal_health_storage_default.te new file mode 100644 index 0000000..af6593a --- /dev/null +++ b/storage/sepolicy/hal_health_storage_default.te @@ -0,0 +1,3 @@ +# Access to /sys/devices/platform/*ufs/* +allow hal_health_storage_default sysfs_scsi_devices_0000:dir r_dir_perms; +allow hal_health_storage_default sysfs_scsi_devices_0000:file rw_file_perms; From 2349e899e76f3203b8aa4f860f945f432e67a5cd Mon Sep 17 00:00:00 2001 From: Adam Shih Date: Mon, 13 Feb 2023 14:35:40 +0800 Subject: [PATCH 5/7] create memory dump Bug: 240530709 Test: adb bugreport Change-Id: Icdd62b1ff1d7a80d089c795bcf2ec0baa81905a4 --- soc/Android.bp | 7 +++++++ soc/dump_memory.sh | 22 ++++++++++++++++++++++ soc/sepolicy/dump_memory.te | 8 ++++++++ soc/sepolicy/dumpstate.te | 2 ++ soc/sepolicy/file.te | 3 +++ soc/sepolicy/file_contexts | 4 +++- soc/sepolicy/genfs_contexts | 3 +++ soc/soc.mk | 2 ++ 8 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 soc/dump_memory.sh create mode 100644 soc/sepolicy/dump_memory.te create mode 100644 soc/sepolicy/dumpstate.te create mode 100644 soc/sepolicy/file.te diff --git a/soc/Android.bp b/soc/Android.bp index 9600855..57b8577 100644 --- a/soc/Android.bp +++ b/soc/Android.bp @@ -2,6 +2,13 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], } +sh_binary { + name: "dump_memory.sh", + src: "dump_memory.sh", + vendor: true, + sub_dir: "dump", +} + cc_binary { name: "dump_soc", srcs: ["dump_soc.cpp"], diff --git a/soc/dump_memory.sh b/soc/dump_memory.sh new file mode 100644 index 0000000..5f4bde7 --- /dev/null +++ b/soc/dump_memory.sh @@ -0,0 +1,22 @@ +#!/vendor/bin/sh +echo "------ ION HEAPS ------" +for d in $(ls -d /d/ion/*) +do + if [ -f $d ]; then + echo --- $d + cat $d + else + for f in $(ls $d) + do + echo --- $d/$f + cat $d/$f + done + fi +done + +echo "------ dmabuf info ------" +cat "/d/dma_buf/bufinfo" + +echo "------ Page Pinner - longterm pin ------" +cat "/sys/kernel/debug/page_pinner/buffer" + diff --git a/soc/sepolicy/dump_memory.te b/soc/sepolicy/dump_memory.te new file mode 100644 index 0000000..47f9f07 --- /dev/null +++ b/soc/sepolicy/dump_memory.te @@ -0,0 +1,8 @@ +pixel_bugreport(dump_memory) +allow dump_memory vendor_toolbox_exec:file execute_no_trans; +userdebug_or_eng(` + allow dump_memory vendor_dmabuf_debugfs:file r_file_perms; + allow dump_memory vendor_page_pinner_debugfs:dir r_dir_perms; + allow dump_memory vendor_page_pinner_debugfs:file r_file_perms; +') + diff --git a/soc/sepolicy/dumpstate.te b/soc/sepolicy/dumpstate.te new file mode 100644 index 0000000..1d23bb4 --- /dev/null +++ b/soc/sepolicy/dumpstate.te @@ -0,0 +1,2 @@ +dontaudit dumpstate vendor_dmabuf_debugfs:file r_file_perms; + diff --git a/soc/sepolicy/file.te b/soc/sepolicy/file.te new file mode 100644 index 0000000..553825a --- /dev/null +++ b/soc/sepolicy/file.te @@ -0,0 +1,3 @@ +type vendor_dmabuf_debugfs, fs_type, debugfs_type; +type vendor_page_pinner_debugfs, fs_type, debugfs_type; + diff --git a/soc/sepolicy/file_contexts b/soc/sepolicy/file_contexts index 81b1e68..23a91e5 100644 --- a/soc/sepolicy/file_contexts +++ b/soc/sepolicy/file_contexts @@ -1 +1,3 @@ -/vendor/bin/dump/dump_soc u:object_r:dump_soc_exec:s0 +/vendor/bin/dump/dump_soc u:object_r:dump_soc_exec:s0 +/vendor/bin/dump/dump_memory\.sh u:object_r:dump_memory_exec:s0 + diff --git a/soc/sepolicy/genfs_contexts b/soc/sepolicy/genfs_contexts index 07ae4b8..454ab6a 100644 --- a/soc/sepolicy/genfs_contexts +++ b/soc/sepolicy/genfs_contexts @@ -5,3 +5,6 @@ genfscon sysfs /devices/system/chip-id/product_id u:object_r:sysfs_chip_id: genfscon sysfs /devices/system/chip-id/revision u:object_r:sysfs_chip_id:s0 genfscon sysfs /devices/system/chip-id/raw_str u:object_r:sysfs_chip_id:s0 +genfscon debugfs /dma_buf/bufinfo u:object_r:vendor_dmabuf_debugfs:s0 +genfscon debugfs /page_pinner u:object_r:vendor_page_pinner_debugfs:s0 + diff --git a/soc/soc.mk b/soc/soc.mk index 75b134e..b9b6208 100644 --- a/soc/soc.mk +++ b/soc/soc.mk @@ -1,3 +1,5 @@ BOARD_VENDOR_SEPOLICY_DIRS += device/google/gs-common/soc/sepolicy PRODUCT_PACKAGES += dump_soc +PRODUCT_PACKAGES_DEBUG += dump_memory.sh + From e9c9e8f03aedd38bf705e197c67fdc2c99303168 Mon Sep 17 00:00:00 2001 From: Randall Huang Date: Tue, 14 Feb 2023 15:10:56 +0800 Subject: [PATCH 6/7] storage: fix dumpstate avc denials Bug: 261933169 Test: no avc denial when generating bugreport Change-Id: Icaa0749bd8ca6121774058fa459fef3ae1400e07 Signed-off-by: Randall Huang --- storage/dumpstate.te | 1 + 1 file changed, 1 insertion(+) create mode 100644 storage/dumpstate.te diff --git a/storage/dumpstate.te b/storage/dumpstate.te new file mode 100644 index 0000000..2c01193 --- /dev/null +++ b/storage/dumpstate.te @@ -0,0 +1 @@ +allow dumpstate sysfs_scsi_devices_0000:file r_file_perms; \ No newline at end of file From 0d862845c4462754ed3951bcac8ddb65f64d4f2a Mon Sep 17 00:00:00 2001 From: Randall Huang Date: Tue, 14 Feb 2023 16:25:54 +0800 Subject: [PATCH 7/7] Storage: fix init avc denials Bug: 262794360 Test: boot to home Change-Id: Ic99d1430f7d4a9a449598152f51327ac13d192f1 Signed-off-by: Randall Huang --- storage/sepolicy/init.te | 1 + 1 file changed, 1 insertion(+) create mode 100644 storage/sepolicy/init.te diff --git a/storage/sepolicy/init.te b/storage/sepolicy/init.te new file mode 100644 index 0000000..7070318 --- /dev/null +++ b/storage/sepolicy/init.te @@ -0,0 +1 @@ +allow init sysfs_scsi_devices_0000:file w_file_perms;