From patchwork Sat Sep 8 21:06:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1427231 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 2726E3FC85 for ; Sat, 8 Sep 2012 21:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754920Ab2IHVGu (ORCPT ); Sat, 8 Sep 2012 17:06:50 -0400 Received: from mail-fa0-f74.google.com ([209.85.161.74]:34444 "EHLO mail-fa0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754593Ab2IHVGs (ORCPT ); Sat, 8 Sep 2012 17:06:48 -0400 Received: by fass10 with SMTP id s10so35354fas.1 for ; Sat, 08 Sep 2012 14:06:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=ulG90FNNdEtZmF+LEmlIs20z2Jq7wwSUN3SAQbuPe5Q=; b=AIx8Fd+OpSU9Cc20e8IWQIc1KhqYTfXiimQUWnf7I9C0o45oOB+Y80eg8dj+Jj6qFp qRZOzGgA+lkr1MgJCMbFbKOh926vzQXH1A49ScfrMvvksSY2vG2hws4gf7w4x/8BD8wL Guxe37lX3ZdlxSPQtlUUHSkCzxGBKiIzt2v9Cu2M9gz+5cgHEgSVVS2l2xuOmcPXO4an LG868y22RWmok/6L8Gt66GtZBU2q1ctMSwOoc28u7/4TToG9k3i2ZLkYvEu6t/Ne49lv iVYFh7VrgbUL4O6oyqyqjjrtcLAp4uLrRK9Ha43xozQkKFr8yASiQAQP1DEjXOrwdrZr 9DGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent :x-gm-message-state; bh=ulG90FNNdEtZmF+LEmlIs20z2Jq7wwSUN3SAQbuPe5Q=; b=GGK1E5wCPsEqIia4zH7c1rhIeXmbNg/M4QPQz+kVtft1b4nOiTBjlZZ7BwA9OWbnMv yUv5DvzzHng1WYuarqRnPWmpejaxm5Vx7Qx7nB6YSWsyw4daKlOmkaUnpJqCjIext9pi 24R1doua/oNPZCRBNEjEYkG5H5OLPkQCZFJ/XW822GkdBKGV1u0G9kLWiHYnl9S0QrgY Jyxi7wN7HO+1MIZI+GumcJoUJUfm15TAGgGwPA/fyl0h+PmiyeWTWBPIVOx2/j2xDE+E bCUUs4PEUBRb9An0pS953uVzYDh33kDjaDsrynmYi0//8TqIwFHQCU4zzlv0sH47eaiQ TMTQ== Received: by 10.216.241.9 with SMTP id f9mr508248wer.5.1347138406891; Sat, 08 Sep 2012 14:06:46 -0700 (PDT) Received: by 10.216.241.9 with SMTP id f9mr508226wer.5.1347138406711; Sat, 08 Sep 2012 14:06:46 -0700 (PDT) Received: from hpza9.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id e5si772290wiw.0.2012.09.08.14.06.46 (version=TLSv1/SSLv3 cipher=AES128-SHA); Sat, 08 Sep 2012 14:06:46 -0700 (PDT) Received: from bhelgaas.mtv.corp.google.com (bhelgaas.mtv.corp.google.com [172.18.96.155]) by hpza9.eem.corp.google.com (Postfix) with ESMTP id 1526D5C0050; Sat, 8 Sep 2012 14:06:46 -0700 (PDT) Received: by bhelgaas.mtv.corp.google.com (Postfix, from userid 131485) id 57EAF180669; Sat, 8 Sep 2012 14:06:45 -0700 (PDT) Date: Sat, 8 Sep 2012 15:06:45 -0600 From: Bjorn Helgaas To: Yinghai Lu Cc: Feng Tang , Fengguang Wu , Greg Kroah-Hartman , "Paul E. McKenney" , Steven Rostedt , Avi Kivity , Steven Rostedt , LKML , "kvm@vger.kernel.org" , Kenji Kaneshige , linux-pci@vger.kernel.org Subject: Re: [PATCH 1/2] PCI: Use local parameter pci_device_id for pci_get_subsys/class() Message-ID: <20120908210645.GA8678@google.com> References: <20120801004319.GA7043@localhost> <20120822025008.GA8066@localhost> <20120822154908.2e6ef3c0@feng-i7> <20120823154503.15a45b14@feng-i7> <20120908134220.GA24831@localhost> <20120908233455.0d0527b3@feng-i7> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Gm-Message-State: ALoCoQmkXWBnCKpvF+y03jlV61i3GVHaBKmvlc1UsX6Dc24w5HhbHMaJI7uqfsrqthTRmAbyiGke+qpaNEhm9QE6Rp2A1AyX8IeW8s0RgPoOeC0tAfaCVudXQxbGX9RqQxou/EupsC7yQSLUqr0sIW8/+62tmRHddCI7LmVEGWtD80phjPE6FCR9h4jWFO10EFZ1VGBdUEVStZsmrbBXW0ftq47NGgh2nA== Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Sat, Sep 08, 2012 at 11:40:52AM -0700, Yinghai Lu wrote: > On Sat, Sep 8, 2012 at 8:34 AM, Feng Tang wrote: > >> This makes lspci work again on my side. The caveat is, kzalloc() will > >> zero out all data while the new local variable leaves some data > >> uninitialized. > > > > Yes, thanks for the quick root cause and fix to the bug in my code. > > Can you resubmit your patch with two extra "memset" line? I updated the patch as follows and rebased my "next" branch to include it: commit e664f5bd55247bba3a6ebd61f83d6c9cd87ce0de Author: Feng Tang Date: Thu Aug 23 15:45:03 2012 +0800 PCI: Use pci_device_id on stack for pci_get_subsys/class() to avoid kmalloc This fixes a kernel warning https://lkml.org/lkml/2012/7/31/682 pci_get_subsys() may get called in late system reboot stage, using a sleepable kmalloc() sounds fragile and will cause a kernel warning with my recent commmit 55c844a "x86/reboot: Fix a warning message triggered by stop_other_cpus()" which disable local interrupt in late system shutdown/reboot phase. Using a local parameter instead will fix it and make it eligible for calling forom atomic context. Do the same change for the pci_get_class() as suggested by Bjorn Helgaas [bhelgaas: changelog, clear pci_device_id on stack with memset()] Bisected-by: Fengguang Wu Signed-off-by: Feng Tang Signed-off-by: Bjorn Helgaas Reviewed-by: Fengguang Wu --- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/search.c b/drivers/pci/search.c index 993d4a0..e0a0310 100644 --- a/drivers/pci/search.c +++ b/drivers/pci/search.c @@ -245,8 +245,7 @@ struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device, unsigned int ss_vendor, unsigned int ss_device, struct pci_dev *from) { - struct pci_dev *pdev; - struct pci_device_id *id; + struct pci_device_id id; /* * pci_find_subsys() can be called on the ide_setup() path, @@ -257,18 +256,13 @@ struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device, if (unlikely(no_pci_devices())) return NULL; - id = kzalloc(sizeof(*id), GFP_KERNEL); - if (!id) - return NULL; - id->vendor = vendor; - id->device = device; - id->subvendor = ss_vendor; - id->subdevice = ss_device; - - pdev = pci_get_dev_by_id(id, from); - kfree(id); + memset(&id, 0, sizeof(id)); + id.vendor = vendor; + id.device = device; + id.subvendor = ss_vendor; + id.subdevice = ss_device; - return pdev; + return pci_get_dev_by_id(&id, from); } /** @@ -307,19 +301,14 @@ pci_get_device(unsigned int vendor, unsigned int device, struct pci_dev *from) */ struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from) { - struct pci_dev *dev; - struct pci_device_id *id; + struct pci_device_id id; - id = kzalloc(sizeof(*id), GFP_KERNEL); - if (!id) - return NULL; - id->vendor = id->device = id->subvendor = id->subdevice = PCI_ANY_ID; - id->class_mask = PCI_ANY_ID; - id->class = class; + memset(&id, 0, sizeof(id)); + id.vendor = id.device = id.subvendor = id.subdevice = PCI_ANY_ID; + id.class_mask = PCI_ANY_ID; + id.class = class; - dev = pci_get_dev_by_id(id, from); - kfree(id); - return dev; + return pci_get_dev_by_id(&id, from); } /**