Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp4486rdf; Mon, 20 Nov 2023 14:16:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCNA5Y7hFmUptEV17/KTJ6FpYAxI92dvKk/2xqtp8dJANnhguT10DNzSN/a0jQfUlUlRZD X-Received: by 2002:a05:6a00:2b1:b0:6c4:d78d:498e with SMTP id q17-20020a056a0002b100b006c4d78d498emr1026450pfs.2.1700518565759; Mon, 20 Nov 2023 14:16:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700518565; cv=none; d=google.com; s=arc-20160816; b=J9WZdot1lUeGt4lCRkmfqOsMDuZvAHyLDARZ5GLLCn3H8cqjLm2Yhg3Z+jz4UlmQT0 KwGExPRsQ5bOMTpmU/3VxrsobbBJv7w8sjfyc2ZL82dLQkbN0maYXENSrVs+YrPNa1uE eMVUqp7CgALldxYTuALWd2rwANk7pdN4tf+dKyUAQ/h89ssLxHbQT4Uq/qS3TNp4+WJW r0zkya71cF+m/25v3chJT2hiSL8XXd+icgaOwPC/mGEIx6PspRktqo2PqGba8fvdBqbN cVTQXyxwnlgw+dPugG77Gw42BjE9b5lDBDHi6IAZvVGQw3wo0uxHrdpbAD7f22hB8SJH G4hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=eAV0U0mLkg/3ylSYaE6a69rqhR2UGGa2kQaKBkZ2jZw=; fh=UdWFGGZ51KzJKl7sbSV0z922PmQGXv0rGb+M/N9tAPc=; b=LsifmeFgF72/ZiGrvk9Cz5yrvfi1dDR7QBN8xjNQjkIx2gJ76DnHG54dR8VyUVy2fb tZIbf6ueblEZ5YJwuRQ3yWtu+B1WKcT5gImZ0DiMfECWx2d9A7Yqn9TKesK4IfGIrBM5 oAIKBrrIamk3J9rXiy5vu8E7d0KlH+NX1Zlj4rVhZPyuJvvwahbyaJ05+e4gPwvUUFxW Q+VLOMfK7CM3z+XfE4h0szU7z7/qq2s97Zdjz/n41OprFdnxkF7697Uo9ON7FVf9dm37 2s6k1ddrvdGQR42FsdE0TJmNT4sp3y+zbQeM/qOUJmXddHImIC/efch8qLoDsh/WTD7P rIJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=EVUmn3+M; 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=linux.dev Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id v71-20020a63894a000000b0057745d87b53si8973046pgd.686.2023.11.20.14.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 14:16:05 -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=@linux.dev header.s=key1 header.b=EVUmn3+M; 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=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 1520A807385B; Mon, 20 Nov 2023 14:15:33 -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 S232300AbjKTWPT (ORCPT + 99 others); Mon, 20 Nov 2023 17:15:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbjKTWPS (ORCPT ); Mon, 20 Nov 2023 17:15:18 -0500 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E00AC95 for ; Mon, 20 Nov 2023 14:15:13 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1700518511; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=eAV0U0mLkg/3ylSYaE6a69rqhR2UGGa2kQaKBkZ2jZw=; b=EVUmn3+MsuT4bi/Wnd+U6PyJ/buLTs5xg27GpRI8RlF4u0lOjFHvYFFgroHRxc0r3Qvt8W niMi6XLGqm13R3htx0KcdBz7hI0yDDqvtwP0zarbV6ChcOfCmbCPVi2puncsOLJ7natqDA uMQPuUX54rTQgKxu9oeU/1UwaA38u9w= From: Kent Overstreet To: linux-kernel@vger.kernel.org Cc: Kent Overstreet , Nicholas Piggin , Mike Christie , Zqiang , Petr Mladek Subject: [PATCH] kthread: kthread_should_stop() checks if we're a kthread Date: Mon, 20 Nov 2023 17:15:03 -0500 Message-ID: <20231120221503.3378095-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=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: 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]); Mon, 20 Nov 2023 14:15:34 -0800 (PST) bcachefs has a fair amount of code that may or may not be running from a kthread (it may instead be called by a userspace ioctl); having kthread_should_stop() check if we're a kthread enables a fair bit of cleanup and makes it safer to use. Cc: Nicholas Piggin Cc: Mike Christie Cc: Zqiang Cc: Petr Mladek Signed-off-by: Kent Overstreet --- kernel/kthread.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/kthread.c b/kernel/kthread.c index 1eea53050bab..fe6090ddf414 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -155,7 +155,8 @@ void free_kthread_struct(struct task_struct *k) */ bool kthread_should_stop(void) { - return test_bit(KTHREAD_SHOULD_STOP, &to_kthread(current)->flags); + return (current->flags & PF_KTHREAD) && + test_bit(KTHREAD_SHOULD_STOP, &to_kthread(current)->flags); } EXPORT_SYMBOL(kthread_should_stop); -- 2.42.0