From: Avi Kivity <avi@qumranet.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: "Yang, Sheng" <sheng.yang@intel.com>, kvm-devel <kvm@vger.kernel.org>
Subject: Re: KVM: x86: accessors for guest registers
Date: Mon, 30 Jun 2008 08:08:58 +0300 [thread overview]
Message-ID: <48686A6A.6070302@qumranet.com> (raw)
In-Reply-To: <20080629193526.GA8337@dmt.cnet>
Marcelo Tosatti wrote:
>
>> - svm always caches registers, and all registers are dirty, since
>> cache/decache is cheap
>>
>
> Accurate regs_dirty information is useful for converting the emulator,
> so that you can do something like:
>
> emul_register_write(ctxt, reg, val)
> {
> if (!__test_and_set_bit(reg, &ctxt->vcpu->regs_dirty))
> ctxt->original_regs[reg] = kvm_register_read(ctxt->vcpu, reg);
> ctxt->vcpu->regs[reg] = val;
> }
>
> Because restoring the original reg contents on failure is necessary.
> Otherwise you need to cache all regs on emulation entry. RIP is always
> read anyway, but RSP not so frequently.
>
> Well, might not be worth the complexity for saving just one vmcs_read().
> Or it can be changed later during conversion.
>
>
That doesn't work, because some of the registers may already be dirty
when the emulator is invoked (say, if we're emulating several
instructions back-to-back). I think the best way to change the emulator
is to let it have its own set of dirty/available bits.
>> if (io->in) {
>> r = pio_copy_data(vcpu);
>> if (r) {
>> - kvm_x86_ops->cache_regs(vcpu);
>> + kvm_x86_ops->cache_reg(vcpu, VCPU_REGS_RAX);
>> return r;
>> }
>>
>
> These two don't go well together. Apparently the intent of this
> ->cache_regs call on failure was to restore the original registers in
> case they were modified by pio_copy_data? But pio_copy_data does not
> write to any guest register (and even if it did, this ->cache_regs call
> assumes what registers are fetched from the guest's originals).
>
> kvm_x86_ops->cache_regs(vcpu);
>
> if (!io->string) {
> if (io->in)
> memcpy(&vcpu->arch.regs[VCPU_REGS_RAX], vcpu->arch.pio_data,
> io->size);
> } else {
> if (io->in) {
> r = pio_copy_data(vcpu);
> if (r) {
> kvm_x86_ops->cache_regs(vcpu);
> return r;
> }
> }
>
> Unless I'm mistaken you can just remove it.
>
>
Right.
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
prev parent reply other threads:[~2008-06-30 5:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-27 17:58 KVM: x86: accessors for guest registers Marcelo Tosatti
2008-06-29 13:14 ` Avi Kivity
2008-06-29 19:35 ` Marcelo Tosatti
2008-06-30 5:08 ` Avi Kivity [this message]
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=48686A6A.6070302@qumranet.com \
--to=avi@qumranet.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=sheng.yang@intel.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox