From patchwork Sat Aug 19 14:12:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13358637 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29A91EE4993 for ; Sat, 19 Aug 2023 14:12:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 596A0900007; Sat, 19 Aug 2023 10:12:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B4EF900018; Sat, 19 Aug 2023 10:12:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 127DC900007; Sat, 19 Aug 2023 10:12:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D5342900011 for ; Sat, 19 Aug 2023 10:12:49 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AF0E61A0933 for ; Sat, 19 Aug 2023 14:12:49 +0000 (UTC) X-FDA: 81141045258.21.9064D8A Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) by imf28.hostedemail.com (Postfix) with ESMTP id E5BEBC000E for ; Sat, 19 Aug 2023 14:12:46 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=YHzUfnhp; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.167.177 as permitted sender) smtp.mailfrom=yury.norov@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692454366; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=igV7SREietQ24odTG+SOK9M1ry44nQsh1uk2kgh31uI=; b=euuTHzOcZdrphM4OPRpvITG3/z0m6TJjqN5WRh94uJpieTm5uSPPvbtXn/urLQHyjQYPVP PL/fQIy9mUGsVE4WxfOVOaHjvg7YMnND4bpKTis8EclWU0DOXKm1+YrFwkjwNikxUqUf0T mbBjEVHF5JvbgI69ISSiajluLxSFXLk= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=YHzUfnhp; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.167.177 as permitted sender) smtp.mailfrom=yury.norov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692454366; a=rsa-sha256; cv=none; b=GaZeCUkFgVMDpW6STqiZ4OSR9xAz9NUaQS/BNhfgAfbV7sVAuYKNoiTPUVF7x9FjaSAGq/ O8ry/r4skXAY5+tpmxWEcl7CvA/Z/MnQ9rtsBW7m81JU3mjws6JGThKII725NYejtk3LNi 5N8tKX9VdxfLkEgI+MNJ+LhXXkR8VKI= Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3a7d4030621so1171264b6e.3 for ; Sat, 19 Aug 2023 07:12:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692454366; x=1693059166; 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=igV7SREietQ24odTG+SOK9M1ry44nQsh1uk2kgh31uI=; b=YHzUfnhp2ULvFItZJ3o9nXuTnirno2N6SDjG259/ov8RQGn1YKf8iAafsV/TZmzM9G +JnpUr2gmWptKe9x+JSvawiBnbrHhC0ttUD2okQ/G1fkWvTO+q+8WWnRri6umDq+AeyL uI0r086HHFLAzxmjNMoczkq3+6neOsKWrv7/U+R0BktdT2UnHnqO2MbZ02/Sv0a3y64w uVF4L/O5aitTTPQbj/ImVhoNslyY90UeKiLJpC1hbba+hqARYZbe+jJxR1t91g/UGIRk cj0t8on3AEkxlEMjodaPmpu584rPPq3QYwFMKZXzjDyKDOj1sI+dorfQbPfPplhlCTXI V2Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692454366; x=1693059166; 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=igV7SREietQ24odTG+SOK9M1ry44nQsh1uk2kgh31uI=; b=Uoq0DxTDM3YVitOg/TJqCtrVIneQr7KqLjgnQCvgUHf9XDF9ataXi6vA7a9j74ox+9 rnF/5Esp5hH9Ws1J68SsZxSy3zHullLbX/r1Ob6ZyGGyvNKSqn2hMiYqTnd3fTfdQ743 Fi8DPTiJXemIcmpzZk3O/pGHaOWrY6kk7nFkuqj7HEvk8Lq08MPRMogvwQ2LhWHh2zuO pfzNQparlGxGKObCjwH1EBK7sCCkD8W9Oc4nmN5k0w2WIiYcCnbv3nMuPBtoqmFZ4a5M 0PxEOzoRXHkayGxgXg47oioFoJN0K7IkI0CyhnbIdVYFW+1eoJF9LrLQKizjrKHmd1zw eBOQ== X-Gm-Message-State: AOJu0YyhoA4SBEStBhctU0NfOlCd43KWPuCCeg6ZJcEoHGBDcfnGQJoA WLp+95/EUyAjZEiSqHrygmg= X-Google-Smtp-Source: AGHT+IHSqqEDImaL7LnYyBklQgJU18/Wzpv/z+7QriCsXPpQMlpRzLKW65D8myoE3i10msbA9KqjvA== X-Received: by 2002:a05:6358:e486:b0:135:499b:a68c with SMTP id by6-20020a056358e48600b00135499ba68cmr488750rwb.8.1692454365835; Sat, 19 Aug 2023 07:12:45 -0700 (PDT) Received: from localhost ([32.218.242.113]) by smtp.gmail.com with ESMTPSA id r11-20020a0ccc0b000000b00631fea4d5bcsm1466439qvk.95.2023.08.19.07.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 07:12:45 -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 , Guenter Roeck Subject: [PATCH v2 3/6] sched: fix sched_numa_find_nth_cpu() in CPU-less case Date: Sat, 19 Aug 2023 07:12:35 -0700 Message-Id: <20230819141239.287290-4-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 X-Rspamd-Queue-Id: E5BEBC000E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: eid6b8up7edn9gppeogym9qrqnhiyh44 X-HE-Tag: 1692454366-71449 X-HE-Meta: U2FsdGVkX1/7mdWv+X23M4WattsIsRYKAoh2V4sUB82KurnH8hCeexFZ/t70BPsVkU4pyY8bZl5TB3iwfooh4nHJTk23eWLlsQg2Tl6uC4Gfo04ebb10bM7T0ZuN66WA6mpuknHY5X6J0OMT5T9P5n2Z/QspZ8/BfZ8ui8MjasjLMvHUF73Ialp3QN0SkHzaUZGFQSj/tkAPcSOOfD6EA+C+qo1ilWmpUeagAi4JyeTCP+XCvAj8RRL4VnDzADAR+7/S3zpu7/LcfC0k7vyM4iMOYMeNx8rgJ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p3B+xknYUuEv+ZMFg79LMogDuLiaC8OITAznFwSba5ag2dL4VCbvXOWik6U37eexabSIOk/0WVt1wHC1WzbT6b18aUBy+M2AoQlP+eLyhIvoOgW8jkp70Wovfhb/WHtieaGIe2fd7VNDcKXUocVev+VtVNi9EDmy4zU6vj/xvkYmrOKqhcZUiQSGpFdSqkfJQonAlnKauHAj8nCUxNAoqcazuCOJOHgBQI1AXVe8jo2bqO/3VqkYErN4Z4y9xgLhK6MO17MVAV4lZKqwlx+0VDu1E2EMJby8FqMwad++b5OFg4mR30pcustYrJb8rjeT15Zx0VbWBLgigjHU+C3BkoXMCV1C9qRPDbmWSh/kRrMm0uboeUzg42LMUesZWhY+Gr6Cjgv0Z9A3RHvOUYTa8+z/JV/j4DaXrKrNyYFipEg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When the node provided by user is CPU-less, corresponding record in sched_domains_numa_masks is not set. Trying to dereference it in the following code leads to kernel crash. To avoid it, start searching from the nearest node with CPUs. Fixes: cd7f55359c90 ("sched: add sched_numa_find_nth_cpu()") Reported-by: Yicong Yang Closes: https://lore.kernel.org/lkml/CAAH8bW8C5humYnfpW3y5ypwx0E-09A3QxFE1JFzR66v+mO4XfA@mail.gmail.com/T/ Reported-by: Guenter Roeck Closes: https://lore.kernel.org/lkml/ZMHSNQfv39HN068m@yury-ThinkPad/T/#mf6431cb0b7f6f05193c41adeee444bc95bf2b1c4 Signed-off-by: Yury Norov Reviewed-by: Yicong Yang --- kernel/sched/topology.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index d3a3b2646ec4..c6e89afa0d65 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2113,12 +2113,16 @@ static int hop_cmp(const void *a, const void *b) */ int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node) { - struct __cmp_key k = { .cpus = cpus, .node = node, .cpu = cpu }; + struct __cmp_key k = { .cpus = cpus, .cpu = cpu }; struct cpumask ***hop_masks; int hop, ret = nr_cpu_ids; rcu_read_lock(); + /* CPU-less node entries are uninitialized in sched_domains_numa_masks */ + node = numa_nearest_node(node, N_CPU); + k.node = node; + k.masks = rcu_dereference(sched_domains_numa_masks); if (!k.masks) goto unlock;