cxl: Add handling of locked CXL decoder
Dave Jiang
maintainerPATCH 1/1 cxl: Add handling of locked CXL decoder
When a decoder is locked, it means that its configuration cannot be changed. CXL spec r3.2 8.2.4.20.13 discusses the details regarding locked decoders. Locking happens when bit 8 of the decoder control register is set and then the decoder is committed afterwards (CXL spec r3.2 8.2.4.20.7).
Given that the driver creates a virtual decoder for each CFMWS, the Fixed Device Configuration (bit 4) of the Window Restriction field is considered as locking for the virtual decoder by the driver.
The current driver code disregards the locked status and a region can be destroyed regardless of the locking state.
Add a region flag to indicate the region is in a locked configuration. The driver will considered a region locked if the CFMWS or any decoder is configured as locked. The consideration is all or nothing regarding the locked state. It is reasonable to determine the region "locked" status while the region is being assembled based on the decoders.
Add a check in region commit_store() to intercept when a 0 is written to the commit sysfs attribute in order to prevent the destruction of a region when in locked state. This should be the only entry point from user space to destroy a region.
Add a check is added to cxl_decoder_reset() to prevent resetting a locked decoder within the kernel driver.
--- drivers/cxl/core/hdm.c | 3 +++ drivers/cxl/core/region.c | 16 ++++++++++++++++ drivers/cxl/cxl.h | 8 ++++++++ 3 files changed, 27 insertions(+)
drivers/cxl/core/hdm.c +3 -0
@@ -905,6 +905,9 @@ 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)) +return ; +if (port->commit_end == id)cxl_port_commit_reap (cxld);else
drivers/cxl/core/region.c +16 -0
@@ -419,6 +419,9 @@ static ssize_t commit_store(struct device *dev, struct device_attribute *attr,return len; } +if (test_bit (CXL_REGION_F_LOCK , &cxlr->flags)) +return -EPERM ; + rc =queue_reset (cxlr);if (rc)return rc;
@@ -1059,6 +1062,16 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr,return 0 ; } +static void cxl_region_set_lock (struct cxl_region *cxlr, +struct cxl_decoder *cxld) +{ +if (!test_bit (CXL_REGION_F_LOCK , &cxlr->flags)) +return ; + +set_bit (CXL_REGION_F_LOCK , &cxlr->flags); +clear_bit (CXL_REGION_F_NEEDS_RESET , &cxlr->flags); +} +/** * cxl_port_attach_region() - track a region's interest in a port by endpoint * @port: port to add a new region reference 'struct cxl_region_ref'
@@ -1170,6 +1183,8 @@ static int cxl_port_attach_region(struct cxl_port *port, } } +cxl_region_set_lock (cxlr, cxld); + rc =cxl_rr_ep_add (cxl_rr, cxled);if (rc) { dev_dbg(&cxlr->dev,
@@ -2439,6 +2454,7 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i dev->bus = &cxl_bus_type; dev->type = &cxl_region_type; cxlr->id = id; +cxl_region_set_lock (cxlr, &cxlrd->cxlsd.cxld);return cxlr; }
drivers/cxl/cxl.h +8 -0
@@ -517,6 +517,14 @@ enum cxl_partition_mode {*/ #define CXL_REGION_F_NEEDS_RESET 1 +/* +* Indicate whether this region is locked due to 1 or more decoders that have +* been locked. The approach of all or nothing is taken with regard to the +* locked attribute. CXL_REGION_F_NEEDS_RESET should not be set if this flag is +* set. +*/ +#define CXL_REGION_F_LOCK 2 +/** * struct cxl_region - CXL region * @dev: This region's device
base-commit: 211ddde0823f1442e4ad052a2f30f050145ccada
Signature · 1 line
2.51.0
Quoted 24 lines · On Tue, 21 Oct 2025 13:50:55 -0700 Dave Jiang <[email protected]> wrote:
When a decoder is locked, it means that its configuration cannot be changed. CXL spec r3.2 8.2.4.20.13 discusses the details regarding locked decoders. Locking happens when bit 8 of the decoder control register is set and then the decoder is committed afterwards (CXL spec r3.2 8.2.4.20.7).
Given that the driver creates a virtual decoder for each CFMWS, the Fixed Device Configuration (bit 4) of the Window Restriction field is considered as locking for the virtual decoder by the driver.
The current driver code disregards the locked status and a region can be destroyed regardless of the locking state.
Add a region flag to indicate the region is in a locked configuration. The driver will considered a region locked if the CFMWS or any decoder is configured as locked. The consideration is all or nothing regarding the locked state. It is reasonable to determine the region "locked" status while the region is being assembled based on the decoders.
Add a check in region
commit_store()to intercept when a 0 is written to the commit sysfs attribute in order to prevent the destruction of a region when in locked state. This should be the only entry point from user space to destroy a region.
Quoted 4 lines
Add a check is added to
cxl_decoder_reset()to prevent resetting a locked decoder within the kernel driver.Signed-off-by Dave Jiang <[email protected]>
Fully agree with what should be happening here, but a question below on the implementation.
Quoted 35 lines
--- drivers/cxl/core/hdm.c | 3 +++ drivers/cxl/core/region.c | 16 ++++++++++++++++ drivers/cxl/cxl.h | 8 ++++++++ 3 files changed, 27 insertions(+)drivers/cxl/core/hdm.c +3
-0@@ -905,6 +905,9 @@ 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)) +return ; +if (port->commit_end == id)cxl_port_commit_reap (cxld);else drivers/cxl/core/region.c +3
-0@@ -419,6 +419,9 @@ static ssize_t commit_store(struct device *dev, struct device_attribute *attr,return len; } +if (test_bit (CXL_REGION_F_LOCK , &cxlr->flags)) +return -EPERM ; + rc =queue_reset (cxlr);if (rc)return rc;
drivers/cxl/core/region.c static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr, · line 1071
Quoted 10 lines
drivers/cxl/core/region.c +7
-0@@ -1059,6 +1062,16 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr,return 0 ; } +static void cxl_region_set_lock (struct cxl_region *cxlr, +struct cxl_decoder *cxld) +{ +if (!test_bit (CXL_REGION_F_LOCK , &cxlr->flags)) +return ; + +set_bit (CXL_REGION_F_LOCK , &cxlr->flags);
The sequence above here looks odd. If the bit is not set, then don't set it? If already set then set it again? Was one of these meant to be related to the decoder that was passed in?
Maybe I need more coffee...
Quoted 44 lines
drivers/cxl/core/region.c +6
-0+clear_bit (CXL_REGION_F_NEEDS_RESET , &cxlr->flags); +} +/** * cxl_port_attach_region() - track a region's interest in a port by endpoint * @port: port to add a new region reference 'struct cxl_region_ref' @@ -1170,6 +1183,8 @@ static int cxl_port_attach_region(struct cxl_port *port, } } +cxl_region_set_lock (cxlr, cxld); + rc =cxl_rr_ep_add (cxl_rr, cxled);if (rc) { dev_dbg(&cxlr->dev,@@ -2439,6 +2454,7 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i dev->bus = &cxl_bus_type; dev->type = &cxl_region_type; cxlr->id = id; +cxl_region_set_lock (cxlr, &cxlrd->cxlsd.cxld);return cxlr; }drivers/cxl/cxl.h +8
-0@@ -517,6 +517,14 @@ enum cxl_partition_mode {*/ #define CXL_REGION_F_NEEDS_RESET 1 +/* +* Indicate whether this region is locked due to 1 or more decoders that have +* been locked. The approach of all or nothing is taken with regard to the +* locked attribute. CXL_REGION_F_NEEDS_RESET should not be set if this flag is +* set. +*/ +#define CXL_REGION_F_LOCK 2 +/** * struct cxl_region - CXL region * @dev: This region's device base-commit:
211ddde0823f1442e4ad052a2f30f050145ccada
Dave Jiang
maintainerQuoted 85 lines · Jonathan Cameron
Quoted 24 lines · On Tue, 21 Oct 2025 13:50:55 -0700 Dave Jiang <[email protected]> wrote:
When a decoder is locked, it means that its configuration cannot be changed. CXL spec r3.2 8.2.4.20.13 discusses the details regarding locked decoders. Locking happens when bit 8 of the decoder control register is set and then the decoder is committed afterwards (CXL spec r3.2 8.2.4.20.7).
Given that the driver creates a virtual decoder for each CFMWS, the Fixed Device Configuration (bit 4) of the Window Restriction field is considered as locking for the virtual decoder by the driver.
The current driver code disregards the locked status and a region can be destroyed regardless of the locking state.
Add a region flag to indicate the region is in a locked configuration. The driver will considered a region locked if the CFMWS or any decoder is configured as locked. The consideration is all or nothing regarding the locked state. It is reasonable to determine the region "locked" status while the region is being assembled based on the decoders.
Add a check in region
commit_store()to intercept when a 0 is written to the commit sysfs attribute in order to prevent the destruction of a region when in locked state. This should be the only entry point from user space to destroy a region.Quoted 4 lines
Add a check is added to
cxl_decoder_reset()to prevent resetting a locked decoder within the kernel driver.Signed-off-by Dave Jiang <[email protected]>Fully agree with what should be happening here, but a question below on the implementation.
Quoted 35 lines
--- drivers/cxl/core/hdm.c | 3 +++ drivers/cxl/core/region.c | 16 ++++++++++++++++ drivers/cxl/cxl.h | 8 ++++++++ 3 files changed, 27 insertions(+)drivers/cxl/core/hdm.c +3
-0@@ -905,6 +905,9 @@ 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)) +return ; +if (port->commit_end == id)cxl_port_commit_reap (cxld);else drivers/cxl/core/region.c +3
-0@@ -419,6 +419,9 @@ static ssize_t commit_store(struct device *dev, struct device_attribute *attr,return len; } +if (test_bit (CXL_REGION_F_LOCK , &cxlr->flags)) +return -EPERM ; + rc =queue_reset (cxlr);if (rc)return rc;drivers/cxl/core/region.c static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr, · line 1071
Quoted 10 lines
drivers/cxl/core/region.c +7
-0@@ -1059,6 +1062,16 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr,return 0 ; } +static void cxl_region_set_lock (struct cxl_region *cxlr, +struct cxl_decoder *cxld) +{ +if (!test_bit (CXL_REGION_F_LOCK , &cxlr->flags)) +return ; + +set_bit (CXL_REGION_F_LOCK , &cxlr->flags);The sequence above here looks odd. If the bit is not set, then don't set it? If already set then set it again? Was one of these meant to be related to the decoder that was passed in?
Quoted 1 line
Maybe I need more coffee...
No. That's my mistake. It should be checking the cxld for locked bit and not the region.
DJ
Quoted 47 lines
Quoted 46 lines
drivers/cxl/core/region.c +6
-0+clear_bit (CXL_REGION_F_NEEDS_RESET , &cxlr->flags); +} +/** * cxl_port_attach_region() - track a region's interest in a port by endpoint * @port: port to add a new region reference 'struct cxl_region_ref' @@ -1170,6 +1183,8 @@ static int cxl_port_attach_region(struct cxl_port *port, } } +cxl_region_set_lock (cxlr, cxld); + rc =cxl_rr_ep_add (cxl_rr, cxled);if (rc) { dev_dbg(&cxlr->dev,@@ -2439,6 +2454,7 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i dev->bus = &cxl_bus_type; dev->type = &cxl_region_type; cxlr->id = id; +cxl_region_set_lock (cxlr, &cxlrd->cxlsd.cxld);return cxlr; }drivers/cxl/cxl.h +8
-0@@ -517,6 +517,14 @@ enum cxl_partition_mode {*/ #define CXL_REGION_F_NEEDS_RESET 1 +/* +* Indicate whether this region is locked due to 1 or more decoders that have +* been locked. The approach of all or nothing is taken with regard to the +* locked attribute. CXL_REGION_F_NEEDS_RESET should not be set if this flag is +* set. +*/ +#define CXL_REGION_F_LOCK 2 +/** * struct cxl_region - CXL region * @dev: This region's device base-commit:
211ddde0823f1442e4ad052a2f30f050145ccada
Quoted 39 lines · Dave Jiang
When a decoder is locked, it means that its configuration cannot be changed. CXL spec r3.2 8.2.4.20.13 discusses the details regarding locked decoders. Locking happens when bit 8 of the decoder control register is set and then the decoder is committed afterwards (CXL spec r3.2 8.2.4.20.7).
Given that the driver creates a virtual decoder for each CFMWS, the Fixed Device Configuration (bit 4) of the Window Restriction field is considered as locking for the virtual decoder by the driver.
The current driver code disregards the locked status and a region can be destroyed regardless of the locking state.
Add a region flag to indicate the region is in a locked configuration. The driver will considered a region locked if the CFMWS or any decoder is configured as locked. The consideration is all or nothing regarding the locked state. It is reasonable to determine the region "locked" status while the region is being assembled based on the decoders.
Add a check in region
commit_store()to intercept when a 0 is written to the commit sysfs attribute in order to prevent the destruction of a region when in locked state. This should be the only entry point from user space to destroy a region.Add a check is added to
cxl_decoder_reset()to prevent resetting a locked decoder within the kernel driver.Signed-off-by Dave Jiang <[email protected]>--- drivers/cxl/core/hdm.c | 3 +++ drivers/cxl/core/region.c | 16 ++++++++++++++++ drivers/cxl/cxl.h | 8 ++++++++ 3 files changed, 27 insertions(+)drivers/cxl/core/hdm.c +0
-0
drivers/cxl/core/hdm.c static void cxl_decoder_reset(struct cxl_decoder *cxld) · line 910
Quoted 6 lines
drivers/cxl/core/hdm.c +3
-0@@ -905,6 +905,9 @@ 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)) +return ; +
This is correct, but is it enough?
Would not the region teardown imply also the reset of those decoders in the path from the root port? Can we assume those will also be locked or should we add some sanity checking here?
Quoted 72 lines
drivers/cxl/core/hdm.c +0
-0if (port->commit_end == id)cxl_port_commit_reap (cxld);else drivers/cxl/core/region.c +16
-0@@ -419,6 +419,9 @@ static ssize_t commit_store(struct device *dev, struct device_attribute *attr,return len; } +if (test_bit (CXL_REGION_F_LOCK , &cxlr->flags)) +return -EPERM ; + rc =queue_reset (cxlr);if (rc)return rc;@@ -1059,6 +1062,16 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr,return 0 ; } +static void cxl_region_set_lock (struct cxl_region *cxlr, +struct cxl_decoder *cxld) +{ +if (!test_bit (CXL_REGION_F_LOCK , &cxlr->flags)) +return ; + +set_bit (CXL_REGION_F_LOCK , &cxlr->flags); +clear_bit (CXL_REGION_F_NEEDS_RESET , &cxlr->flags); +} +/** * cxl_port_attach_region() - track a region's interest in a port by endpoint * @port: port to add a new region reference 'struct cxl_region_ref' @@ -1170,6 +1183,8 @@ static int cxl_port_attach_region(struct cxl_port *port, } } +cxl_region_set_lock (cxlr, cxld); + rc =cxl_rr_ep_add (cxl_rr, cxled);if (rc) { dev_dbg(&cxlr->dev,@@ -2439,6 +2454,7 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i dev->bus = &cxl_bus_type; dev->type = &cxl_region_type; cxlr->id = id; +cxl_region_set_lock (cxlr, &cxlrd->cxlsd.cxld);return cxlr; }drivers/cxl/cxl.h +8
-0@@ -517,6 +517,14 @@ enum cxl_partition_mode {*/ #define CXL_REGION_F_NEEDS_RESET 1 +/* +* Indicate whether this region is locked due to 1 or more decoders that have +* been locked. The approach of all or nothing is taken with regard to the +* locked attribute. CXL_REGION_F_NEEDS_RESET should not be set if this flag is +* set. +*/ +#define CXL_REGION_F_LOCK 2 +/** * struct cxl_region - CXL region * @dev: This region's device base-commit:
211ddde0823f1442e4ad052a2f30f050145ccada
Dave Jiang
maintainerQuoted 51 lines · Alejandro Lucero Palau
Quoted 39 lines · Dave Jiang
When a decoder is locked, it means that its configuration cannot be changed. CXL spec r3.2 8.2.4.20.13 discusses the details regarding locked decoders. Locking happens when bit 8 of the decoder control register is set and then the decoder is committed afterwards (CXL spec r3.2 8.2.4.20.7).
Given that the driver creates a virtual decoder for each CFMWS, the Fixed Device Configuration (bit 4) of the Window Restriction field is considered as locking for the virtual decoder by the driver.
The current driver code disregards the locked status and a region can be destroyed regardless of the locking state.
Add a region flag to indicate the region is in a locked configuration. The driver will considered a region locked if the CFMWS or any decoder is configured as locked. The consideration is all or nothing regarding the locked state. It is reasonable to determine the region "locked" status while the region is being assembled based on the decoders.
Add a check in region
commit_store()to intercept when a 0 is written to the commit sysfs attribute in order to prevent the destruction of a region when in locked state. This should be the only entry point from user space to destroy a region.Add a check is added to
cxl_decoder_reset()to prevent resetting a locked decoder within the kernel driver.Signed-off-by Dave Jiang <[email protected]>---
drivers/cxl/core/hdm.c | 3 +++
drivers/cxl/core/region.c| 16 ++++++++++++++++
drivers/cxl/cxl.h | 8 ++++++++3 files changed, 27 insertions(+)drivers/cxl/core/hdm.c +0
-0drivers/cxl/core/hdm.c static void cxl_decoder_reset(struct cxl_decoder *cxld) · line 909
Quoted 5 lines
drivers/cxl/core/hdm.c +2
-0@@ -905,6 +905,9 @@ 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)) + return; +This is correct, but is it enough?
Quoted 1 line
Would not the region teardown imply also the reset of those decoders in the path from the root port? Can we assume those will also be locked or should we add some sanity checking here?
Would checking the region the decoder belongs to for lock flag be sufficient?
DJ
Quoted 69 lines
Quoted 69 lines
drivers/cxl/core/hdm.c +0
-0if (port->commit_end == id) cxl_port_commit_reap(cxld);else
drivers/cxl/core/region.c +13
-0@@ -419,6 +419,9 @@ static ssize_t commit_store(struct device *dev, struct device_attribute *attr, return len; } + if (test_bit(CXL_REGION_F_LOCK, &cxlr->flags)) + return -EPERM; + rc = queue_reset(cxlr); if (rc) return rc;@@ -1059,6 +1062,16 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr, return 0; } +static void cxl_region_set_lock(struct cxl_region *cxlr, + struct cxl_decoder *cxld) +{ + if (!test_bit(CXL_REGION_F_LOCK, &cxlr->flags)) + return; + + set_bit(CXL_REGION_F_LOCK, &cxlr->flags); + clear_bit(CXL_REGION_F_NEEDS_RESET, &cxlr->flags); +} + /*** cxl_port_attach_region() - track a region's interest in a port by endpoint * @port: port to add a new region reference 'struct cxl_region_ref' @@ -1170,6 +1183,8 @@ static int cxl_port_attach_region(struct cxl_port *port, } } + cxl_region_set_lock(cxlr, cxld); + rc = cxl_rr_ep_add(cxl_rr, cxled); if (rc) { dev_dbg(&cxlr->dev,@@ -2439,6 +2454,7 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i dev->bus = &cxl_bus_type; dev->type = &cxl_region_type; cxlr->id = id; + cxl_region_set_lock(cxlr, &cxlrd->cxlsd.cxld); return cxlr; }drivers/cxl/cxl.h +0
-0@@ -517,6 +517,14 @@ enum cxl_partition_mode {*/ #define CXL_REGION_F_NEEDS_RESET 1+/*
+ * Indicate whether this region is locked due to 1 or more decoders that have
+ * been locked. The approach of all or nothing is taken with regard to the
+ * locked attribute.CXL_REGION_F_NEEDS_RESETshould not be set if this flag is
+ * set.
+ */drivers/cxl/cxl.h +2
-0+#define CXL_REGION_F_LOCK 2 +/**
* structcxl_region- CXL region
* @dev: This region's devicebase-commit:
211ddde0823f1442e4ad052a2f30f050145ccada
Quoted 51 lines · Dave Jiang
Quoted 49 lines · Alejandro Lucero Palau
Quoted 39 lines · Dave Jiang
When a decoder is locked, it means that its configuration cannot be changed. CXL spec r3.2 8.2.4.20.13 discusses the details regarding locked decoders. Locking happens when bit 8 of the decoder control register is set and then the decoder is committed afterwards (CXL spec r3.2 8.2.4.20.7).
Given that the driver creates a virtual decoder for each CFMWS, the Fixed Device Configuration (bit 4) of the Window Restriction field is considered as locking for the virtual decoder by the driver.
The current driver code disregards the locked status and a region can be destroyed regardless of the locking state.
Add a region flag to indicate the region is in a locked configuration. The driver will considered a region locked if the CFMWS or any decoder is configured as locked. The consideration is all or nothing regarding the locked state. It is reasonable to determine the region "locked" status while the region is being assembled based on the decoders.
Add a check in region
commit_store()to intercept when a 0 is written to the commit sysfs attribute in order to prevent the destruction of a region when in locked state. This should be the only entry point from user space to destroy a region.Add a check is added to
cxl_decoder_reset()to prevent resetting a locked decoder within the kernel driver.Signed-off-by Dave Jiang <[email protected]>--- drivers/cxl/core/hdm.c | 3 +++ drivers/cxl/core/region.c | 16 ++++++++++++++++ drivers/cxl/cxl.h | 8 ++++++++ 3 files changed, 27 insertions(+)drivers/cxl/core/hdm.c +0
-0drivers/cxl/core/hdm.c static void cxl_decoder_reset(struct cxl_decoder *cxld) · line 909
Quoted 5 lines
drivers/cxl/core/hdm.c +2
-0@@ -905,6 +905,9 @@ 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)) + return; +This is correct, but is it enough?
Quoted 2 lines
Quoted 1 line
Would not the region teardown imply also the reset of those decoders in the path from the root port? Can we assume those will also be locked or should we add some sanity checking here?
Would checking the region the decoder belongs to for lock flag be sufficient?
Yes, so any trying for removing the region failing, but maybe I'm confused with this check inside cxl_decoder_reset which implies to me such a region is being removed. I would expect a check in cxl_region_decode_reset which invokes this other function.
But my point is if we should check, maybe just at region creation time, if all the involved decoders have the lock bit set for coherency, assuming here the specs refer to such "locking path". Does locking an endpoint HDM decoder, by firmware or driver, implies the locking of the related decoders creating the path?
Quoted 70 lines
DJ
Quoted 68 lines
Quoted 68 lines
drivers/cxl/core/hdm.c +0
-0if (port->commit_end == id) cxl_port_commit_reap(cxld); elsedrivers/cxl/core/region.c +13
-0@@ -419,6 +419,9 @@ static ssize_t commit_store(struct device *dev, struct device_attribute *attr, return len; } + if (test_bit(CXL_REGION_F_LOCK, &cxlr->flags)) + return -EPERM; + rc = queue_reset(cxlr); if (rc) return rc;@@ -1059,6 +1062,16 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr, return 0; } +static void cxl_region_set_lock(struct cxl_region *cxlr, + struct cxl_decoder *cxld) +{ + if (!test_bit(CXL_REGION_F_LOCK, &cxlr->flags)) + return; + + set_bit(CXL_REGION_F_LOCK, &cxlr->flags); + clear_bit(CXL_REGION_F_NEEDS_RESET, &cxlr->flags); +} + /*** cxl_port_attach_region() - track a region's interest in a port by endpoint * @port: port to add a new region reference 'struct cxl_region_ref' @@ -1170,6 +1183,8 @@ static int cxl_port_attach_region(struct cxl_port *port, } } + cxl_region_set_lock(cxlr, cxld); + rc = cxl_rr_ep_add(cxl_rr, cxled); if (rc) { dev_dbg(&cxlr->dev,@@ -2439,6 +2454,7 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i dev->bus = &cxl_bus_type; dev->type = &cxl_region_type; cxlr->id = id; + cxl_region_set_lock(cxlr, &cxlrd->cxlsd.cxld); return cxlr; }drivers/cxl/cxl.h +7
-0@@ -517,6 +517,14 @@ enum cxl_partition_mode {*/ #define CXL_REGION_F_NEEDS_RESET 1 +/* +* Indicate whether this region is locked due to 1 or more decoders that have +* been locked. The approach of all or nothing is taken with regard to the +* locked attribute. CXL_REGION_F_NEEDS_RESET should not be set if this flag is +* set. +*/ +#define CXL_REGION_F_LOCK 2 + /*** struct cxl_region - CXL region * @dev: This region's device base-commit:
211ddde0823f1442e4ad052a2f30f050145ccada
Dave Jiang
maintainerQuoted 53 lines · Alejandro Lucero Palau
Quoted 51 lines · Dave Jiang
Quoted 49 lines · Alejandro Lucero Palau
Quoted 39 lines · Dave Jiang
When a decoder is locked, it means that its configuration cannot be changed. CXL spec r3.2 8.2.4.20.13 discusses the details regarding locked decoders. Locking happens when bit 8 of the decoder control register is set and then the decoder is committed afterwards (CXL spec r3.2 8.2.4.20.7).
Given that the driver creates a virtual decoder for each CFMWS, the Fixed Device Configuration (bit 4) of the Window Restriction field is considered as locking for the virtual decoder by the driver.
The current driver code disregards the locked status and a region can be destroyed regardless of the locking state.
Add a region flag to indicate the region is in a locked configuration. The driver will considered a region locked if the CFMWS or any decoder is configured as locked. The consideration is all or nothing regarding the locked state. It is reasonable to determine the region "locked" status while the region is being assembled based on the decoders.
Add a check in region
commit_store()to intercept when a 0 is written to the commit sysfs attribute in order to prevent the destruction of a region when in locked state. This should be the only entry point from user space to destroy a region.Add a check is added to
cxl_decoder_reset()to prevent resetting a locked decoder within the kernel driver.Signed-off-by Dave Jiang <[email protected]>---
drivers/cxl/core/hdm.c | 3 +++drivers/cxl/core/region.c| 16 ++++++++++++++++ drivers/cxl/cxl.h | 8 ++++++++3 files changed, 27 insertions(+)drivers/cxl/core/hdm.c +0
-0drivers/cxl/core/hdm.c static void cxl_decoder_reset(struct cxl_decoder *cxld) · line 909
Quoted 5 lines
drivers/cxl/core/hdm.c +2
-0@@ -905,6 +905,9 @@ 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)) + return; +This is correct, but is it enough?
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
Would not the region teardown imply also the reset of those decoders in the path from the root port? Can we assume those will also be locked or should we add some sanity checking here?
Would checking the region the decoder belongs to for lock flag be sufficient?
Yes, so any trying for removing the region failing, but maybe I'm confused with this check inside
cxl_decoder_resetwhich implies to me such a region is being removed. I would expect a check incxl_region_decode_resetwhich invokes this other function.
Yeah you are right, we should do the region lock check at cxl_region_decode_reset() and just leave the simple decoder lock check to cxl_decoder_reset(). >
Quoted 2 lines
But my point is if we should check, maybe just at region creation time, if all the involved decoders have the lock bit set for coherency, assuming here the specs refer to such "locking path". Does locking an endpoint HDM decoder, by firmware or driver, implies the locking of the related decoders creating the path?
I'm not sure if the spec implies that. At least currently I'm setting that as a Linux policy to make things simple. We can consider altering that in the future if there's some specific case to consider that goes opposing to that.
DJ
Quoted 72 lines
Quoted 72 lines
DJ
Quoted 68 lines
Quoted 68 lines
drivers/cxl/core/hdm.c +0
-0if (port->commit_end == id) cxl_port_commit_reap(cxld);else
drivers/cxl/core/region.c +13
-0@@ -419,6 +419,9 @@ static ssize_t commit_store(struct device *dev, struct device_attribute *attr, return len; } + if (test_bit(CXL_REGION_F_LOCK, &cxlr->flags)) + return -EPERM; + rc = queue_reset(cxlr); if (rc) return rc;@@ -1059,6 +1062,16 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr, return 0; } +static void cxl_region_set_lock(struct cxl_region *cxlr, + struct cxl_decoder *cxld) +{ + if (!test_bit(CXL_REGION_F_LOCK, &cxlr->flags)) + return; + + set_bit(CXL_REGION_F_LOCK, &cxlr->flags); + clear_bit(CXL_REGION_F_NEEDS_RESET, &cxlr->flags); +} + /*** cxl_port_attach_region() - track a region's interest in a port by endpoint * @port: port to add a new region reference 'struct cxl_region_ref' @@ -1170,6 +1183,8 @@ static int cxl_port_attach_region(struct cxl_port *port, } } + cxl_region_set_lock(cxlr, cxld); + rc = cxl_rr_ep_add(cxl_rr, cxled); if (rc) { dev_dbg(&cxlr->dev,@@ -2439,6 +2454,7 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i dev->bus = &cxl_bus_type; dev->type = &cxl_region_type; cxlr->id = id; + cxl_region_set_lock(cxlr, &cxlrd->cxlsd.cxld); return cxlr; }drivers/cxl/cxl.h +0
-0@@ -517,6 +517,14 @@ enum cxl_partition_mode {*/ #define CXL_REGION_F_NEEDS_RESET 1+/*
+ * Indicate whether this region is locked due to 1 or more decoders that have
+ * been locked. The approach of all or nothing is taken with regard to the
+ * locked attribute.CXL_REGION_F_NEEDS_RESETshould not be set if this flag is
+ * set.
+ */drivers/cxl/cxl.h +2
-0+#define CXL_REGION_F_LOCK 2 +/**
* structcxl_region- CXL region
* @dev: This region's devicebase-commit:
211ddde0823f1442e4ad052a2f30f050145ccada