From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753221AbbCWRlY (ORCPT ); Mon, 23 Mar 2015 13:41:24 -0400 Received: from mail-qg0-f42.google.com ([209.85.192.42]:34466 "EHLO mail-qg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752214AbbCWRlV (ORCPT ); Mon, 23 Mar 2015 13:41:21 -0400 Message-ID: <55105041.5090400@plumgrid.com> Date: Mon, 23 Mar 2015 10:41:21 -0700 From: Alexei Starovoitov User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Ingo Molnar CC: Steven Rostedt , Namhyung Kim , Arnaldo Carvalho de Melo , Jiri Olsa , Masami Hiramatsu , "David S. Miller" , Daniel Borkmann , Peter Zijlstra , linux-api@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v9 tip 8/9] samples: bpf: IO latency analysis (iosnoop/heatmap) References: <1426894210-27441-1-git-send-email-ast@plumgrid.com> <1426894210-27441-9-git-send-email-ast@plumgrid.com> <20150323074028.GE25184@gmail.com> In-Reply-To: <20150323074028.GE25184@gmail.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/23/15 12:40 AM, Ingo Molnar wrote: > > * Alexei Starovoitov wrote: > >> BPF C program attaches to blk_mq_start_request/blk_update_request kprobe events >> to calculate IO latency. > > ... > >> +/* kprobe is NOT a stable ABI >> + * This bpf+kprobe example can stop working any time. >> + */ >> +SEC("kprobe/blk_mq_start_request") >> +int bpf_prog1(struct pt_regs *ctx) >> +{ >> + long rq = ctx->di; >> + u64 val = bpf_ktime_get_ns(); >> + >> + bpf_map_update_elem(&my_map, &rq, &val, BPF_ANY); >> + return 0; >> +} > > So just to make sure the original BPF instrumentation model is still > upheld: no matter in what way the kernel changes, neither the kprobe, > nor the BPF program can ever crash or corrupt the kernel, assuming the > kprobes, perf and BPF subsystem has no bugs, correct? yes. of course. That was always #1 requirement. > So 'stops working' here means that the instrumentation data might not > be reliable if kernel internal interfaces change - but it won't ever > make the kernel unreliable in any fashion. Right? yes. of course. The only situations where it can 'stop working': - in-kernel blk_mq_start_request function is renamed, so kprobe cannot find it and cannot attach. - arguments to blk_mq_start_request change. Then ctx->di can be meaningless and using it as key into map is useless. - whole logic of blk_mq_start_request/blk_update_request pair changes. then this sample code won't be measuring any useful io latency. In all cases kernel will never crash (barring bugs in bpf, kprobe subsystems).