From patchwork Sun Oct 20 11:03:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13843037 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (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 314DA1C6B8 for ; Sun, 20 Oct 2024 11:04:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422260; cv=none; b=s1RmY8RmNCTE3E58BwCaur99BRMwHC42hW1rJWIJyXG4DwtDjTdpf5KVgahvO9GIMY9fYBTmo545rNULnzao0vmXTcoHyOiFTGsJYEr9nAcmRk8uwQtQ7oueiYgBkxyrp1aELZlD86S3+haezpDJKPu3vhrpXJe7IUHr/Ib1nXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422260; c=relaxed/simple; bh=XTpMv+VF8cOdRbUAlZ5ZznC9z7BQObqwvKwaZgZ+cbs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EbLDdkhMBH7VgmuYnzVJM1AW+YzewF5WWkacBrs8j8bhoWz7gDQjkGozl3IZ5CpJi5ffjH2empLGiZYnnLm9NaNT15np0ihGdVbc0KSMB6k+INUNtoE/dlaa9nd+iQ/7eE3N504zd+QWH6qa3wLF++0KjHOWMbSQ/HczKd+xd6o= 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=PDu9mQk0; arc=none smtp.client-ip=209.85.219.46 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="PDu9mQk0" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6cb82317809so24862966d6.0 for ; Sun, 20 Oct 2024 04:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729422256; x=1730027056; 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=PDu9mQk0oDD4WlrmkNt+ACJ6QYI1k/GzFOtdgV4I+NjYo6BVjR3kQ7gyVbtUmTHTrT U1xzDFOK65LDfiwMOUs+hjdyIxDCUh6jQbAk18u6sa6qMcdnutGuaqPKnwwo+6DFgoBk APHqNCkdHSGJYnrH6JxqigpgHCvcx3gBSyOzhXR68c4jwZsiRtjyU9+kPZBtVCWUHk7L 2BlGogsI4XMA1FgYSkmgPHEV2K7k01gTHXxqigWl0JRjeK99wL3SuslDvprWwqCHIEGK fBZCM8fYbIEI3WNgEMiS66oFGnDcH82AkuihXUUAq0T6+AVf3ttpzBg2VZjl5qhF5UdB aalw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729422256; x=1730027056; 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=IOaP7HxZKtF3nBS7XK5HB3SIH4cTTccla5g35ovKpxUZtxT0xZr4I15YZZV++If8jD Va1O3uTH0AiIH3GhjDYZB0aRaBW3byAtgET0EXAz4Ab2TilLZWaSK1dmDEI0s0Cdi9Rm kSzP7ZahhBwguWz7X6uoaphwlVS6kcbHM3uwtlmyPj9FQI+b5S7i+HAoJGoXC7eDQEv+ FLBKJjy530ili09WQLZhRaOUQrey1GDHoIXdNlMP2Y0UHqxDK6IPcLETyUfwKENFnyxG Y5lJcLFc3JMqTJP+wMUwcG/WVe9TG1H4z56tZnDToN4IAr+19+15uDhgmm9/a/2RisxR FKEQ== X-Gm-Message-State: AOJu0YxtE8vFvElnHind6LrBDxxt0PxePePXOkA47HjPAGCc4YIxtHxq kaxZo2yO/BdFsyznAgSQyEaIjqVxJ04gv99EfH+dcWIga8BROvSIv8GP+W3O2Za9v5gBU8GkNnS / X-Google-Smtp-Source: AGHT+IF6+YByGgbPRWlbJ73+fFpp1ToHLFms00K5F02eMeKLvO2RpjTdPB903e80437zTYigtaT6AQ== X-Received: by 2002:a05:6214:33c2:b0:6cd:3a48:5767 with SMTP id 6a1803df08f44-6cde151b8e9mr136733296d6.18.1729422255766; Sun, 20 Oct 2024 04:04:15 -0700 (PDT) Received: from n191-036-066.byted.org ([139.177.233.243]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ce00700c0csm6715216d6.0.2024.10.20.04.04.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2024 04:04:14 -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 bpf 1/8] selftests/bpf: Add txmsg_pass to pull/push/pop in test_sockmap Date: Sun, 20 Oct 2024 11:03:38 +0000 Message-Id: <20241020110345.1468595-2-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241020110345.1468595-1-zijianzhang@bytedance.com> References: <20241020110345.1468595-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 Reviewed-by: John Fastabend --- 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 Sun Oct 20 11:03:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13843038 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (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 B793E18E356 for ; Sun, 20 Oct 2024 11:04:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422262; cv=none; b=g/nXmUSQpFRZrzVIbNuZf5TtHrYw9EhbELnrHKl0WHZjJOFvhHnubyHEQhgFnE4rpPM4wF3N2zebaSOhw0df7blpRLrYlFXq8oGjM5Yn4ik2l+TTQePUT5vQI5jvzxzJSrgGMC11w9v/XL6ViJ/laMexa98Hyd21oVWSixYkfC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422262; c=relaxed/simple; bh=oN+Sq3+CWyQl246OGQEH7dYYr3Jp3o0mxYocnm+sFwY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JQmSjUsp4EJfqPTyUgRK4eccvUCo0eHSz6AiVsUCoAEbkqAk/E22BEdAL2cl/cyfX/Mx+WdII8v10jh/5MUeqC3XhsNAawvRVrukuF7JNtDVKwlSjOPPlDDErpGktP1WQrNbo5rvLFjuHW723dDbpSjUcmPh+XPRet0Vu8mzb3Q= 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=erTerPZ1; arc=none smtp.client-ip=209.85.219.52 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="erTerPZ1" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6cc1b20ce54so30232336d6.0 for ; Sun, 20 Oct 2024 04:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729422258; x=1730027058; 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=L3WbXZvJz7yGm6Xfeyw+tck3A3XQyIYLN+0rsHfU348=; b=erTerPZ1pFRn+Y4I8ODKoEiC/uw7pCZYL6ANqAUYjthOOLo0OcyE0B82OSzmmqeZzw hk/1zULPT96xzA1eqFW41o9i9TyjIieHDqYWl9oKU0wgrbI967RqFZEwDMoEk0TtEoA0 r9FtoIpimK7zYXSAq5ft836xW5aRLyHzX9x9YwhwZXPuq+wyBe/+KWQ+TQpyVdZZIBVU sXK5XNHnVWoZKd+/1FcQu65OlBNZaipdVtQ/66xQKp+y8BWEEiegno8MuiScwGAzn60O 1buMNDUjZtHZYypcLGijReQmz95vplEAegR3j6FyEsjGSvHavUQyperWLwYYgiuJDF2f i90g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729422258; x=1730027058; 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=L3WbXZvJz7yGm6Xfeyw+tck3A3XQyIYLN+0rsHfU348=; b=CTZBlATV4JJMTqcIYdXeQK/fMgiFWKoxIdX2cZC8Gj6v6DMjLqXtgVeEIL4vu1szEI hWXYXscNQojEtimZGMDkruwYGP8nDa4+t3BTCg8lAWL7KhH+oKEfmnO6a2kyMRVCGmnZ tFuTn8MS4z0l3MYrGUIBfdHxrPZFIwxKOU9SUxoRE/d7+qXE466zjXowB8EdLVjvYFPM BZNaPw+hUf0o/7/xX4MfldzUTVLPz4UbO2dzRRG58u5v1ofi+BOjBDt5fk6gMyeB75hP 6OaDVRgjqWE048KAlnCwEX2irdYZueG+mv8OpL96UQgSggLAbAufGqTDtErEKyd2Dc34 lnyw== X-Gm-Message-State: AOJu0YxpWf/uEL+HUxqwQWeV6FEP++cw1yhbA7aP+8M/keV+kt6ZeQHm NennHFVm+dcuqXSU+lqCPQezIelGlXVNvQn0HY0pimMIUoZcshffgifXZwUVK2UksrN1IGwtNVN j X-Google-Smtp-Source: AGHT+IEM/hH/iNBn7snpBBiHewsnB3aIQ/2olVruLmr4+AuU0/NXj9I/KxHVPevCXguxLReiS/T6ng== X-Received: by 2002:a05:6214:3f81:b0:6cb:fac2:82d with SMTP id 6a1803df08f44-6cde155e58emr131332836d6.30.1729422258132; Sun, 20 Oct 2024 04:04:18 -0700 (PDT) Received: from n191-036-066.byted.org ([139.177.233.243]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ce00700c0csm6715216d6.0.2024.10.20.04.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2024 04:04:17 -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 bpf 2/8] selftests/bpf: Fix SENDPAGE data logic in test_sockmap Date: Sun, 20 Oct 2024 11:03:39 +0000 Message-Id: <20241020110345.1468595-3-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241020110345.1468595-1-zijianzhang@bytedance.com> References: <20241020110345.1468595-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 in cnt times of 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 Reviewed-by: John Fastabend --- 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 Sun Oct 20 11:03:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13843039 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.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 CC04F1C6B8 for ; Sun, 20 Oct 2024 11:04:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422264; cv=none; b=brcoJmh36dPFsln1q4h/sKGmjc5a+PDYcqrc6v2isAdazdMgrQjh+0T/PbO4RPoSyIx4gTuUkMnSMxLqjLbbNwv+nYK7vMRRAcsk/QIyot8jFEBFJj32phspwQh83n3iPcXYs+ZxN8gSMUe8hkpYKeav1aI+UWoiNmgyc+rYfVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422264; c=relaxed/simple; bh=vbnyCZDPi0zxXqkZxpf3RXMi4uB9UNpHTfu0NnfuXGc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d9tkQvDN/Tj8st4d243wUS+rkBdrO0Ecj9cskpjB+HR0xmL0NApS9L2+Svdlr3LGR+ugY6IpykZeOeB5Fi1lBXrEA0tpMd5H1azIGaoD7sXjzWnEMVxbJYm7nameNfvfsxre5aVqV2yq+DAYH5AdtjQXW32cLGJGsjfGwBgHNDc= 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=jQ7WF2uL; arc=none smtp.client-ip=209.85.222.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="jQ7WF2uL" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7ac83a98e5eso288707785a.0 for ; Sun, 20 Oct 2024 04:04:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729422261; x=1730027061; 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=xpCp30CARU+D+6JrWwiyU223m/ZLXiiJT/XtdCgb+VQ=; b=jQ7WF2uLUo2icgGhLvgIVvrRO5P7cvvVf5ulb400eHBT3XqxMvxDI2zW5A85TK+vlX 8fFWvJxAgWPZM9uPqQOCqRe+AVcdIEesCvBlaM3/z6N0ezviEGuhyu97jmLnDKjrmKZN dexROWQreetjuBSM2EQdcNDYaL4C7m+79TUnInhRmE3oI0xmoi2waRqWxuHsVgbVi7+e q49GhdeVSNVdNBwNm8W19v0PgCatYcPIicuWaOBVLHgTK3ym5xzMxao8o8zLepbPOlLJ dKPyH49zIk8jrHwGZpsfyX7YYZmhIXESNQU316lriX9ugEE/32gU0s2djR3lHxx5ZglL eeMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729422261; x=1730027061; 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=xpCp30CARU+D+6JrWwiyU223m/ZLXiiJT/XtdCgb+VQ=; b=l8yKG8u/AKktoBkn5XRPqAfFHu8qDSwR6zW9vvbHGQPMKf9GuZYWbxd/mweQymXeuk Mc0zDeHWo8pg8d2Hef4pP6xoDiXcJvOARnnF58pMPdlgD0Wx6u8IJWSb0vK5NGfKIQ/Q DEkF8FcxP0iFCtqkEUZDJroytqCtX+sKnvwvVBySentnnQV+0BG0zkfbNo9yGa6AkaaL ahJjKkmolKIKZVCswBzuNmUhT7lbK6NQ86WGsfYlJ2a9DHUEQ+eB1J3qTZQzwutsRmy+ RCfeKnyiEeSRNrPUQsk/yWdhX/QdRxWBEGcXIB3yhThUXxcry9eZQR8EqgXrvhWIn0Wa ofIg== X-Gm-Message-State: AOJu0YyvtnkT8LLxR5K7Curv5VBEemGFQRrjOUP7LlwI1cpc120aBOmG aPxUzs8/aHEAsFt54JBTJxlF3U8WT/05cI4fsV/cbu7LcySivGVGzvVMbb9r03O/2IRdPzScoto 4 X-Google-Smtp-Source: AGHT+IHr1ZfdD2gJ+Y+xR81kZMoSHdr4acx7tOmi09UC5YgF8jGfwO1b1UjOB3H7tPJCD7Oc1u//Qw== X-Received: by 2002:a05:620a:46a2:b0:7b1:4762:8a with SMTP id af79cd13be357-7b14d4e46c9mr2053239885a.3.1729422261251; Sun, 20 Oct 2024 04:04:21 -0700 (PDT) Received: from n191-036-066.byted.org ([139.177.233.243]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ce00700c0csm6715216d6.0.2024.10.20.04.04.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2024 04:04:20 -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 bpf 3/8] selftests/bpf: Fix total_bytes in msg_loop_rx in test_sockmap Date: Sun, 20 Oct 2024 11:03:40 +0000 Message-Id: <20241020110345.1468595-4-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241020110345.1468595-1-zijianzhang@bytedance.com> References: <20241020110345.1468595-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, 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 Reviewed-by: John Fastabend --- 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 Sun Oct 20 11:03:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13843040 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (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 278BF1C6B8 for ; Sun, 20 Oct 2024 11:04:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422268; cv=none; b=kxwaX3qJLH4DmcW/5f8JJKi4LmuB9rqM0b+Clmsuqtyc5fY3GPeXuNSj70f2whWJaTNVoZjUrcU5261jbVXvvDFOTFSsxIDpeeZTZ9qM80rUhj5FTya6uWbIDtdWfXZ8pXhlaV97NY6m4VTEMNWVypN1ZL7kr0HhLansiDutisc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422268; c=relaxed/simple; bh=KBd+fuXndvtpzmWIJEpuCpeU6J7HxvF1lXzTkTrqY84=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UePl7X3UzUwf+ALXqukoUxEiDRQHZjxklwF+qQqKAAjhcUfqCgOTpvMvOA/9IdxZKcsSPo9XYiFZqvSZDD8Gr7KQF6vz8Jx2es0BH9M43hQTqG6evvB+/GF7ykjBiDl+xYSDVw3UHCxx2/J2R6IRlU9tMIDnEAWEInMeyzOv31A= 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=HcaFEPd4; arc=none smtp.client-ip=209.85.219.43 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="HcaFEPd4" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-6cbcc2bd7fcso20503416d6.1 for ; Sun, 20 Oct 2024 04:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729422265; x=1730027065; 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=koO6264sCddl9GhBTqknTfSMSFf49xtuEmdKRbwRb24=; b=HcaFEPd4HloAty+jV30lvghaxkO/1uziCCL2E3wGHOksZbms8fyW2pfVC1jNjSP09u 9oXVSWPbU/JCJwFniyudaOoxBC4X43b+87G9O8+rw1flOBGo40hvv3VIPYwXY5DYIHnP X9p55mf1QXctKxvdWBMLXV2RaDZU5zRupAz7dfeSlR7fmtXhSt8mEbN2ZCF38I/Txbcd 4i4AdK1Q8e76PVlLeWXuGH/2JRZ0SWM0Ha9xG4RrBiYDzf2/trv4zWzWKULgIcKUIUxk EM4jZZIj02BkVLRwtlRAkMvM4uM93Zpx0EiqGQEhLsIHDIcybM76IGYIdrMShE6DpykB kH8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729422265; x=1730027065; 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=koO6264sCddl9GhBTqknTfSMSFf49xtuEmdKRbwRb24=; b=cNCaN0zpYnqgmcBDH6bfjDJT09EgqxOn7b/tGt69+bKC5j+ThoS/2/GU/AfVv3Pyi7 Gw6BmyNJqCvzXax6lDJQS7tYkwszD5ULGz6BcL3e0C12elkDR4HsTCMRecuY5LgD85Pl /0J9SYeWasiTs8E/HKjOrBFlUcQccxviB7hXo0/u19Sl0wYWb2oyDbfPoAl2mOZPXiog sS9VJnVdXfUSxTFx2VAKBiopXVTH2RDke+pg44rtqPVUz86IITpOi+CeeHzGh2yhA1hq QgOE8AvIbL207er4YD8MyKFav0JdURjxDIsvXfWXArYRBDk17QqxNoIi4RzKWSpFWpn8 XMIA== X-Gm-Message-State: AOJu0Ywk1ciD+0glQ9bGiEdJFWSWo1Mb8bNMdzujD9pvyM6LSZQELc4E 69lsCoVQH2FAbOERJ82XnywcyMRL7q1D9hrkvixPHRcmA/nCMJUlslmSXABTNjdfO5aGj7YQrvL U X-Google-Smtp-Source: AGHT+IECDl9+CLIoDJ8BZMEam26k1p1J/Mugc6MCfgG3xx2rNQk7PjUBE+at8Nv8L/XH6U8MhFZ1XQ== X-Received: by 2002:a05:6214:5784:b0:6c3:5496:3e06 with SMTP id 6a1803df08f44-6cde14b89e9mr117693186d6.10.1729422264668; Sun, 20 Oct 2024 04:04:24 -0700 (PDT) Received: from n191-036-066.byted.org ([139.177.233.243]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ce00700c0csm6715216d6.0.2024.10.20.04.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2024 04:04: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 bpf 4/8] selftests/bpf: Add push/pop checking for msg_verify_data in test_sockmap Date: Sun, 20 Oct 2024 11:03:41 +0000 Message-Id: <20241020110345.1468595-5-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241020110345.1468595-1-zijianzhang@bytedance.com> References: <20241020110345.1468595-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. In pop/push and cork tests, the logic will be different, 1. 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 Reviewed-by: John Fastabend --- 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 Sun Oct 20 11:03:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13843041 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (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 81AC61C6B8 for ; Sun, 20 Oct 2024 11:04:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422271; cv=none; b=hK4Fb2W1jspjHacpw+RY152diLUCYRggSk2e5wcwpFGhsJlytKNK7KYyMZB/72+YdKNdikJmDuqiWNhi15X7LeUOjwnZVNh3uy0Y9c3xsMYagF236JZKNIfAdVE/4wfSWRWGVoN7Nn9DXQa67yBcBsUh1OsMuokamNPjJpaqEx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422271; c=relaxed/simple; bh=XzjJ1kgr9qogiAQ273Sl4papScGSzlIxPbiDYvIV6wY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Mh6kGBJCfUkRlMAEPozuyiruNRtLetk+NDvBzLCVZBxBkqGMB8aoqXvhaDlMSzEEAuj4Iu/XIbdZdT1z/pTMhXoNdf8aPOM/XNeSR1RUVAUGHmuC97FdG5sv1VsE9aoPnlqUrJXuSqcbJH3HD6XNif5flhwyJrwypopMHqvgRf0= 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=XaVxe/E3; arc=none smtp.client-ip=209.85.219.54 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="XaVxe/E3" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6cbd12b38b4so24727856d6.2 for ; Sun, 20 Oct 2024 04:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729422268; x=1730027068; 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=oHPkfNuTBPUIpsuetIE1UELY1k60fVDFIDgPf/g9e4Y=; b=XaVxe/E3SDkMPUb4jmrA7A2Vt6BdmAo0/G7R02uI5hR+GK9VMHzOv6NdiC5UOzngKN HbJCFXdzDWXJs5IhIN7C+Kw6Hw61UTaQRjeTK2qyvHkenRvyWwBrt7/QHjB38eZ2HW8y Dys30Hr9LPUQRA3VbfB6xTTZllSEyJJ0KJ5IJQIzvaSNZBc/tekxK+kg2e9om1REWH6u +4KlBNim6e868Mip1j4DSJWFHQHTQQpYRpCu/FzoeRXWIHM4teTQbpk151+rkgCp8EU9 4T8v+T62eEXj6Ohn2V83TV+MfCcWl7LXeCUofuKd6cA07ugMRAIfGoxxc2r7Vzrpkd12 sdqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729422268; x=1730027068; 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=oHPkfNuTBPUIpsuetIE1UELY1k60fVDFIDgPf/g9e4Y=; b=ilTlr9fK0pkfqcGEN35Tef//k2wHDiZfywXNs4rVsPRooTPyPtD5+PlD/Kk48qzFR0 VJDcczdbfiKx0U93fxGHJXw1fmkcYISZ4U/fv9MNvrouWfyd99IHaHsUv0VKYUFllYwF 8DU10qsJZzFFekXt8zpfsJwsGF4QZZqEoIV5/4Ihx7YQn7wsnFH5UnweMpFwDUwq62zf vEnzERLiJTiJ5NHocpKhHSpBRR7p9eC7u6ywqcQAjkIPYZ+SFIb2vq0amjgzt++8mqBm QmjFI0UO0792stieCuWHutnNJ5gPKzp2YYYPgCMPp5r82rGcdB7vWCbNgWTurbvWVtsc BWxA== X-Gm-Message-State: AOJu0YyfjKaIVBt3Ev430T/C0Jrr4oR9bAilM44L9nJqgOSoN7CNPfyS +fYPhMN8tT6D/jiN4XtChcKhvqJvn0G+NFZw27DohoTyj8yuwQ9trc03Iq9oCokafXhvRdMQTFW 1 X-Google-Smtp-Source: AGHT+IHDc7Nl5OiuDiciocG+1Gk+zLOH0J+ikyJ0/KSvjM6v6waduHysDLfcMjwaIhkmI56X328UQQ== X-Received: by 2002:a05:6214:5b0e:b0:6cb:ff04:655f with SMTP id 6a1803df08f44-6cde15244f7mr148082536d6.22.1729422267744; Sun, 20 Oct 2024 04:04:27 -0700 (PDT) Received: from n191-036-066.byted.org ([139.177.233.243]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ce00700c0csm6715216d6.0.2024.10.20.04.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2024 04:04: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 bpf 5/8] selftests/bpf: Add more tests for test_txmsg_push_pop in test_sockmap Date: Sun, 20 Oct 2024 11:03:42 +0000 Message-Id: <20241020110345.1468595-6-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241020110345.1468595-1-zijianzhang@bytedance.com> References: <20241020110345.1468595-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 stricter tests. Signed-off-by: Zijian Zhang Reviewed-by: John Fastabend --- 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 Sun Oct 20 11:03:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13843042 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (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 273ED190074 for ; Sun, 20 Oct 2024 11:04:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422274; cv=none; b=lebbiymgRDQj9Yax04pzF2dy7PhwhghlYdo1GO1Bi5TeLUxzffkaP59/xcmZgKNKtaMrlrwpyodCT1brDwyU8vHKttVmJunRk/MM/zC5XRb0ptvvW4HI5HHnPlgVmVu9Tk45TUd0Q1zJy8vHq2oaXvP2n+iEZoY+7gmb1AOP8zY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422274; c=relaxed/simple; bh=WQkBTANNrlxAVAxsSwV26WtmnEMH/ALNmAPkbUTnNGg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Wh/49scADHXcJYC5KLzYU+P0GF/Fpj9XNutOv+w928ZW3/2CK27fDI3m266PuxStf520NVFGUAV3/UVX5wv9GSRRZuhpvBgpsq28xz1hTVFv33AujGfxkJlAWfVdFpOBPX1D/T9DBWKXinmFO8W0gZt/jXSWxNeDy/3FeOC+wy4= 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=CF1/lGV0; arc=none smtp.client-ip=209.85.219.47 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="CF1/lGV0" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-6cbd00dd21cso22434276d6.3 for ; Sun, 20 Oct 2024 04:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729422271; x=1730027071; 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=zoVozaRBn349dlY/Y2Xvit4gb/ODSas9Z65fIEa/ErU=; b=CF1/lGV0arYwjIz/P1hxwI7dZWuJkA+ogTPxUrApPYtAhfXOfJhPf8DEEbm6CG0M+u 0tR5VDNeZbFgO/qbz8hFjlFXOgqEec+Er10+F2oNNh2Y2oVWpecBQZfKCZMgtX7mg2Kf OXgcwg8PLa1Va/ezBX8fsCiSfjLFek3z21Bu/uSeip+BZ+ujYHjpiWX6Iw1czo+fZwWt MDFmdDcSvcBfJNhcZ40wM22uk3LEKZl3IDiV7i0TNZkWCXe/NTt6DIslHkP+or6jBRTK CzwLulfNIcejphvbrm+/yADPGhKiHHGGqdwmdIsClPukiizFGiv55x45yBGTuwwFfnZj 3uVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729422271; x=1730027071; 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=zoVozaRBn349dlY/Y2Xvit4gb/ODSas9Z65fIEa/ErU=; b=iycm9+9smSid5vyKrRJoqWY43ncdqVP4Aka8uHX4WAC72ObLMTqnhbuVXQzQvoSvf4 7r2nGDw61cHluu+DmACn3Q4RPf8Uk0Beh7sesNKmcyZdtDdMB7eqS69RukwYrH8nXpEl pguOw/F4vsNvfB0Jh0lFXM1BlzwnTTzVvi8l79dN+nNInLEsWgFqsOeMcKziDNPULtjH sWsmPvOvpXXvbEJSS0L00Fk80vn7DYUh3/CxlerCfu6ok20jnkDn0/QWRAWb+0Dhijaz 7COlNbiLG9pz1wTt+lM3jPPXkWp0anC7fJJWQ5jVb7VyxTtBZ8Mbgj7SY+6Ao7IK/9Nj RVgw== X-Gm-Message-State: AOJu0YxO8Wrv35aTotsTj9fzOrun5Hj88Bzx2bmLrPeu9sQY54qUM1N0 VkiMLF42q584lSv2niKjGf0yjasgHHkpNRM9AnCJURPsVzHJCp+fIhz3mitIXFDFo4fQpjUfLtJ W X-Google-Smtp-Source: AGHT+IHAgMi4MEiqCJ4bP4gKCLPpOSV31PlOHEsfaPhRuSXhhoSOG3x9YOX6fNqmZ3KiY8vC3iEiNQ== X-Received: by 2002:a05:6214:3b83:b0:6cc:42d:bbb with SMTP id 6a1803df08f44-6cde1695f11mr88854186d6.53.1729422270843; Sun, 20 Oct 2024 04:04:30 -0700 (PDT) Received: from n191-036-066.byted.org ([139.177.233.243]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ce00700c0csm6715216d6.0.2024.10.20.04.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2024 04:04:29 -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 bpf 6/8] bpf, sockmap: Several fixes to bpf_msg_push_data Date: Sun, 20 Oct 2024 11:03:43 +0000 Message-Id: <20241020110345.1468595-7-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241020110345.1468595-1-zijianzhang@bytedance.com> References: <20241020110345.1468595-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 be invoked to push some data at the end of a message, but -EINVAL is returned for this case. 2. Add logic for corner case where msg->sg.size is zero 3. 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 Sun Oct 20 11:03:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13843043 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (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 6CAA9188A3B for ; Sun, 20 Oct 2024 11:04:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422277; cv=none; b=Ps1xn6vyCCVhdUQHnagjSAwER3Gy0Tq3E9GBFW2uExFYo++5JSm9XYUfZCa5aFTieAhUEjrV3O3PVBibmxzzhAHP+ySHcKEzqWJVqZIFYewYWXPGGU6WCweW9C1tCDC/QnZ418ytfEtbJT1TxLGfqinCZgrjwBN8e6o2GYHw2K8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422277; c=relaxed/simple; bh=BH9aK3Bdg8WCQ2gQiVerd0CjJMZEBTPkI4XIQehsWe8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ccfaw+EFiEiUvWpFTl4uquUwtwwYRUsVpm5HDovn7WMqKk1xQCS8CRS6NLiRjCkgpNDsKGsCVneCeoOV1MQGafI5sTs62+uxQLc/ozSuE3OTki4jXxUs55G+MJJ8OxIReeP9w/ciSmlT4nW6VDT/tH35TSCnG8tTYemFUC3LZtw= 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=dRk58tIv; arc=none smtp.client-ip=209.85.219.47 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="dRk58tIv" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-6c5acb785f2so19921276d6.0 for ; Sun, 20 Oct 2024 04:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729422274; x=1730027074; 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=tXovnw1hpcieH40jA+UiXwQGUAj7DcN4pSnqNYMpqhQ=; b=dRk58tIvOw4vsScjmEVlBEya0L2UjGzuK484l6lQ9xhuTr2KCafBhkw2AoEtf5LJ1m Ts/zf2mrR7DAw3xCOp5GzKfvoiI37BKC2uLUtGHUsagdDeXdC9TnYA7CNGLMDrZp1uNU tcCfaepSeS0Yb1HPPDmVibTBEomHW/SXeiCsYrSF7EMrWHCAArfYisN0ORrZjmqdTbWF xcV6XAB5v/rmcsHi+W2Eix5wlRR2t0Lf1STUxypn8gMVY0nMTAtBtdodfP0N/EvIYWPj 0xzzJwvJRTzeAOaIMDI656c3j7FDyQz66C+ZGnQyGK9k8GPsNLTisflixqqGpEvzPFWa e1bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729422274; x=1730027074; 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=tXovnw1hpcieH40jA+UiXwQGUAj7DcN4pSnqNYMpqhQ=; b=EpG090cGhVebV3A6GQqLetGcpdbUkSniwXvqKE+kIrdx08DLZ1pmhdCK1IWae00WpE o5d8psr95Uy9r+IbAnN9IIgvebLuuUyitmvH9+g0zJ48BlPnQGDooBcHNcuzW3D7JMhs y/0F1InXd9mHDwSj4PoBaDdFamOIqmhgOGjEYUEEgwWiFAeQe9mF2tGB5CGPwLk8A9GU pA9r2N3NpKQU8UvVC7BiOZ9ktoMbdyCgsJcekaHua3bsfEbr63y6l8nhhZ5ySnhgu+KP BEJCgeyBFOP6j16KxdP8Mq0G19p3nJIu9U7WAVj2T9/8XRtfn9VViPT4zDaUfsUKWt5r yHKQ== X-Gm-Message-State: AOJu0Yx89CnEKJiHCj5HRe5x6lfFjv6Z/GqqzFqxntmJwbekzJNWssqI XJdxa745meYSklXjNZqUuMAfF82G1OgVQBDMfmfDNYIIoN8grbf15yfT8LGJzOvxuSH/ZMIjskP g X-Google-Smtp-Source: AGHT+IFGiWcDzwhgb7IE+bSyqBaskBisy8FHav2v4jTRvSqgfUlTVbnNaSUhs1HKhLolvH2C+/OO7Q== X-Received: by 2002:a05:6214:488e:b0:6c5:8a85:19fe with SMTP id 6a1803df08f44-6cde165082cmr116579386d6.51.1729422273967; Sun, 20 Oct 2024 04:04:33 -0700 (PDT) Received: from n191-036-066.byted.org ([139.177.233.243]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ce00700c0csm6715216d6.0.2024.10.20.04.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2024 04:04: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 bpf 7/8] bpf, sockmap: Several fixes to bpf_msg_pop_data Date: Sun, 20 Oct 2024 11:03:44 +0000 Message-Id: <20241020110345.1468595-8-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241020110345.1468595-1-zijianzhang@bytedance.com> References: <20241020110345.1468595-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 and sge->length 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 Reviewed-by: John Fastabend --- net/core/filter.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 4fae427aa5ca..8e1a8a8d8d55 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,7 @@ BPF_CALL_4(bpf_msg_pop_data, struct sk_msg *, msg, u32, start, if (unlikely(!page)) return -ENOMEM; - sge->length = a; + sge->length = a + b; orig = sg_page(sge); from = sg_virt(sge); to = page_address(page); @@ -3032,7 +3037,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 +3071,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 Sun Oct 20 11:03:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13843044 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (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 BDE8A18E028 for ; Sun, 20 Oct 2024 11:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422279; cv=none; b=TU2HzCF/0ot2j2igrJf+AoJREpXMDSE0RTjiRrvcrpkKuE+BYYYfZS6c//Ho7TY+lNfzD28JKVHigl9qfrX6GMn8aWGwGgmwuZ2bUvvMrFapocUxcjBKfzRlWoqSldhSvW17Z4MUJbUoBkz2Aqcv+svQyKOz4UNydTMMLpvTXko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729422279; c=relaxed/simple; bh=kRwayV11hsUGTVOSUuLhMlPf6jprZ0sEf9dLS4nrasM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HxC5B9Piu0tZlv8rOA8FNwMUS4tmnRh3gqCTV/GPwImrmkjd77gXqX3fv12nclyeSLD40wtHzYXJ3Pm4JEFAfA9xqf1BywIuEX2ZV65Uc1LasmZsmw8nxROE3oIWAhyF1pZvSwoNJAdYY+ET6TsQ3fgwsdVeVbubqzbm9Wta8cM= 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=FkzS1785; arc=none smtp.client-ip=209.85.222.182 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="FkzS1785" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-7b1467af9dbso266001385a.0 for ; Sun, 20 Oct 2024 04:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729422276; x=1730027076; 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=yUCvERanlFc1q+AzssYdf9ytVplB8Xkn9H2PGVZUxv8=; b=FkzS17851ReGNYRgGs9SkQEL+GNNT5UD6MqaF73CfgZRKrKRK+K66O5Brsyd7EWPFv lPrXaLGf19jbxSMIIGLpR1XMZi8yxeB4FzalsqToxdm/QjAriv+pZcKr2O4zILqhSfOF Vfc/UOmrkalkFePaFxiPWkwd1jCBdgQ49x8bMQpdMWu9FyhQk3BgTf18cyD7yge046lB 99GftBxUb0Q2iLA8M8nAhpnuN/JLyqF4C0jeB6Dg9iIy88St1YAXH/pLTJamnzhK1tyD Ias4ebCOUusmiw8tJrVHFQF8m+Uu1LRbnRA+XKoY+VY0X1bexjo+OTkifEgdC1ebaXMk 8csw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729422276; x=1730027076; 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=yUCvERanlFc1q+AzssYdf9ytVplB8Xkn9H2PGVZUxv8=; b=keR2uLaWqH1g+PI5OlAkGbGYZwWpeOYYsm9FOmWaqaztpBvnUiW04L4+xXN96wB/Gn H7uNlh75wgqvl/WrtK2dVes6aqGQ0DuyLjd7pUEiJPr+hUpYoHhc9riIsE67lckr+Kuc f4sCp7bhWRIrvP0awiUuAoT0dq12OzCrcwIB2YCNLxouS8Sg7m8o1KNMq48iclcPTJmC enR6sdOLZAlFdacz2Tzeed31WvTEm+7k2BWWP7bJh/nfsh/NkebmBDiZzjWIrer8Y/jF +5PvBKk2Q1xv/FKHktNqgqODhv7G0sG7M0DDByxDtT0bXcpUo8dYLcO43jeaGMxwNcAq MkYA== X-Gm-Message-State: AOJu0Yz2eUxaUbSUXoKfzhOM5wC2UfulqAT8p0qXY6VnyHubC20QDBHU CkIX0yu35vr0XJz3qJxRWoe36GTSvfPhVJLXqPLYWFacRutIg6nqC9DB6jaykmcE0Vo1XK/Zb+N t X-Google-Smtp-Source: AGHT+IGUi5ruVOvy3vPhPczXAsL3WivLiNyUOw5iT9MnpHEq4evjHjbPnE3Zzsgu/5iDpxvBuSpkhQ== X-Received: by 2002:a05:620a:1711:b0:7b1:54bf:7185 with SMTP id af79cd13be357-7b157bb5371mr1064334885a.38.1729422276321; Sun, 20 Oct 2024 04:04:36 -0700 (PDT) Received: from n191-036-066.byted.org ([139.177.233.243]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ce00700c0csm6715216d6.0.2024.10.20.04.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2024 04:04: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 bpf 8/8] bpf, sockmap: Fix sk_msg_reset_curr Date: Sun, 20 Oct 2024 11:03:45 +0000 Message-Id: <20241020110345.1468595-9-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241020110345.1468595-1-zijianzhang@bytedance.com> References: <20241020110345.1468595-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 8e1a8a8d8d55..b725d3a2fdb8 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 = {