Skip to content

trace: verify argument size - #3393

Merged
lgirdwood merged 5 commits into
thesofproject:masterfrom
ktrzcinx:trace-arg-check
Sep 14, 2020
Merged

lgirdwood merged 5 commits into
thesofproject:masterfrom
ktrzcinx:trace-arg-check

Conversation

@ktrzcinx

@ktrzcinx ktrzcinx commented Sep 7, 2020

Copy link
Copy Markdown
Member

Extracted from #3376.
Here META_MAP functionality has been used, so it's more flexible solution in case of _TRACE_EVENT_MAX_ARGUMENT_COUNT change.

ktrzcinx and others added 2 commits September 7, 2020 15:45
This functionality counldn't handle empty __VA_ARGS__.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
SOF tracing can only handle up to 32-bit long values, attempts to
trace 64-bit values produce unpredictable results. Fix such cases
by making sure values are within range and casting them to 32 bits.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ktrzcinx - Looks good to me. @lyakh any comments ?

Comment thread src/include/sof/trace/trace.h Outdated

@lyakh lyakh left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from my comments - sure, if it works, but I won't pretend to have fully parsed all that ;-) Has this been tested to trigger on large trace parameters?

Comment thread src/include/sof/trace/trace.h Outdated
Comment thread src/include/sof/trace/preproc.h
@ktrzcinx ktrzcinx changed the title [RFC] trace: verify argument size trace: verify argument size Sep 9, 2020
@paulstelian97
paulstelian97 self-requested a review September 9, 2020 11:06

@lyakh lyakh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments are optional. Thanks for the improvements!

Comment thread src/include/sof/trace/trace.h Outdated
Comment thread src/include/sof/trace/preproc.h Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could then remove _META_REQRS_1024()..._META_REQRS_16() but that doesn't have to go with this PR. Looks like _META_DEFER_N() and META_DEFER() are unused too , maybe some other "magic" macros too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could then remove _META_REQRS_1024()..._META_REQRS_16() but that doesn't have to go with this PR.

I add it to commit with META_RECURSE depth reduction, because it's a point from which those are unused.

ktrzcinx and others added 2 commits September 10, 2020 08:17
Trace system support arguments no larger that uint32_t,
so this condition should be checked for each trace.
Create separate CT_ASSERT, because of need to have
multiple instances of assertions with the same error
message, what is not possible for STATIC_ASSERT.
STATIC_ASSERT has better message printing, so
it's not replaced by new version.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
The PP_NARG() macro can only handle integer type arguments, use
META_COUNT_VARAGS_BEFORE_COMPILE() instead to avoid having to cast
pointer types to integers.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
@ktrzcinx
ktrzcinx force-pushed the trace-arg-check branch 2 times, most recently from 7c8f9f2 to 90e71b0 Compare September 10, 2020 06:21
@lgirdwood

Copy link
Copy Markdown
Member

@ktrzcinx can you check CI.

There is any user in source code who need deeper recursion level,
reducing it allow to prevent compiler error message flood during
working with META_RECURSE clients (eg. trace system).

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
@lgirdwood

Copy link
Copy Markdown
Member

@ktrzcinx can you fix this one, everything else is good to go.

WARNING: macros should not use a trailing semicolon
#30: FILE: src/include/sof/trace/trace.h:176:
+#define trace_check_size_uint32(a) \
+	CT_ASSERT(sizeof(a) <= sizeof(uint32_t), "error: trace argument is bigger than a uint32_t");

@ktrzcinx

Copy link
Copy Markdown
Member Author

@lgirdwood it won't work without this semicolon. It's because mapping function doesn't add it, to allow usage different separators, like ; or,.

@lgirdwood

Copy link
Copy Markdown
Member

@ktrzcinx ok, got you.

@lgirdwood
lgirdwood merged commit 63fe935 into thesofproject:master Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants