Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1984464lqz; Tue, 2 Apr 2024 04:02:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWaSOvheqNNh39y9L29ZXr2cWZntO68jT19YZ0xKwZMyWqNCWkyHGIP40I9Dgl+rtWLy9LCh9thJjaHKelDGAp6NaiEOqj7D+Azj7p7HA== X-Google-Smtp-Source: AGHT+IGYI+s3OWbKUe0WfsQpTu6I0qt2sLZE1ABsd423DkbmFjHpGQphenxfT7Wv89Xrbl4IDGdz X-Received: by 2002:a05:620a:1186:b0:78a:282a:c200 with SMTP id b6-20020a05620a118600b0078a282ac200mr14655277qkk.13.1712055769216; Tue, 02 Apr 2024 04:02:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712055769; cv=pass; d=google.com; s=arc-20160816; b=hL4YMCZc0ilD5Naa7h0JBJn2eh3dEU+lEDHfPpH8wjGXqOnQI/y+joU1T8TrBxZkWE As5Uom0bxjBxHYo+ytmh1LE9DJsPTtHqgR2Y733hCJOPXB2CLv4PnXeB2AUsTBJQbYD7 iZ71a8BqdzXswCGiaBw7RUIyErVSKYKuqRxpXKMiT1QkbdM36WYNVxsKee07Vq5CDBQ4 /XCbLjfqNbqWxtzpAOfoqzSR3m8S/It439MaOFfo75iNsLQunh3bN2hVkO3vDNOk4TdV A2ErAfOjC3f7ss/6FtPkRcbcXRkflV/RJBAKQcqWaQ2hcsYzNH9UiwNY00U3zQh9V/4w 10Aw== 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=IUu3nr9E3SwUyf0LhqLc3kAfs3lSg4TLssyKsTdFRrI=; fh=6bgVueXAFu8KqBUSLZ5qYm4afrWhtN0IuydR8fQzX6M=; b=jC/gL5s77q6Edclf8FCVIniYy0K9PgxvKfwouvcUJ3a6MYFYrwZGuUX57WoruUPUAE EUj4x2ZgqGO1iSkvCJzYmD8MrUfLiBFbyL0/Loy0NHcQZvzM8Kl5fTt62cP2aGwjSEny eYT0//IWaoAwpkia4T8z/gQHr/pINsoDHRunlXOjjcRm5UeU5CQ5jl7+Jb+XxvXRVY5I F5EmNvYtbiwccX1Z4+MlpmPAheYeP0hcwkNy3oGSWc2g3Kg/cCWJ5m3lswSuw+pnkIk5 XfC2zDIP3XcjOUaW5D1jaPQxzqWVOPrDRfK+sn4cVZFcYisGzRVQi79g8u6+W44DsDD3 yMfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ehSXeixg; 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-127811-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127811-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. [147.75.199.223]) by mx.google.com with ESMTPS id x3-20020ae9e903000000b0078a0f4c202csi11097688qkf.581.2024.04.02.04.02.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 04:02:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127811-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ehSXeixg; 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-127811-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127811-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 8B2F91C23792 for ; Tue, 2 Apr 2024 11:02:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 10EE179B77; Tue, 2 Apr 2024 11:00:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ehSXeixg" 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 0D78760269 for ; Tue, 2 Apr 2024 11:00: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=1712055625; cv=none; b=WnHKam52MBFellqYgg2QmbkmGV3brI/NFc47007HHWnXTQcIcRXHmaV2FubkLrOQBT4OGxYjNsNwnj18eG8amTreratScSO66rItv30T2kabJrhQD1w13W5xzRG1aRhKVVoj7AhHDnLH0S1/3mbCkfpcX9/FBzE8O10HgHU87CM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712055625; c=relaxed/simple; bh=9l/uJlhZz71INlCmZi6FyRzwD9Rw0VhpOTNQ49UU2H8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=h9PFd1JvUk+5qMmBRDxqjEAnQe/e2Wqyr7l5YBAOdqkZiT7ASkPOWqPscIGflzEHwAAPsl9JS3RWkeK5VHS5DiClnyr+IU4FZrRtPFXwL+7JC7phgoeirAzsXsbMnuEFunvX6lg9FuQbfDFUs6BuYtRuFRmwVclHxEZUtOcG+MY= 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=ehSXeixg; 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=1712055621; 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=IUu3nr9E3SwUyf0LhqLc3kAfs3lSg4TLssyKsTdFRrI=; b=ehSXeixg+KyVttXD4vPPpo3iFUVt4qDVxPgfLKYWuicPoK13EzFBxnOv6Ithfy/hfzzI7E WAyNm105nWqmt/JQl/NNdUjb7RuV16eYjxWiWhFDDjwKJ0e96mLDDWFPJatC8Sm+E60mCC v2Ah6Y8udMFeM6tC/3NK8CvAKa4FYRg= 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-584-pmYRuB_lMcalWZwNXFOHkg-1; Tue, 02 Apr 2024 07:00:18 -0400 X-MC-Unique: pmYRuB_lMcalWZwNXFOHkg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 64D6338143A3; Tue, 2 Apr 2024 11:00:18 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.69]) by smtp.corp.redhat.com (Postfix) with SMTP id 2A25E1C060A4; Tue, 2 Apr 2024 11:00:15 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 2 Apr 2024 12:58:54 +0200 (CEST) Date: Tue, 2 Apr 2024 12:58:47 +0200 From: Oleg Nesterov To: Leonardo Bras , Thomas Gleixner , Peter Zijlstra , Ingo Molnar Cc: Tejun Heo , Lai Jiangshan , linux-kernel@vger.kernel.org, Junyao Zhao , Chris von Recklinghausen Subject: Re: [PATCH v2 1/1] wq: Avoid using isolated cpus' timers on queue_delayed_work Message-ID: <20240402105847.GA24832@redhat.com> References: <20240130010046.2730139-2-leobras@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: <20240130010046.2730139-2-leobras@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 Hello, This patch was applied as aae17ebb53cd3da but as Chris reports with this commit the kernel can crash at boot time because __queue_delayed_work() doesn't check that housekeeping_any_cpu() returns a valid cpu < nr_cpu_ids. Just boot the kernel with nohz_full=mask which includes the boot cpu, say nohz_full=0-6 on a machine with 8 CPUs. __queue_delayed_work() will use add_timer_on(timer, NR_CPUS /* returned by housekeeping_any_cpu */) until start_secondary() brings CPU 7 up. The problem is simple, but I do not know what should we do, I know nothing about CPU isolation. We can fix __queue_delayed_work(), this is simple, but other callers of housekeeping_any_cpu() seem to assume it must always return a valid CPU too. So perhaps we should change housekeeping_any_cpu() - return cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask); + cpu = cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask); + if (cpu < nr_cpu_ids) + return cpu; ? But I'm afraid this can hide other problems. May be - return cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask); + cpu = cpumask_any_and(housekeeping.cpumasks[type], cpu_online_mask); + if (cpu < nr_cpu_ids) + return cpu; + + WARN_ON(system_state > SYSTEM_BOOTING); ? ------------------------------------------------------------------------------- OTOH, Documentation/timers/no_hz.rst says Therefore, the boot CPU is prohibited from entering adaptive-ticks mode. Specifying a "nohz_full=" mask that includes the boot CPU will result in a boot-time error message, and the boot CPU will be removed from the mask. and this doesn't match the reality. So it seems that we should fix housekeeping_setup() ? see the patch below. In any case the usage of cpu_present_mask doesn't look right to me. Oleg. --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -129,7 +154,7 @@ 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)) { + if (!cpumask_test_cpu(smp_processor_id(), housekeeping_staging)) { __cpumask_set_cpu(smp_processor_id(), housekeeping_staging); __cpumask_clear_cpu(smp_processor_id(), non_housekeeping_mask); if (!housekeeping.flags) { On 01/29, Leonardo Bras wrote: > > When __queue_delayed_work() is called, it chooses a cpu for handling the > timer interrupt. As of today, it will pick either the cpu passed as > parameter or the last cpu used for this. > > This is not good if a system does use CPU isolation, because it can take > away some valuable cpu time to: > 1 - deal with the timer interrupt, > 2 - schedule-out the desired task, > 3 - queue work on a random workqueue, and > 4 - schedule the desired task back to the cpu. > > So to fix this, during __queue_delayed_work(), if cpu isolation is in > place, pick a random non-isolated cpu to handle the timer interrupt. > > As an optimization, if the current cpu is not isolated, use it instead > of looking for another candidate. > > Signed-off-by: Leonardo Bras > --- > Changes since v1: > - Make sure the CPU is isolated for any value of "cpu" > > Changes since RFC: > - Do not use the same cpu from the timer for queueing the work. > - If the current cpu is not isolated, use it's timer instead of > looking for another candidate. > > kernel/workqueue.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/kernel/workqueue.c b/kernel/workqueue.c > index 76e60faed8923..8dd7c01b326a4 100644 > --- a/kernel/workqueue.c > +++ b/kernel/workqueue.c > @@ -1958,10 +1958,18 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq, > dwork->cpu = cpu; > timer->expires = jiffies + delay; > > - if (unlikely(cpu != WORK_CPU_UNBOUND)) > + if (housekeeping_enabled(HK_TYPE_TIMER)) { > + /* If the current cpu is a housekeeping cpu, use it. */ > + cpu = smp_processor_id(); > + if (!housekeeping_test_cpu(cpu, HK_TYPE_TIMER)) > + cpu = housekeeping_any_cpu(HK_TYPE_TIMER); > add_timer_on(timer, cpu); > - else > - add_timer(timer); > + } else { > + if (likely(cpu == WORK_CPU_UNBOUND)) > + add_timer(timer); > + else > + add_timer_on(timer, cpu); > + } > } > > /** > -- > 2.43.0 >