Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2966838rwd; Fri, 19 May 2023 12:47:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5DRkTqaa9+V4P2qFU0KTCouKFEOwZDgMvgHSJt0QPetEUUTMAXrygX686qmwM/PrpTL9Yy X-Received: by 2002:a17:90a:53e2:b0:244:a412:47d7 with SMTP id y89-20020a17090a53e200b00244a41247d7mr2808954pjh.20.1684525662473; Fri, 19 May 2023 12:47:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684525662; cv=none; d=google.com; s=arc-20160816; b=IStDbVCEwXmqO9g/F+57JZTQAAmKgdPrBC0vHoUfJkVZq51YuwvZOqHkP6KCB1qRHm rDxd8MCVT3YH/vGOv5nl595aXK87TFPpSBSy5sD7EaNZAG28mGrg4T9k5A7GSKwnRbbF CqjnLfsxo3TVfPWY+OKruKbFB/9SK/ZokBX8hb1mOZL6RbpZFCvuC/wUyZKl7ZKLJKEW dKuWY+TLLIJP4/k9FcZj7iGxFtW91hjQo8DRPnFTmFOAGGWGc3yFkEENecMh34tTZjEz ui5Htlo0y2arbQKi5e0m5MwsGbZ0BrtZSqMNlxfd5NcAD8Yv6/JyFZiWhHPwkweLJ04m FfWg== 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 :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=rMtFGeLTLqs2vfIhLT9M8T7JC+BTSDdRFHdnK5EA330=; b=WV5jVjC6O1oKoRYdBty+Y2jj1ObSgURKijdGzFiBvtREolPrBX0fCTVFj1pZDWw09y Ftp2ElQ0kh8fwjfR4AdSlvDVSGURAtRXHJErudmOV/i4Nqb9XO0oy2ctMmCLBUXhh2Pe ISDLJ8RaonoEcD10kJOR5czR4GvZBfuUeN/q/O5+zztVwRMdPLAuqelIqbrIZs0AX9ng MQ8caeUtSH6h0wtP1BetadsoqjDrRROujXSJ6BOL7GdrEMV21PWZ199MwQlFdspMTeqt b7S5XZ/sIrvVo8CrDGv5lAn1a91l9cVTchAm0P85yJtVII19ELmVp4BarAQiJjLf6PZn vl6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=XzL5HRaJ; 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 k8-20020a636f08000000b0051b15b58764si118985pgc.343.2023.05.19.12.47.27; Fri, 19 May 2023 12:47:42 -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=XzL5HRaJ; 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 S231209AbjESTJ7 (ORCPT + 99 others); Fri, 19 May 2023 15:09:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230480AbjESTJn (ORCPT ); Fri, 19 May 2023 15:09:43 -0400 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B0C110CE for ; Fri, 19 May 2023 12:09:19 -0700 (PDT) Received: from pps.filterd (m0150245.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34JDTVWA014535; Fri, 19 May 2023 19:07:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pps0720; bh=rMtFGeLTLqs2vfIhLT9M8T7JC+BTSDdRFHdnK5EA330=; b=XzL5HRaJFK+bju2aJNuP5fhqryinCnnwnwagWqvr05NRdH5zUaBqh3YJQ2TNYYnyqs5E IoODkewrcZ8JtTMdNIKVvFtnoPjGJz8qGDC+uxyAi4emREZsGgtmzwRW+oq4E6sQiF4J OjjtPI0JPYCQ6wcnuo28PhayN68ygJ3nYlhryOaSLDfevsFxVSu1vk3BE9R7SoK5RDKo YqMSp4MHuVXsN/WPbmijWC8BIav0YLxdMaqC/l55hxgpHh8BXRz9M4+kR2FI0pzGBPrY S4eVrMjInxNjkqOC4nWbMIikT1bL+v+c53Swcoio0aJQTfL1YFzSrx0c/pyEoQz4C6vT Bg== Received: from p1lg14879.it.hpe.com (p1lg14879.it.hpe.com [16.230.97.200]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3qpa1gamap-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 May 2023 19:07:56 +0000 Received: from p1lg14886.dc01.its.hpecorp.net (unknown [10.119.18.237]) (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 4E11C12E96; Fri, 19 May 2023 19:07:55 +0000 (UTC) Received: from dog.eag.rdlabs.hpecorp.net (unknown [16.231.227.36]) by p1lg14886.dc01.its.hpecorp.net (Postfix) with ESMTP id 0F412810920; Fri, 19 May 2023 19:07:55 +0000 (UTC) Received: by dog.eag.rdlabs.hpecorp.net (Postfix, from userid 200934) id 51A5630313049; Fri, 19 May 2023 14:07:52 -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 RESEND v5 5/8] x86/platform/uv: helper functions for allocating and freeing conversion tables Date: Fri, 19 May 2023 14:07:49 -0500 Message-Id: <20230519190752.3297140-6-steve.wahl@hpe.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20230519190752.3297140-1-steve.wahl@hpe.com> References: <20230519190752.3297140-1-steve.wahl@hpe.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-ORIG-GUID: b-3b5yRCOcMxMuZWYKBIlv42gJsEKfpd X-Proofpoint-GUID: b-3b5yRCOcMxMuZWYKBIlv42gJsEKfpd X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-19_14,2023-05-17_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305190164 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_H2,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 Add alloc_conv_table() and FREE_1_TO_1_TABLE() to reduce duplicated code among the conversion tables we use. Signed-off-by: Steve Wahl --- arch/x86/kernel/apic/x2apic_uv_x.c | 97 ++++++++++++++++-------------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c index 2da84befabf0..1bd15b1f7712 100644 --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -1491,16 +1491,50 @@ static __init void boot_init_possible_blades(struct uv_hub_info_s *hub_info) pr_info("UV: number nodes/possible blades %d\n", uv_pb); } +static int __init alloc_conv_table(int num_elem, unsigned short **table) +{ + int i; + size_t bytes; + + bytes = num_elem * sizeof(*table[0]); + *table = kmalloc(bytes, GFP_KERNEL); + if (WARN_ON_ONCE(!*table)) + return -ENOMEM; + for (i = 0; i < num_elem; i++) + ((unsigned short *)*table)[i] = SOCK_EMPTY; + return 0; +} + +/* Remove conversion table if it's 1:1 */ +#define FREE_1_TO_1_TABLE(tbl, min, max, max2) free_1_to_1_table(&tbl, #tbl, min, max, max2) + +static void __init free_1_to_1_table(unsigned short **tp, char *tname, int min, int max, int max2) +{ + int i; + unsigned short *table = *tp; + + if (table == NULL) + return; + if (max != max2) + return; + for (i = 0; i < max; i++) { + if (i != table[i]) + return; + } + kfree(table); + *tp = NULL; + pr_info("UV: %s is 1:1, conversion table removed\n", tname); +} + static void __init build_socket_tables(void) { struct uv_gam_range_entry *gre = uv_gre_table; - int num, nump; + int nums, numn, nump; int cpu, i, lnid; int minsock = _min_socket; int maxsock = _max_socket; int minpnode = _min_pnode; int maxpnode = _max_pnode; - size_t bytes; if (!gre) { if (is_uv2_hub() || is_uv3_hub()) { @@ -1511,22 +1545,20 @@ static void __init build_socket_tables(void) BUG(); } - /* Build socket id -> node id, pnode */ - num = maxsock - minsock + 1; - bytes = num * sizeof(_socket_to_node[0]); - _socket_to_node = kmalloc(bytes, GFP_KERNEL); - _socket_to_pnode = kmalloc(bytes, GFP_KERNEL); - + numn = num_possible_nodes(); nump = maxpnode - minpnode + 1; - bytes = nump * sizeof(_pnode_to_socket[0]); - _pnode_to_socket = kmalloc(bytes, GFP_KERNEL); - BUG_ON(!_socket_to_node || !_socket_to_pnode || !_pnode_to_socket); - - for (i = 0; i < num; i++) - _socket_to_node[i] = _socket_to_pnode[i] = SOCK_EMPTY; - - for (i = 0; i < nump; i++) - _pnode_to_socket[i] = SOCK_EMPTY; + nums = maxsock - minsock + 1; + + /* Allocate and clear tables */ + if ((alloc_conv_table(nump, &_pnode_to_socket) < 0) + || (alloc_conv_table(nums, &_socket_to_pnode) < 0) + || (alloc_conv_table(numn, &_node_to_pnode) < 0) + || (alloc_conv_table(nums, &_socket_to_node) < 0)) { + kfree(_pnode_to_socket); + kfree(_socket_to_pnode); + kfree(_node_to_pnode); + return; + } /* Fill in pnode/node/addr conversion list values: */ pr_info("UV: GAM Building socket/pnode conversion tables\n"); @@ -1565,10 +1597,6 @@ static void __init build_socket_tables(void) } /* Set up physical blade to pnode translation from GAM Range Table: */ - bytes = num_possible_nodes() * sizeof(_node_to_pnode[0]); - _node_to_pnode = kmalloc(bytes, GFP_KERNEL); - BUG_ON(!_node_to_pnode); - for (lnid = 0; lnid < num_possible_nodes(); lnid++) { unsigned short sockid; @@ -1585,31 +1613,12 @@ static void __init build_socket_tables(void) } /* - * If socket id == pnode or socket id == node for all nodes, + * If e.g. socket id == pnode for all pnodes, * system runs faster by removing corresponding conversion table. */ - pr_info("UV: Checking socket->node/pnode for identity maps\n"); - if (minsock == 0) { - for (i = 0; i < num; i++) - if (_socket_to_node[i] == SOCK_EMPTY || i != _socket_to_node[i]) - break; - if (i >= num) { - kfree(_socket_to_node); - _socket_to_node = NULL; - pr_info("UV: 1:1 socket_to_node table removed\n"); - } - } - if (minsock == minpnode) { - for (i = 0; i < num; i++) - if (_socket_to_pnode[i] != SOCK_EMPTY && - _socket_to_pnode[i] != i + minpnode) - break; - if (i >= num) { - kfree(_socket_to_pnode); - _socket_to_pnode = NULL; - pr_info("UV: 1:1 socket_to_pnode table removed\n"); - } - } + FREE_1_TO_1_TABLE(_socket_to_node, _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); } /* Check which reboot to use */ -- 2.26.2