Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp937781imi; Thu, 21 Jul 2022 13:59:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sHq9g6kzSYH8yqc7mE7lfWYVtcOwNNdY6YqwfGMElKvTqJn0OwCSDJsX4BnzGReksZS4A8 X-Received: by 2002:a63:4601:0:b0:412:562e:7243 with SMTP id t1-20020a634601000000b00412562e7243mr230694pga.358.1658437163054; Thu, 21 Jul 2022 13:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658437163; cv=none; d=google.com; s=arc-20160816; b=HWErWRE8QmYaaalLkzEvbctjUKVKjYWXZt6lzd8PR33hH7xNPlysp8JM5ob7eIiNGw sps+RJFUrKi/h68+onlDZTKU0qCsDjXZWtpwYqEzExHV68gd4IDduc2JTzPaGZ9REXkE eHbjFuRUSkA5H35GynkUilmeyVZ4vxfC42y9J5gHOLDjjxTSl06pgTFCL+KJqqL2N6zf OBJc27tMjdXs4PMnRXLIC6n4JzJAAYSoinaPedH762JfL9ebY0Cp37Cz9oID4n0N53Dt wBpj8e2Y7XW5VtIMGEmcgXVcqJiI+cERN+hNGHwCkIk557+Kpi6oG8Ej6SFcITxeFyg4 19yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=KqyIsQrmN7sf+sZ8UdYfrGfrh1GwRz0KjgsGF+7DreQ=; b=vMnDnaBxC4PduKc0aW6FHkMP5oN8kOnV18IBtqvklFEe4O2sDeJWnDH2wiN2j1m1fo C8kzDocBNult2VXYsQi92eEDth7SbT/pG3AyxoA61I/YFEvBGFCGD6DrKnu+/VhzBeu9 t5F5Dt1n6eTKRyYS5trYVB2QtDyApsMFyoIcICA/6l94Dam0Jeil3TELNj2pKrFVl+j9 J2ABeM0bD7ZBmNSsmlTD4XxLdyiozR8R0yszgaAMMfvALjXPaZVOLgHZ3sn++McqYMWz RWRC6RjC2mquT5bHJQiP+Yj6R9Nyrjoiq8LBzSZqHIrZJVPBjsFqUIjp2wkZdLiQPZbm 3wxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=V99tJWDc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v3-20020a056a00148300b0051080c93279si4020997pfu.129.2022.07.21.13.59.07; Thu, 21 Jul 2022 13:59:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=V99tJWDc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233367AbiGUU6Z (ORCPT + 99 others); Thu, 21 Jul 2022 16:58:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233072AbiGUU6U (ORCPT ); Thu, 21 Jul 2022 16:58:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ACB3904F0; Thu, 21 Jul 2022 13:58:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DF54EB82680; Thu, 21 Jul 2022 20:58:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42E5AC3411E; Thu, 21 Jul 2022 20:58:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658437087; bh=TJy6oV2ClpHeP1ehFHQPSiyhoWHgHghft6FoozMWqQg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=V99tJWDcRv1RzXemv+3Vfvjgenyc7nS3ZG+WWdTqQDeQNbj6aXRLWYgpTiwz0Z2Th oXRgO11iP5ibVAECA3ZgfhEHCq2HDspzoJ3U0iGzaqavJCbD4Q60MJdC1X18MnBZzS LOw5oU4GcZoQlSYQXNAAW+ygYc9HKz13l7nRwIuBRf7pFCeaYQLEFDjKNGmWCQ4HlK zHwlMEB9zCY18bn6/gm2Fw4HW368+3Uwfluz520FeEWc1RTezjHCNu1YGM33TUUXqS xiMPotDdrO/nwkkeMyi6bFKI42F7bsr1Ukft7ausiyE02yso2TPYxVRl1ZyJWexIp2 1oFymV61XI/sA== Date: Thu, 21 Jul 2022 21:58:00 +0100 From: Lee Jones To: Yonghong Song Cc: Jiri Olsa , linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , KP Singh , Stanislav Fomichev , Hao Luo , bpf@vger.kernel.org Subject: Re: [PATCH 1/1] bpf: Drop unprotected find_vpid() in favour of find_get_pid() Message-ID: References: <20220721111430.416305-1-lee@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 21 Jul 2022, Yonghong Song wrote: > > > On 7/21/22 5:14 AM, Jiri Olsa wrote: > > On Thu, Jul 21, 2022 at 12:59:09PM +0100, Lee Jones wrote: > > > On Thu, 21 Jul 2022, Jiri Olsa wrote: > > > > > > > On Thu, Jul 21, 2022 at 12:14:30PM +0100, Lee Jones wrote: > > > > > The documentation for find_pid() clearly states: > > > > typo find_vpid > > > > > > > > > > > > "Must be called with the tasklist_lock or rcu_read_lock() held." > > > > > > > > > > Presently we do neither. > > > > just curious, did you see crash related to this or you just spot that > > > > > > > > > > > > In an ideal world we would wrap the in-lined call to find_vpid() along > > > > > with get_pid_task() in the suggested rcu_read_lock() and have done. > > > > > However, looking at get_pid_task()'s internals, it already does that > > > > > independently, so this would lead to deadlock. > > > > > > > > hm, we can have nested rcu_read_lock calls, right? > > > > > > I assumed not, but that might be an oversight on my part. > > From kernel documentation, nested rcu_read_lock is allowed. > https://www.kernel.org/doc/Documentation/RCU/Design/Requirements/Requirements.html > > RCU's grace-period guarantee allows updaters to wait for the completion of > all pre-existing RCU read-side critical sections. An RCU read-side critical > section begins with the marker rcu_read_lock() and ends with the marker > rcu_read_unlock(). These markers may be nested, and RCU treats a nested set > as one big RCU read-side critical section. Production-quality > implementations of rcu_read_lock() and rcu_read_unlock() are extremely > lightweight, and in fact have exactly zero overhead in Linux kernels built > for production use with CONFIG_PREEMPT=n. > > > > > > > Would that be your preference? > > > > seems simpler than calling get/put for ppid > > The current implementation seems okay since we can hide > rcu_read_lock() inside find_get_pid(). We can also avoid > nested rcu_read_lock(), which is although allowed but > not pretty. Right, this was my thinking. Happy to go with whatever you guys decide though. Make the call and I'll rework, or not. -- Lee Jones [李琼斯]