Commit Graph

2306 Commits

Author SHA1 Message Date
chs d54dda5c99 uvm: avoid a deadlock in uvm_map_clean()
The locking order between map locks and page "busy" locks
is that the page "busy" lock comes first, but uvm_map_clean()
breaks this rule by holding a map locked (as reader) while
waiting for page "busy" locks.

If another thread is in the page-fault path holding a page
"busy" lock while waiting for the map lock (as a reader)
and at the same time a third thread is blocked waiting for
the map lock as a writer (which blocks the page-fault thread),
then these three threads will all deadlock with each other.

Fix this by marking the map "busy" (to block any modifications)
and unlocking the map lock before possibly waiting for any
page "busy" locks.

Martin Pieuchot reported that the same problem existed in OpenBSD
he applied this fix there after several people tested it.

fixes PR 56952
2023-05-15 01:42:42 +00:00
skrll 6fc09aadfb Correct a type. 2023-04-27 06:23:31 +00:00
skrll 1144d080df KASSERT(kpreempt_disabled()) before accessing curcpu() 2023-04-22 10:22:43 +00:00
skrll 6d5cf3578a Provide a shared pmap_devmap implementation and convert all pmap_devmap
arrays to use DEVMAP_ENTRY{,_END}
2023-04-20 08:28:02 +00:00
riastradh a812fa9bc4 uvm: Simplify assertion in uvn_get.
No functional change intended.
2023-04-09 12:37:12 +00:00
riastradh a83cdbec2d uvm(9): KASSERT(A && B) -> KASSERT(A); KASSERT(B) 2023-04-09 09:00:56 +00:00
skrll 758cf29b56 Unwrap. NFCI. 2023-03-24 07:26:21 +00:00
riastradh e088bb05d6 uvm(9): KASSERT(A && B) -> KASSERT(A); KASSERT(B)
While here, print some of the inputs with KASSERTMSG.
2023-02-27 16:24:45 +00:00
skrll c1da2a84d2 nkmempages should be size_t 2023-02-26 07:27:14 +00:00
skrll c591e46de3 ci_data.cpu_kcpuset -> ci_kcpuset
NFCI.
2023-02-26 07:13:54 +00:00
riastradh 943e1fb0b5 uvm: Eliminate __HAVE_ATOMIC_AS_MEMBAR conditionals.
Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/02/23/msg028729.html
2023-02-24 11:03:13 +00:00
skrll 42edd8d163 Spaces to TABs. NFCI. 2023-02-19 07:20:44 +00:00
andvar 6c0e29fbe8 s/strucure/structure/ and s/structues/structures/ in comments. 2023-02-12 16:28:32 +00:00
skrll ea44ee84ea Rename pmap_md_pdetab_destroy to pmap_md_pdetab_fini to match
pmap_md_pdetab_init.

Call pmap_md_pdetab_fini from pmap_segtab_destroy.
2022-12-21 11:39:45 +00:00
chs 1f3bc2830b swap: disallow user opens of swap block device
the swap/drum block device was never intended to allow user opens,
but when the internal VOP_OPEN() in uvm_swap_init() was added
back in rev 1.135, the d_open method was changed from always-fail
to always-succeed in order to allow the new initial internal open.
this had the side effect of incorrectly allowing user opens too.
fix this by replacing the swap_bdevsw d_open with one that succeeds
for the first call but fails for all subsequent calls.

Reported-by: syzbot+90a23d2f19e5a0a302b3@syzkaller.appspotmail.com
2022-12-21 02:28:06 +00:00
riastradh 4d78161c33 mmap(2): Avoid arithmetic overflow in search for free space.
PR kern/56900

Reported-by: syzbot+3833ae1d38037a263d05@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=e542bcf59b2564cca1cb38c12f076fb08dcac37e
2022-11-23 23:53:53 +00:00
skrll a0cae18fb0 Fix UVMHIST build 2022-11-07 07:28:04 +00:00
skrll fce798eb46 _KERNEL_OPT protection 2022-11-03 18:55:07 +00:00
skrll a856f9893d Provide MI PMAP support on AARCH64 2022-11-03 09:04:56 +00:00
skrll 2a9964a259 KNF 2022-11-02 08:05:17 +00:00
skrll 8d974145b5 MI PMAP EFI_RUNTIME support 2022-10-28 07:16:34 +00:00
skrll be8a8777f1 In pmap_pte_reserve ensure we're atomically swapping out an invalid entry
otherwise concurrent updates might both think they've updated the entry.
2022-10-27 06:49:51 +00:00
skrll 948f90cbac No need to hold the pmap_tlb_miss_lock when calling pmap_segtab_destroy 2022-10-27 06:20:41 +00:00
skrll 35768640eb Rename pm_count to pm_refcnt 2022-10-27 06:19:56 +00:00
skrll 8d7ffa28f6 Fix the crash(1) build for mips platforms 2022-10-27 05:33:37 +00:00
riastradh dbfa10e52a ddb/db_active.h: New home for extern db_active.
This can be included unconditionally, and db_active can then be
queried unconditionally; if DDB is not in the kernel, then db_active
is a constant zero.  Reduces need for #include opt_ddb.h, #ifdef DDB.
2022-10-26 23:38:05 +00:00
riastradh 2cfaa2f6ca sys/kernel.h: New home for extern start_init_exec. 2022-10-26 23:27:32 +00:00
skrll 196ee94dc2 MI PMAP hardware page table walker support.
This is based on code given to me by Matt Thomas a long time ago with
many updates and bugs fixes from me.
2022-10-26 07:35:19 +00:00
skrll 652d189961 Correct the pmap_kstart_segtab entry in pmap_kern_segtab 2022-10-23 06:37:15 +00:00
skrll a8b51939bd Add a KASSERT to check that tlb_asid_t is a large enough type. 2022-10-20 06:24:51 +00:00
skrll 1974c7e705 Rename pmap_segtab_t *stp to stb for consistency with a future
pmap_pdetab_t *ptb. pmap_pdetab_t *ptp would be far too confusing.

