From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 CCC3033BBAA for ; Wed, 25 Feb 2026 22:34:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772058850; cv=none; b=Yv8ZrDrykdlfjCmSgOCWuleggmPYw1i1C27ktZ8CRZ4Olq+q9iWQny6naqJBbShYBNfEA9HO+gsSmPcm6e5o9RB+diO78HUmsSYnKaQDx0IQGdqS3Fb6iZgRs4ImP96JWEQmHH/yYw2tgZlG2I73WLmIK8FyXxKvjDRACH8moo4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772058850; c=relaxed/simple; bh=vFBhJxCAsIAwYNZ/g3MViZPMIkoQrogOPMTX+aObVJo=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=LLfffqn4harHSmYShZSvFxlB18idtl9B6tlLIGfx3pDUEOl+EXM8+focGHsSGCaJjCMqKFnsrkliw99Pyl7k2MMcoHVi6O9UThReKquJkwrr2DOijPPJ+7rHamnFuk4kUKDdlc++ZG0cKlYTHZCCvWnRBb/IMWnzvoCd4l1xD7s= 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=LKEZUy34; arc=none smtp.client-ip=209.85.210.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="LKEZUy34" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-8230d6d54a5so1095868b3a.1 for ; Wed, 25 Feb 2026 14:34:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772058849; x=1772663649; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=HB0CfyRs1BRb9GE8lihqLejpd0gkHTcJItDcn1kg/F8=; b=LKEZUy34jaPUjF9MWzfk3bnuXTEnsamM2bHOn7MkF0TLl1Z3RJR1bdx+AIT4C7arvR hEwDAYCYoXwbgODyWpZa1JhHj60BgO2BddY5ScrzD8vNZDyvk3xr4RnIK2w/Fd1Isthi PnLrOcuJ9QYQ+O2o4OYLkOtgvVZDFXKr5XCW72wMaIXgC9AGbnc6zk8BOaLw8DQ1Todq hIbgXBO3pyef6CmjquAfRyXT3ctIx3Bf6VYq9rN1HqE17utNxI2V/tnypHku97SM+dfb UtlMFtSCxsmvpoblc+ZtS3a/skpi0MON+xZ8he3w1iWIlW960y8KD4oaJQ/yHNV91y7f hw0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772058849; x=1772663649; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=HB0CfyRs1BRb9GE8lihqLejpd0gkHTcJItDcn1kg/F8=; b=mMYqpds+9a9CPyZg8qinAujH4MNdlT2bZTXp5r8M3Gy+ZWOUpdeoTO4SIIIjcvYvp5 l/nR5gXpTxIAN7/Ppa6NifMWFSd4MUHEFctkeUBGiEvbR46weABfLO7mrVC56CC/ZCqB fTcyjlv19XdD9KC/6seSOwqmH6c9CZF62lb/foQG+TnfSTqGayzdSChQqRHzHAvim98a hxBiBjX4pzKbqxBU18oQ157A911Vgro2HougoBKU5tbNrzVTUEi/bv/fFxe1azvF38LZ rw5todTrKa4zFjq7MVoRss4TZJ+YdO+lNYYmg//prZEh3e4EW/kooFK82GWj2WOEB14w O6LA== X-Forwarded-Encrypted: i=1; AJvYcCVlrGAKUJ+GuuqrOivkVabTHmQJtFo97qupFQz/Y+UgiFQfz/QjS9EH0mcH/5WcJhD1CfqlMF+e/DOAS04Ln+M=@vger.kernel.org X-Gm-Message-State: AOJu0YzzBO5JgJWwpMEVFGQ5aYojRRWsalD+zzb/BA9BbA0m9uVzl4hD O+69zdHSdQnhH4loK6EHuxQgFtraEsCza8OwdOFjc98xOrxlOwqma1nbcIMrZUK2A4XRC1Ur1to e8SmY1qa2ViobU1rJXg== X-Received: from pfbbk2.prod.google.com ([2002:aa7:8302:0:b0:7fa:f279:2d1d]) (user=tjmercier job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:cc8:b0:827:2b7f:e1d0 with SMTP id d2e1a72fcca58-82739827658mr536889b3a.24.1772058848945; Wed, 25 Feb 2026 14:34:08 -0800 (PST) Date: Wed, 25 Feb 2026 14:34:01 -0800 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.414.gf7e9f6c205-goog Message-ID: <20260225223404.783173-1-tjmercier@google.com> Subject: [PATCH v5 0/3] kernfs: Add inotify IN_DELETE_SELF, IN_IGNORED support 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-Type: text/plain; charset="UTF-8" This series adds support for IN_DELETE_SELF and IN_IGNORED inotify events to kernfs files and directories. Currently, kernfs (used by cgroup and others) supports IN_MODIFY events but fails to notify watchers when the file is removed (e.g. during cgroup destruction). This forces userspace monitors to maintain resource intensive side-channels like pidfds, procfs polling, or redundant directory watches to detect when a cgroup dies and a watched file is removed. By generating IN_DELETE_SELF events on destruction, we allow watchers to rely on a single watch descriptor for the entire lifecycle of the monitored file, reducing resource usage (file descriptors, CPU cycles) and complexity in userspace. The series is structured as follows: Patch 1 preemptively addresses a race to set/clear i_nlink that would arise in patch 2. Patch 2 implements the logic to generate DELETE_SELF and IGNORED events on file / dir removal. Patch 3 adds selftests to verify the new behavior. --- Changes in v5: Add comment about inotify, and fanotify limitataions per Tejun Add Tejun's Ack to new patch 2 Fix circular locking reported by syzbot in patch 2 https://lore.kernel.org/all/CABdmKX3jMS5ha2s5FMpnAMW0c9+Wmpmyc+8=D-24KyhVjBJvYg@mail.gmail.com/ Add Tested-by: for syzbot as requested Changes in v4: Clear inode i_nlink upon kernfs removal instead of calling fsnotify from kernfs per Jan. This adds support for directories. Abandon support for files removed from vfs_writes. Add selftest for directory watch per Amir. Add Amir's Ack to selftests. Changes in v3: Remove parent IN_DELETE notification per Amir. Refactored kernfs_notify_workfn to avoid grabbing parent when unnecessary for DELETE events as a result. Use notify_event for fsnotify_inode call per Amir Initialize memcg pointers to NULL in selftests Add Amir's Ack Add Tejun's Acks to the series Changes in v2: Remove unused variables from new selftests per kernel test robot Fix kernfs_type argument per Tejun Inline checks for FS_MODIFY, FS_DELETE in kernfs_notify_workfn per Tejun T.J. Mercier (3): kernfs: Don't set_nlink for directories being removed kernfs: Send IN_DELETE_SELF and IN_IGNORED selftests: memcg: Add tests for IN_DELETE_SELF and IN_IGNORED fs/kernfs/dir.c | 56 ++++++++- fs/kernfs/inode.c | 2 +- .../selftests/cgroup/test_memcontrol.c | 112 ++++++++++++++++++ 3 files changed, 165 insertions(+), 5 deletions(-) base-commit: ba268514ea14b44570030e8ed2aef92a38679e85 -- 2.53.0.414.gf7e9f6c205-goog