xen: arm: do not panic when failing to translate a guest address
PATCH 1/1 xen: arm: do not panic when failing to translate a guest address
The gva_to_{par,ipa} functions currently panic if the guest address cannot be translated. Often the input comes from the guest so panicing the host is a bit harsh!
Change the API of those functions to allow them to return a failure and plumb it through where it is used.
--- xen/arch/arm/guestcopy.c | 30 +++++++++++++++++++---- xen/arch/arm/kernel.c | 14 +++++++++- xen/arch/arm/traps.c | 49 ++++++++++++++++---------------------- xen/include/asm-arm/mm.h | 9 ++++-- xen/include/asm-arm/page.h | 29 +++++++++------------- xen/include/asm-arm/processor.h | 2 +- 6 files changed, 76 insertions(+), 57 deletions(-)
xen/arch/arm/guestcopy.c +24 -6
@@ -12,10 +12,16 @@ unsigned long raw_copy_to_guest(void *to, const void *from, unsigned len)while ( len ) { -paddr_t g =gvirt_to_maddr ((uint32_t ) to); -void *p =map_domain_page (g>>PAGE_SHIFT ); +int rc; +paddr_t g; +void *p;unsigned size =min (len, (unsigned )PAGE_SIZE - offset); + rc =gvirt_to_maddr ((uint32_t ) to, &g); +if ( rc ) +return rc; + + p =map_domain_page (g>>PAGE_SHIFT ); p += offset;memcpy (p, from, size);
@@ -36,10 +42,16 @@ unsigned long raw_clear_guest(void *to, unsigned len)while ( len ) { -paddr_t g =gvirt_to_maddr ((uint32_t ) to); -void *p =map_domain_page (g>>PAGE_SHIFT ); +int rc; +paddr_t g; +void *p;unsigned size =min (len, (unsigned )PAGE_SIZE - offset); + rc =gvirt_to_maddr ((uint32_t ) to, &g); +if ( rc ) +return rc; + + p =map_domain_page (g>>PAGE_SHIFT ); p += offset;memset (p,0x00 , size);
@@ -56,10 +68,16 @@ unsigned long raw_copy_from_guest(void *to, const void __user *from, unsigned le {while ( len ) { -paddr_t g =gvirt_to_maddr ((uint32_t ) from &PAGE_MASK ); -void *p =map_domain_page (g>>PAGE_SHIFT ); +int rc; +paddr_t g; +void *p;unsigned size =min (len, (unsigned )(PAGE_SIZE - ((unsigned )from & (~PAGE_MASK )))); + rc =gvirt_to_maddr ((uint32_t ) from &PAGE_MASK , &g); +if ( rc ) +return rc; + + p =map_domain_page (g>>PAGE_SHIFT ); p += ((unsigned long )from & (~PAGE_MASK ));memcpy (to, p, size);
xen/arch/arm/kernel.c +12 -2
@@ -76,12 +76,22 @@ static void kernel_zimage_load(struct kernel_info *info) paddr, load_addr, load_addr + len);for ( offs =0 ; offs < len; ) { -paddr_t s, l, ma =gvirt_to_maddr (load_addr + offs); -void *dst =map_domain_page (ma>>PAGE_SHIFT ); +int rc; +paddr_t s, l, ma; +void *dst; s = offs & ~PAGE_MASK ; l =min (PAGE_SIZE - s, len); + rc =gvirt_to_maddr (load_addr + offs, &ma); +if ( rc ) + { +panic ("\nUnable to map translate guest address\n" ); +return ; + } + + dst =map_domain_page (ma>>PAGE_SHIFT ); +copy_from_paddr (dst + s, paddr + offs, l, attr);unmap_domain_page (dst);
xen/arch/arm/traps.c +21 -28
80 lines not on this page · raw message
xen/include/asm-arm/mm.h +6 -3
@@ -191,10 +191,13 @@ static inline void *maddr_to_virt(paddr_t ma)return (void *)(unsigned long ) ma +XENHEAP_VIRT_START ; } -static inline paddr_t gvirt_to_maddr (uint32_t va) +static inline int gvirt_to_maddr (uint32_t va,paddr_t *pa) { -uint64_t par =gva_to_par (va); -return (par &PADDR_MASK &PAGE_MASK ) | ((unsigned long ) va & ~PAGE_MASK ); +uint64_t par =gva_to_ma_par (va); +if ( par &PAR_F ) +return -EFAULT ; + *pa = (par &PADDR_MASK &PAGE_MASK ) | ((unsigned long ) va & ~PAGE_MASK ); +return 0 ; }/* Convert between Xen-heap virtual addresses and machine addresses. */
xen/include/asm-arm/page.h +12 -17
@@ -2,6 +2,7 @@#define __ARM_PAGE_H__#include <xen/config.h> +#include <xen/errno.h> #include <public/xen.h> #include <asm/processor.h>
@@ -362,13 +363,13 @@ static inline uint64_t va_to_par(uint32_t va)if ( par &PAR_F ) {dump_hyp_walk (va); -panic_PAR (par,"Hypervisor" ); +panic_PAR (par); }return par; }/* Ask the MMU to translate a Guest VA for us */ -static inline uint64_t __gva_to_par (uint32_t va) +static inline uint64_t gva_to_ma_par (uint32_t va) {uint64_t par, tmp; tmp =READ_CP64 (PAR );
@@ -378,15 +379,7 @@ static inline uint64_t __gva_to_par(uint32_t va)WRITE_CP64 (tmp,PAR );return par; } -static inline uint64_t gva_to_par (uint32_t va) -{ -uint64_t par =__gva_to_par (va); -/* It is not OK to call this with an invalid VA */ -/* XXX harsh for a guest address... */ -if ( par &PAR_F )panic_PAR (par,"Guest" ); -return par; -} -static inline uint64_t __gva_to_ipa (uint32_t va) +static inline uint64_t gva_to_ipa_par (uint32_t va) {uint64_t par, tmp; tmp =READ_CP64 (PAR );
@@ -396,14 +389,16 @@ static inline uint64_t __gva_to_ipa(uint32_t va)WRITE_CP64 (tmp,PAR );return par; } -static inline uint64_t gva_to_ipa (uint32_t va) + +static inline int gva_to_ipa (uint32_t va,paddr_t *paddr) { -uint64_t par =__gva_to_ipa (va); -/* It is not OK to call this with an invalid VA */ -/* XXX harsh for a guest address... */ -if ( par &PAR_F )panic_PAR (par,"Guest" ); -return (par &PADDR_MASK &PAGE_MASK ) | ((unsigned long ) va & ~PAGE_MASK ); +uint64_t par =gva_to_ipa_par (va); +if ( par &PAR_F ) +return -EFAULT ; + *paddr = (par &PADDR_MASK &PAGE_MASK ) | ((unsigned long ) va & ~PAGE_MASK ); +return 0 ; } +/* Bits in the PAR returned by va_to_par */ #define PAR_FAULT 0x1
xen/include/asm-arm/processor.h +1 -1
@@ -231,7 +231,7 @@ union hsr {#ifndef __ASSEMBLY__extern uint32_t hyp_traps_vector[8 ]; -void panic_PAR (uint64_t par,const char *when); +void panic_PAR (uint64_t par);void show_execution_state (struct cpu_user_regs *regs);void show_registers (struct cpu_user_regs *regs);
Signature · 1 line
1.7.9.1
Quoted 8 lines · Ian Campbell
The gva_to_{par,ipa} functions currently panic if the guest address cannot be translated. Often the input comes from the guest so panicing the host is a bit harsh!
Change the API of those functions to allow them to return a failure and plumb it through where it is used.
Signed-off-by Ian Campbell <[email protected]>
Ian Campbell
AppliedQuoted 11 lines · Stefano Stabellini
Quoted 8 lines · Ian Campbell
The gva_to_{par,ipa} functions currently panic if the guest address cannot be translated. Often the input comes from the guest so panicing the host is a bit harsh!
Change the API of those functions to allow them to return a failure and plumb it through where it is used.
Signed-off-by Ian Campbell <[email protected]>
Applied, thanks.