cxl/monitor: coverity and misc other fixes
Vishal Verma
maintainercover cxl/monitor: coverity and misc other fixes
Fix a couple of issues reported by Coverity in the cxl-monitor code, and an async probe wait in the cxl=security.sh test.
---
Vishal Verma (3):
cxl/event_trace: fix a resource leak in cxl_event_to_json() cxl/monitor: retain error code in monitor_event() test/cxl-security.sh: avoid intermittent failures due to sasync probe
cxl/event_trace.c | 3 ++- cxl/monitor.c | 3 ++- test/security.sh | 1 + 3 files changed, 5 insertions(+), 2 deletions(-)
---
base-commit: a88bdcfb4202c73aadfee6f83c5502eb5121cbd9
change-id: 20230217-coverity-fixes-e1d3f8bc2cfb
Best regards,
Signature · 1 line
Vishal Verma <[email protected]>
Vishal Verma
maintainerPATCH 1/3 cxl/event_trace: fix a resource leak in cxl_event_to_json()
Static analysis reports that a 'return -ENOMEM' in the above function bypasses the error unwinding and leaks 'jevent'.
Fix the error handling to use the right goto sequence before returning.
--- cxl/event_trace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
cxl/event_trace.c +2 -1
@@ -142,7 +142,8 @@ static int cxl_event_to_json(struct tep_event *event, struct tep_record *record, jobj =num_to_json (data, f->elementsize, f->flags);if (!jobj) {json_object_put (jarray); -return -ENOMEM ; + rc = -ENOMEM ; + goto err_jevent; }json_object_array_add (jarray, jobj); data += f->elementsize;
Signature · 1 line
2.39.1
Re: [PATCH ndctl 1/3] cxl/event_trace: fix a resource leak in cxl_event_to_json()
Quoted 9 lines · Vishal Verma
Static analysis reports that a 'return
-ENOMEM' in the above function bypasses the error unwinding and leaks 'jevent'.Fix the error handling to use the right goto sequence before returning.
Fixes 8dedc6cf5e85 ("cxl: add a helper to parse trace events into a json object")Cc Dave Jiang <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Quoted 19 lines
--- cxl/event_trace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)cxl/event_trace.c +2
-1@@ -142,7 +142,8 @@ static int cxl_event_to_json(struct tep_event *event, struct tep_record *record, jobj =num_to_json (data, f->elementsize, f->flags);if (!jobj) {json_object_put (jarray); -return -ENOMEM ; + rc = -ENOMEM ; + goto err_jevent; }json_object_array_add (jarray, jobj); data += f->elementsize;
Re: [PATCH ndctl 1/3] cxl/event_trace: fix a resource leak in cxl_event_to_json()
In reply to Vishal VermaQuoted 8 lines · Vishal Verma
Static analysis reports that a 'return
-ENOMEM' in the above function bypasses the error unwinding and leaks 'jevent'.Fix the error handling to use the right goto sequence before returning.
Fixes 8dedc6cf5e85 ("cxl: add a helper to parse trace events into a json object")Cc Dave Jiang <[email protected]>Cc Dan Williams <[email protected]>
Quoted 24 lines
Signed-off-by Vishal Verma <[email protected]>--- cxl/event_trace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)cxl/event_trace.c +2
-1@@ -142,7 +142,8 @@ static int cxl_event_to_json(struct tep_event *event, struct tep_record *record, jobj =num_to_json (data, f->elementsize, f->flags);if (!jobj) {json_object_put (jarray); -return -ENOMEM ; + rc = -ENOMEM ; + goto err_jevent; }json_object_array_add (jarray, jobj); data += f->elementsize;Signature · 2 lines
-- 2.39.1
Vishal Verma
maintainerPATCH 2/3 cxl/monitor: retain error code in monitor_event()
In reply to Vishal VermaStatic analysis reports that the error unwinding path in monitor_event() overwrites 'rc' with the return from cxl_event_tracing_disable(). This masks the actual error code from either epoll_wait() or cxl_parse_events() which is the one that should be propagated.
Print a spot error in case there's an error while disabling tracing, but otherwise retain the rc from the main body of the function.
--- cxl/monitor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
cxl/monitor.c +2 -1
@@ -130,7 +130,8 @@ static int monitor_event(struct cxl_ctx *ctx) } parse_err: - rc =cxl_event_tracing_disable (inst); +if (cxl_event_tracing_disable (inst) <0 ) +err (&monitor,"failed to disable tracing\n" ); event_en_err: epoll_ctl_err:close (fd);
Signature · 1 line
2.39.1
Re: [PATCH ndctl 2/3] cxl/monitor: retain error code in monitor_event()
Quoted 5 lines · Vishal Verma
Static analysis reports that the error unwinding path in
monitor_event()overwrites 'rc' with the return fromcxl_event_tracing_disable(). This masks the actual error code from eitherepoll_wait()orcxl_parse_events()which is the one that should be propagated.
Quoted 7 lines
Print a spot error in case there's an error while disabling tracing, but otherwise retain the rc from the main body of the function.
Fixes 299f69f974a6 ("cxl/monitor: add a new monitor command for CXL trace events")Cc Dave Jiang <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Quoted 19 lines
--- cxl/monitor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)cxl/monitor.c +2
-1@@ -130,7 +130,8 @@ static int monitor_event(struct cxl_ctx *ctx) } parse_err: - rc =cxl_event_tracing_disable (inst); +if (cxl_event_tracing_disable (inst) <0 ) +err (&monitor,"failed to disable tracing\n" ); event_en_err: epoll_ctl_err:close (fd);
Re: [PATCH ndctl 2/3] cxl/monitor: retain error code in monitor_event()
In reply to Vishal VermaQuoted 21 lines · Vishal Verma
Static analysis reports that the error unwinding path in
monitor_event()overwrites 'rc' with the return fromcxl_event_tracing_disable(). This masks the actual error code from eitherepoll_wait()orcxl_parse_events()which is the one that should be propagated.Print a spot error in case there's an error while disabling tracing, but otherwise retain the rc from the main body of the function.
Fixes 299f69f974a6 ("cxl/monitor: add a new monitor command for CXL trace events")Cc Dave Jiang <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- cxl/monitor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)cxl/monitor.c +0
-0
cxl/monitor.c static int monitor_event(struct cxl_ctx *ctx) · line 134
Quoted 6 lines
cxl/monitor.c +2
-1@@ -130,7 +130,8 @@ static int monitor_event(struct cxl_ctx *ctx) } parse_err: - rc =cxl_event_tracing_disable (inst); +if (cxl_event_tracing_disable (inst) <0 ) +err (&monitor,"failed to disable tracing\n" );
Is this even worth printing? Perhaps just makecxl_event_tracing_disable() return void?
Either way:
Quoted 8 lines
cxl/monitor.c +0
-0event_en_err: epoll_ctl_err:close (fd);Signature · 2 lines
-- 2.39.1
Verma, Vishal L
maintainerRe: [PATCH ndctl 2/3] cxl/monitor: retain error code in monitor_event()
Quoted 17 lines · Ira Weiny
Quoted 16 lines · Vishal Verma
Static analysis reports that the error unwinding path in
monitor_event()overwrites 'rc' with the return fromcxl_event_tracing_disable(). This masks the actual error code from eitherepoll_wait()orcxl_parse_events()which is the one that should be propagated.Print a spot error in case there's an error while disabling tracing, but otherwise retain the rc from the main body of the function.
Fixes 299f69f974a6 ("cxl/monitor: add a new monitor command for CXL trace events")Cc Dave Jiang <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>---
cxl/monitor.c | 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines
Quoted 11 lines
cxl/monitor.c +0
-0@@ -130,7 +130,8 @@ static int monitor_event(struct cxl_ctx *ctx) }
parse_err:
- rc =cxl_event_tracing_disable(inst);
+ if (cxl_event_tracing_disable(inst)< 0)
+ err(&monitor, "failed to disable tracing\n");Is this even worth printing? Perhaps just make
cxl_event_tracing_disable()return void?
I thought about it, but the underlying tracefs_trace_off() returns an int, which is probably why cxl_event_tracing_disable() does too. Having the print satisfies static analyzers that we're checking the return value - other than that I agree it doesn't add much.
Quoted 4 lines
Either way:
Reviewed-by Ira Weiny <[email protected]>
Thanks Ira!
Quoted 11 lines
Quoted 9 lines
event_en_err:
epoll_ctl_err:
close(fd);Signature · 1 line
2.39.1
Vishal Verma
maintainerPATCH 3/3 test/cxl-security.sh: avoid intermittent failures due to sasync probe
In reply to Vishal VermaThis test failed intermittently because the ndctl-list operation right after a 'modprobe cxl_test' could race the actual nmem devices getting loaded.
Since CXL device probes are asynchronous, and cxl_acpi might've kicked off a cxl_bus_rescan(), a cxl_flush() (via cxl_wait_probe()) can ensure everything is loaded.
Add a plain cxl-list right after the modprobe to allow for a flush/wait cycle.
--- test/security.sh | 1 + 1 file changed, 1 insertion(+)
test/security.sh +1 -0
@@ -225,6 +225,7 @@ if [ "$uid" -ne 0 ]; then fi modprobe "$KMOD_TEST" +cxl list setup check_prereq "keyctl" rc=1
Signature · 1 line
2.39.1
Re: [PATCH ndctl 3/3] test/cxl-security.sh: avoid intermittent failures due to sasync probe
Quoted 8 lines · Vishal Verma
This test failed intermittently because the ndctl-list operation right after a 'modprobe
cxl_test' could race the actual nmem devices getting loaded.Since CXL device probes are asynchronous, and
cxl_acpimight've kicked off acxl_bus_rescan(), acxl_flush()(viacxl_wait_probe()) can ensure everything is loaded.
Quoted 6 lines
Add a plain cxl-list right after the modprobe to allow for a flush/wait cycle.
Cc Dave Jiang <[email protected]>Suggested-by Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Quoted 17 lines
--- test/security.sh | 1 + 1 file changed, 1 insertion(+)test/security.sh +1
-0@@ -225,6 +225,7 @@ if [ "$uid" -ne 0 ]; then fi modprobe "$KMOD_TEST" +cxl list setup check_prereq "keyctl" rc=1
Alison Schofield
maintainerRe: [PATCH ndctl 3/3] test/cxl-security.sh: avoid intermittent failures due to sasync probe
In reply to Vishal VermaQuoted 10 lines · Vishal Verma
This test failed intermittently because the ndctl-list operation right after a 'modprobe
cxl_test' could race the actual nmem devices getting loaded.Since CXL device probes are asynchronous, and
cxl_acpimight've kicked off acxl_bus_rescan(), acxl_flush()(viacxl_wait_probe()) can ensure everything is loaded.Add a plain cxl-list right after the modprobe to allow for a flush/wait cycle.
Is this the preferred method to 'settle', instead of udevadm settle?
Quoted 25 lines
Cc Dave Jiang <[email protected]>Suggested-by Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- test/security.sh | 1 + 1 file changed, 1 insertion(+)test/security.sh +1
-0@@ -225,6 +225,7 @@ if [ "$uid" -ne 0 ]; then fi modprobe "$KMOD_TEST" +cxl list setup check_prereq "keyctl" rc=1Signature · 2 lines
-- 2.39.1
Re: [PATCH ndctl 3/3] test/cxl-security.sh: avoid intermittent failures due to sasync probe
Quoted 5 lines · Alison Schofield
Quoted 4 lines · Vishal Verma
This test failed intermittently because the ndctl-list operation right after a 'modprobe
cxl_test' could race the actual nmem devices getting loaded.
Quoted 8 lines
Quoted 6 lines
Since CXL device probes are asynchronous, and
cxl_acpimight've kicked off acxl_bus_rescan(), acxl_flush()(viacxl_wait_probe()) can ensure everything is loaded.Add a plain cxl-list right after the modprobe to allow for a flush/wait cycle.
Is this the preferred method to 'settle', instead of udevadm settle?
In general, 'udevadm settle' is only the first phase of flushing subsystem setup work in that it can only flush the udev event queue. I.e. a device arriving kicks off a KOBJ_ADD event, and once that event is processed without kicking off more KOBJ_* events the queue is settled. For CXL this means that the cxl_acpi and cxl_pci modules are loaded, but the asynchronous work they kick off to probe devices and rescan the bus is invisible to 'udevadm settle'.
Internally 'cxl list' is performing a 'udevadm settle' and then flushing the follow on async work.
Verma, Vishal L
maintainerRe: [PATCH ndctl 3/3] test/cxl-security.sh: avoid intermittent failures due to sasync probe
In reply to Alison SchofieldQuoted 5 lines · Alison Schofield
Quoted 4 lines · Vishal Verma
This test failed intermittently because the ndctl-list operation right after a 'modprobe
cxl_test' could race the actual nmem devices getting loaded.
Quoted 8 lines
Quoted 6 lines
Since CXL device probes are asynchronous, and
cxl_acpimight've kicked off acxl_bus_rescan(), acxl_flush()(viacxl_wait_probe()) can ensure everything is loaded.Add a plain cxl-list right after the modprobe to allow for a flush/wait cycle.
Is this the preferred method to 'settle', instead of udevadm settle?
Generally, no. Usually cxl tests would use cxl-cli commands, which now have the necessary waits via cxl_wait_probe(), so even a 'udevadm settle' shouldn't be needed.
In this case, the first thing we run is ndctl list, which waits for nvdimm things to 'settle', but we were racing with cxl_test coming up, which it (ndctl) knows nothing about.
Quoted 26 lines
Quoted 26 lines
Cc Dave Jiang <[email protected]>Suggested-by Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>---
test/security.sh | 1 +1 file changed, 1 insertion(+)test/security.sh +0
-0@@ -225,6 +225,7 @@ if [ "$uid" -ne 0 ]; thenfi
modprobe "$KMOD_TEST"
+cxl list
setup
check_prereq "keyctl"
rc=1Signature · 1 line
2.39.1
Alison Schofield
maintainerRe: [PATCH ndctl 3/3] test/cxl-security.sh: avoid intermittent failures due to sasync probe
Quoted 15 lines · Vishal Verma
Quoted 5 lines · Alison Schofield
Quoted 4 lines · Vishal Verma
This test failed intermittently because the ndctl-list operation right after a 'modprobe
cxl_test' could race the actual nmem devices getting loaded.Quoted 8 lines
Quoted 6 lines
Since CXL device probes are asynchronous, and
cxl_acpimight've kicked off acxl_bus_rescan(), acxl_flush()(viacxl_wait_probe()) can ensure everything is loaded.Add a plain cxl-list right after the modprobe to allow for a flush/wait cycle.
Is this the preferred method to 'settle', instead of udevadm settle?
Quoted 7 lines
Generally, no. Usually cxl tests would use cxl-cli commands, which now have the necessary waits via
cxl_wait_probe(), so even a 'udevadm settle' shouldn't be needed.In this case, the first thing we run is ndctl list, which waits for nvdimm things to 'settle', but we were racing with
cxl_testcoming up, which it (ndctl) knows nothing about.
OK - I'll stop doing the udevadm settle, since what I'm doing is pure 'cxl' and modprobe is always followed by cxl-cli commands.
Quoted 28 lines
Quoted 27 lines
Quoted 27 lines
Cc Dave Jiang <[email protected]>Suggested-by Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- test/security.sh | 1 + 1 file changed, 1 insertion(+)test/security.sh +1
-1@@ -225,6 +225,7 @@ if [ "$uid" -ne 0 ]; then fi modprobe "$KMOD_TEST" +cxl list setup check_prereq "keyctl" rc=1 --2.39.1