Received: by 10.213.65.68 with SMTP id h4csp41068imn; Mon, 19 Mar 2018 18:54:07 -0700 (PDT) X-Google-Smtp-Source: AG47ELv4PsfbaA6ZRCZyz/LDqkDg1t9GRwheK7Qwc/bysUGLBMpl8vZO292Pf1dOnV22bbZxrdqF X-Received: by 10.99.97.149 with SMTP id v143mr10697724pgb.319.1521510847133; Mon, 19 Mar 2018 18:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521510847; cv=none; d=google.com; s=arc-20160816; b=uf6jvEBaplza1VHqX71+cHS8nxRwx8SDPUYJIYzblPaIjVlLPfuMKFX57kNMrYnpAL gCXNRH3gMz+N1aaTYTHnVnx87yuyR9awxmwrcDLRJFNTzMQOTNzACsiCK8MW45bZnHX9 Rc7dEZL5oYGJUXgSX6HiPqbjQOCVDL4NLdXmZKiQ7FgIf/mbu11caY/hW4lyzBnPf74L PA/lS9hrnyYEbSEsdRC/EWvHn1b0e9gAtRIBZrPXoKSYMSXMLpMcNKlzr1lPP/1CrwWn 6U5g1Fl3iO0wa554RuKcupMr3/JvEOrQAtvOHKFW/XtiUgvklnK7sKkmCyhy9BxtT/m+ IKxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=iNMiPHz8dmW2jaSUD4C0Pgt2HQxwEZmfYkV//iW7gA0=; b=EbhbDHWcUEVgiHOBvMeTSDfJND9qjvIp1BAw+jIF2n6NKdfScIO7OXamw09ibjCVHF a/G8fgcbHp1pZlAGSU1YTB5T3hn0ASY8wtaZTIFQYKPWkNRbzg9UTrW9u05pUADqDnJT +a6kYdROH9gHHlzhlOcbBB5rwLRFYqRL8gLSGkNslzyFN2orHMzoML5tOELHDzu96oEs FB+GCXhTFgj1xPXK3dC7G/+LmKWvYpvntnMdprBh5w8vSzUvUjytSMjE6TZpQpypi8P6 E6p9nFnJ90G7ZgYx7MlJP55WyAbY0ACv/wc3Fzj0SCPJ2kBJQv0WMu6abURpnd/jEi/t BayA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y72-v6si576031plh.72.2018.03.19.18.53.53; Mon, 19 Mar 2018 18:54:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S971754AbeCSUzu (ORCPT + 99 others); Mon, 19 Mar 2018 16:55:50 -0400 Received: from mga14.intel.com ([192.55.52.115]:62509 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968538AbeCSSIz (ORCPT ); Mon, 19 Mar 2018 14:08:55 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Mar 2018 11:08:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,331,1517904000"; d="scan'208";a="39330599" Received: from chang-linux.sc.intel.com ([143.183.85.144]) by fmsmga001.fm.intel.com with ESMTP; 19 Mar 2018 11:08:53 -0700 From: "Chang S. Bae" To: x86@kernel.org Cc: luto@kernel.org, ak@linux.intel.com, hpa@zytor.com, markus.t.metzger@intel.com, tony.luck@intel.com, ravi.v.shankar@intel.com, linux-kernel@vger.kernel.org, chang.seok.bae@intel.com Subject: [PATCH 12/15] x86/fsgsbase/64: When copying a thread, use FSGSBASE if enabled Date: Mon, 19 Mar 2018 10:49:24 -0700 Message-Id: <1521481767-22113-13-git-send-email-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521481767-22113-1-git-send-email-chang.seok.bae@intel.com> References: <1521481767-22113-1-git-send-email-chang.seok.bae@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Andi Kleen --- 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