From: Dave Jiang <dave.jiang@intel.com>
To: Robert Richter <rrichter@amd.com>
Cc: <linux-cxl@vger.kernel.org>,
Dan Williams <dan.j.williams@intel.com>,
"Ira Weiny" <ira.weiny@intel.com>, <vishal.l.verma@intel.com>,
<alison.schofield@intel.com>, <Jonathan.Cameron@huawei.com>,
<dave@stgolabs.net>
Subject: Re: [PATCH v6 2/5] cxl: Convert find_cxl_root() to return a 'struct cxl_root *'
Date: Fri, 5 Jan 2024 16:34:01 -0700 [thread overview]
Message-ID: <7148064c-c284-4623-93c8-faa998f1266d@intel.com> (raw)
In-Reply-To: <ZZiH7QGDLD8DlRNu@rric.localdomain>
On 1/5/24 15:51, Robert Richter wrote:
> See comments below.
>
> On 05.01.24 15:07:40, Dave Jiang wrote:
>> Commit 790815902ec6 ("cxl: Add support for _DSM Function for retrieving QTG ID")
>> introduced 'struct cxl_root', however all usages have been worked
>> indirectly through cxl_port. Refactor code such as find_cxl_root()
>> function to use 'struct cxl_root' directly.
>>
>> Suggested-by: Dan Williams <dan.j.williams@intel.com>
>> Reviewed-by: Ira Weiny <ira.weiny@intel.com>
>> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
>> ---
>> v6:
>> - Revert code that broke device_for_each_child() (Dan)
>> - Leave put_device() calls in this patch. (Dan)
>> v5:
>> - Squash in v4 3/6 to update the qos_class to cxl_root. (Dan)
>> - Moved the introduction of __free() for cxl_root_put from v4 1/6 to
>> here. (Dan)
>> v4:
>> - Adjust ordering of patches to move this to 2nd place. (Dan)
>> ---
>> drivers/cxl/acpi.c | 6 ++----
>> drivers/cxl/core/cdat.c | 17 ++++++++++-------
>> drivers/cxl/core/pmem.c | 6 ++++--
>> drivers/cxl/core/port.c | 4 ++--
>> drivers/cxl/cxl.h | 14 +++++++-------
>> drivers/cxl/port.c | 4 +++-
>> 6 files changed, 28 insertions(+), 23 deletions(-)
>>
>> diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c
>> index afc712264d1c..dcf2b39e1048 100644
>> --- a/drivers/cxl/acpi.c
>> +++ b/drivers/cxl/acpi.c
>> @@ -295,14 +295,12 @@ cxl_acpi_evaluate_qtg_dsm(acpi_handle handle, struct access_coordinate *coord,
>> return rc;
>> }
>>
>> -static int cxl_acpi_qos_class(struct cxl_port *root_port,
>> +static int cxl_acpi_qos_class(struct cxl_root *cxl_root,
>> struct access_coordinate *coord, int entries,
>> int *qos_class)
>> {
>> + struct device *dev = cxl_root->port.uport_dev;
>> acpi_handle handle;
>> - struct device *dev;
>> -
>> - dev = root_port->uport_dev;
>>
>> if (!dev_is_platform(dev))
>> return -ENODEV;
>> diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c
>> index cd84d87f597a..0df5379cf02f 100644
>> --- a/drivers/cxl/core/cdat.c
>> +++ b/drivers/cxl/core/cdat.c
>> @@ -162,7 +162,6 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
>> struct xarray *dsmas_xa)
>> {
>> struct access_coordinate c;
>> - struct cxl_port *root_port;
>> struct cxl_root *cxl_root;
>> struct dsmas_entry *dent;
>> int valid_entries = 0;
>> @@ -175,8 +174,7 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
>> return rc;
>> }
>>
>> - root_port = find_cxl_root(port);
>> - cxl_root = to_cxl_root(root_port);
>> + cxl_root = find_cxl_root(port);
>> if (!cxl_root->ops || !cxl_root->ops->qos_class)
>> return -EOPNOTSUPP;
>>
>> @@ -193,7 +191,8 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
>> dent->coord.write_bandwidth);
>>
>> dent->entries = 1;
>> - rc = cxl_root->ops->qos_class(root_port, &dent->coord, 1, &qos_class);
>> + rc = cxl_root->ops->qos_class(cxl_root, &dent->coord, 1,
>> + &qos_class);
>> if (rc != 1)
>> continue;
>>
>> @@ -349,15 +348,19 @@ static int cxl_qos_class_verify(struct cxl_memdev *cxlmd)
>> {
>> struct cxl_dev_state *cxlds = cxlmd->cxlds;
>> struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
>> - struct cxl_port *root_port __free(put_device) = NULL;
>> LIST_HEAD(__discard);
>> struct list_head *discard __free(dpa_perf) = &__discard;
>> + struct cxl_port *root_port;
>> int rc;
>>
>> - root_port = find_cxl_root(cxlmd->endpoint);
>> - if (!root_port)
>> + struct cxl_root *cxl_root __free(put_cxl_root) =
>> + find_cxl_root(cxlmd->endpoint);
>
> That's the drawback that lines get very long. Not sure if that was
> discussed before, maybe just assign NULL in the definition and then
> have the first assignment right after?
>
> Should be moved to the definitions above without a newline.
>
>> +
>> + if (!cxl_root)
>> return -ENODEV;
>>
>> + root_port = &cxl_root->port;
>> +
>> /* Check that the QTG IDs are all sane between end device and root decoders */
>> cxl_qos_match(root_port, &mds->ram_perf_list, discard);
>> cxl_qos_match(root_port, &mds->pmem_perf_list, discard);
>
> It looks like cxl_qos_match() consumes a root port, so we could pass
> cxl_root here directly and get rid of root_port.
>
>> diff --git a/drivers/cxl/core/pmem.c b/drivers/cxl/core/pmem.c
>> index fc94f5240327..da92a901b9e8 100644
>> --- a/drivers/cxl/core/pmem.c
>> +++ b/drivers/cxl/core/pmem.c
>> @@ -64,12 +64,14 @@ static int match_nvdimm_bridge(struct device *dev, void *data)
>>
>> struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_memdev *cxlmd)
>> {
>> - struct cxl_port *port = find_cxl_root(cxlmd->endpoint);
>> + struct cxl_root *cxl_root = find_cxl_root(cxlmd->endpoint);
>> + struct cxl_port *port;
>> struct device *dev;
>>
>> - if (!port)
>> + if (!cxl_root)
>> return NULL;
>>
>> + port = &cxl_root->port;
>> dev = device_find_child(&port->dev, NULL, match_nvdimm_bridge);
>
> No need for port variable here.
>
>> put_device(&port->dev);
>>
>> diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
>> index 64f30d5fe1f6..63a4e3c2baed 100644
>> --- a/drivers/cxl/core/port.c
>> +++ b/drivers/cxl/core/port.c
>> @@ -972,7 +972,7 @@ static bool dev_is_cxl_root_child(struct device *dev)
>> return false;
>> }
>>
>> -struct cxl_port *find_cxl_root(struct cxl_port *port)
>> +struct cxl_root *find_cxl_root(struct cxl_port *port)
>> {
>> struct cxl_port *iter = port;
>>
>> @@ -982,7 +982,7 @@ struct cxl_port *find_cxl_root(struct cxl_port *port)
>> if (!iter)
>> return NULL;
>> get_device(&iter->dev);
>> - return iter;
>> + return to_cxl_root(iter);
>
> I guess this is the last user of to_cxl_root() now so we can remove
> the macro entirely. Unlikely we will ever need it again and a
> container_of() call is also fairly easy.
Looks like there are two other locations using it still:
$ git grep -n "to_cxl_root("
core/port.c:546: kfree(to_cxl_root(port));
core/port.c:914: cxl_root = to_cxl_root(port);
core/port.c:985: return to_cxl_root(iter);
cxl.h:632:to_cxl_root(const struct cxl_port *port)
So we can keep this macro for now.
DJ
>
>> }
>> EXPORT_SYMBOL_NS_GPL(find_cxl_root, CXL);
>>
>> diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
>> index df3db3e43913..3a5004aab97a 100644
>> --- a/drivers/cxl/cxl.h
>> +++ b/drivers/cxl/cxl.h
>> @@ -617,12 +617,6 @@ struct cxl_port {
>> long pci_latency;
>> };
>>
>> -struct cxl_root_ops {
>> - int (*qos_class)(struct cxl_port *root_port,
>> - struct access_coordinate *coord, int entries,
>> - int *qos_class);
>> -};
>> -
>> /**
>> * struct cxl_root - logical collection of root cxl_port items
>> *
>> @@ -640,6 +634,12 @@ to_cxl_root(const struct cxl_port *port)
>> return container_of(port, struct cxl_root, port);
>> }
>>
>> +struct cxl_root_ops {
>> + int (*qos_class)(struct cxl_root *cxl_root,
>> + struct access_coordinate *coord, int entries,
>> + int *qos_class);
>> +};
>> +
>
> Any intention to move code here in addition?
>
>> static inline struct cxl_dport *
>> cxl_find_dport_by_dev(struct cxl_port *port, const struct device *dport_dev)
>> {
>> @@ -734,7 +734,7 @@ struct cxl_port *devm_cxl_add_port(struct device *host,
>> struct cxl_dport *parent_dport);
>> struct cxl_root *devm_cxl_add_root(struct device *host,
>> const struct cxl_root_ops *ops);
>> -struct cxl_port *find_cxl_root(struct cxl_port *port);
>> +struct cxl_root *find_cxl_root(struct cxl_port *port);
>> void put_cxl_root(struct cxl_root *cxl_root);
>> DEFINE_FREE(put_cxl_root, struct cxl_root *, if (_T) put_cxl_root(_T))
>>
>> diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c
>> index da3c3a08bd62..4f3a08fdc9e9 100644
>> --- a/drivers/cxl/port.c
>> +++ b/drivers/cxl/port.c
>> @@ -94,6 +94,7 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)
>> struct cxl_endpoint_dvsec_info info = { .port = port };
>> struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport_dev);
>> struct cxl_dev_state *cxlds = cxlmd->cxlds;
>> + struct cxl_root *cxl_root;
>> struct cxl_hdm *cxlhdm;
>> struct cxl_port *root;
>> int rc;
>> @@ -130,7 +131,8 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)
>> * This can't fail in practice as CXL root exit unregisters all
>> * descendant ports and that in turn synchronizes with cxl_port_probe()
>> */
>> - root = find_cxl_root(port);
>> + cxl_root = find_cxl_root(port);
>> + root = &cxl_root->port;
>
> Same here, no need for the root var.
>
> -Robert
>
>
>>
>> /*
>> * Now that all endpoint decoders are successfully enumerated, try to
>>
>>
next prev parent reply other threads:[~2024-01-05 23:34 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-05 22:07 [PATCH v6 0/5] cxl: find_cxl_root() related cleanups Dave Jiang
2024-01-05 22:07 ` [PATCH v6 1/5] cxl: Introduce put_cxl_root() helper Dave Jiang
2024-01-05 22:14 ` Robert Richter
2024-01-05 22:07 ` [PATCH v6 2/5] cxl: Convert find_cxl_root() to return a 'struct cxl_root *' Dave Jiang
2024-01-05 22:51 ` Robert Richter
2024-01-05 23:08 ` Dave Jiang
2024-01-05 23:34 ` Dave Jiang [this message]
2024-01-08 20:43 ` Dan Williams
2024-01-08 22:30 ` Robert Richter
2024-01-05 22:07 ` [PATCH v6 3/5] cxl: Fix device reference leak in cxl_port_perf_data_calculate() Dave Jiang
2024-01-05 22:56 ` Robert Richter
2024-01-05 23:59 ` Dave Jiang
2024-01-08 21:03 ` Dan Williams
2024-01-05 22:07 ` [PATCH v6 4/5] cxl: Refactor to use __free() for cxl_root allocation in cxl_find_nvdimm_bridge() Dave Jiang
2024-01-05 23:06 ` Robert Richter
2024-01-05 22:07 ` [PATCH v6 5/5] cxl: Refactor to use __free() for cxl_root allocation in cxl_endpoint_port_probe() Dave Jiang
2024-01-05 23:09 ` Robert Richter
2024-01-05 22:35 ` [PATCH v6 0/5] cxl: find_cxl_root() related cleanups Dan Williams
2024-01-08 11:53 ` Jonathan Cameron
2024-01-08 21:05 ` Dan Williams
2024-01-09 1:07 ` [PATCH 1/3] cxl: Remove cxl_root check after find_cxl_root Dave Jiang
2024-01-09 1:16 ` Dan Williams
2024-01-09 1:07 ` [PATCH 2/3] cxl: Cleanup unnecessary uages of cxl_port local vars from cxl_root Dave Jiang
2024-01-09 1:17 ` Dan Williams
2024-01-09 15:29 ` Jonathan Cameron
2024-01-09 15:38 ` Dave Jiang
2024-01-09 1:07 ` [PATCH 3/3] cxl: Make calling of find_cxl_root() declaration uniform Dave Jiang
2024-01-09 1:37 ` Dan Williams
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=7148064c-c284-4623-93c8-faa998f1266d@intel.com \
--to=dave.jiang@intel.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave@stgolabs.net \
--cc=ira.weiny@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=rrichter@amd.com \
--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