Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3146578yba; Mon, 6 May 2019 18:12:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqw3p0NKXHOlcuBs7ttl2Mjj7s/grXvSbPCnTSzXmpPN9St6Tugdam7CnibTdicVmfObtDHn X-Received: by 2002:a17:902:5a2:: with SMTP id f31mr36256330plf.119.1557191578252; Mon, 06 May 2019 18:12:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557191578; cv=none; d=google.com; s=arc-20160816; b=CeR3Dei/f7ETSIIjj+jOUPQBbBMgiJQvAJjbw1yiB39VFhGHzJGyVWhtInYSRGCsP1 SNo73LR6yscLxs49mrPckFS2EOlnpM++6tiGx0IkDMhnY9rORGe6PHOfioh8f+nOmMLi du8rvN/4cuTOl8OZ62JOkESU5OBEuyF+EuwupqPkqqzr8SE9Abn1zJdKSJJFG4UVJ/0K u491Tutu4eRNHGDZC8NQt5h/Drsq989Jvyx/LNYZv0NKQmvdyYfWD4FbdOGGcI+DABQ4 gW8IQKuiFVzndsnUiZUKSE+mKPjDQh29EfWSSXji1wJyxUU1l/Vp/JAo6Gbu8Deo61U5 IYNA== 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=dsyI73dXroFmIqVe+jpEPNjDuWdsj9KSbzEVBNIEYrs=; b=LsO289IVHfwGzRZMzU3L2y3DUyo/1exDI9vVrhH8y7onOgloEZRdPCGq/KgeYKkEZA y3xK1gTsL5OQNlrPG6hjUFoLfEpewJkUdoJXYnRudgk0ImSLAwnCtJZgZbRFEXHTlzK3 Y+cMuw0GOcVWQd4LqqoPmT+yIkhV+E58nURf5mxxaockpKoKxgz7+2WYmG9XzbjhoZI8 Ftwu4nYCpeAp4viFGXMiNYQ2Oa8HDSX0IBs01JFDfG21UacNmbpFE1s2CnQ9phG4HRPh 0uxuCZJxpqM/gML3In2i5FjN7Le3rG96N1jOktnxrhqj/f4XNPhhjnHXk25CATzTFvdc qleg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=dQElmRAK; 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 u74si3067845pgc.346.2019.05.06.18.12.40; Mon, 06 May 2019 18:12:58 -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=dQElmRAK; 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 S1726541AbfEGBLp (ORCPT + 99 others); Mon, 6 May 2019 21:11:45 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:34682 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726073AbfEGBLp (ORCPT ); Mon, 6 May 2019 21:11:45 -0400 Received: by mail-lf1-f68.google.com with SMTP id v18so8304436lfi.1 for ; Mon, 06 May 2019 18: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=dsyI73dXroFmIqVe+jpEPNjDuWdsj9KSbzEVBNIEYrs=; b=dQElmRAKArIck7yA9+RfVsOvJW3DDcGCwatkGx9cmG4psAifaTuQoFxV4JgZzLUHcA rXzE0x3JnhgeqIaLirr0ycOXAmNEUaNkAXj1VvSRU4MGQjxMtL45XwDPT8r4iFT9XcpB 9yTyrUgNoF6ya1p1+4Zxq6b5yvVO+gRHpXFFs= 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=dsyI73dXroFmIqVe+jpEPNjDuWdsj9KSbzEVBNIEYrs=; b=pQC6tuFRnnlHetIfTF6sQ8/IOYax56Lp/ub5xZJ7Ub/mKSRrH1H+23HLkBrNPObfSN IlhuBoUoNsREM67Etj7+n2HxTTNNWybEs8coCJVZyysUmGxgYhvPwHRP1zJjMmQ52Zlg lTykHe5AOHoSMiEQ6Ir6mlenavekr5X8ma0CxON8Icdhq+xnnkNIMRQYsto5Vd+ef00S cEa/z+2fee5drxDoQBbGlpBVc8qM6LOJp/L7ReC8JR5ply4d+ByN6qF+veyHTnOmXh3o OT83qcBwFwhDLnkmwlhzYpKrjGqwcDqUZ+O3iUlyi/yf2cag32uikgjWS3917A//zRzF hlAA== X-Gm-Message-State: APjAAAXgur2fIiJQKanTKHGiGWHdtENFRLy7mbnQH/2oxlQ7NfNWuTXk iVoiZwsGgBqR10vAucQgF33z69uHApY= X-Received: by 2002:a19:f705:: with SMTP id z5mr4608930lfe.164.1557191502110; Mon, 06 May 2019 18:11:42 -0700 (PDT) Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com. [209.85.208.182]) by smtp.gmail.com with ESMTPSA id q29sm2823495ljc.8.2019.05.06.18.11.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 18:11:41 -0700 (PDT) Received: by mail-lj1-f182.google.com with SMTP id r76so1659708lja.12 for ; Mon, 06 May 2019 18:11:41 -0700 (PDT) X-Received: by 2002:a2e:3e0e:: with SMTP id l14mr15262932lja.125.1557191189183; Mon, 06 May 2019 18:06:29 -0700 (PDT) MIME-Version: 1.0 References: <20190502181811.GY2623@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> <20190506201014.484e7b65@oasis.local.home> In-Reply-To: <20190506201014.484e7b65@oasis.local.home> From: Linus Torvalds Date: Mon, 6 May 2019 18:06: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 , 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 5:10 PM Steven Rostedt wrote: > > But the CPU that was rewriting instructions does a run_sync() after > removing the int3: > > static void run_sync(void) > { > int enable_irqs; > > /* No need to sync if there's only one CPU */ > if (num_online_cpus() == 1) > return; > > enable_irqs = irqs_disabled(); > > /* We may be called with interrupts disabled (on bootup). */ > if (enable_irqs) > local_irq_enable(); > on_each_cpu(do_sync_core, NULL, 1); > if (enable_irqs) > local_irq_disable(); > } > > Which sends an IPI to all CPUs to make sure they no longer see the int3. Duh. I have been looking back and forth in that file, and I was mixing ftrace_modify_code_direct() (which only does a local sync) with ftrace_modify_code() (which does run_sync()). The dangers of moving around by searching for function names. That file is a maze of several functions that are very similarly named and do slightly different things. But yes, I was looking at the "direct" sequence. > I think you are missing the run_sync() which is the heavy hammer to > make sure all CPUs are in sync. And this is done at each stage: > > add int3 > run_sync(); > update call cite outside of int3 > run_sync() > remove int3 > run_sync() > > HPA said that the last run_sync() isn't needed, but I kept it because I > wanted to make sure. Looks like your analysis shows that it is needed. Absolutely. I think we could get rid of it, but yes, to then avoid the race we'd need to be a lot more clever. Yeah, with the three run_sunc() things, the races I thought it had can't happen. Linus