Use flush tlb last level when change protection
diff mbox series

Message ID 1550904447-45567-1-git-send-email-wxf.wang@hisilicon.com
State New
Headers show
Series
  • Use flush tlb last level when change protection
Related show

Commit Message

Xuefeng Wang Feb. 23, 2019, 6:47 a.m. UTC
The protection attributes are only kept in last level tlb, so
protection changing only need invalidate last level tlb, exclude
the PWC entries.

Signed-off-by: Xuefeng Wang <wxf.wang@hisilicon.com>
---
 mm/mprotect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Catalin Marinas Feb. 24, 2019, 11:08 a.m. UTC | #1
On Sat, Feb 23, 2019 at 02:47:27PM +0800, Xuefeng Wang wrote:
> The protection attributes are only kept in last level tlb, so
> protection changing only need invalidate last level tlb, exclude
> the PWC entries.
> 
> Signed-off-by: Xuefeng Wang <wxf.wang@hisilicon.com>
> ---
>  mm/mprotect.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/mprotect.c b/mm/mprotect.c
> index 36cb358..0c4303d 100644
> --- a/mm/mprotect.c
> +++ b/mm/mprotect.c
> @@ -287,7 +287,7 @@ static unsigned long change_protection_range(struct vm_area_struct *vma,
>  
>  	/* Only flush the TLB if we actually modified any entries: */
>  	if (pages)
> -		flush_tlb_range(vma, start, end);
> +		__flush_tlb_range(vma, start, end, PAGE_SIZE, true);
>  	dec_tlb_flush_pending(mm);

You are changing a generic file to call an arm64-internal function,
breaking all the other architectures, so NAK.

Do you actually see any performance improvement?
kernel test robot Feb. 25, 2019, 2:38 p.m. UTC | #2
Hi Xuefeng,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.0-rc8 next-20190225]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Xuefeng-Wang/Use-flush-tlb-last-level-when-change-protection/20190225-214747
config: x86_64-randconfig-x017-201908 (attached as .config)
compiler: gcc-8 (Debian 8.2.0-21) 8.2.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   mm/mprotect.c: In function 'change_protection_range':
>> mm/mprotect.c:290:3: error: implicit declaration of function '__flush_tlb_range'; did you mean 'flush_tlb_range'? [-Werror=implicit-function-declaration]
      __flush_tlb_range(vma, start, end, PAGE_SIZE, true);
      ^~~~~~~~~~~~~~~~~
      flush_tlb_range
   cc1: some warnings being treated as errors

vim +290 mm/mprotect.c

   265	
   266	static unsigned long change_protection_range(struct vm_area_struct *vma,
   267			unsigned long addr, unsigned long end, pgprot_t newprot,
   268			int dirty_accountable, int prot_numa)
   269	{
   270		struct mm_struct *mm = vma->vm_mm;
   271		pgd_t *pgd;
   272		unsigned long next;
   273		unsigned long start = addr;
   274		unsigned long pages = 0;
   275	
   276		BUG_ON(addr >= end);
   277		pgd = pgd_offset(mm, addr);
   278		flush_cache_range(vma, addr, end);
   279		inc_tlb_flush_pending(mm);
   280		do {
   281			next = pgd_addr_end(addr, end);
   282			if (pgd_none_or_clear_bad(pgd))
   283				continue;
   284			pages += change_p4d_range(vma, pgd, addr, next, newprot,
   285					 dirty_accountable, prot_numa);
   286		} while (pgd++, addr = next, addr != end);
   287	
   288		/* Only flush the TLB if we actually modified any entries: */
   289		if (pages)
 > 290			__flush_tlb_range(vma, start, end, PAGE_SIZE, true);
   291		dec_tlb_flush_pending(mm);
   292	
   293		return pages;
   294	}
   295	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kernel test robot Feb. 25, 2019, 3:02 p.m. UTC | #3
Hi Xuefeng,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.0-rc8 next-20190225]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Xuefeng-Wang/Use-flush-tlb-last-level-when-change-protection/20190225-214747
config: sparc64-allyesconfig (attached as .config)
compiler: sparc64-linux-gnu-gcc (Debian 8.2.0-11) 8.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=8.2.0 make.cross ARCH=sparc64 

All errors (new ones prefixed by >>):

   mm/mprotect.c: In function 'change_protection_range':
>> mm/mprotect.c:290:3: error: implicit declaration of function '__flush_tlb_range'; did you mean '__flush_tlb_page'? [-Werror=implicit-function-declaration]
      __flush_tlb_range(vma, start, end, PAGE_SIZE, true);
      ^~~~~~~~~~~~~~~~~
      __flush_tlb_page
   cc1: some warnings being treated as errors

vim +290 mm/mprotect.c

   265	
   266	static unsigned long change_protection_range(struct vm_area_struct *vma,
   267			unsigned long addr, unsigned long end, pgprot_t newprot,
   268			int dirty_accountable, int prot_numa)
   269	{
   270		struct mm_struct *mm = vma->vm_mm;
   271		pgd_t *pgd;
   272		unsigned long next;
   273		unsigned long start = addr;
   274		unsigned long pages = 0;
   275	
   276		BUG_ON(addr >= end);
   277		pgd = pgd_offset(mm, addr);
   278		flush_cache_range(vma, addr, end);
   279		inc_tlb_flush_pending(mm);
   280		do {
   281			next = pgd_addr_end(addr, end);
   282			if (pgd_none_or_clear_bad(pgd))
   283				continue;
   284			pages += change_p4d_range(vma, pgd, addr, next, newprot,
   285					 dirty_accountable, prot_numa);
   286		} while (pgd++, addr = next, addr != end);
   287	
   288		/* Only flush the TLB if we actually modified any entries: */
   289		if (pages)
 > 290			__flush_tlb_range(vma, start, end, PAGE_SIZE, true);
   291		dec_tlb_flush_pending(mm);
   292	
   293		return pages;
   294	}
   295	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

Patch
diff mbox series

diff --git a/mm/mprotect.c b/mm/mprotect.c
index 36cb358..0c4303d 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -287,7 +287,7 @@  static unsigned long change_protection_range(struct vm_area_struct *vma,
 
 	/* Only flush the TLB if we actually modified any entries: */
 	if (pages)
-		flush_tlb_range(vma, start, end);
+		__flush_tlb_range(vma, start, end, PAGE_SIZE, true);
 	dec_tlb_flush_pending(mm);
 
 	return pages;