Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp554746imm; Fri, 28 Sep 2018 03:04:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV61vaan+3rZkzVqhp3sbcwPAR33WlJyiWEwWzO98HibiX0yYkrpGoTOcC96HHUPyASr0n68K X-Received: by 2002:a17:902:8a90:: with SMTP id p16-v6mr15734545plo.106.1538129073480; Fri, 28 Sep 2018 03:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538129073; cv=none; d=google.com; s=arc-20160816; b=YcIt2AMgAq8LHI26MYkD9GyUihQY03gUMMlk7kvKt30pTO7ue9eYWC6TrMV0z67eUv 2Td8e48qnyei7Axc5JGdEsc87OJbmCmR6XgE0NeWRySUazdG1+pQSAWlSO7F5MiLfcX9 GODXBpQxbW7sK52eKsgOnZmwDP2wWkDAy0RpdMbZvPjcyrOFCSRwzJZ/pqudcaMZE9Xg /N6EQkwnyHRXjni/nVYloXovb6HDdg/Qcgey6DmKCGczrSELYI9ERB58S24r9v7bKi2i 66JWCbue5NLci+WCxzi1DrrIQvFLGlwfXbZ7I6OdwfK3WOFJSixZx8SxUCkFd4PBmTAB qiJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=SbgyrQ8jmSpwTIMn8LI+3wEcdGBGSDLwN7ihwM337E8=; b=kvkA9yc9FwOZOHTa+qDu+u3qyZidcpioaWecLoh0tWK647TZOfUTTzB6hB+ozNxLPG wDmYBF5AdcVY5TRE2PgEZnBkmMQcW1khK2jL6Hl4uiHGlJ+ozgofsGo1GfK/b9vWSrpP GTyb/nthKUxQJyJLsFZ2abBzA6RmWyxVjy0tgpk/jFk+AssJKxZzMI0ncDH5AB0OG74I VV86UlofuO451LTcBu0bxOGv/z6UyFMSQ1wptzBh+pXjzgZabEZkLt5PMjDvr5MGkd/H glJcR2csxsIA8uHIFHM1nNk8Tgq7RODou1ihlaV2u5QhLuTgFwjQlb7YFf7iVunA9iDG SdhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=KcJH1xid; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=aGSzoGlG; 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 f62-v6si4524869plf.164.2018.09.28.03.04.13; Fri, 28 Sep 2018 03:04:33 -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=KcJH1xid; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=aGSzoGlG; 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 S1729242AbeI1Q1E (ORCPT + 99 others); Fri, 28 Sep 2018 12:27:04 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:53186 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729111AbeI1Q1D (ORCPT ); Fri, 28 Sep 2018 12:27:03 -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 w8SA375o020156; Fri, 28 Sep 2018 03:03:49 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=facebook; bh=SbgyrQ8jmSpwTIMn8LI+3wEcdGBGSDLwN7ihwM337E8=; b=KcJH1xidVjz0Sh2KN0qle0cQk6OKO2ycgWAQ3O31QOQVX210pEJiep62RaBJM3cJEEH4 G95ayaXq/qtwpvMoJ7BOisk05QrxWSGypXPPzvCS+TaS5GfBLv9z7Ub8u3GB1wiiiRQm Co6FmBMEAXXwl6hpRozsJxIwee/zu5UnkD8= Received: from mail.thefacebook.com ([199.201.64.23]) by m0001303.ppops.net with ESMTP id 2ms9mes7fa-7 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 28 Sep 2018 03:03:49 -0700 Received: from NAM04-CO1-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.21) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 28 Sep 2018 03:03:24 -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=SbgyrQ8jmSpwTIMn8LI+3wEcdGBGSDLwN7ihwM337E8=; b=aGSzoGlGPXz5w6QHWkJWHNGSfEZeWrTsWv8C0lGudKhp8mSP4je4QvNbgVdJEZuOYM7orZGU63sFnChQvwJVwz3imqcsgaKJ4sJnXvEr0MUC0lS7KKdkuo14NU/3P7W7jIO807Q+/SF1724Z7sERFnoGNyc10pP7YaEUTi4CYCk= Received: from castle.DHCP.thefacebook.com (2620:10d:c092:180::1:836c) by BLUPR15MB0162.namprd15.prod.outlook.com (2a01:111:e400:5249::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.20; Fri, 28 Sep 2018 10:03:14 +0000 Date: Fri, 28 Sep 2018 11:03:03 +0100 From: Roman Gushchin To: Alexei Starovoitov CC: , Song Liu , , , Daniel Borkmann , Alexei Starovoitov Subject: Re: [PATCH v3 bpf-next 03/10] bpf: introduce per-cpu cgroup local storage Message-ID: <20180928100302.GB9018@castle.DHCP.thefacebook.com> References: <20180926113326.29069-1-guro@fb.com> <20180926113326.29069-4-guro@fb.com> <20180928084528.i5txkac34pmqvs3p@ast-mbp.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20180928084528.i5txkac34pmqvs3p@ast-mbp.dhcp.thefacebook.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Originating-IP: [2620:10d:c092:180::1:836c] X-ClientProxiedBy: AM5PR0701CA0006.eurprd07.prod.outlook.com (2603:10a6:203:51::16) To BLUPR15MB0162.namprd15.prod.outlook.com (2a01:111:e400:5249::12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 03f98db4-5877-4310-de3e-08d625299d65 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BLUPR15MB0162; X-Microsoft-Exchange-Diagnostics: 1;BLUPR15MB0162;3:z5sTaJ4yjs3FqzNzrqCb0rRM2/XCIw5W2q3CJJGpUMTndEpuvUI6eEOhf7rYyp1yUxYlTHquinxgM1CUOYgO4utirYJwW34WHH0KY69BU5sWqqGumNoP6gm3k18glSf/n4RGYZibJX7FgKkwuVHLFa3kcDE/s/ZlUr2TUj2IRAsUZa+17VqE6TM8u3lGiqW1uppJ0EwehgGYcfw3NAofQxMmmjdjsi4grKPskOg+K/OuJbVjXwmx+d366h60TdT1;25:97frmqwd+R+Qbl7yxTvBgizdkU5Bi/2vCNeJI1hSJT6zbHVcMdkkr8bsbOMP+AtHNXUNfIdoHvhX4ugxAM0+Hb/z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5G2RNZTpNkLMZ;4:gKcONC1cHvsw8kaKNzNhuhORRFsMkiRuJe3zW6kDc+i0SfKh2T2Ni89gY+zQm9dTOYhAKDAyLO9ElowAubzAoESf59+oojqnqlL6jdP2TSEERBOHC20r/bcK4HZvryWy2SnVFlGRlFp69yP4raA6GBDVXL9O+HllDdsx9lzZ3BDyHOtAvtOMXAkulPrlccIDJpA0CuWro5Xf565QUBWF2vc28PWTpuBAxdEE9QOxZKCAc/HJDTRB9myHYVFlKTuXRJ4MouOXgYjTZt5eF0cVCm0xKJYod8YIURnN1gY93jLJHTc8csZBJrQXQ51OWSgi 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)(823302061)(3002001)(93006095)(93001095)(10201501046)(3231355)(11241501184)(944501410)(52105095)(149066)(150057)(6041310)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(201708071742011)(7699051);SRVR:BLUPR15MB0162;BCL:0;PCL:0;RULEID:;SRVR:BLUPR15MB0162; X-Forefront-PRVS: 0809C12563 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(39860400002)(366004)(136003)(396003)(346002)(376002)(199004)(189003)(4326008)(2906002)(105586002)(486006)(97736004)(106356001)(7736002)(476003)(46003)(68736007)(58126008)(5660300001)(6506007)(52396003)(7696005)(16586007)(16526019)(186003)(316002)(54906003)(33656002)(386003)(1076002)(23726003)(11346002)(6116002)(305945005)(52116002)(446003)(76176011)(50466002)(229853002)(47776003)(8676002)(55016002)(53936002)(8936002)(478600001)(9686003)(14444005)(25786009)(86362001)(575784001)(34290500001)(6246003)(81156014)(81166006)(39060400002)(6666003)(6916009)(18370500001)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR15MB0162;H:castle.DHCP.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;BLUPR15MB0162;23:KrDo7lAK5CPvrut1wu+WTRQOeItQHGx6ojGaZUNGs?= =?us-ascii?Q?V7tXJyxoxIc+beUq93npTrI5amdvvbmGXV0QY641P3Xfz9Rj83ftL2dJoeq2?= =?us-ascii?Q?5fbfTjjhtdSRnMV/antgKo5Uzj2BLR58b5QVLdVbxXTAPtRj32rQ35u19tGz?= =?us-ascii?Q?+Q+i3cwjwGegT13Tln5HLlxSNrowNp3CskEwcJvS5idQcnpVddIbm/L/t1B6?= =?us-ascii?Q?0SV3squEzAF457aeSn0Kf3V1uEvCg2NlqQShvuHUxzgJJH3oNEgWhbvUk/VB?= =?us-ascii?Q?ouCrIsSyRzNBUjD3Kwawi4FRhxw3ILzfzLxotVCyW481dAql7Ru9GuNoIaJ2?= =?us-ascii?Q?/2lw3svqr5rGt+KSFKgFuu5Iu768Upzq3+yGUAXcpqs6Buqb0njvl8QIcxie?= =?us-ascii?Q?wpzgIFJORL6LXlPnzemt5EY0f6MOi735ZcTzYcZVWhE/6CyToR1HqJuAUyqr?= =?us-ascii?Q?roZDlcfzIeP4q/XXg1Mj2N1XwNy/WDK0t9tH2UFW1v78zsu9Dqoo0G/kLPgd?= =?us-ascii?Q?dx7r4MT2gOFTg8SAdY/xSXSDbg470MF5VsCDMTNeKrE8ar1yioFL1ABlnXGd?= =?us-ascii?Q?rfViy/L6gstkw7ML/fjfUSCmXlZKf87OdZjvv1b9vMWmbUYFh0KRDwNjmInX?= =?us-ascii?Q?I9MqPNxiAPqLFNHOFwWf8O1NFddb1CNSseecOVX51A9tgZdPj+0tDlSSRATD?= =?us-ascii?Q?i3d+y23Y+dus2Io2hHwUmqv4dCg0aE3bamK17+Uh3fSec3c4yuixMidA1MgG?= =?us-ascii?Q?e9I/y3ndqs61W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aq6k/XrGU/PyeBAIIz/Rz8Wrg6+IdRU1ldvhnETFCkpRMEcIuuoHiJXKs5c6yiX2lIfZCEHnJCni33uEYmtziFSw8nNy4zZzw/BdVmYOs/V9UHOyiAKN9HlBBdySBiHZC/Xg= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2018 10:03:14.9951 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 03f98db4-5877-4310-de3e-08d625299d65 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR15MB0162 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-28_04:,, 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 On Fri, Sep 28, 2018 at 10:45:31AM +0200, Alexei Starovoitov wrote: > On Wed, Sep 26, 2018 at 12:33:19PM +0100, Roman Gushchin wrote: > > This commit introduced per-cpu cgroup local storage. > > > > Per-cpu cgroup local storage is very similar to simple cgroup storage > > (let's call it shared), except all the data is per-cpu. > > > > The main goal of per-cpu variant is to implement super fast > > counters (e.g. packet counters), which don't require neither > > lookups, neither atomic operations. > > > > From userspace's point of view, accessing a per-cpu cgroup storage > > is similar to other per-cpu map types (e.g. per-cpu hashmaps and > > arrays). > > > > Writing to a per-cpu cgroup storage is not atomic, but is performed > > by copying longs, so some minimal atomicity is here, exactly > > as with other per-cpu maps. > > > > Signed-off-by: Roman Gushchin > > Cc: Daniel Borkmann > > Cc: Alexei Starovoitov > > --- > > include/linux/bpf-cgroup.h | 20 ++++- > > include/linux/bpf.h | 1 + > > include/linux/bpf_types.h | 1 + > > include/uapi/linux/bpf.h | 1 + > > kernel/bpf/helpers.c | 8 +- > > kernel/bpf/local_storage.c | 148 ++++++++++++++++++++++++++++++++----- > > kernel/bpf/syscall.c | 11 ++- > > kernel/bpf/verifier.c | 15 +++- > > 8 files changed, 177 insertions(+), 28 deletions(-) > > > > diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h > > index 7e0c9a1d48b7..588dd5f0bd85 100644 > > --- a/include/linux/bpf-cgroup.h > > +++ b/include/linux/bpf-cgroup.h > > @@ -37,7 +37,10 @@ struct bpf_storage_buffer { > > }; > > > > struct bpf_cgroup_storage { > > - struct bpf_storage_buffer *buf; > > + union { > > + struct bpf_storage_buffer *buf; > > + void __percpu *percpu_buf; > > + }; > > struct bpf_cgroup_storage_map *map; > > struct bpf_cgroup_storage_key key; > > struct list_head list; > > @@ -109,6 +112,9 @@ int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor, > > static inline enum bpf_cgroup_storage_type cgroup_storage_type( > > struct bpf_map *map) > > { > > + if (map->map_type == BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE) > > + return BPF_CGROUP_STORAGE_PERCPU; > > + > > return BPF_CGROUP_STORAGE_SHARED; > > } > > > > @@ -131,6 +137,10 @@ void bpf_cgroup_storage_unlink(struct bpf_cgroup_storage *storage); > > int bpf_cgroup_storage_assign(struct bpf_prog *prog, struct bpf_map *map); > > void bpf_cgroup_storage_release(struct bpf_prog *prog, struct bpf_map *map); > > > > +int bpf_percpu_cgroup_storage_copy(struct bpf_map *map, void *key, void *value); > > +int bpf_percpu_cgroup_storage_update(struct bpf_map *map, void *key, > > + void *value, u64 flags); > > + > > /* Wrappers for __cgroup_bpf_run_filter_skb() guarded by cgroup_bpf_enabled. */ > > #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk, skb) \ > > ({ \ > > @@ -285,6 +295,14 @@ static inline struct bpf_cgroup_storage *bpf_cgroup_storage_alloc( > > struct bpf_prog *prog, enum bpf_cgroup_storage_type stype) { return 0; } > > static inline void bpf_cgroup_storage_free( > > struct bpf_cgroup_storage *storage) {} > > +static inline int bpf_percpu_cgroup_storage_copy(struct bpf_map *map, void *key, > > + void *value) { > > + return 0; > > +} > > +static inline int bpf_percpu_cgroup_storage_update(struct bpf_map *map, > > + void *key, void *value, u64 flags) { > > + return 0; > > +} > > > > #define cgroup_bpf_enabled (0) > > #define BPF_CGROUP_PRE_CONNECT_ENABLED(sk) (0) > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > > index b457fbe7b70b..018299a595c8 100644 > > --- a/include/linux/bpf.h > > +++ b/include/linux/bpf.h > > @@ -274,6 +274,7 @@ struct bpf_prog_offload { > > > > enum bpf_cgroup_storage_type { > > BPF_CGROUP_STORAGE_SHARED, > > + BPF_CGROUP_STORAGE_PERCPU, > > __BPF_CGROUP_STORAGE_MAX > > }; > > > > diff --git a/include/linux/bpf_types.h b/include/linux/bpf_types.h > > index c9bd6fb765b0..5432f4c9f50e 100644 > > --- a/include/linux/bpf_types.h > > +++ b/include/linux/bpf_types.h > > @@ -43,6 +43,7 @@ BPF_MAP_TYPE(BPF_MAP_TYPE_CGROUP_ARRAY, cgroup_array_map_ops) > > #endif > > #ifdef CONFIG_CGROUP_BPF > > BPF_MAP_TYPE(BPF_MAP_TYPE_CGROUP_STORAGE, cgroup_storage_map_ops) > > +BPF_MAP_TYPE(BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE, cgroup_storage_map_ops) > > #endif > > BPF_MAP_TYPE(BPF_MAP_TYPE_HASH, htab_map_ops) > > BPF_MAP_TYPE(BPF_MAP_TYPE_PERCPU_HASH, htab_percpu_map_ops) > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > > index aa5ccd2385ed..e2070d819e04 100644 > > --- a/include/uapi/linux/bpf.h > > +++ b/include/uapi/linux/bpf.h > > @@ -127,6 +127,7 @@ enum bpf_map_type { > > BPF_MAP_TYPE_SOCKHASH, > > BPF_MAP_TYPE_CGROUP_STORAGE, > > BPF_MAP_TYPE_REUSEPORT_SOCKARRAY, > > + BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE, > > }; > > > > enum bpf_prog_type { > > diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c > > index e42f8789b7ea..6502115e8f55 100644 > > --- a/kernel/bpf/helpers.c > > +++ b/kernel/bpf/helpers.c > > @@ -206,10 +206,16 @@ BPF_CALL_2(bpf_get_local_storage, struct bpf_map *, map, u64, flags) > > */ > > enum bpf_cgroup_storage_type stype = cgroup_storage_type(map); > > struct bpf_cgroup_storage *storage; > > + void *ptr; > > > > storage = this_cpu_read(bpf_cgroup_storage[stype]); > > > > - return (unsigned long)&READ_ONCE(storage->buf)->data[0]; > > + if (stype == BPF_CGROUP_STORAGE_SHARED) > > + ptr = &READ_ONCE(storage->buf)->data[0]; > > + else > > + ptr = this_cpu_ptr(storage->percpu_buf); > > + > > + return (unsigned long)ptr; > > } > > > > const struct bpf_func_proto bpf_get_local_storage_proto = { > > diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c > > index 6742292fb39e..c739f6dcc3c2 100644 > > --- a/kernel/bpf/local_storage.c > > +++ b/kernel/bpf/local_storage.c > > @@ -152,6 +152,71 @@ static int cgroup_storage_update_elem(struct bpf_map *map, void *_key, > > return 0; > > } > > > > +int bpf_percpu_cgroup_storage_copy(struct bpf_map *_map, void *_key, > > + void *value) > > +{ > > + struct bpf_cgroup_storage_map *map = map_to_storage(_map); > > + struct bpf_cgroup_storage_key *key = _key; > > + struct bpf_cgroup_storage *storage; > > + int cpu, off = 0; > > + u32 size; > > + > > + rcu_read_lock(); > > + storage = cgroup_storage_lookup(map, key, false); > > + if (!storage) { > > + rcu_read_unlock(); > > + return -ENOENT; > > + } > > + > > + /* per_cpu areas are zero-filled and bpf programs can only > > + * access 'value_size' of them, so copying rounded areas > > + * will not leak any kernel data > > + */ > > + size = round_up(_map->value_size, 8); > > + for_each_possible_cpu(cpu) { > > + bpf_long_memcpy(value + off, > > + per_cpu_ptr(storage->percpu_buf, cpu), size); > > + off += size; > > + } > > + rcu_read_unlock(); > > + return 0; > > +} > > + > > +int bpf_percpu_cgroup_storage_update(struct bpf_map *_map, void *_key, > > + void *value, u64 map_flags) > > +{ > > + struct bpf_cgroup_storage_map *map = map_to_storage(_map); > > + struct bpf_cgroup_storage_key *key = _key; > > + struct bpf_cgroup_storage *storage; > > + int cpu, off = 0; > > + u32 size; > > + > > + if (unlikely(map_flags & BPF_EXIST)) > > + return -EINVAL; > > that should have been BPF_NOEXIST ? Yeah, or maybe even better s/&/!= ? It's probably better to require BPF_EXIST flag to update a cgroup storage? Agree? If so, let me fix this for both shared and per-cpu versions in a follow-up patch. > > > + > > + rcu_read_lock(); > > + storage = cgroup_storage_lookup(map, key, false); > > + if (!storage) { > > + rcu_read_unlock(); > > + return -ENOENT; > > + } > > + > > + /* the user space will provide round_up(value_size, 8) bytes that > > + * will be copied into per-cpu area. bpf programs can only access > > + * value_size of it. During lookup the same extra bytes will be > > + * returned or zeros which were zero-filled by percpu_alloc, > > + * so no kernel data leaks possible > > + */ > > + size = round_up(_map->value_size, 8); > > + for_each_possible_cpu(cpu) { > > + bpf_long_memcpy(per_cpu_ptr(storage->percpu_buf, cpu), > > + value + off, size); > > + off += size; > > + } > > + rcu_read_unlock(); > > storage_update and storage_copy look essentially the same > with the only difference that src/dst swap. > Would it be possible to combine them ? > Not sure whether #define template would look better. I'll try to refactor this and next one in a follow-up patch. Thanks!