Skip to content

Commit 90fed9c

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Alexei Starovoitov says: ==================== pull-request: bpf-next 2018-05-24 The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) Björn Töpel cleans up AF_XDP (removes rebind, explicit cache alignment from uapi, etc). 2) David Ahern adds mtu checks to bpf_ipv{4,6}_fib_lookup() helpers. 3) Jesper Dangaard Brouer adds bulking support to ndo_xdp_xmit. 4) Jiong Wang adds support for indirect and arithmetic shifts to NFP 5) Martin KaFai Lau cleans up BTF uapi and makes the btf_header extensible. 6) Mathieu Xhonneux adds an End.BPF action to seg6local with BPF helpers allowing to edit/grow/shrink a SRH and apply on a packet generic SRv6 actions. 7) Sandipan Das adds support for bpf2bpf function calls in ppc64 JIT. 8) Yonghong Song adds BPF_TASK_FD_QUERY command for introspection of tracing events. 9) other misc fixes from Gustavo A. R. Silva, Sirio Balmelli, John Fastabend, and Magnus Karlsson ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 49a473f + 10f6786 commit 90fed9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+5213
-812
lines changed

arch/powerpc/net/bpf_jit_comp64.c

Lines changed: 89 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -167,25 +167,37 @@ static void bpf_jit_build_epilogue(u32 *image, struct codegen_context *ctx)
167167

168168
static void bpf_jit_emit_func_call(u32 *image, struct codegen_context *ctx, u64 func)
169169
{
170+
unsigned int i, ctx_idx = ctx->idx;
171+
172+
/* Load function address into r12 */
173+
PPC_LI64(12, func);
174+
175+
/* For bpf-to-bpf function calls, the callee's address is unknown
176+
* until the last extra pass. As seen above, we use PPC_LI64() to
177+
* load the callee's address, but this may optimize the number of
178+
* instructions required based on the nature of the address.
179+
*
180+
* Since we don't want the number of instructions emitted to change,
181+
* we pad the optimized PPC_LI64() call with NOPs to guarantee that
182+
* we always have a five-instruction sequence, which is the maximum
183+
* that PPC_LI64() can emit.
184+
*/
185+
for (i = ctx->idx - ctx_idx; i < 5; i++)
186+
PPC_NOP();
187+
170188
#ifdef PPC64_ELF_ABI_v1
171-
/* func points to the function descriptor */
172-
PPC_LI64(b2p[TMP_REG_2], func);
173-
/* Load actual entry point from function descriptor */
174-
PPC_BPF_LL(b2p[TMP_REG_1], b2p[TMP_REG_2], 0);
175-
/* ... and move it to LR */
176-
PPC_MTLR(b2p[TMP_REG_1]);
177189
/*
178190
* Load TOC from function descriptor at offset 8.
179191
* We can clobber r2 since we get called through a
180192
* function pointer (so caller will save/restore r2)
181193
* and since we don't use a TOC ourself.
182194
*/
183-
PPC_BPF_LL(2, b2p[TMP_REG_2], 8);
184-
#else
185-
/* We can clobber r12 */
186-
PPC_FUNC_ADDR(12, func);
187-
PPC_MTLR(12);
195+
PPC_BPF_LL(2, 12, 8);
196+
/* Load actual entry point from function descriptor */
197+
PPC_BPF_LL(12, 12, 0);
188198
#endif
199+
200+
PPC_MTLR(12);
189201
PPC_BLRL();
190202
}
191203

@@ -256,7 +268,7 @@ static void bpf_jit_emit_tail_call(u32 *image, struct codegen_context *ctx, u32
256268
/* Assemble the body code between the prologue & epilogue */
257269
static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
258270
struct codegen_context *ctx,
259-
u32 *addrs)
271+
u32 *addrs, bool extra_pass)
260272
{
261273
const struct bpf_insn *insn = fp->insnsi;
262274
int flen = fp->len;
@@ -712,11 +724,25 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
712724
break;
713725

714726
/*
715-
* Call kernel helper
727+
* Call kernel helper or bpf function
716728
*/
717729
case BPF_JMP | BPF_CALL:
718730
ctx->seen |= SEEN_FUNC;
719-
func = (u8 *) __bpf_call_base + imm;
731+
732+
/* bpf function call */
733+
if (insn[i].src_reg == BPF_PSEUDO_CALL)
734+
if (!extra_pass)
735+
func = NULL;
736+
else if (fp->aux->func && off < fp->aux->func_cnt)
737+
/* use the subprog id from the off
738+
* field to lookup the callee address
739+
*/
740+
func = (u8 *) fp->aux->func[off]->bpf_func;
741+
else
742+
return -EINVAL;
743+
/* kernel helper call */
744+
else
745+
func = (u8 *) __bpf_call_base + imm;
720746

721747
bpf_jit_emit_func_call(image, ctx, (u64)func);
722748

@@ -864,20 +890,30 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
864890
return 0;
865891
}
866892

