smb: improve search speed of SMB2 maperror
Subsystems (2)
v4 cover smb: improve search speed of SMB2 maperror
From: ChenXiaoSong <[email protected]>
Before applying this patchset, when searching for the last element of smb2_error_map_table array and calling smb2_print_status(), 3486 comparisons are needed.
After applying this patchset, only 10 comparisons are required.
v1: https://lore.kernel.org/linux-cifs/[email protected]/
The three patches from v1 have already been applied to the for-next branch of cifs-2.6.git. Please replace the following patches:
- [v1 01/10] smb/client: reduce loop count in map_smb2_to_linux_error() by half: https://git.samba.org/sfrench/?p=sfrench/cifs-2.6.git;a=commitdiff;h=26866d690bd180e1860548c43e70fdefe50638ff
- Replace it with this version(v4) patch #0001: update commit message: array has 1743 elements
- [v1 02/10] smb/client: remove unused elements from smb2_error_map_table array: https://git.samba.org/sfrench/?p=sfrench/cifs-2.6.git;a=commitdiff;h=905d8999d67dcbe4ce12ef87996e4440e068196d
- It is the same as patch #0002 in this version(v4).
- [v1 03/10] smb: add two elements to smb2_error_map_table array: https://git.samba.org/sfrench/?p=sfrench/cifs-2.6.git;a=commitdiff;h=ba521f56912f6ff5121e54c17c855298f947c9ea
- Replace it with this version(v4) patch #0003 #0004.
v3: https://lore.kernel.org/linux-cifs/[email protected]/v3->v4:
- Patch #0008: the KUnit test searches all elements of the smb2_error_map_table array
- Create patch #0009
ChenXiaoSong (10):
smb/client: reduce loop count in map_smb2_to_linux_error() by half smb/client: remove unused elements from smb2_error_map_table array
smb: rename to STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP smb/client: add two elements to smb2_error_map_table array smb/client: sort smb2_error_map_table array
smb/client: use bsearch() to find target status code smb/client: introduce smb2_get_err_map()
smb/client: introduce smb2maperror KUnit tests smb/client: update some SMB2 status strings
smb/server: rename include guard in smb_common.h
fs/smb/Kconfig | 17 +++++ fs/smb/client/cifsfs.c | 2 + fs/smb/client/smb2glob.h | 6 ++ fs/smb/client/smb2maperror.c | 101 +++++++++++++++++------------- fs/smb/client/smb2maperror_test.c | 71 +++++++++++++++++++++ fs/smb/client/smb2proto.h | 4 +- fs/smb/common/smb2status.h | 5 +- fs/smb/server/smb2pdu.c | 2 +- fs/smb/server/smb_common.h | 6 +- 9 files changed, 165 insertions(+), 49 deletions(-) create mode 100644 fs/smb/client/smb2maperror_test.c
Signature · 1 line
2.43.0
PATCH v4 1/10 smb/client: reduce loop count in map_smb2_to_linux_error() by half
From: ChenXiaoSong <[email protected]>
The smb2_error_map_table array currently has 1743 elements. When searching for the last element and calling smb2_print_status(), 3486 comparisons are needed.
The loop in smb2_print_status() is unnecessary, smb2_print_status() can be removed, and only iterate over the array once, printing the message when the target status code is found.
--- fs/smb/client/smb2maperror.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-)
fs/smb/client/smb2maperror.c +6 -24
@@ -2418,24 +2418,6 @@ static const struct status_to_posix_error smb2_error_map_table[] = { {0, 0, NULL} }; -/***************************************************************************** -Print an error message from the status code -*****************************************************************************/ -static void -smb2_print_status (__le32 status) -{ -int idx =0 ; - -while (smb2_error_map_table[idx].status_string !=NULL ) { -if ((smb2_error_map_table[idx].smb2_status) == status) { -pr_notice ("Status code returned 0x%08x %s\n" , status, - smb2_error_map_table[idx].status_string); - } - idx++; - } -return ; -} -int map_smb2_to_linux_error (char *buf,bool log_err) {
@@ -2452,16 +2434,16 @@ map_smb2_to_linux_error(char *buf, bool log_err)return 0 ; } -/* mask facility */ -if (log_err && (smb2err !=STATUS_MORE_PROCESSING_REQUIRED ) && - (smb2err !=STATUS_END_OF_FILE )) -smb2_print_status (smb2err); -else if (cifsFYI &CIFS_RC ) -smb2_print_status (smb2err); + log_err = (log_err && (smb2err !=STATUS_MORE_PROCESSING_REQUIRED ) && + (smb2err !=STATUS_END_OF_FILE )) || + (cifsFYI &CIFS_RC );for (i =0 ; i <sizeof (smb2_error_map_table) /sizeof (struct status_to_posix_error ); i++) {if (smb2_error_map_table[i].smb2_status == smb2err) { +if (log_err) +pr_notice ("Status code returned 0x%08x %s\n" , smb2err, + smb2_error_map_table[i].status_string); rc = smb2_error_map_table[i].posix_error;break ; }
Signature · 1 line
2.43.0
PATCH v4 2/10 smb/client: remove unused elements from smb2_error_map_table array
In reply to [email protected]From: ChenXiaoSong <[email protected]>
STATUS_SUCCESS and STATUS_WAIT_0 are both zero, and since zero indicates success, they are not needed.
Since smb2_print_status() has been removed, the last element in the array is no longer needed.
--- fs/smb/client/smb2maperror.c | 3 --- 1 file changed, 3 deletions(-)
fs/smb/client/smb2maperror.c +0 -3
@@ -23,8 +23,6 @@ struct status_to_posix_error { };static const struct status_to_posix_error smb2_error_map_table[] = { - {STATUS_SUCCESS ,0 ,"STATUS_SUCCESS" }, - {STATUS_WAIT_0 ,0 ,"STATUS_WAIT_0" }, {STATUS_WAIT_1 , -EIO ,"STATUS_WAIT_1" }, {STATUS_WAIT_2 , -EIO ,"STATUS_WAIT_2" }, {STATUS_WAIT_3 , -EIO ,"STATUS_WAIT_3" },
@@ -2415,7 +2413,6 @@ static const struct status_to_posix_error smb2_error_map_table[] = { {STATUS_IPSEC_INTEGRITY_CHECK_FAILED , -EIO , "STATUS_IPSEC_INTEGRITY_CHECK_FAILED"}, {STATUS_IPSEC_CLEAR_TEXT_DROP, -EIO, "STATUS_IPSEC_CLEAR_TEXT_DROP"}, - {0, 0, NULL} };int
Signature · 1 line
2.43.0
PATCH v4 3/10 smb: rename to STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP
In reply to [email protected]From: ChenXiaoSong <[email protected]>
See MS-SMB2 3.3.5.4. To keep the name consistent with the documentation.
Additionally, move STATUS_INVALID_LOCK_RANGE to correct position in order.
--- fs/smb/common/smb2status.h | 5 +++-- fs/smb/server/smb2pdu.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
fs/smb/common/smb2status.h +3 -2
@@ -631,6 +631,7 @@ struct ntstatus {#define STATUS_DOMAIN_TRUST_INCONSISTENT cpu_to_le32(0xC000019B)#define STATUS_FS_DRIVER_REQUIRED cpu_to_le32(0xC000019C)#define STATUS_IMAGE_ALREADY_LOADED_AS_DLL cpu_to_le32(0xC000019D) +#define STATUS_INVALID_LOCK_RANGE cpu_to_le32(0xC00001A1)#define STATUS_NETWORK_OPEN_RESTRICTION cpu_to_le32(0xC0000201)#define STATUS_NO_USER_SESSION_KEY cpu_to_le32(0xC0000202)#define STATUS_USER_SESSION_DELETED cpu_to_le32(0xC0000203)
@@ -1773,5 +1774,5 @@ struct ntstatus {#define STATUS_IPSEC_INVALID_PACKET cpu_to_le32(0xC0360005)#define STATUS_IPSEC_INTEGRITY_CHECK_FAILED cpu_to_le32(0xC0360006)#define STATUS_IPSEC_CLEAR_TEXT_DROP cpu_to_le32(0xC0360007) -#define STATUS_NO_PREAUTH_INTEGRITY_HASH_OVERLAP cpu_to_le32(0xC05D0000) -#define STATUS_INVALID_LOCK_RANGE cpu_to_le32(0xC00001a1) +/* See MS-SMB2 3.3.5.4 */ +#define STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP cpu_to_le32(0xC05D0000)
fs/smb/server/smb2pdu.c +1 -1
@@ -896,7 +896,7 @@ static __le32 decode_preauth_ctxt(struct ksmbd_conn *conn,return STATUS_INVALID_PARAMETER ;if (pneg_ctxt->HashAlgorithms !=SMB2_PREAUTH_INTEGRITY_SHA512 ) -return STATUS_NO_PREAUTH_INTEGRITY_HASH_OVERLAP ; +return STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP ; conn->preauth_info->Preauth_HashId =SMB2_PREAUTH_INTEGRITY_SHA512 ;return STATUS_SUCCESS ;
Signature · 1 line
2.43.0
PATCH v4 4/10 smb/client: add two elements to smb2_error_map_table array
In reply to [email protected]From: ChenXiaoSong <[email protected]>
Both status codes are mapped to -EIO.
Now all status codes from common/smb2status.h are included in the smb2_error_map_table array(except for the first two zero definitions).
--- fs/smb/client/smb2maperror.c | 3 +++ 1 file changed, 3 insertions(+)
fs/smb/client/smb2maperror.c +3 -0
@@ -734,6 +734,7 @@ static const struct status_to_posix_error smb2_error_map_table[] = { {STATUS_FS_DRIVER_REQUIRED, -EOPNOTSUPP, "STATUS_FS_DRIVER_REQUIRED"}, {STATUS_IMAGE_ALREADY_LOADED_AS_DLL, -EIO, "STATUS_IMAGE_ALREADY_LOADED_AS_DLL"}, + {STATUS_INVALID_LOCK_RANGE, -EIO, "STATUS_INVALID_LOCK_RANGE"}, {STATUS_NETWORK_OPEN_RESTRICTION, -EIO, "STATUS_NETWORK_OPEN_RESTRICTION"}, {STATUS_NO_USER_SESSION_KEY, -EIO, "STATUS_NO_USER_SESSION_KEY"},
@@ -2413,6 +2414,8 @@ static const struct status_to_posix_error smb2_error_map_table[] = { {STATUS_IPSEC_INTEGRITY_CHECK_FAILED , -EIO , "STATUS_IPSEC_INTEGRITY_CHECK_FAILED"}, {STATUS_IPSEC_CLEAR_TEXT_DROP, -EIO, "STATUS_IPSEC_CLEAR_TEXT_DROP"}, + {STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP, -EIO, + "STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP"}, };int
Signature · 1 line
2.43.0
PATCH v4 5/10 smb/client: sort smb2_error_map_table array
In reply to [email protected]From: ChenXiaoSong <[email protected]>
Sort the array in ascending order, and then we can use binary search algorithm to quickly find the target status code.
Since the smb2_init_maperror() is called only once when the module is loaded, the array is sorted just once.
--- fs/smb/client/cifsfs.c | 2 ++ fs/smb/client/smb2maperror.c | 25 ++++++++++++++++++++++++- fs/smb/client/smb2proto.h | 1 + 3 files changed, 27 insertions(+), 1 deletion(-)
fs/smb/client/cifsfs.c +2 -0
@@ -49,6 +49,7 @@#endif #include "fs_context.h" #include "cached_dir.h" +#include "smb2proto.h" /* * DOS dates from 1980/1/1 through 2107/12/31
@@ -1908,6 +1909,7 @@ static int __initinit_cifs (void) {int rc =0 ; +smb2_init_maperror ();cifs_proc_init ();INIT_LIST_HEAD (&cifs_tcp_ses_list);/*
fs/smb/client/smb2maperror.c +24 -1
@@ -8,6 +8,7 @@* */ #include <linux/errno.h> +#include <linux/sort.h> #include "cifsglob.h" #include "cifs_debug.h" #include "smb2pdu.h"
@@ -22,7 +23,7 @@ struct status_to_posix_error {char *status_string; }; -static const struct status_to_posix_error smb2_error_map_table[] = { +static struct status_to_posix_error smb2_error_map_table[] = { {STATUS_WAIT_1 , -EIO ,"STATUS_WAIT_1" }, {STATUS_WAIT_2 , -EIO ,"STATUS_WAIT_2" }, {STATUS_WAIT_3 , -EIO ,"STATUS_WAIT_3" },
@@ -2418,6 +2419,20 @@ static const struct status_to_posix_error smb2_error_map_table[] = { "STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP"}, }; +static unsigned int err_map_num =sizeof (smb2_error_map_table) / +sizeof (struct status_to_posix_error ); + +static int cmp_smb2_status (const void *_a,const void *_b) +{ +const struct status_to_posix_error *a = _a, *b = _b; + +if (a->smb2_status < b->smb2_status) +return -1 ; +if (a->smb2_status > b->smb2_status) +return 1 ; +return 0 ; +} +int map_smb2_to_linux_error (char *buf,bool log_err) {
@@ -2461,3 +2476,11 @@ map_smb2_to_linux_error(char *buf, bool log_err) le32_to_cpu(smb2err), rc);return rc; } + +void smb2_init_maperror (void ) +{ +/* Sort in ascending order */ +sort (smb2_error_map_table, err_map_num, +sizeof (struct status_to_posix_error ), + cmp_smb2_status,NULL ); +}
fs/smb/client/smb2proto.h +1 -0
@@ -21,6 +21,7 @@ struct smb_rqst;***************************************************************** */ extern int map_smb2_to_linux_error (char *buf,bool log_err); +extern void smb2_init_maperror (void );extern int smb2_check_message (char *buf,unsigned int length,struct TCP_Server_Info *server);extern unsigned int smb2_calc_size (void *buf);
Signature · 1 line
2.43.0
PATCH v4 6/10 smb/client: use bsearch() to find target status code
In reply to [email protected]From: ChenXiaoSong <[email protected]>
The smb2_error_map_table array currently has 1742 elements. When searching for the last element, the original loop-based search method requires 1742 comparisons, while binary search algorithm requires only 10 comparisons.
--- fs/smb/client/smb2maperror.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
fs/smb/client/smb2maperror.c +15 -11
@@ -2437,9 +2437,9 @@ int map_smb2_to_linux_error(char *buf, bool log_err) {struct smb2_hdr *shdr = (struct smb2_hdr *)buf; -unsigned int i;int rc = -EIO ;__le32 smb2err = shdr->Status; +struct status_to_posix_error *err_map, key;if (smb2err ==0 ) { trace_smb3_cmd_done(le32_to_cpu(shdr->Id.SyncId.TreeId),
@@ -2453,17 +2453,21 @@ map_smb2_to_linux_error(char *buf, bool log_err) (smb2err != STATUS_END_OF_FILE)) || (cifsFYI &CIFS_RC ); -for (i =0 ; i <sizeof (smb2_error_map_table) / -sizeof (struct status_to_posix_error ); i++) { -if (smb2_error_map_table[i].smb2_status == smb2err) { -if (log_err) -pr_notice ("Status code returned 0x%08x %s\n" , smb2err, - smb2_error_map_table[i].status_string); - rc = smb2_error_map_table[i].posix_error; -break ; - } - } + key = (struct status_to_posix_error ) { + .smb2_status = smb2err, + }; + err_map =bsearch (&key, smb2_error_map_table, err_map_num, +sizeof (struct status_to_posix_error ), + cmp_smb2_status); +if (!err_map) + goto out; + + rc = err_map->posix_error; +if (log_err) +pr_notice ("Status code returned 0x%08x %s\n" , smb2err, + err_map->status_string); +out:/* on error mapping not found - return EIO */ cifs_dbg(FYI, "Mapping SMB2 status code 0x%08x to POSIX err %d\n",
Signature · 1 line
2.43.0
PATCH v4 7/10 smb/client: introduce smb2_get_err_map()
In reply to [email protected]From: ChenXiaoSong <[email protected]>
We may need to get struct status_to_posix_error information in other files in the future. So we move struct status_to_posix_error to smb2glob.h, and introduce new global function smb2_get_err_map().
Additionally, delete unused forward declaration struct statfs in smb2proto.h.
--- fs/smb/client/smb2glob.h | 6 ++++++ fs/smb/client/smb2maperror.c | 28 +++++++++++++++------------- fs/smb/client/smb2proto.h | 3 ++- 3 files changed, 23 insertions(+), 14 deletions(-)
fs/smb/client/smb2glob.h +6 -0
@@ -13,6 +13,12 @@#ifndef _SMB2_GLOB_H#define _SMB2_GLOB_H +struct status_to_posix_error { +__le32 smb2_status; +int posix_error; +char *status_string; +}; +/* ***************************************************************** * Constants go here
fs/smb/client/smb2maperror.c +15 -13
@@ -17,12 +17,6 @@#include "smb2glob.h" #include "trace.h" -struct status_to_posix_error { -__le32 smb2_status; -int posix_error; -char *status_string; -}; -static struct status_to_posix_error smb2_error_map_table[] = { {STATUS_WAIT_1 , -EIO ,"STATUS_WAIT_1" }, {STATUS_WAIT_2 , -EIO ,"STATUS_WAIT_2" },
@@ -2433,13 +2427,26 @@ static int cmp_smb2_status(const void *_a, const void *_b)return 0 ; } +struct status_to_posix_error *smb2_get_err_map (__le32 smb2_status) +{ +struct status_to_posix_error *err_map, key; + + key = (struct status_to_posix_error ) { + .smb2_status = smb2_status, + }; + err_map =bsearch (&key, smb2_error_map_table, err_map_num, +sizeof (struct status_to_posix_error ), + cmp_smb2_status); +return err_map; +} +int map_smb2_to_linux_error (char *buf,bool log_err) {struct smb2_hdr *shdr = (struct smb2_hdr *)buf;int rc = -EIO ;__le32 smb2err = shdr->Status; -struct status_to_posix_error *err_map, key; +struct status_to_posix_error *err_map;if (smb2err ==0 ) { trace_smb3_cmd_done(le32_to_cpu(shdr->Id.SyncId.TreeId),
@@ -2453,12 +2460,7 @@ map_smb2_to_linux_error(char *buf, bool log_err) (smb2err != STATUS_END_OF_FILE)) || (cifsFYI &CIFS_RC ); - key = (struct status_to_posix_error ) { - .smb2_status = smb2err, - }; - err_map =bsearch (&key, smb2_error_map_table, err_map_num, -sizeof (struct status_to_posix_error ), - cmp_smb2_status); + err_map =smb2_get_err_map (smb2err);if (!err_map) goto out;
fs/smb/client/smb2proto.h +2 -1
@@ -12,8 +12,8 @@#include <linux/nls.h> #include <linux/key-type.h> -struct statfs ;struct smb_rqst ; +struct status_to_posix_error ;/* *****************************************************************
@@ -21,6 +21,7 @@ struct smb_rqst;***************************************************************** */ extern int map_smb2_to_linux_error (char *buf,bool log_err); +extern struct status_to_posix_error *smb2_get_err_map (__le32 smb2_status);extern void smb2_init_maperror (void );extern int smb2_check_message (char *buf,unsigned int length,struct TCP_Server_Info *server);
Signature · 1 line
2.43.0
PATCH v4 8/10 smb/client: introduce smb2maperror KUnit tests
In reply to [email protected]From: ChenXiaoSong <[email protected]>
The KUnit tests are executed when cifs.ko is loaded.
Just like fs/ext4/mballoc.c includes fs/ext4/mballoc-test.c. smb2maperror.c also includes smb2maperror_test.c, allowing KUnit tests to access any functions and variables in smb2maperror.c.
The maperror_test_check_sort() checks whether the array is properly sorted.
The maperror_test_check_search() checks whether the expected element can be correctly searched for in the smb2_error_map_table array.
--- fs/smb/Kconfig | 17 ++++++++ fs/smb/client/smb2maperror.c | 4 ++ fs/smb/client/smb2maperror_test.c | 71 +++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 fs/smb/client/smb2maperror_test.c
fs/smb/Kconfig +17 -0
@@ -9,3 +9,20 @@ config SMBFS tristate default y if CIFS=y || SMB_SERVER=y default m if CIFS=m || SMB_SERVER=m + +config SMB_KUNIT_TESTS + tristate "KUnit tests for SMB" if !KUNIT_ALL_TESTS + depends on SMBFS && KUNIT + default KUNIT_ALL_TESTS + help + This builds the SMB KUnit tests. + + KUnit tests run during boot and output the results to the debug log + in TAP format (https://testanything.org/). Only useful for kernel devs + running KUnit test harness and are not for inclusion into a production + build. + + For more information on KUnit and unit tests in general please refer + to the KUnit documentation in Documentation/dev-tools/kunit/. + + If unsure, say N.
fs/smb/client/smb2maperror.c +4 -0
@@ -2490,3 +2490,7 @@ void smb2_init_maperror(void)sizeof (struct status_to_posix_error ), cmp_smb2_status, NULL); } + +#if IS_ENABLED (CONFIG_SMB_KUNIT_TESTS ) +#include "smb2maperror_test.c" +#endif /* CONFIG_SMB_KUNIT_TESTS */
fs/smb/client/smb2maperror_test.c new file +71 -0
71 lines not on this page · raw message
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH v4 08/10] smb/client: introduce smb2maperror KUnit tests
kernel test robot noticed the following build errors:
Hi,
kernel test robot noticed the following build errors:
[auto build test ERROR on brauner-vfs/vfs.all]
[also build test ERROR on linus/master v6.18]
[cannot apply to cifs/for-next next-20251208]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/chenxiaosong-chenxiaosong-linux-dev/smb-client-reduce-loop-count-in-map_smb2_to_linux_error-by-half/20251206-232731 base: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all patch link: https://lore.kernel.org/r/20251206151826.2932970-9-chenxiaosong.chenxiaosong%40linux.dev patch subject: [PATCH v4 08/10] smb/client: introduce smb2maperror KUnit tests config: i386-randconfig-004-20251208 (https://download.01.org/0day-ci/archive/20251209/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251209/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> ld.lld: error: undefined symbol: kunit_binary_str_assert_format >>> referenced by smb2maperror_test.c:40 (fs/smb/client/smb2maperror_test.c:40) >>> fs/smb/client/smb2maperror.o:(maperror_test_check_search) in archive vmlinux.a
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v4 08/10] smb/client: introduce smb2maperror KUnit tests
In reply to [email protected]kernel test robot noticed the following build errors:
Hi,
kernel test robot noticed the following build errors:
[auto build test ERROR on brauner-vfs/vfs.all]
[also build test ERROR on linus/master v6.18]
[cannot apply to cifs/for-next next-20251208]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/chenxiaosong-chenxiaosong-linux-dev/smb-client-reduce-loop-count-in-map_smb2_to_linux_error-by-half/20251206-232731 base: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all patch link: https://lore.kernel.org/r/20251206151826.2932970-9-chenxiaosong.chenxiaosong%40linux.dev patch subject: [PATCH v4 08/10] smb/client: introduce smb2maperror KUnit tests config: i386-randconfig-063-20251208 (https://download.01.org/0day-ci/archive/20251209/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251209/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
ld: fs/smb/client/smb2maperror.o: in function `test_cmp_map':
>> fs/smb/client/smb2maperror_test.c:40:(.text+0x1d4): undefined reference to `kunit_binary_str_assert_format' >> ld: fs/smb/client/smb2maperror_test.c:40:(.text+0x20c): undefined reference to `__kunit_do_failed_assertion' >> ld: fs/smb/client/smb2maperror_test.c:39:(.text+0x245): undefined reference to `kunit_binary_assert_format' ld: fs/smb/client/smb2maperror_test.c:39:(.text+0x263): undefined reference to `__kunit_do_failed_assertion' ld: fs/smb/client/smb2maperror_test.c:38:(.text+0x274): undefined reference to `kunit_binary_assert_format' ld: fs/smb/client/smb2maperror_test.c:38:(.text+0x2ba): undefined reference to `__kunit_do_failed_assertion' >> ld: fs/smb/client/smb2maperror_test.c:37:(.text+0x2da): undefined reference to `kunit_binary_ptr_assert_format' ld: fs/smb/client/smb2maperror_test.c:37:(.text+0x314): undefined reference to `__kunit_do_failed_assertion' ld: fs/smb/client/smb2maperror.o: in function `maperror_test_check_sort': >> fs/smb/client/smb2maperror_test.c:28:(.text.unlikely+0x4b): undefined reference to `kunit_binary_assert_format' >> ld: fs/smb/client/smb2maperror_test.c:28:(.text.unlikely+0x60): undefined reference to `__kunit_do_failed_assertion'
vim +40 fs/smb/client/smb2maperror_test.c
12
13 static void maperror_test_check_sort(struct kunit *test)
14 {
15 bool is_sorted = true;
16 unsigned int i;
17
18 for (i = 1; i < err_map_num; i++) {
19 if (smb2_error_map_table[i].smb2_status >=
20 smb2_error_map_table[i - 1].smb2_status)
21 continue;
22
23 pr_err("smb2_error_map_table array order is incorrect\n");
24 is_sorted = false;
25 break;
26 }
27
> 28 KUNIT_EXPECT_EQ(test, true, is_sorted);
29 }
30
31 static void
32 test_cmp_map(struct kunit *test, struct status_to_posix_error *expect)
33 {
34 struct status_to_posix_error *result;
35
36 result = smb2_get_err_map(expect->smb2_status);
> 37 KUNIT_EXPECT_PTR_NE(test, NULL, result);
38 KUNIT_EXPECT_EQ(test, expect->smb2_status, result->smb2_status);
> 39 KUNIT_EXPECT_EQ(test, expect->posix_error, result->posix_error);
> 40 KUNIT_EXPECT_STREQ(test, expect->status_string, result->status_string);
41 }
42 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v4 9/10 smb/client: update some SMB2 status strings
In reply to [email protected]From: ChenXiaoSong <[email protected]>
The smb2maperror KUnit tests reported the following errors:
KTAP version 1
1..1
KTAP version 1
# Subtest: smb2_maperror
# module: cifs
1..2
ok 1 maperror_test_check_sort
# maperror_test_check_search: EXPECTATION FAILED at fs/smb/client/smb2maperror_test.c:40 Expected expect->status_string == result->status_string, but
expect->status_string == "STATUS_ABANDONED_WAIT_0" result->status_string == "STATUS_ABANDONED"
# maperror_test_check_search: EXPECTATION FAILED at fs/smb/client/smb2maperror_test.c:40 Expected expect->status_string == result->status_string, but
expect->status_string == "STATUS_FWP_TOO_MANY_CALLOUTS" result->status_string == "STATUS_FWP_TOO_MANY_BOOTTIME_FILTERS"
not ok 2 maperror_test_check_search
# smb2_maperror: pass:1 fail:1 skip:0 total:2
# Totals: pass:1 fail:1 skip:0 total:2
not ok 1 smb2_maperror
These status codes have duplicate values, so update the status strings to make the log messages more explicit.
--- fs/smb/client/smb2maperror.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fs/smb/client/smb2maperror.c +6 -4
@@ -22,8 +22,9 @@ static struct status_to_posix_error smb2_error_map_table[] = { {STATUS_WAIT_2, -EIO, "STATUS_WAIT_2"}, {STATUS_WAIT_3, -EIO, "STATUS_WAIT_3"}, {STATUS_WAIT_63, -EIO, "STATUS_WAIT_63"}, - {STATUS_ABANDONED, -EIO, "STATUS_ABANDONED"}, - {STATUS_ABANDONED_WAIT_0, -EIO, "STATUS_ABANDONED_WAIT_0"}, + {STATUS_ABANDONED, -EIO, "STATUS_ABANDONED or STATUS_ABANDONED_WAIT_0"}, + {STATUS_ABANDONED_WAIT_0, -EIO, + "STATUS_ABANDONED or STATUS_ABANDONED_WAIT_0"}, {STATUS_ABANDONED_WAIT_63, -EIO, "STATUS_ABANDONED_WAIT_63"}, {STATUS_USER_APC, -EIO, "STATUS_USER_APC"}, {STATUS_KERNEL_APC, -EIO, "STATUS_KERNEL_APC"},
@@ -2292,8 +2293,9 @@ static struct status_to_posix_error smb2_error_map_table[] = { {STATUS_FWP_LIFETIME_MISMATCH, -EIO, "STATUS_FWP_LIFETIME_MISMATCH"}, {STATUS_FWP_BUILTIN_OBJECT, -EIO, "STATUS_FWP_BUILTIN_OBJECT"}, {STATUS_FWP_TOO_MANY_BOOTTIME_FILTERS, -EIO, - "STATUS_FWP_TOO_MANY_BOOTTIME_FILTERS"}, - {STATUS_FWP_TOO_MANY_CALLOUTS, -EIO, "STATUS_FWP_TOO_MANY_CALLOUTS"}, + "STATUS_FWP_TOO_MANY_BOOTTIME_FILTERS or STATUS_FWP_TOO_MANY_CALLOUTS"}, + {STATUS_FWP_TOO_MANY_CALLOUTS, -EIO, + "STATUS_FWP_TOO_MANY_BOOTTIME_FILTERS or STATUS_FWP_TOO_MANY_CALLOUTS"}, {STATUS_FWP_NOTIFICATION_DROPPED, -EIO, "STATUS_FWP_NOTIFICATION_DROPPED"}, {STATUS_FWP_TRAFFIC_MISMATCH, -EIO, "STATUS_FWP_TRAFFIC_MISMATCH"},
Signature · 1 line
2.43.0
Re: [PATCH v4 09/10] smb/client: update some SMB2 status strings
Good catch - merged into cifs-2.6.git for-next
Quoted 64 lines · On Sat, Dec 6, 2025 at 9:20 AM <[email protected]> wrote:
From: ChenXiaoSong <[email protected]>
The smb2maperror KUnit tests reported the following errors:
KTAP version 1
1..1
KTAP version 1
# Subtest:smb2_maperror
# module: cifs
1..2
ok 1maperror_test_check_sort
#maperror_test_check_search: EXPECTATION FAILED atfs/smb/client/smb2maperror_test.c:40Expectedexpect->status_string==result->status_string, but
expect->status_string== "STATUS_ABANDONED_WAIT_0"result->status_string== "STATUS_ABANDONED"
#maperror_test_check_search: EXPECTATION FAILED atfs/smb/client/smb2maperror_test.c:40Expectedexpect->status_string==result->status_string, but
expect->status_string== "STATUS_FWP_TOO_MANY_CALLOUTS"result->status_string== "STATUS_FWP_TOO_MANY_BOOTTIME_FILTERS"
not ok 2maperror_test_check_search
#smb2_maperror: pass:1 fail:1 skip:0 total:2
# Totals: pass:1 fail:1 skip:0 total:2
not ok 1smb2_maperrorThese status codes have duplicate values, so update the status strings to make the log messages more explicit.
Signed-off-by ChenXiaoSong <[email protected]>--- fs/smb/client/smb2maperror.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)fs/smb/client/smb2maperror.c +6
-5@@ -22,8 +22,9 @@ static struct status_to_posix_error smb2_error_map_table[] = { {STATUS_WAIT_2, -EIO, "STATUS_WAIT_2"}, {STATUS_WAIT_3, -EIO, "STATUS_WAIT_3"}, {STATUS_WAIT_63, -EIO, "STATUS_WAIT_63"}, - {STATUS_ABANDONED, -EIO, "STATUS_ABANDONED"}, - {STATUS_ABANDONED_WAIT_0, -EIO, "STATUS_ABANDONED_WAIT_0"}, + {STATUS_ABANDONED, -EIO, "STATUS_ABANDONED or STATUS_ABANDONED_WAIT_0"}, + {STATUS_ABANDONED_WAIT_0, -EIO, + "STATUS_ABANDONED or STATUS_ABANDONED_WAIT_0"}, {STATUS_ABANDONED_WAIT_63, -EIO, "STATUS_ABANDONED_WAIT_63"}, {STATUS_USER_APC, -EIO, "STATUS_USER_APC"}, {STATUS_KERNEL_APC, -EIO, "STATUS_KERNEL_APC"},@@ -2292,8 +2293,9 @@ static struct status_to_posix_error smb2_error_map_table[] = { {STATUS_FWP_LIFETIME_MISMATCH, -EIO, "STATUS_FWP_LIFETIME_MISMATCH"}, {STATUS_FWP_BUILTIN_OBJECT, -EIO, "STATUS_FWP_BUILTIN_OBJECT"}, {STATUS_FWP_TOO_MANY_BOOTTIME_FILTERS, -EIO, - "STATUS_FWP_TOO_MANY_BOOTTIME_FILTERS"}, - {STATUS_FWP_TOO_MANY_CALLOUTS, -EIO, "STATUS_FWP_TOO_MANY_CALLOUTS"}, + "STATUS_FWP_TOO_MANY_BOOTTIME_FILTERS or STATUS_FWP_TOO_MANY_CALLOUTS"}, + {STATUS_FWP_TOO_MANY_CALLOUTS, -EIO, + "STATUS_FWP_TOO_MANY_BOOTTIME_FILTERS or STATUS_FWP_TOO_MANY_CALLOUTS"}, {STATUS_FWP_NOTIFICATION_DROPPED, -EIO, "STATUS_FWP_NOTIFICATION_DROPPED"}, {STATUS_FWP_TRAFFIC_MISMATCH, -EIO, "STATUS_FWP_TRAFFIC_MISMATCH"}, --2.43.0
Signature · 3 lines
Thanks, Steve
PATCH v4 10/10 smb/server: rename include guard in smb_common.h
In reply to [email protected]From: ChenXiaoSong <[email protected]>
Make the include guard more descriptive to avoid conflicts with include guards that may be used in the future.
--- fs/smb/server/smb_common.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/smb/server/smb_common.h +3 -3
@@ -3,8 +3,8 @@* Copyright (C) 2018 Samsung Electronics Co., Ltd. */ -#ifndef __SMB_COMMON_H__ -#define __SMB_COMMON_H__ +#ifndef __SMB_SERVER_COMMON_H__ +#define __SMB_SERVER_COMMON_H__#include <linux/kernel.h>
@@ -196,4 +196,4 @@ unsigned int ksmbd_server_side_copy_max_chunk_size(void);unsigned int ksmbd_server_side_copy_max_total_size (void );bool is_asterisk (char *p);__le32 smb_map_generic_desired_access (__le32 daccess); -#endif /* __SMB_COMMON_H__ */ +#endif /* __SMB_SERVER_COMMON_H__ */
Signature · 1 line
2.43.0
Hi Steve and Namjae,
I have tested all patches using KUnit tests, xfstests, and smbtorture, and no additional test failures were observed. The detailed test results can be found in: https://chenxiaosong.com/en/smb-test-20251210.html
For more detailed information about the patches to be reviewed, please see the link: https://chenxiaosong.com/en/smb-patch.html
Thanks,
ChenXiaoSong.
Quoted 50 lines · On 12/6/25 23:18, [email protected] wrote:
From: ChenXiaoSong <[email protected]>
Before applying this patchset, when searching for the last element of
smb2_error_map_tablearray and callingsmb2_print_status(), 3486 comparisons are needed.After applying this patchset, only 10 comparisons are required.
v1: https://lore.kernel.org/linux-cifs/[email protected]/
The three patches from v1 have already been applied to the for-next branch of cifs-2.6.git. Please replace the following patches:- [v1 01/10] smb/client: reduce loop count in
map_smb2_to_linux_error()by half: https://git.samba.org/sfrench/?p=sfrench/cifs-2.6.git;a=commitdiff;h=26866d690bd180e1860548c43e70fdefe50638ff
- Replace it with this version(v4) patch #0001: update commit message: array has 1743 elements- [v1 02/10] smb/client: remove unused elements from
smb2_error_map_tablearray: https://git.samba.org/sfrench/?p=sfrench/cifs-2.6.git;a=commitdiff;h=905d8999d67dcbe4ce12ef87996e4440e068196d
- It is the same as patch #0002 in this version(v4).- [v1 03/10] smb: add two elements to
smb2_error_map_tablearray: https://git.samba.org/sfrench/?p=sfrench/cifs-2.6.git;a=commitdiff;h=ba521f56912f6ff5121e54c17c855298f947c9ea
- Replace it with this version(v4) patch #0003 #0004.v3: https://lore.kernel.org/linux-cifs/[email protected]/
v3->v4:
- Patch #0008: the KUnit test searches all elements of thesmb2_error_map_tablearray
- Create patch #0009ChenXiaoSong (10):
smb/client: reduce loop count inmap_smb2_to_linux_error()by half smb/client: remove unused elements fromsmb2_error_map_tablearray
smb: rename toSTATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAPsmb/client: add two elements tosmb2_error_map_tablearray smb/client: sortsmb2_error_map_tablearray
smb/client: usebsearch()to find target status code smb/client: introducesmb2_get_err_map()
smb/client: introduce smb2maperror KUnit tests smb/client: update some SMB2 status strings
smb/server: rename include guard insmb_common.hfs/smb/Kconfig | 17 +++++ fs/smb/client/cifsfs.c | 2 + fs/smb/client/smb2glob.h | 6 ++ fs/smb/client/smb2maperror.c | 101 +++++++++++++++++------------- fs/smb/client/smb2maperror_test.c | 71 +++++++++++++++++++++ fs/smb/client/smb2proto.h | 4 +- fs/smb/common/smb2status.h | 5 +- fs/smb/server/smb2pdu.c | 2 +- fs/smb/server/smb_common.h | 6 +- 9 files changed, 165 insertions(+), 49 deletions(-)create mode 100644
fs/smb/client/smb2maperror_test.c