Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1808137pxf; Fri, 26 Mar 2021 15:41:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOn4f79gspKyp+9UbrTbVcIuv8qchJ9u0jKUk1yE173xh7pdgi7t+M//XayNmv4S1geXLA X-Received: by 2002:a05:6402:4244:: with SMTP id g4mr17558907edb.204.1616798507289; Fri, 26 Mar 2021 15:41:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616798507; cv=none; d=google.com; s=arc-20160816; b=ZoLyL+YwoPmXJ4lOMdG6KJ7Ij/pwBHTQW3tYcCvCYgcTlAmOBYTn9q5kJcN6wFzANO 00QI7s63ZRZaNqDbzB1hivyqm5T3aGpNVxfbUoqurGn6Ltm8hApgDU0StKBXTDt0UPFT 0aMjXdGd68mYoVLYeqzyAuhPstsfWgxcP6/TMrZvM47uzm3DlxmzUno5203Gr8OBOUC9 RPtoU6jc99Dr2VluTHlh/kBiomvv3RbU4pyCXRQ4RMfty/+tHR7RiB0535v7kIFtHCQJ HfYw9PO3G8NTRFrS9zYhViEoqehjS3fEL77qPTCZbjDYADYnQ8GPHHHObEP6TmMeN51v FdEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=oWhGMhbhfaExshGxGcZbmcEJMK/dZUuQgIL4+55tUvE=; b=TiKeO8yxsui16MfFE27sftVnAt3DXffClAMl9ixlg64ASGn7lfimwwZm7H2qLMZMHx qyaZR9NecIj2PiuG7TZxtmUzE6QZ3WdNngSHr+E80njkwPR3aiuzUsAxOMH1DFh6wD+p +i9sppKgagh4Y/2CDke+/jwHO/G9OyQDfQvgG1BE05EETNUdL+U30k7G6XKBO4iR2P9f aUE1xkasaPsFT7uAFP9u9Wr29g2AKN1KiF7KMNDs8AlWRrkI+OMFVDt24OfzBySoNZGS TrO5g1lfp0ZJZWSGFpgHrcfYzR0y01gOcDC9IYnKBcTkly8UHt9Goatk3oPCh2rChwDu 4JmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=VxMB7sku; 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 y5si7652127eda.385.2021.03.26.15.41.24; Fri, 26 Mar 2021 15:41:47 -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=VxMB7sku; 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 S230076AbhCZWiY (ORCPT + 99 others); Fri, 26 Mar 2021 18:38:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230299AbhCZWiS (ORCPT ); Fri, 26 Mar 2021 18:38:18 -0400 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8991AC0613B1 for ; Fri, 26 Mar 2021 15:38:18 -0700 (PDT) Received: by mail-oi1-x22c.google.com with SMTP id n140so7194707oig.9 for ; Fri, 26 Mar 2021 15:38:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=oWhGMhbhfaExshGxGcZbmcEJMK/dZUuQgIL4+55tUvE=; b=VxMB7skuZtkbamoSztTVJkDhpc0enYD2DT9h1F3I0Tky4rMifLy1zHotffpbthRZQc 4ar/mBpaMJLBoxHKd7/nnAF/RvnvQWGr3bSg4PA9QcMkGneu1qOOVVWsqBmhYQvfkEyU OGqTF3NuR/yulYjXxYjlOZyToBFSyj1w8Ef0b5nM3rUDHO0u5dsWc9sLWZocA5zucDYq yzNWvJ0eqE2x5W9h3Xoink719Ee7ot4Kmvn8g7KXKA3NnxRv19DlXxrrl+j7vCqIAxUq Tr3PNT5Upk/fiOqy29BfaQZbb1vGwfPgFAIAwAZtiZL0J1XNl4xjL2pArSOt8G9Ecp5e zCyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=oWhGMhbhfaExshGxGcZbmcEJMK/dZUuQgIL4+55tUvE=; b=SguhscKc0GIwfqnyvOpqDuqSQqvuyRGQlFSnSjYT7TMxKirSkVE7RMreBfBXOc30yf BSqJkJP/O18oHWSwPbxXl8jT2oyOkGZxFnu0tOL6vIMib61u2TN9t+AuieXwljDCVvGg gJvRGiq3AQ9x+kXgVrGR5aR6nbDZaFKlWTjlRiX08UvW0WUCfhsrLfjqEeLyQasogn8s KbgqJDYrSQJqKRjfu52IAxMKm/DRPo0yGclpUTH/lJsAjBWt2bMSkUIaYUtIkh54zGyj OvwJN02eHExW3zFgrCgSV7Z+wB8xSqh21/BdFv+fzWT3pzreGM3W4X7Bm2Mt0Hu4nPv9 /Hcg== X-Gm-Message-State: AOAM530+33lk8hS8w6k70h/+r8R1h0gKURR+7jGj+bd3lo1u98Eby1tK tup47dGhdkU5lhubFqd2q0aW7LVq2Ekkng== X-Received: by 2002:a05:6808:14cc:: with SMTP id f12mr11010998oiw.166.1616798297627; Fri, 26 Mar 2021 15:38:17 -0700 (PDT) Received: from [192.168.1.30] ([207.135.233.147]) by smtp.gmail.com with ESMTPSA id k24sm2051602oic.51.2021.03.26.15.38.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Mar 2021 15:38:17 -0700 (PDT) Subject: Re: [PATCH 2/7] io_uring: handle signals for IO threads like a normal thread To: "Eric W. Biederman" Cc: io-uring@vger.kernel.org, torvalds@linux-foundation.org, metze@samba.org, oleg@redhat.com, linux-kernel@vger.kernel.org References: <20210326155128.1057078-1-axboe@kernel.dk> <20210326155128.1057078-3-axboe@kernel.dk> <106a38d3-5a5f-17fd-41f7-890f5e9a3602@kernel.dk> <01058178-dd66-1bff-4d74-5ff610817ed6@kernel.dk> From: Jens Axboe Message-ID: <7a71da2f-ca39-6bbf-28c1-bcc2eec43943@kernel.dk> Date: Fri, 26 Mar 2021 16:38:16 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/26/21 4:35 PM, Eric W. Biederman wrote: > Jens Axboe writes: > >> On 3/26/21 4:23 PM, Eric W. Biederman wrote: >>> Jens Axboe writes: >>> >>>> On 3/26/21 2:29 PM, Eric W. Biederman wrote: >>>>> Jens Axboe writes: >>>>> >>>>>> 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; >>>>> ^^^^^^^^^^^^^^^^^^^^^^ >>>>> >>>>> That is wrong. You are promising to deliver a signal to signal >>>>> handler and them simply discarding it. Perhaps: >>>>> >>>>> if (!get_signal(&ksig)) >>>>> continue; >>>>> WARN_ON(!sig_kernel_stop(ksig->sig)); >>>>> break; >>>> >>>> Thanks, updated. >>> >>> Gah. Kill the WARN_ON. >>> >>> I was thinking "WARN_ON(!sig_kernel_fatal(ksig->sig));" >>> The function sig_kernel_fatal does not exist. >>> >>> Fatal is the state that is left when a signal is neither >>> ignored nor a stop signal, and does not have a handler. >>> >>> The rest of the logic still works. >> >> I've just come to the same conclusion myself after testing it. >> Of the 3 cases, most of them can do the continue, but doesn't >> really matter with the way the loop is structured. Anyway, looks >> like this now: > > This idiom in the code: >> + if (signal_pending(current)) { >> + struct ksignal ksig; >> + >> + if (fatal_signal_pending(current)) >> + break; >> + if (!get_signal(&ksig)) >> + continue; >> } > > Needs to be: >> + if (signal_pending(current)) { >> + struct ksignal ksig; >> + >> + if (!get_signal(&ksig)) >> + continue; >> + break; >> } > > Because any signal returned from get_signal is fatal in this case. > It might make sense to "WARN_ON(ksig->ka.sa.sa_handler != SIG_DFL)". > As the io workers don't handle that case. > > It won't happen because you have everything blocked. > > The extra fatal_signal_pending(current) logic is just confusing in this > case. OK good point, and follows the same logic even if it won't make a difference in my case. I'll make the change. -- Jens Axboe