Skip to content

Instantly share code, notes, and snippets.

@osandov
Created October 27, 2025 22:52
Show Gist options
  • Select an option

  • Save osandov/44d17c51c28c0ac998ea0334edf90b5a to your computer and use it in GitHub Desktop.

Select an option

Save osandov/44d17c51c28c0ac998ea0334edf90b5a to your computer and use it in GitHub Desktop.
commit baffbe58c26ce8e0105f54916ae548a1e1c283a0
Author: Omar Sandoval <osandov@fb.com>
Date: Mon Oct 27 15:51:10 2025 -0700
Test patch to stress smp_text_poke_int3_handler()
Build this with the following config:
CONFIG_SMP=y
CONFIG_MODULES=n
CONFIG_CC_OPTIMIZE_FOR_SIZE=y
CONFIG_BLK_DEV_INITRD=y
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_CMOS=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_HYPERVISOR_GUEST=y
CONFIG_KVM_GUEST=y
CONFIG_PARAVIRT=y
CONFIG_PARAVIRT_SPINLOCKS=y
CONFIG_JUMP_LABEL=y
diff --git a/kernel/Makefile b/kernel/Makefile
index df3dd8291bb6..ac9f8a79acf7 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -205,3 +205,5 @@ $(obj)/kheaders.md5: $(obj)/kheaders-srclist FORCE
$(call filechk,kheaders_md5sum)
clean-files := kheaders.md5 kheaders-srclist kheaders-objlist
+
+obj-y += pokestress.o
diff --git a/kernel/pokestress.c b/kernel/pokestress.c
new file mode 100644
index 000000000000..a245f534e4ad
--- /dev/null
+++ b/kernel/pokestress.c
@@ -0,0 +1,93 @@
+#include <linux/delay.h>
+#include <linux/jump_label.h>
+#include <linux/kthread.h>
+#include <linux/module.h>
+#include <linux/pgtable.h>
+#include <linux/slab.h>
+#include <asm/cpu_entry_area.h>
+
+DEFINE_STATIC_KEY_FALSE(my_key);
+
+static struct task_struct *toggle_thread;
+static struct task_struct **branch_threads;
+static unsigned int num_branch_threads;
+
+static int toggle_func(void *arg)
+{
+ while (!kthread_should_stop()) {
+ static_branch_enable(&my_key);
+ static_branch_disable(&my_key);
+ cond_resched();
+ }
+ return 0;
+}
+
+static int branch_func(void *arg)
+{
+ while (!kthread_should_stop()) {
+ if (static_branch_unlikely(&my_key))
+ asm volatile(".rept 4096\nnop\n.endr\n");
+ else
+ asm volatile(".rept 2048\n.nops 2\n.endr\n");
+ cond_resched();
+ }
+ return 0;
+}
+
+static void pokestress_exit(void)
+{
+ unsigned int i;
+
+ if (branch_threads) {
+ for (i = 0; i < num_branch_threads; i++) {
+ if (branch_threads[i])
+ kthread_stop(branch_threads[i]);
+ }
+ kfree(branch_threads);
+ }
+ if (toggle_thread)
+ kthread_stop(toggle_thread);
+}
+
+static int __init pokestress_init(void)
+{
+ struct task_struct *thread;
+ unsigned int i;
+
+ for_each_online_cpu(i) {
+ phys_addr_t gpa;
+
+ gpa = slow_virt_to_phys(&get_cpu_entry_area(i)->tss);
+ pr_crit("GPA=%pap\n", &gpa);
+ }
+
+ thread = kthread_run(toggle_func, NULL, "toggle");
+ if (IS_ERR(thread))
+ return PTR_ERR(thread);
+ toggle_thread = thread;
+
+ num_branch_threads = max(num_online_cpus() - 1, 1U);
+ branch_threads = kcalloc(num_branch_threads, sizeof(*branch_threads),
+ GFP_KERNEL);
+ if (!branch_threads) {
+ pokestress_exit();
+ return -ENOMEM;
+ }
+ for (i = 0; i < num_branch_threads; i++) {
+ thread = kthread_run(branch_func, NULL, "branch%u", i);
+ if (IS_ERR(thread)) {
+ pokestress_exit();
+ return PTR_ERR(thread);
+ }
+ branch_threads[i] = thread;
+ }
+
+ pr_crit("POKESTRESS RUNNING\n");
+
+ return 0;
+}
+
+module_init(pokestress_init);
+module_exit(pokestress_exit);
+
+MODULE_LICENSE("GPL");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment