Skip to contentSkip to conversation

cxl/core: Check existence of cxl_memdev_state in poison test

PATCH Applied Alison Schofield 3 participants 3 messages Mar 31 – Apr 1 CXL

lore
Share & tools
lore

Alison Schofield

author maintainer
#0 lore raw

PATCH 1/1 cxl/core: Check existence of cxl_memdev_state in poison test

Before now, all CXL memdevs were assumed to have a mailbox-backed cxl_memdev_state, so poison command checks could safely dereference the @mds.

With the introduction of Type 2 devices, a memdev may not implement a mailbox interface, and so there is no associated cxl_memdev_state. Guard against this case by returning false when @mds is absent.

---
 drivers/cxl/core/memdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/cxl/core/memdev.c +3 -0
index 273c22118d3d..591425866045 100644
@@ -204,6 +204,9 @@ bool cxl_memdev_has_poison_cmd(struct cxl_memdev *cxlmd,
 {
 	struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
 
+	if (!mds)
+		return 0;
+
 	return test_bit(cmd, mds->poison.enabled_cmds);
 }
 
Signature · 1 line
2.37.3
Reviewed-by on v1 1/1
#1 lore raw

Hi Allison,

I think the introduction of type2 is weakening some assumptions of the core design, and this check is another example after similar ones added for type2. Not sure how this could be addressed properly, so I will look at how to make this integration seamless.

By now, as this check is necessary, at least as a sanity check:

Quoted 27 lines · Alison Schofield

Before now, all CXL memdevs were assumed to have a mailbox-backed cxl_memdev_state, so poison command checks could safely dereference the @mds.

With the introduction of Type 2 devices, a memdev may not implement a mailbox interface, and so there is no associated cxl_memdev_state. Guard against this case by returning false when @mds is absent.

---
  drivers/cxl/core/memdev.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/cxl/core/memdev.c +3 -0
index 273c22118d3d..591425866045 100644
@@ -204,6 +204,9 @@ bool cxl_memdev_has_poison_cmd(struct cxl_memdev *cxlmd,
  {
  	struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
 
+	if (!mds)
+		return 0;
+
  	return test_bit(cmd, mds->poison.enabled_cmds);
  }
 
maintainer Applied
#2 lore raw
In reply to Alison Schofield
Quoted 9 lines · Alison Schofield

Before now, all CXL memdevs were assumed to have a mailbox-backed cxl_memdev_state, so poison command checks could safely dereference the @mds.

With the introduction of Type 2 devices, a memdev may not implement a mailbox interface, and so there is no associated cxl_memdev_state. Guard against this case by returning false when @mds is absent.

Applied to cxl/next
261a02b93d9b

Quoted 18 lines
---
 drivers/cxl/core/memdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/cxl/core/memdev.c +3 -0
index 273c22118d3d..591425866045 100644
@@ -204,6 +204,9 @@ bool cxl_memdev_has_poison_cmd(struct cxl_memdev *cxlmd,
 {
 	struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
 
+	if (!mds)
+		return 0;
+
 	return test_bit(cmd, mds->poison.enabled_cmds);
 }