Skip to content
Snippets Groups Projects
  • Nadav Har'El's avatar
    8add1b91
    Warn about incorrect use of percpu<> / PERCPU(..). · 8add1b91
    Nadav Har'El authored
    
    This patch causes incorrect usage of percpu<>/PERCPU() to cause
    compilation errors instead of silent runtime corruptions.
    
    Thanks to Dmitry for first noticing this issue in xen_intr.cc (see his
    separate patch), and to Avi for suggesting a compile-time fix.
    
    With this patch:
    
    1. Using percpu<...> to *define* a per-cpu variable fails compilation.
       Instead, PERCPU(...) must be used for the definition, which is important
       because it places the variable in the ".percpu" section.
    
    2. If a *declaration* is needed additionally (e.g., for a static class
       member), percpu<...> must be used, not PERCPU().
       Trying to use PERCPU() for declaration will cause a compilation error.
    
    3. PERCPU() only works on statically-constructed objects - global variables,
       static function-variables and static class-members. Trying to use it
       on a dynamically-constructed object - stack variable, class field,
       or operator new - will cause a compilation error.
    
    With this patch, the bug in xen_intr.cc would have been caught at
    compile time.
    
    Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
    Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
    8add1b91
    History
    Warn about incorrect use of percpu<> / PERCPU(..).
    Nadav Har'El authored
    
    This patch causes incorrect usage of percpu<>/PERCPU() to cause
    compilation errors instead of silent runtime corruptions.
    
    Thanks to Dmitry for first noticing this issue in xen_intr.cc (see his
    separate patch), and to Avi for suggesting a compile-time fix.
    
    With this patch:
    
    1. Using percpu<...> to *define* a per-cpu variable fails compilation.
       Instead, PERCPU(...) must be used for the definition, which is important
       because it places the variable in the ".percpu" section.
    
    2. If a *declaration* is needed additionally (e.g., for a static class
       member), percpu<...> must be used, not PERCPU().
       Trying to use PERCPU() for declaration will cause a compilation error.
    
    3. PERCPU() only works on statically-constructed objects - global variables,
       static function-variables and static class-members. Trying to use it
       on a dynamically-constructed object - stack variable, class field,
       or operator new - will cause a compilation error.
    
    With this patch, the bug in xen_intr.cc would have been caught at
    compile time.
    
    Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
    Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>