Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3052872iog; Mon, 27 Jun 2022 08:11:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tV7KNkEeFc6ZmT8mYeDp+6Whtn4jJnI8ovr0a83JKO4fJO4Ua5tzJkv0RDolgTXxJi+ivM X-Received: by 2002:a17:902:edd7:b0:16a:1fe3:871 with SMTP id q23-20020a170902edd700b0016a1fe30871mr14519726plk.121.1656342704558; Mon, 27 Jun 2022 08:11:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656342704; cv=none; d=google.com; s=arc-20160816; b=crnmL9apJucTa0H7qXRrTg7NckfMqIotKx3hPYUxhx/B4eohp6ekGEzdLebqU1eHeU a1xjCavzmT0dvwbEquLRaDs6+Vw4Ouy4ELIR+4tCI0Lfs5QGnG1d+73ssHT/TT2CfkuP 8h5w/jFUfczzrH1zIynYfGo/rre3KBBBKdd2pxI0PF3cqOmivSglmcw+wQUqo5bqG/Aj dY5vEzbvOjEW/o7mYp/mnaeT8NBQ76KtmRc8OGOQ2NtTpEheaFZoRZA/tXktUHIoqux8 XApsfUgq3Kg8+n+4aILoj8N9ZbYiaITGuEWE0zoST0+mnVxd0ehe7c2qgGYbHIEwGuNn NDsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UK8oA70/6dUmHW9clqNtBLZ8UI8RcqGlchwYdFojK1A=; b=tSEd7ZX98xMDZtKjbiyGpE8zBQiWCeCR7e162LkyWaLooLFhykkT3px6+Wvrrcgryx 1AORJIHiv5qWoX62F4n8mwVuKHnh0HJu0g5cQb16pYNd2huv9MocDn5Vhp20qToArnE7 lGUCHzS5Q5vaDFzgJojA2vh1AFoMBSFnt8Ok5jYUIJ8waTs0LqYPzECH0ux2zx1RhWfD bzw/RMpltqqzm+kBxlev6tkA6xDPLNwDR0CApgiRoT5OEngWYPI8ehHCqlIzUPBQ3FqP xD1bhHmeKLdZayC2iBzb2dGAfmiVnZ8Ysfvp0L8bhtjADrf619hlCnpJ6ynj/DWFC+qg ThAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EyD5KuLR; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n25-20020a63a519000000b004037c60a2acsi13333279pgf.197.2022.06.27.08.11.31; Mon, 27 Jun 2022 08:11:44 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EyD5KuLR; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237716AbiF0PHd (ORCPT + 99 others); Mon, 27 Jun 2022 11:07:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237687AbiF0PHa (ORCPT ); Mon, 27 Jun 2022 11:07:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADEDB18352; Mon, 27 Jun 2022 08:07:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6239DB81840; Mon, 27 Jun 2022 15:07:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA048C3411D; Mon, 27 Jun 2022 15:07:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656342447; bh=tZxvX20Ke65Yi+x4CGSg+T4rZrQkmThqBiNjJDO6IrE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EyD5KuLRb4jqQFu72TMxxWafj9WqqZ7E9NwUjT12eOG9N1UKPDOSPH9Bl0PxtPLZw Ag6yjG06qk2rKFyvpuYfW+n6ZFb2v7imAhtAgHfZYvGqsWCWyOCaCKneIu1Yg33P39 Ya+JURfgZdwOW+sNCuI4Z7320D/CPaIG2w6fYIOI= Date: Mon, 27 Jun 2022 17:07:24 +0200 From: Greg Kroah-Hartman To: "Rafael J. Wysocki" Cc: Bjorn Helgaas , Bjorn Helgaas , Linux Kernel Mailing List , Len Brown , Linux PCI , ACPI Devel Maling List , whitehat002 Subject: Re: [PATCH] PCI/ACPI: do not reference a pci device after it has been released Message-ID: References: <20220428142854.1065953-1-gregkh@linuxfoundation.org> <20220428155858.GA14614@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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:30:38PM +0200, Rafael J. Wysocki wrote: > 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? Good point. whitehat002, any ideas? You found this issue but it really looks like it is not anything that can ever be hit, so how far do you want to go to unwind it? thanks, greg k-h