Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1614007ybh; Thu, 23 Jul 2020 13:25:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+AlZ5md4Z4D8AoZYJYzN7E5EiSKdsleaEo3P3A8xKcXZgkJ8HZrChwB1zkVDRFYQ0oI9w X-Received: by 2002:a50:fb93:: with SMTP id e19mr5724230edq.106.1595535905130; Thu, 23 Jul 2020 13:25:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595535905; cv=none; d=google.com; s=arc-20160816; b=XDuR1/0CP+OEI0dIE9nLAxEFeXEUsyQkbjME6PoSGFeJ/0E+d0e/HiGr8uci65AdCe mib8p4xaRoH2/SQTBLrbN2dUdfv/DIMlGjTPCLfQfMbb5NA/9Kb+R65yDxaJGB+gWFFb lY4eq/vcoBwNmUtOIQsmlQxQGQGlr1tUYsLU+fTZUoucIfvsKz2xhK4kdq/5hbJKHK7r q36PgM/f93YT+A2qS0Y8N4njcgUsy7STDhGhzVMr+wiWqqciFaAVCrRKxqUUfmMWb2DZ h03fVhNxS3pgkn0HHJwNVzWzYWCsA+dqAIDXLiEWgqir7qOK94nwnt5fOiuHzZVdL7dJ kd8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=xUfejVCnGJSFUxx4AbkzbVJFCZGcWbz/N8REfPWxQoU=; b=qNAKavPRKqfpkdhFKfwt8vN5qI/VUjpaUPaK1awoKdfOMGGhLwVEvvf0hWr9fBP73O S3mO/VS8qfzJHjX4lDv1E9gcrPIEVG9jdM0JBrTt1ZeM+TL8jpSDlnCJVtDr5bgsa393 3eiMP9viz8KcCpmjQcNTBlWt0xburJc4GxSk32wAPwQ7AgM9ixt4McHA88V9MLoZ23vy UfOul2YasaU91QwWBo8VJq/rRb114YLWM/QyaWRzQU4u9Xz5S1i6v2ooNyata0NBoDcD a7l/xRfg+vhDwQ4WE9BzzDAoyRH16cgfODn5aOmehbzz57JO0jGXA+QSRsicGRKus6bH +s4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3w6pydta; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q25si2550683ejb.116.2020.07.23.13.24.42; Thu, 23 Jul 2020 13:25:05 -0700 (PDT) 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=@linutronix.de header.s=2020 header.b=3w6pydta; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727972AbgGWUWI (ORCPT + 99 others); Thu, 23 Jul 2020 16:22:08 -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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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