Re: [RFC PATCH 2/2] mm/mmu_gather: Avoid multiple page walk cache flush

2019-12-17 Thread Peter Zijlstra
On Tue, Dec 17, 2019 at 03:45:36PM +0530, Aneesh Kumar K.V wrote:
> On 12/17/19 2:28 PM, Peter Zijlstra wrote:
> > On Tue, Dec 17, 2019 at 12:47:13PM +0530, Aneesh Kumar K.V wrote:
> > > On tlb_finish_mmu() kernel does a tlb flush before  mmu gather table 
> > > invalidate.
> > > The mmu gather table invalidate depending on kernel config also does 
> > > another
> > > TLBI. Avoid the later on tlb_finish_mmu().
> > 
> > That is already avoided, if you look at tlb_flush_mmu_tlbonly() it does
> > __tlb_range_reset(), which results in ->end = 0, which then triggers the
> > early exit on the next invocation:
> > 
> > if (!tlb->end)
> > return;
> > 
> 
> Is that true for tlb->fulmm flush?

Hmm, no, but I'm thinking you patch is broken, even for that case. We
must issue the TLBI before call_rcu().

Perhaps if we replace !tlb->end with something like:

  !tlb->freed_tables && !tlb->cleared_p*

(which GCC should be able to do with a single load and mask)

I've not really thought too hard about it yet, I need to run some
errands, but I'll look at it more closely when I get back.


Re: [RFC PATCH 2/2] mm/mmu_gather: Avoid multiple page walk cache flush

2019-12-17 Thread Aneesh Kumar K.V

On 12/17/19 2:28 PM, Peter Zijlstra wrote:

On Tue, Dec 17, 2019 at 12:47:13PM +0530, Aneesh Kumar K.V wrote:

On tlb_finish_mmu() kernel does a tlb flush before  mmu gather table invalidate.
The mmu gather table invalidate depending on kernel config also does another
TLBI. Avoid the later on tlb_finish_mmu().


That is already avoided, if you look at tlb_flush_mmu_tlbonly() it does
__tlb_range_reset(), which results in ->end = 0, which then triggers the
early exit on the next invocation:

if (!tlb->end)
return;



Is that true for tlb->fulmm flush?

-aneesh


Re: [RFC PATCH 2/2] mm/mmu_gather: Avoid multiple page walk cache flush

2019-12-17 Thread Peter Zijlstra
On Tue, Dec 17, 2019 at 12:47:13PM +0530, Aneesh Kumar K.V wrote:
> On tlb_finish_mmu() kernel does a tlb flush before  mmu gather table 
> invalidate.
> The mmu gather table invalidate depending on kernel config also does another
> TLBI. Avoid the later on tlb_finish_mmu().

That is already avoided, if you look at tlb_flush_mmu_tlbonly() it does
__tlb_range_reset(), which results in ->end = 0, which then triggers the
early exit on the next invocation:

if (!tlb->end)
return;


[RFC PATCH 2/2] mm/mmu_gather: Avoid multiple page walk cache flush

2019-12-16 Thread Aneesh Kumar K.V
On tlb_finish_mmu() kernel does a tlb flush before  mmu gather table invalidate.
The mmu gather table invalidate depending on kernel config also does another
TLBI. Avoid the later on tlb_finish_mmu().

Signed-off-by: Aneesh Kumar K.V 
---
 mm/mmu_gather.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c
index 7c1b8f67af7b..7e2bd43b9084 100644
--- a/mm/mmu_gather.c
+++ b/mm/mmu_gather.c
@@ -143,17 +143,23 @@ static void tlb_remove_table_rcu(struct rcu_head *head)
free_page((unsigned long)batch);
 }
 
-static void tlb_table_flush(struct mmu_gather *tlb)
+static void __tlb_table_flush(struct mmu_gather *tlb, bool table_inval)
 {
struct mmu_table_batch **batch = >batch;
 
if (*batch) {
-   tlb_table_invalidate(tlb);
+   if (table_inval)
+   tlb_table_invalidate(tlb);
call_rcu(&(*batch)->rcu, tlb_remove_table_rcu);
*batch = NULL;
}
 }
 
+static void tlb_table_flush(struct mmu_gather *tlb)
+{
+   __tlb_table_flush(tlb, true);
+}
+
 void tlb_remove_table(struct mmu_gather *tlb, void *table)
 {
struct mmu_table_batch **batch = >batch;
@@ -178,7 +184,7 @@ void tlb_remove_table(struct mmu_gather *tlb, void *table)
 static void tlb_flush_mmu_free(struct mmu_gather *tlb)
 {
 #ifdef CONFIG_HAVE_RCU_TABLE_FREE
-   tlb_table_flush(tlb);
+   __tlb_table_flush(tlb, false);
 #endif
 #ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER
tlb_batch_pages_flush(tlb);
-- 
2.23.0



[RFC PATCH 2/2] mm/mmu_gather: Avoid multiple page walk cache flush

2019-12-16 Thread Aneesh Kumar K.V
On tlb_finish_mmu() kernel does a tlb flush before  mmu gather table invalidate.
The mmu gather table invalidate depending on kernel config also does another
TLBI. Avoid the later on tlb_finish_mmu().

Signed-off-by: Aneesh Kumar K.V 
---
 mm/mmu_gather.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c
index 7c1b8f67af7b..7e2bd43b9084 100644
--- a/mm/mmu_gather.c
+++ b/mm/mmu_gather.c
@@ -143,17 +143,23 @@ static void tlb_remove_table_rcu(struct rcu_head *head)
free_page((unsigned long)batch);
 }
 
-static void tlb_table_flush(struct mmu_gather *tlb)
+static void __tlb_table_flush(struct mmu_gather *tlb, bool table_inval)
 {
struct mmu_table_batch **batch = >batch;
 
if (*batch) {
-   tlb_table_invalidate(tlb);
+   if (table_inval)
+   tlb_table_invalidate(tlb);
call_rcu(&(*batch)->rcu, tlb_remove_table_rcu);
*batch = NULL;
}
 }
 
+static void tlb_table_flush(struct mmu_gather *tlb)
+{
+   __tlb_table_flush(tlb, true);
+}
+
 void tlb_remove_table(struct mmu_gather *tlb, void *table)
 {
struct mmu_table_batch **batch = >batch;
@@ -178,7 +184,7 @@ void tlb_remove_table(struct mmu_gather *tlb, void *table)
 static void tlb_flush_mmu_free(struct mmu_gather *tlb)
 {
 #ifdef CONFIG_HAVE_RCU_TABLE_FREE
-   tlb_table_flush(tlb);
+   __tlb_table_flush(tlb, false);
 #endif
 #ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER
tlb_batch_pages_flush(tlb);
-- 
2.23.0