Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2822614rwn; Fri, 9 Sep 2022 22:48:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR50fG5UUUAggiJQDdhN0t59zLIvWlj0FLQeidlIdsPq9+rEWFZXZcd+zlQzcQxUUtuWVupZ X-Received: by 2002:a65:6bd3:0:b0:42b:9117:b9d1 with SMTP id e19-20020a656bd3000000b0042b9117b9d1mr15095291pgw.238.1662788937015; Fri, 09 Sep 2022 22:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662788937; cv=none; d=google.com; s=arc-20160816; b=gwkf11MWaV9Stzg7hDmXgC2P9ZpoQRh+bF7gMAbGQc/a0izVGSr9dFGbnGBxdJ7c/f GZuwq+zHqXWtFOQnx3AdNG3koYMtDzWliQmZndPlJWTv68G5pOlAvfAHFUjyzIxNN7+w MqM4+dZXhE6yRBO75IBXYWiQnZmZwVU9DOXRx5750IbGzMP8WVBCZqTZpqeI6IwnqMoo ZNsCJ59lMQ+d0FMx+w29Qxpig1njHrwyyQwhO3H3+kpAy4c7xzLr5JFptjNpXPArLfqH 9fql1rsu1drTPXcP8KAhBsqCLJTP3CWfzvNELTaHvy/jZfeMpLP3xFrl6+KFZiICzfHD sJMA== 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=ap/bl4cR8egBKZyaptAx7IJ4o78mES1hMEIDeZHoiX4=; b=cIwxYvYqOdsKTqkX1ssdD2sbHStF/7tStBFMWLyg2g/fe6q7U+xGrKJsXRv9uF6hk1 2I9lDsBKn+FgR75KSNPt885CTI4b6GZ6GY6UBCwzjnhEOpbUGUFfAwF5EtlhoSi0OV8d abDayuzNGdgmV8TvZeDTq2+F5MSTsWveg7eM3Emql6S4eU3mTw6Qu821CJPV+WJV6XF4 WF4b1zdT7I1d0hi5dJf0tRDFA1/X7yu7ZtNwC5XPjoi82VDzbZ14ut0gLp7tKdVPuTdV jwExagOOMsX1xHsXFQEapuAesuSVfIy+sT56/ubjqfDS1fuu16wuYiswT942ErNt8Z/f s2xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E+hkF3Dc; 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 s4-20020a170903214400b0016d2dcb9b91si972412ple.599.2022.09.09.22.48.44; Fri, 09 Sep 2022 22:48:56 -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=E+hkF3Dc; 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 S229758AbiIJFlp (ORCPT + 99 others); Sat, 10 Sep 2022 01:41:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229546AbiIJFlm (ORCPT ); Sat, 10 Sep 2022 01:41:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD32697D57; Fri, 9 Sep 2022 22:41:41 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 75F996097C; Sat, 10 Sep 2022 05:41:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FAF0C433C1; Sat, 10 Sep 2022 05:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662788500; bh=CCHuYQhbCtE8/FLBJOVSxRolZQXA1M6I2aBFGi0YGnw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=E+hkF3DcoO3dh7l/wmOweKNZnmCqoh63s9KluOWS4idbzv9GvVcX/ToFfoYV9x0ir BXA5ph+dXkB7tNw8RLiRst0O5qInlpKCgowfZKFdXuH9iXCWSbSxLQpFLfVMu45h7Q AAyBNw+ZCnr3td5SJjf15sgzitRXMhaAVVoDCHEU= Date: Sat, 10 Sep 2022 07:42:03 +0200 From: Greg Kroah-Hartman To: "Rafael J. Wysocki" Cc: "Rafael J. Wysocki" , 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> <5870387.lOV4Wx5bFT@kreacher> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5870387.lOV4Wx5bFT@kreacher> X-Spam-Status: No, score=-7.1 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 Fri, Sep 09, 2022 at 11:18:46PM +0200, Rafael J. Wysocki wrote: > On Friday, September 9, 2022 9:42:53 AM CEST Greg Kroah-Hartman wrote: > > On Mon, Jun 27, 2022 at 06:37:06PM +0200, Rafael J. Wysocki wrote: > > > On Mon, Jun 27, 2022 at 5:07 PM Greg Kroah-Hartman > > > wrote: > > > > > > > > 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? > > > > > > I have an idea, sorry for the delay here. > > > > > > I should be ready to post something tomorrow. > > > > Was this ever posted? > > No, it wasn't. Sorry for the glacial pace here. > > So the idea is based on the observation that the PCI device returned by the current > code in acpi_get_pci_dev() needs to be registered, so if it corresponds to an ACPI > device object, the struct acpi_device representing it must be registered too and, > moreover, it should be the ACPI companion of that PCI device. Thus it should be > sufficient to look for it in the ACPI device object's list of physical nodes > corresponding to it. Hence, the patch below. > > I actually can't test it right now (or even compile it for that matter), but > I'll put it in order tomorrow. The idea looks sane to me, let me know if testing works or not, thanks! greg k-h