Wed Jul 26 21:45:29 2023 UTC ()
x86/pmap: Print quantities in failed assertions in pmap_load.


(riastradh)
diff -r1.424 -r1.425 src/sys/arch/x86/x86/pmap.c

cvs diff -r1.424 -r1.425 src/sys/arch/x86/x86/pmap.c (expand / switch to unified diff)

--- src/sys/arch/x86/x86/pmap.c 2023/07/16 19:55:43 1.424
+++ src/sys/arch/x86/x86/pmap.c 2023/07/26 21:45:28 1.425
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.c,v 1.424 2023/07/16 19:55:43 riastradh Exp $ */ 1/* $NetBSD: pmap.c,v 1.425 2023/07/26 21:45:28 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008, 2010, 2016, 2017, 2019, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008, 2010, 2016, 2017, 2019, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran, and by Maxime Villard. 8 * by Andrew Doran, and by Maxime Villard.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -120,27 +120,27 @@ @@ -120,27 +120,27 @@
120 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 120 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
121 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 121 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
122 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 122 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
123 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 123 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
124 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 124 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
125 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 125 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
126 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 126 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
127 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 127 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
128 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 128 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
129 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 129 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
130 */ 130 */
131 131
132#include <sys/cdefs.h> 132#include <sys/cdefs.h>
133__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.424 2023/07/16 19:55:43 riastradh Exp $"); 133__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.425 2023/07/26 21:45:28 riastradh Exp $");
134 134
135#include "opt_user_ldt.h" 135#include "opt_user_ldt.h"
136#include "opt_lockdebug.h" 136#include "opt_lockdebug.h"
137#include "opt_multiprocessor.h" 137#include "opt_multiprocessor.h"
138#include "opt_xen.h" 138#include "opt_xen.h"
139#include "opt_svs.h" 139#include "opt_svs.h"
140#include "opt_kaslr.h" 140#include "opt_kaslr.h"
141#include "opt_efi.h" 141#include "opt_efi.h"
142 142
143#define __MUTEX_PRIVATE /* for assertions */ 143#define __MUTEX_PRIVATE /* for assertions */
144 144
145#include <sys/param.h> 145#include <sys/param.h>
146#include <sys/systm.h> 146#include <sys/systm.h>
@@ -3564,45 +3564,47 @@ pmap_reactivate(struct pmap *pmap) @@ -3564,45 +3564,47 @@ pmap_reactivate(struct pmap *pmap)
3564 * MMU and that there are no stale TLB entries. 3564 * MMU and that there are no stale TLB entries.
3565 * 3565 *
3566 * => The caller should disable kernel preemption or do check-and-retry 3566 * => The caller should disable kernel preemption or do check-and-retry
3567 * to prevent a preemption from undoing our efforts. 3567 * to prevent a preemption from undoing our efforts.
3568 * => This function may block. 3568 * => This function may block.
3569 */ 3569 */
3570void 3570void
3571pmap_load(void) 3571pmap_load(void)
3572{ 3572{
3573 struct cpu_info *ci; 3573 struct cpu_info *ci;
3574 struct pmap *pmap, *oldpmap; 3574 struct pmap *pmap, *oldpmap;
3575 struct lwp *l; 3575 struct lwp *l;
3576 uint64_t ncsw; 3576 uint64_t ncsw;
 3577 int ilevel __diagused;
 3578 u_long psl __diagused;
3577 3579
3578 kpreempt_disable(); 3580 kpreempt_disable();
3579 retry: 3581 retry:
3580 ci = curcpu(); 3582 ci = curcpu();
3581 if (!ci->ci_want_pmapload) { 3583 if (!ci->ci_want_pmapload) {
3582 kpreempt_enable(); 3584 kpreempt_enable();
3583 return; 3585 return;
3584 } 3586 }
3585 l = ci->ci_curlwp; 3587 l = ci->ci_curlwp;
3586 ncsw = l->l_ncsw; 3588 ncsw = l->l_ncsw;
3587 __insn_barrier(); 3589 __insn_barrier();
3588 3590
3589 /* should be able to take ipis. */ 3591 /* should be able to take ipis. */
3590 KASSERT(ci->ci_ilevel < IPL_HIGH); 3592 KASSERTMSG((ilevel = ci->ci_ilevel) < IPL_HIGH, "ilevel=%d", ilevel);
3591#ifdef XENPV 3593#ifdef XENPV
3592 /* Check to see if interrupts are enabled (ie; no events are masked) */ 3594 /* Check to see if interrupts are enabled (ie; no events are masked) */
3593 KASSERT(x86_read_psl() == 0); 3595 KASSERTMSG((psl = x86_read_psl()) == 0, "psl=0x%lx", psl);
3594#else 3596#else
3595 KASSERT((x86_read_psl() & PSL_I) != 0); 3597 KASSERTMSG(((psl = x86_read_psl()) & PSL_I) != 0, "psl=0x%lx", psl);
3596#endif 3598#endif
3597 3599
3598 KASSERT(l != NULL); 3600 KASSERT(l != NULL);
3599 pmap = vm_map_pmap(&l->l_proc->p_vmspace->vm_map); 3601 pmap = vm_map_pmap(&l->l_proc->p_vmspace->vm_map);
3600 KASSERT(pmap != pmap_kernel()); 3602 KASSERT(pmap != pmap_kernel());
3601 oldpmap = ci->ci_pmap; 3603 oldpmap = ci->ci_pmap;
3602 3604
3603 if (pmap == oldpmap) { 3605 if (pmap == oldpmap) {
3604 pmap_reactivate(pmap); 3606 pmap_reactivate(pmap);
3605 ci->ci_want_pmapload = 0; 3607 ci->ci_want_pmapload = 0;
3606 kpreempt_enable(); 3608 kpreempt_enable();
3607 return; 3609 return;
3608 } 3610 }