xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Razvan Cojocaru <rzvncj@gmail.com>
To: xen-devel@lists.xen.org
Subject: Re: hvm_emulate_one() usage
Date: Sat, 29 Dec 2012 01:29:37 +0200	[thread overview]
Message-ID: <50DE2B61.8050606@gmail.com> (raw)
In-Reply-To: <50DE1CE5.1000909@citrix.com>

Hello, thanks for the reply!

> Not that I can help you with your problem specifically, but
> set_current() here ...
> 
>>
>>      hvm_emulate_prepare(ctx, guest_cpu_user_regs());
>>      hvm_emulate_one(ctx);
>>
>>      set_current(current_vcpu);
> 
> and here are absolutely wrong and will cause bad things to happen. (As
> demonstrated by the crash below)

Right.

> "current" is used everywhere in the Xen code, so your call to
> hvm_emulate_prepare is using the real "current" vcpus registers, with
> information from the wrong "current" cpu, including cs and ss segment
> registers, which is then going to be interpreted incorrectly as they
> will being used in the wrong vcms/gdt.

I see, that's what I was trying to avoid with the set_current() call - I
had hoped that it would tell guest_cpu_user_regs() what vcpu to use.

That was my only hope, as in the context of p2m_mem_access_resume() I
don't have the "struct cpu_user_regs *regs" parameter that I have access
to in p2m_mem_access_check().

> Can you describe exactly what behaviour you are attempting to achieve
> with this?  It seems to me that you are wanting to step a paused HVM
> vcpu on by one instruction based off a hypercall from dom0 ?

That's basically it, yes. In the hypervisor, tell dom0 that a mem_event
happened (a write attempt happened on a rx page), and let dom0 decide if
the write should happen or not (without dom0 setting the page to rwx and
losing future events on that same page). If dom0 decides that the write
should go ahead, it should signal this with a special flag in the
response it puts in the mem_event ring buffer, and the hypervisor should
then step the paused vcpu by one instruction (the write instruction).

This does work if I step in p2m_mem_access_check() (where I have access
to the "regs" parameter), before putting the mem_event request in the
ring buffer (and without any set_current() funny business), but that's
not acceptable behaviour because then dom0 gets notified _after_ the
write, and it's important for the notification to occur before the write
(so that dom0 could stop the write from happening if it needs to).

Thanks,
Razvan Cojocaru

  reply	other threads:[~2012-12-28 23:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-28 14:34 hvm_emulate_one() usage Razvan Cojocaru
2012-12-28 22:27 ` Andrew Cooper
2012-12-28 23:29   ` Razvan Cojocaru [this message]
2013-01-10 13:16 ` Tim Deegan
2013-01-10 14:10   ` Razvan Cojocaru
2013-01-10 14:23     ` Tim Deegan
2013-01-10 14:31       ` Razvan Cojocaru
2013-01-10 14:58         ` Tim Deegan

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=50DE2B61.8050606@gmail.com \
    --to=rzvncj@gmail.com \
    --cc=xen-devel@lists.xen.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).