From patchwork Mon Apr 16 16:28:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 152929 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 D8EF2B700D for ; Tue, 17 Apr 2012 02:32:57 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752741Ab2DPQcp (ORCPT ); Mon, 16 Apr 2012 12:32:45 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:52165 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752442Ab2DPQcn (ORCPT ); Mon, 16 Apr 2012 12:32:43 -0400 Received: by mail-pb0-f46.google.com with SMTP id un15so6539626pbc.19 for ; Mon, 16 Apr 2012 09:32:43 -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:in-reply-to:references; bh=UxgvjcffxHhEf/Wy9a7iGYPAR8Vz+4adzCq5x4E7Mz8=; b=TqB37wQrdk8ieCUm57iHS56G9o6QfYZX+aiFGt8l331yRvu7eK8Es3hYobiTHFaG9O qjTh3hX5vgNyq+tWIl+xJH6BSeG3OgWOMcb/e5LHPlSatVlSioD0zpKF8DVKB7Gnzjcw 7AgtH4DR7XPUv9pTCzcOcQAVNnhNLvJ0z0PF9vEIRLb/95GRC93Teh+47ujQ0qbY0E6L WiqIP3tLI5XyelZECi/ungJlZMghHPqAsaaWBONGvW4qpQMLBwIhVsXE1DXYTcrUcPBX YpQa6PcAePZI/2gFEafXYb3XK11AILUB5sXbcxovEDJXgyP9asG7zdnBZOtS3BRfYn9O l0tA== Received: by 10.68.213.73 with SMTP id nq9mr29092255pbc.143.1334593963436; Mon, 16 Apr 2012 09:32:43 -0700 (PDT) Received: from localhost.localdomain ([221.221.22.162]) by mx.google.com with ESMTPS id v1sm18106794pbk.10.2012.04.16.09.32.36 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 Apr 2012 09:32:42 -0700 (PDT) From: Jiang Liu To: Yinghai Lu , Kenji Kaneshige , Bjorn Helgaas , Dan Zink , Greg Kroah-Hartman , Dely Sy Cc: Jiang Liu , Jiang Liu , Keping Chen , linux-pci@vger.kernel.org Subject: [PATCH RFC 05/17] PCI: correctly flush workqueue when destroy pcie hotplug controller Date: Tue, 17 Apr 2012 00:28:59 +0800 Message-Id: <1334593751-5916-6-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1334593751-5916-1-git-send-email-jiang.liu@huawei.com> References: <1334593751-5916-1-git-send-email-jiang.liu@huawei.com> 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 | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index a960fae..98b775f 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -889,8 +889,20 @@ 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); }