FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.

» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Device-mapper Development

LinkBack Thread Tools
Old 03-08-2012, 09:21 PM
Mikulas Patocka
Default dm: remake of the verity target)

On Tue, 6 Mar 2012, Mandeep Singh Baines wrote:

> You are
> allocated a complete shash_desc per I/O. We only allocate one per CPU.

I looked at it --- and using percpu variables in workqueues isn't safe
because the workqueue can change CPU if the CPU is hot-unplugged.

dm-crypt has the same bug --- it also uses workqueue with per-cpu
variables and assumes that the CPU doesn't change for a single work item.

This program shows that work executed in a workqueue can be switched to a
different CPU.

I'm wondering how much other kernel code assumes that workqueues are bound
to a specific CPU, which isn't true if we unplug that CPU.



* A proof of concept that a work item executed on a workqueue may change CPU
* when CPU hot-unplugging is used.
* Compile this as a module and run:
* insmod test.ko; sleep 1; echo 0 >/sys/devices/system/cpu/cpu1/online
* You see that the work item starts executing on CPU 1 and ends up executing
* on different CPU, usually 0.

#include <linux/module.h>
#include <linux/delay.h>

static struct workqueue_struct *wq;
static struct work_struct work;

static void do_work(struct work_struct *w)
printk("starting work on cpu %d
", smp_processor_id());
printk("finishing work on cpu %d
", smp_processor_id());

static int __init test_init(void)
printk("module init
wq = alloc_workqueue("testd", WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
if (!wq) {
printk("alloc_workqueue failed
return -ENOMEM;
INIT_WORK(&work, do_work);
queue_work_on(1, wq, &work);
return 0;

static void __exit test_exit(void)
printk("module exit


dm-devel mailing list

Thread Tools

All times are GMT. The time now is 05:50 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org