Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1165528pxx; Fri, 30 Oct 2020 03:55:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVQt9S0J5ptGYcr81dL7LQ4jBXtacTUA/5tTXhSHNkDmoVMBZxTR2FvkuNSFD2Dv9H1daR X-Received: by 2002:a17:906:aed9:: with SMTP id me25mr1859062ejb.52.1604055309809; Fri, 30 Oct 2020 03:55:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604055309; cv=none; d=google.com; s=arc-20160816; b=ubxvuymrGtqzcdbVKzKcuLVLA+/6Fni5BlYZCqakJAeBZcMjfd2udl9BwRaDx8xss4 BVlWGxEtnuwrvwwoE//gV+Wi+FdzLVUYv7iuPC4i0an5FW+fWnvRYdqO7oFigy716Zpt YCLxVq3dNUlftyf0foV60N0wQyt9krK7e41sY3V/GxJTr74fKILppC7E09RoJ8yaA9P6 Oj9yVL8djiLqqMiUMQPR4borh0lUpiGiXxwaLzTGch8T+aTHCAtJS7A2sRrE59PCw5Md OcZCPplh1jtAEXVucfjj0eu25xYmMydEqWmhLyknBPMnp/GcloTug/bAiSbcdhnfrDRF CDqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RGxKu6N/ljpRrMPYO1GHJVR+cRftYgBFEsOMeaX+uIU=; b=EH0OVW2J7plBYOnc2jwvW4XoFz3xUmHyDbr6VtrjMoHbK8XzWVx9BzxK5dNUtVO+Pb s9Sg3GXUZof3JhfUrtxnTKWmvhEaTGajWp1OlvHupOyVGUYDDqSvcHNIXuihcT/lAbDR 5HwhngGQFCcx+5b1dmgTYTLxhqTByW+B6MHgodmk7ozi5nlLbziHDXyu2sfHne4rJ8oy nRmP+wg+70VU7wCK62IA15aLNeqIJW9a80Zvp8XO6TS/ae4lRAWJDQ+lcIBoJ7IK5Omm TjWZGubd82ARzajKRwls0jQUuA48RQGNWYE8nvGbwnyM/EptCHimytYs1glrM7Yq1rJ5 c6GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jZND6rDL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l23si5013029ejb.488.2020.10.30.03.54.47; Fri, 30 Oct 2020 03:55:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jZND6rDL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726407AbgJ3KxN (ORCPT + 99 others); Fri, 30 Oct 2020 06:53:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726198AbgJ3KxM (ORCPT ); Fri, 30 Oct 2020 06:53:12 -0400 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65220C0613D2 for ; Fri, 30 Oct 2020 03:53:12 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id l2so7336470lfk.0 for ; Fri, 30 Oct 2020 03:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RGxKu6N/ljpRrMPYO1GHJVR+cRftYgBFEsOMeaX+uIU=; b=jZND6rDLmrO9spICzgJTCgUyIjDgF2iwHIqFMlTUr5c9lYncRHD31/x/7EQi8MjLrT uCRhE0xLq1LIUI/SSr+wlB7wQUcMXvAaLBBVYkc80DlaSVmw2nlcyDEh7KQtFUjODJfH QdvLS+s3ocJFBCsofDUuwLvK2t30YKuqtpn8w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RGxKu6N/ljpRrMPYO1GHJVR+cRftYgBFEsOMeaX+uIU=; b=Yth2dvxeoYFtgH3y/WwT99HcCRB8857b0p/4HX540xfW8PeRMZWO/hqSQij5/Iw+ay xRqKXnSvhScn+ObP22Go7ZDymiRkqyRmhA9ybQzrUoj5JaWS/EJZmSo0ZzFz3ttm4/FN ansnJRL/o7VEU8RITjoODFjVhyeoChk2RCanTnGyvXQWSeNqzh12BQQUa6vcoJSIq8Ve o3CpZ4nMQB4WV4i8Ha/Hq5MrovacuNoR4NeDnLQ/ti7NitF6B78u64rKSyiw3VV6bXtp H42qQtZQZYhYDiJo1kO0hn7YTlB88ncWuulCiV/JVbRD3inXICIw6aC3isk851Y9pv5E UAbw== X-Gm-Message-State: AOAM531XAgrE71CWba9mddgTbnscLu2tQi4U9ywque2UKESd+ZsakLHA oxn2bg2E0k3v1LLg7/pOmwzYyk5iVHV9GOcL7ZnzqQ== X-Received: by 2002:a19:c80a:: with SMTP id y10mr736934lff.329.1604055190871; Fri, 30 Oct 2020 03:53:10 -0700 (PDT) MIME-Version: 1.0 References: <20201027170317.2011119-1-kpsingh@chromium.org> <20201027170317.2011119-2-kpsingh@chromium.org> <20201028011321.4yu62347lfzisxwy@kafai-mbp> In-Reply-To: <20201028011321.4yu62347lfzisxwy@kafai-mbp> From: KP Singh Date: Fri, 30 Oct 2020 11:53:00 +0100 Message-ID: Subject: Re: [PATCH bpf-next 1/5] bpf: Implement task local storage To: Martin KaFai Lau Cc: open list , bpf , Alexei Starovoitov , Daniel Borkmann , Paul Turner , Jann Horn , Hao Luo Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks for taking a look! On Wed, Oct 28, 2020 at 2:13 AM Martin KaFai Lau wrote: > > On Tue, Oct 27, 2020 at 06:03:13PM +0100, KP Singh wrote: > [ ... ] > > > diff --git a/kernel/bpf/bpf_task_storage.c b/kernel/bpf/bpf_task_storage.c > > new file mode 100644 > > index 000000000000..774140c458cc > > --- /dev/null > > +++ b/kernel/bpf/bpf_task_storage.c > > @@ -0,0 +1,327 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Copyright (c) 2019 Facebook > > + * Copyright 2020 Google LLC. > > + */ > > + > > +#include "linux/pid.h" > > +#include "linux/sched.h" > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > Is this required? Nope. Removed. > > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +DEFINE_BPF_STORAGE_CACHE(task_cache); > > + > > +static struct bpf_local_storage __rcu **task_storage_ptr(void *owner) [...] > > + err = -EBADF; > > + goto out_fput; > > + } > > + > > + pid = get_pid(f->private_data); > n00b question. Is get_pid(f->private_data) required? > f->private_data could be freed while holding f->f_count? I would assume that holding a reference to the file should also keep the private_data alive but I was not sure so I grabbed the extra reference. > > > + task = get_pid_task(pid, PIDTYPE_PID); > Should put_task_struct() be called before returning? If we keep using get_pid_task then, yes, I see it grabs a reference to the task. We could also call pid_task under rcu locks but it might be cleaner to just get_pid_task and put_task_struct(). > > > + if (!task || !task_storage_ptr(task)) { > "!task_storage_ptr(task)" is unnecessary, task_storage_lookup() should > have taken care of it. > > > > + err = -ENOENT; > > + goto out; > > + } > > + > > + sdata = task_storage_lookup(task, map, true); > > + put_pid(pid); [...] > > + .map_lookup_elem = bpf_pid_task_storage_lookup_elem, > > + .map_update_elem = bpf_pid_task_storage_update_elem, > > + .map_delete_elem = bpf_pid_task_storage_delete_elem, > Please exercise the syscall use cases also in the selftest. Will do. Thanks for the nudge :) > > > + .map_check_btf = bpf_local_storage_map_check_btf, > > + .map_btf_name = "bpf_local_storage_map", > > + .map_btf_id = &task_storage_map_btf_id, > > + .map_owner_storage_ptr = task_storage_ptr, > > +}; > > +