[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1521481767-22113-13-git-send-email-chang.seok.bae@intel.com>
Date: Mon, 19 Mar 2018 10:49:24 -0700
From: "Chang S. Bae" <chang.seok.bae@...el.com>
To: x86@...nel.org
Cc: luto@...nel.org, ak@...ux.intel.com, hpa@...or.com,
markus.t.metzger@...el.com, tony.luck@...el.com,
ravi.v.shankar@...el.com, linux-kernel@...r.kernel.org,
chang.seok.bae@...el.com
Subject: [PATCH 12/15] x86/fsgsbase/64: When copying a thread, use FSGSBASE if enabled
When FSGSBASE enabled, copy real FS/GS base values instead
of approximation.
Factor out to save_fsgs() does not yield the exact same
behavior, because save_base_legacy() does not copy FS/GS base
when index is zero.
Signed-off-by: Chang S. Bae <chang.seok.bae@...el.com>
Cc: Andy Lutomirski <luto@...nel.org>
Cc: H. Peter Anvin <hpa@...or.com>
Cc: Andi Kleen <ak@...ux.intel.com>
---
arch/x86/kernel/process_64.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index 7249a54..5aae132 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -491,10 +491,16 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp,
p->thread.sp = (unsigned long) fork_frame;
p->thread.io_bitmap_ptr = NULL;
- savesegment(gs, p->thread.gsindex);
- p->thread.gsbase = p->thread.gsindex ? 0 : me->thread.gsbase;
savesegment(fs, p->thread.fsindex);
- p->thread.fsbase = p->thread.fsindex ? 0 : me->thread.fsbase;
+ savesegment(gs, p->thread.gsindex);
+ if (static_cpu_has(X86_FEATURE_FSGSBASE)) {
+ p->thread.fsbase = rdfsbase();
+ p->thread.gsbase = rd_shadow_gsbase();
+ } else {
+ /* save_base_legacy() does not set base when index is zero. */
+ p->thread.fsbase = p->thread.fsindex ? 0 : me->thread.fsbase;
+ p->thread.gsbase = p->thread.gsindex ? 0 : me->thread.gsbase;
+ }
savesegment(es, p->thread.es);
savesegment(ds, p->thread.ds);
memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
--
2.7.4
Powered by blists - more mailing lists