devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lizhi Hou <lizhi.hou@amd.com>
To: Rob Herring <robh@kernel.org>, <devicetree@vger.kernel.org>,
	"Saravana Kannan" <saravanak@google.com>,
	Kowshik Jois B S <kowsjois@linux.ibm.com>,
	<linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<kvm-ppc@vger.kernel.org>,
	Vaidyanathan Srinivasan <svaidy@linux.ibm.com>,
	Lukas Wunner <lukas@wunner.de>,
	Nicholas Piggin <npiggin@gmail.com>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	Vaibhav Jain <vaibhav@linux.ibm.com>,
	<linuxppc-dev@lists.ozlabs.org>
Subject: Re: [PATCH v2] PCI: Fix crash during pci_dev hot-unplug on pseries KVM guest
Date: Mon, 29 Jul 2024 11:19:03 -0700	[thread overview]
Message-ID: <8dade04c-609b-f69d-0809-4aa8fecd9b87@amd.com> (raw)
In-Reply-To: <vctizrpvsuy4ebrvmub756sxs2bridn6gkav55ehlz5gjlc44b@jyzymbydkut2>


On 7/29/24 09:55, Amit Machhiwal wrote:
> Hi Lizhi,
>
> On 2024/07/29 09:47 AM, Lizhi Hou wrote:
>> Hi Amit
>>
>> On 7/29/24 04:13, Amit Machhiwal wrote:
>>> Hi Lizhi,
>>>
>>> On 2024/07/26 11:45 AM, Lizhi Hou wrote:
>>>> On 7/26/24 10:52, Rob Herring wrote:
>>>>> On Thu, Jul 25, 2024 at 6:06 PM Lizhi Hou <lizhi.hou@amd.com> wrote:
>>>>>> Hi Amit,
>>>>>>
>>>>>>
>>>>>> I try to follow the option which add a OF flag. If Rob is ok with this,
>>>>>> I would suggest to use it instead of V1 patch
>>>>>>
>>>>>> diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
>>>>>> index dda6092e6d3a..a401ed0463d9 100644
>>>>>> --- a/drivers/of/dynamic.c
>>>>>> +++ b/drivers/of/dynamic.c
>>>>>> @@ -382,6 +382,11 @@ void of_node_release(struct kobject *kobj)
>>>>>>                                    __func__, node);
>>>>>>             }
>>>>>>
>>>>>> +       if (of_node_check_flag(node, OF_CREATED_WITH_CSET)) {
>>>>>> +               of_changeset_revert(node->data);
>>>>>> +               of_changeset_destroy(node->data);
>>>>>> +       }
>>>>> What happens if multiple nodes are created in the changeset?
>>>> Ok. multiple nodes will not work.
>>>>>> +
>>>>>>             if (node->child)
>>>>>>                     pr_err("ERROR: %s() unexpected children for %pOF/%s\n",
>>>>>>                             __func__, node->parent, node->full_name);
>>>>>> @@ -507,6 +512,7 @@ struct device_node *of_changeset_create_node(struct
>>>>>> of_changeset *ocs,
>>>>>>             np = __of_node_dup(NULL, full_name);
>>>>>>             if (!np)
>>>>>>                     return NULL;
>>>>>> +       of_node_set_flag(np, OF_CREATED_WITH_CSET);
>>>>> This should be set where the data ptr is set.
>>>> Ok. It sounds the fix could be simplified to 3 lines change.
>>> Thanks for the patch. The hot-plug and hot-unplug of PCI device seem to work
>>> fine as expected. I see this patch would attempt to remove only the nodes which
>>> were created in `of_pci_make_dev_node()` with the help of the newly introduced
>>> flag, which looks good to me.
>>>
>>> Also, since a call to `of_pci_make_dev_node()` from `pci_bus_add_device()`, that
>>> creates devices nodes only for bridge devices, is conditional on
>>> `pci_is_bridge()`, it only makes sense to retain the logical symmetry and call
>>> `of_pci_remove_node()` conditionally on `pci_is_bridge()` as well in
>>> `pci_stop_dev()`. Hence, I would like to propose the below change along with the
>>> above patch:
>>>
>>> diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
>>> index 910387e5bdbf..c6394bf562cd 100644
>>> --- a/drivers/pci/remove.c
>>> +++ b/drivers/pci/remove.c
>>> @@ -23,7 +23,8 @@ static void pci_stop_dev(struct pci_dev *dev)
>>>                   device_release_driver(&dev->dev);
>>>                   pci_proc_detach_device(dev);
>>>                   pci_remove_sysfs_dev_files(dev);
>>> -               of_pci_remove_node(dev);
>>> +               if (pci_is_bridge(dev))
>>> +                       of_pci_remove_node(dev);
>>>                   pci_dev_assign_added(dev, false);
>>>           }
>>>
>>> Please let me know of your thoughts on this and based on that I can spin the v3
>>> of this patch.
>> As I mentioned, there are endpoints in pci quirks (pci/quirks.c) will also
>> create nodes by of_pci_make_dev_node(). So please remove above two lines.
> Sorry if I'm misinterpreting something here but as I mentioned,
> `of_pci_make_dev_node()` is called only for bridge devices with check performed
> via `pci_is_bridge()`, could you please elaborate more on why the same check
> can't be put while removing the node via `of_pci_remove_node()`?

