From patchwork Thu Jun 25 13:37:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salil Mehta X-Patchwork-Id: 11625389 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E182F14E3 for ; Thu, 25 Jun 2020 13:45:49 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BA5F520781 for ; Thu, 25 Jun 2020 13:45:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="vnEzmgWD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA5F520781 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=alj34k9YWu5dclvBcK3tN1svOqOlrnJzJI2HhGxBQA8=; b=vnEzmgWD1YA38Nd5hLkQ2d/Kq /VIecDpByVrHIZihBsO48FlcRws0+SuYnKMDL/mIbKkYMjYvCGpZdWVlhtrIlift7fdMPTxUdfcCa ChvpMR4Um3S4Q+wl8SHA4utsHbnre/lguHLK0uSMikFLgiKhaARVb9jqPrRLSGEKKAi0LTQOWCQ6r xUfjHaxwsUXXuqfgzimavULwiY/lMUshC58UZpN9jEtx3VQs6K/2T4KDN58TuCRDrDTjbleA+7aov /NgZC7YYfBruAF7tu04jUosAWOPcp1nMS+h6GcVbGhZ8vhobhmrYgu022vgu511fv6iiOATY8Wdjn j8nwUlT3Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1joSAm-0004qd-Gg; Thu, 25 Jun 2020 13:44:12 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32] helo=huawei.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1joSAk-0004pA-3P for linux-arm-kernel@lists.infradead.org; Thu, 25 Jun 2020 13:44:11 +0000 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 6F308B2C6D69505DCE5A; Thu, 25 Jun 2020 21:44:05 +0800 (CST) Received: from A190218597.china.huawei.com (10.47.76.118) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Thu, 25 Jun 2020 21:43:54 +0800 From: Salil Mehta To: Subject: [PATCH RFC 2/4] arm64: kernel: Bound the total(present+disabled) cpus with nr_cpu_ids Date: Thu, 25 Jun 2020 14:37:55 +0100 Message-ID: <20200625133757.22332-3-salil.mehta@huawei.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20200625133757.22332-1-salil.mehta@huawei.com> References: <20200625133757.22332-1-salil.mehta@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.76.118] X-CFilter-Loop: Reflected X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.32 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [45.249.212.32 listed in wl.mailspike.net] 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, peter.maydell@linaro.org, gshan@redhat.com, kvm@vger.kernel.org, mst@redhat.com, catalin.marinas@arm.com, linuxarm@huawei.com, linux-kernel@vger.kernel.org, will@kernel.org, Xiongfeng Wang , lorenzo.pieralisi@arm.com, maz@kernel.org, david@redhat.com, drjones@redhat.com, andre.przywara@arm.com, mehta.salil.lnk@gmail.com, richard.henderson@linaro.org, eric.auger@redhat.com, qemu-arm@nongnu.org, imammedo@redhat.com, Salil Mehta , christoffer.dall@arm.com, james.morse@arm.com, sudeep.holla@arm.com, pbonzini@redhat.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Bound the total number of identified cpus(including disabled cpus) by maximum allowed limit by the kernel. Max value is either specified as part of the kernel parameters 'nr_cpus' or specified during compile time using CONFIG_NR_CPUS. Signed-off-by: Salil Mehta Signed-off-by: Xiongfeng Wang --- arch/arm64/kernel/smp.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 51a707928302..864ccd3da419 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -513,6 +513,7 @@ static int __init smp_cpu_setup(int cpu) } static bool bootcpu_valid __initdata; +static bool cpus_clipped __initdata = false; static unsigned int cpu_count = 1; static unsigned int disabled_cpu_count; @@ -536,6 +537,11 @@ acpi_map_gic_cpu_interface(struct acpi_madt_generic_interrupt *processor) unsigned int total_cpu_count = disabled_cpu_count + cpu_count; u64 hwid = processor->arm_mpidr; + if (total_cpu_count > nr_cpu_ids) { + cpus_clipped = true; + return; + } + if (!(processor->flags & ACPI_MADT_ENABLED)) { #ifndef CONFIG_ACPI_HOTPLUG_CPU pr_debug("skipping disabled CPU entry with 0x%llx MPIDR\n", hwid); @@ -569,9 +575,6 @@ acpi_map_gic_cpu_interface(struct acpi_madt_generic_interrupt *processor) return; } - if (cpu_count >= NR_CPUS) - return; - /* map the logical cpu id to cpu MPIDR */ cpu_logical_map(total_cpu_count) = hwid; @@ -688,8 +691,10 @@ static void __init of_parse_and_init_cpus(void) continue; } - if (cpu_count >= NR_CPUS) + if (cpu_count >= NR_CPUS) { + cpus_clipped = true; goto next; + } pr_debug("cpu logical map 0x%llx\n", hwid); cpu_logical_map(cpu_count) = hwid; @@ -710,6 +715,7 @@ static void __init of_parse_and_init_cpus(void) */ void __init smp_init_cpus(void) { + unsigned int total_cpu_count = disabled_cpu_count + cpu_count; int i; if (acpi_disabled) @@ -717,9 +723,9 @@ void __init smp_init_cpus(void) else acpi_parse_and_init_cpus(); - if (cpu_count > nr_cpu_ids) + if (cpus_clipped) pr_warn("Number of cores (%d) exceeds configured maximum of %u - clipping\n", - cpu_count, nr_cpu_ids); + total_cpu_count, nr_cpu_ids); if (!bootcpu_valid) { pr_err("missing boot CPU MPIDR, not enabling secondaries\n");