From patchwork Wed Aug 27 07:11:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 4786481 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 94EF8C0338 for ; Wed, 27 Aug 2014 07:14:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 75AEA201C7 for ; Wed, 27 Aug 2014 07:14:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 60BF42018B for ; Wed, 27 Aug 2014 07:14:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751684AbaH0HOm (ORCPT ); Wed, 27 Aug 2014 03:14:42 -0400 Received: from mga01.intel.com ([192.55.52.88]:17455 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750965AbaH0HOk (ORCPT ); Wed, 27 Aug 2014 03:14:40 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP; 27 Aug 2014 00:14:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,862,1389772800"; d="scan'208";a="377511956" Received: from lantianyu-ws.sh.intel.com (HELO localhost) ([10.239.37.18]) by FMSMGA003.fm.intel.com with ESMTP; 27 Aug 2014 00:10:26 -0700 From: Lan Tianyu To: rjw@rjwysocki.net, lenb@kernel.org, fengguang.wu@intel.com Cc: Lan Tianyu , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, All applicable , "Rafael J. Wysocki" Subject: [PATCH V3] ACPI / OSL: Make acpi_os_map_cleanup() use call_rcu() to avoid deadlocks Date: Wed, 27 Aug 2014 15:11:29 +0800 Message-Id: <1409123489-11786-1-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <20140827022709.GA22064@localhost> References: <20140827022709.GA22064@localhost> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Deadlock is possible when CPU hotplug and evaluating ACPI method happen at the same time. During CPU hotplug, acpi_cpu_soft_notify() is called under the CPU hotplug lock. Then, acpi_cpu_soft_notify() calls acpi_bus_get_device() to obtain the struct acpi_device attached to the given ACPI handle. The ACPICA's namespace lock will be acquired by acpi_bus_get_device() in the process. Thus it is possible to hold the ACPICA's namespace lock under the CPU hotplug lock. Evaluating an ACPI method may involve accessing an operation region in system memory and the associated address space will be unmapped under the ACPICA's namespace lock after completing the access. Currently, osl.c uses RCU to protect memory ranges used by AML. When unmapping them it calls synchronize_rcu() in acpi_os_map_cleanup(), but that blocks CPU hotplug by acquiring the CPU hotplug lock. Thus it is possible to hold the CPU hotplug lock under the ACPICA's namespace lock. This leads to deadlocks like the following one if AML accessing operation regions in memory is executed in parallel with CPU hotplug. INFO: task bash:741 blocked for more than 30 seconds. Not tainted 3.16.0-rc5+ #671 "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. bash D ffff88014e214140 0 741 716 0x00000080 ffff88009b9f3a10 0000000000000086 ffff88009dcfb840 ffff88009b9f3fd8 0000000000014140 0000000000014140 ffffffff81c18460 ffffffff81c40fc8 ffffffff81c40fcc ffff88009dcfb840 00000000ffffffff ffffffff81c40fd0 Call Trace: [] schedule_preempt_disabled+0x29/0x70 [] __mutex_lock_slowpath+0xca/0x1c0 [] mutex_lock+0x1f/0x2f [] get_online_cpus+0x2c/0x50 [] synchronize_sched_expedited+0x64/0x1c0 [] synchronize_sched+0x45/0x50 [] acpi_os_map_cleanup.part.7+0x14/0x3e [] acpi_os_unmap_iomem+0xe2/0xea [] acpi_os_unmap_memory+0xe/0x14 [] acpi_ev_system_memory_region_setup+0x2d/0x97 [] acpi_ut_update_ref_count+0x24d/0x2de [] acpi_ut_update_object_reference+0x11a/0x18b [] acpi_ut_remove_reference+0x2e/0x31 [] acpi_ns_detach_object+0x7b/0x80 [] acpi_ns_delete_namespace_subtree+0x47/0x81 [] acpi_ds_terminate_control_method+0x85/0x11b [] acpi_ps_parse_aml+0x164/0x289 [] acpi_ps_execute_method+0x1c1/0x26c [] acpi_ns_evaluate+0x1c1/0x258 [] acpi_evaluate_object+0x126/0x22f [] acpi_hw_execute_sleep_method+0x3d/0x68 [] ? acpi_hw_enable_all_runtime_gpes+0x17/0x19 [] acpi_hw_legacy_wake+0x4d/0x9d [] acpi_hw_sleep_dispatch+0x2a/0x2c [] acpi_leave_sleep_state+0x17/0x19 [] acpi_pm_finish+0x3f/0x99 [] suspend_devices_and_enter+0x139/0x560 [] pm_suspend+0xf2/0x370 [] state_store+0x79/0xf0 [] kobj_attr_store+0xf/0x20 [] sysfs_kf_write+0x3d/0x50 [] kernfs_fop_write+0xe0/0x160 [] vfs_write+0xb7/0x1f0 [] SyS_write+0x46/0xb0 [] ? __audit_syscall_exit+0x1f6/0x2a0 [] system_call_fastpath+0x16/0x1b INFO: task async-enable-no:749 blocked for more than 30 seconds. Not tainted 3.16.0-rc5+ #671 "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. async-enable-no D ffff88014e254140 0 749 2 0x00000080 ffff88009de83bf0 0000000000000046 ffff88009b850000 ffff88009de83fd8 0000000000014140 0000000000014140 ffff880148305dc0 ffff880149804160 7fffffffffffffff 0000000000000002 0000000000000000 ffff88009b850000 Call Trace: [] schedule+0x29/0x70 [] schedule_timeout+0x1f9/0x270 [] ? __kernfs_create_file+0x7e/0xa0 [] ? sysfs_add_file_mode_ns+0x9b/0x160 [] __down_common+0x93/0xd8 [] __down_timeout+0x16/0x18 [] down_timeout+0x4c/0x60 [] acpi_os_wait_semaphore+0x43/0x57 [] acpi_ut_acquire_mutex+0x48/0x88 [] ? acpi_match_device+0x4f/0x4f [] acpi_get_data_full+0x3a/0x8e [] acpi_bus_get_device+0x23/0x40 [] acpi_cpu_soft_notify+0x50/0xe6 [] notifier_call_chain+0x4c/0x70 [] __raw_notifier_call_chain+0xe/0x10 [] cpu_notify+0x23/0x50 [] _cpu_up+0x168/0x180 [] _cpu_up_with_trace+0x2c/0xe0 [] ? disable_nonboot_cpus+0x1c0/0x1c0 [] async_enable_nonboot_cpus+0x1f/0x70 [] kthread+0xd2/0xf0 [] ? insert_kthread_work+0x40/0x40 [] ret_from_fork+0x7c/0xb0 To avoid such deadlocks, modify acpi_os_map_cleanup() to use call_rcu() to schedule acpi_os_async_umap() asynchronously to umap memory regions that aren't used any more. The umap operation can't be done in the call_rcu()'s callback directly because the callback will be called in the soft irq context and acpi_unmap() holds mutex lock inside. Signed-off-by: Lan Tianyu [rjw: Subject and changelog.] Cc: All applicable Signed-off-by: Rafael J. Wysocki Signed-off-by: Lan Tianyu --- drivers/acpi/osl.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index 3abe9b2..9baef71 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -94,6 +95,7 @@ struct acpi_ioremap { acpi_physical_address phys; acpi_size size; unsigned long refcount; + struct rcu_head rcu; }; static LIST_HEAD(acpi_ioremaps); @@ -423,13 +425,25 @@ static void acpi_os_drop_map_ref(struct acpi_ioremap *map) list_del_rcu(&map->list); } +static void acpi_os_async_umap(void *data, async_cookie_t cookie) +{ + struct acpi_ioremap *map = data; + + acpi_unmap(map->phys, map->virt); + kfree(map); +} + +static void acpi_os_map_reclaim(struct rcu_head *rcu) +{ + struct acpi_ioremap *map = container_of(rcu, struct acpi_ioremap, rcu); + + async_schedule(acpi_os_async_umap, map); +} + static void acpi_os_map_cleanup(struct acpi_ioremap *map) { - if (!map->refcount) { - synchronize_rcu(); - acpi_unmap(map->phys, map->virt); - kfree(map); - } + if (!map->refcount) + call_rcu(&map->rcu, acpi_os_map_reclaim); } void __ref acpi_os_unmap_iomem(void __iomem *virt, acpi_size size)