{"action":"created","issue":{"url":"https://api.github.com/repos/iovisor/bcc/issues/209","labels_url":"https://api.github.com/repos/iovisor/bcc/issues/209/labels{/name}","comments_url":"https://api.github.com/repos/iovisor/bcc/issues/209/comments","events_url":"https://api.github.com/repos/iovisor/bcc/issues/209/events","html_url":"https://github.com/iovisor/bcc/issues/209","id":106185548,"number":209,"title":"invalid reads: type=inv expected=fp","user":{"login":"brendangregg","id":1101211,"avatar_url":"https://avatars.githubusercontent.com/u/1101211?v=3","gravatar_id":"","url":"https://api.github.com/users/brendangregg","html_url":"https://github.com/brendangregg","followers_url":"https://api.github.com/users/brendangregg/followers","following_url":"https://api.github.com/users/brendangregg/following{/other_user}","gists_url":"https://api.github.com/users/brendangregg/gists{/gist_id}","starred_url":"https://api.github.com/users/brendangregg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendangregg/subscriptions","organizations_url":"https://api.github.com/users/brendangregg/orgs","repos_url":"https://api.github.com/users/brendangregg/repos","events_url":"https://api.github.com/users/brendangregg/events{/privacy}","received_events_url":"https://api.github.com/users/brendangregg/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-09-12T21:23:25Z","updated_at":"2015-09-13T21:25:50Z","closed_at":"2015-09-13T20:44:46Z","body":"I can't figure out some errors like the following:\r\n\r\n```Shell\r\nbpf: Permission denied\r\n0: (79) r6 = *(u64 *)(r1 +112)\r\n1: (85) call 14\r\n2: (63) *(u32 *)(r10 -12) = r0\r\n3: (15) if r6 == 0x0 goto pc+55\r\n R0=inv R6=inv R10=fp\r\n4: (b7) r7 = 0\r\n5: (7b) *(u64 *)(r10 -24) = r7\r\n6: (7b) *(u64 *)(r10 -32) = r7\r\n7: (07) r6 += 16\r\n8: (bf) r1 = r10\r\n9: (07) r1 += -32\r\n10: (b7) r2 = 16\r\n11: (bf) r3 = r6\r\n12: (85) call 4\r\n13: (79) r1 = *(u64 *)(r10 -24)\r\n14: (15) if r1 == 0x0 goto pc+44\r\n R0=inv R1=inv R6=inv R7=imm0 R10=fp\r\n15: (7b) *(u64 *)(r10 -40) = r7\r\n16: (7b) *(u64 *)(r10 -48) = r7\r\n17: (bf) r1 = r10\r\n18: (07) r1 += -48\r\n19: (b7) r2 = 16\r\n20: (bf) r3 = r6\r\n21: (85) call 4\r\n22: (79) r1 = *(u64 *)(r10 -48)\r\n23: (15) if r1 == 0x0 goto pc+35\r\n R0=inv R1=inv R6=inv R7=imm0 R10=fp\r\n24: (b7) r7 = 0\r\n25: (7b) *(u64 *)(r10 -56) = r7\r\n26: (7b) *(u64 *)(r10 -64) = r7\r\n27: (7b) *(u64 *)(r10 -72) = r7\r\n28: (bf) r1 = r10\r\n29: (07) r1 += -72\r\n30: (b7) r2 = 16\r\n31: (bf) r3 = r6\r\n32: (85) call 4\r\n33: (79) r6 = *(u64 *)(r10 -64)\r\n34: (07) r6 += 56\r\n35: (bf) r1 = r10\r\n36: (07) r1 += -56\r\n37: (b7) r2 = 8\r\n38: (bf) r3 = r6\r\n39: (85) call 4\r\n40: (18) r1 = 0x93c8960\r\n42: (bf) r2 = r10\r\n43: (07) r2 += -12\r\n44: (bf) r3 = r6\r\n45: (b7) r4 = 0\r\n46: (85) call 2\r\nR3 type=inv expected=fp\r\n\r\nTraceback (most recent call last):\r\n  File \"./vfsslower\", line 83, in <module>\r\n    b.attach_kprobe(event=\"vfs_read\", fn_name=\"trace_entry\")\r\n  File \"/usr/lib/python2.7/dist-packages/bcc/__init__.py\", line 498, in attach_kprobe\r\n    fn = self.load_func(fn_name, BPF.KPROBE)\r\n  File \"/usr/lib/python2.7/dist-packages/bcc/__init__.py\", line 388, in load_func\r\n    raise Exception(\"Failed to load BPF program %s\" % func_name)\r\nException: Failed to load BPF program trace_entry\r\n```\r\n\r\nWhat actually is \"type=inv expected=fp\"?\r\n\r\nHere's a test program, that in this state works:\r\n\r\n```Python\r\n#!/usr/bin/python\r\n#\r\n# vfsslower\tTrace file system read/writes (via VFS) slower than a threshold.\r\n#\t\tFor Linux, uses BCC, eBPF.\r\n#\r\n# In development. Incomplete. DO NOT USE.\r\n#\r\n# Copyright (c) 2015 Brendan Gregg.\r\n# Licensed under the Apache License, Version 2.0 (the \"License\")\r\n#\r\n# 12-Sep-2015\tBrendan Gregg\tCreated this.\r\n\r\nfrom __future__ import print_function\r\nfrom bcc import BPF\r\n\r\nREQ_WRITE = 1\t\t# from include/linux/blk_types.h\r\n\r\n# load BPF program\r\nbpf_text = \"\"\"\r\n#include <uapi/linux/ptrace.h>\r\n#include <linux/blkdev.h>\r\n#include <linux/mount.h>\r\n\r\nBPF_HASH(start, u32);\r\nBPF_HASH(filebypid, u32, char *);\r\n\r\nint trace_entry(struct pt_regs *ctx, struct file *file)\r\n{\r\n\tu64 ts;\r\n\tu32 pid = bpf_get_current_pid_tgid();\r\n\r\n\r\n\tif (file != NULL && file->f_path.dentry != NULL &&\r\n\t    file->f_path.mnt != NULL) {\r\n// XXX can't get this to work:\r\n//\t\tstruct vfsmount *mnt = file->f_path.mnt;\r\n//\t\tif (!(mnt->mnt_flags & MNT_NODEV)) {\r\n//\t\t\treturn 0;\r\n//\t\t}\r\n\r\n\t\tvoid *name = 0;\r\n\t\tstruct dentry *dent = file->f_path.dentry;\r\n\r\n\t\t// get filename via d_iname\r\n\t\tbpf_probe_read(&name, sizeof(name), dent->d_iname);\r\n// XXX can't get this to work:\r\n//\t\tfilebypid.update(&pid, (char **)&dent->d_iname);\r\n\r\n// debug only:\r\n\t\tbpf_trace_printk(\"read d_iname %s\\\\n\", &dent->d_iname);\r\n\t}\r\n\r\n\tts = bpf_ktime_get_ns();\r\n\tstart.update(&pid, &ts);\r\n\treturn 0;\r\n}\r\n\r\nint trace_return(struct pt_regs *ctx)\r\n{\r\n\tu64 *tsp, delta;\r\n\tu32 pid = bpf_get_current_pid_tgid();\r\n\r\n\tpid = bpf_get_current_pid_tgid();\r\n\ttsp = start.lookup(&pid);\r\n\r\n\tif (tsp != 0) {\r\n\t\tdelta = bpf_ktime_get_ns() - *tsp;\r\n\t\tif (delta > MIN_LATENCY_NS) {\r\n\t\t\tchar *file = (char *)filebypid.lookup(&pid);\r\n\t\t\tbpf_trace_printk(\"%d us %s\\\\n\", delta / 1000, file);\r\n\t\t\tif (file != NULL) {\r\n\t\t\t\tfilebypid.delete(&pid);\r\n\t\t\t}\r\n\t\t}\r\n\t\tstart.delete(&pid);\r\n\t}\r\n\r\n\treturn 0;\r\n}\r\n\"\"\"\r\nbpf_text = bpf_text.replace('MIN_LATENCY_NS', '100000')\r\nb = BPF(text=bpf_text)\r\nb.attach_kprobe(event=\"vfs_read\", fn_name=\"trace_entry\")\r\nb.attach_kretprobe(event=\"vfs_read\", fn_name=\"trace_return\")\r\n\r\nb.trace_print()\r\n```\r\n\r\nThere's a couple of blocks, that when uncommented, break it.\r\n\r\nIt's pretty noisy to run, since it prints tty vfs_read()s from ssh (hence trying to filter it based on MNT_NODEV, which I don't know yet if it works). So I'd been testing it like this:\r\n\r\n```Shell\r\nwindow1# ./vfsslower > out\r\nwindow2# echo 1 > /proc/sys/vm/drop_caches; cksum /usr/bin/*\r\nwindow1# grep cksum out\r\n```"},"comment":{"url":"https://api.github.com/repos/iovisor/bcc/issues/comments/139918929","html_url":"https://github.com/iovisor/bcc/issues/209#issuecomment-139918929","issue_url":"https://api.github.com/repos/iovisor/bcc/issues/209","id":139918929,"user":{"login":"brendangregg","id":1101211,"avatar_url":"https://avatars.githubusercontent.com/u/1101211?v=3","gravatar_id":"","url":"https://api.github.com/users/brendangregg","html_url":"https://github.com/brendangregg","followers_url":"https://api.github.com/users/brendangregg/followers","following_url":"https://api.github.com/users/brendangregg/following{/other_user}","gists_url":"https://api.github.com/users/brendangregg/gists{/gist_id}","starred_url":"https://api.github.com/users/brendangregg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendangregg/subscriptions","organizations_url":"https://api.github.com/users/brendangregg/orgs","repos_url":"https://api.github.com/users/brendangregg/repos","events_url":"https://api.github.com/users/brendangregg/events{/privacy}","received_events_url":"https://api.github.com/users/brendangregg/received_events","type":"User","site_admin":false},"created_at":"2015-09-13T21:25:50Z","updated_at":"2015-09-13T21:25:50Z","body":"FWIW, I can't match on MNT_NODEV because FSes don't respect it:\r\n\r\n```Shell\r\n# mount\r\n/dev/xvda on / type ext4 (rw,noatime,barrier=0)\r\nproc on /proc type proc (rw,noexec,nosuid,nodev)\r\nsysfs on /sys type sysfs (rw,noexec,nosuid,nodev)\r\nnone on /sys/fs/cgroup type tmpfs (rw)\r\nnone on /sys/fs/fuse/connections type fusectl (rw)\r\nnone on /sys/kernel/debug type debugfs (rw)\r\nnone on /sys/kernel/security type securityfs (rw)\r\nudev on /dev type devtmpfs (rw,mode=0755)\r\ndevpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)\r\ntmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)\r\nnone on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)\r\ntmpfs on /run/shm type tmpfs (rw,nosuid,nodev,size=250M)\r\nnone on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)\r\nnone on /sys/fs/pstore type pstore (rw)\r\n/dev/md0 on /mnt type xfs (rw,noatime)\r\nsystemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd)\r\n```\r\n\r\nMany things (I think) should have nosuid, but don't."}}