From patchwork Wed Jan 8 04:28:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 13930114 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4D4BE77188 for ; Wed, 8 Jan 2025 04:28:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 195F76B0088; Tue, 7 Jan 2025 23:28:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 146116B0089; Tue, 7 Jan 2025 23:28:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F28606B008A; Tue, 7 Jan 2025 23:28:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D40876B0088 for ; Tue, 7 Jan 2025 23:28:24 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 631D4140E1F for ; Wed, 8 Jan 2025 04:28:24 +0000 (UTC) X-FDA: 82983002928.12.5DBEBBC Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by imf29.hostedemail.com (Postfix) with ESMTP id 40A4C12000A for ; Wed, 8 Jan 2025 04:28:22 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=canonical.com header.s=20210705 header.b=iy4wlLVr; spf=pass (imf29.hostedemail.com: domain of koichiro.den@canonical.com designates 185.125.188.123 as permitted sender) smtp.mailfrom=koichiro.den@canonical.com; dmarc=pass (policy=none) header.from=canonical.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736310502; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=oOMdZaSTWV9zPT9P5sv6xqI2xjJDEH7cxom6muL8OQo=; b=vMmCGhwYiG2v/x5yQhT3HiD3H6NASe++JERclaV2XrM16dEuz9GMyjYBrFvGUOEhyOfDE8 yWjJ6+L+gOxcLnataw4hNG1DUzMjwVphmArggFohfjDkorvIOai7vN8jk5KZN10MX+MFS0 +jhi+6C7EfVf5rrY0q/JBTcSE8daJes= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=canonical.com header.s=20210705 header.b=iy4wlLVr; spf=pass (imf29.hostedemail.com: domain of koichiro.den@canonical.com designates 185.125.188.123 as permitted sender) smtp.mailfrom=koichiro.den@canonical.com; dmarc=pass (policy=none) header.from=canonical.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736310502; a=rsa-sha256; cv=none; b=03Jjdt85gHbOb8lSWN+hjOHKjlbp4T91/vBZ1ZktE+x1e03KfsDSNIQG12NBP3spGwshOp Di2caQ8A5MVcUn2DmFHktqbkjON2Ps/wXDdrIFI3xSxqGgCqeyIza7S7H+XELYzq1n/OKo 3J3fGtsTGEreSY9qOahNda1I8ucgFlI= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (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-1.canonical.com (Postfix) with ESMTPS id 206E03F2BD for ; Wed, 8 Jan 2025 04:28:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1736310500; bh=oOMdZaSTWV9zPT9P5sv6xqI2xjJDEH7cxom6muL8OQo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=iy4wlLVrYL23UaPoBUrJ2xfK9M4wvntQJl+g+ad7s7TfL3WO2O4IG7tESllC8RgGX Pltz8P3tDJogmk9LWNIW2pCxYGLJnq8UF8m9mpTr+XlB8T6O/uKjqr5RzneDVorNZm C9V0fYfwVWlhcLKfLF4CulD/mwNcnBhrqSFyu2+mI9uTmTsJfCZ4E+9Pq1vdtdu/U5 Uw6D3g1yvKtDG8FQoHAi0EbMuSJQjx1KuHw13vRDyUZQNTzFnezTeZ/Yz1UAkTLiSe oS3FV/hq/owDxvpbeIHrgp+GPW5zAVWs5vKHID/CVV4TTrRpmRhh2NglHkNQLhoDwc ej4/pf5P9kpCw== Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-2ef9da03117so36772494a91.1 for ; Tue, 07 Jan 2025 20:28:20 -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=OctT7/FqWs9340ayhY4abYTwKQhE43O98c3gc5JLmAHOYI4kG1eh30ZFibRZoGXvmb xuZhZt2HesigRQgpVCFtTs5bjlZrfTv9zn7GE2mTRpGJtZVp7+N9El1ZDVovKxI1tFME q8WbGZmJUjNgBZzTfeAJavdQbEmS9E8+Ev89PTaEbBsxE9xg39jO+xcB7zun//zqn5Q9 ZBVzRoiywabQIfhrTX+tsPoK6sJx0CSDQ+RXo3mDg9cvT0H75Wp2YHzzevLJ6fBNULGH 7sNYwLuJgWHhiYYwAskP/wxjeGCtzD6x+F2lJyZcQC6vMu+Fq01AQhKvMv3Fod6NoE10 nopA== X-Gm-Message-State: AOJu0YxYnHxUQRDHmhMUZkBqhuzIvS9AU1AzHTXB+GYRPIxX/ry9saQr fItGR/prwMfv3Cr/7qMnTGMTLQauoT3dWw6bs1ZgEfYCzjZ0nmp7XvnKTRpazV64iEqvXJC8N/a q3QnxCKpJHdkCLk8CfNYLPcRIrvTyCAzjnso2uTPlL7FWghE4uLlyR9Iz9IGr/hb7n0oI1QGr X-Gm-Gg: ASbGncuzccB0L4ihGJkG8dCQ6MaWAcMeMcLCpEuuS17zEESmGPArEfiTZYhNWmdpJVA yYiVPE0x76NQk2TgE6kVK9WbWFGLRbMF4cMzqOkRRY1gEpPCqaT7EsdBS2Pf2MXpfH8sNCWa4Yu 8G3NCDfsBdYmUwBNVijFoXY2w7wkX4ksB+8wAk85cRQE+MdBlRWKP+zEns80lUIbj4+9l6A7lCq fYvz1SIzq2AbKVEZwcxlXBkL6Kz2HsQUIUCPkLa53gmxVnAOA31VYHnjw== X-Received: by 2002:a17:90b:544b:b0:2ee:9902:18b4 with SMTP id 98e67ed59e1d1-2f548f61fe6mr2021283a91.27.1736310497345; 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 MIME-Version: 1.0 X-Rspamd-Queue-Id: 40A4C12000A X-Rspamd-Server: rspam12 X-Stat-Signature: stu596es9rbjqk1hhbe73y5be6ybmqyw X-Rspam-User: X-HE-Tag: 1736310502-823050 X-HE-Meta: U2FsdGVkX19doWrJ2pVSUeHd5VUjyBb8vTy4kSt3mU2kIQSIocfq/HnVSH1u8EkRHVeGRGLseEOXC2Hq/l+mHw6ss9ELM2lJ9K78WcRveugvt6+Ochp4UZZ9stvCVCcfSJTHhCXqNKOKJd94c6E1Ig9FVtlgUiKAV8f0hE5VcuvszoyRao+LFCMm8eobb/HfB5kMDxeJaMQPbAp3oIL3pPCaP2dBPcksVxVvKwB6EZyyBr+QxSCds1mE5SCIzy0mcYewGbYywQCaCyDQPxrOp+mq35cOAl/FLLhY4R/UXuLWe/douad2xIIM/cNBOBWehP3sxhAmcHjGBOXE/QW+x0inpZggRG4jxk1AE3fdQ+qxLMA1a+L7921Cnzzysv1ztFu2Gin8EPMFH0OZVvVfYo10T7SLnn5VTfKbpfSoOO3zPnP3PD0uB0aW+h8tw9LO0Jpou6pqheLtBJr08RJzgnqjpDHPvek0y2pc1Qxspykgc7ps1D/3RCBbcxckbQqPD2isrjl4QyRl1NvJHkrj3BKHZ4JYqgCUw68LzbUkiBF3aOryhfyyCJoMQsw9elpGBXq3pYitL8nzpbZabnpis66ZqKBmf0VksFIQ3ApaWXd3zNYFuCkk64asm/Le2tXEEBAtPOKbWEJhHOPceAKdaQIJgD5ZKIMYdq7Flhb339AIq9TNQSnu7sTUFxH/Hq5GSG0cIhZQOKARIa4zimqaQHapJuZvbk9df8naxUsX67lCzMMmmiM8AGWtiw62SgTU7L3LqsiF73izeoYWd99yQZBPuFIgEhd54HMpONujao7lb71pU/CRv/ZHBPsA7hRbuMEpehwz318d2uP1MzbfJWf5M82bTu0NiXrbBU9ko/W9xsXs035IsXn1v4fhH2TYaDww9xKgYXILex5Bxy9NV6lP9l1q/0vZ/duT7+UrXdXZu5wTCLK3t0IlnUaBkGrc6PtuRPXWpUJF1XR4VBg v8LMgwKk v8sYIpvZmTiYwALR09Oq8RW6jH1hue+M/L1tl3JbNm1XBJAKKKvlROdrGMHJ4NG/MGTgZenrrAdFL0tDr4G3Z8/t5U52VB5KHJ8sKypxkVUWC7TQXVRckSwb9ZIPek5aiw4aKEb/8wJ+CtYjerY1nU0CodF1eWMfMZ790XbCEOyFlnZdgKaMyai7nIiz5VsXI+1S6CXfIkAMMSLqiElmjy9kiubh7lVnIov4/ladKVx2RRmbv1BLYQ8ZspS0X4DGfCrx47f2QZ+9+hec/Q4TXTc4jbzk7XQkpN+eUXcvBs4eRKkDbroR/dNpxfeMAf+DKVH+Eymc1uWnIRaS+cM80Gyu1jfKSNLw4QT+T0WAkq8GSkSnfTixOZbZhW0nn4tNWq2Fg66oMkq6BvFa3WUzMeVXtvtuqUEpEIVTezrdM5UEBFQBU5lnZ8s14VDYU9Ie+zEN0UrKCFqgiEAk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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=y, 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]=TEST 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 --- v2: https://lore.kernel.org/all/20241221033321.4154409-1-koichiro.den@canonical.com/ v1: https://lore.kernel.org/all/20241220134234.3809621-1-koichiro.den@canonical.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; - for_each_possible_cpu(cpu) + for_each_possible_cpu(cpu) { INIT_DEFERRABLE_WORK(per_cpu_ptr(&vmstat_work, cpu), vmstat_update); + /* + * 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)); return 0; } 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; }