@@ -346,27 +346,22 @@ static inline uint32_t check_page_table_present(struct map_params *map_params,
346
346
return (table_entry ) ? PT_PRESENT : PT_NOT_PRESENT ;
347
347
}
348
348
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 )
351
351
{
352
352
uint32_t table_offset ;
353
- uint64_t table_entry ;
354
- int status = 0 ;
355
353
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 ;
360
357
}
361
- ASSERT (status == 0 , "Incorrect Arguments" );
362
358
363
359
table_offset = fetch_page_table_offset (addr , table_level );
364
360
365
361
/* Read the table entry */
366
- table_entry = MEM_READ64 (table_base + table_offset );
362
+ * table_entry = MEM_READ64 (table_base + table_offset );
367
363
368
- /* Return the next table in the walk */
369
- return table_entry ;
364
+ return 0 ;
370
365
}
371
366
372
367
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)
602
597
603
598
}
604
599
605
- void obtain_last_page_table_entry (struct map_params * map_params ,
600
+ int obtain_last_page_table_entry (struct map_params * map_params ,
606
601
struct entry_params * entry , void * addr , bool direct )
607
602
{
608
603
uint64_t table_entry ;
609
604
uint32_t table_present = 0 ;
605
+ int ret = 0 ;
610
606
/* Obtain the PML4 address */
611
607
void * table_addr = direct ? (map_params -> pml4_base )
612
608
: (map_params -> pml4_inverted );
613
609
614
610
/* 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 ;
617
614
table_present = check_page_table_present (map_params , table_entry );
618
615
if (table_present == PT_NOT_PRESENT ) {
619
616
/* PML4E not present, return PML4 base address */
@@ -624,13 +621,14 @@ void obtain_last_page_table_entry(struct map_params *map_params,
624
621
(PAGE_SIZE_1G ) : (PAGE_SIZE_2M );
625
622
entry -> entry_off = fetch_page_table_offset (addr , IA32E_PML4 );
626
623
entry -> entry_val = table_entry ;
627
- return ;
624
+ return 0 ;
628
625
}
629
626
630
627
/* Obtain page table entry from PDPT table*/
631
628
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 ;
634
632
table_present = check_page_table_present (map_params , table_entry );
635
633
if (table_present == PT_NOT_PRESENT ) {
636
634
/* PDPTE not present, return PDPT base address */
@@ -641,7 +639,7 @@ void obtain_last_page_table_entry(struct map_params *map_params,
641
639
(PAGE_SIZE_1G ) : (PAGE_SIZE_2M );
642
640
entry -> entry_off = fetch_page_table_offset (addr , IA32E_PDPT );
643
641
entry -> entry_val = table_entry ;
644
- return ;
642
+ return 0 ;
645
643
}
646
644
if (table_entry & IA32E_PDPTE_PS_BIT ) {
647
645
/* 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,
652
650
entry -> entry_present = PT_PRESENT ;
653
651
entry -> entry_off = fetch_page_table_offset (addr , IA32E_PDPT );
654
652
entry -> entry_val = table_entry ;
655
- return ;
653
+ return 0 ;
656
654
}
657
655
658
656
/* Obtain page table entry from PD table*/
659
657
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 ;
662
661
table_present = check_page_table_present (map_params , table_entry );
663
662
if (table_present == PT_NOT_PRESENT ) {
664
663
/* PDE not present, return PDE base address */
@@ -668,7 +667,7 @@ void obtain_last_page_table_entry(struct map_params *map_params,
668
667
entry -> page_size = PAGE_SIZE_2M ;
669
668
entry -> entry_off = fetch_page_table_offset (addr , IA32E_PD );
670
669
entry -> entry_val = table_entry ;
671
- return ;
670
+ return 0 ;
672
671
673
672
}
674
673
if (table_entry & IA32E_PDE_PS_BIT ) {
@@ -679,13 +678,14 @@ void obtain_last_page_table_entry(struct map_params *map_params,
679
678
entry -> page_size = PAGE_SIZE_2M ;
680
679
entry -> entry_off = fetch_page_table_offset (addr , IA32E_PD );
681
680
entry -> entry_val = table_entry ;
682
- return ;
681
+ return 0 ;
683
682
}
684
683
685
684
/* Obtain page table entry from PT table*/
686
685
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 ;
689
689
table_present = check_page_table_present (map_params , table_entry );
690
690
entry -> entry_present = ((table_present == PT_PRESENT )
691
691
? (PT_PRESENT ):(PT_NOT_PRESENT ));
@@ -694,6 +694,8 @@ void obtain_last_page_table_entry(struct map_params *map_params,
694
694
entry -> page_size = PAGE_SIZE_4K ;
695
695
entry -> entry_off = fetch_page_table_offset (addr , IA32E_PT );
696
696
entry -> entry_val = table_entry ;
697
+
698
+ return 0 ;
697
699
}
698
700
699
701
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,
782
784
}
783
785
784
786
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
+ }
786
792
787
793
/* New entry present - need to allocate a new table */
788
794
sub_tab_addr = alloc_paging_struct ();
@@ -871,7 +877,9 @@ static int modify_paging(struct map_params *map_params, void *paddr,
871
877
* MAP/UNMAP/MODIFY
872
878
*/
873
879
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 ;
875
883
/* filter the unmap request, no action in this case*/
876
884
page_size = entry .page_size ;
877
885
if ((request_type == PAGING_REQUEST_TYPE_UNMAP )
0 commit comments