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: 13871258 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D0BE1AAE19 for ; Mon, 11 Nov 2024 20:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356351; cv=none; b=ZuOH/YP0ahrI3dJa2NLEeP1gECihcg4HzbUmYGLe0zNkxfEHJ9enfeCJpR8nXWpOkgipl2xTbSW7OcKH5RcRG4+6JekjxQYrDppXm1LGH2x0FpHgDAC9PFIPR3SIy+w3EMGydRGRygWcxp/Hlnp5O2BD1E3iF13eatfGvzj5G2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356351; c=relaxed/simple; bh=vjD4OwpRem9TPu2ocewh7lTIgYYZ3zDQs0yfGPZF/n0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=emn9Q+YxgqvAmcchDm31oVBXBppYJQx/CLaJmzW2qZQMIuN5/BAfLXw4Aw6gnebXIdRlKrKeRf+d7gOWUXcwMPRL1+rNVcI7PucCyXJCRD3g9jDZJdD10LKT9ZslpLoezj+kMymXWYAolIDe3oaQOOh6AVRI0uvZY/IDSHitX+Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=FF61wmJC; arc=none smtp.client-ip=209.85.160.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="FF61wmJC" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-46090640f0cso40333241cf.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=vger.kernel.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=FF61wmJCAs5sW+Ltc6hHnxfHNfLuSS7EMPDwSNYovAe+4O30IGEFLbvgSQ/1+G/bgT 2CUt9Jkw09SkKvfwSpHaOBCFYUqdV3/wPQwVSya9LUhSFMhlnaEI5rgB0IU2n/5HBZm9 7Mq22KkcPAUM+hV2NtsjGK/6LBNe4SvVco9EbJ/DBG8z3CF6HXmP2GRtUSeUmBH5qduJ 67VrcBL2bmAPVgsy1gneIE0pjP7rB86Whn5T5NlV+y56u5IZziA9h6y3tufOAtyd7RQr Q7/Cvq/WTHVjlXcFPbSYPqELsIv6MMN63gqUPJunZVa9NLa0lj9i3y+M96JZy5jDn3Ir HzAw== 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=V1t308qEMO4OC83+uyDLjFVL04NsG/HVrtbXjxe7ozzt/HCbtkou631fjP968YhnoN pSULXpV1qSQozYGjcNRduQfDpdz9jojbbeaUu3hFZU804+T0wuHfwo6efmZyFWM7AA+9 0swS27pzMSSZ/cqiHjSdqHaTXp0SS07DgAA844JCVPPJX+pZafOXfXBGTsSdrgStvwKb pWymQEOTIKgGi+xXsjBJsGllcTwWAxKNvQgYCsJoo9HUbG5ZdNz96HQRqbfxIKEHDc/b bkfwF6X83mvSc8jW1/W7YkcEcp6LZbClWzFPeYGHxyG+rG1ddtfoZytHL/E6Lj4LYkSJ RUlQ== X-Forwarded-Encrypted: i=1; AJvYcCWXciExe1l/wdICWtH0Cbu4JV+Y3rqbk4+83VApoerABHEOWnGeWtCGUJlKv+O0jTpKPCqkbLE/iz6qiA==@vger.kernel.org X-Gm-Message-State: AOJu0YzmVFm3i8RUT8iXVrSCkc7LZaCEQ3MXNl1iuehbCFDAbrC2LGS9 ejdfzxmswc/mpdDuH8/l7sDJofhWp/bJgXBsacCpx3H74l6puQs5/nkjN8Gos2s= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871259 Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18F6E1AFB35 for ; Mon, 11 Nov 2024 20:19:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356352; cv=none; b=gPAcS3S+8yqlp+F498ugZRyyJC1nXzcYXEjoiCP6bREoPxk0th7ld0N0lqL61xx1IamCsHS304YNfGHiafvifZUWoxy6fh/nIzvi+LXZkKVqgdQ824VkPb4cjsbdgp64bSMJixeRCIM1gi8Z92q4zNI0b5lFIKCHNBWtSTFwR8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356352; c=relaxed/simple; bh=Yq6xhWaRCpSl+5XXK6zGiPVmtIxpSCGzuPRG5Myp0n0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N5Jz17QTymcgCeBvJBREsimMaDIi46Y0ItNE2V49FC5/+uV4NkPfvligFcjE2mJyLAKrM2JXYutiyfdUdbt0gmfbWLRwVMbuElMg/1e0IqVW4/V/buVqmzxMLdEWMvl/BxR1hbeDkl8pG/a/nxQp7In0xZm9Dix0kDkKqux46uk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=pkHVyBmK; arc=none smtp.client-ip=209.85.210.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="pkHVyBmK" Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-71817c40110so2892607a34.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=vger.kernel.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=pkHVyBmKyihtWfY5VNku/ohy2lUhNLzwjZ9p2ytaO9NOHXtb6rlsUwzg6+x8jtm4lP PhfxClfxk/tRo0+YjaAUYuLfO6f4THzSV0/UUCunrOKdF4jTUS3rcrCvJ9UA57TTLbBR otJWdyRobKJmXBZQVJq84/lLi7zJu21YmvMwOfK1g88ja1bZpU02bpzKDdvs5KSwAEea S6TXDOngvmeBKvmLq/4CLBqRSP/WeTFg0sZNxcrz4Q4kbJpVJOlbcoDCL47t2A+dR94j i1M4UotJNIr6Tf/JOsuNuoybIXoPnc3xFl27iirC4txk7e17xpocHjmu9PPS1XZpY/24 h9PQ== 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=DxWKt3mv/5Rcx+qqlTEbcD1LWVJ+ZWs1YO54+gfyMmz9BVeVIw6o4w/9/YfGG5MBxS aSblaYJA/32mbZcWVK0Txl4SEWeaUSLCGNpGfQ4MU0Mq+7W+6SkVUFzrQbXRvivDFd2u ph7mx5fI4n10ZUJVca7QzkGU8kwoa5GYkAHzSs1tQV02ff+IIuhaMibNANxWBL0q43/X E4yrdVtRfPyVypesMOZCrSfO1Go+8Gjl5RmPrDnCleST2mbsdXlIkmOgNXnDfGj4w6Dz pesir6cZuuueQhb8VM+vQ8LHD5dSv1dS+PT3saSCv7d7Bd9OtuB5fKay8kp10dXRqpAx PJuw== X-Forwarded-Encrypted: i=1; AJvYcCWYNWInG7ed4UlE1Rf/yfVuFbbuuDXWKCR616Jx/KPoNYN5xOokoWK+I3nyOXNyHHWbyJtM1zoAhR1gfA==@vger.kernel.org X-Gm-Message-State: AOJu0Yyk/GYwUUhqNDYxePi6TYeUKn2GFl1vGAaoqD9FTJ8l1iDiTm5A wvsJtbIn5dtuPTX/KEqbhpFP95c9ZXIpEo3gW3K6qqPQzGuuxkeQtuprdaSnmAw= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871260 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 359621BC9E9 for ; Mon, 11 Nov 2024 20:19:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356354; cv=none; b=naVo81f2m2HijyeE3jayg7PFIiNMqXPG19qcbZ2o+oXSYJkUTAba3m/yKbaSgOuNiQoHf5SkwAgmmu6Qt8dg7rMKaBsBEWw78w+SC141RX5Wn1+M7mPdIV7HZITtlad1vIZ0RqUwHwmBE6Qq49VEy06rY/I7t85SwN3sb9NfjpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356354; c=relaxed/simple; bh=u0ZPC8RBKGOY//W0g1jPdakQ+vbKZNphZ2gNuJs6b/U=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R4Kt89qi5J0KaI7QIs5qrtzTtenAMEVScZs8k+Nx+tUQTd21kBNwKsJXc0TMCoa1pr4KdZLJnTmRiZ9r8oQGKmtEyjnwyFapAc0M1E0hnZUrzsAXE6e5j7aini3OnrSrPc5QNgYYUxJbCvgJEH5Z94vFAQw9RFYcmAkE/MjZGYQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=uMBxQLaQ; arc=none smtp.client-ip=209.85.160.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="uMBxQLaQ" Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-46089a6849bso34658831cf.3 for ; Mon, 11 Nov 2024 12:19:13 -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=vger.kernel.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=uMBxQLaQdBTOkogBm81DGliBM20P6mhlC40/Usb1CUb5B86iwNU51MU+HxprOxDz9U yIoBkFy49ZDZqQE28wzwXn25ItTuJZACsCK+rx5Y/PLhtVPHO/A2Nx5lAobzJaSgqvC6 6FFBrz7RfEDMdaeTLP65qrNn4X01xPP5XG/f1hXvofBDzFdmRs5ukFR24JLQ5xUmJcB2 j49GfoP0zMir8eAsUtn4lcmP0LwUVkZWSfFTw1VcJFWu6TZOC3AvrhKTyfzLcg0oXfAt 5CNAgeh5llTo82f2OBja2AiB3ir933Ufd3DFqOPWkua7ph112xYzdcvsgvQ9jHA/tlr4 Scww== 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=vnl2ggAjrqj1+5GXEafd0XYhylAPJ8yzm50Ewvb1IkfZXD9j3Ul39L1LrDIbEEuw6B juuqmnnDRAd7U0BD0c18G5XLavZEycyrwIRArg3tPRlysiPcnmxjVYUB/AAK/MVMR91j N9OZAGWKQUvBuARSrZQqfRuxlNQFB78y22VDJCcYKmVvKc25oFURJW9KwZvFDELTyyqz A4CLFfDOyrpia4G7jv1olXT4OkoF3hT3TvIW1ibh0hfCF9oELruJqtJ6qupxPzLNfujt 31k3PWlyZheac8N7U5N2/VMjmZG8g1SVOWJ2QJx/I1SurjQrSQWvw8cdSgumYopUcsIZ 5TsQ== X-Forwarded-Encrypted: i=1; AJvYcCW5deG98nXTi3EF6VXrSWdZd5AgxAa+pxTKmwyVoutyOh2oNf+TVHNketB6tM5aCzC3o9y0V4TZNJnnEA==@vger.kernel.org X-Gm-Message-State: AOJu0YyGYNd52aefreKXqLYPVlxs6r3O193KaGeaRFx1bpcDAF7jENDw Q+JIY2o6PALIzBAFtKhJyLnlfAgxnj3HH38jzOcwUvqCjuQc2QeFCQQMSc5j0wI= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871261 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B21C81BD00C for ; Mon, 11 Nov 2024 20:19:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356357; cv=none; b=R3BaX1u9xpP3KLtk/B2/phppdMuT1wOzNaDApWj0VkPGUtdpv7NiSJ12pDbw82fIEGoBNdZEdhoUVbhYOmiwOo1D5gwhuRunexlGVbG1rcXyC/0y+Nc+vABuf/zIVDFyLgPR0WGWrQP81vsrb0QxOSJe1T7KLoWTOrEbrAOg9NY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356357; c=relaxed/simple; bh=chNlpW8iwOBtx41TfUvK9qRboNDjBS2Zk4KLK/B4wDA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e1daBui51DFLNpLHRShIqIqvlOsFtrr7GTFNZhvCD8uGO7IvH9dKgYPz8yG6X67Eky4PNqad5ZwLnvmWvXOdeq1aGAqqPRbt84gTRpnYGk+MWOLdphQl8GGiOvzYSaRlwHyixG3/NFTCyIC+ugIsnwudMN2KrRrME15psMOrRM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=D0eBahia; arc=none smtp.client-ip=209.85.160.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="D0eBahia" Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-46101120e70so34745551cf.1 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=vger.kernel.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=D0eBahiaNze8gynsv3WXmW7FCyBuC25FWljtVFm9aMz9832Rx1lLhwAQPjufViymc6 4ldQ75YNH/915rkDrSFrvUAmAeIeHlUzJ0XCK/XC0G6apOKvAeVEOeGau240uOrME3Fn bPum+q6Tlck1qlGArPHHk5qiFm+DwKDjS8QprlbU7KU+lTxGvjZJqknTLJn/B6Etwsuj nAycA1lNIc9AKEmiOTGbRzRjnyHmTXag/iZQisR98x8l7CRgZ+VyuZWDH4CP3VSBc2Gt rU8HuxAdMIzstoTrpW0nFpFHVfCMHBhSlBivVR/PznUXOMsqWxLHoLpU5Kr6GGHCJyqg LY4Q== 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=jgHbZpLizvfSSw0YhH8Zqy0U+SMUzq/DtIC9WYnXXLmkf+FD5AoSptJTiYmGbnUpaV 8V5xyHVf9yzrgxT6n+015NHk6V1oWL9lyzBtM+VOjFjW/MUs94hXcR8DIN8udcYtT45H d4XGsiQs8M1zELmO5QGegFbGFKRq1H5wZuFreSJNl+E8bnR92halSUTwF1N3IMe6SxUT 5ilcqKrUc1iYj722MYJr2CO85UsmiozHuDec52ZhAvvoSE+uuSgFvvPcCmaIdhaoRlZq S05bc9+xrzDaR5KD2v3eSf+PwFhOO4ugfKkjQM4tK88Kkoey8miDf0H+BWvmDE4J8wCx LMhA== X-Forwarded-Encrypted: i=1; AJvYcCWtXDLSfsLNB/1M/1V0WjaPTVMhOkzhJEkmjHCCvnLzkF3MtVsYmvbETLPJlZvFVTdTjf8GlqiWxfIeFw==@vger.kernel.org X-Gm-Message-State: AOJu0YxbgoVdpaGZpgN6k8e3vEJfYuNLKyTYnVGYPrtT/eKtMpItuPoI yA1LCRqdh+DEbrs2lzpNtAoU/tQ42E5Joev3apMHmeyB5k4J/HG67uKyT2OHRBM= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871262 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B51C1BD501 for ; Mon, 11 Nov 2024 20:19:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356358; cv=none; b=RYuI7qiLTTx6D2vsUOBCMf+7TiJE6BHRmse3SWzCg3V+Q76OuBuT2H/uaTBl+gTw2g/AWbiRD6nrBXZWgDXoAGRrAsJu+MiOpf2QPmWyvzlAdb0THsKFQYgoxkXLzKs3ScGZbGu3u9oOLbj8zB9gy2JZfCUxuOo/oJZxm/5pcKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356358; c=relaxed/simple; bh=q5/g4B2rBSTWJB0ECjWykcuamrrImvqQ3LDdFlghI3w=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gv6gi3uGuYKrdclf9VHGqvxQyPn6ej4v7JYt+JSZFVo1ema+xBwGeuLOPFLdyjmhFEP83ZzJiInBvuHdGcXczRj0EyYMyAYYDljkeEmdXhSjNscWnEYGhtdXE3SbIi+ic1Fv+CwCvgKf2eJyh5PTVw4gyzmS/hzp8+k0QHl1e4E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=Br2GaQw8; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="Br2GaQw8" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7b157c9ad12so340574885a.1 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=vger.kernel.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=Br2GaQw8waqdInR0OdL1v01YvC/AT9ozAFYE5R0qrRImtTsIikcVxVt0AyfQossGhM rMFztzhKoAnNJ6aSBgQ1YKwRyn9yBBs9GlflIQRb3Sei4nAePX6Szx++LA0ZKZraK69Y OjsyjXOefWgu2ZDhQY7hkRCShLNXqNpdv6pRnmrc5spVp5mq9+rI0F9TvV5zwJVmdr3x Vpco+eKmxlT8jR+L95eK6YTlKMzZy8/MEeIKtbyS89KWAqvOBaBYGCo7F5DVNMeYIZwh +sxvUKW02HRZwxwB01K0BKjvhUlHByFn6fMZTCOwDoHOMTM+bDvhX7Uv0FJa7oyc+/// 2xfA== 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=p2ycyh4hNsZHQAk7owp/qaIATrK7VEOM1hS1Sf0/Q5hj9imjeKh1hxKMlWmnI0Xr73 uibsiigS1KKpu2NnuJMaDRtXyaBC715sYRdqU3UHQ7+uQvDFGkcu4RCgD44evR3guB37 uKfLeCRWsqO3C03EwnM8MfElvM264EwQJRQw56DkXNmCjTXR/iAcXy7JSfM387QkFWFh wobATInxEVsevOLS4IsHpN93MWj/7J8kZE4YpOGvigIuqpoU/Gnq25YKntHKWonz15RG DVFkyJLo/16ZFpZLmVt9hnS2SwK6Zhu7l/OaIz1KJH9FFxjF+IBuWWulnwCmr4H6I1vq Hmow== X-Forwarded-Encrypted: i=1; AJvYcCV3qehiLW58UDZJi15ZEuFmm/NrqkPzNt2qfSU6RQYVwLnyDMcTRNDYqSfgYabmrNd98I7mWM8GYhKODA==@vger.kernel.org X-Gm-Message-State: AOJu0YwKO2ufX2p6OHkO2h3LX8HNEb+D5bO1T7WDHSbBBlF6LY2aFKss XP0rMNwwvwlQ5JPxWwY165GbhzpZ51dB7eQU5f4ILaixSAhtzFxdLb5FO0qW16g= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871263 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 247A61BD9FC for ; Mon, 11 Nov 2024 20:19:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356360; cv=none; b=SLyLwczqMVqV3YezCnT4nbPrLHB759g8NSAzaviN0cyK/VPXRysXnzzX0dQ5yNAp/lM11OgVIkSbV/CuWYw4NZ1M4VlgbUqjBQtdZ39ePXFNER6hNioWIAu9fLZpT6Uj1EBlXFvWL7Wbg4uxtPYPflN6RcHv6LCk+6ZeBjl8JAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356360; c=relaxed/simple; bh=TmnKu6gi+WKKtr7qPjxxquG53LAeVZdzHoqpUlbbS2k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rKOpnHeJVHNHO6uOD2ZK6M7qlX36+iq2FKF8g6miIHCvdnglXsKjjVY6+BFxvRojvZNNUsggABRi8DuP9HIWc87ds281Xj/2HwCj0vlNJflyMQsKQoOHfCQeoSTx2V6vMgW2AExFMMIMyBOhyiqHjQtnuEl4VgtjnK/n3GQObts= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=EjWQBVgF; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="EjWQBVgF" Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-4609d8874b1so39391041cf.3 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=vger.kernel.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=EjWQBVgF7zw+qFqexL/S7ovocSsG7/9psnTNs7bun9l1TWbRKUkg38WT4N1hegsn0P p7szfHJNSsndulSd8IC9d2LpgjA8yU5y77ziKwB7Du04A7ggNFtp5daWGC1O56JsJ0o6 60x20h231kIJDinBm1Qq83pAkup2RvZyLqvuqVce7qBnLNjycdGxUl2EBBOtgIYI2R2r 6MrS1ZLoJh3mdwqkkf7dhm2s1Pr8VN7Bkd71J4jG7q7EaoWbB3l6eJXGmvnDomXSKHku yEPCDc6+RpRYqc1OK/15dQvL/GK7ZYPcSb+QF2GwoQsBOo+u+kj5O3ctLyZmbB6SA/Ze B3VQ== 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=vtGMM56vILHfqBPuPFDQGQIWHZWtJbUnZEBfEOchCQ0cfKgMlJWqPkp1HJhNagXImT uVXjdo1SBJZ2LtP6r9If+fvV+r7E1qveFe7ufeeqfvFo1yZo68jNdx9PTMM5OXCFiyPl K8VVpe8YiK+RkB5yA7pLdOWtAQI5daPwSPevTrhPTdh5DfNjM5FAe2sso9VFz6BvObMR MVwTkNJS4kbS0dGyd8pkaJku4RGlIDQzd59CLaoTnh3g2a1mwvR/NPg2mnUNYdnuzp8q zj9oIA701YSdQNUCBRRZqTA2aEyyPGJgroY5/aOkgI+LcG6NbRrjwlRzMo0dHm6g0dZm XIxg== X-Forwarded-Encrypted: i=1; AJvYcCUgK3CLtx0mx8ZWuXGKnRAnhNJdAOVn2qCAeugsDuuQE4jaflpwzfUwhYUoWv7d/DS0ZYcy7l2gTN0LHQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yx1INgfiIn7GSV7dSI4GXiGOB4avgUlun9kQfBtEfwbxqTIGQF9 pvACm/Z6nfrBLMZLMcK2TAoIcoME/pwNCR9ttNDW1PTJy2ZKkLp0DQqEkqXoR6o= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871264 Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 775281BD9D4 for ; Mon, 11 Nov 2024 20:19:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356363; cv=none; b=JhHGfRxQaq2Zoig8WSKgvnRxkQmOtpAfCU2tGKJ/ihial/QyK20lvGdJWQy7wV6yg67aPBYb1xRIl9rUOR47jx2bl2KjVg3MM9wULEZHdLSp63Vv/miNAYfMqPsv2Z/YLOHkGGQwR79FkVqkxAV6KIkO6WIJuxC593EP9MBq8Vg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356363; c=relaxed/simple; bh=Oq5L9ja3IMF4doQvebDweKCtXLQGr/nS40VPvwfrn/Y=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lQAKesrntZr9bZZjDL5n2/JZZReTMvTn6Ks2VCQiU/B/KRkVyv1fIxiHxEIQXTfE5a8X1yRKXBFaMcg78UiAcPErjMzGbw/EIkUKNCfGupF6ZLxlOQo9F7D3Bkj+doI/cqU2MRj7mX7QFeI23sQZFUzwsTVb6yWoW62vIFfKfXc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=LrRfVU1R; arc=none smtp.client-ip=209.85.167.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="LrRfVU1R" Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3e60f6ea262so2283757b6e.1 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=vger.kernel.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=LrRfVU1RcDXxsSzvUORvas3nCPwBCE+myjYCFjRCd/EhPGiryTYmn8CNbZq80JW+ZW /iKOFToqNE8TxBCgtYf9QpLWAdcg1ig0Tt7N8uzvWKsgKmlEFz437JnZenKqapCbIpoE 1/TZgUPMZzt3e3aOTwOtWtZ5WW5h0ngRl1pKu8su8vpo3eZWuwKYwiaOo6/TFLGeA2lI 6SQTdj0ziAZ27k4VkhpqsGsdw6zsa8rmD8HEnkWDtRwlHVEeUqufzAK1nzsYyZwXIcb4 YyjJrALB5soyd7YuFuqC3Sb2KMWaSybOmSrf9aFJIGztkrg5XGKf1C/H9BZNaaJsUE8V s7cg== 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=u2s/5pblHN7I3KLn96D7YMqInnv4NPD4KAsXcaraqnPaQ1GOO75jtJ5zaodfxzT80e 9DzN4SemUSVrNQ2aZr1tg+7iFj7meeZE7Hmh1ZLOOqY21sDTTMwuPDhJrBtqj6hQaMHK H2MENn7XQvoQMsZ8M0oLK60NNKphdtbPZ1BrsrqrytIRnVJoVP8ywMCxS4yrCCfmG3lP clFPQhm7xLWb2jG97KZ1FfMENoRK/kC5b8TX5lojmHIC+UUfnn3CgPNKij8xwFoBo97F fgmsZuHLFAjGEFDqJ3Y3qZ3PwqerBiujVXXeUZwsZ3jYRVa+YT1V+WUCLtzEmwZJR3Q3 5rmQ== X-Forwarded-Encrypted: i=1; AJvYcCVrS+SLdLliXSZMmKDfhT9avGRnCOQFSDvIiGAwtuNhQwH418MP74U9eLVlTk7jFoa8XLEeK1RkkAbZUQ==@vger.kernel.org X-Gm-Message-State: AOJu0YxRFqOwhGxM8KBuk0YXctJl1p6lDrfmAyAhEtqN4g8mBxqFXDVk oZQ5pi35xDrwcC5nzaUmMhZ1sQrEhSyuZ4NTUdhPQGXRPnqf1v8gMvTo9Nw4rA4= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871265 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 082F11BDAAE for ; Mon, 11 Nov 2024 20:19:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356364; cv=none; b=nSSif29GlVhAAaZws6g8+rzJdUSuwJZJdzXyC6ujulQ1lK/FlOhkW5GCiWqn5l4FklpmTrsIEa+LqmF3qUzVlxSMHvywBy+VN5CIpLarpHl/0boOCBU/GfeRwcBYMp3e4Qfiftb1utaNyhYUCtScnR/P6d7MAJJkjzkzOdszqsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356364; c=relaxed/simple; bh=kD4ulmGxIpQmCyeh9f4ZPmJ121zBS/vQk1SfQ8U2dVM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GQw/LDQOY7IYBdn9vI6NWhJc3h9UjcuhNDWnu3h5CGSaXIVkUuoyloRHPczYz7oBjW87vxbM7rgn6VOVxVGPTZcLnbPMqCM9/S6Jot5NwOsgUKrj+IUj1WQNArExjOwWILs/yRsnsDI92riDyOrmDuQlAmsR61h5mgLBlx+/E8E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=jYledgT9; arc=none smtp.client-ip=209.85.210.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="jYledgT9" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-718186b5c4eso2345733a34.2 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=vger.kernel.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=jYledgT9O3ZtEcrDQGenFjbRUib7hLXZpEoosj3W26PZjx1qFark3WDbt6HvN+1M5y 8d6pyYnyGYcZJa2SjI5W4ztmzXwtrjkYU2qP+ZYjd1j2qvEqwhkBS6IruSrFucSrFMRP 4kzuHtUGGebGlMJXx7BXXzxnopg4IUibWZ7WWOCW3/FW4js6M1KY1Go5Vceo3uMkK6nR bOFvSRROJupEchLdhmfaIEN4HFtXQUx+mu9+WbzTeSV42rPsnEYjCMFz4NXpak8mD2zk DVFiNPQSc7Mzhm/TjwcyOSCgmC60IJ4q3lYD3DW3vbOxTvlUAGSnFJDepryF3lJaR+fE P1GQ== 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=MQKEJgvYWNhdgLDy8zmB8mQ/yILOUPA6spUzUDtn/47sEyOlEdNZqnAwO/rmilJUPO sFFxkuNPl0Nq2PV3zZyzRnjIzMMZ01s/00+5TsQ38EZj+zkExzXEMKcRxSXAENKvTGxJ jkNEzIU/EQ8bXim8z6Lz/L/fy10eZ6TLCsRmqAO9GOnsY9a/IQVt8pwb6xebp282b9w2 vTbd+ZyUmnNSLkPrZx+G7BVpOT+nYg7BbTCtFdRhIHgBvvkTdeTfMMewUNmWSQULtWVv ouy9eEWhcGvx30crlXfrIN1ermxKj4mB22k91AhQ3iR3M9LPX8GzWtz9n5ktEo/u8Qag sg8w== X-Forwarded-Encrypted: i=1; AJvYcCXDy15UXW3+fEkPHwubau05OLFIMGYZ44wEPw6xWHxJ5jOR1j3SpSKe6JigoDoOKJrzBIO6RiIbPIDYhQ==@vger.kernel.org X-Gm-Message-State: AOJu0YynLCJ/Q+/nWoZz/QpzQqAdAupGnmZAJB0QoY6GQtm3O4hEiZzY qmxZ8adOQyglVlbmvU7oX2uit/hKJQkuElLJDBpdAOuRSvEScGfFvtZvz8ZrIDk= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871266 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 543531C2307 for ; Mon, 11 Nov 2024 20:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356367; cv=none; b=RfWfpONE+Pvrr154JuBQLg4ruiDzc/9nLo8uZR8gv3HGfehx+/zv+w3nMsPCL2De1T2KuC1AZzJAwQLksqfbaQPvIpz4PooSl9YJzyw5oHW8rIY9clu0UBYVvfU9Kunqxo+5DSTs6s7GEvnM/d8Sp4hg8Rg0P+4vDk7DnaLoc5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356367; c=relaxed/simple; bh=QBEIEok2zEjZt3JCIFogxoADuLr4VlZ3jLJ5rAkDDL0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cBABd3f+G2PpZScdtdfzsy3Ed3MuaUizUTAntbpoCU5Rou9nPN+PiSdgS7H7djJBKov6/t4ixJp6tEDc1U1E1HQyWsw+LleOUprbdYjW7w3TYfVpXcwnMLBCJh/88Q86lJhZcyhK0Zr1KAqszeX7b8var7CWdZmZZwj4molJmtI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=RB/8HFdr; arc=none smtp.client-ip=209.85.222.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="RB/8HFdr" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7b1539faa0bso318198985a.1 for ; Mon, 11 Nov 2024 12:19:25 -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=vger.kernel.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=RB/8HFdrpaUKISo5/c+mHum5Up7uW0cVspSBHaW6+YPgOq+33HMHUKmeWWyt/TvKLT duyxHa8VkTVuJcvH5xuawsuoFf+wi2CnOODSHrVuxaDfCj8vl1jbVG9y16vORs1VPp32 ccVstK1dgrzwm23LpUlSZ0O/s0OPcee8SrN2kJVZcFAOc23eqMiuczsRlD4fD2FZst9p +SfaiXeB52+vV+QfVEvC5dwF07A1s7ypt7cG9gZv5X+auOvFldiX6OyvyjB2AgXQa5mu dRvr8W7fJmk717t2iJp/A4BcGcuTprOUePivQfAyg1FJl9oZ0+t95eeaflKZKiW9ugeK ClDA== 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=xGPlvNMm+nN7e4KPyaD4LTDqpWd/7IcqV+0bQCxgrq2UmebRGr0AEDx3MCHHOQAztD Faph2W5h0ZsTqdHYCnNP7LyW4qcrzpgPP8iFHzAX5FV8fPC19Y3/6TnGeisjhAF5ZZCT 45nQmsZRBqsZH+NCEPN79sftGtEndW6T8Oqh1yjCqWZSRFzHoPj+nGD6zcTIm563nWmv IGpGsiKNPBXoLJsZQ4o50bnTMpOoLNMpPLJeLo/kUqNqsOcBAle7TaA6vcDWwuUohz6J LH18sTbu9mqxyiK4yWeZEfnU7OzQ1iRipNBBj/5pKM1qeAOA1gze5D33dpWNIX4K+kn0 k7HA== X-Forwarded-Encrypted: i=1; AJvYcCXgCBMXh5P1l+FN+6Rih6/KiPKC5I8MhS0rJ8bJMlRiV2QUEqqfLwgBHLSur/s44JAvTdjGXqrxZU5wwA==@vger.kernel.org X-Gm-Message-State: AOJu0YyjLWzb+EXW29slMoCju6nYXkshwbJnMNFTq4X/iyUH6E20ICwS f5mbwmIBbfldrPKeWA3MRa0nw00m+KCdIbOuADlrLBv3QX7NEAgjFRGxEWBOdwA= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871267 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB8811BE23C for ; Mon, 11 Nov 2024 20:19:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356369; cv=none; b=dOhIH3DvS6gBSrvMr3deVK6O+uVhu4YfNPydp7E8eZzw0epRn6WoSPs/opxqVX3iU1prglhP4K+IADf22Zjf6HYrKIqTawWfcGwbRjCrtXGJGowpTxghi8xWnF528sdv9VapOUgy4ngt7VqjfSRKV/IFcShMTkm2ckKAz2lxCDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356369; c=relaxed/simple; bh=MUz256iX41IVbMlPbLtNiUl9+PcD0bwfdnjYH0KeBmo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ngJJS7Obi/UH+uOlhV49pGqDhdN5zvPeTajDBGseA+bzV+8LrvTPGQeK5L+0RC4BhmjYNG5IToj2TR0IM5SzPDdW9yi3uTPT7Mh6/2FUCKYostLTRFsWpXJWFoUIkaiTp7WIuADvZ5jMAiZAShSpuSdz7QVnz/vk3buXyNl9Row= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=1mPvJ8G1; arc=none smtp.client-ip=209.85.160.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="1mPvJ8G1" Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-46090640f0cso40335201cf.0 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=vger.kernel.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=1mPvJ8G1OlyrXhsd29QIcwP93TIzi5amxtpKcnL7v5BzB2hNR2IMImlKtqiZ+SER/Q dUQOxytG3YC96/Rw+kvNbjQB1x700Hv4naaUxPha2jvl6pDxvCm3/lWwkX2tvNyZTiYT bGRQDdoksm/8oBgKMWn9sTOMZCaGRT1oN0v3d+N9mnLP72Tcz0zBYdC/zgI7atO+Abeg +ycMWfef01Sp8PLdT+eUs6bXfWkyuv4I/ZXW5qLusM9KsmHovLbfQhX48RLCgDJ8ww2H ss2qQRCkKUGv3+8uygXDNM38sY4KGXB4Ar3bMqG/1OkGybyad41dJ4/qGlPWeGfr1Jou +msA== 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=GKsVp2ZaIcm0mWIJclpVCFR1fddmbaHgs2TWoMI7h98B7gL1r0fcGqEQ45rbYYzmbs 7lNDHFMoY5gmPTI1fbsv8yihXIANtWlDum19g7azKxAQyeq9sCyJ0WfgnpQ9+NiZYhSR oP2yb2uTtyjWjIEEZzB5NVncDO8XIlyLYPGFl/DLQj+3Ckrg56TlPhW1RW33BWTFtKCk JyhpRw6Rlm9IVp9cgt3jn3+sMr59JRA2c1sLeufBFkwNK0gKwUp9zutI19Nbd+GyE4Wu n93uwSaMbZuvYG+jdLRkEM540Y7WCqIaPIcm9Nyj1sr2HpTymE5ISI0nMMKgQ5DFjhb5 4gdw== X-Forwarded-Encrypted: i=1; AJvYcCVTBu0Q0gUzO5xXGDHatzVFxvrEmX6mngCPnF42/fOvE42O1rUMItk1dSG75Pg6ElLKa2QvglDAIeF93w==@vger.kernel.org X-Gm-Message-State: AOJu0YxFq4bQZCo6tKy2ofxe5nmq4Zh3bdzDs2foUSMwMY7QMULDdaZx rSWy9lIfzCpd+ed+7Uc49M3T0Wpd7HgBC8XrylSgTavSk9rYTXAOReSWZGv8w4c= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871268 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F4E61C3318 for ; Mon, 11 Nov 2024 20:19:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356370; cv=none; b=sEvOSJrFBDOn0OHzHDqX1OBtEmuyyJituG1NzHzikqFjZUuZrKO+XlAyktaOkI5wiH0QITyeyeZ/wYwe5zqoA3quhPjEZLrMH8tGTHk+tdxYaJxCSbscEA2AtHzaXeafKwqXI4zF9Po1jb/MEnRxarOftO9O+zv8xUBwLAeUhR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356370; c=relaxed/simple; bh=+GaW79ihYPcVt/7H2tBMApB0qt54+8GxTgU7k9z6Kks=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=odnR59rAbXapwmeW9+QG71+6niRTlGLM9WyzABH+4FlAt/CT2Nn/ru1Y9GRvuPIfAG7UjHsnY8AShw2m+jS68AROTb5flNw9M+d+Z0/PksjE/wxRjHuWlDeja3r9jwU5E4SekLONTpW9bTpSbUNfnKprLW82OhFcMWLkfdNM4c0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=ecMCd6g6; arc=none smtp.client-ip=209.85.160.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="ecMCd6g6" Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-460da5a39fdso37362001cf.1 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=vger.kernel.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=ecMCd6g6+CRWRMGZZap3eaMKIsWFTbfBXssJ5U7Crenx5zgp48uEmJdG9Ja9rMO2+O oQIaN18EVkYDNccBvdMmukip4cUC+psREXW/PUUdNTQ3JGA+LiDQqDBZj3MftvIQ6c4K 4mqDI2ZR7VsyWqgRwvLPlL9JdOkrVRa1nFXIStZ+6J6PlKxpx+cF7W/DaxeYzV2bFReT YFBLkY+Ll1EDiVkwYCx4T/QbSSqyhvBJX2oK2/1d31yz2YAwd021jrpeboYql7Vib3X6 4bhP2pxDEo2h1E04a3+inH3JUpEnROauL1dD43s24AefpxsDhkSnJK2dw4OOvViTvRHK xUQQ== 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=lXGE1wIR0sXRmMKvuR1JHuN+UwBsG1JK4ORrmvhhdNFVezAcg4n89K9UIySIfEEw+W qjSbL3R3TJwJlpPtLn1Jl/SFwJkMvhrk8rJBFM+X/5YGPRrCJQkB79K2xWEQsLiQbztS jfRdDGwp/SnZ8spQD8cEdmNgpkaB8ilFIr9kI02whYVupG3HAro52L/2wXvfSAMnCv1a YKN7lJLqT3XOvwXfC3/UJQECXmh1QnMp0s6HXCsmNgC/1ccrAe1V40K04xKju43oXoJI nAIJLXw1S8Z/b2qgmz4ZSNg4vP7/S/Gm5OMeZpXLDkfJC+C0ixh/hghR5pyfpQOuQuMp gb6g== X-Forwarded-Encrypted: i=1; AJvYcCUW/qiieqUKLta0iGg7LkXQ52p8+D0BvNGLxSE1ZTGrMdCxG0z3RIwZMrnIdhgTB68GB/VzwbR0/lNw7g==@vger.kernel.org X-Gm-Message-State: AOJu0Yx8UalJrP5gfOYY8+Z3AmjkV/2JhAt7+SYXf2CznJTGLDHwF4DD pRPA9TUeuswJTzT9XKJJIbnWAIwNv2sLCBO3ZLsS6czkz36Gb3zulRMjGsnbqeY= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871269 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33D7B1C462C for ; Mon, 11 Nov 2024 20:19:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356371; cv=none; b=Wc0SuEskjgRFKVLx4WICeRqX9LS3jZq1KIKpcfel4GNeUTm9/AYkFT8WLG7ymql7CodpfirSKR6B49JFNXsEpOr6cYJkV/oUDh6TnYbPow3Ncv8/5P6EbDfV+jDh8v7XFapmlyr1qjSRGoqYWc4gG1MJMvuTVrGJdGPFJWBiUws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356371; c=relaxed/simple; bh=ERxzpPq6+BTFpJlaeLsF9b18iaASUw1kO5vY91SqSo4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ScGxXrsd/eWxayUy9cpEV3Ta29IT6eGMHhcM6iYt4VxOSkyeLGsG9h3Mej1cNYVGHXiuFI32Niu3RneVyZNBAmrdNh0ZxmQuJTcjMrnVv1vVq2pxSLCUfyFrI3niZm9JmEBenjZiME6380Gnf4eyOJT9i0lsvB/8FRXX+SFVxH8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=gFeTXSrI; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="gFeTXSrI" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7b1511697a5so337602785a.2 for ; Mon, 11 Nov 2024 12:19:30 -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=vger.kernel.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=gFeTXSrIycX/TFRcG9ot3CIMqEwBusTzJfJ5IlbIaBWNxo73ZSRDM6BY9CvvyPoZyM eLAFXVyKBRD3b0+qOVtLI13a8dkOqfedmLl3sAiOdQsEZwGWQJSETT39rFNTeSbzHpqp 0N2Gt3eQVJg5Br68idRqR7xojEwpK3qSyCdlI3TeoybosHon6M4V3iPCjf+UJ/VU79L2 OWXdRJ+iEsU+YMGxmjjOFG/vyOV/soHJ9lxJK11qd1EpI50x8fHAmQ+QE06XBLbKy0Bz hhrlKYdYhuQrrIqxFWhhQ6u2LSjHkrsrkvKnVCwdj8lkl+W83wJIlghgvPcSdelSDHVI MCgg== 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=wRdpQgTqmeDeVqOQgU3+j5uMhod9ivPWY5LFGAHu38e0+2FzzYCHz2G7iSx26PROHv mSk1c8BUYoL3KhQX4qKR4qSXUhPjHjv5+eXjd+CNwc5c41SoNMWVLjik4CJYvR7PWpqw o8W8Yz5qvN23kLspf3NI+wbLx2iYTds2HIm3sz5m2CvIcL7TEnoQmgvYWSMYNxRgOFfj Qjz4q1pWMgfJ7o+ekalmFtfR7v103uzScPRUPKXu0h+8DC8OTHAJGUNkh4TAY4vryM+Q dvi7j40zKtB7DeyEEhFRkPBhqt5bQJ8M7px8HNn0o3Upaota9xHEEfMJk07R1xowj+RY GVrQ== X-Forwarded-Encrypted: i=1; AJvYcCXQVI1NA1+puNIqK2etIaKxQ3idyk4ssancUy6xTqLjE4zXfiEEgC6zvbEFQqpXvPc1un8Re4zq6E5+sQ==@vger.kernel.org X-Gm-Message-State: AOJu0YzAlCDOAaM2KNKFHNKyXNDC0AWY7jMPKTdsCpdJtRUWCTyjnlE9 LkA7dw3pWqEEETpOIh7oeUc/sHVRNB2PvzqPJ1setGsKuJRDfGb6MfSxC7XDLU4= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871270 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25EAC1C3318 for ; Mon, 11 Nov 2024 20:19:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356375; cv=none; b=Cuwqkt6CKxUeAXe2dmGl067YmSbp1sSCxXkP2HP2b2fX4glh3nriH8dfugULDln2QCa+bPcX1I9rIfI8zekYo78cXhfQX/KTl30y6oIrtoi7qKJP4ZyvXhbhAIBj3I0DgBs8GXTzRyrq6i4LUfJerGCBOkuktGBWWOIiYAxBb/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356375; c=relaxed/simple; bh=t7nvLm79BnbL0G55pVnNTkmA0duqgzyrwuSpS5La8ko=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KEuqgroeJ7g7WO92WUVgm21bHMyzqfBedicdRXR0y9Y2zI4khrNaOs4xFaALJgUXHJEXd1ADG38R3CqVO1wH1enQOTjr+nmEvlCgZip3zu7C3Ij025LiFFnCZoQa2LrIvh4MlTgkchmKrpDVAMGmjsuhcP8vHrJdm6bFZb4C3bM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=SRh+pPmm; arc=none smtp.client-ip=209.85.222.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="SRh+pPmm" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-7b175e059bdso335507185a.0 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=1731356373; x=1731961173; darn=vger.kernel.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=SRh+pPmm8ixAsMoQrAPKciMNt87tnAODzM/E8MMC7uO8gmdqjFrKORPIeSF9D9T5dv d0XghpJQz/zSJki0hO4V+jpEmTp7VbU4a1MWuVVMn6FaqomXXAzHNDLGxCFVzT8dlqh2 5yNau6tdDFGasfo16eMpgLL0MtymMfGjYZeClrZ1iHcEoD1Eb2J5EGeuwYDfBgTFIsGc C6nx4gj3d6LHiYQPQxEJ2EGsCQGrb/dwd/tYH0Ox7Leatukwrbgw70zoxmtI8rY8Lf9+ vfko1iNdDGHfoxphYbjFiQ5Yx+xkE/HuCnaCfD6Yewlfa6i/tY4jqE8X9jdb0CwE9MxS LNIA== 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=EnfT0Yb5X/xvuROVCe/jg0eFNP8fkrm+2/vV7/x3ohyOi56yWf006z0Pj+iHoytfQi CJPdMQ2bF1bseej+jWRAajEdjLN2XGmFV7WmVmkS0cNVPTr2Vbv8SJE61V9PQ2A6YUXT ho+dyR1N3wdLzbXKWEtBV61TvzMouANH7hHLyGaVXQFdVth0hGiltAVTgVhVL8YA4+kf Wb0LXpeGVikhmCvmTuaB0BwNPfvIvzk8GYQjtBc1VCgZq/pKvMv4+VubIPzxjblm5jCP 7DkHerbua25RUNS9Fg7EbA5T//TSwXFw14HrM2FlfN7h/SfCw2tiMCV6P5UnaXVAXSmS IOqw== X-Forwarded-Encrypted: i=1; AJvYcCU5Nxu815dukMDIUNMXta2e9u1dgfjGHYss+iaKjmSqHw8NOtT/BlVdNS0wLpd0oSpBCZaCz/K+eahxDQ==@vger.kernel.org X-Gm-Message-State: AOJu0YzTLV1LZVxsxyIEAVN+GffGL6uSfP2Zhbz5ArqlSy3eXfvJ/KE4 flEsDtLZJrtw4QzN93KWeHeZxJKAoAiW1ssgC/+wkcRWZl1NFwisZevmtU9cHT4= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871271 Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9373B1C462C for ; Mon, 11 Nov 2024 20:19:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356377; cv=none; b=TMAGytixLyFMTKPabph1GNnhFPeJHSK/h6OQLpxeUeyp+FhwSTojkX98hJLh/98GneVDgcoQyuQ+NUT+FiWRlw3CJQ1vR99xojiJKMhVXea52yCYHostNUwwW/IIUxzkzeJH9bnGbaMyzfyKYRRAtEjz+IoLH9eOZBYX1tDg5Vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356377; c=relaxed/simple; bh=rBlo9msfCryQ8ECMKKeQafDSRsCFz5AQABc5DmNyuNU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=McT51sJRSpGdSvdjpc7vTRu4Xuj5Y7bryeRDUpbObJzLjHlxB83E9aDsNQqSjSAPKKiS40Lccu5jGw6a9LwUMB0MCER+kEi/gZZgr7V6IF8PzKcqQD2xPlhIjXcP0IvV/JSK07NGJY0U90g83t1iwjD2g2ChFqtFkYuqJco1AP8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=XJchjYSf; arc=none smtp.client-ip=209.85.167.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="XJchjYSf" Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3e5f9712991so2358643b6e.2 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=vger.kernel.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=XJchjYSfa/9PowqW3RlMTawvBnROQlaDWJU20vVRgXq2beysOhaYvcdTzqpbi14eFA z0d0OV/DKoXz3LVc2CljEqrsiBB5ycM7QYq63lvQKXdofacLIBXBA51hZfGXCB7Y0t6Q P3M+sie4FfoH0wMzYdLrk+MR1Q8+EvAXMCOQ470XfkRAr1lbcT83QU2wtyrfD6vBCHJb t2/weZJ8rlVEi2KdP9mwM3foad0rMfQp+bx8TXI6vxDRRSgVp0EvD6Ek7LKdwUYjiDC1 1xSZtZzN4hbJhPoHCR6Iiig6YdIsw7VhjXkzypHMwlrCCc02b6kjvaURppQY9LBa4wdw G0jg== 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=bnIua2L8SA03fOXQprQwf/rZCt+fOIjzFNfS/R7Fdwgu7ar5V8uYmAg8bCcu5iEuGW hKZkNBfKvt1r0wE5+VPKi3bBX9htBLfYGFVXGZkCqhhjkTojqu4fYg8om8lQMx01QRa4 rjcQLVo2tZ7C26uUTPEXLNBmgsdPYyA30PVdJXY82t4QQq/4fp1BqJjlXZnc0PdeOouV j3njzJ9FV9VpVegGpUq9b81IxVa9DTMcwlVvxkgvHEmjsdA4YNx/T4rEATMsywEYnAV2 PrySPeXdes/EdZBR7vdXQrt2SULo9YKtDrTzm9UMkQj1nj459gql4atdw4VEbaR5I6XY 1iXg== X-Forwarded-Encrypted: i=1; AJvYcCW62P41VxmFNRYRDbGgzeSvo87YBB0Skry91iTC1/0DPSQKV1gXcxw0D8S0VSuTM8k/U70e5fC6zgqgWg==@vger.kernel.org X-Gm-Message-State: AOJu0YzZmsFw/k1/RzJWiJ8dV8jWs2AYNskrmjaaLVQULvWZxTxgcOwi lJg9x+GRcORXdt0KNtRN6zBs+gIlz4va3SrR+dAEWI5K+AGZAAPm+AP4iHVzUgc= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871272 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66F6C1C8FA8 for ; Mon, 11 Nov 2024 20:19:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356378; cv=none; b=pQ1EmYCBMiTaqDf6NZwjIVzI+8T5t9xzdFQFyutA92E7rL4E3FW+cVgx+ErJ3us13V/ACmFDnt3aDVWyL1QTTd6XQBb5Q9EwUkZhZYMG9sEk16OuruKpI12WJdaA/CHBAlkbE+tpq9eeDeKBclUx6NSLnYRGfoXNOG9cgyrtFWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356378; c=relaxed/simple; bh=ebiNpZYnvVnRivNXQB+8i4kmhiMBzkGPNaNaMTrbD18=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HcS8+xzzDA+f28/4A6YYu40CnRQ2k6MVSeXGxb2KhzGCXv+FTVD9nomhIwqEAbYZFtInbsz2cm14Y+lpJeXYwmZHROfl67+vE2/4WGyI065R03HMhggIGg70Hz31mgHCyD1hs7ygpaQEonQbe9muXcD/+4j2EZyoYwdTCPhOXBU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=KsDTylkz; arc=none smtp.client-ip=209.85.219.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="KsDTylkz" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-6cc250bbc9eso36653136d6.2 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=vger.kernel.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=KsDTylkzOgGiWbe4xY9fDmY/F7+0m5JC1Y4l7qPBaZeAv0ydV8vhzH+V9fHZ3NwPZf veb1C7wPnCqaG1gdsoVAkVG1FNVyhNSzDr9MO63p1F+rB/2jMR9b45XGdS4ANqDShUgS 6EWwoOPpd4CiqUei5swGsFI1oYllzegAIbuaHT2JmArM8BAYM0ZX7RPsMDbwUj0Js6TM G1AT9ygGUe0T1yODjStHH+6+0V/waG7Y56iLa4d325OsIoS2SSFuf+9pUTjZrNUi4+ur nMHDjuGo5dxvE3I5i/hJMEXjWaKjhOPp/J+hMjtAMP/JDvyjtWlJVVa9M3Do10WfdbAl fqOw== 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=wS823jb8HAMqW0mb/pa7siOeUvwT5ettJnxevL1gVCYtWRuKssTWO1ZPyBtVGqH3So wmsfw1HiCZEubGgItTfaiD6GLMv15F/lQ+1SY4a6ks8ysL0PqSWCqjjSW6s7vYr+5bWb xHdEdIZN6GuL5IqJUh/PbmTI0WSX7DhG/j9KNxhYbCuR8Qw9w25ClwgVN9lphcCBnCR9 xt96QmbLt0tJ72T39WZk+rfeL0wkrkrG54m9ramc1aUSmvkDER+Gv7eWKiRmPr/CWh0t TUbc2YW33zb/vhk8EU67uTeSsptahNN+FcJoHDXPPGFRVA7aAB6XZ3OH+ACk+iQtdI2n 9bjg== X-Forwarded-Encrypted: i=1; AJvYcCWhGKEqd0aP0rolyl8UGyv9aVUFois/BW86zQ9s0U5NjTEhNJrOJsWxjSd9X/JmGCEi2pShbOic76/gjw==@vger.kernel.org X-Gm-Message-State: AOJu0YzmhMc5WV6LgMcmVyTA1trE2YcEggqsyL3HiW7mMEhaK1qJbhvi TdwlLyO32NM/5pfkEoLzSKoU6ISdUs838i848m/MYRfKfhqqJxxPbBCb0uiTUVI= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871273 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 289781C9B97 for ; Mon, 11 Nov 2024 20:19:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356379; cv=none; b=DCA+wBYL99boKCHR8X6/FbWapbke2XuQmCnuaM8RAJn4yZoHp+qksGx4UD34x0izSH1pIiKViHpzc2QepOml0JPWB10vhhBf0WHRAbp0n4RSPVdevKg919hl750BasCgwwcSW/4ZxCUCamXfUINsCeCjbN5FONb0jkvQNsNXMl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356379; c=relaxed/simple; bh=g8f8HPGo6FF6bNhCenpptLnEwEhFsJS2XcfOHpq3gpw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=epF6VTgR8vOJT46zlARThqcXIXVYzxQjv1YJN19zxsnecEGhV2+UhR/Q5v+P2OlOXasLaS5i8XkrGx63ks+2i+KKP9QadReTGNz6Z62DK16JG+HP4DeR4Z5rc0zbz0NLf1zHu6oCzJVLiOGD6s8QTT1XlXrNW2nLdtPaG+4Cits= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=ul3sfdrd; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="ul3sfdrd" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7b158542592so343955085a.2 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=vger.kernel.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=ul3sfdrdnV34wC5BOw9gEuQZTFZo6RWEaCK/AQr3weUiTVU/eJkPtu9fgqudOsJXnv mZQj0sOAbfHNRFTehmU174vQivZGCUYNwADSJ9qV7Wyw/j3oyq5/gRKmj06ki2wD6JNy 75RkjRTrqTQ/lCnQa22zFxX7asmDSp3503jGvAIce+8FbpLPJ6UB6O/AJPUeLCiV+aCR 7+PZ6R7vOGnkwyTkgTDuCySVK9RNBzQhe5LdYWDiV1Ej1FOBlVtMQwdGy495bC+y56mu 6ZCDJEMlkyjuYiDc5dW7atL7J8aPlLG605AIYviz0sGSZc6jaB8FO3OYgiwfU0pytqqC apdw== 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=TxhRyqVd+lvbETyvFQAmCBIcqv03chqz8uiIGysPGmJl33w6OuqY9CsZpKb5rN2Axy t8bTOWHVA+o++bYe+LZAbdeRmz+v1T6bb910xrjvGqJvsesmuGBvJ8UoE+sqzUjb8ccz c2cPHtZJ5RG71oVd1BNdyucU2SzF7Iukjh2pXRgghCfYXXsjfnNSloCHQl0AkhHRiTTN 2rWHZ3Q/e4nHhdF5Y3SaPCTb2UFQ18yC57IfretttOpKnsBBdbFPmx5sVix+0c+o84ON AN/YHmSsbchiLqix0jz0Tbb9lrWc1j7SJdAATALKYQ7s0PbKY1HUUX4xocNQ0Z+iMNbE mV7g== X-Forwarded-Encrypted: i=1; AJvYcCXTATS9mLut+C4lo3eghoezPmIYerQGqTKzLrR5SEqwBSmNL+5R/3NkDLZYx8j8MqAFmCKMOcoVjqSXow==@vger.kernel.org X-Gm-Message-State: AOJu0YwpmJhfYJ84J+2cHMy5+Ywq92aMdbyVKMCeQHdMNvGYsT0q8zX2 fDrb6sexnSDP7z4/FNGpDNxUbiZ3WBa3/7+aswh3EAopdK7TsAnrzJqjMnZFfJw= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13871274 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B7B41C9EA5 for ; Mon, 11 Nov 2024 20:19:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356382; cv=none; b=rhYg7Kdy8g3EWk/wMCFGmQ/ShO1LrTPApMPDaYdWM6sOgN6vbY22vGHPN35FwMrwhMB+uU08oBopvpnhLAaXGD48UCe+9Xm9jshJWPPKgv43UAHbUqLOrqg4QAUqpHeod7hIoPtyWbrLQO43IARDWwY1rm4/q2BVMSxK8OebnEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731356382; c=relaxed/simple; bh=85dou7ENDPPY5VUOCL1jZRoxjWsulKi6BQ53aoLcHhg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tN+thDm8lIxiPiGIpqYvlxOaFP+Zd32TfNOYL7ldpr+T8VTd/ZCspuRSiIgVSRElB1iUQaVJZDGoO5SjPjvKv5SbKeGqWp110UNWDxwiF5tc2M6H6T6SqafahZyFoFupOYbQjd+4lw/j5Sz2oS7iFM6B7N7rvW6z6uhjJSUlHpk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=rdy9/j1t; arc=none smtp.client-ip=209.85.219.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="rdy9/j1t" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-6cbd092f7f0so33510406d6.0 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=vger.kernel.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=rdy9/j1tGzisk/Y/hiAmtx8Wl5Cvyv0EhLcYyAUxQi6CaisfwP6+n3rg/GPHRW+nmi Uugb7scu09cOC/bH2brS6c9Z5S3G57WHngbPyc7mnnttYOY1zL99a+kIczG6tItCFH85 EGljfgDEIFl8Ty8HbNYCTT/NIv8BSaA7GEh+wq+a+B68eGQOAaHoKxK2pEaG4cnjuzKr LkIlkWyi+c5c1xmkgFo4dSRE/sdcDwjHNFYUxs1LusC2N2JrpAqJ+6qESuFeu04rsw+b IPVp0/9gOUiRInTwJ238lD5riKT+E0gr2YNTUZnvBjloixGsrAmFQBhPGfogr23C8WjA sqXQ== 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=SuFjWM54tqGRan4py27E9pnx62YgXT56+MYdbVwCi3wkGI5l/LUbAqmBlpVypSe4IA ZeEPnUHaGnM7J1Z6pqBerZ6MGBsAxKF48iMWU513X+4qOhEwU/dqzOk+aUXaX/BmGJ6q N1ZtNZZGuO/AZMsg202+tcJgGR8CvOZecjpruQYHMrupIX5+ZCtGxD0lrhuEMp64b8b5 tjBI0yv4ziMbt8H9lQD5qgkGpa8Bb/XEWmmbzO5fn/ijIGVp+gkeArUtBuBH8vszBbz/ h4Jlkasntv26ev8ahWf4yZh9SFTDbx1w8x/QrsX0udytPRu7T9mbMv3tcL78mlc4I5m5 Es4A== X-Forwarded-Encrypted: i=1; AJvYcCUAFft6+CfQ4i0dMCuULzwXCyg1n6HwNx+jD9O+u+C3ZLpMyJVh4c7Cw8w3EFPgX5p54qcdp0hJguezUw==@vger.kernel.org X-Gm-Message-State: AOJu0YxNRlmnNzHDXbjXF3FKv301wpy61mzraOiwJx1GNmdy4F2mE2RU AqrSLtqOTmGhADt5np8/9xOD8qDxikUNMhHyKuvgKjOSeE3X6Tlt1MunusGV5e0= 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: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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);