893+
struct powerpc64_jit_data {
894+
struct bpf_binary_header *header;
895+
u32 *addrs;
896+
u8 *image;
897+
u32 proglen;
898+
struct codegen_context ctx;
899+
};
900+
867901
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
868902
{
869903
u32 proglen;
870904
u32 alloclen;
871905
u8 *image = NULL;
872906
u32 *code_base;
873907
u32 *addrs;
908+
struct powerpc64_jit_data *jit_data;
874909
struct codegen_context cgctx;
875910
int pass;
876911
int flen;
877912
struct bpf_binary_header *bpf_hdr;
878913
struct bpf_prog *org_fp = fp;
879914
struct bpf_prog *tmp_fp;
880915
bool bpf_blinded = false;
916+
bool extra_pass = false;
881917

882918
if (!fp->jit_requested)
883919
return org_fp;
@@ -891,11 +927,32 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
891927
fp = tmp_fp;
892928
}
893929

930+
jit_data = fp->aux->jit_data;
931+
if (!jit_data) {
932+
jit_data = kzalloc(sizeof(*jit_data), GFP_KERNEL);
933+
if (!jit_data) {
934+
fp = org_fp;
935+
goto out;
936+
}
937+
fp->aux->jit_data = jit_data;
938+
}
939+
894940
flen = fp->len;
941+
addrs = jit_data->addrs;
942+
if (addrs) {
943+
cgctx = jit_data->ctx;
944+
image = jit_data->image;
945+
bpf_hdr = jit_data->header;
946+
proglen = jit_data->proglen;
947+
alloclen = proglen + FUNCTION_DESCR_SIZE;
948+
extra_pass = true;
949+
goto skip_init_ctx;
950+
}
951+
895952
addrs = kzalloc((flen+1) * sizeof(*addrs), GFP_KERNEL);
896953
if (addrs == NULL) {
897954
fp = org_fp;
898-
goto out;
955+
goto out_addrs;
899956
}
900957

901958
memset(&cgctx, 0, sizeof(struct codegen_context));
@@ -904,10 +961,10 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
904961
cgctx.stack_size = round_up(fp->aux->stack_depth, 16);
905962

