Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2959584ybd; Fri, 28 Jun 2019 00:02:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZ/cGKh/oISPRQnBdtl5+PWYAsbq5lztJzorFQ1K7RC+A+rdJ1h+NVPwznIRSNRAiiv7nb X-Received: by 2002:a17:902:8a87:: with SMTP id p7mr3137360plo.124.1561705336934; Fri, 28 Jun 2019 00:02:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561705336; cv=none; d=google.com; s=arc-20160816; b=K0NfB9xgPHcZVQtL0WDsHSxjoJUgUbWnaXbQ/PBcOo1batM+RBcCIPl+mBPpkWz1Eh cHmGixaTbru+LkYgPMP6uSEMKEfXKeQcfflesx4Qwfy8GUlFrOrVJ9AGC+EFg7z3fDGe 0dsc5II6vZ+hx+bZw9zodWAe8a2wBdDMWKlqaFX3dqKi0zWZZx5gkZY5LjyKzntyOorm zYHkdiSstfVmfm4Wo8Ii73DqbWEx9/5VT5nzq5T32ZyXQIBq31yS22wqkAtjYc57Udzt ui9WqBL5tpCCweBDk9fGYMI9DK5+wgCQNaMK57W223uEGAYeK/nTkVVXJWai5m/SLttI z8yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:message-id :user-agent:mime-version:in-reply-to:references:cc:to:subject:from :date:dkim-signature; bh=Oej4Il0Mb4EFBZMtlZZn5pX80rvSmbWkyqLWJge1d2k=; b=Lr7bASTirfs8olcb3FB9hiO5DGNNkGvAD1Oh+19vG/I5NLEe5/eZj4kY5SvJsatZ5M mYjiLPsDs5lkzmNjpqU6qDbX1tdHQri/yxm2ocGwfV7AUARzIUqDCbkiFWHGOpkmw655 fMugv70uAf3KcsOEzr2sjv3sZJT+1DBf0pnWAXDXdCeL045jaszS5skszJGHZ2otJnCe 3Uo7JTvYspr54SSBKtxJFn8sw+ssuWah2xNw9yDErByuE5GfgfZrjzMQ9lgOjWhUvwED JJKy4f4Fr/moBPk31kmFMIba+gc2PsdhwxcKBKYAxg/EOTLEAB9xeN0UZcBgt14bAdQB 4b7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L0nBNKPl; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l5si1388700pgp.16.2019.06.28.00.01.59; Fri, 28 Jun 2019 00:02:16 -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=@gmail.com header.s=20161025 header.b=L0nBNKPl; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727312AbfF1HBy (ORCPT + 99 others); Fri, 28 Jun 2019 03:01:54 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:45865 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727282AbfF1HBx (ORCPT ); Fri, 28 Jun 2019 03:01:53 -0400 Received: by mail-pl1-f196.google.com with SMTP id bi6so2696353plb.12 for ; Fri, 28 Jun 2019 00:01:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:subject:to:cc:references:in-reply-to:mime-version :user-agent:message-id:content-transfer-encoding; bh=Oej4Il0Mb4EFBZMtlZZn5pX80rvSmbWkyqLWJge1d2k=; b=L0nBNKPlIlQRaPgZW8NPCGfKolxLNRUS50MpuU1bGXBabvPyJ3Mz5hRD/k76+mno5m SH8fndCLLAjnbIYegvNVs6uFK1m2r+C9h4WprcRraHhb5YOcDOEQurasElg0F7Mjl1Ll BOMwQsGJ3h6xvjSbhZ3X0S1kQSzZORXEDmlwVhBUFV66u6zzFwJboR8NkmswnzWZB6gX Uyo36sqMhSEcKDYu98NdsvvA8+XO3ORJZyLOE8GokAt6AvGeUxer4bknEjBm0X6YvOxm N05VWKTbRnCL48tEMSifhCNYv3MlPeyD0Gq6fpg8QpUKb8KklPhBRoELPDN1mx9TGfpL uVOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:references:in-reply-to :mime-version:user-agent:message-id:content-transfer-encoding; bh=Oej4Il0Mb4EFBZMtlZZn5pX80rvSmbWkyqLWJge1d2k=; b=WOGGZ3pGg6fbe3Q9xjrMRYhkrqyexeuNv6n4eKNvBpvhMIthU6PBhStp0T9gP1jnA1 vF7vEUEIZXws5pB5Yxc0PUqHahRpqrIT/N28BAmTMyaKVKIUGipvyoPr1bz2SQTL/scB 99kLxtIMpP0p1VCXbGfXGkd4wI5hqqrqkZwNgH21V1gH9JpItMf1FQaoLMIVSCNjd8nb Gyjrlxk9PNTz3QYod3PH4NePUOXyHR9uTrEr3yrrN1mbpaqfeUQcL4iaJIcig1JygP7K isfb2Wk2imLxPZ8xa+WaptNOLOjxSqtVFHafDwxVtqbfZJrXrZWrbKJe4kM1LNV0IhKH 19nA== X-Gm-Message-State: APjAAAWLja6Pr22jQ5C3WUf1Hr8+L6F1YINzkrZHlPi4png9yBJK/R8E wmDHT0gBqkwi369Gi0IfXEc= X-Received: by 2002:a17:902:28e9:: with SMTP id f96mr9289889plb.114.1561705312662; Fri, 28 Jun 2019 00:01:52 -0700 (PDT) Received: from localhost ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id b29sm2333297pfr.159.2019.06.28.00.01.51 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 00:01:52 -0700 (PDT) Date: Fri, 28 Jun 2019 17:01:59 +1000 From: Nicholas Piggin Subject: Re: [PATCH v2 4/7] powerpc/ftrace: Additionally nop out the preceding mflr with -mprofile-kernel To: Masami Hiramatsu , Ingo Molnar , Michael Ellerman , "Naveen N. Rao" , Steven Rostedt Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org References: <841386feda429a1f0d4b7442c3ede1ed91466f92.1561634177.git.naveen.n.rao@linux.vnet.ibm.com> In-Reply-To: <841386feda429a1f0d4b7442c3ede1ed91466f92.1561634177.git.naveen.n.rao@linux.vnet.ibm.com> MIME-Version: 1.0 User-Agent: astroid/0.14.0 (https://github.com/astroidmail/astroid) Message-Id: <1561704544.gobmve95sq.astroid@bobo.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Naveen N. Rao's on June 27, 2019 9:23 pm: > With -mprofile-kernel, gcc emits 'mflr r0', followed by 'bl _mcount' to > enable function tracing and profiling. So far, with dynamic ftrace, we > used to only patch out the branch to _mcount(). However, mflr is > executed by the branch unit that can only execute one per cycle on > POWER9 and shared with branches, so it would be nice to avoid it where > possible. >=20 > We cannot simply nop out the mflr either. When enabling function > tracing, there can be a race if tracing is enabled when some thread was > interrupted after executing a nop'ed out mflr. In this case, the thread > would execute the now-patched-in branch to _mcount() without having > executed the preceding mflr. >=20 > To solve this, we now enable function tracing in 2 steps: patch in the > mflr instruction, use 'smp_call_function(isync); > synchronize_rcu_tasks()' to ensure all existing threads make progress, > and then patch in the branch to _mcount(). We override > ftrace_replace_code() with a powerpc64 variant for this purpose. I think this seems like a reasonable sequence that will work on our hardware, although technically outside the ISA as specified maybe we should add a feature bit or at least comment for it. It would be kind of nice to not put this stuff directly in the=20 ftrace code, but rather in the function patching subsystem. I think it would be too expensive to just make a runtime variant of patch_instruction that always does the SMP isync, but possibly a patch_instruction_sync() or something that we say ensures no processor is running code that has been patched away. Thanks, Nick =