Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3958849yba; Mon, 29 Apr 2019 11:17:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCooExJMQ2cNZKN9KtNFwfSUqu/9SS+C2IQZH0MGXRFhqHJBxXmdBp32Gkwe5EVF9ULCaq X-Received: by 2002:a65:448b:: with SMTP id l11mr60111391pgq.185.1556561848477; Mon, 29 Apr 2019 11:17:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556561848; cv=none; d=google.com; s=arc-20160816; b=MsE97VRkwrAe/SiT1Vk84prmMgXsh6Wv4IPv42y2g8/afWBCDp82j0PvD1avreiIHF Ir1EMbbblYi0GG/d1OLWMmBz9mPeq6bzQ/rx8UhWuKjCG5R+mVQ+P/ux04HOSeU4eEob HTGeYhC9ZdtcsXLi+fgW/FawPcjWvLAXfCKpecDXGbh0DbYXCLvybGsEFOJOtD8TqIxy AvZoMyfo4cSDZ5SUjTF6b0+0fINeg3q9fA5+lPf6etUc1q8Uaa06ZwK7/4rzfHHKwKZp ZL+MaFJZCsOSFdYOptPnV2/SmWxx5xjNW04YiyraT1q95wld3SjnWIF4Xyhlf1xj8N8i F7Xg== 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=4rSXrLueo+dlB0QOA/Bz3QN8ayKh59Nj+1c63WoQALY=; b=BumpNDkEsp+Y4LLRh7bxHGSDyuavdGNZ9M3AoQgBuoF11GMAz/WvqLeEg5yCLXpRzS Oi6ik6c8qNtvwZ8R7BWR1aurNskYwTCOHmlJEmSWETDSpcc0Nib5c37Qj2BXDKiJ8fA8 cXXrK6eNGxLkOt08tfW3QqbqXXCZ73dgkT0afa0fjz0jLrSocugBi/YOIQ0sWh6yJOEX FQZdY9PV6tVGgn1Qm0io1EAlz6rg/xZZPSmeuOt9RPfS+zvr4sqyDrr0B4AMvXP4ANkW CP2A2O+e1Xqrhw9bF8THX2kaPQLL0mZriUpnkOIIw/MH1ttNH0IKY0AvK4N+nNwOt0cB NZPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=BGgMKVPs; 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 z127si36167840pfb.254.2019.04.29.11.17.12; Mon, 29 Apr 2019 11:17:28 -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=BGgMKVPs; 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 S1729125AbfD2SPZ (ORCPT + 99 others); Mon, 29 Apr 2019 14:15:25 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:36773 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729043AbfD2SPZ (ORCPT ); Mon, 29 Apr 2019 14:15:25 -0400 Received: by mail-lf1-f66.google.com with SMTP id u17so8772989lfi.3 for ; Mon, 29 Apr 2019 11:15:23 -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=4rSXrLueo+dlB0QOA/Bz3QN8ayKh59Nj+1c63WoQALY=; b=BGgMKVPsvqNoV6+19qjq9PyjRoQcgSyZoqJJgWGli2u+TA0JhPmNLWxVZNZngOTh0Z bBbwt+/UwMXmo/5/P88lqtFZDjNDADrto7uZEZhKt3oRPWdU9IZgxI3xIN6kYaaq5rjS q9ZRgMmDVcReuUcQT1NEHybGemWu/Bnwa48X8= 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=4rSXrLueo+dlB0QOA/Bz3QN8ayKh59Nj+1c63WoQALY=; b=Dx5l/sAkijuIDQ33s7Xq7x8OqI8DnsK34hBSmnP7BurwPKdPMNaraQqivwjZyjASFH MbduerScFGqEVAqkGoXhkZdq5SbsaZG8EA//AdJTnGpO6w/ukSkEJ96STYPftPopXVEB +nfo2R7OJdtz5i4QJT1l6m5czi/PeCfq6MUidu7jPzOS65AA7McrqRYONlygkKM67xXV lPeJI9dLSiArhX7sVwCLKb2pT6FwsnROwyu+GQy9l+NkFOQL2IC/Lm5lfb7aAKe9pseU zR7wb7rs507fjEvo2rTL6cXL0Gux5FD9iy24BDrK7srzLi97hICV9VCEiXA5J041ezSy Ctjg== X-Gm-Message-State: APjAAAWoukUdoVWL9IF+v2ryZSg5QK6Cxymi1cZtPrSq2mGEVQFUO34m QwvnCOsxW/erIwQkspLG4l2tTjL0veg= X-Received: by 2002:a19:a8c8:: with SMTP id r191mr33200338lfe.161.1556561722102; Mon, 29 Apr 2019 11:15:22 -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 y29sm538325ljd.85.2019.04.29.11.15.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Apr 2019 11:15:21 -0700 (PDT) Received: by mail-lf1-f51.google.com with SMTP id w23so8610521lfc.9 for ; Mon, 29 Apr 2019 11:15:21 -0700 (PDT) X-Received: by 2002:a19:48c9:: with SMTP id v192mr32479159lfa.136.1556561234549; Mon, 29 Apr 2019 11:07:14 -0700 (PDT) MIME-Version: 1.0 References: <20190427100639.15074-1-nstange@suse.de> <20190427100639.15074-4-nstange@suse.de> <20190427102657.GF2623@hirez.programming.kicks-ass.net> <20190428133826.3e142cfd@oasis.local.home> In-Reply-To: <20190428133826.3e142cfd@oasis.local.home> From: Linus Torvalds Date: Mon, 29 Apr 2019 11:06:58 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 3/4] x86/ftrace: make ftrace_int3_handler() not to skip fops invocation To: Steven Rostedt Cc: Peter Zijlstra , 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 , Andy Lutomirski , Joerg Roedel , Linux List Kernel Mailing , live-patching@vger.kernel.org, "open list:KERNEL SELFTEST FRAMEWORK" Content-Type: multipart/mixed; boundary="0000000000007504920587af2741" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --0000000000007504920587af2741 Content-Type: text/plain; charset="UTF-8" On Sun, Apr 28, 2019 at 10:38 AM Steven Rostedt wrote: > > For optimization reasons, if there's only a single user of a function > it gets its own trampoline that sets up the call to its callback and > calls that callback directly: So this is the same issue as the static calls, and it has exactly the same solution. Which I already outlined once, and nobody wrote the code for. So here's a COMPLETELY UNTESTED patch that only works (_if_ it works) for (a) 64-bit (b) SMP but that's just because I've hardcoded the percpu segment handling. It does *not* emulate the "call" in the BP handler itself, instead if replace the %ip (the same way all the other BP handlers replace the %ip) with a code sequence that just does push %gs:bp_call_return jmp *%gs:bp_call_target after having filled in those per-cpu things. The reason they are percpu is that after the %ip has been changed, the target CPU goes its merry way, and doesn't wait for the text--poke semaphore serialization. But since we have interrupts disabled on that CPU, we know that *another* text poke won't be coming around and changing the values. THIS IS ENTIRELY UNTESTED! I've built it, and it at least seems to build, although with warnings arch/x86/kernel/alternative.o: warning: objtool: emulate_call_irqoff()+0x9: indirect jump found in RETPOLINE build arch/x86/kernel/alternative.o: warning: objtool: emulate_call_irqon()+0x8: indirect jump found in RETPOLINE build arch/x86/kernel/alternative.o: warning: objtool: emulate_call_irqoff()+0x9: sibling call from callable instruction with modified stack frame arch/x86/kernel/alternative.o: warning: objtool: emulate_call_irqon()+0x8: sibling call from callable instruction with modified stack frame that will need the appropriate "ignore this case" annotations that I didn't do. Do I expect it to work? No. I'm sure there's some silly mistake here, but the point of the patch is to show it as an example, so that it can actually be tested. With this, it should be possible (under the text rewriting lock) to do replace_call(callsite, newcallopcode, callsize, calltargettarget); to do the static rewriting of the call at "callsite" to have the new call target. And again. Untested. But doesn't need any special code in the entry path, and the concept is simple even if there are probably stupid bugs just because it's entirely untested. Oh, and did I mention that I didn't test this? Linus --0000000000007504920587af2741 Content-Type: text/x-patch; charset="US-ASCII"; name="patch.diff" Content-Disposition: attachment; filename="patch.diff" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_jv2o33gb0 IGFyY2gveDg2L2tlcm5lbC9hbHRlcm5hdGl2ZS5jIHwgNTQgKysrKysrKysrKysrKysrKysrKysr KysrKysrKysrKysrKysrKysrKy0tLQogMSBmaWxlIGNoYW5nZWQsIDUxIGluc2VydGlvbnMoKyks IDMgZGVsZXRpb25zKC0pCgpkaWZmIC0tZ2l0IGEvYXJjaC94ODYva2VybmVsL2FsdGVybmF0aXZl LmMgYi9hcmNoL3g4Ni9rZXJuZWwvYWx0ZXJuYXRpdmUuYwppbmRleCA5YTc5Yzc4MDhmOWMuLjky YjU5OTU4Y2ZmMyAxMDA2NDQKLS0tIGEvYXJjaC94ODYva2VybmVsL2FsdGVybmF0aXZlLmMKKysr IGIvYXJjaC94ODYva2VybmVsL2FsdGVybmF0aXZlLmMKQEAgLTczOSw3ICs3MzksMTEgQEAgc3Rh dGljIHZvaWQgZG9fc3lu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