@@ -373,11 +373,36 @@ static int action_free_dpa(struct cxl_memdev *memdev,
static int action_disable(struct cxl_memdev *memdev, struct action_context *actx)
{
+ struct cxl_decoder *decoder;
+ struct cxl_endpoint *ep;
+ bool committed = false;
+ struct cxl_port *port;
+
if (!cxl_memdev_is_enabled(memdev))
return 0;
- if (!param.force) {
- /* TODO: actually detect rather than assume active */
+ ep = cxl_memdev_get_endpoint(memdev);
+ if (!ep)
+ return -ENODEV;
+
+ port = cxl_endpoint_get_port(ep);
+ if (!port)
+ return -ENODEV;
+
+ /*
+ * Look for a committed decoder, which indicates that the region the
+ * memdev belongs to is active. This is best effort as the decoder
+ * state is pulled from sysfs and not atomic. The caller should be in
+ * control of the device to prevent state changes for the decoder.
+ */
+ cxl_decoder_foreach(port, decoder) {
+ if (cxl_decoder_is_committed(decoder)) {
+ committed = true;
+ break;
+ }
+ }
+
+ if (committed && !param.force) {
log_err(&ml, "%s is part of an active region\n",
cxl_memdev_get_devname(memdev));
return -EBUSY;
Add a check for memdev disable to see if there are active regions present before disabling the device. This is necessary now regions are present to fulfill the TODO that was left there. The best way to determine if a region is active is to see if there are decoders enabled for the mem device. This is also best effort as the state is only a snapshot the kernel provides and is not atomic WRT the memdev disable operation. The expectation is the admin issuing the command has full control of the mem device and there are no other agents also attempt to control the device. Signed-off-by: Dave Jiang <dave.jiang@intel.com> --- cxl/memdev.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)