Skip to contentSkip to conversation

cxl/mbox: Fix CEL logic for poison and security commands

PATCH In review Ira Weiny 4 participants 6 messages Sep 3, 2023 – Sep 13, 2023 CXL

lore
Share & tools
lore

Ira Weiny

author
#0 lore raw

PATCH 1/1 cxl/mbox: Fix CEL logic for poison and security commands

The following debug output was observed while testing CXL

cxl_core:cxl_walk_cel:721: cxl_mock_mem cxl_mem.0: Opcode 0x4300 unsupported by driver

opcode 0x4300 (Get Poison) is supported by the driver and the mock device supports it. The logic should be checking that the opcode is both not poison and not security.

Fix the logic to allow poison and security commands.

Fixes ad64f5952ce3 ("cxl/memdev: Only show sanitize sysfs files when supported")
Cc Davidlohr Bueso <[email protected]>
---
 drivers/cxl/core/mbox.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/mbox.c +2 -2
index ca60bb8114f2..b315bdab9197 100644
@@ -716,8 +716,8 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
 		u16 opcode = le16_to_cpu(cel_entry[i].opcode);
 		struct cxl_mem_command *cmd = cxl_mem_find_command(opcode);
 
-		if (!cmd && (!cxl_is_poison_command(opcode) ||
-			     !cxl_is_security_command(opcode))) {
+		if (!cmd && !cxl_is_poison_command(opcode) &&
+		    !cxl_is_security_command(opcode)) {
 			dev_dbg(dev,
 				"Opcode 0x%04x unsupported by driver\n", opcode);
 			continue;

---
base-commit: 1c59d383390f970b891b503b7f79b63a02db2ec5
change-id: 20230903-cxl-cel-fix-9da269bf0f21

Best regards,

Signature · 1 line
Ira Weiny <[email protected]>
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · On Sun, 03 Sep 2023 14:42:58 -0700 Ira Weiny <[email protected]> wrote:

The following debug output was observed while testing CXL

cxl_core:cxl_walk_cel:721: cxl_mock_mem cxl_mem.0: Opcode 0x4300 unsupported by driver

opcode 0x4300 (Get Poison) is supported by the driver and the mock device supports it. The logic should be checking that the opcode is both not poison and not security.

Quoted 5 lines

Fix the logic to allow poison and security commands.

Fixes ad64f5952ce3 ("cxl/memdev: Only show sanitize sysfs files when supported")
Cc Davidlohr Bueso <[email protected]>

Makes sense.

Quoted 25 lines
---
 drivers/cxl/core/mbox.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/mbox.c +2 -3
index ca60bb8114f2..b315bdab9197 100644
@@ -716,8 +716,8 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
 		u16 opcode = le16_to_cpu(cel_entry[i].opcode);
 		struct cxl_mem_command *cmd = cxl_mem_find_command(opcode);
 
-		if (!cmd && (!cxl_is_poison_command(opcode) ||
-			     !cxl_is_security_command(opcode))) {
+		if (!cmd && !cxl_is_poison_command(opcode) &&
+		    !cxl_is_security_command(opcode)) {
 			dev_dbg(dev,
 				"Opcode 0x%04x unsupported by driver\n", opcode);
 			continue;
 
---

base-commit: 1c59d383390f970b891b503b7f79b63a02db2ec5
change-id: 20230903-cxl-cel-fix-9da269bf0f21

Best regards,

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Ira Weiny
Quoted 9 lines · Ira Weiny

The following debug output was observed while testing CXL

cxl_core:cxl_walk_cel:721: cxl_mock_mem cxl_mem.0: Opcode 0x4300 unsupported by driver

opcode 0x4300 (Get Poison) is supported by the driver and the mock device supports it. The logic should be checking that the opcode is both not poison and not security.

Fix the logic to allow poison and security commands.

Hmm yeah sorry about that.

Quoted 32 lines
Fixes ad64f5952ce3 ("cxl/memdev: Only show sanitize sysfs files when supported")
Cc Davidlohr Bueso <[email protected]>

---
drivers/cxl/core/mbox.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/mbox.c +2 -3
index ca60bb8114f2..b315bdab9197 100644
@@ -716,8 +716,8 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
 		u16 opcode = le16_to_cpu(cel_entry[i].opcode);
 		struct cxl_mem_command *cmd = cxl_mem_find_command(opcode);
 
-		if (!cmd && (!cxl_is_poison_command(opcode) ||
-			     !cxl_is_security_command(opcode))) {
+		if (!cmd && !cxl_is_poison_command(opcode) &&
+		    !cxl_is_security_command(opcode)) {
 			dev_dbg(dev,
 				"Opcode 0x%04x unsupported by driver\n", opcode);
 			continue;
 
---

base-commit: 1c59d383390f970b891b503b7f79b63a02db2ec5
change-id: 20230903-cxl-cel-fix-9da269bf0f21

Best regards,
--
Ira Weiny <[email protected]>

#3 lore raw
In reply to Ira Weiny
Quoted 22 lines · Ira Weiny

The following debug output was observed while testing CXL

cxl_core:cxl_walk_cel:721: cxl_mock_mem cxl_mem.0: Opcode 0x4300 unsupported by driver

opcode 0x4300 (Get Poison) is supported by the driver and the mock device supports it. The logic should be checking that the opcode is both not poison and not security.

Fix the logic to allow poison and security commands.

Fixes ad64f5952ce3 ("cxl/memdev: Only show sanitize sysfs files when supported")
Cc Davidlohr Bueso <[email protected]>
---
 drivers/cxl/core/mbox.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/mbox.c +0 -0
index ca60bb8114f2..b315bdab9197 100644

drivers/cxl/core/mbox.c static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel) · line 720

Quoted 7 lines
drivers/cxl/core/mbox.c +2 -2
@@ -716,8 +716,8 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
 		u16 opcode = le16_to_cpu(cel_entry[i].opcode);
 		struct cxl_mem_command *cmd = cxl_mem_find_command(opcode);
 
-		if (!cmd && (!cxl_is_poison_command(opcode) ||
-			     !cxl_is_security_command(opcode))) {
+		if (!cmd && !cxl_is_poison_command(opcode) &&
+		    !cxl_is_security_command(opcode)) {

Given that this is going to be a recurring pattern to add optional command support, I am not a fan of continuing to expand this boolean algebra eye exam.

How about the following to only do the validation check and enabling in one place:

drivers/cxl/core/mbox.c +12 -11
index ca60bb8114f2..4df4f614f490 100644
@@ -715,24 +715,25 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
 	for (i = 0; i < cel_entries; i++) {
 		u16 opcode = le16_to_cpu(cel_entry[i].opcode);
 		struct cxl_mem_command *cmd = cxl_mem_find_command(opcode);
+		int enabled = 0;
 
-		if (!cmd && (!cxl_is_poison_command(opcode) ||
-			     !cxl_is_security_command(opcode))) {
-			dev_dbg(dev,
-				"Opcode 0x%04x unsupported by driver\n", opcode);
-			continue;
-		}
-
-		if (cmd)
+		if (cmd) {
 			set_bit(cmd->info.id, mds->enabled_cmds);
+			enabled++;
+		}
 
-		if (cxl_is_poison_command(opcode))
+		if (cxl_is_poison_command(opcode)) {
 			cxl_set_poison_cmd_enabled(&mds->poison, opcode);
+			enabled++;
+		}
 
-		if (cxl_is_security_command(opcode))
+		if (cxl_is_security_command(opcode)) {
 			cxl_set_security_cmd_enabled(&mds->security, opcode);
+			enabled++;
+		}
 
-		dev_dbg(dev, "Opcode 0x%04x enabled\n", opcode);
+		dev_dbg(dev, "Opcode 0x%04x %s\n", opcode,
+			enabled ? "enabled" : "unsupported by driver");
 	}
 }
 
author Reviewed-by
#4 lore raw
Quoted 35 lines · Dan Williams
Quoted 22 lines · Ira Weiny

The following debug output was observed while testing CXL

cxl_core:cxl_walk_cel:721: cxl_mock_mem cxl_mem.0: Opcode 0x4300 unsupported by driver

opcode 0x4300 (Get Poison) is supported by the driver and the mock device supports it. The logic should be checking that the opcode is both not poison and not security.

Fix the logic to allow poison and security commands.

Fixes ad64f5952ce3 ("cxl/memdev: Only show sanitize sysfs files when supported")
Cc Davidlohr Bueso <[email protected]>
---
 drivers/cxl/core/mbox.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/mbox.c +0 -0
index ca60bb8114f2..b315bdab9197 100644

drivers/cxl/core/mbox.c static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel) · line 720

Quoted 7 lines
drivers/cxl/core/mbox.c +2 -2
@@ -716,8 +716,8 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
 		u16 opcode = le16_to_cpu(cel_entry[i].opcode);
 		struct cxl_mem_command *cmd = cxl_mem_find_command(opcode);
 
-		if (!cmd && (!cxl_is_poison_command(opcode) ||
-			     !cxl_is_security_command(opcode))) {
+		if (!cmd && !cxl_is_poison_command(opcode) &&
+		    !cxl_is_security_command(opcode)) {

Given that this is going to be a recurring pattern to add optional command support, I am not a fan of continuing to expand this boolean algebra eye exam.

Quoted 2 lines

How about the following to only do the validation check and enabling in one place:

I like it.

Quoted 43 lines
drivers/cxl/core/mbox.c +12 -11
index ca60bb8114f2..4df4f614f490 100644
@@ -715,24 +715,25 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
 	for (i = 0; i < cel_entries; i++) {
 		u16 opcode = le16_to_cpu(cel_entry[i].opcode);
 		struct cxl_mem_command *cmd = cxl_mem_find_command(opcode);
+		int enabled = 0;
 
-		if (!cmd && (!cxl_is_poison_command(opcode) ||
-			     !cxl_is_security_command(opcode))) {
-			dev_dbg(dev,
-				"Opcode 0x%04x unsupported by driver\n", opcode);
-			continue;
-		}
-
-		if (cmd)
+		if (cmd) {
 			set_bit(cmd->info.id, mds->enabled_cmds);
+			enabled++;
+		}
 
-		if (cxl_is_poison_command(opcode))
+		if (cxl_is_poison_command(opcode)) {
 			cxl_set_poison_cmd_enabled(&mds->poison, opcode);
+			enabled++;
+		}
 
-		if (cxl_is_security_command(opcode))
+		if (cxl_is_security_command(opcode)) {
 			cxl_set_security_cmd_enabled(&mds->security, opcode);
+			enabled++;
+		}
 
-		dev_dbg(dev, "Opcode 0x%04x enabled\n", opcode);
+		dev_dbg(dev, "Opcode 0x%04x %s\n", opcode,
+			enabled ? "enabled" : "unsupported by driver");
 	}
 }
 
maintainer Reviewed-by
#5 lore raw
In reply to Dan Williams
Quoted 35 lines · Dan Williams
Quoted 22 lines · Ira Weiny

The following debug output was observed while testing CXL

cxl_core:cxl_walk_cel:721: cxl_mock_mem cxl_mem.0: Opcode 0x4300 unsupported by driver

opcode 0x4300 (Get Poison) is supported by the driver and the mock device supports it. The logic should be checking that the opcode is both not poison and not security.

Fix the logic to allow poison and security commands.

Fixes ad64f5952ce3 ("cxl/memdev: Only show sanitize sysfs files when supported")
Cc Davidlohr Bueso <[email protected]>
---
 drivers/cxl/core/mbox.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cxl/core/mbox.c +0 -0
index ca60bb8114f2..b315bdab9197 100644

drivers/cxl/core/mbox.c static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel) · line 720

Quoted 7 lines
drivers/cxl/core/mbox.c +2 -2
@@ -716,8 +716,8 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
 		u16 opcode = le16_to_cpu(cel_entry[i].opcode);
 		struct cxl_mem_command *cmd = cxl_mem_find_command(opcode);
 
-		if (!cmd && (!cxl_is_poison_command(opcode) ||
-			     !cxl_is_security_command(opcode))) {
+		if (!cmd && !cxl_is_poison_command(opcode) &&
+		    !cxl_is_security_command(opcode)) {

Given that this is going to be a recurring pattern to add optional command support, I am not a fan of continuing to expand this boolean algebra eye exam.

Quoted 2 lines

How about the following to only do the validation check and enabling in one place:

Agreed.

... this also is a reminder of the need for regression testing/CI.

Thanks,
Davidlohr