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=-4.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 567A2C433EA for ; Thu, 23 Jul 2020 20:22:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D94B20792 for ; Thu, 23 Jul 2020 20:22:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3w6pydta"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="S6pO3lE+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726763AbgGWUWH (ORCPT ); Thu, 23 Jul 2020 16:22:07 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:32790 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725979AbgGWUWH (ORCPT ); Thu, 23 Jul 2020 16:22:07 -0400 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1595535725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xUfejVCnGJSFUxx4AbkzbVJFCZGcWbz/N8REfPWxQoU=; b=3w6pydta60AUDlW71ctlUmfCuxjZwrDBjdn+FnMylpeeRNx3lZdxfaaRT4irOoFTC9CUuh PXbbNu0NFQnT2ebz/rTRFFus4A56eVJaHT1Nku6xPVzKWr5/EfpxjeqXE2M8OHYK60mpNZ G/1vehBDzGDMsOv9JDLd9t0ZwgJq18uO4GXkwYlXX/XavlQ/d8MeiixW8yeG71ll4tXpXy OSNidJ+vtacBscsslNQRCmpPO3hM5Ayd5CFQN/LEVQ+5TWmlgprge1xI1euwEayu59G88G Yr4RymiC2f4ktP3jTZXWmeO9OG2t4cANxrJrr3YILRR0osb7reG9Ymiqqc1/bg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1595535725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xUfejVCnGJSFUxx4AbkzbVJFCZGcWbz/N8REfPWxQoU=; b=S6pO3lE+IfHj3HhkeQ26FcQansBJxu9GNSfmIP0x4haRe07iB3E2Ls0tYUMfsjoVnW9XRq EEpNr2bboZIhELDQ== To: Andy Lutomirski , Fenghua Yu Cc: Dave Hansen , Andy Lutomirski , Weiny Ira , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Dave Hansen , X86 ML , Dan Williams , Vishal Verma , Andrew Morton , "open list\:DOCUMENTATION" , LKML , linux-nvdimm , Linux FS Devel , Linux-MM , "open list\:KERNEL SELFTEST FRAMEWORK" Subject: Re: [PATCH RFC V2 17/17] x86/entry: Preserve PKRS MSR across exceptions In-Reply-To: References: <20200723165204.GB77434@romley-ivt3.sc.intel.com> Date: Thu, 23 Jul 2020 22:22:04 +0200 Message-ID: <87imeevv6b.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: linux-doc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org Andy Lutomirski writes: > Suppose some kernel code (a syscall or kernel thread) changes PKRS > then takes a page fault. The page fault handler needs a fresh > PKRS. Then the page fault handler (say a VMA=E2=80=99s .fault handler) ch= anges > PKRS. The we get an interrupt. The interrupt *also* needs a fresh > PKRS and the page fault value needs to be saved somewhere. > > So we have more than one saved value per thread, and thread_struct > isn=E2=80=99t going to solve this problem. A stack of 7 entries and an index needs 32bytes total which is a reasonable amount and solves the problem including scheduling from #PF nicely. Make it 15 and it's still only 64 bytes. > But idtentry_state is also not great for a couple reasons. Not all > entries have idtentry_state, and the unwinder can=E2=80=99t find it for > debugging. For that matter, the page fault logic probably wants to > know the previous PKRS, so it should either be stashed somewhere > findable or it should be explicitly passed around. > > My suggestion is to enlarge pt_regs. The save and restore logic can > probably be in C, but pt_regs is the logical place to put a register > that is saved and restored across all entries. Kinda, but that still sucks because schedule from #PF will get it wrong unless you do extra nasties. > Whoever does this work will have the delightful job of figuring out > whether BPF thinks that the layout of pt_regs is ABI and, if so, > fixing the resulting mess. > > The fact the new fields will go at the beginning of pt_regs will make > this an entertaining prospect. Good luck with all of that. Thanks, tglx