Re: [PATCH] perf: enum overflow in uapi/linux/perf_event.h

From: Peter Zijlstra
Date: Fri Sep 07 2018 - 10:24:02 EST


On Fri, Sep 07, 2018 at 04:15:33PM +0200, Christophe LEROY wrote:

> Ah yes, it seems that GCC is happy. So sparse should be fixed instead ?

Ideally, yes.

> Anyway, is it really correct to put this constant inside that enum, after
> PERF_SAMPLE_MAX ?

It is a bit of a hack, agreed. What we do is use the top bit of that
word (u64) for some internal state. By placing it there (after MAX) we
ensure it is not available for userspace (trying to set it will return
in -EINVAL) and by keeping it in the enum we know that bit is
unavailable for future use.

I have a patch queued that puts a little comment on that:

https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/commit/?h=perf/urgent&id=34cad593c9ea350a1811ab718e64b36e5cde870c

(url is not stable, as I regenerate that git tree from quilt every so
often, but it should probably last the day).