From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.14 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796540344; b=MS7ug/1SLPjL/nYpJC56+d1Rrnk3anoL6S4tOIa9Oj5LMXo0ZQ/PTkqGtre/OdQDs5Gp 1s7q+pceDHnL4CR3WCB4ioK5BBFw7FsjJRod/axx231Hk0brZtTr97rqwSxG6JZ7wwCDq X/QJvpn9F3nfkKU2kk5wQFYxj79/pVU6SdGlDrBqzJdg1kuOyODnU7uZy5r2pm9BEfFTm 9NFuZ/TSJQ8I2pNk/MX4k+bhHr7/XG/PybU3+NaYwK9Yf6QW66xbYgdXEuLfwUkIUzyuB 678hCbOHPyyJLEoEGZbIART9UzUF+zspFYwca1Zx46yg/SU4Kio857q9QWLg1v5GFew== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796540344; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=W14GpWiPzZX7a9bGZy1TwsZKnzIT4vFHPib+cI82d8I=; b=LXkpgVy3LqevUU6VIfD2umpvxXrk9SKTwU6Jpu2orU4iugWX9zcMZaXaCL+iKn3RqXNf lEPmTPTI8lf9W2cIDA057Q+dt0shfGU90TUHBvguAVWNVRYUJavwo/iazC/XTKR/OPi/a l2W1mc/xrFjUlcliLZm0eD3wKUfXX7EGamgl6NRkBISzoT5XY7Akl37jpldnZ4ODcdA// bN4T/Ts2XK7ZXiufCEBiAcYpEynLAd6qc9jK7l+5hENnOSHjLqFdNtwXfzJnzlor7aNpd AQgncBbDuBtn48WAJJvIoBcVnnf9WR9ubQRIa6FEG9dpmrNG78uPn9hbuMYSpSIRbkg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=GebtPHT6; arc=none smtp.remote-ip=192.198.163.14 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4834606A31F for ; Sun, 6 Dec 2026 06:59:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E4834606A31F 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, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=GebtPHT6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796540345; x=1828076345; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W14GpWiPzZX7a9bGZy1TwsZKnzIT4vFHPib+cI82d8I=; b=GebtPHT6jylslggdfv5AezBARjfdEzGqjuHt6TlPY0Os02k6zpp6TL0i kDauei1AbKK9zz53sCsF0MLd29KHQUwRRp74hokfooZOq1KGc0LeI/0Po O80ZyMmE84FbBY/mGXfJ0aIBnB3eqQFNEBNtuhz7kb4xPb1kGDkWH3RJZ q/cgPIhIyDGjRZHuLGtWVseF2v5u/1dDh9dhWETjjhsT2jGblNbeFs1Wr zxwb6lP16ZifyvsWjEXV0154NU5GSoyhxWMz2gNdaZel4+X7/mUN5s5w9 UTr5tYv1MqWvpdBhM79tXTvRfwuM9NMERXJ4jnruscl7bm+kgLgrO0kAH A==; X-CSE-ConnectionGUID: pfawec/qQ4ql1A00+o0P4w== X-CSE-MsgGUID: lm1E1sDbQE6994+PnjxTUA== X-IronPort-AV: E=McAfee;i="6800,10657,11987"; a="5449509" X-IronPort-AV: E=Sophos;i="6.29,81,1794902400"; d="scan'208";a="5449509" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2026 22:59:04 -0800 X-CSE-ConnectionGUID: ejQsYwzvQ/+9teCuSrDV+Q== X-CSE-MsgGUID: GgJ9RsN+SiSb3icAZScjUA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,81,1794902400"; d="scan'208";a="14648437" Received: from unknown (HELO localhost.png.intel.com) ([10.107.243.221]) by fmviesa003.fm.intel.com with ESMTP; 05 Dec 2026 22:59:01 -0800 From: Ning Sun To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" Cc: Frederic Weisbecker , x86@kernel.org, tboot-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Ning Sun Subject: [PATCH v3] x86/tboot: Fix AP wait count and timeout reporting Date: Sun, 6 Dec 2026 14:58:56 +0800 Message-ID: <20261206065856.8459-1-ning.sun@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Intel TXT systems using tboot, offlining the last secondary CPU can busy-wait until the AP wait timeout expires. The hotplug core then reports that the x86/tboot:dying callback failed with -EBUSY, although the CPU still goes offline. This was found while reviewing Frederic Weisbecker's patch, "[PATCH 46/47] x86/boot/tboot: Move CPUHP_AP_X86_TBOOT_DYING post stop_machine()". The wait target includes the outgoing CPU, which has not yet entered tboot's wait-for-SIPI (WFS) state. The target also increases on every offline operation but is never reduced when a CPU comes back online. Replace the counter with a cpumask. Clear a CPU's bit in the starting callback and use the mask weight before setting the outgoing CPU's bit as the wait target. Also fix the inverted timeout warning condition and use a single final WFS count check for both the warning and the return value. The exact count comparison and timeout budget are unchanged. APs parked by tboot but never brought online by Linux, and failures before the starting callback, remain accounting limitations. Tested on an Intel TXT system with tboot 1.12.2 running Linux 6.18.64 by performing three complete secondary CPU offline/online cycles. The stall and -EBUSY warning no longer occur. S3 was not tested because the platform supports only s2idle. Signed-off-by: Ning Sun --- Changes in v3: - Replace ap_wfs_count with a cpumask cleared from a new starting callback so the wait target tracks offline/online cycles. - Exclude the outgoing CPU by reading cpumask_weight() before setting its bit. - Base both the timeout warning and -EBUSY return on a single final WFS count check. - Shorten the commit message, describe the user-visible failure, and omit the unverified Fixes tag. arch/x86/kernel/tboot.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c index 46b8f1f16676..cc5265f3055c 100644 --- a/arch/x86/kernel/tboot.c +++ b/arch/x86/kernel/tboot.c @@ -314,7 +314,8 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b) return -ENODEV; } -static atomic_t ap_wfs_count; +/* CPUs expected in tboot WFS after offline, cleared on CPU startup. */ +static struct cpumask tboot_wfs_cpus; static int tboot_wait_for_aps(int num_aps) { @@ -327,19 +328,35 @@ static int tboot_wait_for_aps(int num_aps) timeout--; } - if (timeout) + if (atomic_read((atomic_t *)&tboot->num_in_wfs) != num_aps) { pr_warn("tboot wait for APs timeout\n"); + return -EBUSY; + } + + return 0; +} - return !(atomic_read((atomic_t *)&tboot->num_in_wfs) == num_aps); +static int tboot_starting_cpu(unsigned int cpu) +{ + /* tboot drops this CPU from num_in_wfs when it is woken by SIPI. */ + cpumask_clear_cpu(cpu, &tboot_wfs_cpus); + return 0; } static int tboot_dying_cpu(unsigned int cpu) { - atomic_inc(&ap_wfs_count); - if (num_online_cpus() == 1) { - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count))) - return -EBUSY; - } + /* + * This callback runs on the outgoing CPU, which enters tboot's + * wait-for-SIPI only later from play_dead(). Exclude it from the + * wait target. + */ + int num_aps = cpumask_weight(&tboot_wfs_cpus); + + cpumask_set_cpu(cpu, &tboot_wfs_cpus); + + if (num_online_cpus() == 1) + return tboot_wait_for_aps(num_aps); + return 0; } @@ -417,9 +434,9 @@ static __init int tboot_late_init(void) tboot_create_trampoline(); - atomic_set(&ap_wfs_count, 0); - cpuhp_setup_state(CPUHP_AP_X86_TBOOT_DYING, "x86/tboot:dying", NULL, - tboot_dying_cpu); + cpumask_clear(&tboot_wfs_cpus); + cpuhp_setup_state_nocalls(CPUHP_AP_X86_TBOOT_DYING, "x86/tboot:dying", + tboot_starting_cpu, tboot_dying_cpu); #ifdef CONFIG_DEBUG_FS debugfs_create_file("tboot_log", S_IRUSR, arch_debugfs_dir, NULL, &tboot_log_fops); base-commit: 28a23309c8e40d651faf4cc3cc9b71458a11b987 -- 2.53.0