For devices added in quirks, of_pci_make_dev_node() will be called 
through pci_fixup_device().


Lizhi

>
> Thanks,
> Amit
>
>> Thanks,
>>
>> Lizhi
>>
>>> In addition to this, can this patch be taken as part of 6.11 as a bug fix?
>>>
>>> Thanks,
>>> Amit
>>>
>>>> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
>>>> index 51e3dd0ea5ab..0b3ba1e1b18c 100644
>>>> --- a/drivers/pci/of.c
>>>> +++ b/drivers/pci/of.c
>>>> @@ -613,7 +613,7 @@ void of_pci_remove_node(struct pci_dev *pdev)
>>>>           struct device_node *np;
>>>>
>>>>           np = pci_device_to_OF_node(pdev);
>>>> -       if (!np || !of_node_check_flag(np, OF_DYNAMIC))
>>>> +       if (!np || !of_node_check_flag(np, OF_CREATED_WITH_CSET))
>>>>                   return;
>>>>           pdev->dev.of_node = NULL;
>>>>
>>>> @@ -672,6 +672,7 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
>>>>           if (ret)
>>>>                   goto out_free_node;
>>>>
>>>> +       of_node_set_flag(np, OF_CREATED_WITH_CSET);
>>>>           np->data = cset;
>>>>           pdev->dev.of_node = np;
>>>>           kfree(name);
>>>> diff --git a/include/linux/of.h b/include/linux/of.h
>>>> index a0bedd038a05..a46317f6626e 100644
>>>> --- a/include/linux/of.h
>>>> +++ b/include/linux/of.h
>>>> @@ -153,6 +153,7 @@ extern struct device_node *of_stdout;
>>>>    #define OF_POPULATED_BUS       4 /* platform bus created for children */
>>>>    #define OF_OVERLAY             5 /* allocated for an overlay */
>>>>    #define OF_OVERLAY_FREE_CSET   6 /* in overlay cset being freed */
>>>> +#define OF_CREATED_WITH_CSET    7 /* created by of_changeset_create_node */
>>>>
>>>>    #define OF_BAD_ADDR    ((u64)-1)
>>>>
>>>>
>>>> Lizhi
>>>>
>>>>> Rob

  reply	other threads:[~2024-07-29 18:19 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-15  8:07 [PATCH v2] PCI: Fix crash during pci_dev hot-unplug on pseries KVM guest Amit Machhiwal
2024-07-15 16:20 ` Lizhi Hou
2024-07-15 17:23   ` Bjorn Helgaas
2024-07-15 20:35     ` Lizhi Hou
2024-07-15 18:55 ` Rob Herring
2024-07-15 20:52   ` Lizhi Hou
2024-07-23 16:21     ` Rob Herring
2024-07-23 18:21       ` Lizhi Hou
2024-07-23 19:54         ` Rob Herring
2024-07-23 21:08           ` Lizhi Hou
2024-07-25 17:45             ` Amit Machhiwal
2024-07-25 20:55               ` Bjorn Helgaas
2024-07-26  5:49                 ` Amit Machhiwal
2024-07-26 12:49                   ` Michael Ellerman
2024-07-25 23:06               ` Lizhi Hou
2024-07-26 17:52                 ` Rob Herring
2024-07-26 18:45                   ` Lizhi Hou
2024-07-29 11:13                     ` Amit Machhiwal
2024-07-29 16:47                       ` Lizhi Hou
2024-07-29 16:55                         ` Amit Machhiwal
2024-07-29 18:19                           ` Lizhi Hou [this message]
2024-07-26 11:37               ` Rob Herring
2024-07-29 13:27                 ` Stefan Bader
2024-08-02 16:55                   ` Amit Machhiwal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8dade04c-609b-f69d-0809-4aa8fecd9b87@amd.com \
    --to=lizhi.hou@amd.com \
    --cc=bhelgaas@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=kowsjois@linux.ibm.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=lukas@wunner.de \
    --cc=npiggin@gmail.com \
    --cc=robh@kernel.org \
    --cc=saravanak@google.com \
    --cc=svaidy@linux.ibm.com \
    --cc=vaibhav@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).