Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1409376imm; Wed, 1 Aug 2018 15:41:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdcZmsKIEIUkoikwd48Rd14Q77p7n2KbJP1o9LLHHZvPmAPiyHAITxIBH/3Bq9KgKguAKzZ X-Received: by 2002:a63:4d06:: with SMTP id a6-v6mr233285pgb.408.1533163265669; Wed, 01 Aug 2018 15:41:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533163265; cv=none; d=google.com; s=arc-20160816; b=t9nipGTvzgjo7K/DSFijG974yjg1I13f48LICQmr01tPmffFUb0z6KT0DTIXsJutlG qgJBwoOLtLhDU3YDU/8rwSonLa7pN0OAkDpZoOcxzwMlUnrhqJ+ziNCrZqGQ00fSR8mw TP7wONu10gNIxM51Qp3mzXTuh7SbAqRkJB3qvSrNAef2L6QN+2rCgiaQ9D5AiS7NYJ7e /2rL8NOsZ943q4VI0D/O6XwRtQgPa0TyqWfk1+t6XxXY09thGfeZT3IxbAR2DmYxqLON xipis3PF08Cd0ELl3FLqxeMBXgCTk1uZ1c/ulDpzH3TVZPMcVSg2t6f7iNRcPgX3MEm+ 89Ig== 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=S++8iDftjgOTPDbo5SE6ZnAEkkMRTWf6tAiz9vYFuFz7s68rv2uCBnBMgEcKi4+3+U e0mOfqhRXUsiYsmTG0osrb2q6vJ/HUqvJEvhdleDQRM9AxEngDvAn9Ekhbg9SGwk1PVx aNyXd14qizmO8ESbF8AureU1zHnrzUVilw49/81o3YFk2BjY7TT1zzykadqIOGl4jM7n WAQ4np3JCAGwiiBJYP4ce1YFhMkLAtmTXA7zfYuzGn0SXMrz3aKRpIoQRrGA3XGvOjN7 oFsoLfwFA6/mP/7TJ19mZUVkvfqx3IozIGpPyTwvzAGjEvWcqvzG5w9PCJzK/y+d6gRx GJQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=WWCEUbky; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=eEfHslwR; 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 j30-v6si235026pgm.26.2018.08.01.15.40.51; Wed, 01 Aug 2018 15:41:05 -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=WWCEUbky; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=eEfHslwR; 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 S2387644AbeHBA0w (ORCPT + 99 others); Wed, 1 Aug 2018 20:26:52 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:59476 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732388AbeHBA0v (ORCPT ); Wed, 1 Aug 2018 20:26:51 -0400 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w71MZQcY003965; Wed, 1 Aug 2018 15:38:34 -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=WWCEUbkyIMHHTRFQet2WSLk9ev421wNkI0vTTiSyYlODW1sVh6FoZJJM1aL2ESJN4o6K zDwobwymIDEcDepyodAJrREpnbVKnSMSeJE8bnKUN9y5BfbK6kBO23ZLrALQwzFEdXQh 7DEJ+SRs7lY+azVGOdZDy3OwC0cVr4GmrvQ= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2kknssr07t-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 01 Aug 2018 15:38:34 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.13) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 1 Aug 2018 15:38:32 -0700 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=eEfHslwRbJOnn7LDnRzfnVkjHnZOamEm3+8Md1dqKOsBgb1G4dlWGd5I1BO70ckcVmCg7DRqzECvQ27INM2ffLLYPzCJfyYC7fQmFePxnYa44R+ILgsiMrMRsy9+/EAtPoVfqFGDe8HMA+yU3Pl+AcUisa1oWeDKg4IIxsI8X0I= Received: from castle.thefacebook.com (2620:10d:c090:200::5:7cca) by SN1PR15MB0176.namprd15.prod.outlook.com (2a01:111:e400:58cf::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.19; Wed, 1 Aug 2018 22:38:28 +0000 From: Roman Gushchin To: CC: , , Roman Gushchin , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH v6 bpf-next 14/14] samples/bpf: extend test_cgrp2_attach2 test to use cgroup storage Date: Wed, 1 Aug 2018 15:37:40 -0700 Message-ID: <20180801223740.11252-15-guro@fb.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180801223740.11252-1-guro@fb.com> References: <20180801223740.11252-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c090:200::5:7cca] X-ClientProxiedBy: MWHPR1601CA0016.namprd16.prod.outlook.com (2603:10b6:300:da::26) To SN1PR15MB0176.namprd15.prod.outlook.com (2a01:111:e400:58cf::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 09889d42-e745-4b17-58e3-08d5f7ff80b7 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600074)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020);SRVR:SN1PR15MB0176; X-Microsoft-Exchange-Diagnostics: 1;SN1PR15MB0176;3:jmtOGqVFhu/cObbAZLt0YC/arlDPULVJn7Sv7iKkGv2bbQA9PU3GfBCcfsq0Wj7ssaZ4UI/jJ7FcW2X17FEkbpiRa3D4tg+PfXuWqJ3CLEL5GtIH7v9nnUNf28rXTrm3MsVNBkYu5z0PqpYzHC/it6k7jd4RyhonRjlbLtXVvwREEoxO4fI9QTFheqf7nang6MpqgFHVJaL7IXzXyhklmLZxdmbcU1kK+16lLfDnxEWkg+lg6qoTMzLnXKt1eNGy;25:upG8GZseTSjkyerEtKO6PTIyUuWEBjSplsHcEkq5hgOoi64NCQDp209LWRBWpvfyxWfmBcwxTiYWLz7yGs9ITrZOO9RG4WrXiwszwCYgp52JTvQ4ea9+OMlkaROh/k4dtnUPgG2e8VI4wkMrVR4j4ppBNasoLixGaiRgTBTZ0VmNMdH0fxPCKOWMu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olI2GAhY8Xb2lMYnG5mOpo3XVy5OW6z1hnwYkV2B78MsSKWN8v+eZNteISOQ2QS/1Ue8b3H2y+K0nVy4SoK1lYAIlUhYM+/tXBm/CNTtb9FLDaET5PoJcIDIwktJVP5pdmvCrDkWjg28u1hn34GQGtn8Uuyw5sMVcVMc3JB4dWNflBt0SfaBJdFZXJi9uIMmAi6/ZQAfbzMCGaAxCintihIN3KgSSY 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)(3231311)(11241501184)(944501410)(52105095)(3002001)(93006095)(93001095)(149027)(150027)(6041310)(20161123564045)(20161123562045)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016);SRVR:SN1PR15MB0176;BCL:0;PCL:0;RULEID:;SRVR:SN1PR15MB0176; X-Forefront-PRVS: 0751474A44 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(1496009)(366004)(376002)(39860400002)(346002)(396003)(136003)(199004)(189003)(11346002)(6486002)(6512007)(50226002)(6916009)(2361001)(15760500003)(5660300001)(53416004)(68736007)(6666003)(386003)(106356001)(6506007)(76176011)(105586002)(52116002)(51416003)(86362001)(36756003)(486006)(2616005)(8936002)(81166006)(16586007)(54906003)(478600001)(50466002)(316002)(81156014)(6116002)(2351001)(69596002)(7736002)(1076002)(52396003)(14444005)(5024004)(16526019)(46003)(8676002)(4326008)(476003)(97736004)(47776003)(305945005)(446003)(186003)(2906002)(48376002)(25786009)(53936002)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:SN1PR15MB0176;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-Microsoft-Exchange-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qFtHXGjk2bIiDJyPBrA+W/bWOLYE2He8BaS7XwhYFUnW+dFnxRxyvw+PQsnu0bmEXMzh/WLSamztNE0= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2018 22:38:28.4797 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 09889d42-e745-4b17-58e3-08d5f7ff80b7 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR15MB0176 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-08-01_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