Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4069448pxb; Mon, 4 Oct 2021 16:43:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwA1zKxefiFnE8K/w1WZuHXLjv55yZI5zYFkdTawbVAfFhAfXjbSaLfucJEETaLouxJPRT6 X-Received: by 2002:a17:90a:bf82:: with SMTP id d2mr33689898pjs.201.1633391023879; Mon, 04 Oct 2021 16:43:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633391023; cv=none; d=google.com; s=arc-20160816; b=JesUec5G5DAJIJhG6DsVcqpXL1hIYkyL848fIGUJ2afo8gw+CTmr3n/hdbYslUi60Q CxGRWS9epzS9iuVaC6YUlzOMXfsISgOo2KJGs9wiBIXQBCCi9Ca5jQjt8NEEmE1gIUkk lANLqfEGz3uwn26MmHiXGCGcvkbCvcBbCxlsF4zXU8KrTBiq4lRJqw53oTSnT96PQFQC uUEPrYPqwV4hJnIRtDWvZOKc7FBxIVAoLCzbLZEx71/Gbmvq7nclRa7aamSoaE+uknOj pMHvAwuM/Ec8jLV/Yp5UpFG4wskq+R0QDVn2YK67F29Opk6VNGgm/SIirfYOwWKzMIIG DN7A== 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 :to:subject:dkim-signature; bh=96yyMKyGyUXRTH3hvSKjxri4j4LEUV+D4xGuayE0ULY=; b=ra7SttwySXdKdMUD8yols/YkPnrHyxNCn44yzLzDKAtNb2orRpqvShMY/ZebGTcSXc 2GMVh85vCyYpmkm9Zar2gZUJtjQFpXoMAdVJ/DF0dk66+C/3OTFDjILXFcztOLMxWZim HVeYKj1e1fFBQP504llTUCM86C2UA2DBTZmMRPP6/HhPUtW/Dt3BR6U3TrefkD8I5aZx zOYtVBuji4go25I5G0vaD9F81wburF6dJq8rDA1qyYsiajp6rVCFHpuwzAgPAtLm7puE 9RZ7B7gn6bYZmrzlD9XbsjqTcI7GlZ6llmVeMuM0AuoVNynxjp38RE8jqtYpZXsoXlW9 SPPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=R4PZZbRD; 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 t36si19047018pgk.512.2021.10.04.16.43.31; Mon, 04 Oct 2021 16:43:43 -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.20210112.gappssmtp.com header.s=20210112 header.b=R4PZZbRD; 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 S233997AbhJDUGE (ORCPT + 99 others); Mon, 4 Oct 2021 16:06:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229945AbhJDUGE (ORCPT ); Mon, 4 Oct 2021 16:06:04 -0400 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D08C5C061745 for ; Mon, 4 Oct 2021 13:04:14 -0700 (PDT) Received: by mail-io1-xd34.google.com with SMTP id h129so21801560iof.1 for ; Mon, 04 Oct 2021 13:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=96yyMKyGyUXRTH3hvSKjxri4j4LEUV+D4xGuayE0ULY=; b=R4PZZbRDe1Uw0SmxR3E8GPWXAreInX1lv2ZIKVssmww5RKxP/i6bs48K8i625PrlcK v3/1B96x39zNBmJMKIvj7XnJyU9OFv94037UqaND5h9qIoYwJd8ty5oA1RubUIgzcytM 8g5c5pXRGigNTCh1occRUAPDvk1rD8uVbOFPrI3GNotUqTus7Nk1kNLkFxFQ0BCHurgK DyQLARneICjD66JOhbmBThUz7vruvvlG5LG3zyLFEbkH+19E/i98pGGZour1wRF4ARZV oq9zP226hUgKzF1kGWWwzTCvsWwJLpDV2Dvf4tyHnYv4ydzzxoUQQWrFzslIqZIWgVa9 d2iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=96yyMKyGyUXRTH3hvSKjxri4j4LEUV+D4xGuayE0ULY=; b=P9ZPflSqoQ1U6s708TtDFwN57Mr4JlEPj/pN9NB+rLJCXvtAVWLmjvFUevXTmcSiqG uHK0NhMqYKVLlANU+bmyUlsVBrYmnXLUdiiTK4DFNnh8hco+D3tzOhGxV6GI+0yMBNCs D+yiCwU4oKYXA2uSCieAcFwGR7tROHy2kWCy43mXAZs6nJ9IiMrTe4dFlaJViE9S60co VBKdi2XHxjmfi1soxAIgISOcyw2aqHiswO/SD0Gz4f4WXDnOxDVqygFp7E4+IwCyfM9f BzHVdUMLxQxPaFXFsbpC/vEETGqKPdDRgvVn8iOKumYxp8TDSBSXDpAMVgcj2ULU9/6F xDNw== X-Gm-Message-State: AOAM530Li2ovB8dBs3IepWQXnH8Vo6SvX7gI7OBL9eDs/jnoSZI42CpU XsEtFAVBpPwMQSVuqC0p1hbvDT6//spb2qZ27Lc= X-Received: by 2002:a02:9542:: with SMTP id y60mr7599122jah.133.1633377854091; Mon, 04 Oct 2021 13:04:14 -0700 (PDT) Received: from [192.168.1.30] ([207.135.234.126]) by smtp.gmail.com with ESMTPSA id a11sm10070213ilm.36.2021.10.04.13.04.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Oct 2021 13:04:13 -0700 (PDT) Subject: Re: [PATCH V3 7/9] fork: Add worker flag to ignore signals To: Mike Christie , geert@linux-m68k.org, vverma@digitalocean.com, hdanton@sina.com, hch@infradead.org, stefanha@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org, christian.brauner@ubuntu.com, linux-kernel@vger.kernel.org References: <20211004192128.381453-1-michael.christie@oracle.com> <20211004192128.381453-8-michael.christie@oracle.com> From: Jens Axboe Message-ID: Date: Mon, 4 Oct 2021 14:04:12 -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: <20211004192128.381453-8-michael.christie@oracle.com> 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 10/4/21 1:21 PM, Mike Christie wrote: > The kthread API creates threads that ignore all signals by default so > modules like vhost that will move from that API to kernel_worker will > not be expecting them. This patch adds a worker flag that tells > kernel_worker to setup the task to ignore signals. > > Signed-off-by: Mike Christie > Acked-by: Christian Brauner > --- > include/linux/sched/task.h | 1 + > kernel/fork.c | 11 ++++++++++- > 2 files changed, 11 insertions(+), 1 deletion(-) > > diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h > index 781abbc1c288..aefa0d221b57 100644 > --- a/include/linux/sched/task.h > +++ b/include/linux/sched/task.h > @@ -21,6 +21,7 @@ struct css_set; > #define KERN_WORKER_IO BIT(0) > #define KERN_WORKER_USER BIT(1) > #define KERN_WORKER_NO_FILES BIT(2) > +#define KERN_WORKER_NO_SIGS BIT(3) > > struct kernel_clone_args { > u64 flags; > diff --git a/kernel/fork.c b/kernel/fork.c > index 3f3fcabffa5f..34d3dca70cfb 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -2555,6 +2555,8 @@ struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int node) > struct task_struct *kernel_worker(int (*fn)(void *), void *arg, int node, > unsigned long clone_flags, u32 worker_flags) > { > + struct task_struct *tsk; > + > struct kernel_clone_args args = { > .flags = ((lower_32_bits(clone_flags) | CLONE_VM | > CLONE_UNTRACED) & ~CSIGNAL), > @@ -2564,7 +2566,14 @@ struct task_struct *kernel_worker(int (*fn)(void *), void *arg, int node, > .worker_flags = KERN_WORKER_USER | worker_flags, > }; > > - return copy_process(NULL, 0, node, &args); > + tsk = copy_process(NULL, 0, node, &args); > + if (IS_ERR(tsk)) > + return tsk; > + > + if (worker_flags & KERN_WORKER_NO_SIGS) > + ignore_signals(tsk); > + > + return tsk; When I originally did it this way, Eric (correctly) pointed out that it's racy. See where it's currently done as part of copy_process(), not after. -- Jens Axboe