Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp525855lqp; Sat, 13 Apr 2024 07:19:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXr7m7r7Ssz8BqOmgepG1/CrvW9c8URcvmQ2K9cEybbw5YZzyqvUJ1QgK6oQ3OOvNBTMwkUKnYcTHLlrdMC1zQGEKsq29VE3Z4g8To3uA== X-Google-Smtp-Source: AGHT+IFjVXuaJANnpv4R85yAiOYo2f6DqqK/PiECpJUuVcwlXPGzp9YnBJTyYE9w1dBups84+3BG X-Received: by 2002:a05:6214:b2b:b0:69b:6148:5532 with SMTP id w11-20020a0562140b2b00b0069b61485532mr2574191qvj.65.1713017970003; Sat, 13 Apr 2024 07:19:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713017969; cv=pass; d=google.com; s=arc-20160816; b=Fv5vtNcQ79z6wj55/Z1YustcJ2BthZB+qNo9sxxehychgYVipGIcnw1sNTgZEYihD3 szO12YGa/QtbYPZGmN8AMrcKF7MGmXUWK64a7/ulX9I6RtT2SCZdWoqOfG3ycdMgMS7m aPo4moAMxOeUqDyA3TyQgXgB/v/Pef5HrXyHu8vvNhwykgtpwev+tzZos+GkoXGa6Uuh 5K+MPYBGOuB5271W0mKqTJh8KlwG4wa9wSPslh9v1CSRyQ4947ISNvvYqsCsT2Vb3Bmt fz/lm9W7TrpaIkC7F3Z+1bkg71A0cAbLtsLkL3OEzHTMvU540dNDuSVzQ5QCSd0V4Teu OuFQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=z72n2c9rvzB7U1Xb9kq/ArIj/cYrcKMMmIL868r1S0Q=; fh=MqS8IsxJ1pEKMCgXW+hrIn1JBFv2+dNTwJ2FD7sqbDY=; b=OIk2Zjj38xHcguySSURYsTXmY3gsDKTpiLTbYxRHeODjk05aqaH1IUZkPtWZoef4z3 3yXtYbTMUFjAGPuegB5R8W0/WbI+cSFK+vhRFLewLrxdZMzb45JLHZ8cykYEO6cStiJg TclQmBdX1TLip5WNRAdqOxEHUoeSzMY5Cvo+Uii7awavTSzR/eIWHRUsTI9vYcLr767+ wPxjC2+fIcZZvft2Ik1A46qYTzTSXsptZcBKf2qvq200gEU74aceivtULaf5PSxClbVM tTrkn2J025Mi7KONIOn+Qsu/86vv8DuwyCZbOvs11v+61N/15QnrE99H4FkADbALEkN7 vFlQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=N9MOQg7w; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-143750-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143750-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jk6-20020ad45d46000000b0069b503c0f36si5848162qvb.3.2024.04.13.07.19.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Apr 2024 07:19:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143750-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=N9MOQg7w; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-143750-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143750-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B78D91C20981 for ; Sat, 13 Apr 2024 14:19:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3AB18446A2; Sat, 13 Apr 2024 14:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="N9MOQg7w" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE0E6446AF for ; Sat, 13 Apr 2024 14:19:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713017964; cv=none; b=L6qN8ontVjzJkFzB5+bts/J5kZBCNlQD/CSjxYf3owK9ZXTq/Oiz8Sv8gUHT6yEJjRU5FCnitZWRL224ddZ9j+iJE1cBZzctIIirY95NNjD3yH7oaPvII02INPo1dDD8qDT4gkvvgCWBM9WjYydr8MZjHKS2cRCa5dHYQJYNG+o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713017964; c=relaxed/simple; bh=pI4zqrbDe0xOthfGgbfKKxHvZXDTJNV784x8upizaIs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PPdqXo9Z4HNit6hZ5nshLOI79f6n1uuDTgFT8HWyJp/68hLwWrh/Vk5OrR2dwt5EqmFxFovJKu3GMvGxwVQRnP34J0X0BOJvneJPUMIvEXkLnAu/6mU1GyJkOFKFfT+50H7diJkcOU2LktRAwrZN3CmKg6zNhe27whnfq3dcv+o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=N9MOQg7w; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713017961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=z72n2c9rvzB7U1Xb9kq/ArIj/cYrcKMMmIL868r1S0Q=; b=N9MOQg7wvvVjzLBzK/wKyIzkUVZEuaJDYwRGZXia9I8By41LjvIOV3rtahTlHItV2VaV7X tpkWCSTOr0uqCQGGqJaoFjIiAk4i27XX45GcuSWb52TNWckpDoGnB9cbs2ZoyvS4ZKXxrM XiImTyq7BguqV6CoiNTTQ3HiEx3KxIk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-682-rkB8vYFPOx6M8ku4QDbPOA-1; Sat, 13 Apr 2024 10:19:20 -0400 X-MC-Unique: rkB8vYFPOx6M8ku4QDbPOA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7E9041C03143; Sat, 13 Apr 2024 14:19:19 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.225.136]) by smtp.corp.redhat.com (Postfix) with SMTP id B2AFA2026D06; Sat, 13 Apr 2024 14:19:16 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sat, 13 Apr 2024 16:17:53 +0200 (CEST) Date: Sat, 13 Apr 2024 16:17:46 +0200 From: Oleg Nesterov To: Frederic Weisbecker , Nicholas Piggin , Leonardo Bras , Thomas Gleixner , Peter Zijlstra , Ingo Molnar Cc: Tejun Heo , Lai Jiangshan , linux-kernel@vger.kernel.org, Junyao Zhao , Chris von Recklinghausen Subject: [PATCH] sched/isolation: fix boot crash when maxcpus < first-housekeeping-cpu Message-ID: <20240413141746.GA10008@redhat.com> References: <20240130010046.2730139-2-leobras@redhat.com> <20240402105847.GA24832@redhat.com> <20240411143905.GA19288@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240411143905.GA19288@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 housekeeping_setup() checks cpumask_intersects(present, online) to ensure that the kernel will have at least one housekeeping CPU after smp_init(), but this doesn't work if the maxcpus= kernel parameter limits the number of processors available after bootup. For example, the kernel with "maxcpus=2 nohz_full=0-2" parameters crashes at boot time on my virtual machine with 4 CPUs. Change housekeeping_setup() to use cpumask_first_and() and check that the returned cpu number is valid and less than setup_max_cpus. Another corner case is "nohz_full=0" on a machine with a single CPU or with the maxcpus=1 kernel argument. In this case non_housekeeping_mask is empty and IIUC tick_nohz_full_setup() makes no sense. And indeed, the kernel hits the WARN_ON(tick_nohz_full_running) in tick_sched_do_timer(). And how should the kernel interpret the "nohz_full=" parameter? I think it should be silently ignored, but currently cpulist_parse() happily returns the empty cpumask and this leads to the same problem. Change housekeeping_setup() to check cpumask_empty(non_housekeeping_mask) and do nothing in this case. Signed-off-by: Oleg Nesterov --- kernel/sched/isolation.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index 2a262d3ecb3d..5891e715f00d 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -118,6 +118,7 @@ static void __init housekeeping_setup_type(enum hk_type type, static int __init housekeeping_setup(char *str, unsigned long flags) { cpumask_var_t non_housekeeping_mask, housekeeping_staging; + unsigned int first_cpu; int err = 0; if ((flags & HK_FLAG_TICK) && !(housekeeping.flags & HK_FLAG_TICK)) { @@ -138,7 +139,8 @@ static int __init housekeeping_setup(char *str, unsigned long flags) cpumask_andnot(housekeeping_staging, cpu_possible_mask, non_housekeeping_mask); - if (!cpumask_intersects(cpu_present_mask, housekeeping_staging)) { + first_cpu = cpumask_first_and(cpu_present_mask, housekeeping_staging); + if (first_cpu >= nr_cpu_ids || first_cpu >= setup_max_cpus) { __cpumask_set_cpu(smp_processor_id(), housekeeping_staging); __cpumask_clear_cpu(smp_processor_id(), non_housekeeping_mask); if (!housekeeping.flags) { @@ -147,6 +149,9 @@ static int __init housekeeping_setup(char *str, unsigned long flags) } } + if (cpumask_empty(non_housekeeping_mask)) + goto free_housekeeping_staging; + if (!housekeeping.flags) { /* First setup call ("nohz_full=" or "isolcpus=") */ enum hk_type type; -- 2.25.1.362.g51ebf55