From patchwork Wed Dec 27 02:39:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 1880391 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cE3ZkEt0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T0G9D4dxPz20Rq for ; Wed, 27 Dec 2023 13:41:04 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cE3ZkEt0; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4T0G9B6z4wz3cHP for ; Wed, 27 Dec 2023 13:41:02 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cE3ZkEt0; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::102b; helo=mail-pj1-x102b.google.com; envelope-from=kernelfans@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4T0G7y3K33z2xcn for ; Wed, 27 Dec 2023 13:39:58 +1100 (AEDT) Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-28b06be7cf6so1724461a91.2 for ; Tue, 26 Dec 2023 18:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703644795; x=1704249595; darn=lists.ozlabs.org; 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=eIL9z1K+903Rh3aHRwyuDGVekLCKVq2u3rRzi6i5f88=; b=cE3ZkEt0RIpUz9FILUFAd46D3HqD3Q/6pR6OCxQksSepfVstO6mXxT6OM3Kko2haY9 RNa0jXGCzeLYZZR4qZbkvPcdZAY1faeX5Mwh0XlEr3S1TN4nvjGBVRP/KYcy9HC5qQ5e fQffnLm62QYjIrQaolI5wD2f90U5iNdB89+1XHxhoxHljtlrGClP3PTwsoXy+uEqROqg lt4+Y2jtyQihSMZkKOAMlQn2lwtW9i8g6btEnb4zgs2dfLZE6Y7hAn+DPFjzpAqTCOuu FniOLjk1nilZk+KN/NLIIw5IVIMnWarO8s2ONkTyFztd1NVNe3Jv4F798zHbnkjhcpfX uwyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703644795; x=1704249595; 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=eIL9z1K+903Rh3aHRwyuDGVekLCKVq2u3rRzi6i5f88=; b=fj1YSuNIlD0EA5dz6f9+lXH+/31Uz5AmApX9KllagUjdiOcM6iSzD0DgRjlrndcaZp +gkaxRc5Dq1Ysc1C0bbbtPZDAuq6fD1QpY/96VClWUDDxifMSffQMWgDec22BwW0lL8t Idn3im9Pz1zNqkm7c9e7tcBGEi9wu941B/gVuCIFVskK/uwK8n5XtO7lRNXuEyXj1xDT RYCqRd3SRZWueUdnI5weVw4A+JD1lwbtuN15MwHMoVJWjGo797e3rQrJoffYyHAczmjN Lc/aZrFXBQKDOEhxFdEDyJy+n1DAwMmGyQqwguPdxrMmP9jk4TtH//TgFRPub6hbfL7X jdWg== X-Gm-Message-State: AOJu0Yw34oQGrZEsaQCJ1rNMe3pTvc7nJ8ZVozbRcE33InRWUzyBv4Qh ftTn0/PpaWdE8nw7kFzkaGSlawVRNQCF X-Google-Smtp-Source: AGHT+IGZvG3gCfSUeZvM4P88xxoLyrISs0xdog3hM2HWUCBOAqPUfCfKMA7wSU2kc9npPVA0sBX3jw== X-Received: by 2002:a17:90a:b396:b0:285:adb1:6acb with SMTP id e22-20020a17090ab39600b00285adb16acbmr2089744pjr.29.1703644795539; Tue, 26 Dec 2023 18:39:55 -0800 (PST) Received: from piliu.users.ipa.redhat.com ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id y8-20020a17090a134800b0028c387b2528sm6727454pjf.8.2023.12.26.18.39.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 18:39:54 -0800 (PST) From: Pingfan Liu To: linuxppc-dev@lists.ozlabs.org Subject: [PATCHv10 1/3] powerpc/kernel: Remove check on paca_ptrs_size Date: Wed, 27 Dec 2023 10:39:32 +0800 Message-Id: <20231227023934.12299-2-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231227023934.12299-1-kernelfans@gmail.com> References: <20231227023934.12299-1-kernelfans@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Baoquan He , Pingfan Liu , kexec@lists.infradead.org, Mahesh Salgaonkar , Ming Lei , Nicholas Piggin , Sourabh Jain , Hari Bathini , Wen Xiong Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Pingfan Liu Between early_setup()->allocate_paca_ptrs() and smp_setup_cpu_maps()->free_unused_pacas(), there is no call to set_nr_cpu_ids(), which means nr_cpu_ids is unchanged. Hence removing the check. Signed-off-by: Pingfan Liu Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: Mahesh Salgaonkar Cc: Wen Xiong Cc: Baoquan He Cc: Ming Lei Cc: Sourabh Jain Cc: Hari Bathini Cc: kexec@lists.infradead.org To: linuxppc-dev@lists.ozlabs.org --- arch/powerpc/kernel/paca.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/arch/powerpc/kernel/paca.c b/arch/powerpc/kernel/paca.c index cda4e00b67c1..760f371cf096 100644 --- a/arch/powerpc/kernel/paca.c +++ b/arch/powerpc/kernel/paca.c @@ -286,16 +286,6 @@ void __init allocate_paca(int cpu) void __init free_unused_pacas(void) { - int new_ptrs_size; - - new_ptrs_size = sizeof(struct paca_struct *) * nr_cpu_ids; - if (new_ptrs_size < paca_ptrs_size) - memblock_phys_free(__pa(paca_ptrs) + new_ptrs_size, - paca_ptrs_size - new_ptrs_size); - - paca_nr_cpu_ids = nr_cpu_ids; - paca_ptrs_size = new_ptrs_size; - #ifdef CONFIG_PPC_64S_HASH_MMU if (early_radix_enabled()) { /* Ugly fixup, see new_slb_shadow() */ @@ -304,9 +294,6 @@ void __init free_unused_pacas(void) paca_ptrs[boot_cpuid]->slb_shadow_ptr = NULL; } #endif - - printk(KERN_DEBUG "Allocated %u bytes for %u pacas\n", - paca_ptrs_size + paca_struct_size, nr_cpu_ids); } #ifdef CONFIG_PPC_64S_HASH_MMU From patchwork Wed Dec 27 02:41:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 1880392 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Jxll0fre; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T0GBB0P4dz20Rq for ; Wed, 27 Dec 2023 13:41:54 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Jxll0fre; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4T0GB95YfHz3cTG for ; Wed, 27 Dec 2023 13:41:53 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Jxll0fre; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::430; helo=mail-pf1-x430.google.com; envelope-from=kernelfans@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4T0G9t48Fgz30gs for ; Wed, 27 Dec 2023 13:41:38 +1100 (AEDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6d99980b2e0so2633649b3a.2 for ; Tue, 26 Dec 2023 18:41:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703644896; x=1704249696; darn=lists.ozlabs.org; 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=DRAGnS9n7iZLPN3fzUPBIgeCsqk3wHeryWyE4pqZfzg=; b=Jxll0freK6OhSPUPku9CLV80/yhnzyX53O69aCEjsXerRbotnfIY5qdMrFPi2LzYDi /6CtqWqRUqExGhzrHtnAVON0FKedFZJ8llYsmBwIhhJauv+4DduQID7kzc0hXes6lztm 5m1L/7vlCEiEirIWgNSh9KY+f61E/vOgxfcNJAQ3dJtSfz4dAd6IzvPhyH5dOK891OWj BzakGeHOoa7gSx2cuYbo1ozBT6te5uBDM0sPpOgIvtAURfz928CliVnjMahvJ81QD01b KXf/tJQpG2Q+YKfgF3pgq1QCf1H0bymZ0GciWLjVtGmlsnRhSo6hiiA4JZOKId8DHGyd F1+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703644896; x=1704249696; 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=DRAGnS9n7iZLPN3fzUPBIgeCsqk3wHeryWyE4pqZfzg=; b=mrX0C4WsJ+hTR8eA5fInE0sCMn+yCLPuPfbjRJ949q6OhR6TQ741LOdXanH69Xa46T 2gcQ3vwy3S/HLKFukqGlZCuFI4q9ueQm6Dex44BoxrWwdnCNLBvwIEyvxEEgXfiYPEn/ V8k4Rg58ACr71XHa9/EwSaKqwnn98WvbRjq0PhfhqFVP7HpqRt2RgcOva/3AZetBP7d2 CAD57e8zIb8xbyJjpBaH08VyI57bdwWo9/byUrTcjV7h+XP8UXMO4/0NsCMDx5ckIQmf wHjbcpqvlBgE+POFMmc3GwMxECNxTDbQNVBeFadEvZopKe3G6DiSLvPfnIwbq9WCJoAE jAGg== X-Gm-Message-State: AOJu0YwFs+e622t5zoCBp5uam2CFIkvhQcA7WXwWWL0kBqOzG917fDUx S3P5w9wUPtQx3Ow5vKM5gJgNDo2I8Ou5 X-Google-Smtp-Source: AGHT+IHjk3AA3JcUV9M8k0oIpnUVqTmwmZDYX45WozIhC7j5KkqBhbvaKT0XP5lHWjRaKq44NwhggA== X-Received: by 2002:a05:6a00:b20:b0:6d9:b5ce:f17e with SMTP id f32-20020a056a000b2000b006d9b5cef17emr4195836pfu.5.1703644895865; Tue, 26 Dec 2023 18:41:35 -0800 (PST) Received: from piliu.users.ipa.redhat.com ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id g5-20020aa78745000000b006d9af8c25easm5449200pfo.84.2023.12.26.18.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 18:41:35 -0800 (PST) From: Pingfan Liu To: linuxppc-dev@lists.ozlabs.org Subject: [PATCHv10 2/3] powerpc/kernel: Extend arrays' size to make room for a hole in cpu_possible_mask Date: Wed, 27 Dec 2023 10:41:26 +0800 Message-Id: <20231227024126.12424-1-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231227023934.12299-1-kernelfans@gmail.com> References: <20231227023934.12299-1-kernelfans@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Baoquan He , Pingfan Liu , kexec@lists.infradead.org, Mahesh Salgaonkar , Ming Lei , Nicholas Piggin , Sourabh Jain , Hari Bathini , Wen Xiong Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Pingfan Liu This patch aims to mark all the arrays which size is decided by nr_cpu_ids or num_possible_cpus(). Later if a hole is allowed in cpu_possible_mask, the corresponding array should extend to hold the last bit number in cpu_possible_mask. Signed-off-by: Pingfan Liu Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: Mahesh Salgaonkar Cc: Wen Xiong Cc: Baoquan He Cc: Ming Lei Cc: Sourabh Jain Cc: Hari Bathini Cc: kexec@lists.infradead.org To: linuxppc-dev@lists.ozlabs.org --- arch/powerpc/include/asm/paca.h | 2 ++ arch/powerpc/kernel/paca.c | 8 ++++---- arch/powerpc/kernel/setup-common.c | 2 +- arch/powerpc/kernel/smp.c | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h index e667d455ecb4..a577d98dd0d8 100644 --- a/arch/powerpc/include/asm/paca.h +++ b/arch/powerpc/include/asm/paca.h @@ -299,5 +299,7 @@ static inline void free_unused_pacas(void) { } #endif /* CONFIG_PPC64 */ +extern int paca_last_cpu_num; + #endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_PACA_H */ diff --git a/arch/powerpc/kernel/paca.c b/arch/powerpc/kernel/paca.c index 760f371cf096..840c74dd17d6 100644 --- a/arch/powerpc/kernel/paca.c +++ b/arch/powerpc/kernel/paca.c @@ -236,15 +236,15 @@ void setup_paca(struct paca_struct *new_paca) } -static int __initdata paca_nr_cpu_ids; +int __initdata paca_last_cpu_num; static int __initdata paca_ptrs_size; static int __initdata paca_struct_size; void __init allocate_paca_ptrs(void) { - paca_nr_cpu_ids = nr_cpu_ids; + paca_last_cpu_num = nr_cpu_ids; - paca_ptrs_size = sizeof(struct paca_struct *) * nr_cpu_ids; + paca_ptrs_size = sizeof(struct paca_struct *) * paca_last_cpu_num; paca_ptrs = memblock_alloc_raw(paca_ptrs_size, SMP_CACHE_BYTES); if (!paca_ptrs) panic("Failed to allocate %d bytes for paca pointers\n", @@ -258,7 +258,7 @@ void __init allocate_paca(int cpu) u64 limit; struct paca_struct *paca; - BUG_ON(cpu >= paca_nr_cpu_ids); + BUG_ON(cpu >= paca_last_cpu_num); #ifdef CONFIG_PPC_BOOK3S_64 /* diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c index 2f1026fba00d..f9f5f313abf0 100644 --- a/arch/powerpc/kernel/setup-common.c +++ b/arch/powerpc/kernel/setup-common.c @@ -453,7 +453,7 @@ void __init smp_setup_cpu_maps(void) DBG("smp_setup_cpu_maps()\n"); - cpu_to_phys_id = memblock_alloc(nr_cpu_ids * sizeof(u32), + cpu_to_phys_id = memblock_alloc(paca_last_cpu_num * sizeof(u32), __alignof__(u32)); if (!cpu_to_phys_id) panic("%s: Failed to allocate %zu bytes align=0x%zx\n", diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c index 5826f5108a12..6fefe22fd118 100644 --- a/arch/powerpc/kernel/smp.c +++ b/arch/powerpc/kernel/smp.c @@ -1140,7 +1140,8 @@ void __init smp_prepare_cpus(unsigned int max_cpus) } if (cpu_to_chip_id(boot_cpuid) != -1) { - int idx = DIV_ROUND_UP(num_possible_cpus(), threads_per_core); + int idx = DIV_ROUND_UP(cpumask_last(cpu_possible_mask), + threads_per_core); /* * All threads of a core will all belong to the same core, From patchwork Wed Dec 27 02:41:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 1880393 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=QuJXBe2X; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T0GC36mMSz20Rq for ; Wed, 27 Dec 2023 13:42:39 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=QuJXBe2X; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4T0GC34vjlz3cSn for ; Wed, 27 Dec 2023 13:42:39 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=QuJXBe2X; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::631; helo=mail-pl1-x631.google.com; envelope-from=kernelfans@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4T0GBG39Pgz3cVk for ; Wed, 27 Dec 2023 13:41:58 +1100 (AEDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1d3fc184b6dso17504095ad.2 for ; Tue, 26 Dec 2023 18:41:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703644915; x=1704249715; darn=lists.ozlabs.org; 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=MT7htYeDjY4vTdy1fPJWLnQt0GHG3z7MAu24V6teBIw=; b=QuJXBe2XlG7dzQKaW0YbEjBvaoEyDL1NfI/aOp4I+bvandm09NihA7k5vO3GYtjIzz 75AScHdIa1Ea+EoYTRqQZRpN3PtmfnhHwDmKnv5csAGSfmL6PFCPestGui14vCFOfuPB V4CZpsyQ/pnaTUrP5wwVlWWG7KfTxNC0xPl0sne1KRVfhbHznU+2aj7vg9I+1b2f63St n5vdcrAs9pO87WZOlby4r8oLABQ3Ju66Tt7ETQ3Sh8OyWYsGM84FANswPmUcoGte1dyT dW5cyqCw5vzMfzSslFTokYlL3/Fqmoiw80EODxhhWgeLNJYAkuD7BS3AsPEIjRcHokuB +Yqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703644915; x=1704249715; 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=MT7htYeDjY4vTdy1fPJWLnQt0GHG3z7MAu24V6teBIw=; b=Xhu820Z3sXN5Nk59Ey05d9qWMJzn0jeGMNUhAy4YnmtTbDizdD6DDIR5t6HpQ46IWw 2TjRc29vsK8pYQZUFsHmQX7u/IwrUB8Ef9LSMID5CtdLqmsKU95HwUymheWftIJnMw43 UA5m6JV8702mN8NFPMqAupOQRzORcLbJPdbOPY4nvPIRk8cGOdtfq8bc/PpkBOvbzjLR yZpCU4TI0iWnAZp0AcJnMmIN/Z+YN2OXuJ40pnooyxvYV0yBmS67FadttUGBQnqkTICA b9AazgSwoxkFQdUsPnUBYwn4K3pwTdO8lJ0ohm5s4PMMy5tyfAUamz+Ex/lCCa67zv0Q 9IwA== X-Gm-Message-State: AOJu0YzNfKZ8ook1wehiGjfrBZVJiwnftN5faHHZA09MhJaUkBOC6QiF ccjSRV+14MDLOEC6Gobkp+IJTIdXafrf X-Google-Smtp-Source: AGHT+IHCsge0Pwx3Fk+jrn3t8Mdnc4E5lcxUmO+ET7NbuD+U2d5OqeN9CRJcKSbmZQ7LgIFhpLQ4VQ== X-Received: by 2002:a17:902:d584:b0:1d0:6ffd:8367 with SMTP id k4-20020a170902d58400b001d06ffd8367mr2747235plh.114.1703644915441; Tue, 26 Dec 2023 18:41:55 -0800 (PST) Received: from piliu.users.ipa.redhat.com ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id jj20-20020a170903049400b001c61073b076sm10775062plb.144.2023.12.26.18.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 18:41:54 -0800 (PST) From: Pingfan Liu To: linuxppc-dev@lists.ozlabs.org Subject: [PATCHv10 3/3] powerpc/smp: Allow hole in paca_ptrs to accommodate boot_cpu Date: Wed, 27 Dec 2023 10:41:47 +0800 Message-Id: <20231227024147.12485-1-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231227023934.12299-1-kernelfans@gmail.com> References: <20231227023934.12299-1-kernelfans@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Baoquan He , Pingfan Liu , kexec@lists.infradead.org, Mahesh Salgaonkar , Ming Lei , Nicholas Piggin , Sourabh Jain , Hari Bathini , Wen Xiong Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Pingfan Liu This patch always forces the first core onlined due to some subsystem needs cpu0. After core0, a hole may follow, then comes the crashed core. Signed-off-by: Pingfan Liu Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: Mahesh Salgaonkar Cc: Wen Xiong Cc: Baoquan He Cc: Ming Lei Cc: Sourabh Jain Cc: Hari Bathini Cc: kexec@lists.infradead.org To: linuxppc-dev@lists.ozlabs.org --- arch/powerpc/include/asm/smp.h | 1 + arch/powerpc/kernel/paca.c | 7 +++++-- arch/powerpc/kernel/prom.c | 6 ++++++ arch/powerpc/kernel/setup-common.c | 24 ++++++++++++++++++++---- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h index aaaa576d0e15..f01c7891b0d7 100644 --- a/arch/powerpc/include/asm/smp.h +++ b/arch/powerpc/include/asm/smp.h @@ -27,6 +27,7 @@ extern int boot_cpuid; extern int boot_cpu_hwid; /* PPC64 only */ +extern int threads_in_core; extern int spinning_secondaries; extern u32 *cpu_to_phys_id; extern bool coregroup_enabled; diff --git a/arch/powerpc/kernel/paca.c b/arch/powerpc/kernel/paca.c index 840c74dd17d6..1fe0fd2a6021 100644 --- a/arch/powerpc/kernel/paca.c +++ b/arch/powerpc/kernel/paca.c @@ -242,9 +242,12 @@ static int __initdata paca_struct_size; void __init allocate_paca_ptrs(void) { - paca_last_cpu_num = nr_cpu_ids; + unsigned int cnt; - paca_ptrs_size = sizeof(struct paca_struct *) * paca_last_cpu_num; + /* paca_ptrs should be big enough to hold boot cpu */ + cnt = max((unsigned int)ALIGN(boot_cpuid + 1, threads_in_core), nr_cpu_ids); + paca_last_cpu_num = cnt; + paca_ptrs_size = sizeof(struct paca_struct *) * cnt; paca_ptrs = memblock_alloc_raw(paca_ptrs_size, SMP_CACHE_BYTES); if (!paca_ptrs) panic("Failed to allocate %d bytes for paca pointers\n", diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 0b5878c3125b..e1a671156941 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -371,9 +371,15 @@ static int __init early_init_dt_scan_cpus(unsigned long node, DBG("boot cpu: logical %d physical %d\n", found, be32_to_cpu(intserv[found_thread])); boot_cpuid = found; + /* This forces all threads in a core to be onlined */ + set_nr_cpu_ids(ALIGN(nr_cpu_ids, nthreads)); + /* Core 0 is always onlined and assure enough room for boot core */ + if (nthreads -1 < boot_cpuid && nr_cpu_ids < 2 * nthreads) + set_nr_cpu_ids(2 * nthreads); if (IS_ENABLED(CONFIG_PPC64)) boot_cpu_hwid = be32_to_cpu(intserv[found_thread]); + threads_in_core = nthreads; /* * PAPR defines "logical" PVR values for cpus that diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c index f9f5f313abf0..b70474e1b5fe 100644 --- a/arch/powerpc/kernel/setup-common.c +++ b/arch/powerpc/kernel/setup-common.c @@ -86,6 +86,7 @@ EXPORT_SYMBOL(machine_id); int boot_cpuid = -1; EXPORT_SYMBOL_GPL(boot_cpuid); +int __initdata threads_in_core = 1; #ifdef CONFIG_PPC64 int boot_cpu_hwid = -1; @@ -448,8 +449,9 @@ u32 *cpu_to_phys_id = NULL; void __init smp_setup_cpu_maps(void) { struct device_node *dn; - int cpu = 0; + int cpu_onlined = 0, cpu = 0; int nthreads = 1; + bool bootcpu_covered = false; DBG("smp_setup_cpu_maps()\n"); @@ -484,7 +486,19 @@ void __init smp_setup_cpu_maps(void) nthreads = len / sizeof(int); - for (j = 0; j < nthreads && cpu < nr_cpu_ids; j++) { + if (!bootcpu_covered) { + if (cpu == ALIGN_DOWN(boot_cpuid, nthreads)) { + bootcpu_covered = true; + goto scan; + + /* Reserve the last online slot for boot core */ + } else if (cpu >= nr_cpu_ids - nthreads && !bootcpu_covered) { + cpu += nthreads; + continue; + } + } +scan: + for (j = 0; j < nthreads && cpu_onlined < nr_cpu_ids; j++) { bool avail; DBG(" thread %d -> cpu %d (hard id %d)\n", @@ -499,9 +513,10 @@ void __init smp_setup_cpu_maps(void) set_cpu_possible(cpu, true); cpu_to_phys_id[cpu] = be32_to_cpu(intserv[j]); cpu++; + cpu_onlined++; } - if (cpu >= nr_cpu_ids) { + if (cpu_onlined >= nr_cpu_ids) { of_node_put(dn); break; } @@ -547,7 +562,8 @@ void __init smp_setup_cpu_maps(void) printk(KERN_INFO "Partition configured for %d cpus.\n", maxcpus); - for (cpu = 0; cpu < maxcpus; cpu++) + /* Bits below #cpu have been set */ + for (; cpu < maxcpus; cpu++) set_cpu_possible(cpu, true); out: of_node_put(dn);