From mboxrd@z Thu Jan 1 00:00:00 1970 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 82651C00140 for ; Mon, 22 Aug 2022 02:17:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232508AbiHVCRM (ORCPT ); Sun, 21 Aug 2022 22:17:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232413AbiHVCQo (ORCPT ); Sun, 21 Aug 2022 22:16:44 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 937F122B34 for ; Sun, 21 Aug 2022 19:16:43 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id u22so8652404plq.12 for ; Sun, 21 Aug 2022 19:16:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=PHnhWNxyM6E9IxuW9zPMNCsqVfB66utEZnswI2QVnUY=; b=moyaT8LSzbsNueFItnBmXfweqqJW9rd5NwnfMitdVq1qYPLzlWYAklL72LaXB9oDvS JpCgS1YpoIHyPnh0KSuubJSnDsEtvOt1uncB6yxmaK8MQOhSUye5ULeoyFZ8gLHcgLtm CZha7A0JSZxdrdNhCQIMcHj8tXNLhk7KWvT6y/0bqmWktx98ivUpz7ndxNdcnYsvd4Gv djm4Wghi5lRR/MwRT4vwVy70tUYaHEdli5D2yg/fRmtSZ4BS+A33PfPf0bFw2aQWfAY8 ieb8o1pFrhi9TXDdC7A1CU5ozlkzki6nUWCPZilyRhE0maI0dWIklZ1jVX0QH4g3WCqd nXxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=PHnhWNxyM6E9IxuW9zPMNCsqVfB66utEZnswI2QVnUY=; b=jhl2tQ5whCyjlssfauajxzmwSbQ94GcGetZL4l2ZnSstahovw6SdiOVDkwtGTO4hIx Z7eacy927u0EpsfDQCo7y7+kli/I//p+p+XTL4pKeDtSO15rHdc1QlvcxqjlL4Uj8qKo MVybAMa2jPDTnJuFmcTt/lEOcJN3qYoCEHzFGCDtQRQpVOGlsxNoPzvphZ9D0hFbaYFb lN2/+0Qa5eK3JaoJaeOzjB0snwN1NtHPiJDEC+6NyIWM0xLEQrQcHT2G8c7DQfYZM9TN 9tlO8/WL9JSwJ6+ucR3AEYNvALBo86Llvl4YlJvz/4iol3vD4wCdzY5YBpUZNV8cvHxS Ck4Q== X-Gm-Message-State: ACgBeo0oiZyXEti1ELq6yGcm54dbTtZSY/R1IPxHJKvwWrgavnedHbEm kYzhwrG0+RKA3sttJ33XNA== X-Google-Smtp-Source: AA6agR57jl9X7wl2LO5S9m+7exo7QRftfzMvBzue936dsrZ1sTIFM7iDKbI/NpJ/4k6h+XhaKlz7WA== X-Received: by 2002:a17:90a:c402:b0:1f8:c335:d4d7 with SMTP id i2-20020a17090ac40200b001f8c335d4d7mr26607609pjt.242.1661134602655; Sun, 21 Aug 2022 19:16:42 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k3-20020aa79723000000b005321340753fsm7312139pfg.103.2022.08.21.19.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 19:16:42 -0700 (PDT) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Pingfan Liu , Catalin Marinas , Will Deacon , Viresh Kumar , Sudeep Holla , Phil Auld , Rob Herring , Ben Dooks Subject: [RFC 10/10] arm64: smp: Make __cpu_disable() parallel Date: Mon, 22 Aug 2022 10:15:20 +0800 Message-Id: <20220822021520.6996-11-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220822021520.6996-1-kernelfans@gmail.com> References: <20220822021520.6996-1-kernelfans@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On a dying cpu, take_cpu_down()->__cpu_disable(), which means if the teardown path supports parallel, __cpu_disable() confront the parallel, which may ruin cpu_online_mask etc if no extra lock provides the protection. At present, the cpumask is protected by cpu_add_remove_lock, that lock is quite above __cpu_disable(). In order to protect __cpu_disable() from parrallel in kexec quick reboot path, introducing a local lock cpumap_lock. Signed-off-by: Pingfan Liu Cc: Catalin Marinas Cc: Will Deacon Cc: Viresh Kumar Cc: Sudeep Holla Cc: Phil Auld Cc: Rob Herring Cc: Ben Dooks To: linux-arm-kernel@lists.infradead.org To: linux-kernel@vger.kernel.org --- arch/arm64/kernel/smp.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index ffc5d76cf695..fee8879048b0 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -287,6 +287,28 @@ static int op_cpu_disable(unsigned int cpu) return 0; } +static DEFINE_SPINLOCK(cpumap_lock); + +static void __cpu_clear_maps(unsigned int cpu) +{ + /* + * In the case of kexec rebooting, the cpu_add_remove_lock mutex can not protect + */ + if (kexec_in_progress) + spin_lock(&cpumap_lock); + remove_cpu_topology(cpu); + numa_remove_cpu(cpu); + + /* + * Take this CPU offline. Once we clear this, we can't return, + * and we must not schedule until we're ready to give up the cpu. + */ + set_cpu_online(cpu, false); + if (kexec_in_progress) + spin_unlock(&cpumap_lock); + +} + /* * __cpu_disable runs on the processor to be shutdown. */ @@ -299,14 +321,7 @@ int __cpu_disable(void) if (ret) return ret; - remove_cpu_topology(cpu); - numa_remove_cpu(cpu); - - /* - * Take this CPU offline. Once we clear this, we can't return, - * and we must not schedule until we're ready to give up the cpu. - */ - set_cpu_online(cpu, false); + __cpu_clear_maps(cpu); ipi_teardown(cpu); /* -- 2.31.1