Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2426506pxf; Sat, 20 Mar 2021 15:56:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxzAnYK9ghAV9i4Y4hegvlukgqN1OjAt7ZxUcCSyzLZc4KUZZTY70cyxi0kYNJ1EQ9YWdz X-Received: by 2002:a17:907:76c7:: with SMTP id kf7mr11558517ejc.470.1616281008500; Sat, 20 Mar 2021 15:56:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616281008; cv=none; d=google.com; s=arc-20160816; b=wDdpVTowiN3UhB2lWpvFv2G16KuCxrX8tBW87Fp6Sq9JGbv/ix0UIkk5Vb+FSBJ7cG 7hiQeGn1Y37HLaZNV9UN4Xq1wxZhVEhPC2GP8wuq1cq7ANIWQuY3wDtgd1B+2QNR2gMx 198iNxX60niwcqW2a2GN3ymzduzp+FC2G/1AATvnTWQoC2ieWnK/L2dRRA679uWSFJEr hzkc4gm2CtKMhHtgGw6I/wqyo077vpRrO3q8uuOnYfi/Z/zAhpAH2XPxxu6rePps+0ft uEP+Ov3YhSM9yjwgNRwJa1F3Yokp4r3gaZ7LSktn1ASt33MMuX1+FgIT3ZwoUh66iaMP z1qw== 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=loJtadz11k9s/k92JAPlZ0uUPDBkIe52qTJzUu616NU=; b=wT/kzYBSTOI1NLxyAi36HoTRE6pQO+gpOUgeaFX+eDESWqxNndbeyF4gnBae/mF8ZI BAkYzv+dz577WUoqsrt5uZmGovXhREY2JnpjAyn2ipxnzMaBnwn8DZVj97D4viV7squS uGVWal2JIEIkS44rWgOBzEjEIApYsvRWR0R3J3UEQi2DZy+q9q1mLtt6eXRvmlmA53o3 JsoRuIdwQLa5UIXMxUVkgVqD2d3QCKw+lSSB1drLB0sPQD+DCV/+UKuy9oDiwIrC/5NM GxKrQyKIqbQVNTXPiHJ9gCF7A3LaSpsn+uQYr8Gl1nlxdZiSvNskikbyhKkhU7YrEUQa FbdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=n06jRY9U; 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 gn42si8976573ejc.583.2021.03.20.15.56.26; Sat, 20 Mar 2021 15:56:48 -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=n06jRY9U; 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 S229871AbhCTWxL (ORCPT + 99 others); Sat, 20 Mar 2021 18:53:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229886AbhCTWxJ (ORCPT ); Sat, 20 Mar 2021 18:53:09 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7892C061762 for ; Sat, 20 Mar 2021 15:53:08 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id y5so8403561pfn.1 for ; Sat, 20 Mar 2021 15:53:08 -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=loJtadz11k9s/k92JAPlZ0uUPDBkIe52qTJzUu616NU=; b=n06jRY9UMbT/u4rKxl6i122jNhUHyan6aXjvVaugHUiJocJeu6I9n8Dile+eGY4zkJ ETXf2302ueG59950/GQ6J2RaAclnVbE2xTKoZIQBs1cTmn+0gsyCZcJZkjApg8XRwHyl TCEavpkSMjEiUMTub4LAZBs518LzzzV+YpTtiL9ZbSox5yh2Wq0r2aZlXg8Z3plHRxGK nWWW18XKW2qyQ9IEsyj3SvdwhrqYd1SQxJYRmPf6zb30h1jSy9DMCLalNu42Ws1NiPQe mitiJmz0vpDk5sRLgGD57yF6ZhFs3xs40ZrNKgRuoyb7f0HjebcN6Lz9mMKQyPsUJMfK dMxw== 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=loJtadz11k9s/k92JAPlZ0uUPDBkIe52qTJzUu616NU=; b=EOcjSLjZBwoz/RTIqJM18Y7B6aUcIjqdrrqkhAdzLzqf47H3TPieNp55ZgzLwEI9eP +sObzJ7zUgsDsTjhNN0wIO0uVu4Xag7xshfmGjQ6CBucbn22olZsuDYLu9xNs35Uvb8Y vrW0QLpBWgikgWhIbXvtGMkEwFgB/IlBkEpfjHrRxPyTtKa11VHQCbxBnD8xyLVhIBcL FrhDHeGkkdePwOMbW9rLTSf4PTxhQkCszSGBjbKGXBSdcCzmwzqo4cQZ3eJAQLHApy5R G23GKX/mqGjcC4WCP2vNXw0yXuazMe2N308WAA5SekB50/Ag6XxcxlYKuc3w5/kAJuXZ gOmg== X-Gm-Message-State: AOAM53199uwLCJUYWY3OJX9DwPzOjk2109DImooy+2B2xKyjfnkvq0zf NRAqk703gbS0tAm/N9O6FHyzBA== X-Received: by 2002:a63:d40b:: with SMTP id a11mr16710498pgh.192.1616280788204; Sat, 20 Mar 2021 15:53:08 -0700 (PDT) Received: from [192.168.1.134] ([66.219.217.173]) by smtp.gmail.com with ESMTPSA id l4sm9077825pgn.77.2021.03.20.15.53.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 20 Mar 2021 15:53:07 -0700 (PDT) Subject: Re: [PATCHSET 0/2] PF_IO_WORKER signal tweaks To: "Eric W. Biederman" , Linus Torvalds Cc: io-uring , Linux Kernel Mailing List , Oleg Nesterov , criu@openvz.org References: <20210320153832.1033687-1-axboe@kernel.dk> From: Jens Axboe Message-ID: <907b36b6-a022-019a-34ea-58ce46dc2d12@kernel.dk> Date: Sat, 20 Mar 2021 16:53:06 -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/20/21 4:08 PM, Eric W. Biederman wrote: > > Added criu because I just realized that io_uring (which can open files > from an io worker thread) looks to require some special handling for > stopping and freezing processes. If not in the SIGSTOP case in the > related cgroup freezer case. > > Linus Torvalds writes: > >> On Sat, Mar 20, 2021 at 10:51 AM Linus Torvalds >> wrote: >>> >>> Alternatively, make it not use >>> CLONE_SIGHAND|CLONE_THREAD at all, but that would make it >>> unnecessarily allocate its own signal state, so that's "cleaner" but >>> not great either. >> >> Thinking some more about that, it would be problematic for things like >> the resource counters too. They'd be much better shared. >> >> Not adding it to the thread list etc might be clever, but feels a bit too scary. >> >> So on the whole I think Jens' minor patches to just not have IO helper >> threads accept signals are probably the right thing to do. > > The way I see it we have two options: > > 1) Don't ask PF_IO_WORKERs to stop do_signal_stop and in > task_join_group_stop. > > The easiest comprehensive implementation looks like just > updating task_set_jobctl_pending to treat PF_IO_WORKER > as it treats PF_EXITING. > > 2) Have the main loop of the kernel thread test for JOBCTL_STOP_PENDING > and call into do_signal_stop. > > It is a wee bit trickier to modify the io_workers to stop, but it does > not look prohibitively difficult. > > All of the work performed by the io worker is work scheduled via > io_uring by the process being stopped. > > - Is the amount of work performed by the io worker thread sufficiently > negligible that we don't care? > > - Or is the amount of work performed by the io worker so great that it > becomes a way for an errant process to escape SIGSTOP? > > As the code is all intermingled with the cgroup_freezer. I am also > wondering creating checkpoints needs additional stopping guarantees. The work done is the same a syscall, basically. So it could be long running and essentially not doing anything (eg read from a socket, no data is there), or it's pretty short lived (eg read from a file, just waiting on DMA). This is outside of my domain of expertise, which is exactly why I added you and Linus to make some calls on what the best approach here would be. My two patches obviously go route #1 in terms of STOP. And fwiw, I tested this: > To solve the issue that SIGSTOP is simply broken right now I am totally > fine with something like: > > diff --git a/kernel/signal.c b/kernel/signal.c > index ba4d1ef39a9e..cb9acdfb32fa 100644 > --- a/kernel/signal.c > +++ b/kernel/signal.c > @@ -288,7 +288,8 @@ bool task_set_jobctl_pending(struct task_struct *task, unsigned long mask) > JOBCTL_STOP_SIGMASK | JOBCTL_TRAPPING)); > BUG_ON((mask & JOBCTL_TRAPPING) && !(mask & JOBCTL_PENDING_MASK)); > > - if (unlikely(fatal_signal_pending(task) || (task->flags & PF_EXITING))) > + if (unlikely(fatal_signal_pending(task) || > + (task->flags & (PF_EXITING | PF_IO_WORKER)))) > return false; > > if (mask & JOBCTL_STOP_SIGMASK) and can confirm it works fine for me with 2/2 reverted and this applied instead. > Which just keeps from creating unstoppable processes today. I am just > not convinced that is what we want as a long term solution. How about we go with either my 2/2 or yours above to at least ensure we don't leave workers looping as schedule() is a nop with sigpending? If there's a longer timeline concern that "evading" SIGSTOP is a concern, I have absolutely no qualms with making the IO threads participate. But since it seems conceptually simple but with potentially lurking minor issues, probably not the ideal approach for right now. -- Jens Axboe