Received: by 10.223.185.116 with SMTP id b49csp7434228wrg; Thu, 1 Mar 2018 05:36:13 -0800 (PST) X-Google-Smtp-Source: AG47ELtl9dKI4GVkLv3dgDB7TaF1xfeDVf1tmvtl8jiLkq05gGqEIpj/SA7V/NiBKcenLeu9O8EF X-Received: by 2002:a17:902:1:: with SMTP id 1-v6mr1958382pla.187.1519911372992; Thu, 01 Mar 2018 05:36:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519911372; cv=none; d=google.com; s=arc-20160816; b=QxjXJ7wM+tAGyFa/eiD2fuZ8/7nXN5lfkh5mRk6LGkW2JvEZP6MYeibroHbf7ppA/j BjBa589uVt7PNOY41s0/R0IGPKAbAzb0GV1xdXUFRMaY2NMg8Ehkdc4AYclq/53HIg/D wC+6hdms+t7LmIajbwMgJxHg+Bf3uUI4aeJG1pGatp6KE+KeDUp5s2ZShv4BRIoyCGjn gq2JTibCxIlJEw3G0OMSeAa57VAdxg18tCdQkuSCeTg9JkhXuhmVk5pq50huR5UB28x7 HYzbLTFMfEo7ARbBiA1Pj/HFv5MkKrhZvrga0rQtS4XPLlEHAvPQBX0E4Z7bWELqXutE SNwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=stK49IlzBzUMPbXGTk/uzcvakqauHAqYNGs4XBZ10cY=; b=H+BWsyk/vXaGhtLuHClNpl96RQPq5wgI6ZfGocOWRC+pmM9ghYfn/2kTTU8J7b6R1T B7zMhKjwluPWoHTHUSHzxjTfyF7sLLZU1ZCYOCiciEs2AbgXC9/vwf6xkbm6SgjRvEry 6LIQJIuMAC2VGJRbxybKiPaxKolOHkR+t90HovQi6isounBHARg/pm5pSxaFprNrqzHM wGCxtwQJVdreLKNqys2dzJ1iuKsf8phm+uYmeq5xdpKwL/pu+XZazlVrnjFTKwiqUf1m w8hoXp3N9SFmoS4EgGda3eJ+ileWKQegvEjGKzhVJ5vmy77W60fKsgq4iyekuhuIaGf2 3HAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=F/pISCPD; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a63-v6si3101453pla.44.2018.03.01.05.35.57; Thu, 01 Mar 2018 05:36:12 -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; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=F/pISCPD; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030833AbeCANee (ORCPT + 99 others); Thu, 1 Mar 2018 08:34:34 -0500 Received: from 8bytes.org ([81.169.241.247]:60918 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030711AbeCANed (ORCPT ); Thu, 1 Mar 2018 08:34:33 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 4EFAA1D5; Thu, 1 Mar 2018 14:34:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1519911271; bh=wI9O35xRbS65Rw8yCvFz881g9fLgEf3XclEkdKXluHI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=F/pISCPD4gO1me8bxf9CHDp7HfM/CWOgFkjuI4jKqXAppMsojJSWvYKdtFT7nGMRR p5x6CtsF9lGoTcOZQ9KY7DI0PXGpkVoz/F4I9gliIKOa/2ghpita0jgPlCyjfvACzm iUZ5kp/R98jfjzKn+YJ4TvKH8oLp8QeJUXxDf6ySH/+BTjXFkDdnrfpO6dLNDt8UN/ CUwHacmOfKtP4dR6RhS0mECb6w4Mm+m4pXwioyE6UbvzLwVJWczkNVrdXu4hThrjx2 Dzwo7AF6Hk9hHIvroJeVzPkqSxKnF+mndyYdlqannC5/0lzRbJmAoRs3qyAdsrLUYv Z7KsKTsLD+Thw== Date: Thu, 1 Mar 2018 14:34:30 +0100 From: Joerg Roedel To: Waiman Long Cc: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Andy Lutomirski , Dave Hansen , Josh Poimboeuf , Juergen Gross , Peter Zijlstra , Borislav Petkov , Jiri Kosina , Boris Ostrovsky , Brian Gerst , David Laight , Denys Vlasenko , Eduardo Valentin , Greg KH , Will Deacon , aliguori@amazon.com, daniel.gruss@iaik.tugraz.at, hughd@google.com, keescook@google.com, Andrea Arcangeli , Waiman Long , Pavel Machek , jroedel@suse.de Subject: Re: [PATCH 12/31] x86/entry/32: Add PTI cr3 switch to non-NMI entry/exit points Message-ID: <20180301133430.wda4qesqhxnww7d6@8bytes.org> References: <1518168340-9392-1-git-send-email-joro@8bytes.org> <1518168340-9392-13-git-send-email-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 27, 2018 at 02:18:36PM -0500, Waiman Long wrote: > > + /* Make sure we are running on kernel cr3 */ > > + SWITCH_TO_KERNEL_CR3 scratch_reg=%eax > > + > > xorl %edx, %edx # error code 0 > > movl %esp, %eax # pt_regs pointer > > > > The debug exception calls ret_from_exception on exit. If coming from > userspace, the C function prepare_exit_to_usermode() will be called. > With the PTI-32 code, it means that function will be called with the > entry stack instead of the task stack. This can be problematic as macro > like current won't work anymore. Okay, I had another look at the debug handler. As I said before, it already handles the from-entry-stack case, but with these patches it gets more likely that we actually hit that path. Also, with the special handling for from-kernel-with-entry-stack situations we can simplify the debug handler and make it more robust with the diff below. Thoughts? diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S index 8c149f5..844aff1 100644 --- a/arch/x86/entry/entry_32.S +++ b/arch/x86/entry/entry_32.S @@ -1318,33 +1318,14 @@ ENTRY(debug) ASM_CLAC pushl $-1 # mark this as an int - SAVE_ALL + SAVE_ALL switch_stacks=1 ENCODE_FRAME_POINTER - /* Make sure we are running on kernel cr3 */ - SWITCH_TO_KERNEL_CR3 scratch_reg=%eax - xorl %edx, %edx # error code 0 movl %esp, %eax # pt_regs pointer - /* Are we currently on the SYSENTER stack? */ - movl PER_CPU_VAR(cpu_entry_area), %ecx - addl $CPU_ENTRY_AREA_entry_stack + SIZEOF_entry_stack, %ecx - subl %eax, %ecx /* ecx = (end of entry_stack) - esp */ - cmpl $SIZEOF_entry_stack, %ecx - jb .Ldebug_from_sysenter_stack - - TRACE_IRQS_OFF - call do_debug - jmp ret_from_exception - -.Ldebug_from_sysenter_stack: - /* We're on the SYSENTER stack. Switch off. */ - movl %esp, %ebx - movl PER_CPU_VAR(cpu_current_top_of_stack), %esp TRACE_IRQS_OFF call do_debug - movl %ebx, %esp jmp ret_from_exception END(debug)