Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3026714rdg; Tue, 17 Oct 2023 02:11:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbOSM1zuNehab0eAQWPxjzlUZnk6aozuwuh7lX/9DwcUQnhjvGMylESmkqzVlu0zICGe+r X-Received: by 2002:a05:6358:7a7:b0:13a:a85b:a4ce with SMTP id n39-20020a05635807a700b0013aa85ba4cemr2187165rwj.16.1697533874079; Tue, 17 Oct 2023 02:11:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697533874; cv=none; d=google.com; s=arc-20160816; b=JmZ+FZqRxHF80xJ+MU7eQbVE3OGJ7LIHTFTjGzCmAPvvc8seRpM/Y9pdugnFESADX3 Rk0AFcPTw+6cqJpBn0fHjPYixB1tLrHgpKIr32Gl8bwq1wqLnWkZRwblRMkn2B99Wyar ERCOcpP7Q6xdV3n1Dnne0Kq1nUfqGPCvfvYlpq9AK4f3Z/SEPeUrc9+Z7PH1k+90PIx5 I31UFYGx4EIAzk3ea3drEQ15kxX6CvfRhaSJjiqmLTDePV79DZKKUOUhPr5C4iGeO9cR aFTnaTsq5sxsO6YNRpuyhteMjDa3YWPKb7/GCN/pAEgAJZxjXcnp+WHHXY2a4bSfR2BL DdRQ== 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 Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id t12-20020a056a0021cc00b0068fb95e5401si1229153pfj.65.2023.10.17.02.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 02:11:14 -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 B8E2C80A90D7; Tue, 17 Oct 2023 02:11:03 -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 S234839AbjJQJKf (ORCPT + 99 others); Tue, 17 Oct 2023 05:10:35 -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?B?W1BBVENIIFYyXSBjcHUvaG90cGx1ZzogZG9udCBvZmZsaW5lIHRoZSBsYXN0IG5vbi1pc29sYXRlZCBDUFU=?= Content-Type: text/plain; charset="UTF-8" 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:03 -0700 (PDT) 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) -- 2.15.2