From patchwork Mon May 27 18:59:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Fedorenko X-Patchwork-Id: 13675713 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E053C15A879; Mon, 27 May 2024 19:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.153.30 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716836461; cv=none; b=SVybDCGwGRRsdPwk6i0hoh9rgm2RO1XhRKJR1DxChVltfyAz18cN1vywCav9j83rN9Ob2Oo3gUBZJCmB2mugCnAPtmrw35oaPjvg04TApGBgQFwKuuOhR6SujX8Pw+ZWeRUsd1xTP978d8utlZaMfVpqAt08Cf4z/AT/ZD9/6ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716836461; c=relaxed/simple; bh=yLU8t/0iJ5/QQHKe8t+Yev7MWlW75NtnS3A9bPZ1tQY=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=iloUTYqaIiYaevNS12lYE1/d8puMg73bqEwelNVvLXg70cRfKJXvqNrPhWcDlyn8Rc4xolwzNqTAZEjuwvNpU4xkCQ+erFn3kZT8SlE7+6pBxLtOA8p56Xk4/dunpmqVWYk+uUp23fNPMFFhcaG/9XZ8xMsu1ozsiG4lQmdvkEc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; arc=none smtp.client-ip=67.231.153.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44RIQb8R007199; Mon, 27 May 2024 12:00:23 -0700 DKIM-Signature: =?utf-8?q?v=3D1=3B_a=3Drsa-sha256=3B_c=3Drelaxed/relaxed=3B_?= =?utf-8?q?d=3Dmeta=2Ecom=3B_h=3Dcc=3Acontent-transfer-encoding=3Acontent-ty?= =?utf-8?q?pe=3Adate=3Afrom=3Amessage-id=3Amime-version=3Asubject=3Ato=3B_s?= =?utf-8?q?=3Ds2048-2021-q4=3B_bh=3DW4OmNPrht9nkzrNUm0QI3Obq8q8zB90+87BVHnIV?= =?utf-8?q?V5Q=3D=3B_b=3DiCzv3oXY55/IDKGfZvco/XlTuVOl7b8toVnL+H+3kna9eXLk1MZ?= =?utf-8?q?2Rol2tEznK0gq2qFI_TqN3uhnu6nWdW2I4/2Omy2rJe7fXcgA5kFOXT0N0IkLRd36?= =?utf-8?q?AS7KjHv6DDFcbnBCIvyJz_GeBtS14elPAL5EY7PzfsSaMUaqgcuzo7gINGqZgsIs1?= =?utf-8?q?kQTLPSQ2WPkQP0gLNjMKbx+/p_aY7gpr0gjT+MLzKgxxS2hsyB7pME5E5C2hep6E1?= =?utf-8?q?zu0rZMIw6h/TnEO8wqk1oeDl7B3iJ_qrzfVAz6kCywOExYX1iboRUaV00AL0DiA46?= =?utf-8?q?bHszW6gydLnVt1jwlygFX2i2nutu4nBEK_uA=3D=3D_?= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3ybdr3234w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Mon, 27 May 2024 12:00:22 -0700 Received: from devvm4158.cln0.facebook.com (2620:10d:c0a8:1b::30) by mail.thefacebook.com (2620:10d:c0a9:6f::237c) with Microsoft SMTP Server id 15.2.1544.11; Mon, 27 May 2024 19:00:21 +0000 From: Vadim Fedorenko To: Vadim Fedorenko , Martin KaFai Lau , Andrii Nakryiko , "Alexei Starovoitov" , Mykola Lysenko , Jakub Kicinski CC: Vadim Fedorenko , , Subject: [PATCH bpf-next v3 1/2] bpf: add CHECKSUM_COMPLETE to bpf test progs Date: Mon, 27 May 2024 11:59:27 -0700 Message-ID: <20240527185928.1871649-1-vadfed@meta.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: RkYHWvO3YaOReyy3ChZRdIbSe5Ct2J20 X-Proofpoint-ORIG-GUID: RkYHWvO3YaOReyy3ChZRdIbSe5Ct2J20 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-27_04,2024-05-27_01,2024-05-17_01 X-Patchwork-Delegate: bpf@iogearbox.net Add special flag to validate that TC BPF program properly updates checksum information in skb. Signed-off-by: Vadim Fedorenko --- include/uapi/linux/bpf.h | 2 ++ net/bpf/test_run.c | 18 +++++++++++++++++- tools/include/uapi/linux/bpf.h | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 90706a47f6ff..f7d458d88111 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1425,6 +1425,8 @@ enum { #define BPF_F_TEST_RUN_ON_CPU (1U << 0) /* If set, XDP frames will be transmitted after processing */ #define BPF_F_TEST_XDP_LIVE_FRAMES (1U << 1) +/* If set, apply CHECKSUM_COMPLETE to skb and validate the checksum */ +#define BPF_F_TEST_SKB_CHECKSUM_COMPLETE (1U << 2) /* type for BPF_ENABLE_STATS */ enum bpf_stats_type { diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index f6aad4ed2ab2..4c21562ad526 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -977,7 +977,8 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, void *data; int ret; - if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size) + if ((kattr->test.flags & ~BPF_F_TEST_SKB_CHECKSUM_COMPLETE) || + kattr->test.cpu || kattr->test.batch_size) return -EINVAL; data = bpf_test_init(kattr, kattr->test.data_size_in, @@ -1025,6 +1026,12 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN); __skb_put(skb, size); + + if (kattr->test.flags & BPF_F_TEST_SKB_CHECKSUM_COMPLETE) { + skb->csum = skb_checksum(skb, 0, skb->len, 0); + skb->ip_summed = CHECKSUM_COMPLETE; + } + if (ctx && ctx->ifindex > 1) { dev = dev_get_by_index(net, ctx->ifindex); if (!dev) { @@ -1079,6 +1086,15 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, } convert_skb_to___skb(skb, ctx); + if (kattr->test.flags & BPF_F_TEST_SKB_CHECKSUM_COMPLETE) { + __wsum csum = skb_checksum(skb, 0, skb->len, 0); + + if (skb->csum != csum) { + ret = -EBADMSG; + goto out; + } + } + size = skb->len; /* bpf program can never convert linear skb to non-linear */ if (WARN_ON_ONCE(skb_is_nonlinear(skb))) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 90706a47f6ff..f7d458d88111 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -1425,6 +1425,8 @@ enum { #define BPF_F_TEST_RUN_ON_CPU (1U << 0) /* If set, XDP frames will be transmitted after processing */ #define BPF_F_TEST_XDP_LIVE_FRAMES (1U << 1) +/* If set, apply CHECKSUM_COMPLETE to skb and validate the checksum */ +#define BPF_F_TEST_SKB_CHECKSUM_COMPLETE (1U << 2) /* type for BPF_ENABLE_STATS */ enum bpf_stats_type { From patchwork Mon May 27 18:59:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Fedorenko X-Patchwork-Id: 13675712 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 640E2DDA9; Mon, 27 May 2024 19:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.153.30 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716836460; cv=none; b=eqvzIcwDiJz0xtlVOQa93kiyPIrsST8ukI0XGjW/+S/xzdAWRPImSsQojKidZ5ehvgYy7Z9p6c1gOe7lxZEQCZmxM4dO1+pRtxw2stywG0FID/YgCL92AsvTSYZT48fantUkEadqGJzWGPLvlhDXg7FiUEGFbIgImUcRojyT4eY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716836460; c=relaxed/simple; bh=c0wTFKp9XQXRgUFgtFgR9AuRbrYxnV5EJTEpQx/c25k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tXY+bOM+fcbmjSZ+nTpcjKxwxNsCdfUeujQKNbIqGGcnWYJ0AvO+UNd4McGNwmkI8EHwhUhdjwzPUha4Q/EXnPYUMU8wO7h1KudVILUvwd9fH6+KSL5hHfrMqLoC1hmgK5+BYIwBDe0DiAfnQ8ACndFY7mbriX5wjWoqfKmj/QA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; arc=none smtp.client-ip=67.231.153.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44RIQb8T007199; Mon, 27 May 2024 12:00:24 -0700 DKIM-Signature: =?utf-8?q?v=3D1=3B_a=3Drsa-sha256=3B_c=3Drelaxed/relaxed=3B_?= =?utf-8?q?d=3Dmeta=2Ecom=3B_h=3Dcc=3Acontent-transfer-encoding=3Acontent-ty?= =?utf-8?q?pe=3Adate=3Afrom=3Ain-reply-to=3Amessage-id=3Amime-version=3Arefe?= =?utf-8?q?rences=3Asubject=3Ato=3B_s=3Ds2048-2021-q4=3B_bh=3D7geuP4fh0kfWIQ?= =?utf-8?q?EG10bAFf8y5oNk1kPaQirayNWOM44=3D=3B_b=3DPP/8OkqGURhdvgDRtEzPLuATN?= =?utf-8?q?DLoKjQCiuN0jBlXEOkW2gdyt1fh2C6yjcssjnADwn1H_IULvEAgv4H8H/gOzJjc1X?= =?utf-8?q?GyEr9t+zt9k1YSbjIbEfOHLD7z8t6cFNJ2rARa2ozVfw+kd_w2iuOFxmx0TPVQD9X?= =?utf-8?q?gNtCjYhesqxx7fcGLmuZ4hhAdh2EWxNHKm1tyLJRpMSfosGhiu1_6mTZkq+JZ6rCa?= =?utf-8?q?Mny0LGiNWLK0pqc/gzL+HibYTH5MDi4GrHpcw0CDMNPmW8npEdIy6nL_zi4+Owe8E?= =?utf-8?q?T9xd6qAp93vmxGq7Zoo5gu6IWkQf3ASYkxdziDv6dJg5OdI4AZJ3VQwEOlA_uA=3D?= =?utf-8?q?=3D_?= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3ybdr3234w-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Mon, 27 May 2024 12:00:24 -0700 Received: from devvm4158.cln0.facebook.com (2620:10d:c0a8:1b::30) by mail.thefacebook.com (2620:10d:c0a9:6f::237c) with Microsoft SMTP Server id 15.2.1544.11; Mon, 27 May 2024 19:00:22 +0000 From: Vadim Fedorenko To: Vadim Fedorenko , Martin KaFai Lau , Andrii Nakryiko , "Alexei Starovoitov" , Mykola Lysenko , Jakub Kicinski CC: Vadim Fedorenko , , Subject: [PATCH bpf-next v3 2/2] selftests: bpf: validate CHECKSUM_COMPLETE option Date: Mon, 27 May 2024 11:59:28 -0700 Message-ID: <20240527185928.1871649-2-vadfed@meta.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527185928.1871649-1-vadfed@meta.com> References: <20240527185928.1871649-1-vadfed@meta.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: N8rjF6Oi7ZTwtRAAQkoqWuYf5bPMlzjO X-Proofpoint-ORIG-GUID: N8rjF6Oi7ZTwtRAAQkoqWuYf5bPMlzjO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-27_04,2024-05-27_01,2024-05-17_01 X-Patchwork-Delegate: bpf@iogearbox.net Adjust skb program test to run with checksum validation. Signed-off-by: Vadim Fedorenko --- .../selftests/bpf/prog_tests/test_skb_pkt_end.c | 1 + tools/testing/selftests/bpf/progs/skb_pkt_end.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/test_skb_pkt_end.c b/tools/testing/selftests/bpf/prog_tests/test_skb_pkt_end.c index ae93411fd582..09ca13bdf6ca 100644 --- a/tools/testing/selftests/bpf/prog_tests/test_skb_pkt_end.c +++ b/tools/testing/selftests/bpf/prog_tests/test_skb_pkt_end.c @@ -11,6 +11,7 @@ static int sanity_run(struct bpf_program *prog) .data_in = &pkt_v4, .data_size_in = sizeof(pkt_v4), .repeat = 1, + .flags = BPF_F_TEST_SKB_CHECKSUM_COMPLETE, ); prog_fd = bpf_program__fd(prog); diff --git a/tools/testing/selftests/bpf/progs/skb_pkt_end.c b/tools/testing/selftests/bpf/progs/skb_pkt_end.c index db4abd2682fc..3bb4451524a1 100644 --- a/tools/testing/selftests/bpf/progs/skb_pkt_end.c +++ b/tools/testing/selftests/bpf/progs/skb_pkt_end.c @@ -33,6 +33,8 @@ int main_prog(struct __sk_buff *skb) struct iphdr *ip = NULL; struct tcphdr *tcp; __u8 proto = 0; + int urg_ptr; + u32 offset; if (!(ip = get_iphdr(skb))) goto out; @@ -48,7 +50,14 @@ int main_prog(struct __sk_buff *skb) if (!tcp) goto out; - return tcp->urg_ptr; + urg_ptr = tcp->urg_ptr; + + /* Checksum validation part */ + proto++; + offset = sizeof(struct ethhdr) + offsetof(struct iphdr, protocol); + bpf_skb_store_bytes(skb, offset, &proto, sizeof(proto), BPF_F_RECOMPUTE_CSUM); + + return urg_ptr; out: return -1; }