From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4664C04A6B for ; Mon, 6 May 2019 14:23:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7695520675 for ; Mon, 6 May 2019 14:23:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="UmZd8Do3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726308AbfEFOX1 (ORCPT ); Mon, 6 May 2019 10:23:27 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:55660 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725994AbfEFOX1 (ORCPT ); Mon, 6 May 2019 10:23:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=GxKuXy1+s+PeeiwubdliM/pp8/xYTCCy3OKd2YpFtsI=; b=UmZd8Do3/TQldA46xNq9LjC5o ujqe1cGw3Kwuj67vT+ByS393Qd2O2pXTtZ1B4I26kZ6yV09UpFzfMEym3ETWoPvYl3TVGcyFOk5N4 hK9n2++qFXLdLa5cOTAUwTsSLPqbs5TX6WrYUNpH+naBZ82mAF1U8bJL8O7LXVuxLo7aru+o3jWYK bFQ3YL526U2l6zTU0A6mwlX+e1Gu9OZyH80MquAzo2GtJW53iokh2Otg2gf0O3tD/g6hB4EExmiWK nIgAQZLottZR3RvnuZLeW+L3Rs8ndg5qHLggBa3yxKoYxOZa51yf746AoYXylzcRuh8aCvd6AT7UH IBiqAoBXw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNeW8-0005Ye-1s; Mon, 06 May 2019 14:22:56 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 096412029F884; Mon, 6 May 2019 16:22:54 +0200 (CEST) Date: Mon, 6 May 2019 16:22:54 +0200 From: Peter Zijlstra To: Linus Torvalds Cc: Andy Lutomirski , Steven Rostedt , Linux List Kernel Mailing , Ingo Molnar , Andrew Morton , Andy Lutomirski , Nicolai Stange , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , the arch/x86 maintainers , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , Shuah Khan , Konrad Rzeszutek Wilk , Tim Chen , Sebastian Andrzej Siewior , Mimi Zohar , Juergen Gross , Nick Desaulniers , Nayna Jain , Masahiro Yamada , Joerg Roedel , "open list:KERNEL SELFTEST FRAMEWORK" , stable Subject: Re: [RFC][PATCH 1/2] x86: Allow breakpoints to emulate call functions Message-ID: <20190506142254.GG2650@hirez.programming.kicks-ass.net> References: <20190502202146.GZ2623@hirez.programming.kicks-ass.net> <20190502185225.0cdfc8bc@gandalf.local.home> <20190502193129.664c5b2e@gandalf.local.home> <20190502195052.0af473cf@gandalf.local.home> <20190503092959.GB2623@hirez.programming.kicks-ass.net> <20190503092247.20cc1ff0@gandalf.local.home> <2045370D-38D8-406C-9E94-C1D483E232C9@amacapital.net> <20190506081951.GJ2606@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190506081951.GJ2606@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 06, 2019 at 10:19:51AM +0200, Peter Zijlstra wrote: > +.Lfrom_usermode_no_fixup_\@: > +.endm > + > +.macro IRET_FRAME > + > + /* orig_eax is already POP'ed when we're here */ > + > + testl $CS_FROM_KERNEL, 1*4(%esp) > + jz .Lfinished_frame_\@ > + > + pushl %eax > + >From there.. > + lea 10*4(%esp), %eax # address of > + cmpl %eax, 4*4(%esp) # if ->sp is unmodified > + jnz .Lmodified_sp_do_fixup_\@ > + > + /* > + * Fast path; regs->sp wasn't modified, reuse the original IRET frame. > + */ > + pop %eax > + add $6*4, %esp > + jmp .Lfinished_frame_\@; > + > +.Lmodified_sp_do_fixup_\@: ... until here, needs to go, it is buggy. While a clever idea, it looses updates to regs->ip and ->flags. > + > + /* > + * Reconstruct the 3 entry IRET frame right after the (modified) > + * regs->sp without lowering %esp in between, such that an NMI in the > + * middle doesn't scribble our stack. > + */ > + pushl %ecx > + movl 5*4(%esp), %eax # (modified) regs->sp > + > + movl 4*4(%esp), %ecx # flags > + movl %ecx, -4(%eax) > + > + movl 3*4(%esp), %ecx # cs > + andl $0x0000ffff, %ecx > + movl %ecx, -8(%eax) > + > + movl 2*4(%esp), %ecx # ip > + movl %ecx, -12(%eax) > + > + movl 1*4(%esp), %ecx # eax > + movl %ecx, -16(%eax) > + > + popl %ecx > + lea -16(%eax), %esp > + popl %eax > + > +.Lfinished_frame_\@: > +.endm