linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/mm: Change barriers before TLB flushes to smp_mb__after_atomic
@ 2016-05-28  3:16 Nadav Amit
  2016-06-09 17:19 ` Andy Lutomirski
  0 siblings, 1 reply; 3+ messages in thread
From: Nadav Amit @ 2016-05-28  3:16 UTC (permalink / raw)
  To: x86, linux-kernel
  Cc: nadav.amit, Nadav Amit, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, Andrew Morton, Dave Hansen, Rik van Riel,
	Mel Gorman, Andy Lutomirski, Kirill A. Shutemov, Michal Hocko,
	Vladimir Davydov, Jerome Marchand, Johannes Weiner, Hugh Dickins,
	Minchan Kim, open list:MEMORY MANAGEMENT

When (current->active_mm != mm), flush_tlb_page() does not perform a
memory barrier. In practice, this memory barrier is not needed since in
the existing call-sites the PTE is modified using atomic-operations.
This patch therefore modifies the existing smp_mb in flush_tlb_page to
smp_mb__after_atomic and adds the missing one, while documenting the new
assumption of flush_tlb_page.

In addition smp_mb__after_atomic is also added to
set_tlb_ubc_flush_pending, since it makes a similar implicit assumption
and omits the memory barrier.

Signed-off-by: Nadav Amit <namit@vmware.com>
---
 arch/x86/mm/tlb.c | 9 ++++++++-
 mm/rmap.c         | 3 +++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index fe9b9f7..2534333 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -242,6 +242,10 @@ out:
 	preempt_enable();
 }
 
+/*
+ * Calls to flush_tlb_page must be preceded by atomic PTE change or
+ * explicit memory-barrier.
+ */
 void flush_tlb_page(struct vm_area_struct *vma, unsigned long start)
 {
 	struct mm_struct *mm = vma->vm_mm;
@@ -259,8 +263,11 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long start)
 			leave_mm(smp_processor_id());
 
 			/* Synchronize with switch_mm. */
-			smp_mb();
+			smp_mb__after_atomic();
 		}
+	} else {
+		/* Synchronize with switch_mm. */
+		smp_mb__after_atomic();
 	}
 
 	if (cpumask_any_but(mm_cpumask(mm), smp_processor_id()) < nr_cpu_ids)
diff --git a/mm/rmap.c b/mm/rmap.c
index 307b555..60ab0fe 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -613,6 +613,9 @@ static void set_tlb_ubc_flush_pending(struct mm_struct *mm,
 {
 	struct tlbflush_unmap_batch *tlb_ubc = &current->tlb_ubc;
 
+	/* Synchronize with switch_mm. */
+	smp_mb__after_atomic();
+
 	cpumask_or(&tlb_ubc->cpumask, &tlb_ubc->cpumask, mm_cpumask(mm));
 	tlb_ubc->flush_required = true;
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/mm: Change barriers before TLB flushes to smp_mb__after_atomic
  2016-05-28  3:16 [PATCH] x86/mm: Change barriers before TLB flushes to smp_mb__after_atomic Nadav Amit
@ 2016-06-09 17:19 ` Andy Lutomirski
  2016-07-15 18:43   ` Nadav Amit
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Lutomirski @ 2016-06-09 17:19 UTC (permalink / raw)
  To: Nadav Amit
  Cc: X86 ML, linux-kernel, Nadav Amit, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, Andrew Morton, Dave Hansen, Rik van Riel,
	Mel Gorman, Andy Lutomirski, Kirill A. Shutemov, Michal Hocko,
	Vladimir Davydov, Jerome Marchand, Johannes Weiner, Hugh Dickins,
	Minchan Kim, open list:MEMORY MANAGEMENT

On Fri, May 27, 2016 at 8:16 PM, Nadav Amit <namit@vmware.com> wrote:
> When (current->active_mm != mm), flush_tlb_page() does not perform a
> memory barrier. In practice, this memory barrier is not needed since in
> the existing call-sites the PTE is modified using atomic-operations.
> This patch therefore modifies the existing smp_mb in flush_tlb_page to
> smp_mb__after_atomic and adds the missing one, while documenting the new
> assumption of flush_tlb_page.
>
> In addition smp_mb__after_atomic is also added to
> set_tlb_ubc_flush_pending, since it makes a similar implicit assumption
> and omits the memory barrier.
>
> Signed-off-by: Nadav Amit <namit@vmware.com>
> ---
>  arch/x86/mm/tlb.c | 9 ++++++++-
>  mm/rmap.c         | 3 +++
>  2 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
> index fe9b9f7..2534333 100644
> --- a/arch/x86/mm/tlb.c
> +++ b/arch/x86/mm/tlb.c
> @@ -242,6 +242,10 @@ out:
>         preempt_enable();
>  }
>
> +/*
> + * Calls to flush_tlb_page must be preceded by atomic PTE change or
> + * explicit memory-barrier.
> + */
>  void flush_tlb_page(struct vm_area_struct *vma, unsigned long start)
>  {
>         struct mm_struct *mm = vma->vm_mm;
> @@ -259,8 +263,11 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long start)
>                         leave_mm(smp_processor_id());
>
>                         /* Synchronize with switch_mm. */
> -                       smp_mb();
> +                       smp_mb__after_atomic();
>                 }
> +       } else {
> +               /* Synchronize with switch_mm. */
> +               smp_mb__after_atomic();
>         }
>
>         if (cpumask_any_but(mm_cpumask(mm), smp_processor_id()) < nr_cpu_ids)
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 307b555..60ab0fe 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -613,6 +613,9 @@ static void set_tlb_ubc_flush_pending(struct mm_struct *mm,
>  {
>         struct tlbflush_unmap_batch *tlb_ubc = &current->tlb_ubc;
>
> +       /* Synchronize with switch_mm. */
> +       smp_mb__after_atomic();
> +
>         cpumask_or(&tlb_ubc->cpumask, &tlb_ubc->cpumask, mm_cpumask(mm));
>         tlb_ubc->flush_required = true;
>
> --
> 2.7.4
>

This looks fine for x86, but I have no idea whether other
architectures are okay with it.  akpm?  mm folks?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/mm: Change barriers before TLB flushes to smp_mb__after_atomic
  2016-06-09 17:19 ` Andy Lutomirski
