Linux CXL
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: Ira Weiny <ira.weiny@intel.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Jonathan Cameron <jonathan.cameron@huawei.com>,
	Alison Schofield <alison.schofield@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>
Cc: <linux-cxl@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Ira Weiny <ira.weiny@intel.com>
Subject: Re: [PATCH RFC 2/2] cxl/memdev: Remove temporary variables from cxl_memdev_state
Date: Tue, 4 Feb 2025 16:15:57 -0800	[thread overview]
Message-ID: <67a2adbdde7c6_2d2c294b5@dwillia2-xfh.jf.intel.com.notmuch> (raw)
In-Reply-To: <67a2a4d2519_2d383a29411@iweiny-mobl.notmuch>

Ira Weiny wrote:
> Dan Williams wrote:
> > Ira Weiny wrote:
> 
> Perhaps this would have been good to add to the commit message.
> 
> <quote>
> 
> The net-net of this change is to make partition set up 2 distinct steps.
> 
> 	1) query the device for total, ram, and pmem partition size information
> 	2) create partitions using that information
> 
> While doing so it avoids storing the total, ram, pmem sizes tuple in favor of a
> stack variable cxl_dev_info.
> 
> </quote>
> 
> [snip]
> 
> > > diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
> > > index 998e1df36db673c47c4e87b957df9c29bf3f291a..44618746ad79b0459501bb3001518f6b7d2ceaba 100644
> > > --- a/drivers/cxl/core/mbox.c
> > > +++ b/drivers/cxl/core/mbox.c
> > > @@ -1068,6 +1068,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_mem_get_event_records, "CXL");
> > >  /**
> > >   * cxl_mem_get_partition_info - Get partition info
> > >   * @mds: The driver data for the operation
> > > + * @dev_info: Device info results
> > >   *
> > >   * Retrieve the current partition info for the device specified.  The active
> > >   * values are the current capacity in bytes.  If not 0, the 'next' values are
> > > @@ -1075,9 +1076,10 @@ EXPORT_SYMBOL_NS_GPL(cxl_mem_get_event_records, "CXL");
> > >   *
> > >   * Return: 0 if no error: or the result of the mailbox command.
> > >   *
> > > - * See CXL @8.2.9.5.2.1 Get Partition Info
> > > + * See CXL 3.1 @8.2.9.9.2.1 Get Partition Info
> > >   */
> > > -static int cxl_mem_get_partition_info(struct cxl_memdev_state *mds)
> > > +static int cxl_mem_get_partition_info(struct cxl_memdev_state *mds,
> > > +				      struct cxl_mem_dev_info *dev_info)
> > 
> > I was hoping this would get further away from new in/out arguments and
> > look at centralizing all partition enumeration into one routine.
> 
> I don't understand?  get partition info is only required if the partition align
> bytes is not 0.  IOW if the device allows for partitions to be changed.
> cxl_mem_get_partition_info() is only called IFF that extra query is required.
> So this does centralize byte information queries into one routine.  It leaves
> creating partitions to the device driver which moves us toward these being
> mailbox only calls...

The crux of the concern for me is less about the role of
cxl_mem_get_partition_info() and more about the introduction of a new 'struct
cxl_mem_dev_info' in/out parameter which is similar in function to
'struct cxl_dpa_info'. If you can find a way to avoid another level of
indirection or otherwise consolidate all these steps into a straight
line routine that does "all the DPA enumeration" things.

> What I did fail to do is change mds to a mailbox.  So add this hunk to this
> call with the corresponding change in the caller.

That's a whole separate conversion that can wait for an omnibus cleanup
patch.

