From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f195.google.com (mail-dy1-f195.google.com [74.125.82.195]) (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 74EC63E4C94 for ; Thu, 4 Jun 2026 20:30:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780605006; cv=none; b=gyhU3ykSs2hbfmG525YII5D/y/BvFjOTsCLJS8D0TqYb7bybQBwyaWrZ3FMqDP8DC3kNZ+gkk+JIQh+bVizUIUXKAPTzH2UVso0nJp6UZGnU6vIlhw+WRSbOPz3QX6P+cfqwvUki0WjVGggU9TlcH9WxPeXYNyETVHZgBPnHXuI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780605006; c=relaxed/simple; bh=E0eGepHGYQKUs/ko84r1foShV2m+ylziZzZEGSZpoDU=; h=MIME-Version:Content-Type:Subject:From:To:Cc:In-Reply-To: References:Date:Message-Id; b=BHqJxP8gXr/mVBO3+xY31TpLrVfJz8VBlgBxXcslsy+6bSi9mPgzZ3p8U2vXySTvzpBZPa41dJFZ+WEEqgmgYWH98Yo0xd/FlZJtpFEGp3QmqzW0HVEitZBdaNixntCBkeZDU6LU1Z2yBAyIqQJfNpy33irwKftMGrKkWiSQ5SQ= 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=ddf+k0hn; arc=none smtp.client-ip=74.125.82.195 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="ddf+k0hn" Received: by mail-dy1-f195.google.com with SMTP id 5a478bee46e88-307631dbfedso2320123eec.0 for ; Thu, 04 Jun 2026 13:30:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780605004; x=1781209804; darn=vger.kernel.org; h=message-id:date:references:in-reply-to:cc:to:from:subject :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=SAOEJySs55fRy0cpkhY9pn8i73FB5zhFcaq9qMjLuIk=; b=ddf+k0hncXJhLPD7sBPCrsmhPKjUXEPemrFbb3aX320i0+V5OmxqvLX/6bRkj1f9Y4 5Y4/qDsl2k+bf9E68w/C8tjTSAExG8vkl3Sxu0IlflKP1BLNF2A2lCf7eoei1vSUP+uy Bwnyy3TPBdL7pR+bMdnyDN1VvNaIZ+MkEuwqQ85ip45t4FaBe14Qh6eXDBJbJopZZH15 D2PWVXEuhZTHAhH2/XPVOTEElhmQq4n5ZRlJEW2MGPphdU88mMXbFI+82huUJC7VofI0 p2VKGLP+LiJBgA0A2uTAJx4ZkOPr/SgRuk2fVl8ivoZfNxkN0fl5uc55Ot9KVZBaU6PL wQDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780605004; x=1781209804; h=message-id:date:references:in-reply-to:cc:to:from:subject :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SAOEJySs55fRy0cpkhY9pn8i73FB5zhFcaq9qMjLuIk=; b=SGztLvoUseE2ZMwC1dzwwKiZZOb/5IfNMEGTEoXrM/LhQoLRxe7py9Q9B97fT/03ps Y+TjXL1i1LTudShrZQAjahnI0UqM8JHzyS/146UnBTxhcpvWHNWf1NJyQ0a4C7L6RQe/ qhoa5f+BWnOgdw+oYfjRhWorMDt67DDqUpM1p4wRXgwxX1yG85fDWzW8/mzaOI3zdXOt ShSVJcAFMfpE9pcvZmZgIBi/Ry/3FoPfghvnvQ2Rog7ao3SKmQpsbGcO4vxDUrhYF5xV ft02zUEQl/zfQRK8u+aKAOtBx0n/4JbAXQQIm8zrr9s7bYe0/AtztJZ2XbDPVCsSFy7R qJTg== X-Forwarded-Encrypted: i=1; AFNElJ8jVxpwAmm+Q5kQ7ygArq8NJj18toO8BvR3EU5m0Dw3pEvHwjJwQ0hCCmVWuDgWsaru6LkgcbtfAkliazE=@vger.kernel.org X-Gm-Message-State: AOJu0YzyOrZoPv9f1iC7n+cm1V0UoCuRRr/KPUEauv+9KkBLyeugFdCC tYhcE/rf32f81kFmRWEXJzepC7NGixZ//p3zZo5UAak2UL/st0hHyhYBpvQgh8x4 X-Gm-Gg: Acq92OGIjEVhfruYNvOxjeGthCHG0deyfS9QSF7EW4j6Wn4Q9mAOUN8tEKLtssH/GLP TIloj58Dkbwn7i8nqrWvf+UBhmuUJdWA1owZDM7eUbqvFmmhxi3bUxxhgTBJRN5H6e+o4UUMSkN dPrk2wptdF0wAZa/b4A11kqF7PGPOHrkkvo8Sjk8rURcgOzq1dPLmKulpMebpJ1WJjtDe9TxG9P NvJ3rmK4G7vjygol4rZvImOtzh93Uvk40zf61R5euH7jcz2SZdj+yeZ5SNgAGMymEIs7eg9/OUA FVzq4S4x8tJXvUrKiOjgYZhLjdwfLroj4npKSyANpoxNBTIqPzzz+uwre1i+VfP1MPekghPRdy6 kJI1IeU5ndSdNKWLXentZ8/IH0jAVeMfo1FwY9LcIWjX/2C7YayhYzDXhTltIhDI2aYx0zRODjN 2od2ECvP7DisAxkMNjDbi6Cl6ccChveiPxrPKzGpk= X-Received: by 2002:a05:7300:f193:b0:304:de28:1b16 with SMTP id 5a478bee46e88-3077b7830aemr158595eec.28.1780605004426; Thu, 04 Jun 2026 13:30:04 -0700 (PDT) Received: from [10.61.22.100] ([2605:52c0:2:2f27:be24:11ff:fe89:6f0f]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3074dba9d43sm5343384eec.10.2026.06.04.13.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 13:30:03 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Subject: Re: [PATCH v4 2/2] fanotify: allow reporting pidfds for reaped tasks From: AnonymeMeow To: Christian Brauner Cc: Amir Goldstein , AnonymeMeow , jack@suse.cz, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260603-mehrsprachig-altlasten-unverantwortlich-4fcd029306b0@brauner> References: <20260603001516.26234-3-anonymemeow@gmail.com> <20260603031117.20950-1-anonymemeow@gmail.com> <20260603-schindel-drehzahl-planlos-e334e6899cd5@brauner> <20260603-mehrsprachig-altlasten-unverantwortlich-4fcd029306b0@brauner> Date: Fri, 05 Jun 2026 04:29:47 +0800 Message-Id: <178060498710.12657.15047020114378440191.b4-reply@b4> X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3461; i=anonymemeow@gmail.com; h=from:subject:message-id; bh=E0eGepHGYQKUs/ko84r1foShV2m+ylziZzZEGSZpoDU=; b=owGbwMvMwCWmOm1nep3jlf+Mp9WSGLIUH9iEf1cQZlqQ57YmNXTzLqepLlVvit7kBV76EMy65 //iaYc5O0pZGMS4GGTFFFneOApoP/q88U7B+/f8MHNYmUCGMHBxCsBESoUYGW46fn7/fVXcY4s6 r8uHL89Xqj3GKfir9WKyiam4zsoITjWGfwbrlc/rMO0stuk/vomz1VopfKtlxa3um00RucFOh4+ 48gMA X-Developer-Key: i=anonymemeow@gmail.com; a=openpgp; fpr=EC41102BE2F3B1DC70EFEF0F2596B9677E41D4FF On 2026-06-03 13:25 +0200, Christian Brauner wrote: > On Wed, Jun 03, 2026 at 12:58:09PM +0200, Amir Goldstein wrote: > > On Wed, Jun 3, 2026 at 12:28 PM Christian Brauner wrote: > > > > > > On Wed, Jun 03, 2026 at 12:00:42PM +0200, Amir Goldstein wrote: > > > > On Wed, Jun 3, 2026 at 5:11 AM AnonymeMeow wrote: > > > > > > > > > > Sashiko said that pidfs_register_pid() can fail under memory pressure, > > > > > since it allocates memory using GFP_KERNEL without a way to pass in > > > > > __GFP_NOFAIL. This can cause fanotify_alloc_event() to silently drop > > > > > the event even when the group has an unlimited queue length. > > > > > > > > > > Should we make pidfs registration best-effort instead and still return > > > > > the allocated event if pidfs_register_pid() fails? But IMO this will > > > > > make the API semantically ambiguous. If the kernel guarantees that the > > > > > event pid is registered with pidfs when pidfd reporting is requested, > > > > > then a later FAN_NOPIDFD or -ESRCH can only be caused by the task being > > > > > invisible within the reader's pid namespace. But if we allow best-effort > > > > > registration, the event may still carry a pinned struct pid, but pidfs > > > > > registration may have failed due to memory pressure. If userspace reads > > > > > the event after the task has been reaped, it still gets a FAN_NOPIDFD > > > > > or -ESRCH due to failed pidfs registration caused by memory pressure, > > > > > IMO this should be reported as a -ENOMEM instead of -ESRCH. But > > > > > currently it seems we don't have a good way to register the pid with > > > > > __GFP_NOFAIL or __GFP_RETRY_MAYFAIL, so what would be the preferred > > > > > approach to handle this situation? > > > > > > > > Thanks for noticing the oddity and explaining the options. > > > > > > > > We could fail the event in case on ENOMEM because the system > > > > is likely is a bad shape anyway and other events are likely to fail > > > > allocation themselves, so I am not objecting to your patch as is, > > > > > > > > but I am slightly leaning towards the semantically ambiguous API. > > > > > > As usual, I think a semantically ambiguous api should be avoided. > > > > > > > I don't think that we are going to change the man page to say that > > > > FAN_REPORT_PIDFD is guaranteed to return a pidfd, maybe we just > > > > add a NOTE about increased likelihood of getting a pidfd since kernel XXX > > > > and mention the known cases of pid namespace and ENOMEM. > > > > > > The pid namespace shouldn't matter. > > > > DO you mean that the event reader inside a pidns always gets a pidfd but > > it will not be able to query the pid of the process outside the pidns > > or do you mean something else? > > So they will always get a pidfd since fanotify is correctly using > pidfd_prepare() directly. But when the reader tries to resolve the pidfd > to say a pid or retrieve info via the pidfd info ioctl they would fail > to do so (well, the pid will resolve to 0 which is the global indicator > for "can't be resolved in your pidns"). > Before pidfd_prepare(), fanotify checks whether metadata.pid is non-zero, i.e. whether the event pid is visible in the reader's pidns. If it's not visible, fanotify will not create a valid pidfd and return a FAN_NOPIDFD. This is the existing behavior, and my patches do not change it.