Bug 368419 - Perf Events ioctls not implemented
Summary: Perf Events ioctls not implemented
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: 3.12 SVN
Platform: Compiled Sources Linux
: NOR wishlist
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-07 19:41 UTC by Keno Fischer
Modified: 2016-10-19 16:08 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch to add valgrind support for perf events ioctls. (4.06 KB, patch)
2016-09-07 19:42 UTC, Keno Fischer
Details
Updated patch. (2.92 KB, patch)
2016-09-26 19:16 UTC, Keno Fischer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Keno Fischer 2016-09-07 19:41:02 UTC
The various ioctls supported by the fd returned from perf_event_open(2) are not supported by valgrind.

Reproducible: Always
Comment 1 Keno Fischer 2016-09-07 19:42:47 UTC
Created attachment 100976 [details]
Patch to add valgrind support for perf events ioctls.

Here's a patched I whipped up that seems to work fine. This is my first patch to valgrind, please let me know if I should do anything else.
Comment 2 Julian Seward 2016-09-15 10:25:17 UTC
Keno, thank you for the patch.   It looks OK, apart from this fragment

+   case VKI_PERF_EVENT_IOC_SET_FILTER: {
+      char *filter = (char *)ARG3;
+      PRE_MEM_READ("ioctl(VKI_PERF_EVENT_IOC_SET_FILTER)",
+        (Addr)ARG3, VG_(strnlen)(filter, VKI_PAGE_SIZE)+1);
+      break;
+   }

If I interpret this correctly, ARG3 is a C style zero-terminated string that the syscall
reads.  Is that correct?

If so, there's already a macro for that: PRE_MEM_RASCIIZ.  I think you want
something like  PRE_MEM_RASCIIZ(ioctl(VKI_PERF_EVENT_IOC_SET_FILTER).filter", ARG3).

Can you redo the patch and re-test it?  Thanks.
Comment 3 Keno Fischer 2016-09-15 16:39:18 UTC
> If I interpret this correctly, ARG3 is a C style zero-terminated string that the syscall
> reads.  Is that correct?

Essentially yes, though with the caveat that if there's no NUL after PAGE_SIZE-1 bytes, it'll still accept that as far as I know (as a PAGE_SIZE-1 sized string), since it uses strndup_user(str, PAGE_SIZE) on the kernel side of things.
Comment 4 Mark Wielaard 2016-09-22 15:06:24 UTC
(In reply to Keno Fischer from comment #3)
> > If I interpret this correctly, ARG3 is a C style zero-terminated string that the syscall
> > reads.  Is that correct?
> 
> Essentially yes, though with the caveat that if there's no NUL after
> PAGE_SIZE-1 bytes, it'll still accept that as far as I know (as a
> PAGE_SIZE-1 sized string), since it uses strndup_user(str, PAGE_SIZE) on the
> kernel side of things.

That seems a funny corner case that I cannot imagine anybody relies on (the caller would have to explicitly not pass a zero terminated string larger than PAGE_SIZE, which is different on different arches). If someone does I think a warning from valgrind seems somewhat justified. So just using PRE_MEM_RASCIIZ here should be fine.
Comment 5 Keno Fischer 2016-09-26 19:16:10 UTC
Created attachment 101305 [details]
Updated patch.
Comment 6 Julian Seward 2016-10-19 16:08:42 UTC
Committed, r16077.  Thanks for the patch.