From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933188AbdK2QXM (ORCPT ); Wed, 29 Nov 2017 11:23:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:41464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932094AbdK2QXL (ORCPT ); Wed, 29 Nov 2017 11:23:11 -0500 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85C3521992 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=luto@kernel.org X-Google-Smtp-Source: AGs4zMYW8xu7Z/T3DlZKk2Z31euTyZyTHA/91qENm35LuM10ROE7WfGFl8d9niNtl+gzocrn8UyCH5P8oosLEslE7Cw= MIME-Version: 1.0 In-Reply-To: <4f2c1cf45fd04e83a7d360d0d602830e@AcuMS.aculab.com> References: <0fede9f9-88b0-a6e7-1027-dfb2019b8ef2@linux.intel.com> <20171129070951.hjjjpbyilzaak4ig@gmail.com> <20171129124711.slmq5emx4f26c4zp@hirez.programming.kicks-ass.net> <4f2c1cf45fd04e83a7d360d0d602830e@AcuMS.aculab.com> From: Andy Lutomirski Date: Wed, 29 Nov 2017 08:22:49 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] x86/entry/64: Fix native_load_gs_index() SWAPGS handling with IRQ state tracing enabled To: David Laight Cc: Peter Zijlstra , Ingo Molnar , Jarkko Nikula , linux-kernel , Andy Lutomirski , Thomas Gleixner , Linus Torvalds , Borislav Petkov Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 29, 2017 at 6:56 AM, David Laight wrote: > From: Andy Lutomirski >> Sent: 29 November 2017 14:34 >> > On Nov 29, 2017, at 4:47 AM, Peter Zijlstra wrote: >> > >> >> On Wed, Nov 29, 2017 at 08:09:51AM +0100, Ingo Molnar wrote: >> >> diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S >> >> index f81d50d7ceac..c0b52df8ee4f 100644 >> >> --- a/arch/x86/entry/entry_64.S >> >> +++ b/arch/x86/entry/entry_64.S >> >> @@ -945,16 +945,16 @@ idtentry simd_coprocessor_error do_simd_coprocessor_error >> has_error_code=0 >> >> */ >> >> ENTRY(native_load_gs_index) >> >> FRAME_BEGIN >> >> + SWAPGS /* switch from user GS to kernel GS */ >> >> pushfq >> >> DISABLE_INTERRUPTS(CLBR_ANY & ~CLBR_RDI) >> >> TRACE_IRQS_OFF >> >> - SWAPGS >> > >> > I'm thinking those moves it too far back; we should at least have >> > interrupts disabled when we do SWAPGS, no? Also, curse paravirt. >> > >> >> I'll look in a few hours. >> >> But we definitely can't have irqs on when running with user gs. > > I can't remember what happens when swapgs itself faults. > I'm pretty sure it can, restoring %ds %es and %fs can definitely fault > (especially for 32 bit apps) if the restored values are invalid. > With user LDT I think it is possible for a valid segment register > to become invalid while a process is sleeping. > The debugger (and possible a signal handler) can set the segment > registers to arbitrary values - so loading them faults. > > I fixed NetBSD a few years ago so that all these faults were handled > correctly. SWAPGS never faults. I did test my patch, and I'm wondering how I missed the problem. Looking now...