]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/common/paging.c: Flush TLB only if we are modifying current PT
authorSergiu Moga <sergiu.moga@protonmail.com>
Tue, 18 Apr 2023 11:13:59 +0000 (14:13 +0300)
committerUnikraft <monkey@unikraft.io>
Fri, 11 Aug 2023 10:18:45 +0000 (10:18 +0000)
Flushing the TLB introduces an unnecessary performance penalty if we
are modifying a page table that is different from our current one.
Therefore, ensure that the TLB is flushed only if the page table we
are currently modifying is the same as the one we currently have
active.

Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #848

plat/common/paging.c

index fb5cd9f613caeb4ee358faf7a8cbbf6cec29701e..31c65239fd5e28765f63504bc4d85f39859eec98 100644 (file)
@@ -741,7 +741,7 @@ TOO_BIG:
                        pt->nr_lx_pages[lvl]++;
 #endif /* CONFIG_PAGING_STATS */
 
-               if (PT_Lx_PTE_PRESENT(orig_pte, lvl))
+               if (PT_Lx_PTE_PRESENT(orig_pte, lvl) && pt == pg_active_pt)
                        ukarch_tlb_flush_entry(vaddr);
 
 NEXT_PTE:
@@ -1042,7 +1042,7 @@ static int pg_page_unmap(struct uk_pagetable *pt, __vaddr_t pt_vaddr,
                        if (unlikely(rc))
                                return rc;
 
-                       if (vaddr != __VADDR_ANY)
+                       if (vaddr != __VADDR_ANY && pt == pg_active_pt)
                                ukarch_tlb_flush_entry(vaddr);
 
 #ifdef CONFIG_PAGING_STATS
@@ -1152,7 +1152,7 @@ static int pg_page_unmap(struct uk_pagetable *pt, __vaddr_t pt_vaddr,
                        if (unlikely(rc))
                                return rc;
 
-                       if (vaddr != __VADDR_ANY)
+                       if (vaddr != __VADDR_ANY && pt == pg_active_pt)
                                ukarch_tlb_flush_entry(vaddr);
 
                        pg_pt_free(pt, pt_vaddr_cache[plvl], plvl);
@@ -1176,7 +1176,7 @@ static int pg_page_unmap(struct uk_pagetable *pt, __vaddr_t pt_vaddr,
 
        } while (1);
 
-       if (vaddr == __VADDR_ANY)
+       if (vaddr == __VADDR_ANY && pt == pg_active_pt)
                ukarch_tlb_flush();
 
        return 0;
@@ -1314,7 +1314,7 @@ static int pg_page_set_attr(struct uk_pagetable *pt, __vaddr_t pt_vaddr,
                        if (unlikely(rc))
                                return rc;
 
-                       if (vaddr != __VADDR_ANY)
+                       if (vaddr != __VADDR_ANY && pt == pg_active_pt)
                                ukarch_tlb_flush_entry(vaddr);
                }
 
@@ -1354,7 +1354,7 @@ static int pg_page_set_attr(struct uk_pagetable *pt, __vaddr_t pt_vaddr,
 
        } while (1);
 
-       if (vaddr == __VADDR_ANY)
+       if (vaddr == __VADDR_ANY && pt == pg_active_pt)
                ukarch_tlb_flush();
 
        return 0;