Skip to contentSkip to conversation

cxl: check decoder count for end device

PATCH Superseded Dave Jiang 3 participants 5 messages Sep 15, 2022 – Oct 21, 2022 CXL

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Dave Jiang

author maintainer
#0 lore raw

PATCH 1/1 cxl: check decoder count for end device

CXL spec rev3.0 8.2.4.19.1 added definition for up to 32 decoders. It also indicates that for devices, only 10 decoders should be advertised. Add check on number of decoders greater than 10 for devices and reset to 10 to force spec compliance.

---
 drivers/cxl/core/hdm.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/cxl/core/hdm.c +15 -1
index d1d2caea5c62..1919d99d157e 100644
@@ -71,9 +71,23 @@ EXPORT_SYMBOL_NS_GPL(devm_cxl_add_passthrough_decoder, CXL);
 static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm)
 {
 	u32 hdm_cap;
+	int decoder_count;
+	struct device *dev = &cxlhdm->port->dev;
 
 	hdm_cap = readl(cxlhdm->regs.hdm_decoder + CXL_HDM_DECODER_CAP_OFFSET);
-	cxlhdm->decoder_count = cxl_hdm_decoder_count(hdm_cap);
+	decoder_count = cxl_hdm_decoder_count(hdm_cap);
+	/*
+	 * CXL spec rev3.0 8.2.4.19.1 indicates CXL devices shall not advertise
+	 * more than 10 decoders. Switches and Host Bridges may advertise up to
+	 * 32 decoders. Set the decoders to 10 for devices if more than 10 are
+	 * found.
+	 */
+	if (is_cxl_endpoint(cxlhdm->port) && decoder_count > 10) {
+		dev_warn(dev, "Reset decoders count (%d) to 10, spec violation!\n",
+			 decoder_count);
+		decoder_count = 10;
+	}
+	cxlhdm->decoder_count = decoder_count;
 	cxlhdm->target_count =
 		FIELD_GET(CXL_HDM_DECODER_TARGET_COUNT_MASK, hdm_cap);
 	if (FIELD_GET(CXL_HDM_DECODER_INTERLEAVE_11_8, hdm_cap))
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · On Thu, 15 Sep 2022 11:11:07 -0700 Dave Jiang <[email protected]> wrote:

CXL spec rev3.0 8.2.4.19.1 added definition for up to 32 decoders. It also indicates that for devices, only 10 decoders should be advertised. Add check on number of decoders greater than 10 for devices and reset to 10 to force spec compliance.

Hi Dave

Seems reasonable. I'm a bit curious to whether there is an actual problem if a device is spec non compliant and advertises more decoders?

Either way does no harm and might let us know something fishy is happening.

Quoted 35 lines
---
 drivers/cxl/core/hdm.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/cxl/core/hdm.c +15 -1
index d1d2caea5c62..1919d99d157e 100644
@@ -71,9 +71,23 @@ EXPORT_SYMBOL_NS_GPL(devm_cxl_add_passthrough_decoder, CXL);
 static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm)
 {
 	u32 hdm_cap;
+	int decoder_count;
+	struct device *dev = &cxlhdm->port->dev;
 
 	hdm_cap = readl(cxlhdm->regs.hdm_decoder + CXL_HDM_DECODER_CAP_OFFSET);
-	cxlhdm->decoder_count = cxl_hdm_decoder_count(hdm_cap);
+	decoder_count = cxl_hdm_decoder_count(hdm_cap);
+	/*
+	 * CXL spec rev3.0 8.2.4.19.1 indicates CXL devices shall not advertise
+	 * more than 10 decoders. Switches and Host Bridges may advertise up to
+	 * 32 decoders. Set the decoders to 10 for devices if more than 10 are
+	 * found.
+	 */
+	if (is_cxl_endpoint(cxlhdm->port) && decoder_count > 10) {
+		dev_warn(dev, "Reset decoders count (%d) to 10, spec violation!\n",
+			 decoder_count);
+		decoder_count = 10;
+	}
+	cxlhdm->decoder_count = decoder_count;
 	cxlhdm->target_count =
 		FIELD_GET(CXL_HDM_DECODER_TARGET_COUNT_MASK, hdm_cap);
 	if (FIELD_GET(CXL_HDM_DECODER_INTERLEAVE_11_8, hdm_cap))
author maintainer
#2 lore raw
Quoted 8 lines · Jonathan Cameron
Quoted 5 lines · On Thu, 15 Sep 2022 11:11:07 -0700 Dave Jiang <[email protected]> wrote:

CXL spec rev3.0 8.2.4.19.1 added definition for up to 32 decoders. It also indicates that for devices, only 10 decoders should be advertised. Add check on number of decoders greater than 10 for devices and reset to 10 to force spec compliance.

Quoted 5 lines
Quoted 1 line

Hi Dave

Seems reasonable. I'm a bit curious to whether there is an actual problem if a device is spec non compliant and advertises more decoders?

Not that I'm aware of. Just being cautious.

Quoted 4 lines

Either way does no harm and might let us know something fishy is happening.

Thanks!

Quoted 36 lines
Quoted 36 lines
---
  drivers/cxl/core/hdm.c |   16 +++++++++++++++-
  1 file changed, 15 insertions(+), 1 deletion(-)
drivers/cxl/core/hdm.c +15 -1
index d1d2caea5c62..1919d99d157e 100644
@@ -71,9 +71,23 @@ EXPORT_SYMBOL_NS_GPL(devm_cxl_add_passthrough_decoder, CXL);
  static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm)
  {
  	u32 hdm_cap;
+	int decoder_count;
+	struct device *dev = &cxlhdm->port->dev;
 
  	hdm_cap = readl(cxlhdm->regs.hdm_decoder + CXL_HDM_DECODER_CAP_OFFSET);
-	cxlhdm->decoder_count = cxl_hdm_decoder_count(hdm_cap);
+	decoder_count = cxl_hdm_decoder_count(hdm_cap);
+	/*
+	 * CXL spec rev3.0 8.2.4.19.1 indicates CXL devices shall not advertise
+	 * more than 10 decoders. Switches and Host Bridges may advertise up to
+	 * 32 decoders. Set the decoders to 10 for devices if more than 10 are
+	 * found.
+	 */
+	if (is_cxl_endpoint(cxlhdm->port) && decoder_count > 10) {
+		dev_warn(dev, "Reset decoders count (%d) to 10, spec violation!\n",
+			 decoder_count);
+		decoder_count = 10;
+	}
+	cxlhdm->decoder_count = decoder_count;
  	cxlhdm->target_count =
  		FIELD_GET(CXL_HDM_DECODER_TARGET_COUNT_MASK, hdm_cap);
  	if (FIELD_GET(CXL_HDM_DECODER_INTERLEAVE_11_8, hdm_cap))
#3 lore raw
In reply to Dave Jiang
Quoted 24 lines · Dave Jiang

CXL spec rev3.0 8.2.4.19.1 added definition for up to 32 decoders. It also indicates that for devices, only 10 decoders should be advertised. Add check on number of decoders greater than 10 for devices and reset to 10 to force spec compliance.

---
 drivers/cxl/core/hdm.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/cxl/core/hdm.c +3 -1
index d1d2caea5c62..1919d99d157e 100644
@@ -71,9 +71,23 @@ EXPORT_SYMBOL_NS_GPL(devm_cxl_add_passthrough_decoder, CXL);
 static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm)
 {
 	u32 hdm_cap;
+	int decoder_count;
+	struct device *dev = &cxlhdm->port->dev;
 
 	hdm_cap = readl(cxlhdm->regs.hdm_decoder + CXL_HDM_DECODER_CAP_OFFSET);
-	cxlhdm->decoder_count = cxl_hdm_decoder_count(hdm_cap);
+	decoder_count = cxl_hdm_decoder_count(hdm_cap);

drivers/cxl/core/hdm.c EXPORT_SYMBOL_NS_GPL(devm_cxl_add_passthrough_decoder, CXL); · line 88

Quoted 10 lines
drivers/cxl/core/hdm.c +10 -0
+	/*
+	 * CXL spec rev3.0 8.2.4.19.1 indicates CXL devices shall not advertise
+	 * more than 10 decoders. Switches and Host Bridges may advertise up to
+	 * 32 decoders. Set the decoders to 10 for devices if more than 10 are
+	 * found.
+	 */
+	if (is_cxl_endpoint(cxlhdm->port) && decoder_count > 10) {
+		dev_warn(dev, "Reset decoders count (%d) to 10, spec violation!\n",
+			 decoder_count);
+		decoder_count = 10;

I agree with the reporting, but not the limitation. The Robustness Principle says if allowing it does no harm, then let it through.

author maintainer
#4 lore raw
Quoted 22 lines · Dan Williams
Quoted 21 lines · Dave Jiang

CXL spec rev3.0 8.2.4.19.1 added definition for up to 32 decoders. It also indicates that for devices, only 10 decoders should be advertised. Add check on number of decoders greater than 10 for devices and reset to 10 to force spec compliance.

---
  drivers/cxl/core/hdm.c |   16 +++++++++++++++-
  1 file changed, 15 insertions(+), 1 deletion(-)
drivers/cxl/core/hdm.c +2 -0
index d1d2caea5c62..1919d99d157e 100644
@@ -71,9 +71,23 @@ EXPORT_SYMBOL_NS_GPL(devm_cxl_add_passthrough_decoder, CXL);
  static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm)
  {
  	u32 hdm_cap;
+	int decoder_count;
+	struct device *dev = &cxlhdm->port->dev;
 
Quoted 15 lines

drivers/cxl/core/hdm.c EXPORT_SYMBOL_NS_GPL(devm_cxl_add_passthrough_decoder, CXL); · line 88

Quoted 13 lines
drivers/cxl/core/hdm.c +11 -1
  	hdm_cap = readl(cxlhdm->regs.hdm_decoder + CXL_HDM_DECODER_CAP_OFFSET);
-	cxlhdm->decoder_count = cxl_hdm_decoder_count(hdm_cap);
+	decoder_count = cxl_hdm_decoder_count(hdm_cap);
+	/*
+	 * CXL spec rev3.0 8.2.4.19.1 indicates CXL devices shall not advertise
+	 * more than 10 decoders. Switches and Host Bridges may advertise up to
+	 * 32 decoders. Set the decoders to 10 for devices if more than 10 are
+	 * found.
+	 */
+	if (is_cxl_endpoint(cxlhdm->port) && decoder_count > 10) {
+		dev_warn(dev, "Reset decoders count (%d) to 10, spec violation!\n",
+			 decoder_count);
+		decoder_count = 10;

I agree with the reporting, but not the limitation. The Robustness Principle says if allowing it does no harm, then let it through.

Ok I'll remove the reassigment.