From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Borkmann Subject: Re: [bpf-next PATCH v2 3/4] bpf: sockmap, BPF_F_INGRESS flag for BPF_SK_SKB_STREAM_VERDICT: Date: Wed, 28 Mar 2018 17:46:53 +0200 Message-ID: <59b96ff7-420f-1b5d-fb55-d15f9aa29a34@iogearbox.net> References: <20180327172042.11354.81872.stgit@john-Precision-Tower-5810> <20180327172322.11354.54016.stgit@john-Precision-Tower-5810> <71a13f21-6886-85c3-6911-8ac33c486901@iogearbox.net> <3e7dd92b-a932-d977-2a7e-505b374733df@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: netdev@vger.kernel.org, davem@davemloft.net To: John Fastabend , ast@kernel.org Return-path: Received: from www62.your-server.de ([213.133.104.62]:48289 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753816AbeC1Pqz (ORCPT ); Wed, 28 Mar 2018 11:46:55 -0400 In-Reply-To: <3e7dd92b-a932-d977-2a7e-505b374733df@gmail.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 03/28/2018 05:45 PM, John Fastabend wrote: > On 03/28/2018 07:21 AM, Daniel Borkmann wrote: >> On 03/27/2018 07:23 PM, John Fastabend wrote: >>> Add support for the BPF_F_INGRESS flag in skb redirect helper. To >>> do this convert skb into a scatterlist and push into ingress queue. >>> This is the same logic that is used in the sk_msg redirect helper >>> so it should feel familiar. >>> >>> Signed-off-by: John Fastabend >>> --- >>> include/linux/filter.h | 1 + >>> kernel/bpf/sockmap.c | 94 +++++++++++++++++++++++++++++++++++++++--------- >>> net/core/filter.c | 2 + >>> 3 files changed, 78 insertions(+), 19 deletions(-) >> [...] >>> if (!sg->length && md->sg_start == md->sg_end) { >>> list_del(&md->list); >>> + if (md->skb) >>> + consume_skb(md->skb); >>> kfree(md); >>> } >>> } >>> @@ -1045,27 +1048,72 @@ static int smap_verdict_func(struct smap_psock *psock, struct sk_buff *skb) >>> __SK_DROP; >>> } >>> >>> +static int smap_do_ingress(struct smap_psock *psock, struct sk_buff *skb) >>> +{ >>> + struct sock *sk = psock->sock; >>> + int copied = 0, num_sg; >>> + struct sk_msg_buff *r; >>> + >>> + r = kzalloc(sizeof(struct sk_msg_buff), __GFP_NOWARN | GFP_ATOMIC); >>> + if (unlikely(!r)) >>> + return -EAGAIN; >>> + >>> + if (!sk_rmem_schedule(sk, skb, skb->len)) { >>> + kfree(r); >>> + return -EAGAIN; >>> + } >>> + sk_mem_charge(sk, skb->len); >> >> Usually mem accounting is based on truesize. This is not done here since >> you need the exact length of the skb for the sg list later on, right? > > Correct. > >> >>> + sg_init_table(r->sg_data, MAX_SKB_FRAGS); >>> + num_sg = skb_to_sgvec(skb, r->sg_data, 0, skb->len); >>> + if (unlikely(num_sg < 0)) { >>> + kfree(r); >> >> Don't we need to undo the mem charge here in case of error? >> > > Actually, I'll just move the sk_mem_charge() down below this error > then we don't need to unwind it. Agree, good point.