Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3469032pxb; Sun, 31 Jan 2021 17:24:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+VI/GivSFNQAv3pOb7jawQA55cZjio7Coxp230uw82lspX80UBILeq9BBGRxQ8UrgSwuc X-Received: by 2002:a17:906:fc5:: with SMTP id c5mr14822541ejk.538.1612142643937; Sun, 31 Jan 2021 17:24:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612142643; cv=none; d=google.com; s=arc-20160816; b=CSLXvzRTyMIvP6SkUxVXfQ0N76ZnZZYj2LqlgXQ4h6mcZRmBs+t81XZXp2wfLYqqru DhFAez+FW3mUm9ycGgudLAyN6IfnDpfwqQmedlEw7rXgh3zGcwtT3DghEJYCBsFviU9N +mqHoskUk1DRqz8wi7Iv6ObPdig2j3uOMTcljl0GdAyqK06/fUKxYWX3kgdUFg1Prp/g Q6z/2yx9PhivKSXkxgCmKy56phmtuxFXDP32jbmPO/1Y8arCN3kEsmPRuzlwD1E/RruN 8l5B6uoGKDA6Ue1iu8bXW7FSAV5q7ttq8EcsGAyre+0BxF0IxtGp6WaM6On9PXKc2A1n BuBQ== 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=VgSqX9LBDtKCJRh9zGBpirVAb26bY47tY4Q55rxSQEs=; b=PBdEZ3HFI9oGV/iUk0rBjTkwzv4lnb68Mf1V71CT/6qIu0tEOtEhfZD17LD+fXtt+c anTSmJBtaEFOYIG8ki0sfjFu9T3oJ3liiiIi7S9m+XPcZsiSs9wzGCB81PU05CEnGBli 0M8Y7nFJnSQlv93SvEQlj0toW+PTDMH53QJK2gioSDeg0namRFmBKkRrXDYl38DsdkEi m2jXPLCfX4B9KzdVTEPgPZDTtSCOaoQAKCEDo3XRG+3LJPLnfRbfCA9utcIT6tVrxfKE mL/UzgSvDZblhqdPIg9ZATH/WyOtNydIdT6q2WwixuoQj0rR36PagbXwDprbTdy4lGVu YWTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="SGW8/jrq"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s20si9600733eji.61.2021.01.31.17.23.39; Sun, 31 Jan 2021 17:24:03 -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=@kernel.org header.s=k20201202 header.b="SGW8/jrq"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231216AbhBABWg (ORCPT + 99 others); Sun, 31 Jan 2021 20:22:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:56076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231180AbhBABVj (ORCPT ); Sun, 31 Jan 2021 20:21:39 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B4A9C64E2A for ; Mon, 1 Feb 2021 01:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612142459; bh=3B5tXgdUKMP/kU2hx0a2j+XEtprdSI4NTqN/tYMvOAQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=SGW8/jrqCBICdzyH3qwyuJ21Blyali2BK6NksL70kbxDs+h6+09P8sp4BIvZFO9yl yf1utoJewpfcfNXLicNTmcYi72zLkULNiZzP6XOi3K3OXDZqkE+1On/PeyF/p0puap JFypejveDUDyHz3nUGKbhnBULvWnsXF78WSQmLOECjJuknpZlNjkmZJ/kCjnPgw7wx RCo+VwJ3sG9Eniwi+fuxMPci4U1q5qFi7HM8/huwbPiJ2/JJxa+hVCga10/RiQy5z7 eHGnEplUArA8IlvmaCHeE1CLQd3vIsLcpQXlmkorgwg6tiN4X/xCi3HpcV4qsseFp6 VoPq12coHLF6Q== Received: by mail-lj1-f175.google.com with SMTP id v15so14522910ljk.13 for ; Sun, 31 Jan 2021 17:20:58 -0800 (PST) X-Gm-Message-State: AOAM533VB4k8Jqo5Pa+1811FP2z9pAkNZr3mJlPKmxHUkRyPeyjUiDej 7NiRh8XnBIg2t9H6VuwhPUXaMRWxaewJY5MD4dhRAA== X-Received: by 2002:a2e:2c11:: with SMTP id s17mr8472300ljs.468.1612142456959; Sun, 31 Jan 2021 17:20:56 -0800 (PST) MIME-Version: 1.0 References: <20210128001948.1637901-1-songliubraving@fb.com> <20210128001948.1637901-2-songliubraving@fb.com> In-Reply-To: <20210128001948.1637901-2-songliubraving@fb.com> From: KP Singh Date: Mon, 1 Feb 2021 02:20:46 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 bpf-next 1/4] bpf: enable task local storage for tracing programs To: Song Liu Cc: bpf , Networking , open list , mingo@redhat.com, Peter Zijlstra , Daniel Borkmann , Kernel Team Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 28, 2021 at 1:20 AM Song Liu wrote: > > To access per-task data, BPF programs usually creates a hash table with > pid as the key. This is not ideal because: > 1. The user need to estimate the proper size of the hash table, which may > be inaccurate; > 2. Big hash tables are slow; > 3. To clean up the data properly during task terminations, the user need > to write extra logic. > > Task local storage overcomes these issues and offers a better option for > these per-task data. Task local storage is only available to BPF_LSM. Now > enable it for tracing programs. > > Unlike LSM progreams, tracing programs can be called in IRQ contexts. nit: typo *programs > Helpers that accesses task local storage are updated to use nit: Helpers that access.. > raw_spin_lock_irqsave() instead of raw_spin_lock_bh(). > > Tracing programs can attach to functions on the task free path, e.g. > exit_creds(). To avoid allocating task local storage after > bpf_task_storage_free(). bpf_task_storage_get() is updated to not allocate > new storage when the task is not refcounted (task->usage == 0). > > Signed-off-by: Song Liu Acked-by: KP Singh Thanks for adding better commit descriptions :) I think checking the usage before adding storage should work for the task exit path (I could not think of cases where it would break). Would also be nice to check with Martin and Hao about this.