Skip to content

Commit c2f86f2

Browse files
JasonChenCJjren1
authored andcommitted
mmu: refine functions walk_paging_struct & update_page_table_entry
- walk_paging_struct should return sub_table_addr, if something wrong, it return NULL - update_page_table_entry should return adjusted_size, if something wrong it return 0 the change is valid under release version, as at that time, ASSERT in walk_paging_struct is empty. Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent bb82504 commit c2f86f2

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

hypervisor/arch/x86/mmu.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ static int get_table_entry(void *addr, void *table_base,
364364
return 0;
365365
}
366366

367-
static void *walk_paging_struct(void *addr, void *table_base,
367+
static void *walk_paging_struct(void *addr, void *table_base,
368368
uint32_t table_level, struct map_params *map_params)
369369
{
370370
uint32_t table_offset;
@@ -373,14 +373,13 @@ static void *walk_paging_struct(void *addr, void *table_base,
373373
/* if table_level == IA32E_PT Just return the same address
374374
* can't walk down any further
375375
*/
376-
void *sub_table_addr = ((table_level == IA32E_PT) ? table_base:NULL);
377-
int status = 0;
376+
void *sub_table_addr = (table_level == IA32E_PT) ? table_base : NULL;
378377

379378
if (table_base == NULL || table_level >= IA32E_UNKNOWN
380379
|| map_params == NULL) {
381-
status = -EINVAL;
380+
ASSERT(0, "Incorrect Arguments");
381+
return NULL;
382382
}
383-
ASSERT(status == 0, "Incorrect Arguments");
384383

385384
table_offset = fetch_page_table_offset(addr, table_level);
386385

@@ -404,18 +403,16 @@ static void *walk_paging_struct(void *addr, void *table_base,
404403
/* Determine if a valid entry exists */
405404
if ((table_entry & table_present) == 0) {
406405
/* No entry present - need to allocate a new table */
407-
sub_table_addr =
408-
alloc_paging_struct();
406+
sub_table_addr = alloc_paging_struct();
409407
/* Check to ensure memory available for this structure*/
410-
if (sub_table_addr == 0) {
408+
if (sub_table_addr == NULL) {
411409
/* Error: Unable to find table memory necessary
412410
* to map memory
413411
*/
414-
ASSERT(sub_table_addr == 0,
415-
"Fail to find table memory "
412+
ASSERT(0, "Fail to alloc table memory "
416413
"for map memory");
417414

418-
return sub_table_addr;
415+
return NULL;
419416
}
420417

421418
/* Write entry to current table to reference the new
@@ -712,6 +709,8 @@ static uint64_t update_page_table_entry(struct map_params *map_params,
712709
/* Walk from the PML4 table to the PDPT table */
713710
table_addr = walk_paging_struct(vaddr, table_addr, IA32E_PML4,
714711
map_params);
712+
if (table_addr == NULL)
713+
return 0;
715714

716715
if ((remaining_size >= MEM_1G)
717716
&& (MEM_ALIGNED_CHECK(vaddr, MEM_1G))
@@ -727,6 +726,8 @@ static uint64_t update_page_table_entry(struct map_params *map_params,
727726
/* Walk from the PDPT table to the PD table */
728727
table_addr = walk_paging_struct(vaddr, table_addr,
729728
IA32E_PDPT, map_params);
729+
if (table_addr == NULL)
730+
return 0;
730731
/* Map this 2 MByte memory region */
731732
adjustment_size = map_mem_region(vaddr, paddr,
732733
table_addr, attr, IA32E_PD, table_type,
@@ -735,17 +736,20 @@ static uint64_t update_page_table_entry(struct map_params *map_params,
735736
/* Walk from the PDPT table to the PD table */
736737
table_addr = walk_paging_struct(vaddr,
737738
table_addr, IA32E_PDPT, map_params);
739+
if (table_addr == NULL)
740+
return 0;
738741
/* Walk from the PD table to the page table */
739742
table_addr = walk_paging_struct(vaddr,
740743
table_addr, IA32E_PD, map_params);
744+
if (table_addr == NULL)
745+
return 0;
741746
/* Map this 4 KByte memory region */
742747
adjustment_size = map_mem_region(vaddr, paddr,
743748
table_addr, attr, IA32E_PT,
744749
table_type, request_type);
745750
}
746751

747752
return adjustment_size;
748-
749753
}
750754

751755
static uint64_t break_page_table(struct map_params *map_params, void *paddr,
@@ -918,6 +922,8 @@ static int modify_paging(struct map_params *map_params, void *paddr,
918922
/* The function return the memory size that one entry can map */
919923
adjust_size = update_page_table_entry(map_params, paddr, vaddr,
920924
page_size, attr, request_type, direct);
925+
if (adjust_size == 0)
926+
return -EINVAL;
921927
vaddr += adjust_size;
922928
paddr += adjust_size;
923929
remaining_size -= adjust_size;

0 commit comments

Comments
 (0)