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 34CC2C433EC for ; Thu, 23 Jul 2020 20:22:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E301A207BB for ; Thu, 23 Jul 2020 20:22:09 +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+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E301A207BB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linutronix.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 479166B000E; Thu, 23 Jul 2020 16:22:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 428426B0010; Thu, 23 Jul 2020 16:22:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33F0E8D0002; Thu, 23 Jul 2020 16:22:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by kanga.kvack.org (Postfix) with ESMTP id 1EC236B000E for ; Thu, 23 Jul 2020 16:22:09 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id AF4A9180AD83A for ; Thu, 23 Jul 2020 20:22:08 +0000 (UTC) X-FDA: 77070462336.15.rub58_2b11dbd26f41 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 7C01918001C0A for ; Thu, 23 Jul 2020 20:22:08 +0000 (UTC) X-HE-Tag: rub58_2b11dbd26f41 X-Filterd-Recvd-Size: 4411 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Jul 2020 20:22:07 +0000 (UTC) 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 X-Rspamd-Queue-Id: 7C01918001C0A X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: 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