Skip to content

Commit

Permalink
pmm: get_free_frames() returns frame_t pointer instead of mfn
Browse files Browse the repository at this point in the history
Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Aug 13, 2021
1 parent 5a6413f commit 1898c26
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
10 changes: 8 additions & 2 deletions arch/x86/pagetables.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ static mfn_t get_cr3_mfn(cr3_t *cr3_entry) {
void *cr3_mapped = NULL;

if (mfn_invalid(cr3_entry->mfn)) {
cr3_entry->mfn = get_free_frame();
frame_t *frame = get_free_frame();
BUG_ON(!frame);

cr3_entry->mfn = frame->mfn;
cr3_mapped = init_map_mfn(cr3_entry->mfn);
memset(cr3_mapped, 0, PAGE_SIZE);
}
Expand All @@ -137,7 +140,10 @@ static mfn_t get_pgentry_mfn(mfn_t tab_mfn, pt_index_t index, unsigned long flag

mfn = mfn_from_pgentry(*entry);
if (mfn_invalid(mfn)) {
set_pgentry(entry, get_free_frame(), flags);
frame_t *frame = get_free_frame();
BUG_ON(!frame);

set_pgentry(entry, frame->mfn, flags);
mfn = mfn_from_pgentry(*entry);
tab = init_map_mfn(mfn);
memset(tab, 0, PAGE_SIZE);
Expand Down
4 changes: 2 additions & 2 deletions include/mm/pmm.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern void display_frames_count(void);
extern void init_pmm(void);

extern frame_t *get_free_frames_cond(free_frames_cond_t cb);
extern mfn_t get_free_frames(unsigned int order);
extern frame_t *get_free_frames(unsigned int order);
extern void put_frame(mfn_t mfn, unsigned int order);
extern void reclaim_frame(mfn_t mfn, unsigned int order);

Expand All @@ -62,7 +62,7 @@ static inline bool paddr_invalid(paddr_t pa) {

static inline bool mfn_invalid(mfn_t mfn) { return paddr_invalid(mfn_to_paddr(mfn)); }

static inline mfn_t get_free_frame(void) { return get_free_frames(PAGE_ORDER_4K); }
static inline frame_t *get_free_frame(void) { return get_free_frames(PAGE_ORDER_4K); }

#endif /* __ASSEMBLY__ */

Expand Down
10 changes: 5 additions & 5 deletions mm/pmm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2020 Amazon.com, Inc. or its affiliates.
* Copyright © 2021 Amazon.com, Inc. or its affiliates.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -188,22 +188,22 @@ frame_t *get_free_frames_cond(free_frames_cond_t cb) {
return NULL;
}

mfn_t get_free_frames(unsigned int order) {
frame_t *get_free_frames(unsigned int order) {
frame_t *frame;

if (order > MAX_PAGE_ORDER)
return MFN_INVALID;
return NULL;

if (list_is_empty(&free_frames[order])) {
/* FIXME: Add page split */
return MFN_INVALID;
return NULL;
}

frame = list_first_entry(&free_frames[order], frame_t, list);

frame = reserve_frame(frame, order);

return frame->mfn;
return frame;
}

void put_frame(mfn_t mfn, unsigned int order) {
Expand Down
7 changes: 5 additions & 2 deletions mm/vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
#include <mm/vmm.h>

void *get_free_pages(unsigned int order, uint32_t flags) {
mfn_t mfn = get_free_frames(order);
frame_t *frame = get_free_frames(order);
void *va = NULL;
mfn_t mfn;

if (mfn_invalid(mfn))
if (!frame)
return NULL;

mfn = frame->mfn;

if (flags & GFP_IDENT)
va = vmap(mfn_to_virt(mfn), mfn, order, L4_PROT, L3_PROT, L2_PROT, L1_PROT);
if (flags & GFP_USER)
Expand Down

0 comments on commit 1898c26

Please sign in to comment.