Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1336488imm; Wed, 20 Jun 2018 16:16:36 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK7ZYPESdjpmKgx31ctjn5mlsjufbV99Y4+y79DBynRuWEwhnksESi7ZLoSzi9qJAl7q7rU X-Received: by 2002:a63:6e8f:: with SMTP id j137-v6mr20796432pgc.453.1529536596605; Wed, 20 Jun 2018 16:16:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529536596; cv=none; d=google.com; s=arc-20160816; b=xwWSaALp29O3/+E0x3O8HpyDwr598SU3s5eKJenXUdpevw018Pp2BGtJ9ptwP1f4te d/0lORtNIykMCXUE4zaP88FNT6tG+xa9Pm07o3VGBxSIBtS/NOPDmqIj8kXO/sNJvMMK spxsBpUsst1UtKwkvXC/jEoVWSyjGqxOhD9jtT15s9Fkg6u1ZaQcBMf19SmXK+nommbo O18BGBdzYIsx5V7GX9KL0NkHM6jelR2Kx3AL/HrX7YQsdXCzaKJ756k6uEfqLlM2tmMm gcfU8j070DkZTQ8164w8/xl+SHfHUgBh4RDt+Fxt8k9J4doWb9DbziESrtDauNTLtbm7 hCKQ== 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=507To718D663bDdbWOFhAKUK5cAjke1yI21LUWfykOA=; b=Yd/HCVdMpS1pYYPEzBcSPPTAd1gakkPFp3Zw5EZ+hHc0FdiahskO9200AdVc1x8/a/ S3EhrfFSqiv49kiEiT0oFWL4JCW4Kp0KkHVFmyuMlvtz/clnYSfjxQ3VgyufP0hWf+KF 5LWwad/H/wqcU2Dc0peiL9y0/vfVlONtKi2GBiBJWDdtcpKHfnrhSzoKlUfNV76u6W/Z tOKxF7pWb+OkdQThVVDAT5R7hvvxhThPDWfYZJyJke6qkDDZlAX/UsrLRxF1Gd87UWot pGLAcCx46gz/Kir+MjAVz0Ub3/SyvcS1NfgqNTot9EM3Q7fcSqDIZuMXxeYglwdD2mW3 N2sQ== 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 t9-v6si2835510pgf.222.2018.06.20.16.16.22; Wed, 20 Jun 2018 16:16:36 -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 S932607AbeFTXPd (ORCPT + 99 others); Wed, 20 Jun 2018 19:15:33 -0400 Received: from mga12.intel.com ([192.55.52.136]:65395 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754308AbeFTXP1 (ORCPT ); Wed, 20 Jun 2018 19:15:27 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jun 2018 16:15:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,249,1526367600"; d="scan'208";a="66325217" Received: from chang-linux-2.sc.intel.com ([10.3.52.139]) by orsmga001.jf.intel.com with ESMTP; 20 Jun 2018 16:15:26 -0700 From: "Chang S. Bae" To: Andy Lutomirski , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar Cc: Andi Kleen , Dave Hansen , Markus T Metzger , Ravi Shankar , "Chang S . Bae" , LKML Subject: [PATCH v4 4/7] x86/fsgsbase/64: Factor out load FS/GS segments from __switch_to Date: Wed, 20 Jun 2018 16:15:03 -0700 Message-Id: <1529536506-26237-5-git-send-email-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529536506-26237-1-git-send-email-chang.seok.bae@intel.com> References: <1529536506-26237-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 Instead of open coding the calls to load_seg_legacy(), add a load_fsgs() helper to handle fs and gs. When FSGSBASE is enabled, load_fsgs() will be updated. Signed-off-by: Chang S. Bae Reviewed-by: Andi Kleen Cc: H. Peter Anvin Cc: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar Reviewed-by: Andy Lutomirski --- arch/x86/kernel/process_64.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index e498671..cebf240 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -279,6 +279,15 @@ static __always_inline void load_seg_legacy(unsigned short prev_index, } } +static __always_inline void load_fsgs(struct thread_struct *prev, + struct thread_struct *next) +{ + load_seg_legacy(prev->fsindex, prev->fsbase, + next->fsindex, next->fsbase, FS); + load_seg_legacy(prev->gsindex, prev->gsbase, + next->gsindex, next->gsbase, GS); +} + static unsigned long task_seg_base(struct task_struct *task, unsigned short selector) { @@ -588,10 +597,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) if (unlikely(next->ds | prev->ds)) loadsegment(ds, next->ds); - load_seg_legacy(prev->fsindex, prev->fsbase, - next->fsindex, next->fsbase, FS); - load_seg_legacy(prev->gsindex, prev->gsbase, - next->gsindex, next->gsbase, GS); + load_fsgs(prev, next); switch_fpu_finish(next_fpu, cpu); -- 2.7.4