Thu Apr 18 12:16:23 2024 UTC (21d)
Fix types in pmap_page_clear_attributes so that the top bits of
the u_long mdpg_attrs aren't dropped giving atomic_cas_ulong no
chance of completing if any of the top bits is set.

Update pmap_page_set_attributes for consistency.

An ATF test run completed for me with this fix.

port-riscv/58006: ATF tests no longer complete on riscv-riscv64


(skrll)
diff -r1.77 -r1.78 src/sys/uvm/pmap/pmap.c
diff -r1.26 -r1.27 src/sys/uvm/pmap/pmap.h

cvs diff -r1.77 -r1.78 src/sys/uvm/pmap/pmap.c (expand / switch to unified diff)

--- src/sys/uvm/pmap/pmap.c 2024/03/23 08:31:15 1.77
+++ src/sys/uvm/pmap/pmap.c 2024/04/18 12:16:23 1.78
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.c,v 1.77 2024/03/23 08:31:15 skrll Exp $ */ 1/* $NetBSD: pmap.c,v 1.78 2024/04/18 12:16:23 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.77 2024/03/23 08:31:15 skrll Exp $"); 70__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.78 2024/04/18 12:16:23 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,
@@ -405,50 +405,50 @@ pmap_addr_range_check(pmap_t pmap, vaddr @@ -405,50 +405,50 @@ pmap_addr_range_check(pmap_t pmap, vaddr
405 if (eva > VM_MAXUSER_ADDRESS) 405 if (eva > VM_MAXUSER_ADDRESS)
406 panic("%s: uva %#"PRIxVADDR" not in range", 406 panic("%s: uva %#"PRIxVADDR" not in range",
407 func, eva); 407 func, eva);
408 pmap_asid_check(pmap, func); 408 pmap_asid_check(pmap, func);
409 } 409 }
410#endif 410#endif
411} 411}
412 412
413/* 413/*
414 * Misc. functions. 414 * Misc. functions.
415 */ 415 */
416 416
417bool 417bool
418pmap_page_clear_attributes(struct vm_page_md *mdpg, u_int clear_attributes) 418pmap_page_clear_attributes(struct vm_page_md *mdpg, u_long clear_attributes)
419{ 419{
420 volatile unsigned long * const attrp = &mdpg->mdpg_attrs; 420 volatile u_long * const attrp = &mdpg->mdpg_attrs;
421 421
422#ifdef MULTIPROCESSOR 422#ifdef MULTIPROCESSOR
423 for (;;) { 423 for (;;) {
424 u_int old_attr = *attrp; 424 u_long old_attr = *attrp;
425 if ((old_attr & clear_attributes) == 0) 425 if ((old_attr & clear_attributes) == 0)
426 return false; 426 return false;
427 u_int new_attr = old_attr & ~clear_attributes; 427 u_long new_attr = old_attr & ~clear_attributes;
428 if (old_attr == atomic_cas_ulong(attrp, old_attr, new_attr)) 428 if (old_attr == atomic_cas_ulong(attrp, old_attr, new_attr))
429 return true; 429 return true;
430 } 430 }
431#else 431#else
432 unsigned long old_attr = *attrp; 432 u_long old_attr = *attrp;
433 if ((old_attr & clear_attributes) == 0) 433 if ((old_attr & clear_attributes) == 0)
434 return false; 434 return false;
435 *attrp &= ~clear_attributes; 435 *attrp &= ~clear_attributes;
436 return true; 436 return true;
437#endif 437#endif
438} 438}
439 439
440void 440void
441pmap_page_set_attributes(struct vm_page_md *mdpg, u_int set_attributes) 441pmap_page_set_attributes(struct vm_page_md *mdpg, u_long set_attributes)
442{ 442{
443#ifdef MULTIPROCESSOR 443#ifdef MULTIPROCESSOR
444 atomic_or_ulong(&mdpg->mdpg_attrs, set_attributes); 444 atomic_or_ulong(&mdpg->mdpg_attrs, set_attributes);
445#else 445#else
446 mdpg->mdpg_attrs |= set_attributes; 446 mdpg->mdpg_attrs |= set_attributes;
447#endif 447#endif
448} 448}
449 449
450static void 450static void
451pmap_page_syncicache(struct vm_page *pg) 451pmap_page_syncicache(struct vm_page *pg)
452{ 452{
453 UVMHIST_FUNC(__func__); 453 UVMHIST_FUNC(__func__);
454 UVMHIST_CALLED(pmaphist); 454 UVMHIST_CALLED(pmaphist);

cvs diff -r1.26 -r1.27 src/sys/uvm/pmap/pmap.h (expand / switch to unified diff)

--- src/sys/uvm/pmap/pmap.h 2022/11/03 18:55:07 1.26
+++ src/sys/uvm/pmap/pmap.h 2024/04/18 12:16:23 1.27
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.h,v 1.26 2022/11/03 18:55:07 skrll Exp $ */ 1/* $NetBSD: pmap.h,v 1.27 2024/04/18 12:16:23 skrll Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Ralph Campbell. 8 * Ralph Campbell.
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.
@@ -286,28 +286,28 @@ extern u_int pmap_page_colormask; @@ -286,28 +286,28 @@ extern u_int pmap_page_colormask;
286extern vaddr_t pmap_curmaxkvaddr; 286extern vaddr_t pmap_curmaxkvaddr;
287 287
288#if defined(PMAP_HWPAGEWALKER) 288#if defined(PMAP_HWPAGEWALKER)
289extern pmap_pdetab_t pmap_kern_pdetab; 289extern pmap_pdetab_t pmap_kern_pdetab;
290#else 290#else
291extern pmap_segtab_t pmap_kern_segtab; 291extern pmap_segtab_t pmap_kern_segtab;
292#endif 292#endif
293 293
294#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) 294#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count)
295#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) 295#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
296 296
297bool pmap_remove_all(pmap_t); 297bool pmap_remove_all(pmap_t);
298void pmap_set_modified(paddr_t); 298void pmap_set_modified(paddr_t);
299bool pmap_page_clear_attributes(struct vm_page_md *, u_int); 299bool pmap_page_clear_attributes(struct vm_page_md *, u_long);
300void pmap_page_set_attributes(struct vm_page_md *, u_int); 300void pmap_page_set_attributes(struct vm_page_md *, u_long);
301void pmap_pvlist_lock_init(size_t); 301void pmap_pvlist_lock_init(size_t);
302#ifdef PMAP_VIRTUAL_CACHE_ALIASES 302#ifdef PMAP_VIRTUAL_CACHE_ALIASES
303void pmap_page_cache(struct vm_page_md *, bool); 303void pmap_page_cache(struct vm_page_md *, bool);
304#endif 304#endif
305 305
306#if defined(__HAVE_PMAP_PV_TRACK) && !defined(PMAP_PV_TRACK_ONLY_STUBS) 306#if defined(__HAVE_PMAP_PV_TRACK) && !defined(PMAP_PV_TRACK_ONLY_STUBS)
307void pmap_pv_protect(paddr_t, vm_prot_t); 307void pmap_pv_protect(paddr_t, vm_prot_t);
308#endif 308#endif
309 309
310#define PMAP_WB 0 310#define PMAP_WB 0
311#define PMAP_WBINV 1 311#define PMAP_WBINV 1
312#define PMAP_INV 2 312#define PMAP_INV 2
313 313