From 33a7b3bb47e8e6ac7b571ee30a2b2fd0314a8502 Mon Sep 17 00:00:00 2001 From: yangwencheng Date: Fri, 20 Oct 2023 16:56:49 -0400 Subject: [PATCH] anolis: x86/mm: Merge contiguous pages into a large range when notifying pages enc status changes ANBZ: #29355 It's not performance friendly in the loop invoking notify_page_enc_status_changed() just handling one page, if those pages are physically contiguous, merge them into a large range to get better performance. Hygon-SIG: commit none hygon x86/mm: Merge contiguous pages into a large range when notifying pages enc status changes Signed-off-by: yangwencheng Signed-off-by: hanliyang Cc: hygon-arch@list.openanolis.cn --- arch/x86/mm/mem_encrypt_amd.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index fb949b2c200d..394d79998101 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -294,6 +294,8 @@ static void enc_dec_hypercall(unsigned long vaddr, unsigned long size, bool enc) { #ifdef CONFIG_PARAVIRT unsigned long vaddr_end = vaddr + size; + unsigned long pfn_beg = 0; + unsigned long size_cont = 0; while (vaddr < vaddr_end) { int psize, pmask, level; @@ -313,10 +315,29 @@ static void enc_dec_hypercall(unsigned long vaddr, unsigned long size, bool enc) psize = page_level_size(level); pmask = page_level_mask(level); - notify_page_enc_status_changed(pfn, psize >> PAGE_SHIFT, enc); - vaddr = (vaddr & pmask) + psize; + + if (size_cont == 0) { + /* Record new contiguous range */ + pfn_beg = pfn; + size_cont = psize; + } else if ((pfn_beg + (size_cont >> PAGE_SHIFT)) == pfn) { + /* Merge into current contiguous range */ + size_cont += psize; + } else { + /* Notify current contiguous range */ + notify_page_enc_status_changed(pfn_beg, + size_cont >> PAGE_SHIFT, enc); + /* Record new contiguous range */ + pfn_beg = pfn; + size_cont = psize; + } } + + /* Notify the last contiguous range */ + if (size_cont) + notify_page_enc_status_changed(pfn_beg, + size_cont >> PAGE_SHIFT, enc); #endif } -- Gitee