From 67f185ecf51be1c56de5f46c9c1a9bc9bf97299e Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 12 Dec 2018 10:55:43 -0500 Subject: [PATCH] kernel: Don't retry or wait for the low_resource handler. As axeld pointed out on the mailing list, map_backing_store is called with the address space write-locked, and so the resources won't be released until after we return. Due to the state we are in at this point, unlocking the address space before making this call would be likely be very dangerous, and so simply issuing the notification and then returning an error is all we can safely do here. --- src/system/kernel/vm/vm.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 4e35366f57..bc256bc886 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -872,13 +872,12 @@ map_backing_store(VMAddressSpace* addressSpace, VMCache* cache, off_t offset, status = addressSpace->InsertArea(area, size, addressRestrictions, allocationFlags, _virtualAddress); if (status == B_NO_MEMORY - && addressRestrictions->address_specification == B_ANY_KERNEL_ADDRESS) { - // issue a low resource notification and try again - low_resource(B_KERNEL_RESOURCE_ADDRESS_SPACE, size, B_RELATIVE_TIMEOUT, - ((flags & CREATE_AREA_DONT_WAIT) != 0) ? 0 : 100000 /* 100ms*/); - - status = addressSpace->InsertArea(area, size, addressRestrictions, - allocationFlags, _virtualAddress); + && addressRestrictions->address_specification == B_ANY_KERNEL_ADDRESS) { + // Since the kernel address space is locked by the caller, we can't + // wait here as of course no resources can be released while the locks + // are held. But we can at least issue this so the next caller doesn't + // run into the same problem. + low_resource(B_KERNEL_RESOURCE_ADDRESS_SPACE, size, 0, 0); } if (status != B_OK) goto err2;