From patchwork Fri Apr 27 15:16:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 155519 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 9C1FAB6F9F for ; Sat, 28 Apr 2012 01:25:32 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760495Ab2D0PUr (ORCPT ); Fri, 27 Apr 2012 11:20:47 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:61293 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760473Ab2D0PUo (ORCPT ); Fri, 27 Apr 2012 11:20:44 -0400 Received: by mail-pb0-f46.google.com with SMTP id rp8so666347pbb.19 for ; Fri, 27 Apr 2012 08:20:44 -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=3uRdtWAwJXQjLH9aolMjDDFimAzP2m+DBAoh2b0bfig=; b=QvrIARW1NyUt13/SbwpReXh2wpYcr7i2OC9IvZSPmK3y4zDrNw+4OGaCdP+knM/KoB 2PnXKaZIp6h36Hq6Dm+dlpTVSa/PDtgN7lZTB0075YYgRfsnPo9fjBEzDs0zso49r3EM TyGBDHkh4A9yE7q6V9UjYMLPsk9ggaBaAUQfNyB8afrqH3mBkiz6Z6r2LXWlJA0SaITB O6+MHVnNUMh262YXG1l2m3sUyZ7JJnW3CCP6de1jd5syalCdiiD4TAA/TwhtTt6GhTM3 9Vr8lexOH6DEgrIAW8hm2r46pLYlAeFwiWQdqphu3bMEHEdlYH7WXGZ5SI1+KnAbCSQq x2DA== Received: by 10.68.237.130 with SMTP id vc2mr8609240pbc.134.1335540044402; Fri, 27 Apr 2012 08:20:44 -0700 (PDT) Received: from localhost.localdomain ([221.221.26.142]) by mx.google.com with ESMTPS id 2sm6743917pbw.57.2012.04.27.08.20.35 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Apr 2012 08:20:43 -0700 (PDT) From: Jiang Liu To: Yinghai Lu , Kenji Kaneshige , Bjorn Helgaas , Don Dutile , Greg KH Cc: Jiang Liu , Keping Chen , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Jiang Liu Subject: [PATCH v2 05/19] PCI: correctly flush workqueue when destroy pcie hotplug controller Date: Fri, 27 Apr 2012 23:16:46 +0800 Message-Id: <1335539820-11232-6-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1335539820-11232-1-git-send-email-jiang.liu@huawei.com> References: <1335539820-11232-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 From: Jiang Liu 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 --- 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); }