From patchwork Tue Oct 17 09:09:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yang X-Patchwork-Id: 153979 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3995965vqb; Tue, 17 Oct 2023 02:11:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEaIyelL8+rdugaI5S7WbyrLCz9cEQgdNtF5hxFPiHs3nNPfFtYulZagMhTXSquRkOojT48 X-Received: by 2002:a05:6a20:8f28:b0:172:55c1:f1d4 with SMTP id b40-20020a056a208f2800b0017255c1f1d4mr1732683pzk.4.1697533879806; Tue, 17 Oct 2023 02:11:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697533879; cv=none; d=google.com; s=arc-20160816; b=KesMWJt97zIa2e/NqbNtO4GDuX42+Nv4wEeFL27Sc+pmIzXNKd0UnNHQqRVOdAI2/W 65yHwcT8mKth+ddDcLYSHRtwgpIHkZ7MuUNATM9buAQEkec6XfU+dC86kk/LPCkK91Qk 9xoC9WAj5+sh4QZJVgEAgJUMEAQfgMWElyxoE0J1XCTtgoiBZgNzHx5n2+KreSswyc9B rX8M03GI4SyuWxRbC/m5UcYvMK1fIMLCGJ5Qn1q8VJeIIhP3FSHrk0rPBmbA6pA/o31K 4SKNpUlj90NuMcB1CjtZJjVYph+t+Ql8Z9sWj01fWro9rJnrSMN6AAHRPfEeigkK9MjN ha7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:references :in-reply-to:message-id:date; bh=6s+r13Cxa2waTzSTsgrNAFudsIpmyGX6Sa+ueoxxaPA=; fh=Jn1DuuoEec6+xtTixzbmzybYWa+yE7MeyK6vtBO+Rwg=; b=D66M8HC0WFky6JQxHNuwnfZkFYQ4l52XPuvrk0b0P1cfF1lFnbenGndIY4aOi/pmpz 8BDm7CINTTqJOGz9jYzq4EFAuyFP6iWe853eVrged6aV8bPEA75ZcrfqyYMbVqhrale2 R9rPRl3q0eU8fdJSElTbWfh4Ge34xAXspNRYl57QW5lDcC15wU+7KPjzsEqhjxodZzIt W5RMouxeqaGo/QB309yNmYiiKp99Nhnnhe/TLFOAINdb7/9HxkcsqRiw6C4fTFOgOzxz 5GIVq4qpFm4jAu5oDRFwsIT5oYHnYl7OKIfXXBPX2LjPP1p9QIVxifeZWpeeSDewGaO6 XiUA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id mq16-20020a17090b381000b0027cf284c86asi8742633pjb.56.2023.10.17.02.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 02:11:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 88BF5807C643; Tue, 17 Oct 2023 02:11:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234840AbjJQJKg (ORCPT + 19 others); Tue, 17 Oct 2023 05:10:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234843AbjJQJKV (ORCPT ); Tue, 17 Oct 2023 05:10:21 -0400 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79A7DF5 for ; Tue, 17 Oct 2023 02:10:03 -0700 (PDT) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4S8p8m5kccz8Xrdy; Tue, 17 Oct 2023 17:10:00 +0800 (CST) Received: from szxlzmapp01.zte.com.cn ([10.5.231.85]) by mse-fl2.zte.com.cn with SMTP id 39H99oNn026671; Tue, 17 Oct 2023 17:09:50 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Tue, 17 Oct 2023 17:09:53 +0800 (CST) Date: Tue, 17 Oct 2023 17:09:53 +0800 (CST) X-Zmail-TransId: 2b03652e4f616c5-5a37d X-Mailer: Zmail v1.0 Message-ID: <202310171709530660462@zte.com.cn> In-Reply-To: <87lec9l3mi.ffs@tglx> References: 202309161037416349176@zte.com.cn,87lec9l3mi.ffs@tglx Mime-Version: 1.0 From: To: Cc: , , Subject: =?utf-8?q?=5BPATCH_V2=5D_cpu/hotplug=3A_dont_offline_the_last_non-i?= =?utf-8?q?solated_CPU?= X-MAIL: mse-fl2.zte.com.cn 39H99oNn026671 X-Fangmail-Gw-Spam-Type: 0 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 652E4F68.001/4S8p8m5kccz8Xrdy X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 17 Oct 2023 02:11:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777160300476032401 X-GMAIL-MSGID: 1779993285218876635 From: Ran Xiaokai If system has some isolate cpus with "isolcpus=" parameter, and user try to offline all the non-isolated CPUs, kernel will first report a warning and then panic when taking the last non-isolated CPU offline. When offline the last non-isolate cpu, cpuset_hotplug_workfn() rebuild_sched_domains_locked() ndoms = generate_sched_domains(&doms, &attr); cpumask_and(doms[0], top_cpuset.effective_cpus, housekeeping_cpumask(HK_FLAG_DOMAIN)); As isolated cpus are excluded, "doms" passes to partition_sched_domains_locked() will be an empty cpumask. WARNING: CPU: 4 PID: 80 at kernel/sched/topology.c:2366 build_sched_domains+0x120c/0x1408 Call trace: build_sched_domains+0x120c/0x1408 partition_sched_domains_locked+0x234/0x880 rebuild_sched_domains_locked+0x37c/0x798 rebuild_sched_domains+0x30/0x58 cpuset_hotplug_workfn+0x2a8/0x930 process_scheduled_works+0x178/0x3e0 worker_thread+0x174/0x2f0 ---[ end trace 0000000000000000 ]--- Unable to handle kernel paging request at virtual address fffe80027ab37080 partition_sched_domains_locked+0x318/0x880 rebuild_sched_domains_locked+0x37c/0x798 rebuild_sched_domains+0x30/0x58 cpuset_hotplug_workfn+0x2a8/0x930 process_scheduled_works+0x178/0x3e0 worker_thread+0x174/0x2f0 kthread+0x10c/0x128 ret_from_fork+0x10/0x20 Code: 1a850042 b9441883 f862dae0 8b000021 (f945003b) Kernel should not panic when user managing CPUs with this meaningless behavior, so we add a check for this, which prevent user taking the last non-isolated CPU offline. Signed-off-by: Ran Xiaokai Suggested-by: Thomas Gleixner Cc: Yang Yang Cc: Xuexin Jiang --- kernel/cpu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index 6de7c6bb74ee..94430ea8b4a5 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1515,11 +1515,14 @@ static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target) /* * Ensure that the control task does not run on the to be offlined * CPU to prevent a deadlock against cfs_b->period_timer. + * Also keep at least one housekeeping cpu onlined to avoid generating + * an empty sched_domain span. */ - cpu = cpumask_any_but(cpu_online_mask, cpu); - if (cpu >= nr_cpu_ids) - return -EBUSY; - return work_on_cpu(cpu, __cpu_down_maps_locked, &work); + for_each_cpu_and(cpu, cpu_online_mask, housekeeping_cpumask(HK_TYPE_DOMAIN)) { + if (cpu != work.cpu) + return work_on_cpu(cpu, __cpu_down_maps_locked, &work); + } + return -EBUSY; } static int cpu_down(unsigned int cpu, enum cpuhp_state target)