Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1299791imm; Fri, 27 Jul 2018 14:54:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfthjLDOqeiuTrZytAU4RXzNwRLYTaE+++Vb8Xg3Aop/WmjYo7l7SJOU8+Umf7qajkQRo9O X-Received: by 2002:a62:4808:: with SMTP id v8-v6mr8261011pfa.89.1532728486576; Fri, 27 Jul 2018 14:54:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532728486; cv=none; d=google.com; s=arc-20160816; b=XURCnPX+xxVGtMGZu7o1KF1jNEcsQL60i23s9CjJHgZDoowKmL33YOs4J31QY09e+i +b5F+kkUYY8nsaTFcbKRTafTNPJjuWSR0Y0G/SvgyeglqBH1PBCA+cw7BCyLjT+fKFXN V+NZ1MluVS7e93TXYnC7/f8+CXZ5Di7TOrbcCh3kb6pGE3RJ/dv1pBHrWrepRrKIQQ9F pjn/EWguwsjdImn6y185PFGM071yKuPE0fJAG1XZTK3IR89YjboYOCx5y3N/CRbnXGWm 5eHtqOxjJgqGa5UBsJJr3oarE9MtKwmQNojz8xnoWiFzsaZp/GIkGpQuaa90WFr0Nn17 DikQ== 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=vK/TrcxDaFCDmebHmazSo0SkhyudAMJ2/lJFKf8LkjxoNgSi0rH86zjRrBfbZQ5rtt ez0e7WsMpPBA+z5R68AhJK2+Ydx35pfEJJ3ssjPsnLa9BdCBmufgL0Ysuz007X3cbhG3 VQ6S38+nz16LSuXzhYGmEYEpsVVVDJSAl19q594m9GekaDmBecgRhyqOiATt1zhdRNn+ 1fpi5uACIFbYvmfqwlihEcMTNVaVcRmAEtfvTCw2tc4uYXpBK+SiISaolgKIKu+1YnEc QANAudE8VwG9fv1OI2lEhcjQ5IMCTC0Wbl9i7K58qSmIs0YrK8V2cDLzjFpWz8SmIv8Z f4UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=PA4rfw16; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=W0vJ8ZrX; 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 r28-v6si4772794pfb.65.2018.07.27.14.54.32; Fri, 27 Jul 2018 14:54:46 -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=PA4rfw16; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=W0vJ8ZrX; 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 S2390114AbeG0XR3 (ORCPT + 99 others); Fri, 27 Jul 2018 19:17:29 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:52386 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390063AbeG0XR2 (ORCPT ); Fri, 27 Jul 2018 19:17:28 -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 w6RLjQuM006591; Fri, 27 Jul 2018 14:53:17 -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=PA4rfw16/mnRDb9QdGtEFzi3i1154nmPWBUFcweWmFqAoRys9SNCgNhIJHYW2Ngl19Yn 741ufUXUCrT2rm63IX/pWJYrJ6V1ZdvvJU7+E9ZLS1j3KMysFyvPxfWoACVOjqT6R9qN zRtJPIeMh2VqT1sYvE0uFhN6MPPxxoUHeJE= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2kgb58r2mv-3 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 14:53:17 -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=ccUkIiuy+r9fHc6FqtW+NV/batrBqZJEIjW+tLZ/ydU=; b=W0vJ8ZrX8/RT41JRAqpBfTAzb1hsx2C1GvZW84hBUynnrq+ouAVIHr0YnDf2G/e4IR72TNVjHTiVoQjlXS8UaQUT0Gg5x8avm9IDpRjr/bwvhZLr5rdXXDGbMCW9JFTZ6CPiTfcbU4aFbRkHWhJ4K/TQtsnSaGzDAmJDFnOcGxo= 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:11 +0000 From: Roman Gushchin To: CC: , , Roman Gushchin , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH v4 bpf-next 14/14] samples/bpf: extend test_cgrp2_attach2 test to use cgroup storage Date: Fri, 27 Jul 2018 14:52:43 -0700 Message-ID: <20180727215243.3850-15-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: a0125b6e-6e37-402a-9078-08d5f40b5948 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:cswwqqGtKigmhk4GS0w35QZaXIQoa295zVv946Re/PgpDScBpFQ1lSw72OfQIhMfl82VysCNZVTPIIn6Oxir0QmtSmNXJc9sVGmeWq2tZhyhfncqlAKPJkKmBzX8K9WiOFw0dr+FTRBydYDyNr0JqifbefkjujxYaeabigDt7MLZN7P8HlNq+C2j0vyNbelKtoslznih5tet+P4jtgO39S6VaOa9nRdsNJKXq3740azh3mAtijnd1wQRuhv/f4w7;25:JzuycaQpsOxlPR08YaKT3tzOrLgSx26ayMHB+0UWPNyNyGTjbWuR2v9mAGJeM61/qbFWvi8nxVVUv/fS/5FyujJfSYK349F3r4JA1fa15MQjKAUdK6Sp6b/pzbII/6VV53F7Yu0b3syE+D5idCidTvqvjD91wL3qXNhj6zg5Oaww5CfXZbqpMuDVHKWVo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LuIc8Sc7hAs+TQzNhUAS2MdSxqjStR2ISrtMO8rN89AHWX7wVWt8IXsGEY8dV0bjqTVbe8mqU3xMDeuD58ZBlUCK3r6pxj4r5p1e8CITupDInSrqxD8DeNniJz3XFz3RehEpHM6FwghmpD6YUYpwkbBHmvyKRD6mHtXtngEI4xbclEY+TxXPkEMr2iraR+gwqsdIETFqjguE5tQ03jldh3p3tZB3N 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)(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)(15760500003)(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-Microsoft-Exchange-Diagnostics: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I2pl/zq3Al6LZZJs3VYP1MkOa+QnO9HaNGx8wDeuvmcJfXCl8Y4= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2018 21:53:11.8094 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a0125b6e-6e37-402a-9078-08d5f40b5948 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 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