Hi,

for safety certification we need code coverage information from the
hypervisor. The first open tool/format of choice in this area is gcov.

The way gcov works is that you simply compile and link your code with
"--coverage". In the compile step gcc will automatically add
instrumentation for code coverage to all of your code and put the
related data somewhere in the data-section of your binary. While your
application runs it will happily record a profile of how many times
which basic block was executed.
When an application starts it will run constructors that call
__gcov_init to register themselfs on a list. When the application ends
all items on the list will be given to a function that creates files
containing the counter data. And this magic is in libgcov (part of the
compiler) which gets linked when you have --coverage in your linker
flags.

While all the instrumentation just works out of the box for the
hypervisor, extracting the counters and converting them to the gcda
file-format can't just work with libgcov. That is where we need to
implement something that will produce the files expected by the higher
level tools.

My current implementation does the following to get the data out of the
hypervisor and onto your disk in the required format:

The hypervisor image is made visible in sysfs after jailhouse is
disabled, now we can read the "used" data section after jailhouse ran.
(that is where the gcov data is)
If we left the hypervisor memory mapped ro in Linux we could even get
incremental gcov data at runtime (not implemented at the moment).
We could limit that to just the header and data section, but just
exporting the while thing is less confusing.

The hypervisor executes the gcov constructors created by the
compiler to create a linked list of gcov-related data structures. It
then leaves a pointer to this list in its header. And that is all gcov
related code that we need to include in the hypervisor.
I did play with extracting that information from the binary without
changing a single line of hypervisor code. That worked but is based on
heuristics and ended up looking different for every arch.

A Linux userspace tool mmaps the "dirty" hypervisor image and
translates the data structures from the hypervisor address space into
its own address space. It then uses libgcov to write the data
into .gcda-files.

I tried the same thing within the Linux kernel, and the .gcda-files
popped up in sysfs. But removing/overwriting them there requires a
kernel-patch. And the kernel needs to be recompiled to support gcov
itself.

For the now chosen way the root-cell kernel does not need to be touched
or reconfigured to eventually get gcov data out of jailhouse.

Except for safety certification gcov information can be be useful for
other cases as well. Please check it out and let me know what you think.
The last patch in the series has some "documentation", how to build to
final colorful html reports.

The series still has some TODOs and open ends but is ready for a first
review round. I have tested it on x86 and arm64, arm compiles and
hopefully works as well.

Henning

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to