Received: by 10.223.185.116 with SMTP id b49csp478662wrg; Fri, 16 Feb 2018 02:08:53 -0800 (PST) X-Google-Smtp-Source: AH8x2249ofiyywJY5V42N6KeOgak2cm3VZztaJNNsjxxRV2OoSg6fH8xR5B2I3chHA4bFK1SYB3m X-Received: by 10.99.170.77 with SMTP id x13mr4740672pgo.393.1518775733520; Fri, 16 Feb 2018 02:08:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518775733; cv=none; d=google.com; s=arc-20160816; b=GvAzIwjbQpMb5YqFIZP/v+btsThUMlSSKAc0l/1ziMFNG9/Xh8teTnjDymng6OQSuD vmFo9xrJVOodzysLUQfyCZA/hh6RUgspn/4pBG76JDX/03+zHmv4hWeTEmkAs4X1J7fj b1r/VSHqt+IxBkqfxxXjUMj80yItL/YXwzwrq2N10yCsQphjDEJeJBBjsbKnouGzk6RY 9lbS+KcMQhTr9ffz+GocDI0vAhyg1ToWo2krrtPdEXPJ1u/JrHHoEJkC6Il8JehKKi0V JnrLJA1rB/cAhCSwsqdiOUWTCTfhI+xq9YKAC7c9vslL6VXfofSAZ9RJ3++NY49Z8qUz 1EHw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:cc:references:to:subject:arc-authentication-results; bh=pc+DRDaGGanl+IpyJq4fes8iBqj1sGO5UUxKc1pxFc4=; b=rjnusk/EI9GXLpsCbWRWuFoy2pQkNIGo2AMxQBBeq23/qwLeE/Q81afaD5wkp77x9v YErjMbCFlkWc2WcVHG0DqY6uzmnYc3HLTPuvFBvdLtnD2YKvCW6nOk/e5N/7ROXNGeSr KJ3ROWokYUKCLnBpl2eOUZAiM4TJmN+r8j2DQA/1BbjzIL3Lgb+hSy3Q/f2XkaU1HI// ElEGRqGYxgImld5lVYtsqjDow9ipKuc8zP47p3pW28A70TG//GtTorHLMWBKmG6v/m7w 9/5H1/YHC3Q/Zb85IzSaxxAYaZWNJZBm+f33zOUlpzk548hdGNahtSPjrxD2AL4tq5Bo c57Q== ARC-Authentication-Results: i=1; mx.google.com; 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 e5si977644pgn.3.2018.02.16.02.08.38; Fri, 16 Feb 2018 02:08:53 -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; 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 S1426669AbeBOQzB (ORCPT + 99 others); Thu, 15 Feb 2018 11:55:01 -0500 Received: from mga07.intel.com ([134.134.136.100]:54589 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423681AbeBOQy7 (ORCPT ); Thu, 15 Feb 2018 11:54:59 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Feb 2018 08:54:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,517,1511856000"; d="scan'208";a="18754099" Received: from makhan1-mobl.amr.corp.intel.com (HELO [10.254.69.204]) ([10.254.69.204]) by orsmga006.jf.intel.com with ESMTP; 15 Feb 2018 08:54:58 -0800 Subject: Re: [PATCH RFC v2 5/6] x86: Use global pages when PTI is disabled To: Nadav Amit , Ingo Molnar References: <20180215163602.61162-1-namit@vmware.com> <20180215163602.61162-6-namit@vmware.com> Cc: Thomas Gleixner , Andy Lutomirski , Peter Zijlstra , Willy Tarreau , Nadav Amit , x86@kernel.org, linux-kernel@vger.kernel.org From: Dave Hansen Message-ID: <10c21933-fe93-ccad-b315-2a7ca1e917a4@linux.intel.com> Date: Thu, 15 Feb 2018 08:54:58 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180215163602.61162-6-namit@vmware.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/15/2018 08:36 AM, Nadav Amit wrote: > As long as PTI is disabled, it is possible to use global pages, as long > as we remove them once PTI is enabled again. To do so, return the global > bit to __supported_pte_mask and disable global pages using CR4. > > Signed-off-by: Nadav Amit > --- > arch/x86/include/asm/tlbflush.h | 6 ++++++ > arch/x86/mm/init.c | 14 ++++++-------- > arch/x86/mm/tlb.c | 3 ++- > 3 files changed, 14 insertions(+), 9 deletions(-) > > diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h > index ea65cf951c49..3a44cb0a9f56 100644 > --- a/arch/x86/include/asm/tlbflush.h > +++ b/arch/x86/include/asm/tlbflush.h > @@ -319,6 +319,12 @@ static inline void set_cpu_pti_disable(unsigned short disable) > WARN_ON_ONCE(preemptible()); > > pti_update_user_cs64(cpu_pti_disable(), disable); > + if (__supported_pte_mask & _PAGE_GLOBAL) { > + if (disable) > + cr4_set_bits(X86_CR4_PGE); > + else > + cr4_clear_bits(X86_CR4_PGE); > + } > this_cpu_write(cpu_tlbstate.pti_disable, disable); > } The TLB invalidations when doing this switch are *CRITICAL*. Otherwise, we end up globally-mapped kernel entries persisting to other processes that are then vulnerable to Meltdown. So, where are the TLB flushes? They're hidden in the cr4_set/clear_bits() function, of course. This is dangerous for two reasons because it makes them non-obvious and hard to find. It also has no interactions with the existing TLB invalidation infrastructure. That's _safe_ of course because extra flushing is OK, but it feels really funky because you're going to end up double-flushing on context switches which is rather unfortunate. This also needs some heavy commenting about the fact that _PAGE_GLOBAL is ignored when CR4.PGE=0. That's key to this working and not mentioned anywhere. While this looks OK to me, it still makes me rather nervous. The changelog and commenting definitely need a lot of work. I'm also still rather unconvinced that the added complexity here is worth it. > diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c > index c67ef3fb4f35..979c7ec6baab 100644 > --- a/arch/x86/mm/tlb.c > +++ b/arch/x86/mm/tlb.c > @@ -74,7 +74,8 @@ static void choose_new_asid(struct mm_struct *next, u64 next_tlb_gen, > return; > } > > - if (this_cpu_read(cpu_tlbstate.invalidate_other)) > + if (this_cpu_read(cpu_tlbstate.invalidate_other) && > + !mm_pti_disable(next)) > clear_asid_other(); This isn't obviously correct. Don't we still need to invalidate other user asids?