From patchwork Sat Apr 7 18:18:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 151310 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 09941B703D for ; Sun, 8 Apr 2012 04:22:14 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753319Ab2DGSV3 (ORCPT ); Sat, 7 Apr 2012 14:21:29 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:33768 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752591Ab2DGSV2 (ORCPT ); Sat, 7 Apr 2012 14:21:28 -0400 Received: by iagz16 with SMTP id z16so4335659iag.19 for ; Sat, 07 Apr 2012 11:21:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=FRwuQTW9qvauK/SYK1W5ioPNn5wKgLHGgfzPjdzAupM=; b=zKMgYjeMfVszcdXTrFb60/kaF+Nl5X6T0jIpn4sFhl9d+WIWcESYN4xhfHBb8NxDV2 JcUPwZWVv3wPUfoiOGy/QzN59N2EFVEEjd7E59s6GNt0UeWhiqQVVJZ5RFC1XxfMTkAP sd8dz3glHvYVVzL/V46iv6iccmKsT/7p4OyQN0KOlKiL6ZCHlzWYEBJdDxN/89j3rCSe qvGmpZoyYTZZtE48kTAcM6YLEBJELpn3WgRoe94uKHefhd5qtXjXMNRvt6cMhJ4mObAL kqORMeVi++wnl2JZviXTvYNX7Zhyu82+BFPq+RqE15CEiJOwaz5SUlGL1rNMvnS3FXmJ ZKtA== Received: by 10.50.187.231 with SMTP id fv7mr1437671igc.51.1333822888027; Sat, 07 Apr 2012 11:21:28 -0700 (PDT) Received: from localhost.localdomain ([221.221.23.44]) by mx.google.com with ESMTPS id gh8sm8286808igb.16.2012.04.07.11.21.22 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 07 Apr 2012 11:21:27 -0700 (PDT) From: Jiang Liu To: Bjorn Helgaas , Yinghai Lu , Kenji Kaneshige Cc: Jiang Liu , matsumoto.hiroo@jp.fujitsu.com, Jiang Liu , Keping Chen , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [RFC PATCH 1/2] PCI: correctly flush workqueue when destroy pcie hotplug controller Date: Sun, 8 Apr 2012 02:18:54 +0800 Message-Id: <1333822735-10902-1-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.5.4 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org When destroying a PCIe hotplug controller, all work items associated with that controller should be flushed. Function pcie_cleanup_slot() calls cancel_delayed_work() and flush_workqueue() to achieve that. Function flush_workqueue() will flush all work items already submitted, but new work items submitted by those already submitted work items may still be in live state when returning from flush_workqueue(). For the extreme case, pciehp driver may expierence following calling path: 1) pcie_isr() -> pciehp_handle_xxx() -> queue_interrupt_event()->queue_work() 2) interrupt_event_handler() -> handle_button_press_event() -> queue_delayed_work() 3) pciehp_queue_pushbutton_work() -> queue_work() So enhance pcie_cleanup_slot() to correctly flush workqueue when destroying PCIe hotplug controller. Signed-off-by: Jiang Liu Reviewed-by: Kenji Kaneshige --- drivers/pci/hotplug/pciehp_hpc.c | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index d4fa705..9a48a51 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -890,8 +890,19 @@ static int pcie_init_slot(struct controller *ctrl) static void pcie_cleanup_slot(struct controller *ctrl) { struct slot *slot = ctrl->slot; - cancel_delayed_work(&slot->work); + + /* + * Following workqueue flushing logic is to deal with the special call path: + * 1) pcie_isr() -> pciehp_handle_xxx() -> + * queue_interrupt_event(pciehp_wq_event)->queue_work(pciehp_wq) + * 2) interrupt_event_handler() -> handle_button_press_event() -> + * queue_delayed_work(pciehp_wq) + * 3) pciehp_queue_pushbutton_work() -> queue_work(pciehp_wq) + */ flush_workqueue(pciehp_wq); + cancel_delayed_work_sync(&slot->work); + flush_workqueue(pciehp_wq); + kfree(slot); }