Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2155079rwd; Mon, 15 May 2023 08:00:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7PkNjHDPyHo53N2nJxyeNCNj/KeJjudeWUiwNFOtDxYxq6x/VCNzfX8Fux2Oe3oZR80yu2 X-Received: by 2002:a05:6a20:7345:b0:106:92a:37ae with SMTP id v5-20020a056a20734500b00106092a37aemr3893238pzc.30.1684162848042; Mon, 15 May 2023 08:00:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684162848; cv=none; d=google.com; s=arc-20160816; b=B65qIXEFJUbc6Jy+UuL0LJWW9kHImaTsW9zv7vRNlftAbvESttBC/5jzRuwauPi7h9 3kslzi34Tj0y/TNagRUYWpl0eqNEAl6jnVJaXJTkmgeO2JJLQNsiOp2XQx1ZfABqOOrf gnrijhbHFSwQyGpcfS2naQ95nyPe2KqcTvAVcqLPCPEV8J+zVY5qu5nEy0Lvm071oOds lnStswkKB/rAyTnCY2Vh6dpaPEh8G6BhWji944c5xPocC5eHb4vR88MaDmtXV0mMGWst glpm8P1IS6PaxPhyCDK5XKagowqt14DsZtMkg3nscFjUASFQZ+MYQePwEx7SDhMcsP9X lwMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :message-id:date:user-agent:references:in-reply-to:cc:to:from; bh=gNqXtmbPmGajy/EMKEut3VPwuN50NwLzSeUNRt9eHPs=; b=oUDbxoNKriDNvQkpnN8Y+n+ZshGQrTBfUlkxu/Xoy3Pfo+CgYZ3tpkdx70ujyJlzhN XD/O+/623DmtaeCfWC+Xuso5v/CuV7JYT1z59QcWCmRdo53HKPBwdLVyFOiLwY+LwJIz OkVoR8XCb7ziH2Xqt87cnM9FhDsj9oMi6EgGaY4c2FbtsN7GMvSV8Iy01pt5uqB2DFlB +vqjL0LpPXKSsefKb7EDCkR/teevHEnJAd1C1oCg1uWqTIhbClYtpH6gbngHZZOtRGsK 1hYKYCBkbbXsMtAdh0HUurcSBujzvEAFxgU+/DG4kqEQLiDfc6JrCeD0Z6WLTmK8AJ6D MhGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a63b744000000b0052cc0ba4e82si15848211pgt.758.2023.05.15.08.00.32; Mon, 15 May 2023 08:00:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241776AbjEOOnO convert rfc822-to-8bit (ORCPT + 99 others); Mon, 15 May 2023 10:43:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241759AbjEOOnG (ORCPT ); Mon, 15 May 2023 10:43:06 -0400 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41229270D for ; Mon, 15 May 2023 07:42:50 -0700 (PDT) Received: from in02.mta.xmission.com ([166.70.13.52]:41028) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1pyZPT-000HU2-Ep; Mon, 15 May 2023 08:42:47 -0600 Received: from ip68-110-29-46.om.om.cox.net ([68.110.29.46]:48662 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1pyZPR-003Kxl-OI; Mon, 15 May 2023 08:42:47 -0600 From: "Eric W. Biederman" To: Huacai Chen Cc: Huacai Chen , Luis Chamberlain , Andrew Morton , Kees Cook , linux-mm@kvack.org, linux-kernel@vger.kernel.org In-Reply-To: (Huacai Chen's message of "Sat, 13 May 2023 11:18:37 +0800") References: <20230509104127.1997562-1-chenhuacai@loongson.cn> <87ild0w5qs.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Date: Mon, 15 May 2023 09:41:50 -0500 Message-ID: <87ttwdu05t.fsf@email.froward.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-XM-SPF: eid=1pyZPR-003Kxl-OI;;;mid=<87ttwdu05t.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.110.29.46;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX18kmDAXAFN2evKbBlpraJSCti1ihQ0mM6I= X-SA-Exim-Connect-IP: 68.110.29.46 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Virus: No X-Spam-DCC: XMission; sa03 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;Huacai Chen X-Spam-Relay-Country: X-Spam-Timing: total 1032 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 3.9 (0.4%), b_tie_ro: 2.8 (0.3%), parse: 0.71 (0.1%), extract_message_metadata: 12 (1.1%), get_uri_detail_list: 1.56 (0.2%), tests_pri_-2000: 19 (1.8%), tests_pri_-1000: 1.88 (0.2%), tests_pri_-950: 1.10 (0.1%), tests_pri_-900: 0.80 (0.1%), tests_pri_-200: 0.67 (0.1%), tests_pri_-100: 3.0 (0.3%), tests_pri_-90: 240 (23.2%), check_bayes: 227 (22.0%), b_tokenize: 6 (0.6%), b_tok_get_all: 7 (0.7%), b_comp_prob: 1.81 (0.2%), b_tok_touch_all: 208 (20.2%), b_finish: 0.89 (0.1%), tests_pri_0: 299 (29.0%), check_dkim_signature: 0.55 (0.1%), check_dkim_adsp: 2.6 (0.3%), poll_dns_idle: 436 (42.2%), tests_pri_10: 2.6 (0.2%), tests_pri_500: 445 (43.1%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH RFC] kthread: Unify kernel_thread() and user_mode_thread() X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Huacai Chen writes: > Hi, Eric, > > On Wed, May 10, 2023 at 11:45 PM Eric W. Biederman > wrote: >> >> Huacai Chen writes: >> >> > Commit 343f4c49f2438d8 ("kthread: Don't allocate kthread_struct for init >> > and umh") introduces a new function user_mode_thread() for init and umh. >> > But the name is a bit confusing because init and umh are indeed kernel >> > threads at creation time, the real difference is "they will become user >> > processes". >> >> No they are not "kernel threads" at creation time. At creation time >> init and umh are threads running in the kernel. >> >> It is a very important distinction and you are loosing it. >> >> Because they don't have a kthread_struct such tasks in the kernel >> are not allowed to depend on anything that is ``kthread''. > Hmm, traditionally, we call a "task" without userland address space > (i.e., the task_struct has no mm, it shares kernel's address space) as > a kernel thread, so init and umh are kernel threads until they call > kernel_execve(). No. The important distinction is not the userland address space. The important distinction is how such tasks interact with the rest of the system. It is true the mm does not initially have userspace content but that does not change the fact that it is a valid userspace mm. For scheduling, for signal delivery, and for everything else these tasks are userspace tasks. The very important detail is that it is not at kernel_execve time that the distinction is made, but that it is made earlier when the thread is created. This is a subtle change from the way things used to work once upon a time. But the way things used to work was buggy and racy. Deciding at thread creation time what the thread will be used for, what limitations etc is much less error prone. We had this concept of kthread_create that used to create a special class of tasks. What was special, and what extra could be done with those tasks was defined by the presence "struct kthread" (my apologies I mispoke when I said kthread_struct earlier). Then because that specialness was needed on other tasks struct kthread started to be added to tasks at run-time. That runtime addition of struct kthread introduced races that complicated the code, and had bugs. > Of course in your patch a kernel thread should have a > "kthread" struct (I can't grep "kthread_struct" so I suppose you are > saying "kthread"), but I think the traditional definition is more > natural for most people? Natural and traditional is a silly argument. The fact is those are tasks that ultimately run userspace code. That ability needs to be decided upon at creation time to make them race free. Therefore the old code and definition are wrong. Eric