From patchwork Thu Oct 24 20:12:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849626 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4865F1FC7FE for ; Thu, 24 Oct 2024 20:13:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800803; cv=none; b=OTWM7TncWOO5zSdsz9QJuGicp8FS4dmku+kRSIPIOxapMcdLgzMWR9FrIrXdjJ7XRv+XE779PeYmZL5clcL56l0JcBvVxMPd+TCvqYmT2e0U7UyjsUogKC1f20rlSQItMEyFvsflW8c6EEGW7tXp3L1AsHb40NWm0bmn42VC51o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800803; c=relaxed/simple; bh=XTpMv+VF8cOdRbUAlZ5ZznC9z7BQObqwvKwaZgZ+cbs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TmN5NeJdGKiZCI5APmq7c/ct+l6dXkQVAeqAXkxX0SyDhEAr6o6dOU08yfMBdtsI2hU0PQzt+V1QzxEFwXg8vICcjKfUyWbqt6tmOzYqneJOk30oeUPeIFJFX+6jCyEndU/71HtTIoLq5wTBeMt+/3M+HmAMNIVIkOTH/7HZ8Kg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=VR51Lljd; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="VR51Lljd" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7b15416303aso86455185a.1 for ; Thu, 24 Oct 2024 13:13:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729800799; x=1730405599; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sem2IxJaLw9T/IpmjkFV4In0NxMLK+X+ObaA09ucrMY=; b=VR51LljdIVTKbide2JrZyWUvtrZcPs76byXWaMBDwnyBoZlSRlTCqhTFI4BaFdN/Mv 0K/0mL3Z50YkO6T8kMZwi5o2+amUUs0vpYaKFZU9UmMErX/3FK3NtQxqx+Mb00IWIZ9f 2zD0THoeCRcPGDxnu25hjHswko6Y4tzYKIRqDeSqdq6g1myrtPyzWPR4khW2tjeEQTEb 4zx6Z3Jc4K45W/6GS6yNd50YlFEWtsM7YRCyvu0oGnun1Phrz7M7RQiGsqJft5o2pikx SVWYCn3KM850+G3higecIRuZBWkzwXcCaVw6vPooxRQEfb2pjnCG7NIeyPJG+LajUlnY ZheA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729800799; x=1730405599; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sem2IxJaLw9T/IpmjkFV4In0NxMLK+X+ObaA09ucrMY=; b=EoCvbaOBHw9/tNtyXKd75L6piwbNeOfzE7zz1mpA5xf/qHNxd1ncKrdAzHbv/qzL2a 46GoxYbZqe+eBmEAMeYpqKNWSnJvHZXXWUQHKsuBpDNLw1TSi+9xJf6yY+l2QONAPbo1 ZPzNAV+CTkYy/mL06FZfrp+z0ltj/5D7MPVCDElMlnphfRKd+FKPbS6t3aUs7hqnZ4rE AIgoDGthYhOC8jmlFhsNgDIhZ+or36t62xf7aDsnLb7Oi3CE/cfxK7jaFLEt7vqVdiLZ KPBgRi8CEG26Gf4Cpzm/UqAKz8gGCrqvnivgMhC0auNyVS+8hKQOQTAHf5Mxu58moPo8 Vtiw== X-Gm-Message-State: AOJu0Ywm55gX4UCmmb4r4tcQpOpJfsFqSr36Xp7vhNXWpc5yP8GdLm/F 5/sV620JjnV9lHyCpJgmXaGlBD5Z+kDkzi3fU3HsD6/iLbrmx8LaS7CvI7EyNEw+jkeD7YO/qy1 a X-Google-Smtp-Source: AGHT+IHgzHo5DMf4DntM1vXreBcOxEAzqm1HxEDL99lbldhMAbxSM1gSrj85zqYqGaYP7UVtKEVIbg== X-Received: by 2002:a05:620a:1793:b0:7a9:bc46:2d26 with SMTP id af79cd13be357-7b17e540493mr979266685a.13.1729800798790; Thu, 24 Oct 2024 13:13:18 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.212.111]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b165a037fbsm518952785a.60.2024.10.24.13.13.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:13:18 -0700 (PDT) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: martin.lau@linux.dev, daniel@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, zijianzhang@bytedance.com, cong.wang@bytedance.com Subject: [PATCH v2 bpf-next/net 1/8] selftests/bpf: Add txmsg_pass to pull/push/pop in test_sockmap Date: Thu, 24 Oct 2024 20:12:59 +0000 Message-Id: <20241024201306.3429177-2-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024201306.3429177-1-zijianzhang@bytedance.com> References: <20241024201306.3429177-1-zijianzhang@bytedance.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Zijian Zhang Add txmsg_pass to test_txmsg_pull/push/pop. If txmsg_pass is missing, tx_prog will be NULL, and no program will be attached to the sockmap. As a result, pull/push/pop are never invoked. Fixes: 328aa08a081b ("bpf: Selftests, break down test_sockmap into subtests") Signed-off-by: Zijian Zhang --- tools/testing/selftests/bpf/test_sockmap.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index 075c93ed143e..0f065273fde3 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -1596,11 +1596,13 @@ static void test_txmsg_cork_hangs(int cgrp, struct sockmap_options *opt) static void test_txmsg_pull(int cgrp, struct sockmap_options *opt) { /* Test basic start/end */ + txmsg_pass = 1; txmsg_start = 1; txmsg_end = 2; test_send(opt, cgrp); /* Test >4k pull */ + txmsg_pass = 1; txmsg_start = 4096; txmsg_end = 9182; test_send_large(opt, cgrp); @@ -1629,11 +1631,13 @@ static void test_txmsg_pull(int cgrp, struct sockmap_options *opt) static void test_txmsg_pop(int cgrp, struct sockmap_options *opt) { /* Test basic pop */ + txmsg_pass = 1; txmsg_start_pop = 1; txmsg_pop = 2; test_send_many(opt, cgrp); /* Test pop with >4k */ + txmsg_pass = 1; txmsg_start_pop = 4096; txmsg_pop = 4096; test_send_large(opt, cgrp); @@ -1662,11 +1666,13 @@ static void test_txmsg_pop(int cgrp, struct sockmap_options *opt) static void test_txmsg_push(int cgrp, struct sockmap_options *opt) { /* Test basic push */ + txmsg_pass = 1; txmsg_start_push = 1; txmsg_end_push = 1; test_send(opt, cgrp); /* Test push 4kB >4k */ + txmsg_pass = 1; txmsg_start_push = 4096; txmsg_end_push = 4096; test_send_large(opt, cgrp); @@ -1687,6 +1693,7 @@ static void test_txmsg_push(int cgrp, struct sockmap_options *opt) static void test_txmsg_push_pop(int cgrp, struct sockmap_options *opt) { + txmsg_pass = 1; txmsg_start_push = 1; txmsg_end_push = 10; txmsg_start_pop = 5; From patchwork Thu Oct 24 20:13:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849627 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF7A522B642 for ; Thu, 24 Oct 2024 20:13:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800804; cv=none; b=LcEkZO3bE5NSIU9+k8RB+AI3zTnCKigWctcR+4q/TfEh+SwYsvKSW1Wo/WeoLtetCLr1hivFQb+5emkvlKnz+Pbq9TNBcPcF7IQi0KUUHbezjfhBkqtx3fE7wRDIEwp50xU0fZHTSMAOYJ/+zkmP9LCN1b62vuQho3j0V4jvu7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800804; c=relaxed/simple; bh=CuN2X17yctDLixboLYTLUEjwjVE+eww9uE4fmUoGdGI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ayGqg54bblTIDZ3U2GR9WF34SDoj8F4zQOP7O1XUlcbkuQ7wxHQuCVvh5xVkNSPTVQ+31s6Fbd6NaNPbaj1S43Hrb+Veika5aQVTWEvCzsucuzxtG5xik9mKIgVC09quLPcuTLMzBpgNoSQcjFrbNCOMlpDBd3tfOp4Hi/7/L1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=LaJfBxZe; arc=none smtp.client-ip=209.85.222.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="LaJfBxZe" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-7b13fe8f4d0so90211085a.0 for ; Thu, 24 Oct 2024 13:13:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729800801; x=1730405601; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OMbNSwQ9gBAb/wARsLAJ1QkVS6qPK5BqL+4VBJSggzQ=; b=LaJfBxZehJ8xWEN3Oovh2bP0QlcivMWlk4Y3gdu4/uo0kkI1kObckczCCuecxXCnhD E5ikN0lEWnR+MbQJmKWNEYOw5lqo0cb0j7o83R8jUtxfEW/TYykfYZReQYPpVzPj7x8W J2yDF7Cl5OPJCMpqZOBC/yvV7FwKAunXbv1nJVPRL4VCOuV4qEn5ApzXfiW6Tmf8zHSy +7ne/cVdwWTa0k8NWdn3Sla+Ci8nHeds67HYnqvow0+D2/dZrPmPf4I2BfLtxeXsXivw HtdtAHp/UKrTOsY6nrH8DyDDm8FQUls7LZhHbSd9RddCIvRwOXxPq4bthkWnEbTZVnMA QoRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729800801; x=1730405601; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OMbNSwQ9gBAb/wARsLAJ1QkVS6qPK5BqL+4VBJSggzQ=; b=XIhA4NF7XhkwHVL6Hw82MRTkW3ivMFKL5xx4jWOPjW5H9xXBj7SiDH0OS58dBGJZm5 3uOAfT9cfQ5SPuMBo5tInZrAa3IYZTqv+RzAzmSX9HVpDHHQiTzFPVga9vwS3x+FQR4s xtDjDE5+IMxrHX7M4PUB/2FuZzgkb6ukMudBb5osKh6oqQFs6gGAU7cZ5HiuAe6lt/cb mHQoLVowce3RszTvDX+fM1APCbfrVC5ZTzwDqgawpP1M74FBQTQf55PaKBdCCxlntL7C XDgCdv8mJEvn1tjVAeA/d0hEj6IjWBRzue6vfdJYyZnwLwWYK8G6wW3KRM3cz9KJfxke 9tvA== X-Gm-Message-State: AOJu0Yzj5KzurtOaapsiOx5eE/Jx9xvMIEZsjIT0dkLqAxNjuidKp9LV XTOWJiOAdLReyRFzYeOzVyafUhmVVrmkZ/CONGXIjrQC642h/NqE9FZSH0Kzv8l+Rq6jWtb0Ye+ p X-Google-Smtp-Source: AGHT+IG7OIKBJoU+WQY2fIC49YOfoGaXouMdSYOlaG+5j0mI6Yn0vdeoMdIyzck7o/GlmW3EtYNDGQ== X-Received: by 2002:a05:620a:1791:b0:7b1:517b:ac1e with SMTP id af79cd13be357-7b17e5bc60fmr970901485a.59.1729800801459; Thu, 24 Oct 2024 13:13:21 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.212.111]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b165a037fbsm518952785a.60.2024.10.24.13.13.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:13:21 -0700 (PDT) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: martin.lau@linux.dev, daniel@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, zijianzhang@bytedance.com, cong.wang@bytedance.com Subject: [PATCH v2 bpf-next/net 2/8] selftests/bpf: Fix SENDPAGE data logic in test_sockmap Date: Thu, 24 Oct 2024 20:13:00 +0000 Message-Id: <20241024201306.3429177-3-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024201306.3429177-1-zijianzhang@bytedance.com> References: <20241024201306.3429177-1-zijianzhang@bytedance.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Zijian Zhang In the SENDPAGE test, "opt->iov_length * cnt" size of data will be sent cnt times by sendfile. 1. In push/pop tests, they will be invoked cnt times, for the simplicity of msg_verify_data, change chunk_sz to iov_length 2. Change iov_length in test_send_large from 1024 to 8192. We have pop test where txmsg_start_pop is 4096. 4096 > 1024, an error will be returned. Fixes: 328aa08a081b ("bpf: Selftests, break down test_sockmap into subtests") Signed-off-by: Zijian Zhang --- tools/testing/selftests/bpf/test_sockmap.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index 0f065273fde3..1d59bed90d80 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -420,16 +420,18 @@ static int msg_loop_sendpage(int fd, int iov_length, int cnt, { bool drop = opt->drop_expected; unsigned char k = 0; + int i, j, fp; FILE *file; - int i, fp; file = tmpfile(); if (!file) { perror("create file for sendpage"); return 1; } - for (i = 0; i < iov_length * cnt; i++, k++) - fwrite(&k, sizeof(char), 1, file); + for (i = 0; i < cnt; i++, k = 0) { + for (j = 0; j < iov_length; j++, k++) + fwrite(&k, sizeof(char), 1, file); + } fflush(file); fseek(file, 0, SEEK_SET); @@ -623,7 +625,9 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, * This is really only useful for testing edge cases in code * paths. */ - total_bytes = (float)iov_count * (float)iov_length * (float)cnt; + total_bytes = (float)iov_length * (float)cnt; + if (!opt->sendpage) + total_bytes *= (float)iov_count; if (txmsg_apply) txmsg_pop_total = txmsg_pop * (total_bytes / txmsg_apply); else @@ -701,7 +705,7 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, if (data) { int chunk_sz = opt->sendpage ? - iov_length * cnt : + iov_length : iov_length * iov_count; errno = msg_verify_data(&msg, recv, chunk_sz, &k, &bytes_cnt); @@ -1466,8 +1470,8 @@ static void test_send_many(struct sockmap_options *opt, int cgrp) static void test_send_large(struct sockmap_options *opt, int cgrp) { - opt->iov_length = 256; - opt->iov_count = 1024; + opt->iov_length = 8192; + opt->iov_count = 32; opt->rate = 2; test_exec(cgrp, opt); } From patchwork Thu Oct 24 20:13:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849628 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 207F72010FA for ; Thu, 24 Oct 2024 20:13:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800807; cv=none; b=BYGtK4O9ioZJtb7lYDeIWF0rxp+Er1zSZG8BF3DyY42ttTSuWFAJD4VJx4agVV+cYcD3Cei2OZYD0MnnJARnv0DuANuXu5uVRDoq7KDEv3Ko7IAdT/Mi+jrygnFdJTsOezorSnfQhOVjrAUqmVgmjIwKKpxpjRTO10HZAjFG4LA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800807; c=relaxed/simple; bh=y5xG5PZaDIdA5ZRhc0eCzfqeojjrLwjp1ZGtaVGyGM0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HTK8UjQGEax3uoWnbS8H1y5V7HmEAKY4Ux0bb3jHljkdgIZe50ZhjkqhDjiBKos0M9GW5Nii3VdwBLp+N22dtnzMJKpdWO4eiJY03iAubK/xKQDSz+ncC1NEIC6YpxEnbxgcd90PhhKllFpQ76Jg/peUVn3uhfeVaiPt/Vf+utM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=MWCiMd0S; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="MWCiMd0S" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7b14077ec5aso224701685a.1 for ; Thu, 24 Oct 2024 13:13:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729800804; x=1730405604; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mEFUQiY7ce/KeA/4yaA7IZEeCrfS6Isv4u/QJ5N6wws=; b=MWCiMd0SJOUjqpGXpvy3pnkYpUdNLkBC+zP8wAAoxpFBja0xZY47nqD1R5sEQ4ZATZ ihGGVGVr6iwmuamZ2mLwXeavdaqNn6jpLnsCDF+B5FzL96orV8C7A0jk7+AApyHenQ5B m6E4nX2fjJTnApHabDhTJJ/aKI6x42xbXvbXgr586XjPwu6eyqclxOXUUFjUeSBd5UHd YVyZyzlmjjHiPOGfAuMRYxXiTVWoalPvAVDvgpAlrhZaM5CfUHFUh7bXz1kUhyI5h+cH K27HfC2YLzra3IC21qFsfDm1NVH174jr/1PucCIfSPZxIuOcP8OtwiLgw7QdA4n/Z5wc IlKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729800804; x=1730405604; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mEFUQiY7ce/KeA/4yaA7IZEeCrfS6Isv4u/QJ5N6wws=; b=uCMfesuN63liqqlTqKTnUWoy/Kw4pjdcO5sFFf4Je9agyBi4g2YS7Jeu7ViXwcA/yi bbQ/vJ2qQWVwgiQv6H1iJltkAd+Dr5C6S2yB4Ov3C5G3g0V5Z5wVMVGtIWBxNb8kHE/0 m5kLXpPLZ93oSMcLYL1Qsr6VDJhEJQP6HbjCD99G3I5O9vEhWY5IPAJXKdFCh8tE9pqs FWI4TqF13mlh83eGJ/OjQm0q8M9QbMsQ/xF8Owk6zBJEvRjTdCKrO5l5JEtW/44Otl4Z ylsxQsccKlXP7n4ZwFdFPB/laxnnD++gP1XX/+znwh19aKpof5+VKklxbNolY6G95k+C FJEQ== X-Gm-Message-State: AOJu0YywytmP6xR/KIK71uNxC06rf3RT1WMXwplU9OjsDUrLzUPUsuLv s2TlMo0kBkW+IxOQr/VH8z6JYf5n2tReTtfGp5lvJPm4auhi0+O6D+6WUZtMNMKYsjvq1HBVjq/ e X-Google-Smtp-Source: AGHT+IHLT4QnGiUWlKsW9FMXZcD4Qbfl68tuAix+jOYkP5dfe5nZ55DAyVJMgTRvOhLofmyjNZqrDQ== X-Received: by 2002:a05:620a:424e:b0:7ac:aad3:9135 with SMTP id af79cd13be357-7b1865e662fmr516052785a.15.1729800803792; Thu, 24 Oct 2024 13:13:23 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.212.111]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b165a037fbsm518952785a.60.2024.10.24.13.13.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:13:23 -0700 (PDT) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: martin.lau@linux.dev, daniel@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, zijianzhang@bytedance.com, cong.wang@bytedance.com Subject: [PATCH v2 bpf-next/net 3/8] selftests/bpf: Fix total_bytes in msg_loop_rx in test_sockmap Date: Thu, 24 Oct 2024 20:13:01 +0000 Message-Id: <20241024201306.3429177-4-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024201306.3429177-1-zijianzhang@bytedance.com> References: <20241024201306.3429177-1-zijianzhang@bytedance.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Zijian Zhang total_bytes in msg_loop_rx should also take push into account, otherwise total_bytes will be a smaller value, which makes the msg_loop_rx end early. Besides, total_bytes has already taken pop into account, so we don't need to subtract some bytes from iov_buf in sendmsg_test. The additional subtraction may make total_bytes a negative number, and msg_loop_rx will just end without checking anything. Fixes: 18d4e900a450 ("bpf: Selftests, improve test_sockmap total bytes counter") Fixes: d69672147faa ("selftests, bpf: Add one test for sockmap with strparser") Signed-off-by: Zijian Zhang --- tools/testing/selftests/bpf/test_sockmap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index 1d59bed90d80..5f4558f1f004 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -606,8 +606,8 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, } clock_gettime(CLOCK_MONOTONIC, &s->end); } else { + float total_bytes, txmsg_pop_total, txmsg_push_total; int slct, recvp = 0, recv, max_fd = fd; - float total_bytes, txmsg_pop_total; int fd_flags = O_NONBLOCK; struct timeval timeout; unsigned char k = 0; @@ -628,10 +628,14 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, total_bytes = (float)iov_length * (float)cnt; if (!opt->sendpage) total_bytes *= (float)iov_count; - if (txmsg_apply) + if (txmsg_apply) { + txmsg_push_total = txmsg_end_push * (total_bytes / txmsg_apply); txmsg_pop_total = txmsg_pop * (total_bytes / txmsg_apply); - else + } else { + txmsg_push_total = txmsg_end_push * cnt; txmsg_pop_total = txmsg_pop * cnt; + } + total_bytes += txmsg_push_total; total_bytes -= txmsg_pop_total; err = clock_gettime(CLOCK_MONOTONIC, &s->start); if (err < 0) @@ -800,8 +804,6 @@ static int sendmsg_test(struct sockmap_options *opt) rxpid = fork(); if (rxpid == 0) { - if (txmsg_pop || txmsg_start_pop) - iov_buf -= (txmsg_pop - txmsg_start_pop + 1); if (opt->drop_expected || txmsg_ktls_skb_drop) _exit(0); From patchwork Thu Oct 24 20:13:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849629 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B449922B642 for ; Thu, 24 Oct 2024 20:13:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800809; cv=none; b=bJO1OZP1KtPM9WzZrA1lFPOToG+T4hL0GMK6nMTzUsPHj2re+VKq9wOoyKEc5NxlgWw1br4+mOxDk3jGJu3xnhuYsrx/H1njqlHI4MYAzUivbsKPl7lTtbMIMjcHzAirxE2/rYPLPjqaD+ieobGlMeTHN/hR2BODuVjl+PuKfeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800809; c=relaxed/simple; bh=eb8puX70Jevci/jH+kFlG74v8H4lVm245VUWlkHYLkc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Id2UcvHaIOkooz3VRNfQJejE2HpqlcNO2ZhbHgMYr+IfxoivNGEW3c5Vr0HVFgJn9DuYUNcVd6b3sXBw9GcWONZOMP0LyiJ+5JDSYi44pRy7YeP+qvgs1SspQ7FdLo66Pt/0RyyAJU8U9GAHWMUvVwDGhFzdnxfiSnaUmUel3hs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=kNo+Yd07; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="kNo+Yd07" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7b1601e853eso90580185a.2 for ; Thu, 24 Oct 2024 13:13:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729800805; x=1730405605; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4K+TwNwMyKCU5VO2n/DGvMfeeWGd67kJlM6/di+nJ0A=; b=kNo+Yd07cDfKfbyPN7CWT99YjA7lUuba1plumVZtscuPkQ4b1tmGJI162hhGyKWKwB kX7ruY61yP5NAL9ojdkxvnPVBjv2UhYfNE3+qM/icXf/jaXpwfD7xGSvyQ0V8pwL2Mou NmnpvqfzALYfYrHeKfqxB2Zo+eWito+RtyIBxifSl1GBflcNwROe842nEQin53ygyDEC C74OfXz9JTPbNOaO6K8fkcV7Vv5zexrQuMXrZjTt730kE46g/s0mecAJJ2rfpCnIt+Na JFJzl+EQqPDOjJVoIzBFBT4HaQWp1ays65AxiuEpz3VwmOj2LOkGMfjwlau5Fhm+ZNgW SsPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729800805; x=1730405605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4K+TwNwMyKCU5VO2n/DGvMfeeWGd67kJlM6/di+nJ0A=; b=GHKui7t+jRtrbIzAxC8oFvvUEj0ww1x8j9kvkfTVqceTEPjkOXnDe0kYofyKHSf0u0 bhq3syrzlubWtQe4WE4yJsLj/xg7m0lHlJmJ8BSHuqBvdXJmtpe+3zXM90PqFxrzKxkU j6D7xTg4lQEA9N0/wy6xgyVHf1QAbXShuqLBhQZ1OrRsh6iz+R0U2u+d7uWQwn2BVhG4 VsYaGMuCAD/9447ibP0HR3GQROXlGJc5pKIfQPS8G5MmRSsLPKL3IjbzC86aIRjmt51k k9tHE+c99MIzS0kGTA+ilL3FQfDkk0RcVc9VuwVp5GDGKEGnnKSWwycskhRDAWFPhBBd oatQ== X-Gm-Message-State: AOJu0YwVrkrbgV1p990UnAdbRd2wJSvmbc0pEBYhLqrocS9df9IG1dE6 5Zr4TfkpIlYw8eTQoA5J8v9T9I5ThynHfeetPvyd8PztR8h/BDB5PRfaFr0ZRKCSbr41q7e2AKK E X-Google-Smtp-Source: AGHT+IFEgKfhCEmesPvHB9hE2cW137spd3oqQxN2Vy0LNCYFyy7Q35CWxQgxbEj+QGHhZ8ZmLOHDWw== X-Received: by 2002:a05:620a:19a1:b0:7a9:c333:c559 with SMTP id af79cd13be357-7b17e5acba8mr841194885a.48.1729800805324; Thu, 24 Oct 2024 13:13:25 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.212.111]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b165a037fbsm518952785a.60.2024.10.24.13.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:13:24 -0700 (PDT) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: martin.lau@linux.dev, daniel@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, zijianzhang@bytedance.com, cong.wang@bytedance.com Subject: [PATCH v2 bpf-next/net 4/8] selftests/bpf: Add push/pop checking for msg_verify_data in test_sockmap Date: Thu, 24 Oct 2024 20:13:02 +0000 Message-Id: <20241024201306.3429177-5-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024201306.3429177-1-zijianzhang@bytedance.com> References: <20241024201306.3429177-1-zijianzhang@bytedance.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Zijian Zhang Add push/pop checking for msg_verify_data in test_sockmap, except for pop/push with cork tests, in these tests the logic will be different. 1. With corking, pop/push might not be invoked in each sendmsg, it makes the layout of the received data difficult 2. It makes it hard to calculate the total_bytes in the recvmsg Temporarily skip the data integrity test for these cases now, added a TODO Fixes: ee9b352ce465 ("selftests/bpf: Fix msg_verify_data in test_sockmap") Signed-off-by: Zijian Zhang --- tools/testing/selftests/bpf/test_sockmap.c | 106 ++++++++++++++++++++- 1 file changed, 101 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index 5f4558f1f004..61a747afcd05 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -88,6 +88,10 @@ int ktls; int peek_flag; int skb_use_parser; int txmsg_omit_skb_parser; +int verify_push_start; +int verify_push_len; +int verify_pop_start; +int verify_pop_len; static const struct option long_options[] = { {"help", no_argument, NULL, 'h' }, @@ -514,12 +518,41 @@ static int msg_alloc_iov(struct msghdr *msg, return -ENOMEM; } -/* TODO: Add verification logic for push, pull and pop data */ +/* In push or pop test, we need to do some calculations for msg_verify_data */ +static void msg_verify_date_prep(void) +{ + int push_range_end = txmsg_start_push + txmsg_end_push - 1; + int pop_range_end = txmsg_start_pop + txmsg_pop - 1; + + if (txmsg_end_push && txmsg_pop && + txmsg_start_push <= pop_range_end && txmsg_start_pop <= push_range_end) { + /* The push range and the pop range overlap */ + int overlap_len; + + verify_push_start = txmsg_start_push; + verify_pop_start = txmsg_start_pop; + if (txmsg_start_push < txmsg_start_pop) + overlap_len = min(push_range_end - txmsg_start_pop + 1, txmsg_pop); + else + overlap_len = min(pop_range_end - txmsg_start_push + 1, txmsg_end_push); + verify_push_len = max(txmsg_end_push - overlap_len, 0); + verify_pop_len = max(txmsg_pop - overlap_len, 0); + } else { + /* Otherwise */ + verify_push_start = txmsg_start_push; + verify_pop_start = txmsg_start_pop; + verify_push_len = txmsg_end_push; + verify_pop_len = txmsg_pop; + } +} + static int msg_verify_data(struct msghdr *msg, int size, int chunk_sz, - unsigned char *k_p, int *bytes_cnt_p) + unsigned char *k_p, int *bytes_cnt_p, + int *check_cnt_p, int *push_p) { - int i, j, bytes_cnt = *bytes_cnt_p; + int bytes_cnt = *bytes_cnt_p, check_cnt = *check_cnt_p, push = *push_p; unsigned char k = *k_p; + int i, j; for (i = 0, j = 0; i < msg->msg_iovlen && size; i++, j = 0) { unsigned char *d = msg->msg_iov[i].iov_base; @@ -538,6 +571,37 @@ static int msg_verify_data(struct msghdr *msg, int size, int chunk_sz, } for (; j < msg->msg_iov[i].iov_len && size; j++) { + if (push > 0 && + check_cnt == verify_push_start + verify_push_len - push) { + int skipped; +revisit_push: + skipped = push; + if (j + push >= msg->msg_iov[i].iov_len) + skipped = msg->msg_iov[i].iov_len - j; + push -= skipped; + size -= skipped; + j += skipped - 1; + check_cnt += skipped; + continue; + } + + if (verify_pop_len > 0 && check_cnt == verify_pop_start) { + bytes_cnt += verify_pop_len; + check_cnt += verify_pop_len; + k += verify_pop_len; + + if (bytes_cnt == chunk_sz) { + k = 0; + bytes_cnt = 0; + check_cnt = 0; + push = verify_push_len; + } + + if (push > 0 && + check_cnt == verify_push_start + verify_push_len - push) + goto revisit_push; + } + if (d[j] != k++) { fprintf(stderr, "detected data corruption @iov[%i]:%i %02x != %02x, %02x ?= %02x\n", @@ -545,15 +609,20 @@ static int msg_verify_data(struct msghdr *msg, int size, int chunk_sz, return -EDATAINTEGRITY; } bytes_cnt++; + check_cnt++; if (bytes_cnt == chunk_sz) { k = 0; bytes_cnt = 0; + check_cnt = 0; + push = verify_push_len; } size--; } } *k_p = k; *bytes_cnt_p = bytes_cnt; + *check_cnt_p = check_cnt; + *push_p = push; return 0; } @@ -612,6 +681,8 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, struct timeval timeout; unsigned char k = 0; int bytes_cnt = 0; + int check_cnt = 0; + int push = 0; fd_set w; fcntl(fd, fd_flags); @@ -637,6 +708,10 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, } total_bytes += txmsg_push_total; total_bytes -= txmsg_pop_total; + if (data) { + msg_verify_date_prep(); + push = verify_push_len; + } err = clock_gettime(CLOCK_MONOTONIC, &s->start); if (err < 0) perror("recv start time"); @@ -712,7 +787,8 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, iov_length : iov_length * iov_count; - errno = msg_verify_data(&msg, recv, chunk_sz, &k, &bytes_cnt); + errno = msg_verify_data(&msg, recv, chunk_sz, &k, &bytes_cnt, + &check_cnt, &push); if (errno) { perror("data verify msg failed"); goto out_errno; @@ -722,7 +798,9 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, recvp, chunk_sz, &k, - &bytes_cnt); + &bytes_cnt, + &check_cnt, + &push); if (errno) { perror("data verify msg_peek failed"); goto out_errno; @@ -1636,6 +1714,8 @@ static void test_txmsg_pull(int cgrp, struct sockmap_options *opt) static void test_txmsg_pop(int cgrp, struct sockmap_options *opt) { + bool data = opt->data_test; + /* Test basic pop */ txmsg_pass = 1; txmsg_start_pop = 1; @@ -1654,6 +1734,12 @@ static void test_txmsg_pop(int cgrp, struct sockmap_options *opt) txmsg_pop = 2; test_send_many(opt, cgrp); + /* TODO: Test for pop + cork should be different, + * - It makes the layout of the received data difficult + * - It makes it hard to calculate the total_bytes in the recvmsg + * Temporarily skip the data integrity test for this case now. + */ + opt->data_test = false; /* Test pop + cork */ txmsg_redir = 0; txmsg_cork = 512; @@ -1667,10 +1753,13 @@ static void test_txmsg_pop(int cgrp, struct sockmap_options *opt) txmsg_start_pop = 1; txmsg_pop = 2; test_send_many(opt, cgrp); + opt->data_test = data; } static void test_txmsg_push(int cgrp, struct sockmap_options *opt) { + bool data = opt->data_test; + /* Test basic push */ txmsg_pass = 1; txmsg_start_push = 1; @@ -1689,12 +1778,19 @@ static void test_txmsg_push(int cgrp, struct sockmap_options *opt) txmsg_end_push = 2; test_send_many(opt, cgrp); + /* TODO: Test for push + cork should be different, + * - It makes the layout of the received data difficult + * - It makes it hard to calculate the total_bytes in the recvmsg + * Temporarily skip the data integrity test for this case now. + */ + opt->data_test = false; /* Test push + cork */ txmsg_redir = 0; txmsg_cork = 512; txmsg_start_push = 1; txmsg_end_push = 2; test_send_many(opt, cgrp); + opt->data_test = data; } static void test_txmsg_push_pop(int cgrp, struct sockmap_options *opt) From patchwork Thu Oct 24 20:13:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849630 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68EB41FF02C for ; Thu, 24 Oct 2024 20:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800810; cv=none; b=N7ZThyYRPDZmzpe+GWrYWivVD6x6fs4R3QvCbQfTpgpcdjdkWfgHF3er3i7ooGU1nG9VfUUIsVkplmhx3o6kGzV1VDykfC71wWu76FmAuxgjEZWXoyYh0SpJBzbb8FFvAwMSzM6Mjt4xm1lpRfdi0ki5fzTA0YYVQqjh90hh9BU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800810; c=relaxed/simple; bh=DWOwti3vm2u8IiCa72HOjYzsSxbb+cx9lsbchIICfoE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LnpU3Qv8Ri9z9MzoUcQV3B8G6eBMqgDNfe7YhxfAOAVNpnDL4a0UyX6DewGiCMRW42QuYYX05CoHLqtsYwXFMCf4ZtLMq22djJeDEHRiX+4GumoMfs1UpEt+7KZCg/hS3B4s2H1lI/5TsqsMR06cGoXokJqbXvJA68B9TW/peiM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=JLrVruR1; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="JLrVruR1" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7b14df8f821so91530285a.2 for ; Thu, 24 Oct 2024 13:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729800807; x=1730405607; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TCg7gaVwcg2dVZWa8iWS8H1cWuO7lQC9V7PJRVhPL+k=; b=JLrVruR18HOJY/HEI0WNX1B7OVdCdHySy/l2Zgv31zOu1lKdJiJF6cCvAPCT/QQwPB LA0JOfNCFMu7gwJYarZeWvf/4c950f3agy0+0f8mlzq/G664oqZ3MpmyCxH25x1rKDpQ XWXsFg6XeYlgxtTugudxlBB3NcvYGmPOSX9wZATX1h2qIZkR/WDqsgWU6rSI6wfQb7AJ /LOyCfeSvfj2H733baOHZXHRzCnK406iWuDFRnkW7uQ9Cwr2uOCMpZO96WHfl3LBEw/q vhhVb6n48MJbihV6nvJO6e5W+58GaAjv2RlQYyZxmTTHmS2NdYwpu6uSgWNp05aoBUkK sfNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729800807; x=1730405607; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TCg7gaVwcg2dVZWa8iWS8H1cWuO7lQC9V7PJRVhPL+k=; b=t2ycRAvSeS4dEo2tkKZdupBUmldJ6DALn2KUoI9tlTYY3sbw32qoW1w8noz4G65Png HFuGiObQ7v/4NPvyyZHYE6l5keU2XZMpUhq+hP6DOuhmQNiPHustKy84f3cY1S/HbWmR cJ/PVTWBKR40eve9I/bVqH3q5g3GZn77fJr/2DpFIjTSzeJO8q2LkZotry33HnX64KHb idr9pZ9NSqj3XTcVWlT4xB4fzGI+NsXKsXakcqLmgw5s1jPl5HDhmTlZhfB3P0YzEyXV giC7WQfl6lQWtGOVLBQ1trgtRFXmmfrUBPpHdqoialqNbeo6gzW4jNVjS0W+Nl3CLhCS y0EQ== X-Gm-Message-State: AOJu0YyAn25AqESnZbkuWe0c05C3mBPyg+skWQ6kVP+Je4xs4O+pvNOq 7iJRB+yFBDv+iLvgzURlpkoInPvh8HisBccWVlX3wtEYNYYbKYn+oDlblqIB1HfFBYvY0j5mRnU M X-Google-Smtp-Source: AGHT+IGetNnHHaAtemGnd4iIDKp1df/mwvQ0tS0XMrLXyEmdn9KJHdNDeVJVyQJvy2LeYyQ3yT6DMw== X-Received: by 2002:a05:620a:269b:b0:7a9:d14f:2374 with SMTP id af79cd13be357-7b17e5b309emr1045900985a.44.1729800806888; Thu, 24 Oct 2024 13:13:26 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.212.111]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b165a037fbsm518952785a.60.2024.10.24.13.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:13:26 -0700 (PDT) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: martin.lau@linux.dev, daniel@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, zijianzhang@bytedance.com, cong.wang@bytedance.com Subject: [PATCH v2 bpf-next/net 5/8] selftests/bpf: Add more tests for test_txmsg_push_pop in test_sockmap Date: Thu, 24 Oct 2024 20:13:03 +0000 Message-Id: <20241024201306.3429177-6-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024201306.3429177-1-zijianzhang@bytedance.com> References: <20241024201306.3429177-1-zijianzhang@bytedance.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Zijian Zhang Add more tests for test_txmsg_push_pop in test_sockmap for better coverage Signed-off-by: Zijian Zhang --- tools/testing/selftests/bpf/test_sockmap.c | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index 61a747afcd05..e5c7ecbe57e3 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -1795,12 +1795,49 @@ static void test_txmsg_push(int cgrp, struct sockmap_options *opt) static void test_txmsg_push_pop(int cgrp, struct sockmap_options *opt) { + /* Test push/pop range overlapping */ txmsg_pass = 1; txmsg_start_push = 1; txmsg_end_push = 10; txmsg_start_pop = 5; txmsg_pop = 4; test_send_large(opt, cgrp); + + txmsg_pass = 1; + txmsg_start_push = 1; + txmsg_end_push = 10; + txmsg_start_pop = 5; + txmsg_pop = 16; + test_send_large(opt, cgrp); + + txmsg_pass = 1; + txmsg_start_push = 5; + txmsg_end_push = 4; + txmsg_start_pop = 1; + txmsg_pop = 10; + test_send_large(opt, cgrp); + + txmsg_pass = 1; + txmsg_start_push = 5; + txmsg_end_push = 16; + txmsg_start_pop = 1; + txmsg_pop = 10; + test_send_large(opt, cgrp); + + /* Test push/pop range non-overlapping */ + txmsg_pass = 1; + txmsg_start_push = 1; + txmsg_end_push = 10; + txmsg_start_pop = 16; + txmsg_pop = 4; + test_send_large(opt, cgrp); + + txmsg_pass = 1; + txmsg_start_push = 16; + txmsg_end_push = 10; + txmsg_start_pop = 5; + txmsg_pop = 4; + test_send_large(opt, cgrp); } static void test_txmsg_apply(int cgrp, struct sockmap_options *opt) From patchwork Thu Oct 24 20:13:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849631 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B990C216A10 for ; Thu, 24 Oct 2024 20:13:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800812; cv=none; b=owGzAffKHVEJjO9W9rY2yELmiI/Me6ELqkEP2ZgsXq/pR6ls9rfzedLFcuXSiE/2Ltwjo+4Hgb3GPRoF3HsF0XM3go6/Yd51OcvASzVJNZQEfIo6swNT5N8RI4mYso1vrrLjlnFH6bRV439bRilGWmpPWnDRbFFraYSy9mLbqBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800812; c=relaxed/simple; bh=av6oifeqTeSC9r3U8LnZD4sFuTiyevgdWO0J8BBjSF4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jyp0UEZqHorIPa7VANwzijoeHFZUpeWzWko7fH1OmtyZlRVNi8nr5H0smYZNJD4qjWmVcP8yB6688XqxqOESR0L4E20DdSaV1EeeAPiVwScXjRkL1ErVTKxawZf+Ven9S/PtFCoEdQcK1wITzubw0uJrCPT0I+agWbwZIND/tv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=CXEqWyNv; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="CXEqWyNv" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7b13fe8f4d0so90221985a.0 for ; Thu, 24 Oct 2024 13:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729800809; x=1730405609; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J0zv6WgbV5lxDj2FYVRbA7097HeGDDzwPhUvvFMKtGU=; b=CXEqWyNvEhk7PBHdY7tzpcntVa6cki/v7smACm4uhii1m9Ipu4Iu6SZiDnrCNQHxjy C7eT9J8BZvHk8TTrjsseWxG2G8JHxT170QydHYiT+vyEJQW3Gd1C9vKi+CjlWXZ9vDPA e9fGO4UEiY5OIgo/MaUmGEVZIimDm6ItmzYM8I1kul2gq2UrOFcaD6r2jsFK9jKuKB6Z Vkpmhw7HyHgiHypZ39vUlshhNDUkiSrVDU+nyU3/ktgFd+WCkdVSZ16ah1W6HaAhjZLN NM4GrZPQ8tcnDDx8UQxbEgjfUczlHIJ9UduXoh9TJ8UO1yfvKN5pKV9OoTQrA415fUiY urHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729800809; x=1730405609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J0zv6WgbV5lxDj2FYVRbA7097HeGDDzwPhUvvFMKtGU=; b=JIR2BQWA/t26E+1blPJ372pOCx8Yt5/mniXsg5QUXiT6I0KFAr+H6NH3EH3BwWhKq8 VJx1Qdc4Jo/V6vx4ySeDkmA+AWvuEp3mB9JHfmFj3tjmCW43QVQjdSGMrcAl+vts8Er4 kaGtQyPsC94Sv/rFhOZFXdtkBOVpNE7Z490i3yzMnaEXPG1gMvyJonDvesX8wflxQzCb eq13ZzDW2h2HdX8TJj1QFDUQGizlUR29HQ8VyRox+KanKj+A9oGXzxntcsz18DVO9wqr z6Gep5dWYz8QuwPq16g3b6cdCcUy/eweWj+3KN9C1aDY2t78ApseIeVtJr2ctUIb8VzH ddMA== X-Gm-Message-State: AOJu0Yy6dj3nKe5PWTIj/fmXe+AKMvfrKKVwkF8HWRP7sziQZnzJfKIq wmR2P2z/zWIP5/iwcQLeijf18EbbaJA+OQSBhXdGM0CvZje1Y3gsz1Apkvmeu+kQDBopHHG0me2 8 X-Google-Smtp-Source: AGHT+IG8GVkC4v9NrX5GiZ2VC5Pkekx1BhYqPQ862jNzhzn4mC1fJho5mfimbvOt2G4Q2CQZOJy2tA== X-Received: by 2002:a05:620a:2590:b0:7a7:dd3a:a699 with SMTP id af79cd13be357-7b17e53f079mr873707585a.11.1729800809315; Thu, 24 Oct 2024 13:13:29 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.212.111]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b165a037fbsm518952785a.60.2024.10.24.13.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:13:28 -0700 (PDT) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: martin.lau@linux.dev, daniel@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, zijianzhang@bytedance.com, cong.wang@bytedance.com Subject: [PATCH v2 bpf-next/net 6/8] bpf, sockmap: Several fixes to bpf_msg_push_data Date: Thu, 24 Oct 2024 20:13:04 +0000 Message-Id: <20241024201306.3429177-7-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024201306.3429177-1-zijianzhang@bytedance.com> References: <20241024201306.3429177-1-zijianzhang@bytedance.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Zijian Zhang Several fixes to bpf_msg_push_data, 1. test_sockmap has tests where bpf_msg_push_data is invoked to push some data at the end of a message, but -EINVAL is returned. In this case, in bpf_msg_push_data, after the first loop, i will be set to msg->sg.end, add the logic to handle it. 2. Before "if (!copy)", the logic for some corner cases related to msg->sg.end is missing, thus add the logic to handle it. Fixes: 6fff607e2f14 ("bpf: sk_msg program helper bpf_msg_push_data") Signed-off-by: Zijian Zhang --- net/core/filter.c | 53 +++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index a88e6924c4c0..4fae427aa5ca 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2793,7 +2793,7 @@ BPF_CALL_4(bpf_msg_push_data, struct sk_msg *, msg, u32, start, sk_msg_iter_var_next(i); } while (i != msg->sg.end); - if (start >= offset + l) + if (start > offset + l) return -EINVAL; space = MAX_MSG_FRAGS - sk_msg_elem_used(msg); @@ -2818,6 +2818,8 @@ BPF_CALL_4(bpf_msg_push_data, struct sk_msg *, msg, u32, start, raw = page_address(page); + if (i == msg->sg.end) + sk_msg_iter_var_prev(i); psge = sk_msg_elem(msg, i); front = start - offset; back = psge->length - front; @@ -2834,7 +2836,13 @@ BPF_CALL_4(bpf_msg_push_data, struct sk_msg *, msg, u32, start, } put_page(sg_page(psge)); - } else if (start - offset) { + new = i; + goto place_new; + } + + if (start - offset) { + if (i == msg->sg.end) + sk_msg_iter_var_prev(i); psge = sk_msg_elem(msg, i); rsge = sk_msg_elem_cpy(msg, i); @@ -2845,39 +2853,44 @@ BPF_CALL_4(bpf_msg_push_data, struct sk_msg *, msg, u32, start, sk_msg_iter_var_next(i); sg_unmark_end(psge); sg_unmark_end(&rsge); - sk_msg_iter_next(msg, end); } /* Slot(s) to place newly allocated data */ + sk_msg_iter_next(msg, end); new = i; + sk_msg_iter_var_next(i); + + if (i == msg->sg.end) { + if (!rsge.length) + goto place_new; + sk_msg_iter_next(msg, end); + goto place_new; + } /* Shift one or two slots as needed */ - if (!copy) { - sge = sk_msg_elem_cpy(msg, i); + sge = sk_msg_elem_cpy(msg, new); + sg_unmark_end(&sge); + nsge = sk_msg_elem_cpy(msg, i); + if (rsge.length) { sk_msg_iter_var_next(i); - sg_unmark_end(&sge); + nnsge = sk_msg_elem_cpy(msg, i); sk_msg_iter_next(msg, end); + } - nsge = sk_msg_elem_cpy(msg, i); + while (i != msg->sg.end) { + msg->sg.data[i] = sge; + sge = nsge; + sk_msg_iter_var_next(i); if (rsge.length) { - sk_msg_iter_var_next(i); + nsge = nnsge; nnsge = sk_msg_elem_cpy(msg, i); - } - - while (i != msg->sg.end) { - msg->sg.data[i] = sge; - sge = nsge; - sk_msg_iter_var_next(i); - if (rsge.length) { - nsge = nnsge; - nnsge = sk_msg_elem_cpy(msg, i); - } else { - nsge = sk_msg_elem_cpy(msg, i); - } + } else { + nsge = sk_msg_elem_cpy(msg, i); } } +place_new: /* Place newly allocated data buffer */ sk_mem_charge(msg->sk, len); msg->sg.size += len; From patchwork Thu Oct 24 20:13:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849632 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EAC31FF02C for ; Thu, 24 Oct 2024 20:13:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800814; cv=none; b=bytGuSWUCKt+DbaMg7eAn8LdJ6I6nAn4qLVQ05LinIra4BpnvfHjhMIQGsmrtI/YfAqvGTz0ukr2xzLI9LLLvO/wnLowjRFbr033am5qBTRx2M7P78aIt7sYZrlPh4F6Hwvz5f58OX+1WcOlY7D5YPKLtcWnDk2DubipIrgbA54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800814; c=relaxed/simple; bh=iAsEXIk9lZDLgN0DGbxM4NFohQ2UJ057gn8Noe9P1pM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eHg/9wBzFg8Ju1ThVctZ5tqRbAy05D2zzNeUmBMwUvNcQEq4zyx4mVcvPjqeI15RXuQYWYEuI8NWZr42WzKAoAH9E7/Tgw1rKmZ12zMuCENN2RgkL4dU3JhiZX+iWlH9zHcE7aEIvBVViHweuZslpTMETU96mU8m781dObQ4QZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=IojU1fH5; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="IojU1fH5" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7b1418058bbso83855785a.3 for ; Thu, 24 Oct 2024 13:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729800811; x=1730405611; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y6aRUbO2DFgQjmBeV68T/FRJXd7JIVcxWlH9nZ0+GBY=; b=IojU1fH5ykSgVwqdse7x4TtiAqZxlu+zAvS9ZqaLQOcJdPUy5MySmFgLMhEv/zeZjr QiYCLCDLacFBpY+SF0tJduAFkbjpNx7fA/xJgmr5B7jtq1+Z987NXw2XY8c3wdVYp6kd qB8i5YUWkwcB4W1c1qGb0f2AJ3OYa2luciu4VS/5tbzCXqZh0UqIaQ8oP3ADMh+cYP0v 3aOa4O6Zk8kIlYO+oUkl2flfzvv5goXb35Ml5PgvGD0O8vOYKA2fkI4dNeYamYDhQUEe 0UyMksyxmOvzlcknIaS1ENAOkM2IOzKN0XPJXTCVvNoaMHmPBJExYvkwvDIEaa0SOR6z EWPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729800811; x=1730405611; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y6aRUbO2DFgQjmBeV68T/FRJXd7JIVcxWlH9nZ0+GBY=; b=M+GzyqWj8J3lBWXErSIeSQN3QbzhDWt1wc3FdxWX9TbvqozPjNAuo1OvxbqSu6B+/2 8kkDISOozBXV6hOWfFn8n7IjjA3B4e8EfiqQ5hzQD99FDhOXMFXgTUN2ZpripE0T+MP7 axFnsnIcinMhMLZj2ztYMaaM9ajn3JxCtA0rFEP5QftKCVkgAf6sqUfICWoe2eYOjS1B T93ci6P1ldnKqp6VYywyRq3STyFHKIY1Szw4z6IqEquzFTKg4+ipafhswDGqBubEV2lO ld0icHnGbBpiAmuA658W7ljLqFLbk81pXqlpucO4mR6tIoXz5AoVfJUQG+E8NLWmVCjr RslA== X-Gm-Message-State: AOJu0YxIRoXEmHlO/bAei/sJqrWUm/QWYaf53S4DedKkU3XQNlQqr0AV TpnqEM2dqtSyO3wneZKiM3txqWMzqPf5w2fFshAhHQkW59lar5HIIMOUlueJn3jsq5wBYUmQR61 V X-Google-Smtp-Source: AGHT+IGKFKOvY6/7Fmlgte3Td80ujf/GrIhJW5WPVD6rsS/CUGo3vyKq1t5YoUnb6KJsAIZ9uH8ytA== X-Received: by 2002:a05:620a:4453:b0:7a9:b268:3655 with SMTP id af79cd13be357-7b17e5ac8camr1098596485a.43.1729800811055; Thu, 24 Oct 2024 13:13:31 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.212.111]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b165a037fbsm518952785a.60.2024.10.24.13.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:13:30 -0700 (PDT) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: martin.lau@linux.dev, daniel@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, zijianzhang@bytedance.com, cong.wang@bytedance.com Subject: [PATCH v2 bpf-next/net 7/8] bpf, sockmap: Several fixes to bpf_msg_pop_data Date: Thu, 24 Oct 2024 20:13:05 +0000 Message-Id: <20241024201306.3429177-8-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024201306.3429177-1-zijianzhang@bytedance.com> References: <20241024201306.3429177-1-zijianzhang@bytedance.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Zijian Zhang Several fixes to bpf_msg_pop_data, 1. In sk_msg_shift_left, we should put_page 2. if (len == 0), return early is better 3. pop the entire sk_msg (last == msg->sg.size) should be supported 4. Fix for the value of variable "a" 5. In sk_msg_shift_left, after shifting, i has already pointed to the next element. Addtional sk_msg_iter_var_next may result in BUG. Fixes: 7246d8ed4dcc ("bpf: helper to pop data from messages") Signed-off-by: Zijian Zhang --- net/core/filter.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 4fae427aa5ca..fba445b96de8 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2919,8 +2919,10 @@ static const struct bpf_func_proto bpf_msg_push_data_proto = { static void sk_msg_shift_left(struct sk_msg *msg, int i) { + struct scatterlist *sge = sk_msg_elem(msg, i); int prev; + put_page(sg_page(sge)); do { prev = i; sk_msg_iter_var_next(i); @@ -2957,6 +2959,9 @@ BPF_CALL_4(bpf_msg_pop_data, struct sk_msg *, msg, u32, start, if (unlikely(flags)) return -EINVAL; + if (unlikely(len == 0)) + return 0; + /* First find the starting scatterlist element */ i = msg->sg.start; do { @@ -2969,7 +2974,7 @@ BPF_CALL_4(bpf_msg_pop_data, struct sk_msg *, msg, u32, start, } while (i != msg->sg.end); /* Bounds checks: start and pop must be inside message */ - if (start >= offset + l || last >= msg->sg.size) + if (start >= offset + l || last > msg->sg.size) return -EINVAL; space = MAX_MSG_FRAGS - sk_msg_elem_used(msg); @@ -2998,12 +3003,12 @@ BPF_CALL_4(bpf_msg_pop_data, struct sk_msg *, msg, u32, start, */ if (start != offset) { struct scatterlist *nsge, *sge = sk_msg_elem(msg, i); - int a = start; + int a = start - offset; int b = sge->length - pop - a; sk_msg_iter_var_next(i); - if (pop < sge->length - a) { + if (b > 0) { if (space) { sge->length = a; sk_msg_shift_right(msg, i); @@ -3022,7 +3027,6 @@ BPF_CALL_4(bpf_msg_pop_data, struct sk_msg *, msg, u32, start, if (unlikely(!page)) return -ENOMEM; - sge->length = a; orig = sg_page(sge); from = sg_virt(sge); to = page_address(page); @@ -3032,7 +3036,7 @@ BPF_CALL_4(bpf_msg_pop_data, struct sk_msg *, msg, u32, start, put_page(orig); } pop = 0; - } else if (pop >= sge->length - a) { + } else { pop -= (sge->length - a); sge->length = a; } @@ -3066,7 +3070,6 @@ BPF_CALL_4(bpf_msg_pop_data, struct sk_msg *, msg, u32, start, pop -= sge->length; sk_msg_shift_left(msg, i); } - sk_msg_iter_var_next(i); } sk_mem_uncharge(msg->sk, len - pop); From patchwork Thu Oct 24 20:13:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849633 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57859215F44 for ; Thu, 24 Oct 2024 20:13:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800816; cv=none; b=BUZc+y4jW3082P+l4Latp88Wop/OCTbc462rLjZ1jPv8hSG8Vw0BdAiUxU1bTdtbJE4CdeH2oiWjG6KE9ShEOx+5YbIIBNlQI5nycq1cgrENj6OVwqoTovcn03X41T64TneifLSJOuEgBp3BRyn8YIV0na7QE+M4/S4LcKSf5q4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729800816; c=relaxed/simple; bh=YhhXvISpJMWCXVvLvNjHR458pcrDK6bXpeotwCF1YXk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rS7zcm2psbi6O27cZiaaFpdS4+OD/DN3THGtRVBWLI1VWdq5krpJ6TF+FGv/oMqOzGEfjIQcbEcQ1SyRWhOKS5i042/QfF6V9dm69FdcR6SOMhQz0mKOxp5PN8Qw8FjUQRsIYMBPeKm4D/t1MZMbGScbuIjn0F2rhhX6TEmP3Lk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=NiVv/J4U; arc=none smtp.client-ip=209.85.222.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="NiVv/J4U" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-7b15416303aso86469685a.1 for ; Thu, 24 Oct 2024 13:13:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729800813; x=1730405613; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wmC3XN9L9q5o4DPFsKbMiWTFpube/+doeBhQaM5ZjWg=; b=NiVv/J4U9TWFDKkeY2OdW/SRcaPnxnpwEAjeAcpa2T1lWVOa0RDTABOs1IJnNfsOBU 1TQsW55zmmUAkk3oyPzx21PuV1oL/iwIQM7PcxYmwZJmuvM53yuPPvJrsMsbjF1vaufX JTauX99RCg7x8xjTI7Hiw5Aw9XvJMh5DyxWxm8f6oarRtY70naDHmgNiVPCVmmTq5ANF Brj1rPvAcy/ldkSYtIZr5CsarO/wwoff7AqNmvcTBJw5GIgnXszoh48JWRmsqIWPbfVR VTZ6ylohMUeRHXeu4heIhepMNLyPfArEZSniEUz0o5FhYQsW1+swsryiFbkPUHHLdYhi wuZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729800813; x=1730405613; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wmC3XN9L9q5o4DPFsKbMiWTFpube/+doeBhQaM5ZjWg=; b=wS8qEx9wVTMr0nx6dE3yscizhMpcgk7m5A1S5IA4W4HnJ3nuokhmcYxv/rNDrdWW2c hNdfaPMhNatd3H3VY1IwKhsTOpqp6Lkj2Sv6F+3DVUs2W+cxcUb3At9nAQBMZ3Hub8va cJrAPrjD6G31vfT/c076+V3QKxi+/Ex7uel5tftjdfLZigAQAaSpRDP+FBxbrXp/Iw76 JU5vVmEaH7ldEZXxJMz26Tu7uxZQaxRVURYv0+Xl+GKq27d0anJWVacUAJaH0IfmKFDz ox5UftoibNzLixQY1/vOP9oG7VCoOdoF5Zefwl5GOJm8VZs+/f4KSf4y1bI8YXtH1q2h fhRw== X-Gm-Message-State: AOJu0YzjF3S/U3WJVryHDlWz8Aobn/742GO3OV/iJ/YirRMa3w5ivp5K aBqcuBJVRrMhGGry/l1RlMXk7woDpDKE7qNaHp5kO3n9ymaXqRPl9vkey3a6FxLgg1x6s+f2GxC q X-Google-Smtp-Source: AGHT+IEviN94HfnuMA6wQ7PcYqk6tqPAt9c5uJDkDq97057FsJJcoYVS+h+Mf5YsR7qHyReboIYvRg== X-Received: by 2002:a05:620a:247:b0:7b1:4fab:4413 with SMTP id af79cd13be357-7b17e5bd41fmr746423885a.60.1729800812619; Thu, 24 Oct 2024 13:13:32 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.212.111]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b165a037fbsm518952785a.60.2024.10.24.13.13.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:13:32 -0700 (PDT) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: martin.lau@linux.dev, daniel@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, zijianzhang@bytedance.com, cong.wang@bytedance.com Subject: [PATCH v2 bpf-next/net 8/8] bpf, sockmap: Fix sk_msg_reset_curr Date: Thu, 24 Oct 2024 20:13:06 +0000 Message-Id: <20241024201306.3429177-9-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024201306.3429177-1-zijianzhang@bytedance.com> References: <20241024201306.3429177-1-zijianzhang@bytedance.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Zijian Zhang Found in the test_txmsg_pull in test_sockmap, ``` txmsg_cork = 512; opt->iov_length = 3; opt->iov_count = 1; opt->rate = 512; ``` The first sendmsg will send an sk_msg with size 3, and bpf_msg_pull_data will be invoked the first time. sk_msg_reset_curr will reset the copybreak from 3 to 0, then the second sendmsg will write into copybreak starting at 0 which overwrites the first sendmsg. The same problem happens in push and pop test. Thus, fix sk_msg_reset_curr to restore the correct copybreak. Fixes: bb9aefde5bba ("bpf: sockmap, updating the sg structure should also update curr") Signed-off-by: Zijian Zhang --- net/core/filter.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index fba445b96de8..00491ac4598f 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2619,18 +2619,16 @@ BPF_CALL_2(bpf_msg_cork_bytes, struct sk_msg *, msg, u32, bytes) static void sk_msg_reset_curr(struct sk_msg *msg) { - u32 i = msg->sg.start; - u32 len = 0; - - do { - len += sk_msg_elem(msg, i)->length; - sk_msg_iter_var_next(i); - if (len >= msg->sg.size) - break; - } while (i != msg->sg.end); + if (!msg->sg.size) { + msg->sg.curr = msg->sg.start; + msg->sg.copybreak = 0; + } else { + u32 i = msg->sg.end; - msg->sg.curr = i; - msg->sg.copybreak = 0; + sk_msg_iter_var_prev(i); + msg->sg.curr = i; + msg->sg.copybreak = msg->sg.data[i].length; + } } static const struct bpf_func_proto bpf_msg_cork_bytes_proto = {