Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp846194imm; Fri, 28 Sep 2018 07:48:15 -0700 (PDT) X-Google-Smtp-Source: ACcGV60V0o8+cMMhZFdKAjNjq55mnJ2jhzrXBTRF6dKH8MMJAP+RIxB91gIxTM79ODnZgjCsTqzt X-Received: by 2002:a62:f553:: with SMTP id n80-v6mr16983996pfh.59.1538146095293; Fri, 28 Sep 2018 07:48:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538146095; cv=none; d=google.com; s=arc-20160816; b=G0loF5vY+kCeUlvog9UyYzJKnNCOV4IACWCSQ+fxuV9xtOA1d8UwsS7OVYlgS0z5N6 kbOwb9dO/tNH/qNpbxPsDRbYzM+WDpMsLA34p/tVC0piFnW4e/OE1ipjZqhEzF8mp+Gs /i+WtZDcSE0L8XGxm+iC5xopLoH8rMFHanM9I8HLV5W415ODlcsdSt377C6+vbnrLKRD zXfh4ompNMa0seNLOdJsWOlgzU4L9q9JMdOQxC+35u4McW6vnC0wO+/ZPXlBiCT2eags 4oJ99O/L3qQ+ml+GFiX7x56QvDnEgX0dY1pCMteWBUBPzVoccCuZlbDhU8M0OUx8W9xp Ad6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature:dkim-signature; bh=hodNtQuAkAYTyTymX/Gw9qX04kEhTUZtpXdn9lZSIzo=; b=FBdBMGkndYxH8BrDtReN+qs5ATaKmlZO/SoLmw1XvkhT335pqGJpnQWeqrjsUSDQob tIRnLwUx/T2lsiC1GiWEu/BjxUL2NmyGju50API8SfA0daaDtTDdvxXkVvlPdwygBqRj 36Zdj1ud1M2dGiL0ciKXoO0wlmiAw2eNNxWGdawn06Hg1cMNImCbr3s571OI8eXFdYNm 3Mm4gEJhmBVg3MIT2KdYtZsBScS2kmtmdeeZ9d3+WIZnuUdkGszWwYU6Mee23Hys4ULN iwefUWjhz7l9cNkJMyBrLxZQuhfQYEfPnSoupfWp5VIEBb4/c6qZGwx0mfEaOI31Lhij NvdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b="dcpzcx/B"; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=IYZeVNiD; 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 a11-v6si4843818pgd.400.2018.09.28.07.48.00; Fri, 28 Sep 2018 07:48:15 -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="dcpzcx/B"; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=IYZeVNiD; 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 S1729537AbeI1VKk (ORCPT + 99 others); Fri, 28 Sep 2018 17:10:40 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:52604 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726971AbeI1VKk (ORCPT ); Fri, 28 Sep 2018 17:10:40 -0400 Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8SEhb6b016859; Fri, 28 Sep 2018 07:46:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=facebook; bh=hodNtQuAkAYTyTymX/Gw9qX04kEhTUZtpXdn9lZSIzo=; b=dcpzcx/BuuNVKbn1h0DOdDaarfbl0aH1vQl1YmI4CiXX2dO8Il3Lbm0EdiMhHto/8+hE E1o/Mt7lW1H9ldig+mg3J3iiJCXRQMIrczrOTceBlzWCkTrEi2NYXlK1u/XneKcuWmwF 4H5SS1XMkmwcTqI9P8U3TLQnK5SMW0LUFEk= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2msj270u92-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 28 Sep 2018 07:46:12 -0700 Received: from PRN-CHUB02.TheFacebook.com (2620:10d:c081:35::11) by PRN-CHUB06.TheFacebook.com (2620:10d:c081:35::15) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 28 Sep 2018 07:46:11 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.12) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 28 Sep 2018 07:46:11 -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=hodNtQuAkAYTyTymX/Gw9qX04kEhTUZtpXdn9lZSIzo=; b=IYZeVNiDYrH7XeWfLJ0XHQYqjqMe3DwrKiL0tABrtg6myR/lceT/6HlkEU9iJs/3sAqDp480XKLf/6SA8vDpYzsslT/SysFZKeL62idQ7UCyOuD9SM2cdxvzqaFwPsRNA7CYRK3i903/ApCsVYCijZUifk2grfMNBqJK5DnJEog= Received: from BY2PR15MB0167.namprd15.prod.outlook.com (10.163.64.141) by BY2PR15MB0453.namprd15.prod.outlook.com (10.163.110.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1164.22; Fri, 28 Sep 2018 14:45:59 +0000 Received: from BY2PR15MB0167.namprd15.prod.outlook.com ([fe80::5c5b:75ea:cae:1e68]) by BY2PR15MB0167.namprd15.prod.outlook.com ([fe80::5c5b:75ea:cae:1e68%2]) with mapi id 15.20.1164.027; Fri, 28 Sep 2018 14:45:59 +0000 From: Roman Gushchin To: "netdev@vger.kernel.org" CC: "linux-kernel@vger.kernel.org" , Kernel Team , Roman Gushchin , Daniel Borkmann , Alexei Starovoitov Subject: [PATCH v4 bpf-next 09/10] samples/bpf: extend test_cgrp2_attach2 test to use per-cpu cgroup storage Thread-Topic: [PATCH v4 bpf-next 09/10] samples/bpf: extend test_cgrp2_attach2 test to use per-cpu cgroup storage Thread-Index: AQHUVzn3mMbYFdmQLUWYKHR4fyu0AA== Date: Fri, 28 Sep 2018 14:45:58 +0000 Message-ID: <20180928144452.5284-10-guro@fb.com> References: <20180928144452.5284-1-guro@fb.com> In-Reply-To: <20180928144452.5284-1-guro@fb.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6PR0402CA0022.eurprd04.prod.outlook.com (2603:10a6:209::35) To BY2PR15MB0167.namprd15.prod.outlook.com (2a01:111:e400:58e0::13) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [2620:10d:c092:180::1:8a29] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BY2PR15MB0453;20:qPZx7ApSwRD28vTVRIcovcoULW64zbWaLkNQTMNgurjVoC7F5AjzLgd6yUT84FCbrTMLgPnlJo5bv1wiDHsR9ejPtTmkZi/vJNJ85BCvb+Bia/BRVk1U0I98Y/4zQxGeJ3RLKwDDq0SC63TPaI/6zf/41815BRrCMMhTvmtjP5A= x-ms-office365-filtering-correlation-id: ffdfb944-7560-41e1-c42f-08d625511a18 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:BY2PR15MB0453; x-ms-traffictypediagnostic: BY2PR15MB0453: 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)(8121501046)(5005006)(3002001)(3231355)(11241501184)(944501410)(52105095)(10201501046)(93006095)(93001095)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123560045)(20161123558120)(201708071742011)(7699051)(76991041);SRVR:BY2PR15MB0453;BCL:0;PCL:0;RULEID:;SRVR:BY2PR15MB0453; x-forefront-prvs: 0809C12563 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(376002)(346002)(366004)(136003)(39860400002)(199004)(189003)(478600001)(34290500001)(15760500003)(1076002)(476003)(7736002)(4326008)(25786009)(5250100002)(36756003)(6116002)(68736007)(305945005)(446003)(2501003)(46003)(5660300001)(14454004)(54906003)(486006)(99286004)(86362001)(316002)(53936002)(52116002)(6436002)(105586002)(2900100001)(6486002)(76176011)(14444005)(256004)(6916009)(1730700003)(102836004)(8936002)(71190400001)(106356001)(6512007)(97736004)(2616005)(2351001)(81166006)(11346002)(81156014)(2906002)(71200400001)(5640700003)(8676002)(186003)(5024004)(6506007)(386003)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR15MB0453;H:BY2PR15MB0167.namprd15.prod.outlook.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-antispam-message-info: kSAUOzRl6pAeSYQiaTOyutcCK5acMD/1n68wb1+9Rki/FxiYVfaZSqxmDv0+8YccDJvd7X0W7bAym86I9X7xYrYoyH/eoFRbEi1N1P8QmxooA8eiXOx2nmHpJMww/jK9uoge+BflnCNJ1JgNmt3dIpgCW9S+oL1oSp82Yu4oIr/2s9+C8dYaWnchgKTigEXKm3FzckYwgQ/J/aMhlOPSWwz9Bz2GKPOl3XLEoBNF8VtmVliW3BoO9rVTeUp4CcYLjoxVMMQiUEae17trZt0QLTp2HMFZYk9i8Er386jI7DQY7wxBzAcFH0Rgn2BJk472DDTbgFXKHAnbgI9MqfKmQHBubklQzE15h/IN6FE2jdU= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: ffdfb944-7560-41e1-c42f-08d625511a18 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Sep 2018 14:45:58.4216 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR15MB0453 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-28_06:,, 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 This commit extends the test_cgrp2_attach2 test to cover per-cpu cgroup storage. Bpf program will use shared and per-cpu cgroup storages simultaneously, so a better coverage of corresponding core code will be achieved. 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 Acked-by: Song Liu Cc: Daniel Borkmann Cc: Alexei Starovoitov --- samples/bpf/test_cgrp2_attach2.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/samples/bpf/test_cgrp2_attach2.c b/samples/bpf/test_cgrp2_atta= ch2.c index 180f9d813bca..d7b68ef5ba79 100644 --- a/samples/bpf/test_cgrp2_attach2.c +++ b/samples/bpf/test_cgrp2_attach2.c @@ -209,7 +209,7 @@ static int map_fd =3D -1; =20 static int prog_load_cnt(int verdict, int val) { - int cgroup_storage_fd; + int cgroup_storage_fd, percpu_cgroup_storage_fd; =20 if (map_fd < 0) map_fd =3D bpf_create_map(BPF_MAP_TYPE_ARRAY, 4, 8, 1, 0); @@ -225,6 +225,14 @@ static int prog_load_cnt(int verdict, int val) return -1; } =20 + percpu_cgroup_storage_fd =3D bpf_create_map( + BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE, + sizeof(struct bpf_cgroup_storage_key), 8, 0, 0); + if (percpu_cgroup_storage_fd < 0) { + printf("failed to create map '%s'\n", strerror(errno)); + return -1; + } + struct bpf_insn prog[] =3D { BPF_MOV32_IMM(BPF_REG_0, 0), BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -4), /* *(u32 *)(fp - 4) =3D r= 0 */ @@ -235,11 +243,20 @@ 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 =3D 1 */ BPF_RAW_INSN(BPF_STX | BPF_XADD | BPF_DW, BPF_REG_0, BPF_REG_1, 0, 0), /= * xadd r0 +=3D 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_LD_MAP_FD(BPF_REG_1, percpu_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_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_0, 0), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, 0x1), + BPF_STX_MEM(BPF_W, BPF_REG_0, BPF_REG_3, 0), + BPF_MOV64_IMM(BPF_REG_0, verdict), /* r0 =3D verdict */ BPF_EXIT_INSN(), }; --=20 2.17.1