Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp560582qtg; Fri, 31 Mar 2023 10:16:46 -0700 (PDT) X-Google-Smtp-Source: AKy350YKP26/gnvAd1ASC0a5WKNybT+cMm8HsxXgLy1gBSoWS6qOvFJOi9GWz0Ja+Ugvd/Tr7o/n X-Received: by 2002:a17:902:ecc2:b0:19a:7060:948 with SMTP id a2-20020a170902ecc200b0019a70600948mr7118144plh.1.1680283006620; Fri, 31 Mar 2023 10:16:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680283006; cv=none; d=google.com; s=arc-20160816; b=WPkj1nxeCYAFSTHcYQRKeYYXjr2lK2Vwe48jBIdEKw9W8iYXU0MeE+7xe+u1IpCgXy t9oSsfg1hR/WP3iZdnZGaRJLNN8B4xJuzcBlyXD/m7cNOwFRRsbV9a49w6mRNdll3+Kk Nz1mVO1TYCo3SsEXW/xyDm6ZpqH4MNRPJrXgnptQ/L1RHoVJPTmPcDC1Ro785JWpOBzd YJ6DVaS0K7dW/yLghVKcwBDBYcK8YexiPistaZUqDDOxGZHpObSkQhJ9MHkLMb2wq1sv h9iAC4s8mZtXGtI9jipoVFR2fw91zVL1XzRQH9yZ9QB0ndEOqF5EozaIN4FAtGiq7FCd kMBQ== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XKD3afd/dAGXfiCR1cGKCTKOhGubTZfFsF8fCBghIoQ=; b=aJ0TZKUxeQKwlNEQkxE9/RJM1d29AM/5b9kKLBOeeS/BcQoybcUAxlfoiFrNPYwfVu ou2HDRktUSbTbVvm9WXoi/yAgaVwpy5qjiGtVCbjymNwS9FwZPAqBZF1j05UnoUGl8mY h8CUarwXlQY0/A06ZOGxJ/OXhbr/5RjSdWPPxd27A5WI2I5NiRK9VtLFkr0xC0H8o92H SXOX39krBvbVM2FKSY18C7HVikTCdE/ZwRWrjL1mD9t1j0r/xLClrfO/r2YWImzY1BpX SLEy7UsKzAOP6ePK3+rLbwwaqj23vy3XlkT8gxV8b7TlC5IIPNMyc4mWQnBIwWzrenCe bhBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WkH4rDy+; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b14-20020a170902b60e00b001a216fddcfesi2418684pls.644.2023.03.31.10.16.35; Fri, 31 Mar 2023 10:16:46 -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=@gmail.com header.s=20210112 header.b=WkH4rDy+; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232031AbjCaRFj (ORCPT + 99 others); Fri, 31 Mar 2023 13:05:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbjCaRFK (ORCPT ); Fri, 31 Mar 2023 13:05:10 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D61CCE38A; Fri, 31 Mar 2023 10:05:08 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id q102so21069417pjq.3; Fri, 31 Mar 2023 10:05:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680282308; x=1682874308; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=XKD3afd/dAGXfiCR1cGKCTKOhGubTZfFsF8fCBghIoQ=; b=WkH4rDy+elmsZkRjR7g8zey1NIy7ZCJWDApx9dSlPTYVKX+mTOvVxAWYj/tcyPKtkH IbpPGB1UrPPXg8elixNNZ3W68PDdqrPhH86l+75XXbb88tJPCGLCodgUQO+gyTsvyw9l RzVKG2YPiJjbmQKfKqlCzoMkQdGsZ1bU1Es15hV9iwk0lo+TGfwi4DKnlUpm5SNKlzlf m2bS7cep6+VESbbcPae5fid0UY1yWo9uL9mPLYGPUgokKHnOEClDTYDQTdJy5JYc7jza DcqPqLPa7o/D7nQFKRZuECQNF5syZ6btfe7AchWdWTkmvXeSJdF2iQcC0Kkeyj4fYrL2 F5AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680282308; x=1682874308; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=XKD3afd/dAGXfiCR1cGKCTKOhGubTZfFsF8fCBghIoQ=; b=g7IIVw5mpZul53Zs3hdJ3thmimGNpX0RXR4W1LrDgxryey3fjapL4cMmaE0sIt84H1 x6cejBvmUUCHnj/OsTk8fkR+13sLsQBY3TeI3M9fM97OHp20X11vS7eDLC1snS+XpKs5 RvbhqhwOclPQUX0ZKTjqlMCgGcw9qSZ8BGgPOx+B3YORPa3r9n/tyXex0AAz0QkRvk52 cWK+oZH8HX199tAycKWgU4P+2Wde9gDY80GQfy9L8lF19Qa2HrPzlC1P/YUMBWWR9mfA jeRVjWTRuvkH+yHK+p1VrJY0hUW2enuzzE+AG8XoquS7ZXZJIkqUtW+MuoXgznDxzv7h gJCg== X-Gm-Message-State: AAQBX9diWXL8QczGeBswpzKpUt+2S1eyqutXyF8cwAp3ixnzMlZcGj/t rUpgn6eLDWmrt9EzWzBinKY= X-Received: by 2002:a17:903:22cd:b0:1a1:bcf:db5f with SMTP id y13-20020a17090322cd00b001a10bcfdb5fmr36504598plg.25.1680282308139; Fri, 31 Mar 2023 10:05:08 -0700 (PDT) Received: from dhcp-172-26-102-232.dhcp.thefacebook.com ([2620:10d:c090:400::5:3c8]) by smtp.gmail.com with ESMTPSA id jw18-20020a170903279200b0019e88d9bed3sm1798093plb.210.2023.03.31.10.05.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 10:05:07 -0700 (PDT) Date: Fri, 31 Mar 2023 10:05:04 -0700 From: Alexei Starovoitov To: David Vernet Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: Re: [PATCH bpf-next 1/3] bpf: Make struct task_struct an RCU-safe type Message-ID: <20230331170504.umr5zmcraburmtkg@dhcp-172-26-102-232.dhcp.thefacebook.com> References: <20230331005733.406202-1-void@manifault.com> <20230331005733.406202-2-void@manifault.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230331005733.406202-2-void@manifault.com> X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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, Mar 30, 2023 at 07:57:31PM -0500, David Vernet wrote: > kernel/bpf/helpers.c | 11 ++- > kernel/bpf/verifier.c | 1 + > .../selftests/bpf/prog_tests/task_kfunc.c | 2 + > .../selftests/bpf/progs/task_kfunc_common.h | 5 + > .../selftests/bpf/progs/task_kfunc_failure.c | 98 +++++++++++++++++-- > .../selftests/bpf/progs/task_kfunc_success.c | 52 +++++++++- > 6 files changed, 153 insertions(+), 16 deletions(-) See CI failures on gcc compiled kernel: https://github.com/kernel-patches/bpf/actions/runs/4570493668/jobs/8068004031 > __bpf_kfunc struct task_struct *bpf_task_acquire(struct task_struct *p) > { > - return get_task_struct(p); > + if (refcount_inc_not_zero(&p->rcu_users)) > + return p; > + return NULL; > } I wonder whether we should add a bit of safety net here. Like do not allow acquire of tasks with PF_KTHREAD | PF_EXITING or at least is_idle_task ?