@ 2016-07-15 18:43   ` Nadav Amit
  0 siblings, 0 replies; 3+ messages in thread
From: Nadav Amit @ 2016-07-15 18:43 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Nadav Amit, X86 ML, linux-kernel, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, Dave Hansen, Rik van Riel, Mel Gorman,
	Andy Lutomirski, Kirill A. Shutemov, Michal Hocko,
	Vladimir Davydov, Jerome Marchand, Johannes Weiner, Hugh Dickins,
	Minchan Kim, open list:MEMORY MANAGEMENT, Andy Lutomirski

Andy Lutomirski <luto@amacapital.net> wrote:

> On Fri, May 27, 2016 at 8:16 PM, Nadav Amit <namit@vmware.com> wrote:
>> When (current->active_mm != mm), flush_tlb_page() does not perform a
>> memory barrier. In practice, this memory barrier is not needed since in
>> the existing call-sites the PTE is modified using atomic-operations.
>> This patch therefore modifies the existing smp_mb in flush_tlb_page to
>> smp_mb__after_atomic and adds the missing one, while documenting the new
>> assumption of flush_tlb_page.
>> 
>> In addition smp_mb__after_atomic is also added to
>> set_tlb_ubc_flush_pending, since it makes a similar implicit assumption
>> and omits the memory barrier.
>> 
>> Signed-off-by: Nadav Amit <namit@vmware.com>
>> ---
>> arch/x86/mm/tlb.c | 9 ++++++++-
>> mm/rmap.c         | 3 +++
>> 2 files changed, 11 insertions(+), 1 deletion(-)
>> 
>> diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
>> index fe9b9f7..2534333 100644
>> --- a/arch/x86/mm/tlb.c
>> +++ b/arch/x86/mm/tlb.c
>> @@ -242,6 +242,10 @@ out:
>>        preempt_enable();
>> }
>> 
>> +/*
>> + * Calls to flush_tlb_page must be preceded by atomic PTE change or
>> + * explicit memory-barrier.
>> + */
>> void flush_tlb_page(struct vm_area_struct *vma, unsigned long start)
>> {
>>        struct mm_struct *mm = vma->vm_mm;
>> @@ -259,8 +263,11 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long start)
>>                        leave_mm(smp_processor_id());
>> 
>>                        /* Synchronize with switch_mm. */
>> -                       smp_mb();
>> +                       smp_mb__after_atomic();
>>                }
>> +       } else {
>> +               /* Synchronize with switch_mm. */
>> +               smp_mb__after_atomic();
>>        }
>> 
>>        if (cpumask_any_but(mm_cpumask(mm), smp_processor_id()) < nr_cpu_ids)
>> diff --git a/mm/rmap.c b/mm/rmap.c
>> index 307b555..60ab0fe 100644
>> --- a/mm/rmap.c
>> +++ b/mm/rmap.c
>> @@ -613,6 +613,9 @@ static void set_tlb_ubc_flush_pending(struct mm_struct *mm,
>> {
>>        struct tlbflush_unmap_batch *tlb_ubc = &current->tlb_ubc;
>> 
>> +       /* Synchronize with switch_mm. */
>> +       smp_mb__after_atomic();
>> +
>>        cpumask_or(&tlb_ubc->cpumask, &tlb_ubc->cpumask, mm_cpumask(mm));
>>        tlb_ubc->flush_required = true;
>> 
>> --
>> 2.7.4
> 
> This looks fine for x86, but I have no idea whether other
> architectures are okay with it.  akpm?  mm folks?

Ping?

Note that this patch adds two missing barriers.

Thanks,
Nadav

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-15 18:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-28  3:16 [PATCH] x86/mm: Change barriers before TLB flushes to smp_mb__after_atomic Nadav Amit
2016-06-09 17:19 ` Andy Lutomirski
2016-07-15 18:43   ` Nadav Amit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).