From nobody Mon Jun 8 05:25:26 2026 Received: from mail-dl1-f66.google.com (mail-dl1-f66.google.com [74.125.82.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8816A1FF1B5 for ; Sun, 7 Jun 2026 00:34:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.66 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780792451; cv=none; b=ILUSkmca/qlJti/xNwz0RkE7FPsdsIkybcnI2g7hO3e6nTIIexmqj+zFQtI1DK6cj6ThDzuHwtcxiVBaJkBHJNF/OIzy6z9yuBUBcGzCj4oOZ84bt2w9rkUmtXzkeae4XmysWRe9mKaTnJ2jLb5Wv5M7al2SUUtWMk7YCcc9/Kk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780792451; c=relaxed/simple; bh=ydHyg/yHgbQBSF7WWPMXrPO1fho5KdGEiISM0UJVrLo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CoYLHslid1auDBiVdKr5xkZ3ZbN+Fz8cRpVGxLAf63+45hrPIvSKw8aZM53H/6Q46TGaBD6CQKMChEelBCmauKux1eSt4jxdW0KFwI6EobgQQoLrzUqwl5PobwoiPWE/H+Ue4yZqimltuF6B0zfPxGhlpZ2G5QZsAYSWyY06zAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m0GNYZII; arc=none smtp.client-ip=74.125.82.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m0GNYZII" Received: by mail-dl1-f66.google.com with SMTP id a92af1059eb24-138188a7dccso1164784c88.1 for ; Sat, 06 Jun 2026 17:34:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780792450; x=1781397250; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FKXpsUK4JppanynxEZ3suyCmjR7j3BpgdIBDoN7gy84=; b=m0GNYZIIsAnyPZWsrAq0EPaP7V2LzzTBQyCF3Vt3Z5CPjGVT4kHnvRUCK15pJG0A9T l5Lrkv7jy97+9hgHDihcZJmm3VmzFK1Pp01ILpYDb9koXo5cmYyT7IYO62zo8lrOuqSK JDISlirPF6mCSckB7iUPWElV0BXzSHwxo4zJ2tATFhrTipUqMZwcF1adXfFPswcKtO2I bJmnpNkh7xuxnUNYy+21bue/CdSyrkozQKFnFvmTdoKiFQwnUi5dI1xN2kHT1z3YsEwF OHBghUVlo3joNILlKRbrdK9o9D5748uCLJ34tfuEN+KRYmtNmPUElbtMzsI+1QLk8TEQ SlkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780792450; x=1781397250; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=FKXpsUK4JppanynxEZ3suyCmjR7j3BpgdIBDoN7gy84=; b=k+VVZXkPipAsM/duoxC/krsI7jw8TUkUSDHliQdegnj2Lmd6gbyhL/BsGNhe/jG1f8 oYjLq5bTh958ume0l+m2m7u0A7d+OfwDVnrPI0fvKZ+7qcDd6/9VHBcJfJYEmovoGwAs +OTmDQD97mxiYNsqeqq96UFq/h/KPMXcSrS2lWBqjG2G4YdyQiaWozyA9RlDh1J4YgC2 cmJ5VZ1Aj5vBnl6MX7TeSMtdTWXLtepTUwcBuf8QkhlhkWEiMuOs4EHQTtOb7OzE/cVK eHVy5Te7tvPmk0DDgy+EeWHPwmpNCzgpUdK/odVsNKZR1vSJLOCMFXZ7t6lPbolSjs13 CkXg== X-Forwarded-Encrypted: i=1; AFNElJ8TWR8jLJd+cm19ePq6hvBL1ICfcQEtwfsaYuXGHISgysd+6rdT1wesbLzHfW7qxv3pAUklRwaZv08L1YY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxvk2KdzxYXKygegPVlqnA+Lswv1HdZBc7FnLNgWHZ5JhEgYw/e XSVFwmBdm+E7UZ8ex1Rp3douj5E4ZlML8EgCl/clkpVXGUIHb3EUeKAW X-Gm-Gg: Acq92OEDvbvWqaAWQyDpPk+LbjNnC4Zj72JoNgnqRzsLxABkSzop/At+HgOkfppsKSE 3cX2qLNx9V3PBrMflfM0V6cHdPZGEjivTcVYRqnB7xJcLxsnVzZ/ZutI152OBlyHt+9X4xE3uTl P8lCJW26+6VTrYPOM8sPcS1iticqioO2+TvnfTR7YFOJiwuiiBco+4j7Xu0y7o732D/muO4Tyar 1Vj+Arq++kgBacO/Aq3OBi+9MOkS3bTTliwbGc0YE6GBaLN5tvRwHCqzqDKNVC2PEDBZwrih8V2 R0OrRrp/1RCImKoXheOdi0xx6fVqN5YnNlcy09kIv5bgbfR6CoELTOesCXzWH03Y9fn4Y3NpxXp nlMHyNrAZtB0S1yX+9z6GiEvKt28aYR/BD/soNkFOJNq/u5nqnlJKZAA4q2BulcvG3e2/GCK+XR T71gEXGbqFxK1oe/fbQMuGMO+pbiuCDQ== X-Received: by 2002:a05:7022:eac3:b0:130:aa42:167b with SMTP id a92af1059eb24-138067319f5mr5198147c88.36.1780792449701; Sat, 06 Jun 2026 17:34:09 -0700 (PDT) Received: from anonyme ([2605:52c0:2:2f27:be24:11ff:fe89:6f0f]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-137f716017esm13451383c88.15.2026.06.06.17.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jun 2026 17:34:09 -0700 (PDT) From: AnonymeMeow To: jack@suse.cz Cc: amir73il@gmail.com, brauner@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, AnonymeMeow Subject: [PATCH v5 1/2] fanotify: report thread pidfds for FAN_REPORT_TID Date: Sun, 7 Jun 2026 08:33:42 +0800 Message-ID: <20260607003343.425939-2-anonymemeow@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607003343.425939-1-anonymemeow@gmail.com> References: <20260607003343.425939-1-anonymemeow@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The FAN_REPORT_PIDFD and FAN_REPORT_TID flags used to be mutually exclusive because by the time the pidfd support was introduced to fanotify, pidfds could only be created for thread group leaders. Now that the pidfd API supports thread-specific pidfds via PIDFD_THREAD, this restriction can be lifted. Reviewed-by: Amir Goldstein Signed-off-by: AnonymeMeow --- fs/notify/fanotify/fanotify_user.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanoti= fy_user.c index ae904451dfc0..ebdd48942029 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -19,6 +19,7 @@ #include #include #include +#include =20 #include =20 @@ -903,25 +904,21 @@ static ssize_t copy_event_to_user(struct fsnotify_gro= up *group, metadata.fd =3D fd >=3D 0 ? fd : FAN_NOFD; =20 if (pidfd_mode) { - /* - * Complain if the FAN_REPORT_PIDFD and FAN_REPORT_TID mutual - * exclusion is ever lifted. At the time of incoporating pidfd - * support within fanotify, the pidfd API only supported the - * creation of pidfds for thread-group leaders. - */ - WARN_ON_ONCE(FAN_GROUP_FLAG(group, FAN_REPORT_TID)); + unsigned int tid_mode =3D FAN_GROUP_FLAG(group, FAN_REPORT_TID); + enum pid_type pidtype =3D tid_mode ? PIDTYPE_PID : PIDTYPE_TGID; + unsigned int pidfd_flags =3D tid_mode ? PIDFD_THREAD : 0; =20 /* - * The PIDTYPE_TGID check for an event->pid is performed + * The pid_has_task() check for an event->pid is performed * preemptively in an attempt to catch out cases where the event - * listener reads events after the event generating process has + * listener reads events after the event generating task has * already terminated. Depending on flag FAN_REPORT_FD_ERROR, * report either -ESRCH or FAN_NOPIDFD to the event listener in * those cases with all other pidfd creation errors reported as * the error code itself or as FAN_EPIDFD. */ - if (metadata.pid && pid_has_task(event->pid, PIDTYPE_TGID)) - pidfd =3D pidfd_prepare(event->pid, 0, &pidfd_file); + if (metadata.pid && pid_has_task(event->pid, pidtype)) + pidfd =3D pidfd_prepare(event->pid, pidfd_flags, &pidfd_file); =20 if (!FAN_GROUP_FLAG(group, FAN_REPORT_FD_ERROR) && pidfd < 0) pidfd =3D pidfd =3D=3D -ESRCH ? FAN_NOPIDFD : FAN_EPIDFD; @@ -1628,14 +1625,6 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, = unsigned int, event_f_flags) #endif return -EINVAL; =20 - /* - * A pidfd can only be returned for a thread-group leader; thus - * FAN_REPORT_PIDFD and FAN_REPORT_TID need to remain mutually - * exclusive. - */ - if ((flags & FAN_REPORT_PIDFD) && (flags & FAN_REPORT_TID)) - return -EINVAL; - /* Don't allow mixing mnt events with inode events for now */ if (flags & FAN_REPORT_MNT) { if (class !=3D FAN_CLASS_NOTIF) --=20 2.54.0 From nobody Mon Jun 8 05:25:26 2026 Received: from mail-dl1-f68.google.com (mail-dl1-f68.google.com [74.125.82.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D36521A453 for ; Sun, 7 Jun 2026 00:34:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.68 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780792454; cv=none; b=Iegg58mn0hO5nzAw68uQczCSp5rYPp/gLZfJ6b7mUlK/DEtIUbGT2VYh2NulVILTu48qoFgYV7uL7bTeAe3op5dsx75fAIdptS6glfi7jVe1iChgT0KLNOjmK9ecHo8yXxFqD+z3uEUgctpN3Z665fMcPE3m1bQnNzC1DZ1j7Z0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780792454; c=relaxed/simple; bh=5gxaVxo3xM8fukkjl9cAMluFaofUCDDCFLEg6biKk6s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SHGuYnJRM1/9KehVVgX6KqzQ2FASBS9xJ7xh6Y9h33g3uaLiB9b+CFCurycXhUjKJNMlRI9Vp6iPKCZ3mMB+s3cejybwm8SKP1oLFLeakM9GXYwuB7Z2zsBc5TEk5x7y1hOEugoVEH+S9zo9+0arCJNzl3UGOxbi0Oyu8cpxqkE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iSm5KO3Z; arc=none smtp.client-ip=74.125.82.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iSm5KO3Z" Received: by mail-dl1-f68.google.com with SMTP id a92af1059eb24-137d464c47eso2610929c88.1 for ; Sat, 06 Jun 2026 17:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780792452; x=1781397252; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Yb52RRXQv7KcVlnarae14d7zbBmk629IfEhtSbYPJos=; b=iSm5KO3Z+/ADfxk3HB/dE/Uook5dNzj07Sulr5s16CGuUcsiIy3MOqYRkNEyFsjCTK QnF1EafbPn5w749hq/I9kUBsDRWlWELQazkp3gSN61bVH91GLTblFUX5+wQ2afrJcEoD aICL/6PqexjRUg/yAF6M2gLRM/+6TH7cCnLWnwOd07EH7cOMYa7roOibwDPhcm8Ye58c Mg0ddoHy7LP4QD4qeu8KO8Vu+J1rUkVrSV3ZXOvP3aqJYlxGlK3YJVw97FzRFS+bfXtj 1gplWkwxIl0ChkD59P2lvUvQlFns8avIMZHTWEN8XVNb6E6e2hzpOdgFWCFqIc7vYBkA yzqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780792452; x=1781397252; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Yb52RRXQv7KcVlnarae14d7zbBmk629IfEhtSbYPJos=; b=VDAxN0xQa/k1/en2IPPVVh9ewbLl8QK0R9SOXYyWvfPOpFxxB7tYD3Qyd6f+LSYLSZ T/mY/TAAZ2MYrPhwNHd6F3g/iE0KKEr5i3hITZR8dOwjrmiKyQJ6q4QEZopcUD9PE4+a Jb4GoWpvrtI1U8Zs6TyovMjgaN6pgGcZ8Cwyf/kRFePrcmyO71I2Euk+rhLDGhk5OUOz E2jFUOvvL4NKQY8OM5Kg7ytwXJA43re4jnoeF5zDFANG+uGhxizx3nBSpVrzOSErJxaR bz3Mol9JzXLXfKngpY47UQtI/9N//jDlL3VO6gmt+4WH5QzVzdYSTyWbHimAXsCxHd0m 9xOA== X-Forwarded-Encrypted: i=1; AFNElJ9YQCxrngk3MI/SYXhSNzJAWx3RzhFisTG4dn/0Qf+4XxnnRviB45B55fX7wlGOzpqtVtHTISOs8LFiSnk=@vger.kernel.org X-Gm-Message-State: AOJu0YzqCQ+JL9qq6a0xXWkVK6l+cGejCmTfauVk4y1RXLEyno02jH1z Y4E6V1tP/4WLnATWmfpiXSmq8eb4W73CzuvofRjLbtD7q4vmSCpzIdL1 X-Gm-Gg: Acq92OFYg89UJJ2dYbMwuaGtnKzIJ7OgyAyHjzDgYIiug6xYpewDlaI0NeS/NKlkJKK 4zEYClo6l0oKHBk16rE4ZOrUkVyvpA2vMqxZrrVJLvUq1hjshWr5JYK/QPmF5txFEO5X7MP85sQ 65cA6uqk8ar4Av0GDe2r7ZfkH7WFSqRr9hU7jp7FcxW8P6/yN+46bUB5C0j1hSV0LlBba/RV8Xh xh5MY5qWEznCgCQ4AdhIK8ospqdsPeWdp4XVq8CAX4xRvcE6torkdTffsFZQ9CVSmKR59RFV237 G5/I01I3Wzx2XDavUNzuVMuDItIAbyfWKKPgHF5bjd2xu1kkB058SYI5D02NIrvGmWBA4Mi5p9A 22NBsOD7wW+ELK2SaA26AeriiwHkgBtBQkPaMG4mpjNKeqQipC/a1dYr4TNow2K/bVgs6OOg9V/ GpZE78zsNfo3O2yAiGkoiBF6vZuJs3Dd04BBPrg67y X-Received: by 2002:a05:7022:122:b0:12d:c9b6:bbe2 with SMTP id a92af1059eb24-13807d07321mr4311493c88.2.1780792452211; Sat, 06 Jun 2026 17:34:12 -0700 (PDT) Received: from anonyme ([2605:52c0:2:2f27:be24:11ff:fe89:6f0f]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-137f716017esm13451383c88.15.2026.06.06.17.34.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jun 2026 17:34:11 -0700 (PDT) From: AnonymeMeow To: jack@suse.cz Cc: amir73il@gmail.com, brauner@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, AnonymeMeow Subject: [PATCH v5 2/2] fanotify: allow reporting pidfds for reaped tasks Date: Sun, 7 Jun 2026 08:33:43 +0800 Message-ID: <20260607003343.425939-3-anonymemeow@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607003343.425939-1-anonymemeow@gmail.com> References: <20260607003343.425939-1-anonymemeow@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fanotify used to refuse to report pidfds for reaped tasks by applying a pid_has_task() check before calling pidfd_prepare(). This prevented userspace from obtaining information about the task. Register the event pid with pidfs when creating the fanotify event if pidfd reporting was requested, so pidfd_prepare() can later create a pidfd for the reaped task. Suggested-by: Christian Brauner Link: https://lore.kernel.org/linux-fsdevel/20260528-schmuckvoll-heilen-gar= en-be77b4208671@brauner/ Signed-off-by: AnonymeMeow --- fs/notify/fanotify/fanotify.c | 17 +++++++++++------ fs/notify/fanotify/fanotify_user.c | 18 +++++------------- fs/pidfs.c | 10 ++++++---- include/linux/pidfs.h | 18 +++++++++++++++++- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 38290b9c07f7..ece9523e775b 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -14,6 +14,7 @@ #include #include #include +#include =20 #include "fanotify.h" =20 @@ -842,6 +843,15 @@ static struct fanotify_event *fanotify_alloc_event( /* Whoever is interested in the event, pays for the allocation. */ old_memcg =3D set_active_memcg(group->memcg); =20 + if (FAN_GROUP_FLAG(group, FAN_REPORT_TID)) + pid =3D task_pid(current); + else + pid =3D task_tgid(current); + + if (FAN_GROUP_FLAG(group, FAN_REPORT_PIDFD) && + pidfs_register_pid_gfp(pid, gfp)) + goto out; + if (fanotify_is_perm_event(mask)) { event =3D fanotify_alloc_perm_event(data, data_type, gfp); } else if (fanotify_is_error_event(mask)) { @@ -863,15 +873,10 @@ static struct fanotify_event *fanotify_alloc_event( if (!event) goto out; =20 - if (FAN_GROUP_FLAG(group, FAN_REPORT_TID)) - pid =3D get_pid(task_pid(current)); - else - pid =3D get_pid(task_tgid(current)); - /* Mix event info, FAN_ONDIR flag and pid into event merge key */ hash ^=3D hash_long((unsigned long)pid | ondir, FANOTIFY_EVENT_HASH_BITS); fanotify_init_event(event, hash, mask); - event->pid =3D pid; + event->pid =3D get_pid(pid); =20 out: set_active_memcg(old_memcg); diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanoti= fy_user.c index ebdd48942029..b604e3da58ad 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -904,20 +904,12 @@ static ssize_t copy_event_to_user(struct fsnotify_gro= up *group, metadata.fd =3D fd >=3D 0 ? fd : FAN_NOFD; =20 if (pidfd_mode) { - unsigned int tid_mode =3D FAN_GROUP_FLAG(group, FAN_REPORT_TID); - enum pid_type pidtype =3D tid_mode ? PIDTYPE_PID : PIDTYPE_TGID; - unsigned int pidfd_flags =3D tid_mode ? PIDFD_THREAD : 0; + unsigned int pidfd_flags =3D PIDFD_STALE; =20 - /* - * The pid_has_task() check for an event->pid is performed - * preemptively in an attempt to catch out cases where the event - * listener reads events after the event generating task has - * already terminated. Depending on flag FAN_REPORT_FD_ERROR, - * report either -ESRCH or FAN_NOPIDFD to the event listener in - * those cases with all other pidfd creation errors reported as - * the error code itself or as FAN_EPIDFD. - */ - if (metadata.pid && pid_has_task(event->pid, pidtype)) + if (FAN_GROUP_FLAG(group, FAN_REPORT_TID)) + pidfd_flags |=3D PIDFD_THREAD; + + if (metadata.pid) pidfd =3D pidfd_prepare(event->pid, pidfd_flags, &pidfd_file); =20 if (!FAN_GROUP_FLAG(group, FAN_REPORT_FD_ERROR) && pidfd < 0) diff --git a/fs/pidfs.c b/fs/pidfs.c index 1cce4f34a051..15efecf5cb07 100644 --- a/fs/pidfs.c +++ b/fs/pidfs.c @@ -991,14 +991,16 @@ static void pidfs_put_data(void *data) } =20 /** - * pidfs_register_pid - register a struct pid in pidfs + * pidfs_register_pid_gfp - register a struct pid in pidfs with custom GFP + * flags * @pid: pid to pin + * @gfp: GFP flags for memory allocation * - * Register a struct pid in pidfs. + * Register a struct pid in pidfs with custom GFP flags. * * Return: On success zero, on error a negative error code is returned. */ -int pidfs_register_pid(struct pid *pid) +int pidfs_register_pid_gfp(struct pid *pid, gfp_t gfp) { struct pidfs_attr *new_attr __free(kfree) =3D NULL; struct pidfs_attr *attr; @@ -1014,7 +1016,7 @@ int pidfs_register_pid(struct pid *pid) if (attr) return 0; =20 - new_attr =3D kmem_cache_zalloc(pidfs_attr_cachep, GFP_KERNEL); + new_attr =3D kmem_cache_zalloc(pidfs_attr_cachep, gfp); if (!new_attr) return -ENOMEM; =20 diff --git a/include/linux/pidfs.h b/include/linux/pidfs.h index 416bdff4d6ce..0abf7da9ab23 100644 --- a/include/linux/pidfs.h +++ b/include/linux/pidfs.h @@ -2,6 +2,8 @@ #ifndef _LINUX_PID_FS_H #define _LINUX_PID_FS_H =20 +#include + struct coredump_params; =20 struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags); @@ -14,7 +16,21 @@ void pidfs_exit(struct task_struct *tsk); void pidfs_coredump(const struct coredump_params *cprm); #endif extern const struct dentry_operations pidfs_dentry_operations; -int pidfs_register_pid(struct pid *pid); +int pidfs_register_pid_gfp(struct pid *pid, gfp_t gfp); + +/** + * pidfs_register_pid - register a struct pid in pidfs + * @pid: pid to pin + * + * Register a struct pid in pidfs. + * + * Return: On success zero, on error a negative error code is returned. + */ +static inline int pidfs_register_pid(struct pid *pid) +{ + return pidfs_register_pid_gfp(pid, GFP_KERNEL); +} + void pidfs_free_pid(struct pid *pid); =20 #endif /* _LINUX_PID_FS_H */ --=20 2.54.0