All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Musa Ünal" <umusasadik@gmail.com>
To: kvm@vger.kernel.org
Subject: Trap and Emulate RDTSC Instructions
Date: Sat, 4 Dec 2021 17:09:12 +0300	[thread overview]
Message-ID: <CAMjwK+d_H2qYjMjdQo=0ouz87u1XS1Cv+daLRj9_jLe6_FOkQw@mail.gmail.com> (raw)

Hello all,
For an academic project we need to trap and emulate each RDTSC
instruction executed in a virtual machine. (Our main aim is to
calculate how many rdtsc instructions are executed in a virtual
machine.) Currently we can intercept each of them. But we have a
problem to give the correct tsc values (values are not stable). So we
don't want to mess up the rdtsc reads. We just need to count rdtscs.
Our current approach looks like this.

static int handle_rdtsc(struct kvm_vcpu *vcpu)
{
counter += 1;
vcpu->arch.regs[VCPU_REGS_RAX] = (rdtsc() - VM_EXIT_COS) & -1u;
vcpu->arch.regs[VCPU_REGS_RDX] = ((rdtsc() -  VM_EXIT_COST) >> 32) & -1u;
return skip_emulated_instruction(vcpu);

}

VM_EXIT_COST calculated by how many clock cycles are executed during
host to guest transition (for RDTSC exits only). Can KVM handle these
operations built-in or do you have any idea how we can achieve this?

Thanks a lot.

             reply	other threads:[~2021-12-04 14:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-04 14:09 Musa Ünal [this message]
2021-12-05  4:11 ` Trap and Emulate RDTSC Instructions Jim Mattson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMjwK+d_H2qYjMjdQo=0ouz87u1XS1Cv+daLRj9_jLe6_FOkQw@mail.gmail.com' \
    --to=umusasadik@gmail.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.