Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2520810yba; Mon, 6 May 2019 07:25:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwEM0NFg46932BX8RbtodNtM0V8RYVqJATNKzY61C/1LhRx66YRk6BoDpesjuVKu5EholUc X-Received: by 2002:a63:ee01:: with SMTP id e1mr31477689pgi.20.1557152721730; Mon, 06 May 2019 07:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557152721; cv=none; d=google.com; s=arc-20160816; b=HrtWECZxD/MGEwfwlxFwTReO0qWLSXVl1tZoUsyau2FeHDrbmeqEn/kWOCDwLQt5Rk u9A2lQgiOS7XrQnzEGuNmZQb7IoRF5f321nKMiwPhufPuJV3YlFVs4TfjfXu0KnATx4s zuhz2wSfYPX2lo908+DmR0SQsAYtMAUBBbabe16hYrzqASRvhQ5Wyp7FD+UxMKwFK1wZ Npv64a9D0wiF5vnL9lHket2QHmkHMTRRkEZS7uHS0AG0G/76jel+dbqgAElayG49+jdJ ZLQA1qpHJ4imXSWk237pr7hjmJZoOcKRbmdUQXukoRuePxFWRqH0C2MNE9f9cjk0Q733 X3NQ== 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; bh=5uWhhvNQQpVTLizPgZiuF1wqu0ZojCdb15uwofB7AUg=; b=E2xlZ7Qq05/QFCqBGnV48tl8lDHhoGfa53P9c3XuTJ2f99XErYJFYBPn7lvMnZqwch HydPkEtQF6jZ0novzRMlT0DPC7ypzmfEUsgcDMzlEb8Tc6LsBR0rLuqvYRAFQObqspeR wx2JPVd7+h1NwFpQxgvZumDHNAuBfTaTXA9g3e+Fh4nYRbXlGpDtj3ljaGFST4T5xJIL pxaT7JxN6PkCpEqqFP4cszcfxOGHJzvBK9qK6UFhsoOwm+Hp/m/1enwFshiqc8nFM239 W4rU2BznK+AXy/OoFi6HbZo3ELGXJMZucLeShlbVUuyRXT3hmXHvaOkPiaFLk3jO3/Ve eYpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@infradead.org header.s=bombadil.20170209 header.b=UmZd8Do3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w4si2504511pll.379.2019.05.06.07.25.04; Mon, 06 May 2019 07:25:21 -0700 (PDT) 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=neutral (body hash did not verify) header.i=@infradead.org header.s=bombadil.20170209 header.b=UmZd8Do3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726277AbfEFOX1 (ORCPT + 99 others); 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