Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1057341imm; Thu, 5 Jul 2018 13:56:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeTZY/JLPLiGWxCNPhjiWTBnOlp3y+ion8WZc71nbcJ61E6wc2edzhno4npQFv4dK98iWql X-Received: by 2002:a63:5866:: with SMTP id i38-v6mr7022311pgm.63.1530824208571; Thu, 05 Jul 2018 13:56:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530824208; cv=none; d=google.com; s=arc-20160816; b=nfhwgv4ceL4vhp45vtJBUk/KYqKQSt16sO0jtzO7qDxfYWXemYsrnrwUfRK9CUcWUe UE6siOdZl5FgKnx36mxe51uT+lRoc0ONPoM/tGKVqJGcXpDIeh7AYPqWb5dtWGv4TkI7 7q5O86Fyps3o3SkSYb6GnQRnWmyqmgkDnKEa8rWE3Y/9qIFJV/dc7C9xy2zoi06ttsfT Pb8YmdO5dV5+upYGResWoEwpuymTGsiQ0Sk9chIvdqtL6to9Qg8aRXhnVL28TYZO3dhD LEKortmvk3PTmHQKy1UsXvY6+tP9xpXW1Cjdgi4tsredga5Q6NLps4w/LjQoZqChvbVk z+Jw== 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=ccUkIiuy+r9fHc6FqtW+NV/batrBqZJEIjW+tLZ/ydU=; b=ue5lACfsfYVFqT4HZW9R1uitMbbd9LbiBEt1mVp8yV9NIgNcJ0KPoD0VbWULn944Mp LiQ8PoHezJcVxZkNBurUCN84etww/ej19mSRxEWOHsw7EZJVZe0j1Uq/c5a/9DYXKf0q KNvmdKzNC4AtS+lxJ/toYvHW90e7f/CfLw1m56W72ZHV/Cps62polvAOVj18BBal3B6I fryyqa6/WBAZI5Yld3SEXYZlnnPvd4boUKmg4yagleNTwuj8euXiX66DZA1F6E2G3LaA dQoGH7oalH4Vvf++0YkeHQEsjMqKeJW9drdSrbm03dfyzwBYU/bAjosYmId43RBahTC2 vsLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=m0m3gYTB; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=CXTNtzPR; 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 j3-v6si7172174pfg.306.2018.07.05.13.56.33; Thu, 05 Jul 2018 13:56:48 -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=m0m3gYTB; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=CXTNtzPR; 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 S932282AbeGEUxm (ORCPT + 99 others); Thu, 5 Jul 2018 16:53:42 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:44156 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754371AbeGEUws (ORCPT ); Thu, 5 Jul 2018 16:52:48 -0400 Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w65KmLwj015379; Thu, 5 Jul 2018 13:52:26 -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=ccUkIiuy+r9fHc6FqtW+NV/batrBqZJEIjW+tLZ/ydU=; b=m0m3gYTBTXdTZit6wdB+zs4MWufZfzSwxmCGlyyRgg41xny0o7Bzzr9vQUiIVJt7GgLn oVFN0XU2kP5ByixOLqlerpR4KV5xHNZb5axlgzNmPy+h6gOdHPRuejV/PI7z6DKmvSsX uBbu3h8hhpYkO6WYHZ8lNeUZPF3Hkmyjel4= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2k1r3m0euw-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 05 Jul 2018 13:52:26 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.23) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 5 Jul 2018 16:52:24 -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=ccUkIiuy+r9fHc6FqtW+NV/batrBqZJEIjW+tLZ/ydU=; b=CXTNtzPRgg9F2lB7VuJntPzeQG1w1lXtsNTBcUjiWEkMPbHN/gjg2T0l0lZ8D6KPCqrG7d7RRW0YJI70mAQfOzQjBDvFBgQe8hPF1gNQAj4DAtgTi9DaCOEYOIvYYOup1AD228kk+uJocnO6puku3SOtDsEstt983R5Gg8Njxw4= Received: from castle.thefacebook.com (2620:10d:c090:200::4:9a3d) by BY2PR15MB0166.namprd15.prod.outlook.com (2a01:111:e400:58e0::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.906.26; Thu, 5 Jul 2018 20:52:21 +0000 From: Roman Gushchin To: CC: , , , Roman Gushchin , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH v2 bpf-next 14/14] samples/bpf: extend test_cgrp2_attach2 test to use cgroup storage Date: Thu, 5 Jul 2018 13:51:39 -0700 Message-ID: <20180705205139.3462-15-guro@fb.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180705205139.3462-1-guro@fb.com> References: <20180705205139.3462-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c090:200::4:9a3d] X-ClientProxiedBy: MWHPR13CA0025.namprd13.prod.outlook.com (2603:10b6:300:95::11) To BY2PR15MB0166.namprd15.prod.outlook.com (2a01:111:e400:58e0::12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a280dcea-ed73-4536-c453-08d5e2b9347a X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020);SRVR:BY2PR15MB0166; X-Microsoft-Exchange-Diagnostics: 1;BY2PR15MB0166;3:i07D7CRy/rKknNkDxe+O8M8oI8e4gxREHHEgLg6FykkE3bHpOjMYcxfusmJms22dEOVoCYzBrp8YUlsl44EQ1V8lpQ8vgw1my4IOm3myyVW4fv7+yizzNBqaojdRmoEa0Oioay/OIP45YPFWeQVr0jpd139fpVTaggd2Ouann46usw7voIXKjxAUtFgdOdySppjlnfm8xSapCfjVTh8o39Zq744zCcbGRbzaZ9g3tsJ1xp719FUTXWHmPkgqQcwU;25:t1PcvEK9htofpM324CZQtmxUsbnLkWIU/0K8c9cfoIEdMpzrYyC/RtfDTldn4d7nanbkNmBhe4JDJ2a6rSe2AETE3rYTNSKIHo7uOXYODJVuvZ6l4ZlMuEt+c82svTbwVtL+/Hi6KjtGCXbSZ4xlnVLhUquGgBh644HZ0famVawYppGewfY2uJiBCSTiq5D4AGx3wxtYAZoTefueUlJ0x0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p4w5N4hKGKXYl5yUT9+euxd3WPm4DIgVcDmGWDet+zUUBTBYWvu8fkfHxo/1OJ88RvPWkoKI56CJCq1PBJmt77GM1dTgCEo0JDazTMVXiPRQ0/vc5r4JJIQAHatC4ttK6sCWfe6K/yN5Si/XHVopgkrEmELSMWk2P5YwTd+VFIYLyGkLmX X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3002001)(3231254)(11241501184)(944501410)(52105095)(149027)(150027)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016);SRVR:BY2PR15MB0166;BCL:0;PCL:0;RULEID:;SRVR:BY2PR15MB0166; X-Forefront-PRVS: 0724FCD4CD X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(1496009)(136003)(376002)(346002)(366004)(396003)(39860400002)(189003)(199004)(11346002)(446003)(5660300001)(25786009)(6512007)(4326008)(53936002)(6916009)(6666003)(6116002)(7736002)(16526019)(50466002)(8936002)(48376002)(105586002)(53416004)(486006)(316002)(54906003)(68736007)(1076002)(15760500003)(186003)(16586007)(47776003)(476003)(2616005)(478600001)(106356001)(81166006)(5024004)(69596002)(8676002)(81156014)(305945005)(14444005)(97736004)(51416003)(86362001)(2906002)(46003)(2351001)(50226002)(6506007)(2361001)(52396003)(36756003)(6486002)(76176011)(52116002)(386003)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR15MB0166;H:castle.thefacebook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2PR15MB0166;23:E1kmJBlf6J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ZIStQK8MS2VVJ4hoabH+UMv0U98JBtHQnDLE1h7HN5AA7TL2yvXHbh7/TnF7Bh7zxWphM9v5E8IJgdsD+P6XQhLZ2lEa+QEbtQn+4IbgY/Vp6Z3p1MBoooKBLbVrXdZfzdS/lko= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jul 2018 20:52:21.4346 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a280dcea-ed73-4536-c453-08d5e2b9347a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR15MB0166 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-07-05_08:,, 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 The test_cgrp2_attach test covers bpf cgroup attachment code well, so let's re-use it for testing allocation/releasing of cgroup storage. The extension is pretty straightforward: the bpf program will use the cgroup storage to save the number of transmitted bytes. Expected output: $ ./test_cgrp2_attach2 Attached DROP prog. This ping in cgroup /foo should fail... ping: sendmsg: Operation not permitted Attached DROP prog. This ping in cgroup /foo/bar should fail... ping: sendmsg: Operation not permitted Attached PASS prog. This ping in cgroup /foo/bar should pass... Detached PASS from /foo/bar while DROP is attached to /foo. This ping in cgroup /foo/bar should fail... ping: sendmsg: Operation not permitted Attached PASS from /foo/bar and detached DROP from /foo. This ping in cgroup /foo/bar should pass... ### override:PASS ### multi:PASS Signed-off-by: Roman Gushchin Cc: Alexei Starovoitov Cc: Daniel Borkmann Acked-by: Martin KaFai Lau --- samples/bpf/test_cgrp2_attach2.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/samples/bpf/test_cgrp2_attach2.c b/samples/bpf/test_cgrp2_attach2.c index b453e6a161be..180f9d813bca 100644 --- a/samples/bpf/test_cgrp2_attach2.c +++ b/samples/bpf/test_cgrp2_attach2.c @@ -8,7 +8,8 @@ * information. The number of invocations of the program, which maps * to the number of packets received, is stored to key 0. Key 1 is * incremented on each iteration by the number of bytes stored in - * the skb. + * the skb. The program also stores the number of received bytes + * in the cgroup storage. * * - Attaches the new program to a cgroup using BPF_PROG_ATTACH * @@ -21,12 +22,15 @@ #include #include #include +#include +#include #include #include #include #include "bpf_insn.h" +#include "bpf_rlimit.h" #include "cgroup_helpers.h" #define FOO "/foo" @@ -205,6 +209,8 @@ static int map_fd = -1; static int prog_load_cnt(int verdict, int val) { + int cgroup_storage_fd; + if (map_fd < 0) map_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, 4, 8, 1, 0); if (map_fd < 0) { @@ -212,6 +218,13 @@ static int prog_load_cnt(int verdict, int val) return -1; } + cgroup_storage_fd = bpf_create_map(BPF_MAP_TYPE_CGROUP_STORAGE, + sizeof(struct bpf_cgroup_storage_key), 8, 0, 0); + if (cgroup_storage_fd < 0) { + printf("failed to create map '%s'\n", strerror(errno)); + return -1; + } + struct bpf_insn prog[] = { BPF_MOV32_IMM(BPF_REG_0, 0), BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -4), /* *(u32 *)(fp - 4) = r0 */ @@ -222,6 +235,11 @@ static int prog_load_cnt(int verdict, int val) BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 2), BPF_MOV64_IMM(BPF_REG_1, val), /* r1 = 1 */ BPF_RAW_INSN(BPF_STX | BPF_XADD | BPF_DW, BPF_REG_0, BPF_REG_1, 0, 0), /* xadd r0 += r1 */ + BPF_LD_MAP_FD(BPF_REG_1, cgroup_storage_fd), + BPF_MOV64_IMM(BPF_REG_2, 0), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_get_local_storage), + BPF_MOV64_IMM(BPF_REG_1, val), + BPF_RAW_INSN(BPF_STX | BPF_XADD | BPF_W, BPF_REG_0, BPF_REG_1, 0, 0), BPF_MOV64_IMM(BPF_REG_0, verdict), /* r0 = verdict */ BPF_EXIT_INSN(), }; @@ -237,6 +255,7 @@ static int prog_load_cnt(int verdict, int val) printf("Output from verifier:\n%s\n-------\n", bpf_log_buf); return 0; } + close(cgroup_storage_fd); return ret; } -- 2.14.4