mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-05-05 23:04:09 +00:00
bpf: Start using the BPF dispatcher in BPF_TEST_RUN
In order to properly exercise the BPF dispatcher, this commit adds BPF dispatcher usage to BPF_TEST_RUN when executing XDP programs. Signed-off-by: Björn Töpel <bjorn.topel@intel.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20191213175112.30208-5-bjorn.topel@gmail.com
This commit is contained in:
parent
7e6897f959
commit
f23c4b3924
1 changed files with 10 additions and 5 deletions
|
@ -15,7 +15,7 @@
|
||||||
#include <trace/events/bpf_test_run.h>
|
#include <trace/events/bpf_test_run.h>
|
||||||
|
|
||||||
static int bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat,
|
static int bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat,
|
||||||
u32 *retval, u32 *time)
|
u32 *retval, u32 *time, bool xdp)
|
||||||
{
|
{
|
||||||
struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE] = { NULL };
|
struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE] = { NULL };
|
||||||
enum bpf_cgroup_storage_type stype;
|
enum bpf_cgroup_storage_type stype;
|
||||||
|
@ -41,7 +41,11 @@ static int bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat,
|
||||||
time_start = ktime_get_ns();
|
time_start = ktime_get_ns();
|
||||||
for (i = 0; i < repeat; i++) {
|
for (i = 0; i < repeat; i++) {
|
||||||
bpf_cgroup_storage_set(storage);
|
bpf_cgroup_storage_set(storage);
|
||||||
*retval = BPF_PROG_RUN(prog, ctx);
|
|
||||||
|
if (xdp)
|
||||||
|
*retval = bpf_prog_run_xdp(prog, ctx);
|
||||||
|
else
|
||||||
|
*retval = BPF_PROG_RUN(prog, ctx);
|
||||||
|
|
||||||
if (signal_pending(current)) {
|
if (signal_pending(current)) {
|
||||||
ret = -EINTR;
|
ret = -EINTR;
|
||||||
|
@ -356,7 +360,7 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
|
||||||
ret = convert___skb_to_skb(skb, ctx);
|
ret = convert___skb_to_skb(skb, ctx);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
ret = bpf_test_run(prog, skb, repeat, &retval, &duration);
|
ret = bpf_test_run(prog, skb, repeat, &retval, &duration, false);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
if (!is_l2) {
|
if (!is_l2) {
|
||||||
|
@ -413,8 +417,8 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
|
||||||
|
|
||||||
rxqueue = __netif_get_rx_queue(current->nsproxy->net_ns->loopback_dev, 0);
|
rxqueue = __netif_get_rx_queue(current->nsproxy->net_ns->loopback_dev, 0);
|
||||||
xdp.rxq = &rxqueue->xdp_rxq;
|
xdp.rxq = &rxqueue->xdp_rxq;
|
||||||
|
bpf_prog_change_xdp(NULL, prog);
|
||||||
ret = bpf_test_run(prog, &xdp, repeat, &retval, &duration);
|
ret = bpf_test_run(prog, &xdp, repeat, &retval, &duration, true);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
if (xdp.data != data + XDP_PACKET_HEADROOM + NET_IP_ALIGN ||
|
if (xdp.data != data + XDP_PACKET_HEADROOM + NET_IP_ALIGN ||
|
||||||
|
@ -422,6 +426,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
|
||||||
size = xdp.data_end - xdp.data;
|
size = xdp.data_end - xdp.data;
|
||||||
ret = bpf_test_finish(kattr, uattr, xdp.data, size, retval, duration);
|
ret = bpf_test_finish(kattr, uattr, xdp.data, size, retval, duration);
|
||||||
out:
|
out:
|
||||||
|
bpf_prog_change_xdp(prog, NULL);
|
||||||
kfree(data);
|
kfree(data);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue