From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752415AbdLGJ4J (ORCPT ); Thu, 7 Dec 2017 04:56:09 -0500 Received: from mx2.suse.de ([195.135.220.15]:41880 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750936AbdLGJ4I (ORCPT ); Thu, 7 Dec 2017 04:56:08 -0500 Date: Thu, 7 Dec 2017 10:55:53 +0100 From: Borislav Petkov To: Thomas Gleixner Cc: LKML , x86@kernel.org, Linus Torvalds , Andy Lutomirsky , Peter Zijlstra , Dave Hansen , Greg KH , keescook@google.com, hughd@google.com, Brian Gerst , Josh Poimboeuf , Denys Vlasenko , Rik van Riel , Boris Ostrovsky , Juergen Gross , David Laight , Eduardo Valentin , aliguori@amazon.com, Will Deacon , daniel.gruss@iaik.tugraz.at Subject: Re: [patch 43/60] x86/fixmap: Add debugstore entries to cpu_entry_area Message-ID: <20171207095553.nxixnqinhkevukdq@pd.tnic> References: <20171204140706.296109558@linutronix.de> <20171204150608.356377647@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20171204150608.356377647@linutronix.de> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 04, 2017 at 03:07:49PM +0100, Thomas Gleixner wrote: > From: Thomas Gleixner > > The intel PEBS/BTS debug store is a design trainwreck as is expects virtual > addresses which must be visible in any execution context. Sure, what can possibly go wrong?! :-\ > So it is required to make these mappings visible to user space when kernel > page table isolation is active. > > Provide enough room for the buffer mappings in the cpu_entry_area so the > buffers are available in the user space visible fixmap. > > At the point where the kernel side fixmap is populated there is no buffer > available yet, but the kernel PMD must be populated. To achieve this set > the fixmap entries for these buffers to non present. > > Signed-off-by: Thomas Gleixner > --- > arch/x86/events/intel/ds.c | 5 +++-- > arch/x86/events/perf_event.h | 21 ++------------------- > arch/x86/include/asm/fixmap.h | 13 +++++++++++++ > arch/x86/include/asm/intel_ds.h | 36 ++++++++++++++++++++++++++++++++++++ > arch/x86/kernel/cpu/common.c | 21 +++++++++++++++++++++ > 5 files changed, 75 insertions(+), 21 deletions(-) ... > @@ -592,6 +603,16 @@ static void __init setup_cpu_entry_area( > __set_fixmap(get_cpu_entry_area_index(cpu, entry_trampoline), > __pa_symbol(_entry_trampoline), PAGE_KERNEL_RX); > #endif > + > +#ifdef CONFIG_CPU_SUP_INTEL > + BUILD_BUG_ON(sizeof(struct debug_store) % PAGE_SIZE != 0); > + set_percpu_fixmap_pages(get_cpu_entry_area_index(cpu, cpu_debug_store), > + &per_cpu(cpu_debug_store, cpu), > + sizeof(struct debug_store) / PAGE_SIZE, > + PAGE_KERNEL); > + set_percpu_fixmap_ptes(get_cpu_entry_area_index(cpu, cpu_debug_buffers), > + sizeof(struct debug_store_buffers) / PAGE_SIZE); > +#endif I guess we can do that additionally, so as not to setup the mappings on distro kernels running !INTEL: --- diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 1364a8f378f8..5cfb68090a24 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -606,12 +606,16 @@ static void __init setup_cpu_entry_area(int cpu) #ifdef CONFIG_CPU_SUP_INTEL BUILD_BUG_ON(sizeof(struct debug_store) % PAGE_SIZE != 0); - set_percpu_fixmap_pages(get_cpu_entry_area_index(cpu, cpu_debug_store), - &per_cpu(cpu_debug_store, cpu), - sizeof(struct debug_store) / PAGE_SIZE, - PAGE_KERNEL); - set_percpu_fixmap_ptes(get_cpu_entry_area_index(cpu, cpu_debug_buffers), - sizeof(struct debug_store_buffers) / PAGE_SIZE); + + if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) { + set_percpu_fixmap_pages(get_cpu_entry_area_index(cpu, cpu_debug_store), + &per_cpu(cpu_debug_store, cpu), + sizeof(struct debug_store) / PAGE_SIZE, + PAGE_KERNEL); + + set_percpu_fixmap_ptes(get_cpu_entry_area_index(cpu, cpu_debug_buffers), + sizeof(struct debug_store_buffers) / PAGE_SIZE); + } #endif } -- Regards/Gruss, Boris. SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) --