From patchwork Thu Sep 3 20:58:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 261558 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FABDC433E2 for ; Thu, 3 Sep 2020 20:59:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 15A8F206B8 for ; Thu, 3 Sep 2020 20:59:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599166785; bh=WjAJcozqYUApukYBbu27u+BBeSfDcbmdQWNonq247W8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ZKfmklruL5NwsMI1GR3HGPZg6M+zenHUJJfS8o030hQTcP4Y2n+nFEgUdsEXM0oDD ogGD1elwVFoBdykRHTHHiFskm1te6uPgAnJHaywC3ffV4aWEu9Gj9AogWDCblOR/QH rFazkq3ggN+OMjge8cA6lteo84KjqMPlXpvX7aIY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729371AbgICU7o (ORCPT ); Thu, 3 Sep 2020 16:59:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:56306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729311AbgICU7i (ORCPT ); Thu, 3 Sep 2020 16:59:38 -0400 Received: from lore-desk.redhat.com (unknown [151.66.86.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 94583206CA; Thu, 3 Sep 2020 20:59:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599166777; bh=WjAJcozqYUApukYBbu27u+BBeSfDcbmdQWNonq247W8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c3nAjvG10T6GSK34bZ18wVNmZGoCwFZ56ueaXnam5HajhW65foHRwOFRKFsfPBi4t GpDp+gTBjWCHVBnvQagHCiikFiytqOqP8Rt1osBQIFePvrkEqtgPG0o6g2HRXlTUz5 EubrieyQBgt1zvPJy1RNSIn4fBY2p9sM4fC4XmqM= From: Lorenzo Bianconi To: netdev@vger.kernel.org Cc: bpf@vger.kernel.org, davem@davemloft.net, lorenzo.bianconi@redhat.com, brouer@redhat.com, echaudro@redhat.com, sameehj@amazon.com, kuba@kernel.org, john.fastabend@gmail.com, daniel@iogearbox.net, ast@kernel.org, shayagr@amazon.com Subject: [PATCH v2 net-next 7/9] bpf: helpers: add multibuffer support Date: Thu, 3 Sep 2020 22:58:51 +0200 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Sameeh Jubran The implementation is based on this [0] draft by Jesper D. Brouer. Provided two new helpers: * bpf_xdp_get_frag_count() * bpf_xdp_get_frags_total_size() [0] xdp mb design - https://github.com/xdp-project/xdp-project/blob/master/areas/core/xdp-multi-buffer01-design.org Signed-off-by: Sameeh Jubran Signed-off-by: Lorenzo Bianconi --- include/uapi/linux/bpf.h | 14 ++++++++++++ net/core/filter.c | 39 ++++++++++++++++++++++++++++++++++ tools/include/uapi/linux/bpf.h | 14 ++++++++++++ 3 files changed, 67 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index c4a6d245619c..53db75095306 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -3590,6 +3590,18 @@ union bpf_attr { * * Return * 0 on success, or a negative error in case of failure. + * + * int bpf_xdp_get_frag_count(struct xdp_buff *xdp_md) + * Description + * Get the total number of frags for a given packet. + * Return + * The number of frags + * + * int bpf_xdp_get_frags_total_size(struct xdp_buff *xdp_md) + * Description + * Get the total size of frags for a given packet. + * Return + * The total size of frags for a given packet. */ #define __BPF_FUNC_MAPPER(FN) \ FN(unspec), \ @@ -3742,6 +3754,8 @@ union bpf_attr { FN(d_path), \ FN(copy_from_user), \ FN(xdp_adjust_mb_header), \ + FN(xdp_get_frag_count), \ + FN(xdp_get_frags_total_size), \ /* */ /* integer value in 'imm' field of BPF_CALL instruction selects which helper diff --git a/net/core/filter.c b/net/core/filter.c index ae6b10cf062d..ba058fc16440 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3526,6 +3526,41 @@ static const struct bpf_func_proto bpf_xdp_adjust_mb_header_proto = { .arg2_type = ARG_ANYTHING, }; +BPF_CALL_1(bpf_xdp_get_frag_count, struct xdp_buff*, xdp) +{ + struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp); + + return xdp->mb ? sinfo->nr_frags : 0; +} + +const struct bpf_func_proto bpf_xdp_get_frag_count_proto = { + .func = bpf_xdp_get_frag_count, + .gpl_only = false, + .ret_type = RET_INTEGER, + .arg1_type = ARG_PTR_TO_CTX, +}; + +BPF_CALL_1(bpf_xdp_get_frags_total_size, struct xdp_buff*, xdp) +{ + struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp); + int nfrags, i; + int size = 0; + + nfrags = xdp->mb ? sinfo->nr_frags : 0; + + for (i = 0; i < nfrags && i < MAX_SKB_FRAGS; i++) + size += skb_frag_size(&sinfo->frags[i]); + + return size; +} + +const struct bpf_func_proto bpf_xdp_get_frags_total_size_proto = { + .func = bpf_xdp_get_frags_total_size, + .gpl_only = false, + .ret_type = RET_INTEGER, + .arg1_type = ARG_PTR_TO_CTX, +}; + BPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset) { void *data_hard_end = xdp_data_hard_end(xdp); /* use xdp->frame_sz */ @@ -6889,6 +6924,10 @@ xdp_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_xdp_adjust_tail_proto; case BPF_FUNC_xdp_adjust_mb_header: return &bpf_xdp_adjust_mb_header_proto; + case BPF_FUNC_xdp_get_frag_count: + return &bpf_xdp_get_frag_count_proto; + case BPF_FUNC_xdp_get_frags_total_size: + return &bpf_xdp_get_frags_total_size_proto; case BPF_FUNC_fib_lookup: return &bpf_xdp_fib_lookup_proto; #ifdef CONFIG_INET diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 392d52a2ecef..dd4669096cbb 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -3591,6 +3591,18 @@ union bpf_attr { * * Return * 0 on success, or a negative error in case of failure. + * + * int bpf_xdp_get_frag_count(struct xdp_buff *xdp_md) + * Description + * Get the total number of frags for a given packet. + * Return + * The number of frags + * + * int bpf_xdp_get_frags_total_size(struct xdp_buff *xdp_md) + * Description + * Get the total size of frags for a given packet. + * Return + * The total size of frags for a given packet. */ #define __BPF_FUNC_MAPPER(FN) \ FN(unspec), \ @@ -3743,6 +3755,8 @@ union bpf_attr { FN(d_path), \ FN(copy_from_user), \ FN(xdp_adjust_mb_header), \ + FN(xdp_get_frag_count), \ + FN(xdp_get_frags_total_size), \ /* */ /* integer value in 'imm' field of BPF_CALL instruction selects which helper