From: Song Liu <songliubraving@fb.com>
To: Petr Mladek <pmladek@suse.com>
Cc: kernel test robot <lkp@intel.com>, Song Liu <song@kernel.org>,
bpf <bpf@vger.kernel.org>, lkml <linux-kernel@vger.kernel.org>,
"live-patching@vger.kernel.org" <live-patching@vger.kernel.org>,
"kbuild-all@lists.01.org" <kbuild-all@lists.01.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <Kernel-team@fb.com>,
"jolsa@kernel.org" <jolsa@kernel.org>,
"rostedt@goodmis.org" <rostedt@goodmis.org>
Subject: Re: [PATCH v4 bpf-next 2/4] ftrace: allow IPMODIFY and DIRECT ops on the same function
Date: Mon, 18 Jul 2022 16:59:51 +0000 [thread overview]
Message-ID: <9DAB0710-7D60-46AC-8A2F-ED4B8A1A4BC0@fb.com> (raw)
In-Reply-To: <YtVd4FKOcEmGfubm@alley>
> On Jul 18, 2022, at 6:19 AM, Petr Mladek <pmladek@suse.com> wrote:
>
> On Mon 2022-07-18 15:42:25, kernel test robot wrote:
>> Hi Song,
>>
>> I love your patch! Perhaps something to improve:
>>
>> [auto build test WARNING on bpf-next/master]
>>
>> url: https://github.com/intel-lab-lkp/linux/commits/Song-Liu/ftrace-host-klp-and-bpf-trampoline-together/20220718-135652
>> base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
>> config: x86_64-randconfig-a004 (https://download.01.org/0day-ci/archive/20220718/202207181552.VuKfz9zg-lkp@intel.com/config )
>> compiler: gcc-11 (Debian 11.3.0-3) 11.3.0
>> reproduce (this is a W=1 build):
>> # https://github.com/intel-lab-lkp/linux/commit/9ef1ec8cb818d8ca70887c8c123f2d579384a6c6
>> git remote add linux-review https://github.com/intel-lab-lkp/linux
>> git fetch --no-tags linux-review Song-Liu/ftrace-host-klp-and-bpf-trampoline-together/20220718-135652
>> git checkout 9ef1ec8cb818d8ca70887c8c123f2d579384a6c6
>> # save the config file
>> mkdir build_dir && cp config build_dir/.config
>> make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash kernel/trace/
>>
>> If you fix the issue, kindly add following tag where applicable
>> Reported-by: kernel test robot <lkp@intel.com>
>>
>> All warnings (new ones prefixed by >>):
>>
>> kernel/trace/ftrace.c: In function 'register_ftrace_function':
>>>> kernel/trace/ftrace.c:8197:14: warning: variable 'direct_mutex_locked' set but not used [-Wunused-but-set-variable]
>> 8197 | bool direct_mutex_locked = false;
>> | ^~~~~~~~~~~~~~~~~~~
>>
>>
>> vim +/direct_mutex_locked +8197 kernel/trace/ftrace.c
>>
>> 8182
>> 8183 /**
>> 8184 * register_ftrace_function - register a function for profiling
>> 8185 * @ops: ops structure that holds the function for profiling.
>> 8186 *
>> 8187 * Register a function to be called by all functions in the
>> 8188 * kernel.
>> 8189 *
>> 8190 * Note: @ops->func and all the functions it calls must be labeled
>> 8191 * with "notrace", otherwise it will go into a
>> 8192 * recursive loop.
>> 8193 */
>> 8194 int register_ftrace_function(struct ftrace_ops *ops)
>> 8195 __releases(&direct_mutex)
>> 8196 {
>>> 8197 bool direct_mutex_locked = false;
>> 8198 int ret;
>> 8199
>> 8200 ftrace_ops_init(ops);
>> 8201
>> 8202 ret = prepare_direct_functions_for_ipmodify(ops);
>> 8203 if (ret < 0)
>> 8204 return ret;
>> 8205 else if (ret == 1)
>> 8206 direct_mutex_locked = true;
>
> Honestly, this is another horrible trick. Would it be possible to
> call prepare_direct_functions_for_ipmodify() with direct_mutex
> already taken?
>
> I mean something like:
>
> mutex_lock(&direct_mutex);
>
> ret = prepare_direct_functions_for_ipmodify(ops);
> if (ret)
> goto out:
>
> mutex_lock(&ftrace_lock);
> ret = ftrace_startup(ops, 0);
> mutex_unlock(&ftrace_lock);
>
> out:
> mutex_unlock(&direct_mutex);
> return ret;
Yeah, we can actually do something like this. We can also move the
ops->flags & FTRACE_OPS_FL_IPMODIFY check to
register_ftrace_function(), so we only lock direct_mutex when when
it is necessary.
>
>
>> 8208 mutex_lock(&ftrace_lock);
>> 8209
>> 8210 ret = ftrace_startup(ops, 0);
>> 8211
>> 8212 mutex_unlock(&ftrace_lock);
>> 8213
>
> Would be possible to handle tr->mutex the same way to avoid
> the trylock? I mean to take it in advance before direct_mutex?
Unfortunately, we cannot do this. ftrace code cannot look up
bpf trampolines without locking direct_mutex.
Thanks,
Song
next prev parent reply other threads:[~2022-07-18 17:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-18 5:54 [PATCH v4 bpf-next 0/4] ftrace: host klp and bpf trampoline together Song Liu
2022-07-18 5:54 ` [PATCH v4 bpf-next 1/4] ftrace: add modify_ftrace_direct_multi_nolock Song Liu
2022-07-19 17:57 ` Steven Rostedt
2022-07-18 5:54 ` [PATCH v4 bpf-next 2/4] ftrace: allow IPMODIFY and DIRECT ops on the same function Song Liu
2022-07-18 7:42 ` kernel test robot
2022-07-18 13:19 ` Petr Mladek
2022-07-18 16:59 ` Song Liu [this message]
2022-07-19 18:32 ` Steven Rostedt
2022-07-19 22:28 ` Song Liu
2022-07-19 18:28 ` Steven Rostedt
2022-07-19 18:39 ` Steven Rostedt
2022-07-19 22:57 ` Song Liu
2022-07-19 23:04 ` Steven Rostedt
2022-07-19 23:24 ` Song Liu
2022-07-19 23:27 ` Steven Rostedt
2022-07-18 5:54 ` [PATCH v4 bpf-next 3/4] bpf, x64: Allow to use caller address from stack Song Liu
2022-07-18 5:54 ` [PATCH v4 bpf-next 4/4] bpf: support bpf_trampoline on functions with IPMODIFY (e.g. livepatch) Song Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9DAB0710-7D60-46AC-8A2F-ED4B8A1A4BC0@fb.com \
--to=songliubraving@fb.com \
--cc=Kernel-team@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jolsa@kernel.org \
--cc=kbuild-all@lists.01.org \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=lkp@intel.com \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=song@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®