[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 2/2] altp2m: Implement p2m_get_mem_access for altp2m views





On Thu, Jan 28, 2016 at 9:32 AM, Razvan Cojocaru <rcojocaru@xxxxxxxxxxxxxxx> wrote:
On 01/28/2016 05:58 PM, Lengyel, Tamas wrote:
>
>
> On Thu, Jan 28, 2016 at 8:20 AM, Razvan Cojocaru
> <rcojocaru@xxxxxxxxxxxxxxx <mailto:rcojocaru@xxxxxxxxxxxxxxx>> wrote:
>
>Â Â ÂOn 01/28/2016 05:12 PM, Lengyel, Tamas wrote:
>Â Â Â>
>Â Â Â> On Jan 28, 2016 8:02 AM, "Razvan Cojocaru" <rcojocaru@xxxxxxxxxxxxxxx <mailto:rcojocaru@xxxxxxxxxxxxxxx>
>Â Â Â> <mailto:rcojocaru@xxxxxxxxxxxxxxx <mailto:rcojocaru@xxxxxxxxxxxxxxx>>> wrote:
>Â Â Â>>
>Â Â Â>> On 01/28/2016 04:42 PM, Lengyel, Tamas wrote:
>Â Â Â>> >
>Â Â Â>> > On Jan 28, 2016 6:38 AM, "Jan Beulich" <JBeulich@xxxxxxxx <mailto:JBeulich@xxxxxxxx>
>Â Â Â> <mailto:JBeulich@xxxxxxxx <mailto:JBeulich@xxxxxxxx>>
>Â Â Â>> > <mailto:JBeulich@xxxxxxxx <mailto:JBeulich@xxxxxxxx>
>Â Â Â<mailto:JBeulich@xxxxxxxx <mailto:JBeulich@xxxxxxxx>>>> wrote:
>Â Â Â>> >>
>Â Â Â>> >> >>> On 27.01.16 at 21:06, <tlengyel@xxxxxxxxxxx <mailto:tlengyel@xxxxxxxxxxx>
>Â Â Â> <mailto:tlengyel@xxxxxxxxxxx <mailto:tlengyel@xxxxxxxxxxx>>
>Â Â Â>> > <mailto:tlengyel@xxxxxxxxxxx <mailto:tlengyel@xxxxxxxxxxx>
>Â Â Â<mailto:tlengyel@xxxxxxxxxxx <mailto:tlengyel@xxxxxxxxxxx>>>> wrote:
>Â Â Â>> >> > --- a/xen/arch/x86/mm/p2m.c
>Â Â Â>> >> > +++ b/xen/arch/x86/mm/p2m.c
>Â Â Â>> >> > @@ -1572,7 +1572,9 @@ void p2m_mem_access_emulate_check(struct
>Â Â Â> vcpu *v,
>Â Â Â>> >> >Â Â Â Â Â bool_t violation = 1;
>Â Â Â>> >> >Â Â Â Â Â const struct vm_event_mem_access *data =""> >Â Â Â&rsp->u.mem_access;
>Â Â Â>> >> >
>Â Â Â>> >> > -Â Â Â Â if ( p2m_get_mem_access(v->domain, _gfn(data->gfn),
>Â Â Â>> > &access) == 0 )
>Â Â Â>> >> > +Â Â Â Â if ( p2m_get_mem_access(v->domain, _gfn(data->gfn),
>Â Â Â>> >> > +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â altp2m_active(v->domain) ?
>Â Â Â>> > vcpu_altp2m(v).p2midx : 0,
>Â Â Â>> >> > +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &access) == 0 )
>Â Â Â>> >>
>Â Â Â>> >> This looks to be a behavioral change beyond what title and
>Â Â Â>> >> description say, and it's not clear whether that's actually the
>Â Â Â>> >> behavior everyone wants.
>Â Â Â>> >
>Â Â Â>> > I'm fairly comfident its exactly the expected behavior when one
>Â Â Âuses
>Â Â Â>> > mem_access in altp2m tables and emulation. Right now because
>Â Â Âthe lack of
>Â Â Â>> > this AFAIK emulation would not work correctly with altp2m. But
>Â Â ÂRazvan
>Â Â Â>> > probably can chime in as he uses this path actively.
>Â Â Â>>
>Â Â Â>> I've done an experiment to see how much slower using altp2m would
>Â Â Âbe as
>Â Â Â>> compared to emulation - so I'm not a big user of the feature, but
>Â Â ÂI did
>Â Â Â>> find it cumbersome to have to work with two sets of APIs (one for
>Â Â Âwhat
>Â Â Â>> could arguably be called the default altp2m view, i.e. the regular
>Â Â Â>> xc_set_mem_access(), and one for altp2m, i.e.
>Â Â Â>> xc_altp2m_set_mem_access()). Furthermore, the APIs do not currently
>Â Â Â>> offer the same features (most notably, xc_altp2m_get_mem_access() is
>Â Â Â>> completely missing). I've mentioned this to Tamas while initially
>Â Â Âtrying
>Â Â Â>> to get it to work.
>Â Â Â>>
>Â Â Â>> Now, whether the behaviour I expect is what everyone expects is, of
>Â Â Â>> course, wide open to debate. But I think we can all agree that the
>Â Â Â>> altp2m interface can, and probably should, be improved.
>Â Â Â>>
>Â Â Â>
>Â Â Â> There is that, but also, what is the exact logic behind doing this
>Â Â Âcheck
>Â Â Â> before emulation? AFAIU emulation happens in response to a vm_event so
>Â Â Â> we should be fairly certain that this check succeeds as it just
>Â Â Âverifies
>Â Â Â> that indeed the permissions are restricted by mem_access in the
>Â Â Âp2m (and
>Â Â Â> with altp2m this should be the active one). But when is this check
>Â Â Â> normally expected to fail?
>
>Â Â ÂThat check is important, please do not remove it. A vm_event is sent
>Â Â Âinto userspace to our monitoring application, but the monitoring
>Â Â Âapplication can actually remove the page restrictions before replying,
>Â Â Âso in that case emulation is pointless - there will be no more page
>Â Â Âfaults for that instruction.
>
>
> I see, but then why would you reply with VM_EVENT_FLAG_EMULATE? You know
> you removed the permission before sending the reply, so this sounds like
> something specific to your application.

It's cheap insurance that things go right. If there's some issue with
page rights, or some external tool somehow does an xc_set_mem_access(),
things won't go wrong.

I can see this working for your application if you don't cache the mem_access permissions locally and you don't want to query for it before deciding to send the emulate flag in the response or not. Although, I think that would be the best way to go here.
Â
And they will go wrong if Xen thinks it should
emulate the next instruction and the next instruction is not the one
that has caused the original fault.

How could that happen? When the vCPU is resumed after the fault, isn't the same instruction guaranteed to be retried?
Â
I would think that benefits any
application.

It's just a bit of an obscure exception. From an API perspective I would rather have Xen do what I tell it to do - in this case emulate - rather then it doing something else silently behind the scenes that you really only find out about if you read the code.

Tamas
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.