@@ -5862,7 +5862,7 @@ BPF_CALL_2(bpf_lua_dataref, struct xdp_buff *, ctx, int, offset) {
58625862 if (offset + ctx -> data < ctx -> data_end ) {
58635863 int data_ref ;
58645864
5865- data_ref = ldata_newref (ctx -> L , ctx -> data + offset ,
5865+ data_ref = ldata_newref (ctx -> xdplua -> L , ctx -> data + offset ,
58665866 ctx -> data_end - ctx -> data - offset );
58675867 return data_ref ;
58685868 }
@@ -5880,7 +5880,7 @@ static const struct bpf_func_proto bpf_lua_dataref_proto = {
58805880};
58815881
58825882BPF_CALL_2 (bpf_lua_dataunref , struct xdp_buff * , ctx , int , data_ref ) {
5883- ldata_unref (ctx -> L , data_ref );
5883+ ldata_unref (ctx -> xdplua -> L , data_ref );
58845884 return 0 ;
58855885}
58865886
@@ -5895,16 +5895,16 @@ static const struct bpf_func_proto bpf_lua_dataunref_proto = {
58955895
58965896BPF_CALL_4 (bpf_lua_pcall , struct xdp_buff * , ctx , char * , funcname ,
58975897 int , num_args , int , num_rets ) {
5898- if (lua_getglobal (ctx -> L , funcname ) != LUA_TFUNCTION ) {
5898+ if (lua_getglobal (ctx -> xdplua -> L , funcname ) != LUA_TFUNCTION ) {
58995899 pr_err ("function %s not found\n" , funcname );
5900- lua_pop (ctx -> L , num_args );
5900+ lua_pop (ctx -> xdplua -> L , num_args );
59015901 return 0 ;
59025902 }
59035903
5904- lua_insert (ctx -> L , 1 );
5905- if (lua_pcall (ctx -> L , num_args , num_rets , 0 )) {
5906- pr_err ("%s\n" , lua_tostring (ctx -> L , -1 ));
5907- lua_pop (ctx -> L , 1 );
5904+ lua_insert (ctx -> xdplua -> L , 1 );
5905+ if (lua_pcall (ctx -> xdplua -> L , num_args , num_rets , 0 )) {
5906+ pr_err ("%s\n" , lua_tostring (ctx -> xdplua -> L , -1 ));
5907+ lua_pop (ctx -> xdplua -> L , 1 );
59085908 return 0 ;
59095909 }
59105910 return num_rets ;
@@ -5922,7 +5922,7 @@ static const struct bpf_func_proto bpf_lua_pcall_proto = {
59225922};
59235923
59245924BPF_CALL_2 (bpf_lua_pop , struct xdp_buff * , ctx , int , index ) {
5925- lua_pop (ctx -> L , index );
5925+ lua_pop (ctx -> xdplua -> L , index );
59265926 return 0 ;
59275927}
59285928
@@ -5936,7 +5936,7 @@ static const struct bpf_func_proto bpf_lua_pop_proto = {
59365936};
59375937
59385938BPF_CALL_2 (bpf_lua_pushinteger , struct xdp_buff * , ctx , int , num ) {
5939- lua_pushinteger (ctx -> L , num );
5939+ lua_pushinteger (ctx -> xdplua -> L , num );
59405940 return 0 ;
59415941}
59425942
@@ -5950,7 +5950,7 @@ static const struct bpf_func_proto bpf_lua_pushinteger_proto = {
59505950};
59515951
59525952BPF_CALL_2 (bpf_lua_pushlightuserdata , struct xdp_buff * , ctx , void * , ptr ) {
5953- lua_pushlightuserdata (ctx -> L , ptr );
5953+ lua_pushlightuserdata (ctx -> xdplua -> L , ptr );
59545954 return 0 ;
59555955}
59565956
@@ -5964,12 +5964,12 @@ static const struct bpf_func_proto bpf_lua_pushlightuserdata_proto = {
59645964};
59655965
59665966BPF_CALL_2 (bpf_lua_pushmap , struct xdp_buff * , ctx , struct bpf_map * , map ) {
5967- lua_pushlightuserdata (ctx -> L , map );
5967+ lua_pushlightuserdata (ctx -> xdplua -> L , map );
59685968 return 0 ;
59695969}
59705970
59715971BPF_CALL_3 (bpf_lua_pushlstring , struct xdp_buff * , ctx , const char * , str , size_t , len ) {
5972- lua_pushlstring (ctx -> L , str , len );
5972+ lua_pushlstring (ctx -> xdplua -> L , str , len );
59735973 return 0 ;
59745974}
59755975
@@ -5993,7 +5993,7 @@ static const struct bpf_func_proto bpf_lua_pushmap_proto = {
59935993};
59945994
59955995BPF_CALL_1 (bpf_lua_pushskb , struct xdp_buff * , ctx ) {
5996- lua_pushlightuserdata (ctx -> L , ctx -> skb );
5996+ lua_pushlightuserdata (ctx -> xdplua -> L , ctx -> skb );
59975997 return 0 ;
59985998}
59995999
@@ -6006,7 +6006,7 @@ static const struct bpf_func_proto bpf_lua_pushskb_proto = {
60066006};
60076007
60086008BPF_CALL_2 (bpf_lua_pushstring , struct xdp_buff * , ctx , const char * , str ) {
6009- lua_pushstring (ctx -> L , str );
6009+ lua_pushstring (ctx -> xdplua -> L , str );
60106010 return 0 ;
60116011}
60126012
@@ -6019,29 +6019,8 @@ static const struct bpf_func_proto bpf_lua_pushstring_proto = {
60196019 .arg2_type = ARG_ANYTHING ,
60206020};
60216021
6022- BPF_CALL_1 (bpf_lua_setstate , struct xdp_buff * , ctx ){
6023- struct lua_state_cpu * sc ;
6024- int cpu = smp_processor_id ();
6025-
6026- list_for_each_entry (sc , & lua_state_cpu_list , list ) {
6027- if (sc -> cpu == cpu ) {
6028- ctx -> L = sc -> L ;
6029- break ;
6030- }
6031- }
6032- return 0 ;
6033- }
6034-
6035- static const struct bpf_func_proto bpf_lua_setstate_proto = {
6036- .func = bpf_lua_setstate ,
6037- .gpl_only = false,
6038- .pkt_access = false,
6039- .ret_type = RET_VOID ,
6040- .arg1_type = ARG_PTR_TO_CTX ,
6041- };
6042-
60436022BPF_CALL_2 (bpf_lua_toboolean , struct xdp_buff * , ctx , int , index ) {
6044- return lua_toboolean (ctx -> L , index );
6023+ return lua_toboolean (ctx -> xdplua -> L , index );
60456024}
60466025
60476026static const struct bpf_func_proto bpf_lua_toboolean_proto = {
@@ -6054,7 +6033,7 @@ static const struct bpf_func_proto bpf_lua_toboolean_proto = {
60546033};
60556034
60566035BPF_CALL_2 (bpf_lua_tointeger , struct xdp_buff * , ctx , int , index ) {
6057- return lua_tointeger (ctx -> L , index );
6036+ return lua_tointeger (ctx -> xdplua -> L , index );
60586037}
60596038
60606039static const struct bpf_func_proto bpf_lua_tointeger_proto = {
@@ -6065,6 +6044,34 @@ static const struct bpf_func_proto bpf_lua_tointeger_proto = {
60656044 .arg1_type = ARG_PTR_TO_CTX ,
60666045 .arg2_type = ARG_ANYTHING ,
60676046};
6047+
6048+ BPF_CALL_1 (bpf_lua_putstate , struct xdp_buff * , ctx ) {
6049+ ctx -> xdplua = this_cpu_ptr (& xdplua_per_cpu );
6050+ spin_lock (ctx -> xdplua -> lock );
6051+ return 0 ;
6052+ }
6053+
6054+ static const struct bpf_func_proto bpf_lua_putstate_proto = {
6055+ .func = bpf_lua_putstate ,
6056+ .gpl_only = false,
6057+ .pkt_access = false,
6058+ .ret_type = RET_VOID ,
6059+ .arg1_type = ARG_PTR_TO_CTX ,
6060+ };
6061+
6062+ BPF_CALL_1 (bpf_lua_removestate , struct xdp_buff * , ctx ) {
6063+ spin_unlock (ctx -> xdplua -> lock );
6064+ ctx -> xdplua = NULL ;
6065+ return 0 ;
6066+ }
6067+
6068+ static const struct bpf_func_proto bpf_lua_removestate_proto = {
6069+ .func = bpf_lua_removestate ,
6070+ .gpl_only = false,
6071+ .pkt_access = false,
6072+ .ret_type = RET_VOID ,
6073+ .arg1_type = ARG_PTR_TO_CTX ,
6074+ };
60686075#endif /* CONFIG_XDP_LUA */
60696076
60706077bool bpf_helper_changes_pkt_data (void * func )
@@ -6162,12 +6169,14 @@ bpf_base_func_proto(enum bpf_func_id func_id)
61626169 return & bpf_lua_pushskb_proto ;
61636170 case BPF_FUNC_lua_pushstring :
61646171 return & bpf_lua_pushstring_proto ;
6165- case BPF_FUNC_lua_setstate :
6166- return & bpf_lua_setstate_proto ;
61676172 case BPF_FUNC_lua_toboolean :
61686173 return & bpf_lua_toboolean_proto ;
61696174 case BPF_FUNC_lua_tointeger :
61706175 return & bpf_lua_tointeger_proto ;
6176+ case BPF_FUNC_lua_putstate :
6177+ return & bpf_lua_putstate_proto ;
6178+ case BPF_FUNC_lua_removestate :
6179+ return & bpf_lua_removestate_proto ;
61716180#endif /* CONFIG_XDP_LUA */
61726181 default :
61736182 return NULL ;
0 commit comments