Diff below fixes a bug exposed when swapping on arm64.  When an anon is
released make sure the all the pmap references to the related page are
removed.

We could move the pmap_page_protect(pg, PROT_NONE) inside uvm_pagefree()
to avoid future issue but that's for a later refactoring.

With this diff I can no longer reproduce the SIGBUS issue on the
rockpro64 and swapping is stable as long as I/O from sdmmc(4) work.

This should be good enough to commit the diff that got reverted, but I'll
wait to be sure there's no regression.

ok?

Index: uvm/uvm_anon.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_anon.c,v
retrieving revision 1.54
diff -u -p -r1.54 uvm_anon.c
--- uvm/uvm_anon.c      26 Mar 2021 13:40:05 -0000      1.54
+++ uvm/uvm_anon.c      10 Sep 2022 12:10:34 -0000
@@ -255,6 +255,7 @@ uvm_anon_release(struct vm_anon *anon)
        KASSERT(anon->an_ref == 0);
 
        uvm_lock_pageq();
+       pmap_page_protect(pg, PROT_NONE);
        uvm_pagefree(pg);
        uvm_unlock_pageq();
        KASSERT(anon->an_page == NULL);
Index: uvm/uvm_fault.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_fault.c,v
retrieving revision 1.132
diff -u -p -r1.132 uvm_fault.c
--- uvm/uvm_fault.c     31 Aug 2022 01:27:04 -0000      1.132
+++ uvm/uvm_fault.c     10 Sep 2022 12:10:34 -0000
@@ -396,7 +396,6 @@ uvmfault_anonget(struct uvm_faultinfo *u
                         * anon and try again.
                         */
                        if (pg->pg_flags & PG_RELEASED) {
-                               pmap_page_protect(pg, PROT_NONE);
                                KASSERT(anon->an_ref == 0);
                                /*
                                 * Released while we had unlocked amap.

Reply via email to