lkml.org 
[lkml]   [2018]   [Jan]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [RFC PATCH] asm/generic: introduce if_nospec and nospec_barrier
    > and the *implementation* might be architecture-specific, but one
    > particular implementation would be something like simply
    >
    > #define array_access(base, idx, max) ({ \
    > union { typeof(base[0]) _val; unsigned long _bit; } __u;\
    > unsigned long _i = (idx); \
    > unsigned long _m = (max); \
    > unsigned long _mask = _i < _m ? ~0 : 0; \
    > OPTIMIZER_HIDE_VAR(_mask); \
    > __u._val = base[_i & _mask]; \
    > __u._bit &= _mask; \
    > __u._val; })
    >
    > (Ok, the above is not exhaustively tested, but you get the idea, and
    > gcc doesn't seem to mess it up *too* badly).

    How do you ensure that the CPU doesn't speculate j < _m ? ~0 : 0 pick the
    wrong mask and then reference base[] ?

    It's a nice idea but I think we'd need to run it past the various CPU
    vendors especially before it was implemented as a generic solution.
    Anding with a constant works because the constant doesn't get speculated
    and nor does the and with a constant, but you've got a whole additional
    conditional path in your macro.

    Alan

    \
     
     \ /
      Last update: 2018-01-04 23:57    [W:4.230 / U:0.020 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site