Skip to contentSkip to conversation

cxl: Test decoder flags as bitmasks

PATCH In review Alison Schofield 4 participants 5 messages Feb 6 – Feb 23 CXL

lore
Share & tools
lore

Alison Schofield

author maintainer
#0 lore raw

PATCH 1/1 cxl: Test decoder flags as bitmasks

The CXL decoder flags are defined as bitmasks, not bit indices. Using test_bit() to check them interprets the mask value as a bit index, which is the wrong test.

For CXL_DECODER_F_NORMALIZED_ADDRESSING the test reads beyond the flags word, making the flag sometimes appear set and blocking creation of CXL region debugfs attributes that support poison operations.

For CXL_DECODER_F_LOCK the test reads beyond the defined bits, causing the test to always return false and allowing resets that should have been blocked.

Replace test_bit() with a bitmask check.

Found with cxl-test.

Fixes 208f432406b7 ("cxl: Disable HPA/SPA translation handlers for Normalized Addressing")
Fixes 2230c4bdc412 ("cxl: Add handling of locked CXL decoder")

---

Obsoletes prior patch that only fixed up one test:
cxl/region: Test CXL_DECODER_F_NORMALIZED_ADDRESSING as a bitmask
https://lore.kernel.org/linux-cxl/[email protected]/

 drivers/cxl/core/hdm.c    | 2 +-
 drivers/cxl/core/region.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/cxl/core/hdm.c +1 -1
index e3f0c39e6812..c222e98ae736 100644
@@ -904,7 +904,7 @@ static void cxl_decoder_reset(struct cxl_decoder *cxld)
 	if ((cxld->flags & CXL_DECODER_F_ENABLE) == 0)
 		return;
 
-	if (test_bit(CXL_DECODER_F_LOCK, &cxld->flags))
+	if (cxld->flags & CXL_DECODER_F_LOCK)
 		return;
 
 	if (port->commit_end == id)
