Skip to content

Commit 1457d8c

Browse files
committed
x86/xen: fix pv boot
Commit 9da3f2b ("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. Fixes: 9da3f2b ("x86/fault: BUG() when uaccess helpers fault on kernel addresses") Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com> Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent 6cc4a08 commit 1457d8c

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

arch/x86/include/asm/xen/page.h

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <linux/mm.h>
1010
#include <linux/device.h>
1111

12-
#include <linux/uaccess.h>
12+
#include <asm/extable.h>
1313
#include <asm/page.h>
1414
#include <asm/pgtable.h>
1515

@@ -93,12 +93,39 @@ clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
9393
*/
9494
static inline int xen_safe_write_ulong(unsigned long *addr, unsigned long val)
9595
{
96-
return __put_user(val, (unsigned long __user *)addr);
96+
int ret = 0;
97+
98+
asm volatile("1: mov %[val], %[ptr]\n"
99+
"2:\n"
100+
".section .fixup, \"ax\"\n"
101+
"3: sub $1, %[ret]\n"
102+
" jmp 2b\n"
103+
".previous\n"
104+
_ASM_EXTABLE(1b, 3b)
105+
: [ret] "+r" (ret), [ptr] "=m" (*addr)
106+
: [val] "r" (val));
107+
108+
return ret;
97109
}
98110

99-
static inline int xen_safe_read_ulong(unsigned long *addr, unsigned long *val)
111+
static inline int xen_safe_read_ulong(const unsigned long *addr,
112+
unsigned long *val)
100113
{
101-
return __get_user(*val, (unsigned long __user *)addr);
114+
int ret = 0;
115+
unsigned long rval = ~0ul;
116+
117+
asm volatile("1: mov %[ptr], %[rval]\n"
118+
"2:\n"
119+
".section .fixup, \"ax\"\n"
120+
"3: sub $1, %[ret]\n"
121+
" jmp 2b\n"
122+
".previous\n"
123+
_ASM_EXTABLE(1b, 3b)
124+
: [ret] "+r" (ret), [rval] "+r" (rval)
125+
: [ptr] "m" (*addr));
126+
*val = rval;
127+
128+
return ret;
102129
}
103130

104131
#ifdef CONFIG_XEN_PV

arch/x86/xen/p2m.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,7 @@ bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn)
656656

657657
/*
658658
* The interface requires atomic updates on p2m elements.
659-
* xen_safe_write_ulong() is using __put_user which does an atomic
660-
* store via asm().
659+
* xen_safe_write_ulong() is using an atomic store via asm().
661660
*/
662661
if (likely(!xen_safe_write_ulong(xen_p2m_addr + pfn, mfn)))
663662
return true;

0 commit comments

Comments
 (0)