[PATCH v6 08/11] powerpc/kvm/book3s_hv: Use functions to track lockless pgtbl walks

2020-02-05 Thread Leonardo Bras
kvmppc_do_h_enter: Fixes where local_irq_restore() must be placed (after the last usage of ptep). Given that some of these functions can be called in real mode, and others always are, we use __{begin,end}_lockless_pgtbl_walk so we can decide when to disable interrupts. Signed-off-by: Leonardo Bras

[PATCH v6 07/11] powerpc/kvm/e500: Use functions to track lockless pgtbl walks

2020-02-05 Thread Leonardo Bras
, so there is no need to repeat it here. Variable that saves the irq mask was renamed from flags to irq_mask so it doesn't lose meaning now it's not directly passed to local_irq_* functions. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/e500_mmu_host.c | 9 + 1 file changed, 5

[PATCH v6 06/11] powerpc/mm/book3s64/hash: Use functions to track lockless pgtbl walks

2020-02-05 Thread Leonardo Bras
,restore} is already inside {begin,end}_lockless_pgtbl_walk, so there is no need to repeat it here. Variable that saves the irq mask was renamed from flags to irq_mask so it doesn't lose meaning now it's not directly passed to local_irq_* functions. Signed-off-by: Leonardo Bras --- arch/powerpc/mm

[PATCH v6 05/11] powerpc/perf: Use functions to track lockless pgtbl walks

2020-02-05 Thread Leonardo Bras
meaning now it's not directly passed to local_irq_* functions. Signed-off-by: Leonardo Bras --- arch/powerpc/perf/callchain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/perf/callchain.c b/arch/powerpc/perf/callchain.c index cbc251981209..fd9979e69f36

[PATCH v6 04/11] powerpc/mce_power: Use functions to track lockless pgtbl walks

2020-02-05 Thread Leonardo Bras
Applies the new functions used for tracking lockless pgtable walks on addr_to_pfn(). local_irq_{save,restore} is already inside {begin,end}_lockless_pgtbl_walk, so there is no need to repeat it here. Signed-off-by: Leonardo Bras --- arch/powerpc/kernel/mce_power.c | 6 +++--- 1 file changed, 3

[PATCH v6 03/11] powerpc/mm: Adds arch-specificic functions to track lockless pgtable walks

2020-02-05 Thread Leonardo Bras
argument that allows interrupt enable/disable to be skipped: __begin_lockless_pgtbl_walk() and __end_lockless_pgtbl_walk(). Functions similar to the generic ones are also exported, by calling the above functions with parameter {en,dis}able_irq = true. Signed-off-by: Leonardo Bras --- arch/powerpc

[PATCH v6 02/11] mm/gup: Use functions to track lockless pgtbl walks on gup_pgd_range

2020-02-05 Thread Leonardo Bras
inside {begin,end}_lockless_pgtbl_walk, there should be no change in the workings. Signed-off-by: Leonardo Bras --- mm/gup.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 1b521e0ac1de..04e6f46993b6 100644 --- a/mm/gup.c +++ b/mm/gup.c

[PATCH v6 01/11] asm-generic/pgtable: Adds generic functions to track lockless pgtable walks

2020-02-05 Thread Leonardo Bras
to make sure there is no speculative read outside the interrupt disabled area. Other than that, it is not supposed to have any change of behavior from current code. It is planned to allow arch-specific versions, so that additional steps can be added while keeping the code clean. Signed-off-by: Leonardo

[PATCH v6 00/11] Introduces new functions for tracking lockless pagetable walks

2020-02-05 Thread Leonardo Bras
xed behavior of decrementing before last ptep was used Link: http://patchwork.ozlabs.org/patch/1163093/ Special thanks for: Aneesh Kumar, Nick Piggin, Paul Mackerras, Michael Ellerman, Fabiano Rosas, Dipankar Sarma and Oliver O'Halloran. Leonardo Bras (11): asm-generic/pgtable: Adds gene

[RFC PATCH 1/1] powerpc/pgtable: Skip serialize_against_pte_lookup() when unmapping

2020-01-13 Thread Leonardo Bras
munmap's time reduction from 275 seconds to 39ms. Signed-off-by: Leonardo Bras --- arch/powerpc/include/asm/book3s/64/pgtable.h | 25 +--- arch/powerpc/include/asm/book3s/64/radix.h | 3 ++- arch/powerpc/mm/book3s64/radix_pgtable.c | 6 +++-- 3 files changed, 28 insertions(+), 6

Re: [PATCH 1/1] kvm/book3s_64: Fixes crash caused by not cleaning vhost IOTLB

2019-12-18 Thread Leonardo Bras
roach to find the related vhost_dev's. What do you think? Best regards, Leonardo Bras signature.asc Description: This is a digitally signed message part

[PATCH 1/1] kvm/book3s_64: Fixes crash caused by not cleaning vhost IOTLB

2019-12-17 Thread Leonardo Bras
with this. In this case, qemu does free the vhost IOTLB entry, which fixes the bug. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/book3s_64_vio.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c index 883a66e76638..841eff3f6392

Re: [PATCH v4 1/2] powerpc/pseries/iommu: Share the per-cpu TCE page with the hypervisor.

