Linux Kernels

Merge tag 'lkdtm-next' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux into char-misc-next

This change “Merge tag 'lkdtm-next' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux into char-misc-next” (commit e819acc) in Linux kernel is authored by Greg Kroah-Hartman <gregkh [at] linuxfoundation.org> on Wed Aug 2 12:41:56 2017 -0700.

Description of "Merge tag 'lkdtm-next' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux into char-misc-next"

The change “Merge tag 'lkdtm-next' of git:git.kernel.org/pub/scm/linux/kernel/git/kees/linux into char-misc-next” introduces changes as follows. <file> Merge tag 'lkdtm-next' of git:git.kernel.org/pub/scm/linux/kernel/git/kees/linux into char-misc-next

Kees writes a very short note:

improvements for refcount protections </file>

Linux kernel releases containing commit e819acc

The Linux kernel releases containing this commit are as follows.

Linux kernel code changes from "Merge tag 'lkdtm-next' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux into char-misc-next"

There is no are 0 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/misc/lkdtm.h          |  2 ++
 drivers/misc/lkdtm_core.c     |  2 ++
 drivers/misc/lkdtm_refcount.c | 44 +++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+)
 
diff --git a/drivers/misc/lkdtm.h b/drivers/misc/lkdtm.h
index 04ff8b23b3b0..063f5d651076 100644
--- a/drivers/misc/lkdtm.h
+++ b/drivers/misc/lkdtm.h
@@ -61,6 +61,8 @@ void lkdtm_REFCOUNT_INC_NOT_ZERO_SATURATED(void);
 void lkdtm_REFCOUNT_ADD_NOT_ZERO_SATURATED(void);
 void lkdtm_REFCOUNT_DEC_AND_TEST_SATURATED(void);
 void lkdtm_REFCOUNT_SUB_AND_TEST_SATURATED(void);
+void lkdtm_REFCOUNT_TIMING(void);
+void lkdtm_ATOMIC_TIMING(void);
 
 /* lkdtm_rodata.c */
 void lkdtm_rodata_do_nothing(void);
diff --git a/drivers/misc/lkdtm_core.c b/drivers/misc/lkdtm_core.c
index 156a1a07c3db..51decc07eeda 100644
--- a/drivers/misc/lkdtm_core.c
+++ b/drivers/misc/lkdtm_core.c
@@ -238,6 +238,8 @@ struct crashtype crashtypes[] = {
 	CRASHTYPE(REFCOUNT_ADD_NOT_ZERO_SATURATED),
 	CRASHTYPE(REFCOUNT_DEC_AND_TEST_SATURATED),
 	CRASHTYPE(REFCOUNT_SUB_AND_TEST_SATURATED),
+	CRASHTYPE(REFCOUNT_TIMING),
+	CRASHTYPE(ATOMIC_TIMING),
 	CRASHTYPE(USERCOPY_HEAP_SIZE_TO),
 	CRASHTYPE(USERCOPY_HEAP_SIZE_FROM),
 	CRASHTYPE(USERCOPY_HEAP_FLAG_TO),
diff --git a/drivers/misc/lkdtm_refcount.c b/drivers/misc/lkdtm_refcount.c
index 313abea4bf9d..29af0152a337 100644
--- a/drivers/misc/lkdtm_refcount.c
+++ b/drivers/misc/lkdtm_refcount.c
@@ -354,3 +354,47 @@ void lkdtm_REFCOUNT_SUB_AND_TEST_SATURATED(void)
 
 	check_saturated(&sat);
 }
+
+/* Used to time the existing atomic_t when used for reference counting */
+void lkdtm_ATOMIC_TIMING(void)
+{
+	unsigned int i;
+	atomic_t count = ATOMIC_INIT(1);
+
+	for (i = 0; i < INT_MAX - 1; i++)
+		atomic_inc(&count);
+
+	for (i = INT_MAX; i > 0; i--)
+		if (atomic_dec_and_test(&count))
+			break;
+
+	if (i != 1)
+		pr_err("atomic timing: out of sync up/down cycle: %u\n", i - 1);
+	else
+		pr_info("atomic timing: done\n");
+}
+
+/*
+ * This can be compared to ATOMIC_TIMING when implementing fast refcount
+ * protections. Looking at the number of CPU cycles tells the real story
+ * about performance. For example:
+ *    cd /sys/kernel/debug/provoke-crash
+ *    perf stat -B -- cat <(echo REFCOUNT_TIMING) > DIRECT
+ */
+void lkdtm_REFCOUNT_TIMING(void)
+{
+	unsigned int i;
+	refcount_t count = REFCOUNT_INIT(1);
+
+	for (i = 0; i < INT_MAX - 1; i++)
+		refcount_inc(&count);
+
+	for (i = INT_MAX; i > 0; i--)
+		if (refcount_dec_and_test(&count))
+			break;
+
+	if (i != 1)
+		pr_err("refcount: out of sync up/down cycle: %u\n", i - 1);
+	else
+		pr_info("refcount timing: done\n");
+}

The commit for this change in Linux stable tree is e819acc (patch).

Last modified: 2020/01/11 06:54