From patchwork Mon Mar 7 19:59:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: dann frazier X-Patchwork-Id: 549219 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 A7D18C433EF for ; Mon, 7 Mar 2022 20:00:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245208AbiCGUBK (ORCPT ); Mon, 7 Mar 2022 15:01:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245217AbiCGUBH (ORCPT ); Mon, 7 Mar 2022 15:01:07 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FDF16AA71 for ; Mon, 7 Mar 2022 12:00:08 -0800 (PST) Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 6EC083F79C for ; Mon, 7 Mar 2022 20:00:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1646683207; bh=u9DpCicYR1zCgMhq29xB/tGtROV7y9agv3aZnB57aWE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=QkEGWb6XJhMhPDitgK1bg6nGyDn28TcmUQyIfBegz9PgnYLoDUtYFPlJsdXXD/WKn I242AdbtJI3bXTnbWrGd8pK/e+MIzsvb0XGtmXOz2qwzrnEbS1cznyzCqFPNhS/rpr drs3x5QmjlGlDNlilZKOsuktj2dHxy8BvsxG/DTT4beTdec9OiXb/0OuDr2GBPt267 /5FvobPdKouIhN3gOG9tSINGW7cZh1+VFxHaHhj7gsOG5I4KdyacSyFfdSRED1r7kS woz/ngGULAxitqJ7wPmasKnNIsc/4gTwJRiG9Sj3kmWb5xEiZ1RKufB+xjPtueIlFp Y1op+NHQLO67g== Received: by mail-il1-f200.google.com with SMTP id y11-20020a056e021beb00b002c3f8984f9eso10999847ilv.10 for ; Mon, 07 Mar 2022 12:00:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u9DpCicYR1zCgMhq29xB/tGtROV7y9agv3aZnB57aWE=; b=jN0VMqVTRxnZvdkXAUqT/3LDDrZX4ifXwJblHWhiKc0F+W9svDxiy7IVPqueDcxkqE VUpwt4Gw/e3EFTPlwQ1lhwH5VU81+yKx7iNhAwPe7vAUNgNyAb4anV+gZPB/pDX5umLT Z/TXgFyqhvg7y73x7JK2A/M0C6+RDLvsvxATQ4XIaun9X+3/6K+66Qxildcev/wobBf7 Fa2VM7bKOXbDaA+vRnYKoBfFMh+3R7M78BODVj23scOgwOy9/UYouzTiEucc7StdMg30 0ZPZ2WQv16Z9NupmHnnJP2SFhicNanL+Tda/pgGlUr+fxp9QPa6or7q18dx1XGtvX1di OT4w== X-Gm-Message-State: AOAM530R7zTp0AvcQUDfG7t+FbjpV5t6zKoDhsrfJWfDWIrHBes/SHTX d/iuZHCtt5mYH2OHZnOOTIhom8zh1Z76dqrgkotLgmXLGCdZ8+yLwk8UmbWJDUUYrqxvcRJ+4XF Id1utZHS0nAFWTaVQiPaJ37JUX3gsdyU4Yg== X-Received: by 2002:a05:6e02:1c22:b0:2b9:dcbb:e810 with SMTP id m2-20020a056e021c2200b002b9dcbbe810mr11992528ilh.262.1646683205267; Mon, 07 Mar 2022 12:00:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwgRUa2ElBPiYYNcsCOI4K+1oqUYfEAVRnGfCt6NX7xBXkXVo3OUZ0Zu2i6HaMQh/F4xAL6vg== X-Received: by 2002:a05:6e02:1c22:b0:2b9:dcbb:e810 with SMTP id m2-20020a056e021c2200b002b9dcbbe810mr11992507ilh.262.1646683204906; Mon, 07 Mar 2022 12:00:04 -0800 (PST) Received: from localhost (c-71-196-238-11.hsd1.co.comcast.net. [71.196.238.11]) by smtp.gmail.com with ESMTPSA id b24-20020a5d8d98000000b006409ad493fbsm9518538ioj.21.2022.03.07.12.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 12:00:03 -0800 (PST) From: dann frazier To: stable@vger.kernel.org Cc: Valentin Schneider , Dietmar Eggemann , Peter Zijlstra , Ingo Molnar , Vincent Guittot , John Paul Adrian Glaubitz , Sergei Trofimovich , Anatoly Pugachev , Andrew Morton , Linus Torvalds , linux-kernel@vger.kernel.org Subject: [PATCH 4.19 1/3] sched/topology: Make sched_init_numa() use a set for the deduplicating sort Date: Mon, 7 Mar 2022 12:59:39 -0700 Message-Id: <20220307195941.459076-2-dann.frazier@canonical.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307195941.459076-1-dann.frazier@canonical.com> References: <20220307195941.459076-1-dann.frazier@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Valentin Schneider commit 620a6dc40754dc218f5b6389b5d335e9a107fd29 upstream. The deduplicating sort in sched_init_numa() assumes that the first line in the distance table contains all unique values in the entire table. I've been trying to pen what this exactly means for the topology, but it's not straightforward. For instance, topology.c uses this example: node 0 1 2 3 0: 10 20 20 30 1: 20 10 20 20 2: 20 20 10 20 3: 30 20 20 10 0 ----- 1 | / | | / | | / | 2 ----- 3 Which works out just fine. However, if we swap nodes 0 and 1: 1 ----- 0 | / | | / | | / | 2 ----- 3 we get this distance table: node 0 1 2 3 0: 10 20 20 20 1: 20 10 20 30 2: 20 20 10 20 3: 20 30 20 10 Which breaks the deduplicating sort (non-representative first line). In this case this would just be a renumbering exercise, but it so happens that we can have a deduplicating sort that goes through the whole table in O(n²) at the extra cost of a temporary memory allocation (i.e. any form of set). The ACPI spec (SLIT) mentions distances are encoded on 8 bits. Following this, implement the set as a 256-bits bitmap. Should this not be satisfactory (i.e. we want to support 32-bit values), then we'll have to go for some other sparse set implementation. This has the added benefit of letting us allocate just the right amount of memory for sched_domains_numa_distance[], rather than an arbitrary (nr_node_ids + 1). Note: DT binding equivalent (distance-map) decodes distances as 32-bit values. Signed-off-by: Valentin Schneider Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20210122123943.1217-2-valentin.schneider@arm.com Signed-off-by: dann frazier --- include/linux/topology.h | 1 + kernel/sched/topology.c | 99 +++++++++++++++++++--------------------- 2 files changed, 49 insertions(+), 51 deletions(-) diff --git a/include/linux/topology.h b/include/linux/topology.h index cb0775e1ee4b..707364c90aa6 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -47,6 +47,7 @@ int arch_update_cpu_topology(void); /* Conform to ACPI 2.0 SLIT distance definitions */ #define LOCAL_DISTANCE 10 #define REMOTE_DISTANCE 20 +#define DISTANCE_BITS 8 #ifndef node_distance #define node_distance(from,to) ((from) == (to) ? LOCAL_DISTANCE : REMOTE_DISTANCE) #endif diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index f58efa5cc647..0826f3f4920a 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1322,66 +1322,58 @@ static void init_numa_topology_type(void) } } + +#define NR_DISTANCE_VALUES (1 << DISTANCE_BITS) + void sched_init_numa(void) { - int next_distance, curr_distance = node_distance(0, 0); struct sched_domain_topology_level *tl; - int level = 0; - int i, j, k; - - sched_domains_numa_distance = kzalloc(sizeof(int) * (nr_node_ids + 1), GFP_KERNEL); - if (!sched_domains_numa_distance) - return; - - /* Includes NUMA identity node at level 0. */ - sched_domains_numa_distance[level++] = curr_distance; - sched_domains_numa_levels = level; + unsigned long *distance_map; + int nr_levels = 0; + int i, j; /* * O(nr_nodes^2) deduplicating selection sort -- in order to find the * unique distances in the node_distance() table. - * - * Assumes node_distance(0,j) includes all distances in - * node_distance(i,j) in order to avoid cubic time. */ - next_distance = curr_distance; + distance_map = bitmap_alloc(NR_DISTANCE_VALUES, GFP_KERNEL); + if (!distance_map) + return; + + bitmap_zero(distance_map, NR_DISTANCE_VALUES); for (i = 0; i < nr_node_ids; i++) { for (j = 0; j < nr_node_ids; j++) { - for (k = 0; k < nr_node_ids; k++) { - int distance = node_distance(i, k); - - if (distance > curr_distance && - (distance < next_distance || - next_distance == curr_distance)) - next_distance = distance; - - /* - * While not a strong assumption it would be nice to know - * about cases where if node A is connected to B, B is not - * equally connected to A. - */ - if (sched_debug() && node_distance(k, i) != distance) - sched_numa_warn("Node-distance not symmetric"); + int distance = node_distance(i, j); - if (sched_debug() && i && !find_numa_distance(distance)) - sched_numa_warn("Node-0 not representative"); + if (distance < LOCAL_DISTANCE || distance >= NR_DISTANCE_VALUES) { + sched_numa_warn("Invalid distance value range"); + return; } - if (next_distance != curr_distance) { - sched_domains_numa_distance[level++] = next_distance; - sched_domains_numa_levels = level; - curr_distance = next_distance; - } else break; + + bitmap_set(distance_map, distance, 1); } + } + /* + * We can now figure out how many unique distance values there are and + * allocate memory accordingly. + */ + nr_levels = bitmap_weight(distance_map, NR_DISTANCE_VALUES); - /* - * In case of sched_debug() we verify the above assumption. - */ - if (!sched_debug()) - break; + sched_domains_numa_distance = kcalloc(nr_levels, sizeof(int), GFP_KERNEL); + if (!sched_domains_numa_distance) { + bitmap_free(distance_map); + return; } + for (i = 0, j = 0; i < nr_levels; i++, j++) { + j = find_next_bit(distance_map, NR_DISTANCE_VALUES, j); + sched_domains_numa_distance[i] = j; + } + + bitmap_free(distance_map); + /* - * 'level' contains the number of unique distances + * 'nr_levels' contains the number of unique distances * * The sched_domains_numa_distance[] array includes the actual distance * numbers. @@ -1390,15 +1382,15 @@ void sched_init_numa(void) /* * Here, we should temporarily reset sched_domains_numa_levels to 0. * If it fails to allocate memory for array sched_domains_numa_masks[][], - * the array will contain less then 'level' members. This could be + * the array will contain less then 'nr_levels' members. This could be * dangerous when we use it to iterate array sched_domains_numa_masks[][] * in other functions. * - * We reset it to 'level' at the end of this function. + * We reset it to 'nr_levels' at the end of this function. */ sched_domains_numa_levels = 0; - sched_domains_numa_masks = kzalloc(sizeof(void *) * level, GFP_KERNEL); + sched_domains_numa_masks = kzalloc(sizeof(void *) * nr_levels, GFP_KERNEL); if (!sched_domains_numa_masks) return; @@ -1406,7 +1398,7 @@ void sched_init_numa(void) * Now for each level, construct a mask per node which contains all * CPUs of nodes that are that many hops away from us. */ - for (i = 0; i < level; i++) { + for (i = 0; i < nr_levels; i++) { sched_domains_numa_masks[i] = kzalloc(nr_node_ids * sizeof(void *), GFP_KERNEL); if (!sched_domains_numa_masks[i]) @@ -1414,12 +1406,17 @@ void sched_init_numa(void) for (j = 0; j < nr_node_ids; j++) { struct cpumask *mask = kzalloc(cpumask_size(), GFP_KERNEL); + int k; + if (!mask) return; sched_domains_numa_masks[i][j] = mask; for_each_node(k) { + if (sched_debug() && (node_distance(j, k) != node_distance(k, j))) + sched_numa_warn("Node-distance not symmetric"); + if (node_distance(j, k) > sched_domains_numa_distance[i]) continue; @@ -1431,7 +1428,7 @@ void sched_init_numa(void) /* Compute default topology size */ for (i = 0; sched_domain_topology[i].mask; i++); - tl = kzalloc((i + level + 1) * + tl = kzalloc((i + nr_levels) * sizeof(struct sched_domain_topology_level), GFP_KERNEL); if (!tl) return; @@ -1454,7 +1451,7 @@ void sched_init_numa(void) /* * .. and append 'j' levels of NUMA goodness. */ - for (j = 1; j < level; i++, j++) { + for (j = 1; j < nr_levels; i++, j++) { tl[i] = (struct sched_domain_topology_level){ .mask = sd_numa_mask, .sd_flags = cpu_numa_flags, @@ -1466,8 +1463,8 @@ void sched_init_numa(void) sched_domain_topology = tl; - sched_domains_numa_levels = level; - sched_max_numa_distance = sched_domains_numa_distance[level - 1]; + sched_domains_numa_levels = nr_levels; + sched_max_numa_distance = sched_domains_numa_distance[nr_levels - 1]; init_numa_topology_type(); } From patchwork Mon Mar 7 19:59:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dann frazier X-Patchwork-Id: 549698 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 EDD38C433FE for ; Mon, 7 Mar 2022 20:00:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245236AbiCGUBL (ORCPT ); Mon, 7 Mar 2022 15:01:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245222AbiCGUBJ (ORCPT ); Mon, 7 Mar 2022 15:01:09 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EB426E547 for ; Mon, 7 Mar 2022 12:00:14 -0800 (PST) Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 383113F7E5 for ; Mon, 7 Mar 2022 20:00:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1646683212; bh=wYDSBk7iUMWwKBfS03BdFKJC7SiK0s9WxGrCHtrTAag=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z+gjvDtsAH1x9Yxf+0BiY0koF+3CTWZXVyAHiKRSRORf4HziAyr+PvGeEr/Wq99Ew Myf//mzy3rw/N5iGIOU7WaVuPN2aRhivNX5LjlogxwIJMD9dQCcrZiwcaLHm0PXL10 /1dopKCBT487XBjVqHuTLZokkxLObTVf+FonoIUkccAPbLM8w7tLSMnv7+m7Cn+R5D GrTM/2gcmg7i1CZsiKG2FSxsr/MOE9XytIJ57YFsLEVKwaEyfXIJEGl1DrdztbtzwQ EAbbtWLFEWbLs7ol95OWzMX+Oqv9mTM0ct3hz+CulU04idoFtSxiNCIzot+UWisZ8x U9oMjNix40Gtw== Received: by mail-io1-f70.google.com with SMTP id x9-20020a0566022c4900b0064289c98bf8so11411827iov.12 for ; Mon, 07 Mar 2022 12:00:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wYDSBk7iUMWwKBfS03BdFKJC7SiK0s9WxGrCHtrTAag=; b=nDwQ7sky3gPBlInuAvLQJILbCpxbwLbG4P0xhK1OIT5h62O4c8nxqlirscKAwxYtwV ficFjFjrk0qVVpOYjl8kRBjfOYIL1tpU7QogeppLcqdy/MxDF8pa9UoMPjJ1BxyRmxbH K8yx5CFuOGrTquMpJsqbZ7vcAKLiiq1DRngd3mSsFb3zhOPihs5aLo7atx4Mt87OcGNQ zQtw8V3H2sf6VbKkFJS6/kT6H3nr6yxpFsEkqGdShY2pgJNLu/qIRcVglWNQgm+h+KZf FreOt7lTZ9GLDNruTXpiqgyfcDY1W7xzbMCAxxx95cuQA0cO51YvODc4mCtgkOi5Gq2B HhOQ== X-Gm-Message-State: AOAM5317sdr+F4qiBMuVLyd7RmHziEyRMNxbHyJSOOeGlLCtcYmwoAHy 1PScy0d93xfSSTN0JDbc0hwULjsL60VlbS335W2in+DPiEsa8xYVpUM+L3yA70EQtVw7rRVvr/Q HEfWL0PoxhzremMmDN1AcYa+/YdcFEAJfng== X-Received: by 2002:a05:6e02:1445:b0:2c2:ea36:dcab with SMTP id p5-20020a056e02144500b002c2ea36dcabmr12631738ilo.200.1646683209843; Mon, 07 Mar 2022 12:00:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbeq+Fz7xNxAbYLluyLiyZsv49d7uCqaI9YqSyxJQyitO22Zue0ppVtoVt+VkT1pgMZIoG+w== X-Received: by 2002:a05:6e02:1445:b0:2c2:ea36:dcab with SMTP id p5-20020a056e02144500b002c2ea36dcabmr12631715ilo.200.1646683209602; Mon, 07 Mar 2022 12:00:09 -0800 (PST) Received: from localhost (c-71-196-238-11.hsd1.co.comcast.net. [71.196.238.11]) by smtp.gmail.com with ESMTPSA id w6-20020a056e021c8600b002c602537ab9sm11255624ill.54.2022.03.07.12.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 12:00:05 -0800 (PST) From: dann frazier To: stable@vger.kernel.org Cc: Valentin Schneider , Dietmar Eggemann , Peter Zijlstra , Ingo Molnar , Vincent Guittot , John Paul Adrian Glaubitz , Sergei Trofimovich , Anatoly Pugachev , Andrew Morton , Linus Torvalds , linux-kernel@vger.kernel.org Subject: [PATCH 4.19 2/3] sched/topology: Fix sched_domain_topology_level alloc in sched_init_numa() Date: Mon, 7 Mar 2022 12:59:40 -0700 Message-Id: <20220307195941.459076-3-dann.frazier@canonical.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307195941.459076-1-dann.frazier@canonical.com> References: <20220307195941.459076-1-dann.frazier@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Dietmar Eggemann commit 71e5f6644fb2f3304fcb310145ded234a37e7cc1 upstream. Commit "sched/topology: Make sched_init_numa() use a set for the deduplicating sort" allocates 'i + nr_levels (level)' instead of 'i + nr_levels + 1' sched_domain_topology_level. This led to an Oops (on Arm64 juno with CONFIG_SCHED_DEBUG): sched_init_domains build_sched_domains() __free_domain_allocs() __sdt_free() { ... for_each_sd_topology(tl) ... sd = *per_cpu_ptr(sdd->sd, j); <-- ... } Signed-off-by: Dietmar Eggemann Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Tested-by: Vincent Guittot Tested-by: Barry Song Link: https://lkml.kernel.org/r/6000e39e-7d28-c360-9cd6-8798fd22a9bf@arm.com Signed-off-by: dann frazier --- kernel/sched/topology.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 0826f3f4920a..02e85cd233d4 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1428,7 +1428,7 @@ void sched_init_numa(void) /* Compute default topology size */ for (i = 0; sched_domain_topology[i].mask; i++); - tl = kzalloc((i + nr_levels) * + tl = kzalloc((i + nr_levels + 1) * sizeof(struct sched_domain_topology_level), GFP_KERNEL); if (!tl) return; From patchwork Mon Mar 7 20:01:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dann frazier X-Patchwork-Id: 549697 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 541ECC433F5 for ; Mon, 7 Mar 2022 20:01:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245224AbiCGUCP (ORCPT ); Mon, 7 Mar 2022 15:02:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242723AbiCGUCO (ORCPT ); Mon, 7 Mar 2022 15:02:14 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0086D8AE68 for ; Mon, 7 Mar 2022 12:01:19 -0800 (PST) Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id BA2BC3F7E0 for ; Mon, 7 Mar 2022 20:01:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1646683278; bh=MYa3HOnxdRf4zgP873BwgLR5fhhIJBKgyitcscinRGs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gjPng0wlHZOwhrUtjoppSZhPMZ7tmg5vA2wzniAEx04C9y8uXIW1ZhQXMnHm4WNy3 vEb0jaP+6Koycg08Uvu6eVVpS2u/6LWFn+87bdP+saXhcU7Pk53zxE1T2LQr8yXOy4 0E74/8dnUsAmC9FJufqNcigkqjjF97gdq1jBaSJRwPIUj6mYDjHRvuOZuEwIJjbm2a mUxSeS8yUhe6a+eCbcjYG9Tte6jo1V92PlvCkimJn1nTcUB7YeP7N6/wFDz0qaFPlB DwEsJn5us7+HPdHctCN2umSTpIqmyfjJ35gwLNAoH4aPBVHIjOVVNuvkmPHlkXpN99 +ihyHidkFZ4KA== Received: by mail-io1-f72.google.com with SMTP id s14-20020a0566022bce00b00645e9bc9773so1102200iov.20 for ; Mon, 07 Mar 2022 12:01:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MYa3HOnxdRf4zgP873BwgLR5fhhIJBKgyitcscinRGs=; b=rHY+dHJ4HEFzVV7SfrjRbvOqogb/4DRJyMXYhher1OPEKAT+8GPHfsbimI7EpJedsD OclOFJqJJETGLBCEyUdESPI6b+WEASTlaVcK0AfbqbvEAvP/+y/pmI93skArSYkfRmUG Ho0rfFbmW+x0T7CWuQ4IJic8zLO26RIRq8wdEK7tIYp0JC+jFpgHIdkGixDWF2nZsOy3 6j90VnOY03VoifhtewsJlZlVFRG12ufugh8JOgxWm+cf3pI+4zqgs5dkw7xujVs6VEMI GdZoktZixNZDjxmlObWdGupVwNBqdrJDt6f1JHldkYdQDZWLXSbJVvkw5XCziUY2FEY6 ggjg== X-Gm-Message-State: AOAM533l5MHct7Z8noaVn+tDZ7t9Fsuyn4XJK9Pq0h+Nn+4zo7ltz06C /LdWaEu6piaYSqdQuwSl9iTwZOIc3a+z2IBKKM2JEpQq3t9vdPa0x71EKrSjTukYGmcLP5rC/t3 t0YFbi+WFmr2ZjUAdCflxmjgFIi2iYb2XDw== X-Received: by 2002:a05:6e02:12c8:b0:2c6:343f:b38d with SMTP id i8-20020a056e0212c800b002c6343fb38dmr9044945ilm.191.1646683276066; Mon, 07 Mar 2022 12:01:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJy96vcAbo82iuBKo9tD9gfr0H6HRXTec4IyY9lWSXwZ/FMfpgnRmWgQl1B4puiYokwT6kHEiA== X-Received: by 2002:a05:6e02:12c8:b0:2c6:343f:b38d with SMTP id i8-20020a056e0212c800b002c6343fb38dmr9044912ilm.191.1646683275731; Mon, 07 Mar 2022 12:01:15 -0800 (PST) Received: from localhost (c-71-196-238-11.hsd1.co.comcast.net. [71.196.238.11]) by smtp.gmail.com with ESMTPSA id q4-20020a056e0215c400b002c5fdff3087sm12302924ilu.29.2022.03.07.12.01.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 12:01:14 -0800 (PST) From: dann frazier To: stable@vger.kernel.org Cc: Valentin Schneider , Dietmar Eggemann , Peter Zijlstra , Ingo Molnar , Vincent Guittot , John Paul Adrian Glaubitz , Sergei Trofimovich , Anatoly Pugachev , Andrew Morton , Linus Torvalds , linux-kernel@vger.kernel.org Subject: [PATCH 4.19 3/3] ia64: ensure proper NUMA distance and possible map initialization Date: Mon, 7 Mar 2022 13:01:09 -0700 Message-Id: <20220307200109.459214-1-dann.frazier@canonical.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307195941.459076-1-dann.frazier@canonical.com> References: <20220307195941.459076-1-dann.frazier@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Valentin Schneider commit b22a8f7b4bde4e4ab73b64908ffd5d90ecdcdbfd upstream. John Paul reported a warning about bogus NUMA distance values spurred by commit: 620a6dc40754 ("sched/topology: Make sched_init_numa() use a set for the deduplicating sort") In this case, the afflicted machine comes up with a reported 256 possible nodes, all of which are 0 distance away from one another. This was previously silently ignored, but is now caught by the aforementioned commit. The culprit is ia64's node_possible_map which remains unchanged from its initialization value of NODE_MASK_ALL. In John's case, the machine doesn't have any SRAT nor SLIT table, but AIUI the possible map remains untouched regardless of what ACPI tables end up being parsed. Thus, !online && possible nodes remain with a bogus distance of 0 (distances \in [0, 9] are "reserved and have no meaning" as per the ACPI spec). Follow x86 / drivers/base/arch_numa's example and set the possible map to the parsed map, which in this case seems to be the online map. Link: http://lore.kernel.org/r/255d6b5d-194e-eb0e-ecdd-97477a534441@physik.fu-berlin.de Link: https://lkml.kernel.org/r/20210318130617.896309-1-valentin.schneider@arm.com Fixes: 620a6dc40754 ("sched/topology: Make sched_init_numa() use a set for the deduplicating sort") Signed-off-by: Valentin Schneider Reported-by: John Paul Adrian Glaubitz Tested-by: John Paul Adrian Glaubitz Tested-by: Sergei Trofimovich Cc: "Peter Zijlstra (Intel)" Cc: Ingo Molnar Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Anatoly Pugachev Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds [ dannf: minor context adjustment in arch/ia64/kernel/acpi.c ] Signed-off-by: dann frazier --- arch/ia64/kernel/acpi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/ia64/kernel/acpi.c b/arch/ia64/kernel/acpi.c index 1dacbf5e9e09..3856894e86b8 100644 --- a/arch/ia64/kernel/acpi.c +++ b/arch/ia64/kernel/acpi.c @@ -537,7 +537,8 @@ void __init acpi_numa_fixup(void) if (srat_num_cpus == 0) { node_set_online(0); node_cpuid[0].phys_id = hard_smp_processor_id(); - return; + slit_distance(0, 0) = LOCAL_DISTANCE; + goto out; } /* @@ -580,7 +581,7 @@ void __init acpi_numa_fixup(void) for (j = 0; j < MAX_NUMNODES; j++) node_distance(i, j) = i == j ? LOCAL_DISTANCE : REMOTE_DISTANCE; - return; + goto out; } memset(numa_slit, -1, sizeof(numa_slit)); @@ -605,6 +606,8 @@ void __init acpi_numa_fixup(void) printk("\n"); } #endif +out: + node_possible_map = node_online_map; } #endif /* CONFIG_ACPI_NUMA */