From nobody Thu Apr 2 02:40:39 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 CEC5936AB5A for ; Tue, 31 Mar 2026 02:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774923299; cv=none; b=fAjjgf5KTYnKYLhJ4xs3ehZkRcxX19/EO42lQPNWAXhkNM8Ai/nc3MprvF74EFDsFOpOOIPaYrf28RFiC/JE2lug08mbQoz7/NeP6fWwwogrlTirfWrC39YgOOcYMmfmuUdJsTUOM9DlMqCxv/tUmgiTb5bZ/WGe0QS4G7XS1i0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774923299; c=relaxed/simple; bh=bWPUTIHzB77pCmbOwvOUZ3WJ7CbJ0BxyXczy1UKJjsg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A95Tcde0Gv9I0Xx6MGE4NNkeOwFfyY8xiSKCwXws66DtcwKzjMIByFB7xEY4rPMsIpjIuVUT4m7RqqsmT4GY5/FHpSxtjd77bnC/FkSnanq6WKdgGsqj45mo46ZrDKJvBjb/ZurKpZdDJ9uISuCFVj1GR6fCxIrBH8+lLqjGQHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=c0e9x30K; arc=none smtp.client-ip=192.198.163.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="c0e9x30K" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1774923298; x=1806459298; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bWPUTIHzB77pCmbOwvOUZ3WJ7CbJ0BxyXczy1UKJjsg=; b=c0e9x30KgExc6kFWX6JDbl2YmhYdL1J80iyuyuTEnsu6oNe73WjVhNCN 8vbt7lvEmrjRyj79ViHSwEpis+R0pFTv33k0EbToAwrZ0gJQL+8k0N6D9 0Q8L+4U1Eg20xEbNN7L/L3MZ5oPGjZswpDGSZBg8fIYa7JU7Kq+K4/fiY 1ioiXFfbzML6f4To0yeW0g/w1bRNGDoKkv1H6S3Jk8uc3ggCf4D+Uugmd 1KFZw6GbDuPhnxTvOHRGyb9IZZYSUPAptDK5G2xDcJ4+mxYNC95R0mgny fuF1RdNHSlzIV++1nbCBaUKPVOvTLGAB5vINS6gvXMvVWUWPVKPNq+GyX Q==; X-CSE-ConnectionGUID: HsQ3GAHgRsChfCUPGyhmIw== X-CSE-MsgGUID: FNVT36acTP6WY6EYsck/Yg== X-IronPort-AV: E=McAfee;i="6800,10657,11744"; a="93508064" X-IronPort-AV: E=Sophos;i="6.23,151,1770624000"; d="scan'208";a="93508064" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2026 19:07:40 -0700 X-CSE-ConnectionGUID: dlu+euLvSz6zEMmgP1EjoA== X-CSE-MsgGUID: 7c/reNQITbCGBNzQ8V5/Ew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,151,1770624000"; d="scan'208";a="221358677" Received: from chang-linux-3.sc.intel.com (HELO chang-linux-3) ([172.25.66.172]) by fmviesa006.fm.intel.com with ESMTP; 30 Mar 2026 19:07:37 -0700 From: "Chang S. Bae" To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, peterz@infradead.org, david.kaplan@amd.com, chang.seok.bae@intel.com Subject: [RFC][PATCH v2 02/11] stop_machine: Accumulate error code rather than overwrite Date: Tue, 31 Mar 2026 01:42:40 +0000 Message-ID: <20260331014251.86353-3-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260331014251.86353-1-chang.seok.bae@intel.com> References: <20260331014251.86353-1-chang.seok.bae@intel.com> 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" cpu_stopper_thread() invokes a stop function and collects its error code in struct cpu_stop_done. In the multi stop-machine case, it is shared data, but currently an arbitrary error is recorded as overwriting. With different errors, accumulating error code instead can distinguish a multi-error condition as bits are cumulatively set. Convert the error recoding to accumulate return values. Suggested-by: Borislav Petkov Signed-off-by: Chang S. Bae Link: https://lore.kernel.org/lkml/20260304163335.GDaahe3wdnqxSC2yfw@fat_cr= ate.local --- V1 -> V2: New patch While tried to explain its benefit here, I considered this change deserves more discussions to ensure its impact, so RFC. --- include/linux/stop_machine.h | 12 ++++++------ kernel/stop_machine.c | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/linux/stop_machine.h b/include/linux/stop_machine.h index c753dd53e79d..2f986555113a 100644 --- a/include/linux/stop_machine.h +++ b/include/linux/stop_machine.h @@ -124,9 +124,9 @@ static inline void print_stop_info(const char *log_lvl,= struct task_struct *task * the possibility of blocking in cpus_read_lock() means that the caller * cannot usefully rely on this serialization. * - * Return: 0 if all invocations of @fn return zero. Otherwise, the - * value returned by an arbitrarily chosen member of the set of calls to - * @fn that returned non-zero. + * Return: 0 if all invocations of @fn return zero. Otherwise, an + * accumulated return value from all invocation of @fn that returned + * non-zero. */ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus); =20 @@ -154,9 +154,9 @@ int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *dat= a, const struct cpumask * * * Context: Must be called from within a cpus_read_lock() protected region. * - * Return: 0 if all invocations of @fn return zero. Otherwise, the - * value returned by an arbitrarily chosen member of the set of calls to - * @fn that returned non-zero. + * Return: 0 if all invocations of @fn return zero. Otherwise, an + * accumulated return value from all invocation of @fn that returned + * non-zero. */ int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data); =20 diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index 822cf56fdc81..15268f1207e9 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -459,7 +459,7 @@ static int __stop_cpus(const struct cpumask *cpumask, * RETURNS: * -ENOENT if @fn(@arg) was not executed at all because all cpus in * @cpumask were offline; otherwise, 0 if all executions of @fn - * returned 0, any non zero return value if any returned non zero. + * returned 0, the accumulated value of all non-zero @fn returns. */ static int stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void= *arg) { @@ -512,7 +512,7 @@ static void cpu_stopper_thread(unsigned int cpu) ret =3D fn(arg); if (done) { if (ret) - done->ret =3D ret; + done->ret |=3D ret; cpu_stop_signal_done(done); } preempt_count_dec(); @@ -674,8 +674,8 @@ EXPORT_SYMBOL_GPL(stop_core_cpuslocked); * Local CPU is inactive. Temporarily stops all active CPUs. * * RETURNS: - * 0 if all executions of @fn returned 0, any non zero return value if any - * returned non zero. + * 0 if all executions of @fn returned 0, otherwise the accumulated value + * of all non-zero @fn returns. */ int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus) @@ -705,5 +705,5 @@ int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, vo= id *data, cpu_relax(); =20 mutex_unlock(&stop_cpus_mutex); - return ret ?: done.ret; + return ret | done.ret; } --=20 2.51.0