Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1501832iob; Fri, 29 Apr 2022 06:48:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgibNSOZwCteCo+q6j06+YWP3JNlECzxA9EY3R+VUoK8ux9ae1Ca8STAwSF/1HnBZkQqvz X-Received: by 2002:a2e:86c6:0:b0:246:3c93:1c8a with SMTP id n6-20020a2e86c6000000b002463c931c8amr24817977ljj.354.1651240112274; Fri, 29 Apr 2022 06:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651240112; cv=none; d=google.com; s=arc-20160816; b=npmR+tKCZrxO67fg6ln9+02zMr7i2NxhHCdtpf8OibiIRHwlJbTFhGTreIzH7YJ1Gs FG8pZS/zmSTgO2ayya504JxSZLxWuNanoCURsjIw6z0yhK7gUD4XhNymNJAUYsEMR+6n X51cmJCH40QJ4HTUD6GvJwi8ponatC3yVelcXDE3OJZlEuwSRB0Cn6HdRqpOq50vtrKo wxRxU0rB0MwXl6YUD19Nu+7F+4liMzUWkAXmaZ3LlaUEfksLf3ri3O7OyII5nhe35Gc3 R7me5zr01Nxf4rV/dLRnzDNQCQRnya4TiLLLW65Ayp0A/u9QPXlfnEUWcnNaOllt8au1 P1Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=gSGOnYTcc5ZEbyXrmCTwPn3swHJvidZ0wfFFy4W9DxE=; b=hypAFOKulveya6RaUlKoM8l6whs6yA4DOmDaydpRoSstOlkKsDM416a3No6ckucaTC BXZyI7ILcRFIvhMtarQEgByEp5R9wtLzBSHdCYwOwOfqFH0rU4ZC5QyTAhwBv3JOtWGo /Bg2XigcuKJvpgBxFibMyrm0o3Xr9R8OdS+drZ21wAiY2YJVo466mI/zDztgE+fC1d50 pOw8ME183WmiIDsB6+gKyl9wCCj4M5lik0FGCrVxS5VfVjnaXa0zrCOcscjbfAi6dD7d IpZ66PZ5BRKh3cFalYZsDnzGJsHy0ZJAyMRp58D0+mg/1u7Ejdu6l7ZHC/7neI9CRUIy VYeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s9-20020a05651c048900b0024b0fb6047esi6239393ljc.251.2022.04.29.06.48.04; Fri, 29 Apr 2022 06:48:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351846AbiD1UeK (ORCPT + 99 others); Thu, 28 Apr 2022 16:34:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349078AbiD1UeG (ORCPT ); Thu, 28 Apr 2022 16:34:06 -0400 Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CB7FC0D3C; Thu, 28 Apr 2022 13:30:50 -0700 (PDT) Received: by mail-yb1-f169.google.com with SMTP id y2so11075989ybi.7; Thu, 28 Apr 2022 13:30:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gSGOnYTcc5ZEbyXrmCTwPn3swHJvidZ0wfFFy4W9DxE=; b=JAZVq1yf4shuv61SA0wIQ8MymZvvQNl3J2Ku3VJNyBVK79/T2e0OVVK24awmHR3PFR 5NDZ2cUiOxWiXHca4xGSs70ka31dRmSttNkHY9hmC5q6EwQFc2thgwmzyPVWEC3RrGvC Q686maKmbyDKx8CTisTQ179g2HoU22DRIDRL6dZibIa6HVoa5QjNAPutrA/qQRORD+TT pf4XEbqdDlTSDk4qF4gKf7LnkUZl6LIEd35Y+QI2xYZMPvbCWLjEAoxv7iYv0STysJdo c1QjzcRffdPKw7T3YWjcsbpDVeHbeH5KhFqh5H6IrgspZs+z0u57LuaR1fA6IqhVvdtM MnWA== X-Gm-Message-State: AOAM533b83DmVf60f+Di8D9siZFkwuEqboLCGAHeMP7EgG8IjC7zJvdA 0cyImo/xUGMFzAaN5/lIBPrL/Otmj+cck856Zew= X-Received: by 2002:a25:da84:0:b0:648:423e:57b0 with SMTP id n126-20020a25da84000000b00648423e57b0mr24541320ybf.137.1651177849779; Thu, 28 Apr 2022 13:30:49 -0700 (PDT) MIME-Version: 1.0 References: <20220428142854.1065953-1-gregkh@linuxfoundation.org> <20220428155858.GA14614@bhelgaas> In-Reply-To: From: "Rafael J. Wysocki" Date: Thu, 28 Apr 2022 22:30:38 +0200 Message-ID: Subject: Re: [PATCH] PCI/ACPI: do not reference a pci device after it has been released To: Greg Kroah-Hartman Cc: Bjorn Helgaas , Bjorn Helgaas , "Rafael J. Wysocki" , Linux Kernel Mailing List , Len Brown , Linux PCI , ACPI Devel Maling List , whitehat002 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 28, 2022 at 10:15 PM Rafael J. Wysocki wrote: > > On Thu, Apr 28, 2022 at 6:22 PM Greg Kroah-Hartman > wrote: > > > > On Thu, Apr 28, 2022 at 10:58:58AM -0500, Bjorn Helgaas wrote: > > > On Thu, Apr 28, 2022 at 04:28:53PM +0200, Greg Kroah-Hartman wrote: > > > > In acpi_get_pci_dev(), the debugging message for when a PCI bridge is > > > > not found uses a pointer to a pci device whose reference has just been > > > > dropped. The chance that this really is a device that is now been > > > > removed from the system is almost impossible to happen, but to be safe, > > > > let's print out the debugging message based on the acpi root device > > > > which we do have a valid reference to at the moment. > > > > > > This code was added by 497fb54f578e ("ACPI / PCI: Fix NULL pointer > > > dereference in acpi_get_pci_dev() (rev. 2)"). Not sure if it's worth > > > a Fixes: tag. > > > > Can't hurt, I'll add it for the v2 based on this review. > > > > > > > > acpi_get_pci_dev() is used by only five callers, three of which are > > > video/backlight related. I'm always skeptical of one-off interfaces > > > like this, but I don't know enough to propose any refactoring or other > > > alternatives. > > > > > > I'll leave this for Rafael, but if I were applying I would silently > > > touch up the subject to match convention: > > > > > > PCI/ACPI: Do not reference PCI device after it has been released > > > > Much simpler, thanks. > > > > > > > > > Cc: Bjorn Helgaas > > > > Cc: "Rafael J. Wysocki" > > > > Cc: Len Brown > > > > Cc: linux-pci@vger.kernel.org > > > > Cc: linux-acpi@vger.kernel.org > > > > Reported-by: whitehat002 > > > > Signed-off-by: Greg Kroah-Hartman > > > > --- > > > > drivers/acpi/pci_root.c | 3 ++- > > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c > > > > index 6f9e75d14808..ecda378dbc09 100644 > > > > --- a/drivers/acpi/pci_root.c > > > > +++ b/drivers/acpi/pci_root.c > > > > @@ -303,7 +303,8 @@ struct pci_dev *acpi_get_pci_dev(acpi_handle handle) > > > > * case pdev->subordinate will be NULL for the parent. > > > > */ > > > > if (!pbus) { > > > > - dev_dbg(&pdev->dev, "Not a PCI-to-PCI bridge\n"); > > > > + dev_dbg(&root->device->dev, > > > > + "dev %d, function %d is not a PCI-to-PCI bridge\n", dev, fn); > > > > > > This should use "%02x.%d" to be consistent with the dev_set_name() in > > > pci_setup_device(). > > > > Ah, missed that, will change it and send out a new version tomorrow. > > I would make the change below (modulo the gmail-induced wthite space > breakage), though. That said -> > --- > drivers/acpi/pci_root.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > Index: linux-pm/drivers/acpi/pci_root.c > =================================================================== > --- linux-pm.orig/drivers/acpi/pci_root.c > +++ linux-pm/drivers/acpi/pci_root.c > @@ -295,8 +295,6 @@ struct pci_dev *acpi_get_pci_dev(acpi_ha > break; > > pbus = pdev->subordinate; > - pci_dev_put(pdev); > - > /* > * This function may be called for a non-PCI device that has a > * PCI parent (eg. a disk under a PCI SATA controller). In that > @@ -304,9 +302,12 @@ struct pci_dev *acpi_get_pci_dev(acpi_ha > */ > if (!pbus) { > dev_dbg(&pdev->dev, "Not a PCI-to-PCI bridge\n"); > + pci_dev_put(pdev); > pdev = NULL; > break; > } > + > + pci_dev_put(pdev); -> we are going to use pbus after this and it is pdev->subordinate which cannot survive without pdev AFAICS. Are we not concerned about this case? > } > out: > list_for_each_entry_safe(node, tmp, &device_list, node)