Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1300022imm; Fri, 27 Jul 2018 14:55:08 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeKP7EUw5J0BivjXAur6F5R7JuFKwtH9LGVxqaJelMFr4czE2uwDTY4S2skV+5FrCuOkmBW X-Received: by 2002:a17:902:7d8f:: with SMTP id a15-v6mr7606782plm.332.1532728508507; Fri, 27 Jul 2018 14:55:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532728508; cv=none; d=google.com; s=arc-20160816; b=oMjL6mN5796coFWEBLOBfqPA58ONW344zLGl8Wbz//PsaqF3eklFVX6/FyHzhqkBd9 S1UXZHgPKznMsVw38VLT3kd/5wKGFfrnpBQBfIvM1TDZxkEfBSXWmSL1wH1SHEDb0q3s hOuS7+0W5mTstln3QswrwuvjWvH79yfZWQicYXXQKW56aVT0KrXwCzgHH3lQrERsUrDd 6zAWokz4+lsnUt5VzULOEVvH8zhRvIFDmQ+J9vnqjHalul1FlSQBfXZ3A7zKMb5PJQTy JU87fKsPWP6doHvzHdTtkJCY51q6aLnRrRRahd4V1zGza0zox1LeAfaXdjCkWX1gobH2 2Jsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature :arc-authentication-results; bh=29NOACPFayXMg25FAWiA0pHV/s5tN/evpNO4eWkigbU=; b=qhVi61hDvdEY4CxZ9rl7qrTOP3Fxvypl9voMjo/4kJct9kXwXm9xwClDU6wKV8UvMW h453vAokHbcqEidCdUCOTU1l7+okMP2aVkFEy0yDdMHgPmfBgvM9mCGeiff6RXJEXSdW 1uqy6NgNH4gSfFr+36ZlA3IyNi7YI0Ij6vHvgWS06esoMu26acl1slllh4q8h0P2Nxa0 1vmOYtIJ0DK8CSgdKjsTUoWUcAQAfEABQ4RnPhhk2abUPioQgn0Z2cJV3xPt5e4Wx3cI 9c7MVFt6InuNAhdtzzguCCuwv8Mpm4SY/VPOwJfBfV92QISQAt27nXHSpNlvR8vyP4Ox G7PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=aqHGpVuF; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=IHVwbKYU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n13-v6si5156186pfd.50.2018.07.27.14.54.54; Fri, 27 Jul 2018 14:55:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=aqHGpVuF; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=IHVwbKYU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390064AbeG0XR1 (ORCPT + 99 others); Fri, 27 Jul 2018 19:17:27 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:52382 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389889AbeG0XR0 (ORCPT ); Fri, 27 Jul 2018 19:17:26 -0400 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6RLjQuK006591; Fri, 27 Jul 2018 14:53:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=29NOACPFayXMg25FAWiA0pHV/s5tN/evpNO4eWkigbU=; b=aqHGpVuFQdBZ7BtSzQQoneboSAl46mDn+/XzyS4vpOoAiOW7AVly35r0TzUX9EgM1BCu HTgYnQ/Hu1F7iNAYnzF3wcui8ct/D3fcVqSr2Y3gbKaS7Sy77+j6tpp66SxFCwU/0E1A jQ/Fq7tEYbqSDNmbNZIw535kIp8DqPCT6UU= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2kgb58r2mv-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 14:53:15 -0700 Received: from NAM04-BN3-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.32) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 27 Jul 2018 17:53:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=29NOACPFayXMg25FAWiA0pHV/s5tN/evpNO4eWkigbU=; b=IHVwbKYUqdzEr6bsPXJho3YhWO/1SkEj7KIMIBhptvBnhX6Gxt6nQVkEcayNx9V6Xup/NNxlGricCZq2JQA2d5ybaNbtdIVn9kJtCwv9/x36J3EgjYWjjK96qe/ne1yKb5YhV0NqlCwa36UpXJb0mP0Tiw7TzgSkTagxZMKJ6aM= Received: from castle.thefacebook.com (2620:10d:c090:200::5:fd07) by CY1PR15MB0171.namprd15.prod.outlook.com (2a01:111:e400:58bb::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.17; Fri, 27 Jul 2018 21:53:10 +0000 From: Roman Gushchin To: CC: , , Roman Gushchin , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH v4 bpf-next 13/14] selftests/bpf: add a cgroup storage test Date: Fri, 27 Jul 2018 14:52:42 -0700 Message-ID: <20180727215243.3850-14-guro@fb.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180727215243.3850-1-guro@fb.com> References: <20180727215243.3850-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c090:200::5:fd07] X-ClientProxiedBy: MWHPR11CA0020.namprd11.prod.outlook.com (2603:10b6:301:1::30) To CY1PR15MB0171.namprd15.prod.outlook.com (2a01:111:e400:58bb::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d956e3f7-e1d5-43fd-896d-08d5f40b58c5 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600074)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020);SRVR:CY1PR15MB0171; X-Microsoft-Exchange-Diagnostics: 1;CY1PR15MB0171;3:KXZchSulSFL7B3V4GkdOC2nUM71z4QivlHwHYtk6WpS6GBpAMkytLSRPH4NXRICr2g+aNnb/CYa9s0faV6uaYj32SFaTOWvEAc9B3N2wBkAGFqP6ZgKdEufqgaH7chx7NnSKwYDO8naZLjW5UIQWq3GxGvUKNG8cg4SHSaUYlCOIPdtX+wvDgd2YzsjyFbvgTAQ82Ekk2gDArK1+jCiYyJDe9oyzf7QGbs0IU50MFdqrzLUpJEBPNug8DLYwl+e/;25:sZBBGM0e+de8Mg6NAAQ+9CZa/EtWJwe2aA26cxg3K2SfEg6yEuqsEGkeAk+f5PRnyYmVdrmwClvK3UZomQgwbfCbsCdX8VmhchxU1L0+PE9kj6OdZ3V3/oL8zGC4CyQB+V3ar5FdINjAlzd7ov7APGiZcx6T0E+8x8bWjPRO+M54/qtDwY9MgWbactQqzcgZkB2FhOMxQR9+8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l+aUKbkqtDj+QxNlct3HAwuh2E6vxntbbCJ0Zu/cu74vRgsboM1lqc7bg1qzWDlLnJufBYCR46OUjJPuOZ0X/jJ/GgbjP35eM2xyyQpsr0gHYXaO7TUUocuNQYiwpLKKdj/0osUXLLAGOSJokaPFxfXQcy+s+XYY31qjhTlKfJ0xzF/BZod0Ynyi0Q4YEh0oaak1alUlbTVnzBecRl7bDM7WooHvPCoPL8dIBA= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(265634631926514)(67672495146484); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231311)(11241501184)(944501410)(52105095)(10201501046)(3002001)(93006095)(93001095)(149027)(150027)(6041310)(20161123562045)(20161123560045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016);SRVR:CY1PR15MB0171;BCL:0;PCL:0;RULEID:;SRVR:CY1PR15MB0171; X-Forefront-PRVS: 07467C4D33 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(1496009)(366004)(39860400002)(136003)(376002)(346002)(396003)(199004)(189003)(478600001)(36756003)(52116002)(76176011)(106356001)(52396003)(316002)(50226002)(53416004)(51416003)(6512007)(68736007)(50466002)(48376002)(105586002)(2361001)(4326008)(53936002)(25786009)(16586007)(54906003)(2351001)(97736004)(6506007)(386003)(305945005)(7736002)(11346002)(446003)(46003)(486006)(2616005)(69596002)(6666003)(186003)(16526019)(5660300001)(47776003)(476003)(6486002)(6916009)(8936002)(5024004)(86362001)(6116002)(14444005)(1076002)(81156014)(8676002)(81166006)(2906002)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:CY1PR15MB0171;H:castle.thefacebook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Micros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MIRCdtqweVHQgiZ+BURSqOp1Z9WBaS4RqqC4CYdlhvaggoyU?= =?us-ascii?Q?tQ303SQEMTreIaQ371cAJK2ulPIX45Tddj1jTx304uniDDr77gg1ik1dr9Qr?= =?us-ascii?Q?VKcUe3YSJPg7xTgFTgoW64iHBdaeAVUksHy/0BtWjjIx2iIM33C802LtaZia?= =?us-ascii?Q?WKlh17PGYd9t8MY6JFa8RyNUmcN5dfzoNJYOOt5W4ZuTdQoYaFjlcmdpb1PI?= =?us-ascii?Q?tiiRxRIYywQEVN9Or4pU82pC9lYUMOduX8RSaVw6tzV5SlKRSP38WO8Lp0vS?= =?us-ascii?Q?2of8OnGHE95gNrsLYstnN0bHsFZiUWtYZzDykZBHOUlQyDro9MSuJBuYcHeb?= =?us-ascii?Q?/X8U1eiWHelFYdcITZw4ieqphlJL5PTILiE1aBQ384sbqtwFKwMWvVkflQap?= =?us-ascii?Q?QpjX4xqggQAJQwt60XbaO+IB9Jcia9sc4xVrJwAxrrDIkG26wUJYBdCzNk2m?= =?us-ascii?Q?roixe6eb3/6y5lXe+xy88AZi4DWFEc+cfiUR21cqP/J?= X-Microsoft-Antispam-Message-Info: ry3O5+f04GtlMaHCzRH+WAEQ3Szc1m4Fpl4/0nSRQKDnrDAYBKT/SI13cfAKV89pwY9PYj0V+tmnnflV5dgPNQ0UITShGslVzOnF2VVDg4RjpiVAewfP45IWXnL8qonz/TISZctdsx8GywpGg7fpuQcfm1g2DE+MTOrzIhVz41sukD3krfylvxygBC80s4hZHLpCRbZSDp/u+1UwSmhbtLmLNybbk+dtOQ8XvWWg8BjNCRC+EpITL5LrhXzRVCDM5UM9svj+kllqJgR/WhkeK127UUcbwdfD2cn5kAcd8fYYv4WPGa2gl+Q0Xls56VvbszvsbZ8RiJE9iwLVSOhhq9/exojdtocG/CxY1r6qXAg= X-Microsoft-Exchange-Diagnostics: 1;CY1PR15MB0171;6:MKRqcCgFNTgNGxQj/XP42RIIgf8PsLoV3LyBai4OEa0v8omX86B5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6vmJnTiViqRqgwmnwri9TLkQZJ4= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2018 21:53:10.9477 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d956e3f7-e1d5-43fd-896d-08d5f40b58c5 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR15MB0171 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-07-27_09:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement a test to cover the cgroup storage functionality. The test implements a bpf program which drops every second packet by using the cgroup storage as a persistent storage. The test also use the userspace API to check the data in the cgroup storage, alter it, and check that the loaded and attached bpf program sees the update. Expected output: $ ./test_cgroup_storage test_cgroup_storage:PASS Signed-off-by: Roman Gushchin Cc: Alexei Starovoitov Cc: Daniel Borkmann Acked-by: Martin KaFai Lau --- tools/testing/selftests/bpf/Makefile | 4 +- tools/testing/selftests/bpf/test_cgroup_storage.c | 130 ++++++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/bpf/test_cgroup_storage.c diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 478bf1bcbbf5..8f466af33e09 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -22,7 +22,8 @@ $(TEST_CUSTOM_PROGS): $(OUTPUT)/%: %.c # Order correspond to 'make run_tests' order TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \ - test_sock test_btf test_sockmap test_lirc_mode2_user get_cgroup_id_user + test_sock test_btf test_sockmap test_lirc_mode2_user get_cgroup_id_user \ + test_cgroup_storage TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \ test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \ @@ -64,6 +65,7 @@ $(OUTPUT)/test_sockmap: cgroup_helpers.c $(OUTPUT)/test_tcpbpf_user: cgroup_helpers.c $(OUTPUT)/test_progs: trace_helpers.c $(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c +$(OUTPUT)/test_cgroup_storage: cgroup_helpers.c .PHONY: force diff --git a/tools/testing/selftests/bpf/test_cgroup_storage.c b/tools/testing/selftests/bpf/test_cgroup_storage.c new file mode 100644 index 000000000000..0597943ce34b --- /dev/null +++ b/tools/testing/selftests/bpf/test_cgroup_storage.c @@ -0,0 +1,130 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include + +#include "cgroup_helpers.h" + +char bpf_log_buf[BPF_LOG_BUF_SIZE]; + +#define TEST_CGROUP "/test-bpf-cgroup-storage-buf/" + +int main(int argc, char **argv) +{ + struct bpf_insn prog[] = { + BPF_LD_MAP_FD(BPF_REG_1, 0), /* map fd */ + BPF_MOV64_IMM(BPF_REG_2, 0), /* flags, not used */ + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, + BPF_FUNC_get_local_storage), + BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, 0), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 1), + BPF_STX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, 0), + BPF_ALU64_IMM(BPF_AND, BPF_REG_1, 0x1), + BPF_MOV64_REG(BPF_REG_0, BPF_REG_1), + BPF_EXIT_INSN(), + }; + size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn); + int error = EXIT_FAILURE; + int map_fd, prog_fd, cgroup_fd; + struct bpf_cgroup_storage_key key; + unsigned long long value; + + map_fd = bpf_create_map(BPF_MAP_TYPE_CGROUP_STORAGE, sizeof(key), + sizeof(value), 0, 0); + if (map_fd < 0) { + printf("Failed to create map: %s\n", strerror(errno)); + goto out; + } + + prog[0].imm = map_fd; + prog_fd = bpf_load_program(BPF_PROG_TYPE_CGROUP_SKB, + prog, insns_cnt, "GPL", 0, + bpf_log_buf, BPF_LOG_BUF_SIZE); + if (prog_fd < 0) { + printf("Failed to load bpf program: %s\n", bpf_log_buf); + goto out; + } + + if (setup_cgroup_environment()) { + printf("Failed to setup cgroup environment\n"); + goto err; + } + + /* Create a cgroup, get fd, and join it */ + cgroup_fd = create_and_get_cgroup(TEST_CGROUP); + if (!cgroup_fd) { + printf("Failed to create test cgroup\n"); + goto err; + } + + if (join_cgroup(TEST_CGROUP)) { + printf("Failed to join cgroup\n"); + goto err; + } + + /* Attach the bpf program */ + if (bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_INET_EGRESS, 0)) { + printf("Failed to attach bpf program\n"); + goto err; + } + + if (bpf_map_get_next_key(map_fd, NULL, &key)) { + printf("Failed to get the first key in cgroup storage\n"); + goto err; + } + + if (bpf_map_lookup_elem(map_fd, &key, &value)) { + printf("Failed to lookup cgroup storage\n"); + goto err; + } + + /* Every second packet should be dropped */ + assert(system("ping localhost -c 1 -W 1 -q > /dev/null") == 0); + assert(system("ping localhost -c 1 -W 1 -q > /dev/null")); + assert(system("ping localhost -c 1 -W 1 -q > /dev/null") == 0); + + /* Check the counter in the cgroup local storage */ + if (bpf_map_lookup_elem(map_fd, &key, &value)) { + printf("Failed to lookup cgroup storage\n"); + goto err; + } + + if (value != 3) { + printf("Unexpected data in the cgroup storage: %llu\n", value); + goto err; + } + + /* Bump the counter in the cgroup local storage */ + value++; + if (bpf_map_update_elem(map_fd, &key, &value, 0)) { + printf("Failed to update the data in the cgroup storage\n"); + goto err; + } + + /* Every second packet should be dropped */ + assert(system("ping localhost -c 1 -W 1 -q > /dev/null") == 0); + assert(system("ping localhost -c 1 -W 1 -q > /dev/null")); + assert(system("ping localhost -c 1 -W 1 -q > /dev/null") == 0); + + /* Check the final value of the counter in the cgroup local storage */ + if (bpf_map_lookup_elem(map_fd, &key, &value)) { + printf("Failed to lookup the cgroup storage\n"); + goto err; + } + + if (value != 7) { + printf("Unexpected data in the cgroup storage: %llu\n", value); + goto err; + } + + error = 0; + printf("test_cgroup_storage:PASS\n"); + +err: + cleanup_cgroup_environment(); + +out: + return error; +} -- 2.14.4