Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10771067imu; Thu, 6 Dec 2018 06:34:19 -0800 (PST) X-Google-Smtp-Source: AFSGD/XBYa5j2ud3EwChxiYskehNitz/+8s1rIOiCZrRmr5lTYHhCLmaPV/51OU6UspdCniGBvBI X-Received: by 2002:a62:1212:: with SMTP id a18mr29661668pfj.217.1544106859672; Thu, 06 Dec 2018 06:34:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544106859; cv=none; d=google.com; s=arc-20160816; b=cK1e9umFqQTHwgR/UIK68+xV19lvDK4j2d6V8UOhAP0DaDWymbI8VTBY2jUHqHtJus /4S35ZW0PGgMwRArY9Jv2ca2kWixVK0xEuVYwIZGoSjggrpmizvqiQ1EhEpqKQjDkw9r D4WzexvShj1RL3ziYVf/fqLPy93m0w3wsd1dVupYb0r/p43H47s2x0FB34clRmxjNgKs LVX2jFAgo7+edJrqUm0f35hQNub2Pj6u69k7Z1pf7j8kmNrLUAMC2Mzf/VUlTLk2Yc1o 4HCzXkvHXzIC7s93Dyf9dB1hAy3zbiyoXDOyEYxJOEagC9n/BDmJ/OfrTGYE0NwOFEme ew1g== 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=8bt24wXJlB3M/lDvnWLoRBJfRvQJynIF1gj//D6t4kE=; b=moC4uwsRjiELoSU/c9zAjLcmgR43OHJHOL+rZU2UT2ybrKSTbGDvX0MbCjvoGaCv1C 8NMz25aM9CCUXlYtbpVkXUJfY2+vWh5Lx4WEVIAO2IGWr8Pm8DkvvqXlg7E4tzrW6ExM Vxbdvwi8vsOYWhXRrt9kX8G5S6Ufc2Eru67luJuBtlxzi/sm2PE/Rlk+0gVZMSfv9pis F4EVMCsWB8mh9TyzM+YubUIJ6yLqBAibjBTUJIj8qbnAmvRwrHTkCipDOgHDseEAlOZj ULwxr/4GtyDjjhZu1tOI9muz+vkUinfcriEzRRJPom09VwtkKY5ASOOCrscqfvGWYaJk rrNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RqdhxaXa; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e17si387654pgj.142.2018.12.06.06.33.31; Thu, 06 Dec 2018 06:34:19 -0800 (PST) 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=@linaro.org header.s=google header.b=RqdhxaXa; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729591AbeLFOc2 (ORCPT + 99 others); Thu, 6 Dec 2018 09:32:28 -0500 Received: from mail-yb1-f194.google.com ([209.85.219.194]:32837 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728052AbeLFOc2 (ORCPT ); Thu, 6 Dec 2018 09:32:28 -0500 Received: by mail-yb1-f194.google.com with SMTP id f125so535897ybc.0 for ; Thu, 06 Dec 2018 06:32:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8bt24wXJlB3M/lDvnWLoRBJfRvQJynIF1gj//D6t4kE=; b=RqdhxaXaklLfJhhFhrxdX9K5yq6mS2gD8V05fAbaHStZNCXxlBQj0Rba103nEt8lLG e6FNc9PVakXQAw3cGQGkqic+hVAuYUACuIYzVizlIiKfW3bOEPOxAnE1jHoa8Mqc2Wf/ 7dTcj3XHh6VeiuYOXlv+neq7XwNVb0aXT+O5I= 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=8bt24wXJlB3M/lDvnWLoRBJfRvQJynIF1gj//D6t4kE=; b=Fog6mspouQdR+/tM1vQCaClgxYJrjweAk2i9qal1Lnaz3HJvoh1Z0x5dDMxTk4naZW wDC/smtkKtmECyK7n7ghdQwau7JRNZAmtmiTNtlxsdA0L9Bx82L1Z7UGDofTVdUGHF75 YyA6nUGAKJYkO0ceLTIABnj0Y0e61OpNlH4kp99TV1/xiuNQKRoXN2Bp//AVVCoFClS0 anZFYRjE16S+1uDb4rafFR1a+lotOYIG3NX8HtMckTgDxIUrD76Don2GvWcAzJAr8Fuz o5UYiE8BAPzJ7hPrz3vFMPsCJ1W5IO7Jy0/7sYmKuQWxaJjU8I/RPMSGQTkT6eT9OSsu Kgig== X-Gm-Message-State: AA+aEWYmJNPBrwwH0tJLPJ5uF9ssabnda0XEPHwI+7tlMWGJSVUv7t3h snRjl8dIavJa2lP/Lbn4W88EPw0XlKlL21sK0WMhLw== X-Received: by 2002:a25:1e07:: with SMTP id e7mr460831ybe.195.1544106746892; Thu, 06 Dec 2018 06:32:26 -0800 (PST) MIME-Version: 1.0 References: <20181205174852.435233070@goodmis.org> <20181205183303.828422192@goodmis.org> In-Reply-To: <20181205183303.828422192@goodmis.org> From: Anders Roxell Date: Thu, 6 Dec 2018 15:32:15 +0100 Message-ID: Subject: Re: [PATCH 1/2] ftrace: Allow ftrace_replace_code() to be schedulable To: rostedt@goodmis.org Cc: Linux Kernel Mailing List , Catalin Marinas , Will Deacon , Kees Cook , Arnd Bergmann , Linux ARM , mingo@kernel.org 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 Wed, 5 Dec 2018 at 19:33, Steven Rostedt wrote: > > From: "Steven Rostedt (VMware)" > > The function ftrace_replace_code() is the ftrace engine that does the > work to modify all the nops into the calls to the function callback in > all the functions being traced. > > The generic version which is normally called from stop machine, but an > architecture can implement a non stop machine version and still use the > generic ftrace_replace_code(). When an architecture does this, > ftrace_replace_code() may be called from a schedulable context, where > it can allow the code to be preemptible, and schedule out. > > In order to allow an architecture to make ftrace_replace_code() > schedulable, a new command flag is added called: > > FTRACE_SCHEDULABLE > > Which can be or'd to the command that is passed to > ftrace_modify_all_code() that calls ftrace_replace_code() and will have > it call cond_resched() in the loop that modifies the nops into the > calls to the ftrace trampolines. > > Link: http://lkml.kernel.org/r/20181204192903.8193-1-anders.roxell@linaro.org > > Reported-by: Anders Roxell > Signed-off-by: Steven Rostedt (VMware) Tested-by: Anders Roxell Cheers, Anders > --- > include/linux/ftrace.h | 1 + > kernel/trace/ftrace.c | 19 ++++++++++++++++--- > 2 files changed, 17 insertions(+), 3 deletions(-) > > diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h > index dd16e8218db3..c281b16baef9 100644 > --- a/include/linux/ftrace.h > +++ b/include/linux/ftrace.h > @@ -389,6 +389,7 @@ enum { > FTRACE_UPDATE_TRACE_FUNC = (1 << 2), > FTRACE_START_FUNC_RET = (1 << 3), > FTRACE_STOP_FUNC_RET = (1 << 4), > + FTRACE_SCHEDULABLE = (1 << 5), > }; > > /* > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c > index 77734451cb05..74fdcacba514 100644 > --- a/kernel/trace/ftrace.c > +++ b/kernel/trace/ftrace.c > @@ -77,6 +77,11 @@ > #define ASSIGN_OPS_HASH(opsname, val) > #endif > > +enum { > + FTRACE_MODIFY_ENABLE_FL = (1 << 0), > + FTRACE_MODIFY_SCHEDULABLE_FL = (1 << 1), > +}; > + > static struct ftrace_ops ftrace_list_end __read_mostly = { > .func = ftrace_stub, > .flags = FTRACE_OPS_FL_RECURSION_SAFE | FTRACE_OPS_FL_STUB, > @@ -2415,10 +2420,12 @@ __ftrace_replace_code(struct dyn_ftrace *rec, int enable) > return -1; /* unknow ftrace bug */ > } > > -void __weak ftrace_replace_code(int enable) > +void __weak ftrace_replace_code(int mod_flags) > { > struct dyn_ftrace *rec; > struct ftrace_page *pg; > + int enable = mod_flags & FTRACE_MODIFY_ENABLE_FL; > + int schedulable = mod_flags & FTRACE_MODIFY_SCHEDULABLE_FL; > int failed; > > if (unlikely(ftrace_disabled)) > @@ -2435,6 +2442,8 @@ void __weak ftrace_replace_code(int enable) > /* Stop processing */ > return; > } > + if (schedulable) > + cond_resched(); > } while_for_each_ftrace_rec(); > } > > @@ -2548,8 +2557,12 @@ int __weak ftrace_arch_code_modify_post_process(void) > void ftrace_modify_all_code(int command) > { > int update = command & FTRACE_UPDATE_TRACE_FUNC; > + int mod_flags = 0; > int err = 0; > > + if (command & FTRACE_SCHEDULABLE) > + mod_flags = FTRACE_MODIFY_SCHEDULABLE_FL; > + > /* > * If the ftrace_caller calls a ftrace_ops func directly, > * we need to make sure that it only traces functions it > @@ -2567,9 +2580,9 @@ void ftrace_modify_all_code(int command) > } > > if (command & FTRACE_UPDATE_CALLS) > - ftrace_replace_code(1); > + ftrace_replace_code(mod_flags | FTRACE_MODIFY_ENABLE_FL); > else if (command & FTRACE_DISABLE_CALLS) > - ftrace_replace_code(0); > + ftrace_replace_code(mod_flags); > > if (update && ftrace_trace_function != ftrace_ops_list_func) { > function_trace_op = set_function_trace_op; > -- > 2.19.1 > >