From: "Jan Beulich" Subject: [PATCH] x86: avoid redundant TLB flushes Date: Tue, 03 Feb 2009 15:58:44 +0000 Message-ID: <498877C4.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: 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: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org While in some places the guest requested flushes were already folded into the deferred ops, this wasn't done consistently. Also avoid using an uninitialized variable, even if doing so has no correctness issue. Signed-off-by: Jan Beulich --- 2009-01-30.orig/xen/arch/x86/mm.c 2009-01-30 10:13:53.000000000 = +0100 +++ 2009-01-30/xen/arch/x86/mm.c 2009-02-03 13:54:43.000000000 = +0100 @@ -2773,7 +2773,7 @@ int do_mmuext_op( } =20 case MMUEXT_TLB_FLUSH_ALL: - flush_tlb_mask(d->domain_dirty_cpumask); + this_cpu(percpu_mm_info).deferred_ops |=3D DOP_FLUSH_ALL_TLBS;= break; =20 case MMUEXT_INVLPG_ALL: @@ -3567,34 +3567,40 @@ int do_update_va_mapping(unsigned long v if ( pl1e ) guest_unmap_l1e(v, pl1e); =20 - process_deferred_ops(); - switch ( flags & UVMF_FLUSHTYPE_MASK ) { case UVMF_TLB_FLUSH: switch ( (bmap_ptr =3D flags & ~UVMF_FLUSHTYPE_MASK) ) { case UVMF_LOCAL: - flush_tlb_local(); + this_cpu(percpu_mm_info).deferred_ops |=3D DOP_FLUSH_TLB; break; case UVMF_ALL: - flush_tlb_mask(d->domain_dirty_cpumask); + this_cpu(percpu_mm_info).deferred_ops |=3D DOP_FLUSH_ALL_TLBS;= break; default: + if ( this_cpu(percpu_mm_info).deferred_ops & DOP_FLUSH_ALL_TLB= S ) + break; if ( unlikely(!is_pv_32on64_domain(d) ? get_user(vmask, (unsigned long *)bmap_ptr) : get_user(vmask, (unsigned int *)bmap_ptr)) ) - rc =3D -EFAULT; + rc =3D -EFAULT, vmask =3D 0; pmask =3D vcpumask_to_pcpumask(d, vmask); + if ( cpu_isset(smp_processor_id(), pmask) ) + this_cpu(percpu_mm_info).deferred_ops &=3D ~DOP_FLUSH_TLB;= flush_tlb_mask(pmask); break; } break; =20 case UVMF_INVLPG: + if ( this_cpu(percpu_mm_info).deferred_ops & DOP_FLUSH_ALL_TLBS ) + break; switch ( (bmap_ptr =3D flags & ~UVMF_FLUSHTYPE_MASK) ) { case UVMF_LOCAL: + if ( this_cpu(percpu_mm_info).deferred_ops & DOP_FLUSH_TLB ) + break; if ( !paging_mode_enabled(d) || (paging_invlpg(v, va) !=3D 0) )=20 flush_tlb_one_local(va); @@ -3606,14 +3612,18 @@ int do_update_va_mapping(unsigned long v if ( unlikely(!is_pv_32on64_domain(d) ? get_user(vmask, (unsigned long *)bmap_ptr) : get_user(vmask, (unsigned int *)bmap_ptr)) ) - rc =3D -EFAULT; + rc =3D -EFAULT, vmask =3D 0; pmask =3D vcpumask_to_pcpumask(d, vmask); + if ( this_cpu(percpu_mm_info).deferred_ops & DOP_FLUSH_TLB ) + cpu_clear(smp_processor_id(), pmask); flush_tlb_one_mask(pmask, va); break; } break; } =20 + process_deferred_ops(); + return rc; } =20