From c3e1f86f3a50cfa3762b63fb0f058af5036238ad Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Mon, 4 May 2020 13:16:00 -0700 Subject: [PATCH] LU-12400 ptlrpc: Sun RPC changes for RCU locking In kernel 4.20 SUNRPC cache_detail->hash_lock changed to spinlock_t Now that the reader functions are all RCU protected, use a regular spinlock rather than a reader/writer lock. Linux-commit: 1863d77f15da0addcd293a1719fa5d3ef8cde3ca This patch is back-ported from the following one: Lustre-commit: 77d53777e32c80047cb75293d5f9a4c0d23bbea8 Lustre-change: https://review.whamcloud.com/35499 Test-Parameters: trivial Cray-bug-id: LUS-7600 Signed-off-by: Shaun Tancheff Change-Id: If0df38337d5a2bb0ac4b8cb645dbe89f65e0f352 Reviewed-on: https://review.whamcloud.com/38483 Reviewed-by: Sebastien Buisson Tested-by: jenkins Reviewed-by: James Simmons Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/autoconf/lustre-core.m4 | 28 ++++++++++++++++++++++++++++ lustre/ptlrpc/gss/gss_internal.h | 8 ++++++++ lustre/ptlrpc/gss/gss_svc_upcall.c | 4 ++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index c9132ce..58184b7 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -2658,6 +2658,31 @@ iterate_shared, [ ]) # LC_FOPS_ITERATE_SHARED # +# LC_HAVE_SUNRPC_CACHE_HASH_LOCK_IS_A_SPINLOCK +# +# kernel 4.20 commit 1863d77f15da0addcd293a1719fa5d3ef8cde3ca +# SUNRPC: Replace the cache_detail->hash_lock with a regular spinlock +# +# Now that the reader functions are all RCU protected, use a regular +# spinlock rather than a reader/writer lock. +# +AC_DEFUN([LC_HAVE_SUNRPC_CACHE_HASH_LOCK_IS_A_SPINLOCK], [ +tmp_flags="$EXTRA_KCFLAGS" +EXTRA_KCFLAGS="-Werror" +LB_CHECK_COMPILE([if cache_detail->hash_lock is a spinlock], +hash_lock_isa_spinlock_t, [ + #include +],[ + spinlock_t *lock = &(((struct cache_detail *)0)->hash_lock); + spin_lock(lock); +],[ + AC_DEFINE(HAVE_CACHE_HASH_SPINLOCK, 1, + [if cache_detail->hash_lock is a spinlock]) +]) +EXTRA_KCFLAGS="$tmp_flags" +]) # LC_HAVE_SUNRPC_CACHE_HASH_LOCK_IS_A_SPINLOCK + +# # LC_HAVE_POSIX_ACL_VALID_USER_NS # # 4.8 posix_acl_valid takes struct user_namespace @@ -3386,6 +3411,9 @@ AC_DEFUN([LC_PROG_LINUX], [ LC_INODE_TIMESPEC64 LC_XA_IS_VALUE + # 4.20 + LC_HAVE_SUNRPC_CACHE_HASH_LOCK_IS_A_SPINLOCK + # 5.1 LC_HAS_LINUX_SELINUX_ENABLED diff --git a/lustre/ptlrpc/gss/gss_internal.h b/lustre/ptlrpc/gss/gss_internal.h index 1ba01b3..c49a540 100644 --- a/lustre/ptlrpc/gss/gss_internal.h +++ b/lustre/ptlrpc/gss/gss_internal.h @@ -358,6 +358,14 @@ static inline struct gss_sec_keyring *sec2gsec_keyring(struct ptlrpc_sec *sec) return container_of(sec2gsec(sec), struct gss_sec_keyring, gsk_base); } +#ifdef HAVE_CACHE_HASH_SPINLOCK +# define sunrpc_cache_lookup(c, i, h) sunrpc_cache_lookup_rcu((c), (i), (h)) +# define cache_read_lock(cdetail) spin_lock(&((cdetail)->hash_lock)) +# define cache_read_unlock(cdetail) spin_unlock(&((cdetail)->hash_lock)) +#else /* ! HAVE_CACHE_HASH_SPINLOCK */ +# define cache_read_lock(cdetail) read_lock(&((cdetail)->hash_lock)) +# define cache_read_unlock(cdetail) read_unlock(&((cdetail)->hash_lock)) +#endif #define GSS_CTX_INIT_MAX_LEN (1024) diff --git a/lustre/ptlrpc/gss/gss_svc_upcall.c b/lustre/ptlrpc/gss/gss_svc_upcall.c index 5e88332..bbb4a0b 100644 --- a/lustre/ptlrpc/gss/gss_svc_upcall.c +++ b/lustre/ptlrpc/gss/gss_svc_upcall.c @@ -938,11 +938,11 @@ cache_check: if (first_check) { first_check = 0; - read_lock(&rsi_cache.hash_lock); + cache_read_lock(&rsi_cache); valid = test_bit(CACHE_VALID, &rsip->h.flags); if (valid == 0) set_current_state(TASK_INTERRUPTIBLE); - read_unlock(&rsi_cache.hash_lock); + cache_read_unlock(&rsi_cache); if (valid == 0) { unsigned long jiffies; -- 1.8.3.1