Skip to content

Commit

Permalink
mm,pmm: map percpu, idt and frames arrays in KERNEL_MAP area
Browse files Browse the repository at this point in the history
If there is not enough early frames (or for whatever reason the frame
physical address is big enough), it might be the case that such frame
mapping does not fit into the relatively small KERNEL_BASE area.
It is better to always map in the large enough KERNEL_MAP area.

The early frames arrays (before the final page tables are created)
have to be mapped into the KERNEL_BASE area as this is the only space
covered by boot time page tables (see EARLY_VIRT_MEM settings).

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Nov 24, 2023
1 parent 10d37ef commit 60d2f0d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion arch/x86/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void init_traps(const cpu_t *cpu) {

BUG_ON(!percpu);

percpu->idt = get_free_page(GFP_KERNEL | GFP_USER);
percpu->idt = get_free_page(GFP_KERNEL_MAP | GFP_USER);
BUG_ON(!percpu->idt);

percpu->idt_ptr.size = (sizeof(idt_entry_t) * MAX_INT) - 1;
Expand Down
2 changes: 1 addition & 1 deletion common/percpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ percpu_t *get_percpu_page(unsigned int cpu) {
/* Per CPU page must be identity mapped,
* because GDT descriptor has 32-bit base.
*/
percpu = get_free_page(GFP_IDENT | GFP_KERNEL | GFP_USER);
percpu = get_free_page(GFP_IDENT | GFP_KERNEL_MAP | GFP_USER);
BUG_ON(!percpu);
memset(percpu, 0, PAGE_SIZE);

Expand Down
6 changes: 4 additions & 2 deletions mm/pmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static frames_array_t *new_frames_array(void) {
if (!boot_flags.virt)
array = (frames_array_t *) mfn_to_virt_kern(frame->mfn);
else {
array = vmap_kern_4k(mfn_to_virt_kern(frame->mfn), frame->mfn, L1_PROT);
array = vmap_kern_4k(mfn_to_virt_map(frame->mfn), frame->mfn, L1_PROT);
if (!array)
goto error;
}
Expand Down Expand Up @@ -645,7 +645,9 @@ void map_frames_array(void) {

list_for_each_entry (array, &frames, list) {
mfn_t mfn = virt_to_mfn(array);
void *va = IS_ADDR_SPACE_VA(array, VIRT_KERNEL_BASE) ? mfn_to_virt_kern(mfn)
: mfn_to_virt_map(mfn);

BUG_ON(!vmap_kern_4k(mfn_to_virt_kern(mfn), mfn, L1_PROT));
BUG_ON(!vmap_kern_4k(va, mfn, L1_PROT));
}
}

0 comments on commit 60d2f0d

Please sign in to comment.