Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp37391718rwd; Tue, 11 Jul 2023 13:40:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlFnBOVLDvQ4kUtx27zQb8+G7IVwHciTyiFN6H9oCuB6fud6ietH+EeeTChZotrkBj5IrqM4 X-Received: by 2002:a17:902:e809:b0:1b8:a469:53d8 with SMTP id u9-20020a170902e80900b001b8a46953d8mr21419154plg.0.1689108022343; Tue, 11 Jul 2023 13:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689108022; cv=none; d=google.com; s=arc-20160816; b=xfxB2pOej9MmFXNMT4NaIMHfT6He8fmgM+bmXsV/B9LCqV3a0yPbKuxWUwrTwTbTMT Wv2ko1bqtrVkJoJD+SNzKkneoHwFjPie83pqwGMiCVgYNuE07Lne4QAdWGhsZvZGUT/I WTvr9NjQYWXiOqvOrwlE7b6DRlO4c2oSa1XW52xf/lkFT15Egmj8kg9URJWvBr45bP7Y Rvy6g/NZh8ML31B4S2Ukj5rD3U1gv9wAZFs+MjB9y3/wp6XilXC3wEoGnppwRdj9I4T1 lvzQWVFU22IqeDOZSzvQcKVWFlwowuhiO6uMR4yUzVF7QzbinRjJ+g72dBLR9H4eR1Kh tpbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=wrbYbxmSsn84uXtccGkdG1hHBv4JrqdqdbnPlrwx+qE=; fh=mU6WXvkgmN1mrLNG3Xf0uijnEOsxXEnJii6eEJVoNQA=; b=oON+BKfLClyOKsG0y6wTpsI9IANygSe2r1EmxSt+SoZiLrHQE9JhfuouIXjIlAAr+S aLl750ehMpuX3XzB/1TtN9tf1ALxewiXaT56yUKIPAIIrNuhD+yc1ULO4PNA6PHm+XQv vjp5mURrXxGYuzDqY+WSQFhDbo6wpmpQxhpUobD7pxnhRa8hhevfYntSa1V5KK2J1cuX 67uQOt8aQTm/QjdLOkOMELaff6Cx8dyqGFlQE45kv00TdSgfSCMsdEB4YnzT9Yfz44iW oskGIogSZRN8r0gt5hzZ4p0v35TDBmuhX7+gKL6poYgcPjo5nKsQw8D5ltOZlAVxtAkK qTEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hpe.com header.s=pps0720 header.b="ZN/6ruNI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=hpe.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji2-20020a170903324200b001b9d335175asi1999982plb.292.2023.07.11.13.40.10; Tue, 11 Jul 2023 13:40:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@hpe.com header.s=pps0720 header.b="ZN/6ruNI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=hpe.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbjGKU0r (ORCPT + 99 others); Tue, 11 Jul 2023 16:26:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbjGKU0q (ORCPT ); Tue, 11 Jul 2023 16:26:46 -0400 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C483195 for ; Tue, 11 Jul 2023 13:26:45 -0700 (PDT) Received: from pps.filterd (m0134420.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36BEWD0N010176; Tue, 11 Jul 2023 20:26:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : subject : date : message-id : mime-version : content-transfer-encoding; s=pps0720; bh=wrbYbxmSsn84uXtccGkdG1hHBv4JrqdqdbnPlrwx+qE=; b=ZN/6ruNIdWQL+RPFXjizBeaLe9sPvTdI2CBGTh3eyr7HhNWWguYqX3R/Ocs2CUXXddnD PxY8IziAMYm9jE06np8nx/8bOrNGvlqNpeMCryIZX60tH4JT2H4gXI/Ee4grS3xFE2sC VjJFDvj9A4IrUrhPFtpWTKhBnoHLgkh1h4aFhpcVc77yXVarao8LIouyEiHZBgQJbl8r nafIzNXGU/J8ECwGzx3iNpE0wWzj0ZVZLZ0g47V2R+NAntwhDh7+VL1841/QDhJK2Wha ehs0OurYFf7Fuo6p1qZi/E44fm/B5IFvpa87OwH1+Mb4XJIIKUueynv2TTHZN/ImGkjn cw== Received: from p1lg14879.it.hpe.com (p1lg14879.it.hpe.com [16.230.97.200]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3rrwfj7vnx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Jul 2023 20:26:20 +0000 Received: from p1lg14885.dc01.its.hpecorp.net (unknown [10.119.18.236]) (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 p1lg14879.it.hpe.com (Postfix) with ESMTPS id 0044314799; Tue, 11 Jul 2023 20:26:19 +0000 (UTC) Received: from dog.eag.rdlabs.hpecorp.net (unknown [16.231.227.39]) by p1lg14885.dc01.its.hpecorp.net (Postfix) with ESMTP id D9CF38081F7; Tue, 11 Jul 2023 20:26:18 +0000 (UTC) Received: by dog.eag.rdlabs.hpecorp.net (Postfix, from userid 200934) id 2B261302F47FB; Tue, 11 Jul 2023 15:26:18 -0500 (CDT) From: Steve Wahl To: Steve Wahl , Dimitri Sivanich , Russ Anderson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: [PATCH] x86/platform/uv: Abort UV initialization when reduced nr_cpus requires it Date: Tue, 11 Jul 2023 15:26:18 -0500 Message-Id: <20230711202618.85562-1-steve.wahl@hpe.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-ORIG-GUID: DQUnrhds4lpglLy9FKrTR_ghPaq-sceI X-Proofpoint-GUID: DQUnrhds4lpglLy9FKrTR_ghPaq-sceI X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-11_11,2023-07-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1011 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 adultscore=0 priorityscore=1501 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307110184 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When nr_cpus is set to a smaller number than actually present, there is some node-to-socket mapping info we won't get access to in build_socket_tables(). This could later result in using a -1 value for some array indexing, and eventual kernel page faults. To avoid this, if any unfilled table entries are found, print a warning message, and resume initializing, acting as if this is not a UV system. UV features will be unavailable, but we will not cause kernel dumps. This is a condition we expect only in platform debugging situations, not in day-to-day operation. Fixes: 8a50c5851927 ("x86/platform/uv: UV support for sub-NUMA clustering") Signed-off-by: Steve Wahl --- arch/x86/kernel/apic/x2apic_uv_x.c | 58 ++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c index d9384d5b4b8e..8cf3f61b0000 100644 --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -1567,11 +1567,13 @@ static void __init free_1_to_1_table(unsigned short **tp, char *tname, int min, * If the number of nodes is >1 per socket, socket to node table will * contain lowest node number on that socket. */ -static void __init build_socket_tables(void) +static int __init build_socket_tables(void) { struct uv_gam_range_entry *gre = uv_gre_table; int nums, numn, nump; - int cpu, i, lnid; + int cpu, i, lnid, nid; + int sockid; + int rc = 0; int minsock = _min_socket; int maxsock = _max_socket; int minpnode = _min_pnode; @@ -1580,11 +1582,12 @@ static void __init build_socket_tables(void) if (!gre) { if (is_uv2_hub() || is_uv3_hub()) { pr_info("UV: No UVsystab socket table, ignoring\n"); - return; + return 0; } pr_err("UV: Error: UVsystab address translations not available!\n"); WARN_ON_ONCE(!gre); - return; + rc = -EINVAL; + goto err_free_tables; } numn = num_possible_nodes(); @@ -1596,10 +1599,8 @@ static void __init build_socket_tables(void) || (alloc_conv_table(nums, &_socket_to_pnode) < 0) || (alloc_conv_table(numn, &_node_to_socket) < 0) || (alloc_conv_table(nums, &_socket_to_node) < 0)) { - kfree(_pnode_to_socket); - kfree(_socket_to_pnode); - kfree(_node_to_socket); - return; + rc = -ENOMEM; + goto err_free_tables; } /* Fill in pnode/node/addr conversion list values: */ @@ -1623,9 +1624,9 @@ static void __init build_socket_tables(void) /* Set socket -> node values: */ lnid = NUMA_NO_NODE; for_each_possible_cpu(cpu) { - int nid = cpu_to_node(cpu); - int apicid, sockid; + int apicid; + nid = cpu_to_node(cpu); if (lnid == nid) continue; lnid = nid; @@ -1647,6 +1648,28 @@ static void __init build_socket_tables(void) _socket_to_node[sockid - minsock]); } + /* + * If nr_cpus= is used to reduce the cpu count below + * what's actually present, the cpu loop above may not find + * all the node to socket mappings needed to complete these + * tables. Abort UV init and act like a non-uv system if this + * happens. + */ + for_each_node(nid) { + if (_node_to_socket[nid] == SOCK_EMPTY) { + pr_err("UV: Incomplete node table (nr_cpus too small?)\n"); + rc = -EINVAL; + goto err_free_tables; + } + } + for (sockid = 0; sockid < nums; sockid++) { + if (_socket_to_node[sockid] == SOCK_EMPTY) { + pr_err("UV: Incomplete socket table (nr_cpus too small?)\n"); + rc = -EINVAL; + goto err_free_tables; + } + } + /* * If e.g. socket id == pnode for all pnodes, * system runs faster by removing corresponding conversion table. @@ -1655,6 +1678,17 @@ static void __init build_socket_tables(void) FREE_1_TO_1_TABLE(_node_to_socket, _min_socket, nums, numn); FREE_1_TO_1_TABLE(_socket_to_pnode, _min_pnode, nums, nump); FREE_1_TO_1_TABLE(_pnode_to_socket, _min_pnode, nums, nump); + + return 0; + + err_free_tables: + kfree(_pnode_to_socket); + kfree(_socket_to_pnode); + kfree(_node_to_socket); + kfree(_socket_to_node); + /* make is_uv_system() return false from now on */ + uv_system_type = UV_NONE; + return rc; } /* Check which reboot to use */ @@ -1763,7 +1797,9 @@ static void __init uv_system_init_hub(void) return; } - build_socket_tables(); + if (build_socket_tables() < 0) + return; + build_uv_gr_table(); set_block_size(); uv_init_hub_info(&hub_info); -- 2.26.2