Skip to contentSkip to conversation

HVM guests are allowed to use the entire virtual address space for

PATCH In review Tim Deegan 3 participants 8 messages May 25, 2010 – Jul 26, 2010

lore
Share & tools
lore

Tim Deegan

author
#0 lore raw

PATCH 1/1 HVM guests are allowed to use the entire virtual address space for

whatever they want, without any Xen hole. __addr_ok() is therefore always true for such guests.

# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1274798621 -3600
# Node ID 0b3b2b31e962561390cac4896a4a70841990f0e6
# Parent fef1e7dc74e64cf25d817991dc2594579abf5bd0
HVM guests are allowed to use the entire virtual address space for whatever they want, without any Xen hole. __addr_ok() is therefore always true for such guests.

xen/arch/x86/usercopy.c +1 -0
diff -r fef1e7dc74e6 -r 0b3b2b31e962 xen/arch/x86/usercopy.c
@@ -7,6 +7,7 @@
  */
 
 #include <xen/config.h>
+#include <xen/sched.h>
 #include <xen/lib.h>
 #include <asm/uaccess.h>
 
xen/include/asm-x86/x86_32/uaccess.h +2 -1
diff -r fef1e7dc74e6 -r 0b3b2b31e962 xen/include/asm-x86/x86_32/uaccess.h
@@ -15,7 +15,8 @@
 		:"1" (addr),"g" ((int)(size)),"r" (HYPERVISOR_VIRT_START)); \
 	flag; })
 
-#define access_ok(addr,size) (likely(__range_not_ok(addr,size) == 0))
+#define access_ok(addr,size) \
+    (is_hvm_vcpu(current) || likely(__range_not_ok(addr,size) == 0))
 
 #define array_access_ok(addr,count,size) \
     (likely(count < (~0UL/size)) && access_ok(addr,count*size))
xen/include/asm-x86/x86_64/uaccess.h +8 -5
diff -r fef1e7dc74e6 -r 0b3b2b31e962 xen/include/asm-x86/x86_64/uaccess.h
@@ -14,13 +14,15 @@
 })
 
 /*
- * Valid if in +ve half of 48-bit address space, or above Xen-reserved area.
+ * Valid if in +ve half of 48-bit address space, or above Xen-reserved
+ * area or anywhere in HVM guests (which have no Xen-reserved area).
  * This is also valid for range checks (addr, addr+size). As long as the
  * start address is outside the Xen-reserved area then we will access a
  * non-canonical address (and thus fault) before ever reaching VIRT_START.
  */
