From patchwork Wed Nov 6 22:25: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: 13865586 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E12A20CCF2 for ; Wed, 6 Nov 2024 22:26:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931974; cv=none; b=XcvJAU/AxWfYTnvbDHgYVumBUOh6Gt0iTJhN+SehiYkmhL/DxoTBGstx98H1VLNEzY1oR6KOHaJPG5cJf/y9ipqRHDxrLRzD9PSLxvsh2vnN3ZYbbXgg38OxBGNMhrGI9BruzwIK/myfZT/t1Aqqp1qL72qLVud4Idw7C2gxhFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931974; c=relaxed/simple; bh=r+9pSyIfCGD+0Rut2av2phkfQwWLLxkVPTANyCLrKhs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MKmIqlTbsRQvmIiw6UQxSHl7YhQbAC0jgrCXnsz0NtVaFUvAJa+BfqrVHp8dlDGOJImPSWyduFmLUpOsqIRZg9zgT7s4yFM28MeYYF7tSk7p49QBRKCSBpjWDYRSwsG+6f/gHw1YrJDjkouU6ACZFYfNfcft6EgJY3m8yU2ggU0= 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=COVwsM9o; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="COVwsM9o" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7b1507c42faso114017585a.0 for ; Wed, 06 Nov 2024 14:26:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1730931971; x=1731536771; 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=70hYqqh5KzkH+ztuwDpbbVCToZXmN+0tCwyB3ptILN4=; b=COVwsM9o5xq9hwIjaUmFUHR4wvmtJCWWyotlXYlK/kPTzFFBF7EUf2ywMcE90bgacf XkCTTsrigIBPlUTLMZjD0vdvObSoekJP2KzCdAF+FIvNMfu8xhu334dMZCoH6y1VATO+ uWh4OcdHCdAmcRxfPTRrY4t1GXuabXj28SbBMqFeBEFYVDJRPJ5Al0kvqGV2PA5Vlj3E 0WvdXdVKvqIza/vkllHIlMzLoVyPRNYdjYhgGLBiK00o67Yo5Q5tyUAKVVwwM41MskvH rZ1yDyeObFFG8RM65Q6KaKjxrliu+jcl3cQ6TrxYRA/+pqSO93STTaM1lELJSgBDugRz DOJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730931971; x=1731536771; 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=70hYqqh5KzkH+ztuwDpbbVCToZXmN+0tCwyB3ptILN4=; b=wahDjSRgkyhsI6nr/UOVsXXCFm4JWsHWVZ0AOSDYtNU1dKIED9D/zobXGAIsbxj0Y6 R5Ru7a8H7jwtc17cknWIHPG6lARNVjEdJhj/kMI6DOSXv3cd/2CtyyC/GAl7j381eB6v ZnHAsWxPdObAqdJoJXx5rMidyu65CotbhRYu80qQNv2ruHUenuwgrpfYTxyPa2fXqlxo SNxxjZ7afO0qEhZE6cs//BvfFQWIGDtaaFQnGRc7WQtw6ZCbMSAISVZlRvZFKFWEf7wm XRAxXzhUfHOhKYR2mWG8sP4aHg31+bpQ8YpwYg+q17VCUIvlDZRg0enhuEW5A+cAZkup J4Dg== X-Gm-Message-State: AOJu0YwfYnhHPQI4nS9MVSJY1ypbQmlSr/tCn8SGaeTJBIX+11fECq83 6JYQ3vH2rYXeIPiIRUKjq5cmernKR9mIF1uwW9zLMwvpVDgC8eQigYW/kJMKb/XkOlPD15hpbTe l X-Google-Smtp-Source: AGHT+IEC+EchxIOeNYlx0elqDlv8gEvnhN6u/xf6pB8sK7ldXLtTOtnhDR3mQi4lbpdlHKLb944c0A== X-Received: by 2002:a05:620a:8423:b0:7b1:ab32:b71e with SMTP id af79cd13be357-7b3276e1ce7mr128270285a.0.1730931971080; Wed, 06 Nov 2024 14:26:11 -0800 (PST) Received: from n191-036-066.byted.org ([139.177.233.211]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acf6c46sm2536585a.127.2024.11.06.14.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 14:26:09 -0800 (PST) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, cong.wang@bytedance.com, netdev@vger.kernel.org, Zijian Zhang Subject: [PATCH v2 bpf-next 1/8] selftests/bpf: Add txmsg_pass to pull/push/pop in test_sockmap Date: Wed, 6 Nov 2024 22:25:13 +0000 Message-Id: <20241106222520.527076-2-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241106222520.527076-1-zijianzhang@bytedance.com> References: <20241106222520.527076-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 Wed Nov 6 22:25: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: 13865587 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 E23C620CCF2 for ; Wed, 6 Nov 2024 22:26:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931976; cv=none; b=hccIr7cbRhD05msrXSYEhousC61ojjalo/UMqSU1D+/yPLHsZk/218sIWxqqBA569ETKSVoqwo/Iz+X7svZVIMFywA3Fb9CYVl9HIquBtNc+EtkzRXdL5uU3xolcUle3k/qhOF55mlvotLxHI389RIyahEwd/m2IbRBEMge0YyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931976; c=relaxed/simple; bh=F3Jf6178lEkVT7qfOFeM0G9qFcfTNALZ8gAId/Er1No=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=THlu+vZCeuwdYNsOYaxMdG75zFw+oe8hKaRw9eVMhR2HdE+XP3nvVMzPXaKDRyfe51a/OLOjNdiAWEs/PUL+OpxN51kOkyNwIFpwoTm/dxRFTd2XbcsKDCMXJh9Q24Z4RPP2PaJX3cF3+oWWNILeIy4GYFBYc/3E92c4Bp13a2I= 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=Z3nO11cF; arc=none smtp.client-ip=209.85.210.48 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="Z3nO11cF" Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-71822fabf4fso223435a34.2 for ; Wed, 06 Nov 2024 14:26:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1730931973; x=1731536773; 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=WQURfqhPucUUeIUEtyy8KbqCtKtkt2GXTCiZiainfhg=; b=Z3nO11cF9tfW7ufwpQcDvxzXVS5ifvTdsnOg53O0rnWnbZj/iy8HChM0XtiUgNEWAq dtewyIl0N2XHtdQYY6OOJDzDDGBGNVSb+0fEpGj5vTqfFWkwC4zy5aQ6WW5n01mXBqkh f+C71AX4vblDe0PcVm6se1H635UTEPMvB4xBCu8MWR0TEQ+oN42mt/+p/8fk6speKWTH Fp7pgy6Akr1DJVAHAVCuU7U9BcmlDVoAZR+5aeQjvKtTNg/KeUNpTOPRfQkFdS6XoFRy 8dvXKwODcnhjOxeU7IKuOoB4xrYDVIT1DK3NXHSgm9Hz5q8byXqsGaSpnasQz31+Dp/W GCVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730931973; x=1731536773; 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=WQURfqhPucUUeIUEtyy8KbqCtKtkt2GXTCiZiainfhg=; b=eQegLOKFX7haQsSiqVXon7N2YvdOkos2lCj1Bpf0EqsXSsmQBYGeKBgUA1sfN+kHGj +xavEnbslk9s0RuoaPTWwvF9JQnE9jUiO2oYMFuz8Ue4JZOVyxIHO0FEB4t810RrOb76 PVU6+l10Qp2oZBI10btJEy9IEfcDJiQgVmEUfFMqTyfIcVjD1BbjnEurVTu6xVE4+6uV BOnWCsYizIAb/m0wvn4gxdTOt8870OATe9foKI8BwYfLaIQY9AYsA2vl0phfAAmupLgp BaV6bhxdgMcy8DmSzLsRMeASaVqDmKHE4P0dfpMmqEpFGGFxIHkLmwI0FDFaYKoM9zTs H5RA== X-Gm-Message-State: AOJu0YyaZfW4sl12I/lFPInxWkz6ouj6bq/esosHEqT9GpH4Y0IAXHy3 IQ/CyJ5DU4GkAyW/aFfXPxDqZ4K3e4HSsxSG5sxCQGMd8evLDVZjTT9TmMCPD7c4VZEHbjj2rpZ U X-Google-Smtp-Source: AGHT+IEQaQ3C0XG+F64ORuRhBZ1F88CEEBOsMq5gHG20F+xqAQ4wz9tn7nHxBlJ/fWUNQkD77lolWw== X-Received: by 2002:a05:6830:310f:b0:709:3431:94c3 with SMTP id 46e09a7af769-7186828da5bmr41249141a34.23.1730931973625; Wed, 06 Nov 2024 14:26:13 -0800 (PST) Received: from n191-036-066.byted.org ([139.177.233.211]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acf6c46sm2536585a.127.2024.11.06.14.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 14:26:13 -0800 (PST) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, cong.wang@bytedance.com, netdev@vger.kernel.org, Zijian Zhang Subject: [PATCH v2 bpf-next 2/8] selftests/bpf: Fix SENDPAGE data logic in test_sockmap Date: Wed, 6 Nov 2024 22:25:14 +0000 Message-Id: <20241106222520.527076-3-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241106222520.527076-1-zijianzhang@bytedance.com> References: <20241106222520.527076-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 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 Wed Nov 6 22:25: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: 13865588 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 757C420C486 for ; Wed, 6 Nov 2024 22:26:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931979; cv=none; b=XFQsMU25IwzJ0Bo4N6FvOu+zeUCNv8pBcGzKOJk9yaKRyPizE3+RNNjh5PcTEfDUQ5i1BUKdQWM63fO0IYLmEdVxVhMLzNl+pI43NsQKzYECyki68MfTdmZBzUOa+qHOzWuX3ElfIqWNFl9POuESyfDQEYm2mPwSvaIO2m3/7IA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931979; c=relaxed/simple; bh=vEjvDL/9pRsbu/Y5kaMsh5Pz+1UMjjvbAxje0DPqRyE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c1344lNoP0qHINZT0KEMOHXMbcPJEfurNUs6iBFzKsVc2nqviDEqWOeKq6SRoYDHKSOOF2m9M6mvWyxC78khQtZxgRJpYT19SkPzTmmyNCHtAgImv5/A2qQFF+yLHOm2Ec4YJkdGiR/k2nbxNjaM6Xa/oEn460IsfjIf2PZ18hc= 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=X3rgrRxm; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="X3rgrRxm" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7b1505ef7e3so20966485a.0 for ; Wed, 06 Nov 2024 14:26:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1730931976; x=1731536776; 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=Eexa5HYKEVjD6R3rV24Gretx25puKESuMNQoJZf1TdY=; b=X3rgrRxmdmGBbO4wbWMcSzIdKHcKWt6JST22FPdov87ccqB5eI8qwhJ81zItraPXrH NJ1NVnJfpwTlSsSI7qY5RXxVcoUP2jzQM9NJbD4LA94ykYL2+6UtYk67yGWWZ/ke9WhR cewi4vcwdZlU6d3LLSuMSe/LRw5EL7VYTcLEZwIcLxVDVjDcL3YQv/SmErSJWA/d9Y7b 0DnzWhkrauaOQuMnZcq50Qm2BMcxCB6NTi1VPUpSjGazLMwYM3aFiflKXwgWjJ97GuVd l1mjfeH6s5FgLUodxt3RLrXq4RrxVQ9ILZJyjsG9zxFplk2xKJi5JCa7wP1NB9xgZ6JC LsXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730931976; x=1731536776; 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=Eexa5HYKEVjD6R3rV24Gretx25puKESuMNQoJZf1TdY=; b=jv4YCzCc2O1oUj0Xm+eTiY9ikgzVGtQTNqix2qH13vRklb4uxPc4LCTMwvhLW3CLTX 8ee0hZFC3fwH1D5MDYduvM75ZnopBfQEjl2f5Q9xK4GPoxzA0qFpSp9gureoP28JmwLM yBySW9wha4y9jlOPfgNZRy+bP+a8FmKq4CuVmLM/xJ355BVh0tql8pE4HjgNlIm2tZiw Z0Ypn1G+QT0bxzxCHMlteKYeif+oygdhVr5py2iSKoEUmJcRozKXvixKrkdESSeYN/+O SqpYDDfhoUg+h0viXSj/X8ohKU8Zw0kh3eqA6bcFqleWR3LyaiUWUy+4pjqQNGpvg7K0 0ODw== X-Gm-Message-State: AOJu0YztZXqZ56DqacWs7jfS3wKJ+ODPTRg5BbJb3OzdursdlSThOV6/ jWQHmAjcWkN9ZZuezgQd7w/c3e92mSivP3knvWXHfuTPRzp0omsjsS9koZIQZSGL1jrRCl+UsB0 / X-Google-Smtp-Source: AGHT+IGetZqTTQLie0fDUOt815GdjRKTeDYpP+FuwDi/1WHXqOgmx6xtqwZxNrFwJSssoGEjMtlNQw== X-Received: by 2002:a05:620a:4104:b0:7b1:4fab:9fb0 with SMTP id af79cd13be357-7b193eed9famr5864837585a.18.1730931975987; Wed, 06 Nov 2024 14:26:15 -0800 (PST) Received: from n191-036-066.byted.org ([139.177.233.211]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acf6c46sm2536585a.127.2024.11.06.14.26.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 14:26:15 -0800 (PST) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, cong.wang@bytedance.com, netdev@vger.kernel.org, Zijian Zhang Subject: [PATCH v2 bpf-next 3/8] selftests/bpf: Fix total_bytes in msg_loop_rx in test_sockmap Date: Wed, 6 Nov 2024 22:25:15 +0000 Message-Id: <20241106222520.527076-4-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241106222520.527076-1-zijianzhang@bytedance.com> References: <20241106222520.527076-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 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 Wed Nov 6 22:25: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: 13865589 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (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 8127220E035 for ; Wed, 6 Nov 2024 22:26:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931982; cv=none; b=W3+oCinRUAUjcD0W6NK1i11Ov4AVg1Zs1rBSwZOLWrG1MA2LThRytnjBbEC9tpyU7FzQ+sHaERzgc7xJAv9ab1m5C+uycEgcfgU9Sw7mNwql7Ranh1FRjYcIlUqMS6qBXO4HjPh1UGo1oAFgzieIR6FWv49NWI7I8Y2AORm6Gjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931982; c=relaxed/simple; bh=a3fQNWUrvQf5jt+DPsdchqdB4REVw9CsQ+popnvDTQU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Km62yVhYte0CkiB3Albbm74QMD9whAcX17PjrIZMO7iWqqc+d6ouY3ebYfULuPPMWgTRE+3kTOEoNi286kAOcrdArWakkTlUJs7eofldoYkiFBigpzOOOMBdt6NsWf7BTxBPzPgxy79/3OD6o0nYaY7nvJhCMsV2JGpIlymMbbQ= 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=Tibz8Whb; arc=none smtp.client-ip=209.85.222.179 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="Tibz8Whb" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-7b14077ec5aso129236985a.1 for ; Wed, 06 Nov 2024 14:26:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1730931978; x=1731536778; 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=T75CCI2KA6e0pgIWd3b0Tdu1hojKJ2r+0qGRtXrFmLo=; b=Tibz8Whb6n7gONX3l07KYkkrO3x2SHYm/csT/IsH6bI9GjlzR1J8m1NpsFsPKwJHfD 98RBVwUvA8xx4q45zvmfAFORJTuhAAyMT3/ON4Yx1sMSbJPx3Zrb9ONxO7CitOZzXmOB xmve9j/ws9tlRFfNQhjXahfjSTSmePmYlYiq0JkEY7dqFW3oWOBeE7zStFYzYmh8wZg1 a0DYpgREdY9mH3AnYrR4N/kPjr4pwWKolw2AElngvG6FmWO+p/xsur+n6Ps7cCaCiuQy eXpbpKiSzT7Nl6YglUkaio/1MYmTDQ0eSdKOBXMDA+vigVAcVmazY/GblQq6UvNfPXjq 3Jyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730931978; x=1731536778; 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=T75CCI2KA6e0pgIWd3b0Tdu1hojKJ2r+0qGRtXrFmLo=; b=KzOoEclG1UL6vzCHAKClOpnab4d0jR6Kc/XzdoYUtryrPbu5pNkFBzpzV0GMCn/qED efyNNk6TB7aL5/twLsK4mV6Mosrr46NPLjvJ5Kp4x4kFSWpPx6dbSMhI8JG5OVoKsxxR UV+KUWKRbuuXR2KJ4/mhh2HVsYadQ2omX18NerrLHdUFG56P6sYi0Bj0B6Pktr63XP7A kTd5sZKBuPljvWniUmtauIF8O7G3ld/DlZmMMm26ULX57mTVDzPUbC5xzqFL99gSauzZ Gfo6UTfIuFw3t8rGIj5xwBgps3lNxzjeL71opAFVsHQTtJos/TFBubhWpxbVcUncQDn0 7rXw== X-Gm-Message-State: AOJu0YzsHpjFfXzUp9ohhxvyJUCqa0mcISmujtXZarXVULuGkxzw1i56 eiE8lv0KBtjIqivLCUKhEW6hJlN+okfpEeYiJ5S1KfeQhEBljS7aAJ21YVmZM5ogxCxvmA2ZIW2 I X-Google-Smtp-Source: AGHT+IG/LvGiq9++yolCJCnYZz+H1msLskYqwhA0EysouBKjBstgIxEf0iIpEQ8TarhUxsCO4Ehftg== X-Received: by 2002:a05:620a:280a:b0:7b1:45f3:c28c with SMTP id af79cd13be357-7b3277b8abfmr137912785a.16.1730931978056; Wed, 06 Nov 2024 14:26:18 -0800 (PST) Received: from n191-036-066.byted.org ([139.177.233.211]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acf6c46sm2536585a.127.2024.11.06.14.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 14:26:17 -0800 (PST) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, cong.wang@bytedance.com, netdev@vger.kernel.org, Zijian Zhang Subject: [PATCH v2 bpf-next 4/8] selftests/bpf: Add push/pop checking for msg_verify_data in test_sockmap Date: Wed, 6 Nov 2024 22:25:16 +0000 Message-Id: <20241106222520.527076-5-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241106222520.527076-1-zijianzhang@bytedance.com> References: <20241106222520.527076-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 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 Wed Nov 6 22:25: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: 13865590 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4ED2A20E038 for ; Wed, 6 Nov 2024 22:26:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931983; cv=none; b=cwuAx6nC+nBr3KgllKNVvIHrSo92PxiSUd7CfsxQaQK4UScBXWcuDN+mN6SRLFHCyy4IGG3gZTfnVJr2Q/O2Dk/IPieCY2kv0nLVR+Bfp1qnMM0ZFncbFkGlm6kTnLd8crAI8y73C84DifoSIN3pBfP1CrEYOywC3DfMEuY6YRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931983; c=relaxed/simple; bh=0+lZiHUTqovga3VRLemzrJJ+m5v+hkB9S5f4p34gZO8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nXE46htxZ9aGeU+p4s9WAWFfgYyc+4oR5ZgxrS3wo7DfiQVJGmVHAYDNH6ZwwQ2rctP7DyfYMwUfQjBboA8VJ8rbE5SUTPdwWg4sPwdTKYvSE2iF1mW+8xb965jC6ClDBdB2DS8L98UsMS2HT7zSjQpdvDE86miJoFCpNIuQAxA= 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=MUF4N1Md; arc=none smtp.client-ip=209.85.222.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="MUF4N1Md" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-7b1434b00a2so19424685a.0 for ; Wed, 06 Nov 2024 14:26:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1730931980; x=1731536780; 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=dSLUUA+3gK7LBKeIPsZWWeloCTFG/7YxTHddhbQVWX0=; b=MUF4N1MdOvGfWEzHeuD1TW2AiN7spLRkiZScHuga1pfUQ7L/ZWGSuZwmL5ijH1v62g f1P2p4PFsRKFK+RTDfWBCTVFHjShOiXCodvW7EzWnmHook8rOdUcd4EA4VBMqAS5iCug 2GWYKm6ecnt1qGpx1W3bc4VYLNcvonVh2ddx6G2HlUbti+g2kpkszPc7C6kKDRYaX0An SU8SaYrv+BontyDb201vNgzhjnl+NxAGmMYovKkV3nUFs1PbmyKK0iIzixak6vi2KUNk tBjiKY95uPkorQ4KQ+TdnB2v6BHQLRNCeLv5NUmlhrQ1wHCxjJpngSyFPIDSbXUpIkLG GlgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730931980; x=1731536780; 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=dSLUUA+3gK7LBKeIPsZWWeloCTFG/7YxTHddhbQVWX0=; b=crNX1jz3t269Nyr/jH2gdMF537nfMVnFSISCd6ZF18UOdlcWDHFVAWW+fmQR4jQovH hVc6SwhwgCZmacM5bhvX4+1glayTd47XETLWK+lcmgxHuIt8ijyNu7Q1/g97OZR7gzCd 1fVZiVVhjStEWZM/jw8kfAOhh4+slZIs1jfmWTX1rZ7dcWScsT9KMeRt2f/72B2cdGZe xexho+cZ8NBvLI//G3IG7zC7147OItRhURa/iji9ty2imSmuoIXZfyqhfmpGLwZs5zSQ yJws1ERxslY8KarXPZeZXAdnlKIGRhOwazXVJhePUYLg0bi4ISPmm5YohMRdU4V8k1O2 bwKA== X-Gm-Message-State: AOJu0Yy0rh7Kl4PPM9e3OJfzoxx/EaYu+hUmUX+adQAQo44YEcdNBCLL UpMoEuAwDW9SR91HpHrOcAh9g9tFAMZRghbPqyCnOjFCe04ADRQ4olP8tMflS6Lr/AoYJ71+Frj M X-Google-Smtp-Source: AGHT+IEOl6BpqHaCHe/PLkd3sxGFfkdqT6aBkoY4ehGu479yy6aPii/3bK1D8LBwg94wnefW4PtR/A== X-Received: by 2002:a05:620a:4443:b0:7b1:52a9:ae1a with SMTP id af79cd13be357-7b2fb94e3b8mr2945383785a.4.1730931980408; Wed, 06 Nov 2024 14:26:20 -0800 (PST) Received: from n191-036-066.byted.org ([139.177.233.211]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acf6c46sm2536585a.127.2024.11.06.14.26.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 14:26:19 -0800 (PST) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, cong.wang@bytedance.com, netdev@vger.kernel.org, Zijian Zhang Subject: [PATCH v2 bpf-next 5/8] selftests/bpf: Add more tests for test_txmsg_push_pop in test_sockmap Date: Wed, 6 Nov 2024 22:25:17 +0000 Message-Id: <20241106222520.527076-6-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241106222520.527076-1-zijianzhang@bytedance.com> References: <20241106222520.527076-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 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 Wed Nov 6 22:25:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13865591 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (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 A6B7120E310 for ; Wed, 6 Nov 2024 22:26:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931985; cv=none; b=sdpBSv1SaJ1RNgKxJP8MlxoWCL8XZT91BTvfAoNEOJ1ric1oM68oED581HONOvzDwwXBMiRArHn8peXQH2/LfzV/6VXkQjYg5Y/CN+6QdxKB96gGaQ53z/GEhOH+7rCIaLgx0teo3N/kthoB0ZC25nWs7kSs26GoYJO5sSjuGaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931985; c=relaxed/simple; bh=xY3Iw8eGGcMBCG99o2KeIj7WYBk9LPCRvd2nwY/GJuE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M5ZKLWO5KbPdgosSsNM+cw/0liud6YrCp1qa14Wf5ZyVgabVEdTiU8PFIuOyJUIKom071p/shO9qZ4SyzzbGqIId+c0P6VimPVjwraHV88XMmaNF9LatdRbQ9EWBI6q9Himk18xTX2BunrmQ6PWd6qlkQWcxOkyvwfdUdrwKwQA= 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=U/tbhTFv; arc=none smtp.client-ip=209.85.210.53 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="U/tbhTFv" Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-7181caa08a3so232172a34.0 for ; Wed, 06 Nov 2024 14:26:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1730931982; x=1731536782; 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=h0HGA2syRN5y9s7R9m7dm5GeVLMrSiqb/s9x6nYldOs=; b=U/tbhTFveNp1RcR9SvMSrC90TTdvNEMi+36WZNRFbppeuXhW4XJf2JykckqzWpngoA /RvTV1YPLd7vfoJPa2hCExGiED8jo3qsAhWZmX7rokb0QT0D4eBcKkJbqvJxNbUTDPBO d0jnHtRbD95ZYaD/qRWM+obhHhPXkqFk3dBDs0sZaI3W03V5iYNJbb2qoLCJxU8RTciA Slbt309+CnMzRwFfBccxPszzV/b3J9gDA7xnK5F7uSxeQaXadAPqxznOEjErj/iuHbn5 1m1tEDcvxMnJhqCzs4cNkkK8lgNSZIxJCsqhFzvbHkh1PScuX52YtDNurDhdCNZIsVIB Odxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730931982; x=1731536782; 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=h0HGA2syRN5y9s7R9m7dm5GeVLMrSiqb/s9x6nYldOs=; b=IsaENvoPA4/v8rriV1hkXmwM8H8NooZUytJj5pCDVBM/ixHDyGZyyIg4NJZlHJO9vB 6KjZ3GhCcysJ2zxhLqXmYVAFeCLIxeR/1iuIztwI+QgeAdyM6uellqtoS+n6r92ZyT+2 RwkK21fBNGoDpjw17UYkNXeWilIG2JXHdXMKNvIYhMndeYlJ8Zr7aU4/kZ7vE4CPPeNB RUQ+/NXU511poe7CUZI4JhZkODhwarvDSGIs1naEMUs8P0kQIaANxHx0xbQwFrd1+m/+ wfDoUwLBUngUQQhZ5F5GaRy4dfOUJPjQR2TfSaNM9jq3qyTpMUETwotWgiowE2IbJlCJ PFKw== X-Gm-Message-State: AOJu0YzpfTJZwuTnonD3vWr5EjUSIb3KdgISM1QVJ73QslOeSbYwTDVa 2iuQint5wCOOdEImNZRHIHLewj+xVrDZsmtONqotCLjLhBDHR7h3Od6LR/bdYdsIeDNHMhJRkT9 J X-Google-Smtp-Source: AGHT+IGWKofCI6TAOtgbyO7DqfjcexCEellUqbkcRY5XPUrYDGLq4TV/mfqzGtVhM5LJj4ZqL81z/g== X-Received: by 2002:a05:6830:907:b0:718:194d:8b1 with SMTP id 46e09a7af769-7186828191fmr38372850a34.23.1730931982401; Wed, 06 Nov 2024 14:26:22 -0800 (PST) Received: from n191-036-066.byted.org ([139.177.233.211]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acf6c46sm2536585a.127.2024.11.06.14.26.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 14:26:21 -0800 (PST) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, cong.wang@bytedance.com, netdev@vger.kernel.org, Zijian Zhang Subject: [PATCH v2 bpf-next 6/8] bpf, sockmap: Several fixes to bpf_msg_push_data Date: Wed, 6 Nov 2024 22:25:18 +0000 Message-Id: <20241106222520.527076-7-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241106222520.527076-1-zijianzhang@bytedance.com> References: <20241106222520.527076-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. In the code block of "if (start - offset)", it's possible that "i" points to the last of sk_msg_elem. In this case, "sk_msg_iter_next(msg, end)" might still be called twice, another invoking is in "if (!copy)" code block, but actually only one is needed. Add the logic to handle it, and reconstruct the code to make the logic more clear. 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 Wed Nov 6 22:25:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13865592 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.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 CC85020D4F0 for ; Wed, 6 Nov 2024 22:26:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931990; cv=none; b=bB5Bvye3DUnKyyrbDcQKEFXrDN43OQsTobHTfIfEqDQkiuqrNUqWnWhwB8dqv9t0GvLFOlqNomKYx1BKxoc28rlhnENH/+Tblch09RfxTMGMkhMreWNrG3/NEgi0T+nZh7cU1Wn6GmACjYgK00A82zY//mEJq4m0kj2uwBWV//s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931990; c=relaxed/simple; bh=/m+0uR0MlsRfpngmViBSR0nIX7YXBrTZrqLMMXQ606w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TdrMa11lQCcEwe8Z2xuuIlRJwzI/65MUDuaBcUVbtcIwKlZP/NjsLrbn+wRu9F7A4tqABNV7tIRrTDby8iQcSqLoTYP9qD2vK5ynpF8fhi3nenEq/Ivk8G6iAKTY562nQAFb7FFWE8tFbnPRgYPDdkeCn7wGuXt98VoSfTi05Zs= 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=C2MQmZ9y; arc=none smtp.client-ip=209.85.210.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="C2MQmZ9y" Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-7181885ac34so253936a34.3 for ; Wed, 06 Nov 2024 14:26:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1730931985; x=1731536785; 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=0TeP94uGFKCrHms83cSM4YiyobYdbFTOX87WRlt5MwE=; b=C2MQmZ9ysH4LaYMsCpb4UYkomJ58e6HhRecTAObLnn+2p7Hg0rYlBEaobg/IBrwBSD GXAHvSkPFVq4RxP8LMW86EC3GLQodabf4R/E6jshoDSJJ+bVhep2pW3hD65qBSL0v8MC Jx3y3KMdN4dvfiLZv2djfYgDDmCtgnlrMAZeMi/KMRZFqmoRHYScrV91SX0pD1N/5bGF 82kZSoMhbedk+ThHWclFGtFD/WNPwk2HvCweXfDtb0qqdkDYk5AlexWrRqL2gmqu7e47 bxZIo1JJZpi5hvOEgnzetOgxb3G70UcFGma6eUPrl2u1MG0YFXJs/Zn6AyccEb6Yzki+ 8pLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730931985; x=1731536785; 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=0TeP94uGFKCrHms83cSM4YiyobYdbFTOX87WRlt5MwE=; b=DM3aJUAEU6PvaX1Qtahquvu2IYoJrIFtV7mqqxJL4wqSPq95Ox1pzs44st7ZXeAZ2N VVvqlim/FkM9TGCcNTWpjPa7wtw8rmavJu/bcCKoPlVFfiz/70l2MoyEBIzcnSCkvoRx lFzczUTI/34oJODiKkz9Zv9OGBBqAb14ne2Fm43akMKBjLtKiij+uBA2sqTkt0bIKJM6 YVs6+a+w7H3TwdwO1lbSauWP/VU3Svk7hJRqr/q5M9L3aBAXCvb0hUDrGu6Xa1lygf/3 a4/J8R+PV7KiIcqSKUEctdd6cNI1Fw8CqkcYCIfMcJrrujyV4oFzAPbvhNvioFQ38tBL ooEQ== X-Gm-Message-State: AOJu0Yz3m9E4KyH9PvYqf20nAoWoPKtNZub655Mp0cIgRP0C97EDBHU9 fam7xYTWUCYWwvzVSQUxP9POokN2YBpaDmlfxoPYNYd5fmBZY0gNRoylzICQRjWOiIKrkKzG6JR 2 X-Google-Smtp-Source: AGHT+IEDbyL+ocJjaFcUDxCmW0bULbH4cOPxfLI9IqKQtRqet0QC05czQrSXaQEQ9wLVSuo/eOAQjw== X-Received: by 2002:a05:6830:6e82:b0:718:5a53:cc61 with SMTP id 46e09a7af769-718682964a8mr41678703a34.30.1730931985518; Wed, 06 Nov 2024 14:26:25 -0800 (PST) Received: from n191-036-066.byted.org ([139.177.233.211]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acf6c46sm2536585a.127.2024.11.06.14.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 14:26:24 -0800 (PST) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, cong.wang@bytedance.com, netdev@vger.kernel.org, Zijian Zhang Subject: [PATCH v2 bpf-next 7/8] bpf, sockmap: Several fixes to bpf_msg_pop_data Date: Wed, 6 Nov 2024 22:25:19 +0000 Message-Id: <20241106222520.527076-8-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241106222520.527076-1-zijianzhang@bytedance.com> References: <20241106222520.527076-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 Reviewed-by: John Fastabend --- 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 Wed Nov 6 22:25:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijian Zhang X-Patchwork-Id: 13865593 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 4E3A920D4F3 for ; Wed, 6 Nov 2024 22:26:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931990; cv=none; b=SN42VOQZWeR90taHukkgpAzwexVQZRlDOPDplUqKmE3Pp+5AnIbRlEHTntPbgHu34B0Zt0EG83I/1h36vXs2xSG3KnzOQf8q+PFhFnoegME5tTac0MhltK/xz9OrMSFbLdDe9cDu+dH05yz6mLThNI4NufLRP8Y44q4oKsRMkQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730931990; c=relaxed/simple; bh=992mL4nu9YkF8+FFrpmymEGtYiWtLoYnRcBQBHxN1gk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=erm7ViumgtyOFbAyH1QMu8m6YDVLR87pWpsQoQZjz8BhH6fgSKVapSqzQ7SyHy4yPmlEG5RX5adDsjXCKYzxyuiVuAd0JfYyQnCtuKQUdJDXBC5qmgu/+NulG1Qs2y6ZwDZvJSrn7oTGqJ4Lrioe1DDiCv/N00C3eabO3eNJYAw= 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=VWerLxFZ; arc=none smtp.client-ip=209.85.210.45 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="VWerLxFZ" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-7181eb9ad46so250663a34.1 for ; Wed, 06 Nov 2024 14:26:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1730931988; x=1731536788; 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=NWrBsyggpZaGrTIso39oj3Q+5T3iMLnbjMhz4XNdMpI=; b=VWerLxFZIoK4t5z6Dn/w89a0j/i96azcBHLiuzf3ZO3pz2I8J8NnCUkOrCKDaF2iTO gCmYjT5AVrnTjraS7fdsQojrRDu2rzqXdx7SHR6t8gtm1N859w9FKOns36e6ihagsadH 9LWkvF0RGyYT5ICbNGZOuk8vNbuCtN9rbQtxjtVvERxC41w/aXcoRXjKXEOK5q3JfDSO WQQfELOPeKJM1cirr6kcil8F2U1NYO1QU9vf3YQ13KoM+Xhwgmt0RKEFdu8ohRHPasSD m6krx4+tsW0I1o1z+zVt86Mv/E9uIp0DD2h6321efqDZmzJKwjv81WALGmw9VOELY516 dfkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730931988; x=1731536788; 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=NWrBsyggpZaGrTIso39oj3Q+5T3iMLnbjMhz4XNdMpI=; b=XdxQ/X+8so9mMIjLIq+svnQaEPI9S944xCsl5k+LCda91m5GqNVdcNn3keGDfkPrkc hCdkhKC+BncmuDw8Zh9lWKQLDYRKeG1sMcmfqEIQS5I4vkszumX8Iv0MXei75k+WbGHG IQCrxm7dqJMp8q1x7WBPH9hwy0qJEw9X6bRYfK8A1HcAtTfD2obyfbARYEjXNlZEW9xv QGmtzYyzE/7Jsz9Nok3mCDVb67jgWGLHWoP16UB+s+44VCXPAJEbNgfkuRGF6XEEbCGN ++rKrVmDMx3mdbbe1oUZ8dbj+qn0zvOMTXqDyg2QVND/NOS3P3kU56uY1uXwhErI6IkD ATZg== X-Gm-Message-State: AOJu0Yw8UKmtQDGCzMEIP/VlsRBSy4kbvDKCDdz5mtN4Qgpp2kiSC1Fp 9f6NXM1TIl/nt+ciUpOGCKDhUq2du54PrKBxyAydqRjz7VSEfPIdK2bZ7XQXzGT1ukWLRRTSZMb u X-Google-Smtp-Source: AGHT+IFoo5hLK6lAdsyo3xBYfefR9VHgDBvYV+6gr6X2lyb5TjyxhOM6zzGvdMhgspnPSqspWJTH3w== X-Received: by 2002:a05:6830:2817:b0:718:ce7:9b62 with SMTP id 46e09a7af769-71867e668cdmr43546733a34.0.1730931987931; Wed, 06 Nov 2024 14:26:27 -0800 (PST) Received: from n191-036-066.byted.org ([139.177.233.211]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acf6c46sm2536585a.127.2024.11.06.14.26.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 14:26:27 -0800 (PST) From: zijianzhang@bytedance.com To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, mykolal@fb.com, shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com, cong.wang@bytedance.com, netdev@vger.kernel.org, Zijian Zhang Subject: [PATCH v2 bpf-next 8/8] bpf, sockmap: Fix sk_msg_reset_curr Date: Wed, 6 Nov 2024 22:25:20 +0000 Message-Id: <20241106222520.527076-9-zijianzhang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241106222520.527076-1-zijianzhang@bytedance.com> References: <20241106222520.527076-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; // corking is importrant here opt->iov_length = 3; opt->iov_count = 1; opt->rate = 512; // sendmsg will be invoked 512 times ``` 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. In the second sendmsg, since we are in the stage of corking, psock->cork will be reused in func sk_msg_alloc. msg->sg.copybreak is 0 now, the second msg will overwrite the first msg. As a result, we could not pass the data integrity test. 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 = {