Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1104758yba; Fri, 3 May 2019 16:20:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqw3wc4HHc94NJU7QayeF1VEYJahIXrvdyI+w2BktZ2a2nIV5khVQPMpkFWUITgN501aod+R X-Received: by 2002:a62:1f1b:: with SMTP id f27mr15196473pff.89.1556925651044; Fri, 03 May 2019 16:20:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556925651; cv=none; d=google.com; s=arc-20160816; b=Rqb1tJgaVHXAz7eWQcYYpSWilzSJ5T5cc+FgaOlIMJt8uH83+QX9EyOJ3txuTza6XP wK7i5+36ZgLWNTNdtt6xMwtJF7cDmLPhXu7mNrvnyiFJLtYb4/N+0K01ZTzW7dwAqrY4 Zd8cFNBhtK84X4rqSBGQkZZtwO53dKmyvfTvxITBZU5FudLLWrpwJ7Z4UPjz53KuLuXK 1wbq3n7LbXHEdqRYh6FMrefrg7z8W3DaWsaiRsreGAiu7x3ey1PTqlcGCb5nbl2hE80M 9v7fl+ljjXj/dT6AeymKGWxnuFyd60qsuh36mIPAIzc8qS0ayDzzjPPZ3oZHhfG7M4v1 NpYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=OHqZ1dasojZtZXeDb6AOgPCoclYuOoFb8Dw9XhQcuX8=; b=sH7haMu/LjsoxSHQy+04Rdwusv1zpINtlqCTbRcYyyrz7hT50HXompDMhRCvIznWnZ GiXxKpUfC3kmlecQha26atCtnyqVqOziRQLMnJz9YTRmFXiJnWRvVHtMtYN0BuL7sc3w xnlQojM8dKuIowIpzWzSOopKaAvZQ1o1zJJFkxbyxD3LuYU26NGmCaMQCJ9C5KxNMZCC JS3DrbPj+j/lIqPhgu13ZatAbi/4E9TU6yL0RUHj0UleS9hrQ9C7UtdUrBJCuYYLaA63 Q9BUZiaf3Cyzz2Xr4lyPfn3nk9wzun4cf1FfHRx6shMMe6aIZkPf7uaUgiipB3GPZMS5 ARmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Z5lqxrRs; 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 s4si4611338plq.133.2019.05.03.16.20.35; Fri, 03 May 2019 16:20:51 -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=pass header.i=@linux-foundation.org header.s=google header.b=Z5lqxrRs; 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 S1726579AbfECXRS (ORCPT + 99 others); Fri, 3 May 2019 19:17:18 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:40662 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726041AbfECXRS (ORCPT ); Fri, 3 May 2019 19:17:18 -0400 Received: by mail-lj1-f196.google.com with SMTP id d15so6536948ljc.7 for ; Fri, 03 May 2019 16:17:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OHqZ1dasojZtZXeDb6AOgPCoclYuOoFb8Dw9XhQcuX8=; b=Z5lqxrRs7Uo5ooOZcjNQMQ0wMKgNkbdgLGUsuVX4JfUFji1uCAkCzJ4BGPfIaizpY6 JWe5m/qV8Q8llt6hrEswIs+Q/3t9J9sE6JAaJ3czcaSnBtxbhbEqSZL2NpE9lbHSXdrI gxKi90AMf5eRvy/aupAWhDZHVdVjhL/W1hUdk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OHqZ1dasojZtZXeDb6AOgPCoclYuOoFb8Dw9XhQcuX8=; b=juxE2Tvu1DxTWcZBINvX1e+QsGM4YeJTHnkTcOtg9sn6ys3yc2Q7yeb+fO3xrTZ9lb hpte3/CvFpxhsWYn6iWZnbQ7cwNeH2zwpkVF5HIPRDvpYD0fLADqufwBHGXdZideKRr5 z48gCoj2YjZBOvU0oDIw0MBIt66d5gB57BoSoED+4AxzF/HBPDtczi96hZJ3zeHj2O3v +W4u3S7X80z4fHmImxQL1S+4Rxf6IQk9Ik3N9PxcRmE9sDAINZDOaR2XeIot3iRW7t1A uEjgJxS308zlNXjdx//r2NityLrHsdDMDvTr5VJqELjM9JuDOYuUS9+p/LM4tGFc3XNU 8mbA== X-Gm-Message-State: APjAAAW43GB0cJ6wRiyFH8jTyGicdaKTAxnpNnbmt1plakwirf/BVN/E o5Bn0+KxE2/+NxU1FNExbjm6PfMEfOg= X-Received: by 2002:a2e:9919:: with SMTP id v25mr6526073lji.2.1556925436015; Fri, 03 May 2019 16:17:16 -0700 (PDT) Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com. [209.85.208.181]) by smtp.gmail.com with ESMTPSA id y186sm659823lfa.14.2019.05.03.16.17.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 May 2019 16:17:15 -0700 (PDT) Received: by mail-lj1-f181.google.com with SMTP id c6so1124881lji.11 for ; Fri, 03 May 2019 16:17:14 -0700 (PDT) X-Received: by 2002:a2e:890a:: with SMTP id d10mr5422300lji.94.1556925434455; Fri, 03 May 2019 16:17:14 -0700 (PDT) MIME-Version: 1.0 References: <20190501202830.347656894@goodmis.org> <20190501203152.397154664@goodmis.org> <20190501232412.1196ef18@oasis.local.home> <20190502162133.GX2623@hirez.programming.kicks-ass.net> <20190502181811.GY2623@hirez.programming.kicks-ass.net> <20190502202146.GZ2623@hirez.programming.kicks-ass.net> <20190503152405.2d741af8@gandalf.local.home> <2962A4E4-3B9F-4195-9C6D-9932809D98F9@amacapital.net> In-Reply-To: <2962A4E4-3B9F-4195-9C6D-9932809D98F9@amacapital.net> From: Linus Torvalds Date: Fri, 3 May 2019 16:16:58 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC][PATCH 1/2] x86: Allow breakpoints to emulate call functions To: Andy Lutomirski Cc: Steven Rostedt , Peter Zijlstra , 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 3, 2019 at 3:55 PM Andy Lutomirski wrote: > > But I think this will end up worse than the version where the entry code fixes it up. This is because, if the C code moves pt_regs, then we need some way to pass the new pointer back to the asm. What? I already posted that code. Let me quote it again: Message-ID: # args: pt_regs pointer (no error code for int3) movl %esp,%eax # allocate a bit of extra room on the stack, so that # 'kernel_int3' can move the pt_regs subl $8,%esp call kernel_int3 movl %eax,%esp It's that easy (this is with the assumption that we've already applied the "standalone simple int3" case, but I think the above might work even with the current code model, just the "call do_int3" needs to have the kernel/not-kernel distinction and do the above for the kernel case) That's *MUCH* easier than your code to move entries around on the stack just as you return, and has the advantage of not changing any C-visible layout. The C interface looks like this /* Note: on x86-32, we can move 'regs' around for push/pop emulation */ struct pt_regs *kernel_int3(struct pt_regs *regs) { .. .. need to pass regs to emulation functions .. and call emulation needs to return it .. return regs; } and I just posted as a response to Stephen the *trivial* do_int3() wrapper (so that x86-64 doesn't need to care), and the *trivial* code to actually emulate a call instruction. And when I say "trivial", I obviously mean "totally untested and probably buggy", but it sure seems *simple*., Notice? Simple and minimal changes to entry code that only affect int3, and nothing else. Linus