Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2994190yba; Mon, 6 May 2019 15:13:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwBd7v6XEBzSxYyIz/Ka4a1VM2o3LAuYNAaTBrFC/NVUJ36ROgoh3tgokBcjm6WYdBkoeFu X-Received: by 2002:a17:902:854a:: with SMTP id d10mr36221766plo.8.1557180832922; Mon, 06 May 2019 15:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557180832; cv=none; d=google.com; s=arc-20160816; b=rxeN2Ns7ctugSjN5xAgCBBBKO8tvPdH5XhpWhqYWGq+go/HPPX6kI9OKz4hmZ+S8eD xQcxUMqU/hAOUnuXL70PElTYwrjW4W1GEqvVsxkecqmrnCPVXCaqiDes//gaD0dGMzA9 D3y+bI1e4IIHhUSEQA2j5mxyUM0tncK6YmJk7/CkGkAy/sycnRv/rbDJNBvC+xYbbZaX VdPYNl+GH8ghKMNvziZUhckTW2EOTjAGVydM0WejeJEQxvMd+NlgoYe22KWJ+V5Hjwq+ MwH1HaCf1+vMTZlyYY0lK8rZ+DTkLWpwKR0qtS3Bd0/28yrhfhSn1ifHuT05bOtAkBHm Hdrg== 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=KnC6sHzJKQT/H/efllpurOKq1DqCgmhhrIn+ALVg0f8=; b=FkKVdqxv594NdlHGHuJg4oF2EwFGN+KHRDaipd/T2ALa7aFGh0QOFOg/xy9h5qGzyl EDblzE46UrmUODcDn3WGhdPFyeAaLlAH6lzS9Q/Akkhi64VpogGBHWuhIsNBTMgZ1ZEZ cdKb8OvJjkv1xmeMZS2HtenooH2LBUQduQ9R/WdfxedLtVVwMsZYo0WP3nUSIgasX+5z 7CziCypbGl1PKZp63DOruoA8HsUBVai0mG9TvgVJJ4MlVWIGUxS3KHZ4I/KZuWngvBvx RO1y8CTdj4BXaCpMKQ0larpy6n3futR4t7NTAdHG6vx3bo55MXKUTou2/1ca2nDpCsUr UM3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=UuWTDsQL; 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 73si16598657pgb.414.2019.05.06.15.13.34; Mon, 06 May 2019 15:13:52 -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=UuWTDsQL; 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 S1726324AbfEFWMl (ORCPT + 99 others); Mon, 6 May 2019 18:12:41 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:44062 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725994AbfEFWMk (ORCPT ); Mon, 6 May 2019 18:12:40 -0400 Received: by mail-lf1-f65.google.com with SMTP id n134so8461494lfn.11 for ; Mon, 06 May 2019 15:12:38 -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=KnC6sHzJKQT/H/efllpurOKq1DqCgmhhrIn+ALVg0f8=; b=UuWTDsQLlvb0PtcfEid4ABezWzyagSu44050e/2j488U+99fI3xCIqtuQS8vXMHPrQ xvVSucwGErlEAEYFFWNYIWMj4gj1EPGneYgBBhuklMQ9H4OeRQjj1yrsseBu+AGIqRuC 1DBfQJo9MbI0m5IyIe848iiX0VPuZXVlACZoY= 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=KnC6sHzJKQT/H/efllpurOKq1DqCgmhhrIn+ALVg0f8=; b=Cxf46DZ+LkAoMAiAz7WOlunyjDdzo+a2padbOUCvcukWunsraMO76vBKTYFuvDCAKx zHUJNFl23FKAZyZdqkv/0jwF9lX9gO8stx3dTa6jQY+n0zmTPw41rVgTce/X3FLaM6i3 RLKtGNLcgA/nxrKWd3yHYmjDC1Gh1FNYjlWFy/kjYmSR2vc9Zx8zzJqmuV5ptSyXsVjq qmxgf2CxqBd9lafbiz8UVtroG3ZgC2cnVRpk+zzXIb5sXaMbinzZRuI5c5BrI75+LHIu ZvC6DpkRNazMhvjTAUMahUBJ97AcdVias2UwVUs4S7p1S5gljsoElcSO2IvN2TPb0U8C W2iw== X-Gm-Message-State: APjAAAVpCB9v1EetZ4bxiguZLROU9GUdDcRNm6VdR3ZSzoMumps+JoDC shdo0PZdzzD5eldZdZRXwNeWIr/s0GM= X-Received: by 2002:ac2:50c6:: with SMTP id h6mr3828674lfm.31.1557180757696; Mon, 06 May 2019 15:12:37 -0700 (PDT) Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com. [209.85.167.51]) by smtp.gmail.com with ESMTPSA id g66sm1864346lje.88.2019.05.06.15.12.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 15:12:37 -0700 (PDT) Received: by mail-lf1-f51.google.com with SMTP id u27so10019156lfg.10 for ; Mon, 06 May 2019 15:12:37 -0700 (PDT) X-Received: by 2002:a19:4f54:: with SMTP id a20mr14066761lfk.136.1557180433906; Mon, 06 May 2019 15:07:13 -0700 (PDT) MIME-Version: 1.0 References: <20190502181811.GY2623@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> <20190506174511.2f8b696b@gandalf.local.home> In-Reply-To: <20190506174511.2f8b696b@gandalf.local.home> From: Linus Torvalds Date: Mon, 6 May 2019 15:06:57 -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 , Masami Hiramatsu 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 2:45 PM Steven Rostedt wrote: > > To do that we would need to rewrite the logic to update each of those > 40,000 calls one at a time, or group them together to what gets > changed. Stephen, YOU ARE NOT LISTENING. You are already fixing the value of the call in the instruction as part of the instruction rewriting. When you do things like this: unsigned long ip = (unsigned long)(&ftrace_call); unsigned char *new; int ret; new = ftrace_call_replace(ip, (unsigned long)func); ret = update_ftrace_func(ip, new); you have already decided to rewrite the instruction with one single fixed call target: "func". I'm just saying that you should ALWAYS use the same call target in the int3 emulation. Instead, you hardcode something else than what you are AT THE SAME TIME rewriting the instruction with. See what I'm saying? You already save off the "ip" of the instruction you modify in update_ftrace_func(). I'm just saying that you should *also* save off the actual target of the call, and use *THAT*. So that the int3 emulation and the instruction rewriting *match*. What you do now makes no sense. You're modifing the code with one thing (the "func" argument in update_ftrace_func), so if your modification completed, that's what you'll actually *run*. But you're then _emulating_ doing somethiing completely different, not using "func" at all there. So let me say one more time: how can it *possibly* make sense to emulate something else than you are changing the instruction to read? Are you finally understanding what craziness I'm talking about? Stop with the "there could be thousands of targets" arguyment. The "call" instruction THAT YOU ARE REWRITING has exactly one target. There aren't 40,000 of them. x86 does not have that kind of "call" instruction that randomly calls 40k different functions. You are replacing FIVE BYTES of memory, and the emulation you do should emulate those FIVE BYTES. See? Why are you emulating something different than what you are rewriting? Linus