x86/xen: fix pv boot
Subsystems (2)
Juergen Gross
maintainerPATCH v2 1/1 x86/xen: fix pv boot
Commit 9da3f2b7405440 ("x86/fault: BUG() when uaccess helpers fault on kernel addresses") introduced a regression for booting Xen PV guests.
Xen PV guests are using __put_user() and __get_user() for accessing the p2m map (physical to machine frame number map) as accesses might fail in case of not populated areas of the map.
With above commit using __put_user() and __get_user() for accessing kernel pages is no longer valid. So replace the Xen hack by adding appropriate p2m access functions using the default fixup handler.
--- arch/x86/include/asm/xen/page.h | 35 +++++++++++++++++++++++++++++++---- arch/x86/xen/p2m.c | 3 +-- 2 files changed, 32 insertions(+), 6 deletions(-)
arch/x86/include/asm/xen/page.h +31 -4
@@ -9,7 +9,7 @@#include <linux/mm.h> #include <linux/device.h> -#include <linux/uaccess.h> +#include <asm/extable.h> #include <asm/page.h> #include <asm/pgtable.h>
@@ -93,12 +93,39 @@ clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,*/ static inline int xen_safe_write_ulong (unsigned long *addr,unsigned long val) { -return __put_user (val, (unsigned long __user *)addr); +int ret =0 ; + + asmvolatile ("1: mov %[val], %[ptr]\n" +"2:\n" +".section .fixup, \"ax\"\n" +"3: sub $1, %[ret]\n" +" jmp 2b\n" +".previous\n" + _ASM_EXTABLE(1b, 3b) + : [ret] "+r" (ret), [ptr] "=m" (*addr) + : [val] "r" (val)); + +return ret; } -static inline int xen_safe_read_ulong (unsigned long *addr,unsigned long *val) +static inline int xen_safe_read_ulong (const unsigned long *addr, +unsigned long *val) { -return __get_user (*val, (unsigned long __user *)addr); +int ret =0 ; +unsigned long rval = ~0ul ; + + asmvolatile ("1: mov %[ptr], %[rval]\n" +"2:\n" +".section .fixup, \"ax\"\n" +"3: sub $1, %[ret]\n" +" jmp 2b\n" +".previous\n" + _ASM_EXTABLE(1b, 3b) + : [ret] "+r" (ret), [rval] "+r" (rval) + : [ptr] "m" (*addr)); + *val = rval; + +return ret; }#ifdef CONFIG_XEN_PV
arch/x86/xen/p2m.c +1 -2
@@ -656,8 +656,7 @@ bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn)/* * The interface requires atomic updates on p2m elements. -* xen_safe_write_ulong() is using __put_user which does an atomic -* store via asm(). +* xen_safe_write_ulong() is using an atomic store via asm(). */ if (likely (!xen_safe_write_ulong (xen_p2m_addr + pfn, mfn)))return true;
Signature · 1 line
2.16.4
Quoted 7 lines · Juergen Gross
Commit
9da3f2b7405440("x86/fault:BUG()when uaccess helpers fault on kernel addresses") introduced a regression for booting Xen PV guests.Xen PV guests are using
__put_user()and__get_user()for accessing the p2m map (physical to machine frame number map) as accesses might fail in case of not populated areas of the map.
Quoted 6 lines
With above commit using
__put_user()and__get_user()for accessing kernel pages is no longer valid. So replace the Xen hack by adding appropriate p2m access functions using the default fixup handler.Fixes 9da3f2b7405440 ("x86/fault: BUG() when uaccess helpers fault on kernel addresses")Signed-off-by Juergen Gross <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 lines · Juergen Gross
Commit
9da3f2b7405440("x86/fault:BUG()when uaccess helpers fault on kernel addresses") introduced a regression for booting Xen PV guests.Xen PV guests are using
__put_user()and__get_user()for accessing the p2m map (physical to machine frame number map) as accesses might fail in case of not populated areas of the map.
Quoted 6 lines
With above commit using
__put_user()and__get_user()for accessing kernel pages is no longer valid. So replace the Xen hack by adding appropriate p2m access functions using the default fixup handler.Fixes 9da3f2b7405440 ("x86/fault: BUG() when uaccess helpers fault on kernel addresses")Signed-off-by Juergen Gross <[email protected]>