* [PATCH 0/2] ACPI: container hot remove support. @ 2012-10-23 13:10 Tang Chen 2012-10-23 13:10 ` [PATCH 1/2] Use kacpi_hotplug_wq to handle container hotplug event Tang Chen 2012-10-23 13:10 ` [PATCH 2/2] Improve container_notify_cb() to support container hot-remove Tang Chen 0 siblings, 2 replies; 6+ messages in thread From: Tang Chen @ 2012-10-23 13:10 UTC (permalink / raw) To: yinghai, bhelgaas, lenb, jiang.liu, izumi.taku, isimatu.yasuaki, linux-acpi, linux-pci, linux-kernel Hi, The container hotplug handler container_notify_cb() didn't implement the hot-remove functionality. So, these 2 patches implement it like the following way: patch 1. Do not use kacpid_wq/kacpid_notify_wq to handle container hotplug event, use kacpi_hotplug_wq instead to avoid deadlock. Doing this is to reuse acpi_bus_hot_remove_device() in container hot-remove handling. patch 2. Introduce a new function container_device_remove() to handle ACPI_NOTIFY_EJECT_REQUEST event for container. In __acpi_os_execute(), we have the following comments: We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq because the hotplug code may call driver .remove() functions, which invoke flush_scheduled_work/acpi_os_wait_events_complete to flush these workqueues. Actually, I run into the deadlock caused by running hotplug code in kacpid_wq/kacpid_notify_wq. And I'm not quite sure if I did the right thing in patch1. So, please give some comments if you have a better idea. This is based on Lu Yinghai's job. git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-split-pci-root-hp-2 Tang Chen (2): Use kacpi_hotplug_wq to handle container hotplug event. Container hot remove support. drivers/acpi/container.c | 102 +++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 92 insertions(+), 10 deletions(-) ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] Use kacpi_hotplug_wq to handle container hotplug event. 2012-10-23 13:10 [PATCH 0/2] ACPI: container hot remove support Tang Chen @ 2012-10-23 13:10 ` Tang Chen 2012-10-23 17:36 ` Yinghai Lu 2012-10-24 17:33 ` Toshi Kani 2012-10-23 13:10 ` [PATCH 2/2] Improve container_notify_cb() to support container hot-remove Tang Chen 1 sibling, 2 replies; 6+ messages in thread From: Tang Chen @ 2012-10-23 13:10 UTC (permalink / raw) To: yinghai, bhelgaas, lenb, jiang.liu, izumi.taku, isimatu.yasuaki, linux-acpi, linux-pci, linux-kernel As the comments in __acpi_os_execute() said: We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq because the hotplug code may call driver .remove() functions, which invoke flush_scheduled_work/acpi_os_wait_events_complete to flush these workqueues. we should keep the hotplug code in kacpi_hotplug_wq. But we have the following call series in kernel now: acpi_ev_queue_notify_request() |--> acpi_os_execute() |--> __acpi_os_execute(type, function, context, 0) The last parameter 0 makes the container_notify_cb() executed in kacpi_notify_wq or kacpid_wq. So, we need to put the real hotplug code into kacpi_hotplug_wq. Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com> --- drivers/acpi/container.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 43 insertions(+), 1 deletions(-) diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c index 1f9f7d7..643657a 100644 --- a/drivers/acpi/container.c +++ b/drivers/acpi/container.c @@ -72,8 +72,36 @@ static struct acpi_driver acpi_container_driver = { }, }; +struct acpi_container_hp_work { + struct work_struct work; + acpi_handle handle; + u32 type; + void *context; +}; + /*******************************************************************/ +static void alloc_acpi_container_hp_work(acpi_handle handle, u32 type, + void *context, + void (*func)(struct work_struct *work)) +{ + struct acpi_container_hp_work *hp_work; + int ret; + + hp_work = kmalloc(sizeof(*hp_work), GFP_KERNEL); + if (!hp_work) + return; + + hp_work->handle = handle; + hp_work->type = type; + hp_work->context = context; + + INIT_WORK(&hp_work->work, func); + ret = queue_work(kacpi_hotplug_wq, &hp_work->work); + if (!ret) + kfree(hp_work); +} + static int is_device_present(acpi_handle handle) { acpi_handle temp; @@ -152,14 +180,21 @@ static int container_device_add(struct acpi_device **device, acpi_handle handle) return result; } -static void container_notify_cb(acpi_handle handle, u32 type, void *context) +static void __container_notify_cb(struct work_struct *work) { struct acpi_device *device = NULL; int result; int present; acpi_status status; + struct acpi_container_hp_work *hp_work; + acpi_handle handle; + u32 type; u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; /* default */ + hp_work = container_of(work, struct acpi_container_hp_work, work); + handle = hp_work->handle; + type = hp_work->type; + switch (type) { case ACPI_NOTIFY_BUS_CHECK: /* Fall through */ @@ -211,6 +246,13 @@ static void container_notify_cb(acpi_handle handle, u32 type, void *context) return; } +static void container_notify_cb(acpi_handle handle, u32 type, + void *context) +{ + alloc_acpi_container_hp_work(handle, type, context, + __container_notify_cb); +} + static acpi_status container_walk_namespace_cb(acpi_handle handle, u32 lvl, void *context, void **rv) -- 1.7.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] Use kacpi_hotplug_wq to handle container hotplug event. 2012-10-23 13:10 ` [PATCH 1/2] Use kacpi_hotplug_wq to handle container hotplug event Tang Chen @ 2012-10-23 17:36 ` Yinghai Lu 2012-10-24 17:33 ` Toshi Kani 1 sibling, 0 replies; 6+ messages in thread From: Yinghai Lu @ 2012-10-23 17:36 UTC (permalink / raw) To: Tang Chen Cc: bhelgaas, lenb, jiang.liu, izumi.taku, isimatu.yasuaki, linux-acpi, linux-pci, linux-kernel On Tue, Oct 23, 2012 at 6:10 AM, Tang Chen <tangchen@cn.fujitsu.com> wrote: > As the comments in __acpi_os_execute() said: > > We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq > because the hotplug code may call driver .remove() functions, > which invoke flush_scheduled_work/acpi_os_wait_events_complete > to flush these workqueues. > > we should keep the hotplug code in kacpi_hotplug_wq. > > But we have the following call series in kernel now: > acpi_ev_queue_notify_request() > |--> acpi_os_execute() > |--> __acpi_os_execute(type, function, context, 0) > > The last parameter 0 makes the container_notify_cb() executed in > kacpi_notify_wq or kacpid_wq. So, we need to put the real hotplug code > into kacpi_hotplug_wq. I had other patches that merge acpi_hp_work in acpiphp and pci_root_hp. I just put them in to for-pci-split-pci-root-hp-2. can you check them to see if you can use it? Thanks Yinghai ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] Use kacpi_hotplug_wq to handle container hotplug event. 2012-10-23 13:10 ` [PATCH 1/2] Use kacpi_hotplug_wq to handle container hotplug event Tang Chen 2012-10-23 17:36 ` Yinghai Lu @ 2012-10-24 17:33 ` Toshi Kani 2012-10-25 1:24 ` Tang Chen 1 sibling, 1 reply; 6+ messages in thread From: Toshi Kani @ 2012-10-24 17:33 UTC (permalink / raw) To: Tang Chen Cc: yinghai, bhelgaas, lenb, jiang.liu, izumi.taku, isimatu.yasuaki, linux-acpi, linux-pci, linux-kernel On Tue, 2012-10-23 at 21:10 +0800, Tang Chen wrote: > As the comments in __acpi_os_execute() said: > > We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq > because the hotplug code may call driver .remove() functions, > which invoke flush_scheduled_work/acpi_os_wait_events_complete > to flush these workqueues. > > we should keep the hotplug code in kacpi_hotplug_wq. > > But we have the following call series in kernel now: > acpi_ev_queue_notify_request() > |--> acpi_os_execute() > |--> __acpi_os_execute(type, function, context, 0) > > The last parameter 0 makes the container_notify_cb() executed in > kacpi_notify_wq or kacpid_wq. So, we need to put the real hotplug code > into kacpi_hotplug_wq. Hi Tang, I am curious; is there a particular reason why you use alloc_acpi_container_hp_work() instead of acpi_os_hotplug_execute(), which is already there in the tree? Thanks, -Toshi > Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com> > --- > drivers/acpi/container.c | 44 +++++++++++++++++++++++++++++++++++++++++++- > 1 files changed, 43 insertions(+), 1 deletions(-) > > diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c > index 1f9f7d7..643657a 100644 > --- a/drivers/acpi/container.c > +++ b/drivers/acpi/container.c > @@ -72,8 +72,36 @@ static struct acpi_driver acpi_container_driver = { > }, > }; > > +struct acpi_container_hp_work { > + struct work_struct work; > + acpi_handle handle; > + u32 type; > + void *context; > +}; > + > /*******************************************************************/ > > +static void alloc_acpi_container_hp_work(acpi_handle handle, u32 type, > + void *context, > + void (*func)(struct work_struct *work)) > +{ > + struct acpi_container_hp_work *hp_work; > + int ret; > + > + hp_work = kmalloc(sizeof(*hp_work), GFP_KERNEL); > + if (!hp_work) > + return; > + > + hp_work->handle = handle; > + hp_work->type = type; > + hp_work->context = context; > + > + INIT_WORK(&hp_work->work, func); > + ret = queue_work(kacpi_hotplug_wq, &hp_work->work); > + if (!ret) > + kfree(hp_work); > +} > + > static int is_device_present(acpi_handle handle) > { > acpi_handle temp; > @@ -152,14 +180,21 @@ static int container_device_add(struct acpi_device **device, acpi_handle handle) > return result; > } > > -static void container_notify_cb(acpi_handle handle, u32 type, void *context) > +static void __container_notify_cb(struct work_struct *work) > { > struct acpi_device *device = NULL; > int result; > int present; > acpi_status status; > + struct acpi_container_hp_work *hp_work; > + acpi_handle handle; > + u32 type; > u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; /* default */ > > + hp_work = container_of(work, struct acpi_container_hp_work, work); > + handle = hp_work->handle; > + type = hp_work->type; > + > switch (type) { > case ACPI_NOTIFY_BUS_CHECK: > /* Fall through */ > @@ -211,6 +246,13 @@ static void container_notify_cb(acpi_handle handle, u32 type, void *context) > return; > } > > +static void container_notify_cb(acpi_handle handle, u32 type, > + void *context) > +{ > + alloc_acpi_container_hp_work(handle, type, context, > + __container_notify_cb); > +} > + > static acpi_status > container_walk_namespace_cb(acpi_handle handle, > u32 lvl, void *context, void **rv) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] Use kacpi_hotplug_wq to handle container hotplug event. 2012-10-24 17:33 ` Toshi Kani @ 2012-10-25 1:24 ` Tang Chen 0 siblings, 0 replies; 6+ messages in thread From: Tang Chen @ 2012-10-25 1:24 UTC (permalink / raw) To: Toshi Kani Cc: yinghai, bhelgaas, lenb, jiang.liu, izumi.taku, isimatu.yasuaki, linux-acpi, linux-pci, linux-kernel On 10/25/2012 01:33 AM, Toshi Kani wrote: > On Tue, 2012-10-23 at 21:10 +0800, Tang Chen wrote: >> As the comments in __acpi_os_execute() said: >> >> We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq >> because the hotplug code may call driver .remove() functions, >> which invoke flush_scheduled_work/acpi_os_wait_events_complete >> to flush these workqueues. >> >> we should keep the hotplug code in kacpi_hotplug_wq. >> >> But we have the following call series in kernel now: >> acpi_ev_queue_notify_request() >> |--> acpi_os_execute() >> |--> __acpi_os_execute(type, function, context, 0) >> >> The last parameter 0 makes the container_notify_cb() executed in >> kacpi_notify_wq or kacpid_wq. So, we need to put the real hotplug code >> into kacpi_hotplug_wq. > > Hi Tang, > > I am curious; is there a particular reason why you use > alloc_acpi_container_hp_work() instead of acpi_os_hotplug_execute(), > which is already there in the tree? Hi Toshi, Thanks for telling me this. I didn't realize this function. :) And yes, it is better. Thanks. :) > > Thanks, > -Toshi > > >> Signed-off-by: Tang Chen<tangchen@cn.fujitsu.com> >> --- >> drivers/acpi/container.c | 44 +++++++++++++++++++++++++++++++++++++++++++- >> 1 files changed, 43 insertions(+), 1 deletions(-) >> >> diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c >> index 1f9f7d7..643657a 100644 >> --- a/drivers/acpi/container.c >> +++ b/drivers/acpi/container.c >> @@ -72,8 +72,36 @@ static struct acpi_driver acpi_container_driver = { >> }, >> }; >> >> +struct acpi_container_hp_work { >> + struct work_struct work; >> + acpi_handle handle; >> + u32 type; >> + void *context; >> +}; >> + >> /*******************************************************************/ >> >> +static void alloc_acpi_container_hp_work(acpi_handle handle, u32 type, >> + void *context, >> + void (*func)(struct work_struct *work)) >> +{ >> + struct acpi_container_hp_work *hp_work; >> + int ret; >> + >> + hp_work = kmalloc(sizeof(*hp_work), GFP_KERNEL); >> + if (!hp_work) >> + return; >> + >> + hp_work->handle = handle; >> + hp_work->type = type; >> + hp_work->context = context; >> + >> + INIT_WORK(&hp_work->work, func); >> + ret = queue_work(kacpi_hotplug_wq,&hp_work->work); >> + if (!ret) >> + kfree(hp_work); >> +} >> + >> static int is_device_present(acpi_handle handle) >> { >> acpi_handle temp; >> @@ -152,14 +180,21 @@ static int container_device_add(struct acpi_device **device, acpi_handle handle) >> return result; >> } >> >> -static void container_notify_cb(acpi_handle handle, u32 type, void *context) >> +static void __container_notify_cb(struct work_struct *work) >> { >> struct acpi_device *device = NULL; >> int result; >> int present; >> acpi_status status; >> + struct acpi_container_hp_work *hp_work; >> + acpi_handle handle; >> + u32 type; >> u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; /* default */ >> >> + hp_work = container_of(work, struct acpi_container_hp_work, work); >> + handle = hp_work->handle; >> + type = hp_work->type; >> + >> switch (type) { >> case ACPI_NOTIFY_BUS_CHECK: >> /* Fall through */ >> @@ -211,6 +246,13 @@ static void container_notify_cb(acpi_handle handle, u32 type, void *context) >> return; >> } >> >> +static void container_notify_cb(acpi_handle handle, u32 type, >> + void *context) >> +{ >> + alloc_acpi_container_hp_work(handle, type, context, >> + __container_notify_cb); >> +} >> + >> static acpi_status >> container_walk_namespace_cb(acpi_handle handle, >> u32 lvl, void *context, void **rv) > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] Improve container_notify_cb() to support container hot-remove. 2012-10-23 13:10 [PATCH 0/2] ACPI: container hot remove support Tang Chen 2012-10-23 13:10 ` [PATCH 1/2] Use kacpi_hotplug_wq to handle container hotplug event Tang Chen @ 2012-10-23 13:10 ` Tang Chen 1 sibling, 0 replies; 6+ messages in thread From: Tang Chen @ 2012-10-23 13:10 UTC (permalink / raw) To: yinghai, bhelgaas, lenb, jiang.liu, izumi.taku, isimatu.yasuaki, linux-acpi, linux-pci, linux-kernel This patch introduces a new function container_device_remove() to do the container hot-remove job. It works like the following: 1. call acpi_bus_trim(device, 0) to stop the container device. 2. generate the KOBJ_OFFLINE uevent. (Did I do this correct ?) 3. call acpi_bus_hot_remove_device(), which will call acpi_bus_trim(device, 1) to remove the container. This patch is based on Lu Yinghai's work. git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-split-pci-root-hp-2 Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com> --- drivers/acpi/container.c | 58 ++++++++++++++++++++++++++++++++++++++------- 1 files changed, 49 insertions(+), 9 deletions(-) diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c index 643657a..1de4672 100644 --- a/drivers/acpi/container.c +++ b/drivers/acpi/container.c @@ -180,6 +180,35 @@ static int container_device_add(struct acpi_device **device, acpi_handle handle) return result; } +static int container_device_remove(struct acpi_device *device) +{ + int ret; + struct acpi_eject_event *ej_event; + + ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL); + if (!ej_event) + return -ENOMEM; + + ej_event->device = device; + ej_event->event = ACPI_NOTIFY_EJECT_REQUEST; + + /* stop container device at first */ + ret = acpi_bus_trim(device, 0); + printk(KERN_WARNING "acpi_bus_trim stop return %x\n", ret); + if (ret) + return ret; + + /* event originated from ACPI eject notification */ + device->flags.eject_pending = 1; + + /* send the uevent before remove the device */ + kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE); + + acpi_bus_hot_remove_device(ej_event); + + return 0; +} + static void __container_notify_cb(struct work_struct *work) { struct acpi_device *device = NULL; @@ -195,6 +224,9 @@ static void __container_notify_cb(struct work_struct *work) handle = hp_work->handle; type = hp_work->type; + present = is_device_present(handle); + status = acpi_bus_get_device(handle, &device); + switch (type) { case ACPI_NOTIFY_BUS_CHECK: /* Fall through */ @@ -203,13 +235,14 @@ static void __container_notify_cb(struct work_struct *work) (type == ACPI_NOTIFY_BUS_CHECK) ? "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"); - present = is_device_present(handle); - status = acpi_bus_get_device(handle, &device); if (!present) { if (ACPI_SUCCESS(status)) { /* device exist and this is a remove request */ - device->flags.eject_pending = 1; - kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE); + result = container_device_remove(device); + if (result) { + printk(KERN_WARNING "Failed to remove container\n"); + break; + } return; } break; @@ -229,12 +262,19 @@ static void __container_notify_cb(struct work_struct *work) break; case ACPI_NOTIFY_EJECT_REQUEST: - if (!acpi_bus_get_device(handle, &device) && device) { - device->flags.eject_pending = 1; - kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE); - return; + printk(KERN_WARNING "Container driver received %s event\n", + "ACPI_NOTIFY_EJECT_REQUEST"); + + if (!present || ACPI_FAILURE(status) || !device) + break; + + result = container_device_remove(device); + if (result) { + printk(KERN_WARNING "Failed to remove container\n"); + break; } - break; + + return; default: /* non-hotplug event; possibly handled by other handler */ -- 1.7.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-10-25 1:26 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-10-23 13:10 [PATCH 0/2] ACPI: container hot remove support Tang Chen 2012-10-23 13:10 ` [PATCH 1/2] Use kacpi_hotplug_wq to handle container hotplug event Tang Chen 2012-10-23 17:36 ` Yinghai Lu 2012-10-24 17:33 ` Toshi Kani 2012-10-25 1:24 ` Tang Chen 2012-10-23 13:10 ` [PATCH 2/2] Improve container_notify_cb() to support container hot-remove Tang Chen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).