From nobody Fri Sep 12 10:04:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5EA2EE49A8 for ; Sat, 19 Aug 2023 14:15:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232994AbjHSOPF (ORCPT ); Sat, 19 Aug 2023 10:15:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233236AbjHSOO7 (ORCPT ); Sat, 19 Aug 2023 10:14:59 -0400 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39CAF9EF7 for ; Sat, 19 Aug 2023 07:12:49 -0700 (PDT) Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-76d83954c43so126372485a.2 for ; Sat, 19 Aug 2023 07:12:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692454368; x=1693059168; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Crn5/+8WdRhCgV6i5ssfAVZRKeJzdqL7IL6ctYKnl6U=; b=U7AgRT8Ejxxl/VEdRwqDG1ENqN4QGxU6q+qxz0PKZpU9PSYvv4hGm/LQQLGxOrW1gJ CWLHmh7bBtOZQEIirnGLdBTRwYf5ThOF0JN0i91aMcJOkDKLZxhdvJ3WZr20h2BmTR/b icRcsHm5yrdnjCN64NRgjkhAgWD8MzAJiawtCyEU8rZpGuPTFn7dVM43FYHmSDsEpWgH WeYgmoVQ6tUx1hhTGyjdZmYTtK6mjtcolc7TSb9NigZLMaPqqeQrDZdjkyl/ECDxq5VC CZEAbglb9Y0vPOZDMQZOKdkUtKdyAS3YZNc/qBVNVgenMfI4FRZzgHQ1iiynIlneqMrG HyuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692454368; x=1693059168; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Crn5/+8WdRhCgV6i5ssfAVZRKeJzdqL7IL6ctYKnl6U=; b=YfJ4XkCd0ppkGgVjUFuBoVHJNF6Xml5rRjNf2ykfkNMzb49B3HpgpGsSi+MMjv5Yus 9uK/r/TgfjKhrsO26+rOJl12jr/VJtTTDCY9ZnDZCny4QIWsla8kr4wY11E2rTJ+f9Aa BWRA1XTWouN964bY96dT0cZGzqbrXrWiIU8bjk8dbZWueTjAdgaJNILRQ2VimQmmPxZY Hg0VVp8bn2AYhMaeGO4sAUSnGri859KeNPgkS0aGWYtKdE/8CqSQdjmcPULq9EXK6wDO Ldb6N+qgxdaINy46+iuaLnweeidKhWWiOkNxqi9zlpzT3/lnqRD7InXi841DYcihpHLR cLzg== X-Gm-Message-State: AOJu0YyN/UnNyNwWi3D92zD5lgJ59MZeaB/C46A50ZcYAgI3Z4a0rU72 FckZ/jYgfk0wLzPIpSe9nLbl0dRlCWM= X-Google-Smtp-Source: AGHT+IETTvZTEFyiJf8ZsCBw1Z942T/yFUfrCc+lCrhAif1gu2FCfd/M7wsnPaQD+/POCrDPVTsgpw== X-Received: by 2002:a05:620a:2987:b0:76c:e764:5081 with SMTP id r7-20020a05620a298700b0076ce7645081mr2825410qkp.37.1692454367995; Sat, 19 Aug 2023 07:12:47 -0700 (PDT) Received: from localhost ([32.218.242.113]) by smtp.gmail.com with ESMTPSA id 22-20020a05620a079600b0076ce061f44dsm1204827qka.25.2023.08.19.07.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 07:12:47 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Yury Norov , Ingo Molnar , Peter Zijlstra , Andrew Morton , Ben Segall , Daniel Bristot de Oliveira , Dietmar Eggemann , Jacob Keller , Jakub Kicinski , Juri Lelli , Mel Gorman , Steven Rostedt , Tariq Toukan , Valentin Schneider , Vincent Guittot , shiju.jose@huawei.com, jonathan.cameron@huawei.com, prime.zeng@huawei.com, linuxarm@huawei.com, yangyicong@hisilicon.com, Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v2 5/6] sched: handle NUMA_NO_NODE in sched_numa_find_nth_cpu() Date: Sat, 19 Aug 2023 07:12:37 -0700 Message-Id: <20230819141239.287290-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230819141239.287290-1-yury.norov@gmail.com> References: <20230819141239.287290-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" sched_numa_find_nth_cpu() doesn't handle NUMA_NO_NODE properly, and may crash kernel if passed with it. On the other hand, the only user of sched_numa_find_nth_cpu() has to check NUMA_NO_NODE case explicitly. It would be easier for users if this logic will get moved into sched_numa_find_nth_cpu(). Signed-off-by: Yury Norov --- kernel/sched/topology.c | 3 +++ lib/cpumask.c | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index c6e89afa0d65..bc6802700103 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2117,6 +2117,9 @@ int sched_numa_find_nth_cpu(const struct cpumask *cpu= s, int cpu, int node) struct cpumask ***hop_masks; int hop, ret =3D nr_cpu_ids; =20 + if (node =3D=3D NUMA_NO_NODE) + return cpumask_nth_and(cpu, cpus, cpu_online_mask); + rcu_read_lock(); =20 /* CPU-less node entries are uninitialized in sched_domains_numa_masks */ diff --git a/lib/cpumask.c b/lib/cpumask.c index 19277c6d551f..e77ee9d46f71 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c @@ -147,9 +147,7 @@ unsigned int cpumask_local_spread(unsigned int i, int n= ode) /* Wrap: we always want a cpu. */ i %=3D num_online_cpus(); =20 - cpu =3D (node =3D=3D NUMA_NO_NODE) ? - cpumask_nth(i, cpu_online_mask) : - sched_numa_find_nth_cpu(cpu_online_mask, i, node); + cpu =3D sched_numa_find_nth_cpu(cpu_online_mask, i, node); =20 WARN_ON(cpu >=3D nr_cpu_ids); return cpu; --=20 2.39.2