From: Balbir Singh <sblbir@amazon.com>
To: <linux-kernel@vger.kernel.org>, <tglx@linutronix.de>
Cc: <tony.luck@intel.com>, <keescook@chromium.org>, <x86@kernel.org>,
<benh@kernel.crashing.org>, <dave.hansen@intel.com>,
Balbir Singh <sblbir@amazon.com>
Subject: [RFC PATCH v2 4/4] arch/x86: L1D flush, optimize the context switch
Date: Wed, 25 Mar 2020 18:11:01 +1100 [thread overview]
Message-ID: <20200325071101.29556-5-sblbir@amazon.com> (raw)
In-Reply-To: <20200325071101.29556-1-sblbir@amazon.com>
Use a static branch/jump label to optimize the code. Right now
we don't ref count the users, but that could be done if needed
in the future.
Signed-off-by: Balbir Singh <sblbir@amazon.com>
---
arch/x86/include/asm/nospec-branch.h | 2 ++
arch/x86/mm/tlb.c | 13 +++++++++++++
2 files changed, 15 insertions(+)
diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index 07e95dcb40ad..371e28cea1f4 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -310,6 +310,8 @@ DECLARE_STATIC_KEY_FALSE(switch_mm_always_ibpb);
DECLARE_STATIC_KEY_FALSE(mds_user_clear);
DECLARE_STATIC_KEY_FALSE(mds_idle_clear);
+DECLARE_STATIC_KEY_FALSE(switch_mm_l1d_flush);
+
#include <asm/segment.h>
/**
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index 22f96c5f74f0..bed2b6a5490d 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -155,6 +155,11 @@ EXPORT_SYMBOL_GPL(leave_mm);
static void *l1d_flush_pages;
static DEFINE_MUTEX(l1d_flush_mutex);
+/* Flush L1D on switch_mm() */
+DEFINE_STATIC_KEY_FALSE(switch_mm_l1d_flush);
+EXPORT_SYMBOL_GPL(switch_mm_l1d_flush);
+
+
int enable_l1d_flush_for_task(struct task_struct *tsk)
{
struct page *page;
@@ -170,6 +175,11 @@ int enable_l1d_flush_for_task(struct task_struct *tsk)
l1d_flush_pages = alloc_l1d_flush_pages();
if (!l1d_flush_pages)
return -ENOMEM;
+ /*
+ * We could do more accurate ref counting
+ * if needed
+ */
+ static_branch_enable(&switch_mm_l1d_flush);
}
mutex_unlock(&l1d_flush_mutex);
}
@@ -195,6 +205,9 @@ static void l1d_flush(struct mm_struct *next, struct task_struct *tsk)
{
struct mm_struct *real_prev = this_cpu_read(cpu_tlbstate.loaded_mm);
+ if (static_branch_unlikely(&switch_mm_l1d_flush))
+ return;
+
/*
* If we are not really switching mm's, we can just return
*/
--
2.17.1
next prev parent reply other threads:[~2020-03-25 7:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-25 7:10 [RFC PATCH v2 0/4] arch/x86: Optionally flush L1D on context switch Balbir Singh
2020-03-25 7:10 ` [RFC PATCH v2 1/4] arch/x86/kvm: Refactor l1d flush lifecycle management Balbir Singh
2020-03-25 7:10 ` [RFC PATCH v2 2/4] arch/x86: Refactor tlbflush and l1d flush Balbir Singh
2020-03-25 7:11 ` [RFC PATCH v2 3/4] arch/x86: Optionally flush L1D on context switch Balbir Singh
2020-03-31 18:34 ` Thomas Gleixner
2020-03-31 23:56 ` Singh, Balbir
2020-03-25 7:11 ` Balbir Singh [this message]
2020-03-25 7:15 ` [RFC PATCH v2 4/4] arch/x86: L1D flush, optimize the " Singh, Balbir
2020-03-30 1:13 ` [RFC PATCH v2 0/4] arch/x86: Optionally flush L1D on " Singh, Balbir
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=20200325071101.29556-5-sblbir@amazon.com \
--to=sblbir@amazon.com \
--cc=benh@kernel.crashing.org \
--cc=dave.hansen@intel.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox