From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 C319228F4 for ; Mon, 1 Jul 2024 01:16:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719796570; cv=none; b=h/gm93d7fNUh7QEQ6hnCLxr6KoQd/0u0wgnjWOBxjPYcEBfuejMZIGwoeVeny2fa2jTNVzjQwPSNnaH5iry18c9haPl8wLFuKuZfNNcy3PfbqDkGovFJ/Ut4WLSrjSPYbpRGtiLRU7WNOk6MxgjTpJfGhpnbjJA1ITTXJQU2noQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719796570; c=relaxed/simple; bh=uiod8Gdriil62+Shj/a8XEzFRx/9BbIC8xbxkPmFaC4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dhEsIGt67w8QrQD0g++c4Gqs2Hp5uk7V16cHVjoH7ypBIXi6g7jgYGogwDQiJmS2aqv0WSgXU2Ltj7FATctLCJdDcmwvRFpW8bYWaWS4t/OrpG3uWKiohewyfmJEHQQsUz/p991TBOR8b8fdekGSWnmh10pfUiYeae8JJ0Cm/cY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fromorbit.com; spf=pass smtp.mailfrom=fromorbit.com; dkim=pass (2048-bit key) header.d=fromorbit-com.20230601.gappssmtp.com header.i=@fromorbit-com.20230601.gappssmtp.com header.b=Tq0xx76s; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fromorbit.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fromorbit.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fromorbit-com.20230601.gappssmtp.com header.i=@fromorbit-com.20230601.gappssmtp.com header.b="Tq0xx76s" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1f9b523a15cso15300305ad.0 for ; Sun, 30 Jun 2024 18:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20230601.gappssmtp.com; s=20230601; t=1719796568; x=1720401368; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=/WihJp7JnQZqE8Q3tF8oBlf+IYLcmEBJKiSEmeorD3A=; b=Tq0xx76snsAIWJMCMefJNYzOBp9GG7RNOLUxwPazCWoYLgoANDrrWcP6HgdIL+oeug pDE71+wtCa1gcj/Amc+Znc8cyO4LfIGEk+RvNkMFaC8lkMTsHE7kewe5MvzWt73vCmZs p0dBkv0vqITqelFaatvkyFJWZbah1Qq9KZfRp9MOCV+0UMqw6IkYgOwe/nf6Ng8Tu9c3 f50tpf7XXFeupy8vHPoDt56fQG2BS1+ZocfhOXPrw2zYMFsCAFBadoRc5vvCJGB544T/ zMsoflyatVsi+UjBazXLYH56bQ9iq9aAj75YBxARxN/VHRlG+cpya3AkpJKxQ9OIezI5 w3tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719796568; x=1720401368; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/WihJp7JnQZqE8Q3tF8oBlf+IYLcmEBJKiSEmeorD3A=; b=KjCml5c3PBcjGuCva2CRiyIaM40evaQKWRfC3HGNBgnTQJerXGFDTPVfDM6XU5I/EX 30/yctbml3u5OgH9dRmONHMCCK2ZzDGo1PigxePVV9Cz4hU7b2PgiR/dXI4qcs1Bs59h i6qGC5nHrQ8xJoraVhUv643oAEHsaqN61rgqTFOFif/MxA5lQ0LyWdtEmsKRPrQ1cBFD xDo1LgL96cWGhafisZh9pcvENkvsLcbl79Zk9VaPPaWLjy1VTECHZWqsFNY5IfHXBBCl n8nVE1OHH/by5fA9Da4F2djph7DL42c3Vmlzg0bAMCHjso2IkmmqbyeQcxr9hvqvvOEs tT+g== X-Forwarded-Encrypted: i=1; AJvYcCXBffuJpL1txrb9nIvx8zev5IXjYfW0uE8GsMPlCOl4VGtsOcKTlRIJ7ehPCc6m8xvq1c0a/C8gPbsPwcUzq8yYFqYjBsRXYGSnYoPA X-Gm-Message-State: AOJu0YyKFN9XgD6NqMnjFmWxL5c6wNTecS5Ko2XSsZyT58dsDeCkq664 VAplZaBOOFoQ7s+1LZpqQN3WqKseFhD/utDt5E2OemFWaSFnCj9AuJWly+6UnAI= X-Google-Smtp-Source: AGHT+IEMQ/nIAAwcy5E9ZtnDihQLkeNPAxdYq4I132s7wFI5weLcV6ze43XfRapwnaVRCEDFola+Jw== X-Received: by 2002:a17:903:1cb:b0:1f9:e2c0:d962 with SMTP id d9443c01a7336-1fac7f1b66fmr116097455ad.31.1719796567869; Sun, 30 Jun 2024 18:16:07 -0700 (PDT) Received: from dread.disaster.area (pa49-179-32-121.pa.nsw.optusnet.com.au. [49.179.32.121]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac10c8bb3sm52206465ad.46.2024.06.30.18.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jun 2024 18:16:07 -0700 (PDT) Received: from dave by dread.disaster.area with local (Exim 4.96) (envelope-from ) id 1sO5eH-00HMwu-03; Mon, 01 Jul 2024 11:16:05 +1000 Date: Mon, 1 Jul 2024 11:16:05 +1000 From: Dave Chinner To: Zhang Yi Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, djwong@kernel.org, hch@infradead.org, brauner@kernel.org, chandanbabu@kernel.org, jack@suse.cz, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: Re: [PATCH -next v6 1/2] xfs: reserve blocks for truncating large realtime inode Message-ID: References: <20240618142112.1315279-1-yi.zhang@huaweicloud.com> <20240618142112.1315279-2-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240618142112.1315279-2-yi.zhang@huaweicloud.com> On Tue, Jun 18, 2024 at 10:21:11PM +0800, Zhang Yi wrote: > From: Zhang Yi > > When unaligned truncate down a big realtime file, xfs_truncate_page() > only zeros out the tail EOF block, __xfs_bunmapi() should split the tail > written extent and convert the later one that beyond EOF block to > unwritten, but it couldn't work as expected now since the reserved block > is zero in xfs_setattr_size(), this could expose stale data just after > commit '943bc0882ceb ("iomap: don't increase i_size if it's not a write > operation")'. > > If we truncate file that contains a large enough written extent: > > |< rxext >|< rtext >| > ...WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW > ^ (new EOF) ^ old EOF > > Since we only zeros out the tail of the EOF block, and > xfs_itruncate_extents()->..->__xfs_bunmapi() unmap the whole ailgned > extents, it becomes this state: > > |< rxext >| > ...WWWzWWWWWWWWWWWWW > ^ new EOF > > Then if we do an extending write like this, the blocks in the previous > tail extent becomes stale: > > |< rxext >| > ...WWWzSSSSSSSSSSSSS..........WWWWWWWWWWWWWWWWW > ^ old EOF ^ append start ^ new EOF > > Fix this by reserving XFS_DIOSTRAT_SPACE_RES blocks for big realtime > inode. This same problem is going to happen with force aligned allocations, right? i.e. it is a result of having a allocation block size larger than one filesystem block? If so, then.... > Signed-off-by: Zhang Yi > Reviewed-by: Christoph Hellwig > --- > fs/xfs/xfs_iops.c | 15 ++++++++++++++- > 1 file changed, 14 insertions(+), 1 deletion(-) > > diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c > index ff222827e550..a00dcbc77e12 100644 > --- a/fs/xfs/xfs_iops.c > +++ b/fs/xfs/xfs_iops.c > @@ -17,6 +17,8 @@ > #include "xfs_da_btree.h" > #include "xfs_attr.h" > #include "xfs_trans.h" > +#include "xfs_trans_space.h" > +#include "xfs_bmap_btree.h" > #include "xfs_trace.h" > #include "xfs_icache.h" > #include "xfs_symlink.h" > @@ -811,6 +813,7 @@ xfs_setattr_size( > struct xfs_trans *tp; > int error; > uint lock_flags = 0; > + uint resblks = 0; > bool did_zeroing = false; > > xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL); > @@ -917,7 +920,17 @@ xfs_setattr_size( > return error; > } > > - error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); > + /* > + * For realtime inode with more than one block rtextsize, we need the > + * block reservation for bmap btree block allocations/splits that can > + * happen since it could split the tail written extent and convert the > + * right beyond EOF one to unwritten. > + */ > + if (xfs_inode_has_bigrtalloc(ip)) > + resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0); .... should this be doing this generic check instead: if (xfs_inode_alloc_unitsize(ip) > 1) resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0); -Dave. -- Dave Chinner david@fromorbit.com