Re: [PATCH ndctl RESEND] test/cxl-event: Skip cxl event testing if cxl-test is not available

2023-09-25 Thread Dave Jiang



On 9/25/23 15:16, Ira Weiny wrote:
> CXL event testing is only appropriate when the cxl-test modules are
> available.
> 
> Return error 77 (skip) if cxl-test modules are not available.
> 
> Reported-by: Dave Jiang 
> Signed-off-by: Ira Weiny 

Reviewed-by: Dave Jiang 
> ---
> Changes for resend:
> - iweiny: properly cc the mailing lists
> ---
>  test/cxl-events.sh | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/test/cxl-events.sh b/test/cxl-events.sh
> index 33b68daa6ade..fe702bf98ad4 100644
> --- a/test/cxl-events.sh
> +++ b/test/cxl-events.sh
> @@ -10,6 +10,8 @@ num_fatal_expected=2
>  num_failure_expected=16
>  num_info_expected=3
>  
> +rc=77
> +
>  set -ex
>  
>  trap 'err $LINENO' ERR
> @@ -18,6 +20,7 @@ check_prereq "jq"
>  
>  modprobe -r cxl_test
>  modprobe cxl_test
> +rc=1
>  
>  dev_path="/sys/bus/platform/devices"
>  
> 
> ---
> base-commit: a871e6153b11fe63780b37cdcb1eb347b296095c
> change-id: 20230925-skip-cxl-events-7f16052b9c4e
> 
> Best regards,



[PATCH ndctl RESEND] test/cxl-event: Skip cxl event testing if cxl-test is not available

2023-09-25 Thread Ira Weiny
CXL event testing is only appropriate when the cxl-test modules are
available.

Return error 77 (skip) if cxl-test modules are not available.

Reported-by: Dave Jiang 
Signed-off-by: Ira Weiny 
---
Changes for resend:
- iweiny: properly cc the mailing lists
---
 test/cxl-events.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/test/cxl-events.sh b/test/cxl-events.sh
index 33b68daa6ade..fe702bf98ad4 100644
--- a/test/cxl-events.sh
+++ b/test/cxl-events.sh
@@ -10,6 +10,8 @@ num_fatal_expected=2
 num_failure_expected=16
 num_info_expected=3
 
+rc=77
+
 set -ex
 
 trap 'err $LINENO' ERR
@@ -18,6 +20,7 @@ check_prereq "jq"
 
 modprobe -r cxl_test
 modprobe cxl_test
+rc=1
 
 dev_path="/sys/bus/platform/devices"
 

---
base-commit: a871e6153b11fe63780b37cdcb1eb347b296095c
change-id: 20230925-skip-cxl-events-7f16052b9c4e

Best regards,
-- 
Ira Weiny 




[PATCH 2/2] cxl: Add check for regions before disabling memdev

2023-09-25 Thread Dave Jiang
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 
---
 cxl/memdev.c |   29 +++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/cxl/memdev.c b/cxl/memdev.c
index f6a2d3f1fdca..644369321649 100644
--- a/cxl/memdev.c
+++ b/cxl/memdev.c
@@ -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(, "%s is part of an active region\n",
cxl_memdev_get_devname(memdev));
return -EBUSY;





[PATCH 1/2] cxl: Save the decoder committed state

2023-09-25 Thread Dave Jiang
Save the decoder committed state exported by the kernel to the libcxl
decoder context. The attribute is helpful for determing if a region is active.
Add libcxl API to determine if decoder is committed.
Add the committed state to the decoder for cxl list command.

Links: 
https://lore.kernel.org/linux-cxl/169566515694.3697523.714600762835841180.stgit@djiang5-mobl3/
Signed-off-by: Dave Jiang 
---
 Documentation/cxl/lib/libcxl.txt |4 
 cxl/json.c   |4 
 cxl/lib/libcxl.c |9 +
 cxl/lib/libcxl.sym   |5 +
 cxl/lib/private.h|1 +
 cxl/libcxl.h |1 +
 6 files changed, 24 insertions(+)

diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt
index 31bc85511270..4a2d1affa5a7 100644
--- a/Documentation/cxl/lib/libcxl.txt
+++ b/Documentation/cxl/lib/libcxl.txt
@@ -424,6 +424,7 @@ bool cxl_decoder_is_volatile_capable(struct cxl_decoder 
*decoder);
 bool cxl_decoder_is_mem_capable(struct cxl_decoder *decoder);
 bool cxl_decoder_is_accelmem_capable(struct cxl_decoder *decoder);
 bool cxl_decoder_is_locked(struct cxl_decoder *decoder);
