2022-01-07 19:53:08 +00:00
|
|
|
#!/usr/bin/stap
|
|
|
|
#
|
|
|
|
# Copyright (C) 2022 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library. If not, see
|
|
|
|
# <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
# A script that captures the VMSA blob for the boot vCPU and
|
|
|
|
# first additional vCPU, when a KVM guest is booted with SEV-ES
|
|
|
|
#
|
2023-03-06 10:16:32 +00:00
|
|
|
# NOTE: This directly references specific structures and places in the
|
|
|
|
# kernel source code. It is expected that this example will need to be
|
2023-03-09 13:09:16 +00:00
|
|
|
# edited to match the kernel you intend to run it against.
|
2023-03-06 10:16:32 +00:00
|
|
|
#
|
2022-01-07 19:53:08 +00:00
|
|
|
# The captured VMSA will be printed to the console in hex format,
|
|
|
|
# and can be converted to the required binary format by feeding
|
|
|
|
# it through
|
|
|
|
#
|
|
|
|
# perl -e 'while (<>) { print pack("C64", map { hex($_) } ( $_ =~ m/../g )); }' > vmsa.bin
|
|
|
|
#
|
|
|
|
|
|
|
|
probe begin {
|
|
|
|
printf("Running\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
function dump_vmsa(addr:long) {
|
|
|
|
printf("VMSA\n")
|
|
|
|
for (i = 0; i < 4096 ; i+= 64) {
|
|
|
|
printf("%.64M\n", addr + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# This line number will need to be updated for the specific kernel
|
2023-03-09 13:09:16 +00:00
|
|
|
# version that is being probed. The line that needs to be targeted
|
|
|
|
# is the one between the call to clflush_cache_range(...) and the
|
2022-01-07 19:53:08 +00:00
|
|
|
# call to sev_issue_cmd(kvm, SEV_CMD_LAUNCH_UPDATE...).
|
|
|
|
#
|
2023-03-06 10:17:42 +00:00
|
|
|
# Line 635 is correct for Linux v6.3
|
|
|
|
probe module("kvm_amd").statement("__sev_launch_update_vmsa@arch/x86/kvm/svm/sev.c:635") {
|
|
|
|
dump_vmsa($svm->sev_es->vmsa)
|
2022-01-07 19:53:08 +00:00
|
|
|
}
|