Skip to contentSkip to conversation

pm-graph v5.10 regression fix

PATCH In review Todd Brandt 2 participants 2 messages Mar 13, 2023 – Mar 14, 2023 PM-graph utility

lore
Share & tools
lore

Todd Brandt

author maintainer
#0 lore raw

PATCH v2 1/1 pm-graph v5.10 regression fix

A regression has occurred in the hid-sensor code where a device name string has not been initialized to 0, and ends up without a NULL char and its printed with %s. This includes random binary data in the device name, which makes its way into the ftrace output and ends up crashing sleepgraph because it expects the ftrace output to be ASCII only.

For example: "HID-SENSOR-INT-020b?.39.auto" ends up in ftrace instead of "HID-SENSOR-INT-020b.39.auto". It causes this crash in sleepgraph:

File "/usr/bin/sleepgraph", line 5579, in executeSuspend
for line in fp:
File "/usr/lib/python3.10/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 1568: invalid start byte

The issue is in 6.3-rc1 and is decribed in full here:
https://bugzilla.kernel.org/show_bug.cgi?id=217169

I've submitted a separate fix to have this issue repaired, but it has also exposed a larger bug in sleepgraph, since nothing should make sleepgraph crash. Sleepgraph needs to be able to handle biary data showing up in ftrace gracefully.

I've changed the ftrace processing code to treat it as potentially binary and to filter out binary data and leave just the ASCII.

---
 tools/power/pm-graph/sleepgraph.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/power/pm-graph/sleepgraph.py +2 -3
index 82c09cd25cc2..bf4ac24a1c7a 100755
@@ -5556,9 +5556,8 @@ def executeSuspend(quiet=False):
 		if not quiet:
 			pprint('CAPTURING TRACE')
 		op = sv.writeDatafileHeader(sv.ftracefile, testdata)
-		fp = open(tp+'trace', 'r')
-		for line in fp:
-			op.write(line)
+		fp = open(tp+'trace', 'rb')
+		op.write(ascii(fp.read()))
 		op.close()
 		sv.fsetVal('', 'trace')
 		sv.platforminfo(cmdafter)
Signature · 1 line
2.34.1
#1 lore raw
Quoted 21 lines · Todd Brandt

A regression has occurred in the hid-sensor code where a device name string has not been initialized to 0, and ends up without a NULL char and its printed with %s. This includes random binary data in the device name, which makes its way into the ftrace output and ends up crashing sleepgraph because it expects the ftrace output to be ASCII only.

For example: "HID-SENSOR-INT-020b?.39.auto" ends up in ftrace instead of "HID-SENSOR-INT-020b.39.auto". It causes this crash in sleepgraph:

File "/usr/bin/sleepgraph", line 5579, in executeSuspend
for line in fp:
File "/usr/lib/python3.10/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 1568: invalid start byte

The issue is in 6.3-rc1 and is decribed in full here:
https://bugzilla.kernel.org/show_bug.cgi?id=217169

Quoted 7 lines

I've submitted a separate fix to have this issue repaired, but it has also exposed a larger bug in sleepgraph, since nothing should make sleepgraph crash. Sleepgraph needs to be able to handle biary data showing up in ftrace gracefully.

I've changed the ftrace processing code to treat it as potentially binary and to filter out binary data and leave just the ASCII.

Thanks a lot for the detailed description of the problem, it helps quite a bit.

I've modified the subject and changelog somewhat and applied this as 6.3-rc material, thanks!

Quoted 22 lines
---
 tools/power/pm-graph/sleepgraph.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/power/pm-graph/sleepgraph.py +2 -4
index 82c09cd25cc2..bf4ac24a1c7a 100755
@@ -5556,9 +5556,8 @@ def executeSuspend(quiet=False):
                if not quiet:
                        pprint('CAPTURING TRACE')
                op = sv.writeDatafileHeader(sv.ftracefile, testdata)
-               fp = open(tp+'trace', 'r')
-               for line in fp:
-                       op.write(line)
+               fp = open(tp+'trace', 'rb')
+               op.write(ascii(fp.read()))
                op.close()
                sv.fsetVal('', 'trace')
                sv.platforminfo(cmdafter)
--