From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FC57D2E002 for ; Wed, 23 Oct 2024 00:53:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FBFE6B00B8; Tue, 22 Oct 2024 20:53:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 984F26B00BA; Tue, 22 Oct 2024 20:53:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 825E16B00BB; Tue, 22 Oct 2024 20:53:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 618536B00B8 for ; Tue, 22 Oct 2024 20:53:16 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C49E740671 for ; Wed, 23 Oct 2024 00:53:06 +0000 (UTC) X-FDA: 82703042310.09.5C86442 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) by imf02.hostedemail.com (Postfix) with ESMTP id 31ADF80009 for ; Wed, 23 Oct 2024 00:52:40 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=PQFr+82T; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf02.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729644671; a=rsa-sha256; cv=none; b=QbbVc+7ikIltGJEEp45IotD777VT68boUKdBqHzDq8krBH0waKyAW7Su6WEEo/DyBGSCNy z8dI9R3TCBlFDSu0WNp5rKgyvrO9uSI0rqVEcgpc0CWJGjNwliW8GYP99lxNzUbcy49zaL UjdkcN0h67Fn/pRCmLVbsIgHkQ7/ER4= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=PQFr+82T; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf02.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729644671; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6kCNsEXTfjhm2VD7RcuSJFj1WDFRY4+e/zOdiNTxOWg=; b=WtgeQ12Oua2z2ebjo+VGlFp5D3XSXeu8BFbPK7UtEc2bv5Fw/e+Ps8UCqozd6FJs0yBgGj wP7cgo6SMI9G/EcfBHIkRyzBk3IJ4Q5uQJv0xg+T1iysktskUpsg3NvE9riPHWIyTPQ5Hw /petX5PvLZPdkFEFXHmtwyttPsEgr8w= Date: Tue, 22 Oct 2024 17:53:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1729644789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6kCNsEXTfjhm2VD7RcuSJFj1WDFRY4+e/zOdiNTxOWg=; b=PQFr+82TnUdLaIYZFFzshQFVmAmk1Yd7+0V/csbKw1Q5g5ouUoT7Egf2+eOTF9SVzA6x3K XlThe6JZGnxty58saIYF+G6jJ8wg1xPOeZdmiXyXDSIfO6cjO9eniEPWJTBAIqbRCz/E+W cQWGDsXIMg4UcpTrpNJLEGFUKjgsf2U= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Lorenzo Stoakes Cc: Christian Brauner , Shuah Khan , "Liam R . Howlett" , Suren Baghdasaryan , Vlastimil Babka , pedro.falcato@gmail.com, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Oliver Sang , John Hubbard Subject: Re: [PATCH v4 2/4] pidfd: add PIDFD_SELF_* sentinels to refer to own thread/process Message-ID: References: <3bf7f2d8efc768007b5de8122275405afc9942d4.1729198898.git.lorenzo.stoakes@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3bf7f2d8efc768007b5de8122275405afc9942d4.1729198898.git.lorenzo.stoakes@oracle.com> X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 31ADF80009 X-Stat-Signature: 6m5ro53oikmohw7pof3e4r8o5n6q4ax6 X-Rspam-User: X-HE-Tag: 1729644760-103126 X-HE-Meta: U2FsdGVkX189wZK7OVrP2GdWLv06qKRBIGUXn8lje2MNhap9qbMR/35ej7yqFNf9radUBQJcoowbdPQ6sGu4Ouk41I3Cp0qo+8+LDydhXKefYmk08Dq7IxXEKVXv/FK3h4oDzjy+PeVWVtLWOznC++sBtf4/krCtJgumeJh0K7Ka+gbRj3+gnW96Z6NkyFIG8ZWqfwqGcAbigrpFx1TXGRVwjmIFIKfwUkeGQh4NPdS5frO2sd1+O3xFkA2Q1LeMY60/cu8HmqZ91L6f70wPqmf8dBQuQmB5vJIdEAQpKAYApkhAZCmqKn44Fjk0lGXQ08NlEkexwir2PlajXG909e4kLWURDXxD/avxVZHnttrohvm8vrkk1/7NKUbp58CYM0dTvfXADK1MdHdArc3fn+7X53lsApfLah6e3DpL/82G36NuVWw8RkIo0kGd2agj9HkkEK6cdXUKCGiBwYKSN0wY8w3kteaIDW5gzxgmWVQJ/JVQfHA2Dr5TmYiR4Z5X31fyhzZD9/kKg0/iHph5bNbhuFbqEDj2bS+5A/fz0pcnwOdLgR6YlO21aY7iEuFm6CUh0TvDy4S06aFnLEPlzOBNHv2+DYoAI31eY/ZJpf2l9rShMH7dkXaOvFOZVMeO4nje2qQO3xJPrELExTjFT/LAqArhMYizMPoky/fTj9Mzrn1a6ajprt5CoycErIxN+qIwi7+ni28NMNd3SiobpMyq+Waxnc91wMzQzCAhkR+8S+Tafj4uHSFwqUcQNxOU99un5jUn0gHza1VJCceMLsCsIsK80ML+5MiCjxo+8+3xJ56D0/L+0atAPTrZGPF0RuJSn62Zvj/gVSAqblBdTHbANCY5sTaX9EKM+FJSEVujzdGsf+pzEFuBOm4rRvWr5pxRWzrBifqrHTRdsjAqAu3FeElt4oOnrC6UI50hw5En8KTGx8N3GhMNG/Rfy88uldxPAEOqB8VbNomzDVc YQoKPd0U YeJR8wEhsxYc0Reuuu9IiAWkmwDcA0cUQO+itsghZK6mh0PI10AVmx628rlHJ/LXDR53ubWxa3oCYMX+P3CoFuO1gUGMGQXmSsJnNVk7Z6TyHc620k4q5M1NqRQ9Ts6uFXKLLysIv7rR7WTe2GIlNKgB6AsKI7SpNcRtCJD1P98tjqEYN5JJWmqEo8mcGf4NPA2tCpbxmpZhw9W7kevERz0BhQf1LNdxzTBp/Til/412fVr7vPi/mTMxvFqnwverU13eTLqZHDtyk7y0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Oct 17, 2024 at 10:05:50PM GMT, Lorenzo Stoakes wrote: > It is useful to be able to utilise the pidfd mechanism to reference the > current thread or process (from a userland point of view - thread group > leader from the kernel's point of view). > > Therefore introduce PIDFD_SELF_THREAD to refer to the current thread, and > PIDFD_SELF_THREAD_GROUP to refer to the current thread group leader. > > For convenience and to avoid confusion from userland's perspective we alias > these: > > * PIDFD_SELF is an alias for PIDFD_SELF_THREAD - This is nearly always what > the user will want to use, as they would find it surprising if for > instance fd's were unshared()'d and they wanted to invoke pidfd_getfd() > and that failed. > > * PIDFD_SELF_PROCESS is an alias for PIDFD_SELF_THREAD_GROUP - Most users > have no concept of thread groups or what a thread group leader is, and > from userland's perspective and nomenclature this is what userland > considers to be a process. Should users use PIDFD_SELF_PROCESS in process_madvise() for self madvise() (once the support is added)? > [...] > > +static struct pid *pidfd_get_pid_self(unsigned int pidfd, unsigned int *flags) > +{ > + bool is_thread = pidfd == PIDFD_SELF_THREAD; > + enum pid_type type = is_thread ? PIDTYPE_PID : PIDTYPE_TGID; > + struct pid *pid = *task_pid_ptr(current, type); > + > + /* The caller expects an elevated reference count. */ > + get_pid(pid); Do you want this helper to work for scenarios where pid is used across context? Otherwise can't we get rid of this get and later put for self? > + return pid; > +} > + Overall looks good to me. Reviewed-by: Shakeel Butt