Commit d2f5bbbc authored by Jiri Benc's avatar Jiri Benc Committed by Daniel Borkmann

selftests: bpf: standardize to static __always_inline

The progs for bpf selftests use several different notations to force
function inlining. Standardize to what most of them use,
static __always_inline.
Suggested-by: default avatarSong Liu <liu.song.a23@gmail.com>
Signed-off-by: default avatarJiri Benc <jbenc@redhat.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent 71634d7f
...@@ -75,8 +75,7 @@ typedef struct { ...@@ -75,8 +75,7 @@ typedef struct {
void* co_name; // PyCodeObject.co_name void* co_name; // PyCodeObject.co_name
} FrameData; } FrameData;
static inline __attribute__((__always_inline__)) void* static __always_inline void *get_thread_state(void *tls_base, PidData *pidData)
get_thread_state(void* tls_base, PidData* pidData)
{ {
void* thread_state; void* thread_state;
int key; int key;
...@@ -87,8 +86,8 @@ get_thread_state(void* tls_base, PidData* pidData) ...@@ -87,8 +86,8 @@ get_thread_state(void* tls_base, PidData* pidData)
return thread_state; return thread_state;
} }
static inline __attribute__((__always_inline__)) bool static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData,
get_frame_data(void* frame_ptr, PidData* pidData, FrameData* frame, Symbol* symbol) FrameData *frame, Symbol *symbol)
{ {
// read data from PyFrameObject // read data from PyFrameObject
bpf_probe_read(&frame->f_back, bpf_probe_read(&frame->f_back,
...@@ -161,7 +160,7 @@ struct bpf_elf_map SEC("maps") stackmap = { ...@@ -161,7 +160,7 @@ struct bpf_elf_map SEC("maps") stackmap = {
.max_elem = 1000, .max_elem = 1000,
}; };
static inline __attribute__((__always_inline__)) int __on_event(struct pt_regs *ctx) static __always_inline int __on_event(struct pt_regs *ctx)
{ {
uint64_t pid_tgid = bpf_get_current_pid_tgid(); uint64_t pid_tgid = bpf_get_current_pid_tgid();
pid_t pid = (pid_t)(pid_tgid >> 32); pid_t pid = (pid_t)(pid_tgid >> 32);
......
...@@ -266,8 +266,8 @@ struct tls_index { ...@@ -266,8 +266,8 @@ struct tls_index {
uint64_t offset; uint64_t offset;
}; };
static inline __attribute__((always_inline)) static __always_inline void *calc_location(struct strobe_value_loc *loc,
void *calc_location(struct strobe_value_loc *loc, void *tls_base) void *tls_base)
{ {
/* /*
* tls_mode value is: * tls_mode value is:
...@@ -327,8 +327,8 @@ void *calc_location(struct strobe_value_loc *loc, void *tls_base) ...@@ -327,8 +327,8 @@ void *calc_location(struct strobe_value_loc *loc, void *tls_base)
: NULL; : NULL;
} }
static inline __attribute__((always_inline)) static __always_inline void read_int_var(struct strobemeta_cfg *cfg,
void read_int_var(struct strobemeta_cfg *cfg, size_t idx, void *tls_base, size_t idx, void *tls_base,
struct strobe_value_generic *value, struct strobe_value_generic *value,
struct strobemeta_payload *data) struct strobemeta_payload *data)
{ {
...@@ -342,10 +342,11 @@ void read_int_var(struct strobemeta_cfg *cfg, size_t idx, void *tls_base, ...@@ -342,10 +342,11 @@ void read_int_var(struct strobemeta_cfg *cfg, size_t idx, void *tls_base,
data->int_vals_set_mask |= (1 << idx); data->int_vals_set_mask |= (1 << idx);
} }
static inline __attribute__((always_inline)) static __always_inline uint64_t read_str_var(struct strobemeta_cfg *cfg,
uint64_t read_str_var(struct strobemeta_cfg* cfg, size_t idx, void *tls_base, size_t idx, void *tls_base,
struct strobe_value_generic *value, struct strobe_value_generic *value,
struct strobemeta_payload *data, void *payload) struct strobemeta_payload *data,
void *payload)
{ {
void *location; void *location;
uint32_t len; uint32_t len;
...@@ -371,10 +372,11 @@ uint64_t read_str_var(struct strobemeta_cfg* cfg, size_t idx, void *tls_base, ...@@ -371,10 +372,11 @@ uint64_t read_str_var(struct strobemeta_cfg* cfg, size_t idx, void *tls_base,
return len; return len;
} }
static inline __attribute__((always_inline)) static __always_inline void *read_map_var(struct strobemeta_cfg *cfg,
void *read_map_var(struct strobemeta_cfg *cfg, size_t idx, void *tls_base, size_t idx, void *tls_base,
struct strobe_value_generic *value, struct strobe_value_generic *value,
struct strobemeta_payload* data, void *payload) struct strobemeta_payload *data,
void *payload)
{ {
struct strobe_map_descr* descr = &data->map_descrs[idx]; struct strobe_map_descr* descr = &data->map_descrs[idx];
struct strobe_map_raw map; struct strobe_map_raw map;
...@@ -435,9 +437,9 @@ void *read_map_var(struct strobemeta_cfg *cfg, size_t idx, void *tls_base, ...@@ -435,9 +437,9 @@ void *read_map_var(struct strobemeta_cfg *cfg, size_t idx, void *tls_base,
* read_strobe_meta returns NULL, if no metadata was read; otherwise returns * read_strobe_meta returns NULL, if no metadata was read; otherwise returns
* pointer to *right after* payload ends * pointer to *right after* payload ends
*/ */
static inline __attribute__((always_inline)) static __always_inline void *read_strobe_meta(struct task_struct *task,
void *read_strobe_meta(struct task_struct* task, struct strobemeta_payload *data)
struct strobemeta_payload* data) { {
pid_t pid = bpf_get_current_pid_tgid() >> 32; pid_t pid = bpf_get_current_pid_tgid() >> 32;
struct strobe_value_generic value = {0}; struct strobe_value_generic value = {0};
struct strobemeta_cfg *cfg; struct strobemeta_cfg *cfg;
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2019 Facebook // Copyright (c) 2019 Facebook
#include <features.h>
typedef unsigned int u32; typedef unsigned int u32;
static __attribute__((always_inline)) u32 rol32(u32 word, unsigned int shift) static __always_inline u32 rol32(u32 word, unsigned int shift)
{ {
return (word << shift) | (word >> ((-shift) & 31)); return (word << shift) | (word >> ((-shift) & 31));
} }
......
...@@ -54,7 +54,7 @@ struct sr6_tlv_t { ...@@ -54,7 +54,7 @@ struct sr6_tlv_t {
unsigned char value[0]; unsigned char value[0];
} BPF_PACKET_HEADER; } BPF_PACKET_HEADER;
static __attribute__((always_inline)) struct ip6_srh_t *get_srh(struct __sk_buff *skb) static __always_inline struct ip6_srh_t *get_srh(struct __sk_buff *skb)
{ {
void *cursor, *data_end; void *cursor, *data_end;
struct ip6_srh_t *srh; struct ip6_srh_t *srh;
...@@ -88,9 +88,9 @@ static __attribute__((always_inline)) struct ip6_srh_t *get_srh(struct __sk_buff ...@@ -88,9 +88,9 @@ static __attribute__((always_inline)) struct ip6_srh_t *get_srh(struct __sk_buff
return srh; return srh;
} }
static __attribute__((always_inline)) static __always_inline int update_tlv_pad(struct __sk_buff *skb,
int update_tlv_pad(struct __sk_buff *skb, uint32_t new_pad, uint32_t new_pad, uint32_t old_pad,
uint32_t old_pad, uint32_t pad_off) uint32_t pad_off)
{ {
int err; int err;
...@@ -118,9 +118,10 @@ int update_tlv_pad(struct __sk_buff *skb, uint32_t new_pad, ...@@ -118,9 +118,10 @@ int update_tlv_pad(struct __sk_buff *skb, uint32_t new_pad,
return 0; return 0;
} }
static __attribute__((always_inline)) static __always_inline int is_valid_tlv_boundary(struct __sk_buff *skb,
int is_valid_tlv_boundary(struct __sk_buff *skb, struct ip6_srh_t *srh, struct ip6_srh_t *srh,
uint32_t *tlv_off, uint32_t *pad_size, uint32_t *tlv_off,
uint32_t *pad_size,
uint32_t *pad_off) uint32_t *pad_off)
{ {
uint32_t srh_off, cur_off; uint32_t srh_off, cur_off;
...@@ -177,8 +178,8 @@ int is_valid_tlv_boundary(struct __sk_buff *skb, struct ip6_srh_t *srh, ...@@ -177,8 +178,8 @@ int is_valid_tlv_boundary(struct __sk_buff *skb, struct ip6_srh_t *srh,
return 0; return 0;
} }
static __attribute__((always_inline)) static __always_inline int add_tlv(struct __sk_buff *skb,
int add_tlv(struct __sk_buff *skb, struct ip6_srh_t *srh, uint32_t tlv_off, struct ip6_srh_t *srh, uint32_t tlv_off,
struct sr6_tlv_t *itlv, uint8_t tlv_size) struct sr6_tlv_t *itlv, uint8_t tlv_size)
{ {
uint32_t srh_off = (char *)srh - (char *)(long)skb->data; uint32_t srh_off = (char *)srh - (char *)(long)skb->data;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Copyright (c) 2019 Facebook // Copyright (c) 2019 Facebook
#include <linux/bpf.h> #include <linux/bpf.h>
#include "bpf_helpers.h" #include "bpf_helpers.h"
#define ATTR __attribute__((always_inline)) #define ATTR __always_inline
#include "test_jhash.h" #include "test_jhash.h"
SEC("scale90_inline") SEC("scale90_inline")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment