From patchwork Fri Oct 25 09:41:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13850329 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 9C1E41D4159; Fri, 25 Oct 2024 09:42:02 +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=1729849325; cv=fail; b=hn/7vwdrdRSrfIk2xUaAp1sbTY3/N5M0NugeUDcb3Eltw23DM85VwqhFm7OFT36wFq86bEiwk5jfx2Kj9X7Xe+GupAl/XmW98Wq/tgoApghUcPy3yi2fqdzBOrKt18ukAsmrp9PjNijiN5nm5tgWi1ZJwNwn0f4+2z9anAXpzJw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729849325; c=relaxed/simple; bh=1GpvADSqsq4tnlLFx3u4o6Wwyrnin5JiXLi20OUiVgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=T6DYQD1BVGIP1nY9VuuziZhG8vO+RUJyRYUjd88RY6dQ7dvf/nCHF8TVcxEtbeT6hF9/ZrIxdBTF1WNNq75TSjDRGJ4ZrNhpYAaQrn5FKHgGSt8P3oD8znBIbfP4Pf9pl7TSDwg1iTc14TrZVnDifW2mhhC4tdxdbj3IYKC2Bt0= 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=Tq3GGf2b; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=J4ph4TGT; 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="Tq3GGf2b"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="J4ph4TGT" 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 49P8Bavr014269; Fri, 25 Oct 2024 09:41:48 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= Tq3GGf2blwKua78D5b7tXt+1Xp3ZmjdcFm4xc2xy9aMhvGdjaFh95s++PISFfXYQ +6+X0liyhm+T3AepNFZzcqK/kqyuj7ff366YDkoM7puw6oPhtfVsv8t9kb6EdRWy UfpA21s+dGdQhGYbRcc0Wr02L0p5l4jrXjngWiy8bCMj1Zcagwk5IuzQFwqhnade T1Ke7Sx8lPlk6vhJiMOX/ZIRn4LoqfT0IB2cgnBfGhPzLrzCsRU8LhYp4MlDLzpY L3BgaFDjQrvMsPsRSoAqykZoakGPmJhrRtG0CZ+yfFuMrKz+wVcYlzQXR/cN8/kP 2ehv3nlkTmKdofo1nWQHTA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c55emffp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 09:41:47 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49P9e10I039385; Fri, 25 Oct 2024 09:41:46 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2170.outbound.protection.outlook.com [104.47.57.170]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42emhdnd53-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 09:41:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vXYmR3rk79OjqiibuYJBWrYLTjQv0/5boxrJPvQKoYkwu1vjUyF93AfhqOBJFeQaxbcwroPG1psnb8uVhrmCcHgQvEF9neSJZac+PP9mUwF35kCSrPIfMPZUlLO+bPJky8K0IKOfFbHZDnfyJrVL7wkOlg7hSX0/3lBKe6aGH2g2X/3vP5I+QIs9YyaJbVDGoZYBkSWxl+GC//GhtEC+ZbS/C/1wxJ5swSzwp+gtQ3iTsWH7iSt7e64RgXRTab2nU5WYL9VC993Phx9Msv9VzWPnlGHXwNMLN8UotAFFeslcTkWEXt9Gttbar3L012Lu34KBObZNiaQIlRDnnkZkiQ== 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=EF8oeItZYjT4suTbnO3me1syQ3p2tDrM+ZIbJdOSy9hV7hhyCJNBLmdm/8O3Ay8DNc1uH3Yo8VgvdGX4B057nocYKNQZpvBVENa7OSQlNDuzHnujTHKW927WsO9OTEYv9HUMD7JxxDlLamTOf3RuPcm6sl9VIvPxmovmxD0Lm15JH//lSlrEXP2UHpP9PcABywIpsb4uuQ+LUPNw0EOW3GrnUzm7dtduseLm/GJLbaygcDOppWsJHbf+G5tvliJAHncVX7NLcXi/zGtrxB/Ctm/3tcN0U3cm720CoMbxpD2T06TpPRzpzOa+NHYjmXYrNfeGOK3K61zxbps3hXYc5w== 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=J4ph4TGTPwGzxtT0xyHOl2QRQrYlZiwhvrbtkaQebPWiblSpAHeP9oKuqfdn3vYLo+j52fxJS9TQWlWuu1dkabmI3GzQ+lO/84JkKvFRrXjOCzBzvC7Q1Xip057mnPA89f+dcFcgZIHGgFfWHb/JrOPQ2kRGjeAeFer46yHgd38= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by IA1PR10MB6121.namprd10.prod.outlook.com (2603:10b6:208:3ab::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Fri, 25 Oct 2024 09:41:43 +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; Fri, 25 Oct 2024 09:41:43 +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 v5 1/5] pidfd: extend pidfd_get_pid() and de-duplicate pid lookup Date: Fri, 25 Oct 2024 10:41:30 +0100 Message-ID: <20ff34d7de698a0537adbf4ef67b509eb250961e.1729848252.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0463.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a2::19) 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_|IA1PR10MB6121:EE_ X-MS-Office365-Filtering-Correlation-Id: c39148ee-579f-4e9e-88e9-08dcf4d93c2b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: b1yl3XzSsq6Ib4Z0QMQ4HWbAyhgz6ilGWA5LSd+N9VGOCM2806Mj04Q3Kx3J/jZQBofEUO/CLIq+hbBAUPbIOxow7PVOkcqIEOGW+ck4+zr9snFeJnPkp1H8Zx3YhHhAs4aHcQpZ5yOqgswgZfgOwfdVMdnC1vCYau5qd+y34ysLf/4H1/tuZECltjJBYi4wSW5qdkOu8w8rb8clj808WDZmY/KcxAjd2QNA7ebh0HXrGxmMqO7qJCDkhe5ePIb302AxoSGvw+9aRKjfOhWOS7ZLNU1cE51hu0lYEBNgIrvqeAGFMGZFF0l3gHalPE4jMWFqJtjAaWpk42xflxh5VS0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366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pgQpL6LYelysw/Qqgow0WztzqNt6BHY0YSKUc4w0LI67AmIs+djLpns8FMdXKyps1mzepEnJg2vPShO/YRmxdGd9y+c+TUXbLwAN5L5bYi2VdRCKCbYBoaW1jUNFchYNf7w763NNaZ1LNZHOSiBuXSJTJaV3kEFf1IIeRDJ1Hg2o/P5F6v1eX5b8PlGxYrZCblaSnVmS0TOOeDJldAEoH2C47gsaBLxpEc1gUKtn/A1BZVXIzpMclQGnt5zS7u1m5RDadPhSs4ZdXAo8csYu6O5hmRDOazWYawUpIvk3XsKfc4LSbrVschhVAJfE9nFZlqDiHiwBGLx4RFt2Yhpqvsl1BiSsFLJDeI9Iqx9Z4H4LmOk7Z2Esn/UA3TZfqZAP8BEziqC9hwg1dGxHEOA97M5FntqAQQZOePApOkxJKDV/0dli8E0T8pxeWOGXm0qm3fPuAlkYgccsgIKvHN03fvs8U+3MuQZP42kXE1hMqywKnE97HMdMCgHiJmk1viWYvIAHo0RRb/1hiEjAkdHQQzDcnLWK5RoE6Rm4SM5GB2Xa/cc7uHfOXaZSHUbf+OyhYiR4f6T1g9IN9qyI7gV8kIaLtrQdUqOVtl0Xv/BKm6eVsAgHGqWNm/q+tOVh3v6Mf8r4Dj6sfcyOUaJlV/sieJF4CGDPL8ejj9B6EzbfYBn5qnKT1USbJnDp/EFcDLsCkEq5gKMMjbKihk7LU/jlS1BXwML5FYXDNfpCp6MjjSCmqscsAf8FtHQmVa8Atzte2GjqTaPYVFaEi4Nt0prUfMzDZjj85AjZ/nkWsudjy6rPDQUm6MnxVa/KVi8K5sz1+bcHDTAb/h0zlGLRR1XzPA65L0a1xUM8oL4PgEyL8WZCGVWHxgETRL/3gChbKSIF5jjNXD+SVQV2WMnMkzcLeqitG0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WUzreHHMNV3aFogt50StNd9TmzfzWRDVHVVuAqkrA88jzKmGP0T49NxZNcWJ2OzoQC0gfghksojrDg6sjBNk1rB4vE9ebn1A5ygdPCLNDGNl0i/joL6R5Y19Hlg8i/+sxzg8x941X18pcaw55tkShl2DHvnm+Q9rbiiMHiNQW4hyuEhUYtZK0X95HqKKcpShs3IJankRniro8k67KrWK7YGE/LYbw3PLQWJtq9FnBGGapmwvc4VMt/uMPqVU/WK+r96oFhha7pw9MmAa8iQ5kR7hSD4L/BSfq8lORHtJsGD+9EGqCr5q5KNYodAYpdUEBv0i7ElNANx0Ug3RGkBA45kEOPjFvJLP51Pga0gBkahM3XyexAJyJmPcH3Xcc8Z6E= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c39148ee-579f-4e9e-88e9-08dcf4d93c2b X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 09:41:43.6783 (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: JoCHD4W+gMVz56U5GGhpWxsrkgCSNuFa4SKhVbniEjMXe9zrUoaQJw5MnhFiH8zpX/Klj8luYlRWC+XcVgvvOUicBZrvT/pU3MyHedXx61U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB6121 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_06,2024-10-25_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410250073 X-Proofpoint-ORIG-GUID: BHQhgcVjkEWSlBaWRb6ZeNRN7bmxM0SG X-Proofpoint-GUID: BHQhgcVjkEWSlBaWRb6ZeNRN7bmxM0SG 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 Fri Oct 25 09:41:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13850330 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 9B6F41D90DC; Fri, 25 Oct 2024 09:42:05 +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=1729849328; cv=fail; b=JtnoKepeo/vT4fvoeskk481jaVfqZOWHp2XjLSsWFTNUqn86Q2rRdY6e8KVc9b8yXNQaVLbJhi1QkVaCSgmaxrZUIo0iJDyXsxTaojeK2hfWaWsShhoYGY2P4oev6Mlf3KDtCJ7lZcW8iozLG5Yyd/RNV3+v3PtWRbsEmcEhUzU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729849328; c=relaxed/simple; bh=RDYijylasW+Be+VhATzF8NimNslLW/NMpjpOS1eg89I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=MJWhs1MZQWc1pn9MPKSsKUtfzWj9hPMckt6kmaGImvrUlzadi4xX/ShY7N2NL1/aBlXQ6hjDQ/YUxHlV7ORP6MIlPA2DeHpZ8R5d7teGfIP7sEMlNpw6sNFDDD5c3ke2RgZgceZesJhT5KmkiUQCKCnWvdR9WsS0MPuBfStVfic= 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=gYIQWtve; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=xcT4YrOO; 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="gYIQWtve"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="xcT4YrOO" 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 49P8BYo0014697; Fri, 25 Oct 2024 09:41:50 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=d+w1NL58a0s/TvcpDRjcjRaE1BTZDAu5TSa+cfzMlM0=; b= gYIQWtveTwswJC5LOSgH9ML5sWeC/lu6hm3/MmkOQtLF/2c30wA0eV094VjnVdEx ZaSL+VFGO7ctgZBuC3XiQPZrHmiJtlskTHn5SsLaAi1UwRpe42ZlOuJ9qiJAPl37 OvlKucXkD3WaUI/DPaLLXOJU7Iu21Jwiorl/6+MAm/BFareBRr+0utKIK9XRtAeL 20J/eZm9M23/nmsNv/cSKg4qcAoUFvqOQoxxrWz3dn6ySGhuXONfg/doPk4eDWrG ozbHmzVg06JUHjm9Z9gCpwkU3lwrxllV6nv+/mkRSY8/rrgDzNWlxTU5Imt4Tf8O nVWRfVE1MMXC94muw9dRuQ== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c5asmm29-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 09:41:50 +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 49P91wFN035766; Fri, 25 Oct 2024 09:41:49 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2043.outbound.protection.outlook.com [104.47.73.43]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42emh53wh4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 09:41:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=itYyxZUieXopytDE0V+mFtth7XKP5bY+J6S0WOrFeKa5CQ9ZjhuQy/AcFzJTr58IgKx1m/0tAGjA6JDwZXBT5znxs9qt8QBuF1C1rYvDgptPX1DTMXlmqzB2QsTx0ZwwdLkhBm8e9NsXUOVs9aYmwiugzB+kkni/5aiGpDVTdVXMglkrUTpgrx8rTZ2gWqXmd3ciFjHmEZmDgpYhaEdOEtsIzcnPFc9H6ZTSFcUyPgf9zgovD1Ff5zYWjwknKc3zZnZOG2Y4rBX2yA8GcCFPbRM25HFCI8Vl7B+SvI/gBPSknK5NqPQXdlGtBktVDagMnsd8jpLZQw6dndrcSolC7w== 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=d+w1NL58a0s/TvcpDRjcjRaE1BTZDAu5TSa+cfzMlM0=; b=Ezt4KyUMaZfY4Q9dgmZ8ObbzEA40dJiAylBXJg6jCSiCA2XM9TA/eFIh57xpPUzZvYqbDczfjLMj1QjcB1WHc36EH9k+oBklbwcy1h6tOb6MsJbSL/47USGUyUB8ZEji30iUy2iGXMIZmOeV1QDRB8RmcRHOxus9/miHcxOvYJdX/qqNLct2FuyqDT2Qjv4e7+4x7o6UDUzsr2lBHlADi/M+iHgW490XC8Fx589upR/u1b9zrf93+pF0PBw6UaOHdeBB/7FCubvj0Yhe1iCZ0o4CWL/440WfTWP43Uf9Kko/mSqF9rI9U11WY8Xe8c62YrH76pVPUtR4p91cmxVl1A== 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=d+w1NL58a0s/TvcpDRjcjRaE1BTZDAu5TSa+cfzMlM0=; b=xcT4YrOOlVeiTN/GPnHirh6U0uy2G8AWwP5xbY1XNDrBDR9tXj+qvWpxawUKQlfMi+yeWCoTboAmU8J3EtNIrann3S5DoWP7v9nWx/lfXzcUZdlhG4wgviDOrtbqYYh7ldtu9HLvf8sK7O9Tc7766bOgCpwaiXmvP6wGFVrYXE4= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by IA1PR10MB6121.namprd10.prod.outlook.com (2603:10b6:208:3ab::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Fri, 25 Oct 2024 09:41:47 +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; Fri, 25 Oct 2024 09:41:47 +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 v5 2/5] pidfd: add PIDFD_SELF_* sentinels to refer to own thread/process Date: Fri, 25 Oct 2024 10:41:31 +0100 Message-ID: <788fdfcc9ef602b408951d68097918d6ae379395.1729848252.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0289.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a5::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_|IA1PR10MB6121:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d549080-c03a-4610-35b4-08dcf4d93e25 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: 0asKowcRPCF9i/rU9emtBThCF7yTp0tVbVugzxD89Or/Ws1vigBDnI1aN66rC5hvKrhR5IsfYqx7uL5rvPZfEZdJiuyFHmAZ5KBmVpUz80NAbgwYQN8oO3qin5Q0FOPzSVzynWCXGw3+oosiJkfdfv8/kcmHUgi6C2TkJuvMYE9KZQl/PxheDN7u1bcugaKbcxusURI7PP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HZSguTIJdvM6hb22l2hHeVABmBhnbYxfK6aa4sRX78OzDhPOHFokiKwRjyeN5HupA5Oj+ML8X 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)(10070799003)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wEYUGvaECOaEy+I1/lH2CQETbIVarL+h/AvW2GTdzSLfxthHFvvfM2rW4Tmdrg58Flys8lkbO2ECRSflxU9ZKJHJa5HI1hHi0cVEnhmurXYlwFagRDgRBsnYEyl1D9nCYVjLRl52c3aIj1seBQJO9dhDl8fv405LiQFSYOrCYUEHrNvINgFvZ+fNpIqSwewp0mtj468i6K8CMsqRdl2GYaqPlZeGJq3oADGEXDCQBKbRpp48RCPXKWGzlFgUBClnME3TWYBMnX5rNMGhW/YEtTz1Z8zgHn+61WHlUQ2h/pNEw/m3c+zyKIz49ARt4AK+LXiEqq+xndgXIYMk4g4jY0f2/ElVHewlRSl003qOgQOmayAs1N0Wor82bGygIRQPKnG4DgJisExT3F185nUvtxd4uFSNd7JSHg7xZ9cPzcjgxwS1AfCGbIOXzsVG6ZjSGUu8dhPIwTUuu9hi64Bgjrf+HTDejPsM1a4mvbuBf1V9ta/YiA0YzLfQu6FkH1mVTe1Xh4dkxnCip5U0Fv9yiraDYHAzHq7/4MwZR/BzOc9N8Y/8NglSA21E2jEGovZISXpaCyGC8XV8JbMKUSMe1quzIGxavxcwa9K3A+FP5Y2Bn4TgpuQnAHuU+ZctY0YzbcBVmyF0aLveqNvNL52i0yqJom9s4sJ2tv+KX7BJX3fJlwbKVdhAY4vOV0eDyA4he+/dwIGdbcNzG68IJtg2gAsTtmD7iVgVlcoiNcRC6GvxmyuueMN57pYV21WerVeHmaPGdiYfeNf1y/Q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Qlfr5ymuCsQj/yGIXloAQq2VYKzlCElqh5L6g0gT/aHnA0nTOmo2m1ArLhDIQ5rnWXdyJ/n0em5+D2SnwsNZumRw45N4NnRx98tdiQewtqnmYOrNpAKAB32A6GGKkXHDhv/Il3HVZBEkKAq+XpYZRqy3TSpVQkc20BUHUYTKNrENGZ3Axogclh3AO+IbeEab4RzrZMV/bXwG1rrjA02Fp85kaRPUgUHn7xa7usQvnAosHsKWelMVB7JsoRYl02iXhLhe5UYIDsT4uR+8qQ6htUs+PZCpn2sip8kv4lUNB8esih4kKMtxE9bwje2yyDATTlOa5vOpagQQynl2jKW+FlqJE659ZMWaXJm/AuJH2kW6tQBVQTwvm5m7fAyoGPj6P1PpJL8TEGoJiSKI3e9/o04Owgza8nEWOr1jX+WEOJHIjIiNp/KP/NGDYtjX2xWxHeOvIoZaCLRx6XTA/3lSEjz4831A9mCg9MGQO+ZChB61iGx+0+S+a50QNTxENfAhk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d549080-c03a-4610-35b4-08dcf4d93e25 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 09:41:46.9716 (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: jquN5EKyi/ULP0XFZaqcxlMw2O+JAKUkXm6wXP99XaPxxJzVUFXsWJuF3WSErI7mOYWN8oKjmAG96D5YhqL6iPy4uqdhG78jN2lk7JDByvg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB6121 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_06,2024-10-25_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 adultscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 spamscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410250073 X-Proofpoint-GUID: daerc3PM5lacqOz2kOHa2IyfqB3VU98K X-Proofpoint-ORIG-GUID: daerc3PM5lacqOz2kOHa2IyfqB3VU98K 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. Reviewed-by: Shakeel Butt Signed-off-by: Lorenzo Stoakes --- include/linux/pid.h | 8 ++++-- include/uapi/linux/pidfd.h | 15 +++++++++++ kernel/exit.c | 3 ++- kernel/nsproxy.c | 1 + kernel/pid.c | 51 ++++++++++++++++++++++++-------------- 5 files changed, 57 insertions(+), 21 deletions(-) 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..0ca2ebf906fd 100644 --- a/include/uapi/linux/pidfd.h +++ b/include/uapi/linux/pidfd.h @@ -29,4 +29,19 @@ #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 -100 /* Current thread. */ +#define PIDFD_SELF_THREAD_GROUP -200 /* Current thread group leader. */ + +static inline int pidfd_is_self_sentinel(pid_t pid) +{ + return pid == PIDFD_SELF_THREAD || pid == PIDFD_SELF_THREAD_GROUP; +} + #endif /* _UAPI_LINUX_PIDFD_H */ diff --git a/kernel/exit.c b/kernel/exit.c index 619f0014c33b..3eb20f8252ee 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -71,6 +71,7 @@ #include #include +#include #include #include @@ -1739,7 +1740,7 @@ 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 && !pidfd_is_self_sentinel(upid)) 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..8742157b36f8 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_is_self_sentinel(pidfd)) { + 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 Fri Oct 25 09:41:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13850331 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 0CCF31D90C8; Fri, 25 Oct 2024 09:42:07 +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=1729849330; cv=fail; b=IWsIT+m6zZ8CgfHHDeHCO4DhYuAPX1SIVl34WeNNAhlNVOBJcp2pBJGFkQdKHNIEjMQz5bMSNatN0NF0+UAIHwlHHBz6+cS1BsjQPIuhDtB1rwgUQy9Gwm3T7nvDyi5oq2gXrwq1BLIBnLlM1ozks5A845g/JPi2pjtWOslpdS0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729849330; c=relaxed/simple; bh=URx+MB+d6wqrYB/3X5ImI7mIBPKhLFs10r0aaSX/1/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Z3SyB48EGKydojqAMqsfAAS2qCNG41Kp++35tB1K0OyAeXDc1s49V2JhSluLua3i9rnHcuH9c8/kbK7CLsW/GTb8siexsmI6wyd2JcEAiTrsm+IgVuWemf2GiRWXLr2fokuWUVV44mqMTheYyvumgl11vH1rogZJMPWk2RY4g3U= 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=WSgfrBWl; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=lOmlAua6; 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="WSgfrBWl"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="lOmlAua6" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49P8BZG8005832; Fri, 25 Oct 2024 09:41:54 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=SLlbDZlZ3nLzA+OMshfpAja8xZBB1l8GJOD6tbMQ7pA=; b= WSgfrBWl2sYMqXQtdSQbn6UEGQgYeGnjRMU5BcojRJoGFuqZN+tJd+TEjOIp3bSg 1EeR2KfXaaFX/lYUJ0M0SNqaPhy3/ONpnvvezK/InH2ScaoxbPOeboKgLmTIEbjh jYc1dtMGyY4c8HqNxNztMdIF96KvtDwIJjvSwDGuTFCZIvgzQjrw0795nhhvpGJU KeSuBfwGHRNreSmzejFhwmQG+lIwk/PI37mi4w+5PpqnEwfn/X0jw6qBMdgbuH4x mFor1T9kpm0BRzFS8t5D89L4VmIQSQcOzr4qXwD4BgHN0wKLKHPYxkvNYFN8L5A0 woNkzTZzpzEMxqSVivXmcw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c53uvk1s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 09:41:54 +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 49P8gDuV001662; Fri, 25 Oct 2024 09:41:53 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2172.outbound.protection.outlook.com [104.47.57.172]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42g36a9y8q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 09:41:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sgdSu4tmrR+arS06AgM0LNH4xmXpS5N176v1/USAhEMEWOC0TECj4FPB4VtZzS5otglr/gbwf2coBKAT61O1i1G6rxrSj/sWrB7EHn7IWXwLeGXv561LHVIqjNgi8ltdobXh2hSJoW4GrgI2yVCoYHRp1+vRT0BbZ5ZPRHrTSKlahEjMlrXmNpet9GFNGOx8hmlJtFbLaZBoHDHRhwKsceo0DQTeRPQa9d+wHYBRAyZFKVZbI74qLboNlVVyqh1vR1suGftDq+o/Qw2ADozS1I8npMX6LR/yDY7OsAAhcLldrD2J5jOxIgI8n4zgcxs1UkAdK0ORfazvRd3lp9gM2Q== 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=SLlbDZlZ3nLzA+OMshfpAja8xZBB1l8GJOD6tbMQ7pA=; b=WDe6SEKNxCAKcbTmfSgrL90UKhlwXlvM7dn37XX4BEFgXNFLfndvPS0qzpBN/K9CON6OikUVo9WZC30uQZxv0ayfWT9cvny9RMlZhpgL6qaQlmNBxJHcTTdFifpn7ccfvUYCRuocoF+9T2sUWyRPBNb18qaS5UtfHyTc8LsDBOP1pSgrugNA4JMVTwDm/OF1ubkqm1JspKmxwaDxgiii+/kWhgWuk56oR7077vz0CZr/HFLtNsJHDLhXo1S+xmgTC7lbxp601kHOtqx6q3W2O264hCILRE7QHShXri/nHiicmGARTDKyzWqqhGKKZ4C+pItwfJWfGGxs8ODPae9bWg== 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=SLlbDZlZ3nLzA+OMshfpAja8xZBB1l8GJOD6tbMQ7pA=; b=lOmlAua689kAFCthFnJWNizWEeAZerRgjwzW708mClNJFDTjs2HvHK0ofjo33GqdHBT9y9bsGyrZxhTszwQUSzhv86FuoSn8Ep2ThPNt6o092b1ZuXB77pVsFl3iTW6JZ+0puBEAc00F3BhgVhg6O0U03K4t917n6qOBXGu6qXQ= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by IA1PR10MB6121.namprd10.prod.outlook.com (2603:10b6:208:3ab::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Fri, 25 Oct 2024 09:41:50 +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; Fri, 25 Oct 2024 09:41:50 +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 v5 3/5] tools: testing: separate out wait_for_pid() into helper header Date: Fri, 25 Oct 2024 10:41:32 +0100 Message-ID: <391ca859c6e7c997647f43863a756808d368f8d4.1729848252.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0377.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a3::29) 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_|IA1PR10MB6121:EE_ X-MS-Office365-Filtering-Correlation-Id: d184e8d2-3bee-4e55-bb7e-08dcf4d94062 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: dxET7Lb0S6TU4XQkkrk/7zZgq0wP/7shpYSDYGAzgVQ9EGCzucqBYzRur4W1Zmoq9IwtWz8waop5X0jYnxKu8aBH6dIUuu6l8ducp46sKkV6a+mwTbaGgg4fWzU6kWgBFakZ+pKEo1+XTBLV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A8pkJsyfFqTbckmjzou626anjulnoQ2iasa/Z5EgAyTeaM++B/l4sihulWp0vPuAvOD8xyj2ZqrhcG4uGYjRThHthhtQ9Uzx0Bqqyr9tA 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)(10070799003)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QvM5UmjLoFG9y9JN4IoiZDV2BdJAL/U2mNSmNQOnvJ61vCZpTIC1X/npwTzBWhA2uDrL0VcHRYDEFU38f7xrG0Ghdq/pVbsYJVfA/mv2beX28tt5aaYSzDErSE8wnmaGQuxdF2eM04+YiLmJ9v9nrbWLJ5ZhOppUK/cAQDl3ZhWnRkVk8vlYaBb/F+XdsS/H+QZDspW7LrCl+BakVs6PD/j3GkgCP0o0pFK6I8QF51WRBeHsEs59haBsocsCNnsA5DTHG5CP/01ob9UNU5ZbMubVY/Q3AtwUSaHJFELbLVYq1euW8lPoSi5Fc14LYkqjgzVpdk26p5DNhgskF0q5xoP7lIxZ7M8+ZPg/xSGvVr3IZhRSa3Jtt0MNcEqa3EvoQ2JikceZ4veC/yO5ovu78DGPCGH0hfCWOhJqxfuosN/mIz+R/UXZ63ewyb1Q/VMoHvGCoMX3Rdp5X2Sbge3dGNE1lcFbXdf3IGtsPD1iyZ6jmH6DlZGZGCU8XsPRfHDFpGZkJKasoX1x4cdOU2Bdz4J5WAIFYr/uQSKApeXoQs51939RF3ew+3a+HWyavmyn/zYbIExNeO0XYqJREE+ZsCjC/VF6smo+OOxjsD4uZVc3u78bCMD7vijtDroZdaCzqqNidHdRSvpdIPf5w2Bzd6wPtdev6L83SOs+INfk0lfH69nqMZOLwsgRGV04FdTMJFyyvrGbvoaclfkFZA2fHwRohSuUq6fC6z379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NFL6R+dBEsga0+TncgVgag0ia19uGtrwCQ5XMvK2ab1ZFNkt1AqXApaKbB8G3aO2jzIDPcgNekPdPMqWVAVlO6WRx9+cx+1qK1BfvAB9jZRB5CsA+eHFciDvSkeqYlfNf4hLoK03Rts47rQTUMbgRg0s7bEnVAsE0ZJNPQCdB8j6qUpSocshnyfGTh+T3tkDBm+9PjrtC7p7aXF4gII9gJTfYp7E8P8xe0DJsDN37JnNMi3CA4nP7dyOVcK60ei5uHPDooe4J7bN+qpJi4tK/ZDteq6HO8TcR3+YgUqzsDmxD4+5I6rbr18mpLm0XHbWFPNALbLFbze+QXvcJ0Iiq76L+dosIr3DyQeJmxqM0D4/7zFa/TeOmbA32G031cjIkuga61gAf/eXbGwMmdSs5hOG5GZ23K4TGZ2zAJoJYGOyVsnyzWCAquh1peCgBOgZNrV4DjWX3A/tDNuSsKbsZ5h7knLjRk8dLIbK1vthVyZhNSaH7WN74PNXkyJz8bN9bgilvaJm/1QjUJ0jSo+rIYDQfAk4JNUiUdfvAcv7bWg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d184e8d2-3bee-4e55-bb7e-08dcf4d94062 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 09:41:50.7860 (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: Y+btAPDiwaR5mDz6CRXHVCoH4FYmleoiRobOEE14ntl80tKgS3OBzsZG8+d7K2X+Nn2eDezDa2mxNJGxfwdcGLGZ2LvRCyokUvo9RKw7hac= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB6121 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_06,2024-10-25_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 malwarescore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410250073 X-Proofpoint-GUID: 5FgkEX0XTqnEDSHi1T4J8rYwtS3ykv-L X-Proofpoint-ORIG-GUID: 5FgkEX0XTqnEDSHi1T4J8rYwtS3ykv-L It seems tests other than the pidfd tests use the wait_for_pid() function declared in pidfd.h. Since we will shortly be modifying pidfd.h in a way that might clash with other tests, separate this out and update tests accordingly. Signed-off-by: Lorenzo Stoakes --- tools/testing/selftests/cgroup/test_kill.c | 2 +- .../pid_namespace/regression_enomem.c | 2 +- tools/testing/selftests/pidfd/pidfd.h | 26 +------------ tools/testing/selftests/pidfd/pidfd_helpers.h | 39 +++++++++++++++++++ 4 files changed, 42 insertions(+), 27 deletions(-) create mode 100644 tools/testing/selftests/pidfd/pidfd_helpers.h diff --git a/tools/testing/selftests/cgroup/test_kill.c b/tools/testing/selftests/cgroup/test_kill.c index 0e5bb6c7307a..2367f645fe89 100644 --- a/tools/testing/selftests/cgroup/test_kill.c +++ b/tools/testing/selftests/cgroup/test_kill.c @@ -10,7 +10,7 @@ #include #include "../kselftest.h" -#include "../pidfd/pidfd.h" +#include "../pidfd/pidfd_helpers.h" #include "cgroup_util.h" /* diff --git a/tools/testing/selftests/pid_namespace/regression_enomem.c b/tools/testing/selftests/pid_namespace/regression_enomem.c index 7d84097ad45c..f3e6989c8069 100644 --- a/tools/testing/selftests/pid_namespace/regression_enomem.c +++ b/tools/testing/selftests/pid_namespace/regression_enomem.c @@ -12,7 +12,7 @@ #include #include "../kselftest_harness.h" -#include "../pidfd/pidfd.h" +#include "../pidfd/pidfd_helpers.h" /* * Regression test for: diff --git a/tools/testing/selftests/pidfd/pidfd.h b/tools/testing/selftests/pidfd/pidfd.h index 88d6830ee004..0f3fc51cec73 100644 --- a/tools/testing/selftests/pidfd/pidfd.h +++ b/tools/testing/selftests/pidfd/pidfd.h @@ -17,6 +17,7 @@ #include #include "../kselftest.h" +#include "pidfd_helpers.h" #ifndef P_PIDFD #define P_PIDFD 3 @@ -68,31 +69,6 @@ #define PIDFD_SKIP 3 #define PIDFD_XFAIL 4 -static inline int wait_for_pid(pid_t pid) -{ - int status, ret; - -again: - ret = waitpid(pid, &status, 0); - if (ret == -1) { - if (errno == EINTR) - goto again; - - ksft_print_msg("waitpid returned -1, errno=%d\n", errno); - return -1; - } - - if (!WIFEXITED(status)) { - ksft_print_msg( - "waitpid !WIFEXITED, WIFSIGNALED=%d, WTERMSIG=%d\n", - WIFSIGNALED(status), WTERMSIG(status)); - return -1; - } - - ret = WEXITSTATUS(status); - return ret; -} - static inline int sys_pidfd_open(pid_t pid, unsigned int flags) { return syscall(__NR_pidfd_open, pid, flags); diff --git a/tools/testing/selftests/pidfd/pidfd_helpers.h b/tools/testing/selftests/pidfd/pidfd_helpers.h new file mode 100644 index 000000000000..5637bfe888de --- /dev/null +++ b/tools/testing/selftests/pidfd/pidfd_helpers.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __PIDFD_HELPERS_H +#define __PIDFD_HELPERS_H + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include "../kselftest.h" + +static inline int wait_for_pid(pid_t pid) +{ + int status, ret; + +again: + ret = waitpid(pid, &status, 0); + if (ret == -1) { + if (errno == EINTR) + goto again; + + ksft_print_msg("waitpid returned -1, errno=%d\n", errno); + return -1; + } + + if (!WIFEXITED(status)) { + ksft_print_msg( + "waitpid !WIFEXITED, WIFSIGNALED=%d, WTERMSIG=%d\n", + WIFSIGNALED(status), WTERMSIG(status)); + return -1; + } + + ret = WEXITSTATUS(status); + return ret; +} + +#endif /* __PIDFD_HELPERS_H */ From patchwork Fri Oct 25 09:41:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13850332 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 E520E1FBF50; Fri, 25 Oct 2024 09:42:12 +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=1729849335; cv=fail; b=iGLf22jS8GBN0xc9iWUvkjGnYfPHuQuEjfkrQmTgWPTfSiHZywhTfaI3EkGDWsEGbqh+K0ir56TDHob7LO9BhEs5hZP3/uVbIw7LeQmDDX/7iuWrrr+e1LSAyK56av3E81y1HqF9nMsjZG5FU3QxPLu00O4kQOa2KsEYN5PQW/w= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729849335; c=relaxed/simple; bh=kGXVtdaQIb521qU3APu1XFO+uq3Q/fUT3w4fjLT70e0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=KjA/NmXPZW9S4ieLFYoYL9/7ioLSGYttC5bWb3+o8xVBDSYdOFyYEDd/h+DIjTTyWH1w3eu4qZtmKyM0hA4c2OS4HlKTB4sQ88ImIIVYWqFHHWwwm+nWSZBH7GyzLYgvwomTefVVOCN41OzOsZdX9VerXyuSd9QXOenqL6M29BY= 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=Aojlg+fK; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=arBAV2EF; 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="Aojlg+fK"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="arBAV2EF" 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 49P8BaME014274; Fri, 25 Oct 2024 09:41:57 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= Aojlg+fKaQX4H6xJF+nRy5G9M0/Cq+6/N1nIG2LJUk+JHtrDgmxd/2kV1FIEVPzG F456ojeUr4PFhrjnET/SZ9g3E4eS1905gN4MatQQGiHvdcADnCWCwkLI8sPTxYZH aiKAfSHjaiduV3AEPp5xQyuq/yIwhldXrfAgl80rtXl7T59MfqSQhtpibe9/EpKG a4u2R1PhS29TrDm9AnxKilQlvzezmakdBHMgUUd4+0kU3tBM91C1Pl4ZlI8QAnTz jeOpfDMrn53B4dmVG5Xb+mPw614buQsf7ajD2sGzFKJ7mA9iaNIITIS6JZkpiP85 SSjpnGKZCGjSrFUeHdqcag== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c55emffy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 09:41:57 +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 49P9VBDq036957; Fri, 25 Oct 2024 09:41:56 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2173.outbound.protection.outlook.com [104.47.57.173]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42emh53wkq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 09:41:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=s+v0D3t6JTOyNtaLO4i1XkGEjoUkT8SXDlY23GhUnrMYHeXpWRBchqE7jvT/CxgD3bNkPo3u1h54DQDYvM51ir7TB5D9gwsQWhy4C1naHqSeoMsBc0BRWwx90JzyM7S4UAPWNSXLFD0zRfs7BvDVVTpPK6wu3h5PQdj78hCwJbINzY5EtnflldMyLMKqqqmS7l88Dm8IuQxEnaB/hXSKG6bqoSeC25sfs9goz4gNoXx7R3/WV+/PhEMfRQ/UoHFfurpOffgau5Hzg3nRrN8uQSpJiQRJc5ngCyEvNn2Ch06dieR14ULOKSY0huHZfb98cIQE5QYSr9FRjVKBYapavA== 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=Xj+p2PxdtciUEAqCX8so7EsNJhzjxabq4egQepes70TNfk+H4rlKYtnfg/6Jq4P93s7BopMorUIOSqrhM5h72eYezMCqwldTrTRbqL9KdRofR5aY0O7HIe5GQFTCfMjvp0vNtGcRw94iqgIIGtweaV4KjUpN2fLOcsZDwtWpJnECk6hCvdvyTIHhnvMySo0e6G80yCBY30vcWbgt4+pYyNdsEAc1IZ6X3/Bnd+7U6eFabLlg2Ub/XVjh/gkr172UeBBtIJKJlM73BOycnIzikf6HHHVxJqeAxdH4dD9euXl6ZruhjtoVGSZPFYgZd2l1MBPliuapTnXH+EW51aTHPg== 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=arBAV2EFzZ3i3mY4LbDkIiQ6dGJ8B3Aai5/eUg02j5pALog9xI/PB++tY6NviMMCA6VHHbAb1G1Be0y4hfT67YblWJ+am/AOVfWcJh3++pBtjozOT2nKBZyTNoBJ5r4WQHZF9LzBrcTLvuXS9bE7dEz2twzZgp4tCgFPFham3Dk= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by IA1PR10MB6121.namprd10.prod.outlook.com (2603:10b6:208:3ab::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Fri, 25 Oct 2024 09:41:53 +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; Fri, 25 Oct 2024 09:41:53 +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 v5 4/5] selftests: pidfd: add pidfd.h UAPI wrapper Date: Fri, 25 Oct 2024 10:41:33 +0100 Message-ID: <1002ac9d986cacf44dca8cdf392d62e26528eb83.1729848252.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO2P123CA0094.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:139::9) 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_|IA1PR10MB6121:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a015b8b-97a4-44b0-a390-08dcf4d94228 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: awErcbrjTu0Egf/QTjvxki00G7uJ7Qzp76ObuLB5bI89SZmmyWpcCGwBRBg2KgxZA6bbYhjeTrneXWVRf6nHzbdfhMpsiMLEccB4D1PkVaqz3UhbI7ZnKXtkWLylGTgeLGWANrZBhGJxRxxWgmwegy2MyeolD+sKuatYy4+AdX7cmQ+ISBL1zr7X79+t2+E9s+eDFoP+pm8QEy2K6jthuG+wiPvURai0f8KHkGw3jFA0YK7eAgfB9nQx+EcdNmWSA+1duz26BZpIOOD6W7HvfWpa8dNsxJKGDracoXA8xwErWYLhu9YFyuxpTYF6tSd+hv3iGHdH/6LvR7S/DyDko7w91KkI7yN/js+x2oirUdgMKJGJ50czwx7ef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PTR:;CAT:NONE;SFS:(13230040)(10070799003)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6bfDWLRWtXpybuPezo/EXfYtkdZgcpex7QDMmjA4WqAled//N+62c4vYlCs1AI11Ca4OaR8frISiujxPvywCd1ra1SnilHpkLjY/oUtaW3CLzXQ/AS1XYkDyeCTxg4f/lI3W6VXZCDis9a0y1K7okbjpTY4v4SrxxJ/r8r/AXu102y11O7Fe3CXOdL6FotXTh97Mtkx0P+hcVUw9rnpxU9xT8K++sQnY9tJdwtV68mUGT9bDuMaGxLS6eTt5084/nijyRVxlkFFYGV0T/F2QEhjcNxlmNTNxIK4gcuKu2LkemAAlmBmaKyAibzVDtXMRlpnWZR2BlX83butMbIW23gFcubCddavfXny4cJpwn9UMxOBmE4JbWH5rCw3RKVzmaCOtaEpp3fEP5jmk1Ilq0CqAVW5YGDWvw5QtWUsZGVXZIyTxjf7zBBRDkFcVAqBucNAIOzEcY9Nv5AeCQ9+H4oXR9BoiuZy1I9/ZFpEzRnLYnj1f39at5deKKeWTTH/fBgdT+HADNd8AHacIa+VxgRtl6DA1Ulq8Jo92LklSPQBf4WTtKq/6S2pqUGf36WTm2oBegwurAgD2qO5+529U0teWnY97XUIBXm6qjgID85TIXUiJoUgxCh+7WvMv1c54vRlVckmmdfQNrNx+P20VtjLHHw/D4n/mf6d/x/yJKnu8b/DmnX3lHNxQ0TbtKLnEeGLHcicSMoYy3Lx1bMT5C5ZP3pGtHkPy0J0gbhEps5BAMSUAa6wJUnqbfGdQPCGYQg+z69+L3JMl4zbtJWli3uEUPkk7XGy04AnmsPneTcjCoIs2OAawnZNa1LDIHFtbxzhCARPTdxknoMzbR97/sL/vsdJvMoowvaSm7UG0HOAAYDF452YOGCEgLSz2pxKnFOUKjfu5v/g19ylSs6NcRcUvpFYTk/dEUrfOGo0RQMae/KwrSjuBUxiPY+9iRLbT4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mKrFNl0/Qt8SbHqQZJKJDk73LFOaliYkfBCxZPoZysko/kiktvDJ5eAkrPmJXnb+Y4ncTpsbVg1AJqN9wJk9DEh35qien3AbzExb0d9UaXyxksli0cUf7Lx09WhVbIiI6J90tx2Ds4lP/3yO8TJflyAkFPmvwKc5IjH45Da+4dUe2SPymckEFEstAM36g7BoXV+j1zmAJjAWaMK8PvY0xkZWQIlp1ki7iECeK5L4SEmbp2PsnosaYiRGV0Eoq9NtwVqwtgsDBHw7nCJGsZ1pl9N0EtZUtEN8bKe6TF5LplXQupRATrkRA1+tbrDxLnA5fTdxLd/yTbKMgtV6Y= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a015b8b-97a4-44b0-a390-08dcf4d94228 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 09:41:53.7288 (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: enKY8pkm2t0s/rqlC15lPTIsAGIDhROiAz+mRld2+/M0a0+wSIuNv0wCFeLRL8lns6ELPOk+n/Q6n7HmyvrXN4JbDeOT0B7t2VfIlIqnjDo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB6121 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_06,2024-10-25_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 adultscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 spamscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410250073 X-Proofpoint-ORIG-GUID: H9G-8VMbDrnKc7wRgbtI08FpLtwuQbRz X-Proofpoint-GUID: H9G-8VMbDrnKc7wRgbtI08FpLtwuQbRz 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 - From patchwork Fri Oct 25 09:41:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13850333 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 710662003A2; Fri, 25 Oct 2024 09:42:16 +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=1729849339; cv=fail; b=ft/h/jNPd3osznwuM0IOX/iiEkGNWV2FD+kZX82lf0gOi//5O029cG246SntyE47ZFFwRAY0Ukl8kSxl0BddoYVHkERvuHYsI2+Q/jm7ILW/KKtOCKdGKpZTrbBxHW8Q61XwL89Ua4bAfsfvfhoNFIEZwdOsrWUb0Pz/ps8o02c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729849339; c=relaxed/simple; bh=nmd33tz+RsvGErxgfURnJZUoF6Jk9JXr5vUjQjkwjU4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=CxPlzO/VaZ880cphClyprdH/VriSB9Ab151sWNfFHtfiqAhquzJ8mHHCxN/YUGRvXQug3gmj2fK8MxIoK315WNXOAe/Fwf2TbXDjEMSZEku2bkInlNyCxfRu1sDTVZNXUdT01Sw415vz7IDveMDjJ3/n7crbfsuEi7orrJl+TWk= 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=T7SIR7zr; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=JzmotlE4; 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="T7SIR7zr"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="JzmotlE4" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49P8BXd1026773; Fri, 25 Oct 2024 09:42:00 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=wY6kdgChMItf6mowLK+7M+e6qDkjxAzv9eXffTxVzSk=; b= T7SIR7zruLPBUdWn69jxBGKZ1lnV9mJk9rc/XaYI+q0hd+Z+u+tBFqQPXG1IMwQU PuAtKufm4sc2bzgYnG7BBz6ZGRQ/4uIQ5M2J9myBCX2cif1x3nrQ0htRo9l4bQ6A e9S/zcBveV20+XUuSH35WpOdseW/o/Ge5Fe95NYQ8V3YhihQas9AO9ay7jb4kDAH GpcYetaYQ09QYSBtKgXvUDfE+MNXkQEeqaTQ6eRc2iJcj0aJsghtBCYyH7Cl/c0h inZvAMfjJrAkh67P02JUt75VQA31smB3fOKtZDNV1s3S9ZmZnGvcPNMSKiGtO62q egpe5BLTo0c8JyTQhtx6hQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c55v4kf0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 09:42:00 +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 49P8Mfjc002210; Fri, 25 Oct 2024 09:41:59 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2171.outbound.protection.outlook.com [104.47.57.171]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42g36a9ybt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 09:41:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qfWEdDcI6JMq4cvoz9tEjbhSB/rPbgzUnHhBg9RNk7cKdQLRIE8gCEdZtgP5DMWU1UNY75lKX4YECo+BPea4o0x8eYfzkD+o6QYAHIkdTgT3zJNR5Lpst4keUCdYsJLAqBFS9eJSeP3OWmCp69YUUGbkC8y/Wg581u23orILrV1ZipngOMVmqUX0jQMVAHo/m9RvMiJVQ5OtCyfq+o0aU8s+NQ1IoGAN7a3eN7mASfMs+Fu1T8bgSvYb08mbA1At5Db2haxQeKHhnL48rCBZnv1Th41ZuprmyXZTYFpn+8JBMjy0vd8FXwXVqec/tLPbwUwKgDdwQBU6gPqAHiqM9Q== 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=wY6kdgChMItf6mowLK+7M+e6qDkjxAzv9eXffTxVzSk=; b=dbrD9fEwLHQl1LFLJ2bkPkW96MF/lo4nP1P05RAF8+Pf0FAE57T+g6TMZHK9jtmSgKOcka0guRjcKVeWDjlLaYwWdh1Ae+/epRaIjCqHpSOEWeFyCLfMfsf73wmgzSaiydNx4P4jlLUhEHV4xvtzG1tWaKFmYgvcvdJeTvN8yLqKb9u2oOqEUR39IQB4drMdIZujM0oxWwsAoqI3O/x7+LqTo8xTL9nU+pFRCttRGDZ14w2+MGf/3ZFzr2D/NEui7OhHwzLlpF/qr+QBY4B0xkbTzWYQAkUy+n8xlimwpAooA8+b/5bpc+n4Xfby0IB+INwnBO+42PrjIzJkh430IA== 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=wY6kdgChMItf6mowLK+7M+e6qDkjxAzv9eXffTxVzSk=; b=JzmotlE4Gd2v1juemedHvlZySF2mZbQD0x7376EXToXyVUzY0Hob93MRNhACy2OYjqIvBF5MxRiEgLttYTcOBqnu+Axw3rlH4ONQHMoS0TWnjtD6f0Bf00RZV0ZsO+M8EF69qQVKlVj+uVG3RG+GRIv6+1q5D+3nlqJX/qhnR8U= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by IA1PR10MB6121.namprd10.prod.outlook.com (2603:10b6:208:3ab::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Fri, 25 Oct 2024 09:41:56 +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; Fri, 25 Oct 2024 09:41:56 +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 v5 5/5] selftests: pidfd: add tests for PIDFD_SELF_* Date: Fri, 25 Oct 2024 10:41:34 +0100 Message-ID: <36d9dbea7475850ac9206fcd0d3ea1f1d02312fb.1729848252.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO3P123CA0031.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:388::10) 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_|IA1PR10MB6121:EE_ X-MS-Office365-Filtering-Correlation-Id: 5837dcf0-4138-4b4e-4aff-08dcf4d943fb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: 7y7I41QU/uHo360g6gBhDjMAJBfro2kqm/f1ZUFANDCRbI7sm5Vk90nftW0f35MPCLyrJqkVfD/VHREB5dpt+XdzzsJ43mCKBNhCJoaf9V8v7hpw5jWeTcFZI12gs55LMJIFzX6SfkKnhKubAOxWTPEH2jTeerLEgifqo4BzjxV89WD8W54kqtlW8A1c6ap7yX8UeBT70yyhPi1cxvNPcJOPh4lwczyBcoWtSZwXHgxzJHHwhMQrs+v4Dmau55WCZkchPMxhvXxZKF8tuxJIsUyfAiR9sNv7u4Ee5Ds+Q1ijozk73nLfu/c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PM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: d2tWEioTJC8LAkL+0WpzxZg8GE62VPfEj1kV4UyNZfB/F/4c0bYtACZVTzGWhkMWkdslPW7D85yfqGfnVOnkTttKcn4Tp0LsTKmNr8gwxji1M7K2EZBf5XoZVkQZ/NkfdJR8Ad0bgSL2frD+MkTeF8H0fPtXC8uOHHIfOCwlMlg/sxSU1v9uvOoIrUjrKFD7R731C51uJrDZP+Ezo6NrAuKE2S4JTXeZgaXL9BHwQ0n1xR+vlYSPEtn9QFzdB3DFWuR+HuoDAgrCRdQpzrABpWU5D5Vyb9r7eauT3ItH+IWHFD2mvAX4QgBjIhBuW0TBE8/NrztngiE44jGPwhOmdls1tP0vsOb2gAeEz3VHl1VkWiDyIPtYf4A3qM9rUBm7ZgVEh9mGGO6e3icRDHh29D9cWF/uu3M37det+q3wD3/82kLW/AEYV+X7kyNgNz7rvOMHvml3gxdDfPXV7z0P8CCf8AdH8Gs21rDHR2GQ1AjUriekW9Oi/Q+xoKN7X8osyB6pTn+PJHyIqIkN2rdiFORFgA/h8hnruDzgAC5IujLjiaIsiUn/EJPNNNU2zwCMLE9+iqeKGTl7UhF4+Oq86vrqpJijx6+XynJr3WAbUKPHNSGsD1QAP42c2oOt2xtwn7rswi/fuNynRMOsVnqc6noLiptbQLXTut0KYGYhrZsV2NvMDFsPlcLMzma6fxoDg4VPSSyCc8B9H5rI7A1m1SLDhA6Uqdc+7bJOAs/nccT/DEBJgaiAQFY7CiWR6eF6xPESzBWhSE9LzSHpci4MnxaiM9gh2uQtBogQnvBfr4FNI8qbYTpDunwcdUKsdwHuvBH4ZPKwXinGpwrkOe05g09Bdh7WziMTGah0uR+u1KbA0UldoN9lj5MznMybiMJPvQuoyQia9a3EBcyf2+/5sNNuWJhITiNbM01+AGO7BKFODvWcV3zbf90DK02kq78pYsWI78Blp4KF+lUbhkQR8afLMuDKKt9XwxFqBPyRqpy1gnjV6W2NzXIFcbO7xFlkDNdSkS3UZhYMcSGMuVywCx71l00OZjj5uwufSpW7DiZIssHACAfZFBdoAxriTGJBjh1fYJGeeu4JagYr/hplzKI94vfrZOTlwpYCCug9SR/cNtfjegOh3FVehSkAdADECWBQs5v9n5RB8FBgA/bRpTabvFYlPDrcD7fBJXvrSLmIameOn62VKc2OttLJG4689jI/kJlddyc3xJ3+iVxylpqiWLV+Iz2zbKXzENXLKt6MSREVoMSPDP6AtTuD4U0vrJUPIjd+Uh/gsGZO2XhOS3y5leRWD16pUmwoW6pSnh+GwYWlSX95jIhraF2c1WacpFE2PLeOWqEZbqXqcVavSydjbQFHRODOJGKhyLpm9K8GiM8a5ZnApBgjMeM5lXanyr9INEh7Nj2dZqvCAIch2lHQvFzQsNKqnX8o+0c6S2yQKYdUHIciJdQ2bZG6JGW2aIQIy0mPeNsK4V9exFPk2LuYdIW6PC47iqe/xGghHJLRZI1zXdMno6kHeZuhe2ChrhbvfkYwBUU9waYunf3BwiRvu2WMgasECi9IvrD3Si+QPEfGPNlcKr1Yxn0JF1YBTmDRwkbcP/BxSmbXNy8oaDh1BemEdDL0/GLZXGPeCNC1GY0wUq9TAQU5pklX18O2YJiTbmMniDlBF00zNsLHHg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: +Qpu+I6Nr+FZmZSwcag+LVp8y5Ws2vcdcjvZReCwygKchJC06gP6rBTAfiCmAcfdieERQKY6cnPsOF/GyJPsft3yDF0/q5EKMA2xKvpoZDBcmMFQ6uHlRj3RhWNqLYBqvfAAXmZ/ncP1Ze9gwd6sAHecK8lapUeU49eKujD7RGWzRl8xYxytJ2QXLX28lboOtRTpoM3KrwKlte8RVv9aQC1CoazidwQcVwZfDnNdvBwW5kGXQqPYwAHStidoAlLTt0UrtJ7lW17m7/2g3MnKCb6Vm672NqzmOtfRHmIqY2L/3c+9kam5gJOV1kVh2dmYdgm6RpZ0tHN+4f9MtB2uFNX1lTjmcHmvZxPEVZT6BU3nOt7wOtGCcrVnYrd4HmspEm6DC1aPGg3MgkZQT/eKuR29cpWt44Vtym39o4MVw2Byt8zpZ0tJMsvGb2wXLvUP9BKccY/WPfuATwZg6JvF8y0KezOenfejYFFWZIvVChS0Ov67DxvnjDzjR5ZbMRx6fRJW1CKWHG6QZSMPmb3aEO+bzHqiSIcMxtLeI3bCSkYsaBwfyvdzDqUbJMiLrjUCpUbQOGQ207RXMLTCa21SJU9JuQge08WjUrF2Glui95E= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5837dcf0-4138-4b4e-4aff-08dcf4d943fb X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 09:41:56.6619 (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: fW9Qg/7O8fW9a6gk+PHCaGJBp0vyU224R4eAq27i1JLNIrmq8EhhDNj2Ug6s7FFhfEHboIzm2d5JILi/YZRcsGOm1gcGHFKFsSqXmr2QvNw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB6121 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_06,2024-10-25_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 malwarescore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410250073 X-Proofpoint-GUID: fZaWXAsNQzc4D_kL-EFj7EnRL01cgrnR X-Proofpoint-ORIG-GUID: fZaWXAsNQzc4D_kL-EFj7EnRL01cgrnR Add tests to assert that PIDFD_SELF_* correctly refers to the current thread and process. This is only practically meaningful to pidfd_send_signal() and pidfd_getfd(), but also explicitly test that we disallow this feature for setns() where it would make no sense. We cannot reasonably wait on ourself using waitid(P_PIDFD, ...) so while in theory PIDFD_SELF_* would work here, we'd be left blocked if we tried it. We defer testing of mm-specific functionality which uses pidfd, namely process_madvise() and process_mrelease() to mm testing (though note the latter can not be sensibly tested as it would require the testing process to be dying). Reviewed-by: Shuah Khan Signed-off-by: Lorenzo Stoakes --- tools/testing/selftests/pidfd/pidfd.h | 2 + .../selftests/pidfd/pidfd_getfd_test.c | 141 ++++++++++++++++++ .../selftests/pidfd/pidfd_setns_test.c | 11 ++ tools/testing/selftests/pidfd/pidfd_test.c | 76 ++++++++-- 4 files changed, 218 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/pidfd/pidfd.h b/tools/testing/selftests/pidfd/pidfd.h index 0f3fc51cec73..1dbe48c1cf46 100644 --- a/tools/testing/selftests/pidfd/pidfd.h +++ b/tools/testing/selftests/pidfd/pidfd.h @@ -16,6 +16,8 @@ #include #include +#include + #include "../kselftest.h" #include "pidfd_helpers.h" diff --git a/tools/testing/selftests/pidfd/pidfd_getfd_test.c b/tools/testing/selftests/pidfd/pidfd_getfd_test.c index cd51d547b751..48d224b13c01 100644 --- a/tools/testing/selftests/pidfd/pidfd_getfd_test.c +++ b/tools/testing/selftests/pidfd/pidfd_getfd_test.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include #include @@ -114,6 +116,94 @@ static int child(int sk) return ret; } +static int __pidfd_self_thread_worker(unsigned long page_size) +{ + int memfd; + int newfd; + char *ptr; + int err = 0; + + /* + * Unshare our FDs so we have our own set. This means + * PIDFD_SELF_THREAD_GROUP will fal. + */ + if (unshare(CLONE_FILES) < 0) { + err = -errno; + goto exit; + } + + /* Truncate, map in and write to our memfd. */ + memfd = sys_memfd_create("test_self_child", 0); + if (memfd < 0) { + err = -errno; + goto exit; + } + + if (ftruncate(memfd, page_size)) { + err = -errno; + goto exit_close_memfd; + } + + ptr = mmap(NULL, page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, memfd, 0); + if (ptr == MAP_FAILED) { + err = -errno; + goto exit_close_memfd; + } + ptr[0] = 'y'; + if (munmap(ptr, page_size)) { + err = -errno; + goto exit_close_memfd; + } + + /* Get a thread-local duplicate of our memfd. */ + newfd = sys_pidfd_getfd(PIDFD_SELF_THREAD, memfd, 0); + if (newfd < 0) { + err = -errno; + goto exit_close_memfd; + } + + if (memfd == newfd) { + err = -EINVAL; + goto exit_close_fds; + } + + /* Map in new fd and make sure that the data is as expected. */ + ptr = mmap(NULL, page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, newfd, 0); + if (ptr == MAP_FAILED) { + err = -errno; + goto exit_close_fds; + } + + if (ptr[0] != 'y') { + err = -EINVAL; + goto exit_close_fds; + } + + if (munmap(ptr, page_size)) { + err = -errno; + goto exit_close_fds; + } + +exit_close_fds: + close(newfd); +exit_close_memfd: + close(memfd); +exit: + return err; +} + +static void *pidfd_self_thread_worker(void *arg) +{ + unsigned long page_size = (unsigned long)arg; + int ret; + + /* We forward any errors for the caller to handle. */ + ret = __pidfd_self_thread_worker(page_size); + return (void *)(intptr_t)ret; +} + FIXTURE(child) { /* @@ -264,6 +354,57 @@ TEST_F(child, no_strange_EBADF) EXPECT_EQ(errno, ESRCH); } +TEST(pidfd_self) +{ + int memfd = sys_memfd_create("test_self", 0); + unsigned long page_size = sysconf(_SC_PAGESIZE); + int newfd; + char *ptr; + pthread_t thread; + void *res; + int err; + + ASSERT_GE(memfd, 0); + ASSERT_EQ(ftruncate(memfd, page_size), 0); + + /* + * Map so we can assert that the duplicated fd references the same + * memory. + */ + ptr = mmap(NULL, page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, memfd, 0); + ASSERT_NE(ptr, MAP_FAILED); + ptr[0] = 'x'; + ASSERT_EQ(munmap(ptr, page_size), 0); + + /* Now get a duplicate of our memfd. */ + newfd = sys_pidfd_getfd(PIDFD_SELF_THREAD_GROUP, memfd, 0); + ASSERT_GE(newfd, 0); + ASSERT_NE(memfd, newfd); + + /* Now map duplicate fd and make sure it references the same memory. */ + ptr = mmap(NULL, page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, newfd, 0); + ASSERT_NE(ptr, MAP_FAILED); + ASSERT_EQ(ptr[0], 'x'); + ASSERT_EQ(munmap(ptr, page_size), 0); + + /* Cleanup. */ + close(memfd); + close(newfd); + + /* + * Fire up the thread and assert that we can lookup the thread-specific + * PIDFD_SELF_THREAD (also aliased by PIDFD_SELF). + */ + ASSERT_EQ(pthread_create(&thread, NULL, pidfd_self_thread_worker, + (void *)page_size), 0); + ASSERT_EQ(pthread_join(thread, &res), 0); + err = (int)(intptr_t)res; + + ASSERT_EQ(err, 0); +} + #if __NR_pidfd_getfd == -1 int main(void) { diff --git a/tools/testing/selftests/pidfd/pidfd_setns_test.c b/tools/testing/selftests/pidfd/pidfd_setns_test.c index 7c2a4349170a..bbd39dc5ceb7 100644 --- a/tools/testing/selftests/pidfd/pidfd_setns_test.c +++ b/tools/testing/selftests/pidfd/pidfd_setns_test.c @@ -752,4 +752,15 @@ TEST(setns_einval) close(fd); } +TEST(setns_pidfd_self_disallowed) +{ + ASSERT_EQ(setns(PIDFD_SELF_THREAD, 0), -1); + EXPECT_EQ(errno, EBADF); + + errno = 0; + + ASSERT_EQ(setns(PIDFD_SELF_THREAD_GROUP, 0), -1); + EXPECT_EQ(errno, EBADF); +} + TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/pidfd/pidfd_test.c b/tools/testing/selftests/pidfd/pidfd_test.c index 9faa686f90e4..440447cf89ba 100644 --- a/tools/testing/selftests/pidfd/pidfd_test.c +++ b/tools/testing/selftests/pidfd/pidfd_test.c @@ -42,12 +42,41 @@ static pid_t pidfd_clone(int flags, int *pidfd, int (*fn)(void *)) #endif } -static int signal_received; +static pthread_t signal_received; static void set_signal_received_on_sigusr1(int sig) { if (sig == SIGUSR1) - signal_received = 1; + signal_received = pthread_self(); +} + +static int send_signal(int pidfd) +{ + int ret = 0; + + if (sys_pidfd_send_signal(pidfd, SIGUSR1, NULL, 0) < 0) { + ret = -EINVAL; + goto exit; + } + + if (signal_received != pthread_self()) { + ret = -EINVAL; + goto exit; + } + +exit: + signal_received = 0; + return ret; +} + +static void *send_signal_worker(void *arg) +{ + int pidfd = (int)(intptr_t)arg; + int ret; + + /* We forward any errors for the caller to handle. */ + ret = send_signal(pidfd); + return (void *)(intptr_t)ret; } /* @@ -56,8 +85,11 @@ static void set_signal_received_on_sigusr1(int sig) */ static int test_pidfd_send_signal_simple_success(void) { - int pidfd, ret; + int pidfd; const char *test_name = "pidfd_send_signal send SIGUSR1"; + pthread_t thread; + void *thread_res; + int err; if (!have_pidfd_send_signal) { ksft_test_result_skip( @@ -66,25 +98,45 @@ static int test_pidfd_send_signal_simple_success(void) return 0; } + signal(SIGUSR1, set_signal_received_on_sigusr1); + + /* Try sending a signal to ourselves via /proc/self. */ pidfd = open("/proc/self", O_DIRECTORY | O_CLOEXEC); if (pidfd < 0) ksft_exit_fail_msg( "%s test: Failed to open process file descriptor\n", test_name); + err = send_signal(pidfd); + if (err) + ksft_exit_fail_msg( + "%s test: Error %d on sending pidfd signal\n", + test_name, err); + close(pidfd); - signal(SIGUSR1, set_signal_received_on_sigusr1); + /* Now try the same thing only using PIDFD_SELF_THREAD_GROUP. */ + err = send_signal(PIDFD_SELF_THREAD_GROUP); + if (err) + ksft_exit_fail_msg( + "%s test: Error %d on PIDFD_SELF_THREAD_GROUP signal\n", + test_name, err); - ret = sys_pidfd_send_signal(pidfd, SIGUSR1, NULL, 0); - close(pidfd); - if (ret < 0) - ksft_exit_fail_msg("%s test: Failed to send signal\n", + /* + * Now try the same thing in a thread and assert thread ID is equal to + * worker thread ID. + */ + if (pthread_create(&thread, NULL, send_signal_worker, + (void *)(intptr_t)PIDFD_SELF_THREAD)) + ksft_exit_fail_msg("%s test: Failed to create thread\n", test_name); - - if (signal_received != 1) - ksft_exit_fail_msg("%s test: Failed to receive signal\n", + if (pthread_join(thread, &thread_res)) + ksft_exit_fail_msg("%s test: Failed to join thread\n", test_name); + err = (int)(intptr_t)thread_res; + if (err) + ksft_exit_fail_msg( + "%s test: Error %d on PIDFD_SELF_THREAD signal\n", + test_name, err); - signal_received = 0; ksft_test_result_pass("%s test: Sent signal\n", test_name); return 0; }