Received: by 10.223.164.202 with SMTP id h10csp3515907wrb; Tue, 28 Nov 2017 12:35:43 -0800 (PST) X-Google-Smtp-Source: AGs4zMbZKDMcAufk++zerXIw4JAwmnng09/xn4n1txCLFlbCIbGlUwwfprBNTt8ET2mE2BhjMFHZ X-Received: by 10.99.122.71 with SMTP id j7mr371895pgn.89.1511901342998; Tue, 28 Nov 2017 12:35:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511901342; cv=none; d=google.com; s=arc-20160816; b=bvm9xHrimcDMSqeAy/3oAa1f1aDWOMxPn0EroB8X+C7gUHKd9DjBoNYaADbP+0NeHJ /Q2Y9aNHYe79+sJP8cf7yPgASAwV0xTV/F/FTvbTUFeCwcnGc5SJNY+eSUHXuxagSzSf cE+zDmvzPaHWtsSUkJGOsM7ER0WfFptXdjQekmD2nxiVeCsagbDLDYsINgj6FrOvZNhQ Hf3GIxSDHvLmqfLD3wBSDKM4k6rxhhWzfjB/oUCi5JrUg0Tt5XPfpDlR1mHGZ7eDP86o 2IcJYpsWZse9VsbXV0KMvdi6tAHU6IydxN6wvv6RcBurFmVC4IAazfNHuYTpxNd6xep0 RYXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=FTbZHzfxPU7YRO6lV7N46rVe8TYQ0foQArj54S8pZDA=; b=rAu50Rl0OgG4irJjHuXpXvISq/CY+WcYBuI5cmYR5+bmsNMESQp9jtF4yqLz6vgL5K Lh/zNO9hfflutv6KztEhAtKexjso7sJc1v4AwNTI0IPBzey2PvlOusqTN0vjhAqaXXJd Orfw+NofhJxaIXUN8MF+CvDKdtabR3F5B3VnAfatMPSvf+r0m8lF6czh5ZP5Kz2oFsX3 ItypBPdMaqRKMPIV6NKt4vK6iqPfnycTu7Aorod66+Npk5GK0ZsyfAYWVxjWDtw7DQSC 1jaEkCtiYd0ojI/65ZmEsbExE3ZPCqf3ToSMhUkdUNro+6PtN43TLn3xD99zx6G30zcb 5v3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=YkjLouR1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k63si23751pgk.199.2017.11.28.12.35.32; Tue, 28 Nov 2017 12:35:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=YkjLouR1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754277AbdK1Uel (ORCPT + 70 others); Tue, 28 Nov 2017 15:34:41 -0500 Received: from mail-it0-f47.google.com ([209.85.214.47]:41837 "EHLO mail-it0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752534AbdK1Uej (ORCPT ); Tue, 28 Nov 2017 15:34:39 -0500 Received: by mail-it0-f47.google.com with SMTP id x28so1376106ita.0 for ; Tue, 28 Nov 2017 12:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=FTbZHzfxPU7YRO6lV7N46rVe8TYQ0foQArj54S8pZDA=; b=YkjLouR1/0bt8iLW9ilOFoTdwlI6oOllG6LnH5D+XNZX+Bu57CxA3SEJryLPD3Pzme KyOlZezRjx833tmi3RSm40AYQc8xnZ//4q3S9SOtF2RoGwXG7iAi/ctwqBU0lkVi92k4 0ks00e+M2LHVCWOojn1e1Nre94ohdiclkIuZey/W3lHJeBVeRib8dZkva7O/qfDiseh9 524wwyhUUqmWfhCMK8oNaOnLAFFloo7/MHjXiFxd5GFn4M4xnJizjUmBQY8bPq54aiLS kgHQDnsl9dc2YNqmSWSRGB85BPhYeD9WpdieojHAA/PCF3vMZ8xmOMKybdSX0HVyyj9D pp+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=FTbZHzfxPU7YRO6lV7N46rVe8TYQ0foQArj54S8pZDA=; b=fYJWY0A2y7oWP0iUW32U2G3s8hfNUa0qxokijAvp1SCG1fc+qhv+HoFYrNRXb3QjN1 SG3ObMbzAmJy04SbJtL74Y7qOV4DvHLr3kc30PxR2YJFr2juqFR1bTVLGK3lB3QRFnac Ab1fScneJYMJmSv4yH0VjpY1Qflru0XUWWRmFt3BKJWCn6aGRmLfSVvxaBlPWUlLAo/6 c5dGlP7CtS2oQAK2v6BF1/xrcNcGQRGlOiYgu2TVmPq/2vnJ1o5C8txUAlE08blFN1TT yD4cDD0wggziw+BAqFb9VnNoiTVkjPFY7jcL/kGoE/Zjbl5nqw3GwWRL1fyo/FK9XoGz P9cA== X-Gm-Message-State: AJaThX5LvVvG3VV270M8ditbqGwj81NmHlSvl6EOXB/Z2rynRO3kiIzW cpXq1XZX+D2n3v0cz+0upfU+ZYF4ew+EETHgjZIzZg== X-Received: by 10.36.58.11 with SMTP id m11mr182307itm.109.1511901278245; Tue, 28 Nov 2017 12:34:38 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.133.35 with HTTP; Tue, 28 Nov 2017 12:34:17 -0800 (PST) In-Reply-To: <20171128190505.pqip2v2ewb3isjhd@hirez.programming.kicks-ass.net> References: <20171127104923.14378-1-mingo@kernel.org> <20171127104923.14378-16-mingo@kernel.org> <20171128163908.e3gj6zgq6kcbdlxe@hirez.programming.kicks-ass.net> <1c9a32ed-e754-9d91-98f7-b72c07b2c0dc@linux.intel.com> <20171128190505.pqip2v2ewb3isjhd@hirez.programming.kicks-ass.net> From: Andy Lutomirski Date: Tue, 28 Nov 2017 12:34:17 -0800 Message-ID: Subject: Re: [PATCH 15/24] x86/mm: Allow flushing for future ASID switches To: Peter Zijlstra Cc: Dave Hansen , Ingo Molnar , "linux-kernel@vger.kernel.org" , Thomas Gleixner , "H . Peter Anvin" , Borislav Petkov , Linus Torvalds Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 28, 2017 at 11:05 AM, Peter Zijlstra wrote: > On Tue, Nov 28, 2017 at 10:13:30AM -0800, Dave Hansen wrote: >> Thanks for looking at this, Peter. I've been resisting doing this for a >> bit and it's an embarrassingly small amount of code. > > Right, well, its not complete yet, and it might be complete crap :-) > >> On 11/28/2017 08:39 AM, Peter Zijlstra wrote: >> > @@ -220,7 +221,21 @@ For 32-bit we have the following conventions - kernel is built with >> > .macro SWITCH_TO_USER_CR3 scratch_reg:req >> > STATIC_JUMP_IF_FALSE .Lend_\@, kaiser_enabled_key, def=1 >> > mov %cr3, \scratch_reg >> > - ADJUST_USER_CR3 \scratch_reg >> > + push \scratch_reg >> >> Do we have a good stack in all the spots that we need to do this? It >> may have changed with the trampoline stack, but I'm 100% sure that it >> wasn't so in the recent past. > > Dunno really. I figured I'd give it a go and see what happens. So far > the machine still works. But I was hoping Andy would have an opinion on > this. I thought we had a stack in all these places even before the trampoline. There was an issue with *entry*, but I think exit has always been okay. > >> Let me see if I'm reading the assembly right. > > Yep, seems you can read asm :-) > > >> > +DECLARE_PER_CPU(unsigned long, __asid_flush); >> >> Could we spare enough space to make this something like >> user_asid_flush_pending_mask? > > Yeah, if I can get it all working we'll bikeshed on a name ;-) > >> It took me a minute to realize that it was a mask. Also, since we only >> have 6 asids, should we bit a bit more stingy with the type? > > I picked unsigned long because our bitops (__set_bit in this case, use > it), and I know we're LE and could simply use a shorter type, but meh. > >> It took me a minute to realize that mixing these is still OK, even if >> the mm associated with the ASID changes. It's because once the ASID is >> stale, it doesn't matter *why* it is stale. Just that the next guy who >> *uses* it needs to do the flush. You can do 1,000 tlb flushes, a >> context switch, a tlb flush and another context switch, but if you only >> go out to userspace once, you only need 1 ASID flush. That fits >> perfectly with this bit that gets set a bunch of times and only cleared >> once at exit to userspace. > > Just so. > > I'm now staring at the RESTORE_CR3 stuff, and that appears to be called > in the NMI handling where the stack is not to be used (if I read it > right), so that's going to be a little more tricky. I think it should be fine. A very old version of the patches had that problem, but, in -tip, the nmi RESTORE_CR3 is in the fancy recursion-protected region, and the stack is okay. The idea is that we're already on the old (possibly user) CR3 before we do the crazy recursion-checking bits. But that's fine, since all that's accessed there is the IST stack, and that's in the cpu_entry_area and thus safe regardless of CR3. Side question: on extremely quick read, you're doing bt then btr. Why not just do a single btr and be done with it? Are you trying to avoid getting exclusive access to the cacheline when not needed? From 1585339883049959903@xxx Tue Nov 28 19:38:49 +0000 2017 X-GM-THRID: 1585216393710549190 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread