pmap_activate() should match cpu_switchto, so set up ci_{kern,user}_cr3
authorguenther <guenther@openbsd.org>
Sun, 9 Sep 2018 22:46:54 +0000 (22:46 +0000)
committerguenther <guenther@openbsd.org>
Sun, 9 Sep 2018 22:46:54 +0000 (22:46 +0000)
if activating for the current thread and meltdown mitigations are in effect.
Not clear if it's actually possible to hit the case where this matters,
but it's the Right Thing.

ok mlarkin@

sys/arch/amd64/amd64/pmap.c

index 85f23f0..3b13d45 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pmap.c,v 1.117 2018/09/09 22:41:57 guenther Exp $     */
+/*     $OpenBSD: pmap.c,v 1.118 2018/09/09 22:46:54 guenther Exp $     */
 /*     $NetBSD: pmap.c,v 1.3 2003/05/08 18:13:13 thorpej Exp $ */
 
 /*
@@ -1188,6 +1188,14 @@ pmap_activate(struct proc *p)
        if (p == curproc) {
                lcr3(pcb->pcb_cr3);
 
+               /* in case we return to userspace without context switching */
+               if (cpu_meltdown) {
+                       struct cpu_info *self = curcpu();
+
+                       self->ci_kern_cr3 = pcb->pcb_cr3;
+                       self->ci_user_cr3 = pmap->pm_pdirpa_intel;
+               }
+
                /*
                 * mark the pmap in use by this processor.
                 */