public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@qumranet.com>
Cc: "Yang, Sheng" <sheng.yang@intel.com>, kvm-devel <kvm@vger.kernel.org>
Subject: Re: KVM: x86: accessors for guest registers
Date: Sun, 29 Jun 2008 16:35:26 -0300	[thread overview]
Message-ID: <20080629193526.GA8337@dmt.cnet> (raw)
In-Reply-To: <48678ABD.4070209@qumranet.com>

On Sun, Jun 29, 2008 at 04:14:37PM +0300, Avi Kivity wrote:
> Marcelo Tosatti wrote:
>> As suggested by Avi, introduce accessors to read/write guest registers.
>> This simplifies the ->cache_regs/->decache_regs interface, and improves
>> register caching which is important for VMX, where the cost of
>> vmcs_read/vmcs_write is significant.
>>   
>
> I made some changes, which I think simplify things:

Stripped down, looks great.

> - 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.

> - kvm_register_write() sets the avail bit to avoid read-after-write  
> corruption (like forwarding in a real cpu :)

Eek.

> - made rip a GPR in spite of my own objections, it does simplify things
> - init avail and dirty bitmasks on cpu reset
> - convert a couple mode GUEST_RIP references
> - remove decache_all_regs
> - inline decache_reg() into vmx/svm
>
> How does the attached look?

> -	.cache_regs = svm_cache_regs,
> -	.decache_regs = svm_decache_regs,
>  	.get_rflags = svm_get_rflags,
>  	.set_rflags = svm_set_rflags,

>  		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.


  reply	other threads:[~2008-06-29 19:35 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 [this message]
2008-06-30  5:08     ` Avi Kivity

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=20080629193526.GA8337@dmt.cnet \
    --to=mtosatti@redhat.com \
    --cc=avi@qumranet.com \
    --cc=kvm@vger.kernel.org \
    --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