Skip to contentSkip to conversation

cxl: Test CXL_DECODER_F_LOCK as a bitmask

PATCH Applied Alison Schofield 3 participants 6 messages Feb 23 CXL

lore
Share & tools
lore

Alison Schofield

author maintainer
#0 lore raw

PATCH v2 1/2 cxl: Test CXL_DECODER_F_LOCK as a bitmask

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_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.

Fixes 2230c4bdc412 ("cxl: Add handling of locked CXL decoder")

---

Changes in v2:
Split patches to align w Fixes Tags for backport ease Rebased on 7.0-rc1

 drivers/cxl/core/hdm.c    | 2 +-
 drivers/cxl/core/region.c | 2 +-
 2 files changed, 2 insertions(+), 2 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 +1 -1
index fec37af1dfbf..780ec947ecf2 100644
@@ -1100,7 +1100,7 @@ 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);
 	}

base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f

Signature · 1 line
2.37.3
author maintainer
#1 lore raw

PATCH v2 2/2 cxl/region: Test CXL_DECODER_F_NORMALIZED_ADDRESSING as a bitmask

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.

Replace test_bit() with a bitmask check.

Found with cxl-test.

Fixes 208f432406b7 ("cxl: Disable HPA/SPA translation handlers for Normalized Addressing")

---

Changes in v2:
Split patches to align w Fixes Tags for backport ease Rebased on 7.0-rc1

 drivers/cxl/core/region.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/region.c +1 -1
index 780ec947ecf2..42874948b589 100644
@@ -1105,7 +1105,7 @@ static void cxl_region_setup_flags(struct cxl_region *cxlr,
 		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);
 }
 
Signature · 1 line
2.37.3
Reviewed-by Tested-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] cxl/region: Test CXL_DECODER_F_NORMALIZED_ADDRESSING as a bitmask

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 6 lines

Replace test_bit() with a bitmask check.

Found with cxl-test.

Fixes 208f432406b7 ("cxl: Disable HPA/SPA translation handlers for Normalized Addressing")
maintainer Applied
#3 lore raw

Re: [PATCH v2 2/2] cxl/region: Test CXL_DECODER_F_NORMALIZED_ADDRESSING as a bitmask

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 6 lines

Replace test_bit() with a bitmask check.

Found with cxl-test.

Fixes 208f432406b7 ("cxl: Disable HPA/SPA translation handlers for Normalized Addressing")

Applied to cxl/fixes
ebd11be59f7421e4b1ea19eaa8102d17ade3d6c6

Quoted 22 lines

---

Changes in v2:
Split patches to align w Fixes Tags for backport ease Rebased on 7.0-rc1

 drivers/cxl/core/region.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/region.c +1 -1
index 780ec947ecf2..42874948b589 100644
@@ -1105,7 +1105,7 @@ static void cxl_region_setup_flags(struct cxl_region *cxlr,
 		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);
 }
 
Reviewed-by Tested-by on v2 1/2
#4 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_LOCK the test reads beyond the defined bits, causing the test to always return false and allowing resets that should have been blocked.

Quoted 5 lines

Replace test_bit() with a bitmask check.

Fixes 2230c4bdc412 ("cxl: Add handling of locked CXL decoder")

---

Op, missed the v4 and responded to v1

maintainer Applied
#5 lore raw
In reply to Alison Schofield
Quoted 4 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.

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.

Fixes 2230c4bdc412 ("cxl: Add handling of locked CXL decoder")

Applied to cxl/fixes
8c0025ee29f03d74d34b77127192b9db8457564c

Quoted 38 lines

---

Changes in v2:
Split patches to align w Fixes Tags for backport ease Rebased on 7.0-rc1

 drivers/cxl/core/hdm.c    | 2 +-
 drivers/cxl/core/region.c | 2 +-
 2 files changed, 2 insertions(+), 2 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 +1 -1
index fec37af1dfbf..780ec947ecf2 100644
@@ -1100,7 +1100,7 @@ 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);
 	}

base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f