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 C1621C433E0 for ; Thu, 23 Jul 2020 22:14:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E2CB20768 for ; Thu, 23 Jul 2020 22:14:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="V5Z5Rq1n"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="DpE/SglP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726870AbgGWWOb (ORCPT ); Thu, 23 Jul 2020 18:14:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726417AbgGWWOb (ORCPT ); Thu, 23 Jul 2020 18:14:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CC07C0619D3; Thu, 23 Jul 2020 15:14:31 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1595542468; 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=JmyzjmH8/olb4mM6hh3RrBawdAZ1ohRuT2f6HKf6J84=; b=V5Z5Rq1nk71rXzhuUOz5ybYySxFdqFcH8dpWSElBd5qV0W8MCoBko+38RNWOwqWv2ju5Ig bQIZTjLoRGXb0gRm8ytYEZ+t/kr7TRL00g3qwWdo76SMcfJ4GqUmx1vL6JGaDTvO7FZH+R ehWAUFsqGo/fbWIHtNHboBF7FH01EARrdMRiueauNFcaZcnEvopvmfNUwCfpZJv1T5dDwT im0DmUgWCCRiLQJaa9slhiO8uBTVN7eOzTJKLsyQvSGFvkDS9iSTv6B55CVKQYzX50pMS/ 92w4HmCS53+4wG2ZzwtaOhcrmTM/WnQ4LlDs75AQoLaiaAd4mZmRHbv65Gb2eA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1595542468; 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=JmyzjmH8/olb4mM6hh3RrBawdAZ1ohRuT2f6HKf6J84=; b=DpE/SglP+UbEOY+9bcINMPHA9y7J8tMcjgmZMJCa1/pPbw5ifZwHGpOKKPr+c+G54aYYVK 9inwqDxRJmQ+XGDQ== To: Andy Lutomirski Cc: Fenghua Yu , 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> <87imeevv6b.fsf@nanos.tec.linutronix.de> Date: Fri, 24 Jul 2020 00:14:28 +0200 Message-ID: <874kpxx4jf.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: >> On Jul 23, 2020, at 1:22 PM, Thomas Gleixner wrote: >> =EF=BB=BFAndy Lutomirski writes: >>> 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. > > This seems like we=E2=80=99re reinventing the wheel. PKRS is not > fundamentally different from, say, RSP. If we want to save it across > exceptions, we save it on entry and context-switch-out and restore it > on exit and context-switch-in. It's fundamentally different from RSP because it has state (refcount) attached, which RSP clearly has not. If you get rid of the state then yes. >>> 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. > > We can always cheat like this: > > struct real_pt_regs { > unsigned long pkrs; > struct pt_regs regs; > }; > > and pass a pointer to regs around. What BPF doesn't know about can't hur= t it. Yes, but that's the easy part of the problem :) Thanks, tglx