From nobody Fri May 3 22:48:03 2024 Delivered-To: importer2@patchew.org Received-SPF: pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; envelope-from=linux-kernel-owner@vger.kernel.org; helo=vger.kernel.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1616366871; cv=none; d=zohomail.com; s=zohoarc; b=YyU3HYLBojFHVdTYJZJZ7vWZQvubLb5aVfxM2/CPVu2GNLKMDCP5hAQ3JJo+fv7BTbu08qEZ+Cn5CVulmeYJZuIKljo1wA23wBAiAhVFp0NHradDg7gHIqQ9/8TC+kwNMb0k41JZnyYdGM/hitZorW8Dayj7hOfYdwtU6qoZfQQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616366871; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:MIME-Version:Message-ID:References:Subject:To; bh=Ptq96JfaAwnF7JCWYyRFzxbIiqtchclo0BTDiv9S/Wk=; b=jr6IqsF8ZVYEo8xI0NFVaXCHJAqJdftI1CIMNo0jdsYX43PhdFBxIMDM3UkpblJvQ4/PkVGa4JVnWTSs2rg7ofb2iYfHwFcW8VBHgNQX+Sq8jj2zbY7ZX5WFz8Zx+/6UcL195gqo2WguE5151/6ykQuz6HNspsCrlH5wurF+BBo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mx.zohomail.com with SMTP id 1616366871609861.5204227843428; Sun, 21 Mar 2021 15:47:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231247AbhCUWrL (ORCPT ); Sun, 21 Mar 2021 18:47:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbhCUWqY (ORCPT ); Sun, 21 Mar 2021 18:46:24 -0400 Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35B3EC061574; Sun, 21 Mar 2021 15:46:24 -0700 (PDT) Received: by mail-qv1-xf2d.google.com with SMTP id x27so7837279qvd.2; Sun, 21 Mar 2021 15:46:24 -0700 (PDT) Received: from localhost.localdomain ([179.218.4.27]) by smtp.gmail.com with ESMTPSA id k16sm6556825qkj.55.2021.03.21.15.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 15:46:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ptq96JfaAwnF7JCWYyRFzxbIiqtchclo0BTDiv9S/Wk=; b=A46RN/59frzmi8xXTRMgR3qcn+iO/QIf8ZDC58ZzR4Ii8OHXA3ey4hlzimztmewcER xcmZ7U+qKGOPsg1WWiZgo+E9jLfI2V33NGKtncFtqlZ2mP3qVm1K2PlOtDAcpiOXhEQt jwGGD3KIucGM89HgeFSfskn1BXpMdvk3+viGhXV/6p0YqRKWDQVSVWDq4TBP5I5Wk2tH X/O6nSk2Dgt0e0i/UYqr/GOEn74X21gTBULCc1D34FkSp/mClzxinkxzJI9eWV4Gnji+ 1VCzxOTtbU1ZMcu4Dc3bmoPiNngC1AXY3dMmba64ACGhrbSz4n6aSU83oPhuNAa/6bK1 NJjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ptq96JfaAwnF7JCWYyRFzxbIiqtchclo0BTDiv9S/Wk=; b=iS8p3TJwKjRLnRfY7mICJD7Oj9xCnRagFAkrUMD2x+Z7V8aDZlyz1gMlm8/wEByoDY g7cwZhIoLyXcy7dMb4VF1sVUlhYzBiClpCv+CUSzSb0NxT6oZCYoYeazM6C2vYDnB0PP U2LPMJO5ahdvNvQsIsvqSfRMJngi0w8IVuGIxm023szojRaht2Zapa6WJLUtsxJaKibS nwDuPE9c7fUly26EYZjmpDVquBjkaNrssJqTWwKQo7C9Xcp45Sx32nM60JhKYMIxRqfM +WXXGUZVgLBqGy/OL3owx9jeZsw5ADUykPSlZU3QuFZsJQO8PdRD9qvonsBtoYDzNdvj TEYg== X-Gm-Message-State: AOAM530kIaX2BRRULdmQ7v9mZsjKi80/ps7/7m0zfn+UYf4Ruz+ez6EI g6VkjnHGQf8NmNLkFxHYTTM= X-Google-Smtp-Source: ABdhPJyIf0xUN3hhCZP8/1QG4wlVUEMxBrMp/mKOIhbY2Bf8kQfZynD3fAi8l8TN/ZMBnOoxL9irYw== X-Received: by 2002:ad4:470c:: with SMTP id k12mr18834786qvz.9.1616366783461; Sun, 21 Mar 2021 15:46:23 -0700 (PDT) From: Pedro Tammela Cc: jhs@mojatatu.com, Pedro Tammela , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Shuah Khan , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next 1/2] bpf: add support for batched operations in LPM trie maps Date: Sun, 21 Mar 2021 19:45:20 -0300 Message-Id: <20210321224525.223432-2-pctammela@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321224525.223432-1-pctammela@gmail.com> References: <20210321224525.223432-1-pctammela@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Pedro Tammela Suggested-by: Jamal Hadi Salim Signed-off-by: Pedro Tammela --- kernel/bpf/lpm_trie.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/bpf/lpm_trie.c b/kernel/bpf/lpm_trie.c index cec792a17e5f..1b7b8a6f34ee 100644 --- a/kernel/bpf/lpm_trie.c +++ b/kernel/bpf/lpm_trie.c @@ -726,6 +726,9 @@ const struct bpf_map_ops trie_map_ops =3D { .map_lookup_elem =3D trie_lookup_elem, .map_update_elem =3D trie_update_elem, .map_delete_elem =3D trie_delete_elem, + .map_lookup_batch =3D generic_map_lookup_batch, + .map_update_batch =3D generic_map_update_batch, + .map_delete_batch =3D generic_map_delete_batch, .map_check_btf =3D trie_check_btf, .map_btf_name =3D "lpm_trie", .map_btf_id =3D &trie_map_btf_id, --=20 2.25.1 From nobody Fri May 3 22:48:03 2024 Delivered-To: importer2@patchew.org Received-SPF: pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; envelope-from=linux-kernel-owner@vger.kernel.org; helo=vger.kernel.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1616366871; cv=none; d=zohomail.com; s=zohoarc; b=iIDrP1cRsqvl+HwKgQ1LTe9LYb7UBeNm8xPYp8rnYWmnb6O78h40Bs/LG4hIRnFhKVJiNoxzt3d2MUcOM0hOGkcnP6rhv5gJII02gZM/BUBoze2IGaZInKF93XqRPM9LqQsu4evr4zMfnlO24Aph5wIKQmrij+iL+T+SLhRYvmU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616366871; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:MIME-Version:Message-ID:References:Subject:To; bh=Ly08jgegs+pIqpL7gXfYm3S03fbXbYfaOyO7/zCU9iA=; b=LvVPY5M6WTVoQ4N3ygIEXGnhSN42I4NHV5YS1jEhiGG5LSUkhhT3Fh6/4rwL/qm1hclQC9VPEfvCVm5ybXOa2U05qhqOLzVHhroyC+RPo1f6Fac6jTWJcxet/YsHSUwo0O4EnsteB+ehG7xP7xYQ9Xp9HrPGujR5qalYGuiNDMc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mx.zohomail.com with SMTP id 1616366871860815.248830027449; Sun, 21 Mar 2021 15:47:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231276AbhCUWrN (ORCPT ); Sun, 21 Mar 2021 18:47:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231152AbhCUWqd (ORCPT ); Sun, 21 Mar 2021 18:46:33 -0400 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0382DC061574; Sun, 21 Mar 2021 15:46:33 -0700 (PDT) Received: by mail-qt1-x82a.google.com with SMTP id h7so11055200qtx.3; Sun, 21 Mar 2021 15:46:32 -0700 (PDT) Received: from localhost.localdomain ([179.218.4.27]) by smtp.gmail.com with ESMTPSA id k16sm6556825qkj.55.2021.03.21.15.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 15:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ly08jgegs+pIqpL7gXfYm3S03fbXbYfaOyO7/zCU9iA=; b=XfbeLePCvyckLV/hvwZllGXz+MxJ1T+EyQAxn+H6YIiwHFZxRpQmy50trw60PTcRGF tWUBSWox8uPjAgaoGIhA6CArPQN4VKQMuqFfr8nfUZsOQg6eft0myhz7JuAUVGL6mKD5 61f9Qb5gpkJIvDlTjCi4exal2igilIIg1Kt66RXY1nt9KpcGm/2B0WPMiQQ9cjFSZi6/ gR7kksJUZKFSyciLFU454gx730zMuuNUm9bkJzFIE6MHozLpKo1YqsqTUuWk7ybYaZWn i6CkfxNrS/k87sZi0Gsz45gwDINfFo1ht6JEoEKRRzQc+cg4NhBFj1xOwKS4AucrNDaG aC4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ly08jgegs+pIqpL7gXfYm3S03fbXbYfaOyO7/zCU9iA=; b=eJYTS8AJNpDornZ1nYFwvOFa7YosWgQIOxWKGehAXERYDN33QbWtWtF516H1dLNNYY jhwQ7hr0kOXvb8b2mNWHCUb6n8RnrLY4G5e6fvmqnn21tMseXCnehP+P+7kYym8bdvbc NelMqqreKfFZwVWYib/TYhesnHbJL5E6bat0vmA8RArr1Xhcl8HHnShqSzGtnCWgcojo VC1a5c5Vb9qaGKyj/90PlyznTXVHHLJurglATnrFdo74CGqpXQffuY1ndRjQ9iSqrH1i M7k8QnYw9wzx0D9sEmWI+jZg0BGhAzrFvR8qD/f6JQOR6fomBpMZyUygJVnCCcyeBT+w 4Alw== X-Gm-Message-State: AOAM53115Li0JpyZjAFJ+Mrz1VPgaXrl2S4ON0ARfWWttXAjdYGZsXl7 +NCAbaw3TqZRjwVbSlvnPF8= X-Google-Smtp-Source: ABdhPJxNz47fgib02/DUbYyFHFBmkc7bvnaXYEOB50C2HTTQngWae2JqwdQUpARPZaBFZcB7ntbgtw== X-Received: by 2002:a05:622a:11cd:: with SMTP id n13mr7545369qtk.52.1616366792270; Sun, 21 Mar 2021 15:46:32 -0700 (PDT) From: Pedro Tammela Cc: jhs@mojatatu.com, Pedro Tammela , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Shuah Khan , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next 2/2] bpf: selftests: add tests for batched ops in LPM trie maps Date: Sun, 21 Mar 2021 19:45:21 -0300 Message-Id: <20210321224525.223432-3-pctammela@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321224525.223432-1-pctammela@gmail.com> References: <20210321224525.223432-1-pctammela@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Pedro Tammela Uses the already existing infrastructure for testing batched ops. The testing code is essentially the same, with minor tweaks for this use case. Suggested-by: Jamal Hadi Salim Signed-off-by: Pedro Tammela --- .../map_tests/lpm_trie_map_batch_ops.c (new) | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/tools/testing/selftests/bpf/map_tests/lpm_trie_map_batch_ops.c= b/tools/testing/selftests/bpf/map_tests/lpm_trie_map_batch_ops.c new file mode 100644 index 000000000000..166d0464a0d1 --- /dev/null +++ b/tools/testing/selftests/bpf/map_tests/lpm_trie_map_batch_ops.c @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +struct test_lpm_key { + __u32 prefix; + struct in_addr ipv4; +}; + +static void map_batch_update(int map_fd, __u32 max_entries, + struct test_lpm_key *keys, int *values) +{ + __u32 i; + int err; + char buff[32] =3D { 0 }; + DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, + .elem_flags =3D 0, + .flags =3D 0, + ); + + for (i =3D 0; i < max_entries; i++) { + keys[i].prefix =3D 32; + sprintf(buff, "192.168.1.%d", i + 1); + inet_pton(AF_INET, buff, &keys[i].ipv4); + values[i] =3D i + 1; + } + + err =3D bpf_map_update_batch(map_fd, keys, values, &max_entries, &opts); + CHECK(err, "bpf_map_update_batch()", "error:%s\n", strerror(errno)); +} + +static void map_batch_verify(int *visited, __u32 max_entries, + struct test_lpm_key *keys, int *values) +{ + char buff[32] =3D { 0 }; + __u32 i; + int lower_byte; + + memset(visited, 0, max_entries * sizeof(*visited)); + for (i =3D 0; i < max_entries; i++) { + inet_ntop(AF_INET, &keys[i].ipv4, buff, 32); + sscanf(buff, "192.168.1.%d", &lower_byte); + CHECK(lower_byte !=3D values[i], "key/value checking", + "error: i %d key %s value %d\n", i, buff, values[i]); + visited[i] =3D 1; + } + for (i =3D 0; i < max_entries; i++) { + CHECK(visited[i] !=3D 1, "visited checking", + "error: keys array at index %d missing\n", i); + } +} + +void test_lpm_trie_map_batch_ops(void) +{ + struct bpf_create_map_attr xattr =3D { + .name =3D "lpm_trie_map", + .map_type =3D BPF_MAP_TYPE_LPM_TRIE, + .key_size =3D sizeof(struct test_lpm_key), + .value_size =3D sizeof(int), + .map_flags =3D BPF_F_NO_PREALLOC, + }; + struct test_lpm_key *keys, key; + int map_fd, *values, *visited; + __u32 step, count, total, total_success; + const __u32 max_entries =3D 10; + __u64 batch =3D 0; + int err; + DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, + .elem_flags =3D 0, + .flags =3D 0, + ); + + + xattr.max_entries =3D max_entries; + map_fd =3D bpf_create_map_xattr(&xattr); + CHECK(map_fd =3D=3D -1, "bpf_create_map_xattr()", "error:%s\n", + strerror(errno)); + + keys =3D malloc(max_entries * sizeof(struct test_lpm_key)); + values =3D malloc(max_entries * sizeof(int)); + visited =3D malloc(max_entries * sizeof(int)); + CHECK(!keys || !values || !visited, "malloc()", "error:%s\n", + strerror(errno)); + + total_success =3D 0; + for (step =3D 1; step < max_entries; step++) { + map_batch_update(map_fd, max_entries, keys, values); + map_batch_verify(visited, max_entries, keys, values); + memset(keys, 0, max_entries * sizeof(*keys)); + memset(values, 0, max_entries * sizeof(*values)); + batch =3D 0; + total =3D 0; + /* iteratively lookup/delete elements with 'step' + * elements each. + */ + count =3D step; + while (true) { + err =3D bpf_map_lookup_batch( + map_fd, total ? &batch : NULL, &batch, + keys + total, values + total, &count, &opts); + + CHECK((err && errno !=3D ENOENT), "lookup with steps", + "error: %s\n", strerror(errno)); + + total +=3D count; + if (err) + break; + } + + CHECK(total !=3D max_entries, "lookup with steps", + "total =3D %u, max_entries =3D %u\n", total, max_entries); + + map_batch_verify(visited, max_entries, keys, values); + + total =3D 0; + count =3D step; + while (total < max_entries) { + if (max_entries - total < step) + count =3D max_entries - total; + err =3D bpf_map_delete_batch(map_fd, keys + total, &count, + &opts); + CHECK((err && errno !=3D ENOENT), "delete batch", + "error: %s\n", strerror(errno)); + total +=3D count; + if (err) + break; + } + CHECK(total !=3D max_entries, "delete with steps", + "total =3D %u, max_entries =3D %u\n", total, max_entries); + + /* check map is empty, errono =3D=3D ENOENT */ + err =3D bpf_map_get_next_key(map_fd, NULL, &key); + CHECK(!err || errno !=3D ENOENT, "bpf_map_get_next_key()", + "error: %s\n", strerror(errno)); + + total_success++; + } + + CHECK(total_success =3D=3D 0, "check total_success", + "unexpected failure\n"); + + printf("%s:PASS\n", __func__); + + free(keys); + free(values); + free(visited); +} --=20 2.25.1