diff mbox

[v2,01/19] x86/shadow: Fix #PFs from emulated writes crossing a page boundary

Message ID 1480331616-6165-2-git-send-email-andrew.cooper3@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Cooper Nov. 28, 2016, 11:13 a.m. UTC
When translating the second frame of a write crossing a page boundary, mask
the linear address down to the page boundary.

This causes the correct %cr2 being reported to the guest in the case that the
second frame suffers a pagefault during translation.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Tim Deegan <tim@xen.org>

v2:
 * New
---
 xen/arch/x86/mm/shadow/common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Tim Deegan Nov. 28, 2016, 11:55 a.m. UTC | #1
At 11:13 +0000 on 28 Nov (1480331598), Andrew Cooper wrote:
> When translating the second frame of a write crossing a page boundary, mask
> the linear address down to the page boundary.
> 
> This causes the correct %cr2 being reported to the guest in the case that the
> second frame suffers a pagefault during translation.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Acked-by: Tim Deegan <tim@xen.org>
Jan Beulich Nov. 29, 2016, 3:24 p.m. UTC | #2
>>> On 28.11.16 at 12:13, <andrew.cooper3@citrix.com> wrote:
> When translating the second frame of a write crossing a page boundary, mask
> the linear address down to the page boundary.
> 
> This causes the correct %cr2 being reported to the guest in the case that the
> second frame suffers a pagefault during translation.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>
diff mbox

Patch

diff --git a/xen/arch/x86/mm/shadow/common.c b/xen/arch/x86/mm/shadow/common.c
index ced2313..7e5b8b0 100644
--- a/xen/arch/x86/mm/shadow/common.c
+++ b/xen/arch/x86/mm/shadow/common.c
@@ -1808,7 +1808,8 @@  void *sh_emulate_map_dest(struct vcpu *v, unsigned long vaddr,
     else
     {
         /* This write crosses a page boundary. Translate the second page. */
-        sh_ctxt->mfn[1] = emulate_gva_to_mfn(v, vaddr + bytes - 1, sh_ctxt);
+        sh_ctxt->mfn[1] = emulate_gva_to_mfn(
+            v, (vaddr + bytes - 1) & PAGE_MASK, sh_ctxt);
         if ( !mfn_valid(sh_ctxt->mfn[1]) )
             return ((mfn_x(sh_ctxt->mfn[1]) == BAD_GVA_TO_GFN) ?
                     MAPPING_EXCEPTION :