Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1507865pxf; Fri, 26 Mar 2021 08:53:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsFw7wgQ3JFD+qIly2ZcID918O8gxm7C+vAEsH1RbTpGIzMVYJFzfPGeufooOnieQuATEy X-Received: by 2002:a17:906:90c5:: with SMTP id v5mr16083016ejw.466.1616774009722; Fri, 26 Mar 2021 08:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616774009; cv=none; d=google.com; s=arc-20160816; b=RMmEsQwn2a2N730F9DVhAtvlWc+8EE7uVmqbB8OSa+MvgiKJAm4dgr8a/+p+knb/eq k5J74dUp2GFH44TOrS3O+O8IJPO9+bEqW7aIvwc0zeKjzR78a8gD4NEbgXMouPv2raAC CODgD845pyehRz8mjPxuNM2Z37BbnBaw7M6G/OarzkA+yzJXbQxI/wVOSMtjykVeHTOI +fhzyIJ42wE7X6a4kLBdq5doOEYXcro42KW87M2wuXJMyXkJrfK77MbjJDu0NyJNrlEf GbDMTvgA90/mg9eD8yGierS5FoHyFQ39r24K+x3cabJq+CxN0D5X8sz5HXhlf2/kGb5d jrhQ== 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=2mAmxL/kkU5P2p4/GNsVO44FMkgxyU8s5QHvaqUZUn8=; b=p93vVZ45sYbCJDXtkgSDcRFysPM4S1iPVxq1qe8iVbKATBe57FaEmDR1Oqxjnk6kMo D0H+iUr/UL+0bLoOtH4Ort+dfyoRKrrEBosnu5N/onKa4tC/Q59QzUaTRSdW5deFgEPp FunFz6PEsyL6MAhgXXwyLv8gluTm0P7zmaWYZCwD3w8Yew8x/UJx1hgvTuJBs+A1KAqb UCpstizhxbXfNtV2ujdtFnEWvCHKsJEHaI/89I8IngG4GOSyVpKMua39u0/KUltTAl/l w03Ha3jD18K3sMYtVtprELZdS4ISfrFR4XWK+WxYP+kxISqb8omHbjwdpPvkeH+lStJc aCLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=UiPFxEcN; 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 f18si7441568eja.587.2021.03.26.08.53.07; Fri, 26 Mar 2021 08:53:29 -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=UiPFxEcN; 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 S230514AbhCZPwV (ORCPT + 99 others); Fri, 26 Mar 2021 11:52:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230467AbhCZPwF (ORCPT ); Fri, 26 Mar 2021 11:52:05 -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 17469C0613AA for ; Fri, 26 Mar 2021 08:52:05 -0700 (PDT) Received: by mail-il1-x12a.google.com with SMTP id d2so5381075ilm.10 for ; Fri, 26 Mar 2021 08:52:05 -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=2mAmxL/kkU5P2p4/GNsVO44FMkgxyU8s5QHvaqUZUn8=; b=UiPFxEcNXGdHzMJvXUv5dHcIiKqFHUT5CvVH7tlB7pv5EfO93D7/fRDE8iJ4x3HI57 8Y7CrCde/Co4TH0jsIv8OC+m/0fBeui0uMAbCZCkk9RHM55gII3tog6KrdEf061FYwKO 7+oZDIJZoUzznCdr7DZo6QeA4unSTb+nQqV2MX3t3QnmEU2O5yUj4vMSe41k7umvS6Ye bo8395n8p8FCi3APT50OsW/xoNDcD1M8KS4Z9TyAhchVZ9PnoXcR4Ls3kdviLzQsTEnn DtMOgg2H+t18zIPbNiahlsyrzPvpDEXcs6R9xVTxAXsmgHA4IB2Xqfld5txRED+sp4Ux /OzA== 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=2mAmxL/kkU5P2p4/GNsVO44FMkgxyU8s5QHvaqUZUn8=; b=TAUAOstrSm1IHZGvZOoas2x16g5Ei2zdqvcsG7g+AqZbo7Cm4KnI9WR883Xpru2lk0 8qpnisC7W8l9TA7jkdBaU1m29Y28/Legpxe0CS9TqJq2nM9/5F5995T8kEtRNcdLh5gN scXK/c67PuoraLTGt8H5wA0SeqAYVJBttjtG0BTkH6l645P7FQ6henhGltCOJchYUZo+ YKOWea2jS1biTwXbGZsg5p+si8lfdzpStkNNWVrfQ4oLG45h7+gyzFH3k1ED4jJkld5y EQgPHfFgjweAF7Roa56bFTIrLRRCkuTYXyn6rDX8SLT2ZjEV4cJwfyp5ArmeIdCuzRoU Co0Q== X-Gm-Message-State: AOAM531KBEu31CXBYGfLwRuCeogI/E7DU+h/DMECGQJmalLBbA0l9q4/ ZV+QAQmjC9AmyOy/O/pBzgoZnw== X-Received: by 2002:a05:6e02:4b2:: with SMTP id e18mr10044121ils.42.1616773924539; Fri, 26 Mar 2021 08:52:04 -0700 (PDT) Received: from p1.localdomain ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id a7sm4456337ilj.64.2021.03.26.08.52.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 08:52:04 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: torvalds@linux-foundation.org, ebiederm@xmission.com, metze@samba.org, oleg@redhat.com, linux-kernel@vger.kernel.org, Jens Axboe Subject: [PATCH 2/7] io_uring: handle signals for IO threads like a normal thread Date: Fri, 26 Mar 2021 09:51:15 -0600 Message-Id: <20210326155128.1057078-3-axboe@kernel.dk> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210326155128.1057078-1-axboe@kernel.dk> References: <20210326155128.1057078-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 go through various hoops to disallow signals for the IO threads, but there's really no reason why we cannot just allow them. The IO threads never return to userspace like a normal thread, and hence don't go through normal signal processing. Instead, just check for a pending signal as part of the work loop, and call get_signal() to handle it for us if anything is pending. With that, we can support receiving signals, including special ones like SIGSTOP. Signed-off-by: Jens Axboe --- fs/io-wq.c | 24 +++++++++++++++++------- fs/io_uring.c | 12 ++++++++---- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/fs/io-wq.c b/fs/io-wq.c index b7c1fa932cb3..3e2f059a1737 100644 --- a/fs/io-wq.c +++ b/fs/io-wq.c @@ -16,7 +16,6 @@ #include #include #include -#include #include "../kernel/sched/sched.h" #include "io-wq.h" @@ -503,10 +502,16 @@ static int io_wqe_worker(void *data) if (io_flush_signals()) continue; ret = schedule_timeout(WORKER_IDLE_TIMEOUT); - if (try_to_freeze() || ret) + if (signal_pending(current)) { + struct ksignal ksig; + + if (fatal_signal_pending(current)) + break; + if (get_signal(&ksig)) + continue; + } + if (ret) continue; - if (fatal_signal_pending(current)) - break; /* timed out, exit unless we're the fixed worker */ if (test_bit(IO_WQ_BIT_EXIT, &wq->state) || !(worker->flags & IO_WORKER_F_FIXED)) @@ -714,9 +719,14 @@ static int io_wq_manager(void *data) set_current_state(TASK_INTERRUPTIBLE); io_wq_check_workers(wq); schedule_timeout(HZ); - try_to_freeze(); - if (fatal_signal_pending(current)) - set_bit(IO_WQ_BIT_EXIT, &wq->state); + if (signal_pending(current)) { + struct ksignal ksig; + + if (fatal_signal_pending(current)) + set_bit(IO_WQ_BIT_EXIT, &wq->state); + else if (get_signal(&ksig)) + continue; + } } while (!test_bit(IO_WQ_BIT_EXIT, &wq->state)); io_wq_check_workers(wq); diff --git a/fs/io_uring.c b/fs/io_uring.c index 54ea561db4a5..350418a88db3 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -78,7 +78,6 @@ #include #include #include -#include #define CREATE_TRACE_POINTS #include @@ -6765,8 +6764,14 @@ static int io_sq_thread(void *data) timeout = jiffies + sqd->sq_thread_idle; continue; } - if (fatal_signal_pending(current)) - break; + if (signal_pending(current)) { + struct ksignal ksig; + + if (fatal_signal_pending(current)) + break; + if (get_signal(&ksig)) + continue; + } sqt_spin = false; cap_entries = !list_is_singular(&sqd->ctx_list); list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) { @@ -6809,7 +6814,6 @@ static int io_sq_thread(void *data) mutex_unlock(&sqd->lock); schedule(); - try_to_freeze(); mutex_lock(&sqd->lock); list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) io_ring_clear_wakeup_flag(ctx); -- 2.31.0