Wed Apr 23 20:57:15 2014 UTC ()
Fix a logic inversion introduced with the matt-nb5-mips64 for
pmap_{zero,copy}_page cache alias handing. The check previously used
PG_MD_UNCACHED_P, where it now uses PG_MD_CACHED_P, when considering if
a cache invalidation is required.

Additionally flush the cache for the uarea va to avoid potential (future)
cache aliases in cpu_uarea_free when handing pages back to uvm for later
use.

ok matt@

Hopefully this addresses the instability reported in the following PRs:

PR/44900 - R5000/Rm5200 mips ports are broken
PR/46170 - NetBSD/cobalt 6.0_BETA does not boot
PR/46890 - upcoming NetBSD 6.0 release is very unstable / unusable on cobalt qube 2
PR/48628 - cobalt and hpcmips ports are dead


(skrll)
diff -r1.209 -r1.210 src/sys/arch/mips/mips/pmap.c
diff -r1.142 -r1.143 src/sys/arch/mips/mips/vm_machdep.c

cvs diff -r1.209 -r1.210 src/sys/arch/mips/mips/Attic/pmap.c (expand / switch to unified diff)

--- src/sys/arch/mips/mips/Attic/pmap.c 2013/11/10 18:27:15 1.209
+++ src/sys/arch/mips/mips/Attic/pmap.c 2014/04/23 20:57:15 1.210
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.c,v 1.209 2013/11/10 18:27:15 christos Exp $ */ 1/* $NetBSD: pmap.c,v 1.210 2014/04/23 20:57:15 skrll Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2001 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 Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center and by Chris G. Demetriou. 9 * NASA Ames Research Center and by Chris G. Demetriou.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -57,27 +57,27 @@ @@ -57,27 +57,27 @@
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE. 63 * SUCH DAMAGE.
64 * 64 *
65 * @(#)pmap.c 8.4 (Berkeley) 1/26/94 65 * @(#)pmap.c 8.4 (Berkeley) 1/26/94
66 */ 66 */
67 67
68#include <sys/cdefs.h> 68#include <sys/cdefs.h>
69 69
70__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.209 2013/11/10 18:27:15 christos Exp $"); 70__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.210 2014/04/23 20:57:15 skrll Exp $");
71 71
72/* 72/*
73 * Manages physical address maps. 73 * Manages physical address maps.
74 * 74 *
75 * In addition to hardware address maps, this 75 * In addition to hardware address maps, this
76 * module is called upon to provide software-use-only 76 * module is called upon to provide software-use-only
77 * maps which may or may not be stored in the same 77 * maps which may or may not be stored in the same
78 * form as hardware maps. These pseudo-maps are 78 * form as hardware maps. These pseudo-maps are
79 * used to store intermediate results from copy 79 * used to store intermediate results from copy
80 * operations to and from address spaces. 80 * operations to and from address spaces.
81 * 81 *
82 * Since the information managed by this module is 82 * Since the information managed by this module is
83 * also stored by the logical address mapping module, 83 * also stored by the logical address mapping module,
@@ -444,36 +444,38 @@ pmap_map_ephemeral_page(struct vm_page * @@ -444,36 +444,38 @@ pmap_map_ephemeral_page(struct vm_page *
444 } 444 }
445 445
446 return va; 446 return va;
447} 447}
448 448
449static void 449static void
450pmap_unmap_ephemeral_page(struct vm_page *pg, vaddr_t va, 450pmap_unmap_ephemeral_page(struct vm_page *pg, vaddr_t va,
451 pt_entry_t old_pt_entry) 451 pt_entry_t old_pt_entry)
452{ 452{
453 struct vm_page_md * const md = VM_PAGE_TO_MD(pg); 453 struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
454 pv_entry_t pv = &md->pvh_first; 454 pv_entry_t pv = &md->pvh_first;
455  455
456 (void)PG_MD_PVLIST_LOCK(md, false); 456 (void)PG_MD_PVLIST_LOCK(md, false);
457 if (MIPS_CACHE_VIRTUAL_ALIAS 457 if (MIPS_CACHE_VIRTUAL_ALIAS) {
458 && (PG_MD_UNCACHED_P(md) 458 if (PG_MD_CACHED_P(md)
459 || (pv->pv_pmap != NULL 459 || (pv->pv_pmap != NULL
460 && mips_cache_badalias(pv->pv_va, va)))) { 460 && mips_cache_badalias(pv->pv_va, va))) {
461 /* 461
462 * If this page was previously uncached or we had to use an 462 /*
463 * incompatible alias and it has a valid mapping, flush it 463 * If this page was previously cached or we had to use an
464 * from the cache. 464 * incompatible alias and it has a valid mapping, flush it
465 */ 465 * from the cache.
466 mips_dcache_wbinv_range(va, PAGE_SIZE); 466 */
 467 mips_dcache_wbinv_range(va, PAGE_SIZE);
 468 }