> 
> diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
> index 44618746ad79..873793dab68e 100644
> --- a/drivers/cxl/core/mbox.c
> +++ b/drivers/cxl/core/mbox.c
> @@ -1067,7 +1067,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_mem_get_event_records, "CXL");
>  
>  /**
>   * cxl_mem_get_partition_info - Get partition info
> - * @mds: The driver data for the operation
> + * @mbox: Mailbox to query
>   * @dev_info: Device info results
>   *
>   * Retrieve the current partition info for the device specified.  The active
> @@ -1078,10 +1078,9 @@ EXPORT_SYMBOL_NS_GPL(cxl_mem_get_event_records, "CXL");
>   *
>   * See CXL 3.1 @8.2.9.9.2.1 Get Partition Info
>   */
> -static int cxl_mem_get_partition_info(struct cxl_memdev_state *mds,
> +static int cxl_mem_get_partition_info(struct cxl_mailbox *mbox,
>                                       struct cxl_mem_dev_info *dev_info)
>  {
> -       struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;
>         struct cxl_mbox_get_partition_info pi;
>         struct cxl_mbox_cmd mbox_cmd;
>         int rc;
> @@ -1091,7 +1090,7 @@ static int cxl_mem_get_partition_info(struct cxl_memdev_state *mds,
>                 .size_out = sizeof(pi),
>                 .payload_out = &pi,
>         };
> -       rc = cxl_internal_send_cmd(cxl_mbox, &mbox_cmd);
> +       rc = cxl_internal_send_cmd(mbox, &mbox_cmd);
>         if (rc)
>                 return rc;
>  
> 
> > That
> > was the intent of cxl_mem_dpa_fetch() to capture all generic Memory
> > Expander DPA boundary information.
> 
> The problem with cxl_mem_dpa_fetch() is it mixes in the partition info mailbox
> call after you have already supposedly set up volatile/persistent byte
> settings.
> 
> IOW I don't think it is clean to have the cxl_mem_get_partition_info() call
> hidden away in cxl_mem_dpa_fetch().

If it can save new in/out parameters and hide that thrash from
cxl_pci_probe() outside of "get/set DPA information", then that's the
final organization I would like to see for a cleanup like this.

[..]
> > Why does media_ready affect partition boundary enumeration?
> 
> We want the driver to load without any partitions so that the device can be
> queried.
> 
[..]
> I explored getting rid of media_ready but I think that is a bigger fish to fry
> than I have time for ATM.  And you have ideas there which I need to explore
> more.

It is jarring to see cxl_pci_probe() now handling this detail when
previously cxl_pci_probe() just called a helper that either succeeds or
fails without bothering cxl_pci_probe() with the details.

Push / leave complexity and logic to leaf functions where possible.

> > > +		range_info.size = dev_info.total_bytes;
> > > +		cxl_add_partition(&range_info, 0, dev_info.volatile_bytes,
> > > +				  CXL_PARTMODE_RAM);
> > > +		cxl_add_partition(&range_info, dev_info.volatile_bytes,
> > > +				  dev_info.persistent_bytes, CXL_PARTMODE_PMEM);
> > > +	}
> > 
> > Why remove the cxl_mem_dpa_fetch() helper in favor of open-coding these
> > cxl_add_partition() calls?
> 
> After removing the ugly hidden get partition info call in cxl_mem_dpa_fetch()
> cxl_mem_dpa_fetch boiled down to 2 cxl_add_partition() calls.  That was very
> tiny.
> 
> More importantly this exported a very clean cxl_add_parition() call for any
> driver (ie type 2) to call without creating special structures to pass to the
> cxl core.
> 
> I can put cxl_mem_dpa_fetch() back if you want...  I had changed it to
> cxl_mem_create_partitions() to make it more clear what it was actually doing
> before realizing it was so small it was probably best removed.
> 
> It would be used both here and cxl_test.

The name does not matter to me, although it is unfortunate that this
helper lived for all of 2 commits in the history, it is more about
adding a new potentially redundant in/out object and adding logic to
cxl_pci_probe().

  reply	other threads:[~2025-02-05  0:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-28 18:51 [PATCH RFC 0/2] cxl: Further clean up of memdev state Ira Weiny
2025-01-28 18:51 ` [PATCH RFC 1/2] cxl/memdev: Remove unused partition values Ira Weiny
2025-01-29  8:58   ` Alejandro Lucero Palau
2025-01-29 15:09   ` Davidlohr Bueso
2025-01-29 16:51   ` Dave Jiang
2025-01-30 13:44   ` Jonathan Cameron
2025-02-04 20:59   ` Dan Williams
2025-02-04 23:59   ` Fan Ni
2025-01-28 18:51 ` [PATCH RFC 2/2] cxl/memdev: Remove temporary variables from cxl_memdev_state Ira Weiny
2025-01-29  9:08   ` Alejandro Lucero Palau
2025-01-29 16:32     ` Ira Weiny
2025-01-29 18:17       ` Alejandro Lucero Palau
2025-01-29 21:16         ` Ira Weiny
2025-01-29 16:52   ` Dave Jiang
2025-01-30  0:15   ` Davidlohr Bueso
2025-01-30 13:52   ` Jonathan Cameron
2025-01-30 15:14     ` Ira Weiny
2025-02-04 21:39   ` Dan Williams
2025-02-04 23:37     ` Ira Weiny
2025-02-05  0:15       ` Dan Williams [this message]
2025-02-05  9:01         ` Alejandro Lucero Palau

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=67a2adbdde7c6_2d2c294b5@dwillia2-xfh.jf.intel.com.notmuch \
    --to=dan.j.williams@intel.com \
    --cc=alison.schofield@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=ira.weiny@intel.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vishal.l.verma@intel.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