From patchwork Sat Oct 26 07:24:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 838882 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68C4F13BAE7; Sat, 26 Oct 2024 07:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729927530; cv=fail; b=fmlmMOOXzShgEgIb2Da2NAikQAjfhyjI2ThZIdtnE2l/n0h6fagc1cXZ8acqc4WlXPHWdyTYPA6WeJXbieyKcuPhouqv0HZso0WXycULWxEgb51TF0R1ma2VWOVfeFRyaIuTgEaCyLo4hILmNyX2q5S2KBxSZ0+Cd/O3/AfJFNg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729927530; c=relaxed/simple; bh=1GpvADSqsq4tnlLFx3u4o6Wwyrnin5JiXLi20OUiVgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Z87dMTvZciOKunQfUXN840bacnbllGTPNFLeAIfuVKxXSMW+U4FjYM4LH1EAZXNFcWDQ4GHf/Xx8th+2kPv7IARN9e5ehQV7rlX0YS02GYwf4Bcel0ZolY046fz3o6q/ZatqCJu6kb42bYoJ6uUvVlQJPR0saFFPNU9OVkrO1sM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=GAGewO8t; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=ziQTk4gS; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="GAGewO8t"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="ziQTk4gS" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49Q3JgJP012970; Sat, 26 Oct 2024 07:25:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=ysaPi8DTdXVgT7KKevj+tCObGLJIis9xvmd4QhwzTz8=; b= GAGewO8tTWzaTK//HW+fhgGnno7PPrGkRb/kIAtH3lM3prIfv+LYUFTwZmcilNVf iI8fhCkgWeEQ4nmakKDBzdHK7QZ2A44/Zur4jVTXKGCPaTUkkklVkeARvLxbuOxf v0xjBONKp4B1MDc6bJt8TliUTu1Am+JbxDPpkOFHdvPgklHXzFLAeC4IvYDxoEOA jnzfcgycvgJA5mhtY1WZwOr5Kb5NO+/oFv7VaES8Fu4rPekFwuHsjACUD6SeWcRW YLK8cVuyED+vv97WVZjUagDTFWxtTuglgSbcq1aUXHmFkByx1bfkpB0CWcs2371P IPAl3Ln3mU9nZ6YyeLhMrg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grdq84m5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 26 Oct 2024 07:25:13 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49Q3DnSq004393; Sat, 26 Oct 2024 07:25:12 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2045.outbound.protection.outlook.com [104.47.70.45]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42gpvaddaf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 26 Oct 2024 07:25:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sIZIYXgoEWDtreLmcjhbLHDJeWYiDxCiTiVWwQgRdDF3IgML6fW65byngz1Pu7lejA+3wkG1WuYTEb1RZ+QHldbAZ7kvQ3He51Jjaml3ATWAmUylOFS0RHTBrWX3DN+STQOVr1HSRFEOCmknJO2TC07f7DR2tGnj9qQeb7WoTGZBO1TCTGlYYY+xYSNY9kBP0WB8BJIOYnL9djipoWS72DrFe/ZAZj3JLmNiOmHeJnF1MzQCJQDH3MusdAw6i4k7n/CThPATMktUvCweloZB1agaCrwIPnkNg5Q7+Wi7/yjSmsNEBXeOEpu3xTIM918D/eZsN8PH0vfPA7VOoyR+ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ysaPi8DTdXVgT7KKevj+tCObGLJIis9xvmd4QhwzTz8=; b=Rj4ttO5m1couZ0t757d4YIKH1inbhju5RBz0Ljszk5cUF+kXh0Oj8amOruaHWx7D6DpRCjo31FUxmIyh801Ft0fJUYPkCXe+E5RSzp+9DhtLivA7Ribn+6oNe6FPKwEvKpxIVmdSH3pragbHuW9Mom7GTka1N8zaV/jUT7NHlSucBEVNx127aWrWQeu2DrnQL9KO8mhTtKLJN3U6ZuxL4HVcTlR2n7KoL8tAt4UF/z2Wp/9unx465NwCajYLED83P62rqjrcd3rghKvVUtbWeADmkexYqxXjJu2kuVSkH9B7fiN/kcdefcVLEkrb6cjLJJXJTUpqnGOzGftauZxItw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ysaPi8DTdXVgT7KKevj+tCObGLJIis9xvmd4QhwzTz8=; b=ziQTk4gSeO9xtNFwiRkSJjuP7Yo7O25I9Nq6vkRCkqOgM/fVG6V06MbCKCFHWSTXcp3yFHMRWQVc5ms5kHcA0rnhGGGNHb7YNz8WbpaUt+VeaVxLCbxpmFzxAVvz+N+K5WKJKZ5ZYe0q05TUmC5gna7h8sQEzriA4JtT+IviTRA= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SJ0PR10MB4543.namprd10.prod.outlook.com (2603:10b6:a03:2d9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23; Sat, 26 Oct 2024 07:25:10 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8093.014; Sat, 26 Oct 2024 07:25:10 +0000 From: Lorenzo Stoakes To: Christian Brauner Cc: 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: [PATCH v6 1/5] pidfd: extend pidfd_get_pid() and de-duplicate pid lookup Date: Sat, 26 Oct 2024 08:24:57 +0100 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LNXP265CA0015.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5e::27) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|SJ0PR10MB4543:EE_ X-MS-Office365-Filtering-Correlation-Id: c05217eb-4440-417a-ad7f-08dcf58f5329 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: oZ3SFKdHgje5eXDvuQbRKET7S3nY+TkEX3a560LEjgiy/SD6zib8F4JvjHK7bOF+m6B+zVIfulr6TFwE/WrrU5cR0yIqBzuuJOnKfMt0CX/wRV6HD53S5Im8+bvXsiLT1t4O8PswYxpT21cjtp3RFo9U8RqkV7werDouagJpucA+bFVIXK467ae3DoSG33Fffqsx1/eSK1jMtg7EmI69zLOepFlV8dVEUlEFSRU3gAfk9rOS9m9igetjknQM8MTzfHnw8t0nZnUaDTk2ELK6fQNvFq6Ph1Tw30mR6WuGWQU1Rdh4dk9j1xosPDzADScgVXj6e4f53r2G4W5pukjC57YjJAomlCdX3d0Yp3dlhFtdkp0fP+4DlbyS6OD4GIx00ShUTd0XueZWjfHZBz5XJFvcJgijp+FspWlFhp8ZJskeJpuKHXj/YpvNLNSNwBWl3yfDn+klKhIXZcDA7734zKd71P/8WeD+qjqRFElJq60/V6ewjlAxZR8xyiCFLhLfipGpTSBuK2c7oBZB+3LMwiXdDbpfzLTfac0qlyzodjmwReqFj4S/pV3EZfTes1qLn0Z48Us+IHqUrDgpvuqA+ApT3byBu7oyzVWqspCig5ddyS38RLcyOCNEG98sSou1c6pdI0LI7PVRN5m+cKobAOzLm6TmK76WR7r//cuEVlzJ2dmtet9UDJn9v0e5k8XZHY18er/zYdx8RVGc96Je3uyxwka+sjM5vj1HsOICLyYPTduJLzEzwypHuQClX2H1ouyfxL8GV6cbTfdaRIcm3ilMptOaBj2ycNzFzxGcfqhn+Y7JdKrqhBtqEFdumVducDEUK2Y7dI8xk7yfUCI9JNhqcY2GHuSYHyl0ERDSBCX2V8b1DR2hX67gAfuBLdzE2yXrfA0oHa9HEkovw/ZWFJE9nwR7D/KtBRLLDPZQHCTkxcLIhQFHMkj2+Ao0KZyogKpgTtRWjA6H2GDOHxt70YodajD1cs7FzCGcDM9ELWUIMNa04UYUhd44vFsH6awbyf6Nyie831XZjKnx5yD3tzNbDi58vO6+ce+q79p2BE/DWwvHXCT6YeUlZgFuOQmCC/f04/HLz3iJgGcgXm+t7dJKWP3qU7JCGH2LfvrEAlvTQDW7vNJiehyxExKIQqYSFYH7iavuMexs1JNlZEjJWq8Rn+TUxI2Qjy4exBrzUL2Ae+WoRwO1NP3+IUrmnomE+aQqdGhicNjADg4fbt2TMIhJ37OHoJv4ELJGW+MJyZG6fGc42KmyJK0OfSFm7ra6OriuLq5Rwss39f+gZIkR4PUi+Ese4F0dFGKgBkHaKxhuAKVDEik0qhvr2nmxguyB X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB3366.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(7416014)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-Anti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apb8DS082CJKrr0Qk8CQFDEFnLV2eiqvIN+tLFuCkHssI7IVTn0iK8BtyIem91yA7Dj7ahKZmxspER25qxM+Axh942MGcAnTuGON0S+Nzk5kIouZQhdKSgnWhgXYjnesKu7RW9jPKXM+WThuF0lo5SEJVs66xBzGFEXbStETtyz+Ho+XZGvB/nPtT+6TILgZpdyDD4E/nvGhOo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c05217eb-4440-417a-ad7f-08dcf58f5329 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2024 07:25:10.6290 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: b2JItDQRoB4Nw1G0Xl+VIjGtGBb53CxFCxNaxlBqd/sZpd8W1lEz1wURzlp/FnuMFU4m5/vOG0atlW8m4iaNLTu8dqPxxBTQKDj0FCNvZxs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4543 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-25_14,2024-10-25_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410260060 X-Proofpoint-GUID: 4VBHUktliZglGhPqbtwc-fvR6CZ04yP4 X-Proofpoint-ORIG-GUID: 4VBHUktliZglGhPqbtwc-fvR6CZ04yP4 The means by which a pid is determined from a pidfd is duplicated, with some callers holding a reference to the (pid)fd, and others explicitly pinning the pid. Introduce __pidfd_get_pid() which narrows this to one approach of pinning the pid, with an optional output parameters for file->f_flags to avoid the need to hold onto a file to retrieve this. Additionally, allow the ability to open a pidfd by opening a /proc/ directory, utilised by the pidfd_send_signal() system call, providing a pidfd_get_pid_proc() helper function to do so. Doing this allows us to eliminate open-coded pidfd pid lookup and to consistently handle this in one place. This lays the groundwork for a subsequent patch which adds a new sentinel pidfd to explicitly reference the current process (i.e. thread group leader) without the need for a pidfd. Reviewed-by: Shakeel Butt Signed-off-by: Lorenzo Stoakes --- include/linux/pid.h | 30 +++++++++++++++++++++++++++++- kernel/pid.c | 42 ++++++++++++++++++++++++------------------ kernel/signal.c | 29 ++++++----------------------- 3 files changed, 59 insertions(+), 42 deletions(-) diff --git a/include/linux/pid.h b/include/linux/pid.h index a3aad9b4074c..d466890e1b35 100644 --- a/include/linux/pid.h +++ b/include/linux/pid.h @@ -2,6 +2,7 @@ #ifndef _LINUX_PID_H #define _LINUX_PID_H +#include #include #include #include @@ -72,8 +73,35 @@ extern struct pid init_struct_pid; struct file; + +/** + * __pidfd_get_pid() - Retrieve a pid associated with the specified pidfd. + * + * @pidfd: The pidfd whose pid we want, or the fd of a /proc/ file if + * @alloc_proc is also set. + * @allow_proc: If set, then an fd of a /proc/ file can be passed instead + * of a pidfd, and this will be used to determine the pid. + * @flags: Output variable, if non-NULL, then the file->f_flags of the + * pidfd will be set here. + * + * Returns: If successful, the pid associated with the pidfd, otherwise an + * error. + */ +struct pid *__pidfd_get_pid(unsigned int pidfd, bool allow_proc, + unsigned int *flags); + +static inline struct pid *pidfd_get_pid(unsigned int pidfd, unsigned int *flags) +{ + return __pidfd_get_pid(pidfd, /* allow_proc = */ false, flags); +} + +static inline struct pid *pidfd_get_pid_proc(unsigned int pidfd, + unsigned int *flags) +{ + return __pidfd_get_pid(pidfd, /* allow_proc = */ true, flags); +} + struct pid *pidfd_pid(const struct file *file); -struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags); struct task_struct *pidfd_get_task(int pidfd, unsigned int *flags); int pidfd_prepare(struct pid *pid, unsigned int flags, struct file **ret); void do_notify_pidfd(struct task_struct *task); diff --git a/kernel/pid.c b/kernel/pid.c index 2715afb77eab..94c97559e5c5 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -534,22 +535,32 @@ struct pid *find_ge_pid(int nr, struct pid_namespace *ns) } EXPORT_SYMBOL_GPL(find_ge_pid); -struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags) +struct pid *__pidfd_get_pid(unsigned int pidfd, bool allow_proc, + unsigned int *flags) { - struct fd f; struct pid *pid; + struct fd f = fdget(pidfd); + struct file *file = fd_file(f); - f = fdget(fd); - if (!fd_file(f)) + if (!file) return ERR_PTR(-EBADF); - pid = pidfd_pid(fd_file(f)); - if (!IS_ERR(pid)) { - get_pid(pid); - *flags = fd_file(f)->f_flags; + pid = pidfd_pid(file); + /* If we allow opening a pidfd via /proc/, do so. */ + if (IS_ERR(pid) && allow_proc) + pid = tgid_pidfd_to_pid(file); + + if (IS_ERR(pid)) { + fdput(f); + return pid; } + /* Pin pid before we release fd. */ + get_pid(pid); + if (flags) + *flags = file->f_flags; fdput(f); + return pid; } @@ -747,23 +758,18 @@ SYSCALL_DEFINE3(pidfd_getfd, int, pidfd, int, fd, unsigned int, flags) { struct pid *pid; - struct fd f; int ret; /* flags is currently unused - make sure it's unset */ if (flags) return -EINVAL; - f = fdget(pidfd); - if (!fd_file(f)) - return -EBADF; - - pid = pidfd_pid(fd_file(f)); + pid = pidfd_get_pid(pidfd, NULL); if (IS_ERR(pid)) - ret = PTR_ERR(pid); - else - ret = pidfd_getfd(pid, fd); + return PTR_ERR(pid); - fdput(f); + ret = pidfd_getfd(pid, fd); + + put_pid(pid); return ret; } diff --git a/kernel/signal.c b/kernel/signal.c index 4344860ffcac..9a35b1cf40ad 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3875,17 +3875,6 @@ static int copy_siginfo_from_user_any(kernel_siginfo_t *kinfo, return copy_siginfo_from_user(kinfo, info); } -static struct pid *pidfd_to_pid(const struct file *file) -{ - struct pid *pid; - - pid = pidfd_pid(file); - if (!IS_ERR(pid)) - return pid; - - return tgid_pidfd_to_pid(file); -} - #define PIDFD_SEND_SIGNAL_FLAGS \ (PIDFD_SIGNAL_THREAD | PIDFD_SIGNAL_THREAD_GROUP | \ PIDFD_SIGNAL_PROCESS_GROUP) @@ -3908,10 +3897,10 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, siginfo_t __user *, info, unsigned int, flags) { int ret; - struct fd f; struct pid *pid; kernel_siginfo_t kinfo; enum pid_type type; + unsigned int f_flags; /* Enforce flags be set to 0 until we add an extension. */ if (flags & ~PIDFD_SEND_SIGNAL_FLAGS) @@ -3921,16 +3910,10 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, if (hweight32(flags & PIDFD_SEND_SIGNAL_FLAGS) > 1) return -EINVAL; - f = fdget(pidfd); - if (!fd_file(f)) - return -EBADF; - /* Is this a pidfd? */ - pid = pidfd_to_pid(fd_file(f)); - if (IS_ERR(pid)) { - ret = PTR_ERR(pid); - goto err; - } + pid = pidfd_get_pid_proc(pidfd, &f_flags); + if (IS_ERR(pid)) + return PTR_ERR(pid); ret = -EINVAL; if (!access_pidfd_pidns(pid)) @@ -3939,7 +3922,7 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, switch (flags) { case 0: /* Infer scope from the type of pidfd. */ - if (fd_file(f)->f_flags & PIDFD_THREAD) + if (f_flags & PIDFD_THREAD) type = PIDTYPE_PID; else type = PIDTYPE_TGID; @@ -3978,7 +3961,7 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, else ret = kill_pid_info_type(sig, &kinfo, pid, type); err: - fdput(f); + put_pid(pid); return ret; } From patchwork Sat Oct 26 07:24:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 838881 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5EAC192586; Sat, 26 Oct 2024 07:25:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729927539; cv=fail; b=ePW6NPYMEvrUWhioGj9LESvN4A+8/ccqGoxXDr0uLonJXvZLsoHNtLRgr23iGC5WJQpE2/Dq4UCJ+492SmE1bnG+s/A6PT+IFttYtRmWcR7/ugq8IEJZi3LuvVQxj/2o7pIfhGzZCtqCgvOMhNzuUodr0DHt3m/UmWQjteg/AhU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729927539; c=relaxed/simple; bh=YAL4uH7qzxdEpQx7rIRDZYNT+L2oPes1YFmGpVufLok=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=dZtT5GF3qLGC545FUqWr3LEKfOqQiOwe8Zi50BiWocIvdaPrnplP9Wvmv6VFMgDW96nkDOKpxig1PZS9bCwbXMHgbKeoyxjpddzmq7nbIjyvdrsrNrJ0oKK630e+kP1u0l8a9hsyMKGKFqz1pCoWtaNa4+io6qhP+Kfw8j5LBog= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=aRK2Fv2U; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=uz6EpHGz; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="aRK2Fv2U"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="uz6EpHGz" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49Q5qD04013183; Sat, 26 Oct 2024 07:25:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=93AZ6BG56bmfV9M0Ek0gTeDCqx9TsJGx9O40zGmQoQk=; b= aRK2Fv2ULY8QJBV43POrC1wseTUg54Q45be6zn3iRebWEisj/2FlQhkaQBe2K+NX 1gOT0YmR+t7LgLrPW1BfT45VqZOe951oYipgKdHl0P7TkdUYzi7NZucJB3nTBmCV sxYJP4M/mXx5y5/2zqmYQvmhBBC1sjdzwTI8CE9Gj3Ew0FgWLaQqZbCZWfdXxTa3 2dyS5zNeZ2DOzfnD8HyZToMqqBwiX/TmwAzIqsg0fU7y9C8pCGz1VdO1+aufEwp7 Gw2wUWdgoBcmXYlRJDzeHA/o7fqwq7M+Gm6tAQt/xgquB0tG+EN0CSbW05WC6YZO p3CfaX9XBLfMy39DUVoINg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grys0444-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 26 Oct 2024 07:25:17 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49Q3DlB0019193; Sat, 26 Oct 2024 07:25:17 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2048.outbound.protection.outlook.com [104.47.70.48]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42gpv3vu3x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 26 Oct 2024 07:25:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aPGl8e5Rely2S3A6zAysVRjpwRY0R4xcHm0KxsTGV5ix768Nr49uKq0PBLhKZlSavxnUkaLJsj89Wrc23EhKPXIm978TE/+k/3MMQPLSKHnHn/P5FOJCjORYSQ2EZl6NtQnof6JInwh9InkQlbMS2jTTsId4oQSEivVsGINdP0ull5GBTEW2/K+SCnPB0DKiYOaVb9bt8vQLyDt7/gacCxFF4bxmNkx3Ul0+49wABogWqLmpeutCTcohetXp04usNHUwj+BvdN/sqZOahfItczOaLRf+X9KM+ts1KQWOKaZcqdPn2vedt18pi+F+tc3/BDDvrvsyhag3cMKQlJqPcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=93AZ6BG56bmfV9M0Ek0gTeDCqx9TsJGx9O40zGmQoQk=; b=Z54XVg+abTHJ5hDfJPiFnCH3qqgAWS0rLKYi0zUgTUIJg5qt/xCGEEgUr1QQA6gcOydsN2NlAVndgQryUcr1wyE2VIwpmUF3CxyOHTn/coLxAwLinFuyG+8/5hefR1EU7LhDnhdfoHGRjJ4oqfZVMsEQNW03iTKyvnLgKC88D+zrzMg0XOYTitMNdZ+99b+lgiqBXU9jXEmpTrlb9S9RApqPYGy1jI5xxvNF6L5usJuDDW8YfFBiCJXa4HBL06Ut+nEq8aM6SfTVmG4D58pWnpG1yhEx9UcqJsy/DTBVBSZswqt7B+iZsuQKCjVNykMhwWhvd/UpeAPOw+zs/NPq6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=93AZ6BG56bmfV9M0Ek0gTeDCqx9TsJGx9O40zGmQoQk=; b=uz6EpHGzatEkGT7WfU+xtID3ZGBE+27NtJCaT9fiJ9/RazGWsheT121U5fIRsfOYxP/fyLv7Y3lr2dQLtgpPZYasrnQ+9CHcpk8zH/5ghccRV+O3I5hNz4jRTAKuqUJRoXI8wHhbkNdYjUqr/N2Mo5lF7Qf/TfDgLUTsdAA3cgw= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SJ0PR10MB4543.namprd10.prod.outlook.com (2603:10b6:a03:2d9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23; Sat, 26 Oct 2024 07:25:14 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8093.014; Sat, 26 Oct 2024 07:25:14 +0000 From: Lorenzo Stoakes To: Christian Brauner Cc: 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: [PATCH v6 2/5] pidfd: add PIDFD_SELF_* sentinels to refer to own thread/process Date: Sat, 26 Oct 2024 08:24:58 +0100 Message-ID: <8eceec08eb64b744b24bf2aa09d4535e77e1ba47.1729926229.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0570.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:276::14) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|SJ0PR10MB4543:EE_ X-MS-Office365-Filtering-Correlation-Id: 98aa9585-7f16-476c-6126-08dcf58f5562 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: 4UNGFj3RG/4r4OyRuOmt0xlf3OQsgGGyY4Dx37lUJL4LK7UNVDDa55cVAIW+ZhHlXaDr5BUhM2L/a+h9ylyZf8ZKSMzw8HAi0dP3HSHrwJY+5h09tO+z4pYexk3L0/yAdLj2P2bS5d3fJZqv1y5jyXJbOJyfcl0pYXePQU1DFRRMXq23PfRglXMLxSamdOFEjLQpJe5x11kXUMJUjgclc46mKBMf1nC4FWBBpunyokNIfMH2hDTocH5lo7KPM69ojF4WdqeUvvdcnQxLEXwp2iAKUUl1kcpx9a3BGbOEoOaUP7SiM46GNkcS8I4l2uTZ0ehOXseuKtUM0AKsK5F/oOiyedclso6aLbcKpP19bsoSnE5OCLRAY3qZxl/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; CAT:NONE; SFS:(13230040)(366016)(7416014)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XyB5VJWFYfG/13+5YC3i+WShc13Aa6YSjGCGkGwH5yNPuF7sziUV/G86F1o+eME9cDcIBOUZIOPS/hSCgphziGe8nVszQKyn2nHe/1FC7F8jWHSlDXTP/FrKA6CpBtTrFZBrPTTM98zFnGhg+fifu6qMyn/FV2joewqMfPeN8Z2JTh3R6/y3a5Jc0cX9sQddZcFaUUu6ZUdbMV3FOc5cnFn/hWT+oxYbP8X561zeZulVVcdpo2SIuql5VWJci2gEwbtHtN0TmFLAruV9eRZZNkKqoPgOTvMcbwgP67H0siREN8ufYN2NIrAOtaFe4wYMJXmmUqC8m30Jo8TlD4jDYVObkA8jhRQaiq4TiPLtwBWr1eam0GvKFCYKDfooBD9QOAY5uLfVvG4uNbxgYdKnGq3IkP8G+Qevb60CwC4wqU7dre2K2WV6ZU1XE3LSoFmOoRDUPghdiEZ2TLwKP/Fe8O7P8UMAU0TTylLNA7Pyf6Ve/7rJJNFb/kZXs/dFQNEcQMmz7qrKNe6LB0uoEx8JsYwqrC0+Yp4ra8tl2W5LysfIltFkx64Jo0ywa2Qmbc6Lj/6hGkYcmdyglNhi85jhKF7X1Vso9DI8h4qrhBgsz1pzg4Th+w5mbynT42bblqR42rR9aB4HdZhfyEBFHDy85INTdTvWGA2z+Uy9ipuB8VW+H2C7/YNL5D7x5L+BUo8xtA1ShaIJosnUrIcvgoFjxlMKzARvMJEQpIiDU4xHl6tc4jEUrr/1OnLfmrsrKCT7znghJLYRrwsAqyZUkq+rZrSYdnRHNyCUdkCZXI0Wa7R8JB685jOGy9kqtn5VWaZN172nA2DVj5UwhW8rXWyBYueYQfH6Ayp90HyIitrPxiAieElrRKD2aFDysnsoMSDUzrbiMfOKasAN+yifKUIyHMVSM6FotHvBBKsgoAdBkPG7AW4VYpO6yBzSxltMTGm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lh40mfmvuMy5CgWg0GvjXR6gOIOn55aderqcopomP/WGiZy81S//+tz/MicUQVsXFzevZ0DTEOLYC4Hzy7x5//3u+DHf/bM4aqRvjr5w2ZCmZ0+DV+meNtN9emJmNdo75u6ULN57WIWcYSiRhBqWqzK1VSc9eWbyCMyuSj76X75DMliFr9xpG6AfEMSbu6w3uBmRkwEVF/QtsMWgOm7iQ2Zx1H1ZEvCPA568IPEvCQprd7PyjfFJsoFl/fGnj5PRb4Lcb19i/TOPnkW878CACHUdNujTjRE0Vjk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 98aa9585-7f16-476c-6126-08dcf58f5562 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2024 07:25:14.3492 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0LxEsuD6wWOGJ90mMrtVpJGHklbGdNvvdjrMl2CNsjMhuo8BKCyKqPTv2ry2Y4p7q+wyKuM15Ym5nAiUUC7Y5y8xwTp+lf5JD3pTXKoJe00= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4543 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-25_14,2024-10-25_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410260060 X-Proofpoint-ORIG-GUID: 41Tm4lFbxtFktYxv57L6w3UwjiN1Q8fH X-Proofpoint-GUID: 41Tm4lFbxtFktYxv57L6w3UwjiN1Q8fH 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. Due to the refactoring of the central __pidfd_get_pid() function we can implement this functionality centrally, providing the use of this sentinel in most functionality which utilises pidfd's. We need to explicitly adjust kernel_waitid_prepare() to permit this (though it wouldn't really make sense to use this there, we provide the ability for consistency). We explicitly disallow use of this in setns(), which would otherwise have required explicit custom handling, as it doesn't make sense to set the current calling thread to join the namespace of itself. As the callers of pidfd_get_pid() expect an increased reference count on the pid we do so in the self case, reducing churn and avoiding any breakage from existing logic which decrements this reference count. This change implicitly provides PIDFD_SELF_* support in the waitid(P_PIDFS, ...), process_madvise(), process_mrelease(), pidfd_send_signal(), and pidfd_getfd() system calls. Things such as polling a pidfs and general fd operations are not supported, this strictly provides the sentinel for APIs which explicitly accept a pidfd. Suggested-by: Pedro Falcato Reviewed-by: Shakeel Butt Signed-off-by: Lorenzo Stoakes --- include/linux/pid.h | 8 ++++-- include/uapi/linux/pidfd.h | 10 ++++++++ kernel/exit.c | 4 ++- kernel/nsproxy.c | 1 + kernel/pid.c | 51 ++++++++++++++++++++++++-------------- 5 files changed, 53 insertions(+), 21 deletions(-) -- 2.47.0 diff --git a/include/linux/pid.h b/include/linux/pid.h index d466890e1b35..3b2ac7567a88 100644 --- a/include/linux/pid.h +++ b/include/linux/pid.h @@ -78,11 +78,15 @@ struct file; * __pidfd_get_pid() - Retrieve a pid associated with the specified pidfd. * * @pidfd: The pidfd whose pid we want, or the fd of a /proc/ file if - * @alloc_proc is also set. + * @alloc_proc is also set, or PIDFD_SELF_* to refer to the current + * thread or thread group leader. * @allow_proc: If set, then an fd of a /proc/ file can be passed instead * of a pidfd, and this will be used to determine the pid. + * @flags: Output variable, if non-NULL, then the file->f_flags of the - * pidfd will be set here. + * pidfd will be set here or If PIDFD_SELF_THREAD is set, this is + * set to PIDFD_THREAD, otherwise if PIDFD_SELF_THREAD_GROUP then + * this is set to zero. * * Returns: If successful, the pid associated with the pidfd, otherwise an * error. diff --git a/include/uapi/linux/pidfd.h b/include/uapi/linux/pidfd.h index 565fc0629fff..6fe1d63b2086 100644 --- a/include/uapi/linux/pidfd.h +++ b/include/uapi/linux/pidfd.h @@ -29,4 +29,14 @@ #define PIDFD_GET_USER_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 9) #define PIDFD_GET_UTS_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 10) +/* + * Special sentinel values which can be used to refer to the current thread or + * thread group leader (which from a userland perspective is the process). + */ +#define PIDFD_SELF PIDFD_SELF_THREAD +#define PIDFD_SELF_PROCESS PIDFD_SELF_THREAD_GROUP + +#define PIDFD_SELF_THREAD -10000 /* Current thread. */ +#define PIDFD_SELF_THREAD_GROUP -20000 /* Current thread group leader. */ + #endif /* _UAPI_LINUX_PIDFD_H */ diff --git a/kernel/exit.c b/kernel/exit.c index 619f0014c33b..e4f85ec4ba78 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -71,6 +71,7 @@ #include #include +#include #include #include @@ -1739,7 +1740,8 @@ int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid, break; case P_PIDFD: type = PIDTYPE_PID; - if (upid < 0) + if (upid < 0 && upid != PIDFD_SELF_THREAD && + upid != PIDFD_SELF_THREAD_GROUP) return -EINVAL; pid = pidfd_get_pid(upid, &f_flags); diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c index dc952c3b05af..d239f7eeaa1f 100644 --- a/kernel/nsproxy.c +++ b/kernel/nsproxy.c @@ -550,6 +550,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, flags) struct nsset nsset = {}; int err = 0; + /* If fd is PIDFD_SELF_*, implicitly fail here, as invalid. */ if (!fd_file(f)) return -EBADF; diff --git a/kernel/pid.c b/kernel/pid.c index 94c97559e5c5..0a1861b4422c 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -535,33 +535,48 @@ struct pid *find_ge_pid(int nr, struct pid_namespace *ns) } EXPORT_SYMBOL_GPL(find_ge_pid); +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); + return pid; +} + struct pid *__pidfd_get_pid(unsigned int pidfd, bool allow_proc, unsigned int *flags) { - struct pid *pid; - struct fd f = fdget(pidfd); - struct file *file = fd_file(f); + if (pidfd == PIDFD_SELF_THREAD || pidfd == PIDFD_SELF_THREAD_GROUP) { + return pidfd_get_pid_self(pidfd, flags); + } else { + struct pid *pid; + struct fd f = fdget(pidfd); + struct file *file = fd_file(f); - if (!file) - return ERR_PTR(-EBADF); + if (!file) + return ERR_PTR(-EBADF); - pid = pidfd_pid(file); - /* If we allow opening a pidfd via /proc/, do so. */ - if (IS_ERR(pid) && allow_proc) - pid = tgid_pidfd_to_pid(file); + pid = pidfd_pid(file); + /* If we allow opening a pidfd via /proc/, do so. */ + if (IS_ERR(pid) && allow_proc) + pid = tgid_pidfd_to_pid(file); - if (IS_ERR(pid)) { + if (IS_ERR(pid)) { + fdput(f); + return pid; + } + + /* Pin pid before we release fd. */ + get_pid(pid); + if (flags) + *flags = file->f_flags; fdput(f); + return pid; } - - /* Pin pid before we release fd. */ - get_pid(pid); - if (flags) - *flags = file->f_flags; - fdput(f); - - return pid; } /** From patchwork Sat Oct 26 07:25:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 838880 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B837B1925B2; Sat, 26 Oct 2024 07:25:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729927541; cv=fail; b=R82+Mmvno32+KmfB+Qel/gKmLCqI3B86cH/BgNGY5guzhdmbbvbQQVYuHSDns5b1ZDn8wPCv0GRh4lN+yCkdvBEY/VKflyxQnxbu4/qHejQPfPmQ0ZbFUX8kTgeSsBxrOkXMbJfhoAivMsdpwUR1CXQGOmLkgcHScSy4fVYC50s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729927541; c=relaxed/simple; bh=kGXVtdaQIb521qU3APu1XFO+uq3Q/fUT3w4fjLT70e0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=O+oiib80ihL/yepYmQwWMJTouJqXcPxzBABwQVcOl/qPVIeF3rrdNS8CQ76o1s9LaA3yCEm/CIQ/4BPfI/GZV40nnx7ryZ57iGxEKI+nvvFV8z1aBtqs6sRnCvzZbJ2JZb+07UMsrrf4bLSMOl++niIXv2aalV1arffqv27SqQg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=FKjxNgI0; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=rb3ZBBtg; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="FKjxNgI0"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="rb3ZBBtg" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49Q4CPtA019896; Sat, 26 Oct 2024 07:25:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=//aIKsfakC4UDo1gdtqhmI6TrmfLl1HZuQqSyReu2Fg=; b= FKjxNgI0jpufHS7K0sdlNOuPC+tXa37xtdLgGhxvYQD6elrrSrq0iXrFNn7fUpES S/FvXQSfrgOsr7kEUYxnv1I+B1sfuqCfZoc1hrNP7Rcq9I6pHz0yCMwkRkvrr3u6 C3rJTv8FmtnBRAj5ppS7e7kXv2ttLTUklXUgEeJdDFisdzdtx2suC37KqkVqCnsu sc5fBjUqUc4EcJVSHI25zEJOQ+b4XcyHwPlmrsitDVqqRl2juAbys/WPF9uTr62T ApYPZ7MG7p0nMcAO5s+gKNr+ZQ70th/yF1dEV0dgJ+8avBHEZLxhVeRnaz6/YwxE caDK6lgRX6LirL4QYJBHHg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grgw84md-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 26 Oct 2024 07:25:23 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49Q71Gbd016456; Sat, 26 Oct 2024 07:25:22 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2049.outbound.protection.outlook.com [104.47.70.49]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42gpv44vtq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 26 Oct 2024 07:25:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sHEECgoInfWP09Qa6wRPpev3IO2Q+D9VAB4nPnFaKM9QL5Lcd4QQIArVQvnCpYhy25ohSDRMyyW6e4bMUtp59MlXaet7TR8oo0R5SosWfvKlUwDo6zLHiZjfzFovqXpLUk5Q2lteKcEpJUqAwg/TpDjtS24D2WX8+dAchLEXawnQQeY93qrdsmiUSqTP2orCByFj3q8X84KqS8j/o9cvhYrFs5BIvx1GKK3d7gF/Sg2I1Pc7pW3Vda9GyNzwvoA9lPv1vyZyxFUd82fwgR9DP1nTtIndCmRCYL7l3ymc/4A4D6RKF9H8yToJzkksP6NIqeJyxruwtYwAdYV7j7gK5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=//aIKsfakC4UDo1gdtqhmI6TrmfLl1HZuQqSyReu2Fg=; b=X8c0MolUxsGy0+tNJXh5DBLzi0QIeNkqDABZ7GxOHPtKOgHnsvHllchqg/yVAOI9sYxdI+Zs8TyxLpPAjWyQh/OALgXEydbB2SFGoVsdnvkvtJ5mNHYfS/R2hOcQ7hZkQz9DVnOg/i5qLeKnH6gjgTV0RUsgAaMGaAUfyGDWHgZbMKjcoKOLQq6+rb11VksxfnMLPLLoP7fC6hzO9NBUXFQZf0qeK/3YOa4q4jftnmri8C6JBQEIxjnIqPLrT4PyB9//b4QtOKIiCiL865lzmyyqvC44BFvUDfbHWi8jPTjlEt1J+M5J4NCp3DKkcO/zJZmYqRUj6VJAGkoSibXBBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=//aIKsfakC4UDo1gdtqhmI6TrmfLl1HZuQqSyReu2Fg=; b=rb3ZBBtgd6llz+TWLplmkYOYmrzqoU6zaVu1VV1t32phWPVPHbACeqen8+IZlf3L3F0jPv/pL8n7pJbGMkwZD3otu+lQ4nkO3eYTuEYVpN8gqjmy3Mc7LRdB8zbU4HTqekkQmRglpsrXhT7ylEgjQSt31UWJrgd4nLU8psSEbWk= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SJ0PR10MB4543.namprd10.prod.outlook.com (2603:10b6:a03:2d9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23; Sat, 26 Oct 2024 07:25:19 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8093.014; Sat, 26 Oct 2024 07:25:19 +0000 From: Lorenzo Stoakes To: Christian Brauner Cc: 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: [PATCH v6 4/5] selftests: pidfd: add pidfd.h UAPI wrapper Date: Sat, 26 Oct 2024 08:25:00 +0100 Message-ID: <185b546439c29e9c36272462768af014a262985a.1729926229.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0109.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c3::13) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|SJ0PR10MB4543:EE_ X-MS-Office365-Filtering-Correlation-Id: 28d26bbb-28f9-4e84-126c-08dcf58f58b9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: Am2cCXO6PfuZ7ExJlpXoaxYpeAtgIA5DfV2Cn8Fmy/ia53WY/82hMq1nWrsupqwSqVnGWPRjHLeaHQgXrpi6y/PEAwjV/zOzoh+SgeOiejuAgT10hrTBNfC5pk5rewGCn/JFaAV3hni4jTOiozLIA2isTU+9dNCLkmPv7YqGC+CZWxdSyOf7dLzS0ic+twJgLhvzUYhxMQa9/F+sHZwSye/zToFxw9bbO+2Lk4n/WqHRGVGRFhihlv+IEbbX+Zs7AehKerQ7RD66hn40XE5SG5iKeSLIiJrikyTOLqgpx8tmGeLuTlHzpZJAESqm7ZlOp6CD0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I; SFV:NSPM; H:BYAPR10MB3366.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(7416014)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Aw8tl1A8/mOq/6H8o1T9AdRHiuZxU0fBPIR+98nBHKQUrIts6UZPuy6M/t/lu8LbVB290I6rTABLVuLmbPIQyISjk5Ux9J61lneZofTdlYIy63VJb8eVIUEP9necLtrKYZwkWf55k56sG6q10LIMifIo836Tw99JCtUjmAPYydU3m/q+r8tQSaAqSmLP3HIaQi94TAoZdA0R44huLMBVBuvmOUYsLpO3RErzCmXFgGCE5rC2sqGeUCfxT8G7AC2GtCGjuTVmE+gaxquk9UMuTqnyH2yJO9Dr4jnemUmUEqTwnzZPaXS86v218CTYrESbObzOmp4+TtwO876IZyM3YT0kqnrRSnk2zEebpXRw+eFhjV5kVTLm+5UlMfRZXa5dSRODtvdsncnSd3TGoC2W8DBIdEpAcYqwVxmZaZuK66oOMZc+0lkWHtNDjEJwOf6YCDcmJa5QHVgDRjQMIRlcO6pvVeA6ZUOXgkXI7I1/kVyfikbJpTIEC+1uxB50Fy6ehO1AxnEyJXgWHK3jM8Wm73bpcGAzOuDbuMamJAtEjzGnpBQPHDkFkh6cPbnT6RsowccR3vdwXNTtBV3EFfCbtO9i0lQ4TGOVDWgX8K3yMzwYzkraGOHgv1Yw0uiM8sLq3cY6j+XzU2z04GOo8zh8tSKvguWFoU1WAfWYvi0kxGvVZYK6NCqPjU6kepp+Dn8nt/uLo+c6a1dX2BqLDKSk0TRXMof6jbdmRhx7TVjtfHbKLYjguCec9W/xcVIg0N1CTrTnaYTy890gW4J0L9E6qaqI9J0GXSTiv39CZm/eaFtptVme2a31tKXLHRkE6KYaS1c+mkcDt7ToZqwCo1N8Fbdtbpejv0xwpac+/BOegcsrl7QMq0XzrqYk7F+UQqVs9rQ5b3wPcOjDCTgKu3rR8ICQD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FVVo3ENnJ+A7pzmbUsq+aRsS1cSJ9CoNd1B7/dJcGLOFwLD9wXRSLqMpANtrQSqC4Fyq2vM482b/1qWY+kcU5g+av3ZmTCJQnusF2Ko5jPUWW9KeZB9M8TXXNQP+LM7N1KyIIgxmbZtVrqbTbxUnv+JnlE8iq1a8nOshdFRXkSrUVkqj6qvBT2d72ZU8FJZWMxi8/SxX7gn/TiESHjffR5oY0qmpd1DJXJ5wrV8UkQER9n1upsh1KvAulI6OUQ82N0GKGZQ7648qZg0G/Y0n+K/8QsiboIbIM5EpenkcU66oxKTEydbCB4y6/QdfD3a4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 28d26bbb-28f9-4e84-126c-08dcf58f58b9 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2024 07:25:19.8133 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: p3ruLJlrA+9xs1Vrn7L6iGYzhcHuDMqJmhkxwiwQVzJKD49dMrZT3g4Vp/mPTMIa8zYFBQYD8/5HeCOfrcNVdT9QzEjBUcJGpuzz9LISliw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4543 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-25_14,2024-10-25_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 adultscore=0 bulkscore=0 suspectscore=0 mlxscore=0 spamscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410260060 X-Proofpoint-ORIG-GUID: Gaq-OBWvUkuEf77HGwlNH2BC56nN9RUp X-Proofpoint-GUID: Gaq-OBWvUkuEf77HGwlNH2BC56nN9RUp Conflicts can arise between system fcntl.h and linux/fcntl.h, imported by the linux/pidfd.h UAPI header. Work around this by adding a wrapper for linux/pidfd.h to tools/include/ which sets the linux/fcntl.h header guard ahead of importing the pidfd.h header file. Adjust the pidfd selftests Makefile to reference this include directory and put it at a higher precidence than any make header installed headers to ensure the wrapper is preferred. This way we can directly import the UAPI header file without issue, use the latest system header file without having to duplicate anything. Reviewed-by: Shuah Khan Signed-off-by: Lorenzo Stoakes --- tools/include/linux/pidfd.h | 14 ++++++++++++++ tools/testing/selftests/pidfd/Makefile | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 tools/include/linux/pidfd.h diff --git a/tools/include/linux/pidfd.h b/tools/include/linux/pidfd.h new file mode 100644 index 000000000000..113c8023072d --- /dev/null +++ b/tools/include/linux/pidfd.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _TOOLS_LINUX_PIDFD_H +#define _TOOLS_LINUX_PIDFD_H + +/* + * Some systems have issues with the linux/fcntl.h import in linux/pidfd.h, so + * work around this by setting the header guard. + */ +#define _LINUX_FCNTL_H +#include "../../../include/uapi/linux/pidfd.h" +#undef _LINUX_FCNTL_H + +#endif /* _TOOLS_LINUX_PIDFD_H */ diff --git a/tools/testing/selftests/pidfd/Makefile b/tools/testing/selftests/pidfd/Makefile index d731e3e76d5b..f5038c9dae14 100644 --- a/tools/testing/selftests/pidfd/Makefile +++ b/tools/testing/selftests/pidfd/Makefile @@ -1,8 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only -CFLAGS += -g $(KHDR_INCLUDES) -pthread -Wall +CFLAGS += -g -isystem $(top_srcdir)/tools/include $(KHDR_INCLUDES) -pthread -Wall TEST_GEN_PROGS := pidfd_test pidfd_fdinfo_test pidfd_open_test \ pidfd_poll_test pidfd_wait pidfd_getfd_test pidfd_setns_test include ../lib.mk -