Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3231853yba; Mon, 6 May 2019 20:13:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrXvlBO03GysE0h8g/xMOoEHZhX0cDh7zYYBinI23IQd9Wt8I+ovrWbGcGWmy5qx4FWAJq X-Received: by 2002:a17:902:10c:: with SMTP id 12mr26435767plb.61.1557198798784; Mon, 06 May 2019 20:13:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557198798; cv=none; d=google.com; s=arc-20160816; b=x1Z5c7VMiP6RVlTk8glmSaA/lJxnfWban5YeglVmvh8QffVGkdTyXstpr0dF2Ocdrb YsjwoI11LzI4SzMLHZ+H+JGFbD9Ft+qpmqAJUsRGyteS7UYh2zFMLxY1yapXExoD9KGf 4mnNoXDdGVumQVlERgxM23kZsoe9VZWX9C3euESgAKaNscoe05he7eJnS+lkmhjYK06T s+1u/KavzE6M7FV+bS0sg5HPxaoRB0Ms/RvfyxMNouAQ9fSc50Rhhc44+kv/ALVXSBGn OXSY9x5SbVOxGPdxk9R1i/w3pOsVFdMcPneiS1NF9UYcI1s6jqQDYBgEqT3BYp6LEHi6 XlYA== 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=1vPH9I5PWr2TI7X5PE+d7W4anLeW7LWz/OE4YpqPd8k=; b=n916dml8hNSuY4hzwgPHhaXKmf2ZBvh6yvVT7bA8gBo2wpUJc/ySIsgJm5k+3eALJZ aoDOg9QbMsQ3HM+GHXUP61DWS19v5KSDQt7JWyftkD6gPkQ2ltk7kMkPoUiJoXNx4g// v4AUArlOcCm5JHCYwOWflnuwlDEh9Vv43m9O62aa6SGopG0CS2uI67q470DgHIxDgYGC Ta15LnsqQoQlrwhz7mh+AYYNNeeApEUEk/YjyxFzPFa/SUGO2rExg5SrJCc+G1M/bq8J 8sB+OwkbhIlI/bqQ4ig6GCGuO4OdM3r1ZQMLs1bREFtJ+3qHDEEQNad6jsLWZ0VPmAKp 4OYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=eMRYbWYF; 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 s31si7658126pga.207.2019.05.06.20.13.03; Mon, 06 May 2019 20:13:18 -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=eMRYbWYF; 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 S1726916AbfEGDLp (ORCPT + 99 others); Mon, 6 May 2019 23:11:45 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:38475 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726468AbfEGDLp (ORCPT ); Mon, 6 May 2019 23:11:45 -0400 Received: by mail-lj1-f195.google.com with SMTP id u21so3775334lja.5 for ; Mon, 06 May 2019 20:11:43 -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=1vPH9I5PWr2TI7X5PE+d7W4anLeW7LWz/OE4YpqPd8k=; b=eMRYbWYFmPHyc8hLoVhhlUEKgGTDjH5U4y4GUjFL0QRJ8UTmZq4UYf25wlrtMiMJOo aZaKmEpFAHwSky6xN0UwF6xEVDQDS7lUnQRo2Ewz4hbjzvKaF1XxCm25cBfHKnpnn8L1 SHmoa9QAiN9pzOrwoTZhfnY5bu9mini6zfThg= 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=1vPH9I5PWr2TI7X5PE+d7W4anLeW7LWz/OE4YpqPd8k=; b=q8I7HfjnJVrA7tCN+erhOd9GHiN4Xb8Ml/Ufs1GIy4ajJF7QjJ8+bQYNMyvmH18UyJ nMHoXVafeNJ7gBDBuvpeEXSC63ZubmN6LNP7JMcsCILpfngspI8bNhFnnCTKZQYpp4wl TC1SRpAdNKiSmq4gU2e54KVG8x0/9sum/PaZb+6hd+d5OqbvgFsh2YinOFuEDewbkBzj 5inU3ppdpxkNtuAvo7LIwuwpthaq2LGXLO9Jm2+MUoqfUOfc5IGs5rBhb4i60p6K8cUh Z2wIbTGbI9HOzYpcewVQHXkOsRUA2SVnYPQFYIdq+EgAWtEWHoIpL0Unum95JfRijz/m 7hjw== X-Gm-Message-State: APjAAAUCxu2NB8u3wUNg0z8DKsHDO627Q5mLxka7Jl4jHnQ3DCBteyTu 7o2+NjI+PuUSMVbtKCvL1z8Jp0wb/UE= X-Received: by 2002:a05:651c:155:: with SMTP id c21mr15862816ljd.10.1557198702431; Mon, 06 May 2019 20:11:42 -0700 (PDT) Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com. [209.85.208.174]) by smtp.gmail.com with ESMTPSA id n1sm2776963ljg.84.2019.05.06.20.11.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 20:11:42 -0700 (PDT) Received: by mail-lj1-f174.google.com with SMTP id k8so12884397lja.8 for ; Mon, 06 May 2019 20:11:42 -0700 (PDT) X-Received: by 2002:a2e:9ac8:: with SMTP id p8mr14197859ljj.79.1557198341113; Mon, 06 May 2019 20:05:41 -0700 (PDT) MIME-Version: 1.0 References: <20190502181811.GY2623@hirez.programming.kicks-ass.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> <20190506210416.2489a659@oasis.local.home> <20190506215353.14a8ef78@oasis.local.home> <20190506225819.11756974@oasis.local.home> In-Reply-To: <20190506225819.11756974@oasis.local.home> From: Linus Torvalds Date: Mon, 6 May 2019 20:05:24 -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 7:58 PM Steven Rostedt wrote: > > > Notice? We'd not even have to look up any values. We'd literally just > > do something like > > > > int offset = locked_atomic_read(ip+1); > > return int3_emulate_call(ip, ip+5+offset); > > > > and it would be *atomic* with respect to whatever other user that > > updates the instruction, as long as they update the offset with a > > "xchg" instruction. > > Honestly, I'm not really sure what you are trying to do here. > > Are you talking about making the update to the code in the int3 > handler? No. The above would be pretty much the entirely of the the ftrace_int3_handler. It would emulate the call that has had its first byte overwritten by 'int3'. Without doing any lookups of what it was supposed to change the call to, because it simply depends on what the rewriting code is doing on another CPU (or on the same CPU - it wouldn't care). So no need to look up anything, not at int3 time, and not at return time. It would just emulate the instruction atomically, with no state, and no need to look up what the 'ip' instruction is at the time. It could literally just use a single flag: "is ftrace updating call instructions". Add another flag for the "I'm nop'ing out call instructions" so that it knows to emulate a jump-over instead. That's it. Because all the actual *values* would be entirely be determined by the actual rewriting that is going on independently of the 'int3' exception. Linus