From: "Jan Beulich" Subject: Re: [PATCH] 32on64: increase size of compatargumenttranslation area to 2 pages Date: Fri, 03 Jul 2009 16:16:20 +0100 Message-ID: <4A4E3CE40200007800008D02@vpn.id2.novell.com> References: <4A4E24450200007800008CBD@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Campbell , Keir Fraser Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org >>> Keir Fraser 03.07.09 15:47 >>> >On 03/07/2009 14:31, "Jan Beulich" wrote: > >>> Increasing COMPAT_ARG_XLAT_SIZE to 2 pages is sufficient to support >>> order 9 exchanges. PERCPU_SHIFT must also be increased since the >>> translation area is percpu. >>=20 >> Perhaps we should decouple this by allocating those pages as CPUs get >> brought up, and just have a pointer in per-CPU storage. > >Good idea. I will sort out a patch to do so, and apply Ian's patch on = top. I >will backport both for 3.4.1. Just in case - here's my take on it. And I'd think 3.3.2 may also need this and Ian's adjustment then. Jan Subject: avoid compat_arg_xlat to be a large per-CPU object Signed-off-by: Jan Beulich --- 2009-06-10.orig/xen/arch/x86/smpboot.c 2009-07-03 16:13:10.0000000= 00 +0200 +++ 2009-06-10/xen/arch/x86/smpboot.c 2009-07-03 16:48:29.000000000 = +0200 @@ -878,6 +878,9 @@ static int __devinit do_boot_cpu(int api per_cpu(doublefault_tss, cpu) =3D alloc_xenheap_page(); memset(per_cpu(doublefault_tss, cpu), 0, PAGE_SIZE); } +#else + if (!per_cpu(compat_arg_xlat, cpu)) + setup_compat_arg_xlat(cpu, apicid_to_node[apicid]); #endif =20 if (!idt_tables[cpu]) { --- 2009-06-10.orig/xen/arch/x86/x86_64/compat/mm.c 2009-07-03 = 16:13:10.000000000 +0200 +++ 2009-06-10/xen/arch/x86/x86_64/compat/mm.c 2009-07-03 15:42:21.0000000= 00 +0200 @@ -58,7 +58,7 @@ int compat_arch_memory_op(int op, XEN_GU case XENMEM_add_to_physmap: { struct compat_add_to_physmap cmp; - struct xen_add_to_physmap *nat =3D (void *)COMPAT_ARG_XLAT_VIRT_BA= SE; + struct xen_add_to_physmap *nat =3D COMPAT_ARG_XLAT_VIRT_BASE; =20 if ( copy_from_guest(&cmp, arg, 1) ) return -EFAULT; @@ -72,7 +72,7 @@ int compat_arch_memory_op(int op, XEN_GU case XENMEM_set_memory_map: { struct compat_foreign_memory_map cmp; - struct xen_foreign_memory_map *nat =3D (void *)COMPAT_ARG_XLAT_VIR= T_BASE; + struct xen_foreign_memory_map *nat =3D COMPAT_ARG_XLAT_VIRT_BASE; =20 if ( copy_from_guest(&cmp, arg, 1) ) return -EFAULT; @@ -91,7 +91,7 @@ int compat_arch_memory_op(int op, XEN_GU case XENMEM_machine_memory_map: { struct compat_memory_map cmp; - struct xen_memory_map *nat =3D (void *)COMPAT_ARG_XLAT_VIRT_BASE; + struct xen_memory_map *nat =3D COMPAT_ARG_XLAT_VIRT_BASE; =20 if ( copy_from_guest(&cmp, arg, 1) ) return -EFAULT; @@ -118,7 +118,7 @@ int compat_arch_memory_op(int op, XEN_GU case XENMEM_get_pod_target: { struct compat_pod_target cmp; - struct xen_pod_target *nat =3D (void *)COMPAT_ARG_XLAT_VIRT_BASE; + struct xen_pod_target *nat =3D COMPAT_ARG_XLAT_VIRT_BASE; =20 if ( copy_from_guest(&cmp, arg, 1) ) return -EFAULT; @@ -212,7 +212,7 @@ int compat_mmuext_op(XEN_GUEST_HANDLE(mm if ( unlikely(!guest_handle_okay(cmp_uops, count)) ) return -EFAULT; =20 - set_xen_guest_handle(nat_ops, (void *)COMPAT_ARG_XLAT_VIRT_BASE); + set_xen_guest_handle(nat_ops, COMPAT_ARG_XLAT_VIRT_BASE); =20 for ( ; count; count -=3D i ) { --- 2009-06-10.orig/xen/arch/x86/x86_64/mm.c 2009-07-03 16:13:10.0000000= 00 +0200 +++ 2009-06-10/xen/arch/x86/x86_64/mm.c 2009-07-03 17:04:19.000000000 = +0200 @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -30,7 +31,6 @@ #include #include #include -#include #include =20 #ifdef CONFIG_COMPAT @@ -37,7 +37,7 @@ int mpt_valid; unsigned int m2p_compat_vstart =3D __HYPERVISOR_COMPAT_VIRT_START; #endif =20 -DEFINE_PER_CPU(char, compat_arg_xlat[COMPAT_ARG_XLAT_SIZE]); +DEFINE_PER_CPU(void *, compat_arg_xlat); =20 /* Top-level master (and idle-domain) page directory. */ l4_pgentry_t __attribute__ ((__section__ (".bss.page_aligned"))) @@ -293,6 +293,25 @@ void __init zap_low_mappings(void) 0x10, __PAGE_HYPERVISOR); } =20 +int __cpuinit setup_compat_arg_xlat(unsigned int cpu, int node) +{ + unsigned int order =3D get_order_from_bytes(COMPAT_ARG_XLAT_SIZE); + unsigned long sz =3D PAGE_SIZE << order; + unsigned int memflags =3D node !=3D NUMA_NO_NODE ? MEMF_node(node) : = 0; + struct page_info *pg; + + pg =3D alloc_domheap_pages(NULL, order, memflags); + if ( !pg ) + return -ENOMEM; + + for ( ; (sz -=3D PAGE_SIZE) >=3D COMPAT_ARG_XLAT_SIZE; ++pg ) + free_domheap_page(pg); + + per_cpu(compat_arg_xlat, cpu) =3D page_to_virt(pg); + + return 0; +} + void __init subarch_init_memory(void) { unsigned long i, n, v, m2p_start_mfn; @@ -350,6 +369,10 @@ void __init subarch_init_memory(void) share_xen_page_with_privileged_guests(page, XENSHARE_readonly)= ; } } + + if ( setup_compat_arg_xlat(smp_processor_id(), + apicid_to_node[boot_cpu_physical_apicid]) = ) + panic("Could not setup argument translation area"); } =20 long subarch_memory_op(int op, XEN_GUEST_HANDLE(void) arg) --- 2009-06-10.orig/xen/common/compat/domain.c 2009-07-03 16:13:10.0000000= 00 +0200 +++ 2009-06-10/xen/common/compat/domain.c 2009-07-03 15:43:41.0000000= 00 +0200 @@ -87,7 +87,7 @@ int compat_vcpu_op(int cmd, int vcpuid,=20 =20 if ( copy_from_guest(&cmp, arg, 1) ) return -EFAULT; - nat =3D (void *)COMPAT_ARG_XLAT_VIRT_BASE; + nat =3D COMPAT_ARG_XLAT_VIRT_BASE; XLAT_vcpu_set_singleshot_timer(nat, &cmp); rc =3D do_vcpu_op(cmd, vcpuid, guest_handle_from_ptr(nat, void)); break; --- 2009-06-10.orig/xen/common/compat/grant_table.c 2009-07-03 = 16:13:10.000000000 +0200 +++ 2009-06-10/xen/common/compat/grant_table.c 2009-07-03 15:43:54.0000000= 00 +0200 @@ -99,7 +99,7 @@ int compat_grant_table_op(unsigned int c struct compat_gnttab_copy copy; } cmp; =20 - set_xen_guest_handle(nat.uop, (void *)COMPAT_ARG_XLAT_VIRT_BASE); + set_xen_guest_handle(nat.uop, COMPAT_ARG_XLAT_VIRT_BASE); switch ( cmd ) { case GNTTABOP_setup_table: --- 2009-06-10.orig/xen/common/compat/memory.c 2009-07-03 16:13:10.0000000= 00 +0200 +++ 2009-06-10/xen/common/compat/memory.c 2009-07-03 15:44:00.0000000= 00 +0200 @@ -25,7 +25,7 @@ int compat_memory_op(unsigned int cmd, X struct compat_memory_exchange xchg; } cmp; =20 - set_xen_guest_handle(nat.hnd, (void *)COMPAT_ARG_XLAT_VIRT_BASE); + set_xen_guest_handle(nat.hnd, COMPAT_ARG_XLAT_VIRT_BASE); split =3D 0; switch ( op ) { --- 2009-06-10.orig/xen/include/asm-x86/x86_64/uaccess.h 2009-07-03 = 16:13:10.000000000 +0200 +++ 2009-06-10/xen/include/asm-x86/x86_64/uaccess.h 2009-07-03 = 16:49:28.000000000 +0200 @@ -3,7 +3,8 @@ =20 #define COMPAT_ARG_XLAT_VIRT_BASE this_cpu(compat_arg_xlat) #define COMPAT_ARG_XLAT_SIZE PAGE_SIZE -DECLARE_PER_CPU(char, compat_arg_xlat[COMPAT_ARG_XLAT_SIZE]); +DECLARE_PER_CPU(void *, compat_arg_xlat); +int setup_compat_arg_xlat(unsigned int cpu, int node); #define is_compat_arg_xlat_range(addr, size) ({ = \ unsigned long __off; = \ __off =3D (unsigned long)(addr) - (unsigned long)COMPAT_ARG_XLAT_VIRT_= BASE; \