From patchwork Fri Feb 12 20:41:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 1440068 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DclmR2HHkz9sRf; Sat, 13 Feb 2021 07:42:15 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1lAfGW-0005WB-5U; Fri, 12 Feb 2021 20:42:12 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lAfGU-0005VT-5k for kernel-team@lists.ubuntu.com; Fri, 12 Feb 2021 20:42:10 +0000 Received: from mail-qv1-f69.google.com ([209.85.219.69]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lAfGT-0005qb-QI for kernel-team@lists.ubuntu.com; Fri, 12 Feb 2021 20:42:09 +0000 Received: by mail-qv1-f69.google.com with SMTP id l13so374091qvt.13 for ; Fri, 12 Feb 2021 12:42:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V6aG9fiJ4SrMmGEjgblpz0dhYMCni7/ElLP9t2fZXkg=; b=YRIWUOaze4/VU91Ls93iBSiZAn1+yfLOSpHjhYmrTFglwBBtHvC0jFZ6gEBnEHEg80 kMKLms6et6iFa0OF6LkOtWRVMcf6r8MJagi+/ICczX9V0c6PWaZHnaAoLCpn576Y2SrT v60GpEcma4zwqzXrSIVfHbp63aeI/GQabCCfRG4JolTLzd6PjAYof7yQZpAuFB+uWrML AU30SYPciox0ajHOXjBfKxMW5ZlH8EWHSOJyqpULGWBe0nFOMf+aRPhcbRH7uQ0Kr64N jxzBcTHBI5G74JUmZwwG0F01acJEkxicuU6w/0P8IsFXysWX0CR028/Xln0mvOsbobRU 9TPg== X-Gm-Message-State: AOAM533imBIt2pfIaFb6F788rVzaSZxje3vsWPbFyFIlXDNlmMQ/KmbP AVyUvCbaMpD81BFN83zYrtW/3BzGUTxj9p2UjcJZGvX1hE9Uh2pzpm8PaJMmtHRFWOTdNJEB9wO cgXgkNDnmCtjCrXQ0zrZGTwJaEGn5XAx0oe9XV/lr3g== X-Received: by 2002:aed:2be3:: with SMTP id e90mr4162642qtd.367.1613162528608; Fri, 12 Feb 2021 12:42:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwkG+hXfbUIw+FCDBJaomeu6KnVmFNRmpAGuDXgVhVL0Rh8C/h+CuNnfxaXIElOPJ6xJDTxMA== X-Received: by 2002:aed:2be3:: with SMTP id e90mr4162596qtd.367.1613162528048; Fri, 12 Feb 2021 12:42:08 -0800 (PST) Received: from localhost ([177.138.180.216]) by smtp.gmail.com with ESMTPSA id c143sm173622qkg.83.2021.02.12.12.42.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Feb 2021 12:42:07 -0800 (PST) From: "Guilherme G. Piccoli" To: kernel-team@lists.ubuntu.com Subject: [B][PATCH 2/3] net: bpf: add a test for skb_segment in test_bpf module Date: Fri, 12 Feb 2021 17:41:58 -0300 Message-Id: <20210212204159.28472-3-gpiccoli@canonical.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210212204159.28472-1-gpiccoli@canonical.com> References: <20210212204159.28472-1-gpiccoli@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Yonghong Song BugLink: https://bugs.launchpad.net/bugs/1915552 Without the previous commit, "modprobe test_bpf" will have the following errors: ... [ 98.149165] ------------[ cut here ]------------ [ 98.159362] kernel BUG at net/core/skbuff.c:3667! [ 98.169756] invalid opcode: 0000 [#1] SMP PTI [ 98.179370] Modules linked in: [ 98.179371] test_bpf(+) ... which triggers the bug the previous commit intends to fix. The skbs are constructed to mimic what mlx5 may generate. The packet size/header may not mimic real cases in production. But the processing flow is similar. Signed-off-by: Yonghong Song Signed-off-by: David S. Miller (cherry picked from commit 76db8087c4c991dcd17f5ea8ac0eafd0696ab450) Signed-off-by: Guilherme G. Piccoli --- lib/test_bpf.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/lib/test_bpf.c b/lib/test_bpf.c index 1fe4d4b33217..3f0821cb0ab4 100644 --- a/lib/test_bpf.c +++ b/lib/test_bpf.c @@ -6482,6 +6482,93 @@ static bool exclude_test(int test_id) return test_id < test_range[0] || test_id > test_range[1]; } +static __init struct sk_buff *build_test_skb(void) +{ + u32 headroom = NET_SKB_PAD + NET_IP_ALIGN + ETH_HLEN; + struct sk_buff *skb[2]; + struct page *page[2]; + int i, data_size = 8; + + for (i = 0; i < 2; i++) { + page[i] = alloc_page(GFP_KERNEL); + if (!page[i]) { + if (i == 0) + goto err_page0; + else + goto err_page1; + } + + /* this will set skb[i]->head_frag */ + skb[i] = dev_alloc_skb(headroom + data_size); + if (!skb[i]) { + if (i == 0) + goto err_skb0; + else + goto err_skb1; + } + + skb_reserve(skb[i], headroom); + skb_put(skb[i], data_size); + skb[i]->protocol = htons(ETH_P_IP); + skb_reset_network_header(skb[i]); + skb_set_mac_header(skb[i], -ETH_HLEN); + + skb_add_rx_frag(skb[i], 0, page[i], 0, 64, 64); + // skb_headlen(skb[i]): 8, skb[i]->head_frag = 1 + } + + /* setup shinfo */ + skb_shinfo(skb[0])->gso_size = 1448; + skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV4; + skb_shinfo(skb[0])->gso_type |= SKB_GSO_DODGY; + skb_shinfo(skb[0])->gso_segs = 0; + skb_shinfo(skb[0])->frag_list = skb[1]; + + /* adjust skb[0]'s len */ + skb[0]->len += skb[1]->len; + skb[0]->data_len += skb[1]->data_len; + skb[0]->truesize += skb[1]->truesize; + + return skb[0]; + +err_skb1: + __free_page(page[1]); +err_page1: + kfree_skb(skb[0]); +err_skb0: + __free_page(page[0]); +err_page0: + return NULL; +} + +static __init int test_skb_segment(void) +{ + netdev_features_t features; + struct sk_buff *skb, *segs; + int ret = -1; + + features = NETIF_F_SG | NETIF_F_GSO_PARTIAL | NETIF_F_IP_CSUM | + NETIF_F_IPV6_CSUM; + features |= NETIF_F_RXCSUM; + skb = build_test_skb(); + if (!skb) { + pr_info("%s: failed to build_test_skb", __func__); + goto done; + } + + segs = skb_segment(skb, features); + if (segs) { + kfree_skb_list(segs); + ret = 0; + pr_info("%s: success in skb_segment!", __func__); + } else { + pr_info("%s: failed in skb_segment!", __func__); + } + kfree_skb(skb); +done: + return ret; +} + static __init int test_bpf(void) { int i, err_cnt = 0, pass_cnt = 0; @@ -6539,9 +6626,11 @@ static int __init test_bpf_init(void) return ret; ret = test_bpf(); - destroy_bpf_tests(); - return ret; + if (ret) + return ret; + + return test_skb_segment(); } static void __exit test_bpf_exit(void)