From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 971A7304BC4 for ; Fri, 14 Nov 2025 22:58:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763161136; cv=none; b=U1PBSBnFmGxwefu7i9twVGestp6CF04lmxeefS/hGCyKqrw7Jmjxfyuxno/5UfupEnKnzLTZchKE334LMzUOeiqzkNhfWABY3nh45m0Ud3Fq48iarZNJYAWJbHXuoCT3ocHjMkIoT2zzOuED0UghJhVNHJrCfiVGCLVzUiqVJVk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763161136; c=relaxed/simple; bh=ipkw7gDXNKw457zzrFhf/wCTkh2JVz3fmqAqqHA0Khg=; h=Date:To:From:Subject:Message-Id; b=lprOx2hMIf8gP6S28wCDVSUfFd+0iEvBR3CwIN8tfJ418eSBVjfV6drEbWDWy+mc2n6eOO54nwYKN7+2empYo/KBWT/m4f6YtARquxHGkInbITzCF5laopNcIOTkmNfuYTEl9IXv3Kab5cZFsAZRBUG1Ql3iEm/v295Sm16hdII= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=Yfhbnp7V; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="Yfhbnp7V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 200F4C4CEF1; Fri, 14 Nov 2025 22:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1763161136; bh=ipkw7gDXNKw457zzrFhf/wCTkh2JVz3fmqAqqHA0Khg=; h=Date:To:From:Subject:From; b=Yfhbnp7VYXFOD+gRsJxU+U+XngdFjGSf2tfZ1WC4o2xsAy332wy3sl8KuHtS7/9OX ELFuFOv+T4Ki1ZUWZI1oTmD2oOnTvNwcvU5COz02uVjqjH6sRjKEMQvQHqR3hoq7BL 4d/zeRB828ELus0BO5snvVpIvOESE/C7wdOfKhzk= Date: Fri, 14 Nov 2025 14:58:55 -0800 To: mm-commits@vger.kernel.org,xiubli@redhat.com,visitorckw@gmail.com,tytso@mit.edu,Slava.Dubeyko@ibm.com,sagi@grimberg.me,kbusch@kernel.org,jaegeuk@kernel.org,idryomov@gmail.com,home7438072@gmail.com,hch@lst.de,ebiggers@kernel.org,david.laight.linux@gmail.com,axboe@kernel.dk,409411716@gms.tku.edu.tw,akpm@linux-foundation.org From: Andrew Morton Subject: + ceph-replace-local-base64-helpers-with-lib-base64.patch added to mm-nonmm-unstable branch Message-Id: <20251114225856.200F4C4CEF1@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: ceph: replace local base64 helpers with lib/base64 has been added to the -mm mm-nonmm-unstable branch. Its filename is ceph-replace-local-base64-helpers-with-lib-base64.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/ceph-replace-local-base64-helpers-with-lib-base64.patch This patch will later appear in the mm-nonmm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Guan-Chun Wu <409411716@gms.tku.edu.tw> Subject: ceph: replace local base64 helpers with lib/base64 Date: Fri, 14 Nov 2025 14:02:40 +0800 Remove the ceph_base64_encode() and ceph_base64_decode() functions and replace their usage with the generic base64_encode() and base64_decode() helpers from lib/base64. This eliminates the custom implementation in Ceph, reduces code duplication, and relies on the shared Base64 code in lib. The helpers preserve RFC 3501-compliant Base64 encoding without padding, so there are no functional changes. This change also improves performance: encoding is about 2.7x faster and decoding achieves 43-52x speedups compared to the previous local implementation. Link: https://lkml.kernel.org/r/20251114060240.89965-1-409411716@gms.tku.edu.tw Signed-off-by: Guan-Chun Wu <409411716@gms.tku.edu.tw> Reviewed-by: Kuan-Wei Chiu Reviewed-by: Viacheslav Dubeyko Cc: Keith Busch Cc: Jens Axboe Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Xiubo Li Cc: Ilya Dryomov Cc: Eric Biggers Cc: "Theodore Y. Ts'o" Cc: Jaegeuk Kim Cc: David Laight Cc: Yu-Sheng Huang Signed-off-by: Andrew Morton --- fs/ceph/crypto.c | 60 +++------------------------------------------ fs/ceph/crypto.h | 6 ---- fs/ceph/dir.c | 5 ++- fs/ceph/inode.c | 2 - 4 files changed, 9 insertions(+), 64 deletions(-) --- a/fs/ceph/crypto.c~ceph-replace-local-base64-helpers-with-lib-base64 +++ a/fs/ceph/crypto.c @@ -15,59 +15,6 @@ #include "mds_client.h" #include "crypto.h" -/* - * The base64url encoding used by fscrypt includes the '_' character, which may - * cause problems in snapshot names (which can not start with '_'). Thus, we - * used the base64 encoding defined for IMAP mailbox names (RFC 3501) instead, - * which replaces '-' and '_' by '+' and ','. - */ -static const char base64_table[65] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; - -int ceph_base64_encode(const u8 *src, int srclen, char *dst) -{ - u32 ac = 0; - int bits = 0; - int i; - char *cp = dst; - - for (i = 0; i < srclen; i++) { - ac = (ac << 8) | src[i]; - bits += 8; - do { - bits -= 6; - *cp++ = base64_table[(ac >> bits) & 0x3f]; - } while (bits >= 6); - } - if (bits) - *cp++ = base64_table[(ac << (6 - bits)) & 0x3f]; - return cp - dst; -} - -int ceph_base64_decode(const char *src, int srclen, u8 *dst) -{ - u32 ac = 0; - int bits = 0; - int i; - u8 *bp = dst; - - for (i = 0; i < srclen; i++) { - const char *p = strchr(base64_table, src[i]); - - if (p == NULL || src[i] == 0) - return -1; - ac = (ac << 6) | (p - base64_table); - bits += 6; - if (bits >= 8) { - bits -= 8; - *bp++ = (u8)(ac >> bits); - } - } - if (ac & ((1 << bits) - 1)) - return -1; - return bp - dst; -} - static int ceph_crypt_get_context(struct inode *inode, void *ctx, size_t len) { struct ceph_inode_info *ci = ceph_inode(inode); @@ -318,7 +265,7 @@ int ceph_encode_encrypted_dname(struct i } /* base64 encode the encrypted name */ - elen = ceph_base64_encode(cryptbuf, len, p); + elen = base64_encode(cryptbuf, len, p, false, BASE64_IMAP); doutc(cl, "base64-encoded ciphertext name = %.*s\n", elen, p); /* To understand the 240 limit, see CEPH_NOHASH_NAME_MAX comments */ @@ -412,7 +359,8 @@ int ceph_fname_to_usr(const struct ceph_ tname = &_tname; } - declen = ceph_base64_decode(name, name_len, tname->name); + declen = base64_decode(name, name_len, + tname->name, false, BASE64_IMAP); if (declen <= 0) { ret = -EIO; goto out; @@ -426,7 +374,7 @@ int ceph_fname_to_usr(const struct ceph_ ret = fscrypt_fname_disk_to_usr(dir, 0, 0, &iname, oname); if (!ret && (dir != fname->dir)) { - char tmp_buf[CEPH_BASE64_CHARS(NAME_MAX)]; + char tmp_buf[BASE64_CHARS(NAME_MAX)]; name_len = snprintf(tmp_buf, sizeof(tmp_buf), "_%.*s_%ld", oname->len, oname->name, dir->i_ino); --- a/fs/ceph/crypto.h~ceph-replace-local-base64-helpers-with-lib-base64 +++ a/fs/ceph/crypto.h @@ -8,6 +8,7 @@ #include #include +#include #define CEPH_FSCRYPT_BLOCK_SHIFT 12 #define CEPH_FSCRYPT_BLOCK_SIZE (_AC(1, UL) << CEPH_FSCRYPT_BLOCK_SHIFT) @@ -89,11 +90,6 @@ static inline u32 ceph_fscrypt_auth_len( */ #define CEPH_NOHASH_NAME_MAX (180 - SHA256_DIGEST_SIZE) -#define CEPH_BASE64_CHARS(nbytes) DIV_ROUND_UP((nbytes) * 4, 3) - -int ceph_base64_encode(const u8 *src, int srclen, char *dst); -int ceph_base64_decode(const char *src, int srclen, u8 *dst); - void ceph_fscrypt_set_ops(struct super_block *sb); void ceph_fscrypt_free_dummy_policy(struct ceph_fs_client *fsc); --- a/fs/ceph/dir.c~ceph-replace-local-base64-helpers-with-lib-base64 +++ a/fs/ceph/dir.c @@ -998,13 +998,14 @@ static int prep_encrypted_symlink_target if (err) goto out; - req->r_path2 = kmalloc(CEPH_BASE64_CHARS(osd_link.len) + 1, GFP_KERNEL); + req->r_path2 = kmalloc(BASE64_CHARS(osd_link.len) + 1, GFP_KERNEL); if (!req->r_path2) { err = -ENOMEM; goto out; } - len = ceph_base64_encode(osd_link.name, osd_link.len, req->r_path2); + len = base64_encode(osd_link.name, osd_link.len, + req->r_path2, false, BASE64_IMAP); req->r_path2[len] = '\0'; out: fscrypt_fname_free_buffer(&osd_link); --- a/fs/ceph/inode.c~ceph-replace-local-base64-helpers-with-lib-base64 +++ a/fs/ceph/inode.c @@ -958,7 +958,7 @@ static int decode_encrypted_symlink(stru if (!sym) return -ENOMEM; - declen = ceph_base64_decode(encsym, enclen, sym); + declen = base64_decode(encsym, enclen, sym, false, BASE64_IMAP); if (declen < 0) { pr_err_client(cl, "can't decode symlink (%d). Content: %.*s\n", _ Patches currently in -mm which might be from 409411716@gms.tku.edu.tw are lib-base64-rework-encode-decode-for-speed-and-stricter-validation.patch lib-add-kunit-tests-for-base64-encoding-decoding.patch fscrypt-replace-local-base64url-helpers-with-lib-base64.patch ceph-replace-local-base64-helpers-with-lib-base64.patch