Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3971448yba; Mon, 29 Apr 2019 11:30:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqxmGOv+Ijd4YtRPLPcgeHgUFrthXDDTfSBdSeJJBMZzvR3X4KLPSFUKjXJMXezaHXeFiZGE X-Received: by 2002:a17:902:8f88:: with SMTP id z8mr57324924plo.54.1556562659580; Mon, 29 Apr 2019 11:30:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556562659; cv=none; d=google.com; s=arc-20160816; b=jFScEv6thczxepp0hhHi1PFfix84d1mUusz8x+/QDaczL+pJB8DAOdt1OtLQvlaseh LnFokY3dembABPmDzJ3dcgOjtDVfeEJ82l6pberZs52C1zEpparspkHKAr7CZ5LFaCvB vCjaTQzikF1chmFucJdzI3xBamEdzBJVFRAYuO7K83ytOwKX9Cns/Hs7A2m3/6ulb+XS zp3iwYsM3F5ALfdffcv+gByxccZEfKu1u9zQYt2/VzfVuYS9x7uSAmvqH65CGOmsaq7m gj81wjzdvXucp2EXMltPm4S/XMdaxgpNNh1XdoeuRyxFj4JsxeDHzuKqemmI+24knXW9 fYAA== 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=liktUAQ84meAwYxARrOaB57hFmqHknre6y7TLap/pyw=; b=KANen3majFvLzNqVnKIL7UTgyk8tqwS2qeCvrxQWP/lsK5C8dWKVuF3DfniMg0l2rq 3Uc9eRc4izVytXw4k/eBQjt0eJXJXV0dDNoT67lxdYoYKRhn/x7PGrfvrSOslOaRFR8a JTSBg6mdQwcCHhbACCZQa+DvduwuytNWWWU/orxPgHofMNg0gV6+0YQxOhzDF09XxVzq 5JyIg00DgWWP73Mia2wQegXJjoBfZ13o3P9r2W4B4ZhASH5CZzsO03zT7fgxdHo403b3 1GuJsD4f8lhw4bg6AozlvvzprpYde+HrprhP3X6CMWkirShq2BNMarE2JTQnmsLqrYQk NVZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=TlX1vlaN; 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 a3si33751042pfc.276.2019.04.29.11.30.43; Mon, 29 Apr 2019 11:30:59 -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=TlX1vlaN; 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 S1729031AbfD2S30 (ORCPT + 99 others); Mon, 29 Apr 2019 14:29:26 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:35221 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728962AbfD2S30 (ORCPT ); Mon, 29 Apr 2019 14:29:26 -0400 Received: by mail-lj1-f196.google.com with SMTP id z26so10335649ljj.2 for ; Mon, 29 Apr 2019 11:29:24 -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=liktUAQ84meAwYxARrOaB57hFmqHknre6y7TLap/pyw=; b=TlX1vlaNRutHcVL0zAHMii8+n9hCbC2fIKsPMUSq4g7TknK8mmi/6eY9keIz02Ws6a 0sxXLjiXKqUe5nVD8Hq9h6XVk1mWLMo7lAqkO0QgXrp0M7JguoB/2YMziFqvFKujU3CI Oo2bSTLegqzhOQTgHMmIMbR2g7S9IuZHsXaQU= 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=liktUAQ84meAwYxARrOaB57hFmqHknre6y7TLap/pyw=; b=BKQkHtlkRw/m6jtICj4m9ajZl3TSKIhkm1sEFoMCuE1g0P+3t7+qJMPW9+Qpy/hpzm DLl5z20xYrH+gNX56GwCwC4KPPmZzktzARRPltdTha1Mp0A8Fe/hX6tq4ebXjTCzoVZc nCLPTcw1x1xmPNdsXHb6OUKqH+Nd7W308cRezm0dY9lHWsc28jIXO8415qkvXkqnCDb/ s+12GgxuAF3u/2O9LkHsgr9oKd9b1pr64T2/Pir4Vx+KLfrWyXF7z0XqtJV1Rpd2COsi N/rid6QKkHNNvcdcrG1v6ReWNkLa5vGRfHdeNspGjP0tVDud1/s7trFK0LAUZ+0VDRhW hPGw== X-Gm-Message-State: APjAAAV1AGpJYoYrrtAasfJz+R1HEVpnp/Q3DY7figdxZ2q1GDq8pPMx x/V6qaZfcboud7w0iEstA/jYHbKVfdE= X-Received: by 2002:a2e:8693:: with SMTP id l19mr32985699lji.47.1556562563537; Mon, 29 Apr 2019 11:29:23 -0700 (PDT) Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com. [209.85.208.169]) by smtp.gmail.com with ESMTPSA id h6sm7368659lfp.1.2019.04.29.11.29.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Apr 2019 11:29:23 -0700 (PDT) Received: by mail-lj1-f169.google.com with SMTP id m18so5688225lje.12 for ; Mon, 29 Apr 2019 11:29:23 -0700 (PDT) X-Received: by 2002:a2e:9ac8:: with SMTP id p8mr30224042ljj.79.1556562187132; Mon, 29 Apr 2019 11:23:07 -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: From: Linus Torvalds Date: Mon, 29 Apr 2019 11:22:51 -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: 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, Apr 29, 2019 at 11:06 AM Linus Torvalds wrote: > > > 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. Note that if you read the patch, you'll see that my explanation glossed over the "what if an interrupt happens" part. Which is handled by having two handlers, one for "interrupts were already disabled" and one for "interrupts were enabled, so I disabled them before entering the handler". The second handler does the same push/jmp sequence, but has a "sti" before the jmp. Because of the one-instruction sti shadow, interrupts won't actually be enabled until after the jmp instruction has completed, and thus the "push/jmp" is atomic wrt regular interrupts. It's not safe wrt NMI, of course, but since NMI won't be rescheduling, and since any SMP IPI won't be punching through that sequence anyway, it's still atomic wrt _another_ text_poke() attempt coming in and re-using the bp_call_return/tyarget slots. So yeah, it's not "one-liner" trivial, but it's not like it's complicated either, and it actually matches the existing "call this code to emulate the replaced instruction". So I'd much rather have a couple of tens of lines of code here that still acts pretty much exactly like all the other rewriting does, rather than play subtle games with the entry stack frame. Finally: there might be other situations where you want to have this kind of "pseudo-atomic" replacement sequence, so I think while it's a hack specific to emulating a "call" instruction, I don't think it is conceptually limited to just that case. Linus