[PATCH OLK-5.10] eventpoll: Fix return fixed cpu bug in set_prefetch_numa_cpu()

hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/release-management/issues/IC9Q31 -------------------------------- The original intention of set_prefetch_numa_cpu() was to randomly select a CPU from the pfi->related_cpu range based on fd. The function of cpumask_next(int n, const struct cpumask *srcp) is, in the given CPU mask "srcp", find the next CPU number that is set (i.e., set to 1) starting from the specified position n. So cpumask_next() in set_prefetch_numa_cpu() will always return cpumask_first(&related_cpus) if the following conditions are met: fd % cpumask_weight(&related_cpus) < cpumask_first(&related_cpus) But use the calculated offset in cpumask_next() may also not be correct if the "related_cpus" is discontinuous. So count the nth cpu in "related_cpus" to return the prefetch cpu. Fixes: 7e1291339cb5 ("eventpoll: Support xcall async prefetch") Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> --- fs/eventpoll.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index dd11e92994c9..4360444afb83 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -949,6 +949,20 @@ static void prefetch_work_fn(struct work_struct *work) trace_epoll_rc_ready(pfi->file, pfi->len); } +static int get_nth_cpu_in_cpumask(const struct cpumask *mask, int n) +{ + int count = 0; + int cpu; + + for_each_cpu(cpu, mask) { + if (count == n) + return cpu; + count++; + } + + return cpumask_first(mask); +} + static void set_prefetch_numa_cpu(struct prefetch_item *pfi, int fd) { int cur_cpu = smp_processor_id(); @@ -959,11 +973,9 @@ static void set_prefetch_numa_cpu(struct prefetch_item *pfi, int fd) cpumask_and(&pfi->related_cpus, cpu_cpu_mask(cur_cpu), cpu_online_mask); if (cpumask_intersects(&tmp, &pfi->related_cpus)) cpumask_and(&pfi->related_cpus, &pfi->related_cpus, &tmp); - cpu = cpumask_next(fd % cpumask_weight(&pfi->related_cpus), - &pfi->related_cpus); - if (cpu > cpumask_last(&pfi->related_cpus)) - cpu = cpumask_first(&pfi->related_cpus); - pfi->cpu = cpu; + + pfi->cpu = get_nth_cpu_in_cpumask(&pfi->related_cpus, + fd % cpumask_weight(&pfi->related_cpus)); } static struct prefetch_item *alloc_prefetch_item(struct epitem *epi) -- 2.34.1

反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/17329 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/I5O... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/17329 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/I5O...
participants (2)
-
Jinjie Ruan
-
patchwork bot