drivers/cxl/core/region.c +2 -2
index 08fa3deef70a..befa2a7b81c2 100644
@@ -1100,12 +1100,12 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr,
 static void cxl_region_setup_flags(struct cxl_region *cxlr,
 				   struct cxl_decoder *cxld)
 {
-	if (test_bit(CXL_DECODER_F_LOCK, &cxld->flags)) {
+	if (cxld->flags & CXL_DECODER_F_LOCK) {
 		set_bit(CXL_REGION_F_LOCK, &cxlr->flags);
 		clear_bit(CXL_REGION_F_NEEDS_RESET, &cxlr->flags);
 	}
 
-	if (test_bit(CXL_DECODER_F_NORMALIZED_ADDRESSING, &cxld->flags))
+	if (cxld->flags & CXL_DECODER_F_NORMALIZED_ADDRESSING)
 		set_bit(CXL_REGION_F_NORMALIZED_ADDRESSING, &cxlr->flags);
 }
 

base-commit: 9845cf73f7db6094c0d8419d6adb848028f4a921

Signature · 1 line
2.37.3
maintainer
#1 lore raw
Quoted 12 lines · Alison Schofield

The CXL decoder flags are defined as bitmasks, not bit indices. Using test_bit() to check them interprets the mask value as a bit index, which is the wrong test.

For CXL_DECODER_F_NORMALIZED_ADDRESSING the test reads beyond the flags word, making the flag sometimes appear set and blocking creation of CXL region debugfs attributes that support poison operations.

For CXL_DECODER_F_LOCK the test reads beyond the defined bits, causing the test to always return false and allowing resets that should have been blocked.

Quoted 6 lines

Replace test_bit() with a bitmask check.

Found with cxl-test.

Fixes 208f432406b7 ("cxl: Disable HPA/SPA translation handlers for Normalized Addressing")
Fixes 2230c4bdc412 ("cxl: Add handling of locked CXL decoder")

Given it needs to back port and fix 2 different commits, maybe this needs to split?

Quoted 46 lines

---

Obsoletes prior patch that only fixed up one test:
cxl/region: Test CXL_DECODER_F_NORMALIZED_ADDRESSING as a bitmask
https://lore.kernel.org/linux-cxl/[email protected]/

 drivers/cxl/core/hdm.c    | 2 +-
 drivers/cxl/core/region.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/cxl/core/hdm.c +1 -1
index e3f0c39e6812..c222e98ae736 100644
@@ -904,7 +904,7 @@ static void cxl_decoder_reset(struct cxl_decoder *cxld)
 	if ((cxld->flags & CXL_DECODER_F_ENABLE) == 0)
 		return;
 
-	if (test_bit(CXL_DECODER_F_LOCK, &cxld->flags))
+	if (cxld->flags & CXL_DECODER_F_LOCK)
 		return;
 
 	if (port->commit_end == id)
drivers/cxl/core/region.c +2 -2
index 08fa3deef70a..befa2a7b81c2 100644
@@ -1100,12 +1100,12 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr,
 static void cxl_region_setup_flags(struct cxl_region *cxlr,
 				   struct cxl_decoder *cxld)
 {
-	if (test_bit(CXL_DECODER_F_LOCK, &cxld->flags)) {
+	if (cxld->flags & CXL_DECODER_F_LOCK) {
 		set_bit(CXL_REGION_F_LOCK, &cxlr->flags);
 		clear_bit(CXL_REGION_F_NEEDS_RESET, &cxlr->flags);
 	}
 
-	if (test_bit(CXL_DECODER_F_NORMALIZED_ADDRESSING, &cxld->flags))
+	if (cxld->flags & CXL_DECODER_F_NORMALIZED_ADDRESSING)
 		set_bit(CXL_REGION_F_NORMALIZED_ADDRESSING, &cxlr->flags);
 }
 

base-commit: 9845cf73f7db6094c0d8419d6adb848028f4a921

author maintainer
#2 lore raw
Quoted 15 lines · Dave Jiang
Quoted 12 lines · Alison Schofield

The CXL decoder flags are defined as bitmasks, not bit indices. Using test_bit() to check them interprets the mask value as a bit index, which is the wrong test.

For CXL_DECODER_F_NORMALIZED_ADDRESSING the test reads beyond the flags word, making the flag sometimes appear set and blocking creation of CXL region debugfs attributes that support poison operations.

For CXL_DECODER_F_LOCK the test reads beyond the defined bits, causing the test to always return false and allowing resets that should have been blocked.

Quoted 8 lines
Quoted 6 lines

Replace test_bit() with a bitmask check.

Found with cxl-test.

Fixes 208f432406b7 ("cxl: Disable HPA/SPA translation handlers for Normalized Addressing")
Fixes 2230c4bdc412 ("cxl: Add handling of locked CXL decoder")

Given it needs to back port and fix 2 different commits, maybe this needs to split?

OK - will do, ignore this patch.

It'll be a 2 patch series because of the dependency, but I believe that is still preferred by backport folks.

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

The CXL decoder flags are defined as bitmasks, not bit indices. Using test_bit() to check them interprets the mask value as a bit index, which is the wrong test.

For CXL_DECODER_F_NORMALIZED_ADDRESSING the test reads beyond the flags word, making the flag sometimes appear set and blocking creation of CXL region debugfs attributes that support poison operations.

Quoted 8 lines

For CXL_DECODER_F_LOCK the test reads beyond the defined bits, causing the test to always return false and allowing resets that should have been blocked.

Replace test_bit() with a bitmask check.

Found with cxl-test.

Nice find. Other than splitting the fixes as suggested by Dave:

Reviewed-by Tested-by on v1 1/1
#4 lore raw
In reply to Alison Schofield
Quoted 12 lines · Alison Schofield

The CXL decoder flags are defined as bitmasks, not bit indices. Using test_bit() to check them interprets the mask value as a bit index, which is the wrong test.

For CXL_DECODER_F_NORMALIZED_ADDRESSING the test reads beyond the flags word, making the flag sometimes appear set and blocking creation of CXL region debugfs attributes that support poison operations.

For CXL_DECODER_F_LOCK the test reads beyond the defined bits, causing the test to always return false and allowing resets that should have been blocked.

Quoted 7 lines

Replace test_bit() with a bitmask check.

Found with cxl-test.

Fixes 208f432406b7 ("cxl: Disable HPA/SPA translation handlers for Normalized Addressing")
Fixes 2230c4bdc412 ("cxl: Add handling of locked CXL decoder")

I independently found and fixed this with the same patch. So +1