From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5540CC43381 for ; Mon, 25 Jan 2021 16:36:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2505B22795 for ; Mon, 25 Jan 2021 16:36:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730801AbhAYQgd (ORCPT ); Mon, 25 Jan 2021 11:36:33 -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-Google-Smtp-Source: ABdhPJzybYKA1znlHXhhGgXLMk93uctVdNxPhUeXsQAQ+YB8kNQc0MgFmE1hR0jx322y1i0gJkPw9Q== 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