2019-12-04 Thread Leonardo Bras
On Sun, 2019-12-01 at 22:45 -0800, Ram Pai wrote: > @@ -206,8 +224,7 @@ static int tce_buildmulti_pSeriesLP(struct iommu_table > *tbl, long tcenum, > * from iommu_alloc{,_sg}() > */ > if (!tcep) { > - tcep = (__be64 *)__get_free_page(GFP_ATOMIC); > -

Re: [PATCH 1/1] powerpc/kvm/book3s: Fixes possible 'use after release' of kvm

2019-11-28 Thread Leonardo Bras
On Wed, 2019-11-27 at 17:40 +0100, Paolo Bonzini wrote: > > diff --git a/arch/powerpc/kvm/book3s_64_vio.c > > b/arch/powerpc/kvm/book3s_64_vio.c > > index 5834db0a54c6..a402ead833b6 100644 > > --- a/arch/powerpc/kvm/book3s_64_vio.c > > +++ b/arch/powerpc/kvm/book3s_64_vio.c > > @@ -316,14 +316,13

Re: [PATCH 1/1] powerpc/kvm/book3s: Fixes possible 'use after release' of kvm

2019-11-28 Thread Leonardo Bras
On Thu, 2019-11-28 at 09:57 +1100, Paul Mackerras wrote: > There isn't a potential use-after-free here. We are relying on the > property that the release function (kvm_vm_release) cannot be called > in parallel with this function. The reason is that this function >

Re: [PATCH 1/1] powerpc/kvm/book3s: Fixes possible 'use after release' of kvm

2019-11-27 Thread Leonardo Bras
On Wed, 2019-11-27 at 17:40 +0100, Paolo Bonzini wrote: > > > >if (ret >= 0) > >list_add_rcu(>list, >arch.spapr_tce_tables); > > - else > > - kvm_put_kvm(kvm); > > > >mutex_unlock(>lock); > > > >if (ret >= 0) > >

Re: [PATCH v3 0/2] Replace current->mm by kvm->mm on powerpc/kvm

2019-11-27 Thread Leonardo Bras
Result of Travis-CI testing the change: https://travis-ci.org/LeoBras/linux-ppc/builds/617712012 signature.asc Description: This is a digitally signed message part

[PATCH v3 2/2] powerpc/kvm/book3e: Replace current->mm by kvm->mm

2019-11-26 Thread Leonardo Bras
code, relying more in the contents of kvm struct. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/booke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index be9a45874194..fd7bdb4f8f87 100644 --- a/arch/powerpc/kvm/booke.c

[PATCH v3 1/2] powerpc/kvm/book3s: Replace current->mm by kvm->mm

2019-11-26 Thread Leonardo Bras
code, relying more in the contents of kvm struct. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 4 ++-- arch/powerpc/kvm/book3s_64_vio.c| 10 ++ arch/powerpc/kvm/book3s_hv.c| 10 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git

[PATCH v3 0/2] Replace current->mm by kvm->mm on powerpc/kvm

2019-11-26 Thread Leonardo Bras
le 'use after free' on kvm_vm_ioctl_create_spapr_tce - Fixes undeclared variable error Leonardo Bras (2): powerpc/kvm/book3s: Replace current->mm by kvm->mm powerpc/kvm/book3e: Replace current->mm by kvm->mm arch/powerpc/kvm/book3s_64_mmu_hv.c | 4 ++-- arch/powerpc/kvm/book3s_64_vio.c| 1

[PATCH 1/1] powerpc/kvm/book3s: Fixes possible 'use after release' of kvm

2019-11-26 Thread Leonardo Bras
Fixes a possible 'use after free' of kvm variable. It does use mutex_unlock(>lock) after possible freeing a variable with kvm_put_kvm(kvm). Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/book3s_64_vio.c | 3 +-- virt/kvm/kvm_main.c | 8 2 files changed, 5 inserti

Re: [PATCH v2 1/4] powerpc/kvm/book3s: Fixes possible 'use after release' of kvm

2019-11-21 Thread Leonardo Bras
On Thu, 2019-11-14 at 15:43 -0300, Leonardo Bras wrote: > > If the kvm_put_kvm() you've moved actually caused the last > > reference > > to > > be dropped that would mean that our caller had passed us a kvm > > struct > > without holding a reference to it, and t

Re: [PATCH v2 1/4] powerpc/kvm/book3s: Fixes possible 'use after release' of kvm

2019-11-14 Thread Leonardo Bras
On Tue, 2019-11-12 at 15:57 +1100, Michael Ellerman wrote: > Hi Leonardo, Hello Micheal, thanks for the feedback! > > Leonardo Bras writes: > > Fixes a possible 'use after free' of kvm variable in > > kvm_vm_ioctl_create_spapr_tce, where it does a mutex_unlock(

Re: [PATCH v2 1/1] powerpc/pseries/hotplug-memory.c: Change rc variable to bool

2019-11-14 Thread Leonardo Bras
On Thu, 2019-11-14 at 20:07 +1100, Michael Ellerman wrote: > On Fri, 2019-08-02 at 13:39:15 UTC, Leonardo Bras wrote: > > Changes the return variable to bool (as the return value) and > > avoids doing a ternary operation before returning. > > > > Signed-off-by: Leonard

[PATCH v2 3/4] powerpc/kvm/book3e: Replace current->mm by kvm->mm

2019-11-07 Thread Leonardo Bras
code, relying more in the contents of kvm struct. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/booke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index be9a45874194..fd7bdb4f8f87 100644 --- a/arch/powerpc/kvm/booke.c

[PATCH v2 2/4] powerpc/kvm/book3s: Replace current->mm by kvm->mm

2019-11-07 Thread Leonardo Bras
code, relying more in the contents of kvm struct. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 10 +- arch/powerpc/kvm/book3s_64_vio.c| 10 ++ arch/powerpc/kvm/book3s_hv.c| 10 +- 3 files changed, 16 insertions(+), 14 deletions(-)

[PATCH v2 0/4] Replace current->mm by kvm->mm on powerpc/kvm

2019-11-07 Thread Leonardo Bras
'use after free' on kvm_vm_ioctl_create_spapr_tce - Fixes undeclared variable error Build test: - https://travis-ci.org/LeoBras/linux-ppc/builds/608807573 Leonardo Bras (4): powerpc/kvm/book3s: Fixes possible 'use after release' of kvm powerpc/kvm/book3s: Replace current->mm by kvm->mm

[PATCH v2 4/4] powerpc/kvm/e500: Replace current->mm by kvm->mm

2019-11-07 Thread Leonardo Bras
code, relying more in the contents of kvm struct. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/e500_mmu_host.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c index 321db0fdb9db..425d13806645 100644

[PATCH v2 1/4] powerpc/kvm/book3s: Fixes possible 'use after release' of kvm

2019-11-07 Thread Leonardo Bras
Fixes a possible 'use after free' of kvm variable in kvm_vm_ioctl_create_spapr_tce, where it does a mutex_unlock(>lock) after a kvm_put_kvm(kvm). Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/book3s_64_vio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/powe

Re: [PATCH v5 01/11] asm-generic/pgtable: Adds generic functions to monitor lockless pgtable walks

2019-10-09 Thread Leonardo Bras
On Fri, 2019-10-04 at 13:28 +0200, Peter Zijlstra wrote: > > Could you please explain it? > > I mean, why this breaks tmpfs-thp? > > Also, why mm_cpumask() is also broken? > > Because shared pages are not bound by a mm; or does it not share the thp > state between mappings? By what I could

Re: [PATCH v5 02/11] powerpc/mm: Adds counting method to monitor lockless pgtable walks

2019-10-08 Thread Leonardo Bras
On Tue, 2019-10-08 at 17:43 +, Christopher Lameter wrote: > On Tue, 8 Oct 2019, Leonardo Bras wrote: > > > > You are creating contention on a single exclusive cacheline. Doesnt this > > > defeat the whole purpose of the lockless page table walk? Use mmap_sem or > &

Re: [PATCH v5 02/11] powerpc/mm: Adds counting method to monitor lockless pgtable walks

2019-10-08 Thread Leonardo Bras
On Tue, 2019-10-08 at 15:11 +, Christopher Lameter wrote: > > On Wed, 2 Oct 2019, Leonardo Bras wrote: > > > + > > +inline unsigned long __begin_lockless_pgtbl_walk(struct mm_struct *mm, > > +bool disable_irq) > >

Re: [PATCH v5 00/11] Introduces new count-based method for tracking lockless pagetable walks

2019-10-03 Thread Leonardo Bras
On Thu, 2019-10-03 at 13:49 -0700, John Hubbard wrote: > Yes. And to clarify, I was assuming that the changes to mm/gup.c were > required in order to accomplish your goals. Given that assumption, I > wanted the generic code to be "proper", and that's what that feedback > is about. You assumed

Re: [PATCH v5 01/11] asm-generic/pgtable: Adds generic functions to monitor lockless pgtable walks

2019-10-03 Thread Leonardo Bras
Hello Peter, thanks for the feedback! On Thu, 2019-10-03 at 13:51 +0200, Peter Zijlstra wrote: > On Thu, Oct 03, 2019 at 09:11:45AM +0200, Peter Zijlstra wrote: > > On Wed, Oct 02, 2019 at 10:33:15PM -0300, Leonardo Bras wrote: > > > diff --git a/include/asm-generic/pgtab

Re: [PATCH v5 10/11] mm/Kconfig: Adds config option to track lockless pagetable walks

2019-10-03 Thread Leonardo Bras
On Thu, 2019-10-03 at 09:44 +0200, Peter Zijlstra wrote: > This shouldn't be a user visible option at all. Either the arch needs > it and selects it or not. You are right. I will do that on v6. Thanks for the feedback! signature.asc Description: This is a digitally signed message part

Re: [PATCH v5 00/11] Introduces new count-based method for tracking lockless pagetable walks

2019-10-03 Thread Leonardo Bras
Hello Peter, thanks for the feedback! On Thu, 2019-10-03 at 09:29 +0200, Peter Zijlstra wrote: > On Wed, Oct 02, 2019 at 10:33:14PM -0300, Leonardo Bras wrote: > > If a process (qemu) with a lot of CPUs (128) try to munmap() a large > > chunk of memory (496GB) mapped with THP, it t

Re: [PATCH v5 10/11] mm/Kconfig: Adds config option to track lockless pagetable walks

2019-10-03 Thread Leonardo Bras
On Thu, 2019-10-03 at 16:04 -0300, Leonardo Bras wrote: > On Wed, 2019-10-02 at 22:08 -0400, Qian Cai wrote: > > Can’t this name and all those new *lockless* function names be shorter? > > There are many functions name with *_locked, so how about dropping > >

Re: [PATCH v5 10/11] mm/Kconfig: Adds config option to track lockless pagetable walks

2019-10-03 Thread Leonardo Bras
On Wed, 2019-10-02 at 22:08 -0400, Qian Cai wrote: > Can’t this name and all those new *lockless* function names be shorter? > There are many functions name with *_locked, so how about dropping > lockless at all, i.e., PAGE_TABLE_WALK_TRACKING blah blah? Thanks for the feedback! Well, in this

[PATCH v5 10/11] mm/Kconfig: Adds config option to track lockless pagetable walks

2019-10-02 Thread Leonardo Bras
Adds config option LOCKLESS_PAGE_TABLE_WALK_TRACKING to make possible enabling tracking lockless pagetable walks directly from kernel config. Signed-off-by: Leonardo Bras --- mm/Kconfig | 11 +++ 1 file changed, 11 insertions(+) diff --git a/mm/Kconfig b/mm/Kconfig index a5dae9a7eb51

[PATCH v5 05/11] powerpc/perf: Applies counting method to monitor lockless pgtbl walks

2019-10-02 Thread Leonardo Bras
lose meaning now it's not directly passed to local_irq_* functions. Signed-off-by: Leonardo Bras --- arch/powerpc/perf/callchain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/perf/callchain.c b/arch/powerpc/perf/callchain.c index c84bbd4298a0..43e49d8be344

[PATCH v5 11/11] powerpc/mm/book3s64/pgtable: Uses counting method to skip serializing

2019-10-02 Thread Leonardo Bras
Skips slow part of serialize_against_pte_lookup if there is no running lockless pagetable walk. Signed-off-by: Leonardo Bras --- arch/powerpc/mm/book3s64/pgtable.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/book3s64/pgtable.c b/arch/powerpc/mm

[PATCH v5 09/11] powerpc/kvm/book3s_64: Applies counting method to monitor lockless pgtbl walks

2019-10-02 Thread Leonardo Bras
to end_lockless_pgtbl_walk() to mimic the effect of local_irq_enable(). Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/book3s_64_mmu_hv.c| 6 ++--- arch/powerpc/kvm/book3s_64_mmu_radix.c | 34 +++--- arch/powerpc/kvm/book3s_64_vio_hv.c| 7 +- 3 files changed, 40 insertions(+), 7

[PATCH v5 08/11] powerpc/kvm/book3s_hv: Applies counting method to monitor lockless pgtbl walks

2019-10-02 Thread Leonardo Bras
-by: Leonardo Bras --- arch/powerpc/kvm/book3s_hv_nested.c | 22 ++-- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 32 - 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_nested.c b/arch/powerpc/kvm/book3s_hv_nested.c index

[PATCH v5 07/11] powerpc/kvm/e500: Applies counting method to monitor lockless pgtbl walks

2019-10-02 Thread Leonardo Bras
}_lockless_pgtbl_walk, so there is no need to repeat it here. Variable that saves the irq mask was renamed from flags to irq_mask so it doesn't lose meaning now it's not directly passed to local_irq_* functions. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/e500_mmu_host.c | 9 + 1 file changed, 5

[PATCH v5 06/11] powerpc/mm/book3s64/hash: Applies counting method to monitor lockless pgtbl walks

2019-10-02 Thread Leonardo Bras
. local_irq_{save,restore} is already inside {begin,end}_lockless_pgtbl_walk, so there is no need to repeat it here. Variable that saves the irq mask was renamed from flags to irq_mask so it doesn't lose meaning now it's not directly passed to local_irq_* functions. Signed-off-by: Leonardo Bras --- arch

[PATCH v5 04/11] powerpc/mce_power: Applies counting method to monitor lockless pgtbl walks

2019-10-02 Thread Leonardo Bras
Applies the counting-based method for monitoring lockless pgtable walks on addr_to_pfn(). local_irq_{save,restore} is already inside {begin,end}_lockless_pgtbl_walk, so there is no need to repeat it here. Signed-off-by: Leonardo Bras --- arch/powerpc/kernel/mce_power.c | 6 +++--- 1 file

[PATCH v5 01/11] asm-generic/pgtable: Adds generic functions to monitor lockless pgtable walks

2019-10-02 Thread Leonardo Bras
what was already needed to lockless pagetable walks (disabling interrupt). A memory barrier was also added just to make sure there is no speculative read outside the interrupt disabled area. Signed-off-by: Leonardo Bras --- include/asm-generic/pgtable.h | 58

[PATCH v5 00/11] Introduces new count-based method for tracking lockless pagetable walks

2019-10-02 Thread Leonardo Bras
alk() Fixed behavior of decrementing before last ptep was used Link: http://patchwork.ozlabs.org/patch/1163093/ Leonardo Bras (11): asm-generic/pgtable: Adds generic functions to monitor lockless pgtable walks powerpc/mm: Adds counting method to monitor lockless pgtable walks mm/gup: Appl

[PATCH v5 03/11] mm/gup: Applies counting method to monitor gup_pgd_range

2019-10-02 Thread Leonardo Bras
to repeat it here. Signed-off-by: Leonardo Bras --- mm/gup.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 23a9f9c9d377..52e53b4f39d8 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2319,7 +2319,7 @@ int __get_user_pages_fast(unsigned long start

[PATCH v5 02/11] powerpc/mm: Adds counting method to monitor lockless pgtable walks

2019-10-02 Thread Leonardo Bras
read outside the interrupt disabled area. Signed-off-by: Leonardo Bras --- arch/powerpc/include/asm/book3s/64/pgtable.h | 9 ++ arch/powerpc/mm/book3s64/pgtable.c | 117 +++ 2 files changed, 126 insertions(+) diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h

Re: [PATCH v4 03/11] mm/gup: Applies counting method to monitor gup_pgd_range

2019-10-01 Thread Leonardo Bras
On Tue, 2019-10-01 at 12:04 -0700, John Hubbard wrote: > On 10/1/19 10:56 AM, Leonardo Bras wrote: > > On Mon, 2019-09-30 at 14:51 -0700, John Hubbard wrote: > > > On 9/27/19 4:40 PM, Leonardo Bras wrote: > ... > > > > diff --git a/mm/gup.c b/mm/gup.c > &g

Re: [PATCH v4 01/11] powerpc/mm: Adds counting method to monitor lockless pgtable walks

2019-10-01 Thread Leonardo Bras
On Mon, 2019-09-30 at 14:47 -0700, John Hubbard wrote: > On 9/30/19 11:42 AM, Leonardo Bras wrote: > > On Mon, 2019-09-30 at 10:57 -0700, John Hubbard wrote: > > > > As I told before, there are cases where this function is called from > > > > 'real mode' in po

Re: [PATCH v4 03/11] mm/gup: Applies counting method to monitor gup_pgd_range

2019-10-01 Thread Leonardo Bras
On Mon, 2019-09-30 at 14:51 -0700, John Hubbard wrote: > On 9/27/19 4:40 PM, Leonardo Bras wrote: > > As decribed, gup_pgd_range is a lockless pagetable walk. So, in order to > > monitor against THP split/collapse with the couting method, it's necessary > > s/couting/counti

Re: [PATCH v4 01/11] powerpc/mm: Adds counting method to monitor lockless pgtable walks

2019-09-30 Thread Leonardo Bras
On Mon, 2019-09-30 at 10:57 -0700, John Hubbard wrote: > > As I told before, there are cases where this function is called from > > 'real mode' in powerpc, which doesn't disable irqs and may have a > > tricky behavior if we do. So, encapsulate the irq disable in this > > function can be a bad

Re: [PATCH v4 01/11] powerpc/mm: Adds counting method to monitor lockless pgtable walks

2019-09-30 Thread Leonardo Bras
one or more of the PPC Kconfig files should select > LOCKLESS_PAGE_TABLE_WALK_TRACKING.) The way it works today is defining it on platform pgtable.h. I agree that using Kconfig may be a better solution that can make this config more visible to disable/enable. Thanks for the feedback, Leonardo Bras signature.asc Description: This is a digitally signed message part

Re: [PATCH v4 03/11] mm/gup: Applies counting method to monitor gup_pgd_range

2019-09-30 Thread Leonardo Bras
On Mon, 2019-09-30 at 14:09 +0300, Kirill A. Shutemov wrote: > On Fri, Sep 27, 2019 at 08:40:00PM -0300, Leonardo Bras wrote: > > As decribed, gup_pgd_range is a lockless pagetable walk. So, in order to > ^ typo > Fixed, thanks! signature.asc Description: This is a digitally

[PATCH v4 11/11] powerpc/mm/book3s64/pgtable: Uses counting method to skip serializing

2019-09-27 Thread Leonardo Bras
Skips slow part of serialize_against_pte_lookup if there is no running lockless pagetable walk. Signed-off-by: Leonardo Bras --- arch/powerpc/mm/book3s64/pgtable.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/book3s64/pgtable.c b/arch/powerpc/mm

[PATCH v4 10/11] powerpc/book3s_64: Enables counting method to monitor lockless pgtbl walk

2019-09-27 Thread Leonardo Bras
Enables count-based monitoring method for lockless pagetable walks on PowerPC book3s_64. Other architectures/platforms fallback to using generic dummy functions. Signed-off-by: Leonardo Bras --- arch/powerpc/include/asm/book3s/64/pgtable.h | 5 + 1 file changed, 5 insertions(+) diff --git

[PATCH v4 09/11] powerpc/kvm/book3s_64: Applies counting method to monitor lockless pgtbl walks

2019-09-27 Thread Leonardo Bras
+ MSR_EE = 0. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/book3s_64_mmu_hv.c| 2 ++ arch/powerpc/kvm/book3s_64_mmu_radix.c | 30 ++ arch/powerpc/kvm/book3s_64_vio_hv.c| 3 +++ 3 files changed, 35 insertions(+) diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c

[PATCH v4 08/11] powerpc/kvm/book3s_hv: Applies counting method to monitor lockless pgtbl walks

2019-09-27 Thread Leonardo Bras
+ MSR_EE = 0 kvmppc_do_h_enter: Fixes where local_irq_restore() must be placed (after the last usage of ptep). Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/book3s_hv_nested.c | 22 -- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 18 ++ 2 files changed, 34 insertions

[PATCH v4 07/11] powerpc/kvm/e500: Applies counting method to monitor lockless pgtbl walks

2019-09-27 Thread Leonardo Bras
Applies the counting-based method for monitoring lockless pgtable walks on kvmppc_e500_shadow_map(). Fixes the place where local_irq_restore() is called: previously, if ptep was NULL, local_irq_restore() would never be called. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/e500_mmu_host.c

[PATCH v4 06/11] powerpc/mm/book3s64/hash: Applies counting method to monitor lockless pgtbl walks

2019-09-27 Thread Leonardo Bras
-off-by: Leonardo Bras --- arch/powerpc/mm/book3s64/hash_tlb.c | 2 ++ arch/powerpc/mm/book3s64/hash_utils.c | 12 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/book3s64/hash_tlb.c b/arch/powerpc/mm/book3s64/hash_tlb.c index 4a70d8dd39cd

[PATCH v4 04/11] powerpc/mce_power: Applies counting method to monitor lockless pgtbl walks

2019-09-27 Thread Leonardo Bras
Applies the counting-based method for monitoring lockless pgtable walks on addr_to_pfn(). Signed-off-by: Leonardo Bras --- arch/powerpc/kernel/mce_power.c | 13 ++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kernel/mce_power.c b/arch/powerpc/kernel

[PATCH v4 05/11] powerpc/perf: Applies counting method to monitor lockless pgtbl walks

2019-09-27 Thread Leonardo Bras
Applies the counting-based method for monitoring lockless pgtable walks on read_user_stack_slow. Signed-off-by: Leonardo Bras --- arch/powerpc/perf/callchain.c | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/perf/callchain.c b/arch/powerpc/perf/callchain.c

[PATCH v4 03/11] mm/gup: Applies counting method to monitor gup_pgd_range

2019-09-27 Thread Leonardo Bras
this method. Signed-off-by: Leonardo Bras --- mm/gup.c | 8 1 file changed, 8 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 98f13ab37bac..7105c829cf44 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2325,6 +2325,7 @@ static bool gup_fast_permitted(unsigned long start, unsigned long end) int

[PATCH v4 02/11] asm-generic/pgtable: Adds dummy functions to monitor lockless pgtable walks

2019-09-27 Thread Leonardo Bras
approach, that counts the number of lockless pagetable walks happening on the process. Given that there are lockless pagetable walks on generic code, it's necessary to create dummy functions for archs that won't use the approach. Signed-off-by: Leonardo Bras --- include/asm-generic/pgtable.h

[PATCH v4 00/11] Introduces new count-based method for monitoring lockless pagetable walks

2019-09-27 Thread Leonardo Bras
ons *_lockless_pgtbl_walk() Fixed behavior of decrementing before last ptep was used Link: http://patchwork.ozlabs.org/patch/1163093/ Leonardo Bras (11): powerpc/mm: Adds counting method to monitor lockless pgtable walks asm-generic/pgtable: Adds dummy functions to monitor lockless pgta

[PATCH v4 01/11] powerpc/mm: Adds counting method to monitor lockless pgtable walks

2019-09-27 Thread Leonardo Bras
end_lockless_pgtbl_walk(mm) Insert after the end of any lockless pgtable walk (Mostly after the ptep is last used) running_lockless_pgtbl_walk(mm) Returns the number of lockless pgtable walks running Signed-off-by: Leonardo Bras --- arch/powerpc/include/asm/book3s/64/mmu.h | 3

Re: [PATCH v3 00/11] Introduces new count-based method for monitoring lockless pagetable walks

2019-09-27 Thread Leonardo Bras
On Fri, 2019-09-27 at 11:46 -0300, Leonardo Bras wrote: > I am not sure if it would be ok to use irq_{save,restore} in real mode, > I will do some more reading of the docs before addressing this. It looks like it's unsafe to merge irq_{save,restore} in {start,end}_lockless_pgtbl_walk(

Re: [PATCH v3 00/11] Introduces new count-based method for monitoring lockless pagetable walks

2019-09-27 Thread Leonardo Bras
se, that the > caller can tolerate that. I am not sure if it would be ok to use irq_{save,restore} in real mode, I will do some more reading of the docs before addressing this. > > 4. Please see the v2 series for any other details I've missed. > > thanks, > -- > John Hub

[PATCH v3 11/11] powerpc/mm/book3s64/pgtable: Uses counting method to skip serializing

2019-09-24 Thread Leonardo Bras
Skips slow part of serialize_against_pte_lookup if there is no running lockless pagetable walk. Signed-off-by: Leonardo Bras --- arch/powerpc/mm/book3s64/pgtable.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/book3s64/pgtable.c b/arch/powerpc/mm

[PATCH v3 09/11] powerpc/kvm/book3s_64: Applies counting method to monitor lockless pgtbl walks

2019-09-24 Thread Leonardo Bras
Applies the counting-based method for monitoring all book3s_64-related functions that do lockless pagetable walks. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/book3s_64_mmu_hv.c| 2 ++ arch/powerpc/kvm/book3s_64_mmu_radix.c | 20 ++-- arch/powerpc/kvm

[PATCH v3 10/11] powerpc/book3s_64: Enables counting method to monitor lockless pgtbl walk

2019-09-24 Thread Leonardo Bras
Enables count-based monitoring method for lockless pagetable walks on PowerPC book3s_64. Other architectures/platforms fallback to using generic dummy functions. Signed-off-by: Leonardo Bras --- arch/powerpc/include/asm/book3s/64/pgtable.h | 5 + 1 file changed, 5 insertions(+) diff --git

[PATCH v3 07/11] powerpc/kvm/e500: Applies counting method to monitor lockless pgtbl walks

2019-09-24 Thread Leonardo Bras
Applies the counting-based method for monitoring lockless pgtable walks on kvmppc_e500_shadow_map(). Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/e500_mmu_host.c | 4 1 file changed, 4 insertions(+) diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c

[PATCH v3 08/11] powerpc/kvm/book3s_hv: Applies counting method to monitor lockless pgtbl walks

2019-09-24 Thread Leonardo Bras
Applies the counting-based method for monitoring all book3s_hv related functions that do lockless pagetable walks. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/book3s_hv_nested.c | 8 arch/powerpc/kvm/book3s_hv_rm_mmu.c | 9 - 2 files changed, 16 insertions(+), 1 deletion

[PATCH v3 05/11] powerpc/perf: Applies counting method to monitor lockless pgtbl walks

2019-09-24 Thread Leonardo Bras
Applies the counting-based method for monitoring lockless pgtable walks on read_user_stack_slow. Signed-off-by: Leonardo Bras --- arch/powerpc/perf/callchain.c | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/perf/callchain.c b/arch/powerpc/perf/callchain.c

[PATCH v3 06/11] powerpc/mm/book3s64/hash: Applies counting method to monitor lockless pgtbl walks

2019-09-24 Thread Leonardo Bras
Applies the counting-based method for monitoring all hash-related functions that do lockless pagetable walks. Signed-off-by: Leonardo Bras --- arch/powerpc/mm/book3s64/hash_tlb.c | 2 ++ arch/powerpc/mm/book3s64/hash_utils.c | 7 +++ 2 files changed, 9 insertions(+) diff --git a/arch

[PATCH v3 03/11] mm/gup: Applies counting method to monitor gup_pgd_range

2019-09-24 Thread Leonardo Bras
this method. Signed-off-by: Leonardo Bras --- mm/gup.c | 8 1 file changed, 8 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 98f13ab37bac..eabd6fd15cf8 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2325,6 +2325,7 @@ static bool gup_fast_permitted(unsigned long start, unsigned long end) int

[PATCH v3 02/11] asm-generic/pgtable: Adds dummy functions to monitor lockless pgtable walks

2019-09-24 Thread Leonardo Bras
approach, that counts the number of lockless pagetable walks happening on the process. Given that there are lockless pagetable walks on generic code, it's necessary to create dummy functions for archs that won't use the approach. Signed-off-by: Leonardo Bras --- include/asm-generic/pgtable.h

[PATCH v3 04/11] powerpc/mce_power: Applies counting method to monitor lockless pgtbl walks

2019-09-24 Thread Leonardo Bras
Applies the counting-based method for monitoring lockless pgtable walks on addr_to_pfn(). Signed-off-by: Leonardo Bras --- arch/powerpc/kernel/mce_power.c | 13 ++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kernel/mce_power.c b/arch/powerpc/kernel

[PATCH v3 01/11] powerpc/mm: Adds counting method to monitor lockless pgtable walks

2019-09-24 Thread Leonardo Bras
end_lockless_pgtbl_walk(mm) Insert after the end of any lockless pgtable walk (Mostly after the ptep is last used) running_lockless_pgtbl_walk(mm) Returns the number of lockless pgtable walks running Signed-off-by: Leonardo Bras --- arch/powerpc/include/asm/book3s/64/mmu.h | 3

[PATCH v3 00/11] Introduces new count-based method for monitoring lockless pagetable walks

2019-09-24 Thread Leonardo Bras
ges since v1: Isolated atomic operations in functions *_lockless_pgtbl_walk() Fixed behavior of decrementing before last ptep was used Link: http://patchwork.ozlabs.org/patch/1163093/ Leonardo Bras (11): powerpc/mm: Adds counting method to monitor lockless pgtable walks asm-generic/pgta

Re: [PATCH v2 11/11] powerpc/mm/book3s64/pgtable: Uses counting method to skip serializing

2019-09-24 Thread Leonardo Bras
before, I think it would be wiser to send a v3 and gather feedback while I keep trying to understand how it works, and if it needs additional memory barrier here. Thanks! Leonardo Bras signature.asc Description: This is a digitally signed message part

Re: [PATCH v2 00/11] Introduces new count-based method for monitoring lockless pagetable wakls

2019-09-24 Thread Leonardo Bras
John Hubbard writes: > Also, which tree do these patches apply to, please? I will send a v3 that applies directly over v5.3, and make sure to include mm mailing list. Thanks! signature.asc Description: This is a digitally signed message part

Re: [PATCH 1/1] powerpc: kvm: Reduce calls to get current->mm by storing the value locally

2019-09-23 Thread Leonardo Bras
I have done a very simple comparison with gdb disassemble: By applying this patch, there was a reduction in the function size from 882 to 878 instructions. (It's a resend, due to not having all the correct lists on my previous mail) On Mon, 2019-09-23 at 18:30 -0300, Leonardo Bras wrote

[PATCH 1/1] powerpc: kvm: Reduce calls to get current->mm by storing the value locally

2019-09-23 Thread Leonardo Bras
Reduces the number of calls to get_current() in order to get the value of current->mm by doing it once and storing the value, since it is not supposed to change inside the same process). Signed-off-by: Leonardo Bras --- Re-sending to all lists involved. (I missed kvm ones) arch/powerpc/

Re: [PATCH v2 03/11] mm/gup: Applies counting method to monitor gup_pgd_range

2019-09-23 Thread Leonardo Bras
On Mon, 2019-09-23 at 13:27 -0700, John Hubbard wrote: > I'd also like a second opinion from the "core" -mm maintainers, but it seems > like > there is now too much code around the gup_pgd_range() call. Especially since > there > are two places where it's called--did you forget the other one in

Re: [PATCH v2 00/11] Introduces new count-based method for monitoring lockless pagetable wakls

2019-09-23 Thread Leonardo Bras
rged fast. But since I got no feedback, it was not merged and the present patchset became broken. :( But I will rebase v3 on top of plain v5.3. Thanks, Leonardo Bras signature.asc Description: This is a digitally signed message part

Re: [PATCH v2 01/11] powerpc/mm: Adds counting method to monitor lockless pgtable walks

2019-09-23 Thread Leonardo Bras
On Mon, 2019-09-23 at 13:42 -0700, John Hubbard wrote: > Somewhere, there should be a short comment that explains how the following > functions > are meant to be used. And it should include the interaction with irqs, so > maybe > if you end up adding that combined wrapper function that does

Re: [PATCH v2 02/11] asm-generic/pgtable: Adds dummy functions to monitor lockless pgtable walks

2019-09-23 Thread Leonardo Bras
Thanks for the feedback, On Mon, 2019-09-23 at 13:39 -0700, John Hubbard wrote: > Please remember to include linux-mm if there is a v2. Sure, I will include on v3. > Nit: seems like it would be nicer to just put it all in one place, and use > positive logic, and also I think people normally

Re: [PATCH v2 11/11] powerpc/mm/book3s64/pgtable: Uses counting method to skip serializing

2019-09-23 Thread Leonardo Bras
On Mon, 2019-09-23 at 12:58 -0700, John Hubbard wrote: > > CPU 0CPU 1 > -- -- >READ(pte) (re-ordered at run time) >atomic_inc(val) (no run-time memory barrier!) >

Re: [PATCH v2 11/11] powerpc/mm/book3s64/pgtable: Uses counting method to skip serializing

2019-09-23 Thread Leonardo Bras
On Mon, 2019-09-23 at 11:14 -0700, John Hubbard wrote: > On 9/23/19 10:25 AM, Leonardo Bras wrote: > [...] > That part is all fine, but there are no run-time memory barriers in the > atomic_inc() and atomic_dec() additions, which means that this is not > safe, because memory oper

Re: [PATCH 1/1] powerpc: kvm: Reduce calls to get current->mm by storing the value locally

2019-09-23 Thread Leonardo Bras
On Mon, 2019-09-23 at 15:35 -0300, Leonardo Bras wrote: > Could you please provide feedback on this patch? I have done a very simple comparison with gcc disassemble: By applying this patch, there was a reduction in the function size from 882 to 878 instructions. signature.asc Descript

[PATCH 3/3] powerpc/kvm/e500: Replace current->mm by kvm->mm

2019-09-23 Thread Leonardo Bras
code, relying more in the contents of kvm struct. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/e500_mmu_host.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c index 321db0fdb9db..425d13806645 100644

[PATCH 2/3] powerpc/kvm/book3e: Replace current->mm by kvm->mm

2019-09-23 Thread Leonardo Bras
code, relying more in the contents of kvm struct. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/booke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index be9a45874194..383108263af5 100644 --- a/arch/powerpc/kvm/booke.c

[PATCH 1/3] powerpc/kvm/book3s: Replace current->mm by kvm->mm

2019-09-23 Thread Leonardo Bras
code, relying more in the contents of kvm struct. Signed-off-by: Leonardo Bras --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 4 ++-- arch/powerpc/kvm/book3s_64_vio.c| 6 +++--- arch/powerpc/kvm/book3s_hv.c| 10 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git

[PATCH 0/3] Replace current->mm by kvm->mm on powerpc/kvm

2019-09-23 Thread Leonardo Bras
rn -EIO; So this change would be safe. I split the changes in 3 patches, so it would be easier to read and reject separated parts. If decided that squashing is better, I see no problem doing that. Best regards, Leonardo Bras (3): powerpc/kvm/book3s: Replace current->mm by kvm->mm powerpc/k

Re: [PATCH 1/1] powerpc: kvm: Reduce calls to get current->mm by storing the value locally

2019-09-23 Thread Leonardo Bras
On Thu, 2019-09-19 at 23:47 -0300, Leonardo Bras wrote: > Hello Paul, > I sent this patch, but I have a question: > > > + mm = current->mm; > > Here, current->mm is not always the same as kvm->mm? > Thanks I have contacted Paul, who said it is eq

Re: [PATCH v2 11/11] powerpc/mm/book3s64/pgtable: Uses counting method to skip serializing

2019-09-23 Thread Leonardo Bras
ollapse wait for gup_pgd_range() completion in every cpu before continuing. (here happens the lock) (As told before, every gup_pgd_range() that occurs after it uses a updated pmd, so no problem.) I am sure other archs may have a similar mechanism using local_irq_{disable,enable}. Did it answer your quest

Re: [PATCH v2 11/11] powerpc/mm/book3s64/pgtable: Uses counting method to skip serializing

2019-09-20 Thread Leonardo Bras
On Fri, 2019-09-20 at 13:11 -0700, John Hubbard wrote: > On 9/20/19 12:50 PM, Leonardo Bras wrote: > > Skips slow part of serialize_against_pte_lookup if there is no running > > lockless pagetable walk. > > > > Signed-off-by: Leonardo Bras > > --- > >

<    1   2   3   4   5   >