xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Kevin Tian <kevin.tian@intel.com>, Wei Liu <wei.liu2@citrix.com>,
	George Dunlap <george.dunlap@eu.citrix.com>,
	Tim Deegan <tim@xen.org>, Xen-devel <xen-devel@lists.xen.org>,
	Jun Nakajima <jun.nakajima@intel.com>
Subject: Re: [PATCH for-4.7] xen/nested_p2m: Don't walk EPT tables with a regular PT walker
Date: Fri, 13 May 2016 16:00:37 +0100	[thread overview]
Message-ID: <5735EC15.8080906@citrix.com> (raw)
In-Reply-To: <5735FD1C02000078000EB428@prv-mh.provo.novell.com>

On 13/05/16 15:13, Jan Beulich wrote:
>>>> On 13.05.16 at 15:33, <andrew.cooper3@citrix.com> wrote:
>> --- a/xen/arch/x86/mm/hap/nested_hap.c
>> +++ b/xen/arch/x86/mm/hap/nested_hap.c
>> @@ -141,7 +141,7 @@ nestedhap_fix_p2m(struct vcpu *v, struct p2m_domain *p2m,
>>   * walk is successful, the translated value is returned in
>>   * L1_gpa. The result value tells what to do next.
>>   */
>> -static int
>> +int
>>  nestedhap_walk_L1_p2m(struct vcpu *v, paddr_t L2_gpa, paddr_t *L1_gpa,
>>                        unsigned int *page_order, uint8_t *p2m_acc,
> The function becoming non-static widens the visibility of the bogus
> uint8_t here (should be p2m_access_t afaics). Granted this isn't an
> issue the patch introduces, but I would prefer this to be adjusted
> prior to dropping the static here...
>
>> --- a/xen/arch/x86/mm/p2m.c
>> +++ b/xen/arch/x86/mm/p2m.c
>> @@ -2081,20 +2081,29 @@ unsigned long paging_gva_to_gfn(struct vcpu *v,
>>  
>>      if ( is_hvm_vcpu(v) && paging_mode_hap(v->domain) && nestedhvm_is_n2(v) )
>>      {
>> -        unsigned long gfn;
>> +        unsigned long l2_gfn, l1_gfn;
>>          struct p2m_domain *p2m;
>>          const struct paging_mode *mode;
>> -        uint32_t pfec_21 = *pfec;
>>          uint64_t np2m_base = nhvm_vcpu_p2m_base(v);
>> +        uint8_t l1_p2ma;
> ... avoiding proliferation of the quirkiness.

Will do.

>
>> +        unsigned int l1_page_order;
>> +        int rv;
>>  
>>          /* translate l2 guest va into l2 guest gfn */
>>          p2m = p2m_get_nestedp2m(v, np2m_base);
>>          mode = paging_get_nestedmode(v);
>> -        gfn = mode->gva_to_gfn(v, p2m, va, pfec);
>> +        l2_gfn = mode->gva_to_gfn(v, p2m, va, pfec);
>> +
>> +        if ( l2_gfn == INVALID_GFN )
>> +            return INVALID_GFN;
>>  
>>          /* translate l2 guest gfn into l1 guest gfn */
>> -        return hostmode->p2m_ga_to_gfn(v, hostp2m, np2m_base,
>> -                                       gfn << PAGE_SHIFT, &pfec_21, NULL);
>> +        rv = nestedhap_walk_L1_p2m(v, l2_gfn, &l1_gfn, &l1_page_order, &l1_p2ma,
>> +                                   1,
>> +                                   !!(*pfec & PFEC_write_access),
>> +                                   !!(*pfec & PFEC_insn_fetch));
>> +
>> +        return rv == NESTEDHVM_PAGEFAULT_DONE ? l1_gfn : INVALID_GFN;
>>      }
> I'm really happy to see this getting cleaned up - I've stumbled across
> the apparent brokenness here more than once, without ever finding
> the time to help the situation. One question though: Is the return
> value here correct even for l1_page_order > 0?

Not completely sure.  This code is messy, and my current testing is "it
now doesn't crash where it used to crash before".

The specific path being tripped over was __hvm_copy() performing an
instruction fetch for emulation from the L2 guest.

Looking at the code, if your caller only cares about 4K mappings, you
will get the correct translation, due to the adjustment
nept_walk_tables() makes.

~Andrew

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

  reply	other threads:[~2016-05-13 15:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-13 13:33 [PATCH for-4.7] xen/nested_p2m: Don't walk EPT tables with a regular PT walker Andrew Cooper
2016-05-13 14:13 ` Jan Beulich
2016-05-13 15:00   ` Andrew Cooper [this message]
2016-05-13 15:19     ` Jan Beulich
2016-05-13 17:25       ` [PATCH v2 " Andrew Cooper
2016-05-17  6:06         ` Tian, Kevin
2016-05-18 13:36         ` George Dunlap
2016-05-18 13:50         ` Wei Liu
2016-05-13 15:24     ` [PATCH " Andrew Cooper
2016-05-13 15:31       ` Jan Beulich

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=5735EC15.8080906@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.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).