Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp379172pxu; Thu, 15 Oct 2020 06:22:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHQ1yYAm6ksBdY9XTyPydKIAwRBHSuui7CMyPRlV7i2Mz7iG/z6pxlYEbu0kY4lWCZa/Le X-Received: by 2002:a50:fd83:: with SMTP id o3mr4412825edt.17.1602768177395; Thu, 15 Oct 2020 06:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602768177; cv=none; d=google.com; s=arc-20160816; b=i8xGbYqOJUWb69qOB9Hd9TSuJhpTEouhazNWffwDCgDaBiOofpKfZPkoDh04o6FLZJ 6/6BgvqUhqEak9h6EN7/Y2Qs358ADgoyKRy1H4MADbvzUA9imEgg4VNU9MxD3H2lJs0n hVWGUhH5TKT1Sbz/kT1Ta47jqOJ3S9LgT5q4GGIhlmuK2czmua7BUlwgL7/493Jnih/T 4dAkdnuKIkRbq1jWgj5kMDKQ8e9/Lg9E1/CdY4EZXztwLR/4gyXlylxb3tcNoAUPhBUq mqck3L9xFNg7DFGlmHEMyGrWnPqTbkFPr1a0GzlfXbQWlQeBF5yADZZZZUvfgPf/ex/q qtBg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WTmL06FHUzHZIgnmMADoS0LxIHWnkbferYQGPtLLnsY=; b=Ma4SHmO3Nf4m6FUBNk9FMEh2CXJgOt9A7S6bgoksBxWpvyc/6Jqf2CiOa0n/MNkQMI ix9ZNRKKlzilSFL1oeJavsWaCgWdUN1vnGuplV70tgCpZVioB4ZO95HY3e//Z3QHJEpE D6LeKmT3neTQPcsIwxb1PiugjP5R61u8rkQpWZkPO0bXShPExAxpUXCVV+TmDUxDS2Uq QGx9C6CTHhcyGexkPjHkagTrvETRsb766f1w8gZzoKOm94gwOaKFv3cm96J12Ecum9kC D6lhonMv2lspYcY8yNgzrYI0bRRxlZ/S/MaYPakdRtsxoYq4Tc4WAZOTOOYlW160lo1s S9pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=erVfJZjh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt1si2049036ejc.566.2020.10.15.06.22.26; Thu, 15 Oct 2020 06:22:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=erVfJZjh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729266AbgJONR2 (ORCPT + 99 others); Thu, 15 Oct 2020 09:17:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728460AbgJONRK (ORCPT ); Thu, 15 Oct 2020 09:17:10 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC8A7C0613D4 for ; Thu, 15 Oct 2020 06:17:08 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id k21so4244409ioa.9 for ; Thu, 15 Oct 2020 06:17:08 -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=WTmL06FHUzHZIgnmMADoS0LxIHWnkbferYQGPtLLnsY=; b=erVfJZjhLpwNHHuy5iHq0c2bcRxlxLVYZF2nSeDiKSPyvFzl24CAkMVQVJFRqTTJAP GBONmEaHM7r2I+krRKvZhdMjJxUlxnvjJlXwBiOMPX5NmyjOC4VkQ6mKEJQ2BKMGwVn5 49tqVqoYiVJNZI2mcOPMeGn7YEkyw2dFaMESfyWD1sslHEJA7yeuXu+/dys4lDeQXu7S 1blrpm/2JdVn1rJPpore7e6hE5hCvglnycUc6JgcislETEwUxiwSTepY39dMpWPh3uM4 EU5zTN6+yQJtFcOehM1qFRz1u6Ysm9hDIRgCnFY4cFTauoSt9m63enm94jp0eM6iFlE9 Yslg== 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=WTmL06FHUzHZIgnmMADoS0LxIHWnkbferYQGPtLLnsY=; b=gA+oTo5up4PQL8nHiRX8iBYvfjyCKbTSh+C5LiEoo5eUT6Vo9oSWiNNxKgteL7FJ77 tPHZfhkUl+ahYTWSWhW+QqcaDgevB4Rxs55mrI4QpvmFjcQDbfpUVnzf2hYgmvyqwZaY tQxxJT+IGrHKAlceMopvsx3EXkmtoHAuOv3pAI3xRiSXHlj2pG1vdMZUiaSnL+yb+KeE JdO5OkckginKJXdN1v1J7KfEy75MB8ywQZRJuTzGhg52g1a0DRU53AkEsZaV6xgjcWrk ZBKZpfiTGi9HTXn6WNymAVRakUiMOMbTjjzLt/OwOrPWYQoJ5gekTUdHQR1Ee9qLbI7h jcvQ== X-Gm-Message-State: AOAM533OfCSc424TpxIMJFH66/1DygzTqcsTEkLH+ao1quqsVruVg3us rvCuKvwXBLJN//4ZBblX1qRyZnicmdsNAA== X-Received: by 2002:a02:3b57:: with SMTP id i23mr3619877jaf.110.1602767827191; Thu, 15 Oct 2020 06:17:07 -0700 (PDT) Received: from p1.localdomain ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id m13sm2486736ioo.9.2020.10.15.06.17.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 06:17:06 -0700 (PDT) From: Jens Axboe To: linux-kernel@vger.kernel.org, io-uring@vger.kernel.org Cc: peterz@infradead.org, oleg@redhat.com, tglx@linutronix.de, Jens Axboe Subject: [PATCH 2/5] kernel: add task_sigpending() helper Date: Thu, 15 Oct 2020 07:16:58 -0600 Message-Id: <20201015131701.511523-3-axboe@kernel.dk> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201015131701.511523-1-axboe@kernel.dk> References: <20201015131701.511523-1-axboe@kernel.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is in preparation for maintaining signal_pending() as the decider of whether or not a schedule() loop should be broken, or continue sleeping. This is different than the core signal use cases, where we really want to know if an actual signal is pending or not. task_sigpending() returns non-zero if TIF_SIGPENDING is set. Only core kernel use cases should care about the distinction between the two, make sure those use the task_sigpending() helper. Reviewed-by: Thomas Gleixner Signed-off-by: Jens Axboe --- include/linux/sched/signal.h | 9 +++++++-- kernel/events/uprobes.c | 2 +- kernel/signal.c | 8 ++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 1bad18a1d8ba..404145dc536e 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -353,11 +353,16 @@ static inline int restart_syscall(void) return -ERESTARTNOINTR; } -static inline int signal_pending(struct task_struct *p) +static inline int task_sigpending(struct task_struct *p) { return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING)); } +static inline int signal_pending(struct task_struct *p) +{ + return task_sigpending(p); +} + static inline int __fatal_signal_pending(struct task_struct *p) { return unlikely(sigismember(&p->pending.signal, SIGKILL)); @@ -365,7 +370,7 @@ static inline int __fatal_signal_pending(struct task_struct *p) static inline int fatal_signal_pending(struct task_struct *p) { - return signal_pending(p) && __fatal_signal_pending(p); + return task_sigpending(p) && __fatal_signal_pending(p); } static inline int signal_pending_state(long state, struct task_struct *p) diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 0e18aaf23a7b..8bb26a338e06 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -1973,7 +1973,7 @@ bool uprobe_deny_signal(void) WARN_ON_ONCE(utask->state != UTASK_SSTEP); - if (signal_pending(t)) { + if (task_sigpending(t)) { spin_lock_irq(&t->sighand->siglock); clear_tsk_thread_flag(t, TIF_SIGPENDING); spin_unlock_irq(&t->sighand->siglock); diff --git a/kernel/signal.c b/kernel/signal.c index a38b3edc6851..9f86246a8637 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -983,7 +983,7 @@ static inline bool wants_signal(int sig, struct task_struct *p) if (task_is_stopped_or_traced(p)) return false; - return task_curr(p) || !signal_pending(p); + return task_curr(p) || !task_sigpending(p); } static void complete_signal(int sig, struct task_struct *p, enum pid_type type) @@ -2822,7 +2822,7 @@ static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which) /* Remove the signals this thread can handle. */ sigandsets(&retarget, &retarget, &t->blocked); - if (!signal_pending(t)) + if (!task_sigpending(t)) signal_wake_up(t, 0); if (sigisemptyset(&retarget)) @@ -2856,7 +2856,7 @@ void exit_signals(struct task_struct *tsk) cgroup_threadgroup_change_end(tsk); - if (!signal_pending(tsk)) + if (!task_sigpending(tsk)) goto out; unblocked = tsk->blocked; @@ -2900,7 +2900,7 @@ long do_no_restart_syscall(struct restart_block *param) static void __set_task_blocked(struct task_struct *tsk, const sigset_t *newset) { - if (signal_pending(tsk) && !thread_group_empty(tsk)) { + if (task_sigpending(tsk) && !thread_group_empty(tsk)) { sigset_t newblocked; /* A set of now blocked but previously unblocked signals. */ sigandnsets(&newblocked, newset, ¤t->blocked); -- 2.28.0