906963
/* Scouting faux-generate pass 0 */
907-
if (bpf_jit_build_body(fp, 0, &cgctx, addrs)) {
964+
if (bpf_jit_build_body(fp, 0, &cgctx, addrs, false)) {
908965
/* We hit something illegal or unsupported. */
909966
fp = org_fp;
910-
goto out;
967+
goto out_addrs;
911968
}
912969

913970
/*
@@ -925,17 +982,18 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
925982
bpf_jit_fill_ill_insns);
926983
if (!bpf_hdr) {
927984
fp = org_fp;
928-
goto out;
985+
goto out_addrs;
929986
}
930987

988+
skip_init_ctx:
931989
code_base = (u32 *)(image + FUNCTION_DESCR_SIZE);
932990

933991
/* Code generation passes 1-2 */
934992
for (pass = 1; pass < 3; pass++) {
935993
/* Now build the prologue, body code & epilogue for real. */
936994
cgctx.idx = 0;
937995
bpf_jit_build_prologue(code_base, &cgctx);
938-
bpf_jit_build_body(fp, code_base, &cgctx, addrs);
996+
bpf_jit_build_body(fp, code_base, &cgctx, addrs, extra_pass);
939997
bpf_jit_build_epilogue(code_base, &cgctx);
940998

941999
if (bpf_jit_enable > 1)
@@ -961,10 +1019,20 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
9611019
fp->jited_len = alloclen;
9621020

9631021
bpf_flush_icache(bpf_hdr, (u8 *)bpf_hdr + (bpf_hdr->pages * PAGE_SIZE));
1022+
if (!fp->is_func || extra_pass) {
1023+
out_addrs:
1024+
kfree(addrs);
1025+
kfree(jit_data);
1026+
fp->aux->jit_data = NULL;
1027+
} else {
1028+
jit_data->addrs = addrs;
1029+
jit_data->ctx = cgctx;
1030+
jit_data->proglen = proglen;
1031+
jit_data->image = image;
1032+
jit_data->header = bpf_hdr;
1033+
}
9641034

9651035
out:
966-
kfree(addrs);
967-
9681036
if (bpf_blinded)
9691037
bpf_jit_prog_release_other(fp, fp == org_fp ? tmp_fp : org_fp);
9701038

drivers/net/ethernet/intel/i40e/i40e_txrx.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3664,26 +3664,38 @@ netdev_tx_t i40e_lan_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
36643664
* @dev: netdev
36653665
* @xdp: XDP buffer
36663666
*
3667-
* Returns Zero if sent, else an error code
3667+
* Returns number of frames successfully sent. Frames that fail are
3668+
* free'ed via XDP return API.
3669+
*
3670+
* For error cases, a negative errno code is returned and no-frames
3671+
* are transmitted (caller must handle freeing frames).
36683672
**/
3669-
int i40e_xdp_xmit(struct net_device *dev, struct xdp_frame *xdpf)
3673+
int i40e_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames)
36703674
{
36713675
struct i40e_netdev_priv *np = netdev_priv(dev);
36723676
unsigned int queue_index = smp_processor_id();
36733677
struct i40e_vsi *vsi = np->vsi;
3674-
int err;
3678+
int drops = 0;
3679+
int i;
36753680

36763681
if (test_bit(__I40E_VSI_DOWN, vsi->state))
36773682
return -ENETDOWN;
36783683

36793684
if (!i40e_enabled_xdp_vsi(vsi) || queue_index >= vsi->num_queue_pairs)
36803685
return -ENXIO;
36813686

3682-
err = i40e_xmit_xdp_ring(xdpf, vsi->xdp_rings[queue_index]);
3683-
if (err != I40E_XDP_TX)
3684-
return -ENOSPC;
3687+
for (i = 0; i < n; i++) {
3688+
struct xdp_frame *xdpf = frames[i];
3689+
int err;
36853690

3686-
return 0;
3691+
err = i40e_xmit_xdp_ring(xdpf, vsi->xdp_rings[queue_index]);
3692+
if (err != I40E_XDP_TX) {
3693+
xdp_return_frame_rx_napi(xdpf);
3694+
drops++;
3695+
}
3696+
}
3697+
3698+
return n - drops;
36873699
}
36883700

36893701
/**

drivers/net/ethernet/intel/i40e/i40e_txrx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ u32 i40e_get_tx_pending(struct i40e_ring *ring, bool in_sw);
487487
void i40e_detect_recover_hung(struct i40e_vsi *vsi);
488488
int __i40e_maybe_stop_tx(struct i40e_ring *tx_ring, int size);
489489
bool __i40e_chk_linearize(struct sk_buff *skb);
490-
int i40e_xdp_xmit(struct net_device *dev, struct xdp_frame *xdpf);
490+
int i40e_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames);
491491
void i40e_xdp_flush(struct net_device *dev);
492492

493493
/**

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10022,11 +10022,13 @@ static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp)
1002210022
}
1002310023
}
1002410024

10025-
static int ixgbe_xdp_xmit(struct net_device *dev, struct xdp_frame *xdpf)
10025+
static int ixgbe_xdp_xmit(struct net_device *dev, int n,
10026+
struct xdp_frame **frames)
1002610027
{
1002710028
struct ixgbe_adapter *adapter = netdev_priv(dev);
1002810029
struct ixgbe_ring *ring;
10029-
int err;
10030+
int drops = 0;
10031+
int i;
1003010032

1003110033
if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
1003210034
return -ENETDOWN;
@@ -10038,11 +10040,18 @@ static int ixgbe_xdp_xmit(struct net_device *dev, struct xdp_frame *xdpf)
1003810040
if (unlikely(!ring))
1003910041
return -ENXIO;
1004010042

10041-
err = ixgbe_xmit_xdp_ring(adapter, xdpf);
10042-
if (err != IXGBE_XDP_TX)
10043-
return -ENOSPC;
10043+
for (i = 0; i < n; i++) {
10044+
struct xdp_frame *xdpf = frames[i];
10045+
int err;
1004410046

10045-
return 0;
10047+
err = ixgbe_xmit_xdp_ring(adapter, xdpf);
10048+
if (err != IXGBE_XDP_TX) {
10049+
xdp_return_frame_rx_napi(xdpf);
10050+
drops++;
10051+
}
10052+
}
10053+
10054+
return n - drops;
1004610055
}
1004710056

1004810057
static void ixgbe_xdp_flush(struct net_device *dev)

0 commit comments

Comments
 (0)