Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2915071yba; Mon, 6 May 2019 13:45:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4OedclEWxHUQLDXT47njhLC+voTR0XR415MWZTHq49KDRbbl0Y+qcobyXpVhPi2O44KNE X-Received: by 2002:a17:902:b407:: with SMTP id x7mr6730420plr.28.1557175506090; Mon, 06 May 2019 13:45:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557175506; cv=none; d=google.com; s=arc-20160816; b=IthqWxZr5qiUGNxjXu34nDvJoNymODx2Rs9S1Gq26bY243KLOyKJ0160P0x2o+j+cJ kZwxz8s6cWCWWfoCbIXZD110YDijcoFFKF0t3+ccuMgii31tQ7gt9O3TxXzWJ93tBpXX IHVKgUwitfMNDMuQ+0jTsGyuOBJVhi1WeeMLX03LC7dega6osl7q7hUUjWdfXgJuU6Vk 2BSqq0BXXfje0JRgd6MRZ1kK3GPBVyEut3+Mi0CsjnuvR2OD7WV7jlT8Ph9eTzvts5Cu McknHfD+dNftK0nP8XGkeAadOUq5efJf1m/II/ZSiPdWAgbJEncS1zTy/ajWr3HPQL4y m9Pg== 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=LN8/NTM9pRgOW6Qf1pdY0qkm+a38UqLa0bBTAH2+TkU=; b=UsCmgH7r19xn0L0mnF00cNu2NCZUTyxeuUYPhfDjB8E47936cpXrsyercjaaUOeFMI 5yU9KSo3YYijdJzAe46FQSMpjU6mJwjM6hx48N05UeF/L/5owZBbae1bw16EaWEaUIH5 D3VUc0k4k4MXE6EDYq9VmjXnThSHl2sLFaZ0r89kFLq7oeZ4s8fWNsM8sU1Dp//KHmDG wg1GgvGFc947mYy3X7lgMlrcWedp1lUH2npvPTk1cY9v2c6UUDdr+Fvb2Crq61iLnXOX Fb8/4kpz9HxwccFeIGuCiGQ1CwCKzqyQk/mhoAqjsyPHukO903VO+jbJRMS5i4jQ8/bX EUTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="evA/FZOl"; 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 w21si17249124pgj.513.2019.05.06.13.44.50; Mon, 06 May 2019 13:45:06 -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="evA/FZOl"; 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 S1726468AbfEFUme (ORCPT + 99 others); Mon, 6 May 2019 16:42:34 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:43354 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726403AbfEFUme (ORCPT ); Mon, 6 May 2019 16:42:34 -0400 Received: by mail-lf1-f65.google.com with SMTP id u27so9882407lfg.10 for ; Mon, 06 May 2019 13:42:32 -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=LN8/NTM9pRgOW6Qf1pdY0qkm+a38UqLa0bBTAH2+TkU=; b=evA/FZOl+4vi7XMcxBB/gYj89Z6IdHQ5/igigK5Y+YPsXpuGYwuw6t4TEIDlA60P57 BPb+CmUxzNVrjEfc4zrJ5mmulbz8GTGhJS3vzxORSu4CzH/aGkuq6kd1492nwVstVwD7 +BsguG7MutEBgjcZlB/Jrxx7a0wvgr9VRX8Jo= 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=LN8/NTM9pRgOW6Qf1pdY0qkm+a38UqLa0bBTAH2+TkU=; b=P2bBcvWlbxY0gd8gmnjmibXtaLcI62jLsne6S9xhyfOXj7K2srXXZ7k4NE8E/0jJxg szQzXiqsuSaA+5F8mwjP9pQ+9Y1Ak+wJQcXXq4GrVF+/YqeSNYkuBtf2yLw5S3jZ5qbV uQuWI6g/dEpkKYqBW9bEQxQLIjEqz3ul9CeNL5BMuC4EC2Gs3cjUswmfquy4rs1Emrki /ItGu2qjO7C/TrsAR5LolKBle7w8qY10t+aHGGOd3TdW45QjTkxa2EVRnniG9Wphf+Wa N8kmQBTEOKyXHiX2WZj3UW+HxlM7IMkXs2fhV9vsKuHYxeQlx2iTdu/TL2VxQxFjRbNK IKzA== X-Gm-Message-State: APjAAAWpDIKD7wbXHwp9SHJ5ez8QnomW698VEqexmmoONq+eTE9FbbaU Piw/f1Vhu0SKixLHf5YSBwoyxLDAqx8= X-Received: by 2002:ac2:554c:: with SMTP id l12mr7474045lfk.111.1557175350450; Mon, 06 May 2019 13:42:30 -0700 (PDT) Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com. [209.85.167.45]) by smtp.gmail.com with ESMTPSA id g8sm2808267lfg.4.2019.05.06.13.42.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 13:42:29 -0700 (PDT) Received: by mail-lf1-f45.google.com with SMTP id k18so10125220lfj.13 for ; Mon, 06 May 2019 13:42:28 -0700 (PDT) X-Received: by 2002:a19:f50e:: with SMTP id j14mr13952445lfb.11.1557175348252; Mon, 06 May 2019 13:42:28 -0700 (PDT) MIME-Version: 1.0 References: <20190502181811.GY2623@hirez.programming.kicks-ass.net> <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> <20190506095631.6f71ad7c@gandalf.local.home> <20190506130643.62c35eeb@gandalf.local.home> <20190506145745.17c59596@gandalf.local.home> <20190506162915.380993f9@gandalf.local.home> In-Reply-To: <20190506162915.380993f9@gandalf.local.home> From: Linus Torvalds Date: Mon, 6 May 2019 13:42:12 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC][PATCH 1/2] x86: Allow breakpoints to emulate call functions To: Steven Rostedt Cc: Peter Zijlstra , Andy Lutomirski , 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 Mon, May 6, 2019 at 1:29 PM Steven Rostedt wrote: > > Because that call to ftrace_stub is also dynamic. You're missing the point. We are rewriting a single "cal" instruction to point to something. The "int3" emulation should call THE SAME THING. Right now it doesn't. > Part of the code will change it to call the function needed directly. > > struct ftrace_ops my_ops { > .func = my_handler > }; > > register_ftrace_function(&my_ops); > > Will change "call ftrace_stub" into "call my_handler" But that's not what you're actually *doing*. Instead, you're now _emulating_ calling ftrace_regs_caller, which will call that ftrace_stub, which in turn will try to update the call site. But that's insane. It's insane because - it's not even what your call rewriting is doing Why aren't you just doing the emulation using the *SAME* target that you're rewriting the actual call instruction with? - even if ftrace_regs_caller ends up being that same function, you'd be better off just passing the "struct pt_regs" that you *ALREADY HAVE* directly to ftrace_stub in the int3 handler, rather than create *another* pt_regs stack See? In that second case, why don't you just use "int3_emulate_call()" to do the reguired 'struct pt_regs' updates, and then call ftrace_stub() *with* that fixed-up pt_regs thing? In other words, I think you should always do "int3_emulate_call()" with the *exact* same address that the instruction you are rewriting is using. There's no "three different cases". The only possible cases are "am I rewriting a jump" or "am I rewriting a call". There is no "am I rewriting a call to one address, and then emulating it with a call to another address" case that makes sense. What *can* make sense is "Oh, I'm emulating a call, but I know that call will be rewritten, so let me emulate the call and then short-circuit the emulation immediately". But that is not what the ftrace code is doing. The ftrace code is doing something odd and insane. And no, your "explanation" makes no sense. Because it doesn't actually touch on the fundamental insanity. Linus