Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3518194pxb; Fri, 11 Feb 2022 01:26:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQfmCm1cbzux20mDQJ7WENHSkjapW8RbTZAkcigzvlWc/sFpd28qSMJkrWQI6AWrHdnFiY X-Received: by 2002:a65:6093:: with SMTP id t19mr576875pgu.584.1644571564253; Fri, 11 Feb 2022 01:26:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644571564; cv=none; d=google.com; s=arc-20160816; b=cArgVRqG+Z1rxx7FqCvTHPuk/ca/+2jXG88qMgyhP+KVb0IoAiN1KzBW21LxKRE4vg Xi5Jx9A/Fle0P1K2hn+oHZp7O7PrbTWf66zYGT8Bh1WEB8eB1b2sgguANuEiMAELgaEK CBkIjucnYnLlZ11f8199WVHxjckJCYczt7OIBYdtU0Xr4AtkMrZxKwBT+WAJVAY8iqur wfe0EULZ033vVCvEzMmCVaojSOuZX7FlmKLd9922e7ZWZgzuXXC9i0u4tHyiqiVq7hKk FXfOSw4Lw+wvFZC6Cxgq2ec2dJDnvwIKwTGAdQVw1bV75lkd0XNNt3ELoABGKBDuOgSk x8vw== 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:dkim-signature; bh=CIFupKjScNCpYUypn/cIhD7JLtCVAeh6PLxmrAitRYA=; b=iDo5mjG/LknCBNu64xkXBXFz/cOq0i4zxLVuedI3765HiEagTiG4R6wjrOkqbhBw10 pPpQh3qsktDyNpkNdErp9lRUDf13rvrPrIiwF/zE4qEl5BTdxmc/0ot+1mqrfvqbfEU0 F06CW9jJjLAs9jrhQ7oIXksP3gzy0HMQFidTwcAK82ZJ5VdBNyO5iDgUO658A7vCgH1l wZ0bFTo2emk8goZwpGqF7/FSOwMVv9KraZDNi0eiMyVCBUr+0CYMODK2s/9EkMdESz73 yvsVswLhhF1WlvbPqQ+uMMAU782SjscV8gOYQX9bmCwzYyGgovzh1N33QuAnCzrd3yJL nSqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20210112.gappssmtp.com header.s=20210112 header.b=liNDrbQ5; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t63si20718596pgd.83.2022.02.11.01.25.52; Fri, 11 Feb 2022 01:26:04 -0800 (PST) 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=@intel-com.20210112.gappssmtp.com header.s=20210112 header.b=liNDrbQ5; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347524AbiBKCyd (ORCPT + 99 others); Thu, 10 Feb 2022 21:54:33 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:36418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347515AbiBKCyc (ORCPT ); Thu, 10 Feb 2022 21:54:32 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 371335F45 for ; Thu, 10 Feb 2022 18:54:32 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id on2so6870499pjb.4 for ; Thu, 10 Feb 2022 18:54:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=CIFupKjScNCpYUypn/cIhD7JLtCVAeh6PLxmrAitRYA=; b=liNDrbQ5qLKYyheA7YyqzvUjCK4Md1FDophA9rnAmj7c8qrIi5laNaHwKU4eFrB53R Q7inJruYR907OTZ9RTAcSewzni7BLvKKPKVqeBmGZxNlkKIhGkKYh4WccpQuG8gc2iOw YG4YqDWcHpvZg3RnqUT/pJB0XoXTeGoFXRrJKN7F2ZBLOhswM2JhofuKC94T9WvK91pD dg+iOnr61COPXt4zz53rr9P+G5vuRq/0QXax/xfrPh6FA4UqZTgeUMZYfip/lr9I3bLx yp+ULnDIJ08XwUBYBS5uEw1sxahhVMSHR9sCcmdHe8ALSNZJ30wQEeHBWjmFYNkW08ps UHWQ== 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=CIFupKjScNCpYUypn/cIhD7JLtCVAeh6PLxmrAitRYA=; b=RVKLoa+og46QLIppRa4UoF5yknK/Jbw1pIbv7HMf6zMW9x7ykOB2G2BR3CkCMspj7D xCFd9iGi+ocbN0XnkgJHhv2m8QRDkHXRf70+C+47moIGZkjT4o3m9iOPSoBPu0HdoRiy oyKjmW/itOSb1SReroSHSMR/0UesHbBNuxYMg+q+Q7SqVdbjwfL9w1m7Gp7843fBdopP D/DyeiKBnseEBwNRaHpwF/ikIEiirreW0yrjL0QcneefYu5bCaLnUWCLpyRyO5w4H5ED 0FlgCzaqFoq31OiKJ/YOOPQ6affOGD9cfWYp9v1bUQIugyL/gcMWxlBbPJLzFvkBPGdM JrVw== X-Gm-Message-State: AOAM530oHlYPJ0NHuQFyD62EWnFEUKM9F1sG2dAHoybHApfaqGSW1/wf G/Vl+ZpH9u+oUP6kZnl0daeaaYKsZuo8Bdv+44H84cHuACp6tg== X-Received: by 2002:a17:90b:1bcc:: with SMTP id oa12mr468122pjb.93.1644548071677; Thu, 10 Feb 2022 18:54:31 -0800 (PST) MIME-Version: 1.0 References: <20220204145116.00000f5c@Huawei.com> <20220204162756.GA187525@bhelgaas> In-Reply-To: <20220204162756.GA187525@bhelgaas> From: Dan Williams Date: Thu, 10 Feb 2022 18:54:20 -0800 Message-ID: Subject: Re: [PATCH V6 04/10] PCI/DOE: Introduce pci_doe_create_doe_devices To: Bjorn Helgaas Cc: Jonathan Cameron , "Weiny, Ira" , Bjorn Helgaas , Alison Schofield , Vishal Verma , Ben Widawsky , Linux Kernel Mailing List , linux-cxl@vger.kernel.org, Linux PCI Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, 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, Feb 4, 2022 at 8:28 AM Bjorn Helgaas wrote: > > On Fri, Feb 04, 2022 at 02:51:16PM +0000, Jonathan Cameron wrote: > > On Thu, 3 Feb 2022 16:44:37 -0600 > > Bjorn Helgaas wrote: > > > On Mon, Jan 31, 2022 at 11:19:46PM -0800, ira.weiny@intel.com wrote: > > > > > + * pci_doe_create_doe_devices - Create auxiliary DOE devices for all DOE > > > > + * mailboxes found > > > > + * @pci_dev: The PCI device to scan for DOE mailboxes > > > > + * > > > > + * There is no coresponding destroy of these devices. This function associates > > > > + * the DOE auxiliary devices created with the pci_dev passed in. That > > > > + * association is device managed (devm_*) such that the DOE auxiliary device > > > > + * lifetime is always greater than or equal to the lifetime of the pci_dev. > > > > > > This seems backwards. What does it mean if the DOE aux dev > > > lifetime is *greater* than that of the pci_dev? Surely you can't > > > access a PCI DOE Capability if the pci_dev is gone? > > > > I think the description is inaccurate - the end of life is the same > > as that of the PCI driver binding to the pci_dev. It'll get cleared > > up if that is unbound etc. > > I don't know much about devm, but I *think* the devm things get > released by devres_release_all(), which is called by > __device_release_driver() after it calls the bus or driver's .remove() > method (pci_device_remove(), in this case). > > So in this case, I think the aux dev is created after the pci_dev and > released after the PCI driver and the PCI core are done with the > pci_dev. I assume some refcounting prevents the pci_dev from actually > being deallocated until the aux dev is done with it. > > I'm not confident that this is a robust situation. devm is a replacement for hand coding driver ->remove() handlers. Anything devm allocated at ->probe() will be freed in the proper reverse order by the driver core after it calls ->remove(). Ideally for pure devm usage the ->remove() handler can be elided altogether. I'll go read this patch to make sure it follows the expected pattern which is: 1/ Parent device driver performs kmalloc(), device_initialize(), and device_add() of a child device. 2/ Parent registers a devm handler for that child device that will trigger device_unregister() at remove During parent device unregister or unbind the devm action will complete device_unregister() for all children first. That process is independent of the device lifetime that can be arbitrarily extended by 3rd party get_device() or CONFIG_DEBUG_KOBJECT_RELEASE. The device core / kobject hierarchy guarantees that the parent device is pinned until after child-device final put event. I.e. final put_device() on a child also triggers a put_device() on the parent paired with the get_device() taken on the parent at device_add() time.