From patchwork Thu Oct 24 20:29:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849666 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.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 6761C16E89B for ; Thu, 24 Oct 2024 20:29:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801777; cv=none; b=oa5UqNsmixtv7XXF0CdiqkPhQsDNfVujFXO0Ww42KT5J8kGLzPv5rg3VHKPEYGFCkkUlrzGwluUcrem+Pk/1ZlqCRgVHhOemheROJvfIXi7qlDakmx7FlUTKiqLJyDDOe1whrNpJjE18eKksg0Es4IFo763iI7QVwX15M6ADzhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801777; c=relaxed/simple; bh=XTpMv+VF8cOdRbUAlZ5ZznC9z7BQObqwvKwaZgZ+cbs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QzJkVXBjQkxJH82XWo1i9s8+r4nJVwz6EXII/HhD8JIBfyVdPHrRDly/zVr7HSgrJnxiN67oTXskV9Q0BZHualL4fSJNVcxP+rba/CCUM8f4zOY3kH+Po4c7GZThWwzdBshG0tctWODwx+fejBs4HGsPRxc6grRMcckGsmk8vKk= 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=I8PMurbf; arc=none smtp.client-ip=209.85.160.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="I8PMurbf" Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-460963d6233so7999681cf.2 for ; Thu, 24 Oct 2024 13:29:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729801774; x=1730406574; 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=I8PMurbf8dP5882uQOihlAa1thhOdjNWldbGSNSkz55A2wYjalQ6Kmjt/MkPkeXps2 mMnR74GQFAwm2twRlEhLWcwf3vBAqZUQvowXc0L/WKsyEZ/BDNrnFhxRgFsFCm5R2w5J Zd4alYiIo+RGZzeKpDBmP6B/HJpQxLkARlmzBhdVQ1VJ1BLN6AAR9SYnHlgxkMNGSMIg E6bxTsXuu9VOeoIgZguKfFiTXMO7FpQbPdGe3jSaDcqpIRsrlc7wimvdgLnuxLn5i5B8 nE4J8fZVIBGC3RemxjfU7QXKwNz5ce09PAI3uOZ9btvzsxe+WjwLsaaTtPr5qyvVwmMk aScQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729801774; x=1730406574; 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=eiW19xH9SiEa0T9mcwYumRRQtglt92rtIu4uyQon1wD2dtKHhWcjaTTOgSows9zu8N YTc/jxpo/vBMoKOy480TlDeOybJLzt3pv0Skk8Q0oHtxTGuq2Ohm6dSExFodLZody+7M 0YMyhwhXdst77M5K3gCpXCkR2Vd5lWFiCxhim3x/TokYRVg4GvukcXShP2kqyV6cBMD+ iOWCy6THlJrer16rqU8foOlTQU5WiXP/Aewslut6dhCf+NMHHhE38zd1DmawaZ0b/QMx msZajaG4iQeV8CfpEPkWQ8sYzdla3KIcOrdkmbrI7RxC8bhnagqpy+cDMT4NscY1uOf1 fcVQ== X-Gm-Message-State: AOJu0YzgvfbpaDSA7/hSSl16JsTx8Vew8pIsU7VVHvaa+b1BBj91ONUa 2geY4nNPQuv2AyYOkZKa5sfPKDo1gPE3gpVZNPvVVfubkhhVK11+zlIsBnzKGS3knx1OHyGjNPd S X-Google-Smtp-Source: AGHT+IG7sM2s5H4PjfXvlDnpGlW208tF1NvXrbumTC37Dur6ax+0S9fvBoZek74AHshgHtscJ+e5gQ== X-Received: by 2002:a05:622a:2c3:b0:461:1df4:6b16 with SMTP id d75a77b69052e-4611df471d2mr74646711cf.0.1729801774028; Thu, 24 Oct 2024 13:29:34 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.215.80]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-460d3cbb3c3sm55486081cf.52.2024.10.24.13.29.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:29: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 1/8] selftests/bpf: Add txmsg_pass to pull/push/pop in test_sockmap Date: Thu, 24 Oct 2024 20:29:10 +0000 Message-Id: <20241024202917.3443231-2-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024202917.3443231-1-zijianzhang@bytedance.com> References: <20241024202917.3443231-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:29:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849667 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.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 9461316E89B for ; Thu, 24 Oct 2024 20:29:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801780; cv=none; b=F1dYLfZq7Tmyd9EQ2u3ltIlcwbUJj8foo3PPIh/plZlXLFgQ9YPz/QiMCtXNh9N9JPIo53mOIg3xqxwUZnmEAbWE7FEpRd9GKdIQEl7++sA0fNO5D3Lm+U7OeyDueVLOX6VdU5W4QZv7s1EtW8plmEmLLhw+IZ4wp9hJRdJd3Ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801780; c=relaxed/simple; bh=CuN2X17yctDLixboLYTLUEjwjVE+eww9uE4fmUoGdGI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K8zcTebopLySsQh4bXUb3OZikHmsB1KMUkGdD2n0P373Bh7d4G0h1s9jCqaxQuDkDNG+vJlyuZT4mq0hcw7d/ts/Tiyji2nIbO2aLzO2S/5sNln49L4kU2LJswcCSe23Ttm80zuOY+eMhn/cZuFhjZLNIrRGG0sDxJLkp5ne6B0= 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=IEzhJOkb; arc=none smtp.client-ip=209.85.219.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="IEzhJOkb" Received: by mail-yb1-f176.google.com with SMTP id 3f1490d57ef6-dff1ccdc17bso1472986276.0 for ; Thu, 24 Oct 2024 13:29:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729801777; x=1730406577; 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=IEzhJOkbmqN2Mc6adZveK26q6/B/WsomHZZR3FZ/29VHdkzZQU8JMMJlVXLJR4BP9V 0OVkrHxMgKlM1I2gAfPEiF3CkaZvXDM9ymbVx5uHWjtIR1gEDFxjJFtA6u7habWT7r/V Sip7gKqFSAKJoInU+xNNMc+AFOUy8obuIdQV3O6KS+Ru/SsdTfWCyOH7dxG7SDRMxZ3y FpkAR1uhqkUgwcZ/1Gr+TsQMouxbP7kZ9mypF91aE1rEy54SyHQnlRqnx54YUCWwGNu3 wd9nwFxMZdQVRjlwOjGrgjiUL22pg90n+tYowhGY/ledl/+x74Fn9J9QKMwvfDvc6jHw 1j+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729801777; x=1730406577; 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=RelFW4xc1iL6ppOJRUUVLehmUgBAJBoaNOVSLmHZ4RgWjKRx1zv2yoVm3G8G/m4tgL 3F76wVmZDc2MvVlRiQ1q2XfUJY41esFOlWBIEjpkP0A5jha0W3iYAdVPoZNEtzlx1YGa koeE3jogNJGwDb2Ux6j8qVJcxYVxircJdgIQlaSN5oh0UOOE4faf7duzDtJG3Gc/H5kv XIKOKy1XCIbp5AOMy6pnw+L1HvPeBsa1s//6rcO/qmrqX9yAq+ySmPbM27oRWdjaL9zb 2jbyKyz6mxm4GL1jldmNsQuh6HpAc+dMkEr4S/JNq7oCM/v2s+fP0mirgwNfzO4U6BIt N9uA== X-Gm-Message-State: AOJu0YzfPd7TSKDEWFoeKX2D6hJQq5CvPO5FE3xuzJy4EHNMBMiIIkjN Ag724U3j4+juFIQJzMLUX2VnkgTVld8nw2ux2AJOC3lDZTT7drP3T0lyfbbifPsGEQ3ywg4pYYJ X X-Google-Smtp-Source: AGHT+IFK8BQNRgf6mzrAiN94ZmTef4IBlZaAaIuWhrl6mgUNCrNEzSc8Fj3DP40LW9XJvhCIaKrvsQ== X-Received: by 2002:a05:6902:1b82:b0:e0b:5b37:d0c9 with SMTP id 3f1490d57ef6-e2e3a61991bmr7817689276.14.1729801777128; Thu, 24 Oct 2024 13:29:37 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.215.80]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-460d3cbb3c3sm55486081cf.52.2024.10.24.13.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:29:36 -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 2/8] selftests/bpf: Fix SENDPAGE data logic in test_sockmap Date: Thu, 24 Oct 2024 20:29:11 +0000 Message-Id: <20241024202917.3443231-3-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024202917.3443231-1-zijianzhang@bytedance.com> References: <20241024202917.3443231-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:29:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849668 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (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 8EE8816E89B for ; Thu, 24 Oct 2024 20:29:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801783; cv=none; b=hzLPEmnVYmYXl/NOuju4O/y7mv3sXLTIp6fFG8Zaz1WWMmMmg9Cyze/5SjBL1bgzIEYdFkuAUXMrZmig9OpstKZvsXSxe6dMJwYkvL7JEWqJ/PGWzfTEeO11z1PczkVRWIstfaC7PtLg2pQ0TKeoqlBFOD07s/8NDoz/5352RWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801783; c=relaxed/simple; bh=y5xG5PZaDIdA5ZRhc0eCzfqeojjrLwjp1ZGtaVGyGM0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EQOBTJ4OYdcQTC4rJkURQlFLKjBDKSa2P2Vl62joKBkQyOKRJAL/oQeWbsEjm8Stj+LmRy6F8LvFl62jVr6IbooxCWncDDqT1Bu/LSF5UMlLExSnpjtAANaVjZGUOt7QSSKp9QgqHn7OLl5a73tJbjSCyMvDtsHYyvD+Qud7JS0= 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=K4SgISXo; arc=none smtp.client-ip=209.85.160.180 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="K4SgISXo" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-460af1a1154so8233951cf.0 for ; Thu, 24 Oct 2024 13:29:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729801779; x=1730406579; 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=K4SgISXo5AePFZERnIbVcij+FUChLnKnX37QfUQ6LVNBuWCZxJvVLADJCVUkoNNLtE NUiTobgwekL2H+w8TbyxZQtCUa5DwisHP5nCvtpd+lTrHS0fHCBMXMkD0DJRKCidqOfr pLGU83encz4/TqDNEgG4d2LZ8mc4MhgFoq2sJoB2oHJpd8FF/wgu1V6DDDkdgktTtn20 56qs8fI4bpluPfZYU7K0IrylnBRwfIR+mJeOCHh1cnbg3A7Mk0VVrQCeIBrPW8Up6Por I4OxENAjGuApmZfQwECgqnwUohqPavm6x+iGwFXXYT0hg66NgcGNCO6tioVngop3keB0 T43Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729801779; x=1730406579; 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=XoyhlK45NrAHJw3h5u+CVhH1qrt//6ZwstAo6cCx/+KnB9z7Onhye5i7fmiAA5X2vW crAxTNT4KvqVgdgn242KTKZMdSacpJv2E8OX+tN/8EdFKeI24yx9xcVe6QAyKsbxz5Gv Ab0tMdZ3n0zt/8V+++uj+kjC3OjFmob/7d+WQIxubXli4jfWtN0bepoD/iUN4dq1phqv z3s6PO7wBG46A3mxVlSCLhq7rxTWZnqMj8pK28XU1zJo0ITHGbxQhc+6SNnrcUaFaNmq jrSNUPzBruTGJtmLGzUHSsNQGNg4/bdzXWqLNR1YRs5OLCmAFFloHs4ESbl9R5KZ3BPI lRYw== X-Gm-Message-State: AOJu0YyxVSFDAQqF6R2ssK6bVw3Bh51FSru+2toN4wzNvhdKlsaYdZ9q Dt7nxn2No9fHU2Ue7YouCetOPQlZyZgL1SPFbK6yvyYL9eBS51jFv4X30SrkM2IC+xHfaYrhl7m A X-Google-Smtp-Source: AGHT+IGMcvzQmOYWk0hn7PvIzRn5w7ky84jbLhm/dTeW7m37PTCJ5nmtoorUaX5hC5TlrdF3CniASg== X-Received: by 2002:a05:622a:89:b0:460:dd3a:8f68 with SMTP id d75a77b69052e-461145b351cmr80794681cf.3.1729801778817; Thu, 24 Oct 2024 13:29:38 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.215.80]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-460d3cbb3c3sm55486081cf.52.2024.10.24.13.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:29:38 -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 3/8] selftests/bpf: Fix total_bytes in msg_loop_rx in test_sockmap Date: Thu, 24 Oct 2024 20:29:12 +0000 Message-Id: <20241024202917.3443231-4-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024202917.3443231-1-zijianzhang@bytedance.com> References: <20241024202917.3443231-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:29:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849669 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (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 0B6251FAF08 for ; Thu, 24 Oct 2024 20:29:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801784; cv=none; b=oPot/aksGkqAK9lhhfr5cp4ohUvLvCVSoQUUN62psxrEr3yjDEI7lj7bwHzhEJHLDAaF8ow5KQV/9/ypX4K26ytGEA5625iwuJKhujIJMEd6NH5EKLry4Z97aqB8kO+be367KRIFA/jCaEYiuJ4rqFTs3J3ZHN9TgUVjJvkCm34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801784; c=relaxed/simple; bh=eb8puX70Jevci/jH+kFlG74v8H4lVm245VUWlkHYLkc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mT8TNiX6kYN0MTfA8l0uP4+Z32wVtxL+t+fvyt6MQNe77BYQNDCGvqHWrb3E7NW/g7yDx7sn+oHvm5NDBFLyppe7JuoxbVkrlcRqMgSIJIk4E8Vmr7REt16oN5vyokq6kNPVGhjfCNCYxu3qRv4i0nYDh0u9CyKzJi/4Daguero= 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=MVcLDHu2; arc=none smtp.client-ip=209.85.160.177 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="MVcLDHu2" Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-460a23ad00eso21700441cf.0 for ; Thu, 24 Oct 2024 13:29:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729801780; x=1730406580; 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=MVcLDHu2jqELr1aPNMrBtSCDfPlz4a2ddedcvWl6diC1Hg0YXzVWiQ4NLri7LsAbKu QrNcnieb65vLuvPfAozD6x6frjdKy2HM7qk/t/VAwQ+P2vA5a2SxRM9y+CCwOpRipNde RY71/lR3LWyFK70oZJgmjrwZ0CcdvRXH1zDMETKncm9kMC4ePW5qkqdWAXsoXVJsEzAe /CU6QVLf35CsSfwVlpuWqlO6wzRvk2MAX/HfKU/Hya6w6+UI7qVK1tCOt8CRrTp7Qhfc N6Tbk0cUcSs723uTMfWS8pQ+Ag6dK9YEXEkdVdxXcW2LS/B2955xuygthlpKJC+dZ5g6 4blA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729801780; x=1730406580; 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=kc1wFTcMIZIFQec+ByIgWa49fJbXFKqsrAlJmlYOyLOu1NM1e0dM8Gp/acqjTPdz+Y JDTPyjje7HVgItmTlQWOmSakznxVD0JJbHPVqMvGJLBfil2xJv29Q3Pyt+Isz4vDPSsX z19ehJpb39ca+jmMEkOono8UePbuXJ5m1SWUR4VHZqNyxqo4ycgGWXMHK+Y2gpx0+dSc 8khoMR54rFgPN18ZkxwQTjUcjMkXOQOCFCZI+gk6mYs0ov22UHHfSMaWhGXO1v4LHV/P OYBCJAxEEmkzTA57q8kPyG0qVOKUz27hXZfI2AnNW787Yh4F1qWYWTMVrSOSyLh1bqpd MKCw== X-Gm-Message-State: AOJu0YyzVhMMtthy3fZN9PnlhOSXikQDQb0upMu6XlHlJSYJU0a1Vg1d LGMrap82FyAPzkOQH9CKVf/nAi90TFzc0jLYRNdhD3lSaH1LD2alTi1H8qyJiqb/4Yq6BNUptaH d X-Google-Smtp-Source: AGHT+IGZG7ZZO05/orT0GzKUg+/9P6kA1RW6MDvA631CpjLO2NmplDdmA3uqovSW4Bk3vKnm4Mf7iQ== X-Received: by 2002:a05:622a:11c8:b0:460:854f:a1c with SMTP id d75a77b69052e-461252d167emr54644721cf.27.1729801780473; Thu, 24 Oct 2024 13:29:40 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.215.80]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-460d3cbb3c3sm55486081cf.52.2024.10.24.13.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:29:40 -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 4/8] selftests/bpf: Add push/pop checking for msg_verify_data in test_sockmap Date: Thu, 24 Oct 2024 20:29:13 +0000 Message-Id: <20241024202917.3443231-5-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024202917.3443231-1-zijianzhang@bytedance.com> References: <20241024202917.3443231-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:29:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849670 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.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 7643B1AF0BF for ; Thu, 24 Oct 2024 20:29:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801785; cv=none; b=KOOZ8pZIVLQ3em6fd7Y6LoUH/piHT47e619Kds+ydZhb209iXtARsRf1L1xdOkzi4IhKrS2NFGLP5DW96QM9PcS9awJuKVUurj5kg/CcVUdAksi89tztRWMANwzvPPH4v1o6zZvexkjIAZvsprIE2hwVNjdxSFtaCB2ONRkG5uc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801785; c=relaxed/simple; bh=DWOwti3vm2u8IiCa72HOjYzsSxbb+cx9lsbchIICfoE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kwzRmL2uOwNuQnrrxIPVzHJgiAe5Uh2mf49xbXHI1LPxRAE6Y/wBWQjt3W59/ESThjL8mloMwUH4oojahGCSyPCkLRA/KUc7m4bzQlrqK2EMvHa+W7eeVJNe4Ed9btFfGd4S/kft2FqxPVuwMUEoCV6AkvuKmC802x4hJI/yq6g= 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=LHVDrxn2; arc=none smtp.client-ip=209.85.160.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="LHVDrxn2" Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-4609d75e2f8so21150821cf.1 for ; Thu, 24 Oct 2024 13:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729801782; x=1730406582; 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=LHVDrxn2/vtkbDEALu6OBbkDu8eq7/KSbBoeBS/7x18PbfVPrtibcmzd9F5IWEtBZJ aKAcCg+OTRkinB5uljM3t5ZaDVVFneLhDzKty1lAPZavzujfai+t5wITYqcT3wcnz4Nj t2uQK8ByJe4Ck7fc1+7ZtdgyPbG1hCL6hVBEchgYe5gFLnUUlAXCdWzK1+3tvpNb82t0 f/qUnuGML1IOK9w9Z2gOA/NKXORANcG5i4T+iZHwNd0VAqZ4YIsvNhvzy7YuqABR/lIL Y2MixCikUtC9fiO8eaHgA1oQk4xO9i6vBTcGdHc/85rZP0aYp9+wFvE2z901M4Qf28jf VGXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729801782; x=1730406582; 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=T81dPWTXBhMPBJRg6JDvDU2ATCEXx6T3fDnxg4DVcQXwuqCMRODAlVXD5q0zUuzH/n qbeoqYJ+Wp7r/QrjRoafL3KygSSpmZVqt8lWdclnYN57xLJEYZMNCyHSkq05WLYvrQVl HhXqdNLYK6tear0KQ8Jzxw6f+O5aZoO05YQDih/yxABDBTLQhMXgJOEG1dHbzoafeP3f uxisMt07FAVMLD+raqhqd/zIesN6jHNvTuEo0Z4JyYEPEO0wInn+/yjRHUvtX54VyApA iTyiP03G+1uZnJE9sxuHbWa59M7KjtIhdjaQ8JVMQlUoKsm9LxsGRcYFKuj6pt/IKpcC d+uw== X-Gm-Message-State: AOJu0YwoCSo7IXkLd+NjuPa3OaxAwaiztCdp8r5/JHW92NawAcjqiqg7 dgO14Hk9FthH+GuLqkdFUdkB7VPJh5Tv2o3pTzX3K/c+P/nAX2vpnd55S8iM8oSgzBXRrlo7G3c 9 X-Google-Smtp-Source: AGHT+IHm7q96jprVuce6iQHEO/Ikwa2YD01YgvCBtq/vg9Vl9St+zVIsTguouLzWY1OClbC5ABwwnA== X-Received: by 2002:ac8:5907:0:b0:451:b77e:a8c1 with SMTP id d75a77b69052e-4612525b39emr54201131cf.3.1729801781984; Thu, 24 Oct 2024 13:29:41 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.215.80]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-460d3cbb3c3sm55486081cf.52.2024.10.24.13.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:29:41 -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 5/8] selftests/bpf: Add more tests for test_txmsg_push_pop in test_sockmap Date: Thu, 24 Oct 2024 20:29:14 +0000 Message-Id: <20241024202917.3443231-6-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024202917.3443231-1-zijianzhang@bytedance.com> References: <20241024202917.3443231-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:29:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849671 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (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 AE1B52170B9 for ; Thu, 24 Oct 2024 20:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801787; cv=none; b=ZetoyrZfff19J2MNE058+y5zGeJgu0O4TPayBw5bVJdBOCeBFBaCAK4YpdkeTxs+MxIDenjXtjnza6FQF2xGcAr4sYroQK1KtoNdtOzrlnjwUL1WfMOyg2TBsjQRTe4n3LxgI2qc3uTyvreKgQo4NOiyGrBDUdB3zJ6EfFoA/q0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801787; c=relaxed/simple; bh=j34bvrCVF0oaO1wKlQh8wGEACHFU/0w9veoKch8xoxk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VpdBzGBIUNxhvzWcXMRvSJYyjAPUnSYGeq8dbkVr/SfVUX1Ey/3Gnn9NXUmL0uFhfN6RWP2ULcR/I6FNXUEX/unOjr9mu0OAsbLYB2P+t59ETsSugRIuTMDrnA+hmECeIRpQ4x0ZsAWLyQdOL3kBRwHZ7qvcVE0Wf9TCz+1X2pQ= 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=D+R+28L8; arc=none smtp.client-ip=209.85.160.169 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="D+R+28L8" Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-460a23ad00eso21701041cf.0 for ; Thu, 24 Oct 2024 13:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729801784; x=1730406584; 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=8XhEsmOF8nZeJsm6eI/AhkOJHXVkV3Jbs6Tk1mX0i8M=; b=D+R+28L8DYkB8n9uKnImUSzvP4mmpai2YqH2IrpSFWdMe57hV3a5r3nVnEA30xDCgW v0mWevMvZEKY2VoQJUh2759TvdRsTMwDEOrwkvLHCQLa4b6DTqkFpTHbIyN6rd2g50O5 e/gx085rTdCeooTpapwKKgU6gYdJ7/3UzPYFHdJ746BQVjT0piETKNvjCWfXJZsx0RYC OnWu7CjPuDnAciswPooFJeuz2woiBpgVCpWhORaO+KOWYKmGbUOuBOG//8a2MZEIt76k SUnzWw3za+4171ZHFnuMiPzQUjkRp5yNB9ghzy/yCZ/gyaIaX/ie9bsWUDYu65AfAi0w 23+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729801784; x=1730406584; 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=8XhEsmOF8nZeJsm6eI/AhkOJHXVkV3Jbs6Tk1mX0i8M=; b=tQrASXm6/Y31B/7xsvWJb4rZvoKRWnLfaN0WPp1F/VtWfHZJ8+94wUueVuAur/j/s1 /K9KuK6t6WrRQ9UWsK2Kncfu1T2CsiNUqBNZitFEEYJudKuG8nFfeqXaloCo33/miwsV MibyYngLmg2WXfyfFRkb1fOQNMlwi3xm33Iyx6ev4V3UaTKpUIEqMWdfnseOxx6+MjCV MHBvkbU8wrSKgMh2PESLYFT+yt+8xw2586N7NGcZKbj8uBn9EYcVDzTBCfKK0XI+mE8R VIqpqItfI+3lwx1jUMvhj3UXS/9uyznLIYK61O89mr7sj/gyfo6hIn/fh4cTfKko/AF7 1hdw== X-Gm-Message-State: AOJu0YxKGfdfc3lL/pzQ7Bc6QE8sLQ7DmWTDdhQf/oKUTX27HssgG36g tweuCk90iSWkLyymgelLvJT+fxPtd+Kf03zGa2EgVdAE3UO5V6rgX9xWgGO6ypCswsJXl886cSn w X-Google-Smtp-Source: AGHT+IHt6jNVAFAtxbYTk6vicLjIQ/twn/x5r4MiC2EooTqfxA9qqcS2BDfMXntfQLdRH8DO1UgT+w== X-Received: by 2002:ac8:7c4f:0:b0:45e:ff39:ea6c with SMTP id d75a77b69052e-461252d181cmr59089361cf.29.1729801784100; Thu, 24 Oct 2024 13:29:44 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.215.80]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-460d3cbb3c3sm55486081cf.52.2024.10.24.13.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:29:43 -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 6/8] bpf, sockmap: Several fixes to bpf_msg_push_data Date: Thu, 24 Oct 2024 20:29:15 +0000 Message-Id: <20241024202917.3443231-7-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024202917.3443231-1-zijianzhang@bytedance.com> References: <20241024202917.3443231-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:29:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849672 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (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 D25541AF0BF for ; Thu, 24 Oct 2024 20:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801788; cv=none; b=M3R1K1dlc35MKGyQ2/Zla2XuBghdPnfZhJKj5Oacu5nr8Ml3sH7yaWu4be3TOFSQjhTY/a2Da/mFoMq842zkeoahQbDKvLvlN8MaSssf81DNBYWfmp/ID6F6n7I+qz9nbmTxaQkBX4L26TmqFOGMfF8tZcc5MGYTyQRP/PQSI4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801788; c=relaxed/simple; bh=iAsEXIk9lZDLgN0DGbxM4NFohQ2UJ057gn8Noe9P1pM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EKC9CMmQHw9UFqZbfZuBOYHd3UDVDdoVmB7G7eK/UTAi28LSk5ounePVGtU8AfngqLat3pw0+g8s9kosSqik7aCgTQlq3IJzfTJk5hYbNXVe37hb37vZlxMbExmKHJy4AzhaTw3bPjQ4cBVLO0CWZIVM8/EkkRMt33NOBbQFz9U= 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=koZy5brh; arc=none smtp.client-ip=209.85.219.181 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="koZy5brh" Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e28fa2807eeso1531380276.1 for ; Thu, 24 Oct 2024 13:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729801785; x=1730406585; 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=koZy5brhtIDCPY7ozap4+DdY+RtVS83gCf6s1ri42pj6mq7HRxAp4xcQZDjbZ1RnQm Luhm34ZLQ+yZD0hK9COYSsNygL0pkXTzFA9MNzA5WSexqIdnNrE48XsGchm4NjjZ57td BLFgUjkdP/DbLWtxFLME9Ky/+SsPh3wj3I2mkW47kQPTOinRHq/bIJYiY8aDxVErKlg4 UkBCVtmyRAf8qqO+3aNaZ52ta8hXvBTx70YLv9fH8UVBUWwz3M9rw2bVXFWgShk0gyDz 21s5dxhcQiobMt7i1BA4yPsjZEgTFInsk6UrMIvqOPlDO8gNTI1nhVOBm+Yl9rpgMIOe ndvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729801785; x=1730406585; 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=b7O0eKOigK/fqRDoxgSkb6NlrEqHuT5sVQBZ1H+1xlkyEutbkWtaEFMbn4Zu1/w0em xH0Smr3QB3DY/l6eRYIQklK+JChpHL25CmDxWXRvhSgsHyPUTiQXKzXO19C0wnLc4kwd UdV1RBqFQZPdPiPPIaBMg8bhOLyRvMay2Bto0S2qfVQezGZe88yqOFk5Pol3wwJA3VdD 8EQFZs6o2SzbyOiHrku4BjcI4jVbluGEfLlWgCyTBnYkn0S3eyQk78SfpG4e25PDOT0U EjmcKwAfhQeqyMxw9Vb4EDYNC+k7kdNIDaIFrEFB6qLsRAkr7HDCDanWmfAfxcrBZXvx 0K8A== X-Gm-Message-State: AOJu0YzazZw+gnTrMgIl2NuY/b91cAk8K7vDk33GqLosd4uTg7MUZvsI RZ+zX4ce9H40xq2tjiQuYQKxMOTw6GeffSsMLHZbF+Pv0rF3ShRG670eP6oH3PyTYADv7Tzb/Ed 3 X-Google-Smtp-Source: AGHT+IF5dijjfumS8n8+qcRDEWEMsXd2GgVjVCS970UbRLXe/Upc33tK6dykXc6je1Mza+tNe6TQ4A== X-Received: by 2002:a05:6902:1685:b0:e2b:48af:aa93 with SMTP id 3f1490d57ef6-e2e3a6e76b1mr7894708276.54.1729801785606; Thu, 24 Oct 2024 13:29:45 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.215.80]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-460d3cbb3c3sm55486081cf.52.2024.10.24.13.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:29:45 -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 7/8] bpf, sockmap: Several fixes to bpf_msg_pop_data Date: Thu, 24 Oct 2024 20:29:16 +0000 Message-Id: <20241024202917.3443231-8-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024202917.3443231-1-zijianzhang@bytedance.com> References: <20241024202917.3443231-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:29:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13849673 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (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 485CF1A7ADE for ; Thu, 24 Oct 2024 20:29:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801793; cv=none; b=lHdR5OC1CgQx6+n2nIR2UxgfwhI1C2FGkdqxFv//toddnSnYp7wYNE4XjX9FDojprtoIPSCF2aeiV6R/LWu8F5lBGbS2tnnh/baaIP8g804WK/FauQLzuxOOLe+2T9VYg3KmDQPb02ahu251A1f4Im6cJTHRhk8Q78Nm/hxf6Es= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729801793; c=relaxed/simple; bh=YhhXvISpJMWCXVvLvNjHR458pcrDK6bXpeotwCF1YXk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kLxjQf6FnY2o8TZDBDdS7y3RV3rrET/2P7pvuAK9cqpi6v+2QayRsojLlg+e8naQMMauQqllmlVVMqV+xnmPjiawNubG2+m8Tufao3GHE0At3DHgj6MyQp+8vNWbdxStXBF5979YphlyKBk0ESh1NctbCL7KDk6x8vT+dG1Yfdw= 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=ZQfG2db5; arc=none smtp.client-ip=209.85.219.178 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="ZQfG2db5" Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-e28fa2807eeso1531441276.1 for ; Thu, 24 Oct 2024 13:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729801790; x=1730406590; 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=ZQfG2db5SCJyZ3A4inuGQ5bWiJ9kXFkjdB/SQEV8CavZVYS+PUYgiujYP/TGgUJ9vx RiDbF3vXzBzyoC4QqSoCQMPLJgr2pNxf6rxWhi0nBut9D7MCK1ERy03esyLq5+S4OPxG fo0zBnXiDOZ6R9S6CL6yBWuAkqP984OqhQg4/Xv22eqBKpwpFGKSRoS4PMDDPShSw54o G6tCuc32YYonpZFA5YiVoX/RWwcMsNFDDRa0z+63gDFnyPF12rof6l7a2bUE7c2p3V6j owa5hy8GWAxaQuZVHozDyaP0EI+Y0rNPSdTsSoD7wXgcHcqOts6ZM0JJKZuqvlUmP2Ah SZ9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729801790; x=1730406590; 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=X5DDwvqu4bWMsiR44OGznkH6hUbk4WTUlFyPPns4bWMgH/jk8TWjMPuPt5TeWHwOXA iHTvRsR8Ba2RZDX2FJuye1CwQgwwDywWKCDZKhkuZOV2OWLA08RZwQOQVMXIS5raS0sf tH9HkLA0l3GewOipEfioQgHb+r2GKlMZF2xwg4n8qqiwtaxw8KSOVMkjb0IKVI3wZdLq S3tKwG9rkxAVQO41fHqSyEJMNscePy9z4LA+JnfzgtKhzfgpzYaCcsl+nB8L655Ar+/P 5xvJBV1wvdHjoZS62GUrdzPivrfDEvtpiwEQupvHcUxZ7MjlYcQFo2BjGCMjNCCIhz+j 2yqA== X-Gm-Message-State: AOJu0Yyp0Wt/dOQJphQ7G7DgZ5kbW/DK0wPGn7xLesMYs+W+gTJsFKde T3plJS0RnOqnQf059UfXYEU8BE3urRHN9kTficud9tjRmSnpqNdJpMUw7Ttxqf6xS5mPBrlnGRB 6 X-Google-Smtp-Source: AGHT+IHdKRnD6nq4tKR6kxYLy+UXquO5fzi88lVtvUqzHwDmX60LdHGAq3+j//jbe+2pIFRlXLYmVw== X-Received: by 2002:a05:6902:1026:b0:e28:6822:a280 with SMTP id 3f1490d57ef6-e2e3a680695mr9235523276.26.1729801790005; Thu, 24 Oct 2024 13:29:50 -0700 (PDT) Received: from n191-036-066.byted.org ([130.44.215.80]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-460d3cbb3c3sm55486081cf.52.2024.10.24.13.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 13:29:48 -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 8/8] bpf, sockmap: Fix sk_msg_reset_curr Date: Thu, 24 Oct 2024 20:29:17 +0000 Message-Id: <20241024202917.3443231-9-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241024202917.3443231-1-zijianzhang@bytedance.com> References: <20241024202917.3443231-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 = {