From nobody Mon Feb 9 16:17:22 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 8478F4418CB for ; Fri, 6 Feb 2026 18:24:44 +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=1770402284; cv=none; b=WSQJq8YPaLoG5Hz0U4ToeJEmUoIwsdXK34B7KVmheeUARvli1UStCPtDdYZVY+vUUV8zJpilKZoNvrflASVI0ZblN76wOs5cyrukSRYbNogl3stf2xktrlaj/zdUgFyXwrO234P5RR06wPRRAqeGx+r/l6GTWnkCVAfQzE/b344= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770402284; c=relaxed/simple; bh=57zrBcpTNnZ9dSBcH18Ql37o6I66oeN+cim/q8qd3Bo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eA+mA04Tf2DhPtKJQ0Nb+I1UCVkU0csqN9nw11VBy5fLGIvgeq8mmkFx0KclUlzFEpgu842ZBzASvv+u7yk0ohhHtyYzc4LgwwWTMCtCcWF3rQ4x78Zk2LlVe6Xs018HyNZm98W+Wj8g1uIMxq8yTu/Fil7YhEWlkJ5eBUuTxdE= 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 E14D95BD2B; Fri, 6 Feb 2026 18:24:05 +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 B22DC3EA63; Fri, 6 Feb 2026 18:24:05 +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 mNQIK8UxhmkTCQAAD6G6ig (envelope-from ); Fri, 06 Feb 2026 18:24:05 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Jens Axboe , David Sterba Cc: linux-block@vger.kernel.org, Daniel Vacek , linux-fscrypt@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Sweet Tea Dorminy Subject: [PATCH v6 18/43] btrfs: set file extent encryption excplicitly Date: Fri, 6 Feb 2026 19:22:50 +0100 Message-ID: <20260206182336.1397715-19-neelx@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260206182336.1397715-1-neelx@suse.com> References: <20260206182336.1397715-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-Score: -4.00 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Queue-Id: E14D95BD2B X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Flag: NO Content-Type: text/plain; charset="utf-8" From: Sweet Tea Dorminy This puts the long-preserved 1-byte encryption field to work, storing whether the extent is encrypted. Update the tree-checker to allow for the encryption bit to be set to our valid types. Signed-off-by: Sweet Tea Dorminy Signed-off-by: Josef Bacik Signed-off-by: Daniel Vacek --- v5: https://lore.kernel.org/linux-btrfs/1bf1cb768bc8bc54b3855e271412077c60f= 23c50.1706116485.git.josef@toxicpanda.com/ * No changes since. --- fs/btrfs/accessors.h | 2 ++ fs/btrfs/inode.c | 6 ++++-- fs/btrfs/tree-checker.c | 8 +++++--- fs/btrfs/tree-log.c | 2 ++ include/uapi/linux/btrfs_tree.h | 8 +++++++- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/accessors.h b/fs/btrfs/accessors.h index 8938357fcb40..09ed68fa2041 100644 --- a/fs/btrfs/accessors.h +++ b/fs/btrfs/accessors.h @@ -907,6 +907,8 @@ BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_byt= es, struct btrfs_file_extent_item, disk_num_bytes, 64); BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression, struct btrfs_file_extent_item, compression, 8); +BTRFS_SETGET_STACK_FUNCS(stack_file_extent_encryption, + struct btrfs_file_extent_item, encryption, 8); =20 =20 BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, = 8); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 79f0b67249de..758dde148be6 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3123,7 +3123,8 @@ static int insert_ordered_extent_file_extent(struct b= trfs_trans_handle *trans, btrfs_set_stack_file_extent_num_bytes(&stack_fi, num_bytes); btrfs_set_stack_file_extent_ram_bytes(&stack_fi, ram_bytes); btrfs_set_stack_file_extent_compression(&stack_fi, oe->compress_type); - /* Encryption and other encoding is reserved and all 0 */ + btrfs_set_stack_file_extent_encryption(&stack_fi, BTRFS_ENCRYPTION_NONE); + /* Other encoding is reserved and always 0 */ =20 /* * For delalloc, when completing an ordered extent we update the inode's @@ -9205,7 +9206,8 @@ static struct btrfs_trans_handle *insert_prealloc_fil= e_extent( btrfs_set_stack_file_extent_num_bytes(&stack_fi, len); btrfs_set_stack_file_extent_ram_bytes(&stack_fi, len); btrfs_set_stack_file_extent_compression(&stack_fi, BTRFS_COMPRESS_NONE); - /* Encryption and other encoding is reserved and all 0 */ + btrfs_set_stack_file_extent_encryption(&stack_fi, BTRFS_ENCRYPTION_NONE); + /* Other encoding is reserved and always 0 */ =20 ret =3D btrfs_qgroup_release_data(inode, file_offset, len, &qgroup_releas= ed); if (ret < 0) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 452394b34d01..9675dbcd78a3 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -213,6 +213,7 @@ static int check_extent_data_item(struct extent_buffer = *leaf, u32 sectorsize =3D fs_info->sectorsize; u32 item_size =3D btrfs_item_size(leaf, slot); u64 extent_end; + u8 policy; =20 if (unlikely(!IS_ALIGNED(key->offset, sectorsize))) { file_extent_err(leaf, slot, @@ -264,10 +265,11 @@ static int check_extent_data_item(struct extent_buffe= r *leaf, BTRFS_NR_COMPRESS_TYPES - 1); return -EUCLEAN; } - if (unlikely(btrfs_file_extent_encryption(leaf, fi))) { + policy =3D btrfs_file_extent_encryption(leaf, fi); + if (unlikely(policy >=3D BTRFS_NR_ENCRYPTION_TYPES)) { file_extent_err(leaf, slot, - "invalid encryption for file extent, have %u expect 0", - btrfs_file_extent_encryption(leaf, fi)); + "invalid encryption for file extent, have %u expect range [0, %u]", + policy, BTRFS_NR_ENCRYPTION_TYPES - 1); return -EUCLEAN; } if (btrfs_file_extent_type(leaf, fi) =3D=3D BTRFS_FILE_EXTENT_INLINE) { diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index d6d3ce41fc3e..118dd1888996 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -5123,6 +5123,7 @@ static int log_one_extent(struct btrfs_trans_handle *= trans, u64 block_start =3D btrfs_extent_map_block_start(em); u64 block_len; int ret; + u8 encryption =3D BTRFS_ENCRYPTION_NONE; =20 btrfs_set_stack_file_extent_generation(&fi, trans->transid); if (em->flags & EXTENT_FLAG_PREALLOC) @@ -5144,6 +5145,7 @@ static int log_one_extent(struct btrfs_trans_handle *= trans, btrfs_set_stack_file_extent_num_bytes(&fi, em->len); btrfs_set_stack_file_extent_ram_bytes(&fi, em->ram_bytes); btrfs_set_stack_file_extent_compression(&fi, compress_type); + btrfs_set_stack_file_extent_encryption(&fi, encryption); =20 ret =3D log_extent_csums(trans, inode, log, em, ctx); if (ret) diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tre= e.h index 02b1ab1f7858..cb8dbcc612e9 100644 --- a/include/uapi/linux/btrfs_tree.h +++ b/include/uapi/linux/btrfs_tree.h @@ -1107,8 +1107,14 @@ struct btrfs_file_extent_item { * but not for stat. */ __u8 compression; + + /* + * Type of encryption in use. Unencrypted value is 0. + */ __u8 encryption; - __le16 other_encoding; /* spare for later use */ + + /* spare for later use */ + __le16 other_encoding; =20 /* are we inline data or a real extent? */ __u8 type; --=20 2.51.0