kernel-shark: Add check for return of ksmodel_get_cpu_front()
PATCH 1/1 kernel-shark: Add check for return of ksmodel_get_cpu_front()
From: Steven Rostedt (VMware) <[email protected]>
When I loaded two trace.dat files (host and guest), but the mapping of which host thread is associated to which guest vCPU was missing from the file, it caused a SEGFAULT. That's because in fillTaskGraph(), the lamGetPidCPU() calls ksmodule_get_cpu_front() which returns a negative number and does not set index. But the next line checks data[index] where index is some random number, and the application crashes.
By checking the return of ksmodule_get_cpu_front(), and if it is negative do not reference data[index] and just let eFront be nullptr, the application shows no mapping, but at least it does not crash.
---
You can reproduce this with:
http://rostedt.org/private/trace-no-map.tar.bz2
src/KsPlotTools.cpp +1 -1
@@ -1280,7 +1280,7 @@ void Graph::fillTaskGraph(int sd, int pid) false, _collectionPtr, &index); - if (index >= 0) + if (cpuFront >= 0 && index >= 0) eFront = _histoPtr->data[index]; cpuBack = ksmodel_get_cpu_back(_histoPtr, bin,
Hi Steven,
Quoted 24 lines · Steven Rostedt
From: Steven Rostedt (VMware) <[email protected]>
When I loaded two trace.dat files (host and guest), but the mapping of which host thread is associated to which guest vCPU was missing from the file, it caused a SEGFAULT. That's because in
fillTaskGraph(), thelamGetPidCPU()callsksmodule_get_cpu_front()which returns a negative number and does not set index. But the next line checks data[index] where index is some random number, and the application crashes.By checking the return of
ksmodule_get_cpu_front(), and if it is negative do not reference data[index] and just let eFront be nullptr, the application shows no mapping, but at least it does not crash.Signed-off-by Steven Rostedt (VMware) <[email protected]>---
You can reproduce this with:http://rostedt.org/private/trace-no-map.tar.bz2
src/KsPlotTools.cpp +0
-0
src/KsPlotTools.cpp void Graph::fillTaskGraph(int sd, int pid) · line 1282
Quoted 3 lines
src/KsPlotTools.cpp +0
-0@@ -1280,7 +1280,7 @@ void Graph::fillTaskGraph(int sd, int pid) false, _collectionPtr, &index);
I wonder why this fails? Is it because "pid" is negative? The fix below is appropriate, however we should detect negative PIDs and abort plotting much earlier.
Thanks!
Yordan
Quoted 6 lines
src/KsPlotTools.cpp +1
-1- if (index >= 0) + if (cpuFront >= 0 && index >= 0) eFront = _histoPtr->data[index]; cpuBack = ksmodel_get_cpu_back(_histoPtr, bin,
Quoted 4 lines · On Tue, 11 May 2021 16:25:35 +0300 Yordan Karadzhov <[email protected]> wrote:
Quoted 4 lines
You can reproduce this with:
Quoted 12 lines
src/KsPlotTools.cpp void Graph::fillTaskGraph(int sd, int pid) · line 1282
Quoted 8 lines
src/KsPlotTools.cpp +0
-0@@ -1280,7 +1280,7 @@ void Graph::fillTaskGraph(int sd, int pid) false, _collectionPtr, &index);I wonder why this fails? Is it because "pid" is negative? The fix below is appropriate, however we should detect negative PIDs and abort plotting much earlier.
I believe the issue is that we failed to map which host task goes with which guest vCPUU, and just randomly picked one (or none).
I fixed trace-cmd to get the mappings when qemu is not found, and KernelShark works fine on that case. This bug only appears when it can't find the host thread that corresponds to the guest vCPU.
-- Steve
Quoted 6 lines · Steven Rostedt
Quoted 3 lines · On Tue, 11 May 2021 16:25:35 +0300 Yordan Karadzhov <[email protected]> wrote:
Quoted 3 lines
You can reproduce this with:
What should I do to make it SEGFAULT?
Y.
Quoted 23 lines
Quoted 13 lines
src/KsPlotTools.cpp void Graph::fillTaskGraph(int sd, int pid) · line 1282
Quoted 9 lines
src/KsPlotTools.cpp +0
-0@@ -1280,7 +1280,7 @@ void Graph::fillTaskGraph(int sd, int pid) false, _collectionPtr, &index);I wonder why this fails? Is it because "pid" is negative? The fix below is appropriate, however we should detect negative PIDs and abort plotting much earlier.
I believe the issue is that we failed to map which host task goes with which guest vCPUU, and just randomly picked one (or none).
I fixed trace-cmd to get the mappings when qemu is not found, and KernelShark works fine on that case. This bug only appears when it can't find the host thread that corresponds to the guest vCPU.
-- Steve
Quoted 9 lines · Steven Rostedt
From: Steven Rostedt (VMware) <[email protected]>
When I loaded two trace.dat files (host and guest), but the mapping of which host thread is associated to which guest vCPU was missing from the file, it caused a SEGFAULT. That's because in
fillTaskGraph(), thelamGetPidCPU()callsksmodule_get_cpu_front()which returns a negative number and does not set index. But the next line checks data[index] where index is some random number, and the application crashes.
Quoted 5 lines
By checking the return of
ksmodule_get_cpu_front(), and if it is negative do not reference data[index] and just let eFront be nullptr, the application shows no mapping, but at least it does not crash.Signed-off-by Steven Rostedt (VMware) <[email protected]>
I am applying this one.
Thanks Steven!
Y.
Quoted 19 lines
---
You can reproduce this with:http://rostedt.org/private/trace-no-map.tar.bz2
src/KsPlotTools.cpp +1
-1@@ -1280,7 +1280,7 @@ void Graph::fillTaskGraph(int sd, int pid) false, _collectionPtr, &index); - if (index >= 0) + if (cpuFront >= 0 && index >= 0) eFront = _histoPtr->data[index]; cpuBack = ksmodel_get_cpu_back(_histoPtr, bin,