From patchwork Wed Jul 18 09:40:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 10531807 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C29B602CA for ; Wed, 18 Jul 2018 09:41:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DDA128FD5 for ; Wed, 18 Jul 2018 09:41:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 019AC29062; Wed, 18 Jul 2018 09:41:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FA8328FD5 for ; Wed, 18 Jul 2018 09:41:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 975B86B0272; Wed, 18 Jul 2018 05:41:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9041A6B0274; Wed, 18 Jul 2018 05:41:29 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79FF86B0275; Wed, 18 Jul 2018 05:41:29 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id 16F276B0272 for ; Wed, 18 Jul 2018 05:41:29 -0400 (EDT) Received: by mail-ed1-f69.google.com with SMTP id r9-v6so1701507edh.14 for ; Wed, 18 Jul 2018 02:41:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=Vb1oaWWyn3PQtq7kXGB9a6wdMCDhJ5c1XEZnqe0STRY=; b=Nzi9pYwwCCpssIQ2yawy/VBPXfYvhOCl7aWkA/IQnMkgI0Y+7ukIobQce7IbBW9i0+ wBzcxFo42NHW42wSsmns5Dr79xK2lvQfJjH3EXStJoN8RMFNSsnVLhRp7phDvFzS7tpu 4KogxPGTm3OwFlwWvjl6n7YojMDLOmm5Hmqb83olvYF7D659aV1offeN6G0Ea5hSMZKz ugB+BaZwvA+AVtVyp31APQur3asQT3KocCVqmXBEmg3/+R4AkQavfE8LtVcfG9cAHDhH QjQMkvu34Aj/OvKMFfl7cLQuhDxHSxflJkkOT3HKBpOUpwAkPSEib/yVHaFQIN7B1aaq dJNw== X-Gm-Message-State: AOUpUlGOsaubR5Qr7tygU6nUmvgRSqBQHaMybSlcxWDPYnbzd6MoPlSG vnXkM1YRFZ434lZMc3Wc8sMrxbirKnD7aKS1zfjMr1ttwx5GAkR1uvdmnID4T27RS+xIhX3W/v8 LqNYyTm3s6FBfon8/exJ1I+Z7uCcKYgISSBYvxi92Wj/FVrw2IgMwvnPzzeijkxnaIg== X-Received: by 2002:a50:e146:: with SMTP id i6-v6mr6282586edl.204.1531906888640; Wed, 18 Jul 2018 02:41:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcw2F4ywmp+9wlbDJkm89jpLecLx3lRRd+AjqbfekXKhV19zTaQ3ZZb+mJFoi/rAaMRH6jN X-Received: by 2002:a50:e146:: with SMTP id i6-v6mr6282543edl.204.1531906887908; Wed, 18 Jul 2018 02:41:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531906887; cv=none; d=google.com; s=arc-20160816; b=wsUlTYULxvbsyysX8O3epDeDLx7NZpLV5Vp2sVG57F1WAL4P2BFVWe4lnRRyvB4YKV ED1MUPDZQa1AkmeFc/sIOc1CLaDmT/Va5dxxtSsXt+22Gp9qDTGIpxZbsanF4+o9ik/A JSoM9KRx4HhrTJSCqeDERW9POvUQ6R1+WZ/m6IQzvWuiK2GrJft1dFQflsLd0vsRxCer u5HU82/rbwwwVEeXnN/Qj2Jxiw7z1IjLUAEngAY7wW9+AJkOGRRMBhaSiBtVEUEaDf2r b8aT2U6vXA205ORw3C/p4iL8JwI3sS/7aoS+ZrAV4FJWKtR8ffVUpjx3BQxVHVs4Z86a Udog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Vb1oaWWyn3PQtq7kXGB9a6wdMCDhJ5c1XEZnqe0STRY=; b=O/dk66clEyHviqSn58gTdt91KbIPjLIsQaC7oKuU1gh/6Ye5Y+GGKYRfzqaGsXSFxA eJau5qymC7oMD2tSKLSo/hP3cOXBncleqDH2nH2ByS1TqUwnVVdotdUgI9OwfoSPTEv8 alFJxjykDEeZsYhh8TWANamhxv7h2kUpJAk5b+tBku2/KB3IWKZfjO3ts47+7TCC1pik Q9vG1ZjIcn7g9IUg7A1GXWQkIUTL2T0EKtBpcKplinuVvwYD09E/Yc5zQeUChLuVb9js tpR2SAxIEkLJxD3hRf17Rpgp1jP+ESaPIY2j8/ZRN9v23R8C/12Frekie5uunQCAgM2e IHoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b="XOVe/mQd"; spf=pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 as permitted sender) smtp.mailfrom=joro@8bytes.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: from theia.8bytes.org (8bytes.org. [81.169.241.247]) by mx.google.com with ESMTPS id p7-v6si687097edh.418.2018.07.18.02.41.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 02:41:27 -0700 (PDT) Received-SPF: pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 as permitted sender) client-ip=81.169.241.247; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b="XOVe/mQd"; spf=pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 as permitted sender) smtp.mailfrom=joro@8bytes.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: by theia.8bytes.org (Postfix, from userid 1000) id 8CFAF219; Wed, 18 Jul 2018 11:41:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1531906879; bh=w4DXGqDHgCkivWXTkiZjSWhwcxxFw+CPZ35l4K1+2YU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XOVe/mQdTYm01PubZ4K7rGVa8RoLqKe0Jx3lHy3Wfil8L9zFTbo/7PmW08/XEbgPM sz0Y6yEInMf3qjwdfOe6iouzy0hj20g6k+FQFGETdXBdC10yEGu16A8JgI4jtAZLDe Dtdw1TZZzhKVKpf/gviM54XgvHND1aoqq/kt5l+NhC5AUfxycsf9L/lmUCBy/oQaaB gMfdDKptZX7xgeuNy8EkUpRO5j1TQDuHtrPzmc9Kk3Qi+hLUcxvZp4TWTXkE84IZgs dPszHouRBECsORYuyQrglC7092LNKqns5fah1YzL9bb2HeE08bwoQ9JZTqRswBjRVv Ja1uwElnZK7Kg== From: Joerg Roedel To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Andy Lutomirski , Dave Hansen , Josh Poimboeuf , Juergen Gross , Peter Zijlstra , Borislav Petkov , Jiri Kosina , Boris Ostrovsky , Brian Gerst , David Laight , Denys Vlasenko , Eduardo Valentin , Greg KH , Will Deacon , aliguori@amazon.com, daniel.gruss@iaik.tugraz.at, hughd@google.com, keescook@google.com, Andrea Arcangeli , Waiman Long , Pavel Machek , "David H . Gutteridge" , jroedel@suse.de, joro@8bytes.org Subject: [PATCH 03/39] x86/entry/32: Load task stack from x86_tss.sp1 in SYSENTER handler Date: Wed, 18 Jul 2018 11:40:40 +0200 Message-Id: <1531906876-13451-4-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531906876-13451-1-git-send-email-joro@8bytes.org> References: <1531906876-13451-1-git-send-email-joro@8bytes.org> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Joerg Roedel We want x86_tss.sp0 point to the entry stack later to use it as a trampoline stack for other kernel entry points besides SYSENTER. So store the task stack pointer in x86_tss.sp1, which is otherwise unused by the hardware, as Linux doesn't make use of Ring 1. Signed-off-by: Joerg Roedel --- arch/x86/kernel/asm-offsets_32.c | 9 +++++++-- arch/x86/kernel/process_32.c | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c index 15b3f45..82826f2 100644 --- a/arch/x86/kernel/asm-offsets_32.c +++ b/arch/x86/kernel/asm-offsets_32.c @@ -46,9 +46,14 @@ void foo(void) OFFSET(saved_context_gdt_desc, saved_context, gdt_desc); BLANK(); - /* Offset from the entry stack to task stack stored in TSS */ + /* + * Offset from the entry stack to task stack stored in TSS. Kernel entry + * happens on the per-cpu entry-stack, and the asm code switches to the + * task-stack pointer stored in x86_tss.sp1, which is a copy of + * task->thread.sp0 where entry code can find it. + */ DEFINE(TSS_entry2task_stack, - offsetof(struct cpu_entry_area, tss.x86_tss.sp0) - + offsetof(struct cpu_entry_area, tss.x86_tss.sp1) - offsetofend(struct cpu_entry_area, entry_stack_page.stack)); #ifdef CONFIG_STACKPROTECTOR diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c index 0ae659d..ec62cc7 100644 --- a/arch/x86/kernel/process_32.c +++ b/arch/x86/kernel/process_32.c @@ -290,6 +290,8 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) this_cpu_write(cpu_current_top_of_stack, (unsigned long)task_stack_page(next_p) + THREAD_SIZE); + /* SYSENTER reads the task-stack from tss.sp1 */ + this_cpu_write(cpu_tss_rw.x86_tss.sp1, next_p->thread.sp0); /* * Restore %gs if needed (which is common)