From nobody Thu Apr 2 20:20:30 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 291762D7812 for ; Wed, 18 Feb 2026 03:22:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771384973; cv=none; b=hi98ZIHi12S9PoOvq3h6kRTt2KJs+/f7hYknu0pJAhggYSIX+mMV4OrZXQlJL4j65ccUCNaIivdJh7O45E1HxNOH70uOGj+55z7RmnljOj96n/Y+VQXccO/vEsMDmKCkRDclpL3v8mULkatFypPrawAmEEiCsvPbqyRiZySWF5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771384973; c=relaxed/simple; bh=eJq/+XMB6svi9x0AYQBnKDSKHm/BAthL5E4dV59waz8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CNfVicZd0t2rkvuygAkpTxQQe9jQfd8m7hdNJkXRjC4QTq67sQpNuRpzhhnU69Ny6adefIciTh9s5F5aUzz3CN/pcaVDJ9W9IaNuZavGUqBmK0hYhREgr+owGLXmo33RqDTS3CFoVon+6oyDuOEdimH+DBjSNGYQApM5q/ArpEo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tjmercier.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CrPqB6VR; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tjmercier.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CrPqB6VR" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b62da7602a0so3741874a12.2 for ; Tue, 17 Feb 2026 19:22:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771384971; x=1771989771; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jIqN0vs9eY+KC/olxzGPUhC+4vShBUNYIEvhGLetjOc=; b=CrPqB6VRjy9s9BTsODgdfyZcG4t9vTioT9RzS8smM/SxCtfy1JM8584ZJ6bIhadpSI IHOzbJVNXtlowFPYiE5pILX2MH6B3Fq8ua5Un1ktmxXYm96cFSMav6QWbeIvwVjWnd6p N56tXqMyGO5Mx3Z1IwDGF9fxMrGiHsccr6KUeMce+y9+p00+Y2EkCt8Fj0VycRM995i1 EtB3Ip7wYhSp6xFlGVHJvVGNjA3m4nTYIj4MTNfA9TW8boOXas42PnVxTrIVtCd797Hp v3Bm0dDYXkOyC7WJItPZLObHSPCV4d7Q0HeWPHc7pQzkOeV19XxpUhZPYE/Hyr8jw7IQ GtEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771384971; x=1771989771; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jIqN0vs9eY+KC/olxzGPUhC+4vShBUNYIEvhGLetjOc=; b=MgoPfp1ZZIaYqY4m8ZQ8NkuVuKvGZZFaLlhGI6zNc9+EYAwU5VVjmCpuQ9LzgJZLZz K+n0kR5XERIXhzE6r2cyZTlNULyUAVE9l9VQheWgF7d9wEfD/00cEpdtMy/ymK6zohug TQvj44nr9lkTArkWcMqPUK2UJQyWOt4QR3GmEeOAzlcLM11JKqeVIjlIs5r2BYWhzVUP nLA7TibkGMsID6xriErUUtUu0aNZuFjgbaIsiEYpEGh1cRKuNVWyXulSZqF6l9Pazhpt 2aNIRBS7FXIoAfRBvlNNiLRaD5lIxtQU8QVUkclD/3VtWJZpnQkRJr9t7HZWmdFg4ESZ I5TQ== X-Forwarded-Encrypted: i=1; AJvYcCU2bn0j1k4HGP/J+ADJeEfz4eBtYiLu0P+VguX02c/9zTk16h0WjMOJmphE2dEGvm4COLm+kuegqDUnLv4=@vger.kernel.org X-Gm-Message-State: AOJu0YwW5P4VFaGUoyLKwEXTr36+3mG0JwFOS7IBwmbeMctNFu2h44hv VshOVpcp5E3Mjbi9L3pJKTAsRPqkGq73qgH27IoVMvkCHbtk5NPnTIcRP6ZINDVzkmWZgXuvzcF P9hBSvjoGpH3vnM5PVg== X-Received: from pgbda14.prod.google.com ([2002:a05:6a02:238e:b0:c65:c5fc:1707]) (user=tjmercier job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:9d4c:b0:38d:fad1:cf2a with SMTP id adf61e73a8af0-394837816admr11609765637.13.1771384971359; Tue, 17 Feb 2026 19:22:51 -0800 (PST) Date: Tue, 17 Feb 2026 19:22:30 -0800 In-Reply-To: <20260218032232.4049467-1-tjmercier@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260218032232.4049467-1-tjmercier@google.com> X-Mailer: git-send-email 2.53.0.310.g728cabbaf7-goog Message-ID: <20260218032232.4049467-2-tjmercier@google.com> Subject: [PATCH v3 1/3] kernfs: allow passing fsnotify event types From: "T.J. Mercier" To: gregkh@linuxfoundation.org, tj@kernel.org, driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: "T.J. Mercier" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The kernfs_notify function is hardcoded to only issue FS_MODIFY events since that is the only current use case. Allow for supporting other events by adding a notify_event field to kernfs_elem_attr. The limitation of only one queued event per kernfs_node continues to exist as a consequence of the design of the kernfs_notify_list. The new notify_event field is protected by the same kernfs_notify_lock as the existing notify_next field. Signed-off-by: T.J. Mercier Acked-by: Tejun Heo Acked-by: Amir Goldstein --- fs/kernfs/file.c | 8 ++++++-- include/linux/kernfs.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c index 9adf36e6364b..e978284ff983 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c @@ -914,6 +914,7 @@ static void kernfs_notify_workfn(struct work_struct *wo= rk) struct kernfs_node *kn; struct kernfs_super_info *info; struct kernfs_root *root; + u32 notify_event; repeat: /* pop one off the notify_list */ spin_lock_irq(&kernfs_notify_lock); @@ -924,6 +925,8 @@ static void kernfs_notify_workfn(struct work_struct *wo= rk) } kernfs_notify_list =3D kn->attr.notify_next; kn->attr.notify_next =3D NULL; + notify_event =3D kn->attr.notify_event; + kn->attr.notify_event =3D 0; spin_unlock_irq(&kernfs_notify_lock); =20 root =3D kernfs_root(kn); @@ -954,7 +957,7 @@ static void kernfs_notify_workfn(struct work_struct *wo= rk) if (parent) { p_inode =3D ilookup(info->sb, kernfs_ino(parent)); if (p_inode) { - fsnotify(FS_MODIFY | FS_EVENT_ON_CHILD, + fsnotify(notify_event | FS_EVENT_ON_CHILD, inode, FSNOTIFY_EVENT_INODE, p_inode, &name, inode, 0); iput(p_inode); @@ -964,7 +967,7 @@ static void kernfs_notify_workfn(struct work_struct *wo= rk) } =20 if (!p_inode) - fsnotify_inode(inode, FS_MODIFY); + fsnotify_inode(inode, notify_event); =20 iput(inode); } @@ -1005,6 +1008,7 @@ void kernfs_notify(struct kernfs_node *kn) if (!kn->attr.notify_next) { kernfs_get(kn); kn->attr.notify_next =3D kernfs_notify_list; + kn->attr.notify_event =3D FS_MODIFY; kernfs_notify_list =3D kn; schedule_work(&kernfs_notify_work); } diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index b5a5f32fdfd1..1762b32c1a8e 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h @@ -181,6 +181,7 @@ struct kernfs_elem_attr { struct kernfs_open_node __rcu *open; loff_t size; struct kernfs_node *notify_next; /* for kernfs_notify() */ + u32 notify_event; /* for kernfs_notify() */ }; =20 /* --=20 2.53.0.310.g728cabbaf7-goog From nobody Thu Apr 2 20:20:30 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 13FAD2EC090 for ; Wed, 18 Feb 2026 03:22:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771384977; cv=none; b=efxBaFyikAmw0iLEhqx1RYOBz2BX4wurMCEk9T8ge+Bu+jCu+8OCmgbM+8fsNe39YIUhlBukohBoy8EA9Skv/WeOeiKqbSybYavAaiPPaljE6iHAloZc/p6MdkR4NWxX44qXIr2c3pVYkLD39vUn6n7/KxbN8pzu/EpburXWcDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771384977; c=relaxed/simple; bh=E5jwkj734pizptjz+7tZbtEgw4+EqYGDhoDFZuTbg3c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pluQTvYpajzuJTiikCuUfTKoKm0ZeLDZaxNuX1fTfnevvEGvRKAKbXPMowb/Gds0HZFcxBdM3OanNW3yx9EmK6KrB4daxixkgO7+sih88qN5biKMx925nrBw6WdSuYz3n6QAw4qnVASLFfmbznQLA44G6kQniH8b6GcqFU1JkIo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tjmercier.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LXmWz36H; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tjmercier.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LXmWz36H" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2aae0d40a47so241958315ad.2 for ; Tue, 17 Feb 2026 19:22:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771384975; x=1771989775; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pBIv4Kjul+M1r0tdQ268vYu5sNrxPVO9X/dnp6afltc=; b=LXmWz36HuaGSNsBkp6fGmHQhmaZ1esi1rfaMJwuEtht45TmjvQ3zpTV+4BejFCiE+P kjKltJKl5rV+0SJfjaPsGu6RLZOih+1vGhvX8h+glPZQ4fw0lozYiJx+j9TYzjcvMwec tSvsDEJQN/6eWoBiHOayTDFLelmk2x+G1Zu665Uk8AlUsLayB4SMPol7gwwwreVZbmdI 8XLrtXt41QKIctzxmuIKnA5JpY08bIuubx7/KR6dRTsMa0jeGIx9x1Pc4BHUCOc1dDFm +l0hBEeY0Vp0KjDyf6OBbyAjK+l5CAgILGAfGRxUWhCJIbyOFWRYAg21zngdaYhWgAWa kJQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771384975; x=1771989775; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pBIv4Kjul+M1r0tdQ268vYu5sNrxPVO9X/dnp6afltc=; b=Wi8JDJb5NG/t11FFjfCgOET9y9dl1oF4fJhyn8iTwWdbBmxuqezquZMKkmtJkp9ufH iNe86C4bIds0b4KloACvoji6TkzAww+b6vx8QM/3ZXS4lFtvWpZvz4FosxA7xCuZGAmS 33JyRnh1KOxgvb3NMsZKPV2cljEUwm0WzlkPjuKXe1MqgxJ5p9dKJpSMqWUkXcyOc7Bc g55POesReD/L+WtdjoSQhc/6wdPghZ2AEvW4PPZHyOUSdQZYRj8TgJqeHRqp+sr1yoOf 0Imij1tvnhMGsusdE+v1gE1/fPtU5kSd6sU6+AUSQslDyrIeH+kP36tQS1Nwhw5TuK9S p8wQ== X-Forwarded-Encrypted: i=1; AJvYcCUaLInFRWRWF1nyH+aWlWttKn+82iFhgXeZFjeQDatOKbYItGC25H+axfBNpfrxSyacr1EvRsB/EDaxhr8=@vger.kernel.org X-Gm-Message-State: AOJu0YzzNKU6htNPg7mJ5y5WSsA16ikIvtN735xTyE5MKGMY6KWxMnlA gyv/iV4O/U4sNnMeUV21Yd6Dpf2WcnSR/xXZU9zzmMAbiv68kQSiUhnUMfihR5inBYqnIEySN9x 4iMZk7ynMbsVgXZ34EQ== X-Received: from pjbls16.prod.google.com ([2002:a17:90b:3510:b0:354:c082:9b93]) (user=tjmercier job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:144f:b0:366:14ac:e1df with SMTP id adf61e73a8af0-39483aa8f59mr12907868637.69.1771384975197; Tue, 17 Feb 2026 19:22:55 -0800 (PST) Date: Tue, 17 Feb 2026 19:22:31 -0800 In-Reply-To: <20260218032232.4049467-1-tjmercier@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260218032232.4049467-1-tjmercier@google.com> X-Mailer: git-send-email 2.53.0.310.g728cabbaf7-goog Message-ID: <20260218032232.4049467-3-tjmercier@google.com> Subject: [PATCH v3 2/3] kernfs: send IN_DELETE_SELF and IN_IGNORED on file deletion From: "T.J. Mercier" To: gregkh@linuxfoundation.org, tj@kernel.org, driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: "T.J. Mercier" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently some kernfs files (e.g. cgroup.events, memory.events) support inotify watches for IN_MODIFY, but unlike with regular filesystems, they do not receive IN_DELETE_SELF or IN_IGNORED events when they are removed. This creates a problem for processes monitoring cgroups. For example, a service monitoring memory.events for memory.high breaches needs to know when a cgroup is removed to clean up its state. Where it's known that a cgroup is removed when all processes die, without IN_DELETE_SELF the service must resort to inefficient workarounds such as: 1. Periodically scanning procfs to detect process death (wastes CPU and is susceptible to PID reuse). 2. Placing an additional IN_DELETE watch on the parent directory (wastes resources managing double the watches). 3. Holding a pidfd for every monitored cgroup (can exhaust file descriptors). This patch enables kernfs to send IN_DELETE_SELF and IN_IGNORED events. This allows applications to rely on a single existing watch on the file of interest (e.g. memory.events) to receive notifications for both modifications and the eventual removal of the file, as well as automatic watch descriptor cleanup, simplifying userspace logic and improving resource efficiency. Implementation details: The kernfs notification worker is updated to handle file deletion. The optimized single call for MODIFY events to both the parent and the file is retained, however because CREATE (parent) events remain unsupported for kernfs files, support for DELETE (parent) events is not added here to retain symmetry. Only support for DELETE_SELF events is added. Signed-off-by: T.J. Mercier Acked-by: Tejun Heo --- fs/kernfs/dir.c | 21 +++++++++++++++++ fs/kernfs/file.c | 45 ++++++++++++++++++++----------------- fs/kernfs/kernfs-internal.h | 3 +++ 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 29baeeb97871..e5bda829fcb8 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -9,6 +9,7 @@ =20 #include #include +#include #include #include #include @@ -1471,6 +1472,23 @@ void kernfs_show(struct kernfs_node *kn, bool show) up_write(&root->kernfs_rwsem); } =20 +static void kernfs_notify_file_deleted(struct kernfs_node *kn) +{ + static DECLARE_WORK(kernfs_notify_deleted_work, + kernfs_notify_workfn); + + guard(spinlock_irqsave)(&kernfs_notify_lock); + /* may overwite already pending FS_MODIFY events */ + kn->attr.notify_event =3D FS_DELETE; + + if (!kn->attr.notify_next) { + kernfs_get(kn); + kn->attr.notify_next =3D kernfs_notify_list; + kernfs_notify_list =3D kn; + schedule_work(&kernfs_notify_deleted_work); + } +} + static void __kernfs_remove(struct kernfs_node *kn) { struct kernfs_node *pos, *parent; @@ -1520,6 +1538,9 @@ static void __kernfs_remove(struct kernfs_node *kn) struct kernfs_iattrs *ps_iattr =3D parent ? parent->iattr : NULL; =20 + if (kernfs_type(pos) =3D=3D KERNFS_FILE) + kernfs_notify_file_deleted(pos); + /* update timestamps on the parent */ down_write(&kernfs_root(kn)->kernfs_iattr_rwsem); =20 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c index e978284ff983..4be9bbe29378 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c @@ -37,8 +37,8 @@ struct kernfs_open_node { */ #define KERNFS_NOTIFY_EOL ((void *)&kernfs_notify_list) =20 -static DEFINE_SPINLOCK(kernfs_notify_lock); -static struct kernfs_node *kernfs_notify_list =3D KERNFS_NOTIFY_EOL; +DEFINE_SPINLOCK(kernfs_notify_lock); +struct kernfs_node *kernfs_notify_list =3D KERNFS_NOTIFY_EOL; =20 static inline struct mutex *kernfs_open_file_mutex_ptr(struct kernfs_node = *kn) { @@ -909,7 +909,7 @@ static loff_t kernfs_fop_llseek(struct file *file, loff= _t offset, int whence) return ret; } =20 -static void kernfs_notify_workfn(struct work_struct *work) +void kernfs_notify_workfn(struct work_struct *work) { struct kernfs_node *kn; struct kernfs_super_info *info; @@ -935,11 +935,7 @@ static void kernfs_notify_workfn(struct work_struct *w= ork) down_read(&root->kernfs_supers_rwsem); down_read(&root->kernfs_rwsem); list_for_each_entry(info, &kernfs_root(kn)->supers, node) { - struct kernfs_node *parent; - struct inode *p_inode =3D NULL; - const char *kn_name; struct inode *inode; - struct qstr name; =20 /* * We want fsnotify_modify() on @kn but as the @@ -951,24 +947,31 @@ static void kernfs_notify_workfn(struct work_struct *= work) if (!inode) continue; =20 - kn_name =3D kernfs_rcu_name(kn); - name =3D QSTR(kn_name); - parent =3D kernfs_get_parent(kn); - if (parent) { - p_inode =3D ilookup(info->sb, kernfs_ino(parent)); - if (p_inode) { - fsnotify(notify_event | FS_EVENT_ON_CHILD, - inode, FSNOTIFY_EVENT_INODE, - p_inode, &name, inode, 0); - iput(p_inode); + if (notify_event =3D=3D FS_DELETE) { + fsnotify_inoderemove(inode); + } else { + struct kernfs_node *parent =3D kernfs_get_parent(kn); + struct inode *p_inode =3D NULL; + + if (parent) { + p_inode =3D ilookup(info->sb, kernfs_ino(parent)); + if (p_inode) { + const char *kn_name =3D kernfs_rcu_name(kn); + struct qstr name =3D QSTR(kn_name); + + fsnotify(notify_event | FS_EVENT_ON_CHILD, + inode, FSNOTIFY_EVENT_INODE, + p_inode, &name, inode, 0); + iput(p_inode); + } + + kernfs_put(parent); } =20 - kernfs_put(parent); + if (!p_inode) + fsnotify_inode(inode, notify_event); } =20 - if (!p_inode) - fsnotify_inode(inode, notify_event); - iput(inode); } =20 diff --git a/fs/kernfs/kernfs-internal.h b/fs/kernfs/kernfs-internal.h index 6061b6f70d2a..cf4b21f4f3b6 100644 --- a/fs/kernfs/kernfs-internal.h +++ b/fs/kernfs/kernfs-internal.h @@ -199,6 +199,8 @@ struct kernfs_node *kernfs_new_node(struct kernfs_node = *parent, * file.c */ extern const struct file_operations kernfs_file_fops; +extern struct kernfs_node *kernfs_notify_list; +extern void kernfs_notify_workfn(struct work_struct *work); =20 bool kernfs_should_drain_open_files(struct kernfs_node *kn); void kernfs_drain_open_files(struct kernfs_node *kn); @@ -212,4 +214,5 @@ extern const struct inode_operations kernfs_symlink_iop= s; * kernfs locks */ extern struct kernfs_global_locks *kernfs_locks; +extern spinlock_t kernfs_notify_lock; #endif /* __KERNFS_INTERNAL_H */ --=20 2.53.0.310.g728cabbaf7-goog From nobody Thu Apr 2 20:20:30 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 5D8B32DEA95 for ; Wed, 18 Feb 2026 03:22:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771384980; cv=none; b=rl5xHtG0POdiVewPnIzxAbw3LTdb6DMh7vALTfOLvnGRM6/L0sAgYVXbfE4l3j7peGB+XZAvhSEJMwyE61m+DuSLzi0F3ZbmpervW3wsUEmz/eVueVZFWKabZItjkxNzYz3dQSmfv4iwvk2x3gKNadGobuqgLpC2smnExpUr7bA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771384980; c=relaxed/simple; bh=amJ6sTsdRzljNmWNFyyNWbH0+wmhpkN9l7CXsUdsmJY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=t0CCWBq4sK8Y4HUnXlUv9mEqSl+0swy0pOJP1gdb/tImDly3AN5RUOwg6GRkW2l7Oe5SNPkZ3+E9VAqr5zHKocXJZG8EWx6tkAHWRkfT+/TN0EMW8Y0nRNCvOaPcrOpzNeMCaxm4f3WfnrindGEamxt8Wv4e9036LlXMKR5R6u0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tjmercier.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KwsBFT7J; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tjmercier.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KwsBFT7J" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2a863be8508so54072645ad.2 for ; Tue, 17 Feb 2026 19:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771384979; x=1771989779; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fK/D1opWbvNOOx0YfmI5FNRjOmnqGdMEH8VMO81NrfE=; b=KwsBFT7J4jYlacwY5b6LXwNUxYhroxASeKKBDpzY0RzrPypElBwUwIGQJ/QwymGZs6 1s2pVOf4ZhbLymL73iZPExX2c5la+7uM3+8u7XEXT226z4K+PEN8ef6CnjvfHQ7m9/FB WoUFR+8AUVWz668Gi2+zF5M71r2XjvdKFz3ZwqFRWWyNUTBGv5hEJkxkBJtam9mBiBsq Ul7blxHCa1rWPMF3aFfbQNSWD9JhwjX0w1O15f7CJf59JP61L4TF6FFoDz5HUnTd2YP+ AMMcU29tcw9fCiFgoOcKlFKP9gvqkyCjReeT9ZOTOHB7x7diTbkbKNynsbRdyyETqLrY 95Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771384979; x=1771989779; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fK/D1opWbvNOOx0YfmI5FNRjOmnqGdMEH8VMO81NrfE=; b=CnB6Klo4pxC5pxRp70bCsoAt1KELwsQtmt2K3r3msb4NIfpusbwhGdIaf5zJuxvVvC 9AWHVgcZ3QAPLicusXPskQrCv+m67SeHk7RuSCAlsgsNymBtKkrV7+xXOmcIMjONPnPi omdbvUr5pGfee/UGlb0+y5Bw1GlMpQuUq2VU2F0+KHhiBuUSHcXSJ3gj1ByXQiv8PQJy 1LF2Ocb2p5dRGqKWUzt2zR3sbJlJWxfZPqoY5rnXHAaEPyNSYGruNQkavPZbSYlfFSeU lEP1ZNTR0BQCebD5v2XNfYRqHKg2RVTYUXzuGOaH4T0JxmXssuCOHRAl8yqGcFwAozKI a71w== X-Forwarded-Encrypted: i=1; AJvYcCVEXRAZ5rKe92IayNfKd0SZlnmrQwp77Nswb5J31PL2QPbdLixiELGocTvngN5S10XC9DLGF3CIpM8W9XU=@vger.kernel.org X-Gm-Message-State: AOJu0YyQiGFksdpYLcY2fKBCsWvdT701EznAC94PSEqeYcyBQ9e6KZ0S 1iKTvrBRWPmIcvhhTHNpmKsIe303osxKYs6UM8T7XFE8l3sU1t5NzfYRfxd5uQH08IvPfS8/sig s97IcCxjosOjUq1sGfQ== X-Received: from pfbhc6.prod.google.com ([2002:a05:6a00:6506:b0:823:c4bd:60eb]) (user=tjmercier job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:f8f:b0:81d:a1b1:731b with SMTP id d2e1a72fcca58-824d951b02dmr12246190b3a.19.1771384978430; Tue, 17 Feb 2026 19:22:58 -0800 (PST) Date: Tue, 17 Feb 2026 19:22:32 -0800 In-Reply-To: <20260218032232.4049467-1-tjmercier@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260218032232.4049467-1-tjmercier@google.com> X-Mailer: git-send-email 2.53.0.310.g728cabbaf7-goog Message-ID: <20260218032232.4049467-4-tjmercier@google.com> Subject: [PATCH v3 3/3] selftests: memcg: Add tests IN_DELETE_SELF and IN_IGNORED on memory.events From: "T.J. Mercier" To: gregkh@linuxfoundation.org, tj@kernel.org, driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: "T.J. Mercier" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add two new tests that verify inotify events are sent when memcg files are removed. Signed-off-by: T.J. Mercier Acked-by: Tejun Heo Acked-by: Amir Goldstein --- .../selftests/cgroup/test_memcontrol.c | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testi= ng/selftests/cgroup/test_memcontrol.c index 4e1647568c5b..2b065d03b730 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -1625,6 +1626,125 @@ static int test_memcg_oom_group_score_events(const = char *root) return ret; } =20 +static int read_event(int inotify_fd, int expected_event, int expected_wd) +{ + struct inotify_event event; + ssize_t len =3D 0; + + len =3D read(inotify_fd, &event, sizeof(event)); + if (len < (ssize_t)sizeof(event)) + return -1; + + if (event.mask !=3D expected_event || event.wd !=3D expected_wd) { + fprintf(stderr, + "event does not match expected values: mask %d (expected %d) wd %d (exp= ected %d)\n", + event.mask, expected_event, event.wd, expected_wd); + return -1; + } + + return 0; +} + +static int test_memcg_inotify_delete_file(const char *root) +{ + int ret =3D KSFT_FAIL; + char *memcg =3D NULL, *child_memcg =3D NULL; + int fd, wd; + + memcg =3D cg_name(root, "memcg_test_0"); + + if (!memcg) + goto cleanup; + + if (cg_create(memcg)) + goto cleanup; + + if (cg_write(memcg, "cgroup.subtree_control", "+memory")) + goto cleanup; + + child_memcg =3D cg_name(memcg, "child"); + if (!child_memcg) + goto cleanup; + + if (cg_create(child_memcg)) + goto cleanup; + + fd =3D inotify_init1(0); + if (fd =3D=3D -1) + goto cleanup; + + wd =3D inotify_add_watch(fd, cg_control(child_memcg, "memory.events"), IN= _DELETE_SELF); + if (wd =3D=3D -1) + goto cleanup; + + cg_write(memcg, "cgroup.subtree_control", "-memory"); + + if (read_event(fd, IN_DELETE_SELF, wd)) + goto cleanup; + + if (read_event(fd, IN_IGNORED, wd)) + goto cleanup; + + ret =3D KSFT_PASS; + +cleanup: + if (fd >=3D 0) + close(fd); + if (child_memcg) + cg_destroy(child_memcg); + free(child_memcg); + if (memcg) + cg_destroy(memcg); + free(memcg); + + return ret; +} + +static int test_memcg_inotify_delete_rmdir(const char *root) +{ + int ret =3D KSFT_FAIL; + char *memcg =3D NULL; + int fd, wd; + + memcg =3D cg_name(root, "memcg_test_0"); + + if (!memcg) + goto cleanup; + + if (cg_create(memcg)) + goto cleanup; + + fd =3D inotify_init1(0); + if (fd =3D=3D -1) + goto cleanup; + + wd =3D inotify_add_watch(fd, cg_control(memcg, "memory.events"), IN_DELET= E_SELF); + if (wd =3D=3D -1) + goto cleanup; + + if (cg_destroy(memcg)) + goto cleanup; + free(memcg); + memcg =3D NULL; + + if (read_event(fd, IN_DELETE_SELF, wd)) + goto cleanup; + + if (read_event(fd, IN_IGNORED, wd)) + goto cleanup; + + ret =3D KSFT_PASS; + +cleanup: + if (fd >=3D 0) + close(fd); + if (memcg) + cg_destroy(memcg); + free(memcg); + + return ret; +} + #define T(x) { x, #x } struct memcg_test { int (*fn)(const char *root); @@ -1644,6 +1764,8 @@ struct memcg_test { T(test_memcg_oom_group_leaf_events), T(test_memcg_oom_group_parent_events), T(test_memcg_oom_group_score_events), + T(test_memcg_inotify_delete_file), + T(test_memcg_inotify_delete_rmdir), }; #undef T =20 --=20 2.53.0.310.g728cabbaf7-goog