From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFF22C433E5 for ; Thu, 25 Mar 2021 16:44:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B4C3B61A16 for ; Thu, 25 Mar 2021 16:44:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229934AbhCYQoM (ORCPT ); Thu, 25 Mar 2021 12:44:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbhCYQnv (ORCPT ); Thu, 25 Mar 2021 12:43:51 -0400 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5310C06175F for ; Thu, 25 Mar 2021 09:43:50 -0700 (PDT) Received: by mail-il1-x12a.google.com with SMTP id u10so2724350ilb.0 for ; Thu, 25 Mar 2021 09:43:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3dp61o6F3hqxMbMpN9J8E9x3tY2eyW4PS/mGGFHMbvA=; b=dL5jZOqPFrSb9Oj9FLfuY4FAbj8v8dXvuyG1H2e2jy3Epf4WMDngkcwDf/GDjlEqeq BrT84yl0cCzQQtqcUYiiHF2mqWSmtBlESC8TaZVNXe9NVGAmtX1BUNN34UteLmwJjpxd oP7QA1j9pguI2UI7+D2a2TlQdw6w4W5mtttT6msMI18lLSMJ2sIn82ljFY2WUl1gXofE frs1SpctbE0XjMIttEzkYHfXcAe3TP/TAWqtkuzcSHv5xqisOJrHMqxapB68t+Wa2dmS CiO/0mZRvRqi1VPXqAVC9QQC3KDZfK2HJFAadvP1QHURIKQzUFV1koVsYPBLFHSmAZLo xjtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3dp61o6F3hqxMbMpN9J8E9x3tY2eyW4PS/mGGFHMbvA=; b=YB6jHc0PmS/jUYC5mgfFrL7ZybabNpjtJkOsFntzM9ACZV9ZOD8JRLm8x1A6PIENn1 RCTB3xcvZCqmTUTLcCj4Zt6Nz6KXwauGPcwluwolfm1Q53ti7muzrpZLzX0mOw7OUPL0 PZpHIBq5y2mfS2NXcdq2xQeJVqRv37gMZ64glQntim1qqmgVx0LzzYQserlrXFwIXQls ROnhce6qUY8ehMfIw0hVL07JgNda8wNbftjk6dGQYj1E8zXExcpryp8+5KHIGOKfhVO6 +i7pQAqAaPkHNFgn6OyD0x4gLecVxR+kw/Im9nejZeWKlbLEAwEIYbAM+eAqvRauaFRM kpcg== X-Gm-Message-State: AOAM5325aumUtA/4MEeB+099PSqcbZiaiKhN2SFbuqM6DqwXdQ27DWwg CX70Bsc1er3J7Vfe5I0HmMQ4Tw== X-Google-Smtp-Source: ABdhPJxwxYjP5S4lA8SJOW+4pNwM6kgk9NMYjp4EfBYFflCceicfN5WxY49qjwu9LCrK/G/hMq9KVQ== X-Received: by 2002:a05:6e02:1b86:: with SMTP id h6mr7051197ili.145.1616690629868; Thu, 25 Mar 2021 09:43:49 -0700 (PDT) Received: from p1.localdomain ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id k12sm2990605ios.2.2021.03.25.09.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 09:43:49 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: torvalds@linux-foundation.org, ebiederm@xmission.com, linux-kernel@vger.kernel.org, oleg@redhat.com, metze@samba.org, Jens Axboe Subject: [PATCH 2/2] proc: don't show PF_IO_WORKER threads as threads in /proc//task/ Date: Thu, 25 Mar 2021 10:43:43 -0600 Message-Id: <20210325164343.807498-3-axboe@kernel.dk> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210325164343.807498-1-axboe@kernel.dk> References: <20210325164343.807498-1-axboe@kernel.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We don't allow SIGSTOP and ptrace attach to these threads, and that confuses applications like gdb that assume they can attach to any thread listed in /proc//task/. gdb then enters an infinite loop of retrying attach, even though it fails with the same error (-EPERM) every time. Skip over PF_IO_WORKER threads in the proc task setup. We can't just terminate the when we find a PF_IO_WORKER thread, as there's no real ordering here. It's perfectly feasible to have the first thread be an IO worker, and then a real thread after that. Hence just implement the skip. Reported-by: Stefan Metzmacher Signed-off-by: Jens Axboe --- fs/proc/base.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 3851bfcdba56..abff2fe10bfa 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -3723,7 +3723,7 @@ static struct task_struct *first_tid(struct pid *pid, int tid, loff_t f_pos, */ pos = task = task->group_leader; do { - if (!nr--) + if (same_thread_group(task, pos) && !nr--) goto found; } while_each_thread(task, pos); fail: @@ -3744,16 +3744,22 @@ static struct task_struct *first_tid(struct pid *pid, int tid, loff_t f_pos, */ static struct task_struct *next_tid(struct task_struct *start) { - struct task_struct *pos = NULL; + struct task_struct *tmp, *pos = NULL; + rcu_read_lock(); - if (pid_alive(start)) { - pos = next_thread(start); - if (thread_group_leader(pos)) - pos = NULL; - else - get_task_struct(pos); + if (!pid_alive(start)) + goto no_thread; + list_for_each_entry_rcu(tmp, &start->thread_group, thread_group) { + if (!thread_group_leader(tmp) && same_thread_group(start, tmp)) { + get_task_struct(tmp); + pos = tmp; + break; + } } +no_thread: rcu_read_unlock(); + if (!pos) + return NULL; put_task_struct(start); return pos; } -- 2.31.0