All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: George.Dunlap@eu.citrix.com, xen-devel@lists.xenproject.org,
	kevin.tian@intel.com, jun.nakajima@intel.com
Subject: Re: [PATCH 5/6] x86/HVM: prefill cache with PDPTEs when possible
Date: Thu, 19 Jul 2018 19:47:24 +0100	[thread overview]
Message-ID: <95a0aace-ae9b-6595-978c-05a1de712f6c@citrix.com> (raw)
In-Reply-To: <5B50DA850200007800137618@prv1-mh.provo.novell.com>

On 19/07/18 19:37, Jan Beulich wrote:
>>>> Andrew Cooper <andrew.cooper3@citrix.com> 07/19/18 1:55 PM >>>
>> On 19/07/18 12:47, Jan Beulich wrote:
>>>>>> On 19.07.18 at 13:15, <andrew.cooper3@citrix.com> wrote:
>>>> On 19/07/18 11:50, Jan Beulich wrote:
>>>>> Since strictly speaking it is incorrect for guest_walk_tables() to read
>>>>> L3 entries during PAE page walks, try to overcome this where possible by
>>>>> pre-loading the values from hardware into the cache. Sadly the
>>>>> information is available in the EPT case only. On the positive side for
>>>>> NPT the spec spells out that L3 entries are actually read on walks, so
>>>>> us reading them is consistent with hardware behavior in that case.
>>>>>
>>>>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>>>> I'm afraid that this isn't architecturally correct.  It means that an
>>>> emulated memory access will read the PDPTE register values, rather than
>>>> what is actually in RAM.
>>> I'm afraid I don't understand: A CR3 load loads the PDPTEs into
>>> registers, and walks use those registers, not memory. That's the very
>>> difference between PAE and all other walks.
>> Patch 3 causes memory reads to come from the cache.
>>
>> This patch feeds the PDPTE registers into the cache, which breaks the
>> architectural correctness of patch 3, because the PDPTE registers may
>> legitimately be stale WRT the content in memory.
> Exactly. And I want to use the register contents in that case. Hence the filling
> of the cache here from the register values.

But using the register values is wrong here.

>
>
>> The pagewalk reading of top_map doesn't require that top_map points into
>> guest space.  If you read the PDPTE registers onto the stack, and pass a
>> pointer to the stack into the pagewalk in the 3-level case, then you fix
>> the issue described here without breaking patch 3.
> I'm afraid I still don't understand: Why "onto the stack"? And anyway - are
> you trying to tell me this odd is how actual hardware behaves?

Consider the following scenario:

; %eax points at some valid PDPTEs

mov %eax, %cr3 ; Copies 32 bytes into the hidden registers.
mov $0xdead, 8(%eax) ; Clobbers PDPTE[1].  Hardware register still intact.
FEP mov 8(%eax), %ebx ; Reads the memory behind the clobbered PDPTE[1]

When emulating the 3rd instruction, you actually need to read memory,
not the cached PDPTEs, because the value can be different.  Therefore,
you must not put the PDPTEs into the cache in the first place, because
it will cause erroneous behaviour.

My point with the top_map pointer is that you can arrange for it to
point to the real PDPTEs (pulled out of the VMCS) rather than reading
the real guest RAM at the physical address pointed to by %cr3.

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-07-19 18:47 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
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 [this message]
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=95a0aace-ae9b-6595-978c-05a1de712f6c@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.