From bcf29b785eddf85526866b76a227754a9651ec74 Mon Sep 17 00:00:00 2001 From: Oscar Megia Date: Sun, 25 Sep 2022 09:43:57 +0200 Subject: [PATCH 1/3] This kfree hangs my vm kernel. I needed to change where kfree(my_data) to avoid this hang. Now works fine. --- Chapter03/shared-workqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter03/shared-workqueue.c b/Chapter03/shared-workqueue.c index 3eb3749..3afef89 100644 --- a/Chapter03/shared-workqueue.c +++ b/Chapter03/shared-workqueue.c @@ -23,7 +23,6 @@ static void work_handler(struct work_struct *work) pr_info("Work queue module handler: %s, data is %d\n", __FUNCTION__, my_data->the_data); msleep(3000); wake_up_interruptible(&my_data->my_wq); - kfree(my_data); } static int __init my_init(void) @@ -40,6 +39,7 @@ static int __init my_init(void) pr_info("I'm goint to sleep ...\n"); wait_event_interruptible(my_data->my_wq, sleep != 0); pr_info("I am Waked up...\n"); + kfree(my_data); return 0; } From e6793fdcd55f94946e8bb355861a626838d5e196 Mon Sep 17 00:00:00 2001 From: Oscar Megia Date: Sun, 25 Sep 2022 13:31:58 +0200 Subject: [PATCH 2/3] Dont work on my Oracle VM VirtualBox I needed to apply this fix in my VM VirtualBox machine with Linux archlinux 5.18.14-arch1-1 #1 SMP PREEMPT_DYNAMIC to make it work. --- Chapter03/user-invoke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter03/user-invoke.c b/Chapter03/user-invoke.c index 6599a3f..fd09ae3 100644 --- a/Chapter03/user-invoke.c +++ b/Chapter03/user-invoke.c @@ -20,7 +20,7 @@ static void delayed_shutdown(struct work_struct *work) NULL, }; - call_usermodehelper(cmd, argv, envp, 0); + call_usermodehelper(cmd, argv, envp, UMH_WAIT_PROC); } static int __init my_shutdown_init( void ) From 8e58fe202bfac1f03914425539b8b962f6fe133e Mon Sep 17 00:00:00 2001 From: Oscar Megia Date: Sun, 25 Sep 2022 19:52:29 +0200 Subject: [PATCH 3/3] I forgot add set sleep = 1 If not, insmod hangs. You can press CTRL+C to abort it. --- Chapter03/shared-workqueue.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Chapter03/shared-workqueue.c b/Chapter03/shared-workqueue.c index 3afef89..630d6a5 100644 --- a/Chapter03/shared-workqueue.c +++ b/Chapter03/shared-workqueue.c @@ -22,6 +22,7 @@ static void work_handler(struct work_struct *work) struct work_data, my_work); pr_info("Work queue module handler: %s, data is %d\n", __FUNCTION__, my_data->the_data); msleep(3000); + sleep = 1; wake_up_interruptible(&my_data->my_wq); }