linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: Haren Myneni <haren@linux.ibm.com>, linuxppc-dev@lists.ozlabs.org
Cc: npiggin@gmail.com, tyreld@linux.ibm.com, brking@linux.ibm.com,
	hbabu@us.ibm.com
Subject: Re: [PATCH v3 3/3] powerpc/pseries/dlpar: Add device tree nodes for DLPAR IO add
Date: Thu, 29 Aug 2024 14:10:17 +1000	[thread overview]
Message-ID: <87plpsdl5i.fsf@mail.lhotse> (raw)
In-Reply-To: <706b666aaf1e515506bb6a4bc1146ee00571a137.camel@linux.ibm.com>

Haren Myneni <haren@linux.ibm.com> writes:
> On Wed, 2024-08-28 at 18:12 +1000, Michael Ellerman wrote:
>> Hi Haren,
>> 
>> One query below about the of_node refcounting.
>> 
>> Haren Myneni <haren@linux.ibm.com> writes:
>> > In the powerpc-pseries specific implementation, the IO hotplug
>> > event is handled in the user space (drmgr tool). For the DLPAR
>> > IO ADD, the corresponding device tree nodes and properties will
>> > be added to the device tree after the device enable. The user
>> > space (drmgr tool) uses configure_connector RTAS call with the
>> > DRC index to retrieve the device nodes and updates the device
>> > tree by writing to /proc/ppc64/ofdt. Under system lockdown,
>> > /dev/mem access to allocate buffers for configure_connector RTAS
>> > call is restricted which means the user space can not issue this
>> > RTAS call and also can not access to /proc/ppc64/ofdt. The
>> > pseries implementation need user interaction to power-on and add
>> > device to the slot during the ADD event handling. So adds
>> > complexity if the complete hotplug ADD event handling moved to
>> > the kernel.
>> > 
>> > To overcome /dev/mem access restriction, this patch extends the
>> > /sys/kernel/dlpar interface and provides ‘dt add index <drc_index>’
>> > to the user space. The drmgr tool uses this interface to update
>> > the device tree whenever the device is added. This interface
>> > retrieves device tree nodes for the corresponding DRC index using
>> > the configure_connector RTAS call and adds new device nodes /
>> > properties to the device tree.
>> > 
>> > Signed-off-by: Scott Cheloha <cheloha@linux.ibm.com>
>> > Signed-off-by: Haren Myneni <haren@linux.ibm.com>
>> > ---
>> >  arch/powerpc/platforms/pseries/dlpar.c | 130
>> > +++++++++++++++++++++++++
>> >  1 file changed, 130 insertions(+)
>> > 
>> > diff --git a/arch/powerpc/platforms/pseries/dlpar.c
>> > b/arch/powerpc/platforms/pseries/dlpar.c
>> > index 1b49b47c4a4f..6f0bc3ddbf85 100644
>> > --- a/arch/powerpc/platforms/pseries/dlpar.c
>> > +++ b/arch/powerpc/platforms/pseries/dlpar.c
>> ...
>> > @@ -330,6 +345,118 @@ int dlpar_unisolate_drc(u32 drc_index)
>> >  	return 0;
>> >  }
>> >  
>> > +static struct device_node *
>> > +get_device_node_with_drc_index(u32 index)
>> > +{
>> > +	struct device_node *np = NULL;
>> > +	u32 node_index;
>> > +	int rc;
>> > +
>> > +	for_each_node_with_property(np, "ibm,my-drc-index") {
>> > +		rc = of_property_read_u32(np, "ibm,my-drc-index",
>> > +					     &node_index);
>> > +		if (rc) {
>> > +			pr_err("%s: %pOF: of_property_read_u32 %s:
>> > %d\n",
>> > +			       __func__, np, "ibm,my-drc-index", rc);
>> > +			of_node_put(np);
>> > +			return NULL;
>> > +		}
>> > +
>> > +		if (index == node_index)
>> > +			break;
>> 
>> Here we return with np's refcount elevated.
>> 
>> > +	}
>> > +
>> > +	return np;
>> > +}
>> ...
>> > +
>> > +static int dlpar_hp_dt_add(u32 index)
>> > +{
>> > +	struct device_node *np, *nodes;
>> > +	struct of_changeset ocs;
>> > +	int rc;
>> > +
>> > +	/*
>> > +	 * Do not add device node(s) if already exists in the
>> > +	 * device tree.
>> > +	 */
>> > +	np = get_device_node_with_drc_index(index);
>> > +	if (np) {
>> > +		pr_err("%s: Adding device node for index (%d), but "
>> > +				"already exists in the device tree\n",
>> > +				__func__, index);
>> > +		rc = -EINVAL;
>> > +		goto out;
>>  
>> In the error case you drop the reference on np (at out).
>> 
>> > +	}
>> > +	np = get_device_node_with_drc_info(index);
>> > 
>> But in the success case np is reassigned, so the refcount is leaked.
>> I think that's unintentional, but I'm not 100% sure.
>
> Michael, 
>
> get_device_node_with_drc_index() holds the refcount only if the node is
> already exists. In this case this refcount is dropped. 
>
> if (np) {
>                 pr_err("%s: Adding device node for index (%d), but "
>                                 "already exists in the device tree\n",
>                                 __func__, index);
>                 rc = -EINVAL;
>                 goto out; --> drop refcount 
>         }

Oh yep. I misread that as if (!np).

> Whereas failure from the get_device_node_with_drc_index() - can not
> find the match node. means we do not hold the refcount and need to add
> the node from get_device_node_with_drc_info()

Right.

> I should add a comment regarding refcount to make it clear. will post
> V4 patch with this comment.

It's probably fine as-is, I just needed to read it properly :)

cheers


  reply	other threads:[~2024-08-29  4:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-22  2:50 [PATCH v3 1/3] powerpc/pseries: Use correct data types from pseries_hp_errorlog struct Haren Myneni
2024-08-22  2:50 ` [PATCH v3 2/3] powerpc/pseries/dlpar: Remove device tree node for DLPAR IO remove Haren Myneni
2024-08-22  2:50 ` [PATCH v3 3/3] powerpc/pseries/dlpar: Add device tree nodes for DLPAR IO add Haren Myneni
2024-08-28  8:12   ` Michael Ellerman
2024-08-29  2:26     ` Haren Myneni
2024-08-29  4:10       ` Michael Ellerman [this message]
2024-09-06 11:52 ` [PATCH v3 1/3] powerpc/pseries: Use correct data types from pseries_hp_errorlog struct Michael Ellerman

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=87plpsdl5i.fsf@mail.lhotse \
    --to=mpe@ellerman.id.au \
    --cc=brking@linux.ibm.com \
    --cc=haren@linux.ibm.com \
    --cc=hbabu@us.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=npiggin@gmail.com \
    --cc=tyreld@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).