From 3d35b7477ff64b0ec846f31a71488ff3fd606f1d Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 11 Mar 2019 02:50:21 +0000 Subject: [PATCH 1/3] scst: Avoid switching explicitly to per-cpu git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8044 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 21 +-------------------- scst/src/scst_lib.c | 8 ++------ 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index 19e4cd246..2d10fce11 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -884,17 +884,11 @@ struct percpu_ref { percpu_ref_func_t *release; }; -/* @flags for percpu_ref_init() */ -enum { - PERCPU_REF_INIT_ATOMIC = 1 << 0, - PERCPU_REF_INIT_DEAD = 1 << 1, -}; - static inline int __must_check percpu_ref_init(struct percpu_ref *ref, percpu_ref_func_t *release, unsigned int flags, gfp_t gfp) { - WARN_ON_ONCE(flags != PERCPU_REF_INIT_ATOMIC); + WARN_ON_ONCE(flags != 0); atomic_long_set(&ref->count, 1); ref->release = release; return 0; @@ -904,19 +898,6 @@ static inline void percpu_ref_exit(struct percpu_ref *ref) { } -static inline void percpu_ref_switch_to_atomic(struct percpu_ref *ref, - percpu_ref_func_t *confirm_switch) -{ -} - -static inline void percpu_ref_switch_to_atomic_sync(struct percpu_ref *ref) -{ -} - -static inline void percpu_ref_switch_to_percpu(struct percpu_ref *ref) -{ -} - static inline void percpu_ref_get(struct percpu_ref *ref) { atomic_long_inc(&ref->count); diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 62cd5e417..dabd921aa 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -4225,11 +4225,9 @@ int scst_alloc_device(gfp_t gfp_mask, int nodeid, struct scst_device **out_dev) dev->handler = &scst_null_devtype; INIT_WORK(&dev->free_work, scst_finally_free_device); - res = percpu_ref_init(&dev->refcnt, scst_release_device, - PERCPU_REF_INIT_ATOMIC, GFP_KERNEL); + res = percpu_ref_init(&dev->refcnt, scst_release_device, 0, GFP_KERNEL); if (res < 0) goto free_dev; - percpu_ref_switch_to_percpu(&dev->refcnt); #ifdef CONFIG_SCST_PER_DEVICE_CMD_COUNT_LIMIT atomic_set(&dev->dev_cmd_count, 0); #endif @@ -7062,11 +7060,9 @@ struct scst_session *scst_alloc_session(struct scst_tgt *tgt, gfp_t gfp_mask, sess->init_phase = SCST_SESS_IPH_INITING; sess->shut_phase = SCST_SESS_SPH_READY; - ret = percpu_ref_init(&sess->refcnt, scst_sess_release, - PERCPU_REF_INIT_ATOMIC, GFP_KERNEL); + ret = percpu_ref_init(&sess->refcnt, scst_sess_release, 0, GFP_KERNEL); if (ret < 0) goto out_free; - percpu_ref_switch_to_percpu(&sess->refcnt); mutex_init(&sess->tgt_dev_list_mutex); for (i = 0; i < SESS_TGT_DEV_LIST_HASH_SIZE; i++) { struct list_head *head = &sess->sess_tgt_dev_list[i]; From b9969a09a5a77f2c963a1aaba194815179fdf041 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 11 Mar 2019 02:51:09 +0000 Subject: [PATCH 2/3] scst: Simplify the percpu-ref code for RHEL 7 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8045 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index 2d10fce11..b222ab2b2 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -30,9 +30,6 @@ #endif #include #include -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0) -#include -#endif #include /* struct scatterlist */ #include /* kmalloc() */ #include /* sizeof_field() */ @@ -875,7 +872,9 @@ static inline struct ib_pd *ib_alloc_pd_backport(struct ib_device *device) #endif /* */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) && RHEL_MAJOR -0 <= 6 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0) || RHEL_MAJOR -0 >= 7 +#include +#else struct percpu_ref; typedef void (percpu_ref_func_t)(struct percpu_ref *); From a4c05a4b31eaaacac765a7b103af9277e5e16ceb Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 11 Mar 2019 02:53:24 +0000 Subject: [PATCH 3/3] scst: Backport the percpu-ref code to kernel version 3.17 and before git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8046 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index b222ab2b2..4a9e65f48 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -872,8 +872,42 @@ static inline struct ib_pd *ib_alloc_pd_backport(struct ib_device *device) #endif /* */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0) || RHEL_MAJOR -0 >= 7 +#if defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 7 #include +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0) +#include +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) +/* + * See also commit 2aad2a86f668 ("percpu_ref: add PERCPU_REF_INIT_* flags") + * # v3.18. + */ +static inline int __must_check percpu_ref_init_backport(struct percpu_ref *ref, + percpu_ref_func_t *release, unsigned int flags, + gfp_t gfp) +{ + WARN_ON_ONCE(flags != 0); + WARN_ON_ONCE(gfp != GFP_KERNEL); + return percpu_ref_init(ref, release); +} +#define percpu_ref_init percpu_ref_init_backport +#endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) +/* + * See also commit 2d7227828e14 ("percpu-refcount: implement percpu_ref_reinit() + * and percpu_ref_is_zero()") # v3.17. + */ +static inline bool percpu_ref_is_zero(struct percpu_ref *ref) +{ + return !atomic_read(&ref->count); +} +/* + * See also commit 9a1049da9bd2 ("percpu-refcount: require percpu_ref to be + * exited explicitly") # v3.17. + */ +static inline void percpu_ref_exit(struct percpu_ref *ref) +{ +} +#endif #else struct percpu_ref; typedef void (percpu_ref_func_t)(struct percpu_ref *);