Attempt to guarantee that on copy-on-write faulting, the new copy
authorguenther <guenther@openbsd.org>
Tue, 1 Feb 2022 08:38:53 +0000 (08:38 +0000)
committerguenther <guenther@openbsd.org>
Tue, 1 Feb 2022 08:38:53 +0000 (08:38 +0000)
commit43687ba57c7d88063c6fa2df2386adbd1a0cf241
treecf41afecdf5634e880b7be536b11ca699fd22794
parenta647a2ae98151be8e2465b47cac6090a18f05a12
Attempt to guarantee that on copy-on-write faulting, the new copy
can't be written to while any thread can see the original version
of the page via a not-yet-flushed stale TLB entry: pmaps can indicate
they do this correctly by defining __HAVE_PMAP_MPSAFE_ENTER_COW;
uvm will force the initial CoW fault to be read-only otherwise.

Set that on amd64 and fix the problem case in pmap_enter() by putting
a read-only mapping in place, shooting the TLB entry, then fixing
it to the final read-write entry so this thread can continue without
re-faulting.

reported by jsing@ from https://github.com/golang/go/issues/34988
assisted by discussion in https://reviews.freebsd.org/D14347
tweaks from jsing@ and kettenis@

ok jsing@ mpi@ kettenis@
sys/arch/amd64/amd64/pmap.c
sys/arch/amd64/include/pmap.h
sys/uvm/uvm_fault.c