* [PATCH] lib: interval_tree_test: validate benchmark parameters
@ 2026-06-09 0:54 Samuel Moelius
2026-06-10 1:13 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Samuel Moelius @ 2026-06-09 0:54 UTC (permalink / raw)
To: Andrew Morton; +Cc: Samuel Moelius, open list:LIBRARY CODE
The interval tree runtime test accepts module parameters that are later
used as divisors while generating randomized intervals and while
reporting average timings. For example, max_endpoint=1 makes the
generated interval end value zero and the next modulo operation divides
by that zero value.
Reject non-positive counts and require max_endpoint to provide at least
one non-zero generated endpoint before the test allocates state or
starts the benchmark.
Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
---
lib/interval_tree_test.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/lib/interval_tree_test.c b/lib/interval_tree_test.c
index 16200feacbf3..58f6f3a307f4 100644
--- a/lib/interval_tree_test.c
+++ b/lib/interval_tree_test.c
@@ -311,6 +311,27 @@ static inline int span_iteration_check(void) {return 0; }
static int interval_tree_test_init(void)
{
+ if (nnodes <= 0) {
+ pr_warn("nnodes must be positive\n");
+ return -EINVAL;
+ }
+ if (nsearches <= 0) {
+ pr_warn("nsearches must be positive\n");
+ return -EINVAL;
+ }
+ if (perf_loops <= 0) {
+ pr_warn("perf_loops must be positive\n");
+ return -EINVAL;
+ }
+ if (search_loops <= 0) {
+ pr_warn("search_loops must be positive\n");
+ return -EINVAL;
+ }
+ if (max_endpoint < 2) {
+ pr_warn("max_endpoint must be at least 2\n");
+ return -EINVAL;
+ }
+
nodes = kmalloc_objs(struct interval_tree_node, nnodes);
if (!nodes)
return -ENOMEM;
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] lib: interval_tree_test: validate benchmark parameters
2026-06-09 0:54 [PATCH] lib: interval_tree_test: validate benchmark parameters Samuel Moelius
@ 2026-06-10 1:13 ` Andrew Morton
2026-06-10 17:17 ` Samuel Moelius
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2026-06-10 1:13 UTC (permalink / raw)
To: Samuel Moelius; +Cc: open list:LIBRARY CODE
On Tue, 9 Jun 2026 00:54:47 +0000 Samuel Moelius <sam.moelius@trailofbits.com> wrote:
> The interval tree runtime test accepts module parameters that are later
> used as divisors while generating randomized intervals and while
> reporting average timings. For example, max_endpoint=1 makes the
> generated interval end value zero and the next modulo operation divides
> by that zero value.
>
> Reject non-positive counts and require max_endpoint to provide at least
> one non-zero generated endpoint before the test allocates state or
> starts the benchmark.
That makes sense, thanks.
> --- a/lib/interval_tree_test.c
> +++ b/lib/interval_tree_test.c
> @@ -311,6 +311,27 @@ static inline int span_iteration_check(void) {return 0; }
>
> static int interval_tree_test_init(void)
> {
> + if (nnodes <= 0) {
> + pr_warn("nnodes must be positive\n");
> + return -EINVAL;
> + }
> + if (nsearches <= 0) {
> + pr_warn("nsearches must be positive\n");
> + return -EINVAL;
> + }
> + if (perf_loops <= 0) {
> + pr_warn("perf_loops must be positive\n");
> + return -EINVAL;
> + }
> + if (search_loops <= 0) {
> + pr_warn("search_loops must be positive\n");
> + return -EINVAL;
> + }
> + if (max_endpoint < 2) {
> + pr_warn("max_endpoint must be at least 2\n");
> + return -EINVAL;
> + }
> +
> nodes = kmalloc_objs(struct interval_tree_node, nnodes);
> if (!nodes)
> return -ENOMEM;
Perhaps this can be done within the __param macro:
#define __param(type, name, init, msg) \
static type name = init; \
module_param(name, type, 0444); \
if (name <= 0) { \
pr_warn(__stringify(name) " must be positive\n"); \
name = init; \
} \
MODULE_PARM_DESC(name, msg);
I'll add your patch as-is. If you prefer the above approach, please send
along a replacement patch.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] lib: interval_tree_test: validate benchmark parameters
2026-06-10 1:13 ` Andrew Morton
@ 2026-06-10 17:17 ` Samuel Moelius
0 siblings, 0 replies; 3+ messages in thread
From: Samuel Moelius @ 2026-06-10 17:17 UTC (permalink / raw)
To: Andrew Morton; +Cc: open list:LIBRARY CODE
On Tue, Jun 9, 2026 at 9:13 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Tue, 9 Jun 2026 00:54:47 +0000 Samuel Moelius <sam.moelius@trailofbits.com> wrote:
>
> > The interval tree runtime test accepts module parameters that are later
> > used as divisors while generating randomized intervals and while
> > reporting average timings. For example, max_endpoint=1 makes the
> > generated interval end value zero and the next modulo operation divides
> > by that zero value.
> >
> > Reject non-positive counts and require max_endpoint to provide at least
> > one non-zero generated endpoint before the test allocates state or
> > starts the benchmark.
>
> That makes sense, thanks.
>
> > --- a/lib/interval_tree_test.c
> > +++ b/lib/interval_tree_test.c
> > @@ -311,6 +311,27 @@ static inline int span_iteration_check(void) {return 0; }
> >
> > static int interval_tree_test_init(void)
> > {
> > + if (nnodes <= 0) {
> > + pr_warn("nnodes must be positive\n");
> > + return -EINVAL;
> > + }
> > + if (nsearches <= 0) {
> > + pr_warn("nsearches must be positive\n");
> > + return -EINVAL;
> > + }
> > + if (perf_loops <= 0) {
> > + pr_warn("perf_loops must be positive\n");
> > + return -EINVAL;
> > + }
> > + if (search_loops <= 0) {
> > + pr_warn("search_loops must be positive\n");
> > + return -EINVAL;
> > + }
> > + if (max_endpoint < 2) {
> > + pr_warn("max_endpoint must be at least 2\n");
> > + return -EINVAL;
> > + }
> > +
> > nodes = kmalloc_objs(struct interval_tree_node, nnodes);
> > if (!nodes)
> > return -ENOMEM;
>
> Perhaps this can be done within the __param macro:
>
> #define __param(type, name, init, msg) \
> static type name = init; \
> module_param(name, type, 0444); \
> if (name <= 0) { \
> pr_warn(__stringify(name) " must be positive\n"); \
> name = init; \
> } \
> MODULE_PARM_DESC(name, msg);
>
> I'll add your patch as-is. If you prefer the above approach, please send
> along a replacement patch.
I looked at this, but it would seem to require a more complicated
__param macro. For example, max_endpoint must be 2 or more. Also, the
macro would need to emit a checking function.
If it's okay, I would like to please go with this patch.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-10 17:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-09 0:54 [PATCH] lib: interval_tree_test: validate benchmark parameters Samuel Moelius
2026-06-10 1:13 ` Andrew Morton
2026-06-10 17:17 ` Samuel Moelius
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®