Skip to content

Commit

Permalink
kvm: Print KVM memslots related information.
Browse files Browse the repository at this point in the history
Orabug: 37357370
Signed-off-by: Siddhi Katage <[email protected]>
  • Loading branch information
SiddhiK29 committed Jan 17, 2025
1 parent 4bda6ff commit aaabe7f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
73 changes: 73 additions & 0 deletions drgn_tools/kvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,70 @@ def print_vcpu_list(prog: Program) -> None:
print_table(rows)


def print_memslot_info(prog: Program) -> None:
vm_list = for_each_vm(prog)
rows = [
[
"KVM",
"KVM_MEMSLOTS",
"KVM_MEMORY_SLOT",
"BASE_GFN",
"PAGES",
"ARCH",
"USER_ADDR",
"FLAGS",
]
]

for vm in vm_list:
for i in range(len(vm.memslots)):
kvm_memslots = hex(vm.memslots[i])
if has_member(vm.memslots[i], "memslots"):
for j in range(vm.memslots[i].used_slots.value_()):
mm = hex(vm.memslots[i].memslots[j].address_of_())
gfn = vm.memslots[i].memslots[j].base_gfn.value_()
pages = vm.memslots[i].memslots[j].npages.value_()
arch = hex(vm.memslots[i].memslots[j].arch.address_of_())
usr_addr = hex(
vm.memslots[i].memslots[j].userspace_addr.value_()
)
flags = vm.memslots[i].memslots[j].flags.value_()
rows.append(
[
hex(vm.value_()),
kvm_memslots,
mm,
gfn,
pages,
arch,
usr_addr,
flags,
]
)
else:
for vcpu in for_each_vcpu(vm):
mmslot = vcpu.last_used_slot
mm = hex(mmslot.address_of_())
gfn = mmslot.base_gfn.value_()
pages = mmslot.npages.value_()
arch = hex(mmslot.arch.address_of_())
usr_addr = hex(mmslot.userspace_addr.value_())
flags = mmslot.flags.value_()
rows.append(
[
hex(vm.value_()),
kvm_memslots,
mm,
gfn,
pages,
arch,
usr_addr,
flags,
]
)
print_table(rows)


class KvmUtil(CorelensModule):
"""
Show all the VM related info from KVM host side
Expand All @@ -193,6 +257,7 @@ class KvmUtil(CorelensModule):
[
"--vms",
"--vcpu",
"--mmslot",
]
]

Expand All @@ -209,10 +274,18 @@ def add_args(self, parser: argparse.ArgumentParser) -> None:
action="store_true",
help="show all vcpu info",
)
parser.add_argument(
"--mmslot",
dest="memslot",
action="store_true",
help="show all memslot info",
)

def run(self, prog: Program, args: argparse.Namespace) -> None:
if args.list_vm:
print_vm_list(prog)
if args.vcpu_list:
print_vcpu_list(prog)
if args.memslot:
print_memslot_info(prog)
return
1 change: 1 addition & 0 deletions tests/test_kvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
def test_kvmutil(prog):
kvm.print_vm_list(prog)
kvm.print_vcpu_list(prog)
kvm.print_memslot_info(prog)

0 comments on commit aaabe7f

Please sign in to comment.