From: Andrea Arcangeli <aarcange@redhat.com>
To: Will Deacon <will@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Jon Masters <jcm@jonmasters.org>,
Rafael Aquini <aquini@redhat.com>,
Mark Salter <msalter@redhat.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] mm: use_mm: fix for arches checking mm_users to optimize TLB flushes
Date: Mon, 3 Feb 2020 15:17:44 -0500 [thread overview]
Message-ID: <20200203201745.29986-2-aarcange@redhat.com> (raw)
In-Reply-To: <20200203201745.29986-1-aarcange@redhat.com>
alpha, ia64, mips, powerpc, sh, sparc are relying on a check on
mm->mm_users to know if they can skip some remote TLB flushes for
single threaded processes.
Most callers of use_mm() tend to invoke mmget_not_zero() or
get_task_mm() before use_mm() to ensure the mm will remain alive in
between use_mm() and unuse_mm().
Some callers however don't increase mm_users and they instead rely on
serialization in __mmput() to ensure the mm will remain alive in
between use_mm() and unuse_mm(). Not increasing mm_users during
use_mm() is however unsafe for aforementioned arch TLB flushes
optimizations. So either mmget()/mmput() should be added to the
problematic callers of use_mm()/unuse_mm() or we can embed them in
use_mm()/unuse_mm() which is more robust.
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
---
mm/mmu_context.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mm/mmu_context.c b/mm/mmu_context.c
index 3e612ae748e9..ced0e1218c0f 100644
--- a/mm/mmu_context.c
+++ b/mm/mmu_context.c
@@ -30,6 +30,7 @@ void use_mm(struct mm_struct *mm)
mmgrab(mm);
tsk->active_mm = mm;
}
+ mmget(mm);
tsk->mm = mm;
switch_mm(active_mm, mm, tsk);
task_unlock(tsk);
@@ -57,6 +58,7 @@ void unuse_mm(struct mm_struct *mm)
task_lock(tsk);
sync_mm_rss(mm);
tsk->mm = NULL;
+ mmput(mm);
/* active_mm is still 'mm' */
enter_lazy_tlb(mm, tsk);
task_unlock(tsk);
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
WARNING: multiple messages have this Message-ID (diff)
From: Andrea Arcangeli <aarcange@redhat.com>
To: Will Deacon <will@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Jon Masters <jcm@jonmasters.org>,
Rafael Aquini <aquini@redhat.com>,
Mark Salter <msalter@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] mm: use_mm: fix for arches checking mm_users to optimize TLB flushes
Date: Mon, 3 Feb 2020 15:17:44 -0500 [thread overview]
Message-ID: <20200203201745.29986-2-aarcange@redhat.com> (raw)
In-Reply-To: <20200203201745.29986-1-aarcange@redhat.com>
alpha, ia64, mips, powerpc, sh, sparc are relying on a check on
mm->mm_users to know if they can skip some remote TLB flushes for
single threaded processes.
Most callers of use_mm() tend to invoke mmget_not_zero() or
get_task_mm() before use_mm() to ensure the mm will remain alive in
between use_mm() and unuse_mm().
Some callers however don't increase mm_users and they instead rely on
serialization in __mmput() to ensure the mm will remain alive in
between use_mm() and unuse_mm(). Not increasing mm_users during
use_mm() is however unsafe for aforementioned arch TLB flushes
optimizations. So either mmget()/mmput() should be added to the
problematic callers of use_mm()/unuse_mm() or we can embed them in
use_mm()/unuse_mm() which is more robust.
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
---
mm/mmu_context.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mm/mmu_context.c b/mm/mmu_context.c
index 3e612ae748e9..ced0e1218c0f 100644
--- a/mm/mmu_context.c
+++ b/mm/mmu_context.c
@@ -30,6 +30,7 @@ void use_mm(struct mm_struct *mm)
mmgrab(mm);
tsk->active_mm = mm;
}
+ mmget(mm);
tsk->mm = mm;
switch_mm(active_mm, mm, tsk);
task_unlock(tsk);
@@ -57,6 +58,7 @@ void unuse_mm(struct mm_struct *mm)
task_lock(tsk);
sync_mm_rss(mm);
tsk->mm = NULL;
+ mmput(mm);
/* active_mm is still 'mm' */
enter_lazy_tlb(mm, tsk);
task_unlock(tsk);
next prev parent reply other threads:[~2020-02-03 20:20 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-03 20:17 [RFC] [PATCH 0/2] arm64: tlb: skip tlbi broadcast for single threaded TLB flushes Andrea Arcangeli
2020-02-03 20:17 ` Andrea Arcangeli
2020-02-03 20:17 ` Andrea Arcangeli [this message]
2020-02-03 20:17 ` [PATCH 1/2] mm: use_mm: fix for arches checking mm_users to optimize " Andrea Arcangeli
2020-02-18 11:31 ` Michal Hocko
2020-02-18 11:31 ` Michal Hocko
2020-02-18 18:56 ` Andrea Arcangeli
2020-02-18 18:56 ` Andrea Arcangeli
2020-02-19 11:58 ` Michal Hocko
2020-02-19 11:58 ` Michal Hocko
2020-02-19 20:04 ` Andrea Arcangeli
2020-02-19 20:04 ` Andrea Arcangeli
2020-02-03 20:17 ` [PATCH 2/2] arm64: tlb: skip tlbi broadcast for single threaded " Andrea Arcangeli
2020-02-03 20:17 ` Andrea Arcangeli
2020-02-10 17:51 ` Catalin Marinas
2020-02-10 17:51 ` Catalin Marinas
2020-02-10 20:14 ` Andrea Arcangeli
2020-02-10 20:14 ` Andrea Arcangeli
2020-02-11 14:00 ` Catalin Marinas
2020-02-11 14:00 ` Catalin Marinas
2020-02-12 12:57 ` Andrea Arcangeli
2020-02-12 12:57 ` Andrea Arcangeli
2020-02-12 14:13 ` qi.fuli
2020-02-12 14:13 ` qi.fuli
2020-02-12 15:26 ` Catalin Marinas
2020-02-12 15:26 ` Catalin Marinas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200203201745.29986-2-aarcange@redhat.com \
--to=aarcange@redhat.com \
--cc=aquini@redhat.com \
--cc=catalin.marinas@arm.com \
--cc=jcm@jonmasters.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=msalter@redhat.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.