Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3139671imm; Fri, 20 Jul 2018 10:49:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfy4EH0UMBtNcvnV6bAFgrAAnVDr1PQf757jZ2kzc4MtnF6HiuwxXJtDhnrFhCa87at8uzb X-Received: by 2002:a65:52cc:: with SMTP id z12-v6mr2984366pgp.69.1532108941935; Fri, 20 Jul 2018 10:49:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532108941; cv=none; d=google.com; s=arc-20160816; b=E6n34vuma78dbj+QH8m/IkpCtdYwjKGy8sDt5Tv+pecQ+08mGVAtLuL8E33YWRwyHC fahMkuzytFEbsoORKgE2kF7J6qwCk0QlPQFOUwTWOJYjSBxyC+lqEEEUMJ5lYdPQKs33 x8Le0PW+CN9OLgI+YgeyJapMH/NOpAnPBbULYQRXNscGlOBG2mddB3CJKzxnNg4I+EZJ BLgDQX8d+wnbfJzrNN/rIkOFeP1OrTPXnPgsyq0L+6sbiXuNo+hr2wOheyvIQaL5VmT2 1kX6yDvb99dWdEbiE97ZXodNhdyXrtctomD+y+luqjkMAotWSxZ8IzTLnWSunu4BNZnx OwYg== 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=JLY4YhEmv2Q0OMvBg1KWpD1OGkIDUDn+eQMEK5i9oog=; b=NPnkL8JcrrrcMGP9wxh65dRjYYT7/U/n4GYplcx7FKydVo07qK+4mpHFGjdi0T58Bq 2VyIRcizClF2CmOdPoHDvSQ5qZdywv4RJfi4mXuhYXeeG+W+92pAmNzIBXtaygojXZaq YzgodsWfKGTdwG23YmQ2RuDi/gvaj+eceHWCKqDXE//C2H5p0anFtZBIonpZZhJ4W4VY XlwnPwVq9Et8FstMBFxfUZLfviQ/8uWS6ctd1cGYOxB4J//4xZJiRi+PBdfc9ouJxS9B Q3dEczRMQFPQDPvG2AGjJYTb5tADHHVuvDTf/iP5X87quKF8XmvbfJ07LvMo282DdgTw Dr6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=EVNja8mn; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b="N6ZMxb/z"; 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 k15-v6si2083716pls.463.2018.07.20.10.48.47; Fri, 20 Jul 2018 10:49:01 -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=EVNja8mn; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b="N6ZMxb/z"; 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 S2388384AbeGTSgE (ORCPT + 99 others); Fri, 20 Jul 2018 14:36:04 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:38264 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387881AbeGTSgE (ORCPT ); Fri, 20 Jul 2018 14:36:04 -0400 Received: from pps.filterd (m0044008.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6KHhh0p025812; Fri, 20 Jul 2018 10:46:25 -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=JLY4YhEmv2Q0OMvBg1KWpD1OGkIDUDn+eQMEK5i9oog=; b=EVNja8mnCTilNyerWL+fhIW8Z8dvTpGF2iECUoksu3jTFdQdiQJ5qiRmqdqcf/XKbtfr 5+TFgXNljT7w8Uoc12VQETf+MsRs6ImOr9A/6VyZIzVt7Q+J12scDro2WzptLY8CP5iq XCfdAZZ7VBa79z5UdU3h9P0mc3xGwgmfPU0= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2kbmbv80dv-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 20 Jul 2018 10:46:25 -0700 Received: from NAM03-BY2-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.31) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 20 Jul 2018 13:46:23 -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=JLY4YhEmv2Q0OMvBg1KWpD1OGkIDUDn+eQMEK5i9oog=; b=N6ZMxb/zklntjPOQftXc7P7T3ykiF+/+4WiOmwSk00JSCeaH48iwtxn2L2Iign1WjzuaFM4PLRRfuMr+Kx8Z5043cEbO/vvmAqbt+uAc9XXr05/OI+L5YBQ4v5SLK96BQw6APgE8LxiJY8YMCVRA1lWlUq2vUTMeuBa4D8XfRtY= Received: from castle.thefacebook.com (2620:10d:c090:200::6:ca05) by SN1PR15MB0175.namprd15.prod.outlook.com (2a01:111:e400:58cf::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.973.21; Fri, 20 Jul 2018 17:46:17 +0000 From: Roman Gushchin To: CC: , , Roman Gushchin , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH v3 bpf-next 04/14] bpf: allocate cgroup storage entries on attaching bpf programs Date: Fri, 20 Jul 2018 10:45:48 -0700 Message-ID: <20180720174558.5829-5-guro@fb.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180720174558.5829-1-guro@fb.com> References: <20180720174558.5829-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c090:200::6:ca05] X-ClientProxiedBy: MWHPR17CA0096.namprd17.prod.outlook.com (2603:10b6:300:c2::34) To SN1PR15MB0175.namprd15.prod.outlook.com (2a01:111:e400:58cf::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d683ea4c-1203-452d-864e-08d5ee68b2a4 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600067)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020);SRVR:SN1PR15MB0175; X-Microsoft-Exchange-Diagnostics: 1;SN1PR15MB0175;3:gbFhgdxoY53OcjU6q36QvMqubWaNNKVC66B+Vs/Ha+uOt7CkGJw7tRfL4hcfF3YPKTbuAfHNUTtNUU6CfVbFA3KGW/rwvDZm/ke8DrTNom121QCIhhlN895KvCeGSoAHF1enJ0B3+qUGT/HU3ok+TtxmQk1O7shJiCdWzoaKaClyCkWr6EZ7dVBp64K9Ja6mh+eJVN5sdTC0WlZskd0H/H/atJBFRhmMTX7OKDffLi0+vbhH28wLijtBC6Y5wATs;25:EPg1wIKjT9uJGmgqAE3jXYtlMI6ZpAzLudNVUIRVTXqIYXTb8crBOUH0eg3XcDdPke95UPl8fuTBzpz8nnvmfzRyn+HO+lVZ49u2Enqeizxrbtd8/Qqf+h1o4h1d6ixhN2BOI6ytC3BiWTKskzPUrEUuFQXVXSLX7qXptWgqaIkpN+T0JbKvozRBSMB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2T5SjCbGEyW8x+ogym2uRD3tZ/44fWl92Ct+/Db3VCFJAMAQgQq5FVURDdkX+4w3ZGYMLv2lApvSKgZpgvpYD9J0PBGzH7E62iMgYgHFIZ9lueI2fM724KR8qVc10PHaLdDuqyYtMZm+cjKgwt6akMIE5m3USF/s8Rpg36eNQc3rTxG+eQDXwtKAyraqWeLaEZk58yWwok5oKMIB0WTYNwn5eLme1sb9Wus2J 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)(93006095)(93001095)(3231311)(11241501184)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123560045)(20161123564045)(6072148)(201708071742011)(7699016);SRVR:SN1PR15MB0175;BCL:0;PCL:0;RULEID:;SRVR:SN1PR15MB0175; X-Forefront-PRVS: 073966E86B X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(366004)(136003)(376002)(396003)(189003)(199004)(2906002)(6666003)(50466002)(81166006)(53416004)(8676002)(48376002)(2351001)(68736007)(81156014)(106356001)(8936002)(25786009)(105586002)(1076002)(5660300001)(6512007)(6486002)(575784001)(36756003)(478600001)(86362001)(69596002)(7736002)(6116002)(305945005)(97736004)(2361001)(16586007)(316002)(52116002)(51416003)(52396003)(446003)(50226002)(46003)(54906003)(14444005)(47776003)(2616005)(5024004)(476003)(486006)(6916009)(11346002)(386003)(76176011)(16526019)(53936002)(6506007)(186003)(4326008)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:SN1PR15MB0175;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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jNZri0yAYL95bldzYrVqd6OULh?= =?us-ascii?Q?BRS6HiIv+BGdW+DT+UVacM5OtgzRG6S6hPw2yrgoeJeR9KMT317FfgYuCUGb?= =?us-ascii?Q?rdvCWn2PbJ3FVZlQoqfauNpC/QKFr70ivry2vnesi26iN3u6WVgK0iLpiK2k?= =?us-ascii?Q?1OTZIW7zcZUGeul4nsM8hJ0BmXHZ25v/jtOrO+77ybfXhZOXd4OT2wYSS37E?= =?us-ascii?Q?3oJQ2EZcZo3xXWgD69Tz7CMIPFDLU9Z1azEYFrVmMmcFo4vxTqukShz/oAMa?= =?us-ascii?Q?8WIQBfalwos/1qM36j1T+UsNq8cSjsCPSYCmh2Y/rZMvFalPdjbdB8AHa2yI?= =?us-ascii?Q?E0Yc/GilfRKLR9WM1j6Guk7MeVrc3gwmShTe1j1gDMeUwIIZoa7niehEiAmD?= =?us-ascii?Q?ty//YRx3UcG+gU7jqbfettZ7Gcd6TRbg1OgWldACcxT3zM0hrIPbNvj6Fsv7?= =?us-ascii?Q?2YEh3/5W0h6mseEndaPReRtvK/GtYt3F9UeG4KxzjwK?= X-Microsoft-Antispam-Message-Info: PNOhc7bTLBUpWmKHRDGeO/UYg5drvh5TCtS3RSj7GZ4E1glhR+Tos5qpSgNNw9H6vyERghOWhe3pCgHDYaO8F+lwcLI13EqLVKo/ySvt9lPZXAq/UW011fW/rzUiMpXr5FjjybMtscRPmXrmdQQgCtd5/kb/1178KpQIZ57irKQomkijxeT26sTGeO9J+yn/2WL6a0BiM1YMmTVC4gS5EfyNZBkIxazqHcO37vNDMLVV1lbxP9CVDHZdzVsBXNtaHaLI/fCO5HdPzNhAGWvtVYTqPS0jdM3n5YRVWD0uFVgGpXx2t2MaapxLTANMfvl60zsxqEx01DLIKvjaJeVMqcbqRTCd8rob082XKq0SJ5s= X-Microsoft-Exchange-Diagnostics: 1;SN1PR15MB0175;6:bsdMSbx/CDtGtvfUu//C2XUDf139KcjIeslzDqJEYmEnEvERx+GGSKIl2Y0dEx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Q= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2018 17:46:17.6893 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d683ea4c-1203-452d-864e-08d5ee68b2a4 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR15MB0175 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-07-20_05:,, 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 If a bpf program is using cgroup local storage, allocate a bpf_cgroup_storage structure automatically on attaching the program to a cgroup and save the pointer into the corresponding bpf_prog_list entry. Analogically, release the cgroup local storage on detaching of the bpf program. Signed-off-by: Roman Gushchin Cc: Alexei Starovoitov Cc: Daniel Borkmann Acked-by: Martin KaFai Lau --- include/linux/bpf-cgroup.h | 1 + kernel/bpf/cgroup.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h index 1b1b4e94d77d..f37347331fdb 100644 --- a/include/linux/bpf-cgroup.h +++ b/include/linux/bpf-cgroup.h @@ -42,6 +42,7 @@ struct bpf_cgroup_storage { struct bpf_prog_list { struct list_head node; struct bpf_prog *prog; + struct bpf_cgroup_storage *storage; }; struct bpf_prog_array; diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index badabb0b435c..986ff18ef92e 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -34,6 +34,8 @@ void cgroup_bpf_put(struct cgroup *cgrp) list_for_each_entry_safe(pl, tmp, progs, node) { list_del(&pl->node); bpf_prog_put(pl->prog); + bpf_cgroup_storage_unlink(pl->storage); + bpf_cgroup_storage_free(pl->storage); kfree(pl); static_branch_dec(&cgroup_bpf_enabled_key); } @@ -188,6 +190,7 @@ int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog, { struct list_head *progs = &cgrp->bpf.progs[type]; struct bpf_prog *old_prog = NULL; + struct bpf_cgroup_storage *storage, *old_storage = NULL; struct cgroup_subsys_state *css; struct bpf_prog_list *pl; bool pl_was_allocated; @@ -210,6 +213,10 @@ int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog, if (prog_list_length(progs) >= BPF_CGROUP_MAX_PROGS) return -E2BIG; + storage = bpf_cgroup_storage_alloc(prog); + if (IS_ERR(storage)) + return -ENOMEM; + if (flags & BPF_F_ALLOW_MULTI) { list_for_each_entry(pl, progs, node) if (pl->prog == prog) @@ -217,24 +224,33 @@ int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog, return -EINVAL; pl = kmalloc(sizeof(*pl), GFP_KERNEL); - if (!pl) + if (!pl) { + bpf_cgroup_storage_free(storage); return -ENOMEM; + } + pl_was_allocated = true; pl->prog = prog; + pl->storage = storage; list_add_tail(&pl->node, progs); } else { if (list_empty(progs)) { pl = kmalloc(sizeof(*pl), GFP_KERNEL); - if (!pl) + if (!pl) { + bpf_cgroup_storage_free(storage); return -ENOMEM; + } pl_was_allocated = true; list_add_tail(&pl->node, progs); } else { pl = list_first_entry(progs, typeof(*pl), node); old_prog = pl->prog; + old_storage = pl->storage; + bpf_cgroup_storage_unlink(old_storage); pl_was_allocated = false; } pl->prog = prog; + pl->storage = storage; } cgrp->bpf.flags[type] = flags; @@ -257,10 +273,13 @@ int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog, } static_branch_inc(&cgroup_bpf_enabled_key); + if (old_storage) + bpf_cgroup_storage_free(old_storage); if (old_prog) { bpf_prog_put(old_prog); static_branch_dec(&cgroup_bpf_enabled_key); } + bpf_cgroup_storage_link(storage, cgrp, type); return 0; cleanup: @@ -276,6 +295,9 @@ int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog, /* and cleanup the prog list */ pl->prog = old_prog; + bpf_cgroup_storage_free(pl->storage); + pl->storage = old_storage; + bpf_cgroup_storage_link(old_storage, cgrp, type); if (pl_was_allocated) { list_del(&pl->node); kfree(pl); @@ -356,6 +378,8 @@ int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, /* now can actually delete it from this cgroup list */ list_del(&pl->node); + bpf_cgroup_storage_unlink(pl->storage); + bpf_cgroup_storage_free(pl->storage); kfree(pl); if (list_empty(progs)) /* last program was detached, reset flags to zero */ -- 2.14.4