Skip to content

Commit

Permalink
Skip dereferences inside bpf_probe_reads calls (iovisor#1824)
Browse files Browse the repository at this point in the history
* Skip all dereferences inside bpf_probe_read calls

If the user decides to rely on a manual call to bpf_probe_read, we
don't try to rewrite its last argument.  This is needed as the
rewriter starts to recognize and rewrite more and more dereferences.

* tools: fix dereferences following 1a765a1
  • Loading branch information
pchaigno authored and yonghong-song committed Jun 14, 2018
1 parent 37f7fef commit f86f7e8
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
5 changes: 1 addition & 4 deletions src/cc/frontends/clang/b_frontend_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,7 @@ bool ProbeVisitor::VisitCallExpr(CallExpr *Call) {
if (VarDecl *V = dyn_cast<VarDecl>(Call->getCalleeDecl())) {
if (V->getName() == "bpf_probe_read" && Call->getNumArgs() >= 3) {
const Expr *E = Call->getArg(2)->IgnoreParenCasts();
if (const UnaryOperator *UnaryExpr = dyn_cast<UnaryOperator>(E)) {
if (UnaryExpr->getOpcode() == UO_AddrOf)
whitelist_.insert(E);
}
whitelist_.insert(E);
return true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion tools/biosnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@
data.len = req->__data_len;
data.sector = req->__sector;
bpf_probe_read(&data.name, sizeof(data.name), valp->name);
struct gendisk *rq_disk = req->rq_disk;
bpf_probe_read(&data.disk_name, sizeof(data.disk_name),
req->rq_disk->disk_name);
rq_disk->disk_name);
}
/*
Expand Down
6 changes: 3 additions & 3 deletions tools/filelife.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@
delta = (bpf_ktime_get_ns() - *tsp) / 1000000;
birth.delete(&dentry);
if (dentry->d_name.len == 0)
struct qstr d_name = dentry->d_name;
if (d_name.len == 0)
return 0;
if (bpf_get_current_comm(&data.comm, sizeof(data.comm)) == 0) {
data.pid = pid;
data.delta = delta;
bpf_probe_read(&data.fname, sizeof(data.fname),
(void *)dentry->d_name.name);
bpf_probe_read(&data.fname, sizeof(data.fname), d_name.name);
}
events.perf_submit(ctx, &data, sizeof(data));
Expand Down
5 changes: 3 additions & 2 deletions tools/fileslower.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@
val.sz = count;
val.ts = bpf_ktime_get_ns();
val.name_len = de->d_name.len;
bpf_probe_read(&val.name, sizeof(val.name), (void *)de->d_name.name);
struct qstr d_name = de->d_name;
val.name_len = d_name.len;
bpf_probe_read(&val.name, sizeof(val.name), d_name.name);
bpf_get_current_comm(&val.comm, sizeof(val.comm));
entryinfo.update(&pid, &val);
Expand Down
7 changes: 4 additions & 3 deletions tools/filetop.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,15 @@ def signal_ignore(signal, frame):
// skip I/O lacking a filename
struct dentry *de = file->f_path.dentry;
int mode = file->f_inode->i_mode;
if (de->d_name.len == 0 || TYPE_FILTER)
struct qstr d_name = de->d_name;
if (d_name.len == 0 || TYPE_FILTER)
return 0;
// store counts and sizes by pid & file
struct info_t info = {.pid = pid};
bpf_get_current_comm(&info.comm, sizeof(info.comm));
info.name_len = de->d_name.len;
bpf_probe_read(&info.name, sizeof(info.name), (void *)de->d_name.name);
info.name_len = d_name.len;
bpf_probe_read(&info.name, sizeof(info.name), d_name.name);
if (S_ISREG(mode)) {
info.type = 'R';
} else if (S_ISSOCK(mode)) {
Expand Down
6 changes: 3 additions & 3 deletions tools/mdflush.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
* and maintenance burden.
*/
#ifdef bio_dev
bpf_probe_read(&data.disk, sizeof(data.disk), bio->bi_disk->disk_name);
struct gendisk *bi_disk = bio->bi_disk;
#else
bpf_probe_read(&data.disk, sizeof(data.disk),
bio->bi_bdev->bd_disk->disk_name);
struct gendisk *bi_disk = bio->bi_bdev->bd_disk;
#endif
bpf_probe_read(&data.disk, sizeof(data.disk), bi_disk->disk_name);
events.perf_submit(ctx, &data, sizeof(data));
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion tools/slabratetop.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def signal_ignore(signal, frame):
int kprobe__kmem_cache_alloc(struct pt_regs *ctx, struct kmem_cache *cachep)
{
struct info_t info = {};
bpf_probe_read(&info.name, sizeof(info.name), (void *)cachep->name);
const char *name = cachep->name;
bpf_probe_read(&info.name, sizeof(info.name), name);
struct val_t *valp, zero = {};
valp = counts.lookup_or_init(&info, &zero);
Expand Down

0 comments on commit f86f7e8

Please sign in to comment.