HV: panic on 0 address when do e820_alloc_memory

Current memory allocation algorithm is to find the available address from
the highest possible address below max_address. If the function returns 0,
means all memory is used up and we have to put the resource at address 0,
this is dangerous for a running hypervisor.

Also returns 0 would make code logic very complicated, since memcpy_s()
doesn't support address 0 copy.

Tracked-On: #5626

Signed-off-by: Victor Sun <victor.sun@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
This commit is contained in:
Victor Sun 2021-02-24 11:49:20 +08:00 committed by wenlingz
parent 2e72bb97e7
commit 26abc82f3c

View File

@ -115,7 +115,13 @@ uint64_t e820_alloc_memory(uint32_t size_arg, uint64_t max_addr)
}
}
if (ret == INVALID_HPA) {
if ((ret == INVALID_HPA) || (ret == 0UL)) {
/* current memory allocation algorithm is to find the available address from the highest
* possible address below max_addr. if ret == 0, means all memory is used up and we have to
* put the resource at address 0, this is dangerous.
* Also ret == 0 would make code logic very complicated, since memcpy_s() doesn't support
* address 0 copy.
*/
panic("Requested memory from E820 cannot be reserved!!");
}