From e3d187f6af4fe35b1f052ba19586e6492d23b044 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 21 Dec 2020 20:56:58 +0000 Subject: [PATCH 1/2] scripts/kernel-functions: Apply kernel patches more selectively Only try to apply kernel patches that should apply such that 'patch' does not report any error messages that some patches fail to apply. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@9228 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scripts/kernel-functions | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/kernel-functions b/scripts/kernel-functions index d5b978b38..c50668a76 100644 --- a/scripts/kernel-functions +++ b/scripts/kernel-functions @@ -139,8 +139,11 @@ function patch_kernel { # files") # v4.2. if kernel_version_le 2.6.29 "$1" && kernel_version_lt "$1" 4.2; then # Tell the kernel that we are using gcc 4.6 since older kernel - # versions do not support recent gcc versions. - patch -f -s -p1 <<'EOF' || + # versions do not support recent gcc versions. See also commit + # 9c695203a7dd ("compiler-gcc.h: gcc-4.5 needs noclone and + # noinline on __naked functions") # v2.6.35. + if kernel_version_le 2.6.35 "$1"; then + patch -f -s -p1 <<'EOF' diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 02ae99e8e6d3..47e12c19c965 100644 --- a/include/linux/compiler-gcc.h @@ -155,7 +158,8 @@ index 02ae99e8e6d3..47e12c19c965 100644 #if !defined(__noclone) #define __noclone /* not needed */ EOF - patch -f -s -p1 <<'EOF' + else + patch -f -s -p1 <<'EOF' diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index a3ed7cb8ca34..c5a6b8b52db4 100644 --- a/include/linux/compiler-gcc.h @@ -167,7 +171,11 @@ index a3ed7cb8ca34..c5a6b8b52db4 100644 -#include gcc_header(__GNUC__) +#include "linux/compiler-gcc4.h" EOF - patch -f -s -p1 <<'EOF' || + fi + # See also commit 733ed6e43756 ("compiler-gcc{3,4}.h: Use + # GCC_VERSION macro") # v3.9. + if kernel_version_le 3.9 "$1"; then + patch -f -s -p1 <<'EOF' diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h index 769e19864632..2ec6c7a11502 100644 --- a/include/linux/compiler-gcc4.h @@ -187,7 +195,8 @@ index 769e19864632..2ec6c7a11502 100644 #define __must_check __attribute__((warn_unused_result)) #define __compiler_offsetof(a,b) __builtin_offsetof(a,b) EOF - patch -f -s -p1 <<'EOF' + else + patch -f -s -p1 <<'EOF' diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h index 412bc6c2b023..901ca31be7f8 100644 --- a/include/linux/compiler-gcc4.h @@ -207,6 +216,7 @@ index 412bc6c2b023..901ca31be7f8 100644 #define __must_check __attribute__((warn_unused_result)) #define __compiler_offsetof(a,b) __builtin_offsetof(a,b) EOF + fi fi ;; esac @@ -666,7 +676,7 @@ EOF # See also commit e33a814e772c ("scripts/dtc: Remove redundant YYLOC global # declaration") # v5.6~10^2. - if kernel_version_lt "$1" 5.6; then + if kernel_version_le 2.6.38 "$1" && kernel_version_lt "$1" 5.6; then patch -p1 -f -s <<'EOF' From e33a814e772cdc36436c8c188d8c42d019fda639 Mon Sep 17 00:00:00 2001 From: Dirk Mueller From 5826f2c8de9c66937e3f5bb5828e2e7db58bf687 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 21 Dec 2020 22:06:06 +0000 Subject: [PATCH 2/2] scst: Fix two bugs in error paths Wait for percpu_ref_kill() to finish before calling percpu_ref_exit(). This patch fixes the following complaint: WARNING: CPU: 7 PID: 56710 at lib/percpu-refcount.c:110 percpu_ref_exit+0x28/0x30 RIP: 0010:percpu_ref_exit+0x28/0x30 Call Trace: scst_free_device+0x89/0x120 [scst] scst_register_virtual_device_node+0x27a/0x4f0 [scst] vdisk_add_blockio_device+0x1fa/0x3d0 [scst_vdisk] scst_devt_mgmt_store_work_fn+0x21b/0x2d0 [scst] sysfs_work_thread_fn+0xef/0x400 [scst] kthread+0x112/0x130 Fixes: c5ff6adeaec6 ("Fix unloading of scst_vdisk while I/O is ongoing"; r9048) git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@9229 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index f4f942a18..6fa785d15 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -1057,8 +1057,9 @@ int scst_get_suspend_count(void) static int scst_register_device(struct scsi_device *scsidp) { - int res; + DECLARE_COMPLETION_ONSTACK(c); struct scst_device *dev, *d; + int res; TRACE_ENTRY(); @@ -1128,8 +1129,9 @@ out_del_unlocked: scst_pr_clear_dev(dev); out_free_dev: + dev->remove_completion = &c; percpu_ref_kill(&dev->refcnt); - + wait_for_completion(&c); scst_free_device(dev); out_unlock: @@ -1283,9 +1285,10 @@ out: int scst_register_virtual_device_node(struct scst_dev_type *dev_handler, const char *dev_name, int nodeid) { - int res; + DECLARE_COMPLETION_ONSTACK(c); struct scst_device *dev, *d; bool sysfs_del = false; + int res; TRACE_ENTRY(); @@ -1405,7 +1408,9 @@ out_free_dev: mutex_unlock(&scst_mutex); if (sysfs_del) scst_dev_sysfs_del(dev); + dev->remove_completion = &c; percpu_ref_kill(&dev->refcnt); + wait_for_completion(&c); scst_free_device(dev); goto out;