On Fri, 7 May 2021 07:20:15 +0300 Tzvetomir Stoyanov <tz.stoyanov@xxxxxxxxx> wrote: > As Dario said, we can get the guest from the /proc/{kvm_exit task > ID}/status - the Tgid written there is the guest, the host task which > runs that guest. Maybe I'm not understanding the question. > Doesn't a VMExit always happen in the thread that runs the vCPU anyway? The problem is that we do not know what Tgid we are looking for. If you have 10 guests, you have 10 different Tgid's that are running those guests. How do you know which guest is attached to the cid you are looking for? There's currently no way to find that mapping. In fact, that's why I posted this patch: https://lore.kernel.org/kvm/20210505163855.32dad8e7@xxxxxxxxxxxxxxxxxx/ So you trace the kvm exit, and all 10 guests were active at that time, and you have 100 threads that called kvm exit. Now how do you find the pid of the task that owns the cid you are looking for, especially if each guest has their own cid? Oh, and the guest is run by a fork of qemu that has some other name! So you can not rely on looking at the thread's cmdline. If you look at the code I have, I use the wake ups to find the thread of the task that is woken up by the current task. my-task: start tracing kvm_exit and sched_waking connect to cid I want. my_task -> wakes up vhost-worker vhost-worker -> wakes up guest thread with cid I want guest-thread -> does kvm_exit stop tracing. Follow the wake ups to find that guest-thread pid Now look at /proc/guest-thread-pid/status and get the Tgid of the task in /debug/kvm. That's what this patch does. Again, how else can you map the cid to the guest thread? That's the missing link that following the wake ups give you. -- Steve