From nobody Sun Feb 8 13:10:59 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 3CF8934DB54 for ; Wed, 12 Nov 2025 19:36:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976213; cv=none; b=hK6YFW+Wd81qWJIEURFTiLRqeKaSZleeju0i2WFpcHOQ7+0E8wcPL63N/0qSTWRNuq4bz9vbMLX06NfWPjCRy4t3m57c1LdVmATUX/Y2eMOssUAo0+QTRVPKbQ1hrYJ+TfvT0hvRELAuYByfhU7u3cC3Y0DEoxgTVyTBtK6/9H8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976213; c=relaxed/simple; bh=DF+MVdRWcVUZ/4TkEyR6yaW+AaoXs/sGpAXtLMqbLGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CS8NC0amWpGPztCidmaRAAWCEZKo224Q6AiYR4N82VfAQgDcEBEk/p2KJ0z+Zk1ATc3k/TtfnIY3hj0k56BIK9bAHlYCyf1lc4Ev5Kq+eo3yuP1w7aPZb1DT//8VvnJMbA46+SbaLkx3K9kYRnkUFcVzFG4MG+KYFOFgYH0rvw8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 3448521B61; Wed, 12 Nov 2025 19:36:41 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none 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 1A3A73EA61; Wed, 12 Nov 2025 19:36:41 +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 CJW8BcnhFGm+YgAAD6G6ig (envelope-from ); Wed, 12 Nov 2025 19:36:41 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , David Sterba Cc: Daniel Vacek , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Omar Sandoval , Sweet Tea Dorminy Subject: [PATCH v6 1/8] btrfs: disable various operations on encrypted inodes Date: Wed, 12 Nov 2025 20:36:01 +0100 Message-ID: <20251112193611.2536093-2-neelx@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251112193611.2536093-1-neelx@suse.com> References: <20251112193611.2536093-1-neelx@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Queue-Id: 3448521B61 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.00 Content-Type: text/plain; charset="utf-8" From: Omar Sandoval Initially, only normal data extents will be encrypted. This change forbids various other bits: - allows reflinking only if both inodes have the same encryption status - disable inline data on encrypted inodes Signed-off-by: Omar Sandoval Signed-off-by: Sweet Tea Dorminy Signed-off-by: Josef Bacik Signed-off-by: Daniel Vacek --- v5 was 'Reviewed-by: Boris Burkov ' [1] but the rebase changed the code a bit so dropping. [1] https://lore.kernel.org/linux-btrfs/20240124195303.GC1789919@zen.locald= omain/ --- fs/btrfs/inode.c | 4 ++++ fs/btrfs/reflink.c | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 8737914e8552..b810e831fc23 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -592,6 +592,10 @@ static bool can_cow_file_range_inline(struct btrfs_ino= de *inode, if (size < i_size_read(&inode->vfs_inode)) return false; =20 + /* Encrypted file cannot be inlined. */ + if (IS_ENCRYPTED(&inode->vfs_inode)) + return false; + return true; } =20 diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c index 775a32a7953a..3c9c570d6493 100644 --- a/fs/btrfs/reflink.c +++ b/fs/btrfs/reflink.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 =20 #include +#include #include #include "ctree.h" #include "fs.h" @@ -789,6 +790,12 @@ static int btrfs_remap_file_range_prep(struct file *fi= le_in, loff_t pos_in, ASSERT(inode_in->vfs_inode.i_sb =3D=3D inode_out->vfs_inode.i_sb); } =20 + /* + * Can only reflink encrypted files if both files are encrypted. + */ + if (IS_ENCRYPTED(&inode_in->vfs_inode) !=3D IS_ENCRYPTED(&inode_out->vfs_= inode)) + return -EINVAL; + /* Don't make the dst file partly checksummed */ if ((inode_in->flags & BTRFS_INODE_NODATASUM) !=3D (inode_out->flags & BTRFS_INODE_NODATASUM)) { --=20 2.51.0 From nobody Sun Feb 8 13:10:59 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 B1B3F347FD0 for ; Wed, 12 Nov 2025 19:36:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976220; cv=none; b=lt4UiebcVUQx8aOhWqQplgVxbrUuSgNV5zlVerECEG7i4+QvQHBHvCMXvnZdhAKsXcsHiHRC0doteLI3wull92afvNt+YudwAFWE6ydbMgakhvGrPY8nIlrztaDCWAXrbjhBa5gEwGLpa1ipEKq5NGa4wUjXaRj/gzNAT9EiT30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976220; c=relaxed/simple; bh=xymZVfFCJfQzSdbUC7e/Ua6YrGiRBeqz+tdX5ASlweQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GB72A20qJX7ztsHKw/g6YA/9pm/ZyQzQwffSF2HiesC8/vDm21DHsj6kuRfLFhoUW0/HeIR8wuaJv2zsfSCAwF8NgNLkPMHhVViLThfu1U3WEvtn1ZlbTP2bcF0VsMPo9VKLO7bcQABHtCUnp0gY/0n8POidHzLRpMQ5YkTfacc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 9303221B5F; Wed, 12 Nov 2025 19:36:41 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none 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 781D63EA61; Wed, 12 Nov 2025 19:36:41 +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 0MbEHMnhFGm+YgAAD6G6ig (envelope-from ); Wed, 12 Nov 2025 19:36:41 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , David Sterba Cc: Daniel Vacek , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Sweet Tea Dorminy , Boris Burkov Subject: [PATCH v6 2/8] btrfs: disable verity on encrypted inodes Date: Wed, 12 Nov 2025 20:36:02 +0100 Message-ID: <20251112193611.2536093-3-neelx@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251112193611.2536093-1-neelx@suse.com> References: <20251112193611.2536093-1-neelx@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: 9303221B5F X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.00 X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] Content-Type: text/plain; charset="utf-8" From: Sweet Tea Dorminy Right now there isn't a way to encrypt things that aren't either filenames in directories or data on blocks on disk with extent encryption, so for now, disable verity usage with encryption on btrfs. Signed-off-by: Sweet Tea Dorminy Signed-off-by: Josef Bacik Reviewed-by: Boris Burkov --- No changes since v5, just a merge conflict due to cleanup in context. --- fs/btrfs/verity.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/verity.c b/fs/btrfs/verity.c index 16f5580cba55..06dfcb461f53 100644 --- a/fs/btrfs/verity.c +++ b/fs/btrfs/verity.c @@ -578,6 +578,9 @@ static int btrfs_begin_enable_verity(struct file *filp) =20 btrfs_assert_inode_locked(inode); =20 + if (IS_ENCRYPTED(&inode->vfs_inode)) + return -EOPNOTSUPP; + if (test_bit(BTRFS_INODE_VERITY_IN_PROGRESS, &inode->runtime_flags)) return -EBUSY; =20 --=20 2.51.0 From nobody Sun Feb 8 13:10:59 2026 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 EC07534D91E for ; Wed, 12 Nov 2025 19:36:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976205; cv=none; b=COCd4lmqaN7bK1IvYocHzYJAnWa4sQ7bb5hdDkRzwwkup2862ZPOD13Dt5K/B81SbkcfHCLduuvkfhWONdgw5pehm0AFR2P7vyQQCEq8SKZJJM7XewckcbafWpHlfLIAGxBUiPISxmxUqz2kx8gNHYSKshIzLbEKOgQoy+AeJTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976205; c=relaxed/simple; bh=cJRleMYkhB7ftVmOOWDmYy5Xb7gMv+BWoTmEtMo3il0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XTok5axa8TEjSHGyHTA6fDoJD5rR6/+U/XXwgMmjMRr5iUrzn8vIAvqlyvCUgR8q4FLdE4iKzH/JW+Mb4Bw33eCiXRyypomvj0VNzT+t1hS5SfK0ncIJlT1rH5/RC61NQ1aTlBGHi40AT949a/78Xkc+QqZRTgsodxyC8cfht4A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out2.suse.de (Postfix) with ESMTPS id 3A00C1F7A1; Wed, 12 Nov 2025 19:36:42 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none 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 2403D3EA61; Wed, 12 Nov 2025 19:36:42 +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 6IBNCMrhFGm+YgAAD6G6ig (envelope-from ); Wed, 12 Nov 2025 19:36:42 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , David Sterba Cc: Daniel Vacek , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 3/8] btrfs: add a bio argument to btrfs_csum_one_bio Date: Wed, 12 Nov 2025 20:36:03 +0100 Message-ID: <20251112193611.2536093-4-neelx@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251112193611.2536093-1-neelx@suse.com> References: <20251112193611.2536093-1-neelx@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: 3A00C1F7A1 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.00 X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] Content-Type: text/plain; charset="utf-8" From: Josef Bacik We only ever needed the bbio in btrfs_csum_one_bio, since that has the bio embedded in it. However with encryption we'll have a different bio with the encrypted data in it, and the original bbio. Update btrfs_csum_one_bio to take the bio we're going to csum as an argument, which will allow us to csum the encrypted bio and stuff the csums into the corresponding bbio to be used later when the IO completes. Signed-off-by: Josef Bacik Signed-off-by: Daniel Vacek --- Compared to v5 this needed to adapt to recent async csum changes. --- fs/btrfs/bio.c | 4 ++-- fs/btrfs/bio.h | 1 + fs/btrfs/file-item.c | 17 ++++++++--------- fs/btrfs/file-item.h | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index a73652b8724a..a69174b2b6b6 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -542,9 +542,9 @@ static int btrfs_bio_csum(struct btrfs_bio *bbio) if (bbio->bio.bi_opf & REQ_META) return btree_csum_one_bio(bbio); #ifdef CONFIG_BTRFS_EXPERIMENTAL - return btrfs_csum_one_bio(bbio, true); + return btrfs_csum_one_bio(bbio, &bbio->bio, true); #else - return btrfs_csum_one_bio(bbio, false); + return btrfs_csum_one_bio(bbio, &bbio->bio, false); #endif } =20 diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h index deaeea3becf4..c5a6c66d51a0 100644 --- a/fs/btrfs/bio.h +++ b/fs/btrfs/bio.h @@ -58,6 +58,7 @@ struct btrfs_bio { struct btrfs_ordered_sum *sums; struct work_struct csum_work; struct completion csum_done; + struct bio *csum_bio; struct bvec_iter csum_saved_iter; u64 orig_physical; }; diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 72be3ede0edf..474949074da8 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -765,21 +765,19 @@ int btrfs_lookup_csums_bitmap(struct btrfs_root *root= , struct btrfs_path *path, return ret; } =20 -static void csum_one_bio(struct btrfs_bio *bbio, struct bvec_iter *src) +static void csum_one_bio(struct btrfs_bio *bbio, struct bio *bio, struct b= vec_iter *iter) { struct btrfs_inode *inode =3D bbio->inode; struct btrfs_fs_info *fs_info =3D inode->root->fs_info; SHASH_DESC_ON_STACK(shash, fs_info->csum_shash); - struct bio *bio =3D &bbio->bio; struct btrfs_ordered_sum *sums =3D bbio->sums; - struct bvec_iter iter =3D *src; phys_addr_t paddr; const u32 blocksize =3D fs_info->sectorsize; int index =3D 0; =20 shash->tfm =3D fs_info->csum_shash; =20 - btrfs_bio_for_each_block(paddr, bio, &iter, blocksize) { + btrfs_bio_for_each_block(paddr, bio, iter, blocksize) { btrfs_calculate_block_csum(fs_info, paddr, sums->sums + index); index +=3D fs_info->csum_size; } @@ -791,19 +789,18 @@ static void csum_one_bio_work(struct work_struct *wor= k) =20 ASSERT(btrfs_op(&bbio->bio) =3D=3D BTRFS_MAP_WRITE); ASSERT(bbio->async_csum =3D=3D true); - csum_one_bio(bbio, &bbio->csum_saved_iter); + csum_one_bio(bbio, bbio->csum_bio, &bbio->csum_saved_iter); complete(&bbio->csum_done); } =20 /* * Calculate checksums of the data contained inside a bio. */ -int btrfs_csum_one_bio(struct btrfs_bio *bbio, bool async) +int btrfs_csum_one_bio(struct btrfs_bio *bbio, struct bio *bio, bool async) { struct btrfs_ordered_extent *ordered =3D bbio->ordered; struct btrfs_inode *inode =3D bbio->inode; struct btrfs_fs_info *fs_info =3D inode->root->fs_info; - struct bio *bio =3D &bbio->bio; struct btrfs_ordered_sum *sums; unsigned nofs_flag; =20 @@ -822,12 +819,14 @@ int btrfs_csum_one_bio(struct btrfs_bio *bbio, bool a= sync) btrfs_add_ordered_sum(ordered, sums); =20 if (!async) { - csum_one_bio(bbio, &bbio->bio.bi_iter); + struct bvec_iter iter =3D bio->bi_iter; + csum_one_bio(bbio, bio, &iter); return 0; } init_completion(&bbio->csum_done); bbio->async_csum =3D true; - bbio->csum_saved_iter =3D bbio->bio.bi_iter; + bbio->csum_bio =3D bio; + bbio->csum_saved_iter =3D bio->bi_iter; INIT_WORK(&bbio->csum_work, csum_one_bio_work); schedule_work(&bbio->csum_work); return 0; diff --git a/fs/btrfs/file-item.h b/fs/btrfs/file-item.h index 5645c5e3abdb..d16fd2144552 100644 --- a/fs/btrfs/file-item.h +++ b/fs/btrfs/file-item.h @@ -64,7 +64,7 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *t= rans, int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_ordered_sum *sums); -int btrfs_csum_one_bio(struct btrfs_bio *bbio, bool async); +int btrfs_csum_one_bio(struct btrfs_bio *bbio, struct bio *bio, bool async= ); int btrfs_alloc_dummy_sum(struct btrfs_bio *bbio); int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, struct list_head *list, int search_commit, --=20 2.51.0 From nobody Sun Feb 8 13:10:59 2026 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 252573538BF for ; Wed, 12 Nov 2025 19:36:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976213; cv=none; b=mV3Rghw2e0kl5qzrGGNFdrtX+mRF09Y2DM/PST5gXY+UOsVRKgy/LgkF5nHEr2bip62FkzbOqKCPIaF/5FnH3gnBjkK0io/gYr0L4bRvK7+kF2lDP/WRJHl0G1/PDNgZG2YGP3kqXiJHvM84HVKOWTvh2appPNsrCYPBiCwtYFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976213; c=relaxed/simple; bh=Qq4Tp00GXzNvEm9j0Ogoy9B+mJlCtDLzO+gAdCsskZk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AXU0lCba6Xxx4oAlEO67Alr4Qx+2eCi4zPj+5USulGAIVIvWfGKGMKFCJ7/R3a28ONHSAErj273itsNxRNY+TeaP6JWLw/GJXcgRRxQObhTSsovzgGd/MUcs3lZJnpwcBE6DPx/nWj8k5GgQzrPY08fem4/eZkL1V+Zzq8oyvlg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out2.suse.de (Postfix) with ESMTPS id BF7CE1F7BD; Wed, 12 Nov 2025 19:36:42 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none 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 A8A2D3EA61; Wed, 12 Nov 2025 19:36:42 +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 0NyiKMrhFGm+YgAAD6G6ig (envelope-from ); Wed, 12 Nov 2025 19:36:42 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , David Sterba Cc: Daniel Vacek , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 4/8] btrfs: add orig_logical to btrfs_bio Date: Wed, 12 Nov 2025 20:36:04 +0100 Message-ID: <20251112193611.2536093-5-neelx@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251112193611.2536093-1-neelx@suse.com> References: <20251112193611.2536093-1-neelx@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: BF7CE1F7BD X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.00 X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] Content-Type: text/plain; charset="utf-8" From: Josef Bacik When checksumming the encrypted bio on writes we need to know which logical address this checksum is for. At the point where we get the encrypted bio the bi_sector is the physical location on the target disk, so we need to save the original logical offset in the btrfs_bio. Then we can use this when csum'ing the bio instead of the bio->iter.bi_sector. Signed-off-by: Josef Bacik --- No code changes other than context since v5. --- fs/btrfs/bio.c | 10 ++++++++++ fs/btrfs/bio.h | 2 ++ fs/btrfs/file-item.c | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index a69174b2b6b6..aba452dd9904 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -94,6 +94,8 @@ static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_= info *fs_info, if (bbio_has_ordered_extent(bbio)) { refcount_inc(&orig_bbio->ordered->refs); bbio->ordered =3D orig_bbio->ordered; + bbio->orig_logical =3D orig_bbio->orig_logical; + orig_bbio->orig_logical +=3D map_length; } bbio->csum_search_commit_root =3D orig_bbio->csum_search_commit_root; atomic_inc(&orig_bbio->pending_ios); @@ -726,6 +728,14 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio,= int mirror_num) goto end_bbio; } =20 + /* + * For fscrypt writes we will get the encrypted bio after we've + * remapped our bio to the physical disk location, so we need to + * save the original bytenr so we know what we're checksumming. + */ + if (bio_op(bio) =3D=3D REQ_OP_WRITE && is_data_bbio(bbio)) + bbio->orig_logical =3D logical; + map_length =3D min(map_length, length); if (use_append) map_length =3D btrfs_append_map_length(bbio, map_length); diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h index c5a6c66d51a0..5015e327dbd9 100644 --- a/fs/btrfs/bio.h +++ b/fs/btrfs/bio.h @@ -52,6 +52,7 @@ struct btrfs_bio { * - pointer to the checksums for this bio * - original physical address from the allocator * (for zone append only) + * - original logical address, used for checksumming fscrypt bios. */ struct { struct btrfs_ordered_extent *ordered; @@ -61,6 +62,7 @@ struct btrfs_bio { struct bio *csum_bio; struct bvec_iter csum_saved_iter; u64 orig_physical; + u64 orig_logical; }; =20 /* For metadata reads: parentness verification. */ diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 474949074da8..d2ecd26727ac 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -812,7 +812,7 @@ int btrfs_csum_one_bio(struct btrfs_bio *bbio, struct b= io *bio, bool async) if (!sums) return -ENOMEM; =20 - sums->logical =3D bio->bi_iter.bi_sector << SECTOR_SHIFT; + sums->logical =3D bbio->orig_logical; sums->len =3D bio->bi_iter.bi_size; INIT_LIST_HEAD(&sums->list); bbio->sums =3D sums; --=20 2.51.0 From nobody Sun Feb 8 13:10:59 2026 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 5C499354AE1 for ; Wed, 12 Nov 2025 19:36:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976220; cv=none; b=WSOXaeXzf8E4l3OPKj+BWpM2tq16coGuooV5EEvPQ1zKmDwk60AEHghREQqX80AxtnC+P85agpCBQP9ai7iUtdDxYMvC8yqc/fw//1KMXdY0oMBygZF+iGvwKWgbKOndMqfhmct6R/SsdBaYcy++5DXpmF509UwzyNDM+Fcyd7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976220; c=relaxed/simple; bh=PFv1OmBfIMgSJ3pXO9p+5/cBcBjYjG4mM7vYgMXZFLo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rBMj/4Rnc2KHZCUrZz+wns/wvpRwUZOPlIBnHlpKGr6oNS9YxcRX9o/oc5nZ/MeRVBVE6ahKPC8e+KQt2CLLQ1O89MhvcUof0yn1zzPyW4eGYpOEbbhmgLSve2E/833AJsoIIkLnfeG04bpaxuG8nPdQnoM2XuZo5FmQcVVtWpU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out2.suse.de (Postfix) with ESMTPS id 249FB1F798; Wed, 12 Nov 2025 19:36:43 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none 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 0D8113EA61; Wed, 12 Nov 2025 19:36:43 +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 0LvQAsvhFGm+YgAAD6G6ig (envelope-from ); Wed, 12 Nov 2025 19:36:43 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , David Sterba Cc: Daniel Vacek , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 5/8] btrfs: don't rewrite ret from inode_permission Date: Wed, 12 Nov 2025 20:36:05 +0100 Message-ID: <20251112193611.2536093-6-neelx@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251112193611.2536093-1-neelx@suse.com> References: <20251112193611.2536093-1-neelx@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: 249FB1F798 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.00 X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] Content-Type: text/plain; charset="utf-8" From: Josef Bacik In our user safe ino resolve ioctl we'll just turn any ret into -EACCES from inode_permission. This is redundant, and could potentially be wrong if we had an ENOMEM in the security layer or some such other error, so simply return the actual return value. Signed-off-by: Josef Bacik --- No changes since v5 other than context. --- fs/btrfs/ioctl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index b524db8a4973..2973230f2988 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1910,10 +1910,8 @@ static int btrfs_search_path_in_tree_user(struct mnt= _idmap *idmap, ret =3D inode_permission(idmap, &temp_inode->vfs_inode, MAY_READ | MAY_EXEC); iput(&temp_inode->vfs_inode); - if (ret) { - ret =3D -EACCES; + if (ret) goto out_put; - } =20 if (key.offset =3D=3D upper_limit) break; --=20 2.51.0 From nobody Sun Feb 8 13:10:59 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 B34FF34E75C for ; Wed, 12 Nov 2025 19:37:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976228; cv=none; b=jugbeBJ1Z/0ga6zmoOwBaL8tBq7r4HnEKr3pwDLi+CK2IoaVP6xXJKMT5s+ytkMINflNHHyh3DDK6/NbkNcDCqY6mHsVMbOy6usum7sjmyo07t/1bp1iHlprSsrZwhzPLXNfHZM/tCBR2l3BozJlHoBE+b+HxnwcOw3WwURXXZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976228; c=relaxed/simple; bh=z8FtcWKnUX7aVQ3mV9pa8Goe4n8I3HewXIT6tjCipgc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uNDaG7KNrkOel9gEmNSSViwc03aWUR+t4+a4MShLo3RQ62mNA/O9UARPfiYrAxW2WHIA1Yla6ZfoyVS/7tg9Z2KjNW0pdvep8WLTu8Sp1jZn9xCziiupn5tOkzR3xH4kWTiiNYAe6x80KG0ENaTabqaxacyefnSg8QFJbEutQtA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 8499221B66; Wed, 12 Nov 2025 19:36:43 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none 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 6F29D3EA61; Wed, 12 Nov 2025 19:36:43 +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 kC58GsvhFGm+YgAAD6G6ig (envelope-from ); Wed, 12 Nov 2025 19:36:43 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , David Sterba Cc: Daniel Vacek , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 6/8] btrfs: move inode_to_path higher in backref.c Date: Wed, 12 Nov 2025 20:36:06 +0100 Message-ID: <20251112193611.2536093-7-neelx@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251112193611.2536093-1-neelx@suse.com> References: <20251112193611.2536093-1-neelx@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Queue-Id: 8499221B66 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.00 Content-Type: text/plain; charset="utf-8" From: Josef Bacik We have a prototype and then the definition lower below, we don't need to do this, simply move the function to where the prototype is. Signed-off-by: Josef Bacik --- No code changes since v5. --- fs/btrfs/backref.c | 68 ++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index eff2d388a706..56e177941da4 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -2574,8 +2574,39 @@ int iterate_inodes_from_logical(u64 logical, struct = btrfs_fs_info *fs_info, return iterate_extent_inodes(&walk_ctx, false, build_ino_list, ctx); } =20 +/* + * returns 0 if the path could be dumped (probably truncated) + * returns <0 in case of an error + */ static int inode_to_path(u64 inum, u32 name_len, unsigned long name_off, - struct extent_buffer *eb, struct inode_fs_paths *ipath); + struct extent_buffer *eb, struct inode_fs_paths *ipath) +{ + char *fspath; + char *fspath_min; + int i =3D ipath->fspath->elem_cnt; + const int s_ptr =3D sizeof(char *); + u32 bytes_left; + + bytes_left =3D ipath->fspath->bytes_left > s_ptr ? ipath->fspath->bytes_l= eft - s_ptr : 0; + + fspath_min =3D (char *)ipath->fspath->val + (i + 1) * s_ptr; + fspath =3D btrfs_ref_to_path(ipath->fs_root, ipath->btrfs_path, name_len, + name_off, eb, inum, fspath_min, bytes_left); + if (IS_ERR(fspath)) + return PTR_ERR(fspath); + + if (fspath > fspath_min) { + ipath->fspath->val[i] =3D (u64)(unsigned long)fspath; + ++ipath->fspath->elem_cnt; + ipath->fspath->bytes_left =3D fspath - fspath_min; + } else { + ++ipath->fspath->elem_missed; + ipath->fspath->bytes_missing +=3D fspath_min - fspath; + ipath->fspath->bytes_left =3D 0; + } + + return 0; +} =20 static int iterate_inode_refs(u64 inum, struct inode_fs_paths *ipath) { @@ -2700,41 +2731,6 @@ static int iterate_inode_extrefs(u64 inum, struct in= ode_fs_paths *ipath) return ret; } =20 -/* - * returns 0 if the path could be dumped (probably truncated) - * returns <0 in case of an error - */ -static int inode_to_path(u64 inum, u32 name_len, unsigned long name_off, - struct extent_buffer *eb, struct inode_fs_paths *ipath) -{ - char *fspath; - char *fspath_min; - int i =3D ipath->fspath->elem_cnt; - const int s_ptr =3D sizeof(char *); - u32 bytes_left; - - bytes_left =3D ipath->fspath->bytes_left > s_ptr ? - ipath->fspath->bytes_left - s_ptr : 0; - - fspath_min =3D (char *)ipath->fspath->val + (i + 1) * s_ptr; - fspath =3D btrfs_ref_to_path(ipath->fs_root, ipath->btrfs_path, name_len, - name_off, eb, inum, fspath_min, bytes_left); - if (IS_ERR(fspath)) - return PTR_ERR(fspath); - - if (fspath > fspath_min) { - ipath->fspath->val[i] =3D (u64)(unsigned long)fspath; - ++ipath->fspath->elem_cnt; - ipath->fspath->bytes_left =3D fspath - fspath_min; - } else { - ++ipath->fspath->elem_missed; - ipath->fspath->bytes_missing +=3D fspath_min - fspath; - ipath->fspath->bytes_left =3D 0; - } - - return 0; -} - /* * this dumps all file system paths to the inode into the ipath struct, pr= ovided * is has been created large enough. each path is zero-terminated and acce= ssed --=20 2.51.0 From nobody Sun Feb 8 13:10:59 2026 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 A1DA834E74B for ; Wed, 12 Nov 2025 19:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976227; cv=none; b=BqNay5L2tg59hUL0m6lW6i0T9dfrNXNYuPx9EAD0S8UNZkFiSmGTy48MEfMeYYx4tqJjeyugWAlwonYz/73WJdX2WxfVcWsD+MgpY8PdZvQAO8jSaYOsTtiOvm6vmDqbriR+U2y0fHTWL/0BpEEY0DLi3Wh19SymJlpNw7LqDYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976227; c=relaxed/simple; bh=vQZZmF+r/N5FK4W+zNe8l6ZtC1vXlbuUXtui9c9aRZY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R5UUEkJtkm56fMEg55duwkn6gObS6VM+I+jtjbzSuYDvJipd7kBB9FQGXBaDwqMWl78Z/RVJsemM29/AUCi/XH0yeX3HGImCSApiXTCCaYQ5G5HViplwn4T90fXAWGFLgZTKM4BMhpJT/RIyy3ODjLUjd0v9KxPxbIAdnHkfnMQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out2.suse.de (Postfix) with ESMTPS id E369E1F7CF; Wed, 12 Nov 2025 19:36:43 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none 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 CD5603EA61; Wed, 12 Nov 2025 19:36:43 +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 ED13McvhFGm+YgAAD6G6ig (envelope-from ); Wed, 12 Nov 2025 19:36:43 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , David Sterba Cc: Daniel Vacek , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 7/8] btrfs: don't search back for dir inode item in INO_LOOKUP_USER Date: Wed, 12 Nov 2025 20:36:07 +0100 Message-ID: <20251112193611.2536093-8-neelx@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251112193611.2536093-1-neelx@suse.com> References: <20251112193611.2536093-1-neelx@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Queue-Id: E369E1F7CF X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.00 Content-Type: text/plain; charset="utf-8" From: Josef Bacik We don't need to search back to the inode item, the directory inode number is in key.offset, so simply use that. If we can't find the directory we'll get an ENOENT at the iget. Signed-off-by: Josef Bacik --- Since v5 resolved rebase merge conflicts due to changes in API, dropping the sb parameter in btrfs_iget(). --- fs/btrfs/ioctl.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 2973230f2988..d323fc351c00 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1822,7 +1822,7 @@ static int btrfs_search_path_in_tree_user(struct mnt_= idmap *idmap, struct btrfs_root_ref *rref; struct btrfs_root *root =3D NULL; struct btrfs_path *path; - struct btrfs_key key, key2; + struct btrfs_key key; struct extent_buffer *leaf; char *ptr; int slot; @@ -1877,24 +1877,6 @@ static int btrfs_search_path_in_tree_user(struct mnt= _idmap *idmap, read_extent_buffer(leaf, ptr, (unsigned long)(iref + 1), len); =20 - /* Check the read+exec permission of this directory */ - ret =3D btrfs_previous_item(root, path, dirid, - BTRFS_INODE_ITEM_KEY); - if (ret < 0) { - goto out_put; - } else if (ret > 0) { - ret =3D -ENOENT; - goto out_put; - } - - leaf =3D path->nodes[0]; - slot =3D path->slots[0]; - btrfs_item_key_to_cpu(leaf, &key2, slot); - if (key2.objectid !=3D dirid) { - ret =3D -ENOENT; - goto out_put; - } - /* * We don't need the path anymore, so release it and * avoid deadlocks and lockdep warnings in case @@ -1902,11 +1884,12 @@ static int btrfs_search_path_in_tree_user(struct mn= t_idmap *idmap, * btree and lock the same leaf. */ btrfs_release_path(path); - temp_inode =3D btrfs_iget(key2.objectid, root); + temp_inode =3D btrfs_iget(key.offset, root); if (IS_ERR(temp_inode)) { ret =3D PTR_ERR(temp_inode); goto out_put; } + /* Check the read+exec permission of this directory */ ret =3D inode_permission(idmap, &temp_inode->vfs_inode, MAY_READ | MAY_EXEC); iput(&temp_inode->vfs_inode); --=20 2.51.0 From nobody Sun Feb 8 13:10:59 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 E2CCE2798ED for ; Wed, 12 Nov 2025 19:37:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976234; cv=none; b=Lw47v75oY9T1LuYprw44vPmfdDkBaqWaRdrSXn1G4L1ygCpckE0gx0GrD7iwlpvdnN0PFQKNzuX0ebsatOXY58USOdWy2nygTUQC2HKrqWqt/3rxcP3X3aOBsWjfGdku/efP9mHh3gI3Cx6/o+PT5WxKsKdfIXwRN9krzYWk/JM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976234; c=relaxed/simple; bh=4uUxavDDm1MyVNq8AVQrYfBBwqALCkU5jsIrs/D2RT0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EXYbz5EsqeNCuNRni34SEDta+jwfg0Hmx5dszLGOcQRITdJaPpLROhheKq0GojjDJEixm8imgJazNB5IM3w6+UWQG9bdbMKBAUo33cDgQeZmtXlKtAShnnxZtD95MVRxoEBPtmPzdpl8itJNU9DuFJhLQ8Nt0N/8gfkqgKVKcxA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 78EA921B67; Wed, 12 Nov 2025 19:36:44 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none 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 62E723EA61; Wed, 12 Nov 2025 19:36:44 +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 6K6SF8zhFGm+YgAAD6G6ig (envelope-from ); Wed, 12 Nov 2025 19:36:44 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , David Sterba Cc: Daniel Vacek , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 8/8] btrfs: set the appropriate free space settings in reconfigure Date: Wed, 12 Nov 2025 20:36:08 +0100 Message-ID: <20251112193611.2536093-9-neelx@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251112193611.2536093-1-neelx@suse.com> References: <20251112193611.2536093-1-neelx@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Queue-Id: 78EA921B67 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.00 Content-Type: text/plain; charset="utf-8" From: Josef Bacik btrfs/330 uncovered a problem where we were accidentally turning off the free space tree when we do the transition from ro->rw. This happens because we don't update Signed-off-by: Josef Bacik --- Since v5 just a rebase conflict with changing API of mount_opt flags being 64bit now. --- fs/btrfs/disk-io.c | 2 +- fs/btrfs/super.c | 28 +++++++++++++++------------- fs/btrfs/super.h | 3 ++- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 6a1fa3b08b3f..3bc7a773b900 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3399,7 +3399,7 @@ int __cold open_ctree(struct super_block *sb, struct = btrfs_fs_devices *fs_device * Handle the space caching options appropriately now that we have the * super block loaded and validated. */ - btrfs_set_free_space_cache_settings(fs_info); + btrfs_set_free_space_cache_settings(fs_info, &fs_info->mount_opt); =20 if (!btrfs_check_options(fs_info, &fs_info->mount_opt, sb->s_flags)) { ret =3D -EINVAL; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 4ffd7059e27a..f8759b856174 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -723,10 +723,10 @@ bool btrfs_check_options(const struct btrfs_fs_info *= info, } =20 /* - * This is subtle, we only call this during open_ctree(). We need to pre-= load - * the mount options with the on-disk settings. Before the new mount API = took - * effect we would do this on mount and remount. With the new mount API w= e'll - * only do this on the initial mount. + * Because we have an odd set of behavior with turning on and off the spac= e cache + * and free space tree we have to call this before we start the mount oper= ation + * after we load the super, or before we start remount. This is to make s= ure we + * have the proper free space settings in place if the user didn't specify= any. * * This isn't a change in behavior, because we're using the current state = of the * file system to set the current mount options. If you mounted with spec= ial @@ -734,15 +734,16 @@ bool btrfs_check_options(const struct btrfs_fs_info *= info, * settings, because mounting without these features cleared the on-disk * settings, so this being called on re-mount is not needed. */ -void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info) +void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info, + unsigned long long *mount_opt) { if (fs_info->sectorsize < PAGE_SIZE) { - btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE); - if (!btrfs_test_opt(fs_info, FREE_SPACE_TREE)) { + btrfs_clear_opt(*mount_opt, SPACE_CACHE); + if (!btrfs_raw_test_opt(*mount_opt, FREE_SPACE_TREE)) { btrfs_info(fs_info, "forcing free space tree for sector size %u with page size %lu", fs_info->sectorsize, PAGE_SIZE); - btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE); + btrfs_set_opt(*mount_opt, FREE_SPACE_TREE); } } =20 @@ -750,7 +751,7 @@ void btrfs_set_free_space_cache_settings(struct btrfs_f= s_info *fs_info) * At this point our mount options are populated, so we only mess with * these settings if we don't have any settings already. */ - if (btrfs_test_opt(fs_info, FREE_SPACE_TREE)) + if (btrfs_raw_test_opt(*mount_opt, FREE_SPACE_TREE)) return; =20 if (btrfs_is_zoned(fs_info) && @@ -760,10 +761,10 @@ void btrfs_set_free_space_cache_settings(struct btrfs= _fs_info *fs_info) return; } =20 - if (btrfs_test_opt(fs_info, SPACE_CACHE)) + if (btrfs_raw_test_opt(*mount_opt, SPACE_CACHE)) return; =20 - if (btrfs_test_opt(fs_info, NOSPACECACHE)) + if (btrfs_raw_test_opt(*mount_opt, NOSPACECACHE)) return; =20 /* @@ -771,9 +772,9 @@ void btrfs_set_free_space_cache_settings(struct btrfs_f= s_info *fs_info) * them ourselves based on the state of the file system. */ if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) - btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE); + btrfs_set_opt(*mount_opt, FREE_SPACE_TREE); else if (btrfs_free_space_cache_v1_active(fs_info)) - btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE); + btrfs_set_opt(*mount_opt, SPACE_CACHE); } =20 static void set_device_specific_options(struct btrfs_fs_info *fs_info) @@ -1523,6 +1524,7 @@ static int btrfs_reconfigure(struct fs_context *fc) =20 sync_filesystem(sb); set_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); + btrfs_set_free_space_cache_settings(fs_info, &ctx->mount_opt); =20 if (!btrfs_check_options(fs_info, &ctx->mount_opt, fc->sb_flags)) return -EINVAL; diff --git a/fs/btrfs/super.h b/fs/btrfs/super.h index d80a86acfbbe..584f428d36e2 100644 --- a/fs/btrfs/super.h +++ b/fs/btrfs/super.h @@ -16,7 +16,8 @@ bool btrfs_check_options(const struct btrfs_fs_info *info, int btrfs_sync_fs(struct super_block *sb, int wait); char *btrfs_get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info, u64 subvol_objectid); -void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info); +void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info, + unsigned long long *mount_opt); =20 static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) { --=20 2.51.0