Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1408706imm; Wed, 1 Aug 2018 15:40:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf0u1S96KCrE7mh4EvZeteKSqNSnQg+zpD+fRt8OrOVH366CfbHAklLM6DJ6LvcMIawqW/W X-Received: by 2002:a62:4c0f:: with SMTP id z15-v6mr266448pfa.110.1533163207725; Wed, 01 Aug 2018 15:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533163207; cv=none; d=google.com; s=arc-20160816; b=WDWq2GmmpIqrLjd0PtUchHsS5yFv/RLgGitRXbkUmfzj4s28uTZaVxsP19RS88JUlz qOgev9WR9Na/tuybxGLuhL4H5Imkul0wZzFTTJatoQzc6RBx/8wRwz6dzXA29m0YRX3O APjdwpGpakL2j6O7QtkLsr/sQCExTIL7WYYbm+HQYwrEsfxmU3RzXmLomyM2r3zQBWQi 6HVXaq6vKxYuf8eRXBUFSkhwYEUvM6FAJUoI0JoY+Mdj/48YswRBCyPgkxFSbkPAa6K2 TfsyYJDS83QNACIuVKtt2DPdFZfB+H/YKeBckQXd+/V2bEipALQkHrFfGEyI34icWG9A +SnA== 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=KYnSp7NsKyMzyHdhSDtQhVvHlpJLTQwyiFaE9Hw63ek=; b=aopVeJ7wUUF8YtjAg2wdKYvKBj5Pa4XIHB7ErMAceVIocNVocdDiXxXHbyzLEFND+K 13E7sXGjPPJNIB+Blk4Ik1ZJanLhOQN8BEECs7TuRaY3nZjfsF+cA2UEsYgT/oeaScfB /GsZ8KcRO3xuAJTX7UpjeTlL7yQZmU7nbe34ZPQ8k3+kUo7R2ua3/Wx9M42WGl1bg/bE spXuetKnqAXwNMiOgnYB9cTN4Hf9xvNiUS4ymSSmLPemWNYbVWFRFSYOElNqvmHlN6dy QgH4vyOSm14zNIlTYgfY/RIqqmA0zadvaN/rYCAWbWfhgnG7WU3UthqrrU2kHCyM2r0D u40Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=NQks+D7u; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=J2blapEn; 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 o23-v6si140579pgv.518.2018.08.01.15.39.53; Wed, 01 Aug 2018 15:40:07 -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=NQks+D7u; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=J2blapEn; 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 S2387694AbeHBA0w (ORCPT + 99 others); Wed, 1 Aug 2018 20:26:52 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:40270 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732387AbeHBA0v (ORCPT ); Wed, 1 Aug 2018 20:26:51 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.22/8.16.0.22) with SMTP id w71Mb8xU029725; Wed, 1 Aug 2018 15:38:21 -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=KYnSp7NsKyMzyHdhSDtQhVvHlpJLTQwyiFaE9Hw63ek=; b=NQks+D7unYERpj+rx7imqIIKJCeqoK0XA2UHxO+1Zo7YAtm3W4KhZ7fR+bk13CR9FElu f6VuxiVMdmyE/2/y/7hyjcOolBb3gziV7CYuOTlHskWCTTLXx+zrE831sUFD3H1kXhAb qfmmGxif9zb1UJPFyBxAeTSA0tmMYoQHgaA= Received: from maileast.thefacebook.com ([199.201.65.23]) by m0001303.ppops.net with ESMTP id 2kkn4c03m9-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 01 Aug 2018 15:38:21 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.28) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 1 Aug 2018 18:38:20 -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=KYnSp7NsKyMzyHdhSDtQhVvHlpJLTQwyiFaE9Hw63ek=; b=J2blapEnvkM04SemnfKsFRBYD2r1ogBAgPLprnYuGtwcCr98MMoHYqzS5ZZZsFE1i/VtHRxbMlvYl/SurqVhS9NEaqKHun0vn3k/VM1hbo6HzZng5eRfXiLvQzEC3kq196lTEsHOcspXQj8WnSEnGQzZcbJjyt1+q+HUz/fxsfM= 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:17 +0000 From: Roman Gushchin To: CC: , , Roman Gushchin , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH v6 bpf-next 04/14] bpf: allocate cgroup storage entries on attaching bpf programs Date: Wed, 1 Aug 2018 15:37:30 -0700 Message-ID: <20180801223740.11252-5-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: 7cf7a8a8-21cf-49f3-a32c-08d5f7ff7a5d 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:CjQehB3MYTgCvRUDKU3B6vG/kkT1RpBv9D82NP0lTP7/McQIHbuu8eg4G7Nn9G639ibY1iRa0kId0xq1W0MAJ2xTKgTc6f9tHbvIN6X+sZlAysxRFm7uWarfQ/WpcRDMbUORDZ63gE1CV3cjPnilygbNiXszowCih9nSgtD0qDPZp/qRVP1/iuUkmtK4gB1gTBSRflfqAr+cZhrJeREboQ/YuGEqb9AczP2XoOg43k6QYt9cFqZhe58Vg0g2AxrX;25:T27wx1WVoUc5vJ8ZiIWIt480mX7XUw9XdMkwRBMG/mKK+dqkzDCmiNAyH4SNAB96pGxSGhTnnhXVvI8LW0d7RX55p9chUrB0ggWL+xOMXms3V9FXgOe+Q2pqN6VeQA/XE1C5cqW+lhxlnI+Ya2snXw40LwyYs96986JblF7FV51sD3rqpXf9ly7NdY2ZiDV2FMrB6Pi5kn8YU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gV0oI6Hy1opBLPi8Illeut6M7nV+cip/pyZ+C/v0owYlPoZ8zklD+BV0Ffc0T8dihM69M8UyAMgdBu5VM+t3ryK1r9RPeRfi3nMmKyx/+aH3pbjW5NrWmIk6GzD/I7HUTbmgnf9vYrXAAc3i89ks9/BB7aR5n9d6BftMYGPjsAiV9SgZ9msb2NR7K08x 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)(366004)(376002)(39860400002)(346002)(396003)(136003)(199004)(189003)(11346002)(6486002)(6512007)(50226002)(6916009)(2361001)(5660300001)(53416004)(68736007)(6666003)(386003)(106356001)(6506007)(76176011)(105586002)(52116002)(51416003)(86362001)(575784001)(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-Diagnostics: =?us-ascii?Q?1;SN1PR15MB0176;23:g1lyjsRk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InA6LZcYAH1zdYoIkmx4wiijQFx+alqM1ou0WOAVHxYERni4jwdoZqeiJnnu/xNtIQ4QtDv0gukPCMiCbZoZ2PNV6PDClie6liihk9LrFXtRYZs47k/qqJ0xi8hph1SnOk17ClOKKyMFh3UwTyfeDufxthJECrcaHfC2gdC9IWLCkDHuoevpyIbFaxEpK0o6uWkm+B96flbPqB/tzjLnE6rz6OQ6UF17kqwLa8n+uDzegWTJqMI3iH7sCkuMAcb8MnIEva9MQPYIAMDx4Exphc0RMDyierTu5dr/OOZ9HWs5omRY4n1rTKTMA1YPvnkzRdN/qBOws3LQJ1MHKNtLFtPsVLpZ5Df5okoZxUCka4sxslvyw==;5:iTrA/5RzuTzL0s44ZWwMKmU/atnuHbGSmYOQ7Bjdad3hbdVDPdrjwV6FmGetalecrojX9lODuTHDz5oDtlOJyCFiNNAfxbFTmOgiS7/fAZlqM76PpLTxJxsseMfHZN5c8wUxkfqBuqy62ch5Am9qSSga0DOPNIX12SNTmD1P704=;7:fyFCaoXi8YsGkknIpjoW4T1Qaw061iAzct2TxbpoZnT9OVw3285qyypiU9f0fcfPHJqsuonrzOEXialqHox2fcYuW/z7EaB4NEz0WmyOwwTTTAcbk018epfDP2gQDCXAf8n35h22tTKKIuXDKI4Ato7ji7j+e2ghPmY04NDv5FHeC+MjiKS6hgn3ymPxupjTBN+MwVUbCvn+JL9S803iVD3lPt/xmE+wUlyP4Iy5FHX396zOVZfXRfU+PPGTs5Vx SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN1PR15MB0176;20:L8nsHRZ9C2spC/2wyArJ7oltv1uNjD8MnD4/xTz0yHHKS8VLdPiEy8hnDn4qwUTbZ31+b7xBWGuCLiJQoxKcbMLd5pQ9zsUuvqh/D8nXvy4XRnWjtY6QyiLjsJ5Wr5i0rNPZ+pl5dkot9p7VIbV2daeMKy/+ZMQw/u5sYtc46po= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2018 22:38:17.8235 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7cf7a8a8-21cf-49f3-a32c-08d5f7ff7a5d 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 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 | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h index 9a144ddbbc8f..f91b0f8ff3a9 100644 --- a/include/linux/bpf-cgroup.h +++ b/include/linux/bpf-cgroup.h @@ -43,6 +43,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..935274c86bfe 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,31 +213,47 @@ 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) + list_for_each_entry(pl, progs, node) { + if (pl->prog == prog) { /* disallow attaching the same prog twice */ + bpf_cgroup_storage_free(storage); 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 +276,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 +298,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 +381,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