Message ID | 20231114163211.GA874@redhat.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a59:b0:164:83eb:24d7 with SMTP id 25csp2045912rwb; Tue, 14 Nov 2023 08:33:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqm3iC6o3ruUXLe0DWEuIgdnqkXEJ3+bFXsO8GDgMU3m9hAmYaEV1sp0BmaXHIe1YphO5H X-Received: by 2002:a05:6a20:3a99:b0:181:bc16:48f3 with SMTP id d25-20020a056a203a9900b00181bc1648f3mr6702014pzh.59.1699979621195; Tue, 14 Nov 2023 08:33:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699979621; cv=none; d=google.com; s=arc-20160816; b=aZ90UIW9q/0mf73R3uk+IsUg4pyLTHbvwABTlj5LsnZfmbRlOZDGAub5od0RBgnMlf VAniU60LjuWQSvxYJLDQAiOaYku2IHSYL15DkpXAzAE/MYOeF7LeyR5Jkdd7GgfRspia pFJd4pK2HiAjE/MYtbGoaW55pSHoC4XayLbz4XO0P/OC9meWCDL9zvw3wJhaR0DefkWL qfyJPLnvYzD6w84Hq+gITNrKJWVp7AqI+bVxTmpHPrbu5UIjClnlLyaMUu8CGHcv4jyU 6V2Xbq0HeHXNIbOOBvvh1zOUrGcS6dKBs9brMidyhV9MHdPwG6/p0WG0FTwZH+lQaRR3 3yVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=tzfSnDUwga1tSh876/MWCFEyzy4dmGr84sjeijPXpA0=; fh=pTGUKWZxncu7pMozd936arYcX4w7ULKvTVsDVCv3mqw=; b=k0S/Y7bMiuoqy9R41wLeg6xFm0lE8WgXGFqqLZ8enYflivNBJi/5rAqU0FOWyLLZod mYEUABlDffKefAzSofu6e6paBNB1Y44354j6dU2RJdpiuZ/lI8EchsDLwI/oZXoOaSqc qWf8UC7kgB5Q3jDSXK/uUCfMrA0reJilrcETWHkASXLsR4a/4GglJhx4atCmHnhqhPGM UsaBwj4uwg0Z+BC7OGwRrDDP9ytygXYx2d6tm35z8akPyfsOMRfTX88p5mWPYY6r2xox mf22J+bDPyqo3/QAFyjB9s0sUa52B0SmX9Q8U1rZDW1lcz+QlLuBo39k80fm/rDuJ+r2 r/0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FKfK0QBW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id cg10-20020a056a00290a00b00690d695b113si8490893pfb.337.2023.11.14.08.33.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 08:33:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FKfK0QBW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 237FF802F944; Tue, 14 Nov 2023 08:33:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232297AbjKNQd2 (ORCPT <rfc822;lhua1029@gmail.com> + 29 others); Tue, 14 Nov 2023 11:33:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229822AbjKNQd1 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 14 Nov 2023 11:33:27 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 524A5AD for <linux-kernel@vger.kernel.org>; Tue, 14 Nov 2023 08:33:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699979603; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=tzfSnDUwga1tSh876/MWCFEyzy4dmGr84sjeijPXpA0=; b=FKfK0QBWtLMd32SKVFtX0lqjPqkbVISFwNkk4103Cy4OVd+Fjv4zxZe4fqmRpn/2Ddf8cu nBYTkxvXfYy1VFFTOwdDwDEl4BnUS/RX8TnAX8cE5TVeMHoIvBc/wDG36+nRaq9gONLgdG 5B38OuOAvKvtnOP54y/xN6a9K26qOSI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-X_-LwZLeNp2U6b5NRUTECQ-1; Tue, 14 Nov 2023 11:33:19 -0500 X-MC-Unique: X_-LwZLeNp2U6b5NRUTECQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E97A8185A7A8; Tue, 14 Nov 2023 16:33:18 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.225.253]) by smtp.corp.redhat.com (Postfix) with SMTP id 17A771121306; Tue, 14 Nov 2023 16:33:16 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 14 Nov 2023 17:32:14 +0100 (CET) Date: Tue, 14 Nov 2023 17:32:11 +0100 From: Oleg Nesterov <oleg@redhat.com> To: Alexei Starovoitov <ast@kernel.org>, Yonghong Song <yonghong.song@linux.dev> Cc: Chuyi Zhou <zhouchuyi@bytedance.com>, Daniel Borkmann <daniel@iogearbox.net>, Kui-Feng Lee <kuifeng@fb.com>, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 0/3] bpf: kernel/bpf/task_iter.c: don't abuse next_thread() Message-ID: <20231114163211.GA874@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 14 Nov 2023 08:33:39 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782557831259960867 X-GMAIL-MSGID: 1782557831259960867 |
Series |
bpf: kernel/bpf/task_iter.c: don't abuse next_thread()
|
|
Message
Oleg Nesterov
Nov. 14, 2023, 4:32 p.m. UTC
Compile tested. Every lockless usage of next_thread() was wrong, bpf/task_iter.c is the last user and is no exception. Oleg. --- kernel/bpf/task_iter.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-)
Comments
On 11/14/23 11:32 AM, Oleg Nesterov wrote: > Compile tested. > > Every lockless usage of next_thread() was wrong, bpf/task_iter.c is > the last user and is no exception. It would be great if you can give more information in the commit message about why the usage of next_thread() is wrong in bpf/task_iter.c. IIUC, some information is presented in : https://lore.kernel.org/all/20230824143112.GA31208@redhat.com/ Also, please add 'bpf' in the subject tag ([PATCH bpf 0/3]) to make it clear the patch should be applied to bpf tree. > > Oleg. > --- > > kernel/bpf/task_iter.c | 29 +++++++++++------------------ > 1 file changed, 11 insertions(+), 18 deletions(-) >
On 11/15, Yonghong Song wrote: > > On 11/14/23 11:32 AM, Oleg Nesterov wrote: > >Compile tested. > > > >Every lockless usage of next_thread() was wrong, bpf/task_iter.c is > >the last user and is no exception. > > It would be great if you can give more information in the commit message > about why the usage of next_thread() is wrong in bpf/task_iter.c. I tried to explain the problems in the changelogs: 1/3: task_group_seq_get_next() can return the group leader twice if it races with mt-thread exec which changes the group->leader's pid. 2/3: bpf_iter_task_next() can loop forever, "kit->pos == kit->task" can never happen if kit->pos execs. > IIUC, some information is presented in : > https://lore.kernel.org/all/20230824143112.GA31208@redhat.com/ Yes, Linus and Eric suggest to simply kill next_thread(). I am not sure, this needs another discussion. But as for bpf/task_iter.c... Even _if_ the usage was correct, this code simply doesn't need the "circular" next_thread(), NULL at the end simplifies the code. > Also, please add 'bpf' in the subject tag ([PATCH bpf 0/3]) to > make it clear the patch should be applied to bpf tree. OK, will do next time. Or should I resend this series with 'bpf' in the subject tag? Thanks, Oleg.
On 11/16/23 4:54 AM, Oleg Nesterov wrote: > On 11/15, Yonghong Song wrote: >> On 11/14/23 11:32 AM, Oleg Nesterov wrote: >>> Compile tested. >>> >>> Every lockless usage of next_thread() was wrong, bpf/task_iter.c is >>> the last user and is no exception. >> It would be great if you can give more information in the commit message >> about why the usage of next_thread() is wrong in bpf/task_iter.c. > I tried to explain the problems in the changelogs: > > 1/3: > task_group_seq_get_next() can return the group leader twice if it races > with mt-thread exec which changes the group->leader's pid. > > 2/3: > bpf_iter_task_next() can loop forever, "kit->pos == kit->task" can never > happen if kit->pos execs. > >> IIUC, some information is presented in : >> https://lore.kernel.org/all/20230824143112.GA31208@redhat.com/ > Yes, Linus and Eric suggest to simply kill next_thread(). I am not > sure, this needs another discussion. > > But as for bpf/task_iter.c... Even _if_ the usage was correct, this > code simply doesn't need the "circular" next_thread(), NULL at the > end simplifies the code. > >> Also, please add 'bpf' in the subject tag ([PATCH bpf 0/3]) to >> make it clear the patch should be applied to bpf tree. > OK, will do next time. Or should I resend this series with 'bpf' > in the subject tag? There is no need then. We can wait for maintainers who may or may not have additional requests. > > Thanks, > > Oleg. >
Hello: This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <ast@kernel.org>: On Tue, 14 Nov 2023 17:32:11 +0100 you wrote: > Compile tested. > > Every lockless usage of next_thread() was wrong, bpf/task_iter.c is > the last user and is no exception. > > Oleg. > > [...] Here is the summary with links: - [1/3] bpf: task_group_seq_get_next: use __next_thread() rather than next_thread() https://git.kernel.org/bpf/bpf-next/c/2d1618054f25 - [2/3] bpf: bpf_iter_task_next: use __next_thread() rather than next_thread() https://git.kernel.org/bpf/bpf-next/c/5a34f9dabd9a - [3/3] bpf: bpf_iter_task_next: use next_task(kit->task) rather than next_task(kit->pos) https://git.kernel.org/bpf/bpf-next/c/ac8148d957f5 You are awesome, thank you!