Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3169148pxb; Mon, 25 Jan 2021 08:40:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJzhCc6tXNSMsr/xA9LrC+PzsbFaxIi89xEVLY5rlXZkGkYRmBBCUuidBbY5oB6Pqan/Voey X-Received: by 2002:a17:907:1701:: with SMTP id le1mr960317ejc.68.1611592838137; Mon, 25 Jan 2021 08:40:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611592838; cv=none; d=google.com; s=arc-20160816; b=pbIaXXFgih7zx7Kxs7N21CrbSlWmsa115Ko90Iue0svxByXQUU8fIIBE4Ti6I5I9il 5TKvyZfhLzC0Tp0FVGIER2O+QWrxoJiTmh5n6m853YHHPvAAIWHYrxFQwCw4vJYKLY6Q IU4vTYLU47bpF+WDTN9xIsMIhE6ArsTAzR61TSJEf+tZ8P4LtLuo5BAzm9Tj2V4QijP3 /H95biM1eexlCBJLRMR7QQAhc2IoIAesvw/zn/L7U0CmhadFVHnbi0GErkhC3q4f26cQ QwbDfBz7GwcThEL0Poinsw5hFJbb2Gu4UGVDxmRp6VbcSrsfWEt3MAATKvu3BSFKI9dw Wuqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+AO/2UPHVqA76MbynGpJlAANlIGJYjkKh16kwZOTMC4=; b=BauWJBf8pXtTlN7XB0PXmlZQNXnB36z4GYlibbJqO/QT/Mjffx76ChCJFmR8wo4JzD b3STGX8x494xPrIUFqNZFJgG/aUTaVf+8nu/y0OaY9HT/qxuXg+JrZRbB9yPP8nMOZCv 2iZN9WcZ5z+u1XHyi7oYhCMMMVT8HfXp+tD71PA734yDZvlB+jfzXVWfdhrJR+MChwdT oQ4pvHSJnA6bqeV/jzXEcg+FBBjvU8ADt2nxfCwJFIzFUUFnImyJfy2x3358UrFa2ddn q0y2q+/q35ck+8+bW+6I4ksWSpHLTQQLIlB0Bp9mpHdjbPG8pRiKDh6K3BYzwfckdNFY jT6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PPuMnezY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m25si7251280edr.186.2021.01.25.08.40.09; Mon, 25 Jan 2021 08:40:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PPuMnezY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730734AbhAYQgO (ORCPT + 99 others); Mon, 25 Jan 2021 11:36:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730714AbhAYQev (ORCPT ); Mon, 25 Jan 2021 11:34:51 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F168C06174A for ; Mon, 25 Jan 2021 08:34:11 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id cq1so8720598pjb.4 for ; Mon, 25 Jan 2021 08:34:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+AO/2UPHVqA76MbynGpJlAANlIGJYjkKh16kwZOTMC4=; b=PPuMnezYxZLU1GBR+XJo640F4pBzFCyqglGIccvXWXFTVkFWv4ReNDC50805k1Q+nN pg0DQnB7qe+yrM1z7ppEcUd9bW/ChiB4vxXRzkzhUFsXQbt6+HqLueR1PpleCHp0c3pE VS7XyrD9pmDq5XtEJmdajsibreM5BjGvnu4eI9SFUcOUJ7IzNTPJMOrqD9CdCL8bhNyz Ppq4soczUAo+KR1vtq9dkSzMdQc/8Y+bqH/LBZ4ewmrVyrOhMRaN2mQlq9NesO6kJEzi wEBpjYjv9baKkyed1m9vmxn9jX1ytG4JdEyVeNCnI6n7WoatKuz6huBO1vedAH1wolo1 LdbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+AO/2UPHVqA76MbynGpJlAANlIGJYjkKh16kwZOTMC4=; b=ZLcMB/W/G+6Zq8+vxS+iTs93UCn7L3SwXB4S3QLQwrX5areWrKtyP7Z4k41po5K4xV WbXQQA1h5zNff+HZa0pQETuT1jkBge9L8YcjG1CmIjCOuBpi9ki9KfBMuSmMCJjEprS/ BhaZnBQHJf3Yq6XHlQ937LrH2ADaCEtfTCuHmMDKyba5tBsj7h7xzJ+Bn656rldNf+/n AtmFS+GDXkxbYreTptBqBp4DVy0igxvvISM/fz+6d3W6YICTvxdYwLHz2sSxgbIGv3cw 4Lpx/ImMm4cI1710PlBFrj6Hs+xHPa73jOT2b/1vsKXdToimQGXAHrVxPwyN9J/MCG08 XzyA== X-Gm-Message-State: AOAM530QpVklES6mHfXUiD2ehx1s9opAZtRvhTbC6LUoihkEz5trFjT8 v6hHWJKZAxhDJ6C2ofEWnd1m2GiGkDdgtA== X-Received: by 2002:a17:902:70c6:b029:df:d62a:8c69 with SMTP id l6-20020a17090270c6b02900dfd62a8c69mr1518424plt.20.1611592450638; Mon, 25 Jan 2021 08:34:10 -0800 (PST) Received: from localhost ([47.251.4.198]) by smtp.gmail.com with ESMTPSA id gt21sm18568189pjb.56.2021.01.25.08.34.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jan 2021 08:34:09 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , Peter Zijlstra , Al Viro , Vincenzo Frascino , Joerg Roedel , Ricardo Neri , Reinette Chatre , Andrew Morton , Gabriel Krisman Bertazi , Kees Cook , Frederic Weisbecker , Jens Axboe , Arvind Sankar , Brian Gerst , Ard Biesheuvel , Andi Kleen , Mike Rapoport , Mike Hommey , Mark Gross , Fenghua Yu , Tony Luck , Anthony Steinhauser , Jay Lang , "Chang S. Bae" Subject: [PATCH V2 0/6] x86: don't abuse tss.sp1 Date: Tue, 26 Jan 2021 01:34:28 +0800 Message-Id: <20210125173444.22696-1-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lai Jiangshan In x86_64, tss.sp1 is reused as cpu_current_top_of_stack. But we can directly use percpu since CR3 and gs_base is correct when it is used. In x86_32, tss.sp1 is resued as thread.sp0 in three places in entry code. We have the correct CR3 and %fs at two of the places. The last one is sysenter. This patchset makes %fs available earlier so that we can also use percpu in sysenter. And add a percpu cpu_current_thread_sp0 for thread.sp0 instead of tss.sp1 Changed from V1 Requested from Andy to also fix sp1 for x86_32. Update comments in the x86_64 patch as Andy sugguested. Lai Jiangshan (6): x86_64: move cpu_current_top_of_stack out of TSS x86_32: use percpu instead of offset-calculation to get thread.sp0 when SWITCH_TO_KERNEL_STACK x86_32/sysenter: switch to the task stack without emptying the entry stack x86_32/sysenter: restore %fs before switching stack x86_32/sysenter: use percpu to get thread.sp0 when sysenter x86_32: use cpu_current_thread_sp0 instead of cpu_tss_rw.x86_tss.sp1 arch/x86/entry/entry_32.S | 38 +++++++++++++++++------------- arch/x86/include/asm/processor.h | 12 ++-------- arch/x86/include/asm/switch_to.h | 9 ++----- arch/x86/include/asm/thread_info.h | 6 ----- arch/x86/kernel/asm-offsets.c | 1 - arch/x86/kernel/asm-offsets_32.c | 10 -------- arch/x86/kernel/cpu/common.c | 12 +++++++++- arch/x86/kernel/process.c | 7 ------ arch/x86/mm/pti.c | 7 +++--- 9 files changed, 40 insertions(+), 62 deletions(-) -- 2.19.1.6.gb485710b