On 25/09/22 11:05, Yury Norov wrote: > On Fri, Sep 23, 2022 at 04:55:40PM +0100, Valentin Schneider wrote: >> +const struct cpumask *sched_numa_hop_mask(int node, int hops) >> +{ >> + struct cpumask ***masks = rcu_dereference(sched_domains_numa_masks); >> + >> + if (node == NUMA_NO_NODE && !hops) >> + return cpu_online_mask; >> + >> + if (node >= nr_node_ids || hops >= sched_domains_numa_levels) >> + return ERR_PTR(-EINVAL); > > This looks like a sanity check. If so, it should go before the snippet > above, so that client code would behave consistently. > nr_node_ids is unsigned, so -1 >= nr_node_ids is true. >> + >> + if (!masks) >> + return NULL; > > In (node == NUMA_NO_NODE && !hops) case you return online cpus. Here > you return NULL just to convert it to cpu_online_mask in the caller. > This looks inconsistent. So, together with the above comment, this > makes me feel that you'd do it like this: > > const struct cpumask *sched_numa_hop_mask(int node, int hops) > { > struct cpumask ***masks; > > if (node >= nr_node_ids || hops >= sched_domains_numa_levels) > { > #ifdef CONFIG_SCHED_DEBUG > pr_err(...); > #endif > return ERR_PTR(-EINVAL); > } > > if (node == NUMA_NO_NODE && !hops) > return cpu_online_mask; /* or NULL */ > > masks = rcu_dereference(sched_domains_numa_masks); > if (!masks) > return cpu_online_mask; /* or NULL */ > > return masks[hops][node]; > } If we're being pedantic, sched_numa_hop_mask() shouldn't return cpu_online_mask in those cases, but that was the least horrible option I found to get something sensible for the NUMA_NO_NODE / !CONFIG_NUMA case. I might be able to better handle this with your suggestion of having a mask iterator.