powerpc: use smp_rmb when looking at deposisted pgtable to store hash index
PATCH 1/2 powerpc: use smp_rmb when looking at deposisted pgtable to store hash index
From: "Aneesh Kumar K.V" <[email protected]>
We need to use smb_rmb when looking at hpte slot array. Otherwise we could reorder the hpte_slot array load bfore even we marked the pmd trans huge.
--- arch/powerpc/include/asm/pgtable-ppc64.h | 15 +++++++++++++++ arch/powerpc/mm/hugepage-hash64.c | 6 +----- arch/powerpc/mm/pgtable_64.c | 6 +----- 3 files changed, 17 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/pgtable-ppc64.h +15 -0
@@ -10,6 +10,7 @@#else #include <asm/pgtable-ppc64-4k.h> #endif +#include <asm/barrier.h> #define FIRST_USER_ADDRESS 0
@@ -393,6 +394,20 @@ static inline void mark_hpte_slot_valid(unsigned char *hpte_slot_array, hpte_slot_array[index] = hidx <<4 |0x1 <<3 ; } +static inline char *get_hpte_slot_array (pmd_t *pmdp) +{ +/* +* The hpte hindex is stored in the pgtable whose address is in the +* second half of the PMD +* +* Order this load with the test for pmd_trans_huge in the caller +*/ +smp_rmb (); +return *(char **)(pmdp +PTRS_PER_PMD ); + + +} +extern void hpte_do_hugepage_flush (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp);#ifdef CONFIG_TRANSPARENT_HUGEPAGE
arch/powerpc/mm/hugepage-hash64.c +1 -5
@@ -84,11 +84,7 @@ int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid, vpn =hpt_vpn (ea, vsid, ssize); hash =hpt_hash (vpn, shift, ssize); -/* -* The hpte hindex are stored in the pgtable whose address is in the -* second half of the PMD -*/ - hpte_slot_array = *(char **)(pmdp +PTRS_PER_PMD ); + hpte_slot_array =get_hpte_slot_array (pmdp); valid =hpte_valid (hpte_slot_array, index);if (valid) {
arch/powerpc/mm/pgtable_64.c +1 -5
@@ -701,11 +701,7 @@ void hpte_do_hugepage_flush(struct mm_struct *mm, unsigned long addr,* Flush all the hptes mapping this hugepage */ s_addr = addr &HPAGE_PMD_MASK ; -/* -* The hpte hindex are stored in the pgtable whose address is in the -* second half of the PMD -*/ - hpte_slot_array = *(char **)(pmdp +PTRS_PER_PMD ); + hpte_slot_array =get_hpte_slot_array (pmdp);/* * IF we try to do a HUGE PTE update after a withdraw is done. * we will find the below NULL. This happens when we do
Signature · 1 line
1.8.1.2
PATCH 2/2 powerpc: split hugepage when using subpage protection
From: "Aneesh Kumar K.V" <[email protected]>
We find all the overlapping vma and mark them such that we don't allocate hugepage in that range. Also we split existing huge page so that the normal page hash can be invalidated and new page faulted in with new protection bits.
--- arch/powerpc/mm/subpage-prot.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
arch/powerpc/mm/subpage-prot.c +27 -0
@@ -130,6 +130,14 @@ static void subpage_prot_clear(unsigned long addr, unsigned long len)up_write (&mm->mmap_sem); } +static int subpage_walk_pmd_entry (pmd_t *pmd,unsigned long addr, +unsigned long end,struct mm_walk *walk) +{ +struct vm_area_struct *vma = walk->private; +split_huge_page_pmd (vma, addr, pmd); +return 0 ; +} +/* * Copy in a subpage protection map for an address range. * The map has 2 bits per 4k subpage, so 32 bits per 64k page.
@@ -149,6 +157,12 @@ long sys_subpage_prot(unsigned long addr, unsigned long len, u32 __user *map)size_t nw;unsigned long next, limit;int err; +struct vm_area_struct *vma; + +struct mm_walk subpage_proto_walk = { + .mm = mm, + .pmd_entry = subpage_walk_pmd_entry, + };/* Check parameters */ if ((addr & ~PAGE_MASK) || (len & ~PAGE_MASK) ||
@@ -168,6 +182,19 @@ long sys_subpage_prot(unsigned long addr, unsigned long len, u32 __user *map)return -EFAULT ;down_write (&mm->mmap_sem); + +/* +* We don't try too hard, we just mark all the vma in that range +* VM_NOHUGEPAGE and split them. +*/ +for (vma =find_vma (mm, addr); + (vma && vma->vm_end < (addr + len)); vma = vma->vm_next) { + + vma->vm_flags |=VM_NOHUGEPAGE ; + subpage_proto_walk.private = vma; +walk_page_range (vma->vm_start, vma->vm_end, + &subpage_proto_walk); + }for (limit = addr + len; addr < limit; addr = next) { next =pmd_addr_end (addr, limit); err = -ENOMEM ;
Signature · 1 line
1.8.1.2
Re: [PATCH 2/2] powerpc: split hugepage when using subpage protection
Quoted 45 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
We find all the overlapping vma and mark them such that we don't allocate hugepage in that range. Also we split existing huge page so that the normal page hash can be invalidated and new page faulted in with new protection bits.
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/mm/subpage-prot.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)arch/powerpc/mm/subpage-prot.c +14
-0@@ -130,6 +130,14 @@ static void subpage_prot_clear(unsigned long addr, unsigned long len)up_write (&mm->mmap_sem); } +static int subpage_walk_pmd_entry (pmd_t *pmd,unsigned long addr, +unsigned long end,struct mm_walk *walk) +{ +struct vm_area_struct *vma = walk->private; +split_huge_page_pmd (vma, addr, pmd); +return 0 ; +} +/* * Copy in a subpage protection map for an address range. * The map has 2 bits per 4k subpage, so 32 bits per 64k page. @@ -149,6 +157,12 @@ long sys_subpage_prot(unsigned long addr, unsigned long len, u32 __user *map)size_t nw;unsigned long next, limit;int err; +struct vm_area_struct *vma; + +struct mm_walk subpage_proto_walk = { + .mm = mm, + .pmd_entry = subpage_walk_pmd_entry, + };/* Check parameters */ if ((addr & ~PAGE_MASK) || (len & ~PAGE_MASK) ||
arch/powerpc/mm/subpage-prot.c long sys_subpage_prot(unsigned long addr, unsigned long len, u32 __user *map) · line 191
Quoted 10 lines
arch/powerpc/mm/subpage-prot.c +7
-0@@ -168,6 +182,19 @@ long sys_subpage_prot(unsigned long addr, unsigned long len, u32 __user *map)return -EFAULT ;down_write (&mm->mmap_sem); + +/* +* We don't try too hard, we just mark all the vma in that range +* VM_NOHUGEPAGE and split them. +*/ +for (vma =find_vma (mm, addr); + (vma && vma->vm_end < (addr + len)); vma = vma->vm_next) {
should be, Missed commit -amend
(vma && vma->vm_start < (addr + len)); vma = vma->vm_next) {arch/powerpc/mm/subpage-prot.c long sys_subpage_prot(unsigned long addr, unsigned long len, u32 __user *map) · line 200
Quoted 8 lines
arch/powerpc/mm/subpage-prot.c +5
-0+ vma->vm_flags |=VM_NOHUGEPAGE ; + subpage_proto_walk.private = vma; +walk_page_range (vma->vm_start, vma->vm_end, + &subpage_proto_walk); + }for (limit = addr + len; addr < limit; addr = next) { next =pmd_addr_end (addr, limit); err = -ENOMEM ;
-aneesh
Quoted 4 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
We need to use
smb_rmbwhen looking at hpte slot array. Otherwise we could reorder thehpte_slotarray load bfore even we marked the pmd trans huge.
Does this need to go back into the stable series?
Mikey
Quoted 83 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/include/asm/pgtable-ppc64.h | 15 +++++++++++++++ arch/powerpc/mm/hugepage-hash64.c | 6 +----- arch/powerpc/mm/pgtable_64.c | 6 +----- 3 files changed, 17 insertions(+), 10 deletions(-)arch/powerpc/include/asm/pgtable-ppc64.h +15
-0@@ -10,6 +10,7 @@#else #include <asm/pgtable-ppc64-4k.h> #endif +#include <asm/barrier.h> #define FIRST_USER_ADDRESS 0@@ -393,6 +394,20 @@ static inline void mark_hpte_slot_valid(unsigned char *hpte_slot_array, hpte_slot_array[index] = hidx <<4 |0x1 <<3 ; } +static inline char *get_hpte_slot_array (pmd_t *pmdp) +{ +/* +* The hpte hindex is stored in the pgtable whose address is in the +* second half of the PMD +* +* Order this load with the test for pmd_trans_huge in the caller +*/ +smp_rmb (); +return *(char **)(pmdp +PTRS_PER_PMD ); + + +} +extern void hpte_do_hugepage_flush (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp);#ifdef CONFIG_TRANSPARENT_HUGEPAGE arch/powerpc/mm/hugepage-hash64.c +1
-5@@ -84,11 +84,7 @@ int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid, vpn =hpt_vpn (ea, vsid, ssize); hash =hpt_hash (vpn, shift, ssize); -/* -* The hpte hindex are stored in the pgtable whose address is in the -* second half of the PMD -*/ - hpte_slot_array = *(char **)(pmdp +PTRS_PER_PMD ); + hpte_slot_array =get_hpte_slot_array (pmdp); valid =hpte_valid (hpte_slot_array, index);if (valid) {arch/powerpc/mm/pgtable_64.c +1
-5@@ -701,11 +701,7 @@ void hpte_do_hugepage_flush(struct mm_struct *mm, unsigned long addr,* Flush all the hptes mapping this hugepage */ s_addr = addr &HPAGE_PMD_MASK ; -/* -* The hpte hindex are stored in the pgtable whose address is in the -* second half of the PMD -*/ - hpte_slot_array = *(char **)(pmdp +PTRS_PER_PMD ); + hpte_slot_array =get_hpte_slot_array (pmdp);/* * IF we try to do a HUGE PTE update after a withdraw is done. * we will find the below NULL. This happens when we do Signature · 6 lines
1.8.1.2 _______________________________________________ Linuxppc-dev mailing list [email protected] https://lists.ozlabs.org/listinfo/linuxppc-dev
Quoted 9 lines · Michael Neuling
Quoted 4 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
We need to use
smb_rmbwhen looking at hpte slot array. Otherwise we could reorder thehpte_slotarray load bfore even we marked the pmd trans huge.Does this need to go back into the stable series?
No the changes are not yet upstream. hpte_slot_array changes are in the THP series. I didn't want to post the entire series again with the above two patches.
-aneesh
Quoted 9 lines · Aneesh Kumar K.V
Quoted 7 lines · Michael Neuling
Quoted 4 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
We need to use
smb_rmbwhen looking at hpte slot array. Otherwise we could reorder thehpte_slotarray load bfore even we marked the pmd trans huge.
Quoted 6 lines
Quoted 2 lines
Does this need to go back into the stable series?
No the changes are not yet upstream.
hpte_slot_arraychanges are in the THP series. I didn't want to post the entire series again with the above two patches.
Note that any patch that adds such a rmb should have a very clear description of what is the corresponding wmb. It's almost never right to have one without the other. IE. What is it that you are ordering against.
Cheers,
Ben.
Quoted 13 lines · Benjamin Herrenschmidt
Quoted 12 lines · Aneesh Kumar K.V
Quoted 9 lines · Michael Neuling
Quoted 4 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
We need to use
smb_rmbwhen looking at hpte slot array. Otherwise we could reorder thehpte_slotarray load bfore even we marked the pmd trans huge.Does this need to go back into the stable series?
Quoted 8 lines
Quoted 3 lines
No the changes are not yet upstream.
hpte_slot_arraychanges are in the THP series. I didn't want to post the entire series again with the above two patches.Note that any patch that adds such a rmb should have a very clear description of what is the corresponding wmb. It's almost never right to have one without the other. IE. What is it that you are ordering against.
Will update the commit message. Some of that smb_wmb() are in the core THP, and the others in ppc64 code. Will update with more info.
When we deposit pgtable we use pgtable_trans_huge_deposit that calls related smb_wmb(). When we read pgtable via pgtable_trans_huge_withdraw, core THP code does the related smb_wmb() after setting the right PTE information in the pgtable.
-aneesh