From nobody Thu Dec 18 03:29:51 2025 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 822992EB5B4 for ; Fri, 14 Nov 2025 06:02:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763100170; cv=none; b=mjYD41NR7jCceAIKPTvGvYnalQUwreNKoKygJyBdBb1c4S2xm4mH9kXTED6Gr4sXSrMJcCwdDH1xm4jH6gFmEqIvddGeNhq6ccxn72Xj0XsPRXttSQOHboRnjc5Vs4nEADcYmV6IUwf4lH/2YdE8ddA17yze/epDBRUH4OpMENA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763100170; c=relaxed/simple; bh=gDlG7kblX5YeTHlzPrAqnEVGCYQCrx9weplGIGbrDpA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cmA65ppKeVgZRvScQQT/tSbHTT+KSeFIxOyaOaDBq0WQoD+Fp5A0tIFLK6K5crFkiZFIZKqS3N98z0qEaNZIz3Y5HgnjA2SG3Jek/Rcw9xEBP07VB3YQK654IiD8a38MckxHvwVK3I1CPNMOgq7Pl6hFWH8CoP/zF+YVLC7GXMU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gms.tku.edu.tw; spf=pass smtp.mailfrom=gms.tku.edu.tw; dkim=pass (2048-bit key) header.d=gms-tku-edu-tw.20230601.gappssmtp.com header.i=@gms-tku-edu-tw.20230601.gappssmtp.com header.b=ZFGM+JFR; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gms.tku.edu.tw Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gms.tku.edu.tw Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gms-tku-edu-tw.20230601.gappssmtp.com header.i=@gms-tku-edu-tw.20230601.gappssmtp.com header.b="ZFGM+JFR" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-7a9c64dfa8aso1434316b3a.3 for ; Thu, 13 Nov 2025 22:02:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gms-tku-edu-tw.20230601.gappssmtp.com; s=20230601; t=1763100168; x=1763704968; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y3VNVy+UYeqY3IVTtkh/AbSvZ3E8GHu4GINXGK2iL3Y=; b=ZFGM+JFRrpC2719pwW9w3/ChjvaR2tTMKgsVK1oUWlePszG4GrKOiWk4H6P550LKI+ DVgEquE55pjrW/0WvmBeCsojIMDM579HC3DUxxr4lr1i+90jIcFC6hosyEv5UtoacMXj i2Xr0IZPS1DlN0KGWj0Rx6cH603C31FKKw9kBlH28bID43dBfVX4Ra5W0D2kD7dDaDUI 9CmLM44Tb/5+7ES85BTSXL5AWcKJtxDkDfn6Xj4ISpsnHDLpI8eTwUShWX+gCevZt//0 SagegkvypNQ4tWRpD7SOzLU1cCijbVanaP0sd97xQQy11RTV7dMUnu2pWwbgcOHWrLU+ zgjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763100168; x=1763704968; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=y3VNVy+UYeqY3IVTtkh/AbSvZ3E8GHu4GINXGK2iL3Y=; b=e4xSbKrkHfxV5Ai4gG2vkIEivOfa17uqNp8MI0GRsx/QX1MityF0KFDU1ZNuAIAfnu QfxEK3PB5AJVeoNflAXqr4UuuwEAjySskVV83BHxFAzmwxkwLc2iO+vNyuliUuSFBio7 bycSzMqhJsfrHXLLRS2juZWpaTGslXN65PeQOpngStNJTutQIxP1nTTj+8S8USQbXL/Z Y03CHIIAp/FgBUyyHQnnZqoqjADpp2s6/HU4f3KXeDBUFwkLzz8g6m1T80oBdDepw0L7 9pVUssjUcO5YCafcN/tTH4srldxarY4N0QT/GFyDSe/8aWxr4g0H0FrT0uJMmAqGtnnP Brrg== X-Forwarded-Encrypted: i=1; AJvYcCWHgNqX54xsmH2JRTYbIbWnW3OwnsA8FkNRcOEgFYyjW+BNKgG6S06LPs8um3ZnW0Ujqugk/W7w862ZdSw=@vger.kernel.org X-Gm-Message-State: AOJu0Yynoz+f/O6/yPmt880QUWhpB6cqrzEK5EmNdoguKVmBpbv/UkBx 7k13EH4to+HjcG1dnkMpazJnvfBZG3yF/obqiZ8rXM/k8tRh1ik//ZPCy7MjwoYppc0= X-Gm-Gg: ASbGnctaapYFiyds8yVT95TgaMDqCWQL+4Gf12VX7mqKhZJbewgDabTbLjo6dEEvUgW FLZIAkJTqZ0gQi5tjndweTMVuWoJOCqTxJnBMSBtcS/UnRxLF70EGQqZXu4zUYvns8qS1cVuGPE 1VPUf0ewN9VY5hTAHpuy0hKM/Gzu44+8HaqzvFYo3Km+1uoay7t7hkn5rG//RehKOxWux6wOgAY pJt2VWDIuSVNkv2yhroRy3/hk0AbiaYeTnVEJZhanSUl+V/nyxcd6O6dpa2i8QDw3xkRvuM0Rfa VdcFdIXuQeQrkkHIxHj/W3rlLG5/cgL+pX/wVPt+IA1hI40NordVsDUzmS7ct5o0fjDvf3HWnvQ 221hMXY2w0TEkTGwBhTwy83HMV8Twqh+2nSPnyZbYTJQGWCoEV86Q5N/88SJitRIAJp9NPRyVDg SjpLfJsNSf5x0CNG2aXOUySifNXqOafjY8yWM= X-Google-Smtp-Source: AGHT+IFu12NV5C3ZMb+GzTshy782WYZvWJoPnURdrRS7I9I9BogTqLlIkKyKPKA2EoshONrHEKmUHw== X-Received: by 2002:a05:6a00:4b12:b0:7a4:f552:b522 with SMTP id d2e1a72fcca58-7ba3c669976mr2406190b3a.27.1763100167825; Thu, 13 Nov 2025 22:02:47 -0800 (PST) Received: from wu-Pro-E500-G6-WS720T.. ([2001:288:7001:2703:22d2:323c:497d:adbd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7ba438bed8csm1236316b3a.53.2025.11.13.22.02.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Nov 2025 22:02:47 -0800 (PST) From: Guan-Chun Wu <409411716@gms.tku.edu.tw> To: 409411716@gms.tku.edu.tw Cc: akpm@linux-foundation.org, andriy.shevchenko@intel.com, axboe@kernel.dk, ceph-devel@vger.kernel.org, david.laight.linux@gmail.com, ebiggers@kernel.org, hch@lst.de, home7438072@gmail.com, idryomov@gmail.com, jaegeuk@kernel.org, kbusch@kernel.org, linux-fscrypt@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, sagi@grimberg.me, tytso@mit.edu, visitorckw@gmail.com, xiubli@redhat.com Subject: [PATCH v5 6/6] ceph: replace local base64 helpers with lib/base64 Date: Fri, 14 Nov 2025 14:02:40 +0800 Message-Id: <20251114060240.89965-1-409411716@gms.tku.edu.tw> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251114055829.87814-1-409411716@gms.tku.edu.tw> References: <20251114055829.87814-1-409411716@gms.tku.edu.tw> 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 Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: Kuan-Wei Chiu Signed-off-by: Guan-Chun Wu <409411716@gms.tku.edu.tw> Reviewed-by: Viacheslav Dubeyko Tested-by: Viacheslav Dubeyko --- 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(-) diff --git a/fs/ceph/crypto.c b/fs/ceph/crypto.c index 7026e794813c..b6016dcffbb6 100644 --- a/fs/ceph/crypto.c +++ b/fs/ceph/crypto.c @@ -15,59 +15,6 @@ #include "mds_client.h" #include "crypto.h" =20 -/* - * The base64url encoding used by fscrypt includes the '_' character, whic= h may - * cause problems in snapshot names (which can not start with '_'). Thus,= we - * used the base64 encoding defined for IMAP mailbox names (RFC 3501) inst= ead, - * which replaces '-' and '_' by '+' and ','. - */ -static const char base64_table[65] =3D - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; - -int ceph_base64_encode(const u8 *src, int srclen, char *dst) -{ - u32 ac =3D 0; - int bits =3D 0; - int i; - char *cp =3D dst; - - for (i =3D 0; i < srclen; i++) { - ac =3D (ac << 8) | src[i]; - bits +=3D 8; - do { - bits -=3D 6; - *cp++ =3D base64_table[(ac >> bits) & 0x3f]; - } while (bits >=3D 6); - } - if (bits) - *cp++ =3D base64_table[(ac << (6 - bits)) & 0x3f]; - return cp - dst; -} - -int ceph_base64_decode(const char *src, int srclen, u8 *dst) -{ - u32 ac =3D 0; - int bits =3D 0; - int i; - u8 *bp =3D dst; - - for (i =3D 0; i < srclen; i++) { - const char *p =3D strchr(base64_table, src[i]); - - if (p =3D=3D NULL || src[i] =3D=3D 0) - return -1; - ac =3D (ac << 6) | (p - base64_table); - bits +=3D 6; - if (bits >=3D 8) { - bits -=3D 8; - *bp++ =3D (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 l= en) { struct ceph_inode_info *ci =3D ceph_inode(inode); @@ -318,7 +265,7 @@ int ceph_encode_encrypted_dname(struct inode *parent, c= har *buf, int elen) } =20 /* base64 encode the encrypted name */ - elen =3D ceph_base64_encode(cryptbuf, len, p); + elen =3D base64_encode(cryptbuf, len, p, false, BASE64_IMAP); doutc(cl, "base64-encoded ciphertext name =3D %.*s\n", elen, p); =20 /* To understand the 240 limit, see CEPH_NOHASH_NAME_MAX comments */ @@ -412,7 +359,8 @@ int ceph_fname_to_usr(const struct ceph_fname *fname, s= truct fscrypt_str *tname, tname =3D &_tname; } =20 - declen =3D ceph_base64_decode(name, name_len, tname->name); + declen =3D base64_decode(name, name_len, + tname->name, false, BASE64_IMAP); if (declen <=3D 0) { ret =3D -EIO; goto out; @@ -426,7 +374,7 @@ int ceph_fname_to_usr(const struct ceph_fname *fname, s= truct fscrypt_str *tname, =20 ret =3D fscrypt_fname_disk_to_usr(dir, 0, 0, &iname, oname); if (!ret && (dir !=3D fname->dir)) { - char tmp_buf[CEPH_BASE64_CHARS(NAME_MAX)]; + char tmp_buf[BASE64_CHARS(NAME_MAX)]; =20 name_len =3D snprintf(tmp_buf, sizeof(tmp_buf), "_%.*s_%ld", oname->len, oname->name, dir->i_ino); diff --git a/fs/ceph/crypto.h b/fs/ceph/crypto.h index 23612b2e9837..b748e2060bc9 100644 --- a/fs/ceph/crypto.h +++ b/fs/ceph/crypto.h @@ -8,6 +8,7 @@ =20 #include #include +#include =20 #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(struct ceph_fscr= ypt_auth *fa) */ #define CEPH_NOHASH_NAME_MAX (180 - SHA256_DIGEST_SIZE) =20 -#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); =20 void ceph_fscrypt_free_dummy_policy(struct ceph_fs_client *fsc); diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index d18c0eaef9b7..0fa7c7777242 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -998,13 +998,14 @@ static int prep_encrypted_symlink_target(struct ceph_= mds_request *req, if (err) goto out; =20 - req->r_path2 =3D kmalloc(CEPH_BASE64_CHARS(osd_link.len) + 1, GFP_KERNEL); + req->r_path2 =3D kmalloc(BASE64_CHARS(osd_link.len) + 1, GFP_KERNEL); if (!req->r_path2) { err =3D -ENOMEM; goto out; } =20 - len =3D ceph_base64_encode(osd_link.name, osd_link.len, req->r_path2); + len =3D base64_encode(osd_link.name, osd_link.len, + req->r_path2, false, BASE64_IMAP); req->r_path2[len] =3D '\0'; out: fscrypt_fname_free_buffer(&osd_link); diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index a6e260d9e420..b691343cb7f1 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -958,7 +958,7 @@ static int decode_encrypted_symlink(struct ceph_mds_cli= ent *mdsc, if (!sym) return -ENOMEM; =20 - declen =3D ceph_base64_decode(encsym, enclen, sym); + declen =3D base64_decode(encsym, enclen, sym, false, BASE64_IMAP); if (declen < 0) { pr_err_client(cl, "can't decode symlink (%d). Content: %.*s\n", --=20 2.34.1