Skip to content

Commit 481f662

Browse files
committed
hv_vm: Fix CTRR hugepage issue
This is the hypervisor counterpart to da9cedd. Signed-off-by: Hector Martin <[email protected]>
1 parent 2389fa9 commit 481f662

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/hv_vm.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "uartproxy.h"
1515
#include "utils.h"
1616

17+
extern uint64_t ram_base;
18+
1719
#define PAGE_SIZE 0x4000
1820
#define CACHE_LINE_SIZE 64
1921
#define CACHE_LINE_LOG2 6
@@ -325,8 +327,12 @@ int hv_map(u64 from, u64 to, u64 size, u64 incr)
325327
}
326328

327329
// L3 mappings to boundary
328-
chunk = ALIGN_DOWN(min(size, ALIGN_UP(from, BIT(VADDR_L2_OFFSET_BITS)) - from),
329-
BIT(VADDR_L3_OFFSET_BITS));
330+
u64 boundary = ALIGN_UP(from, MASK(VADDR_L2_OFFSET_BITS));
331+
// CPU CTRR doesn't like L2 mappings crossing CTRR boundaries!
332+
// Map everything below the m1n1 base as L3
333+
if (boundary >= ram_base && boundary < (u64)_base)
334+
boundary = ALIGN_UP((u64)_base, MASK(VADDR_L2_OFFSET_BITS));
335+
chunk = ALIGN_DOWN(min(size, boundary - from), BIT(VADDR_L3_OFFSET_BITS));
330336
if (chunk) {
331337
hv_pt_map_l3(from, to, chunk, incr);
332338
from += chunk;

0 commit comments

Comments
 (0)