Skip to content

Commit bb82504

Browse files
JasonChenCJjren1
authored andcommitted
mmu: refine functions get_table_entry & obtain_last_page_table_entry
- remove unused map_params in get_table_entry - add error return for both, which is valid under release version, as at that time, ASSERT in get_table_entry is empty. Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent cbcc7c0 commit bb82504

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

hypervisor/arch/x86/mmu.c

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -346,27 +346,22 @@ static inline uint32_t check_page_table_present(struct map_params *map_params,
346346
return (table_entry) ? PT_PRESENT : PT_NOT_PRESENT;
347347
}
348348

349-
static uint64_t get_table_entry(struct map_params *map_params, void *addr,
350-
void *table_base, uint32_t table_level)
349+
static int get_table_entry(void *addr, void *table_base,
350+
uint32_t table_level, uint64_t *table_entry)
351351
{
352352
uint32_t table_offset;
353-
uint64_t table_entry;
354-
int status = 0;
355353

356-
if (table_base == NULL
357-
|| table_level >= IA32E_UNKNOWN
358-
|| map_params == NULL) {
359-
status = -EINVAL;
354+
if (table_base == NULL || table_level >= IA32E_UNKNOWN) {
355+
ASSERT(0, "Incorrect Arguments");
356+
return -EINVAL;
360357
}
361-
ASSERT(status == 0, "Incorrect Arguments");
362358

363359
table_offset = fetch_page_table_offset(addr, table_level);
364360

365361
/* Read the table entry */
366-
table_entry = MEM_READ64(table_base + table_offset);
362+
*table_entry = MEM_READ64(table_base + table_offset);
367363

368-
/* Return the next table in the walk */
369-
return table_entry;
364+
return 0;
370365
}
371366

372367
static void *walk_paging_struct(void *addr, void *table_base,
@@ -602,18 +597,20 @@ uint64_t config_page_table_attr(struct map_params *map_params, uint32_t flags)
602597

603598
}
604599

605-
void obtain_last_page_table_entry(struct map_params *map_params,
600+
int obtain_last_page_table_entry(struct map_params *map_params,
606601
struct entry_params *entry, void *addr, bool direct)
607602
{
608603
uint64_t table_entry;
609604
uint32_t table_present = 0;
605+
int ret = 0;
610606
/* Obtain the PML4 address */
611607
void *table_addr = direct ? (map_params->pml4_base)
612608
: (map_params->pml4_inverted);
613609

614610
/* Obtain page table entry from PML4 table*/
615-
table_entry = get_table_entry(map_params, addr,
616-
table_addr, IA32E_PML4);
611+
ret = get_table_entry(addr, table_addr, IA32E_PML4, &table_entry);
612+
if (ret < 0)
613+
return ret;
617614
table_present = check_page_table_present(map_params, table_entry);
618615
if (table_present == PT_NOT_PRESENT) {
619616
/* PML4E not present, return PML4 base address */
@@ -624,13 +621,14 @@ void obtain_last_page_table_entry(struct map_params *map_params,
624621
(PAGE_SIZE_1G) : (PAGE_SIZE_2M);
625622
entry->entry_off = fetch_page_table_offset(addr, IA32E_PML4);
626623
entry->entry_val = table_entry;
627-
return;
624+
return 0;
628625
}
629626

630627
/* Obtain page table entry from PDPT table*/
631628
table_addr = (void *)(table_entry & IA32E_REF_MASK);
632-
table_entry = get_table_entry(map_params, addr,
633-
table_addr, IA32E_PDPT);
629+
ret = get_table_entry(addr, table_addr, IA32E_PDPT, &table_entry);
630+
if (ret < 0)
631+
return ret;
634632
table_present = check_page_table_present(map_params, table_entry);
635633
if (table_present == PT_NOT_PRESENT) {
636634
/* PDPTE not present, return PDPT base address */
@@ -641,7 +639,7 @@ void obtain_last_page_table_entry(struct map_params *map_params,
641639
(PAGE_SIZE_1G) : (PAGE_SIZE_2M);
642640
entry->entry_off = fetch_page_table_offset(addr, IA32E_PDPT);
643641
entry->entry_val = table_entry;
644-
return;
642+
return 0;
645643
}
646644
if (table_entry & IA32E_PDPTE_PS_BIT) {
647645
/* 1GB page size, return the base addr of the pg entry*/
@@ -652,13 +650,14 @@ void obtain_last_page_table_entry(struct map_params *map_params,
652650
entry->entry_present = PT_PRESENT;
653651
entry->entry_off = fetch_page_table_offset(addr, IA32E_PDPT);
654652
entry->entry_val = table_entry;
655-
return;
653+
return 0;
656654
}
657655

658656
/* Obtain page table entry from PD table*/
659657
table_addr = (void *)(table_entry & IA32E_REF_MASK);
660-
table_entry = get_table_entry(map_params, addr,
661-
table_addr, IA32E_PD);
658+
ret = get_table_entry(addr, table_addr, IA32E_PD, &table_entry);
659+
if (ret < 0)
660+
return ret;
662661
table_present = check_page_table_present(map_params, table_entry);
663662
if (table_present == PT_NOT_PRESENT) {
664663
/* PDE not present, return PDE base address */
@@ -668,7 +667,7 @@ void obtain_last_page_table_entry(struct map_params *map_params,
668667
entry->page_size = PAGE_SIZE_2M;
669668
entry->entry_off = fetch_page_table_offset(addr, IA32E_PD);
670669
entry->entry_val = table_entry;
671-
return;
670+
return 0;
672671

673672
}
674673
if (table_entry & IA32E_PDE_PS_BIT) {
@@ -679,13 +678,14 @@ void obtain_last_page_table_entry(struct map_params *map_params,
679678
entry->page_size = PAGE_SIZE_2M;
680679
entry->entry_off = fetch_page_table_offset(addr, IA32E_PD);
681680
entry->entry_val = table_entry;
682-
return;
681+
return 0;
683682
}
684683

685684
/* Obtain page table entry from PT table*/
686685
table_addr = (void *)(table_entry & IA32E_REF_MASK);
687-
table_entry = get_table_entry(map_params, addr,
688-
table_addr, IA32E_PT);
686+
ret = get_table_entry(addr, table_addr, IA32E_PT, &table_entry);
687+
if (ret < 0)
688+
return ret;
689689
table_present = check_page_table_present(map_params, table_entry);
690690
entry->entry_present = ((table_present == PT_PRESENT)
691691
? (PT_PRESENT):(PT_NOT_PRESENT));
@@ -694,6 +694,8 @@ void obtain_last_page_table_entry(struct map_params *map_params,
694694
entry->page_size = PAGE_SIZE_4K;
695695
entry->entry_off = fetch_page_table_offset(addr, IA32E_PT);
696696
entry->entry_val = table_entry;
697+
698+
return 0;
697699
}
698700

699701
static uint64_t update_page_table_entry(struct map_params *map_params,
@@ -782,7 +784,11 @@ static uint64_t break_page_table(struct map_params *map_params, void *paddr,
782784
}
783785

784786
if (page_size != next_page_size) {
785-
obtain_last_page_table_entry(map_params, &entry, vaddr, direct);
787+
if (obtain_last_page_table_entry(map_params, &entry, vaddr,
788+
direct) < 0) {
789+
pr_err("Fail to obtain last page table entry");
790+
return 0;
791+
}
786792

787793
/* New entry present - need to allocate a new table */
788794
sub_tab_addr = alloc_paging_struct();
@@ -871,7 +877,9 @@ static int modify_paging(struct map_params *map_params, void *paddr,
871877
* MAP/UNMAP/MODIFY
872878
*/
873879
while (remaining_size > 0) {
874-
obtain_last_page_table_entry(map_params, &entry, vaddr, direct);
880+
if (obtain_last_page_table_entry(map_params, &entry, vaddr,
881+
direct) < 0)
882+
return -EINVAL;
875883
/* filter the unmap request, no action in this case*/
876884
page_size = entry.page_size;
877885
if ((request_type == PAGING_REQUEST_TYPE_UNMAP)

hypervisor/include/arch/x86/mmu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ int modify_mem(struct map_params *map_params, void *paddr, void *vaddr,
326326
uint64_t size, uint32_t flags);
327327
void mmu_invept(struct vcpu *vcpu);
328328
bool check_continuous_hpa(struct vm *vm, uint64_t gpa, uint64_t size);
329-
void obtain_last_page_table_entry(struct map_params *map_params,
329+
int obtain_last_page_table_entry(struct map_params *map_params,
330330
struct entry_params *entry, void *addr, bool direct);
331331

332332
int register_mmio_emulation_handler(struct vm *vm,

0 commit comments

Comments
 (0)