Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp745057ima; Fri, 15 Mar 2019 13:10:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwiPU2NWlVOv/v/6ypvlEvkWIGllAUiOTbokUZEoh/ce4El5oDVNYFhrk1SP1hn74Up02Vf X-Received: by 2002:a62:46cc:: with SMTP id o73mr6032235pfi.182.1552680629320; Fri, 15 Mar 2019 13:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552680629; cv=none; d=google.com; s=arc-20160816; b=d/1PzXSSWGcFp14Eaeu32KhkfzULMAUUuPRTD9OkZiCoGzKQBWDDZIlCBhY6lG+rxv Slq3lHIdm7MAfuwK0fV7i9eWe/AH7abKB9Mdi3yqEyJoIaoZaU7jsb9sUszxXUh9WVXh QI6Jr97EDsJ4ZsVod3WhcxHiD7xG8NqIBFPyIzU4OfUwgF7cNavcxuqT7zXu3BtXWi9P tg8gJHn1qw6Z8iJRHmRqWIc72L3+zxA07g27lzxyIWbWl4T00VOURjDHGWVPqwoES64p 6uPLqJUnwNM0JZV1v5sDwnk1Zk+/2NQnkoVILyYWq/64DzGnGJK0+Wo5XHTJChf20Vsz nJsQ== 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; bh=poDqLJBwdK4J1SFS9R+JK5MPyD3I3j7BoAjprASYAqk=; b=czHDLeve5wC7hoTBxF2nhZ95xg/+CsXLvQkYWKdmdyNoWZzghPr6BoR41SjeY3MVlV RjoKeikbupcyiYuoNvba8uAZF0zCFk8GnllOPi36sFiRrXqoMF4xIW8kOqhDEKfvnDkA gVo9XTL9gHhdd/tuTvqp6uRzDPGiTverh6jPyY0yat9vekURzUZ4AFSscfZEDIYoLUgG pBsDrqfkmSKH9p1+PNdf28RX2LRalt9YHPC8SpgoxGPS7OfFooT8F61pidANONub0y+O PM6ReAaxtFyznrgjum7hDJH7FSNUTGdWm8MXDM+yRdjGs1wg9fi3hL33TE0nADFGDpy8 rMxg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t193si2616962pgc.336.2019.03.15.13.10.11; Fri, 15 Mar 2019 13:10:29 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727044AbfCOUHt (ORCPT + 99 others); Fri, 15 Mar 2019 16:07:49 -0400 Received: from mga01.intel.com ([192.55.52.88]:22900 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726585AbfCOUHD (ORCPT ); Fri, 15 Mar 2019 16:07:03 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Mar 2019 13:07:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,483,1544515200"; d="scan'208";a="307617710" Received: from chang-linux-3.sc.intel.com ([143.183.85.65]) by orsmga005.jf.intel.com with ESMTP; 15 Mar 2019 13:07:02 -0700 From: "Chang S. Bae" To: Thomas Gleixner , Ingo Molnar , Andy Lutomirski , "H . Peter Anvin" , Andi Kleen Cc: Ravi Shankar , "Chang S . Bae" , LKML Subject: [RESEND PATCH v6 06/12] x86/fsgsbase/64: When copying a thread, use the FSGSBASE instructions if available Date: Fri, 15 Mar 2019 13:06:39 -0700 Message-Id: <1552680405-5265-7-git-send-email-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1552680405-5265-1-git-send-email-chang.seok.bae@intel.com> References: <1552680405-5265-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 Copy real FS/GSBASE values instead of approximation when FSGSBASE is enabled. Suggested-by: Andy Lutomirski Signed-off-by: Chang S. Bae Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Andi Kleen --- arch/x86/kernel/process_64.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index d3abe4748d8b..c4de0907d909 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -422,7 +422,8 @@ unsigned long x86_fsbase_read_task(struct task_struct *task) if (task == current) fsbase = x86_fsbase_read_cpu(); - else if (task->thread.fsindex == 0) + else if (static_cpu_has(X86_FEATURE_FSGSBASE) || + (task->thread.fsindex == 0)) fsbase = task->thread.fsbase; else fsbase = x86_fsgsbase_read_task(task, task->thread.fsindex); @@ -436,7 +437,8 @@ unsigned long x86_gsbase_read_task(struct task_struct *task) if (task == current) gsbase = x86_gsbase_read_cpu_inactive(); - else if (task->thread.gsindex == 0) + else if (static_cpu_has(X86_FEATURE_FSGSBASE) || + (task->thread.gsindex == 0)) gsbase = task->thread.gsbase; else gsbase = x86_fsgsbase_read_task(task, task->thread.gsindex); @@ -475,10 +477,11 @@ 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; + save_fsgs(me); + p->thread.fsindex = me->thread.fsindex; + p->thread.fsbase = me->thread.fsbase; + p->thread.gsindex = me->thread.gsindex; + p->thread.gsbase = 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.19.1