From e0c537bf37d84c68144735d452510369ae59b5f9 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Mon, 21 Apr 2025 07:19:46 -0400 Subject: [PATCH] Fixes for 5.4 Signed-off-by: Sasha Levin --- ...d-missing-selections-of-config_crc32.patch | 177 ++++++++++++++++++ ..._fhandle_hash-to-common-include-file.patch | 92 +++++++++ ...onstify-fh-argument-of-knfsd_fh_hash.patch | 45 +++++ queue-5.4/series | 3 + 4 files changed, 317 insertions(+) create mode 100644 queue-5.4/nfs-add-missing-selections-of-config_crc32.patch create mode 100644 queue-5.4/nfs-move-nfs_fhandle_hash-to-common-include-file.patch create mode 100644 queue-5.4/nfsd-constify-fh-argument-of-knfsd_fh_hash.patch diff --git a/queue-5.4/nfs-add-missing-selections-of-config_crc32.patch b/queue-5.4/nfs-add-missing-selections-of-config_crc32.patch new file mode 100644 index 0000000000..983c224d8d --- /dev/null +++ b/queue-5.4/nfs-add-missing-selections-of-config_crc32.patch @@ -0,0 +1,177 @@ +From b4ee30ab3a6534fc9bf51650bc73cdaf06f1f56f Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 1 Apr 2025 15:02:21 -0700 +Subject: nfs: add missing selections of CONFIG_CRC32 + +From: Eric Biggers + +[ Upstream commit cd35b6cb46649750b7dbd0df0e2d767415d8917b ] + +nfs.ko, nfsd.ko, and lockd.ko all use crc32_le(), which is available +only when CONFIG_CRC32 is enabled. But the only NFS kconfig option that +selected CONFIG_CRC32 was CONFIG_NFS_DEBUG, which is client-specific and +did not actually guard the use of crc32_le() even on the client. + +The code worked around this bug by only actually calling crc32_le() when +CONFIG_CRC32 is built-in, instead hard-coding '0' in other cases. This +avoided randconfig build errors, and in real kernels the fallback code +was unlikely to be reached since CONFIG_CRC32 is 'default y'. But, this +really needs to just be done properly, especially now that I'm planning +to update CONFIG_CRC32 to not be 'default y'. + +Therefore, make CONFIG_NFS_FS, CONFIG_NFSD, and CONFIG_LOCKD select +CONFIG_CRC32. Then remove the fallback code that becomes unnecessary, +as well as the selection of CONFIG_CRC32 from CONFIG_NFS_DEBUG. + +Fixes: 1264a2f053a3 ("NFS: refactor code for calculating the crc32 hash of a filehandle") +Signed-off-by: Eric Biggers +Acked-by: Anna Schumaker +Signed-off-by: Chuck Lever +Signed-off-by: Sasha Levin +--- + fs/Kconfig | 1 + + fs/nfs/Kconfig | 2 +- + fs/nfs/internal.h | 7 ------- + fs/nfs/nfs4session.h | 4 ---- + fs/nfsd/Kconfig | 1 + + fs/nfsd/nfsfh.h | 7 ------- + include/linux/nfs.h | 7 ------- + 7 files changed, 3 insertions(+), 26 deletions(-) + +diff --git a/fs/Kconfig b/fs/Kconfig +index 2501e6f1f9655..52853cf5d7dab 100644 +--- a/fs/Kconfig ++++ b/fs/Kconfig +@@ -292,6 +292,7 @@ config GRACE_PERIOD + config LOCKD + tristate + depends on FILE_LOCKING ++ select CRC32 + select GRACE_PERIOD + + config LOCKD_V4 +diff --git a/fs/nfs/Kconfig b/fs/nfs/Kconfig +index e84c187d942e8..1a5bfd42443f9 100644 +--- a/fs/nfs/Kconfig ++++ b/fs/nfs/Kconfig +@@ -2,6 +2,7 @@ + config NFS_FS + tristate "NFS client support" + depends on INET && FILE_LOCKING && MULTIUSER ++ select CRC32 + select LOCKD + select SUNRPC + select NFS_ACL_SUPPORT if NFS_V3_ACL +@@ -194,5 +195,4 @@ config NFS_USE_KERNEL_DNS + config NFS_DEBUG + bool + depends on NFS_FS && SUNRPC_DEBUG +- select CRC32 + default y +diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h +index 5c9166357ae7c..bfb53756654d9 100644 +--- a/fs/nfs/internal.h ++++ b/fs/nfs/internal.h +@@ -720,18 +720,11 @@ u64 nfs_timespec_to_change_attr(const struct timespec *ts) + return ((u64)ts->tv_sec << 30) + ts->tv_nsec; + } + +-#ifdef CONFIG_CRC32 + static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid) + { + return ~crc32_le(0xFFFFFFFF, &stateid->other[0], + NFS4_STATEID_OTHER_SIZE); + } +-#else +-static inline u32 nfs_stateid_hash(nfs4_stateid *stateid) +-{ +- return 0; +-} +-#endif + + static inline bool nfs_error_is_fatal(int err) + { +diff --git a/fs/nfs/nfs4session.h b/fs/nfs/nfs4session.h +index b996ee23f1bae..8ad99938aae18 100644 +--- a/fs/nfs/nfs4session.h ++++ b/fs/nfs/nfs4session.h +@@ -147,16 +147,12 @@ static inline void nfs4_copy_sessionid(struct nfs4_sessionid *dst, + memcpy(dst->data, src->data, NFS4_MAX_SESSIONID_LEN); + } + +-#ifdef CONFIG_CRC32 + /* + * nfs_session_id_hash - calculate the crc32 hash for the session id + * @session - pointer to session + */ + #define nfs_session_id_hash(sess_id) \ + (~crc32_le(0xFFFFFFFF, &(sess_id)->data[0], sizeof((sess_id)->data))) +-#else +-#define nfs_session_id_hash(session) (0) +-#endif + #else /* defined(CONFIG_NFS_V4_1) */ + + static inline int nfs4_init_session(struct nfs_client *clp) +diff --git a/fs/nfsd/Kconfig b/fs/nfsd/Kconfig +index 4d6e71335bce2..45fc2fcb8fe49 100644 +--- a/fs/nfsd/Kconfig ++++ b/fs/nfsd/Kconfig +@@ -4,6 +4,7 @@ config NFSD + depends on INET + depends on FILE_LOCKING + depends on FSNOTIFY ++ select CRC32 + select LOCKD + select SUNRPC + select EXPORTFS +diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h +index 42c168ac6b934..5001c134b8eb6 100644 +--- a/fs/nfsd/nfsfh.h ++++ b/fs/nfsd/nfsfh.h +@@ -208,7 +208,6 @@ static inline bool fh_fsid_match(struct knfsd_fh *fh1, struct knfsd_fh *fh2) + return true; + } + +-#ifdef CONFIG_CRC32 + /** + * knfsd_fh_hash - calculate the crc32 hash for the filehandle + * @fh - pointer to filehandle +@@ -220,12 +219,6 @@ static inline u32 knfsd_fh_hash(const struct knfsd_fh *fh) + { + return ~crc32_le(0xFFFFFFFF, (unsigned char *)&fh->fh_base, fh->fh_size); + } +-#else +-static inline u32 knfsd_fh_hash(const struct knfsd_fh *fh) +-{ +- return 0; +-} +-#endif + + #ifdef CONFIG_NFSD_V3 + /* +diff --git a/include/linux/nfs.h b/include/linux/nfs.h +index a8b62a08e784f..5746acd066457 100644 +--- a/include/linux/nfs.h ++++ b/include/linux/nfs.h +@@ -54,7 +54,6 @@ enum nfs3_stable_how { + NFS_INVALID_STABLE_HOW = -1 + }; + +-#ifdef CONFIG_CRC32 + /** + * nfs_fhandle_hash - calculate the crc32 hash for the filehandle + * @fh - pointer to filehandle +@@ -66,10 +65,4 @@ static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) + { + return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size); + } +-#else /* CONFIG_CRC32 */ +-static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) +-{ +- return 0; +-} +-#endif /* CONFIG_CRC32 */ + #endif /* _LINUX_NFS_H */ +-- +2.39.5 + diff --git a/queue-5.4/nfs-move-nfs_fhandle_hash-to-common-include-file.patch b/queue-5.4/nfs-move-nfs_fhandle_hash-to-common-include-file.patch new file mode 100644 index 0000000000..30ce6cac98 --- /dev/null +++ b/queue-5.4/nfs-move-nfs_fhandle_hash-to-common-include-file.patch @@ -0,0 +1,92 @@ +From 487ed12a108d894c87c7ac9cac5662477d41ecec Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 3 Mar 2023 07:16:02 -0500 +Subject: nfs: move nfs_fhandle_hash to common include file + +From: Jeff Layton + +[ Upstream commit e59fb6749ed833deee5b3cfd7e89925296d41f49 ] + +lockd needs to be able to hash filehandles for tracepoints. Move the +nfs_fhandle_hash() helper to a common nfs include file. + +Signed-off-by: Jeff Layton +Signed-off-by: Chuck Lever +Stable-dep-of: cd35b6cb4664 ("nfs: add missing selections of CONFIG_CRC32") +Signed-off-by: Sasha Levin +--- + fs/nfs/internal.h | 15 --------------- + include/linux/nfs.h | 20 ++++++++++++++++++++ + 2 files changed, 20 insertions(+), 15 deletions(-) + +diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h +index e8b692d41b26e..5c9166357ae7c 100644 +--- a/fs/nfs/internal.h ++++ b/fs/nfs/internal.h +@@ -721,27 +721,12 @@ u64 nfs_timespec_to_change_attr(const struct timespec *ts) + } + + #ifdef CONFIG_CRC32 +-/** +- * nfs_fhandle_hash - calculate the crc32 hash for the filehandle +- * @fh - pointer to filehandle +- * +- * returns a crc32 hash for the filehandle that is compatible with +- * the one displayed by "wireshark". +- */ +-static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) +-{ +- return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size); +-} + static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid) + { + return ~crc32_le(0xFFFFFFFF, &stateid->other[0], + NFS4_STATEID_OTHER_SIZE); + } + #else +-static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) +-{ +- return 0; +-} + static inline u32 nfs_stateid_hash(nfs4_stateid *stateid) + { + return 0; +diff --git a/include/linux/nfs.h b/include/linux/nfs.h +index 0dc7ad38a0da4..a8b62a08e784f 100644 +--- a/include/linux/nfs.h ++++ b/include/linux/nfs.h +@@ -10,6 +10,7 @@ + + #include + #include ++#include + #include + + /* +@@ -52,4 +53,23 @@ enum nfs3_stable_how { + /* used by direct.c to mark verf as invalid */ + NFS_INVALID_STABLE_HOW = -1 + }; ++ ++#ifdef CONFIG_CRC32 ++/** ++ * nfs_fhandle_hash - calculate the crc32 hash for the filehandle ++ * @fh - pointer to filehandle ++ * ++ * returns a crc32 hash for the filehandle that is compatible with ++ * the one displayed by "wireshark". ++ */ ++static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) ++{ ++ return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size); ++} ++#else /* CONFIG_CRC32 */ ++static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) ++{ ++ return 0; ++} ++#endif /* CONFIG_CRC32 */ + #endif /* _LINUX_NFS_H */ +-- +2.39.5 + diff --git a/queue-5.4/nfsd-constify-fh-argument-of-knfsd_fh_hash.patch b/queue-5.4/nfsd-constify-fh-argument-of-knfsd_fh_hash.patch new file mode 100644 index 0000000000..78cd1d0b55 --- /dev/null +++ b/queue-5.4/nfsd-constify-fh-argument-of-knfsd_fh_hash.patch @@ -0,0 +1,45 @@ +From 16b8cbc44fc698ead8a1c0fbef04631170dea2e4 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 14 May 2021 15:56:25 -0400 +Subject: NFSD: Constify @fh argument of knfsd_fh_hash() + +From: Chuck Lever + +[ Upstream commit 1736aec82a15cb5d4b3bbe0b2fbae0ede66b1a1a ] + +Enable knfsd_fh_hash() to be invoked in functions where the +filehandle pointer is a const. + +Signed-off-by: Chuck Lever +Signed-off-by: J. Bruce Fields +Stable-dep-of: cd35b6cb4664 ("nfs: add missing selections of CONFIG_CRC32") +Signed-off-by: Sasha Levin +--- + fs/nfsd/nfsfh.h | 7 ++----- + 1 file changed, 2 insertions(+), 5 deletions(-) + +diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h +index 755e256a91039..42c168ac6b934 100644 +--- a/fs/nfsd/nfsfh.h ++++ b/fs/nfsd/nfsfh.h +@@ -216,15 +216,12 @@ static inline bool fh_fsid_match(struct knfsd_fh *fh1, struct knfsd_fh *fh2) + * returns a crc32 hash for the filehandle that is compatible with + * the one displayed by "wireshark". + */ +- +-static inline u32 +-knfsd_fh_hash(struct knfsd_fh *fh) ++static inline u32 knfsd_fh_hash(const struct knfsd_fh *fh) + { + return ~crc32_le(0xFFFFFFFF, (unsigned char *)&fh->fh_base, fh->fh_size); + } + #else +-static inline u32 +-knfsd_fh_hash(struct knfsd_fh *fh) ++static inline u32 knfsd_fh_hash(const struct knfsd_fh *fh) + { + return 0; + } +-- +2.39.5 + diff --git a/queue-5.4/series b/queue-5.4/series index 31b2012bc5..b4807fddf3 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -91,3 +91,6 @@ bluetooth-btrtl-prevent-potential-null-dereference.patch revert-wifi-mac80211-update-skb-s-control-block-key-.patch net-openvswitch-fix-nested-key-length-validation-in-.patch net-b53-enable-bpdu-reception-for-management-port.patch +nfsd-constify-fh-argument-of-knfsd_fh_hash.patch +nfs-move-nfs_fhandle_hash-to-common-include-file.patch +nfs-add-missing-selections-of-config_crc32.patch -- 2.47.3