Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp559597pxb; Tue, 3 Nov 2020 06:48:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzE4cXe7pjH93owVVxt5N1B7ViVrh/c+n5SK8CO9uddCf3atu5wOT7/frNO8IdO7cMdtCc X-Received: by 2002:a05:6402:495:: with SMTP id k21mr22387327edv.232.1604414919199; Tue, 03 Nov 2020 06:48:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604414919; cv=none; d=google.com; s=arc-20160816; b=PQRMymbouMqNfarM2k67FZAxHMQPGNSD4TRTPUtNht/8k4zXsrNZ4AlPznaEKuhcFr 6yAHvzYfOUYsdx/n5t9ldDFly/nTxb86UMIrvIKiHvvdTsGG1RqQzy3cfpyP8L11sXuL bfQ5jV4ro9BASvH1fbWqaooiMvEt+c8lKFijkXIKLniN6TPRkSb/WA9LiOHMbyL5EWpN vF3O2pgAtubnJvNoLfUfVY4ysivPtZFNKm3LbW/Ak4b9rAnG6/AG3Re7hYM+Q4zvSU5b kezY/i6NEpI1MPn7uhsOKp0YBLfsko0ETvSj1JXe6yPSWxYqFXLa0hxyFT80FJDQhQRp 3+IA== 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=Pp8uAn32f3t2FIuwzoaa3d8s2O0PQKKs2nYF0Ij9oV0=; b=HTF7qm0Jneknr/YfwYv5NdaFIt/67Fhv3ASVflq1im6/z8718WhF2fWCjHWkLG4EAh LldtAW2QF3cRAxNl2fOH7TUrQp7vlI5xLqtLDcNFtxSaKk0dxQs0X5Pf1UQDK9Q731WP Kezr2cnuutYereEr/0ZeYvaZuGBtj81F+ZNaKidD77yuvliZ25Ro9iN9EZIEzYDh8IjP BiCSK5/dXEHK//JZUVVu0OkMX/KGtjNZbRTTD2GDOYwyeJuWIdOR7TqIesZ6BVSczWUu wXCo4WJnmpBwXY8ep22Hel0Eq+VNVPBBF6xtLsG8tZHB2knqSLj3/zS0sqGvXRM2mlyg GLZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Lp8sR9nP; 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 b10si3294387ejv.433.2020.11.03.06.48.16; Tue, 03 Nov 2020 06:48:39 -0800 (PST) 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=Lp8sR9nP; 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 S1728228AbgKCOqz (ORCPT + 99 others); Tue, 3 Nov 2020 09:46:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728169AbgKCOqq (ORCPT ); Tue, 3 Nov 2020 09:46:46 -0500 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87AD6C0613D1 for ; Tue, 3 Nov 2020 06:46:46 -0800 (PST) Received: by mail-lj1-x241.google.com with SMTP id m16so19330093ljo.6 for ; Tue, 03 Nov 2020 06:46:46 -0800 (PST) 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=Pp8uAn32f3t2FIuwzoaa3d8s2O0PQKKs2nYF0Ij9oV0=; b=Lp8sR9nPKnAG2KgrCOLy/YNC01bsS2U/CefENaisdUaUl3RHmmqXuECaKfQC6Rt1As 35jHUVFOoIO5YGknLJg2/sB51Cidar0vALts1XYOf54MtMKdpvSbtwmvAAsPRUIs40CD gxHo3IGflEu+oIrpqzJ9f4iIISKkCT/PonEt0= 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=Pp8uAn32f3t2FIuwzoaa3d8s2O0PQKKs2nYF0Ij9oV0=; b=SWL4gLRQXcsO5KhIZLaPNiuFOwXbofauuUwc2SfBdOq8Ikp+miv4tZQwKmH3F4nh4a wD7lqYI9Ih9CMc0+d1R/Sq4WbYj36V4pP97GKNB/FJm0+dd91gzozUkwGpaOixtMeqx2 cTGLB+jHIOWN+h/wOJOLe2EPKZ6y8du96P6FSSWKBNDBD+rkzdoPKSNpx0w40oW0EIWE x/Qldp6C7QBcbtEfSyiPAScQT4d97aSDUGK5f3npvNCOwu15BY54xJsq6FTOIDmyczUd Ju3sBJ4C21LP1x/+4HYXoadaBcpgYOIY/Y1HIbYAZwuLPI+TPWxF1EOBR76Bx4H0y28X HJLA== X-Gm-Message-State: AOAM533GEcBoYZS5eY+y9jotM0RUCnODFLDUnkXfeAO9pWk6EJuLlffZ OY1cW3Hcj9e6k1/ujAklWw9Dnh+WW1KZJnCL3Otiiw== X-Received: by 2002:a2e:984e:: with SMTP id e14mr305831ljj.110.1604414804910; Tue, 03 Nov 2020 06:46:44 -0800 (PST) MIME-Version: 1.0 References: <20201027170317.2011119-1-kpsingh@chromium.org> <20201027170317.2011119-2-kpsingh@chromium.org> <20201028011321.4yu62347lfzisxwy@kafai-mbp> In-Reply-To: From: KP Singh Date: Tue, 3 Nov 2020 15:46:34 +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 On Fri, Oct 30, 2020 at 11:53 AM KP Singh wrote: > > 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(). I refactored this to use pidfd_get_pid and it seems like we can simply call pid_task since we are already in an RCU read side critical section. And to be pedantic, I added a WARN_ON_ONCE(!rcu_read_lock_held()); (although this is not required as lockdep should pretty much handle it by default) - KP > > > > > > + 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 :) I also added another patch to exercise them for the other storage types too. - KP > > > > > > + .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, > > > +}; > > > +