+bool cxl_decoder_is_committed(struct cxl_decoder *decoder);
 
 The kernel protects the enumeration of the physical address layout of
 the system. Without CAP_SYS_ADMIN cxl_decoder_get_resource() returns
@@ -449,6 +450,9 @@ Platform firmware may setup the CXL decode hierarchy before 
the OS
 boots, and may additionally require that the OS not change the decode
 settings. This property is indicated by the cxl_decoder_is_locked() API.
 
+cxl_decoder_is_committed() provides a snapshot of the decoder state
+from the OS indicating if the decoder is committed or free.
+
 When a decoder is associated with a region cxl_decoder_get_region()
 returns that region object. Note that it is only applicable to switch
 and endpoint decoders as root decoders have a 1:N relationship with
diff --git a/cxl/json.c b/cxl/json.c
index 7678d02020b6..56ab42c747a0 100644
--- a/cxl/json.c
+++ b/cxl/json.c
@@ -857,6 +857,10 @@ struct json_object *util_cxl_decoder_to_json(struct 
cxl_decoder *decoder,
   jobj);
}
 
+   jobj = json_object_new_boolean(cxl_decoder_is_committed(decoder));
+   if (jobj)
+   json_object_object_add(jdecoder, "committed", jobj);
+
json_object_set_userdata(jdecoder, decoder, NULL);
return jdecoder;
 }
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index af4ca44eae19..094e14d6be8f 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -2116,6 +2116,10 @@ static void *add_cxl_decoder(void *parent, int id, const 
char *cxldecoder_base)
else
decoder->interleave_ways = strtoul(buf, NULL, 0);
 
+   sprintf(path, "%s/committed", cxldecoder_base);
+   if (sysfs_read_attr(ctx, path, buf) == 0)
+   decoder->committed = !!strtoul(buf, NULL, 0);
+
switch (port->type) {
case CXL_PORT_ENDPOINT:
sprintf(path, "%s/dpa_resource", cxldecoder_base);
@@ -2464,6 +2468,11 @@ CXL_EXPORT bool cxl_decoder_is_locked(struct cxl_decoder 
*decoder)
return decoder->locked;
 }
 
+CXL_EXPORT bool cxl_decoder_is_committed(struct cxl_decoder *decoder)
+{
+   return decoder->committed;
+}
+
 CXL_EXPORT unsigned int
 cxl_decoder_get_interleave_granularity(struct cxl_decoder *decoder)
 {
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
index 8fa1cca3d0d7..eb8b5829851d 100644
--- a/cxl/lib/libcxl.sym
+++ b/cxl/lib/libcxl.sym
@@ -264,3 +264,8 @@ global:
cxl_memdev_update_fw;
cxl_memdev_cancel_fw_update;
 } LIBCXL_5;
+
+LIBCXL_7 {
+global:
+   cxl_decoder_is_committed;
+} LIBCXL_6;
diff --git a/cxl/lib/private.h b/cxl/lib/private.h
index a641727000f1..c79190827258 100644
--- a/cxl/lib/private.h
+++ b/cxl/lib/private.h
@@ -139,6 +139,7 @@ struct cxl_decoder {
bool mem_capable;
bool accelmem_capable;
bool locked;
+   bool committed;
enum cxl_decoder_target_type target_type;
int regions_init;
struct list_head targets;
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
index 0f4f4b2648fb..a7fad3e30055 100644
--- a/cxl/libcxl.h
+++ b/cxl/libcxl.h
@@ -245,6 +245,7 @@ bool cxl_decoder_is_volatile_capable(struct cxl_decoder 
*decoder);
 bool cxl_decoder_is_mem_capable(struct cxl_decoder *decoder);
 bool cxl_decoder_is_accelmem_capable(struct cxl_decoder *decoder);
 bool cxl_decoder_is_locked(struct cxl_decoder *decoder);
+bool cxl_decoder_is_committed(struct cxl_decoder *decoder);
 unsigned int
 cxl_decoder_get_interleave_granularity(struct cxl_decoder *decoder);
 unsigned int cxl_decoder_get_interleave_ways(struct cxl_decoder *decoder);