467 } 469 }
468 PG_MD_PVLIST_UNLOCK(md); 470 PG_MD_PVLIST_UNLOCK(md);
469#ifndef _LP64 471#ifndef _LP64
470 /* 472 /*
471 * If we had to map using a page table entry, unmap it now. 473 * If we had to map using a page table entry, unmap it now.
472 */ 474 */
473 if (va >= VM_MIN_KERNEL_ADDRESS) { 475 if (va >= VM_MIN_KERNEL_ADDRESS) {
474 pmap_kremove(va, PAGE_SIZE); 476 pmap_kremove(va, PAGE_SIZE);
475 if (mips_pg_v(old_pt_entry.pt_entry)) { 477 if (mips_pg_v(old_pt_entry.pt_entry)) {
476 *kvtopte(va) = old_pt_entry; 478 *kvtopte(va) = old_pt_entry;
477 pmap_tlb_update_addr(pmap_kernel(), va, 479 pmap_tlb_update_addr(pmap_kernel(), va,
478 old_pt_entry.pt_entry, false); 480 old_pt_entry.pt_entry, false);
479 } 481 }

cvs diff -r1.142 -r1.143 src/sys/arch/mips/mips/vm_machdep.c (expand / switch to unified diff)

--- src/sys/arch/mips/mips/vm_machdep.c 2012/02/19 21:06:20 1.142
+++ src/sys/arch/mips/mips/vm_machdep.c 2014/04/23 20:57:15 1.143
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vm_machdep.c,v 1.142 2012/02/19 21:06:20 rmind Exp $ */ 1/* $NetBSD: vm_machdep.c,v 1.143 2014/04/23 20:57:15 skrll Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988 University of Utah. 4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1992, 1993 5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved. 6 * The Regents of the University of California. All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to Berkeley by 8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer 9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department and Ralph Campbell. 10 * Science Department and Ralph Campbell.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -29,27 +29,27 @@ @@ -29,27 +29,27 @@
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE. 34 * SUCH DAMAGE.
35 * 35 *
36 * from: Utah Hdr: vm_machdep.c 1.21 91/04/06 36 * from: Utah Hdr: vm_machdep.c 1.21 91/04/06
37 * 37 *
38 * @(#)vm_machdep.c 8.3 (Berkeley) 1/4/94 38 * @(#)vm_machdep.c 8.3 (Berkeley) 1/4/94
39 */ 39 */
40 40
41#include <sys/cdefs.h> 41#include <sys/cdefs.h>
42__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.142 2012/02/19 21:06:20 rmind Exp $"); 42__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.143 2014/04/23 20:57:15 skrll Exp $");
43 43
44#include "opt_ddb.h" 44#include "opt_ddb.h"
45#include "opt_coredump.h" 45#include "opt_coredump.h"
46 46
47#include <sys/param.h> 47#include <sys/param.h>
48#include <sys/systm.h> 48#include <sys/systm.h>
49#include <sys/proc.h> 49#include <sys/proc.h>
50#include <sys/malloc.h> 50#include <sys/malloc.h>
51#include <sys/buf.h> 51#include <sys/buf.h>
52#include <sys/cpu.h> 52#include <sys/cpu.h>
53#include <sys/vnode.h> 53#include <sys/vnode.h>
54#include <sys/core.h> 54#include <sys/core.h>
55#include <sys/exec.h> 55#include <sys/exec.h>
@@ -220,26 +220,31 @@ cpu_uarea_alloc(bool system) @@ -220,26 +220,31 @@ cpu_uarea_alloc(bool system)
220bool 220bool
221cpu_uarea_free(void *va) 221cpu_uarea_free(void *va)
222{ 222{
223#ifdef _LP64 223#ifdef _LP64
224 if (!MIPS_XKPHYS_P(va)) 224 if (!MIPS_XKPHYS_P(va))
225 return false; 225 return false;
226 paddr_t pa = MIPS_XKPHYS_TO_PHYS(va); 226 paddr_t pa = MIPS_XKPHYS_TO_PHYS(va);
227#else 227#else
228 if (!MIPS_KSEG0_P(va)) 228 if (!MIPS_KSEG0_P(va))
229 return false; 229 return false;
230 paddr_t pa = MIPS_KSEG0_TO_PHYS(va); 230 paddr_t pa = MIPS_KSEG0_TO_PHYS(va);
231#endif 231#endif
232 232
 233#ifdef MIPS3_PLUS
 234 if (MIPS_CACHE_VIRTUAL_ALIAS)
 235 mips_dcache_inv_range((vaddr_t)va, USPACE);
 236#endif
 237
233 for (const paddr_t epa = pa + USPACE; pa < epa; pa += PAGE_SIZE) { 238 for (const paddr_t epa = pa + USPACE; pa < epa; pa += PAGE_SIZE) {
234 struct vm_page * const pg = PHYS_TO_VM_PAGE(pa); 239 struct vm_page * const pg = PHYS_TO_VM_PAGE(pa);
235 KASSERT(pg != NULL); 240 KASSERT(pg != NULL);
236 uvm_pagefree(pg); 241 uvm_pagefree(pg);
237 } 242 }
238 return true; 243 return true;
239} 244}
240 245
241void 246void
242cpu_lwp_free(struct lwp *l, int proc) 247cpu_lwp_free(struct lwp *l, int proc)
243{ 248{
244 249
245 (void)l; 250 (void)l;