From nobody Mon Jun 8 04:27:19 2026 Received: from TYDPR03CU002.outbound.protection.outlook.com (mail-japaneastazon11013042.outbound.protection.outlook.com [52.101.127.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FFCE3DA5B1; Tue, 2 Jun 2026 13:41:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.127.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780407691; cv=fail; b=t1BEO8FBn8yyr2pk+qhhCRTliTDfv6cePDP628P9Nq2ESc0JAwQrDot1BQnHug5J5f1ZH5sui4TIiroeZ6tVUEj9uFMm/9HSh0elXeNPqu1zRJEb39HtJLXXsUJn/jvTs1uBexWj8enWY1N16hGO9WKtbpTihHBQsZ/KOQgnh94= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780407691; c=relaxed/simple; bh=jdPpZb+7h10VhkVm1aWlCsm64ZSSStaSTwV51KFxWBs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=GMJEpIjw5FIlabtppP3PtcTPUuXkMBOWNN/3sV/Cp625RZJFa3oq+MAz4dIFRyFpo/ysd6Jqjl8gqJOWe9hN/SvwXvP/4RmrE1p7RAnQIMZ7djFWKlb49TdBysj+nj+shzq3Z1l/6ERbtmNrTEIY3ZGILbZ2e6wa478G/m3bKBw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com; spf=pass smtp.mailfrom=vivo.com; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b=I7ypdBjz; arc=fail smtp.client-ip=52.101.127.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="I7ypdBjz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gGRHD0kTXx0HdCDvVnkHFq2SNqZMa46T71T9QeRjWSVv96B+DuMRtiuohzILGnRsR+bmckmQPKLXD7K0xzkDoZKOFUlLMDRz9vXpVMrSYWD9oqVFcmovvuC+D5Q0lYdGpglzPlSjZZFEbl2f6B4vzwJOmt9Wf9NhshUYQYiqZAu+ocpPXjENwKYFtzA7vmD2QaKsgptOCaFA08hvNvfZj2Od6YD+yikPBXUGBBj5RMcwddyMr0EapArrivfajSGdXqNw3kP1C3kzO5N1I1Q/dcg5XH9j8Bx6Cxh+yZyrFwKY/GUlZx7eEU8nslrrY1tbP19D9yEwEyYThSiuHCUiJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MZs3bw6xDa+qwRBplqh+zN1aFXtmsIvM3abxmh/s+4s=; b=csQ8FLqbRIEj0t/l2+SyY3nCfRY0EyWqYSBvj3aim04F54JjCcoWdrSJPwnRbRxNdmPZR93lgbL4dhAf2RB+h0IYUYSdnPxzXm4FQXIco8QHeHfXP/B6Q4cGOmLwFn5n6ahsIHYokBeveFtiN3XKyr7+Cs36ide1TrQil7AOnKuZF50W1BAVJW1m9S5caZmkKOipVnA8MAdEJnWDoZEHv6V17DHWYXaWDt1OJLgVYlOIj37oMbPTJgOS1s8p6WfuBwXMhIiCRSy3nV5tOT32qkPJl7iLd7dinoX+OurG8jbe0L4McEZFBj+c5McjuBqbcUZv5UzNvCbDPRD1t1m1gw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MZs3bw6xDa+qwRBplqh+zN1aFXtmsIvM3abxmh/s+4s=; b=I7ypdBjzReFEP860ZjHTpWJVK1kicGalOGHjHsnwiJQXD7DBQZ4/SiMzO1Ensp/zvdr3thgsDWpTtiEFgUZOWXZzvv83SQvcr/wHEccp3WrPGVBxYCn+rr5yra8hKu/3S1UztaWvyYrcyXWA2NWD/ExW53Wyet4wQplb+XKpkBCYadZ44IzfGgoYVfhPWWXJQk2bEGhWNWV+86r/Z3pxx8tqNJ0pesTXMjGjCzjxeRcyafrCAikYoMgYpT+tvB39D/9WsVmq5cNXPFSvFbT5MdwIJDqxmRili28nfyaebb1CsCuZUiiSHd/Mz6TScDk8xqJgG+erv9iKRLJR5wjXWA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5576.apcprd06.prod.outlook.com (2603:1096:101:c9::14) by TYZPR06MB5950.apcprd06.prod.outlook.com (2603:1096:400:333::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.12; Tue, 2 Jun 2026 13:41:25 +0000 Received: from SEZPR06MB5576.apcprd06.prod.outlook.com ([fe80::24bc:5613:3ffa:cb96]) by SEZPR06MB5576.apcprd06.prod.outlook.com ([fe80::24bc:5613:3ffa:cb96%6]) with mapi id 15.21.0071.015; Tue, 2 Jun 2026 13:41:23 +0000 From: LiaoYuanhong-vivo To: Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , linux-fscrypt@vger.kernel.org (open list:FSCRYPT: FILE SYSTEM LEVEL ENCRYPTION SUPPORT), linux-kernel@vger.kernel.org (open list) Cc: LiaoYuanhong-vivo Subject: [PATCH v2 1/3] fscrypt: prepare software keys for filesystem-managed data units Date: Tue, 2 Jun 2026 21:41:00 +0800 Message-Id: <20260602134104.348655-2-liaoyuanhong@vivo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260602134104.348655-1-liaoyuanhong@vivo.com> References: <20260602134104.348655-1-liaoyuanhong@vivo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TP0P295CA0038.TWNP295.PROD.OUTLOOK.COM (2603:1096:910:4::11) To SEZPR06MB5576.apcprd06.prod.outlook.com (2603:1096:101:c9::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5576:EE_|TYZPR06MB5950:EE_ X-MS-Office365-Filtering-Correlation-Id: 11897c65-e0b3-4fe7-6cc9-08dec0aca2fe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|1800799024|366016|56012099006|11063799006|18002099003|22082099003|38350700014; X-Microsoft-Antispam-Message-Info: pNKxCjX/b595JjFwIw8PAjkmVu5YikJxGslJWe4Pnw/xgxP1NR83D1icpb7cTtbuji8c+vlGXP++zPetzohV3hBdgSuT/v0UVOjWs5faAWrs1RzQuNuKf8Tlwq66MxRg8ToeoxkXOjP79ggAqy9voe+C1fWfKGatqPkxpc+DBBRNuiSu7IXRke25/MkMFSaIStNpSao4Kr7GJY9luR1MAY+suKie98UADJhNgE7BAPJIvypYuzpkm0SMKgyXyBb7JpfmSAwWlpk+lYLwPoeaNRYXG5VXZ/x3AFcCqdmFCGCwdf0rZb/pRQC9SPAc/eaCdI9DEDmGTJsrilZXb2VNlLGTHYqs9f1ExgrXa46obc6NDCZywGD6fWynsVvGW3aSLNrCVI6QrIllrcV4raDuX+c+6u6fxirR3NCLXnT1tOcidHHFfOfopWy8rrhejjRc784/xGzkByZyYhtdnyQna6V/qBwf28FlfoN3GL9u6MTdlaBqChXV+Sf/I50yYWA6SU4kRxVUwSjejGxwWfOvbx2R3xP/Nk9hCzCUpPcg5Naa5BDQ7FnYGF/MaeTKEhQLPBvrgJgXkMKYmoZVwLKJc2ohXESj6YGlfDf4QxpxHHAARDloxHQsjTK9LAZ0XhWzbAx7wxtCZb191IwKeZFs/uldykauKDiaVQQuY0EYJ/rD0nUi+QHJOqBscoj1FUEvn9zbmJeYjlBxdrJKXlFGYuNMGnh0MxkfRqcl+RASgO7RYxJfPX1WeowYMwocqciV X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEZPR06MB5576.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(1800799024)(366016)(56012099006)(11063799006)(18002099003)(22082099003)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?xR8J8TaUgR/s8U01cboxCgtIoBhyeev+BNdn2FpmjMs/Y1aL5k07wsUGnXLJ?= =?us-ascii?Q?JNsbhGt//xEF1bScuH1HG+XTePdZ1dSI3jflHy9noEP0EMw5K4SqaEzXfS1M?= =?us-ascii?Q?N6sfvL6ZyOQUhTddPLr6HS0nIeId3uDgoMZLHHE4KWfLKIH7tAg0Qw4XJUmp?= =?us-ascii?Q?aArKuF7DdNhjCCMtdy/LlN089Xpxz4ZZeepV12r9ZYMyWynDpMp6RRHoBcPG?= =?us-ascii?Q?J9R/dM5EY1HRuz+neC74lj/MyvZwGHGbak2ge1hgPA/62r4cGsn71Es9mLZC?= =?us-ascii?Q?JgBwTA4ccZHdLC/UiiJVrExMY5S3QepGGDy0hyZAvkyngJ4Qo+n3ZYY1zvvy?= =?us-ascii?Q?SXgfH54IGUxUgLNxpbQSj6i9/ATKxUteJfDUvT9A7tNXO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jjRsjNTEICuJ6qe3HEDnzDetROsULgKJGfPw3pB9N+CiyMtVwRc?= =?us-ascii?Q?NgvR1ARWjm7DPaV744/oQqDzgbUA5K5T3Pk52HLWL1MHiELQIiqbWN9gJ7rW?= =?us-ascii?Q?4qeO7Nusxs2QGRKgH6g/A9vqSva8bc1wFmcyBZjDlwHXRg1PMDs/uwHUhjYk?= =?us-ascii?Q?pWga4lDk5CVheZkxmqik4QpZhyWkniH+inYbVJktG194gDrGufKM7LfYTw3d?= =?us-ascii?Q?tiJog6DVldZti9pxFdoeTJqm533+yL14rbA5Z5mT2i7UkV9n9mpJinA8aDTu?= =?us-ascii?Q?YynEc9BGP6vR8BLqTeYrfnJLiY1yG/QbyBnQ1jlNjhU4wZHJQHaooMxKRivc?= =?us-ascii?Q?niOQGSHWv9Lvo2Owl+K07Cp2Ia9HVxBrZcfQy2bJEZN06MAkydboJr0jI9o2?= =?us-ascii?Q?LAvcG5UjlOnKC4D7MUinz6bLXoEHwdahsTzn91siaGn3i9FxLV2gABulohWp?= =?us-ascii?Q?hNxlWL3O9g=3D=3D?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 11897c65-e0b3-4fe7-6cc9-08dec0aca2fe X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5576.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2026 13:41:23.6681 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: O1Nm8VPGa8AXViXHKZB7J6pdCLyrG3eaEro9Y0nbIX47t90FfFBhiyCekVTTXgweF4cIRdhuQhnP+MXqnGB2/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB5950 Content-Type: text/plain; charset="utf-8" Some filesystems store small data regions inside filesystem metadata rather than submitting them through the normal bio path. F2FS inline data is one such case. When encrypted file contents normally use blk-crypto, these filesystem-managed regions still need software fscrypt handling because no data bio is submitted for them. Add helpers for this case. fscrypt_supports_data_unit_inplace() lets a filesystem check whether an inode's current key and policy can support this path without preparing a software transform. fscrypt_prepare_data_unit_inplace() prepares the transform when the filesystem actually needs to read or write such a region. fscrypt_crypt_data_unit_inplace() encrypts or decrypts an in-page region by fscrypt data-unit size. For raw-key inlinecrypt, support is limited to per-mode key policies (DIRECT_KEY, IV_INO_LBLK_64, and IV_INO_LBLK_32), so the software transform is shared per mode instead of being allocated per file. Hardware-wrapped keys and per-file inlinecrypt keys are not supported for this path. Signed-off-by: LiaoYuanhong-vivo --- Changes in v2: - Split capability checking from software transform preparation. - Limit raw-key inlinecrypt support to per-mode policies; reject per-file and hardware-wrapped keys. - Use one direction-aware helper and process regions by fscrypt data-unit size. fs/crypto/crypto.c | 47 ++++++++++ fs/crypto/fscrypt_private.h | 3 +- fs/crypto/keysetup.c | 178 ++++++++++++++++++++++++++++++++++++ include/linux/fscrypt.h | 24 ++++++ 4 files changed, 251 insertions(+), 1 deletion(-) diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c index 570a2231c945..a85ea313b0d9 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c @@ -208,6 +208,53 @@ struct page *fscrypt_encrypt_pagecache_blocks(struct f= olio *folio, } EXPORT_SYMBOL(fscrypt_encrypt_pagecache_blocks); =20 +/** + * fscrypt_crypt_data_unit_inplace() - En/decrypt data units in-place + * @inode: The inode to which these data units belong + * @page: The page containing the data units to en/decrypt + * @len: Size of the region to en/decrypt. This must be a multiple of + * FSCRYPT_CONTENTS_ALIGNMENT. + * @offs: Byte offset within @page at which the region begins + * @index: Fscrypt data unit index of the start of the region + * @encrypt: True to encrypt, false to decrypt + * + * Return: 0 on success; -errno on failure + */ +int fscrypt_crypt_data_unit_inplace(const struct inode *inode, + struct page *page, unsigned int len, + unsigned int offs, u64 index, bool encrypt) +{ + const struct fscrypt_inode_info *ci =3D fscrypt_get_inode_info_raw(inode); + unsigned int du_size; + unsigned int i; + int err; + + /* + * Pairs with the smp_store_release() that publishes ->tfm after the + * software transform has been fully initialized. + */ + if (!ci || !smp_load_acquire(&ci->ci_enc_key.tfm)) + return -EOPNOTSUPP; + du_size =3D 1U << ci->ci_data_unit_bits; + + if (WARN_ON_ONCE(len <=3D 0)) + return -EINVAL; + if (WARN_ON_ONCE(!IS_ALIGNED(len | offs, FSCRYPT_CONTENTS_ALIGNMENT))) + return -EINVAL; + + for (i =3D 0; i < len; i +=3D du_size, index++) { + unsigned int todo =3D min(du_size, len - i); + + err =3D fscrypt_crypt_data_unit(ci, + encrypt ? FS_ENCRYPT : FS_DECRYPT, + index, page, page, todo, offs + i); + if (err) + return err; + } + return 0; +} +EXPORT_SYMBOL(fscrypt_crypt_data_unit_inplace); + /** * fscrypt_encrypt_block_inplace() - Encrypt a filesystem block in-place * @inode: The inode to which this block belongs diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h index 8d3c278a7591..b5c0b881fd4b 100644 --- a/fs/crypto/fscrypt_private.h +++ b/fs/crypto/fscrypt_private.h @@ -236,7 +236,8 @@ struct fscrypt_symlink_data { * @tfm: crypto API transform object * @blk_key: key for blk-crypto * - * Normally only one of the fields will be non-NULL. + * Most users need only one prepared form. Inline-crypto users that also = need + * filesystem-layer software crypto for non-bio data regions may prepare b= oth. */ struct fscrypt_prepared_key { struct crypto_sync_skcipher *tfm; diff --git a/fs/crypto/keysetup.c b/fs/crypto/keysetup.c index ce327bfdada4..2cb629d4383c 100644 --- a/fs/crypto/keysetup.c +++ b/fs/crypto/keysetup.c @@ -400,6 +400,184 @@ static int fscrypt_setup_v2_file_key(struct fscrypt_i= node_info *ci, return 0; } =20 +static int fscrypt_prepare_data_unit_inplace_software_key( + struct fscrypt_prepared_key *prep_key, + const u8 *raw_key, + const struct fscrypt_inode_info *ci) +{ + struct crypto_sync_skcipher *tfm; + + /* Pairs with the smp_store_release() below. */ + if (smp_load_acquire(&prep_key->tfm)) + return 0; + tfm =3D fscrypt_allocate_skcipher(ci->ci_mode, raw_key, ci->ci_inode); + if (IS_ERR(tfm)) + return PTR_ERR(tfm); + /* Pairs with the smp_load_acquire() above and other ->tfm readers. */ + smp_store_release(&prep_key->tfm, tfm); + return 0; +} + +static int fscrypt_prepare_per_mode_data_unit_inplace_key( + struct fscrypt_inode_info *ci, + struct fscrypt_master_key *mk, + struct fscrypt_prepared_key *keys, + u8 hkdf_context, bool include_fs_uuid) +{ + const struct super_block *sb =3D ci->ci_inode->i_sb; + struct fscrypt_mode *mode =3D ci->ci_mode; + const u8 mode_num =3D mode - fscrypt_modes; + struct fscrypt_prepared_key *prep_key; + u8 mode_key[FSCRYPT_MAX_RAW_KEY_SIZE]; + u8 hkdf_info[sizeof(mode_num) + sizeof(sb->s_uuid)]; + unsigned int hkdf_infolen =3D 0; + int err; + + if (WARN_ON_ONCE(mode_num > FSCRYPT_MODE_MAX)) + return -EINVAL; + + prep_key =3D &keys[mode_num]; + + BUILD_BUG_ON(sizeof(mode_num) !=3D 1); + BUILD_BUG_ON(sizeof(sb->s_uuid) !=3D 16); + BUILD_BUG_ON(sizeof(hkdf_info) !=3D 17); + hkdf_info[hkdf_infolen++] =3D mode_num; + if (include_fs_uuid) { + memcpy(&hkdf_info[hkdf_infolen], &sb->s_uuid, + sizeof(sb->s_uuid)); + hkdf_infolen +=3D sizeof(sb->s_uuid); + } + + fscrypt_hkdf_expand(&mk->mk_secret.hkdf, hkdf_context, hkdf_info, + hkdf_infolen, mode_key, mode->keysize); + err =3D fscrypt_prepare_data_unit_inplace_software_key(prep_key, + mode_key, ci); + memzero_explicit(mode_key, mode->keysize); + if (!err) + ci->ci_enc_key =3D *prep_key; + return err; +} + +/** + * fscrypt_supports_data_unit_inplace() - check data-unit crypto support + * @inode: an encrypted regular file inode + * + * Check whether filesystem-managed data regions can use fscrypt contents + * encryption for this inode. Per-file inlinecrypt keys are intentionally + * unsupported to avoid per-file software tfm memory growth. Hardware-wra= pped + * keys are unsupported because the software contents key is not available. + */ +bool fscrypt_supports_data_unit_inplace(const struct inode *inode) +{ + struct fscrypt_inode_info *ci =3D fscrypt_get_inode_info_raw(inode); + struct fscrypt_master_key *mk; + u8 flags; + bool supported; + + if (!ci) + return false; + /* + * Pairs with the smp_store_release() that publishes ->tfm after the + * software transform has been fully initialized. + */ + if (smp_load_acquire(&ci->ci_enc_key.tfm)) + return true; + if (!fscrypt_using_inline_encryption(ci)) + return false; + + mk =3D ci->ci_master_key; + if (!mk) + return false; + + down_read(&mk->mk_sem); + if (!mk->mk_present || mk->mk_secret.is_hw_wrapped || + ci->ci_policy.version !=3D FSCRYPT_POLICY_V2) { + supported =3D false; + goto out; + } + + flags =3D ci->ci_policy.v2.flags; + supported =3D flags & (FSCRYPT_POLICY_FLAG_DIRECT_KEY | + FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64 | + FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32); +out: + up_read(&mk->mk_sem); + return supported; +} +EXPORT_SYMBOL_GPL(fscrypt_supports_data_unit_inplace); + +/** + * fscrypt_prepare_data_unit_inplace() - prepare software data-unit crypto + * @inode: an encrypted regular file inode + * + * Prepare the software transform used by filesystem-managed data regions = that + * need fscrypt contents encryption but do not go through a data bio. If = the + * inode already uses filesystem-layer encryption, the normal contents key= is + * already prepared. If the inode uses blk-crypto with a raw per-mode key= , this + * prepares the software form of that same per-mode contents key. + */ +int fscrypt_prepare_data_unit_inplace(const struct inode *inode) +{ + struct fscrypt_inode_info *ci =3D fscrypt_get_inode_info_raw(inode); + struct fscrypt_master_key *mk; + u8 flags; + int err =3D 0; + + if (!ci) + return -ENOKEY; + /* + * Pairs with the smp_store_release() that publishes ->tfm after the + * software transform has been fully initialized. + */ + if (smp_load_acquire(&ci->ci_enc_key.tfm)) + return 0; + if (!fscrypt_using_inline_encryption(ci)) + return -EOPNOTSUPP; + + mk =3D ci->ci_master_key; + if (!mk) + return -EOPNOTSUPP; + + down_read(&mk->mk_sem); + if (!mk->mk_present) { + err =3D -ENOKEY; + goto out_unlock; + } + if (mk->mk_secret.is_hw_wrapped || + ci->ci_policy.version !=3D FSCRYPT_POLICY_V2) { + err =3D -EOPNOTSUPP; + goto out_unlock; + } + + mutex_lock(&fscrypt_mode_key_setup_mutex); + /* Pairs with fscrypt_prepare_data_unit_inplace_software_key(). */ + if (smp_load_acquire(&ci->ci_enc_key.tfm)) + goto out_mutex; + + flags =3D ci->ci_policy.v2.flags; + if (flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) { + err =3D fscrypt_prepare_per_mode_data_unit_inplace_key(ci, mk, + mk->mk_direct_keys, HKDF_CONTEXT_DIRECT_KEY, + false); + } else if (flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64) { + err =3D fscrypt_prepare_per_mode_data_unit_inplace_key(ci, mk, + mk->mk_iv_ino_lblk_64_keys, + HKDF_CONTEXT_IV_INO_LBLK_64_KEY, true); + } else if (flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32) { + err =3D fscrypt_prepare_per_mode_data_unit_inplace_key(ci, mk, + mk->mk_iv_ino_lblk_32_keys, + HKDF_CONTEXT_IV_INO_LBLK_32_KEY, true); + } else { + err =3D -EOPNOTSUPP; + } +out_mutex: + mutex_unlock(&fscrypt_mode_key_setup_mutex); +out_unlock: + up_read(&mk->mk_sem); + return err; +} +EXPORT_SYMBOL_GPL(fscrypt_prepare_data_unit_inplace); + /* * Check whether the size of the given master key (@mk) is appropriate for= the * encryption settings which a particular file will use (@ci). diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h index 54712ec61ffb..2702bf1018c1 100644 --- a/include/linux/fscrypt.h +++ b/include/linux/fscrypt.h @@ -346,6 +346,12 @@ void fscrypt_enqueue_decrypt_work(struct work_struct *= ); =20 struct page *fscrypt_encrypt_pagecache_blocks(struct folio *folio, size_t len, size_t offs, gfp_t gfp_flags); + +bool fscrypt_supports_data_unit_inplace(const struct inode *inode); +int fscrypt_prepare_data_unit_inplace(const struct inode *inode); +int fscrypt_crypt_data_unit_inplace(const struct inode *inode, + struct page *page, unsigned int len, + unsigned int offs, u64 index, bool encrypt); int fscrypt_encrypt_block_inplace(const struct inode *inode, struct page *= page, unsigned int len, unsigned int offs, u64 lblk_num); @@ -519,6 +525,24 @@ static inline struct page *fscrypt_encrypt_pagecache_b= locks(struct folio *folio, return ERR_PTR(-EOPNOTSUPP); } =20 +static inline bool fscrypt_supports_data_unit_inplace(const struct inode *= inode) +{ + return false; +} + +static inline int fscrypt_prepare_data_unit_inplace(const struct inode *in= ode) +{ + return -EOPNOTSUPP; +} + +static inline int fscrypt_crypt_data_unit_inplace(const struct inode *inod= e, + struct page *page, unsigned int len, + unsigned int offs, u64 index, + bool encrypt) +{ + return -EOPNOTSUPP; +} + static inline int fscrypt_encrypt_block_inplace(const struct inode *inode, struct page *page, unsigned int len, --=20 2.34.1 From nobody Mon Jun 8 04:27:19 2026 Received: from TYDPR03CU002.outbound.protection.outlook.com (mail-japaneastazon11013042.outbound.protection.outlook.com [52.101.127.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83CA73E3170 for ; Tue, 2 Jun 2026 13:41:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.127.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780407693; cv=fail; b=OVkVgYZ2MZyW8I4AY1kM1RUc1q0HJHYY1GgDXN6Ksv5UxdUEcpPnh7gOxcM7Vp/HWRtYMTUH7JV+iZQgzu8m4WmlTMBlyEBzINokC0A9QCN9KCZQAGSd4c0QpYJqY5tKP0eRTLFClsjK9/wVI0KjmjqJXWHvEoVstEVpcQoTkQY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780407693; c=relaxed/simple; bh=wZ25LXGjd8H9ELWIx6a8FjFLtPajRackspMgM8gAgR0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=M1HhQfWcyR7tneOffUrpHy6DOTCILJrur1VNjMAtOiDEDdHFsopCptUVeIMM/+/neIJlMvigQ6aKOYI+d8WDel5c2802BT2Pdw3nG/baKpz6zEiFFoEG6b/Gy7uzz/OOQHgv3NAW3iQKfPeUEgjrTxfcoEW9mom7D37vF0LC4M8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com; spf=pass smtp.mailfrom=vivo.com; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b=no6nHZmg; arc=fail smtp.client-ip=52.101.127.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="no6nHZmg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EUdB8QUIlo0EbV9Z8Pj2yuvmNJUrG7A9PIT3vJgEtVTe4a+tOxeNDB87ouDyMvhv/LKWbkjRU+npDuKOXTNPECTnlq+rtaS7HtgHvFHL21JuDnRQQXbTuBlyCxiT4thPoyJM2uYrMcEyj/eMvvmHE2xA30KM1Ontjlh/N2TaIwTIPtT8TdOq6DRSt1lEySNp9QE/dNMNzTktxi4deWvz0VUuQqxD3US/JHUKCaSkZzTp0BMM6naTE5YuaHsdbk+wqHt5OMU9DjGWlii8eSuYqlfL6kB5QR8OVk0iM3sPnXxNbk7AoNqonk0ZCH6OE2KsMLAH+CqMJKq6MS4udDczeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UaYA916ZJ96ybeoIPMCMzMGmDK1PEz5P0GkHJvTfqZ4=; b=n8uSWhwiM5yZxUTHczaad6UJelcS5xcxk25WJv4ohO/aURmwog1C2Z5VEFhvjIW6JW7AAopxSzBWbfBkwu2R8QFHr9iFGuSJAO7NPtZx4rDS5gawi/C2rgfxITWBqe/xucihXmJSx7M8rrWjNp+xO6dlKSbiWRTnKtHP/l+SWfZUSu6nYRE0nAJWkcsHrmKBpjXtCpZNNWKIHynQXxe2L8+UuLTktdUFZu7Mu1A4WDQlCnx12D+cYA7VxRfSNGb7puhrMZqahlMLBrB+KMMyz2H/XDcDk099O6wGLTWG49+7jyI+0eA4v5lbqkj5hCh2etojzEusecBufL9KLV610g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UaYA916ZJ96ybeoIPMCMzMGmDK1PEz5P0GkHJvTfqZ4=; b=no6nHZmgaPnDMLNHY86kdsRDHSqIGF4grWTwrPTapeU/y1sj3ntEaHlR6HlMAKb8sdXsT6YhHDsyxwKEb/bj0+4HJZiPfMWOSfdt6q2c8dWtCGE3NuoyBZZ05HkexfG34yTNuejGHLTa8aARHLlhgOVunUBJlYcwB1esEXQ1goQX/xYHJLtFN4ecBj+aW4IN/0ea/YepV8MiAiLGCeOenrsWKK9x0bKzD1U232PSbRxSiQ1OVcvuTxknaS4GjHKxHL5DLf0np0C6yYEkOlJoZ2tcpOEx+ihOCbVPA2PbnOJxRpUv3lJkaEk8BUou6kDnqSjs8mbG+o2L+3eaqOhZvA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5576.apcprd06.prod.outlook.com (2603:1096:101:c9::14) by TYZPR06MB5950.apcprd06.prod.outlook.com (2603:1096:400:333::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.12; Tue, 2 Jun 2026 13:41:26 +0000 Received: from SEZPR06MB5576.apcprd06.prod.outlook.com ([fe80::24bc:5613:3ffa:cb96]) by SEZPR06MB5576.apcprd06.prod.outlook.com ([fe80::24bc:5613:3ffa:cb96%6]) with mapi id 15.21.0071.015; Tue, 2 Jun 2026 13:41:26 +0000 From: LiaoYuanhong-vivo To: Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), linux-kernel@vger.kernel.org (open list) Cc: LiaoYuanhong-vivo Subject: [PATCH v2 2/3] f2fs: support encrypted inline data Date: Tue, 2 Jun 2026 21:41:01 +0800 Message-Id: <20260602134104.348655-3-liaoyuanhong@vivo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260602134104.348655-1-liaoyuanhong@vivo.com> References: <20260602134104.348655-1-liaoyuanhong@vivo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TP0P295CA0038.TWNP295.PROD.OUTLOOK.COM (2603:1096:910:4::11) To SEZPR06MB5576.apcprd06.prod.outlook.com (2603:1096:101:c9::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5576:EE_|TYZPR06MB5950:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e52fe00-bcb9-418f-53b4-08dec0aca4e5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|1800799024|366016|56012099006|11063799006|18002099003|22082099003|3023799007|38350700014; X-Microsoft-Antispam-Message-Info: Gi5SJ3fMySpwjQMZsC7KQJKBVSZXye9OjEjdHK9HrUHrCaqIvomGxe3cDoyQc60jFC0K10EF729+Kh2s+zUSOp6ckfzeVj8sufbhykvJx/Vomrfmhg/AloS5Td0eCUjybtzuK06kvwfhcT6/Jp0Z3eHs9yATScSYdnTG8V/5M49IEkuGFCMDxw8FrrP2q5bAaSb/oCD4qSmEKhgPCRLTHL05PZcDuzW6jPQuALlbCnvYxWaixExcyjy47Zj2eIM/PiG71mLw3kaj7lH735RTyxYEwhnUU7t/nl8uN8/OEfRwNHSUFrYYOddd9Tya6hbRIcOQAItoP3CCDWj/IDu5BXgD9b10bGZUyO+Fkb0hLLLf+ZzbYc9i1Ijez06e2CKBPQTVykq5W9+xN+GGrV7ave5cZZ2od7jRea33bX0/WnCOPNBCOToin1D6PCHLleo2SsnLJ/iGV6dl/sT8k7b59vMqENoSswGuLRs3+boxiXlLYNSA6X6aTBQK8RQgFYi55+yryQcZCTXHqMaqg5xNLR5XKGwZZ0ob329m4Bcjd2ixilaon0k1ZbGSNlngkwxoP4mVI8OkH62NPdXmAu+BF/NNgTKlER8ig2jr5hPkT4S1xw3mqLybexdfxKtSb+mIAyamyfeYvQjGLhoWC8B4hB9qa68S8Pks69UNvFxlEoBi7K2WN+Egwc1WrU/uo3F1/k46XBvGWV2GeEfXOF7SnjEMxEVVfAFp58f84WhSg0DnNuWU77AhjkWNI0ZJk4Ow X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEZPR06MB5576.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(1800799024)(366016)(56012099006)(11063799006)(18002099003)(22082099003)(3023799007)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Ex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O/wtt5iXu+Jw4?= =?us-ascii?Q?2xtDLWRV6Q=3D=3D?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e52fe00-bcb9-418f-53b4-08dec0aca4e5 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5576.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2026 13:41:26.8511 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: U+RH0r332tzfMQNJrMIc9tKNLwg6HdPimlA4CBr7zzXSid53y+JDNIM8speOrwUsxG+eUPjkk2HuwbalBedbXg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB5950 Content-Type: text/plain; charset="utf-8" F2FS normally disables inline data for encrypted regular files because the inline payload is stored in the inode block and does not pass through the regular fscrypt data I/O path. This wastes space for small encrypted files on filesystems that otherwise use inline_data. Add encrypted inline data support for encrypted regular files. When the encrypted_inline_data on-disk feature is enabled, inline payloads of encrypted regular files are stored as ciphertext in the inode block. They are decrypted into page-cache plaintext on read and encrypted before being copied back into the inode block on write. F2FS keeps the on-disk format decision separate from fscrypt key capability. It uses fscrypt_supports_data_unit_inplace() when deciding whether a new file may keep inline_data. It calls fscrypt_prepare_data_unit_inplace() only when the encrypted inline payload is actually read or written. Update inline-data size checks to use the encrypted inline capacity, since the stored payload is rounded to the fscrypt contents alignment. If an encrypted inline-data file is truncated from a non-zero offset, convert it to normal data blocks first and then use the normal truncate path. Recovery copies inline payloads as on-disk bytes. Signed-off-by: LiaoYuanhong-vivo --- Changes in v2: - Use fscrypt capability checking in f2fs_may_inline_data(); prepare software crypto only in encrypted inline read/write paths. - Use the encrypted inline-data capacity across F2FS size checks. - Convert encrypted inline data before non-zero truncation and propagate inline read/decrypt errors. fs/f2fs/Kconfig | 14 +++++ fs/f2fs/data.c | 8 +-- fs/f2fs/f2fs.h | 37 ++++++++++++- fs/f2fs/file.c | 24 ++++++++- fs/f2fs/inline.c | 131 ++++++++++++++++++++++++++++++++++++++++++----- fs/f2fs/super.c | 12 +++++ fs/f2fs/sysfs.c | 8 +++ 7 files changed, 214 insertions(+), 20 deletions(-) diff --git a/fs/f2fs/Kconfig b/fs/f2fs/Kconfig index 5916a02fb46d..0220f23be56d 100644 --- a/fs/f2fs/Kconfig +++ b/fs/f2fs/Kconfig @@ -92,6 +92,20 @@ config F2FS_FAULT_INJECTION =20 If unsure, say N. =20 +config F2FS_FS_ENCRYPTED_INLINE_DATA + bool "F2FS encrypted inline data support" + depends on F2FS_FS && FS_ENCRYPTION + help + Allow encrypted regular files to keep inline data inside the inode + while encrypting that inode-managed payload in software. + + This does not change normal data block encryption. Normal data + blocks continue to use the existing fscrypt path, such as blk-crypto + when inline encryption is enabled. + + Filesystems carrying the encrypted_inline_data incompat feature + require this option in order to be mounted correctly. + config F2FS_FS_COMPRESSION bool "F2FS compression feature" depends on F2FS_FS diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 657fd5986c73..9371ffa7c96d 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3700,7 +3700,7 @@ static int prepare_write_begin(struct f2fs_sb_info *s= bi, =20 /* f2fs_lock_op avoids race between write CP and convert_inline_page */ if (f2fs_has_inline_data(inode)) { - if (pos + len > MAX_INLINE_DATA(inode)) + if (pos + len > f2fs_max_inline_data(inode)) flag =3D F2FS_GET_BLOCK_DEFAULT; f2fs_map_lock(sbi, &lc, flag); locked =3D true; @@ -3720,8 +3720,10 @@ static int prepare_write_begin(struct f2fs_sb_info *= sbi, set_new_dnode(&dn, inode, ifolio, ifolio, 0); =20 if (f2fs_has_inline_data(inode)) { - if (pos + len <=3D MAX_INLINE_DATA(inode)) { - f2fs_do_read_inline_data(folio, ifolio); + if (pos + len <=3D f2fs_max_inline_data(inode)) { + err =3D f2fs_do_read_inline_data(folio, ifolio); + if (err) + goto out; set_inode_flag(inode, FI_DATA_EXIST); if (inode->i_nlink) folio_set_f2fs_inline(ifolio); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 832b2f8beb11..0a2d75baf23e 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -276,6 +276,7 @@ struct f2fs_mount_info { #define F2FS_FEATURE_RO 0x00004000 #define F2FS_FEATURE_DEVICE_ALIAS 0x00008000 #define F2FS_FEATURE_PACKED_SSA 0x00010000 +#define F2FS_FEATURE_ENCRYPTED_INLINE_DATA 0x00020000 =20 #define __F2FS_HAS_FEATURE(raw_super, mask) \ ((raw_super->feature & cpu_to_le32(mask)) !=3D 0) @@ -4502,7 +4503,7 @@ extern struct kmem_cache *f2fs_inode_entry_slab; bool f2fs_may_inline_data(struct inode *inode); bool f2fs_sanity_check_inline_data(struct inode *inode, struct folio *ifol= io); bool f2fs_may_inline_dentry(struct inode *inode); -void f2fs_do_read_inline_data(struct folio *folio, struct folio *ifolio); +int f2fs_do_read_inline_data(struct folio *folio, struct folio *ifolio); void f2fs_truncate_inline_inode(struct inode *inode, struct folio *ifolio, u64 from); int f2fs_read_inline_data(struct inode *inode, struct folio *folio); @@ -4595,6 +4596,39 @@ static inline bool f2fs_encrypted_file(struct inode = *inode) return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode); } =20 +static inline bool f2fs_sb_has_encrypted_inline_data(struct f2fs_sb_info *= sbi); + +static inline bool f2fs_uses_encrypted_inline_data(struct inode *inode) +{ +#ifdef CONFIG_F2FS_FS_ENCRYPTED_INLINE_DATA + /* + * When the filesystem allows encrypted inline data, inline payloads + * in encrypted regular files are interpreted as ciphertext. + */ + return f2fs_sb_has_encrypted_inline_data(F2FS_I_SB(inode)) && + f2fs_encrypted_file(inode); +#else + return false; +#endif +} + +static inline unsigned int f2fs_max_inline_data(struct inode *inode) +{ + unsigned int max_bytes =3D MAX_INLINE_DATA(inode); + + /* + * Encrypted inline data is rounded up to the fscrypt contents + * alignment before being stored back into the inode. This is an + * on-disk layout constraint, so it must not depend on whether the + * inode's key has been prepared yet. + */ +#ifdef CONFIG_F2FS_FS_ENCRYPTED_INLINE_DATA + if (f2fs_uses_encrypted_inline_data(inode)) + max_bytes =3D round_down(max_bytes, FSCRYPT_CONTENTS_ALIGNMENT); +#endif + return max_bytes; +} + static inline void f2fs_set_encrypted_inode(struct inode *inode) { #ifdef CONFIG_FS_ENCRYPTION @@ -4827,6 +4861,7 @@ F2FS_FEATURE_FUNCS(compression, COMPRESSION); F2FS_FEATURE_FUNCS(readonly, RO); F2FS_FEATURE_FUNCS(device_alias, DEVICE_ALIAS); F2FS_FEATURE_FUNCS(packed_ssa, PACKED_SSA); +F2FS_FEATURE_FUNCS(encrypted_inline_data, ENCRYPTED_INLINE_DATA); =20 #ifdef CONFIG_BLK_DEV_ZONED static inline bool f2fs_zone_is_seq(struct f2fs_sb_info *sbi, int devi, diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 71385ca4163d..ec243bb9039b 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -825,12 +825,32 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 = from, bool lock) } =20 if (f2fs_has_inline_data(inode)) { + if (f2fs_uses_encrypted_inline_data(inode) && from) { + f2fs_folio_put(ifolio, true); + if (lock) + f2fs_unlock_op(sbi, &lc); + + err =3D f2fs_convert_inline_inode(inode); + + if (lock) + f2fs_lock_op(sbi, &lc); + if (err) + goto out; + + ifolio =3D f2fs_get_inode_folio(sbi, inode->i_ino); + if (IS_ERR(ifolio)) { + err =3D PTR_ERR(ifolio); + goto out; + } + goto truncate_blocks; + } f2fs_truncate_inline_inode(inode, ifolio, from); f2fs_folio_put(ifolio, true); truncate_page =3D true; goto out; } =20 +truncate_blocks: set_new_dnode(&dn, inode, ifolio, NULL, 0); err =3D f2fs_get_dnode_of_data(&dn, free_from, LOOKUP_NODE_RA); if (err) { @@ -1147,7 +1167,7 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dent= ry *dentry, if (attr->ia_valid & ATTR_SIZE) { loff_t old_size =3D i_size_read(inode); =20 - if (attr->ia_size > MAX_INLINE_DATA(inode)) { + if (attr->ia_size > f2fs_max_inline_data(inode)) { /* * should convert inline inode before i_size_write to * keep smaller than inline_data size with inline flag. @@ -5007,7 +5027,7 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb= , struct iov_iter *iter, =20 if (f2fs_has_inline_data(inode)) { /* If the data will fit inline, don't bother. */ - if (pos + count <=3D MAX_INLINE_DATA(inode)) + if (pos + count <=3D f2fs_max_inline_data(inode)) return 0; ret =3D f2fs_convert_inline_inode(inode); if (ret) diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 099f72089701..37d6509ea01a 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -21,7 +21,7 @@ static bool support_inline_data(struct inode *inode) return false; if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode)) return false; - if (i_size_read(inode) > MAX_INLINE_DATA(inode)) + if (i_size_read(inode) > f2fs_max_inline_data(inode)) return false; return true; } @@ -31,6 +31,9 @@ bool f2fs_may_inline_data(struct inode *inode) if (!support_inline_data(inode)) return false; =20 + if (f2fs_uses_encrypted_inline_data(inode)) + return fscrypt_supports_data_unit_inplace(inode); + return !f2fs_post_read_required(inode); } =20 @@ -65,7 +68,9 @@ bool f2fs_sanity_check_inline_data(struct inode *inode, s= truct folio *ifolio) * been synchronized to inmem fields. */ return (S_ISREG(inode->i_mode) && - (file_is_encrypt(inode) || file_is_verity(inode) || + ((file_is_encrypt(inode) && + !f2fs_sb_has_encrypted_inline_data(F2FS_I_SB(inode))) || + file_is_verity(inode) || (F2FS_I(inode)->i_flags & F2FS_COMPR_FL))); } =20 @@ -80,22 +85,66 @@ bool f2fs_may_inline_dentry(struct inode *inode) return true; } =20 -void f2fs_do_read_inline_data(struct folio *folio, struct folio *ifolio) +int f2fs_do_read_inline_data(struct folio *folio, struct folio *ifolio) { struct inode *inode =3D folio->mapping->host; + unsigned int len =3D min_t(loff_t, i_size_read(inode), + f2fs_max_inline_data(inode)); =20 if (folio_test_uptodate(folio)) - return; + return 0; =20 f2fs_bug_on(F2FS_I_SB(inode), folio->index); =20 - folio_zero_segment(folio, MAX_INLINE_DATA(inode), folio_size(folio)); + if (f2fs_uses_encrypted_inline_data(inode)) { + struct page *tmp_page; + void *kaddr; + int err; + + folio_zero_segment(folio, 0, folio_size(folio)); =20 - /* Copy the whole inline data block */ - memcpy_to_folio(folio, 0, inline_data_addr(inode, ifolio), - MAX_INLINE_DATA(inode)); + /* + * Decrypt through a temporary page because inline data occupies + * only a byte range inside the inode folio. + */ + tmp_page =3D alloc_page(GFP_NOFS | __GFP_ZERO); + if (!tmp_page) + return -ENOMEM; + + len =3D round_up(len, FSCRYPT_CONTENTS_ALIGNMENT); + if (len) { + err =3D fscrypt_prepare_data_unit_inplace(inode); + if (err) { + __free_page(tmp_page); + return err; + } + memcpy_to_page(tmp_page, 0, inline_data_addr(inode, ifolio), + len); + err =3D fscrypt_crypt_data_unit_inplace(inode, tmp_page, + len, 0, 0, + false); + if (err) { + __free_page(tmp_page); + return err; + } + } + + kaddr =3D kmap_local_page(tmp_page); + memcpy_to_folio(folio, 0, kaddr, + min_t(loff_t, i_size_read(inode), + f2fs_max_inline_data(inode))); + kunmap_local(kaddr); + __free_page(tmp_page); + } else { + folio_zero_segment(folio, MAX_INLINE_DATA(inode), + folio_size(folio)); + /* Copy the whole inline data block */ + memcpy_to_folio(folio, 0, inline_data_addr(inode, ifolio), + MAX_INLINE_DATA(inode)); + } if (!folio_test_uptodate(folio)) folio_mark_uptodate(folio); + return 0; } =20 void f2fs_truncate_inline_inode(struct inode *inode, struct folio *ifolio, @@ -119,6 +168,7 @@ void f2fs_truncate_inline_inode(struct inode *inode, st= ruct folio *ifolio, int f2fs_read_inline_data(struct inode *inode, struct folio *folio) { struct folio *ifolio; + int ret =3D 0; =20 ifolio =3D f2fs_get_inode_folio(F2FS_I_SB(inode), inode->i_ino); if (IS_ERR(ifolio)) { @@ -134,7 +184,13 @@ int f2fs_read_inline_data(struct inode *inode, struct = folio *folio) if (folio->index) folio_zero_segment(folio, 0, folio_size(folio)); else - f2fs_do_read_inline_data(folio, ifolio); + ret =3D f2fs_do_read_inline_data(folio, ifolio); + + if (!folio->index && ret) { + f2fs_folio_put(ifolio, true); + folio_unlock(folio); + return ret; + } =20 if (!folio_test_uptodate(folio)) folio_mark_uptodate(folio); @@ -186,7 +242,9 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn,= struct folio *folio) =20 f2fs_bug_on(F2FS_F_SB(folio), folio_test_writeback(folio)); =20 - f2fs_do_read_inline_data(folio, dn->inode_folio); + err =3D f2fs_do_read_inline_data(folio, dn->inode_folio); + if (err) + return err; folio_mark_dirty(folio); =20 /* clear dirty state */ @@ -267,6 +325,8 @@ int f2fs_write_inline_data(struct inode *inode, struct = folio *folio) { struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); struct folio *ifolio; + void *inline_addr; + int err =3D 0; =20 ifolio =3D f2fs_get_inode_folio(sbi, inode->i_ino); if (IS_ERR(ifolio)) @@ -280,8 +340,50 @@ int f2fs_write_inline_data(struct inode *inode, struct= folio *folio) f2fs_bug_on(F2FS_I_SB(inode), folio->index); =20 f2fs_folio_wait_writeback(ifolio, NODE, true, true); - memcpy_from_folio(inline_data_addr(inode, ifolio), - folio, 0, MAX_INLINE_DATA(inode)); + inline_addr =3D inline_data_addr(inode, ifolio); + + if (f2fs_uses_encrypted_inline_data(inode)) { + struct page *tmp_page; + void *kaddr; + unsigned int len =3D min_t(loff_t, i_size_read(inode), + f2fs_max_inline_data(inode)); + + tmp_page =3D alloc_page(GFP_NOFS | __GFP_ZERO); + if (!tmp_page) { + err =3D -ENOMEM; + goto out; + } + + len =3D round_up(len, FSCRYPT_CONTENTS_ALIGNMENT); + if (len) { + err =3D fscrypt_prepare_data_unit_inplace(inode); + if (err) { + __free_page(tmp_page); + goto out; + } + kaddr =3D kmap_local_page(tmp_page); + memcpy_from_folio(kaddr, folio, 0, + min_t(loff_t, i_size_read(inode), + f2fs_max_inline_data(inode))); + kunmap_local(kaddr); + err =3D fscrypt_crypt_data_unit_inplace(inode, tmp_page, + len, 0, 0, + true); + } + if (!err) { + memset(inline_addr, 0, MAX_INLINE_DATA(inode)); + if (len) { + kaddr =3D kmap_local_page(tmp_page); + memcpy(inline_addr, kaddr, len); + kunmap_local(kaddr); + } + } + __free_page(tmp_page); + if (err) + goto out; + } else { + memcpy_from_folio(inline_addr, folio, 0, MAX_INLINE_DATA(inode)); + } folio_mark_dirty(ifolio); =20 f2fs_clear_page_cache_dirty_tag(folio); @@ -290,8 +392,9 @@ int f2fs_write_inline_data(struct inode *inode, struct = folio *folio) set_inode_flag(inode, FI_DATA_EXIST); =20 folio_clear_f2fs_inline(ifolio); +out: f2fs_folio_put(ifolio, true); - return 0; + return err; } =20 int f2fs_recover_inline_data(struct inode *inode, struct folio *nfolio) @@ -826,7 +929,7 @@ int f2fs_inline_data_fiemap(struct inode *inode, return PTR_ERR(ifolio); f2fs_folio_wait_writeback(ifolio, NODE, true, true); } - ilen =3D min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode)); + ilen =3D min_t(size_t, f2fs_max_inline_data(inode), i_size_read(inode)); if (start >=3D ilen) goto out; if (start + len < ilen) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index c6afdbd6e1cd..9eddcde7939c 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1549,6 +1549,18 @@ static int f2fs_check_opt_consistency(struct fs_cont= ext *fc, return -EINVAL; } =20 + if (f2fs_sb_has_encrypted_inline_data(sbi)) { + if (!IS_ENABLED(CONFIG_F2FS_FS_ENCRYPTED_INLINE_DATA)) { + f2fs_err(sbi, + "encrypted_inline_data requires CONFIG_F2FS_FS_ENCRYPTED_INLINE_DATA"= ); + return -EINVAL; + } + if (!f2fs_sb_has_encrypt(sbi)) { + f2fs_err(sbi, "encrypted inline_data requires encryption feature"); + return -EINVAL; + } + } + /* * The BLKZONED feature indicates that the drive was formatted with * zone alignment optimization. This is optional for host-aware diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 665687244c93..600eaee75926 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -1399,6 +1399,9 @@ F2FS_FEATURE_RO_ATTR(pin_file); F2FS_FEATURE_RO_ATTR(linear_lookup); #endif F2FS_FEATURE_RO_ATTR(packed_ssa); +#ifdef CONFIG_F2FS_FS_ENCRYPTED_INLINE_DATA +F2FS_FEATURE_RO_ATTR(encrypted_inline_data); +#endif F2FS_FEATURE_RO_ATTR(fserror); =20 #define ATTR_LIST(name) (&f2fs_attr_##name.attr) @@ -1567,6 +1570,9 @@ static struct attribute *f2fs_feat_attrs[] =3D { BASE_ATTR_LIST(linear_lookup), #endif BASE_ATTR_LIST(packed_ssa), +#ifdef CONFIG_F2FS_FS_ENCRYPTED_INLINE_DATA + BASE_ATTR_LIST(encrypted_inline_data), +#endif BASE_ATTR_LIST(fserror), NULL, }; @@ -1604,6 +1610,7 @@ F2FS_SB_FEATURE_RO_ATTR(compression, COMPRESSION); F2FS_SB_FEATURE_RO_ATTR(readonly, RO); F2FS_SB_FEATURE_RO_ATTR(device_alias, DEVICE_ALIAS); F2FS_SB_FEATURE_RO_ATTR(packed_ssa, PACKED_SSA); +F2FS_SB_FEATURE_RO_ATTR(encrypted_inline_data, ENCRYPTED_INLINE_DATA); =20 static struct attribute *f2fs_sb_feat_attrs[] =3D { ATTR_LIST(sb_encryption), @@ -1622,6 +1629,7 @@ static struct attribute *f2fs_sb_feat_attrs[] =3D { ATTR_LIST(sb_readonly), ATTR_LIST(sb_device_alias), ATTR_LIST(sb_packed_ssa), + ATTR_LIST(sb_encrypted_inline_data), NULL, }; ATTRIBUTE_GROUPS(f2fs_sb_feat); --=20 2.34.1 From nobody Mon Jun 8 04:27:19 2026 Received: from TYDPR03CU002.outbound.protection.outlook.com (mail-japaneastazon11013042.outbound.protection.outlook.com [52.101.127.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA4423E6389; Tue, 2 Jun 2026 13:41:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.127.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780407695; cv=fail; b=MXzpmu7igKSSvCtd3Ise7EtiLy8/qsWQZ6uOMgLTwBE45Uo2gaXMxC8zNI4I8YUtk40q6D8GT0UfuBLmFyYooGfmheoOMQ2RQz2KBXbqvXFWoyEX3KqJPuu9O4RER401eYwma7vc59e/Z9tX+fnO1vls7YiWJQ0jMbFM3OS4q68= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780407695; c=relaxed/simple; bh=iMLBG+/k0NcamdRvLCm4uENEuesNe54o0rMtLDtC5AU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Ik0Ta2ep9HhydYJSzbZ77/Tt734735wBGoycHjWvAzuU6XypIXjuEREm1rlZPsBJCARKhQKuG8rWa0uqtA26vQRoVpvhAUCYySr4T4aDAgmaK/7oWuvu5f91Et9diUU+vaAwN0iRMBIdFk9qU0WkWpE8eqITUgpx5F8YSMSC7Zo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com; spf=pass smtp.mailfrom=vivo.com; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b=DGZ3x3HV; arc=fail smtp.client-ip=52.101.127.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="DGZ3x3HV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fnGPVG8HtkXM32UCV0xscCZL6j7Js27AAUk/r0sE4grkTvxDB2rEMnzvrfy7g/G6+6hCZCtJYmAbqRlSLxKpp3H8839pjDyxc6QyohWFfpwJgH5YN8tbTh+DQfFKbH9AbFSg7oFstXiZ/w//APmHlOHwCrpFvoJFkbiED/yDWSNeyYr/ulK+bZZZuZe2BqWCEDp3izrpLIxB9BdQaY79PwWS2gygdYa2DUIBSIi5fNB0uK0azMtqLHXhniGp6vlCe/FAgAL9cEestsv0c5lxWWtszuZJ9AudrpaYW19TTHG8UmiAj3K5EF9YHP94iqSADsx4OY4rjc1pQ3NK0JOhfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IGsbgp24/gLZK+zWyryaN6NwQoGL3B3SBZ3Dpcj5IWQ=; b=UGNvP+BePIMm9Qgt/Op5q6lZnDjxpz8dJciZiiqfrMU/NrMwYL7dGY55MQWC+jbPWLuVvuerziBU/zJoKUpTWVO3IESK9oZ1tNt6yPM/ULdnyvnGnpo8rfmw+6vNjSf+Ulj4zMdMHN83V5/PshIadphxyaEW4u+hxpy5YErMEgwFWB1gccPyEeQhJ+Um0t3234jTyBUESDL9UEK06zR9K5+0KJSgffnLmxb2lou7lUns3Inmpavv+hk2khDIZdy4LVDDTiU5CHNh/Y2U6IT4cItCjit182Zqhoz3MTzoXxx+84FknvnLbIELFXC2QHUp4tJLcFWxohw2OpL9nApK8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IGsbgp24/gLZK+zWyryaN6NwQoGL3B3SBZ3Dpcj5IWQ=; b=DGZ3x3HVEsc5niAPSHooldI2Ru2X+BYEwkPfSNZMaJ0lfpk2sMIwp72WUrxhwcQM/ZSSQ5GC+EPmXWLgQYjUDTFHJwf9KdHmJxCEZVtMnqEai43CHHMPqIozq72NluXbAYu21rJCfs60zkRhZhtqHANKBCLgBC4Ug72gZF0szsb5l3M3j7gQ9UM5Ug6bnQ/sit6ealUW0YFKryU103fBigG3sixiSGKKxL457mqNQqJKek+P/0bRwZMheM5msFaR5SXGsUYkE+3ihNstW+Rz60AvTKLwDeuNfjnTJG9i6qBLgSgtXAk43WRDpTGkb8Vda2azK3e8VTJeE3DR+yA7cQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5576.apcprd06.prod.outlook.com (2603:1096:101:c9::14) by TYZPR06MB5950.apcprd06.prod.outlook.com (2603:1096:400:333::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.12; Tue, 2 Jun 2026 13:41:30 +0000 Received: from SEZPR06MB5576.apcprd06.prod.outlook.com ([fe80::24bc:5613:3ffa:cb96]) by SEZPR06MB5576.apcprd06.prod.outlook.com ([fe80::24bc:5613:3ffa:cb96%6]) with mapi id 15.21.0071.015; Tue, 2 Jun 2026 13:41:30 +0000 From: LiaoYuanhong-vivo To: Jaegeuk Kim , Chao Yu , Jonathan Corbet , Shuah Khan , linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), linux-kernel@vger.kernel.org (open list), linux-doc@vger.kernel.org (open list:DOCUMENTATION) Cc: LiaoYuanhong-vivo Subject: [PATCH v2 3/3] Documentation: f2fs: document encrypted inline data Date: Tue, 2 Jun 2026 21:41:02 +0800 Message-Id: <20260602134104.348655-4-liaoyuanhong@vivo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260602134104.348655-1-liaoyuanhong@vivo.com> References: <20260602134104.348655-1-liaoyuanhong@vivo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TP0P295CA0038.TWNP295.PROD.OUTLOOK.COM (2603:1096:910:4::11) To SEZPR06MB5576.apcprd06.prod.outlook.com (2603:1096:101:c9::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5576:EE_|TYZPR06MB5950:EE_ X-MS-Office365-Filtering-Correlation-Id: 9eaf1d90-a711-4a33-b76a-08dec0aca6c3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|1800799024|366016|56012099006|11063799006|18002099003|22082099003|3023799007|38350700014; X-Microsoft-Antispam-Message-Info: Nn6k+59qa44eMOpPuSaYJWaoSicQ03d3xerimMIjTFG+Kjh5+vqUOcY8IJxyqcxQM8pPUBFkJXfRTZSdBflsMsWQUnswu97tUKuTwCjYzU1PWPbNBWFaWyvrJCY1osvuL6GoI1TP2W98z8riy/J71n73c4CSmVy0RXVp+ufjVeLtuLraUPCes0q/DrhqBQ3JvEtGwyBy8LTpUHfxK4XPSJHe4PLhsnSIvN1goK5rL/LiT5c/esx94nCnASS3RIS7/dT7xsV9qzpS5gizOPBkhBZQpZOFCrTPprSJ8CknyuQs8fLAtYqngexK0Yq2hMpvznw981xHpD26bCWLFnzxeQBP02JMHDoBZWBMqjaAiyIBwRcRGPbNPBf24SHnVweMEYyofbESicbcAECtmWaVhgyZ+hn65ztXJADspbw4/2kar3s8W4RwCSazqWC/xPCkPkrrfP3df7rxY7v6QiJQQOhABM5cQMkJT0AEqj7ALng79ju49SL9pM8+IOD04J4DxSLVEaPmHmiw8ZfNcV7QzFBSvjt9zOsfW4Z4QkqE9b/C2WnaQJ6mKdo/RpGebyFki7+r7rykpIt81UT/jDTtXoeR/UDPds7d2NML4iZ3d1c0pGiuUN+s+/ZpWL95oYy4OaeWdeNlxsh95vspVE7GliHDYPZh+SXxzXVr4zs5WkU4v83rP2+p+nFD6EDjCsqDtsdXTUHGu82eS2seydB/6fjOOxeB5TLA5EPRGyl2zEux2q9pOl6PjjgXbHv8PUjv X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEZPR06MB5576.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(1800799024)(366016)(56012099006)(11063799006)(18002099003)(22082099003)(3023799007)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?SMBT8w2S5xg95hVjVIX1H8Yu6AhHRfztWbcNXtUhNKXLibLto2TKB7qh4aDt?= =?us-ascii?Q?j1pKeZ8VbxIZE8U8Ps3Bjhb0Ahz5bPbsQpfzI9pGel96DnD47JXamk2Q42D/?= =?us-ascii?Q?AbLZ4LuXkXgn//03Li/57/BVOIbWa1ScqAS6FpVT6unai2AZLnrIBu+dj6mw?= =?us-ascii?Q?nh7xJdt/T3OKefj2Mz7d6nAed4Mb2CATVYU6mWKeCk7UkJb5ldYnJeXvRDBj?= =?us-ascii?Q?Q0wtHiWzHtAzmloecc4q0Jgk74rplG6+LaO6Sq7jUF5eArs7I20NOvMPKQ6B?= =?us-ascii?Q?w3AB+BfxaAxXpV38ZUC5hkfN9cOhnDvbIE/D52C9EVWazUQfuD7PmwX5kYOS?= =?us-ascii?Q?n1RMEjixxe/E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ascii?Q?xsIswbrOAsPkqz/KSvZrSQu30fcGC2mkVlRlDnUNV9LFfy6rpHjBnCc+kyh1?= =?us-ascii?Q?mhgOq50/qDDDGYpviC0/iXuwSRH593hY1aX7N5emzhExgSJyKxXlZUxl/qL/?= =?us-ascii?Q?/LKp6AEO85z33jWEovQvwXjWEzEeCrsl661dxDoioJRNsihbkWeNNoKcIScy?= =?us-ascii?Q?quQDOPwBuilph+bj1t0swMVimJp4K98w0TL/Y7cNbe4oYzREvKbxqNQc8lCY?= =?us-ascii?Q?yph1XAiH3OvSGkvWwl0goh3N9PacOzWK5lC0bFk7A0mN8k8MNPvo2ncZ5FAQ?= =?us-ascii?Q?jyVoBy1Qgg3lYsPYnPvujonh/qLbM9UDz6frGJoElyAVnx8Zi4vnJwssw6hg?= =?us-ascii?Q?6ZaXtdPpEDhV+qquqMdY74DbP3n+PBXG+ldjCmwqn09+9j3DDyXnz0s8gC4S?= =?us-ascii?Q?spM/TTW8OlzTmO7Jfg7Al5HGAZqfXv0It+Eo5rs7wl2Xz4vBoZ6n15g46y7I?= =?us-ascii?Q?/yXlgqK/bQ=3D=3D?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9eaf1d90-a711-4a33-b76a-08dec0aca6c3 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5576.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2026 13:41:29.9675 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: r4oZF+63BsVtxG1pvMheH5scnYDiLN3fJuhfsH7omsAkgIGEf3MCofB9Bk92iDbXqlX0MVBBTE+oxllxNtcpiQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB5950 Content-Type: text/plain; charset="utf-8" Document the F2FS encrypted_inline_data feature, including the on-disk feature requirement, the CONFIG_F2FS_FS_ENCRYPTED_INLINE_DATA dependency, how inline payloads are encrypted and decrypted, and the truncate behavior. Also document the supported key combinations. Files using filesystem-layer encryption reuse the normal software transform. Raw-key inlinecrypt is supported only for per-mode policies, while per-file inlinecrypt keys and hardware-wrapped keys are not supported for encrypted inline data. List encrypted_inline_data in the supported F2FS feature sysfs documentation. Signed-off-by: LiaoYuanhong-vivo --- Changes in v2: - Document raw-key inlinecrypt support as limited to per-mode policies. - Document unsupported per-file inlinecrypt and hardware-wrapped key cases. - Clarify when fscrypt prepares the software transform for inline payloads. Documentation/ABI/testing/sysfs-fs-f2fs | 5 ++-- Documentation/filesystems/f2fs.rst | 34 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/te= sting/sysfs-fs-f2fs index 27d5e88facbe..dad483fb2fc1 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -258,7 +258,8 @@ Description: Expand /sys/fs/f2fs//features to mee= t sysfs rule. encryption, block_zoned (aka blkzoned), extra_attr, project_quota (aka projquota), inode_checksum, flexible_inline_xattr, quota_ino, inode_crtime, lost_found, - verity, sb_checksum, casefold, readonly, compression. + verity, sb_checksum, casefold, readonly, compression, + encrypted_inline_data. Note that, pin_file is moved into /sys/fs/f2fs/features/. =20 What: /sys/fs/f2fs/features/ @@ -271,7 +272,7 @@ Description: Shows all enabled kernel features. inode_crtime, lost_found, verity, sb_checksum, casefold, readonly, compression, test_dummy_encryption_v2, atomic_write, pin_file, encrypted_casefold, linear_lookup, - fserror. + fserror, encrypted_inline_data. =20 What: /sys/fs/f2fs//inject_rate Date: May 2016 diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems= /f2fs.rst index 5bc37a1c4e51..feffad89db01 100644 --- a/Documentation/filesystems/f2fs.rst +++ b/Documentation/filesystems/f2fs.rst @@ -420,6 +420,40 @@ lookup_mode=3D%s Control the directory lookup behavi= or for casefolded =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 +Encrypted inline data +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +F2FS normally disables inline data for encrypted regular files, since inli= ne +data is stored inside the inode block and does not pass through the regular +block I/O path. When a filesystem is formatted with the encrypted_inline_= data +feature, encrypted regular files may keep small file contents in the inode +block. The inline payload is encrypted with fscrypt contents-key semantics +before it is written to the inode, and it is decrypted back to page-cache +plaintext when it is read. + +This feature requires the encrypt feature on disk and kernel support for +CONFIG_F2FS_FS_ENCRYPTED_INLINE_DATA. It is intended to be used together = with +the inline_data mount option. Files using filesystem-layer encryption reu= se the +normal software contents-key transform. When the normal encrypted file +contents path uses blk-crypto with a raw per-mode key, fscrypt can prepare= a +software contents-key transform when the filesystem-managed inline payload= is +read or written. +Per-file inlinecrypt keys are not supported for encrypted inline data, to = avoid +per-file software transform memory growth. Hardware-wrapped keys are not +supported for encrypted inline data, so F2FS does not create encrypted inl= ine +payloads for such files and existing unsupported inline payloads fail rath= er +than being interpreted with the wrong key. + +Encrypted inline data is stored in fscrypt contents-aligned units. Theref= ore, +the maximum plaintext size that can stay inline may be slightly smaller th= an the +ordinary inline data capacity. If an encrypted inline-data file is trunca= ted +from a non-zero offset, F2FS first converts the inline payload to normal d= ata +blocks and then applies the truncate operation. + +Recovery copies inline payloads as on-disk bytes. Encryption and decrypti= on are +performed only when moving data between the inode inline area and page-cac= he +plaintext. + Debugfs Entries =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 --=20 2.34.1