From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1CCED711BF for ; Wed, 20 Nov 2024 16:16:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5662C6B009B; Wed, 20 Nov 2024 11:16:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 515E96B009C; Wed, 20 Nov 2024 11:16:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B8326B009D; Wed, 20 Nov 2024 11:16:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1BBC86B009B for ; Wed, 20 Nov 2024 11:16:33 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3AAAA16092D for ; Wed, 20 Nov 2024 16:16:32 +0000 (UTC) X-FDA: 82806973956.27.4EB27A5 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf14.hostedemail.com (Postfix) with ESMTP id 4EEED100002 for ; Wed, 20 Nov 2024 16:15:32 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IisjzLSh; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=6R5ZHaJW; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IisjzLSh; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=6R5ZHaJW; dmarc=none; spf=pass (imf14.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732119205; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Wz13sx0cDR8noJSoNQ/P4iPjmJ9JKdZOk5KjfUWLOnk=; b=jCkwXpYrv1wMfk0vs+AN25jaO0whfyuCI/MqVzKFuqgktNKYpMVfBAnuHfb549+lmWykBL hxKMytnzEXkSrb+S746wfwnP2gLyrO+snL5IOt3/vvWQSVhWTw8AK8CA6fJ/iyR0XK3rVl +jEPSoOMuBztQLpD3VUmRyO+M1pAJPg= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IisjzLSh; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=6R5ZHaJW; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IisjzLSh; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=6R5ZHaJW; dmarc=none; spf=pass (imf14.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732119205; a=rsa-sha256; cv=none; b=qZTgCzbOuo3jngQ4z2oyUFkLQ8Rc0FdyFzKbFEh2YVfwQMDN8Jk6ykkvuQZ3cdWWqfzCy7 r/r8Ru+w/PEbrytCS+EjU/2CLcUku+SSkX6okFj2Sy8tdJfVnE4+fBY1Q9l5FWb35HOd5+ mlOkZ73HsdrGDwUJDVkBDe8vlp8p6oQ= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3BF2C219B3; Wed, 20 Nov 2024 16:16:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1732119388; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wz13sx0cDR8noJSoNQ/P4iPjmJ9JKdZOk5KjfUWLOnk=; b=IisjzLShbwz7Pj1uEHoXXbbKY/Uieu+EWXzK2LpFMn4x55huJksMH4KvC7c+Np7thb9Xr1 fyflW0FGhu7K87I8XIMxRAcsmSwUZuQIfOZYJcuzS0Y8Duqb9zOTXRhBJpNGObZqt55a5v moGTA+2Dl+1jTxPMDLtVPvKuuVxBBVs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1732119388; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wz13sx0cDR8noJSoNQ/P4iPjmJ9JKdZOk5KjfUWLOnk=; b=6R5ZHaJWwGwfgTvxo4AQbJvD7X9Zi+P7MjsUD+TAY0+NTfvSIhPtg1ebrUKTKC/8WB/xup sy6+m4iFeMkFt3CQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1732119388; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wz13sx0cDR8noJSoNQ/P4iPjmJ9JKdZOk5KjfUWLOnk=; b=IisjzLShbwz7Pj1uEHoXXbbKY/Uieu+EWXzK2LpFMn4x55huJksMH4KvC7c+Np7thb9Xr1 fyflW0FGhu7K87I8XIMxRAcsmSwUZuQIfOZYJcuzS0Y8Duqb9zOTXRhBJpNGObZqt55a5v moGTA+2Dl+1jTxPMDLtVPvKuuVxBBVs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1732119388; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wz13sx0cDR8noJSoNQ/P4iPjmJ9JKdZOk5KjfUWLOnk=; b=6R5ZHaJWwGwfgTvxo4AQbJvD7X9Zi+P7MjsUD+TAY0+NTfvSIhPtg1ebrUKTKC/8WB/xup sy6+m4iFeMkFt3CQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2B0B1137CF; Wed, 20 Nov 2024 16:16:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id WrvrCVwLPmdEUwAAD6G6ig (envelope-from ); Wed, 20 Nov 2024 16:16:28 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id C9B38A08A2; Wed, 20 Nov 2024 17:16:23 +0100 (CET) Date: Wed, 20 Nov 2024 17:16:23 +0100 From: Jan Kara To: Amir Goldstein Cc: Jan Kara , Josef Bacik , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: Re: [PATCH v8 09/19] fsnotify: generate pre-content permission event on truncate Message-ID: <20241120161623.brmiiggtwcvcre3u@quack3> References: <23af8201db6ac2efdea94f09ab067d81ba5de7a7.1731684329.git.josef@toxicpanda.com> <20241120152340.gu7edmtm2j3lmxoy@quack3> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4EEED100002 X-Stat-Signature: bn9xyhedtwfdjr4zj1pnpgy9q6dg913c X-Rspam-User: X-HE-Tag: 1732119332-687539 X-HE-Meta: U2FsdGVkX1/vv1MXaiyK/7TaM9jQbglwm/kAxPvxXBVPLS/sG9NzxXgbj2NlAdcKImJpFIxBzIsDxJkwQMei3ei+Ctxt3SlK7OTYzZ/IexbFMaRcmhKY7RMbEJg2TBLf1UknBGMgajXLTi9IZ/JEccvMBYvW+pqK4v9sDl5nyepYnIbF1ZKj7yhtFS7KIOsT1cND2dGdhUGV8yrPcn+/5Sv3qMvJKK7QPrQg1KB1GCU/qsCpqfLkoOLKa6izfUJqjNX0AGSdkFKA0wrmftaSY+p6k/j0z0cOebBgdjUhhBU/AnHRYoS7eN1kjAT/JaqJlUBXq356DV2+zJ0wic6ma85n7ZW6+rFKc+nBCg3Fk94k3nUeiR+xG+ogJ70X3CjGaeXrHG/5ziME/a63iwSHrO9fv2vOr0Rct7GVXKgwW4Z7hTxi1XnhrD4MVYCXLFnVRETEfUAL64y9ZfC4AyVWkG9tOCr3WDHW1E/PNnq1JCDQ8ngLFcfaUHD27q5Dx3reODYmTeIym1+A8wnHZHOMVO8yR6D3TucAMAFlNBQC4YbmX6oihFLhxBGkdy1WE5rGOzVo9DQNKuTsIEtf/O/ZTF/4ydaQRhKQ7OZo+AfqA9QzWnkKcCsUaS0QGJcH8GiYyZHhIuHWG8QyH4ojdpLobOdrCQwkt00nvDGDGuVhRQ/6LzLkFQ1e4cXugo8j3GFEkzjxE3OB3bDHOUUqqg2UkEKAZJ5nRXl1M6G158WX1W3iThKVeW0UIltU4vJofApIcwhRK/8XzIKg1j/urDr+JfWB+VoiDnT9LbjUBKdrRlp/XtGexQy+UJfiVpSzbFcwv/dRfNLYmWKMbivHY8nLBq4L08YtVMbJ2b81z/s1+pDTry59ENHalKcRssRlA3qRH3VvqVwphNJA1oCK94nay7icfwFGjKVC2or6qDpiRU8LLDMSv4dw86N2YGYBBUJ6DeshV9OHnwOdFHoMGzq ci8Qkr5H 0IufI8uL7cJsLrxwh9lyXEx+arU8aYFOew4NTJdZKAfAqrBOConLrHLZIQfTLxRhM0PJTfewPj0ExmlYQ+oxU6RMzSs4pypDVThoLP30mLlDRPbfQXq3Ua9VJiZAahKg4TnYsngf/k2MturINt0Vwfszgd5OkDpNsiHqu7GXnD+sZJXeoR/z8URO3Pl1RnrRW+1w5/AfUsPVC5ZZQwvZEQs/ip2++51kY9q2OvwwuFPLRtlEzUhYiy+WRXAD3gBQcKmGQLv7EVwL6Ba2mBj8d0dRaBa33n+Ixk+EVf8VwsrqC6n6M48J5hS2tFWRbj97veTIkSbemWgrQKn+YxA4tioOpJBw4uyJAWk4fKCEp76qytrsmmwM0Y/VM+bgSi46ZKYaVDmS6wsl6zhQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed 20-11-24 16:57:30, Amir Goldstein wrote: > On Wed, Nov 20, 2024 at 4:23 PM Jan Kara wrote: > > > > On Fri 15-11-24 10:30:22, Josef Bacik wrote: > > > 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 > > > > I was thinking about this. One small issue is that similarly as the > > filesystems may do RMW of tail page during truncate, they will do RMW of > > head & tail pages on hole punch or zero range so we should have some > > strategically sprinkled fsnotify_truncate_perm() calls there as well. > > That's easy enough to fix. > > fallocate already has fsnotify_file_area_perm() hook. > What is missing? Sorry, I've missed that in the patch that was adding it. > > But there's another problem which I'm more worried about: If we have > > a file 64k large, user punches 12k..20k and then does read for 0..64k, then > > how does HSM daemon in userspace know what data to fill in? When we'll have > > modify pre-content event, daemon can watch it and since punch will send modify > > for 12k-20k, the daemon knows the local (empty) page cache is the source of > > truth. But without modify event this is just a recipe for data corruption > > AFAICT. > > > > So it seems the current setting with access pre-content event has only chance > > to work reliably in read-only mode? So we should probably refuse writeable > > open if file is being watched for pre-content events and similarly refuse > > truncate? > > I am confused. not sure I understand the problem. > > In the events that you specific, punch hole WILL generate a FS_PRE_ACCESS > event for 12k-20k. > > When HSM gets a FS_PRE_ACCESS event for 12k-20k it MUST fill the content > and keep to itself that 12k-20k is the source of truth from now on. Ah, right. I've got confused and didn't realize we'll be sending FS_PRE_ACCESS for 12k-20k. Thanks for clarification! > The extra FS_PRE_ACCESS event on 0..64k absolutely does not change that. > IOW, a FS_PRE_ACCESS event on 0..64k definitely does NOT mean that > HSM NEEDS to fill content in 0..64k, it just means that it MAY needs > to fill content > if it hasn't done that for a range before the event. > > To reiterate this important point, it is HSM responsibility to maintain the > "content filled map" per file is its own way, under no circumstances it is > assumed that fiemap or page cache state has anything to do with the > "content filled map". > > The *only* thing that HSM can assume if that if its "content filled map" > is empty for some range, then page cache is NOT yet populated in that > range and that also relies on how HSM and mount are being initialized > and exposed to users. OK, understood and makes sense. Honza -- Jan Kara SUSE Labs, CR