NFC. Same code before and after.
2022-09-25 06:21:58 +00:00
skrll 5110c8f250 whitespace - remove spaces before tabs 2022-09-15 06:44:18 +00:00
skrll 2b807ab842 A simplification and some minor whitespace 2022-09-12 07:38:32 +00:00
riastradh ffbd2bca51 uvm_pdpolicy.h: Fix missing forward declarations and includes. 2022-08-20 23:26:02 +00:00
riastradh 7cc851291f uvm/uvm_pmap.h: Fix missing types and forward declarations.
- Need sys/types.h for vaddr_t, paddr_t, u_int, &c.
- Forward-declare struct vm_page so we don't have to rely on
  machine/pmap.h to do so.
2022-08-20 23:08:53 +00:00
chs 1369379d41 allow KMSAN to work again by restoring the limiting of kva even with
NKMEMPAGES_MAX_UNLIMITED.  we used to limit kva to 1/8 of physmem
but limiting to 1/4 should be enough, and 1/4 still gives the kernel
enough kva to map all of the RAM that KMSAN has not stolen.

Reported-by: syzbot+ca3710b4c40cdd61aa72@syzkaller.appspotmail.com
2022-08-06 05:55:37 +00:00
chs f39adc8860 for platforms which define NKMEMPAGES_MAX_UNLIMITED, set nkmempages
high enough to allow the kernel to map all of RAM into kmem,
so that free physical pages rather than kernel virtual space is
the limiting factor in allocating kernel memory.  this gives ZFS
more flexibility in tuning how much memory to use for its ARC cache.
2022-08-03 01:52:11 +00:00
riastradh 0fdc653939 uvm: CTASSERT about MIN_PAGE_SIZE, which is constant. 2022-07-07 13:27:02 +00:00
rin e9bfa3f40e Convert CTASSERT(9) for PAGE_{SIZE,MASK} into KASSERT(9).
They are not compile-time constants for sparc.
2022-07-07 11:29:18 +00:00
riastradh c39ca7f41a kern: Work around spurious -Wtype-limits warnings.
This useless garbage warning is apparently designed to make it
painful to write portable safe arithmetic and I think we ought to
just disable it.
2022-07-06 13:52:24 +00:00
riastradh 3f844e8417 mmap(2): Guarantee two's-complement wraparound for D_NEGOFFSAFE.
XXX Not sure this should be allowed at all, but this way we don't
change the semantics of the existing code which was written under
essentially the assumption of -fwrapv.
2022-07-06 01:16:36 +00:00
riastradh 58c59e79d6 uvm/uvm_device.c: Sprinkle KNF. 2022-07-06 01:15:51 +00:00
riastradh 583a8e6e3a mmap(2): Prohibit overflowing offsets for non-D_NEGOFFSAFE devices.
Reported-by: syzbot+d5a96e7a0ebbd0b76dfc@syzkaller.appspotmail.com
2022-07-06 01:13:30 +00:00
riastradh 1dc3d718d7 uvm(9): fo_mmap caller guarantees positive size.
No functional change intended, just sprinkling assertions to make it
clearer.
2022-07-06 01:12:45 +00:00
riastradh c9e9a8867f mmap(2): Assert size != 0 in non-anonymous case.
This is guaranteed by a test earlier; adding the assertion just makes
it clearer that it applies to the branch where we call fo_mmap -- no
functional change intended.
2022-07-06 00:40:28 +00:00
riastradh c13bf49fbb mmap(2): Avoid overflow in rounding and checking size. 2022-07-06 00:40:16 +00:00
macallan c0f61075ad initialize a variable to appease clang 2022-06-08 16:55:00 +00:00
rin 0685b389ae PR kern/51254
uvm_map_findspace(): Output current value of "entry" when KASSERT fires.
2022-06-06 07:00:02 +00:00
riastradh fe47d13dc0 uvm(9): Sprinkle assertions into uvm_map_findspace.
May help to diagnose PR kern/51254.
2022-06-05 13:45:28 +00:00
riastradh ccc4828b62 uvm(9): Don't duplicate vm_map_min/max in `show map' output.
Didn't notice these were already there, oops!
2022-06-05 01:45:45 +00:00