Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5005789imm; Sun, 22 Jul 2018 10:46:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeVRZD0LFKZA2YxoyevZdlEmvZmo3ytQjhwXvrOelOfdxyzS0lL75F3TGh51P1Q7YKaoljA X-Received: by 2002:a63:41c6:: with SMTP id o189-v6mr9449994pga.323.1532281605699; Sun, 22 Jul 2018 10:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532281605; cv=none; d=google.com; s=arc-20160816; b=VJDRA6Dzi/1kPLmIHLLthZcVF1QQEssK9YNkzjdABI75Dwe2m46WTZaGLYMNJ7A5Oc OLoKcW1LhUFY1BKUzMuQhRhgwaQPjKe7MI1Qw51Ze7xdvSr3lPsnrd93QNLPCUiI1Rea QalNjmNk7QX9KFLuQaxmpjf7vGUC2sIgHd+ZSj87EHApZQA921GF8vt7RvcOvYedmnHC EjK6DnUzskG6xQ7FRHdBxqPj+woFecOWXjzBqmszO3g3hFYIPFXiNCHY4mV+Dumd2a+W MsJBWP2P4vpXjYZlwAEvPizjjsShK9s1WTxwRkBPcSwQbCmbE/0ofYBhVwVNWvShGTxp WILA== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=1sIgEaW8XzfxEMOCgcD6L7OhMudjWkTYWtzzQ1SAtm8=; b=cuvYvJ4GcxComz2gy3E1P7tdE5bcMyfgONWRpItUgnGQ9FXfWbEbkiD/yloLkfB2Fq GOD1Lwq8RjSviPi89q914haN+OZAk9/8U8agIm4Xxrng/UwK/8dhxiJDyCAJaEUl0y9z b6QfPo6Gs2eETQAjsJjVMuhLQ2xIWh6HkUdklr9/omJRN1c092MM3xCfVcVUt7eONL4j OaFtFVwDTmBt9mBAv2AedQs8pjzpuVc25UdiAJ/0uPgtOxlAQCMmCeMW05gW6M2cZUIP UNHabSw/gL7BO2xkS2SYXAYEm7KjPLFpfBs9pq8F1OKNgyUsx9uwMSgL6uvRN06XXedR Q1Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Hw6ulbw4; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p77-v6si7175319pfj.294.2018.07.22.10.46.29; Sun, 22 Jul 2018 10:46:45 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Hw6ulbw4; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730259AbeGVSnC (ORCPT + 99 others); Sun, 22 Jul 2018 14:43:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:56224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730090AbeGVSnC (ORCPT ); Sun, 22 Jul 2018 14:43:02 -0400 Received: from localhost (c-71-202-137-17.hsd1.ca.comcast.net [71.202.137.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C57E920878; Sun, 22 Jul 2018 17:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1532281535; bh=BNJSDyUcS534h4/I6xNgsBJtQJXPMxd7px3/OcnTBr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=Hw6ulbw40Rert94iMS/zWYY1vTzL4uFwG7MHLTmeOV2eSHcQ6v9h36AfyB3bA19Tw 5kovAaLFPQ8tBxJEiWaY357c7QY7xyieJwaiR4/lxXDvKUiLfy2ORZuj2Kj1QeR3ii p0dSqVgDvFI32KxFGrm0E1IMA0dyqmYRTKicXgEM= From: Andy Lutomirski To: x86@kernel.org, LKML Cc: Borislav Petkov , Linus Torvalds , Dave Hansen , Andy Lutomirski Subject: [RFC 1/2] x86/entry/64: Use the TSS sp2 slot for rsp_scratch Date: Sun, 22 Jul 2018 10:45:26 -0700 Message-Id: <38b5a24f3c9f519dd7dc98171eb3a3c669fff48c.1532281180.git.luto@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the non-trampoline SYSCALL64 path, we use a percpu variable to temporarily store the user RSP value. Instead of a separate variable, use the otherwise unused sp2 slot in the TSS. This will improve cache locality, as the sp1 slot is already used in the same code to find the kernel stack. It will also simplify a future change to make the non-trampoline path work in PTI mode. Signed-off-by: Andy Lutomirski --- arch/x86/include/asm/processor.h | 5 +++++ arch/x86/include/asm/thread_info.h | 1 + arch/x86/kernel/asm-offsets_64.c | 1 + arch/x86/kernel/process_64.c | 2 -- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index cfd29ee8c3da..2ef4c39ded45 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -308,7 +308,12 @@ struct x86_hw_tss { */ u64 sp1; + /* + * sp2 is scratch space used by the SYSCALL64 handler. Linux does + * not use rung 2, so sp2 is not otherwise needed. + */ u64 sp2; + u64 reserved2; u64 ist[7]; u32 reserved3; diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h index 2ff2a30a264f..9a2f84233e39 100644 --- a/arch/x86/include/asm/thread_info.h +++ b/arch/x86/include/asm/thread_info.h @@ -209,6 +209,7 @@ static inline int arch_within_stack_frames(const void * const stack, #ifdef CONFIG_X86_64 # define cpu_current_top_of_stack (cpu_tss_rw + TSS_sp1) +# define rsp_scratch (cpu_tss_rw + TSS_sp2) #endif #endif diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c index b2dcd161f514..621bf6b5a63b 100644 --- a/arch/x86/kernel/asm-offsets_64.c +++ b/arch/x86/kernel/asm-offsets_64.c @@ -67,6 +67,7 @@ int main(void) OFFSET(TSS_ist, tss_struct, x86_tss.ist); OFFSET(TSS_sp0, tss_struct, x86_tss.sp0); OFFSET(TSS_sp1, tss_struct, x86_tss.sp1); + OFFSET(TSS_sp2, tss_struct, x86_tss.sp2); BLANK(); #ifdef CONFIG_STACKPROTECTOR diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 12bb445fb98d..3ed5fed181cc 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -59,8 +59,6 @@ #include #endif -__visible DEFINE_PER_CPU(unsigned long, rsp_scratch); - /* Prints also some state that isn't saved in the pt_regs */ void __show_regs(struct pt_regs *regs, int all) { -- 2.17.1