Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1620121pxp; Thu, 17 Mar 2022 12:54:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdjr1OUj/l7uiYUZHVhEM0HLhV8GF/X3OnCSXBTfsVGe2rIDZiiBI/oTHx7gyijIOvnFxJ X-Received: by 2002:a05:6a00:1253:b0:4f7:61c7:9313 with SMTP id u19-20020a056a00125300b004f761c79313mr6182482pfi.14.1647546860177; Thu, 17 Mar 2022 12:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647546860; cv=none; d=google.com; s=arc-20160816; b=pO6bAY4DjNsSO0H80snlDxZRNp2J2yVrkOFWfPphDtPKTl2UrIIfZ0xR4oPfei1nBh HGJi943SFQlRrTCmWXOM2yB+8uzXBEMQQi2Bz8tUFxT+my7XsbHPD6uWUfw/z2QFS2IO rBVHufxmcQiMD0Ai1kq8Px9S45Ig82Lct1kJv5tqPRVJCJWbGte8UdnYyC4LGHZFOgVl oFKGo3j47kd/5h884KLsS8ToMnbK3LDqhQa7W3plxVvysIavlhSXQgogbsy377LpYi95 k4RalLqEVyINKK+3qsoBSsKIJMt1z45D+NC9uAdMI95F7WQO0hrs3AcZ2FZTJjhlFkeM SqTg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yngcTsuFvM1sjL3iU0hFqx0soMtXJ9X2zdkxjXynBq4=; b=RvUR1arDgaPB//opx6JoWuGXSaJS0jm7ayKqOmy5q3ciBEa8nH+Z8FZD8+U8VamhJU g041TpN8iAkQ7Qpl8EU1noDC7/jrA+vxGiD1MJBXDtDR00jVX556b70W/+LHSOx7kHAD U3RmubOYtu3h+w4DHW4F1lMnkGm8uM8rWw9PqqGqwVVtmesUF07K35EVuG3BtRL974W4 /IOVcu82FMK2iv1eYV5vQ1Y5keFUEoSngOp50/NNPCT2j+PJbknOFnxjWUBx6Q9woaFP /BLI/dFxd6k0n1knfK4cSfZLDrbEnwGLVVCzX5YocIdTzeaU8XCBfqGFvIL8xcI+/N/t ExFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DeuGyHK9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id hf4-20020a17090aff8400b001c6363b0c53si3163137pjb.117.2022.03.17.12.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 12:54:20 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DeuGyHK9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1763A11CF60; Thu, 17 Mar 2022 12:48:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233913AbiCQMuG (ORCPT + 99 others); Thu, 17 Mar 2022 08:50:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233889AbiCQMta (ORCPT ); Thu, 17 Mar 2022 08:49:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74C6B1F0CA2; Thu, 17 Mar 2022 05:48:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AB73FB81E8F; Thu, 17 Mar 2022 12:48:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F403C340ED; Thu, 17 Mar 2022 12:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647521287; bh=aEYPqwArAW+uwcXlKMY5N85b/gaIqcBdlnG6nxEOdnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DeuGyHK9s4istAcFq3l1eu7RXImaQrQ+udTWRhOIok6x2WhsMUT0LmtYsKtALMVPs ULijL4wWhdMz7J2Dtz3ev7BCm55emEufSTkU2mcCtHG+uDdvF2zv9rM8roJs4f+nPi GZoa0aof20sZUwtp7kSaf/yI3GFaaRRLvpyDv0Ww= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Lobakin , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Bogendoerfer , Sasha Levin Subject: [PATCH 5.4 33/43] MIPS: smp: fill in sibling and core maps earlier Date: Thu, 17 Mar 2022 13:45:44 +0100 Message-Id: <20220317124528.589586207@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220317124527.672236844@linuxfoundation.org> References: <20220317124527.672236844@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Alexander Lobakin [ Upstream commit f2703def339c793674010cc9f01bfe4980231808 ] After enabling CONFIG_SCHED_CORE (landed during 5.14 cycle), 2-core 2-thread-per-core interAptiv (CPS-driven) started emitting the following: [ 0.025698] CPU1 revision is: 0001a120 (MIPS interAptiv (multi)) [ 0.048183] ------------[ cut here ]------------ [ 0.048187] WARNING: CPU: 1 PID: 0 at kernel/sched/core.c:6025 sched_core_cpu_starting+0x198/0x240 [ 0.048220] Modules linked in: [ 0.048233] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.17.0-rc3+ #35 b7b319f24073fd9a3c2aa7ad15fb7993eec0b26f [ 0.048247] Stack : 817f0000 00000004 327804c8 810eb050 00000000 00000004 00000000 c314fdd1 [ 0.048278] 830cbd64 819c0000 81800000 817f0000 83070bf4 00000001 830cbd08 00000000 [ 0.048307] 00000000 00000000 815fcbc4 00000000 00000000 00000000 00000000 00000000 [ 0.048334] 00000000 00000000 00000000 00000000 817f0000 00000000 00000000 817f6f34 [ 0.048361] 817f0000 818a3c00 817f0000 00000004 00000000 00000000 4dc33260 0018c933 [ 0.048389] ... [ 0.048396] Call Trace: [ 0.048399] [<8105a7bc>] show_stack+0x3c/0x140 [ 0.048424] [<8131c2a0>] dump_stack_lvl+0x60/0x80 [ 0.048440] [<8108b5c0>] __warn+0xc0/0xf4 [ 0.048454] [<8108b658>] warn_slowpath_fmt+0x64/0x10c [ 0.048467] [<810bd418>] sched_core_cpu_starting+0x198/0x240 [ 0.048483] [<810c6514>] sched_cpu_starting+0x14/0x80 [ 0.048497] [<8108c0f8>] cpuhp_invoke_callback_range+0x78/0x140 [ 0.048510] [<8108d914>] notify_cpu_starting+0x94/0x140 [ 0.048523] [<8106593c>] start_secondary+0xbc/0x280 [ 0.048539] [ 0.048543] ---[ end trace 0000000000000000 ]--- [ 0.048636] Synchronize counters for CPU 1: done. ...for each but CPU 0/boot. Basic debug printks right before the mentioned line say: [ 0.048170] CPU: 1, smt_mask: So smt_mask, which is sibling mask obviously, is empty when entering the function. This is critical, as sched_core_cpu_starting() calculates core-scheduling parameters only once per CPU start, and it's crucial to have all the parameters filled in at that moment (at least it uses cpu_smt_mask() which in fact is `&cpu_sibling_map[cpu]` on MIPS). A bit of debugging led me to that set_cpu_sibling_map() performing the actual map calculation, was being invocated after notify_cpu_start(), and exactly the latter function starts CPU HP callback round (sched_core_cpu_starting() is basically a CPU HP callback). While the flow is same on ARM64 (maps after the notifier, although before calling set_cpu_online()), x86 started calculating sibling maps earlier than starting the CPU HP callbacks in Linux 4.14 (see [0] for the reference). Neither me nor my brief tests couldn't find any potential caveats in calculating the maps right after performing delay calibration, but the WARN splat is now gone. The very same debug prints now yield exactly what I expected from them: [ 0.048433] CPU: 1, smt_mask: 0-1 [0] https://git.kernel.org/pub/scm/linux/kernel/git/mips/linux.git/commit/?id=76ce7cfe35ef Signed-off-by: Alexander Lobakin Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Thomas Bogendoerfer Signed-off-by: Sasha Levin --- arch/mips/kernel/smp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c index f510c00bda88..c563b03bdccc 100644 --- a/arch/mips/kernel/smp.c +++ b/arch/mips/kernel/smp.c @@ -361,6 +361,9 @@ asmlinkage void start_secondary(void) cpu = smp_processor_id(); cpu_data[cpu].udelay_val = loops_per_jiffy; + set_cpu_sibling_map(cpu); + set_cpu_core_map(cpu); + cpumask_set_cpu(cpu, &cpu_coherent_mask); notify_cpu_starting(cpu); @@ -372,9 +375,6 @@ asmlinkage void start_secondary(void) /* The CPU is running and counters synchronised, now mark it online */ set_cpu_online(cpu, true); - set_cpu_sibling_map(cpu); - set_cpu_core_map(cpu); - calculate_cpu_foreign_map(); /* -- 2.34.1