* [PATCH v2 0/3] Fix using wrong GPF DVSEC location issue
@ 2025-03-23 9:31 Li Ming
2025-03-23 9:31 ` [PATCH v2 1/3] cxl/core: Fix caching dport GPF DVSEC issue Li Ming
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Li Ming @ 2025-03-23 9:31 UTC (permalink / raw)
To: dave, jonathan.cameron, dave.jiang, alison.schofield,
vishal.l.verma, ira.weiny, dan.j.williams
Cc: linux-cxl, linux-kernel, Li Ming
During review all new patches in branch cxl/next. I noticed there may be
a problem in below commit.
commit a52b6a2c1c99 ("cxl/pci: Support Global Persistent Flush (GPF)")
There is a new field gpf_dvsec in struct cxl_port to cache GPF DVSEC for
Port(DVSEC ID 04h) location. When the first EP attaching to a cxl port,
it will trigger locating GPF DVSEC on the cxl dport which the first EP
is under, then the location is cached in port->gpf_dvsec. So if another
EP under another dport is attaching, it will reuse the value of
port->gpf_dvsec as GPF DVSEC location for this another dport. The
problem is the cached location may be a wrong location for other dports
of the port.
Per Table 8-2 in CXL r3.2 section 8.1.1 and CXL r3.2 section 8.1.6, Each
CXL Downstream switch ports and CXL root ports have their own GPF DVSEC
for Port(DVSEC ID 04h). So my understanding is that CXL subsystem should
locate GPF DVSEC for Port for each dport rather than using the cached
location in CXL port.
base-commit: 3b5d43245f0a56390baaa670e1b6d898772266b3 cxl/next
v2:
- Drop RFC tag.
- Add Fixes tag to patch #1.
- Pickup reviews.
- Add tested by Davidlohr.
- Adjust the changelog of patch #2.(Davidlohr)
- Fix typo issue in patch #2.(Davidlohr)
Li Ming (3):
cxl/core: Fix caching dport GPF DVSEC issue
cxl/pci: Update Port GPF timeout only when the first EP attaching
cxl/pci: Drop the parameter is_port of cxl_gpf_get_dvsec()
drivers/cxl/core/core.h | 2 +-
drivers/cxl/core/pci.c | 30 +++++++++++++++++-------------
drivers/cxl/core/port.c | 2 +-
drivers/cxl/cxl.h | 6 +++---
drivers/cxl/pmem.c | 2 +-
5 files changed, 23 insertions(+), 19 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] cxl/core: Fix caching dport GPF DVSEC issue
2025-03-23 9:31 [PATCH v2 0/3] Fix using wrong GPF DVSEC location issue Li Ming
@ 2025-03-23 9:31 ` Li Ming
2025-03-23 9:31 ` [PATCH v2 2/3] cxl/pci: Update Port GPF timeout only when the first EP attaching Li Ming
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Li Ming @ 2025-03-23 9:31 UTC (permalink / raw)
To: dave, jonathan.cameron, dave.jiang, alison.schofield,
vishal.l.verma, ira.weiny, dan.j.williams
Cc: linux-cxl, linux-kernel, Li Ming, Jonathan Cameron
Per Table 8-2 in CXL r3.2 section 8.1.1 and CXL r3.2 section 8.1.6, only
CXL Downstream switch ports and CXL root ports have GPF DVSEC for CXL
Port(DVSEC ID 04h).
CXL subsystem has a gpf_dvsec in struct cxl_port which is used to cache
the offset of a GPF DVSEC in PCIe configuration space. It will be
updated during the first EP attaching to the cxl_port, so the gpf_dvsec
can only cache the GPF DVSEC offset of the dport which the first EP is
under. Will not have chance to update it during other EPs attaching.
That means CXL subsystem will use the same GPF DVSEC offset for all
dports under the port, it will be a problem if the GPF DVSEC offset
cached in cxl_port is not the right offset for a dport.
Moving gpf_dvsec from struct cxl_port to struct cxl_dport, make every
cxl dport has their own GPF DVSEC offset caching, and each cxl dport
uses its own GPF DVSEC offset for GPF DVSEC accessing.
Fixes: a52b6a2c1c99 ("cxl/pci: Support Global Persistent Flush (GPF)")
Signed-off-by: Li Ming <ming.li@zohomail.com>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Tested-by: Davidlohr Bueso <dave@stgolabs.net>
---
drivers/cxl/core/core.h | 2 +-
drivers/cxl/core/pci.c | 16 ++++++++--------
drivers/cxl/core/port.c | 2 +-
drivers/cxl/cxl.h | 4 ++--
4 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h
index 15699299dc11..17b692eb3257 100644
--- a/drivers/cxl/core/core.h
+++ b/drivers/cxl/core/core.h
@@ -119,7 +119,7 @@ int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,
int cxl_ras_init(void);
void cxl_ras_exit(void);
-int cxl_gpf_port_setup(struct device *dport_dev, struct cxl_port *port);
+int cxl_gpf_port_setup(struct cxl_dport *dport);
int cxl_acpi_get_extended_linear_cache_size(struct resource *backing_res,
int nid, resource_size_t *size);
diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c
index 96fecb799cbc..aab0a505d527 100644
--- a/drivers/cxl/core/pci.c
+++ b/drivers/cxl/core/pci.c
@@ -1128,26 +1128,26 @@ static int update_gpf_port_dvsec(struct pci_dev *pdev, int dvsec, int phase)
return rc;
}
-int cxl_gpf_port_setup(struct device *dport_dev, struct cxl_port *port)
+int cxl_gpf_port_setup(struct cxl_dport *dport)
{
struct pci_dev *pdev;
- if (!port)
+ if (!dport)
return -EINVAL;
- if (!port->gpf_dvsec) {
+ if (!dport->gpf_dvsec) {
int dvsec;
- dvsec = cxl_gpf_get_dvsec(dport_dev, true);
+ dvsec = cxl_gpf_get_dvsec(dport->dport_dev, true);
if (!dvsec)
return -EINVAL;
- port->gpf_dvsec = dvsec;
+ dport->gpf_dvsec = dvsec;
}
- pdev = to_pci_dev(dport_dev);
- update_gpf_port_dvsec(pdev, port->gpf_dvsec, 1);
- update_gpf_port_dvsec(pdev, port->gpf_dvsec, 2);
+ pdev = to_pci_dev(dport->dport_dev);
+ update_gpf_port_dvsec(pdev, dport->gpf_dvsec, 1);
+ update_gpf_port_dvsec(pdev, dport->gpf_dvsec, 2);
return 0;
}
diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
index 0fd6646c1a2e..726bd4a7de27 100644
--- a/drivers/cxl/core/port.c
+++ b/drivers/cxl/core/port.c
@@ -1678,7 +1678,7 @@ int devm_cxl_enumerate_ports(struct cxl_memdev *cxlmd)
if (rc && rc != -EBUSY)
return rc;
- cxl_gpf_port_setup(dport_dev, port);
+ cxl_gpf_port_setup(dport);
/* Any more ports to add between this one and the root? */
if (!dev_is_cxl_root_child(&port->dev))
diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
index be8a7dc77719..2d81ccd83916 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -592,7 +592,6 @@ struct cxl_dax_region {
* @cdat: Cached CDAT data
* @cdat_available: Should a CDAT attribute be available in sysfs
* @pci_latency: Upstream latency in picoseconds
- * @gpf_dvsec: Cached GPF port DVSEC
*/
struct cxl_port {
struct device dev;
@@ -616,7 +615,6 @@ struct cxl_port {
} cdat;
bool cdat_available;
long pci_latency;
- int gpf_dvsec;
};
/**
@@ -664,6 +662,7 @@ struct cxl_rcrb_info {
* @regs: Dport parsed register blocks
* @coord: access coordinates (bandwidth and latency performance attributes)
* @link_latency: calculated PCIe downstream latency
+ * @gpf_dvsec: Cached GPF port DVSEC
*/
struct cxl_dport {
struct device *dport_dev;
@@ -675,6 +674,7 @@ struct cxl_dport {
struct cxl_regs regs;
struct access_coordinate coord[ACCESS_COORDINATE_MAX];
long link_latency;
+ int gpf_dvsec;
};
/**
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] cxl/pci: Update Port GPF timeout only when the first EP attaching
2025-03-23 9:31 [PATCH v2 0/3] Fix using wrong GPF DVSEC location issue Li Ming
2025-03-23 9:31 ` [PATCH v2 1/3] cxl/core: Fix caching dport GPF DVSEC issue Li Ming
@ 2025-03-23 9:31 ` Li Ming
2025-03-23 9:31 ` [PATCH v2 3/3] cxl/pci: Drop the parameter is_port of cxl_gpf_get_dvsec() Li Ming
2025-04-09 20:32 ` [PATCH v2 0/3] Fix using wrong GPF DVSEC location issue Dave Jiang
3 siblings, 0 replies; 5+ messages in thread
From: Li Ming @ 2025-03-23 9:31 UTC (permalink / raw)
To: dave, jonathan.cameron, dave.jiang, alison.schofield,
vishal.l.verma, ira.weiny, dan.j.williams
Cc: linux-cxl, linux-kernel, Li Ming, Jonathan Cameron
update_gpf_port_dvsec() is used to update GPF Phase timeout, if a CXL
switch is under a CXL root port, update_gpf_port_dvsec() will be invoked
on the CXL root port when each cxl memory device under the CXL switch is
attaching. It is enough to be invoked once, others are redundant.
When the first EP attaching, it always triggers its ancestor dports to
locate their own Port GPF DVSEC. The change is that invoking
update_gpf_port_dvsec() on these ancestor dports after ancestor dport
locating a Port GPF DVSEC. It guarantees that update_gpf_port_dvsec() is
invoked on a dport only happens during the first EP attaching.
Signed-off-by: Li Ming <ming.li@zohomail.com>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Tested-by: Davidlohr Bueso <dave@stgolabs.net>
---
drivers/cxl/core/pci.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c
index aab0a505d527..edbdaf1681e8 100644
--- a/drivers/cxl/core/pci.c
+++ b/drivers/cxl/core/pci.c
@@ -1130,12 +1130,11 @@ static int update_gpf_port_dvsec(struct pci_dev *pdev, int dvsec, int phase)
int cxl_gpf_port_setup(struct cxl_dport *dport)
{
- struct pci_dev *pdev;
-
if (!dport)
return -EINVAL;
if (!dport->gpf_dvsec) {
+ struct pci_dev *pdev;
int dvsec;
dvsec = cxl_gpf_get_dvsec(dport->dport_dev, true);
@@ -1143,11 +1142,10 @@ int cxl_gpf_port_setup(struct cxl_dport *dport)
return -EINVAL;
dport->gpf_dvsec = dvsec;
+ pdev = to_pci_dev(dport->dport_dev);
+ update_gpf_port_dvsec(pdev, dport->gpf_dvsec, 1);
+ update_gpf_port_dvsec(pdev, dport->gpf_dvsec, 2);
}
- pdev = to_pci_dev(dport->dport_dev);
- update_gpf_port_dvsec(pdev, dport->gpf_dvsec, 1);
- update_gpf_port_dvsec(pdev, dport->gpf_dvsec, 2);
-
return 0;
}
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] cxl/pci: Drop the parameter is_port of cxl_gpf_get_dvsec()
2025-03-23 9:31 [PATCH v2 0/3] Fix using wrong GPF DVSEC location issue Li Ming
2025-03-23 9:31 ` [PATCH v2 1/3] cxl/core: Fix caching dport GPF DVSEC issue Li Ming
2025-03-23 9:31 ` [PATCH v2 2/3] cxl/pci: Update Port GPF timeout only when the first EP attaching Li Ming
@ 2025-03-23 9:31 ` Li Ming
2025-04-09 20:32 ` [PATCH v2 0/3] Fix using wrong GPF DVSEC location issue Dave Jiang
3 siblings, 0 replies; 5+ messages in thread
From: Li Ming @ 2025-03-23 9:31 UTC (permalink / raw)
To: dave, jonathan.cameron, dave.jiang, alison.schofield,
vishal.l.verma, ira.weiny, dan.j.williams
Cc: linux-cxl, linux-kernel, Li Ming, Jonathan Cameron
The first parameter of cxl_gpf_get_dvsec() is a struct device, can be
used to distinguish if the device is a cxl dport or a cxl pci device by
checking the PCIe type of it, so the parameter is_port is unnecessary
to cxl_gpf_get_dvsec(), using parameter struct device is enough.
Signed-off-by: Li Ming <ming.li@zohomail.com>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Tested-by: Davidlohr Bueso <dave@stgolabs.net>
---
drivers/cxl/core/pci.c | 12 +++++++++---
drivers/cxl/cxl.h | 2 +-
drivers/cxl/pmem.c | 2 +-
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c
index edbdaf1681e8..3b80e9a76ba8 100644
--- a/drivers/cxl/core/pci.c
+++ b/drivers/cxl/core/pci.c
@@ -1072,14 +1072,20 @@ int cxl_pci_get_bandwidth(struct pci_dev *pdev, struct access_coordinate *c)
#define GPF_TIMEOUT_BASE_MAX 2
#define GPF_TIMEOUT_SCALE_MAX 7 /* 10 seconds */
-u16 cxl_gpf_get_dvsec(struct device *dev, bool is_port)
+u16 cxl_gpf_get_dvsec(struct device *dev)
{
+ struct pci_dev *pdev;
+ bool is_port = true;
u16 dvsec;
if (!dev_is_pci(dev))
return 0;
- dvsec = pci_find_dvsec_capability(to_pci_dev(dev), PCI_VENDOR_ID_CXL,
+ pdev = to_pci_dev(dev);
+ if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ENDPOINT)
+ is_port = false;
+
+ dvsec = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_CXL,
is_port ? CXL_DVSEC_PORT_GPF : CXL_DVSEC_DEVICE_GPF);
if (!dvsec)
dev_warn(dev, "%s GPF DVSEC not present\n",
@@ -1137,7 +1143,7 @@ int cxl_gpf_port_setup(struct cxl_dport *dport)
struct pci_dev *pdev;
int dvsec;
- dvsec = cxl_gpf_get_dvsec(dport->dport_dev, true);
+ dvsec = cxl_gpf_get_dvsec(dport->dport_dev);
if (!dvsec)
return -EINVAL;
diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
index 2d81ccd83916..a9ab46eb0610 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -910,6 +910,6 @@ bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port);
#define __mock static
#endif
-u16 cxl_gpf_get_dvsec(struct device *dev, bool is_port);
+u16 cxl_gpf_get_dvsec(struct device *dev);
#endif /* __CXL_H__ */
diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c
index d061fe3d2b86..e197883690ef 100644
--- a/drivers/cxl/pmem.c
+++ b/drivers/cxl/pmem.c
@@ -108,7 +108,7 @@ static void cxl_nvdimm_arm_dirty_shutdown_tracking(struct cxl_nvdimm *cxl_nvd)
return;
}
- if (!cxl_gpf_get_dvsec(cxlds->dev, false))
+ if (!cxl_gpf_get_dvsec(cxlds->dev))
return;
if (cxl_get_dirty_count(mds, &count)) {
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/3] Fix using wrong GPF DVSEC location issue
2025-03-23 9:31 [PATCH v2 0/3] Fix using wrong GPF DVSEC location issue Li Ming
` (2 preceding siblings ...)
2025-03-23 9:31 ` [PATCH v2 3/3] cxl/pci: Drop the parameter is_port of cxl_gpf_get_dvsec() Li Ming
@ 2025-04-09 20:32 ` Dave Jiang
3 siblings, 0 replies; 5+ messages in thread
From: Dave Jiang @ 2025-04-09 20:32 UTC (permalink / raw)
To: Li Ming, dave, jonathan.cameron, alison.schofield,
vishal.l.verma, ira.weiny, dan.j.williams
Cc: linux-cxl, linux-kernel
On 3/23/25 2:31 AM, Li Ming wrote:
> During review all new patches in branch cxl/next. I noticed there may be
> a problem in below commit.
>
> commit a52b6a2c1c99 ("cxl/pci: Support Global Persistent Flush (GPF)")
>
> There is a new field gpf_dvsec in struct cxl_port to cache GPF DVSEC for
> Port(DVSEC ID 04h) location. When the first EP attaching to a cxl port,
> it will trigger locating GPF DVSEC on the cxl dport which the first EP
> is under, then the location is cached in port->gpf_dvsec. So if another
> EP under another dport is attaching, it will reuse the value of
> port->gpf_dvsec as GPF DVSEC location for this another dport. The
> problem is the cached location may be a wrong location for other dports
> of the port.
>
> Per Table 8-2 in CXL r3.2 section 8.1.1 and CXL r3.2 section 8.1.6, Each
> CXL Downstream switch ports and CXL root ports have their own GPF DVSEC
> for Port(DVSEC ID 04h). So my understanding is that CXL subsystem should
> locate GPF DVSEC for Port for each dport rather than using the cached
> location in CXL port.
Applied to cxl/fixes for 6.15-rc
>
> base-commit: 3b5d43245f0a56390baaa670e1b6d898772266b3 cxl/next
>
> v2:
> - Drop RFC tag.
> - Add Fixes tag to patch #1.
> - Pickup reviews.
> - Add tested by Davidlohr.
> - Adjust the changelog of patch #2.(Davidlohr)
> - Fix typo issue in patch #2.(Davidlohr)
>
> Li Ming (3):
> cxl/core: Fix caching dport GPF DVSEC issue
> cxl/pci: Update Port GPF timeout only when the first EP attaching
> cxl/pci: Drop the parameter is_port of cxl_gpf_get_dvsec()
>
> drivers/cxl/core/core.h | 2 +-
> drivers/cxl/core/pci.c | 30 +++++++++++++++++-------------
> drivers/cxl/core/port.c | 2 +-
> drivers/cxl/cxl.h | 6 +++---
> drivers/cxl/pmem.c | 2 +-
> 5 files changed, 23 insertions(+), 19 deletions(-)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-09 20:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-23 9:31 [PATCH v2 0/3] Fix using wrong GPF DVSEC location issue Li Ming
2025-03-23 9:31 ` [PATCH v2 1/3] cxl/core: Fix caching dport GPF DVSEC issue Li Ming
2025-03-23 9:31 ` [PATCH v2 2/3] cxl/pci: Update Port GPF timeout only when the first EP attaching Li Ming
2025-03-23 9:31 ` [PATCH v2 3/3] cxl/pci: Drop the parameter is_port of cxl_gpf_get_dvsec() Li Ming
2025-04-09 20:32 ` [PATCH v2 0/3] Fix using wrong GPF DVSEC location issue Dave Jiang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®