Skip to contentSkip to conversation

ptwr_emulate adjustments

PATCH In review Jan Beulich 2 participants 3 messages Jan 16, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ptwr_emulate adjustments

- really only do the invalid PAE PTE fixup on write to the high part
- dump guest execution state when emulation fails
- use the passed in register pointer rather than re-calculating guest_cpu_user_regs()

xen/arch/x86/mm.c +9 -5
Index: 2007-01-08/xen/arch/x86/mm.c
===================================================================
@@ -3237,22 +3237,25 @@ static int ptwr_emulated_update(
     {
         if ( (CONFIG_PAGING_LEVELS == 3 || IS_COMPAT(d)) &&
              (bytes == 4) &&
+             (addr & 4) &&
              !do_cmpxchg &&
              (l1e_get_flags(nl1e) & _PAGE_PRESENT) )
         {
             /*
-             * If this is a half-write to a PAE PTE then we assume that the
-             * guest has simply got the two writes the wrong way round. We
-             * zap the PRESENT bit on the assumption the bottom half will be
-             * written immediately after we return to the guest.
+             * If this is an upper half write to a PAE PTE then we assume
+             * that the guest has simply got the two writes the wrong way
+             * round. We zap the PRESENT bit on the assumption the bottom
+             * half will be written immediately after we return to the guest.
              */
             MEM_LOG("ptwr_emulate: fixing up invalid PAE PTE %"PRIpte,
                     l1e_get_intpte(nl1e));
+            show_execution_state(ptwr_ctxt->ctxt.regs);
             l1e_remove_flags(nl1e, _PAGE_PRESENT);
         }
         else
         {
             MEM_LOG("ptwr_emulate: could not get_page_from_l1e()");
+            show_execution_state(ptwr_ctxt->ctxt.regs);
             return X86EMUL_UNHANDLEABLE;
         }
     }
@@ -3375,7 +3378,8 @@ int ptwr_do_page_fault(struct vcpu *v, u
          (page_get_owner(page) != d) )
         goto bail;
 
-    ptwr_ctxt.ctxt.regs = guest_cpu_user_regs();
+    ASSERT(regs = guest_cpu_user_regs());
+    ptwr_ctxt.ctxt.regs = regs;
     ptwr_ctxt.ctxt.addr_size = ptwr_ctxt.ctxt.sp_size =
         IS_COMPAT(d) ? 32 : BITS_PER_LONG;
     ptwr_ctxt.cr2 = addr;
#1 lore raw
Quoted 1 line · Jan Beulich

- really only do the invalid PAE PTE fixup on write to the high part

Okay. We could theoretically get failures the other way round too I should think but clearly the existing code doesn't handle that properly (since it'll lose the PAGE_PRESENT forever) so it can't be something we've seen in practise. This clarification and extra check makes sense.

Quoted 1 line

- dump guest execution state when emulation fails

We can't put anything more than XENLOG_G_WARNING on a path that a guest can exercise at will. One option is to make show_execution_state (and hence all underlying state-dump functions) take the dump log level as a parameter.

Quoted 2 lines

- use the passed in register pointer rather than re-calculating guest_cpu_user_regs()

The assertion is broken and anyway really a bit overkill imo. Using regs rather than guest_cpu_user_regs() makes sense.

-- Keir

Quoted 1 line
#2 lore raw
Quoted 5 lines
Quoted 1 line

- dump guest execution state when emulation fails

We can't put anything more than XENLOG_G_WARNING on a path that a guest can exercise at will. One option is to make show_execution_state (and hence all underlying state-dump functions) take the dump log level as a parameter.

Oh, understood. I'm not insisting on this part. It just helped me in debugging.

Quoted 5 lines
Quoted 2 lines

- use the passed in register pointer rather than re-calculating guest_cpu_user_regs()

The assertion is broken and anyway really a bit overkill imo. Using regs rather than guest_cpu_user_regs() makes sense.

While I don't understand why it's broken (I just added it to check in debug builds that the value now used matches the one previously used), but I'm fully with you to remove it if you agree that using the function parameter is okay.

Jan