From patchwork Mon Nov 11 20:17:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35BF3D3ABF6 for ; Mon, 11 Nov 2024 20:19:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A180A6B009A; Mon, 11 Nov 2024 15:19:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C64E6B009B; Mon, 11 Nov 2024 15:19:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8189E6B009C; Mon, 11 Nov 2024 15:19:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 676136B009A for ; Mon, 11 Nov 2024 15:19:11 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 14D4B1A1C05 for ; Mon, 11 Nov 2024 20:19:11 +0000 (UTC) X-FDA: 82774926780.27.C69166B Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by imf22.hostedemail.com (Postfix) with ESMTP id 6DABBC0024 for ; Mon, 11 Nov 2024 20:18:18 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=rt9IXwUA; dmarc=none; spf=none (imf22.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.177) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356174; a=rsa-sha256; cv=none; b=f08XOUroIwMaMlxLLkGxxjEc6SQJzPv+pl4uyiN4kVmpZC7NH0lBCExyED1N9aDS+uvY6e y1y6jFmVog3vnf9QlrYIDi854Pqx6obM2MslqLzgifxzW06LD59EOlUYpVlz1lV5T5iMaV HpWiwCBQO7rcSlte9rfXdT5kYttyPEo= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=rt9IXwUA; dmarc=none; spf=none (imf22.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.177) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356174; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=E7uBdkMZBWHBDqGd5Y6AU6Zp9KPmNzsckryemzg27pk=; b=mxZ6nh+ZNO5na2izUHrVGm1rQzBaNIvi9vkvjjsZwPDh/tYWUaly0ZYtsdjsxIXErHMVVk NNzmj3hMLIR2GKhQSFLe2p1XnbVd5pjIgVftgCFWdIiSBFDEzOA0QwDBJgq+pZQJVj3DOm WqcSUmnHfpEw90Q8X+FsFTgOO2k6Duc= Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-46090640f0cso40333251cf.0 for ; Mon, 11 Nov 2024 12:19:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356348; x=1731961148; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=E7uBdkMZBWHBDqGd5Y6AU6Zp9KPmNzsckryemzg27pk=; b=rt9IXwUAkMmMBAq893TE2/DRWlMlzYHvQBgG2ebxaUj08DsTXC7CO/8nuDU23kMbtE L1qyA+gvouEb65060Y87kCGqx66Bv1R8cBtnRq2uBrY+qyrSxfE4FnCJUEMqAC4KBA5T GjSploiSjnkp1K2vtHlENcHUyB5lmZ5zP0DivC4rI0cGymF9e8gFIPaVpwaDnLeJBDcL am4Qi/YHY8uxJ2ZvI6MOsKRy+a5LQbJs1ClrzZNXy7SlDo9XPnAnl1HPwB9Y+/KieJIa g8EaFnMj09dzuLBYrByWgk24PbANLkpOfH9famQnPImo9DnGxiKzZ3cBtwxqUKOcB7O1 +VTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356348; x=1731961148; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E7uBdkMZBWHBDqGd5Y6AU6Zp9KPmNzsckryemzg27pk=; b=VMA3kw7BhjniCVx0z8+XjND7P0lCs1EFKADPfqS2rKRJAuS712rFcxHuDDsCrkF8h7 lSO8BwjTaQ+xjg6OvTp/jpH8TKYMy4erF6EkJA/HDqRplXNevjxEWi4IeIxGLtLwUKNz kEIq6u/Oh7jjmajiA4fDDjLiXhQcH1aw6OuKXrF8BnOLG7z+vTFY66EWgriRVgYISOD0 Z435tx7MRMwSneVjh5NfjmRDNxbphuu5kB7EW1hM28ELeiOXHLHDaiTlSQi9oc6YAAem 1cDDuSQUVSGbX6w0HzRtxxXRYnHCcj1TB2KzxkLtYUhGIoptk7Py/3nQiHNKwyCUiUNS ujFA== X-Forwarded-Encrypted: i=1; AJvYcCWvlXoMEYezblTZZx6/cpJA/rHiPTeAy0uhFEkrwiwlektfMFK4XkdFgHyo7kyPbKFghqvk9LBWXA==@kvack.org X-Gm-Message-State: AOJu0YzysS0K9ZNaCLz2eJl2/UBq6lRdJdgmjljWY+wNtFL+L2Q5RdgJ NN8gdGeCxYAjJ6PxIYkQxVruLXaeGDXptgnuFTxc9aGB035CUn/66q5Z969/7lo= X-Google-Smtp-Source: AGHT+IEBguTWGGBpfMXX3i8vnE5t3UsJSDJvfVnQMRYjxbDOQbaxUPSmwC+HZSzOw+awlnAlKaw9jA== X-Received: by 2002:ac8:7390:0:b0:463:eef:baaf with SMTP id d75a77b69052e-4630eefbc12mr132991331cf.29.1731356348402; Mon, 11 Nov 2024 12:19:08 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff3df534sm66530971cf.10.2024.11.11.12.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:07 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 01/17] fanotify: don't skip extra event info if no info_mode is set Date: Mon, 11 Nov 2024 15:17:50 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: 8u8sxgkkw7get5z64x8tkb3zpexwb5ub X-Rspamd-Queue-Id: 6DABBC0024 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1731356298-306991 X-HE-Meta: U2FsdGVkX19zWyAnVOwrXK6ox9RKitR4r41CVZSSQiRzfkG3fPH14KSNiC5fz3PoJMqCgc+lwZDapuGcY+buvbJDlshmjgUNPG9Ah339EUx+n8TKKvgCnCvMhXcBCxjHoi3aTOw05+fvLMuj5u5OkXq9pXqxLvJy/2qAKg1JlXd9JhTUEAdfZsBDONKdorxKx/KPd6v7nHtyyGw0Lv625v2KKHEoVgcX70y5lr9fVmzEhrYt6l/OiWv6/FP3FtKhcagNJgYQzaSI0fN2918wl1ZSTCFibC9dItd7r4Kq3KeP9YXnLXJT/Gbvr/cX/jn6LO+nRrWIC03MOn7NtGw9Z1LADEQQGT2QGuG9riaCmFugfHugefhZEj7H2R+Vcz7yO0j2JO68+HyHu+h1N0jd/avn2mqrESjF1dgOY23Dc8jnJvIfAMC5BzRCnXN8MBRXSlLS7i63mQjLD5iAXoMGihkirRSQdOSRisejRRhASUf/w6tT90yoqfLx88adUU12ATprCP8Jvhxd91nzgvPgqeyNbrZDiIA9nn608SzEa7kNKuvvZZyYwRNRZi6Aft8mTANNXrcsSGFSNKrH+nozxPCzjBmpQuUs3wfOVTqadJxonfCIR36WwO6TRzVoviMQ6E9AGVRRfx29bI9vIqoSwlbqhd7950Orfj3b55ST1JDHN5ubHPm0csOi+QIfhnJ1MpvSPVKnE+iIX41rb1EHcrwf1d83D5xvjRDWI/+XWJ7hDh9rBKNHom9qOp+Gz7gPBfR3mNEY9FvpA+LZl9JwhqQg9ltvpygDQ7BkXcRNk6FkG9T1SKTQNjySVNE7gZclZAIQ7jNraH5wpKa0e9YGd31Y9DezcBLD6m9qaYpCsR0piPG7OYboM3wUz2Z0yN4JTqAlZgJEaqorok9NrGqR19UanBtXr9tqqKsOqHLz4GlaBoKJZGQe/hFYimKQNhwUNKu0zw9zEZFia4voa1p 7ZURs/8v kN6cQ4tuw32ktPQq/v3RfsPPqEZxI2W0J6onDPeICpzQks/il1cvvDWC/3AbCN4cj1snuKCkyu1EQr3HldclQqGNezvlKl5UxQx+ynEelnxHLYXz/RFGBJY7u3mbTsLSrsTxDv56Xnz9KLN/5KaHAQhqIG47UttkM0r1nEnzE6vEMcWodX9y2Wgo8xebA238qhylzAswCbBlS1JZKp4OhjX1kzxn0H7ytCQNakVv5xVHCVU01y3JTVU9Rngd2/xHntg+JuVfeMkhUhXLdWZ/twnL4yMKbFgTS2vLGoPduDJnWYqNF1Ut7NGWmE9kFx5gCKS2lpOF/++dPuWgTunbbK71DXiRfLYJ1QJekmM5iVuydMe3AV95dst0jKiPSrNOJhsPK6b1Zd0+MoWZuY/CTx9LVC2BtjNDRZgsN X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: New pre-content events will be path events but they will also carry additional range information. Remove the optimization to skip checking whether info structures need to be generated for path events. This results in no change in generated info structures for existing events. Signed-off-by: Josef Bacik --- fs/notify/fanotify/fanotify_user.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 8e2d43fc6f7c..d4dd34690fc6 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -160,9 +160,6 @@ static size_t fanotify_event_len(unsigned int info_mode, int fh_len; int dot_len = 0; - if (!info_mode) - return event_len; - if (fanotify_is_error_event(event->mask)) event_len += FANOTIFY_ERROR_INFO_LEN; @@ -757,12 +754,10 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group, buf += FAN_EVENT_METADATA_LEN; count -= FAN_EVENT_METADATA_LEN; - if (info_mode) { - ret = copy_info_records_to_user(event, info, info_mode, pidfd, - buf, count); - if (ret < 0) - goto out_close_fd; - } + ret = copy_info_records_to_user(event, info, info_mode, pidfd, + buf, count); + if (ret < 0) + goto out_close_fd; if (f) fd_install(fd, f); From patchwork Mon Nov 11 20:17:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871220 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A71BCD3ABF5 for ; Mon, 11 Nov 2024 20:19:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD6B16B009C; Mon, 11 Nov 2024 15:19:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C87D96B009D; Mon, 11 Nov 2024 15:19:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A65936B009E; Mon, 11 Nov 2024 15:19:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 86E116B009C for ; Mon, 11 Nov 2024 15:19:13 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0AF6581ADB for ; Mon, 11 Nov 2024 20:19:13 +0000 (UTC) X-FDA: 82774927326.26.0E75826 Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) by imf18.hostedemail.com (Postfix) with ESMTP id 0E87C1C0015 for ; Mon, 11 Nov 2024 20:18:52 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=xbjEZKht; spf=none (imf18.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.210.50) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356297; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lFLPxoJTcjCEj1ORcqyvSgazShZk3E55Emf6HOBV3dQ=; b=3TfAvnJUOGxIxrBvqrAKe9Y2IvaQHVs0VJFVgYfpf1rNgPsSwu80th2f0pl4hY/lh7etMZ Y/LdWjzlCviWFJDKvsfDmyc+W6Lx6PQwlm8JOWWC+P+tT7X3PeByuuTftJWrMjTpEMoUBa QRMYgfBEn1RD3gTg8Lj8iTuqogvYKgk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356297; a=rsa-sha256; cv=none; b=3GebYQ/NvBQGgWVu35rOuis1XzvbWGv8RJGk4ARX6U/aCH+58Hv6pgQptbLT9DuwCt7OYC cRX438z5TwiODesx2AtRo7ArMwQnUKxeKtR7bUuhCwVQlmvx6/G0Br9Kr/rxbgdqsklnf1 KimH9HeziYRss0LyvHqHaYldieYlQpo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=xbjEZKht; spf=none (imf18.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.210.50) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-71817c40110so2892606a34.1 for ; Mon, 11 Nov 2024 12:19:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356350; x=1731961150; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=lFLPxoJTcjCEj1ORcqyvSgazShZk3E55Emf6HOBV3dQ=; b=xbjEZKhtohiY0V5wUPmKwop+3jHRe6k42oqa7Ekndpbo49W4QvYK+cQamujvg6FCIA XEqbydbHC4SL39DJ/gwgNsks3bcb6dWAEF3qXZB5GNCvIFGpO/2UtlyqYKuOPVk6P+i7 xRLZglgEkzqz31p3Z+lRzTlTcYADqTeNDnMdhKoda9gKt2KPL9Xbj3JlFO8/p2l9G5VX oleuY/N3//ZElW+IbbZgg3MkYal5kjpka3T75G7kugCUkamtsCvE+g3VVYi2fSWdzrMA Sk7phdVWBReronZ005x5Lft/YYdyNcIPRYqRzC2w5poqxRTft+0kwRL6BjFv3lKoLkRj newA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356350; x=1731961150; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lFLPxoJTcjCEj1ORcqyvSgazShZk3E55Emf6HOBV3dQ=; b=fbOIMRlel0+CbIpCXopxlSeBdnJnU/vjil/5DrPwmoO+v8b6TQiGHV50RgVM3IRI4E Jk4k0nche4Kh6ENLkoq2wRKAwwpcqAPBl3kHH9ONm5ZBUE0Kz8L5ltXMBwvgMQ1HdDbj y7r5OfBLfwNDg5VvFRnDJODWTqnhnSvjp0nk2v5AckNRsyOgXlxwv9ClymwfoA4I6n5n di7I/vxmW38h+88BbB0ZXMo/atms3f3AMpSZ+Z5fxrJJ/HvqPjvsytdA12+cGFn8sE/g NYV738hBa6+xoPEM0p/cveyl4YdBDRD5wbsdsJKDbXou+p0zQFjYupRCApJ0K7enuUiM mfeg== X-Forwarded-Encrypted: i=1; AJvYcCXoE7UQV0qQYJoLgl/1MOXKF5iWbJkqu+yPmYFSVja2Qe1af4Ag02Szx/wBqA7bi08JqE8iyxlKxg==@kvack.org X-Gm-Message-State: AOJu0YzMHQCAwEeaINeAvEmHeqy6M1f9UfOfqkOHvg2XpY6ExcGfhYPG cqTLqIpoHG7y2I1e37Q9nyPkddw3LH9xsRFwmtdIxKp0mSR7jVzxxOIlTIZ2Q94= X-Google-Smtp-Source: AGHT+IG2MV5qcj0/qv1T8GLtm7r8mUhtQUE4d7uFXdf1Vo811CIBSN+1LBAjgReufZYAxzjdCeh83g== X-Received: by 2002:a05:6830:6081:b0:718:12af:c89b with SMTP id 46e09a7af769-71a51545819mr54277a34.1.1731356350161; Mon, 11 Nov 2024 12:19:10 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acae562sm528957285a.83.2024.11.11.12.19.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:09 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 02/17] fanotify: rename a misnamed constant Date: Mon, 11 Nov 2024 15:17:51 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: q8dshmc5uoast4sn8q1hdjf9ky4756iu X-Rspam-User: X-Rspamd-Queue-Id: 0E87C1C0015 X-Rspamd-Server: rspam02 X-HE-Tag: 1731356332-963186 X-HE-Meta: U2FsdGVkX193Ff0GxjCLQkP99YaHpeVKg/rvzUueDDmneXTAywSIRrC5CGkB0m75fz88VK0mMh6PWzyzDg7rfxcEXnKxHOL7eE8M/ZnHEHGsJZl5AbXLn6ZfxrM8cqsxHK4dnuaDntWJVZmrj6oZnuRUayjYlmMWvD5DfMO8R2pn1Ezb6OcuDFTx1oCYkjkSHYx5icTuBXUEijdZu4gKPygzIK/KOeqLjSVsWYJ37TUA5L0tdKVvS4Iy963FVxRAYwJXQqP9/duHJ/HMC87LKuMYwl2piNCoHyJ5Ttaqi9Gje+RraDKuv/H9oknCxjxtiSWnIdjc7kuhoaivy7jKaDjNRcV9YWyFVO+yFTgS3VnO8GTG5b2k38lJNS5QQdw81WoC5/xXYjVadnR6gTdk6vvjffXaf5tH5NHbN61goe7CrOdpXY5xkgzTnlXSDgw0wLvZE+F1fmY0Yfqm5KOIc+4LEVj/H7ZaNDiJ6mQ3LmBflGMK0mtn3oX7R3cVgjsQ5wCRwyurFAUnx3kUVIO9oMwQFv3JjxLy43oMvY/nzkeESVjjyDOhUerUTxH8P4ufQRcVk1t9atF8Sfa8yb3vLlB46bP3/MavmnkPenbSfMefWwGZyAToDY6yjjISisFzdktZ8PIhI93eQHCUSMLhlSYHf8hqUsuBW8REnhfa3t5gJ6aab0pv9YC2KAdEb0f1DD09xo4iUTw1SkoOgpBvMgnOsVJ+2G4qnHrXLWRIlq1jU6H7MgRcdccsA2BQs4/Z4iAS4GDYXEvycW7N1DFGx86USRuikqyVsALH+XJxdGCmHMSIt3p/mkRoRqWr+vbJL127yHlj8dCCDgC2HlPI8XoduxOIPI0Fn7vzE9GDLet82VOsU0ScWO9UpPBEQPj8nOyeh79742yGXpr2bFz2dtUxEnabScMpG7WvbwVuYCw+7OGCzbdbqizmB23u3OpJSHgMEhWM/l1Ce8HGNmC KGwiX8ex +c+qpbpHq9mQyK/wSK0iW8AtJCo+KaKhT+u3VGFTq6ZFTEDuYhqY/KEV/sprIpeYbZHGGfYHN5D6KDXlKAw0wGfix6xS/d0LWvr54ezEZS2NyO+q7QGZwyx5Ah8hJQGvAoyi+1azToAbjlVHFuo+fB2CnxCLq4x6QArIFKs/zMrDkqqwvWmEzfSuIjY2UE22n3pnhHNCEuRR/fyV1eTQ1fdgP9GJcNK3EurYWGPNto+0ru8DPUsC956RaGeGEDG8Xc8Sf206QoHfFT9zXUmkOtXcY99fnDmZCUd6v+jfFq9ksJzqQEH/WqYdnfo2totZlgfS09i/GMF1ZUzw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000230, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein FANOTIFY_PIDFD_INFO_HDR_LEN is not the length of the header. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index d4dd34690fc6..0ae4cd87e712 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -119,7 +119,7 @@ struct kmem_cache *fanotify_perm_event_cachep __ro_after_init; #define FANOTIFY_EVENT_ALIGN 4 #define FANOTIFY_FID_INFO_HDR_LEN \ (sizeof(struct fanotify_event_info_fid) + sizeof(struct file_handle)) -#define FANOTIFY_PIDFD_INFO_HDR_LEN \ +#define FANOTIFY_PIDFD_INFO_LEN \ sizeof(struct fanotify_event_info_pidfd) #define FANOTIFY_ERROR_INFO_LEN \ (sizeof(struct fanotify_event_info_error)) @@ -174,14 +174,14 @@ static size_t fanotify_event_len(unsigned int info_mode, dot_len = 1; } - if (info_mode & FAN_REPORT_PIDFD) - event_len += FANOTIFY_PIDFD_INFO_HDR_LEN; - if (fanotify_event_has_object_fh(event)) { fh_len = fanotify_event_object_fh_len(event); event_len += fanotify_fid_info_len(fh_len, dot_len); } + if (info_mode & FAN_REPORT_PIDFD) + event_len += FANOTIFY_PIDFD_INFO_LEN; + return event_len; } @@ -504,7 +504,7 @@ static int copy_pidfd_info_to_user(int pidfd, size_t count) { struct fanotify_event_info_pidfd info = { }; - size_t info_len = FANOTIFY_PIDFD_INFO_HDR_LEN; + size_t info_len = FANOTIFY_PIDFD_INFO_LEN; if (WARN_ON_ONCE(info_len > count)) return -EFAULT; From patchwork Mon Nov 11 20:17:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871221 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A64BD3ABF6 for ; Mon, 11 Nov 2024 20:19:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 674266B009D; Mon, 11 Nov 2024 15:19:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 620106B009E; Mon, 11 Nov 2024 15:19:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 496696B009F; Mon, 11 Nov 2024 15:19:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2ABF56B009D for ; Mon, 11 Nov 2024 15:19:15 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D524841BA9 for ; Mon, 11 Nov 2024 20:19:14 +0000 (UTC) X-FDA: 82774927326.21.02D37A9 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by imf21.hostedemail.com (Postfix) with ESMTP id A711D1C000D for ; Mon, 11 Nov 2024 20:17:55 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=g6cENZCH; dmarc=none; spf=none (imf21.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.179) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356266; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=c28yJdRjKgJn+HaLKJzmXzT/1RpIgNKOoAPY3XeErlk=; b=GQTiDwIsgL2HpIJgqOsWIueWm65MeK2S87OGTFMOe/cC4kly6hidKCK+2uWrGZX/d13tug U5ouqCDpOT8j863yDpiWHW73CjX8Mi9O6VZCj2fqsLm8dEFPapT7u7cJhfcB3F1wh/Pbfn bagElwb0UTY120x7GmdT2P75+vbMDcM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=g6cENZCH; dmarc=none; spf=none (imf21.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.179) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356266; a=rsa-sha256; cv=none; b=iImTOTOxCpDW7zykH36USXGEFQEEzVgh153PZjspJAkQIwvBDT3Py9kUV9uy0z6bCEBst6 aBXhiULf2MCd50OBAS6D7N53+3vSjppg29vR3ma7xXgLe5euAQFG+69JxeDsnT7x9605on DtItOIk4iMsS3BULyV3I+39Qq6vUjDc= Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-460af1a1154so33125261cf.0 for ; Mon, 11 Nov 2024 12:19:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356352; x=1731961152; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=c28yJdRjKgJn+HaLKJzmXzT/1RpIgNKOoAPY3XeErlk=; b=g6cENZCHrw9CsxyxZ4Qb7AZE/4heXxOlRTqNY20C+m/z8HBb4ydnXc3T23uiO/c/un rBxraA6MHzcGePepzEG4k6SQETZUgfF4zJNLySyOeJ1WninOR5d2pgiCny0BnJZON63y KHL6NS/Hj+zlDl7dG0DZErYaND6XGLFf/DV97TFpoyZfG4080CyOTRnPF2j+Op1yyGP/ 7vnLT5jtWGkfg1elx56p3rz5FBkx5zORX2VO7+I+gYxr6r3SmvsbPLT6hESKIZ/1mY0p 0NnNzP1d2PUneGA27H3WX29ItyznPMQCrVTQL9Z4m0pLtULL96AnCDvdXoX8ZXE2fsGh NKYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356352; x=1731961152; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c28yJdRjKgJn+HaLKJzmXzT/1RpIgNKOoAPY3XeErlk=; b=ntKt7/G7MP3bZ9p14THD3Ck+vRjRxbrLsAX8SRpMW53RZ3O3eDn/Lbdl82TfHhvpk/ fNetTPG1MKOaqaagnMsk7DZ1rsEyzpnt6Ug4fxcl63AWlCjpZuWwsf1MuUrHZkgWeWOM BlxiFBm7uzMNn3/JSCA3p2vW6P80OumgRgG3zPYEawek4YlpI/nol254Uh+T3drX31R1 xuUwGjekE2OjgY1MSKi0RBMQyzDQsK4iHJ9/oC/Rbllb8A11qzV8ZrjPYyqUnBc86Zuc MW6tnTk9J9NWeuBEtTaQ6aHRTaiH21OKvaBHn8+Y8qsGP4NxYe3vN9fATd66eNzuVFTW G67A== X-Forwarded-Encrypted: i=1; AJvYcCWG1pOK7h4rkxKc+ud7vQWMJQsQFKToAGzkCWDhuLzGj7fhLPtjniKDOycKW8LQMERqPXbva0MBbA==@kvack.org X-Gm-Message-State: AOJu0YyMIx5f/QORAKbEZQZ995bocy1rBgZnzy6mvKqD+GLsroTRGv4G Qrl3npgBkuxZoSy5xnd6y8mTQGRjOel7ypp/g1xL+r1uElIu1zRZcStCqVp4u6c= X-Google-Smtp-Source: AGHT+IGJ1y9f+W3Xzh+MP+v/BdPhaguxeBsLZfL0+LeTficfSUhpJzafSU29+3SIM79iI497xnnP7Q== X-Received: by 2002:a05:622a:189d:b0:461:123:d168 with SMTP id d75a77b69052e-46309415f15mr198172601cf.50.1731356352177; Mon, 11 Nov 2024 12:19:12 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff41b63fsm66638381cf.23.2024.11.11.12.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:11 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 03/17] fanotify: reserve event bit of deprecated FAN_DIR_MODIFY Date: Mon, 11 Nov 2024 15:17:52 -0500 Message-ID: <0ac31d4ce175116ee220bc3e1deb0f437ac03ea4.1731355931.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A711D1C000D X-Stat-Signature: 8jyisgrm8493rbpw55a55b6dnht99ipu X-HE-Tag: 1731356275-981424 X-HE-Meta: U2FsdGVkX1/PsLbEK5JcVQNuE3qtb9PY9//c1M9qMK+7+mgp/OlcHeCWuomqcwUqQePwnKbtJBH/z23KQrOsvWbr3atG4CFMJg9MQp2WZ73TW0GVYRhAkiuew0UtUKZJ7/YDUSEfDTFsycxeVMWTJo1V4GB/qSpeD4GM8ka0bmMUefXakP0qYIghriBvg3BW2yi6/tjXRB0yna1Xc5Ja++SeXo/e8O7y4vVFI1ufEU31GdfRA/g5XFk05Bd+G2bwrOYWoIzzMo6MjdCojspBKlGq9abJp6kx74JFyKbji++wGAWYEXbZdeooAJsStajYkeyNzmNRE5BCOM1LyAySO54nl/GbmbEC5OwSPc+DMBpn8WUg7WgpfrgrRjmPVfe+uFEHpZ8AbheLoevP6gcFN2N/+c4245c3Pase/LuHZvjhW01fOBAcwhr4tyqy6db9qIB/TrT9MTI0B5a3XkO62WcObSDT8WfwL3yhq4AfpwP3vgWVSNoEm1QlIgX2XGHJ5t8jpHaoah9F2tGPPBIeuHYv+TZESvUDEB7ixlYS/eMWl8WzeHMzDWewTaaPoupDdXrL/L+Jd/UEeLow081UJh3lEFkbKggzkLBqyxz3TM4r7pYenvOElw4jSbO2pfQfynwqRre/fPusBZqWoXHnQCjEAnUrKovWBtsNZK0nfnqdAT2tC2paf0F0zigoOGLSKT66va2T6HyVR07msQaDY/PsRZxUy1pLbir+YtMB0FqOm6Qn20NKBkACACpcUfLXxPyoHrWj7x8JjfEWdNP2V/GYLKXBeTpLqohegsAF8hlpuowlUpQ4IMj7RVmxY9PIWlCMkymNUXz5xB8TOqkA/c4ibPX4QswuwnBS2hNLbXhbkA47y6zp5cQR08yyigCsZajfY9nHHsEno4jk19uKftx9lovSJkcxWKWlygqw5F/yQus2lCMPMnJqpKWS76ybQzAyMvHWBsOyY2FnZCP Ru5yPcB7 GvRz8xdWlhv84+ik7jgkMcwTVGR15XrVexWBF8tLstJyZVdWvGLxrl2NHVE3bW7H6HOYJI7EABGaR8WdW/N5xDA/7gH0XCV7Cje/9JERcOV4zWMsq7EzE1lvZ34tneND1suXl0K1Hi0Jn2hoZxsMLXk+6vU37AklC33wZAEc5/dmOMw/NV0Mx7ltnf/NF6FGMff+2R67M8lnpkujKLpRoQ5ivXg+Lr3OxFRIyhGw8W6hSc/HuLnTfGCAsN4fMXX9b4aPdLcj21MuzTUqr18DRSzx6gh2Voa68D5zTfEQEhDnwvJVl/6f98slsWlSpSygJ/I1UD9QdWO2peZfNYXT62m2PqBQUbFBptDop1V/BYTWvBK6ZbVEH4m/F6PRJra6oQIQk X-Bogosity: Ham, tests=bogofilter, spamicity=0.000082, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Avoid reusing it, because we would like to reserve it for future FAN_PATH_MODIFY pre-content event. Signed-off-by: Amir Goldstein --- include/linux/fsnotify_backend.h | 1 + include/uapi/linux/fanotify.h | 1 + 2 files changed, 2 insertions(+) diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 3ecf7768e577..53d5d0e02943 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -55,6 +55,7 @@ #define FS_OPEN_PERM 0x00010000 /* open event in an permission hook */ #define FS_ACCESS_PERM 0x00020000 /* access event in a permissions hook */ #define FS_OPEN_EXEC_PERM 0x00040000 /* open/exec event in a permission hook */ +/* #define FS_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) */ /* * Set on inode mark that cares about things that happen to its children. diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 34f221d3a1b9..79072b6894f2 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -25,6 +25,7 @@ #define FAN_OPEN_PERM 0x00010000 /* File open in perm check */ #define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */ #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */ +/* #define FAN_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) */ #define FAN_EVENT_ON_CHILD 0x08000000 /* Interested in child events */ From patchwork Mon Nov 11 20:17:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871222 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D70DFD3ABF5 for ; Mon, 11 Nov 2024 20:19:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADB766B009F; Mon, 11 Nov 2024 15:19:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A63D36B00A0; Mon, 11 Nov 2024 15:19:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B7ED6B00A1; Mon, 11 Nov 2024 15:19:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6BEF36B009F for ; Mon, 11 Nov 2024 15:19:17 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 27AED1C73BF for ; Mon, 11 Nov 2024 20:19:17 +0000 (UTC) X-FDA: 82774927536.22.90BF54B Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) by imf09.hostedemail.com (Postfix) with ESMTP id E4B82140006 for ; Mon, 11 Nov 2024 20:18:46 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=XoEeiUQQ; spf=none (imf09.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.178) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356123; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vqB9yXQqmSu2fdFt06tpBDtWwHudP1dE+kW/6EzrLBA=; b=gDZ916JGdBxupy3366ObeIyotk8qB3aMn/fYcVF9cfoa7qqkyLzkoEkW13f8mmUP20gkx2 9YIU9WMSOPct0GLiyAUue6lZm1ACdBDHChFdpLkKF93fq2dsrU0xaUskzIFimEzb+a6U5y Z9fDPePxNumfgMiGmazUEugwI6swPy0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=XoEeiUQQ; spf=none (imf09.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.178) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356123; a=rsa-sha256; cv=none; b=gTBycMCgeYasyrTULw2r3h4VsW41PrUvrY7E8AzjwFLKtWfK5K445vyglVcPQVKySYkco7 vCy3HFF7Y8bS1dhPb6QAiUxl+MWbPpF/dDMvbqWkuQojGHibTxwKy1gNshY900k5BoIJ6/ G45KceoHlV4q6MX4i8qUhrdR/r+dDZU= Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-46096aadaf0so31077771cf.2 for ; Mon, 11 Nov 2024 12:19:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356354; x=1731961154; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=vqB9yXQqmSu2fdFt06tpBDtWwHudP1dE+kW/6EzrLBA=; b=XoEeiUQQBLmB7+YzPSiiT2JkfwJ2ac/45W3dojggl4ll8hlV/TEk32yKyjSnZQHVrF IJHHif2v9tGtp1Oc2gvsr+ieGSCyd7bLlYajgPX+pyqh2GMBpdoOlll3cCEM2NciEXxM sTsfGheNONpW+kflxX20OelXWJibwx5SklKoAuqhqcdxQntu0lZubt6B6Oc8lj6m8Eyo tO5u9X+94PHftRlNkze4LzHLWgFOKkndGFD7fmG3Ux9OtS1099GebDzRp+12QIAT06hI lzR9Dxs8W916Gzz2J6iOrMepQJnvi/zgCyBMtPliwo8TulFKzYXbIzMr2niytIT1tKSG tlqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356354; x=1731961154; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vqB9yXQqmSu2fdFt06tpBDtWwHudP1dE+kW/6EzrLBA=; b=cT3e99IGezR994nhbe9nEeJwdamw834btIpT6SQtnX0wN9ePxDO6BwEevdUIwxvR5t Cv09otodVK1XPqhnl6YLR3yZDiiBekxq/39+YaCjeOkq7FPGgJgBnxzpKd3ZOOm1kTI+ NpaRiwRIe62nxebgSAmOa6LQCIzIkeLkLEOTdz5a4cySIRNtArHuy0SavWulixcovkHd O2U92QD4ZA0lBIZgFfn0jeCU6DsR2kCtAI0r0ENSQlf2FRbABUW70TGsrRwn2RHFykT+ 4tOGsZSl+rVbuMRhcCR9gkb1ZbBv9MbmevZA3Iiiu+yTIHuSUiKXWhLqsrMYCHAK0OdV osGA== X-Forwarded-Encrypted: i=1; AJvYcCXELMAbOo9D7thf1tAxIEeLT1q/G/YFmDyBL4y9aefeT4YfEE5qQH0zGjsCbghFKjMx5yQpyegKmA==@kvack.org X-Gm-Message-State: AOJu0YzQyKZ102FGZHu75oWzlHYeu4fkXFDbX7RYWHq4fEoKHuOsdAF+ 0WbPHXZaUQVb2qX5m4N4baQlsvX5CjKup073AxqStbXW7eDqBexHIQIJPYJ6oOA= X-Google-Smtp-Source: AGHT+IFyVEZ8nNhuWSqUTWzgqbTv35BuUsnpAhULP/H0sf68MY9l9ZgPUoCV23Vx6WfGGQrB4k4Iag== X-Received: by 2002:ac8:5a4b:0:b0:461:7467:e9f1 with SMTP id d75a77b69052e-4634022f337mr184071cf.26.1731356354292; Mon, 11 Nov 2024 12:19:14 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff3df143sm66588861cf.5.2024.11.11.12.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:13 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 04/17] fsnotify: introduce pre-content permission events Date: Mon, 11 Nov 2024 15:17:53 -0500 Message-ID: <09566e774319a45108594fe51349c1bb511204f2.1731355931.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E4B82140006 X-Stat-Signature: wft3xibkpmnjyn3zxxrksjz64rhoruo9 X-Rspam-User: X-HE-Tag: 1731356326-3679 X-HE-Meta: U2FsdGVkX1/pzu7a95wMxARnNmosYWde8XicPPKJLD/ahCcNfWSD5JAxcFkjqTve+V7yV6suIKdlZGitX3qu4E5YBsSj/SP8OdKxxyoGhl1K7ReN1yjoFDI106/1QJH9D75XV3IzC998e8JTxK5MA93bV+UeVRtkpjch56ma/ev0xHPViUEmKmOCAMaVp7r34587IC7omVULleFOn4t9gTcK9+m19XNBsOyliSehysH7YvVBvlfQYlB0KIHe9UaUSvbriSAIpaULTSzfMAdb/WDMYHXX1puOuUGTC3jQPTR5cFUcc/O+lHFATdzZTinYjH9i1j3gjB5DrWffoc2xD+UaiyyFqcRPWO8ilT7mF4MNoVvPRumAj1dcPlzc5Sxib3qw9qNyzBT65LxNm+VKQZ05wlNBsvKUrQ0nJ6lP1T0YKOev2WN4c27EJ+jeWSS/2I/7dbg6OSoyNcPy8SYy8a/kJJmVfPmvumJRu+Wm8cs1XUO5nBF25ZPk0EfXGfMRvfPsAVVFe/WhViMag1C3nuC/vXTkOJ/s19lPwHJ+WC/dfUPKWT+SbbrA/85b5vW+YRraCuMOldR85lQf4PY8NLh5a9uht3wQRGjpm4oe+dGQliACR+jOWJFd0DErpt6xoFayCuF/56BAP1YKHk+4AUmBehR/1Na8IqbIo5vhC/C0up8xe50M8F6tn1N5OOKvXcFydTZ6wszkaZ4p741RgcwwPbYGGkZzTLV/uBA7ajCbGwNc2zH+pg1Z2ZE5AM9cZmUoYWenOYgz3bMh7wgGHcc2BN52MWgGhPUnf4LnCQlt+jILTxt4KsfS02c6wV4BsFmtTTB9MlwYHsYIXEWaSuSpJEqLoqLffWdfBSq4q3fsJsZOWHnh4fWQDZv4hVA9UMGaG7ISRzWWLc8ue7RoFhLTHb/iroq4oPj8R/6ZooHqhA2SU5XU1PJ+mUl+NqGzJwzznvSdTPzxAZ7KLm/ MWdgQi8u CZIsLNPtuCfDxZmZESCe8yYMf2/UpJec6SDIDJAa5LN9SYlf3N3bFt1sCmIOZ0PVNgpU0rIQYbVWcpzpdzmVfvtBMIDz9ikmIqPkG0euyooAtElvqtdxFzZyCsBJOAQzZulm3ujKV7Jhh3PAiphOSXxAwtqhTaYizxPuDfziVvJQN2JNOdJmBU7aj8Nfak8fxCdTjhVq0Eys8ySLTQTLaPIcrz1cwFYOOwo2Zbh8R1y57eyGO1TT5Ms6aDCDkWEyd/OZpi8FkDKGNbkPUXXoNakZ9TV84MLN4ICN7C6WbA1O9GwscGGvCtB783muHIYzdbeMkyzGAenBAFQgmTswquJaF+A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein The new FS_PRE_ACCESS permission event is similar to FS_ACCESS_PERM, but it meant for a different use case of filling file content before access to a file range, so it has slightly different semantics. Generate FS_PRE_ACCESS/FS_ACCESS_PERM as two seperate events, so content scanners could inspect the content filled by pre-content event handler. Unlike FS_ACCESS_PERM, FS_PRE_ACCESS is also called before a file is modified by syscalls as write() and fallocate(). FS_ACCESS_PERM is reported also on blockdev and pipes, but the new pre-content events are only reported for regular files and dirs. The pre-content events are meant to be used by hierarchical storage managers that want to fill the content of files on first access. There are some specific requirements from filesystems that could be used with pre-content events, so add a flag for fs to opt-in for pre-content events explicitly before they can be used. Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 2 +- include/linux/fs.h | 1 + include/linux/fsnotify.h | 37 ++++++++++++++++++++++++++++---- include/linux/fsnotify_backend.h | 12 +++++++++-- security/selinux/hooks.c | 3 ++- 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 82ae8254c068..0696c1771b2a 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -624,7 +624,7 @@ static __init int fsnotify_init(void) { int ret; - BUILD_BUG_ON(HWEIGHT32(ALL_FSNOTIFY_BITS) != 23); + BUILD_BUG_ON(HWEIGHT32(ALL_FSNOTIFY_BITS) != 24); ret = init_srcu_struct(&fsnotify_mark_srcu); if (ret) diff --git a/include/linux/fs.h b/include/linux/fs.h index 3559446279c1..1b9f74bda43c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1230,6 +1230,7 @@ extern int send_sigurg(struct file *file); #define SB_I_RETIRED 0x00000800 /* superblock shouldn't be reused */ #define SB_I_NOUMASK 0x00001000 /* VFS does not apply umask */ #define SB_I_NOIDMAP 0x00002000 /* No idmapped mounts on this superblock */ +#define SB_I_ALLOW_HSM 0x00004000 /* Allow HSM events on this superblock */ /* Possible states of 'frozen' field */ enum { diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 278620e063ab..7c641161b281 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -132,14 +132,29 @@ static inline int fsnotify_file(struct file *file, __u32 mask) } #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +static inline int fsnotify_pre_content(struct file *file) +{ + struct inode *inode = file_inode(file); + + /* + * Pre-content events are only reported for regular files and dirs + * if there are any pre-content event watchers on this sb. + */ + if ((!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode)) || + !(inode->i_sb->s_iflags & SB_I_ALLOW_HSM) || + !fsnotify_sb_has_priority_watchers(inode->i_sb, + FSNOTIFY_PRIO_PRE_CONTENT)) + return 0; + + return fsnotify_file(file, FS_PRE_ACCESS); +} + /* - * fsnotify_file_area_perm - permission hook before access to file range + * fsnotify_file_area_perm - permission hook before access of file range */ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, const loff_t *ppos, size_t count) { - __u32 fsnotify_mask = FS_ACCESS_PERM; - /* * filesystem may be modified in the context of permission events * (e.g. by HSM filling a file on access), so sb freeze protection @@ -147,10 +162,24 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, */ lockdep_assert_once(file_write_not_started(file)); + /* + * read()/write and other types of access generate pre-content events. + */ + if (perm_mask & (MAY_READ | MAY_WRITE | MAY_ACCESS)) { + int ret = fsnotify_pre_content(file); + + if (ret) + return ret; + } + if (!(perm_mask & MAY_READ)) return 0; - return fsnotify_file(file, fsnotify_mask); + /* + * read() also generates the legacy FS_ACCESS_PERM event, so content + * scanners can inspect the content filled by pre-content event. + */ + return fsnotify_file(file, FS_ACCESS_PERM); } /* diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 53d5d0e02943..9bda354b5538 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -57,6 +57,8 @@ #define FS_OPEN_EXEC_PERM 0x00040000 /* open/exec event in a permission hook */ /* #define FS_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) */ +#define FS_PRE_ACCESS 0x00100000 /* Pre-content access hook */ + /* * Set on inode mark that cares about things that happen to its children. * Always set for dnotify and inotify. @@ -78,8 +80,14 @@ */ #define ALL_FSNOTIFY_DIRENT_EVENTS (FS_CREATE | FS_DELETE | FS_MOVE | FS_RENAME) -#define ALL_FSNOTIFY_PERM_EVENTS (FS_OPEN_PERM | FS_ACCESS_PERM | \ - FS_OPEN_EXEC_PERM) +/* Content events can be used to inspect file content */ +#define FSNOTIFY_CONTENT_PERM_EVENTS (FS_OPEN_PERM | FS_OPEN_EXEC_PERM | \ + FS_ACCESS_PERM) +/* Pre-content events can be used to fill file content */ +#define FSNOTIFY_PRE_CONTENT_EVENTS (FS_PRE_ACCESS) + +#define ALL_FSNOTIFY_PERM_EVENTS (FSNOTIFY_CONTENT_PERM_EVENTS | \ + FSNOTIFY_PRE_CONTENT_EVENTS) /* * This is a list of all events that may get sent to a parent that is watching diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index fc926d3cac6e..c6f38705c715 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3404,7 +3404,8 @@ static int selinux_path_notify(const struct path *path, u64 mask, perm |= FILE__WATCH_WITH_PERM; /* watches on read-like events need the file:watch_reads permission */ - if (mask & (FS_ACCESS | FS_ACCESS_PERM | FS_CLOSE_NOWRITE)) + if (mask & (FS_ACCESS | FS_ACCESS_PERM | FS_PRE_ACCESS | + FS_CLOSE_NOWRITE)) perm |= FILE__WATCH_READS; return path_has_perm(current_cred(), path, perm); From patchwork Mon Nov 11 20:17:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B643D3ABF6 for ; Mon, 11 Nov 2024 20:19:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 49B116B00A1; Mon, 11 Nov 2024 15:19:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4489A6B00A2; Mon, 11 Nov 2024 15:19:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 278BE6B00A3; Mon, 11 Nov 2024 15:19:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 02D816B00A1 for ; Mon, 11 Nov 2024 15:19:18 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 85FDC1C79FC for ; Mon, 11 Nov 2024 20:19:18 +0000 (UTC) X-FDA: 82774927578.23.2B71B36 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by imf28.hostedemail.com (Postfix) with ESMTP id 296B9C0011 for ; Mon, 11 Nov 2024 20:18:35 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=OaQymNll; dmarc=none; spf=none (imf28.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.169) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356270; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=O6ag15Q24m9w8QwPLcjiANNOCwpZepXzE8l8EGOvBlA=; b=KqVGkxiivneYFPO0HN4b5pmlQPgz/uYfmCIJx3gRevwimGBD1REMGDEWPZBK2opzfBbNYh r1myB9wro48Es6bKkD2zf0YjSiwI8t1hcVQMJ7bDBJf4b5nOmB8+XPQ86fbox82f3Y+HTq a0vP+thBLMUFVPwBDRRCDTMwx+F1d2E= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=OaQymNll; dmarc=none; spf=none (imf28.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.169) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356270; a=rsa-sha256; cv=none; b=G0WtGzMrDQB0aWkFt4Y1uUJ+wW8P4VBcybk2XGmkbG3ghFtucRTSsXcZSWRwrm0UNNOOhh Bl6k+xY3PFSf6Jh+Raw4mtIuuyoWEKXWjKgUwFnudmjXgYKXvzjiDvweBXHmKXfCCGMMod WAjh2qgGmNSbHr40WVNVc4ufV02r/2s= Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-7b1505ef7e3so300684585a.0 for ; Mon, 11 Nov 2024 12:19:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356356; x=1731961156; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=O6ag15Q24m9w8QwPLcjiANNOCwpZepXzE8l8EGOvBlA=; b=OaQymNllEnoffm7dDIgbj3WA5XRiI6zKIG1aL5y+Axej7usyRP9lCAFVcDaAuobmZQ CnDbAl9HEkuEF8ZvtQe0sWMqafXMMo1+VxQkz3r+GA8Vs6RzsTBWFfHlS62vpiQXAtQg /MzY/xFYMh7UbitUZApru8n2zF5qwGN6GYyQkAIJZ/k+9oqaFQdRDqMU205K8Q+4VdLK fH3QQ4gE+uOWJaUZQnofRjV0Rj0QSDxcgBZPi4fOo+GRg+8zoMHbPDdku7GeA1/eoUJd QZvtfIyJenTAV4ENlS4Ve2HLm+3ut0cS3FflGzuDaaTOkdK8PW6oMxyNvcYoOko/miy7 wWFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356356; x=1731961156; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O6ag15Q24m9w8QwPLcjiANNOCwpZepXzE8l8EGOvBlA=; b=JI5+EKYQlHAVwOSRfIvxJBwmMklnvZIesDItsqzkD/L1WEOA9QsO7u03bPOKG6WE/e SsDi9H7+dTtQvw8OVRpdlMIMfkIPGJjWdSXBJdrrZZNdxbCcKsmT0PPqewB6cte6kGrp B8oghXOPUVFWQQj1oDY1oaz47wVR+8M4iLdW1SOzpyQdAyl9ilpwR+gCVZcQSYf9EgUr NJIVkZm+TF2U5Pfuh6Pw2jg8lKlbsvBGi5R6qCpukiRyfoo9rfLYGCzQS/8W6z4NB0uu TZSb1dclrjG63apGjCyDwKlDmtLKTtBxDujbuHBhRVCytYpA6OBBx+UzGOoqkEAF8nop Ycew== X-Forwarded-Encrypted: i=1; AJvYcCW+3buXUmx469mmwq/Rt+LhT8sdnMJjiZ5qy3s0IbwDhUK21KTP/525g5BVqxz5mM9CYYM0QleJZg==@kvack.org X-Gm-Message-State: AOJu0YwgLg/bECVWrqwdBF6asYIjWN3z2/ud53yvqbxAjAaN4xA57zin GEOHudd/kvgGACa1sNLU54jzfmNyRUeXssdtzyrlBhM3sXVLbvQ8DpidYd1sHOY= X-Google-Smtp-Source: AGHT+IEW2yf22nobd0a01YcQDEMyEsXEK6xdxMmQ1VVAPmH7hZnR8VEcq8csG7mjjoxGe6bC+tsVsw== X-Received: by 2002:a05:620a:468c:b0:7b1:48d2:f15e with SMTP id af79cd13be357-7b331f3477emr1883416685a.54.1731356355916; Mon, 11 Nov 2024 12:19:15 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acf7f31sm524088485a.129.2024.11.11.12.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:15 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 05/17] fsnotify: pass optional file access range in pre-content event Date: Mon, 11 Nov 2024 15:17:54 -0500 Message-ID: <17994e73515dbbad80c1687421dedd3a44f765ae.1731355931.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 296B9C0011 X-Stat-Signature: igs9tthmsykb6zwt4zqbnn3ijpti58yg X-HE-Tag: 1731356315-836488 X-HE-Meta: U2FsdGVkX18EoefQIqJRI+VDXSrzJAxdPx2khzgM9nKKpzqIa8g+k9LB0WW/R15ZdRiZDJuMgX5f+GE6V7Ghr4p7G59s7u2DKt9Le/iY0rs5IzyqEZCNNYhz/6ValqLpHqnD58nKYSvvxtG5eUZKcpYlP7dqbGK5Mu5sy6h371o9qnga7LBBp85YYtRuMxcAD9FlgH+wkaTISPUQPpYtuHmoA5srB19zoLKQCVf5mlXpQg41vbtYP2L4+lui9ED0kEf6VQiEngnGXoAEp5xCbJrUzwG2fHI1cZnDj8wNi1S8XWbdYYIGMTCOFCJ3ufYU/2QYS8c4kUYpYuC0Kd7usTVbacG92wmQuNNZqa/FSaNAosjLOAV0gltMAExFx0OslsIQDxP74qpoy+4FMky6EgW0TSCgeMLHEwDVEI4OmbqXvCD/DL3h4CRH1+wmQlH0rBJyY84y7Cm564YdFblZ2R9LuNDjtBeeG7/oACh55mj3lnZScnH0vAUvmKhlXa25XThBmyUYv1Rs7KWwgrXbqgV6l6EaYN53ZgX/YrLw12wC5qAqkUxnZeytgQQ9tVEJveCx16Kd9Y0L1kzbkMehz6OuTq7U/Iw8CjolbNVqdGqc90ZguRIIW1rhePmPWUd4GRWwuE0Fb11GUM/afMdZTD368GOVcKIarVaANMjUtB5y8QS4CM2qqaLLJEhDYFsD22tH00XDqMx+7yja9JQ5x23963CCll+Nn+Qc63hBcy0AQIO6u9P22Hjg2jAXT4eI1oDfHnX+bTYPgLqx4aWiGQlPxv4ixOdS6idNFFzuS7+uFMuGYeGK4VOFTipj0BxCtfmS/MWpgekLuQ8XOUjc5KFBXRPE7VM0zcMOTkoOO3B3IEmJ4fBGsM6/d9WfvbFGre4Nv+s4lPA+EQVFVL9XajOxzckxMdFMvQxq67hw8v1QAMrSj1P2U4fTU8p+eCwcLRULEBVAU2Y7UiBnbfw jkJoqA1w IjU4BBgPT29LSBQT+FFX+DzhMdTeFUS1XrAguNiBZa5GX+fxeO4Dr/fbnVd+cZyuz0lhoubq9ImsER01EVh/8GqgRV5WKkrle+L9bqFicNLiEXDvFogjSfhlGo5915aM+0iWBubiJ47cWr9VCX2jTVCgU33JQcR2DPEkA2wMp5ExIOyWjgafCX+IDGkEkqiVcQhIH4M94SJVt40jfJdgG952qzGKZ+eylcAyfXLGsblyZLAi+eeg204AfxoXSf0sws3nfrOIYW8rRJSRsJrRWcBNoMCRZGFyN4jA61aTmvIVyBxxcto74skLWXlshWu16qdeb/XCo1Vi0oS3WBqK9ApWGhw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein We would like to add file range information to pre-content events. Pass a struct file_range with offset and length to event handler along with pre-content permission event. The offset and length are aligned to page size, but we may need to align them to minimum folio size for filesystems with large block size. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 11 +++++++++-- fs/notify/fanotify/fanotify.h | 2 ++ include/linux/fsnotify.h | 28 ++++++++++++++++++++++++---- include/linux/fsnotify_backend.h | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 224bccaab4cc..c1e4ae221093 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -549,9 +549,13 @@ static struct fanotify_event *fanotify_alloc_path_event(const struct path *path, return &pevent->fae; } -static struct fanotify_event *fanotify_alloc_perm_event(const struct path *path, +static struct fanotify_event *fanotify_alloc_perm_event(const void *data, + int data_type, gfp_t gfp) { + const struct path *path = fsnotify_data_path(data, data_type); + const struct file_range *range = + fsnotify_data_file_range(data, data_type); struct fanotify_perm_event *pevent; pevent = kmem_cache_alloc(fanotify_perm_event_cachep, gfp); @@ -565,6 +569,9 @@ static struct fanotify_event *fanotify_alloc_perm_event(const struct path *path, pevent->hdr.len = 0; pevent->state = FAN_EVENT_INIT; pevent->path = *path; + /* NULL ppos means no range info */ + pevent->ppos = range ? &range->pos : NULL; + pevent->count = range ? range->count : 0; path_get(path); return &pevent->fae; @@ -802,7 +809,7 @@ static struct fanotify_event *fanotify_alloc_event( old_memcg = set_active_memcg(group->memcg); if (fanotify_is_perm_event(mask)) { - event = fanotify_alloc_perm_event(path, gfp); + event = fanotify_alloc_perm_event(data, data_type, gfp); } else if (fanotify_is_error_event(mask)) { event = fanotify_alloc_error_event(group, fsid, data, data_type, &hash); diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index e5ab33cae6a7..93598b7d5952 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -425,6 +425,8 @@ FANOTIFY_PE(struct fanotify_event *event) struct fanotify_perm_event { struct fanotify_event fae; struct path path; + const loff_t *ppos; /* optional file range info */ + size_t count; u32 response; /* userspace answer to the event */ unsigned short state; /* state of the event */ int fd; /* fd we passed to userspace for this event */ diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 7c641161b281..22150e5797c5 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -132,9 +132,16 @@ static inline int fsnotify_file(struct file *file, __u32 mask) } #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS -static inline int fsnotify_pre_content(struct file *file) +static inline int fsnotify_pre_content(const struct file *file, + const loff_t *ppos, size_t count) { struct inode *inode = file_inode(file); + struct file_range range; + const void *data; + int data_type; + + if (file->f_mode & FMODE_NONOTIFY) + return 0; /* * Pre-content events are only reported for regular files and dirs @@ -146,7 +153,20 @@ static inline int fsnotify_pre_content(struct file *file) FSNOTIFY_PRIO_PRE_CONTENT)) return 0; - return fsnotify_file(file, FS_PRE_ACCESS); + /* Report page aligned range only when pos is known */ + if (ppos) { + range.path = &file->f_path; + range.pos = PAGE_ALIGN_DOWN(*ppos); + range.count = PAGE_ALIGN(*ppos + count) - range.pos; + data = ⦥ + data_type = FSNOTIFY_EVENT_FILE_RANGE; + } else { + data = &file->f_path; + data_type = FSNOTIFY_EVENT_PATH; + } + + return fsnotify_parent(file->f_path.dentry, FS_PRE_ACCESS, + data, data_type); } /* @@ -166,7 +186,7 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, * read()/write and other types of access generate pre-content events. */ if (perm_mask & (MAY_READ | MAY_WRITE | MAY_ACCESS)) { - int ret = fsnotify_pre_content(file); + int ret = fsnotify_pre_content(file, ppos, count); if (ret) return ret; @@ -183,7 +203,7 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, } /* - * fsnotify_file_perm - permission hook before file access + * fsnotify_file_perm - permission hook before file access (unknown range) */ static inline int fsnotify_file_perm(struct file *file, int perm_mask) { diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 9bda354b5538..abd292edb48c 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -294,6 +294,7 @@ static inline void fsnotify_group_assert_locked(struct fsnotify_group *group) /* When calling fsnotify tell it if the data is a path or inode */ enum fsnotify_data_type { FSNOTIFY_EVENT_NONE, + FSNOTIFY_EVENT_FILE_RANGE, FSNOTIFY_EVENT_PATH, FSNOTIFY_EVENT_INODE, FSNOTIFY_EVENT_DENTRY, @@ -306,6 +307,17 @@ struct fs_error_report { struct super_block *sb; }; +struct file_range { + const struct path *path; + loff_t pos; + size_t count; +}; + +static inline const struct path *file_range_path(const struct file_range *range) +{ + return range->path; +} + static inline struct inode *fsnotify_data_inode(const void *data, int data_type) { switch (data_type) { @@ -315,6 +327,8 @@ static inline struct inode *fsnotify_data_inode(const void *data, int data_type) return d_inode(data); case FSNOTIFY_EVENT_PATH: return d_inode(((const struct path *)data)->dentry); + case FSNOTIFY_EVENT_FILE_RANGE: + return d_inode(file_range_path(data)->dentry); case FSNOTIFY_EVENT_ERROR: return ((struct fs_error_report *)data)->inode; default: @@ -330,6 +344,8 @@ static inline struct dentry *fsnotify_data_dentry(const void *data, int data_typ return (struct dentry *)data; case FSNOTIFY_EVENT_PATH: return ((const struct path *)data)->dentry; + case FSNOTIFY_EVENT_FILE_RANGE: + return file_range_path(data)->dentry; default: return NULL; } @@ -341,6 +357,8 @@ static inline const struct path *fsnotify_data_path(const void *data, switch (data_type) { case FSNOTIFY_EVENT_PATH: return data; + case FSNOTIFY_EVENT_FILE_RANGE: + return file_range_path(data); default: return NULL; } @@ -356,6 +374,8 @@ static inline struct super_block *fsnotify_data_sb(const void *data, return ((struct dentry *)data)->d_sb; case FSNOTIFY_EVENT_PATH: return ((const struct path *)data)->dentry->d_sb; + case FSNOTIFY_EVENT_FILE_RANGE: + return file_range_path(data)->dentry->d_sb; case FSNOTIFY_EVENT_ERROR: return ((struct fs_error_report *) data)->sb; default: @@ -375,6 +395,18 @@ static inline struct fs_error_report *fsnotify_data_error_report( } } +static inline const struct file_range *fsnotify_data_file_range( + const void *data, + int data_type) +{ + switch (data_type) { + case FSNOTIFY_EVENT_FILE_RANGE: + return (struct file_range *)data; + default: + return NULL; + } +} + /* * Index to merged marks iterator array that correlates to a type of watch. * The type of watched object can be deduced from the iterator type, but not From patchwork Mon Nov 11 20:17:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871224 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA0B1D3ABF4 for ; Mon, 11 Nov 2024 20:19:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5ABB88D0002; Mon, 11 Nov 2024 15:19:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BF088D0001; Mon, 11 Nov 2024 15:19:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3119A8D0002; Mon, 11 Nov 2024 15:19:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0A0978D0001 for ; Mon, 11 Nov 2024 15:19:21 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B26061C7960 for ; Mon, 11 Nov 2024 20:19:20 +0000 (UTC) X-FDA: 82774926066.20.07DAD95 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) by imf15.hostedemail.com (Postfix) with ESMTP id 3A4C7A0005 for ; Mon, 11 Nov 2024 20:18:37 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=QjGBJA2I; spf=none (imf15.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.174) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356127; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Gc+ksxaIwBOBmlko1WTmjrx90HfK/kHGON+QNx8apDo=; b=FmZ24W4YWmx9fEe0mSWs5Mr7bKdHhPROUtg3yn2/zfYnnKC+jYJsRUaPuXyiNXLgyj4miT MkQQhNFQAikbvpGx1aQyLZVWwIHyX+zTiRq1zYYHtbetsgeHtwzpnikp7Ila/S2es8dizu 795RECSAVK3w3X2hV6L4CgOLHAslHpM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=QjGBJA2I; spf=none (imf15.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.174) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356127; a=rsa-sha256; cv=none; b=fFA1Bvh/hqY9MXjvDt+ZRXqzEkdTNSo4ea+T/qlCCAyS2cXEylZTDroRFLc0cq+CoOsdP6 ewmTxIhCibgwtsjMe/74AR6vMxhfXA7EKFKlk26aMqsbgIPtyHiUzA9NnOeZymh2uwEDMI Bh4p4R5HAtI3DTuT5rb/V3NZ0+8XxfQ= Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-460a415633fso34513571cf.2 for ; Mon, 11 Nov 2024 12:19:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356358; x=1731961158; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Gc+ksxaIwBOBmlko1WTmjrx90HfK/kHGON+QNx8apDo=; b=QjGBJA2Imyh8GE+i/wwozhTyID5rDg8uPO2k+cDZHp8Ou4tO5t8JdYr+6tpnFyKwEC cWExKBC9lLXoMTdmcwg7ilV0v+drwLScVYZvJHnKz6sD29JPyjh9av8ruA1FpbI34Z/N 47zRFamZTjg8qiy+4ZGL2AfaTmj+3TtH2shZfMpkV84nbx7NcjPFKhNE/VWPwqxEMC6z gMIoZpee/yL275Yy9vxO4Jtj8588y2HQLWnL7w34OIL66tLfdLy4bnZk+xkwOADyIZ0G 3nyppJFiyVmosTB+naxHZM0BSxmmZrbNLaUu3aa/CO0Sex25zd/5Rn2j2eizZmaKB6oX jUiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356358; x=1731961158; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gc+ksxaIwBOBmlko1WTmjrx90HfK/kHGON+QNx8apDo=; b=lkjnhVBL5KmfCo5wiYlvquH4DhZV9w4C6U+ovADmCbPvA/gLCn/uzmuY0y7Zw+TSk8 xIjwiDLt00km7pdgsJwMQ5/+LNnqI5MfmyEZZ8scMOu62QZCyWTf8bcncugH2D3Bh03J ZOSwCA5zTdSslCK5UyQVfm8U+jwUZWWej8wlahRLlLoUIgBvORaTYDqDQs7Y+DH5vUYw gUssNSIewLirkQ7MwRTvA9MZmJFcZEdtCZk0nlyMWXXWMIxxaDt920p5ED0hdSvyk5ba AWowsBSDbBH1o+89hnOVjzNvS3bavJ7aPHKcCaEi3yPGQvTy2aJhFea6kwOsASoSw/fB Q2iA== X-Forwarded-Encrypted: i=1; AJvYcCXlEpJrPhhYH3Pxjmqk1hpmELZVbXW/53dgCwEcvV3nO615tLYnEGRY6MevHW2Vxdbq2l5Q6fHp0A==@kvack.org X-Gm-Message-State: AOJu0YzCQxZrkkwHc+m1YVFXNRuLxgJH6ZU7E2BJvwAXkBNfQCLEcpU9 jKkOAyzWouZX24oE4D0GVmnLSAwf3BleWbEfr8DYgBSpHydJPzY4Sxno1SFAKGU= X-Google-Smtp-Source: AGHT+IHqngnO/59yGfndmsDZIAVzuHVhRF3bKyXBU2iniiGLSmmnpck59CK/mpALqfBlBcxTed5EdA== X-Received: by 2002:a05:622a:4d:b0:460:c5b2:58b7 with SMTP id d75a77b69052e-4630942cc70mr178650181cf.51.1731356358100; Mon, 11 Nov 2024 12:19:18 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff5e2385sm66402261cf.88.2024.11.11.12.19.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:17 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 06/17] fsnotify: generate pre-content permission event on open Date: Mon, 11 Nov 2024 15:17:55 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3A4C7A0005 X-Stat-Signature: e811mcaa374rnqfndd5411mp34tojfsn X-Rspam-User: X-HE-Tag: 1731356317-865576 X-HE-Meta: U2FsdGVkX1+spEJq5QueWvrsl0p08T6Q1nGYmFskQlSSop0nWyAZGtxBadUXDWjfu80/ziPbB/2xv73BAx413QXLtxbZfWzvS6TgjjFdS+Jam92H7XQB+RmIh8jl3Qozk+P1nEBmSmJpAvrUvA3qlqNMPUcCTPy5P8G19eqSX+G5EcM4EtWCBm/0JEdYkAQq978rPTwXZcn9hdAviW99sTfLvO08pUMaOTQDZ5HMcLx+8mr8+FwQP5D1opthoMdUMtKaIS3W3uWtfyJWtUtmZObjAXhazVCKlxJlsLZCOthkodhOEuBu/nz6Iy4gRAbrwxuaoFN0haMXlzevhR8xQ3iJzLMQ4LH/KOgvGz1zXyiuHsoVKt9tyLe7pBhLxcyhwepei18iZaexvGo9GjBFsqtCfWwZNkyBrPrYjmd8rdwreyPwcgqNT3gickJgIQ601lXQUAyajLERBZ7oxWakSO13DSp1n5KPIenCz19Hp8aFNUKbWo7C57W2g/f5h1fc7eObRarCroEA8897IRpFrs7l7+rI7sHZv+ip5VqNeHhk07s3k4U2AmOQDvgifEC+qtaL9su2EXR588pM0IFwYVHyG5wVZ7thWzD1v53omgqi7SFpfsP/4IUo+t+hXiuEJZTII9O9to52DHRG/e8Zgnut0wBLDA/ekBfxiDlb7sTo87MeAF+ysXcBytXIGa8zWG80NGIYKvD7awpt4pxP71eLyNHKOGSOduEjTPtp/W44wRFzTt1lrU4AbnBsWkvW42hH7MAlNfdJcULNc3lYvMQC0R4Bj6jTCcfcaYZ3LVMHBsFmsdBB4NLIBDHuHBmz+MfkAAUQMKz0XWMNmGSd+oC/H4JnYDaGQhASU+UQFv0OYxFLDl9AHY9V8S+oeNtQIl1TZ5FlyO4X+Je+Ns1N3YuFng9zFp+zfVhd7LqM3S3dvcqYXp86C5BaXiW4xdQ1FnRLufp5m0OPrOrCNvF dLcY+3RO q2r5MPElZChxAGp2hI0IZILH07I046TzOmsM3I+hTW289tGhiYUfcPEpqNWcxRnAk3aKcuEdkBYXB8zYPgKny0bvLrqygHSr8bSzKyTqVzMiGruOfN8zGgBbJ5Es+Zx9a2+kdII7Sgx10q4WhntHy81imFnmBaUSt+A2z3bG24KTyM+rTACHtWU2JArKfeBjQeePtR9CRR1DDwnxED2dSW6zABRKAcSUQtgbyEbszss/iq6ZGWiFJDUzvAW0QzW8kp5Hl6YXpvM6rEanTMCxfOLdbleRi976jbLl1BVTdrRgfaZRyd8IicdPC4QNyz0X9x3UCv5ZbGkaVSYssMsuxlQ9/rQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Generate pre-content event on open in addition to FS_OPEN_PERM, but without sb_writers held and after file was truncated in case file was opened with O_CREAT and/or O_TRUNC. The event will have a range info of [0..0] to provide an opportunity to fill entire file content on open. Signed-off-by: Amir Goldstein --- fs/namei.c | 10 +++++++++- include/linux/fsnotify.h | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 4a4a22a08ac2..b49fb1f80c0c 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3782,7 +3782,15 @@ static int do_open(struct nameidata *nd, } if (do_truncate) mnt_drop_write(nd->path.mnt); - return error; + if (error) + return error; + + /* + * This permission hook is different than fsnotify_open_perm() hook. + * This is a pre-content hook that is called without sb_writers held + * and after the file was truncated. + */ + return fsnotify_file_area_perm(file, MAY_OPEN, &file->f_pos, 0); } /** diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 22150e5797c5..1e87a54b88b6 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -171,6 +171,8 @@ static inline int fsnotify_pre_content(const struct file *file, /* * fsnotify_file_area_perm - permission hook before access of file range + * + * Called post open with access range [0..0]. */ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, const loff_t *ppos, size_t count) @@ -185,7 +187,7 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, /* * read()/write and other types of access generate pre-content events. */ - if (perm_mask & (MAY_READ | MAY_WRITE | MAY_ACCESS)) { + if (perm_mask & (MAY_READ | MAY_WRITE | MAY_ACCESS | MAY_OPEN)) { int ret = fsnotify_pre_content(file, ppos, count); if (ret) From patchwork Mon Nov 11 20:17:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871225 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31B84D3ABF5 for ; Mon, 11 Nov 2024 20:19:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED3BA8D0003; Mon, 11 Nov 2024 15:19:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E6A8A8D0001; Mon, 11 Nov 2024 15:19:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CADC58D0003; Mon, 11 Nov 2024 15:19:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A048D8D0001 for ; Mon, 11 Nov 2024 15:19:23 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 46B4341BC0 for ; Mon, 11 Nov 2024 20:19:23 +0000 (UTC) X-FDA: 82774927284.27.343D217 Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) by imf24.hostedemail.com (Postfix) with ESMTP id 1011F180002 for ; Mon, 11 Nov 2024 20:19:15 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=jz3wTsB4; dmarc=none; spf=none (imf24.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.167.182) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356186; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UZOrOsZ4U8Z1PLuT0mm2pKda/bBg1AqKhK+ePUzLSNs=; b=JIbXe7DVb59b5jIvu490LXv7G1LQbE6EW6vHwwW20fi1IlWLgfiGBrvlSjqC4/S28qIoI9 bdN589QOPu19DCSKXT32eRvA1OBmuQBweBHVqnLs5Rt47Lj3vlmU1oolWCGn1mAhWKiHA+ 0kzXvpNQKsd0GIqO1N+aVW+UCd7eHkc= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=jz3wTsB4; dmarc=none; spf=none (imf24.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.167.182) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356186; a=rsa-sha256; cv=none; b=rW6AzjsgRq+MWzaKP6redwspZDEnfJLCYEUsU8ueg0RB+CXSx/83NNI/1Dkw4HJuuXN8tt e7SwliZnI1fpIqtOuN+zJCKagggyC7A0JlF4d47xuB6g2jxwWb12FEDzIBeSnP+mn34g8W dFXDlLWaEOTbno1W24WUDy9XVBcTaiA= Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3e5f835c024so3021877b6e.2 for ; Mon, 11 Nov 2024 12:19:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356360; x=1731961160; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=UZOrOsZ4U8Z1PLuT0mm2pKda/bBg1AqKhK+ePUzLSNs=; b=jz3wTsB4waUIe2WQr3GetJaDlnD9EM9uhzX606FDlfulGM8A65rcCxdnnWm9WUU2My RVNEoLOrSf7Xu3AwooY16DHH9kSYfWQ+hcouTx9k1yZsqdURGCfD4ywFfeV73UfHDMej yjrMvtIJtdTtjA376vDnpfPNHJILNLaeWDSf2vUwJdwuB4yKrxpOL6tW8G9TF8vqW6K+ ki0AEw6Rm+lFX7HFYd6X0ANK0UiMZyIyLS2rmKT1x9MTAdIhjd6mfNeuBHtWIW6siwyM Ws1k+0Wdj4moSyTnc77eU70TRYyLW7gpUaJgOXbz+EH4++phnanUz1EGs75Xd4IX87eP ejqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356360; x=1731961160; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UZOrOsZ4U8Z1PLuT0mm2pKda/bBg1AqKhK+ePUzLSNs=; b=RS+HnT6Tsr3gC1O1YFwHWpkUpadsC4GB2oGFnv3vPgsqYmXeHdJ1rv3HGJcYu+wUfU dDSFw8/YEnmTG1Am4v3vKp18B3xk38F2VL1ogiiPzpHtcVnH/iJT0+XKGb4bfqPVOhyv kOLw0FyHx/hX5NvSsjmitue/I20oZMZjZphrEvjRd52kdqOHeVevTLsJvlu4JDa0R9cZ VXKT75A7jBsOIEsIJtsiaO6eGHTwOcvycNYWPCHph6iZ9ktGbAt/RQI32JglLFtOnjGf m8r4iQ0xySaBtplJAx7Th/TYWhdGxjGWUjEuvbaADRrMqTbTwfzNTEts5JPJ0vMl5Wvt ntng== X-Forwarded-Encrypted: i=1; AJvYcCWjXywWrY5goVjHrr2TbTsAnTTK+/DYvnk/wCzDIwGhr6pAelZbeMXeU74RzaaPiXS5xuvTzPw9bg==@kvack.org X-Gm-Message-State: AOJu0YwtxuDB7//hGhpQcSMSMRzwiMtR7Rm9YWJhM6n4cimNSZFk9of2 YqZ6ww5LCN36w91Vi2SCBm5EENACpyB+43Po5/6vcrQu3/+cqQU0bIGjI2ByMdk= X-Google-Smtp-Source: AGHT+IHipOS2ybKSG81rwkOStrwkrxpZJxan2OC6U26/iyaDXrZO7WYlZi5blzqVcMk5sSNReEzGJQ== X-Received: by 2002:a05:6808:1305:b0:3e6:40b3:e525 with SMTP id 5614622812f47-3e7947734bbmr9745673b6e.41.1731356360425; Mon, 11 Nov 2024 12:19:20 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3961ecdcbsm63623066d6.31.2024.11.11.12.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:19 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 07/17] fsnotify: generate pre-content permission event on truncate Date: Mon, 11 Nov 2024 15:17:56 -0500 Message-ID: <95769c056a65cbc2d6ca6aa1fb66918acbe5ad0e.1731355931.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1011F180002 X-Stat-Signature: ok9uspy5aew1jx9suhj7ah4anqpxpjuo X-Rspam-User: X-HE-Tag: 1731356355-350951 X-HE-Meta: U2FsdGVkX193JmU9cSpcYIblVB4gwMxFOLg7MiFhTQBR8FWMhiKxzrLZjmsqyfitNrB3ZBUak/FvCyNDyU8YSJn7dt7hR3YKONQsx29CQ7B85LTVQOwJ+cTxRJvMQ8cDEugKO7Bg85R2B3LEiyY+uuXDPNxj5Z8WFyjXRl/NhiUw7XlZ4vdfmmlfsqZrpsMWhaFlx0VKyTjl0rDu8VX8h/fGCynFIvaZx8VhbVeb9sVZRSuNjzgGB/VWkKGlQxVhqZfTOkC9d1vlFC5ZMUw7l7dnhdJOxSbiTffCupFPCE8ZL/uGbjnch8KE7scHbYRRTI1X+OiCorMx63cK0TKYgX5wIveaCIxj9IpDapm7oTVFnMKTCiIi/2tFWkltBQ+NgcLJhsV9jnrBMQnAzGCIdvVvsXhNfe9fzrOH/B3l2kMmH0LBq79L1tLI3vke17nXExOKQmvJLswJVpLPAEGA8euo1wzqsncU1yZ2TQdpvr55vgZiGQItLHnIMHqY36em0UREtTPuojO7BGbpgdduuc5hPGd07u3Mcx0OOShydJK+565ho2amjBJrBeIJqK+3ds9gr7CmPUnywnVtBpxcZbvlxvVWDQ8R7mxhJvrGMvv3v3zrHZVrP18MLtTsiVQeDayakAZk4IBME/p/m/5eDdUSOa6wFpne8TdoT5RntKX3UI7pzYzwwVX7quPpOty4IvZxg+ywbpsodsI+1/VZ95JSTpSQx7G2ZYDxSz+vOpPZiuN2aScpJf5VXF7H49WKFdmTYs2s4TwhlC/15VaS+QrcGR8iTekIOa0yWFbPCEUH/WJs4E0puew+BZT45EeK72hXVz8x/wkRpMwuwQQ0PHKDLP+EZkb59sAIiC/w3Rn9m6dPLNqEuNaFXiUIN4FHfkSRr7HPf2ZdlQP7qLQ2/kVOIOu9dArx6Swx17Lt76xuDohEKrlXCvfwCRSbabh+juTvMNAbkV1mFrUv8jT AvQPnRLk GSWo1++pmec6OZZ3WINZW2U4/Yj0cyFP+qasiENPM7FaBe0rvj/ER16rvQ6dHdBzs+AU8TdXliCbhGEhEpxm+akr1ScUcqjMKSag8E+aNMbIFaXU4vYKdDNqedrijVBnHP+5pNStbvJJLH+xr88SnQG/vX5TDoZ+sqKZcmIrp3xB6iCks9szb0/KDKiOBvqZaskG+Q+YZQvcN9VjB4f1S5fi13HBWhJOXRn4q1/ZO9MXssQ41XsExeuHHq1vhGTyyl1vb9ZTfZjxjulricWXEPYZtmLgm9HGdfrsI+uD8OPxHFOgyMcMF/T0ZWSTAbER4h2NoviJW8jEOsRe2PJhbafGS5A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000089, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Generate FS_PRE_ACCESS event before truncate, without sb_writers held. Move the security hooks also before sb_start_write() to conform with other security hooks (e.g. in write, fallocate). The event will have a range info of the page surrounding the new size to provide an opportunity to fill the conetnt at the end of file before truncating to non-page aligned size. Signed-off-by: Amir Goldstein --- fs/open.c | 31 +++++++++++++++++++++---------- include/linux/fsnotify.h | 32 ++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/fs/open.c b/fs/open.c index c822f88d4c1d..51103ba339d0 100644 --- a/fs/open.c +++ b/fs/open.c @@ -81,14 +81,18 @@ long vfs_truncate(const struct path *path, loff_t length) if (!S_ISREG(inode->i_mode)) return -EINVAL; - error = mnt_want_write(path->mnt); - if (error) - goto out; - idmap = mnt_idmap(path->mnt); error = inode_permission(idmap, inode, MAY_WRITE); if (error) - goto mnt_drop_write_and_out; + return error; + + error = fsnotify_truncate_perm(path, length); + if (error) + return error; + + error = mnt_want_write(path->mnt); + if (error) + return error; error = -EPERM; if (IS_APPEND(inode)) @@ -114,7 +118,7 @@ long vfs_truncate(const struct path *path, loff_t length) put_write_access(inode); mnt_drop_write_and_out: mnt_drop_write(path->mnt); -out: + return error; } EXPORT_SYMBOL_GPL(vfs_truncate); @@ -175,11 +179,18 @@ long do_ftruncate(struct file *file, loff_t length, int small) /* Check IS_APPEND on real upper inode */ if (IS_APPEND(file_inode(file))) return -EPERM; - sb_start_write(inode->i_sb); + error = security_file_truncate(file); - if (!error) - error = do_truncate(file_mnt_idmap(file), dentry, length, - ATTR_MTIME | ATTR_CTIME, file); + if (error) + return error; + + error = fsnotify_truncate_perm(&file->f_path, length); + if (error) + return error; + + sb_start_write(inode->i_sb); + error = do_truncate(file_mnt_idmap(file), dentry, length, + ATTR_MTIME | ATTR_CTIME, file); sb_end_write(inode->i_sb); return error; diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 1e87a54b88b6..fbcdddb9601a 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -132,17 +132,14 @@ static inline int fsnotify_file(struct file *file, __u32 mask) } #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS -static inline int fsnotify_pre_content(const struct file *file, +static inline int fsnotify_pre_content(const struct path *path, const loff_t *ppos, size_t count) { - struct inode *inode = file_inode(file); + struct inode *inode = d_inode(path->dentry); struct file_range range; const void *data; int data_type; - if (file->f_mode & FMODE_NONOTIFY) - return 0; - /* * Pre-content events are only reported for regular files and dirs * if there are any pre-content event watchers on this sb. @@ -155,18 +152,17 @@ static inline int fsnotify_pre_content(const struct file *file, /* Report page aligned range only when pos is known */ if (ppos) { - range.path = &file->f_path; + range.path = path; range.pos = PAGE_ALIGN_DOWN(*ppos); range.count = PAGE_ALIGN(*ppos + count) - range.pos; data = ⦥ data_type = FSNOTIFY_EVENT_FILE_RANGE; } else { - data = &file->f_path; + data = path; data_type = FSNOTIFY_EVENT_PATH; } - return fsnotify_parent(file->f_path.dentry, FS_PRE_ACCESS, - data, data_type); + return fsnotify_parent(path->dentry, FS_PRE_ACCESS, data, data_type); } /* @@ -184,11 +180,14 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, */ lockdep_assert_once(file_write_not_started(file)); + if (file->f_mode & FMODE_NONOTIFY) + return 0; + /* * read()/write and other types of access generate pre-content events. */ if (perm_mask & (MAY_READ | MAY_WRITE | MAY_ACCESS | MAY_OPEN)) { - int ret = fsnotify_pre_content(file, ppos, count); + int ret = fsnotify_pre_content(&file->f_path, ppos, count); if (ret) return ret; @@ -204,6 +203,14 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, return fsnotify_file(file, FS_ACCESS_PERM); } +/* + * fsnotify_truncate_perm - permission hook before file truncate + */ +static inline int fsnotify_truncate_perm(const struct path *path, loff_t length) +{ + return fsnotify_pre_content(path, &length, 0); +} + /* * fsnotify_file_perm - permission hook before file access (unknown range) */ @@ -235,6 +242,11 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, return 0; } +static inline int fsnotify_truncate_perm(const struct path *path, loff_t length) +{ + return 0; +} + static inline int fsnotify_file_perm(struct file *file, int perm_mask) { return 0; From patchwork Mon Nov 11 20:17:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871226 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7B74D3ABF6 for ; Mon, 11 Nov 2024 20:19:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E406D8D0005; Mon, 11 Nov 2024 15:19:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DE7B58D0001; Mon, 11 Nov 2024 15:19:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B27608D0005; Mon, 11 Nov 2024 15:19:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 927D68D0001 for ; Mon, 11 Nov 2024 15:19:25 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C464C141AD2 for ; Mon, 11 Nov 2024 20:19:24 +0000 (UTC) X-FDA: 82774927830.23.B8902A2 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) by imf26.hostedemail.com (Postfix) with ESMTP id 141DA140021 for ; Mon, 11 Nov 2024 20:18:51 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=qYcJajoX; dmarc=none; spf=none (imf26.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.167.172) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356188; a=rsa-sha256; cv=none; b=o4ogkVvsdquJdfShmtWQqCK708HH+nqvjXO/zwwhSzL/fYEzMDPwSkHwqoaom7WEd98omo JbrspwVYzdR66AbUAV9tpxAn2ktHxgZRfeJpc4gyhgK7ik1NYoL9nlKyjS5ASkCMfKMuO/ UQvqMsSgazdL+iwaDUD4uVyilGeV4NQ= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=qYcJajoX; dmarc=none; spf=none (imf26.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.167.172) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356188; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BIr6hfiIJt6Z0W2/VohDEaflGJcbA2BZOCByAdmo7A4=; b=vWstQCDmohKDE4Rl3XOJcjoSe+igJ9hw6I5KiGRHCieU15B9l9DonLY5MoZ/Z60gZ79eNT TQ6WDR9E7+Nmo2vrJLJvMUsRucivm3V6ilrAv+uR5QxXbZjzdgRnMB92k3w4heblPHzqrg pQKmG4EgpLhWcOCN19IIzV8lAU790pA= Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-3e786167712so3127548b6e.3 for ; Mon, 11 Nov 2024 12:19:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356362; x=1731961162; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=BIr6hfiIJt6Z0W2/VohDEaflGJcbA2BZOCByAdmo7A4=; b=qYcJajoXyTQpId/D/btBVmWXOwQyduvrt836v5QNijUaQPH6SJ8/G0uymzZjU+ncb4 ozPa+C8WO6F0KGaoN5hvWCivwQ5lfkM/ibRs4360OJoN+1lgIYVlupdBV8vtmcUlc57g 0e0t2veDiAgKO4waQtzfcGwY0FmYmXWsr05kI3SBgu9fJT4XF9w4vLm61N+ZLDtwvLas rBvOklCAlC4jmDRHB94/xF7p6VtjM/obvFuYjr5fenx09Nqdz/Qlx2vSXvjuuwOoXQ1j bMhkCW/2RHRHmYeJQDb1PSimUoVWDduninMpRAL/HydPmp1qapeqZ/HFQYiDr51V2RS+ 5IvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356362; x=1731961162; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BIr6hfiIJt6Z0W2/VohDEaflGJcbA2BZOCByAdmo7A4=; b=cyIV9KSbRcsRF6HyIDr2HNtDnX+kZAh8RKOtQlCw0qdz5huQjdE5Xbz6R+2Sd9GGaA oxYiad1CykyL4Pty6lhmDYryopHlU557w40oFC+7VEKz46LntsSEfEk1S5OuRTk4xwFb 3LkFkYTuxhOkLwhQ1A1JtH41f2jy41TZK+NUqn22PMGwb6QPj+MkwrfvPvjV/LNwzOsN GaEcuf5Cm8a+mOgjsuSPPIS4A/DyOPM23U2E+u04e5e3vahR0AUTkioqW5tocQmjapS2 Mu9A9JaUlD/tBUyVCVuHKpIEDkCe5HxrVL2I2lWNlJm9DbKaRMZ6ec0OSlrYMgaNqMtD +N5g== X-Forwarded-Encrypted: i=1; AJvYcCX+K3xCECqSaY3ybxw14HQYWJLpIBJ2BHHeNy40Ps+nRjcPPBF2Fk5QSNRlKh4eGB+GSTF1uPs7Ng==@kvack.org X-Gm-Message-State: AOJu0YzGcnO6a2QtNxcvKVswQycUBfHkD8sisRKqTM8HN3SZaexiSQOZ 5TXNlE0CbjOru2A37mYNJFxFWbNyM6EO2NL6RFwiwwv13x+t/dfmeCkWCuh9fZU= X-Google-Smtp-Source: AGHT+IG9bGBtdAa/UNjAV/reMXpITXA7+6iabefhDuqPBQRMez+d/kh/izRimXSRfAf9RRVXnEpYWw== X-Received: by 2002:a05:6358:5d8a:b0:1c2:f482:5c0b with SMTP id e5c5f4694b2df-1c641f66059mr620325055d.24.1731356362041; Mon, 11 Nov 2024 12:19:22 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3961f4a0fsm63335146d6.41.2024.11.11.12.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:21 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 08/17] fanotify: introduce FAN_PRE_ACCESS permission event Date: Mon, 11 Nov 2024 15:17:57 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: hthr85zrsrkw3835zkyfkurekkk5bin3 X-Rspamd-Queue-Id: 141DA140021 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1731356331-345494 X-HE-Meta: U2FsdGVkX18hfVqyRah+qnmSZgt7zd1tVKcuKsvkvnh4dRtr3zCnfVZCSJH03Bz/Bls+V+DJR8NyHzm/jbvju3B/gdQn7qYAktAUQzj0iBKlZDJsdIqCjJuzfxGDpj3tV9MGJNzFA/OCdQkfiXgvgar1wyQZiQfKP3tpmxemaRY/QimCabx26KkND9E4YoBCPBQI8uhGnJuM4ZXnJXLDs0u816GQSbSrYQSlDEpdyChTPXl/ilQvOk0zfSKVC0kAJY1bBhAzjWemAsHAHGFB2KCIWDgtM+FOHGKwU84DBQk00yzHorSSogYwVmyBGc7fSd0JYQXFACEV3Mh/JaG4qlO6oQxKHwr86OYkShHbgsNlvabpo43yGiWurYTP7KXCwJsJgYo1jM67gF54kKrSy9tvYButfUfBDp4QtkK2TY/e6KYuTNdfDixmOEh2pZPap+TTKhXV3uOWeDnrlKp4Bw4T742CIVYhvVR7m0ge9QQOvJrKb3OnYivx4YQst+jjjE2kuWVG4Wcy1ijFOEVHzZjPjLnh3HCltGYgNufb7twoglMZn4qJ3YDu3TP9pUgNAs7+I7TvcKC8jTcBO/+/GD3GQvGoQhCOXr5kYzSPp9Rc9YG3S0MjwzqxJnX/EP8OUnyhd28KNSaSKWCCPk0FyQQyVFQq0Nt7nh4oHBr1/tHzpkmrsIeFB1Hnprd7QmxJ05A51iUXKGpF4CKax4RU8MThTMAg7b8zkYeBt4qIJc2seElbjsJ7wPH37HPBe4G/Jo/fgYsAoDM6sn4ThVWrZaGAgLCibmEBfbSYi6vJ0gi0MzTsJaVsGfFz2zOrPxUDruI9aJpkJRDvpzFRyDZgfqGir2Z+io5gyoyhy0lulLnn/Nvf9jVobVRwIC/Vytka5sdNNZbfaU0/rjVLad0dSncBGqSpxXKjaGPGK2WnaECRwx5+H/Bi9bwxCEVZC5yOftt30k+FRjqQr62yKjO ZVpQEdAe Qc9RM8YpUZQd7/jXIbW15p9R8i47BpBaqyv2fbxwjrW4DAzwpnE7yooXFpc2YSDTstYYKWjDSTB/RMyg2My2tcDLapMcFTK+laIUsTPub/b0gFnut+zOFSo9DkmwLT6CHMEIpgn6h59mW9I6KoV/N62qfEwVAQ/PygrbMJ3NjUtQeVKK+vTlYIzlY2LJXLkf/Hbk3JmeIKPDZBfUSgpDak7o+AkPGHjecpiTYG0yasGBJdgr5V/5cANHEv2otSuzUcOD0Al3uXiGodY88lxU3adtQ1AOadMshFmLwCm7L2hCmtGHL1ZRuaXhmA/m8VwWXR0YYffpgKsAUQ+7xbwGpPr6CEM/3gTMvQMXvkAvswS5F5+yfa5rAHMfg9I0q8YEyxToB X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Similar to FAN_ACCESS_PERM permission event, but it is only allowed with class FAN_CLASS_PRE_CONTENT and only allowed on regular files and dirs. Unlike FAN_ACCESS_PERM, it is safe to write to the file being accessed in the context of the event handler. This pre-content event is meant to be used by hierarchical storage managers that want to fill the content of files on first read access. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 3 ++- fs/notify/fanotify/fanotify_user.c | 22 +++++++++++++++++++--- include/linux/fanotify.h | 14 ++++++++++---- include/uapi/linux/fanotify.h | 2 ++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index c1e4ae221093..5e05410ddb9f 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -917,8 +917,9 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask, BUILD_BUG_ON(FAN_OPEN_EXEC_PERM != FS_OPEN_EXEC_PERM); BUILD_BUG_ON(FAN_FS_ERROR != FS_ERROR); BUILD_BUG_ON(FAN_RENAME != FS_RENAME); + BUILD_BUG_ON(FAN_PRE_ACCESS != FS_PRE_ACCESS); - BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) != 21); + BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) != 22); mask = fanotify_group_event_mask(group, iter_info, &match_mask, mask, data, data_type, dir); diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 0ae4cd87e712..da9cf09565ce 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1639,11 +1639,23 @@ static int fanotify_events_supported(struct fsnotify_group *group, unsigned int flags) { unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; + bool is_dir = d_is_dir(path->dentry); /* Strict validation of events in non-dir inode mask with v5.17+ APIs */ bool strict_dir_events = FAN_GROUP_FLAG(group, FAN_REPORT_TARGET_FID) || (mask & FAN_RENAME) || (flags & FAN_MARK_IGNORE); + /* + * Filesystems need to opt-into pre-content evnets (a.k.a HSM) + * and they are only supported on regular files and directories. + */ + if (mask & FANOTIFY_PRE_CONTENT_EVENTS) { + if (!(path->mnt->mnt_sb->s_iflags & SB_I_ALLOW_HSM)) + return -EINVAL; + if (!is_dir && !d_is_reg(path->dentry)) + return -EINVAL; + } + /* * Some filesystems such as 'proc' acquire unusual locks when opening * files. For them fanotify permission events have high chances of @@ -1676,7 +1688,7 @@ static int fanotify_events_supported(struct fsnotify_group *group, * but because we always allowed it, error only when using new APIs. */ if (strict_dir_events && mark_type == FAN_MARK_INODE && - !d_is_dir(path->dentry) && (mask & FANOTIFY_DIRONLY_EVENT_BITS)) + !is_dir && (mask & FANOTIFY_DIRONLY_EVENT_BITS)) return -ENOTDIR; return 0; @@ -1780,11 +1792,15 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, goto fput_and_out; /* - * Permission events require minimum priority FAN_CLASS_CONTENT. + * Permission events are not allowed for FAN_CLASS_NOTIF. + * Pre-content permission events are not allowed for FAN_CLASS_CONTENT. */ ret = -EINVAL; if (mask & FANOTIFY_PERM_EVENTS && - group->priority < FSNOTIFY_PRIO_CONTENT) + group->priority == FSNOTIFY_PRIO_NORMAL) + goto fput_and_out; + else if (mask & FANOTIFY_PRE_CONTENT_EVENTS && + group->priority == FSNOTIFY_PRIO_CONTENT) goto fput_and_out; if (mask & FAN_FS_ERROR && diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index 89ff45bd6f01..c747af064d2c 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -89,6 +89,16 @@ #define FANOTIFY_DIRENT_EVENTS (FAN_MOVE | FAN_CREATE | FAN_DELETE | \ FAN_RENAME) +/* Content events can be used to inspect file content */ +#define FANOTIFY_CONTENT_PERM_EVENTS (FAN_OPEN_PERM | FAN_OPEN_EXEC_PERM | \ + FAN_ACCESS_PERM) +/* Pre-content events can be used to fill file content */ +#define FANOTIFY_PRE_CONTENT_EVENTS (FAN_PRE_ACCESS) + +/* Events that require a permission response from user */ +#define FANOTIFY_PERM_EVENTS (FANOTIFY_CONTENT_PERM_EVENTS | \ + FANOTIFY_PRE_CONTENT_EVENTS) + /* Events that can be reported with event->fd */ #define FANOTIFY_FD_EVENTS (FANOTIFY_PATH_EVENTS | FANOTIFY_PERM_EVENTS) @@ -104,10 +114,6 @@ FANOTIFY_INODE_EVENTS | \ FANOTIFY_ERROR_EVENTS) -/* Events that require a permission response from user */ -#define FANOTIFY_PERM_EVENTS (FAN_OPEN_PERM | FAN_ACCESS_PERM | \ - FAN_OPEN_EXEC_PERM) - /* Extra flags that may be reported with event or control handling of events */ #define FANOTIFY_EVENT_FLAGS (FAN_EVENT_ON_CHILD | FAN_ONDIR) diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 79072b6894f2..7596168c80eb 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -27,6 +27,8 @@ #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */ /* #define FAN_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) */ +#define FAN_PRE_ACCESS 0x00100000 /* Pre-content access hook */ + #define FAN_EVENT_ON_CHILD 0x08000000 /* Interested in child events */ #define FAN_RENAME 0x10000000 /* File was renamed */ From patchwork Mon Nov 11 20:17:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871227 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26BD1D3ABF4 for ; Mon, 11 Nov 2024 20:19:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81BC18D0006; Mon, 11 Nov 2024 15:19:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CC9E8D0001; Mon, 11 Nov 2024 15:19:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F7838D0006; Mon, 11 Nov 2024 15:19:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 402568D0001 for ; Mon, 11 Nov 2024 15:19:27 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F3A45C1042 for ; Mon, 11 Nov 2024 20:19:26 +0000 (UTC) X-FDA: 82774928754.29.D4D6A02 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by imf07.hostedemail.com (Postfix) with ESMTP id B737B4001E for ; Mon, 11 Nov 2024 20:18:27 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=X0i4XsQ+; spf=none (imf07.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.180) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356192; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LGryhZjhYAebksFaS9pdbr55rRjOBk5banX6k6b7VeY=; b=ibPFGbPOeMzd8D7Dy6+mqZZpdeNiV4RL5uXnxgQeu/l3Q/wGJAMHzEwZpD2KLK8UWI6Gv/ k8UhD36WJ5x0qyiyJ4P9LKO5kgyJWb7ScRW//sI2YU0LTHaMS7Vfu5ji0iENk9p9jednY3 l/WauXBACEJnxpzDOpwFgIaRbOj8+VY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=X0i4XsQ+; spf=none (imf07.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.180) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356192; a=rsa-sha256; cv=none; b=Or+Voi4jmseUUCbXlk55v6hK8PxjKDpcjCYRt84jyZ1uNbiTrGIeISqYJpyCF8bJkqHX45 LV158EG3eiJJBZVGdekh2SHyKVamPbXB/e1aIJyXV8C7sYREmNnYNlRPWBXd7Oh+VC6rnA CiPK8XShZPTkXO4ZNAoU5jDQNXEXUUA= Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7b13fe8f4d0so308243885a.0 for ; Mon, 11 Nov 2024 12:19:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356364; x=1731961164; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=LGryhZjhYAebksFaS9pdbr55rRjOBk5banX6k6b7VeY=; b=X0i4XsQ+R/oOi/GbBqRW1muw+qY5NX3bixcLgtUl9UPiKop5l0oPUyF8jIRdyTz2zY M7AgNCXw2Yy+i66tNyKJZ0ZRdeZ4CXh6jjlFUD5PMrykiRqvIoUuvAXNVkxUMf8IEiu0 WCcTLhvfwXQhq30lNLWw5qsWrhJCcVfrKT3Y5AmXcqDmelrXa1Y9CwRix2LREnNhGAKY Whk2Am7PeimIUeGghCrD6ePisT5BTNroBkPvnOlpVEObjJfU0YPKDT3IaXyOHqpa3zuD Wqnhgcj5m60vQJ+kZeyZgieg1tE+hkW60/g4fvtk+32Yu29w3pknqJ+hW26ut7NDflwH pfDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356364; x=1731961164; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LGryhZjhYAebksFaS9pdbr55rRjOBk5banX6k6b7VeY=; b=RsNEAgO50oQqnjGlZXHQ1QTQ3pZ3tBiBAjwNJJm3G9FusTly1/WvQ82/7Ig2ymCnAu /5Pu9MXrRuSFxQgdd8xl8TJ8unWF/Zy/r0EmIOs4ZDmXhmI5RzM5a2uNQdg9J33SQUfm FAVirvBuUWkFrMlSp2MIZKiZoPLjnV1f+9B2k97ZZKsWsfstvI68ndt1nXHU4GO3vXKI X+/PqCezDYCBszOMhw1iiybaR/HsL8DDYGRhEiBiRlEbYdoEO4y381X7L8Ht+cIqT1t0 TOnkvI6U+AlwXtFq+bRGawABEnRSUHz+mYu85hdDVAurvP0IMadjghtl7JSb8LiHnd32 dK3Q== X-Forwarded-Encrypted: i=1; AJvYcCUdgdA5TgxYr+tmjGsLAV3w2eG0FN9uZXwPhKIvJnPE+pVg7m94/Ed9z4D98TiZ6FIn1pVZV4ahUA==@kvack.org X-Gm-Message-State: AOJu0Yz+wwCrjyQmrwbjHh/SDEQdbH3Bd1/7n28d7T5USSEFFwb6d+Os SsL/onaMLN4G0Qau5NgoGjX1Zt/tBZ4PKps971grn425a60YGoNDZ1AInhDRW25uByWOcTOmiwX a X-Google-Smtp-Source: AGHT+IF22B/D1c9DuKVBsfxqpgJ2vY2z65TspT6Q0Pw0A6vpDeL8FShi0pjnRxFhWA3rscCdafTgdQ== X-Received: by 2002:a05:620a:1a94:b0:7b1:48ff:6b3c with SMTP id af79cd13be357-7b331d8b905mr1736558085a.16.1731356364156; Mon, 11 Nov 2024 12:19:24 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32ac57002sm525823885a.43.2024.11.11.12.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:23 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 09/17] fanotify: report file range info with pre-content events Date: Mon, 11 Nov 2024 15:17:58 -0500 Message-ID: <2146833d30122ef9a031e231d8ced7d8a085196d.1731355931.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B737B4001E X-Stat-Signature: g1swt5fie99szfwpmwqex4nkjyukrp9z X-Rspam-User: X-HE-Tag: 1731356307-966751 X-HE-Meta: U2FsdGVkX1+dzpaiO4BK0qI6wty3GMDyVWheLVJLUCqhqqpqkzQfyLVfz6VytI0kJDuarntVwz3C4CDWR7Oip6OjPfETHfTyk/isOOkz6aNslBxzTMFXAzeypAjSlK5dCO+LPop1JPZh3uQYB+YVfLMou4DlRV4J6nIg6Ex3rijuJyDP06Ig6vjaFJn9ZotgRUSb5pZgsd1nmmvuRsvpcii5TAHHlNPDVgv92Eil2xfm3HtlCKxxWLNby71Ney1Crh4qSICtIZu6zzPvt0Meb0p6uDUuwka8/7k3tNMql5LXsVrktipUSNh8Amj2WA5GAYurZcwMqkMq2CNxRsrYoJHw4L/bikUEWtnkWmA7b+ki4VJTO4g+Zr4ydQikAxxt/Z6Wn1/LjI1bIAClAYQ1cU7Q7hhebYahkG4g6WT7h696j2Rlwuz6r/3sSfGND0SgiNXHfZkFM41hlqWvKSC2JdiPM4QHzgEExEeHClHKAyERPBm8OXZp4cQQvK0XW9DywOiHhDIdpM8/4ZZxgRN+xF0IDe0piwjkn5NQycWa+EhMrvPQ2Gno7yrLc/PN4KMfReD3GY2wpZ8HZlZJEsQ4BaLj40ngUgPf6m9+wt/dAhwzXNrssTyzAMK+iQfUnWrGkGKkquDxTW34DF7v8nlvoHF6NvhyDTWs3XyYO5GRChOWO2muuY+INCw/sa3Ms3YXpryIuTZ9vhfIRzg/YXtAjGcK8Orh2DiTZlAa5puniLhfUJkSelvM8x5CU9LNGcPdgOsJ4NnEIm+Af7QaMhhK1IYfgmRaM7FRyP5RL+EfR9ZBbgLCAjr3vKJiZUqwyihh8sW5dGZkzAHpQ7sA1PS+8UkXFuXlQ97QjenHsiU0CELgstZcRWAFmeporEEvBqg3HbkJwU/GCG8vR6bz3eDlYzaDeA2XIP0Wqpsg/fd9ilRRayywx2M5VdkzrTaXFpI/ijioNnKqmZ5pOEBPj7V enOV4Mjt GNndKpqm6rt50cb3B+ShuwSw/xrrKv28EKl/WTlr3gQcpe46EscuEml5/nD0g+kYmV/v32jO2oEMP9F4CJtMxKYStURZ+dbQO3GWRNzInxDE9KBn+USZjmZGawh/v/pJgXSoY06J68H3TW0wyrIDh0beBxPdIELchtcDkiO5MZkvsJP4naxUZn6iSfu8jG4ETg3zkEXI0qRRzs0Z/YFwvNYFKJ3OWtyhakE6smml/wz6k3Vt22rfyo9frswpz61fnOX05/12hVVMcskCEkWsiU6drrufXgO08YtMDW2aFcjK7eKiKl6XdVk+MglwsJY6q3QiaaUmbwTYGmuuKoG7hYdrfCw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein With group class FAN_CLASS_PRE_CONTENT, report offset and length info along with FAN_PRE_ACCESS pre-content events. This information is meant to be used by hierarchical storage managers that want to fill partial content of files on first access to range. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.h | 8 +++++++ fs/notify/fanotify/fanotify_user.c | 38 ++++++++++++++++++++++++++++++ include/uapi/linux/fanotify.h | 8 +++++++ 3 files changed, 54 insertions(+) diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 93598b7d5952..7f06355afa1f 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -448,6 +448,14 @@ static inline bool fanotify_is_perm_event(u32 mask) mask & FANOTIFY_PERM_EVENTS; } +static inline bool fanotify_event_has_access_range(struct fanotify_event *event) +{ + if (!(event->mask & FANOTIFY_PRE_CONTENT_EVENTS)) + return false; + + return FANOTIFY_PERM(event)->ppos; +} + static inline struct fanotify_event *FANOTIFY_E(struct fsnotify_event *fse) { return container_of(fse, struct fanotify_event, fse); diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index da9cf09565ce..17402f9e8609 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -123,6 +123,8 @@ struct kmem_cache *fanotify_perm_event_cachep __ro_after_init; sizeof(struct fanotify_event_info_pidfd) #define FANOTIFY_ERROR_INFO_LEN \ (sizeof(struct fanotify_event_info_error)) +#define FANOTIFY_RANGE_INFO_LEN \ + (sizeof(struct fanotify_event_info_range)) static int fanotify_fid_info_len(int fh_len, int name_len) { @@ -182,6 +184,9 @@ static size_t fanotify_event_len(unsigned int info_mode, if (info_mode & FAN_REPORT_PIDFD) event_len += FANOTIFY_PIDFD_INFO_LEN; + if (fanotify_event_has_access_range(event)) + event_len += FANOTIFY_RANGE_INFO_LEN; + return event_len; } @@ -519,6 +524,30 @@ static int copy_pidfd_info_to_user(int pidfd, return info_len; } +static size_t copy_range_info_to_user(struct fanotify_event *event, + char __user *buf, int count) +{ + struct fanotify_perm_event *pevent = FANOTIFY_PERM(event); + struct fanotify_event_info_range info = { }; + size_t info_len = FANOTIFY_RANGE_INFO_LEN; + + if (WARN_ON_ONCE(info_len > count)) + return -EFAULT; + + if (WARN_ON_ONCE(!pevent->ppos)) + return -EINVAL; + + info.hdr.info_type = FAN_EVENT_INFO_TYPE_RANGE; + info.hdr.len = info_len; + info.offset = *(pevent->ppos); + info.count = pevent->count; + + if (copy_to_user(buf, &info, info_len)) + return -EFAULT; + + return info_len; +} + static int copy_info_records_to_user(struct fanotify_event *event, struct fanotify_info *info, unsigned int info_mode, int pidfd, @@ -640,6 +669,15 @@ static int copy_info_records_to_user(struct fanotify_event *event, total_bytes += ret; } + if (fanotify_event_has_access_range(event)) { + ret = copy_range_info_to_user(event, buf, count); + if (ret < 0) + return ret; + buf += ret; + count -= ret; + total_bytes += ret; + } + return total_bytes; } diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 7596168c80eb..0636a9c85dd0 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -146,6 +146,7 @@ struct fanotify_event_metadata { #define FAN_EVENT_INFO_TYPE_DFID 3 #define FAN_EVENT_INFO_TYPE_PIDFD 4 #define FAN_EVENT_INFO_TYPE_ERROR 5 +#define FAN_EVENT_INFO_TYPE_RANGE 6 /* Special info types for FAN_RENAME */ #define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME 10 @@ -192,6 +193,13 @@ struct fanotify_event_info_error { __u32 error_count; }; +struct fanotify_event_info_range { + struct fanotify_event_info_header hdr; + __u32 pad; + __u64 offset; + __u64 count; +}; + /* * User space may need to record additional information about its decision. * The extra information type records what kind of information is included. From patchwork Mon Nov 11 20:17:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871228 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D6D8D3ABF4 for ; Mon, 11 Nov 2024 20:19:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F20F18D0007; Mon, 11 Nov 2024 15:19:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ED1908D0001; Mon, 11 Nov 2024 15:19:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD4248D0007; Mon, 11 Nov 2024 15:19:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id ADDB58D0001 for ; Mon, 11 Nov 2024 15:19:28 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 73F70A1B18 for ; Mon, 11 Nov 2024 20:19:28 +0000 (UTC) X-FDA: 82774927494.27.31DCA36 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf27.hostedemail.com (Postfix) with ESMTP id D8C574000D for ; Mon, 11 Nov 2024 20:18:44 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=RTnn3Wxx; dmarc=none; spf=none (imf27.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.173) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356192; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bnm9HoX75xrhKnowV+mgCQOJIE5h2IvV5FM7hUYuNNY=; b=TtrRg9OsKeN0ocN5nxaw50ZPfAAMyxHsc9kFdBRy71gtMeE7SURH9/063f0eDu8UDIFcbx adSiMEtw16wC91RjF2HzpYxn5fkbvglZhnOxzKeDPcql/mBYjMMPBVqHM5lMGlSKoPPq3W /jvcjhgAZE6hv4O0du2a6om4hqfSySg= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=RTnn3Wxx; dmarc=none; spf=none (imf27.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.173) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356192; a=rsa-sha256; cv=none; b=yTAfmC0AHVCGieyLtI4WA6l3LlDg5uRMO2qLNEG0bdrovgoYXcK5Dm3/fJVItEa7wNHbf9 gwFpR0wiz8/5FJS8/Zu9faYqlq9RLrMaTQ6iM4nyV7m4Bn5CL4SwhripXyc5YgJo4EQKXx D43vLEaIRvgu5TJ3wAxkILHGMP/9X5g= Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-4613162181dso36959301cf.3 for ; Mon, 11 Nov 2024 12:19:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356366; x=1731961166; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=bnm9HoX75xrhKnowV+mgCQOJIE5h2IvV5FM7hUYuNNY=; b=RTnn3WxxIWA9CHkLNV4qBN1no2FGQjQ1njcELr4dqc6dnWS3ZVZ4W29/xhDbPb96eV 6qE2Td4K1zD4Touzz8s5lvap0WRaRAmCwYdbh756yEI6wlEqTdWeHKZ7qrWdEzBBlcPO 70LVI3RKn1qfchkiexZOWVekHxdachCjSwqYDvfk0r8mxFfFxRS2rdtzf75rJVsRBmNd WPCO3gKMI1H7W/cSIh4sa97iZgfSfk+Ih/F6u8Ee9xo2rmwtnL39NiBjrkS8gQoLKwlh oQwGMOPGqR72s537odI56WK79V8ed09B2AtFIpdYxneGFCbqMISom1yqf1XPSSP1oR5f Zgvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356366; x=1731961166; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bnm9HoX75xrhKnowV+mgCQOJIE5h2IvV5FM7hUYuNNY=; b=jEOwMZV6L+PsPa+EPLQgjczFnWIcRe0Qf5OF8sMcUJriuRis1Jvxtoom7wwHo5XX9N W+cLQpZisj59wagOgMzTloj8eZwWKnfQhGxrmeZFoSKOFWs36Fgx1Lprz8xIoCXAnZrl 4Iy6Y/mV3BwFjwIQEMX3IThzqnyn88BOxq+yqUWkaO79MRNCUAoQIi+4sEhhNOA6xOGF szJK9fQjqB6EZmbtGetkEY5f6DEmv7hf3IIAXx+kBNM5wxYwt3pR/04L44SEjImG44WS dX1+ki3UtGaZE9K/UMvc9YTG780ua2q6y65JWWEKR6omHFaH6OwG/dQb7cSZ5HFAudyL u2hQ== X-Forwarded-Encrypted: i=1; AJvYcCUqEunf3Db6xzRlrr74AhoijfiXbnQJHBvkkdoS98wrSfPtj0jOjDtMfb12zA2UxIsR9SeqigcBpw==@kvack.org X-Gm-Message-State: AOJu0Yyfh5QuJ7sIrR/SjSTVo1IZbtoZPrQX6o6asl/qvPyFJEf0fifc /aGNIKpcvbnc+bsBz8V9PhQ51/qePxnkE3wEESa2M1dpMmEKFaHdSaME40NzBxc= X-Google-Smtp-Source: AGHT+IEMnK5byD6bzAeE8nnbH3/s1NiwYi6YVeXR6nrdTlyrutHvVhB1PYsiGKz3eP2xCUnFM1iy+Q== X-Received: by 2002:a05:622a:1a15:b0:460:ac6f:477a with SMTP id d75a77b69052e-46309396323mr199480931cf.33.1731356365794; Mon, 11 Nov 2024 12:19:25 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff57e935sm66717941cf.57.2024.11.11.12.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:25 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 10/17] fanotify: allow to set errno in FAN_DENY permission response Date: Mon, 11 Nov 2024 15:17:59 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D8C574000D X-Stat-Signature: snhhi73hes7n18cjqn7dcqeme13yqzbx X-Rspam-User: X-HE-Tag: 1731356324-37651 X-HE-Meta: U2FsdGVkX1/NcQ0I4MGbvR/bGu7ZQca0Mig35uvX73uQQkYosJtZ0w3nZIaq6uv/FLKMS0aQlmpfnBa29mQ8VxoPvX/2Wkb2EkXra8pUMGW6nkTMToieHw7HAj7j+dIul4hGByeuLh98K2J/LWU3SeC9dRcSGB23DBqQYH1dwW/D2s7XOn5lo25hT0yh80eDsVd/pczZTv6iQIgj4YfmPoOchJVi0vyzTi4YAacRmz9KiJxcwq2CFTPTDspK7zzVlR5u0ts+VeZN7veP9VeW3PS/zbkb3ASKgPBhBm2fQ4+9R+W+fgJ2/TUWQGF3kwmCQNlY9saJ75JmEOINiVlUHhZWYGGpkoIHGHKHmftrcKH7lYrcdxkgvD/5P68TXCa8EwpYLCIeauq4Wn02VYR/pav+ZAQyiPk3yN6xOltxODCRuD56alg9RBOhQ6xaa5bdQEBFCb1XjyJ3JZPoT/rCYim9SwlrkKZjiAPK72d/zX7VMBBxyYR75Wzzq8AEiziq8507aDjyIypCal+rAHp9pfDdpC220Vw7bTya4mQthljH8o/eLvKFANIgTOPyIBaknQJ6CuveHD0Vk2KJpwdim/v/QgwLSh9iYAIJBU0BxjOBBbz9RtT2tMV9KhzDA3uzaL44QWe46niWF2b85xF+NZ8YcTHQqx4EcQEhZJyrmEhHCuwM4Mc+mouQcQ4owf2rgrXgTlSPUcwK2Y8yTOrm7Uc85kXhx/OL135ef7oCHN5WUKmg9h2VDcQol3B8JbxZb5Ve/1nlMOQlWog5cK70rgeSop4qywq0Xj9NlZ1xXnqV56NgsN0BoOj0gnNGd0g+1XXtTw/sUYHjFN8Nz1Ku+VEIVxlLXqJfFOqEqQtZd6TbnoPRmc4JOwSlPAxrX48oBjDdKVkJt2Eif8NEux7Hc4mUjIFyk2kitAaQq3z2Tbn86iMZy9DpyG6ToBCMzzLiR4iKYPwXllcyU4l+jyt QtMtMY0u x4qlHm2ux9Rz+y10ogfiUA4k2Ax1yRMkgkdK+KGf4uyR/i4guKPtOnK2wbGWEKfprnMna7wcma+BD2qarG9UUsePzwqsC9jKUVhTLd/voiDJzvRJw9fU3pXobDWmsCmjSXF+l55J/bY3buCwQdJxkKNOnrAv6eF/KPnLq6riDz0jeFX9vixOsBw5bUqzbZM/jjGlucYCWhVRNnfiT1ucOv7VpNYtMUNEirvyKBtJvUkjyiy9pbIL/Zjc5TilZgQdJeiTp7+qPljnxsWr5p95utwnAn/Ybzog1jCOMAOJNyL8Qe+AxWt6E32duJYKQDPTD5oRUrgUsn7E+Wo6btCEHn1/qldBBMTw/it97kYbcr8eswNyCT0IGMhaHSlePgf3ZxGTA X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein With FAN_DENY response, user trying to perform the filesystem operation gets an error with errno set to EPERM. It is useful for hierarchical storage management (HSM) service to be able to deny access for reasons more diverse than EPERM, for example EAGAIN, if HSM could retry the operation later. Allow fanotify groups with priority FAN_CLASSS_PRE_CONTENT to responsd to permission events with the response value FAN_DENY_ERRNO(errno), instead of FAN_DENY to return a custom error. Limit custom error values to errors expected on read(2)/write(2) and open(2) of regular files. This list could be extended in the future. Userspace can test for legitimate values of FAN_DENY_ERRNO(errno) by writing a response to an fanotify group fd with a value of FAN_NOFD in the fd field of the response. The change in fanotify_response is backward compatible, because errno is written in the high 8 bits of the 32bit response field and old kernels reject respose value with high bits set. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 19 +++++++++++---- fs/notify/fanotify/fanotify.h | 5 ++++ fs/notify/fanotify/fanotify_user.c | 37 ++++++++++++++++++++++++++---- include/linux/fanotify.h | 5 +++- include/uapi/linux/fanotify.h | 7 ++++++ 5 files changed, 62 insertions(+), 11 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 5e05410ddb9f..17af1b822791 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -224,7 +224,8 @@ static int fanotify_get_response(struct fsnotify_group *group, struct fanotify_perm_event *event, struct fsnotify_iter_info *iter_info) { - int ret; + int ret, errno; + u32 decision; pr_debug("%s: group=%p event=%p\n", __func__, group, event); @@ -257,20 +258,28 @@ static int fanotify_get_response(struct fsnotify_group *group, goto out; } + decision = event->response & + (FANOTIFY_RESPONSE_ACCESS | FANOTIFY_RESPONSE_FLAGS); /* userspace responded, convert to something usable */ - switch (event->response & FANOTIFY_RESPONSE_ACCESS) { + switch (decision & FANOTIFY_RESPONSE_ACCESS) { case FAN_ALLOW: ret = 0; break; case FAN_DENY: + /* Check custom errno from pre-content events */ + errno = fanotify_get_response_errno(event->response); + if (errno) { + ret = -errno; + break; + } + fallthrough; default: ret = -EPERM; } /* Check if the response should be audited */ - if (event->response & FAN_AUDIT) - audit_fanotify(event->response & ~FAN_AUDIT, - &event->audit_rule); + if (decision & FAN_AUDIT) + audit_fanotify(decision & ~FAN_AUDIT, &event->audit_rule); pr_debug("%s: group=%p event=%p about to return ret=%d\n", __func__, group, event, ret); diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 7f06355afa1f..9e93aba210c9 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -528,3 +528,8 @@ static inline unsigned int fanotify_mark_user_flags(struct fsnotify_mark *mark) return mflags; } + +static inline u32 fanotify_get_response_errno(int res) +{ + return res >> FAN_ERRNO_SHIFT; +} diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 17402f9e8609..ca8cc2103b5d 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -330,11 +330,14 @@ static int process_access_response(struct fsnotify_group *group, struct fanotify_perm_event *event; int fd = response_struct->fd; u32 response = response_struct->response; + u32 decision = response & + (FANOTIFY_RESPONSE_ACCESS | FANOTIFY_RESPONSE_FLAGS); + int errno = fanotify_get_response_errno(response); int ret = info_len; struct fanotify_response_info_audit_rule friar; - pr_debug("%s: group=%p fd=%d response=%u buf=%p size=%zu\n", __func__, - group, fd, response, info, info_len); + pr_debug("%s: group=%p fd=%d response=%x errno=%d buf=%p size=%zu\n", + __func__, group, fd, response, errno, info, info_len); /* * make sure the response is valid, if invalid we do nothing and either * userspace can send a valid response or we will clean it up after the @@ -343,18 +346,42 @@ static int process_access_response(struct fsnotify_group *group, if (response & ~FANOTIFY_RESPONSE_VALID_MASK) return -EINVAL; - switch (response & FANOTIFY_RESPONSE_ACCESS) { + switch (decision & FANOTIFY_RESPONSE_ACCESS) { case FAN_ALLOW: + if (errno) + return -EINVAL; + break; case FAN_DENY: + /* Custom errno is supported only for pre-content groups */ + if (errno && group->priority != FSNOTIFY_PRIO_PRE_CONTENT) + return -EINVAL; + + /* + * Limit errno to values expected on open(2)/read(2)/write(2) + * of regular files. + */ + switch (errno) { + case 0: + case EIO: + case EPERM: + case EBUSY: + case ETXTBSY: + case EAGAIN: + case ENOSPC: + case EDQUOT: + break; + default: + return -EINVAL; + } break; default: return -EINVAL; } - if ((response & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT)) + if ((decision & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT)) return -EINVAL; - if (response & FAN_INFO) { + if (decision & FAN_INFO) { ret = process_access_response_info(info, info_len, &friar); if (ret < 0) return ret; diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index c747af064d2c..d9bb48976b53 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -132,7 +132,10 @@ /* These masks check for invalid bits in permission responses. */ #define FANOTIFY_RESPONSE_ACCESS (FAN_ALLOW | FAN_DENY) #define FANOTIFY_RESPONSE_FLAGS (FAN_AUDIT | FAN_INFO) -#define FANOTIFY_RESPONSE_VALID_MASK (FANOTIFY_RESPONSE_ACCESS | FANOTIFY_RESPONSE_FLAGS) +#define FANOTIFY_RESPONSE_ERRNO (FAN_ERRNO_MASK << FAN_ERRNO_SHIFT) +#define FANOTIFY_RESPONSE_VALID_MASK \ + (FANOTIFY_RESPONSE_ACCESS | FANOTIFY_RESPONSE_FLAGS | \ + FANOTIFY_RESPONSE_ERRNO) /* Do not use these old uapi constants internally */ #undef FAN_ALL_CLASS_BITS diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 0636a9c85dd0..bd8167979707 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -235,6 +235,13 @@ struct fanotify_response_info_audit_rule { /* Legit userspace responses to a _PERM event */ #define FAN_ALLOW 0x01 #define FAN_DENY 0x02 +/* errno other than EPERM can specified in upper byte of deny response */ +#define FAN_ERRNO_BITS 8 +#define FAN_ERRNO_SHIFT (32 - FAN_ERRNO_BITS) +#define FAN_ERRNO_MASK ((1 << FAN_ERRNO_BITS) - 1) +#define FAN_DENY_ERRNO(err) \ + (FAN_DENY | ((((__u32)(err)) & FAN_ERRNO_MASK) << FAN_ERRNO_SHIFT)) + #define FAN_AUDIT 0x10 /* Bitmask to create audit record for result */ #define FAN_INFO 0x20 /* Bitmask to indicate additional information */ From patchwork Mon Nov 11 20:18:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04D4AD3ABF5 for ; Mon, 11 Nov 2024 20:19:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A2128D0008; Mon, 11 Nov 2024 15:19:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 953558D0001; Mon, 11 Nov 2024 15:19:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A7B58D0008; Mon, 11 Nov 2024 15:19:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 563718D0001 for ; Mon, 11 Nov 2024 15:19:30 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 14D23160D5C for ; Mon, 11 Nov 2024 20:19:30 +0000 (UTC) X-FDA: 82774927200.07.E604E60 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by imf27.hostedemail.com (Postfix) with ESMTP id 88A3C40013 for ; Mon, 11 Nov 2024 20:18:46 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=nEnJB7Dw; spf=none (imf27.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.175) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356280; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mxzNxKWQS223qRTjvLG5E3r4Xe02F6POoSVqC+sjeek=; b=yBwGFdEHNlpZAlmUC2vkXI0HmjJ54Cmv9b14O1aZN5lJmPeQFhTwyduZJg10UUraOzcYxS 7afL6YXAzi+DEQ9Nos71QAZhLYzlWT6mzatK5U8vMyZF7TK+5phirnXJ9XkRkOQnkdP4Hf W06xxwlsJ3u0FcGmhibXhTm3K6Z5DsU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356280; a=rsa-sha256; cv=none; b=g53tq6xE1O3P1uV3MrFEV6aUrJDbD4e2Qa4PSwAYt9xGLzEUGFqbf/EGjC8cDHcxzN/cIO M2e2m9/DQ65c0U6ZvxXfcTm2wzG6ZosEF4HRKo8TLvoaQbiSWU2ByLxwAH7pgE3t6H/4G8 iYRlWJBURCTJZcMnakO6RaQHCymFsuk= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=nEnJB7Dw; spf=none (imf27.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.175) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-460ad0440ddso33609131cf.3 for ; Mon, 11 Nov 2024 12:19:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356367; x=1731961167; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=mxzNxKWQS223qRTjvLG5E3r4Xe02F6POoSVqC+sjeek=; b=nEnJB7Dw48uWmt5g8UCTF+vKKSe9j/UQM26b9leQR2ka1aSF9q12sXzhFMqsWWjs6l B14rJUNM6UcQV+pIUsQYkRDt9tpzRWxMX4HrBh7nH9ShW1TsmhRhgtA+UvDX9AWOwfg0 TDcT3iccwZUDom4XwAkmsgJLzhvyqJ0rF6gHDvDyLpiekOfcnEOhsYaOTzlQIkF20W35 uUamkyboFFK3u8VIXG3A67m82qZqP+oPOshk+Sk8ZKTvfbNxFcnDm1NIoSk/84pvCUCC q7yLToULDS/ONURWX/nC/oWlMcreZVMHT8KRxPOYFvgOoEHGtgtfhW0ilO0jV4e0uxBd QKBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356367; x=1731961167; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mxzNxKWQS223qRTjvLG5E3r4Xe02F6POoSVqC+sjeek=; b=VfUVXQfqviBfpcM+81OZSKC0BbBdn/0GVM350YNbW4xy3LAuCQSQzVw7hXCy00MGxE a6sqz8wgo0ks6LwGqiNMchojZ+JlZNJmbhkUzpF1GRY1XBUL9biaqGoaDQKpzxtHC+gi yQb2BqgAoq3NUjpe+6AW3z1kvGdkKCBMGXOVJzMBLI9YlLfqojQG0Td8Sjj6KQLDSviB XBhrH5Uu+mYgcF2VUSH4Lr9AYPtDRVcMMsCXZo+U3Gw/Y3ArOwo1X1Crcu3NNjumr2jc GbJCBojWMxJ+EzRxCzxI+9sbNE8ZxLe7cAYScC6RevTd5lVGXaE9H0uc1pFoDH8nmwji hoLw== X-Forwarded-Encrypted: i=1; AJvYcCUmWwLwA0/ecStuDtETenFMWawgOJTFnZlda+q1tR/BoailHp8urDgtWHLYSrYzgfrAB+qF3RXnDQ==@kvack.org X-Gm-Message-State: AOJu0Yyso3GRDnxqjqQwdlZM+Gc0bYH4VaDy+EzUE2KyuZ4WBKt/VCF0 QJk0ZrNhZSHwv4iCeG1DMZ/DUoPiHbQZzsqowvp0vA8CiwpE3FiHUrkCxOv/cRA= X-Google-Smtp-Source: AGHT+IErujsxQUzTbV6poIIfui4YaoHywzZ9+iKLxxl+cBzfLZ4qZlTFt050wM/IYDovGmekQNr9vg== X-Received: by 2002:a05:622a:8d:b0:460:8d16:e8cc with SMTP id d75a77b69052e-46309331aa3mr187305441cf.16.1731356367498; Mon, 11 Nov 2024 12:19:27 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff580e2asm66683971cf.67.2024.11.11.12.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:26 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 11/17] fanotify: add a helper to check for pre content events Date: Mon, 11 Nov 2024 15:18:00 -0500 Message-ID: <0b76f68806fefceae2618e5f135765e429b23025.1731355931.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: 955gj4yx5essrexpwehfhh9gysfuey1p X-Rspamd-Queue-Id: 88A3C40013 X-Rspam-User: X-HE-Tag: 1731356326-487729 X-HE-Meta: U2FsdGVkX1/cydl7R3buJM8KjVovTqRBtDuE+bDmxwMmzHQFPgOIImiU8JnS6I97/vmQDniGtCwI3YKrFkuJL62+ejI9kEdYdyPSXLiGC8aSQG7ToCsExakkCgE3NY0SWL1WxqrtB/OvVs41n0WM66YMeYKGnfFv7C0wpr6/9VbbX8o/qTI+23mIvJGS8TTnhkWLESvxBmRE1KEQw/nQ0/EKfR87AdouieP8cw9caBvkAJDXlYPOy8oX0cBVrqlCIcX5+uJbP3YIepoVAoZa1FST5CoUEN3j1/OWtPyVHiI7h5atlt/SbfuBv78lGz1Dr1nL0G4XWhpGDmUdPCjpqR+xe9gWjwki9jjAMMqTZB2RZ5y6v584zTXLz8lqvRu/8jyM3PAqrRMR2sFnl0nvThOfWYgj9Aao6cRlYuRgijQSZXtMcDBMcjyyhlEWu82Q1p2pR42sH2VlEqoLMeX++3NO2P9epX/zZg6cXS+6J+ZaWuLQyo15AI49TDdgUcUPKG40z17a4GaeaYUSutRvK/XHZp3l3OQKvuXd7GE7YUucYTAjd9G4mP4fR5R/JyjcYZ2zc19C0a4s8AMFktWlgSbyKxj16YfP9d+8G7Xp6KzsBmKBo9RC12jUHVYfk2iGW0qnzkdQ2awBiHgjEDW932WKNhucNUtxCIepdJBFeAmyvE/UmSAZAIlgg4MCcDr0zSJuqIYW5zKTeGlBUR24SrAlSoMA589IVFg+RKNznc9wy5H+OgWsXvFv4nrGmPNCpORABG+lCbhMM+F4orYc3HUigleWCcv9j9cABHcMem++S016t0tKL5bhbhlBeZNamBU+43JkUOd1ERWBRO66fjzGvmGYtJHLF1RcfO0u7QDRv3arWdXxApD7zig99tZDKhs6I9GnqfTrqrSgE6t4b+2vdGBewzKnlUWCOr2Kj9Of10tGZZeXBkRd7w03m5/REkDnzcBjiEko7iTD0e0 +aasPhrQ yaspSmEmgaiwKQy5BJlWC9ZvDSljUYgLEDd04eSPSCZ5DtrdvD401w9Mafmsy0c/9rhfNFZXptydtzX5N6Y9vS66K7gRruhPncP8XsOGw+wCYWBfdmw0lRFvQ+f05tW7G7QLgHzKsJgw0Wq5FmRS7cuA7O5LsMu5hphhufMhTusyZzf7zewhFglbdn9vSIylEnXQQCLXCQROH5YqrQRKeeNenYKDp708xM0geAcAvyCP0Le0f+avaNWCl09RyyHoypDy0zlGW6CSkVVMqEQ/ad8PeqIb7F9S9i0hRC6u3oie2/4RGjF42az9xN83aqmaVypP0Ahb0JHAImjwHxIbRXQNzvMMG6dUPS2CsTGxGTooFX+P1gFWwvrk/nCG7BnVag2kF8icr1H4izT0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000308, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to emit events during page fault, and calling into fanotify could be expensive, so add a helper to allow us to skip calling into fanotify from page fault. This will also be used to disable readahead for content watched files which will be handled in a subsequent patch. Reviewed-by: Christian Brauner Signed-off-by: Josef Bacik --- fs/notify/fsnotify.c | 16 ++++++++++++++++ include/linux/fsnotify_backend.h | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 0696c1771b2a..a49c42c6ce01 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -203,6 +203,22 @@ static inline bool fsnotify_object_watched(struct inode *inode, __u32 mnt_mask, return mask & marks_mask & ALL_FSNOTIFY_EVENTS; } +#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + struct inode *inode = file_inode(file); + __u32 mnt_mask = real_mount(file->f_path.mnt)->mnt_fsnotify_mask; + + if (!(inode->i_sb->s_iflags & SB_I_ALLOW_HSM)) + return false; + + return fsnotify_object_watched(inode, mnt_mask, + FSNOTIFY_PRE_CONTENT_EVENTS); +} +EXPORT_SYMBOL_GPL(fsnotify_file_has_pre_content_watches); +#endif + + /* * Notify this dentry's parent about a child's events with child name info * if parent is watching or if inode/sb/mount are interested in events with diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index abd292edb48c..e3a4a8e06fa0 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -896,6 +896,15 @@ static inline void fsnotify_init_event(struct fsnotify_event *event) INIT_LIST_HEAD(&event->list); } +#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +bool fsnotify_file_has_pre_content_watches(struct file *file); +#else +static inline bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + return false; +} +#endif /* CONFIG_FANOTIFY_ACCESS_PERMISSIONS */ + #else static inline int fsnotify(__u32 mask, const void *data, int data_type, @@ -934,6 +943,11 @@ static inline u32 fsnotify_get_cookie(void) static inline void fsnotify_unmount_inodes(struct super_block *sb) {} +static inline bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + return false; +} + #endif /* CONFIG_FSNOTIFY */ #endif /* __KERNEL __ */ From patchwork Mon Nov 11 20:18:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871230 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1E44D3ABF4 for ; Mon, 11 Nov 2024 20:19:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BD966B008A; Mon, 11 Nov 2024 15:19:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 66F906B008C; Mon, 11 Nov 2024 15:19:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 471656B00A3; Mon, 11 Nov 2024 15:19:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 271AA6B008A for ; Mon, 11 Nov 2024 15:19:32 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D3BAAADDDC for ; Mon, 11 Nov 2024 20:19:31 +0000 (UTC) X-FDA: 82774928124.23.2A70023 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by imf08.hostedemail.com (Postfix) with ESMTP id D7F55160006 for ; Mon, 11 Nov 2024 20:19:02 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=DiPyz97R; spf=none (imf08.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.182) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356197; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+z+eQ7oJzdE2umju6Fr1kTV7qg6yn6q+3nb8dNkk/ko=; b=Xf/TWpFX02RSe3IFFkF6smuhlfMpB/alpsLsZCzfok7o3ndnsSfqTgoB3w6xMDHjQhEBmm 62RefvCA7wvbYE7oIqGflW/1x33kgzAj5eI4nnQWX+RMKaWDkEGAXRrVnAhbNvP28EnlQZ P7BYP9pW4Im8KMsRl185u5P1jlIwdbg= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=DiPyz97R; spf=none (imf08.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.182) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356197; a=rsa-sha256; cv=none; b=bNjY/RwKjXR1b9gWmP7WiZdOM7IPlzNBAH+roA+4g2WRiPE3i0loqmxToyUbo8MfD4hKPt NeaiSvy2ui51Ug03X1HEk+q3zgcjxY97DnOHMQyVrkwc8YgJikKd7lszR50lOjNQ+JdRO2 ws+2hnknDLSXbBsMW8mT7eaaBrgoJfU= Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-7b161fa1c7bso325655585a.0 for ; Mon, 11 Nov 2024 12:19:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356369; x=1731961169; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=+z+eQ7oJzdE2umju6Fr1kTV7qg6yn6q+3nb8dNkk/ko=; b=DiPyz97RC+317aabQ8yGGFGzlUJWsQDBqv5s8NZIy4rntfYvLd6fSYZ3JUMhBXWu/F 6UHtk+f2yOZ1/cHTOAYmSdlKA/zi0u+ePEUtWtcuCzV1Yp/yPkfUZS8M7VoeHANJAraI eLe9TNVn5p7UNsfFAGtSKyRPq1Dk85djj6c3xSJrokKRLO1ZfJFcRgFFe+x2t3CvoJKg m7f409GjjApsQ4akLg0BAvBTuLt2JaqlhkzB8+O7OfAfLuvkMMnSUgaLqP3eWUAbOX7b QZWAJ8jyFkFlRjMRwU4advqBUcJyNw6S1/UB96uStcMw+h3aH5KMONg8BStbTrMGb3pA 0AGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356369; x=1731961169; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+z+eQ7oJzdE2umju6Fr1kTV7qg6yn6q+3nb8dNkk/ko=; b=F+q6uvFVLrpBkYKYloVxtJTGEEVzkv5slTgOkl2352Rtwf24Rl71+8cTYubY7UJQQq Jaz3mBa6SttFf4YAt6sKMCFfQvNaHZFtDfI7tRcVz0+fxrhmW79a7BExWbWqjem4NCNC qVb49PcOEKGX7CtWgcvD7JQbcyZHHSPgrVUSep2mHMSwSfJk6ip1QB2GTSimGk27ZECd RuJGXKcyZnTWjzsSYIivstPRcWFSJelX3aPxta6TEIIWSoAGDkMHlvX2jOdZRL9MsFBx 0uBwj2U7NFkuFCEr+99s3TKhYwU9OYf6S2OmKyY46/X2aaZpKBmGI+g4TD+bn54JyoJL XQjw== X-Forwarded-Encrypted: i=1; AJvYcCVxzhMtXycvHBEcIt94cspWQGFg5eGFsE6lBa8LOGmQM8m8RjJlXEqoNd7lHqzwv2JsjD1+wbZrrQ==@kvack.org X-Gm-Message-State: AOJu0Yz8a+bt8XNGMQIhB4o/00mfCyH96bCpTA2xjn8+7WwjtHUTCR4k bAcj6QYuY9VeCBo9nM75b70R0EcV9MfJsOj2/Cce640y3WfSW0VHXrAC04HPqM4= X-Google-Smtp-Source: AGHT+IGms12DOLEJdB5bkW0IvqVA392HkoYhkn4Pg1bvSAHP7u5Zdmd/IqhCvTQbHrBd1gwbJKpdcw== X-Received: by 2002:a05:620a:179e:b0:7ac:9b5e:baf3 with SMTP id af79cd13be357-7b331eb4c7cmr2112662485a.26.1731356369095; Mon, 11 Nov 2024 12:19:29 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acf7f31sm524104585a.129.2024.11.11.12.19.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:28 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 12/17] fanotify: disable readahead if we have pre-content watches Date: Mon, 11 Nov 2024 15:18:01 -0500 Message-ID: <983e7415c8d083c7bee0d77e81c87b630f093170.1731355931.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D7F55160006 X-Stat-Signature: 81tkinw7e6u8yn8hnqf7h6o83d4zunu1 X-Rspam-User: X-HE-Tag: 1731356342-4550 X-HE-Meta: U2FsdGVkX1+CUOVI2NWWe7DS2SgUH54Zdin3LIOMn1EmXi5h8ft6my2icEcmUzEPjoFl/7C5xa8q8DdaElwAIfRmQMbPI48UJl1bM2v8LCijInCNH1iCUUqigUspOzNIY8ZpRJmG5KKumLKdIEF/drgA8mRezFwRBDh0BZJINL32JS9blAj+NCLh/spA8alFe8KYmEzc0jdwTAIVlAsCkCXFfAKzs6l0LT8WtY6mY4VW/3ckpqfFXTyLZQhCu/AkIGP6ow899FrPvH9P69oblfcz2SqgoaiwqF5I3r72oESqIVbD3eLYcDmuXYMVqS8+2ZmoKAbzt9ti5n5XbJ1kdAEfpVPgqfK97C1lVksDZoKIIqrys8e+mmVz/Rcc4pDuYWwqT/O5OIDr2GMLcjRkiteaVTduE3aUTxuDaYsZeFNxwKGGWuu/FKE1OSxrxT3gMi0uD+OsWEpqsUEmTYjMjD02Ur/m7CVWLx5DK5fUz58FA+4aG87WOzDmIlPTha2hldjEYVH8apx/jwwDlPT34bPwrWSJhk4616Bu3Bk8vXjRRQUm1yhA9a1hbtionlGj6laOMZUjeJY3cc8kkahVrqdcWfJuPAFovW7QJeoDEhxK8Qyi8NH/JjyEHK5yoh2eXW8R12/0sUTqikG7OEUMan/KTWtl84rEbj4xN8XpcM7hfIwe+0dgS+oRTHleJjEMrEXYS/CjDJF7oK/EGpMc+rWgYVUrs+XHsAcVn7idR2yHxkrzx8EQh6DhSSP7yk8SXo3zEBbqTckQT7sO9gIaYaUEGp1ExCt7Ww7CymATJMYkxr+82pMgV6K19kGuvSlZ08rJ6tDVaZkoioTHwRlwVrOnMMQG4ITA/k5+RQupL7g+MC+sanydKMZPYjUEkKNMjoyys13RbJGGimkRNbjaMbUD6ms7XrSi1Suq5uIaSDIaCb3wF6m/Us/jgbRk64W2jU6DxsOUzsmFnVDMJiN iACsqCON xtdIR3/oP3z3We4lqGwkNRCXTQBweR9CnNLuKwrwZhBs0mZwR17K/Ir/B44v72j3+MdmK3mDHfe2ERmnBtgR0WkI15HSKFoVeMa9RlGQZuCCb50KzH8vaoDW8WNUNyR5hSEFGJcgZqPCi7EhvAHJGb9xlEyl/zOYHCT77P8cWdU8X74+fb3YYdjaT6xnWDDIZyiS4jcWKFesXUoU8Ob/QS3qDUS2dFqQ8IiCcVMw0c/BvAhLGFzLtaRcr+MeNABW3rWWtX2+Nps6W3DrOJR27bgL9YHT22b3YU+YOUIInDwhz3tHzP2G24TjfcvrjgAYC0y+1i4qJS/oPeRnFwwumvsCNt0sbbxnXWyEYh71n9RZCkPuefq+Jyr2pGIx8vS3pBecVd/eKipSqPXg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.024849, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: With page faults we can trigger readahead on the file, and then subsequent faults can find these pages and insert them into the file without emitting an fanotify event. To avoid this case, disable readahead if we have pre-content watches on the file. This way we are guaranteed to get an event for every range we attempt to access on a pre-content watched file. Reviewed-by: Christian Brauner Signed-off-by: Josef Bacik --- mm/filemap.c | 12 ++++++++++++ mm/readahead.c | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/mm/filemap.c b/mm/filemap.c index 56fa431c52af..fc36a00fa014 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3149,6 +3149,14 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) unsigned long vm_flags = vmf->vma->vm_flags; unsigned int mmap_miss; + /* + * If we have pre-content watches we need to disable readahead to make + * sure that we don't populate our mapping with 0 filled pages that we + * never emitted an event for. + */ + if (fsnotify_file_has_pre_content_watches(file)) + return fpin; + #ifdef CONFIG_TRANSPARENT_HUGEPAGE /* Use the readahead code, even if readahead is disabled */ if ((vm_flags & VM_HUGEPAGE) && HPAGE_PMD_ORDER <= MAX_PAGECACHE_ORDER) { @@ -3217,6 +3225,10 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf, struct file *fpin = NULL; unsigned int mmap_miss; + /* See comment in do_sync_mmap_readahead. */ + if (fsnotify_file_has_pre_content_watches(file)) + return fpin; + /* If we don't want any read-ahead, don't bother */ if (vmf->vma->vm_flags & VM_RAND_READ || !ra->ra_pages) return fpin; diff --git a/mm/readahead.c b/mm/readahead.c index 3dc6c7a128dd..9fe678cceba8 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -128,6 +128,7 @@ #include #include #include +#include #include "internal.h" @@ -544,6 +545,14 @@ void page_cache_sync_ra(struct readahead_control *ractl, unsigned long max_pages, contig_count; pgoff_t prev_index, miss; + /* + * If we have pre-content watches we need to disable readahead to make + * sure that we don't find 0 filled pages in cache that we never emitted + * events for. + */ + if (ractl->file && fsnotify_file_has_pre_content_watches(ractl->file)) + return; + /* * Even if readahead is disabled, issue this request as readahead * as we'll need it to satisfy the requested range. The forced @@ -622,6 +631,10 @@ void page_cache_async_ra(struct readahead_control *ractl, if (!ra->ra_pages) return; + /* See the comment in page_cache_sync_ra. */ + if (ractl->file && fsnotify_file_has_pre_content_watches(ractl->file)) + return; + /* * Same bit is used for PG_readahead and PG_reclaim. */ From patchwork Mon Nov 11 20:18:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1578FD3ABF4 for ; Mon, 11 Nov 2024 20:19:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C0336B00A4; Mon, 11 Nov 2024 15:19:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 448D86B00A5; Mon, 11 Nov 2024 15:19:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EB156B00A6; Mon, 11 Nov 2024 15:19:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0F6806B00A4 for ; Mon, 11 Nov 2024 15:19:36 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C09691A1C2B for ; Mon, 11 Nov 2024 20:19:35 +0000 (UTC) X-FDA: 82774928376.12.87FDCDD Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by imf10.hostedemail.com (Postfix) with ESMTP id D0762C0010 for ; Mon, 11 Nov 2024 20:19:15 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=qngBGmU8; spf=none (imf10.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.172) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356201; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QtBO4W7ojcvMiQeJDBijogkryb22CThmLCgaVfO4L7E=; b=Y0VNRwGnj+yC5fi+CBNkxhHKe+QNZM48w+yke9YcftlUj27ry2DxlEDo9qB1wGtSDW76HK yr9uwdjY0/35+5CxDnuYyYmYNCYXILgSVrJeFEFrA98MG/vGi7xDyWFIvmmKwl6s67JFru /rKs0aNoq6ukKDIz4hBMH4nUYx+olLA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=qngBGmU8; spf=none (imf10.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.172) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356201; a=rsa-sha256; cv=none; b=Q1Y+ajG9tO1d6XOGGRgoogkuizGkrRgtCCYAASfmFEGBY5PVLTBtpM1TzjH6fy3J2mL6TL uUghkPmt1u8zIud7BkqSm4osCVNrQf6h12CfE9njfEBh8ZUYB+i+8gPrwZuybAeqd5+7Cv oVMG3C30EWO/zTA8DioyEKUURnZg7hQ= Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7b1601e853eso325312485a.2 for ; Mon, 11 Nov 2024 12:19:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356373; x=1731961173; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=QtBO4W7ojcvMiQeJDBijogkryb22CThmLCgaVfO4L7E=; b=qngBGmU8rHufJmGT9WJSjtfAhhT5HA1GuoHO0tAkQRRpzw1ok6cQQKxwfvsVahOQJG 8D3bVSHq2R1uKD78YykyrMcNGpwV3IOc1S+dmNnfAJMlhA0uJkxJDKEz+kyu0KFDLW5D szbSpx6AqvjieZDKK0Wq2R2zzVINXquYGOj4idM0sqK1HvgRUSYAONMlnNh2UTaj8wQx Y66aPvbixnSyWvYVibk9YJmIJfvLsm085gQi3AxkULB9I8VpOdx4Z4StAkMRKv8hqv37 tIClujBhYYiIsvHapOGCTNFYgkvgNK7QJNhHTr3PRUZt5+aAAutq7D4gsVeShq1lJTeA 69OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356373; x=1731961173; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QtBO4W7ojcvMiQeJDBijogkryb22CThmLCgaVfO4L7E=; b=qfbHrMFjI50ZThLgE0ilhcsDxgHS+bkvbhtmF1MJuU99V+qVK7mSL4Z5HdmxpWRcZL r41V4NtDPY+Gj7gjkF8ZE8Ef01qsB7By2iKtRwD/R9GTxsG4ud6vDPXh3W5kXzMoAScH xNVfHBH2PMkJ0Dvt+hfu6rUBS2vVtaMsaAJ2n4vmmd1KCZbmAiPw08XQOh0hS+kDVeUb gLhE8zjN8kZ88IRVjyV6cw8DAxbkBHKMBsQTX83pHMw4jF4gGd0/Hi2LQNd0gsPGDZeM lTwazvcs9ob8FmeFeVnOSbUfaKxXRxRsTjAXkm3dquwiXvFJQQqg4BJL9V/5JFx0dpjP zwrQ== X-Forwarded-Encrypted: i=1; AJvYcCULK54auKKV98oX2+Qwzmd5iH5u8fe+vrufXSxlC3dqQOMb2JZLpNHiWUH/zFnCQe3cOjqXVgHpAQ==@kvack.org X-Gm-Message-State: AOJu0Yy1rAuS5Sd59rV4uIWUW9pvqrb6w5EeJxMzh9VgDL3XOYtDB2+j FX1xIcERfiYo9jsZEdfPwpiiP9ZE1OzLMinogwXkdaHiiqIP8pLMdFBpHRyD7gU= X-Google-Smtp-Source: AGHT+IEVZ5vmyN/LZmrG/1kTbJ7T1FWoFz0xAw/6r2wr8/vwFJmdfm3sS2snhEtpIWxC1ONY/ffBRQ== X-Received: by 2002:a05:620a:178b:b0:7b1:447f:d6f0 with SMTP id af79cd13be357-7b331eb87dbmr1968482385a.23.1731356371650; Mon, 11 Nov 2024 12:19:31 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acea072sm526763585a.114.2024.11.11.12.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:30 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 13/17] mm: don't allow huge faults for files with pre content watches Date: Mon, 11 Nov 2024 15:18:02 -0500 Message-ID: <5c64164cd1f16431edd1d468cb3204d29d86bbf4.1731355931.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D0762C0010 X-Stat-Signature: gzpjs3wasx1nwkroeyifaw1u4qutfg9j X-Rspam-User: X-HE-Tag: 1731356355-651519 X-HE-Meta: U2FsdGVkX19I9/MbIGpKs+cWcvalOOBXZKjzLeme5vc+Xqljj0ToDeRgFJP6tGZ/a059f/m9KEBbk04MxDlINk9tT99Yfoy//X4Ky/bjTe4uAgyRUJ6oAg79+ek4rqcQrQni86EF6XMIAEgBOWqkGySp9amLzucXJKnhak7mym6moiLc273C9ZAu3y5MAJdBLnb7YLSntaJ4hnHtqd1LwfeKJdxckcQ/yoTqRnXp5u3baV3/7PQ3WEHA90ailo3CU3Atgz5YK3CpY9cgFhdAPLM/ntG4F1GvHKvi+Ld9YsnpVUQN+gCYy4PUst4r2Q6IOBOtLQItQshWgV2TLlkjBHrgdcCukqSysz8yHFq/ATptuVGCmPRLM0HoLySC1N3uu41rOcbDOE4sMLbZ0puIkwTiyg6jK7h0UoOXNGDxz1Sz9pqtEb6gxBPhCkwz9k74xlEkXBC49ik2DHQ887d6kZsObD1uhxquzytdMDclq3gxlw/+m34Fmvv3bp5ASRzVOOylFG3+lZRoS9a3IYXNWpcOyqMR7/3lUeYJGK87UtORQSI3b/UgiWL0Tiae/kwWnuqlWjO5LOF8Uf/B+EAEp702dKfWpUTM0pr2aD4wLuE602WC/PZxq709l7lE8w4LTiw3FJQAurrJGZ8fmNlrtFkjQLZosxKQUQLF9DzyWvWKde2HxcWb5zpk5j+b4hUVI+sACoKA8FE6KE+RuTI133oeuz+FaZfkqFU6NEkzVNHOgV2RpiSTWqDXu+3aEVlw6qdbMB/POzeiX0298F/e75bnbZyDVhHQ7IXszA2ecTgYNWt77VwnUdz4UfUXMScwvfsDSp16sRrJTLrEVltiyxpXJs9cxqnxXwPyK17LkWHVDKS8FfEWVF7dxPebH+hRBMnnScoyt7GAiz2nO2HUOO5z6dI41TY36HqYLvIzaLow45d1s4dsmm/rRc/66nIaxVlTGRF6axGj/u3KWw0 yakL9rMw QTbzgoP3S459oUaaLmnFqhFzNu3ZE6sSYdlX73beuRS7D03hgJzWmBcGAG6yJL8jd161iD5IvNcY6Xs0GstTHCwy6O6HTbhki5UUUdg9b/Puz1A1HRxqzgq1ImiTUuotLLuo5UOvPwvxQuiCvGVm3p6eEj+oB0gk6ea3sKyyi+X+JvwYXCKiVEvGyLaZzXW36l74E+WmuRnJKzLOcNeZQ72D2TDetpL8C4O/UWHl714ese2Oy7Ui/7dsFqLyV0QfoXqEHdYj4R4aldc4VfDoEfhnxCtyTemtuF/AhLN0umTIbLsX6uuRPLeGL6Fbz61EGGzRoiCPNUbFcXhh/eyPoCB4f3s8F01Zn4ldYfAkRzw6+J/Y16n2GQmiRNwLgjntknSkKe/D6HpV+urE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.011995, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: There's nothing stopping us from supporting this, we could simply pass the order into the helper and emit the proper length. However currently there's no tests to validate this works properly, so disable it until there's a desire to support this along with the appropriate tests. Reviewed-by: Christian Brauner Signed-off-by: Josef Bacik --- mm/memory.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index bdf77a3ec47b..dc16a0b171e3 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -78,6 +78,7 @@ #include #include #include +#include #include @@ -5637,8 +5638,17 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) static inline vm_fault_t create_huge_pmd(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; if (vma_is_anonymous(vma)) return do_huge_pmd_anonymous_page(vmf); + /* + * Currently we just emit PAGE_SIZE for our fault events, so don't allow + * a huge fault if we have a pre content watch on this file. This would + * be trivial to support, but there would need to be tests to ensure + * this works properly and those don't exist currently. + */ + if (file && fsnotify_file_has_pre_content_watches(file)) + return VM_FAULT_FALLBACK; if (vma->vm_ops->huge_fault) return vma->vm_ops->huge_fault(vmf, PMD_ORDER); return VM_FAULT_FALLBACK; @@ -5648,6 +5658,7 @@ static inline vm_fault_t create_huge_pmd(struct vm_fault *vmf) static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; const bool unshare = vmf->flags & FAULT_FLAG_UNSHARE; vm_fault_t ret; @@ -5662,6 +5673,9 @@ static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf) } if (vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) { + /* See comment in create_huge_pmd. */ + if (file && fsnotify_file_has_pre_content_watches(file)) + goto split; if (vma->vm_ops->huge_fault) { ret = vma->vm_ops->huge_fault(vmf, PMD_ORDER); if (!(ret & VM_FAULT_FALLBACK)) @@ -5681,9 +5695,13 @@ static vm_fault_t create_huge_pud(struct vm_fault *vmf) #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; /* No support for anonymous transparent PUD pages yet */ if (vma_is_anonymous(vma)) return VM_FAULT_FALLBACK; + /* See comment in create_huge_pmd. */ + if (file && fsnotify_file_has_pre_content_watches(file)) + return VM_FAULT_FALLBACK; if (vma->vm_ops->huge_fault) return vma->vm_ops->huge_fault(vmf, PUD_ORDER); #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ @@ -5695,12 +5713,16 @@ static vm_fault_t wp_huge_pud(struct vm_fault *vmf, pud_t orig_pud) #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; vm_fault_t ret; /* No support for anonymous transparent PUD pages yet */ if (vma_is_anonymous(vma)) goto split; if (vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) { + /* See comment in create_huge_pmd. */ + if (file && fsnotify_file_has_pre_content_watches(file)) + goto split; if (vma->vm_ops->huge_fault) { ret = vma->vm_ops->huge_fault(vmf, PUD_ORDER); if (!(ret & VM_FAULT_FALLBACK)) From patchwork Mon Nov 11 20:18:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3905D3ABF4 for ; Mon, 11 Nov 2024 20:19:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E86696B00A5; Mon, 11 Nov 2024 15:19:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E0EEB6B00A6; Mon, 11 Nov 2024 15:19:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C87296B00A7; Mon, 11 Nov 2024 15:19:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A5CA66B00A5 for ; Mon, 11 Nov 2024 15:19:36 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 62FD41C73BF for ; Mon, 11 Nov 2024 20:19:36 +0000 (UTC) X-FDA: 82774928292.26.E5D2903 Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) by imf20.hostedemail.com (Postfix) with ESMTP id B4C871C000E for ; Mon, 11 Nov 2024 20:18:43 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=rYzyObNl; spf=none (imf20.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.167.173) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356232; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+nXKwcxfUzOePvYnZ4Bb/p4hYsf8sSP8uIyFDoaTPjc=; b=ijJi842hVXwJX3FbRjGnMhbtiEJJkbCScIKxVF3KUqigfeK4ldrpsSA8zj4lX/SpwXsNWz Js3svbHbBiTxmbzwtDtZ4b9VxMlAdZ8VUOyXmE5bGJEgyYUnvgXdFGkRic5WrrHWOvyo4c qaJABSoBG2KnNxR4Gsq/Yfg49Htvgqg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356232; a=rsa-sha256; cv=none; b=GBtwR/sEVPxJAbs6OGN2HbHMb4CkGmqXC5Thhp5bQ4tV4HwuGxSFohwTgMrPs7qe507Ls9 HA/AvMXWw4TxADIK1KDJZOCjCpduOyFhIwowTfl8dBXE44EijV1xUIwAtDMp3692nvuFbA z84ug2Hqpo6j2n6V+CwcOIK7mByRsZA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=rYzyObNl; spf=none (imf20.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.167.173) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3e60966297fso2283323b6e.1 for ; Mon, 11 Nov 2024 12:19:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356374; x=1731961174; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=+nXKwcxfUzOePvYnZ4Bb/p4hYsf8sSP8uIyFDoaTPjc=; b=rYzyObNlum9/8TbbD4hsXQNISz5O/04Qfrkrd381+P7WYnUU2GRbXEm1X50hUAZqgk 2B1eZennVMKkI2sH+UcNN8koorofswf4Xdb/jZOIwcy1xL2EuvdP1s8aZN1+9KomC4Tt 4TtsJXvtrahle372fH3gb8rakA4qAnEsiS+Dxm64xQqSzhNzXx+siMB5Yn+aWUbsxTch s3wQuif7sgD9s9Avlnfdoa2hKegSsATYNf+EC64BVD/QnyhcpqPiVWt/G+Bg9CBUvOL5 n+y+yw8DUaZkhS0ziWbZtrRMoi6OTEAzrX6TnG1twidZrF+tP2nt+1SLy2XBczmuFpHp zBXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356374; x=1731961174; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+nXKwcxfUzOePvYnZ4Bb/p4hYsf8sSP8uIyFDoaTPjc=; b=X6v2KJUQD5u32971JL5BWUbIcQKKhEOsk0F1eYefSvOcTxIwQGhD0RNlrSbLwvkxbv K7WuheamVWdXbPqyaFvhJP5raZpsGlbBMxz8zwmd4kdlAjaU8k0cdhFBH38ENsWbp9B3 o8wKJw1T88al5NtXCy6TzpD0+nGlHv4l4Q7DkAaRV00P8TfKQKDb9NL5Hjpk2/DlQW/r qigkdawNWnBkIUfgYfLICWYIylVhPxH/+RCMhveEovEOAosaUiQy7ijyV+cFghaMXm4L poyFJrYNb5BLUDk8TqAG+IW00/zdZHE/T6yN+DsfDd8owbK+H+JV9mDdc/wSBTzRmjly 5P9Q== X-Forwarded-Encrypted: i=1; AJvYcCWRQWelu/w37qgNZ1IrM06/ATJnkMbaguuiGEm6uxk86Nj3PhQeggllB7TCsKPc5rfgWcg3fxUjZg==@kvack.org X-Gm-Message-State: AOJu0YwY16JtKt5ohU5Nd/LMJAdAUhNkTFbYxsHdjh9y/1QhPWn61m7G chvqLZdYocb5HA5gGM5xH0xUurUZ5UNvVf3UjL27CGmutDTGk0OjrpdJtG/rMR0= X-Google-Smtp-Source: AGHT+IHAntmNSKHnJiD7mii22aSouugOuv2LnJCY83E+/C/49mfb6yy9irDZkbJmhglaB0kAus4AaA== X-Received: by 2002:a05:6808:3a15:b0:3e6:943:63c9 with SMTP id 5614622812f47-3e79470a33cmr12285250b6e.33.1731356373743; Mon, 11 Nov 2024 12:19:33 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3962089fesm63519156d6.61.2024.11.11.12.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:33 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 14/17] fsnotify: generate pre-content permission event on page fault Date: Mon, 11 Nov 2024 15:18:03 -0500 Message-ID: <4046b63f054f5896c9c4c715180664eca1366ac1.1731355931.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B4C871C000E X-Stat-Signature: bjz89gyhjj48aix37fxnddezftraekfk X-HE-Tag: 1731356323-300334 X-HE-Meta: U2FsdGVkX1/tErC+frwBj2HouwGdOGFcoS+RuTJYweZa4zRDEQR/VgQMhteDgcpjHLuTIyBdSFNdfoMBWmgzPSGM3yX1E5z4i+OxY+bnW2sy3UGPnu8I+MXuVIDuGPu4ze91dvCTAign+g4FoN6ZWuqX0CwU5mAOa6gi8RgYJxmiqs8L4KICB7wYu3TgiVH+AUcWU3GaF7KqRRiwgtg2UXQMhU0ol/+IOcMHUxIrgBA5uAIS6se4Ku3MJOqPopPfYoFwiIKIX6r5yoSaZSAQl3qIGlZq+RkpZ/m4sfH1BWcoMTHnpe+pFgTUlxPi0dVOMB/U5I5K/g3FtJqRhYZ34T3YOQw61wpaXVASPNhPfP0AQo/IbEmjwVc/ljZS6QMCIh5DQuKuIuBVw+wEn0fWgNQdO5/By2t1hTXaCtIP9kxBigHGjO1J65OmUNtROU9IF3HRixAzmBjCfWI02uvudZVYX5U+90VwzTsNnGllFamm+tmlLo106RRDFMKPsH5uPniqB+o5CHRwAqIZOo19S+OrP3ddO+a7FzHpFQpb/SG54cOC5h52+eBjQ0JnmDghwcTaOXNTUEJjW8XXDkMOu9f5qOdqTg1I+K7PbEPsXqwliKJm4NS5eJ4GM8Z3qLzbCwjzFBylyhdHsKAwxFx0q0hcglpMkc5g+Kjwd1+dUDWzOjZCEdbWJwPlvuiM5A5zf/5I33d89tKR0LlfaXAq6jE8aJ8ImnNfabdCEtRaRY0fWtLEVKQ/nY+pFZbej+OQF7xZYKGP4C9+TIs4XX//8U6A5ZlqEmdiDL2NgqhAkv8tdHVVSmbWt6UD1tu6bsWoX+WUb5zJ3qAfwK6ffmUAmv9Km/OKlhbpZQazdCkYtqqjzqG6hoZy+sOj0srpFrI9KCPcZ7xf7PuoM/iMhA1ujjgHnHYXywM24O056tejsxOjG7cGp9UPJ833bORO+y5XL9n6DJ13SE+YuPqHAr/ Kslz4+9I qi05ZZUni1FVnR9ZOgRwCMxEO0ICINLXK6GhRVaXdLuuYawvHMA7SVTSZBsrw7czoUMIQaHtBVz/AsKZvZi6hxIKdt7FrN21dS6vrbe6Eque1/U3jk0KSuq41zwMR6zDQk2BbhevwAx+pkUsmGKyv1/80zxLRF0ZXWrfwJElUfiG2qfXsno+f/NA7w2YWFTK3aPXhbmgVfK/0VKNUWaMFpR6u22nWbH8BKioW2Mi0mSfWo78cxyAeqW6hpaCjAgmQRge507ECnXEz0KhU2eoEq8nnvoECIXiOMPcewvBzH6BGLBVmxUk+UA5/Tmek/wI4ETQXjazBs6pAZuP2BB+SEbrsalnpDCt5OSWwpV7K5dpVWhUHtzwixj/D8hpCdx4SUoPNtuuU0p5HB/ZdLpLIlbyj+g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: FS_PRE_ACCESS or FS_PRE_MODIFY will be generated on page fault depending on the faulting method. This pre-content event is meant to be used by hierarchical storage managers that want to fill in the file content on first read access. Export a simple helper that file systems that have their own ->fault() will use, and have a more complicated helper to be do fancy things with in filemap_fault. Signed-off-by: Josef Bacik --- include/linux/mm.h | 1 + mm/filemap.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 61fff5d34ed5..bce9e2f5dfa4 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3405,6 +3405,7 @@ extern vm_fault_t filemap_fault(struct vm_fault *vmf); extern vm_fault_t filemap_map_pages(struct vm_fault *vmf, pgoff_t start_pgoff, pgoff_t end_pgoff); extern vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf); +extern vm_fault_t filemap_fsnotify_fault(struct vm_fault *vmf); extern unsigned long stack_guard_gap; /* Generic expand stack which grows the stack according to GROWS{UP,DOWN} */ diff --git a/mm/filemap.c b/mm/filemap.c index fc36a00fa014..aa3c92d605b4 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include "internal.h" @@ -3287,6 +3288,52 @@ static vm_fault_t filemap_fault_recheck_pte_none(struct vm_fault *vmf) return ret; } +/** + * filemap_fsnotify_fault - maybe emit a pre-content event. + * @vmf: struct vm_fault containing details of the fault. + * @folio: the folio we're faulting in. + * + * If we have a pre-content watch on this file we will emit an event for this + * range. If we return anything the fault caller should return immediately, we + * will return VM_FAULT_RETRY if we had to emit an event, which will trigger the + * fault again and then the fault handler will run the second time through. + * + * This is meant to be called with the folio that we will be filling in to make + * sure the event is emitted for the correct range. + * + * Return: a bitwise-OR of %VM_FAULT_ codes, 0 if nothing happened. + */ +vm_fault_t filemap_fsnotify_fault(struct vm_fault *vmf) +{ + struct file *fpin = NULL; + int mask = (vmf->flags & FAULT_FLAG_WRITE) ? MAY_WRITE : MAY_ACCESS; + loff_t pos = vmf->pgoff >> PAGE_SHIFT; + size_t count = PAGE_SIZE; + vm_fault_t ret; + + /* + * We already did this and now we're retrying with everything locked, + * don't emit the event and continue. + */ + if (vmf->flags & FAULT_FLAG_TRIED) + return 0; + + /* No watches, we're done. */ + if (!fsnotify_file_has_pre_content_watches(vmf->vma->vm_file)) + return 0; + + fpin = maybe_unlock_mmap_for_io(vmf, fpin); + if (!fpin) + return VM_FAULT_SIGBUS; + + ret = fsnotify_file_area_perm(fpin, mask, &pos, count); + fput(fpin); + if (ret) + return VM_FAULT_SIGBUS; + return VM_FAULT_RETRY; +} +EXPORT_SYMBOL_GPL(filemap_fsnotify_fault); + /** * filemap_fault - read in file data for page fault handling * @vmf: struct vm_fault containing details of the fault @@ -3390,6 +3437,37 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) * or because readahead was otherwise unable to retrieve it. */ if (unlikely(!folio_test_uptodate(folio))) { + /* + * If this is a precontent file we have can now emit an event to + * try and populate the folio. + */ + if (!(vmf->flags & FAULT_FLAG_TRIED) && + fsnotify_file_has_pre_content_watches(file)) { + loff_t pos = folio_pos(folio); + size_t count = folio_size(folio); + + /* We're NOWAIT, we have to retry. */ + if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT) { + folio_unlock(folio); + goto out_retry; + } + + if (mapping_locked) + filemap_invalidate_unlock_shared(mapping); + mapping_locked = false; + + folio_unlock(folio); + fpin = maybe_unlock_mmap_for_io(vmf, fpin); + if (!fpin) + goto out_retry; + + error = fsnotify_file_area_perm(fpin, MAY_ACCESS, &pos, + count); + if (error) + ret = VM_FAULT_SIGBUS; + goto out_retry; + } + /* * If the invalidate lock is not held, the folio was in cache * and uptodate and now it is not. Strange but possible since we From patchwork Mon Nov 11 20:18:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E224ED3ABF5 for ; Mon, 11 Nov 2024 20:19:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E0D26B00A7; Mon, 11 Nov 2024 15:19:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 88E9C6B00A8; Mon, 11 Nov 2024 15:19:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 709756B00A9; Mon, 11 Nov 2024 15:19:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 497DF6B00A7 for ; Mon, 11 Nov 2024 15:19:38 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 000FA121A93 for ; Mon, 11 Nov 2024 20:19:37 +0000 (UTC) X-FDA: 82774928880.11.FDB4E10 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) by imf26.hostedemail.com (Postfix) with ESMTP id 47608140024 for ; Mon, 11 Nov 2024 20:19:05 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b="D54r+mM/"; spf=none (imf26.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.45) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356184; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=K354FbH7N36y1HXaBsHf/k0mJrRSZmAsPpq48Ppw2zw=; b=lVbNEZpDTHeELNShgXggtSEcdUQMRcEXUPwI1XItPaVmqxT5sNMQAsqSj0HKiHzbi70icX STO3sBRXy+RYeYwuAMou6pUb0fo949mtpvTksu5XHnyllLdNT4kVABxRmgOzhhoPIFqoyy FaiLfEZ3L/MR++QaGemls91uEZ3TD58= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b="D54r+mM/"; spf=none (imf26.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.45) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356184; a=rsa-sha256; cv=none; b=Dss/5bxCxWdRjX8LVeDM1X4esnxgAelYhh5XW6AYeD2c07EoXIp6GFU0ZIq1MkiuIpqcBZ USth5sKBtGoDi1XC5XXnYZw6re22MC4WBKkcHKmRwmSH6aVp8k/DDK3RnFwwTyBsyvXDCy 7cAddUTaEcvB/HWRSwHOQ3DWDJL2xwg= Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-6cc03b649f2so31868486d6.3 for ; Mon, 11 Nov 2024 12:19:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356375; x=1731961175; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=K354FbH7N36y1HXaBsHf/k0mJrRSZmAsPpq48Ppw2zw=; b=D54r+mM/WwQpN2eff8wNcQlgAaIJ0oql2tg9imSpxcnx28NRVpgrmA0noQKHDi25v9 UURLT6SQTmi4IEHkfm1RVxSuzMur1461K7lFP25rCeEi/zBiKSjEQkK19r0TfteMD82X MK3B6Ja6BtF9BJvyTz9rxzWgztUyGshZ4RbnO/p/b5KqfGaADEDvhF1QLRqGLVUDlrgD QzRMz2Ejt2kmXU1L/UMUM9OnLhYufA/quXApg72A9q28bn1FnoNsuWcanSEerzHxdQHW 1HCgIw2ErOKnvCDe+MoVLGqAbMuOuD73p7QvkVQpsZlhzDa+UMdwxus9ifuRATvPFohX ufdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356375; x=1731961175; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K354FbH7N36y1HXaBsHf/k0mJrRSZmAsPpq48Ppw2zw=; b=pf49LlaPVncFhH1CYyQHCzLDnBCBFReJd32aTZaMj8dcERAB9mwujndlqhRbjPri2b 1AWj2ilnpn2XJyiQwWNwqvhynn9UIhaAs+uZvv6BnpQSDlkoM0k6/K3JyE+bcQCFzogU N24Did7pkbgiVLMFANKfV81CBsJIZKA53VbzhGtKSoW4LsiqK9EmZ7OwYKvOBkD1JZVb s5SG7jQZahKL/LScLtAlivq/pJ1Y1avXvZ43nzY52rH/rD1z3Vv4m0olsvv77AN3lDc1 EG0IX1YFEvB0u6vsxKBMLyWmOgoa/u8jEMeHYNYPgRdZf2vVbbDlBFgbxK32iW885p3U FLew== X-Forwarded-Encrypted: i=1; AJvYcCUWH1MmUEA+Y0hd3FfXVDwZ0n0/PFaOMnhQlvN76IIc0MyYHEq7L7LujGovN6tb6hUlSmWqtd4efw==@kvack.org X-Gm-Message-State: AOJu0YzN2bAaLTK1pzLoMuZnSh9FS4oS/8ka1s2gbFuESONdeRpMmI1O 9fAQ3SuY2RZNRw80DXOrQzOt7MjANpCzNaH6Y3du+GTpSAIWLH6f98yIrKmWE9E= X-Google-Smtp-Source: AGHT+IHFQZuz+k/JoyCiK5HhS+saKZlDM8Ru8ImET04ZPdGlwroC1m2336uogkksO+jSLPZVucywhA== X-Received: by 2002:a05:6214:4518:b0:6cb:5273:7265 with SMTP id 6a1803df08f44-6d39e1800c0mr180760506d6.20.1731356375457; Mon, 11 Nov 2024 12:19:35 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3961df2d2sm63665716d6.25.2024.11.11.12.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:34 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 15/17] xfs: add pre-content fsnotify hook for write faults Date: Mon, 11 Nov 2024 15:18:04 -0500 Message-ID: <339a520d48acf1c8dc736460d09fd240201d6e00.1731355931.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 47608140024 X-Stat-Signature: r6z7wa7skwd88bf18qys3353yajfjip8 X-Rspam-User: X-HE-Tag: 1731356345-617756 X-HE-Meta: U2FsdGVkX19ac1SwYMdlBkDGJzJqtGlwDtWt1itzKMJtapYOsaSQiObLDjVhYutl6DkX1lsm4+faVBWYoMifX516eTpakUJdCdfPwfeJQtdrm2Hgh/OAvxv4cjkrujc/UvXm4mEqeG07hNse3dqZdi3pHC30q1bIQxKFETjeEKQr2Us8+797RaU33DF7PxTdHXFwVHICyLMKMBy0viIPzTO/AhNR530QQYHSzKAt6Kb79ZU8ca8/oStAumSFlGOOzX/zHmZvJMm7s4JbtT1XZX2gp8U1AitwUAORrq/iU2J52YVYcKCOBzotzvGaU9qS5+vSCaDT0W22gYDtYUCvykTyY49PIXGnc0lnLXf9aDV653CQ8fhizZUX0a6qvHd6t/d8boPrP+GsvVzoG/yVo5C3xOaSQdA6vUoSl1TO8WS0U51Ge9Ei7eHtjU61Wf3fEzO6LMMuidwGSVoalDj/JUlj3FVA586Xq3cr+mV6rjGmFGW7OEyhdKcjoUW566kxVX5W+GHZebY3o93aVNZa3o0bVi2y9XRA7V705Si0ETt17o9H7wTPC0WU1FYQ9guWbNHtcJVVdtieWOxrMomYztkPA8pN4s7Zx7AuSsA3WXfP8Ko/fZWL+7iuVl8ewRZF2cGollU4xIJw1PYYpfkb2rP00Ei0FYqMA7QiVsLebQu3WXaImtp6m51b5cM2VjrXcHEpESLdrFFMCvHvUvwhn7oY+fj7po1viUbqm0kR5q957yz4EUvUZ08HUuItCGP3IyX5itpaLwWZFv5z/w1Yv5ZnPRPQTpOWuLSL7zcnU8HzlYHFJ6UfrjuHn6n6zWJ2sFTdWeV9Z5ASSSLBZAlokqpX8edBKUQO784aEWcm8zkxKLknng+ZWKhXYlbmTEt2XPzuEaeC+ig+KG1RPeVZz9G1n/RxPY494oXpIBpCfuWKh/8tqAaWowiffImlPInV5OWXULReyYoSysb/Mjf OZNSM6oM o8AVL6E8BO3PDxEB6e3B9OmEZU0BT2phha9ljq6f1QkVkZu9A5UDKM3P4zsEPo5ULoLK08ig73CX8SYM04yuH2KlFdfYeASY+t1ZWkLFsWEw5NUX9Cx+sSXvN8SXPL+/z1jKJ4aExjfWDRH5AKPtAjMNWmzQks6m/BpXBYCMNgLmbPmpHZ5npR7ItxfD6qNzY5ta/7a5cCSVkdmzvz/dE+t/Tm0GX2gCApapF/jzU8G+1kGy4HdEYuR9O8tF6s1SArDfQhSH6KjvIehUh4uxkTOjX0aF/KeT3GTUymFe0fEo1UURrIBLb9Jo/7RxlpE8FZtmPfZ18AP8ekhaDo78osMtQYLgQFNagl418ODEVC+Bjl9mMT6D5VF7cZA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: xfs has it's own handling for write faults, so we need to add the pre-content fsnotify hook for this case. Reads go through filemap_fault so they're handled properly there. Signed-off-by: Josef Bacik --- fs/xfs/xfs_file.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index b19916b11fd5..d1966f996c77 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1442,6 +1442,10 @@ xfs_write_fault( unsigned int lock_mode = XFS_MMAPLOCK_SHARED; vm_fault_t ret; + ret = filemap_fsnotify_fault(vmf); + if (unlikely(ret)) + return ret; + sb_start_pagefault(inode->i_sb); file_update_time(vmf->vma->vm_file); From patchwork Mon Nov 11 20:18:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871234 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9386D3ABF5 for ; Mon, 11 Nov 2024 20:19:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F5656B00A8; Mon, 11 Nov 2024 15:19:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 77CAC6B00A9; Mon, 11 Nov 2024 15:19:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D0266B00AA; Mon, 11 Nov 2024 15:19:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2D6346B00A8 for ; Mon, 11 Nov 2024 15:19:40 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E5DAA140BBB for ; Mon, 11 Nov 2024 20:19:39 +0000 (UTC) X-FDA: 82774929300.28.0092F4C Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf26.hostedemail.com (Postfix) with ESMTP id EFB43140010 for ; Mon, 11 Nov 2024 20:19:06 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=cyRfScMC; spf=none (imf26.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.170) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356324; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qkyyLOcMapxd8eZps50M2cPjgtuAOvBDRyUA+1LsM90=; b=uxs08Fw0SQ+vGFP8GfMu7BdhNzuRc42zgIQcRp6ZxmHKAhBzpexAgRw9u8PQ8C2m7IzLuN ZjzEBPi4t73wDG/XB9RyXrpawC8ANCnhoY4VTIymtHMOKZoNVFSqOyC86r0IuEpLyB0ebE dgIkJ8DHUcXchQr0wcJCFrpop6hR2B8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356324; a=rsa-sha256; cv=none; b=8lOwsIU3/hpk8LmWPFnbJ5X2MOKvGWU1S0UrlGYFXC7qWX9n1GBahhD8TSEKvd7jcwwapv 1jI5Nf94vFmlgw1fB3+fiPKnouioj/kWTF/l/57/9cfRC8K2JNwJ6krySyWPUaubgKwhbP 1YdJDdeS3w7z5ZFumlYvRt+WmvrZ+6o= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=cyRfScMC; spf=none (imf26.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.222.170) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7b1434b00a2so388524085a.0 for ; Mon, 11 Nov 2024 12:19:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356377; x=1731961177; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=qkyyLOcMapxd8eZps50M2cPjgtuAOvBDRyUA+1LsM90=; b=cyRfScMCpAkeTeL/JkmpJkevrTfgUznt8o4N8+N6ekk4GOBQMipgM0OSOZ1kH8Tju9 FNitxd701Age6AZm+n6/Ut/mzHQ/05nTjjbMMA9TMTnuoJCT3Lf1gb1ZLg2c+p88gDgO 4+9+53Wn4RIK8OD5WvfmaTMn45qIgXc2+UtIIffkeBRh+TjBBU1Oik4Moxp6Z/AkMmC0 gZVhwHV3VSDC/TrhZWnjaYfnqcsaChuGAs3WdXroeyZJBfnvAG8BFR9Sx9Z7apImPgeA apoElSndyF3WXAbCIgwsUEsRcP8pVJUv9Tl1G0FSALne7kjxtksBSjuvsMvQli4SFdXN Z7XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356377; x=1731961177; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qkyyLOcMapxd8eZps50M2cPjgtuAOvBDRyUA+1LsM90=; b=LcvjVxGJPfB/c5XbmdI223eYbYtu/Vdx5OLxOr8KTgcFcgRfbzP73PChbdni/JP3hA mTIxsRGSEBBx3WP5L3udxINDFJfHvTmZ/sv5oLQjzJBgtjMFxkp8bwwW4eTR/DsGpY05 9XIp4WwR6MWaJbFrSZvemoQFqefLA28BRnJ5zvRPND4iIpKsTi9XDtBe+CojwaANaPDR BgYz9a9a1wzDEuF4p7iGr6dwT9t+WKbTykKXeuT9jo70V1VCjyNce8L6pqcYSFIz6hTQ jwUntNY/MCqoeChLn3dSq5cYizGQDdFrmhZLIL5bnEN+jQ9rolyguEyFNsmToytBjmca RneQ== X-Forwarded-Encrypted: i=1; AJvYcCUH889yzWCqR537DsCf91TgX73MCXnEJlnrFiI22Bxl06lrrRHwlYmNIvQEZhvwPlwu7Xqox7E3Eg==@kvack.org X-Gm-Message-State: AOJu0YxuWVNMfOXXp9HqPNcQaA4sCwyc0FBL2sQKOVlWwbP8PBDEx0FA sq+BhtuDSQUrVsDlRLlo2YqEk6xPSsdVfxZ59e+VthglTIfKJJUhVv+cQmJUyws= X-Google-Smtp-Source: AGHT+IGjGL9g3kFfcH+6V8KAtQzfg7b48XSPpKvHKYOiM22WInprVkhEgNc7K8iBcMmLd7E6fsLBYg== X-Received: by 2002:a05:620a:19a7:b0:7b1:3e41:849f with SMTP id af79cd13be357-7b331eff745mr2211412185a.47.1731356377090; Mon, 11 Nov 2024 12:19:37 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acae57asm525455685a.81.2024.11.11.12.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:36 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 16/17] btrfs: disable defrag on pre-content watched files Date: Mon, 11 Nov 2024 15:18:05 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: u6rqae3ma5696yi3pp4mcx1yd797xxmw X-Rspam-User: X-Rspamd-Queue-Id: EFB43140010 X-Rspamd-Server: rspam02 X-HE-Tag: 1731356346-210507 X-HE-Meta: U2FsdGVkX19Q2UMk8x8CZCuFzi6QJrTKHH3DYNKWOL1zeA5DFkEkhdDyvkq4NYCdpcEEawBwULeq+CJubmNJlhQRCjMvUvcjSaA3c87WTizfE3rIfk0Ekb9CpMe1NwNe2PEwC/Z0SdtOjT+wpTRoqwdXeclQYwa8fbscYJt6zeALPf1pAb+KP8qknnZsenX32f9OYHeGTc3+gfVsbGFL7Ue+YNcP9FLOYi/eGKz6pEAj9lxjqzTKVLsBT7CXlkbtQLt8BJt9wC/s47PrR6VSVgSgoC0AtJg3g+QFNYuYKRvmEX1iauO5+HPvA0iUNTM0U8WCgiF+QcPmjI5oQdjs7dAckKKiepegMoKtQBWpGAS4WaffHR+NxjPhLNTtPczTucLj/0MS28VJVvuyN5+tWc8lG9KP9piZc9KDi9FXEGxKk7kMWvHRd1HlP+sguxurJ2ZsI2tmUSd8PHUV28uh+5UP0A7oTW5C+txoJmTjhg3tC8Q3FYPXfPHkP0YohaABNc/b5uzxEAzwe0Km7cbkX9OT/ZMVkAnictIYD/5h6BU2AiI7Cj/KwBx12QXi+VSglSvCid4a1hwe/9pkbu6ZA4ka0eKN3Lbn8uhBAWX7FOgAmhHpJ7+xPu7T9b974pMDFeK62fTnX2+OaBO24/xMYJXPXgeKtsUPbZQz9EoGzK6nZVw05iqj85cB2gzvvAV7RuYX5vEXqPb1QwsruNmuvYDXX1DzS7rAzLLMgyisjhE3OrrEMdIDl7O7UIyLYjKCsMOzqJO8VBju113EB1ufyLSZXCCU2j/YkJaP0cEcfb3HcDu2tLysVMd/1ayvhvWAA3FA0rQXfZW3faEMJNLAO9vw3xUvvjXBt5Q3FeLdczpT2MLF1w+bNPeWz/DgDUlIZ1b0as85v+P9HF1Lsu3RihOOq48zYvAXfHLHp7gCngutIBDCloViLTZTzywOLl4x6QXjM2SEpaMU8QSoXF4 2mrIwVC+ GOdIsua/gKKeh3c4oEftFOvn20hjdXr++7IcePaCGYtbzedlrCVjWoAERss+LWhoiSgLHG3kr15ek89pHMCDRSwP9t1ovcCQEihLpXZjLlyj/I1KPLxXnCtmeBPATHS1t1MKz5Fd0AbqAW1h5k04iO7/PIOiVnjY+9NMKmRo5uOCeDOsoWPyxNM0P0K/CNVJdQ2TruYk0XAKD6c9LHCW1EZ6O59UfRteLDdRyCfTQb6I9vMGJLJlqHHh7r3pdZ+5bqV1sKDayJoQQyKRUsT5ei2rZzb+XxvrwX0VpiBtbpJ430d9/3H+Bn5Ma/rKYBiVbkL0aK9Klih5bv25ZTquH0TFF+Hj0R+76GVVpBoX/D5tSU84A0WeI9rRdYQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000040, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We queue up inodes to be defrag'ed asynchronously, which means we do not have their original file for readahead. This means that the code to skip readahead on pre-content watched files will not run, and we could potentially read in empty pages. Handle this corner case by disabling defrag on files that are currently being watched for pre-content events. Signed-off-by: Josef Bacik --- fs/btrfs/ioctl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 226c91fe31a7..9b13df1ea729 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2638,6 +2638,15 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) goto out; } + /* + * Don't allow defrag on pre-content watched files, as it could + * populate the page cache with 0's via readahead. + */ + if (fsnotify_file_has_pre_content_watches(file)) { + ret = -EINVAL; + goto out; + } + if (argp) { if (copy_from_user(&range, argp, sizeof(range))) { ret = -EFAULT; From patchwork Mon Nov 11 20:18:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871235 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CF50D3ABF4 for ; Mon, 11 Nov 2024 20:19:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A18406B00A9; Mon, 11 Nov 2024 15:19:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C6606B00AA; Mon, 11 Nov 2024 15:19:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 841666B00AB; Mon, 11 Nov 2024 15:19:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 64C0F6B00A9 for ; Mon, 11 Nov 2024 15:19:42 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 32D8EADE48 for ; Mon, 11 Nov 2024 20:19:42 +0000 (UTC) X-FDA: 82774927704.07.CFAD910 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) by imf19.hostedemail.com (Postfix) with ESMTP id 430FF1A0019 for ; Mon, 11 Nov 2024 20:18:49 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=j4o9Gcci; dmarc=none; spf=none (imf19.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.52) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356293; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9HNnqNRpeXpq6oZz7CLrI+1uWLVA6nBimiK4CaRQWps=; b=lD7Wi+VVEnbwDOMhl+m/cXaxvzfHtP3V6e5WwIoZCyE2VgKiEIOSx6s+RLYhXpXGHsHMPK 9IIuPbudds8fianM516o1G/2HnnR1gIu/V0oelaWrDE/qT1wtFWJh0rOpHxxPtMbN1vcad q+WerNaa+LVdEqt6AFeMgzLcxv6B2N8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=j4o9Gcci; dmarc=none; spf=none (imf19.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.52) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356293; a=rsa-sha256; cv=none; b=rD44eW1pRcR/tgUVnv5lGBEGSt035lFUrErEZDiZrrt74/FAsZCexI5x5D2Lzzv18c4vYm krd2NhCfBi/NrCx0j9qsrlMTKorHkKGv3TfPBQYk4iXTBneLmKbLfL+TfzmVMfmLvXx90A ixN9gVLEB4bU+DkaSSAnJfKws799vKc= Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6d382664fadso33686836d6.2 for ; Mon, 11 Nov 2024 12:19:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356379; x=1731961179; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=9HNnqNRpeXpq6oZz7CLrI+1uWLVA6nBimiK4CaRQWps=; b=j4o9Gcci1Wzm8eKMvcLT8jOiny/6CCCoMd59H2JpT1FaHBQU/t/7pUO67mQEw9bjZ3 fFczkPlxsWHdlrxpBNAVk0MkPgbtaAE1hiHDOzr+c+iqRqPH05WSRHv0ql9A44BxDV98 nXo3pizobSJhkvE5E2N79U/Xza4ZfK4hbqMCvIb/quKTZ4T0Ywk0f53yBG7FTf8/5t/+ OkM+GeR5SbauQIhFuW/Rs+Z36mIwLfHBwjm01DvRlsCPmYmpAN34m20u1dXiYIVFISTk +E032AONrq6F9D0St0EwhzJBYZ8sUyY8PC/rwqGr2uHGGUyozyYFACzmLCNkziIZgKun /ldA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356379; x=1731961179; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9HNnqNRpeXpq6oZz7CLrI+1uWLVA6nBimiK4CaRQWps=; b=gHmAaPa/lIJHlBj7C9orW4rfMw8h//LQeUZ/pgvG5Z25ESrsia+zqYo0fCPTdx/b2U PlHPnWOtrPkZjECYT5+hMRvYgy8sH6w/w3xrw83rwFYm4PL/tkRsrpfS3gd8OsuMj744 Tj2IA03XZnpAE+E1IPQElGv91e2tBqoBsvkN5vvKyN8q2Asyb1t4iqV+3k9YauETrw8j EiJH3Ih9z126USZHyfS3j06IUH6sELJeLD/xp7aKxhUTGWjZUhzlUHsC7o+pI7KWXWiv x8P+76RADH+gAQP7ZvLDUg4btaafy9kdui3wVy4oqnTy4VPRF22WSdxHQqi0v4elKaA5 /Vmw== X-Forwarded-Encrypted: i=1; AJvYcCXX9RU4lBJPWAVDLnBg9pjfb7vEk0zsuo/7gt0FN2hgxGfNHED+aJ4yfXJizLYZF3Awb3bBrRs5ZQ==@kvack.org X-Gm-Message-State: AOJu0Yw+Q3b4G0OUeqEFSLcaetJItuGDL6rRjROLkgiuPviNIMM5MT7/ vP6M/ukqzQ8sOThwubB1Y9mT60CQRkszSx7jzqcd1oK0lbnOmpXuXClh2Dk+FXQ= X-Google-Smtp-Source: AGHT+IEeW5dWNNzP0Q/mSWg08VXdP/QJY4mGTFCLDa3FijIuqEGWFA/DFexUYUDI803eaDEW3J43MQ== X-Received: by 2002:a05:6214:469b:b0:6c3:5a9a:572b with SMTP id 6a1803df08f44-6d3d01cd58emr414996d6.20.1731356379654; Mon, 11 Nov 2024 12:19:39 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d396643141sm63385236d6.126.2024.11.11.12.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:38 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 17/17] fs: enable pre-content events on supported file systems Date: Mon, 11 Nov 2024 15:18:06 -0500 Message-ID: <0618e1fcc426e66545a6680c795423313b7ad8d5.1731355931.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 430FF1A0019 X-Stat-Signature: 5wfqogk6a4ptr3jqaa7gcrh6k7gwi3z6 X-HE-Tag: 1731356329-738141 X-HE-Meta: U2FsdGVkX1/CV/pgblqboImpkG0eyk/VmxpOnuY1aDWiBLVmjmhuocLtLAdw6QT9tFtqPVwhfQBOsxzGQa1N5UfpTDXiRtpoB10cyp228P7rOTWJuQtHH+CDdRCHZvaUAgJLnzlbtebs3m+xoNDZc+nmMkeaoFSU5m82pFWmVpU5rkQZghGWrhlu9sYCM65Y6m4t4aR+3NbZmDuOASWbjAwKrGaRIGqELn32a3vIu2F7H+k+bOTGa4GrWThF7CpnU/skbpY+HV8Tcb78oG+lCBE5zed9m8M9AQMgSgPt0E6Ybfp7ibY8m6QVbCtqrVWtBLGjHPvrAiI+4/Brr2iw8vRaUaKR2q3/l8HximbcxiD5ErH6evX26LqR0iMqshjOlWWSiL0tixwnwJiG8lDbqEm3xs6KvNxiyRbWFl/XQz4OHG5Q08g5o2ub4VJuK73vO4DlXB26dWrYr4aFk15eXE3/tsq0i5pbS2kenxh6L0eg3FeBsVr0DFL5LMYrYPV97pNQBH7wDAzyki+g/do2B8lYZsIbAetBWWEoSFwm1ODYJMnQsHrvW1Lcr4R2bSyuov9j4U0dX4qBWuierzB5fYqAs9KDxwoQt3uGaHOaoM6J0AyZFo9C7q0z1J0uu4TskrKP2NrkmbBxXYmuR/79ffT9cMRgtyy2O44TGc+FS391h70IosxQSqOdqNrAIUkLLseM7BOD6BFCD2xpOksqhH8XkOXmjah1KA71ntOxvvP2hpYxRhaGQ31aoh7+MdPRXXf+U84c3wX40TithScrr/hPvdZMcZBaL2OmKqCFTv4BgucmbQetAKxttP3wprxmWo2b8FnFLsbTd7ms7IWmryUz/NZ4MmOzlIpbBoe2RPdAtSP4pNCSVjmZd49tnixE3IXm+o44LEwPC6YQwPqMtBguqkiwwemUKAdCNZyJ7AaJs6I7RYC1EZhgA19rNTtRxF2aCfPaQCbRFCrntAp U/45f/kI 4aHMjyJ61efkYN419Z91ux0KG73MxdYPk4wlORja3pPWgtdG4Wo7NxquUiy8V1Hejv1HXLEdocZh7OzM2/x+i4yFTey3JTqyoFCeVc4RpKVBmvA5FdEihvEZWz1ZO0NRFTdlwn5cyLpa2YGU8enK98u85zg1vE3+31tDVuzMmh7OBr/S1C8I7TQNJtfKfEoLUxpiosjwpQRDKZcSUhxaLA2bs34glCW1baiZ/qBJVly2QPMgFGH/fugVih9IyFgvRT06HKpNxq/PwY/RekUVn3wbMu+bs1+U+BKzWn8TN0SjIpcEaHi0PqWIAYrsocRKKe8yOf7Es5S89Kmd77bT6n1MAtV3IA6T0OM/ZVR3W4IN/ZF3ub+S9HK7GrA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Now that all the code has been added for pre-content events, and the various file systems that need the page fault hooks for fsnotify have been updated, add SB_I_ALLOW_HSM to the supported file systems. Signed-off-by: Josef Bacik --- fs/btrfs/super.c | 5 +++-- fs/ext4/super.c | 3 +++ fs/xfs/xfs_super.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index c64d07134122..9c3877aee9d4 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -963,7 +963,7 @@ static int btrfs_fill_super(struct super_block *sb, #endif sb->s_xattr = btrfs_xattr_handlers; sb->s_time_gran = 1; - sb->s_iflags |= SB_I_CGROUPWB; + sb->s_iflags |= SB_I_CGROUPWB | SB_I_ALLOW_HSM; err = super_setup_bdi(sb); if (err) { @@ -2191,7 +2191,8 @@ static struct file_system_type btrfs_fs_type = { .init_fs_context = btrfs_init_fs_context, .parameters = btrfs_fs_parameters, .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | + FS_ALLOW_IDMAP, }; MODULE_ALIAS_FS("btrfs"); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 16a4ce704460..733d71dac09e 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5266,6 +5266,9 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) /* i_version is always enabled now */ sb->s_flags |= SB_I_VERSION; + /* HSM events are allowed by default. */ + sb->s_iflags |= SB_I_ALLOW_HSM; + err = ext4_check_feature_compatibility(sb, es, silent); if (err) goto failed_mount; diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index fbb3a1594c0d..b6cd52f2289d 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1713,7 +1713,7 @@ xfs_fs_fill_super( sb->s_time_max = XFS_LEGACY_TIME_MAX; } trace_xfs_inode_timestamp_range(mp, sb->s_time_min, sb->s_time_max); - sb->s_iflags |= SB_I_CGROUPWB; + sb->s_iflags |= SB_I_CGROUPWB | SB_I_ALLOW_HSM; set_posix_acl_flag(sb);