forked from VictorNogueiraRio/linux
-
Notifications
You must be signed in to change notification settings - Fork 2
add XDPLua #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
add XDPLua #6
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4d82fa2
add Lunatik submodule
VictorNogueiraRio ff7c9b9
add XDPLua
VictorNogueiraRio f278687
add LuaData submodule
VictorNogueiraRio 7d184d9
add LuaXDP submodule
lneto 7e405cf
add LuaRCU submodule
lneto 13a42eb
add XDPLua map sample
VictorNogueiraRio 5eb463c
Fix script loading synchronization issue
VictorNogueiraRio e20f358
add LuaUnpack submodule
VictorNogueiraRio 36ceb19
Add bpf_lua_tostring function
VictorNogueiraRio 040b06b
Add bpf_lua_type function
VictorNogueiraRio 50e056a
Add javascript challenge sample
VictorNogueiraRio fc60140
Limit number of instructions executed by a Lua script
VictorNogueiraRio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix script loading synchronization issue
- Loading branch information
commit 5eb463c6e5bc7c8ac063257e9a721fe5147a903c
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5855,10 +5855,22 @@ static const struct bpf_func_proto bpf_tcp_gen_syncookie_proto = { | |
#endif /* CONFIG_INET */ | ||
|
||
#ifdef CONFIG_XDP_LUA | ||
|
||
static inline void verify_and_lock(void) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggested change, by @lneto
|
||
struct xdplua_create_work *lw; | ||
|
||
lw = this_cpu_ptr(&luaworks); | ||
if (!lw->init) { | ||
lw->init = true; | ||
spin_lock(&lw->lock); | ||
} | ||
} | ||
|
||
BPF_CALL_2(bpf_lua_dataref, struct xdp_buff *, ctx, int, offset) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggested change, by @lneto
|
||
if (offset + ctx->data < ctx->data_end) { | ||
int data_ref; | ||
|
||
verify_and_lock(); | ||
data_ref = ldata_newref(ctx->L, ctx->data + offset, | ||
ctx->data_end - ctx->data - offset); | ||
return data_ref; | ||
|
@@ -5877,6 +5889,7 @@ static const struct bpf_func_proto bpf_lua_dataref_proto = { | |
}; | ||
|
||
BPF_CALL_2(bpf_lua_dataunref, struct xdp_buff *, ctx, int, data_ref) { | ||
verify_and_lock(); | ||
ldata_unref(ctx->L, data_ref); | ||
return 0; | ||
} | ||
|
@@ -5892,18 +5905,28 @@ static const struct bpf_func_proto bpf_lua_dataunref_proto = { | |
|
||
BPF_CALL_4(bpf_lua_pcall, struct xdp_buff *, ctx, char *, funcname, | ||
int, num_args, int, num_rets) { | ||
int base; | ||
|
||
verify_and_lock(); | ||
|
||
base = lua_gettop(ctx->L) - num_args; | ||
if (lua_getglobal(ctx->L, funcname) != LUA_TFUNCTION) { | ||
pr_err("function %s not found\n", funcname); | ||
lua_pop(ctx->L, num_args); | ||
return 0; | ||
num_rets = 0; | ||
goto clean_state; | ||
} | ||
|
||
lua_insert(ctx->L, 1); | ||
lua_insert(ctx->L, base + 1); | ||
if (lua_pcall(ctx->L, num_args, num_rets, 0)) { | ||
pr_err("%s\n", lua_tostring(ctx->L, -1)); | ||
lua_pop(ctx->L, 1); | ||
return 0; | ||
num_rets = 0; | ||
goto clean_state; | ||
} | ||
|
||
base += num_rets; | ||
|
||
clean_state: | ||
lua_settop(ctx->L, base); | ||
return num_rets; | ||
} | ||
|
||
|
@@ -5919,6 +5942,7 @@ static const struct bpf_func_proto bpf_lua_pcall_proto = { | |
}; | ||
|
||
BPF_CALL_2(bpf_lua_pop, struct xdp_buff *, ctx, int, index) { | ||
verify_and_lock(); | ||
lua_pop(ctx->L, index); | ||
return 0; | ||
} | ||
|
@@ -5933,6 +5957,7 @@ static const struct bpf_func_proto bpf_lua_pop_proto = { | |
}; | ||
|
||
BPF_CALL_2(bpf_lua_pushinteger, struct xdp_buff *, ctx, int, num) { | ||
verify_and_lock(); | ||
lua_pushinteger(ctx->L, num); | ||
return 0; | ||
} | ||
|
@@ -5947,6 +5972,7 @@ static const struct bpf_func_proto bpf_lua_pushinteger_proto = { | |
}; | ||
|
||
BPF_CALL_2(bpf_lua_pushlightuserdata, struct xdp_buff *, ctx, void *, ptr) { | ||
verify_and_lock(); | ||
lua_pushlightuserdata(ctx->L, ptr); | ||
return 0; | ||
} | ||
|
@@ -5961,6 +5987,7 @@ static const struct bpf_func_proto bpf_lua_pushlightuserdata_proto = { | |
}; | ||
|
||
BPF_CALL_2(bpf_lua_pushmap, struct xdp_buff *, ctx, struct bpf_map *, map) { | ||
verify_and_lock(); | ||
lua_pushlightuserdata(ctx->L, map); | ||
return 0; | ||
} | ||
|
@@ -5975,6 +6002,7 @@ static const struct bpf_func_proto bpf_lua_pushmap_proto = { | |
}; | ||
|
||
BPF_CALL_3(bpf_lua_pushlstring, struct xdp_buff *, ctx, const char *, str, size_t, len) { | ||
verify_and_lock(); | ||
lua_pushlstring(ctx->L, str, len); | ||
return 0; | ||
} | ||
|
@@ -5990,6 +6018,7 @@ static const struct bpf_func_proto bpf_lua_pushlstring_proto = { | |
}; | ||
|
||
BPF_CALL_1(bpf_lua_pushskb, struct xdp_buff *, ctx) { | ||
verify_and_lock(); | ||
lua_pushlightuserdata(ctx->L, ctx->skb); | ||
return 0; | ||
} | ||
|
@@ -6003,6 +6032,7 @@ static const struct bpf_func_proto bpf_lua_pushskb_proto = { | |
}; | ||
|
||
BPF_CALL_2(bpf_lua_pushstring, struct xdp_buff *, ctx, const char *, str) { | ||
verify_and_lock(); | ||
lua_pushstring(ctx->L, str); | ||
return 0; | ||
} | ||
|
@@ -6016,28 +6046,8 @@ static const struct bpf_func_proto bpf_lua_pushstring_proto = { | |
.arg2_type = ARG_ANYTHING, | ||
}; | ||
|
||
BPF_CALL_1(bpf_lua_setstate, struct xdp_buff *, ctx){ | ||
struct lua_state_cpu *sc; | ||
int cpu = smp_processor_id(); | ||
|
||
list_for_each_entry(sc, &lua_state_cpu_list, list) { | ||
if (sc->cpu == cpu) { | ||
ctx->L = sc->L; | ||
break; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
static const struct bpf_func_proto bpf_lua_setstate_proto = { | ||
.func = bpf_lua_setstate, | ||
.gpl_only = false, | ||
.pkt_access = false, | ||
.ret_type = RET_VOID, | ||
.arg1_type = ARG_PTR_TO_CTX, | ||
}; | ||
|
||
BPF_CALL_2(bpf_lua_toboolean, struct xdp_buff *, ctx, int, index) { | ||
verify_and_lock(); | ||
return lua_toboolean(ctx->L, index); | ||
} | ||
|
||
|
@@ -6051,6 +6061,7 @@ static const struct bpf_func_proto bpf_lua_toboolean_proto = { | |
}; | ||
|
||
BPF_CALL_2(bpf_lua_tointeger, struct xdp_buff *, ctx, int, index) { | ||
verify_and_lock(); | ||
return lua_tointeger(ctx->L, index); | ||
} | ||
|
||
|
@@ -6161,8 +6172,6 @@ bpf_base_func_proto(enum bpf_func_id func_id) | |
return &bpf_lua_pushskb_proto; | ||
case BPF_FUNC_lua_pushstring: | ||
return &bpf_lua_pushstring_proto; | ||
case BPF_FUNC_lua_setstate: | ||
return &bpf_lua_setstate_proto; | ||
case BPF_FUNC_lua_toboolean: | ||
return &bpf_lua_toboolean_proto; | ||
case BPF_FUNC_lua_tointeger: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/init/inuse/