Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1025960ybt; Fri, 19 Jun 2020 22:03:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzb6nLkU5z/lDKoxluhRn7vIS1PnnFMa9Y8uqWosSX2GN0xkGuuARHAy5LCs/RLvnKmgkWe X-Received: by 2002:a50:8186:: with SMTP id 6mr109282ede.45.1592629423506; Fri, 19 Jun 2020 22:03:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592629423; cv=none; d=google.com; s=arc-20160816; b=WX8Hvvyuoo3cKC8IntDIoe8eiv6vFUygaToGNzrZ19IM2qkNTV246TGlqgZYOm74xC qmn+1v9PvqgYYppvPijWlDEKY5dfW6QuFBKQkio9wfXTkTbN1g/QK77zoK/f4fZL0kkg Bb72X8l60gHIVES4riGDpDciM2LbllpJZ0ADfApJmMNeulYj/YY81+3d3fS4luCIBGba TPud7HOxx0MrWb0u5tzkqNMOcLLgpxDHrErAMca+jwSvChb8GAC3QSd27NEjD9CHdoVz f1NMXuz54arPhdwfJuAWcG1JvtUQvbIwkQqA/2XpTGcZ5r7cy1Z5662Tg/d0n2I43hh3 YsIQ== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=MMo2gYRLQpMRfoUpGtM4P6F7Roc2r8eqp/45Y9DiCZA=; b=Wf6gPUBRe2XgJK7RuuC98+ysZTo6fZ79iSjab7C8thq7oTkOAVIq4z5CNtBTxiieT2 bpfygFbzbmMKiwsvgq9P2WK3G8BpteNOn4v0vEx+SB9NhDIcVJ2Z3gTLJohtaGprnRtc Wx4MT39M4cDEPf7hT2Vvw5dQ2BbnKY+DcMZkmGNr5RQvduvhbQnP16HLHyPrnm4+abEf Ni98rt2WNOlG+VE3e4Nd1/KeB4sx9+ZiEDmabZ7IHkVf9H/VfDUJgHWg8L8oe4pnQq1s T6GzB+1l/gXZNOMgB/Qi28y1wAWFgN9dCc+lN2TCTGhlDL2qnjhppOB5IxiUO1QMGq96 7HvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk14si5010492edb.0.2020.06.19.22.03.21; Fri, 19 Jun 2020 22:03:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731165AbgFTA7s (ORCPT + 99 others); Fri, 19 Jun 2020 20:59:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:52878 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730293AbgFTA7s (ORCPT ); Fri, 19 Jun 2020 20:59:48 -0400 Received: from oasis.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A794D22B4D; Sat, 20 Jun 2020 00:59:46 +0000 (UTC) Date: Fri, 19 Jun 2020 20:59:44 -0400 From: Steven Rostedt To: Ming Lei Cc: Masami Hiramatsu , Ming Lei , "Naveen N. Rao" , Anil S Keshavamurthy , Linux Kernel Mailing List , "David S. Miller" , linux-block Subject: Re: kprobe: __blkdev_put probe is missed Message-ID: <20200619205944.4c9bb076@oasis.local.home> In-Reply-To: <20200619232820.GE353853@T590> References: <20200618125438.GA191266@T590> <20200618225602.3f2cca3f0ed48427fc0a483b@kernel.org> <20200618231901.GA196099@T590> <20200619141239.56f6dda0976453b790190ff7@kernel.org> <20200619072859.GA205278@T590> <20200619081954.3d72a252@oasis.local.home> <20200619133240.GA351476@T590> <20200620003509.9521053fbd384f4f5d23408f@kernel.org> <20200619232820.GE353853@T590> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 20 Jun 2020 07:28:20 +0800 Ming Lei wrote: > Thanks for your investigation. > > Some trace tools can just trace on function entry, such as bcc, and some > user script always trace on function entry. > > I guess the issue should belong to kprobe implementation: The issue is that kprobes is to dynamically add trace events into an already compiled kernel. I'm guessing you would get the same result from ftrace's function tracer. That's because the compiler has no idea about what or where you intend to add these dynamically created trace events (that's basically the point of kprobes). But if you add static events (and this includes trace_printk()), the compiler knows about them, because they exist at compile time, and will make sure they execute the number of times the code shows it. But if you don't have these events at compile time, the compiler is free to modify the code in such a way it doesn't make sense if you add a probe at run time. gdb suffers the same problem on user space debugging if you let the compiler aggressively optimize the code. If you step through highly optimized user space code with gdb, the position jumps all over the place. This is basically the same effect. > > 1) __blkdev_put() is capable of being kprobed, so from user view, the > probe on entry of __blkdev_put() should be triggered > > 2) from implementation view, I understand exception should be trapped > on the entry of __blkdev_put(), looks it isn't done. But it is done! But the compiler removed the second call and basically just inlined it. So that entry no longer exists. When you added a "trace_printk()" in there, the compiler is not allowed to skip that trace call. But because there's nothing in here to tell the compiler that it can't just remove the second call (which it did, and the kprobe is just showing you what the compiler did!) then there's nothing kprobes can do about it. > > Correct me if the above is wrong, and is it possible to fix it in kprobe? No. -- Steve