-#define __addr_ok(addr) \
-    (((unsigned long)(addr) < (1UL<<48)) || \
+#define __addr_ok(addr)                                 \
+    (is_hvm_vcpu(current) ||                            \
+     ((unsigned long)(addr) < (1UL<<48)) ||             \
      ((unsigned long)(addr) >= HYPERVISOR_VIRT_END))
 
 #define access_ok(addr, size) \
@@ -32,8 +34,9 @@
 #define __compat_addr_ok(d, addr) \
     ((unsigned long)(addr) < HYPERVISOR_COMPAT_VIRT_START(d))
 
-#define __compat_access_ok(d, addr, size) \
-    __compat_addr_ok(d, (unsigned long)(addr) + ((size) ? (size) - 1 : 0))
+#define __compat_access_ok(d, addr, size)                               \
+    (is_hvm_vcpu(current) ||                                            \
+     __compat_addr_ok(d, (unsigned long)(addr) + ((size) ? (size) - 1 : 0)))
 
 #define compat_access_ok(addr, size) \
     __compat_access_ok(current->domain, addr, size)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

I think this is already handled correctly by guest_access.h, which is what really matters. Nowadays copy_{to,from}_user (but not __copy_{to,from}_user) are mainly for private usage only by the guest-access macros, and just a few other arch-dependent PV_specific bits of code. Of course the __ versions are still generally useful as 'copy but catch any fault' functions.

-- Keir

Quoted 6 lines · Tim Deegan

whatever they want, without any Xen hole. __addr_ok() is therefore always true for such guests.

#2 lore raw

Put another way, I'd rather ASSERT(!is_hvm_vcpu(current)) than further reinforce the current confusion around these macros by supporting an obsolete usage.

-- Keir

Quoted 23 lines · Keir Fraser

I think this is already handled correctly by guest_access.h, which is what really matters. Nowadays copy_{to,from}_user (but not __copy_{to,from}_user) are mainly for private usage only by the guest-access macros, and just a few other arch-dependent PV_specific bits of code. Of course the __ versions are still generally useful as 'copy but catch any fault' functions.

-- Keir

Quoted 6 lines · Tim Deegan

whatever they want, without any Xen hole. __addr_ok() is therefore always true for such guests.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#3 lore raw
In reply to Keir Fraser
Quoted 5 lines · Keir Fraser

I think this is already handled correctly by guest_access.h, which is what really matters. Nowadays copy_{to,from}_user (but not __copy_{to,from}_user) are mainly for private usage only by the guest-access macros, and just a few other arch-dependent PV_specific bits of code. Of course the __ versions are still generally useful as 'copy but catch any fault' functions.

OK, can I suggest the attached change instead? It brings the compat guest-handle macros in line with the normal ones.

There are a few more callers of access_ok() around but at first glance they seem all to be PV-only.

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, XenServer Engineering
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
xen/include/xen/compat.h +2 -1
diff -r 10ad9b50b4ca xen/include/xen/compat.h
@@ -90,8 +90,9 @@
  * Allows use of faster __copy_* functions.
  */
 #define compat_handle_okay(hnd, nr)                                  \
+    (paging_mode_external(current->domain) ||                        \
     compat_array_access_ok((void *)(full_ptr_t)(hnd).c, (nr),        \
-                           sizeof(**(hnd)._))
+                           sizeof(**(hnd)._)))
 
 #define __copy_to_compat_offset(hnd, off, ptr, nr) ({                \
     const typeof(*(ptr)) *_s = (ptr);                                \

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#4 lore raw
Quoted 9 lines · Tim Deegan
Quoted 5 lines · Keir Fraser

I think this is already handled correctly by guest_access.h, which is what really matters. Nowadays copy_{to,from}_user (but not __copy_{to,from}_user) are mainly for private usage only by the guest-access macros, and just a few other arch-dependent PV_specific bits of code. Of course the __ versions are still generally useful as 'copy but catch any fault' functions.

OK, can I suggest the attached change instead? It brings the compat guest-handle macros in line with the normal ones.

Yeah, that's a good bug fix.

Thanks,
K.

author
#6 lore raw
Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · Tim Deegan

whatever they want, without any Xen hole. __addr_ok() is therefore always true for such guests.

Sorry for picking up yet another old patch after two months. :)

Do you have a testcase for this or the other patch in the thread?

I'm afraid not - this was a very old patch that had been gathering dust at the bottom of the XenServer code base. Calling
e.g. GNTTABOP_setup_table from inside a HVM guest with the frame_list argument somewhere in the Xen virtual address space should trigger it, though.

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, XenServer Engineering
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#7 lore raw
Quoted 9 lines · Tim Deegan
Quoted 8 lines · Paolo Bonzini
Quoted 4 lines · Tim Deegan

whatever they want, without any Xen hole. __addr_ok() is therefore always true for such guests.

Sorry for picking up yet another old patch after two months. :)

Quoted 7 lines
Quoted 1 line

Do you have a testcase for this or the other patch in the thread?

I'm afraid not - this was a very old patch that had been gathering dust at the bottom of the XenServer code base. Calling
e.g. GNTTABOP_setup_table from inside a HVM guest with the frame_list argument somewhere in the Xen virtual address space should trigger it, though.

The patch never got applied (to xen-unstable) by the way. We agreed on xen-unstable:21456, which was a more targeted bug fix.

-- Keir

Quoted 3 lines

Cheers,

Tim.