Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/alpha Pages that are in-use as page table pages sho...



details:   https://anonhg.NetBSD.org/src/rev/1240347b2f9a
branches:  trunk
changeset: 1021426:1240347b2f9a
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun May 30 04:04:26 2021 +0000

description:
Pages that are in-use as page table pages should never be part of a
UVM loan transaction, so use the vm_page::loan_count field as the PT
page reference count.

diffstat:

 sys/arch/alpha/alpha/pmap.c   |  52 ++++++++++++++++++------------------------
 sys/arch/alpha/include/pmap.h |   5 +--
 2 files changed, 24 insertions(+), 33 deletions(-)

diffs (141 lines):

diff -r 96f5b8904175 -r 1240347b2f9a sys/arch/alpha/alpha/pmap.c
--- a/sys/arch/alpha/alpha/pmap.c       Sun May 30 03:26:33 2021 +0000
+++ b/sys/arch/alpha/alpha/pmap.c       Sun May 30 04:04:26 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.284 2021/05/30 01:41:45 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.285 2021/05/30 04:04:26 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.284 2021/05/30 01:41:45 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.285 2021/05/30 04:04:26 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -3358,6 +3358,15 @@
 /******************** misc. functions ********************/
 
 /*
+ * Pages that are in-use as page table pages should never be part
+ * of a UVM loan, so we'll use that field for our PT page reference
+ * count.
+ */
+#define        PHYSPAGE_REFCNT(pg)     atomic_load_relaxed(&(pg)->loan_count)
+#define        PHYSPAGE_REFCNT_INC(pg) atomic_inc_uint_nv(&(pg)->loan_count)
+#define        PHYSPAGE_REFCNT_DEC(pg) atomic_dec_uint_nv(&(pg)->loan_count)
+
+/*
  * pmap_physpage_alloc:
  *
  *     Allocate a single page from the VM system and return the
@@ -3376,14 +3385,7 @@
        pg = uvm_pagealloc(NULL, 0, NULL, usage == PGU_L1PT ?
            UVM_PGA_USERESERVE : UVM_PGA_USERESERVE|UVM_PGA_ZERO);
        if (pg != NULL) {
-#ifdef DEBUG
-               struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
-               if (md->pvh_refcnt != 0) {
-                       printf("pmap_physpage_alloc: page 0x%lx has "
-                           "%d references\n", pa, md->pvh_refcnt);
-                       panic("pmap_physpage_alloc");
-               }
-#endif
+               KASSERT(PHYSPAGE_REFCNT(pg) == 0);
        }
        return pg;
 }
@@ -3401,11 +3403,7 @@
        if ((pg = PHYS_TO_VM_PAGE(pa)) == NULL)
                panic("pmap_physpage_free: bogus physical page address");
 
-#ifdef DEBUG
-       struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
-       if (md->pvh_refcnt != 0)
-               panic("pmap_physpage_free: page still has references");
-#endif
+       KASSERT(PHYSPAGE_REFCNT(pg) == 0);
 
        uvm_pagefree(pg);
 }
@@ -3419,16 +3417,14 @@
 pmap_physpage_addref(void *kva)
 {
        struct vm_page *pg;
-       struct vm_page_md *md;
        paddr_t pa;
 
        pa = ALPHA_K0SEG_TO_PHYS(trunc_page((vaddr_t)kva));
        pg = PHYS_TO_VM_PAGE(pa);
-       md = VM_PAGE_TO_MD(pg);
-
-       KASSERT((int)md->pvh_refcnt >= 0);
-
-       return atomic_inc_uint_nv(&md->pvh_refcnt);
+
+       KASSERT(PHYSPAGE_REFCNT(pg) < UINT32_MAX);
+
+       return PHYSPAGE_REFCNT_INC(pg);
 }
 
 /*
@@ -3440,16 +3436,14 @@
 pmap_physpage_delref(void *kva)
 {
        struct vm_page *pg;
-       struct vm_page_md *md;
        paddr_t pa;
 
        pa = ALPHA_K0SEG_TO_PHYS(trunc_page((vaddr_t)kva));
        pg = PHYS_TO_VM_PAGE(pa);
-       md = VM_PAGE_TO_MD(pg);
-
-       KASSERT((int)md->pvh_refcnt > 0);
-
-       return atomic_dec_uint_nv(&md->pvh_refcnt);
+
+       KASSERT(PHYSPAGE_REFCNT(pg) != 0);
+
+       return PHYSPAGE_REFCNT_DEC(pg);
 }
 
 /******************** page table page management ********************/
@@ -3685,10 +3679,8 @@
        struct vm_page * const pg = PHYS_TO_VM_PAGE(ptpa);
        KASSERT(pg != NULL);
 
+       KASSERT(PHYSPAGE_REFCNT(pg) == 0);
 #ifdef DEBUG
-       struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
-       KDASSERT(md->pvh_refcnt == 0);
-
        pmap_zero_page(ptpa);
 #endif
 
diff -r 96f5b8904175 -r 1240347b2f9a sys/arch/alpha/include/pmap.h
--- a/sys/arch/alpha/include/pmap.h     Sun May 30 03:26:33 2021 +0000
+++ b/sys/arch/alpha/include/pmap.h     Sun May 30 04:04:26 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.90 2021/05/30 01:41:45 thorpej Exp $ */
+/* $NetBSD: pmap.h,v 1.91 2021/05/30 04:04:26 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -361,13 +361,12 @@
 struct vm_page_md {
        struct pv_entry *pvh_list;              /* pv_entry list */
        int pvh_attrs;                          /* page attributes */
-       unsigned pvh_refcnt;
 };
 
 #define        VM_MDPAGE_INIT(pg)                                              \
 do {                                                                   \
        (pg)->mdpage.pvh_list = NULL;                                   \
-       (pg)->mdpage.pvh_refcnt = 0;                                    \
+       (pg)->mdpage.pvh_attrs = 0;                                     \
 } while (/*CONSTCOND*/0)
 
 #endif /* _KERNEL */



Home | Main Index | Thread Index | Old Index