From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752244AbdK2V5x (ORCPT ); Wed, 29 Nov 2017 16:57:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:36034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751531AbdK2V5w (ORCPT ); Wed, 29 Nov 2017 16:57:52 -0500 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 76A6521996 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: AGs4zMYEx54ZPRQRxq+7vXmrmw+3WqKWpGeHIxKPaPSsUkTt/L3O0S8wzUoWhw6dy3leTQlFsFIgW+DykEisINKbwCI= MIME-Version: 1.0 In-Reply-To: References: <0fede9f9-88b0-a6e7-1027-dfb2019b8ef2@linux.intel.com> <20171129070951.hjjjpbyilzaak4ig@gmail.com> <31643632-8A3F-46AC-95AB-27FC94ED79A3@amacapital.net> From: Andy Lutomirski Date: Wed, 29 Nov 2017 13:57:30 -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: Andy Lutomirski Cc: Linus Torvalds , Ingo Molnar , Jarkko Nikula , linux-kernel , Thomas Gleixner , Peter Zijlstra , 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 1:41 PM, Andy Lutomirski wrote: > On Wed, Nov 29, 2017 at 1:25 PM, Andy Lutomirski wrote: >> >> >>> On Nov 29, 2017, at 12:58 PM, Linus Torvalds wrote: >>> >>>> On Wed, Nov 29, 2017 at 10:12 AM, Andy Lutomirski wrote: >>>> >>>> Jarkko, can you try the attached patch? If it survives resume, can >>>> you see if the log contains anything interesting? >>> >>> I'm not Jarkko, but I'm not a huge fan of that patch. >>> >>> If this was the cause of the problem (and it looks likely), wouldn't >>> it be nicer to instead make sure that __restore_processor_state() is >>> made to use only low-level code and easy to verify? >>> >>> That function is already marked "notrace" because it is so fragile, >>> and it does the segment register reloads manually with inline asms. >> >> I completely agree, and I think it might be better to move more of that crap to asm. Also, it looks quite buggy -- it restores segment registers before it loads the LDT, so they had better not be user registers. > > It does indeed restore user state. And it very well may need to work > on Xen PV, too. Blech. I took another look. This function is severely busted. Bugs include: - 32-bit fails to save and restore %ds. I have no idea why. - 64-bit has inlined restores of segment regs. This is busted because it's missing exception handling. Admittedly, there shouldn't be exceptions these days since we try pretty hard to keep segments in sync. - GSBASE is restored way too late. - Segments are restored before the LDT is restored. *Boom* if we write to /sys/power/state from a program compiled with a sufficiently ancient libc. - Because we aren't sensible enough to do all this from a kernel thread, we probably fail to correctly handle nasty things like blockstep. I'll make a patch to fix a few of these bugs.