From patchwork Mon Aug 22 02:15:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 12950126 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6401DC00140 for ; Mon, 22 Aug 2022 02:19:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hiihpLPve/REZQhUrDB+KXE5M9jiubMXMaKcfLXun9c=; b=bUE+RzKMjqckN3 CMs+EalgWpdcl8gU5pnQHB7/t8zsPF9fU6mCUuJa/NleYPE6WaTEPBwtqFAarGQ0Mo6ofx8AoLI49 k5f9BV2wd0DKa2cOCFnmpCO/PNLGSTlIPXXkRNpxI0UrR6b4dX/yt5aV0CJ0CLLAMTIiOwRqez1Md vppXgngwUx4crf+WDF0ltZrC3qpIr+9lONaP5iSIESkK+2UJr4Cneluj/VMPUeNe9P2Wj/EQv9rPt Arp9V20Rj2+WmvtsBupCRnSiDJQsLlArg8kw6yZzQNd1HuVEJQO+XDkx+4dcM4MgnaiiTr5iWS/eq Hkw1FIYmtbxpf7iGluAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oPx1C-003mtS-1B; Mon, 22 Aug 2022 02:18:22 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oPwzc-003leM-LB for linux-arm-kernel@lists.infradead.org; Mon, 22 Aug 2022 02:16:46 +0000 Received: by mail-pl1-x62e.google.com with SMTP id m2so8679226pls.4 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=3ndb89pHmOOcts49TQhPplytTKJ93aAuGjT6svekScZiFVpO37prpPC3nlv95ySyT4 m+XWg7z17n6pEF1KXVuqr/IK+mY5Hrj1jrAfHqEMOsXKviDAc4qAMfcaRglXX4K/Roxz rMXcj1nHwO/ELxtee7QIawEXI0zcOO6BwwW1d8qUPtjijIYNv1M9wlwwvsffNdbHZbvf Dy8HXKeNnCescFSo2Y5fdbqUSZlikILg8Jy+WK9C5ZlJ7JrFVVhfaHkSJYuokG+e2gzq W2K9hhY+RF82qYYuKh/MB7qZm06XmjRbtnTcBVLfmV0J/ZNCinJ+hYvGFdfh4RLN91MK czIg== X-Gm-Message-State: ACgBeo2FCALlF3jLQhtRhAMhlPH4tqhPSTkyT4tm3vFFxFQ/4QSxg9fx Tly/M35cM4Tlstrpb4x54pqtEEzn+A== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220821_191644_768074_2B1471E9 X-CRM114-Status: GOOD ( 15.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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); /*