Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4979369imm; Tue, 31 Jul 2018 03:35:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdKlxrHpsZVIinudVq33aAp8rmWa4c9BTMlDPxYM7F3nLVv0d8VvebFrWFxpcegghPi6yHK X-Received: by 2002:a63:a347:: with SMTP id v7-v6mr19357852pgn.182.1533033351429; Tue, 31 Jul 2018 03:35:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533033351; cv=none; d=google.com; s=arc-20160816; b=CGRPoac1gEaN9sYGixasa9j2JJMJSK1taxSZRwkUEVIc2onkD5+BElkMWnpq1emlBA WaAlMnSQBJtjdbMn0eM9MeMxYcETOy9JMlj3EAzpiBtZtuwyMaBBGH556FUgHYWAIP1l naSUMYZ793+dWH6fPG3nJhPrBlDYF4gJjubgpuweGj8savSdVsEvXirCL+Wzb1cRZYVI +CB+hSVpz7bqMWlZIbOoAcp0Rvtg9SOPIKEG/RUyiKuZmqX63VBGd/YQR61sI11SAyKK OZZIximVo63JO1KDlEIPYXvpxdg60s2z/tGisPO6EadoHNYsk6ewu9au3GCiAR2zuyDS 9eGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=XYKH6z4DdNflXEkvH3x75uta8HwyYvkhZsYFpw02pcA=; b=b9TQLeHAOgN5J+zP0Fyg6wqSeylAHUGm9DDQzpA28gnJOSdm0+PfFdG4XPMWFyD8oh xHopP9tvJzBdKu944tC/fF+T5blrlwEJUPFU5DaLlo1bh56R+3UTeAgKMRN3vS8mJv0o VGVOT9GdX0yzhuSBrvS1je+K/uozUk3175I4loxwPmrPnqHeG9Umm0blDos7SrgkGwpj WK1dbrjsHrhYtxTxqNAaTvjlszHD2RDR4pGG5OdXoMpzXNv1JXnoy5nE5ShbIERGOoTa WzdMhTO3qBzS/ocFv6CRHGroBnKIBJcRwnNSPNUCwin9Y3fMFJL+jtXsBg75BN+BhcEF JSrA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z13-v6si14438310pfc.118.2018.07.31.03.35.37; Tue, 31 Jul 2018 03:35:51 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731931AbeGaMNv (ORCPT + 99 others); Tue, 31 Jul 2018 08:13:51 -0400 Received: from www62.your-server.de ([213.133.104.62]:35053 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730422AbeGaMNu (ORCPT ); Tue, 31 Jul 2018 08:13:50 -0400 Received: from [78.46.172.2] (helo=sslproxy05.your-server.de) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1fkRyi-0005mQ-0X; Tue, 31 Jul 2018 12:34:08 +0200 Received: from [2a02:120b:c3f4:b8b0:b5ea:3969:d380:aafd] (helo=linux.home) by sslproxy05.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1fkRyh-000Mst-Pb; Tue, 31 Jul 2018 12:34:07 +0200 Subject: Re: [PATCH v4 bpf-next 08/14] bpf: introduce the bpf_get_local_storage() helper function To: Roman Gushchin , netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com, Alexei Starovoitov References: <20180727215243.3850-1-guro@fb.com> <20180727215243.3850-9-guro@fb.com> From: Daniel Borkmann Message-ID: Date: Tue, 31 Jul 2018 12:34:06 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20180727215243.3850-9-guro@fb.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.0/24799/Tue Jul 31 10:44:57 2018) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Roman, On 07/27/2018 11:52 PM, Roman Gushchin wrote: > The bpf_get_local_storage() helper function is used > to get a pointer to the bpf local storage from a bpf program. > > It takes a pointer to a storage map and flags as arguments. > Right now it accepts only cgroup storage maps, and flags > argument has to be 0. Further it can be extended to support > other types of local storage: e.g. thread local storage etc. > > Signed-off-by: Roman Gushchin > Cc: Alexei Starovoitov > Cc: Daniel Borkmann > Acked-by: Martin KaFai Lau > --- > include/linux/bpf.h | 2 ++ > include/uapi/linux/bpf.h | 13 ++++++++++++- > kernel/bpf/cgroup.c | 2 ++ > kernel/bpf/core.c | 1 + > kernel/bpf/helpers.c | 20 ++++++++++++++++++++ > kernel/bpf/verifier.c | 18 ++++++++++++++++++ > net/core/filter.c | 23 ++++++++++++++++++++++- > 7 files changed, 77 insertions(+), 2 deletions(-) > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > index ca4ac2a39def..cd8790d2c6ed 100644 > --- a/include/linux/bpf.h > +++ b/include/linux/bpf.h > @@ -788,6 +788,8 @@ extern const struct bpf_func_proto bpf_sock_map_update_proto; > extern const struct bpf_func_proto bpf_sock_hash_update_proto; > extern const struct bpf_func_proto bpf_get_current_cgroup_id_proto; > > +extern const struct bpf_func_proto bpf_get_local_storage_proto; > + > /* Shared helpers among cBPF and eBPF. */ > void bpf_user_rnd_init_once(void); > u64 bpf_user_rnd_u32(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5); > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > index a0aa53148763..495180f229ee 100644 > --- a/include/uapi/linux/bpf.h > +++ b/include/uapi/linux/bpf.h > @@ -2081,6 +2081,16 @@ union bpf_attr { > * Return > * A 64-bit integer containing the current cgroup id based > * on the cgroup within which the current task is running. > + * > + * void* get_local_storage(void *map, u64 flags) > + * Description > + * Get the pointer to the local storage area. > + * The type and the size of the local storage is defined > + * by the *map* argument. > + * The *flags* meaning is specific for each map type, > + * and has to be 0 for cgroup local storage. > + * Return > + * Pointer to the local storage area. > */ I think it would be crucial to clarify what underlying assumption the program writer can make with regards to concurrent access to this storage. E.g. in this context, can _only_ BPF_XADD be used for counters as otherwise any other type of access may race in parallel, or are we protected by the socket lock and can safely override all data in this buffer via normal stores (e.g. for socket related progs)? What about other types? Right now nothing is mentioned here, but I think it must be clarified to avoid any surprises. E.g. in normal htab case program can at least use the map update there for atomic value updates, but those are disallowed from the cgroup local storage, hence my question. Btw, no need to resend, I can also update the paragraph there. Thanks, Daniel