Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Harden cross-cpu L3 sync - avoid optimisations that...



details:   https://anonhg.NetBSD.org/src/rev/596ee488adf0
branches:  trunk
changeset: 772583:596ee488adf0
user:      cherry <cherry%NetBSD.org@localhost>
date:      Mon Jan 09 12:58:49 2012 +0000

description:
Harden cross-cpu L3 sync - avoid optimisations that may race.
Update ci->ci_kpm_pdir from user pmap, not global pmap_kernel() entry which may get clobbered by other CPUs.
XXX: Look into why we use pmap_kernel() userspace entries at all.

diffstat:

 sys/arch/x86/x86/pmap.c     |  26 ++++++++++----------------
 sys/arch/xen/x86/xen_pmap.c |  11 +++++++----
 2 files changed, 17 insertions(+), 20 deletions(-)

diffs (100 lines):

diff -r acdb8d0d066a -r 596ee488adf0 sys/arch/x86/x86/pmap.c
--- a/sys/arch/x86/x86/pmap.c   Mon Jan 09 11:52:43 2012 +0000
+++ b/sys/arch/x86/x86/pmap.c   Mon Jan 09 12:58:49 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.152 2012/01/09 04:55:35 cherry Exp $        */
+/*     $NetBSD: pmap.c,v 1.153 2012/01/09 12:58:49 cherry Exp $        */
 
 /*-
  * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
@@ -171,7 +171,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.152 2012/01/09 04:55:35 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.153 2012/01/09 12:58:49 cherry Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -1882,20 +1882,14 @@
                 * If ptp is a L3 currently mapped in kernel space,
                 * on any cpu, clear it before freeing
                 */
-               struct cpu_info *ci;
-               CPU_INFO_ITERATOR cii;
-
-               for (CPU_INFO_FOREACH(cii, ci)) {
-                       if (pmap_pdirpa(pmap, 0) == ci->ci_xen_current_user_pgd
-                           && level == PTP_LEVELS - 1) {
-                               pmap_pte_set(&pmap_kernel()->pm_pdir[index], 0);
-                               /*
-                                * Update the per-cpu PD on all cpus the current
-                                * pmap is active on 
-                                */ 
-                               xen_kpm_sync(pmap, index);
-                               break;
-                       }
+               if (level == PTP_LEVELS - 1) {
+                       pmap_pte_set(&pmap_kernel()->pm_pdir[index], 0);
+                       /*
+                        * Update the per-cpu PD on all cpus the current
+                        * pmap is active on 
+                        */ 
+                       xen_kpm_sync(pmap, index);
+
                }
 #  endif /*__x86_64__ */
                invaladdr = level == 1 ? (vaddr_t)ptes :
diff -r acdb8d0d066a -r 596ee488adf0 sys/arch/xen/x86/xen_pmap.c
--- a/sys/arch/xen/x86/xen_pmap.c       Mon Jan 09 11:52:43 2012 +0000
+++ b/sys/arch/xen/x86/xen_pmap.c       Mon Jan 09 12:58:49 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xen_pmap.c,v 1.12 2011/12/30 16:55:21 cherry Exp $     */
+/*     $NetBSD: xen_pmap.c,v 1.13 2012/01/09 12:58:49 cherry Exp $     */
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -102,7 +102,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.12 2011/12/30 16:55:21 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.13 2012/01/09 12:58:49 cherry Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -576,6 +576,8 @@
 
        struct pmap *pmap = arg1;
        int index = *(int *)arg2;
+       KASSERT(pmap == pmap_kernel() || index < PDIR_SLOT_PTE);
+       
        struct cpu_info *ci = xpq_cpu();
 
        if (pmap == pmap_kernel()) {
@@ -596,7 +598,7 @@
        }
        
        pmap_pte_set(&ci->ci_kpm_pdir[index],
-           pmap_kernel()->pm_pdir[index]);
+           pmap->pm_pdir[index]);
        pmap_pte_flush();
 #endif /* PAE || __x86_64__ */
 }
@@ -650,6 +652,7 @@
 #else /* MULTIPROCESSOR */
 #define CPU_IS_CURCPU(ci) __predict_true((ci) == curcpu())
 #endif /* MULTIPROCESSOR */
+#if 0 /* XXX: Race with remote pmap_load() */
                                if (ci->ci_want_pmapload &&
                                    !CPU_IS_CURCPU(ci)) {
                                        /*
@@ -659,7 +662,7 @@
                                         */
                                        continue;
                                    }
-
+#endif /* 0 */
                                where = xc_unicast(XC_HIGHPRI, pmap_kpm_sync_xcall,
                                    pmap, &index, ci);
                                xc_wait(where);



Home | Main Index | Thread Index | Old Index