mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-06 13:09:50 +00:00
vm_page: Fix a logic bug in vm_page_unwire_managed()
When releasing a page reference, we have logic for various cases, based on the value of the counter. But, the implementation fails to take into account the possibility that the VPRC_BLOCKED flag is set, which is ORed into the counter for short windows when removing mappings of a page. If the flag is set while the last reference is being released, we may fail to add the page to a page queue when the last wiring reference is released. Fix the problem by performing comparisons with VPRC_BLOCKED masked off. While here, add a related assertion. Reviewed by: dougm, kib Tested by: pho MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D46944
This commit is contained in:
parent
d8b32da235
commit
c59166e5b4
@ -4275,10 +4275,13 @@ vm_page_unwire_managed(vm_page_t m, uint8_t nqueue, bool noreuse)
|
||||
*/
|
||||
old = atomic_load_int(&m->ref_count);
|
||||
do {
|
||||
u_int count;
|
||||
|
||||
KASSERT(VPRC_WIRE_COUNT(old) > 0,
|
||||
("vm_page_unwire: wire count underflow for page %p", m));
|
||||
|
||||
if (old > VPRC_OBJREF + 1) {
|
||||
count = old & ~VPRC_BLOCKED;
|
||||
if (count > VPRC_OBJREF + 1) {
|
||||
/*
|
||||
* The page has at least one other wiring reference. An
|
||||
* earlier iteration of this loop may have called
|
||||
@ -4287,7 +4290,7 @@ vm_page_unwire_managed(vm_page_t m, uint8_t nqueue, bool noreuse)
|
||||
*/
|
||||
if ((vm_page_astate_load(m).flags & PGA_DEQUEUE) == 0)
|
||||
vm_page_aflag_set(m, PGA_DEQUEUE);
|
||||
} else if (old == VPRC_OBJREF + 1) {
|
||||
} else if (count == VPRC_OBJREF + 1) {
|
||||
/*
|
||||
* This is the last wiring. Clear PGA_DEQUEUE and
|
||||
* update the page's queue state to reflect the
|
||||
@ -4296,7 +4299,7 @@ vm_page_unwire_managed(vm_page_t m, uint8_t nqueue, bool noreuse)
|
||||
* clear leftover queue state.
|
||||
*/
|
||||
vm_page_release_toq(m, nqueue, noreuse);
|
||||
} else if (old == 1) {
|
||||
} else if (count == 1) {
|
||||
vm_page_aflag_clear(m, PGA_DEQUEUE);
|
||||
}
|
||||
} while (!atomic_fcmpset_rel_int(&m->ref_count, &old, old - 1));
|
||||
@ -4572,6 +4575,8 @@ vm_page_try_blocked_op(vm_page_t m, void (*op)(vm_page_t))
|
||||
do {
|
||||
KASSERT(old != 0,
|
||||
("vm_page_try_blocked_op: page %p has no references", m));
|
||||
KASSERT((old & VPRC_BLOCKED) == 0,
|
||||
("vm_page_try_blocked_op: page %p blocks wirings", m));
|
||||
if (VPRC_WIRE_COUNT(old) != 0)
|
||||
return (false);
|
||||
} while (!atomic_fcmpset_int(&m->ref_count, &old, old | VPRC_BLOCKED));
|
||||
|
Loading…
Reference in New Issue
Block a user