Skip to contentSkip to conversation

32-on-64 emulation

RFC PATCH In review Jan Beulich 1 participant 1 message Oct 4, 2006

lore
Share & tools
lore
#0 lore raw

RFC PATCH 8/17 32-on-64 emulation

This intentionally enhances the decoder of the privileged op emulation farther than explicitly required to get 32on64 to work - there were missing pieces already before.

xen/arch/x86/mm.c +26 -1
Index: 2006-10-04/xen/arch/x86/mm.c
===================================================================
@@ -1741,6 +1741,31 @@ int new_guest_cr3(unsigned long mfn)
     if ( hvm_guest(v) && !hvm_paging_enabled(v) )
         domain_crash_synchronous();
 
+#ifdef CONFIG_COMPAT
+    if ( IS_COMPAT(d) )
+    {
+        l4_pgentry_t l4e = l4e_from_pfn(mfn, _PAGE_PRESENT|_PAGE_RW|_PAGE_USER|_PAGE_ACCESSED|_PAGE_DIRTY);
+
+        if ( shadow_mode_refcounts(d) )
+        {
+            DPRINTK("CR3 update on shadow-refcounted domain!");//todo
+            return 0;
+        }
+
+        okay = mod_l4_entry(__va(pagetable_get_paddr(v->arch.guest_table)),
+                            l4e, mfn);
+        if ( unlikely(!okay) )
+        {
+            MEM_LOG("Error while installing new compat baseptr %lx", mfn);
+            return 0;
+        }
+
+        invalidate_shadow_ldt(v);
+        write_ptbase(v);
+
+        return 1;
+    }
+#endif
     if ( shadow_mode_refcounts(d) )
     {
         okay = get_page_from_pagenr(mfn, d);
@@ -3253,7 +3278,7 @@ int ptwr_do_page_fault(struct vcpu *v, u
 
     emul_ctxt.regs = guest_cpu_user_regs();
     emul_ctxt.cr2  = addr;
-    emul_ctxt.mode = X86EMUL_MODE_HOST;
+    emul_ctxt.mode = !IS_COMPAT(d) ? X86EMUL_MODE_HOST : X86EMUL_MODE_PROT32;
     if ( x86_emulate_memop(&emul_ctxt, &ptwr_emulate_ops) )
         goto bail;
 
xen/arch/x86/traps.c +234 -45

456 lines not on this page · raw message

xen/arch/x86/x86_64/mm.c +5 -1
Index: 2006-10-04/xen/arch/x86/x86_64/mm.c
===================================================================
@@ -352,7 +352,11 @@ int check_descriptor(const struct domain
 
     /* All code and data segments are okay. No base/limit checking. */
     if ( (b & _SEGMENT_S) )
-        goto good;
+    {
+        if ( !IS_COMPAT(dom) || !(b & _SEGMENT_L) )
+            goto good;
+        goto bad;
+    }
 
     /* Invalid type 0 is harmless. It is used for 2nd half of a call gate. */
     if ( (b & _SEGMENT_TYPE) == 0x000 )
xen/include/asm-x86/desc.h +7 -0
Index: 2006-10-04/xen/include/asm-x86/desc.h
===================================================================
@@ -113,12 +113,19 @@
 
 /* These are bitmasks for the high 32 bits of a descriptor table entry. */
 #define _SEGMENT_TYPE    (15<< 8)
+#define _SEGMENT_WR      ( 1<< 9) /* Writeable (data) or Readable (code)
+                                     segment */
 #define _SEGMENT_EC      ( 1<<10) /* Expand-down or Conforming segment */
 #define _SEGMENT_CODE    ( 1<<11) /* Code (vs data) segment for non-system
                                      segments */
 #define _SEGMENT_S       ( 1<<12) /* System descriptor (yes iff S==0) */
 #define _SEGMENT_DPL     ( 3<<13) /* Descriptor Privilege Level */
 #define _SEGMENT_P       ( 1<<15) /* Segment Present */
+#ifdef __x86_64
+#define _SEGMENT_L       ( 1<<21) /* 64-bit segment */
+#else
+#define _SEGMENT_L       0
+#endif
 #define _SEGMENT_DB      ( 1<<22) /* 16- or 32-bit segment */
 #define _SEGMENT_G       ( 1<<23) /* Granularity */
 
xen/include/asm-x86/mm.h +5 -0
Index: 2006-10-04/xen/include/asm-x86/mm.h
===================================================================
@@ -344,6 +344,11 @@ static inline unsigned long get_mfn_from
     return INVALID_MFN;
 }
 
+#ifdef CONFIG_COMPAT
+#define compat_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
+#define compat_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
+#endif
+
 #ifdef MEMORY_GUARD
 void memguard_init(void);
 void memguard_guard_range(void *p, unsigned long l);
xen/include/asm-x86/x86_32/uaccess.h +1 -1
Index: 2006-10-04/xen/include/asm-x86/x86_32/uaccess.h
===================================================================
@@ -83,7 +83,7 @@ do {									\
 	case 2: __get_user_asm(x,ptr,retval,"w","w","=r",errret);break;	\
 	case 4: __get_user_asm(x,ptr,retval,"l","","=r",errret);break;	\
 	case 8: __get_user_u64(x,ptr,retval,errret);break;		\
-	default: (x) = __get_user_bad();				\
+	default: __get_user_bad();					\
 	}								\
 } while (0)
 
xen/include/asm-x86/x86_64/uaccess.h +1 -1
Index: 2006-10-04/xen/include/asm-x86/x86_64/uaccess.h
===================================================================
@@ -48,7 +48,7 @@ do {									\
 	case 2: __get_user_asm(x,ptr,retval,"w","w","=r",errret);break;	\
 	case 4: __get_user_asm(x,ptr,retval,"l","k","=r",errret);break;	\
 	case 8: __get_user_asm(x,ptr,retval,"q","","=r",errret); break;	\
-	default: (x) = __get_user_bad();				\
+	default: __get_user_bad();					\
 	}								\
 } while (0)