Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3296734pxb; Mon, 16 Nov 2020 10:38:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxk06yFcTkPWYf0Iwb6oEH2h/eITb9vfUshkR2ZWsdE4xADn48gzN0X/k/tairzHhzS3uM X-Received: by 2002:aa7:c612:: with SMTP id h18mr16607382edq.27.1605551885907; Mon, 16 Nov 2020 10:38:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605551885; cv=none; d=google.com; s=arc-20160816; b=G2fqUmsTF2goF8fdLons9lf1TIvvymG+h2bS/uJtNJvrLNuPxj52b1PZ7qBB5147vy GtTAet1329JDjrbSrED9vLAszUJuJfzmiiEnlpOHqSlGbXoerXJP5RkwqJHlTTvaKvf9 QucrwiObQuLxEuMWK4xV1ECZ3RII0PAJmdY8rlfLTa0+Lcx3CJ77uv+3UU75msQWVjJH ldAAIyphpa0gExMiSjnvNCTSaI2XTtizv9XKjBKhe6ifIy/WGs6jypYKySpCPMPhTZLZ ud/X3jrLgC16AbnPLKudCGUUrJ3FRwWOANXUSdgjkM/edhVqAidfF4OeZKX264SiUCVL zg6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=0kEyEbaOa0gAfT4QykSL62L4+YtyL2wl2z4A1w0Wfn8=; b=DDaNjqWAxyyZWusH2SE82EQrFzl8WmYIqGu/23KUSrPzJwdEaajL8O//fXgkWc8bjB vQmDODcjZAzBglrbGHwC+sWgGypMuNcFFcgSwW1MpfrjUKp2RDUz4wVqrdJoipVq3YxE K/gJmIo7APdoezCYJaZM8WJ6M0gpg0y12/+KvPlJ92RpPlornvjdJIYjN5oozSHmZx4D kR0VtSECLO5amH3xG58SLodocdqe7fxK+tZfThonq2wxu+Scm6E5qBtctmp2Atx9Jdo9 8KrPS5kQYruvysMGjkE1yrwomBDrXnMIc34F7tRHtuEOPVBRW0FnUgLWUAXC6dJ4ZsdD +b+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tTeOeRj+; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e20si12029658eja.480.2020.11.16.10.37.43; Mon, 16 Nov 2020 10:38:05 -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=@kernel.org header.s=default header.b=tTeOeRj+; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731655AbgKPSe6 (ORCPT + 99 others); Mon, 16 Nov 2020 13:34:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:43698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387910AbgKPSe5 (ORCPT ); Mon, 16 Nov 2020 13:34:57 -0500 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0E3422231B for ; Mon, 16 Nov 2020 18:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605551696; bh=Ae16e9zwZ+DMUvyqQKTLhkJCEL5vVvGc+zxNjI9QG6Y=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=tTeOeRj+1wV4lXQRIfuGFYomlCLP2E8WEJ08+mAtKOrsNTqJHqUVk6+j0Oja2iqKE vHAhvs4ALdqOyrxLDnR/jgb2QfZ7qDEixWK8SkhcWRmDKY9ow1TNwSheR2/3vz+PnS oBjkufh2HJ/bLpkH1YSTI2ilV9Kp3Vq0AZswKgCU= Received: by mail-wm1-f50.google.com with SMTP id a65so247852wme.1 for ; Mon, 16 Nov 2020 10:34:55 -0800 (PST) X-Gm-Message-State: AOAM533h5MEoWpY2Gx1OC96lc6v6K5rlFvQCSZjcaFJ/X6TbxMpRE8SN Pdn901XQbAfeawW3/6TbdpiXcMo8kZgTdyp0jYhrLw== X-Received: by 2002:a1c:7e87:: with SMTP id z129mr236051wmc.176.1605551694330; Mon, 16 Nov 2020 10:34:54 -0800 (PST) MIME-Version: 1.0 References: <20201116144757.1920077-1-alexandre.chartre@oracle.com> <20201116144757.1920077-13-alexandre.chartre@oracle.com> In-Reply-To: From: Andy Lutomirski Date: Mon, 16 Nov 2020 10:34:40 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC][PATCH v2 12/21] x86/pti: Use PTI stack instead of trampoline stack To: Alexandre Chartre Cc: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , X86 ML , Dave Hansen , Peter Zijlstra , LKML , Tom Lendacky , Joerg Roedel , Konrad Rzeszutek Wilk , jan.setjeeilers@oracle.com, Junaid Shahid , oweisse@google.com, Mike Rapoport , Alexander Graf , mgross@linux.intel.com, kuzuno@gmail.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 16, 2020 at 10:10 AM Alexandre Chartre wrote: > > > On 11/16/20 5:57 PM, Andy Lutomirski wrote: > > On Mon, Nov 16, 2020 at 6:47 AM Alexandre Chartre > > wrote: > >> > >> When entering the kernel from userland, use the per-task PTI stack > >> instead of the per-cpu trampoline stack. Like the trampoline stack, > >> the PTI stack is mapped both in the kernel and in the user page-table. > >> Using a per-task stack which is mapped into the kernel and the user > >> page-table instead of a per-cpu stack will allow executing more code > >> before switching to the kernel stack and to the kernel page-table. > > > > Why? > > When executing more code in the kernel, we are likely to reach a point > where we need to sleep while we are using the user page-table, so we need > to be using a per-thread stack. > > > I can't immediately evaluate how nasty the page table setup is because > > it's not in this patch. > > The page-table is the regular page-table as introduced by PTI. It is just > augmented with a few additional mapping which are in patch 11 (x86/pti: > Extend PTI user mappings). > > > But AFAICS the only thing that this enables is sleeping with user pagetables. > > That's precisely the point, it allows to sleep with the user page-table. > > > Do we really need to do that? > > Actually, probably not with this particular patchset, because I do the page-table > switch at the very beginning and end of the C handler. I had some code where I > moved the page-table switch deeper in the kernel handler where you definitively > can sleep (for example, if you switch back to the user page-table before > exit_to_user_mode_prepare()). > > So a first step should probably be to not introduce the per-task PTI trampoline stack, > and stick with the existing trampoline stack. The per-task PTI trampoline stack can > be introduced later when the page-table switch is moved deeper in the C handler and > we can effectively sleep while using the user page-table. Seems reasonable. Where is the code that allocates and frees these stacks hiding? I think I should at least read it.