Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp606934pxp; Wed, 9 Mar 2022 09:01:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrwqfPs3KWAxJUVaBBdjwo3FCi0MtJOJ2DgdHWXin/GUWf9xwuIqFJcnqw2HwRTa54jVY5 X-Received: by 2002:a17:907:2da1:b0:6da:8e01:8313 with SMTP id gt33-20020a1709072da100b006da8e018313mr693418ejc.32.1646845280282; Wed, 09 Mar 2022 09:01:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646845280; cv=none; d=google.com; s=arc-20160816; b=o6XHuwirvcpLhPr3V5fYvIdLV5UZOxQ4E3s5a2vGXlK5jdXsR6zqI99t5rJ6OOesXs JhnymHa8/TscbAOclT4PiLE0KftvrQB/Gc/Kpg3xBOb7nNXtMVsN2QmdbtjMJTyG7NlA gZdYJ75aMd3CIUZV8BO7ztbzJppvnVPQvSpH5a3W9o96plFryuKJz6LIBZ2V5svHPILB HAjhLNnWW5auy49FUDO2qzAVC8hh8lcLPTATuEa+O4MhmKjF6XuoblljEjZgoFSubTim i3hQWOvVgU3kS+anaMGxcC5LAAVbjHVB/2cjrcgugVoaJSDdAwwioo9BYfDU1MAEi69E ESlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from; bh=uNZLNafg3h3tQeB0XtOSlgC8aWjfFJwxNaCrZvs/CbM=; b=TxWqqYyvju4IO1dS+pWegVS5r5+WdlVBQ4ncjFfcWllQ24fEB7Kczz4il+VXvc2IJx AiCIqwLlSYOKkv5nraiAe7kteLQnOCaAdHxcyN+4f8LzOG9vSTSsDGC85NlwVNWgOmC+ czg6SMKwtk03GWAfk2XP/Ya0O6UbxZ21r6NTi6Rik2M7w+WZuDg8zWrWIRS3OUQuSZIg jzKrF8YKboJdkZlTzB/ayiPHi00qxwDNoIcejD7XumNxXycv0hyDrXIckKtJvH4RsfrY nEvJwtiTuJ9lTGM/8Xj99vq6q3WvEN1TT2Iyxzg3eKXLSOXO7+7YztWKFE23pC696Xas /VVg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y9-20020a056402358900b004169073c60asi1646242edc.190.2022.03.09.09.00.46; Wed, 09 Mar 2022 09:01:20 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230378AbiCIQpQ (ORCPT + 99 others); Wed, 9 Mar 2022 11:45:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238445AbiCIQb1 (ORCPT ); Wed, 9 Mar 2022 11:31:27 -0500 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ABAD190C17 for ; Wed, 9 Mar 2022 08:25:49 -0800 (PST) Received: from in02.mta.xmission.com ([166.70.13.52]:35780) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nRz89-00CNAK-HE; Wed, 09 Mar 2022 09:25:41 -0700 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:34572 helo=localhost.localdomain) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nRz86-005hAS-5s; Wed, 09 Mar 2022 09:25:41 -0700 From: "Eric W. Biederman" To: linux-kernel@vger.kernel.org Cc: Linus Torvalds , Alexey Gladkov , Kyle Huey , Oleg Nesterov , Kees Cook , Al Viro , Jens Axboe , "Eric W. Biederman" Date: Wed, 9 Mar 2022 10:24:48 -0600 Message-Id: <20220309162454.123006-7-ebiederm@xmission.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <87o82gdlu9.fsf_-_@email.froward.int.ebiederm.org> References: <87o82gdlu9.fsf_-_@email.froward.int.ebiederm.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-XM-SPF: eid=1nRz86-005hAS-5s;;;mid=<20220309162454.123006-7-ebiederm@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18pJwd2lf+RP9kvKgOhhWVsNfjktPzgMEY= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;linux-kernel@vger.kernel.org X-Spam-Relay-Country: X-Spam-Timing: total 2238 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 11 (0.5%), b_tie_ro: 9 (0.4%), parse: 0.94 (0.0%), extract_message_metadata: 12 (0.5%), get_uri_detail_list: 1.98 (0.1%), tests_pri_-1000: 13 (0.6%), tests_pri_-950: 1.24 (0.1%), tests_pri_-900: 1.03 (0.0%), tests_pri_-90: 1832 (81.9%), check_bayes: 1830 (81.8%), b_tokenize: 9 (0.4%), b_tok_get_all: 8 (0.4%), b_comp_prob: 1.93 (0.1%), b_tok_touch_all: 1807 (80.7%), b_finish: 1.19 (0.1%), tests_pri_0: 351 (15.7%), check_dkim_signature: 0.91 (0.0%), check_dkim_adsp: 2.9 (0.1%), poll_dns_idle: 0.39 (0.0%), tests_pri_10: 3.1 (0.1%), tests_pri_500: 10 (0.4%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 07/13] task_work: Introduce task_work_pending X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wrap the test of task->task_works in a helper function to make it clear what is being tested. Signed-off-by: "Eric W. Biederman" --- fs/io_uring.c | 6 +++--- include/linux/task_work.h | 5 +++++ include/linux/tracehook.h | 4 ++-- kernel/signal.c | 4 ++-- kernel/task_work.c | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index e54c4127422e..e85261079a78 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -2590,7 +2590,7 @@ static inline unsigned int io_sqring_entries(struct io_ring_ctx *ctx) static inline bool io_run_task_work(void) { - if (test_thread_flag(TIF_NOTIFY_SIGNAL) || current->task_works) { + if (test_thread_flag(TIF_NOTIFY_SIGNAL) || task_work_pending(current)) { __set_current_state(TASK_RUNNING); tracehook_notify_signal(); return true; @@ -7602,7 +7602,7 @@ static int io_sq_thread(void *data) } prepare_to_wait(&sqd->wait, &wait, TASK_INTERRUPTIBLE); - if (!io_sqd_events_pending(sqd) && !current->task_works) { + if (!io_sqd_events_pending(sqd) && !task_work_pending(current)) { bool needs_sched = true; list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) { @@ -10321,7 +10321,7 @@ static __cold void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, hlist_for_each_entry(req, list, hash_node) seq_printf(m, " op=%d, task_works=%d\n", req->opcode, - req->task->task_works != NULL); + task_work_pending(req->task)); } seq_puts(m, "CqOverflowList:\n"); diff --git a/include/linux/task_work.h b/include/linux/task_work.h index 5b8a93f288bb..897494b597ba 100644 --- a/include/linux/task_work.h +++ b/include/linux/task_work.h @@ -19,6 +19,11 @@ enum task_work_notify_mode { TWA_SIGNAL, }; +static inline bool task_work_pending(struct task_struct *task) +{ + return READ_ONCE(task->task_works); +} + int task_work_add(struct task_struct *task, struct callback_head *twork, enum task_work_notify_mode mode); diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h index b77bf4917196..fa834a22e86e 100644 --- a/include/linux/tracehook.h +++ b/include/linux/tracehook.h @@ -90,7 +90,7 @@ static inline void tracehook_notify_resume(struct pt_regs *regs) * hlist_add_head(task->task_works); */ smp_mb__after_atomic(); - if (unlikely(current->task_works)) + if (unlikely(task_work_pending(current))) task_work_run(); #ifdef CONFIG_KEYS_REQUEST_CACHE @@ -115,7 +115,7 @@ static inline void tracehook_notify_signal(void) { clear_thread_flag(TIF_NOTIFY_SIGNAL); smp_mb__after_atomic(); - if (current->task_works) + if (task_work_pending(current)) task_work_run(); } diff --git a/kernel/signal.c b/kernel/signal.c index 0e0bd1c1068b..3b4cf25fb9b3 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2344,7 +2344,7 @@ static void ptrace_do_notify(int signr, int exit_code, int why) void ptrace_notify(int exit_code) { BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP); - if (unlikely(current->task_works)) + if (unlikely(task_work_pending(current))) task_work_run(); spin_lock_irq(¤t->sighand->siglock); @@ -2626,7 +2626,7 @@ bool get_signal(struct ksignal *ksig) struct signal_struct *signal = current->signal; int signr; - if (unlikely(current->task_works)) + if (unlikely(task_work_pending(current))) task_work_run(); /* diff --git a/kernel/task_work.c b/kernel/task_work.c index 1698fbe6f0e1..cc6fccb0e24d 100644 --- a/kernel/task_work.c +++ b/kernel/task_work.c @@ -78,7 +78,7 @@ task_work_cancel_match(struct task_struct *task, struct callback_head *work; unsigned long flags; - if (likely(!task->task_works)) + if (likely(!task_work_pending(task))) return NULL; /* * If cmpxchg() fails we continue without updating pprev. -- 2.29.2