Skip to contentSkip to conversation

cxl/region: Guard against a missing peer mapping

PATCH Applied Alison Schofield 3 participants 4 messages Aug 21 – Sep 1 CXL

lore
Share & tools
lore

Alison Schofield

author maintainer
#0 lore raw

PATCH 1/1 cxl/region: Guard against a missing peer mapping

When two endpoints share a dport, both must be mapped by the port.

sashiko-bot reports that a missing peer mapping could result in a NULL pointer dereference during region creation.

No caller can reach this today. Guard it anyway so a future violation of the mapping requirement fails region creation rather than causing an oops.

---
 drivers/cxl/core/region.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/cxl/core/region.c +3 -2
index 27e63e6dab7c..75b8092e6dc2 100644
@@ -1367,7 +1367,8 @@ static int check_last_peer(struct cxl_endpoint_decoder *cxled,
 	/*
 	 * If this position wants to share a dport with the last endpoint mapped
 	 * then that endpoint, at index 'position - distance', must also be
-	 * mapped by this dport.
+	 * mapped by this dport. An endpoint that this port does not map at all
+	 * fails that requirement.
 	 */
 	if (pos < distance) {
 		dev_dbg(&cxlr->dev, "%s:%s: cannot host %s:%s at %d\n",
@@ -1378,7 +1379,7 @@ static int check_last_peer(struct cxl_endpoint_decoder *cxled,
 	cxled_peer = p->targets[pos - distance];
 	cxlmd_peer = cxled_to_memdev(cxled_peer);
 	ep_peer = cxl_ep_load(port, cxlmd_peer);
-	if (ep->dport != ep_peer->dport) {
+	if (!ep_peer || ep->dport != ep_peer->dport) {
 		dev_dbg(&cxlr->dev,
 			"%s:%s: %s:%s pos %d mismatched peer %s:%s\n",
 			dev_name(port->uport_dev), dev_name(&port->dev),

base-commit: 7098e9cd98a05c0c5de2fae0c2465f9d966fdd07

Signature · 1 line
2.37.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 41 lines · Alison Schofield

When two endpoints share a dport, both must be mapped by the port.

sashiko-bot reports that a missing peer mapping could result in a NULL pointer dereference during region creation.

No caller can reach this today. Guard it anyway so a future violation of the mapping requirement fails region creation rather than causing an oops.

---
 drivers/cxl/core/region.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/cxl/core/region.c +3 -2
index 27e63e6dab7c..75b8092e6dc2 100644
@@ -1367,7 +1367,8 @@ static int check_last_peer(struct cxl_endpoint_decoder *cxled,
 	/*
 	 * If this position wants to share a dport with the last endpoint mapped
 	 * then that endpoint, at index 'position - distance', must also be
-	 * mapped by this dport.
+	 * mapped by this dport. An endpoint that this port does not map at all
+	 * fails that requirement.
 	 */
 	if (pos < distance) {
 		dev_dbg(&cxlr->dev, "%s:%s: cannot host %s:%s at %d\n",
@@ -1378,7 +1379,7 @@ static int check_last_peer(struct cxl_endpoint_decoder *cxled,
 	cxled_peer = p->targets[pos - distance];
 	cxlmd_peer = cxled_to_memdev(cxled_peer);
 	ep_peer = cxl_ep_load(port, cxlmd_peer);
-	if (ep->dport != ep_peer->dport) {
+	if (!ep_peer || ep->dport != ep_peer->dport) {
 		dev_dbg(&cxlr->dev,
 			"%s:%s: %s:%s pos %d mismatched peer %s:%s\n",
 			dev_name(port->uport_dev), dev_name(&port->dev),
Quoted 5 lines

base-commit: 7098e9cd98a05c0c5de2fae0c2465f9d966fdd07

Signature · 1 line
2.37.3

LGTM.

Best regards,
Richard Cheng.

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Alison Schofield
Quoted 5 lines · Alison Schofield

When two endpoints share a dport, both must be mapped by the port.

sashiko-bot reports that a missing peer mapping could result in a NULL pointer dereference during region creation.

Quoted 8 lines

No caller can reach this today. Guard it anyway so a future violation of the mapping requirement fails region creation rather than causing an oops.

Quoted 29 lines
---
 drivers/cxl/core/region.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/cxl/core/region.c +3 -2
index 27e63e6dab7c..75b8092e6dc2 100644
@@ -1367,7 +1367,8 @@ static int check_last_peer(struct cxl_endpoint_decoder *cxled,
 	/*
 	 * If this position wants to share a dport with the last endpoint mapped
 	 * then that endpoint, at index 'position - distance', must also be
-	 * mapped by this dport.
+	 * mapped by this dport. An endpoint that this port does not map at all
+	 * fails that requirement.
 	 */
 	if (pos < distance) {
 		dev_dbg(&cxlr->dev, "%s:%s: cannot host %s:%s at %d\n",
@@ -1378,7 +1379,7 @@ static int check_last_peer(struct cxl_endpoint_decoder *cxled,
 	cxled_peer = p->targets[pos - distance];
 	cxlmd_peer = cxled_to_memdev(cxled_peer);
 	ep_peer = cxl_ep_load(port, cxlmd_peer);
-	if (ep->dport != ep_peer->dport) {
+	if (!ep_peer || ep->dport != ep_peer->dport) {
 		dev_dbg(&cxlr->dev,
 			"%s:%s: %s:%s pos %d mismatched peer %s:%s\n",
 			dev_name(port->uport_dev), dev_name(&port->dev),

base-commit: 7098e9cd98a05c0c5de2fae0c2465f9d966fdd07

maintainer Applied
#3 lore raw
In reply to Alison Schofield
Quoted 5 lines · Alison Schofield

When two endpoints share a dport, both must be mapped by the port.

sashiko-bot reports that a missing peer mapping could result in a NULL pointer dereference during region creation.

Quoted 8 lines

No caller can reach this today. Guard it anyway so a future violation of the mapping requirement fails region creation rather than causing an oops.

Applied to cxl/next
b212e37113f8

Quoted 29 lines
---
 drivers/cxl/core/region.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/cxl/core/region.c +3 -2
index 27e63e6dab7c..75b8092e6dc2 100644
@@ -1367,7 +1367,8 @@ static int check_last_peer(struct cxl_endpoint_decoder *cxled,
 	/*
 	 * If this position wants to share a dport with the last endpoint mapped
 	 * then that endpoint, at index 'position - distance', must also be
-	 * mapped by this dport.
+	 * mapped by this dport. An endpoint that this port does not map at all
+	 * fails that requirement.
 	 */
 	if (pos < distance) {
 		dev_dbg(&cxlr->dev, "%s:%s: cannot host %s:%s at %d\n",
@@ -1378,7 +1379,7 @@ static int check_last_peer(struct cxl_endpoint_decoder *cxled,
 	cxled_peer = p->targets[pos - distance];
 	cxlmd_peer = cxled_to_memdev(cxled_peer);
 	ep_peer = cxl_ep_load(port, cxlmd_peer);
-	if (ep->dport != ep_peer->dport) {
+	if (!ep_peer || ep->dport != ep_peer->dport) {
 		dev_dbg(&cxlr->dev,
 			"%s:%s: %s:%s pos %d mismatched peer %s:%s\n",
 			dev_name(port->uport_dev), dev_name(&port->dev),

base-commit: 7098e9cd98a05c0c5de2fae0c2465f9d966fdd07