Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3216267rdb; Wed, 13 Sep 2023 05:55:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmzcxBqvg+cs8+4DeORY5YgbkgCrejKGSrqdhohA/GnjhqmkTg6cjSJWS57baE/Fbt5/8o X-Received: by 2002:a05:6a20:160c:b0:13e:7a0a:36d8 with SMTP id l12-20020a056a20160c00b0013e7a0a36d8mr2636309pzj.9.1694609700563; Wed, 13 Sep 2023 05:55:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694609700; cv=none; d=google.com; s=arc-20160816; b=YDtAuuoaVIo61EstyqUWMJ+ZPUgP4t83z0wBf4Up9WfYmVj3MuohX1gBSjdONgvKZV RdSACZBoof+WrBq6SpA56YylQnGwwMcML4NDUNnUb/WGii4TwQZJhJWf1f2h69TCK3TS 4JPSdlXIleiA3ENbVhHHs/B60VAOJfE3fhBOio3f30kH1UVugjpNJR+3m67DAucuRb0Q F1VO5rhwE2fP0PpPOzE4rLwFjxU9QMcuCUNTIFCA3NbfzPMKIoajRgH93MMkVaTc9tiZ 8GI+uIMtyHbokP8qgt7CsOQnozEcrLsXEG65MrRDZ5quq1uDQFR/9pOGqeXdpr3UyAKn rQVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=jiNxbcSOLxpPnUhSZUodOD8LEFyaYcW8PqIEZ5OzHjo=; fh=VDi0j6CzAhGPFtfNxgLLgB7Zn4kZfZXHee+cAWGXhLw=; b=yckmQwdTDpH41T7GxBTw0quV+3jNPpWENEWeQu4TxOALJwvBjbPaCXAyoz8gaDiShg neOlGwH8a6u8XIt0D5x4E0KrpWdNpNL09OB+q6rMPCuS05TenvQTXC0Xp1OzwPCTs8RE 4SJxwHfuN2Ps6LvJc+6dRPbCeV7uuFhORKwJiQKuVo3dCTRVj2xZkbSG76pLR5Yrxkg+ 0TMvrNT2w9xDJoKAowpiCR4y89pkdDH4BXwsfTyFfHBEvoOd3p3q8QSfH/6j27y8IOm5 tT3mJoTe0aNfIxlWQekaV/B+RP4kzQl8GVUsIxDiBi4blRMfYRLcTF3DNgwBfeQ3KrMX /BXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Es4rxKw9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id q16-20020a170902dad000b001b6c462acbdsi10316002plx.15.2023.09.13.05.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 05:55:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Es4rxKw9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 7DC4780847BE; Wed, 13 Sep 2023 05:40:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233560AbjIMMkQ (ORCPT + 99 others); Wed, 13 Sep 2023 08:40:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231132AbjIMMkP (ORCPT ); Wed, 13 Sep 2023 08:40:15 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19E6619AD for ; Wed, 13 Sep 2023 05:40:11 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABF4FC433CD for ; Wed, 13 Sep 2023 12:40:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694608810; bh=4V8qeyNYyKzAHbUxZffZtlUMKemRi78OFAMYUMKMJ04=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Es4rxKw9xoWiu5Ku0pFilVXDAImSINpJibTZOdygZDvJYhrPP6aSUNnStcjHMtVGY BiODUMdD0BQmTEZVQVvN7SnSetss4WxX7nT60uPobHJADY0BiHv+dzDeMONmFfy6xH hxqZQCSAuhNydGWqEFTAGGUoUcmyl2xx6bzl8qITq5e1AhMjA/5CSQ6DFSQ6lLOkio 97mOiHby49qXqkZfoArNWya8nibFITeb6f2wZqBr7f5LOwP4AEuUS+GUELp4ej2+Xd GgGPcIwPNZ/rsYUGFWk3ZwWQGrV/OrcJxzENg2YCU2VwVrme0wQA83UrNr/EVdYvix l66+138v5LMdA== Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2bfb0a2682fso20718541fa.2 for ; Wed, 13 Sep 2023 05:40:10 -0700 (PDT) X-Gm-Message-State: AOJu0YxxsHHxayE0U4o/s57JtkVZrsRRHMb5zx3+8yX5YAbT6yzm4Xdk jQjjzZhPMZfqaJsu2Gechi1oXVqkvLsRdHPDJzo= X-Received: by 2002:a2e:928a:0:b0:2b9:ecab:d924 with SMTP id d10-20020a2e928a000000b002b9ecabd924mr2055184ljh.18.1694608808577; Wed, 13 Sep 2023 05:40:08 -0700 (PDT) MIME-Version: 1.0 References: <20230615121016.3731983-1-chenhuacai@loongson.cn> <87cyyo9moz.fsf@email.froward.int.ebiederm.org> <87a5tr1eri.fsf@email.froward.int.ebiederm.org> In-Reply-To: <87a5tr1eri.fsf@email.froward.int.ebiederm.org> From: Huacai Chen Date: Wed, 13 Sep 2023 20:39:58 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] kthread: Rename user_mode_thread() to kmuser_thread() To: "Eric W. Biederman" Cc: Luis Chamberlain , Huacai Chen , Andrew Morton , Kees Cook , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Thomas Gleixner Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 13 Sep 2023 05:40:17 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Hi, Eric, On Wed, Sep 13, 2023 at 1:30=E2=80=AFAM Eric W. Biederman wrote: > > Huacai Chen writes: > > > Hi, Eric, > > > > On Tue, Sep 12, 2023 at 9:59=E2=80=AFAM Eric W. Biederman wrote: > >> > >> Huacai Chen writes: > >> > >> > Hi, all, > >> > > >> > Friendly ping again? > >> > > >> > > >> > Huacai > >> > > >> > On Sun, Jul 23, 2023 at 10:13=E2=80=AFPM Huacai Chen wrote: > >> >> > >> >> Hi, Eric, > >> >> > >> >> On Tue, Jul 18, 2023 at 8:43=E2=80=AFPM Huacai Chen wrote: > >> >> > > >> >> > Hi, Luis, > >> >> > > >> >> > On Sat, Jul 1, 2023 at 7:25=E2=80=AFAM Luis Chamberlain wrote: > >> >> > > > >> >> > > On Sun, Jun 25, 2023 at 04:55:33PM +0800, Huacai Chen wrote: > >> >> > > > Friendly ping? > >> >> > > > >> >> > > You want to cc the folks who Nacked your patch. Until then, thi= s > >> >> > > probably can't go further. > >> >> > Thank you very much. Eric and Andrew are already in the CC list, = so > >> >> > add Thomas now. > >> >> > > >> >> > My brain is a little old-fashioned so I insisted that "a thread > >> >> > without mm_struct should be a kernel thread" in the previous patc= h. > >> >> > Unfortunately this makes Eric and Thomas unhappy, I'm very sorry = for > >> >> > that. > >> >> > > >> >> > During the discussion of the previous patch I know I made some > >> >> > mistakes about some basic concepts, but I also found the name > >> >> > "user_mode_thread()" is somewhat confusing. I think rename it to > >> >> > kmuser_thread() is better, because: > >> >> > 1, it identify init and umh as user threads; > >> >> > 2, it points out that init and umh are special user threads that = run > >> >> > in kernel mode before loading a user program. > >> >> > > >> >> > Sorry for my rudeness again. > >> >> Excuse me, but could you please tell me what your opinion is. In my > >> >> opinion a typical user thread is created by > >> >> pthread_create()/sys_clone(), it is better to distinguish typical u= ser > >> >> threads from init and umh. > >> > >> If we want to emphasize that it is a kernel concept I am happy with > >> renaming user_mode_thread to user_mode_task. That is more accurate. > >> > >> But all threads from the kernel perspective are tasks. Further > >> all threads have times when they run code in the kernel (aka system > >> calls) and times when they run code in userspace. > >> > >> Linux kernel tasks created with user_mode_thread() are exactly like > >> other user mode tasks, and have all treated exactly the same was by th= e > >> system as any the tasks created by pthread_create() and sys_clone(). > >> > >> The only oddity is that there is no user mode code to execute until > >> after execve is called. > >> > >> When running code in the kernel, user space threads never logically > >> do not use the user space page tables. > >> > >> They are different in some significant ways from tasks created with > >> kernel_thread(). Tasks created with kernel_thread do not support > >> calling execve, among other things. > >> > >> But deeply and fundamentally I think you are trying to make a > >> distinction that is not there. All user space threads run code > >> in the kernel before they run code in userspace. Most often > >> it is from the system calls fork/clone/exec. For init and umh it > >> is effectively a special dedicated system call that includes > >> an execve. > >> > >> Let me ask what difference are you trying to high light that callers > >> of user_mode_thread need to be aware of? What problem in thinking > >> do you think that the name user_mode_thread creates? I am asking > >> because I might just be missing your point. > > 1, My first key point is =E2=80=9Cintuition=E2=80=9D, by intuition > > sys_clone()/pthread_create() creates a user thread, but init and umh > > are more or less different (special user thread). > > My point is the entire point of the name is to point out your intuition > is probably wrong in this context. In another thread I had said that init and umh are special kernel threads. But after your patient explanation, I admit init and umh are user threads now. However I still don't think they are completely the same as pthread_create()/sys_clone() so I say they are special user threads. kernel_execve() makes init and umh user processes, but the call to kernel_execve() is the internal logic of the created threads, this logic has no direct relationship with 'user_mode_thread()'. And it is also difficult for me to consider 'user_mode_thread()' as "a special syscall", because syscall comes from userspace... > > > 2, My second key point is "symmetry", for symmetry =E2=80=98kernel_thre= ad=E2=80=99 is > > a counterpart of =E2=80=98user_thread=E2=80=99, while =E2=80=98user_mod= e_thread=E2=80=99 is a > > counterpart of =E2=80=98kernel_mode_thread=E2=80=99. If we keep the =E2= =80=98kernel_thread=E2=80=99 > > name, then we can only rename the =E2=80=98user_mode_thread=E2=80=99. > > Frankly they could just as well be named user_mode_process, > and user_mode_task. All are equally accurate. For me, 'thread' in the name has no problem. because 'task' is a general concept, 'process' is a 'task' with independent address space, and 'thread' is a 'task' with shared address space. I want to remove 'mode' because I like symmetry, and Andrew also thinks that 'mode' is superfluous. Again, I admit init and umh are user threads, but they are special so need a modifier. This modifier can be 'km' (stands for 'kernel mode') or 'kc' (stands for 'kernel created'). Huacai > > kernel_thread is a bit different. Strictly speaking they are all > processes that share the same address space. But because they > all share the same address space and userspace can't touch them > thread is a perfectly adequate term. > > > As discussed > > before, init and umh are user threads, but they are special user > > threads run in kernel mode before kernel_execve, so I want to rename > > it to =E2=80=98user_thread=E2=80=99 with a 'km' prefix, so =E2=80=98kmu= ser_thread=E2=80=99. > > My deep and fundamental question to you is what technically makes umh > and init special? > > What are you trying to point out to the rest of us with an improved > name? > > I want to point out that people need to treat umh and init as user space > processes, and very much not as kernel threads. That none of the > kernel_thread infrastructure works on them. > > Eric