From patchwork Fri May 24 11:06:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Fedorenko X-Patchwork-Id: 13673083 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0a-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 33265538A; Fri, 24 May 2024 11:07:23 +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=1716548845; cv=none; b=quNZ3K7n0AO/tpKJcXY743DiG5K3K/Xyyhn700XBc2tJu/JGxYz9I6by+dcabXHVmxq1PXjwNjupcvHWT4ZgPbhMDJD34Iuq2T2pghYPXKRCFm8QAPDl9vleDWVk2BWIXFo7w905Eb1FrDDp5bJBNVbNU0cawIiN20VfCaWI6Tw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716548845; c=relaxed/simple; bh=UE3jy3zFh/c6NQWrovwjNIcisNg3j4klg8dpXsoqg5M=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=kPicNe8vVVK0UKrOh4mKHE3uozMVkIhy0htUqAdRaZB9NlOFM2LRFH4H7Gk4N7JMxsUH/8iBlWxRs0SdKfJRaARqPlS0F0WdnCld/7wc6NDribN3GcJC8GNn6CV7P7ebZvC+c0J4+gFUqMUh4L7ePE4GbUCwJfcloLdd8QFyMwo= 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; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=Q67TJrCK; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="Q67TJrCK" Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.17.1.19/8.17.1.19) with ESMTP id 44O7rHcS012621; Fri, 24 May 2024 04:07:18 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=s2048-2021-q4; bh=4wVN9uy2SQb3ooGo+DAW3A2Lx0NK5VTY8+0sdFaXHwE=; b=Q67TJrCKqDHt4S3cQ1KPSflEtuttdTLgFeJHWIco40NrWppuiudO1XKuIkZ49T1QMnGq fI8+GPNtZubKrOeCFz8LnrF765VJcAB+TlbNIlyqVws8CUo26r2Ng9DfOJ3tUgPUdSZy j0NcfMV/E+EpgjCfludph4dQVG9Pbd22IBBJKZskqdiQl53MPfU3lj6JxDbuZABqZmGa B3nHzukgBau4cIhRkcZrqN7yoLHd4aSGnLsEb+MsqYpMjOIKaAQo973nKPEfjKO57ZQn N36A1P9bgp44F9iW9y7Yg/Aa3xplDQ9HkpLrknYfwVJBmkhw0jUp/o+DupwnjM0Aa60n 4g== Received: from mail.thefacebook.com ([163.114.134.16]) by m0001303.ppops.net (PPS) with ESMTPS id 3yapw68tm5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 24 May 2024 04:07:17 -0700 Received: from devvm4158.cln0.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c08b:78::2ac9) with Microsoft SMTP Server id 15.2.1544.11; Fri, 24 May 2024 11:07:14 +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 v2 1/2] bpf: add CHECKSUM_COMPLETE to bpf test progs Date: Fri, 24 May 2024 04:06:58 -0700 Message-ID: <20240524110659.3612077-1-vadfed@meta.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: qyg0uD1H-3zvb-KtnIr0TXVWDHN6J97b X-Proofpoint-GUID: qyg0uD1H-3zvb-KtnIr0TXVWDHN6J97b 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-24_04,2024-05-23_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 | 17 ++++++++++++++++- tools/include/uapi/linux/bpf.h | 2 ++ 3 files changed, 20 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..c6189bb9bf67 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 = -EINVAL; + 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 BIT(2) /* type for BPF_ENABLE_STATS */ enum bpf_stats_type { From patchwork Fri May 24 11:06:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Fedorenko X-Patchwork-Id: 13673084 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 D355442078; Fri, 24 May 2024 11:07:24 +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=1716548846; cv=none; b=heyrKxMDIEHm27jnvV1kwnYF+TtUpMwvsqnO8F/WnuHcdyauQccn1y7x/VJ+zqkifkKIrqgLmWB2nJYg+et2L/9vo9xyAS1iLhcKQciVcsw1TUl8tLEnpZx0bkt9rP28tzPcm07ixUrhE9TZtb2Tso+qRLWcePC9EzYaWG6WBx4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716548846; c=relaxed/simple; bh=c0wTFKp9XQXRgUFgtFgR9AuRbrYxnV5EJTEpQx/c25k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DUAmyIKn5LdP1+RaE8dYtP/BUx9a9uAs0/eJlPhstoyZ110TdwVWWF8OA1OXn36Y3hTnwUwdIfiA7oWVKat1fqe1aQ7acucMoMiC7J+zWqfKWHk4N5LwsSOr9RnvdSTJ6fhoojtx6weH+dh56uV3rC57u1ZypWQcj0sVWu36kBU= 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; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=gSyW0ChT; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="gSyW0ChT" Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44NLuDih024404; Fri, 24 May 2024 04:07:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=s2048-2021-q4; bh=7geuP4fh0kfWIQEG10bAFf8y5oNk1kPaQirayNWOM44=; b=gSyW0ChTNZZ35+nDi3kwoUmzSNIAm95ciUh3TbCZg7Ee8HhXgBVcB7kNtRpKMzmes8wH Do62wydCh2US3wT7Lr53EuQUpwOKe+MXBjapYmDZX3EL2nAUE9emdlWWLpWD7ItvoECm ClaxWCGwRBw7M9qJ+mou6SP74QBBzWG220j/ZS+3AJH6bT7MvONddGthwRA4PyYW1A43 ScuUJ4TDuTuoldKjLRtCJ/XdFY0rNqFVD25v0ZQ91TbkdkXMXQYkTLu/brJAKqQ+W9s8 g4E3ePXQ9JLJzwhm6/OyCSqy3K2v/DppgybAm30pqu++yHUiv2KSnAPTmKAdWq+ZFYlT LQ== Received: from mail.thefacebook.com ([163.114.134.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3y9xf4sf0n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 24 May 2024 04:07:20 -0700 Received: from devvm4158.cln0.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c08b:78::2ac9) with Microsoft SMTP Server id 15.2.1544.11; Fri, 24 May 2024 11:07:16 +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 v2 2/2] selftests: bpf: validate CHECKSUM_COMPLETE option Date: Fri, 24 May 2024 04:06:59 -0700 Message-ID: <20240524110659.3612077-2-vadfed@meta.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240524110659.3612077-1-vadfed@meta.com> References: <20240524110659.3612077-1-vadfed@meta.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: BQWtFhvrcmBDTI_P6unpYnXPktkhWNWs X-Proofpoint-GUID: BQWtFhvrcmBDTI_P6unpYnXPktkhWNWs 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-24_04,2024-05-23_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; }