From nobody Mon Feb 9 00:10:24 2026 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (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 36B801A00E7 for ; Wed, 8 Jan 2025 04:28:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736310506; cv=none; b=qcrurrw2TMR96G8SZ6/23Poq+lEFewu6jZu5KPx5LBEVjASq0E2C9xyqm+t/LG3YsYZQurfz70SKrSfYSmOPHMKPvM0KCJVzXobFyq/AvTrlVnQ+pqeSte7WEPXHHfO+pczfSONOemUDUoTtPiaGZoD5Nb65V40yNxt7L9lt7pM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736310506; c=relaxed/simple; bh=UdB55/+yG1z13JyFF3TyNGq27A8PT1wg4ixuk61+few=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=UwYcXrw9PMSLyQaSNoeLXUxkn7ryVXumEP1+VuKpuWn7zCwOEKdaWAOpfdYqJOTJYRLaouVSJ6ftMQNk4sSc5I+1POPmfJHQv5D6tfppBaIMR5sLmGix/RSCIoP1eydDYyk3yBoUQY6ppbvxnITCrwo3kaAtkcDtMLxkwlA9AAs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=f8W1r0nP; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="f8W1r0nP" Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id DBC903F86F for ; Wed, 8 Jan 2025 04:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1736310498; bh=oOMdZaSTWV9zPT9P5sv6xqI2xjJDEH7cxom6muL8OQo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=f8W1r0nPWUCF+5pt0D6DhD878PTN3v8HyxyKZgnyFy+Orjsfao84RRVXCVqkZy4x7 v9UQKRHCGm3nh0f8URwF83tjEGguktrkzYIBKcdw8nbE0e/SJDWO5AwlO8u5YJjXrb brglVdCadKgyDzp4TCpViWhdOtuy4v2JlrTPCPVKCzcCEoVsxY3dUfiJOYLUuIafdR Smk/xrxMduYAizWlSN51n3StxWVKdDIK/eCzBGdL+aURabRJP8WA0Sor/SQjAQq7Ig WBKbSz3X/fGvElapm13DE3lxxLgYiGi9fd2CEeEJuO6u4mfOPHXm8NARgnMsEuejVh OS8oPtMqXo5eg== Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-2eebfd6d065so36763346a91.3 for ; Tue, 07 Jan 2025 20:28:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736310497; x=1736915297; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oOMdZaSTWV9zPT9P5sv6xqI2xjJDEH7cxom6muL8OQo=; b=DnVCzkcQbqQquLK17DrK8vnENCAobVo8TkPgGv5pDOv3q9LmEdaAQPWkI+lcrJM5PA 8PDy46IMtBSa5ctDZGyg8H0QrvhJh2JY2GtrBFa21qL6wgomNiZMaRAMC1REWfq+80gK 4mklrgU10opcEZZiRILzh64ryfXGbUNYPBZQbuRPLKy4gihIcItxV2ZN1oh9sUnpomol fW5HPwZqNnPnIDZjZvakdYRU2MrJN69q7K0RSW5/Li8iYTBB2lAsEVjjNjW4NHXfN7IV KDcnOD7/mWTqMNeh5qFTFDgyqumkgYHOjK3r3XYMhsIf+rXAYnvTkYGj4fg3/SP6d6p8 9Vzw== X-Forwarded-Encrypted: i=1; AJvYcCU5UEsuQd4/cA5sjnZVy6EanjGWaC3+xQgQwY0XCFgs/MSM1BrJDMiQ7rxR88IFUvWouPoxrE/MYNUk4yQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yy75Es5y/LnwC/7OMWREAhCEZSHIxsjFitduwwkjPCrPSZHlB07 OPQaWj8uyVI6jn4x3WktBXqny7Iwp4WAIP8WLJ6iCwCiUDIEqHbb+96SdcY8sAVjO5srcxwJTfb xk2E9/SWVBCatM938fQIn3qxwCFLZhN971O0tj/hHz5efeZnpm/6mx2c9AZC2Ri+gug3AtI8vgC PB0fQsgL4ENA== X-Gm-Gg: ASbGncsaVA5OJvq8cqJJFhVtjzfLfYSDPOb/F1g8flxLzZFrWZUJQVtdT4vZf/TG3zS /J8O5miepm6X7mjOUnlKgSv7X/g2ZZcGUhSeyhyCXg5UDcR2yYV/JbFCve+5fwW8z9gZo6zQ9v2 FmeeToLYTUsHIBvX52srlWsI8BXZk8sQTwTrQZPygTA3q4xBYoxMudCBG0/0dtrAtESvyUL/Xrd yhvRSIzxrodfUtdHNC2PrfWI9/Zu3Y6WSY5vv7HNs7ms8/at8hwfffCEQ== X-Received: by 2002:a17:90b:544b:b0:2ee:9902:18b4 with SMTP id 98e67ed59e1d1-2f548f61fe6mr2021275a91.27.1736310497262; Tue, 07 Jan 2025 20:28:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfn4mGZgrES4F8/rPaylgRHZDp42BYBzfgI/1F1zjY5DiaxDOa1atqgeqP6YQaSuv39SbIBw== X-Received: by 2002:a17:90b:544b:b0:2ee:9902:18b4 with SMTP id 98e67ed59e1d1-2f548f61fe6mr2021256a91.27.1736310496912; Tue, 07 Jan 2025 20:28:16 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:4e52:6214:fe82:b2d3]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f54a287254sm395670a91.20.2025.01.07.20.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 20:28:16 -0800 (PST) From: Koichiro Den To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, lorenzo.stoakes@oracle.com, chenhuacai@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] vmstat: disable vmstat_work on vmstat_cpu_down_prep() Date: Wed, 8 Jan 2025 13:28:07 +0900 Message-ID: <20250108042807.3429745-1-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The upstream commit adcfb264c3ed ("vmstat: disable vmstat_work on vmstat_cpu_down_prep()") introduced another warning during the boot phase so was soon reverted on upstream by commit cd6313beaeae ("Revert "vmstat: disable vmstat_work on vmstat_cpu_down_prep()""). This commit resolves it and reattempts the original fix. Even after mm/vmstat:online teardown, shepherd may still queue work for the dying cpu until the cpu is removed from online mask. While it's quite rare, this means that after unbind_workers() unbinds a per-cpu kworker, it potentially runs vmstat_update for the dying CPU on an irrelevant cpu before entering atomic AP states. When CONFIG_DEBUG_PREEMPT=3Dy, it results in the following error with the backtrace. BUG: using smp_processor_id() in preemptible [00000000] code: \ kworker/7:3/1702 caller is refresh_cpu_vm_stats+0x235/0x5f0 CPU: 0 UID: 0 PID: 1702 Comm: kworker/7:3 Tainted: G Tainted: [N]=3DTEST Workqueue: mm_percpu_wq vmstat_update Call Trace: dump_stack_lvl+0x8d/0xb0 check_preemption_disabled+0xce/0xe0 refresh_cpu_vm_stats+0x235/0x5f0 vmstat_update+0x17/0xa0 process_one_work+0x869/0x1aa0 worker_thread+0x5e5/0x1100 kthread+0x29e/0x380 ret_from_fork+0x2d/0x70 ret_from_fork_asm+0x1a/0x30 So, for mm/vmstat:online, disable vmstat_work reliably on teardown and symmetrically enable it on startup. For secondary CPUs during CPU hotplug scenarios, ensure the delayed work is disabled immediately after the initialization. These CPUs are not yet online when start_shepherd_timer() runs on boot CPU. vmstat_cpu_online() will enable the work for them. Suggested-by: Huacai Chen Signed-off-by: Huacai Chen Signed-off-by: Koichiro Den Tested-by: Charalampos Mitrodimas --- v2: https://lore.kernel.org/all/20241221033321.4154409-1-koichiro.den@canon= ical.com/ v1: https://lore.kernel.org/all/20241220134234.3809621-1-koichiro.den@canon= ical.com/ --- mm/vmstat.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mm/vmstat.c b/mm/vmstat.c index 4d016314a56c..16bfe1c694dd 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -2122,10 +2122,20 @@ static void __init start_shepherd_timer(void) { int cpu; =20 - for_each_possible_cpu(cpu) + for_each_possible_cpu(cpu) { INIT_DEFERRABLE_WORK(per_cpu_ptr(&vmstat_work, cpu), vmstat_update); =20 + /* + * For secondary CPUs during CPU hotplug scenarios, + * vmstat_cpu_online() will enable the work. + * mm/vmstat:online enables and disables vmstat_work + * symmetrically during CPU hotplug events. + */ + if (!cpu_online(cpu)) + disable_delayed_work_sync(&per_cpu(vmstat_work, cpu)); + } + schedule_delayed_work(&shepherd, round_jiffies_relative(sysctl_stat_interval)); } @@ -2148,13 +2158,14 @@ static int vmstat_cpu_online(unsigned int cpu) if (!node_state(cpu_to_node(cpu), N_CPU)) { node_set_state(cpu_to_node(cpu), N_CPU); } + enable_delayed_work(&per_cpu(vmstat_work, cpu)); =20 return 0; } =20 static int vmstat_cpu_down_prep(unsigned int cpu) { - cancel_delayed_work_sync(&per_cpu(vmstat_work, cpu)); + disable_delayed_work_sync(&per_cpu(vmstat_work, cpu)); return 0; } =20 --=20 2.43.0