All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrei LUTAS <vlutas@bitdefender.com>
To: Razvan Cojocaru <rcojocaru@bitdefender.com>,
	Tamas Lengyel <tamas.lengyel@zentific.com>
Cc: kevin.tian@intel.com, Ian Campbell <Ian.Campbell@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	eddie.dong@intel.com,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>,
	Jan Beulich <JBeulich@suse.com>,
	Andres Lagar-Cavilla <andres@lagarcavilla.org>,
	jun.nakajima@intel.com, Andrew Cooper <andrew.cooper3@citrix.com>
Subject: Re: [PATCH RFC V3 4/5] xen, libxc: Request page fault injection via libxc
Date: Wed, 23 Jul 2014 23:17:56 +0300	[thread overview]
Message-ID: <53D01874.80109@bitdefender.com> (raw)
In-Reply-To: <53CFD108.5020107@bitdefender.com>

Hello, everybody!

The logic with the #PF injection goes like this:
- The memory introspection engine wants to inspect (for whatever reason) a
   virtual page X insidevirtual address space Y(inside user-mode, although
   with proper knowledge about the guest kernel,one can also inject #PF 
inside
   kernel-mode on Windows - proper IRQL, working set trim inactive, etc.)
- The memory introspection engine will write-protect (via EPT) the Page 
Table
   Entries responsible for thetranslation of X to the Guest Physical 
Address Z
- The memory introspection engine requests the #PF injection
- The memory introspection engine patiently waits until the PTE 
corresponding
   tothe virtualpage Xis written - this means that the page has been 
swapped
   in, either due to our synthetic #PF, orbecause the guest OS accessed it
- We now need to analyse the faulting instruction in order to extract the
   written value, which containsthe address of the guest-physical page
   containing the datawe want to analyse - W - what X will translate to 
after
   the swap-in operation will be complete; we basically need to map W,
   without doing a new translation for X. No pause of the entire domain is
   normally needed for this.

Hopefully this covers in more detail the actual use-case of the #PF 
injection
and how it interacts with the introspection engine.

Thanks!
Andrei

On 7/23/2014 6:13 PM, Razvan Cojocaru wrote:
> On 07/23/2014 05:27 PM, Tamas Lengyel wrote:
>>      > wrapped into an unlikely(). But isn't this a bit of an overkill at
>>      every
>>      > VMENTER for every domain? Surely there are less invasive mechanisms to
>>      > trigger a VMEXIT when you know your VM will be in a state where
>>      you can
>>      > inject your page fault, without incurring an overhead for every
>>      domain.
>>
>>      It's not much of an overhead, basically if
>>      d->arch.hvm_domain.fault_info.virtual_address == 0 (which is almost
>>      always the case), nothing happens.
>>
>>
>> Since the majority of the domains will never use it, even a tiny
>> overhead adds up, especially over time. It would be a lot cleaner to
>> trap the execution of the VM at the moment when it is safe to inject the
>> page fault instead. For example you could just mark the process' code
>> pages non-executable in the EPT, catch the violations, and if the
>> conditions are met inject your pagefault.
> Ufortunately it's more complicated than that. Our application wants to
> be able to inject page faults at process initialization time, for PEB,
> etc., where we're not necessarily talking about a process executing code.
>
>>      > Also, it might make sense to perform some sanity checks on the
>>      vaddr and
>>      > address space before injection (ie. is the page really swapped out).
>>      > There is no guarantee that the page is still swapped out, even if you
>>      > checked before issuing xc_domain_set_pagefault_info, unless the domain
>>      > had been paused for both checking and setting.
>>
>>      As said above, the particular VCPU is in our case paused and waiting for
>>      a mem_event reply. The assumption is that other clients will work under
>>      similar circumstances, however it's always a good idea to check
>>      everything that can be checked.
>>
>>
>> I don't think having just the VCPU paused is enough, another still
>> active VCPU might still swap the page back, so you would really need to
>> have the entire VM paused for this to be safe. Furthermore, if there are
>> any limitations/assumptions like this about the intended use of the
>> function, describing them in a comment in xenctrl.h would be appropriate.
> A typical use case for this is:
>
> 1. the application figures out that it needs a swapped out page;
> 2. the application tries to bring it in (via the code in this patch);
> 3. the application maps the page.
>
> Now, if the application fails step 3, it might go back to step 2 until
> it succeeds, or it might give up after some retries. If, however, it
> succeeds, the mapped page should be safe to use until unmapped via libxc.
>
> I would add that in practice this problem never occured with any of the
> HVM Windows guests we've used for testing. The OS doesn't seem likely to
> immediately swap out a page that's just been brought in.
>
> If this is a concern, maybe I could simply add a comment in xenctrl.h
> that would say that the new function is only to be used while the domain
> is paused. I seem to recall having seen such comments there for other
> libxc functions.
>
>
> Thanks,
> Razvan Cojocaru
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
>

  reply	other threads:[~2014-07-23 20:17 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-23 12:34 [PATCH RFC V3 1/5] xen: Emulate with no writes Razvan Cojocaru
2014-07-23 12:34 ` [PATCH RFC V3 2/5] xen: Optimize introspection access to guest state Razvan Cojocaru
2014-07-24 15:07   ` Jan Beulich
2014-07-23 12:34 ` [PATCH RFC V3 3/5] xen: Force-enable relevant MSR events; optimize the number of sent MSR events Razvan Cojocaru
2014-07-24 15:14   ` Jan Beulich
2014-07-24 15:56     ` Razvan Cojocaru
2014-07-23 12:34 ` [PATCH RFC V3 4/5] xen, libxc: Request page fault injection via libxc Razvan Cojocaru
2014-07-23 13:40   ` Tamas Lengyel
2014-07-23 14:08     ` Razvan Cojocaru
2014-07-23 14:27       ` Tamas Lengyel
2014-07-23 15:13         ` Razvan Cojocaru
2014-07-23 20:17           ` Andrei LUTAS [this message]
2014-07-24 12:38             ` Ian Jackson
2014-07-24 12:41               ` Andrew Cooper
2014-07-24 12:44                 ` Razvan Cojocaru
2014-07-24 12:33   ` Ian Jackson
2014-07-24 15:27   ` Jan Beulich
2014-07-24 16:18     ` Razvan Cojocaru
2014-07-25  7:50       ` Jan Beulich
2014-07-23 12:34 ` [PATCH RFC V3 5/5] xen: Handle resumed instruction based on previous mem_event reply Razvan Cojocaru
2014-07-24 15:42   ` Jan Beulich
2014-07-24 16:29     ` Razvan Cojocaru
2014-07-25  7:52       ` Jan Beulich
2014-07-24 11:20 ` [PATCH RFC V3 1/5] xen: Emulate with no writes Tim Deegan
2014-07-24 11:40   ` Razvan Cojocaru
2014-07-25 13:52   ` Razvan Cojocaru
2014-07-25 14:07     ` Jan Beulich
2014-07-24 12:32 ` Ian Jackson
2014-07-24 12:36   ` Razvan Cojocaru
2014-07-24 12:37     ` Razvan Cojocaru
2014-07-24 17:25     ` Tian, Kevin

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=53D01874.80109@bitdefender.com \
    --to=vlutas@bitdefender.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=JBeulich@suse.com \
    --cc=andres@lagarcavilla.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=eddie.dong@intel.com \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=rcojocaru@bitdefender.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=tamas.lengyel@zentific.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 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.