From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>,
xen-devel <xen-devel@lists.xenproject.org>
Cc: George Dunlap <George.Dunlap@eu.citrix.com>,
Kevin Tian <kevin.tian@intel.com>,
Jun Nakajima <jun.nakajima@intel.com>
Subject: Re: [PATCH 4/6] VMX: correct PDPTE load checks
Date: Tue, 28 Aug 2018 14:12:13 +0100 [thread overview]
Message-ID: <5d4aa341-60eb-7170-72f6-a9845e1a4f81@citrix.com> (raw)
In-Reply-To: <5B506CAD02000078001D5D55@prv1-mh.provo.novell.com>
On 19/07/18 11:49, Jan Beulich wrote:
> Checking the low 5 bits of CR3 is not the job of vmx_load_pdptrs().
> Instead it should #GP upon bad PDPTE values, rather than causing a VM
> entry failure.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> --- a/xen/arch/x86/hvm/vmx/vmx.c
> +++ b/xen/arch/x86/hvm/vmx/vmx.c
> @@ -1361,20 +1361,18 @@ static void vmx_set_interrupt_shadow(str
> __vmwrite(GUEST_INTERRUPTIBILITY_INFO, intr_shadow);
> }
>
> -static void vmx_load_pdptrs(struct vcpu *v)
> +static bool vmx_load_pdptrs(struct vcpu *v)
> {
> unsigned long cr3 = v->arch.hvm_vcpu.guest_cr[3];
> - uint64_t *guest_pdptes;
> + uint64_t *guest_pdptes, valid_mask;
> struct page_info *page;
> p2m_type_t p2mt;
> char *p;
> + unsigned int i;
>
> /* EPT needs to load PDPTRS into VMCS for PAE. */
> if ( !hvm_pae_enabled(v) || (v->arch.hvm_vcpu.guest_efer & EFER_LMA) )
> - return;
> -
> - if ( (cr3 & 0x1fUL) && !hvm_pcid_enabled(v) )
> - goto crash;
> + return true;
>
> page = get_page_from_gfn(v->domain, cr3 >> PAGE_SHIFT, &p2mt, P2M_UNSHARE);
cr3 needs truncating to 32 bits before doing this. The upper bits of
cr3 can remain set after transitioning away from long mode, which will
cause this emulation to do the wrong thing.
> if ( !page )
> @@ -1385,34 +1383,47 @@ static void vmx_load_pdptrs(struct vcpu
> gdprintk(XENLOG_ERR,
> "Bad cr3 on load pdptrs gfn %lx type %d\n",
> cr3 >> PAGE_SHIFT, (int) p2mt);
> - goto crash;
> + domain_crash(v->domain);
> + return false;
> }
>
> p = __map_domain_page(page);
>
> - guest_pdptes = (uint64_t *)(p + (cr3 & ~PAGE_MASK));
> + guest_pdptes = (uint64_t *)(p + (cr3 & 0xfe0));
You can drop p, and guest_pdptes can lose its prefix.
>
> - /*
> - * We do not check the PDPTRs for validity. The CPU will do this during
> - * vm entry, and we can handle the failure there and crash the guest.
> - * The only thing we could do better here is #GP instead.
> - */
> + valid_mask = ((1ULL << v->domain->arch.cpuid->extd.maxphysaddr) - 1) &
> + (PAGE_MASK | _PAGE_AVAIL | _PAGE_PRESENT);
How did you come across this list? The only valid bits are Present, PWT
and PCD, while the upper nibble of control bits is documented as ignored
rather than reserved.
> + for ( i = 0; i < 4; ++i )
> + if ( (guest_pdptes[i] & _PAGE_PRESENT) &&
> + (guest_pdptes[i] & ~valid_mask) )
> + {
> + if ( v == current )
> + hvm_inject_hw_exception(TRAP_gp_fault, 0);
The function is void for the same reason why this isn't correct. We are
in the hvm_update_* path rather than the set_* path, which is beyond the
point of being able to unwind (and why I haven't yet got around to
fixing this function).
The only way I can see of fixing this is plumbing everything into a new
paging_set_cr3() callback, which can return X86EMUL_EXCEPTION and fail
the hvm_set_cr3() call.
~Andrew
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-08-28 13:12 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-19 10:39 [PATCH 0/6] x86/HVM: implement memory read caching Jan Beulich
2018-07-19 10:46 ` [PATCH 1/6] x86/mm: add optional cache to GLA->GFN translation Jan Beulich
2018-07-19 13:12 ` Paul Durrant
2018-07-19 10:47 ` [PATCH 2/6] x86/mm: use optional cache in guest_walk_tables() Jan Beulich
2018-07-19 13:22 ` Paul Durrant
2018-09-03 15:12 ` Jan Beulich
2018-07-19 10:48 ` [PATCH 3/6] x86/HVM: implement memory read caching Jan Beulich
2018-07-19 14:20 ` Paul Durrant
2018-07-24 10:28 ` Jan Beulich
2018-07-23 15:45 ` Tim Deegan
2018-07-19 10:49 ` [PATCH 4/6] VMX: correct PDPTE load checks Jan Beulich
2018-08-28 11:59 ` Ping: " Jan Beulich
2018-08-28 13:12 ` Andrew Cooper [this message]
2018-08-30 1:24 ` Tian, Kevin
2018-08-30 13:58 ` Jan Beulich
2018-07-19 10:50 ` [PATCH 5/6] x86/HVM: prefill cache with PDPTEs when possible Jan Beulich
2018-07-19 11:15 ` Andrew Cooper
2018-07-19 11:47 ` Jan Beulich
2018-07-19 11:55 ` Andrew Cooper
2018-07-19 18:37 ` Jan Beulich
2018-07-19 18:47 ` Andrew Cooper
2018-07-19 19:00 ` Jan Beulich
2018-07-19 19:07 ` Andrew Cooper
2018-07-24 7:04 ` Jan Beulich
2018-07-24 7:27 ` Juergen Gross
2018-07-24 7:44 ` Jan Beulich
2018-07-19 10:51 ` [PATCH 6/6] x86/shadow: a little bit of style cleanup Jan Beulich
2018-07-23 15:05 ` 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=5d4aa341-60eb-7170-72f6-a9845e1a4f81@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=jun.nakajima@intel.com \
--cc=kevin.tian@intel.com \
--cc=xen-devel@lists.xenproject.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.