From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752498AbdLDWe7 (ORCPT ); Mon, 4 Dec 2017 17:34:59 -0500 Received: from mga11.intel.com ([192.55.52.93]:25607 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752213AbdLDWey (ORCPT ); Mon, 4 Dec 2017 17:34:54 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,361,1508828400"; d="scan'208";a="9530682" Subject: Re: [patch 51/60] x86/mm: Allow flushing for future ASID switches To: Andy Lutomirski , Thomas Gleixner References: <20171204140706.296109558@linutronix.de> <20171204150609.002009374@linutronix.de> Cc: LKML , X86 ML , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Greg KH , Kees Cook , Hugh Dickins , Brian Gerst , Josh Poimboeuf , Denys Vlasenko , Rik van Riel , Boris Ostrovsky , Juergen Gross , David Laight , Eduardo Valentin , aliguori@amazon.com, Will Deacon , Daniel Gruss , Dave Hansen , Ingo Molnar , michael.schwarz@iaik.tugraz.at, Borislav Petkov , moritz.lipp@iaik.tugraz.at, richard.fellner@student.tugraz.at From: Dave Hansen Message-ID: <5c94250f-486e-e1e4-c571-07af8b0b8887@intel.com> Date: Mon, 4 Dec 2017 14:34:53 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/04/2017 02:22 PM, Andy Lutomirski wrote: >> + >> + this_cpu_write(cpu_tlbstate.invalidate_other, true); > > Why do we need this extra variable instead of just looping over all > other ASIDs and invalidating them? It would be something like: > > for (i = 1; i < TLB_NR_DYN_ASIDS; i++) { > if (i != this_cpu_read(cpu_tlbstate.loaded_mm_asid)) > this_cpu_write(cpu_tlbstate.ctxs[i].ctx_id, 0); > } We have loops like this: for (addr = start; addr < end; addr += PAGE_SIZE) flush_tlb_single(); Where flush_tlb_single() does a invalidate_pcid_other(). So, inlining flush_tlb_single() rougly looks like: for (addr = start; addr < end; addr += PAGE_SIZE) { invlpg; for (i = 1; i < TLB_NR_DYN_ASIDS; i++) { this_cpu_write(cpu_tlbstate.ctxs[i].ctx_id, 0); } or, with a "invalidate_other" variable: for (addr = start; addr < end; addr += PAGE_SIZE) { invlpg; this_cpu_write(cpu_tlbstate.ctxs.invalidate_other, 1); } The double-for-loop looks a bit wasteful to me. >> static inline void __flush_tlb_one(unsigned long addr) >> { >> count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ONE); >> __flush_tlb_single(addr); >> + /* >> + * Invalidate other address spaces inaccessible to single-page >> + * invalidation: >> + */ > > Ugh. If I'm reading this right, __flush_tlb_single() means "flush one > user address" and __flush_tlb_one() means "flush one kernel address". > That's, um, not exactly obvious. Could this be at least commented > better? That sounds sane, but let me take a look at it. Didn't Peter have some patches to do some of that rename?