From nobody Sat Feb 7 09:30:23 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 9D2532063C3; Thu, 6 Mar 2025 12:08:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741262933; cv=none; b=isJaN+PphC79JCnb1iVj+WjYeNRLJK81Kv7jBWRgtHmIKW9D64O4fZyNFi8+lZ0wGWu2mZ+/A/WNvhTjool+rWbd1j+Y2C3wRs2nP3h08EnmbFizs8+liGsPExROrKwCoP8Ki8u4aZhhGBlESg1hnGGMLDkJYiZOhl/ekQAo32I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741262933; c=relaxed/simple; bh=b1eskB3+jKzke5mK6dNDmDwkkwAvYzKjmYaFDblRCQg=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=VdH5G0SpL8xhUoYBtWHVrcITCe1Goc590OpbVMG/egXirVdJ54/QO0CS+FvZBc3PjvRDx8YyvUtahctvKpki3BRwMLH04wlpILZDLPoVcfYqRbRLEBLjVFFTDGWIQNr5uZfXNFkttrv/W+nRBHUGcdS/2OXq7TarGT1gVQmW23E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=b3+eTU51; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8RFkdHVK; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="b3+eTU51"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8RFkdHVK" Date: Thu, 06 Mar 2025 12:08:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741262929; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eXSrHbqvc85kekpt3M7gf4ybLOIxtP1viOdbImXDoUA=; b=b3+eTU51nrv/wg46T3pE44H1OB8LhoyMmYnXdEHhsQn6ZBpMd0QL1ulHbLGPSGKkdwdlWg CqtCs8JubCJ7Z4HEnV4ZtS1H8axiuBxyS4PuG+mMXzX504FsTSUi1/kWMJQWKm16wIbqjN nzD4hbeQPt/t+UTGBzSlByHRmpoekqHRIX37ogHeG17FzbttgIrbA+u1Enyz+4JIL/1iic /0hX+zCNSTB+CX2qyKlyG5B6Dnq0b29E4riGlaOApnMDFDknWfHPG7zl9hloTvFmzK6j1A 6eiDYL13OpLrOmYuupAmgScgHIx5p1JbromUt2rlcEfNiEZf9PRCBdWB4baOPA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741262929; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eXSrHbqvc85kekpt3M7gf4ybLOIxtP1viOdbImXDoUA=; b=8RFkdHVKLP5LHTaPr+EcKa9mnWOEFTPAFLg2tV+7LFf6q7RlnWmZvO1GtOZJe9r6Rinx/J RBKih3XvrbsciDCw== From: "tip-bot2 for Maksim Davydov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] x86/split_lock: Fix the delayed detection logic Cc: Maksim Davydov , Ingo Molnar , "Guilherme G. Piccoli" , Thomas Gleixner , Ravi Bangoria , Tom Lendacky , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20250115131704.132609-1-davydov-max@yandex-team.ru> References: <20250115131704.132609-1-davydov-max@yandex-team.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <174126292877.14745.3765755603441311896.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the locking/core branch of tip: Commit-ID: c85391793f4ef47ba5275c57aea7653ead92632f Gitweb: https://git.kernel.org/tip/c85391793f4ef47ba5275c57aea7653ea= d92632f Author: Maksim Davydov AuthorDate: Wed, 15 Jan 2025 16:17:04 +03:00 Committer: Ingo Molnar CommitterDate: Thu, 06 Mar 2025 12:59:51 +01:00 x86/split_lock: Fix the delayed detection logic If the warning mode with disabled mitigation mode is used, then on each CPU where the split lock occurred detection will be disabled in order to make progress and delayed work will be scheduled, which then will enable detection back. Now it turns out that all CPUs use one global delayed work structure. This leads to the fact that if a split lock occurs on several CPUs at the same time (within 2 jiffies), only one CPU will schedule delayed work, but the rest will not. The return value of schedule_delayed_work_on() would have shown this, but it is not checked in the code. A diagram that can help to understand the bug reproduction: - sld_update_msr() enables/disables SLD on both CPUs on the same core - schedule_delayed_work_on() internally checks WORK_STRUCT_PENDING_BIT. If a work has the 'pending' status, then schedule_delayed_work_on() will return an error code and, most importantly, the work will not be placed in the workqueue. Let's say we have a multicore system on which split_lock_mitigate=3D0 and a multithreaded application is running that calls splitlock in multiple threads. Due to the fact that sld_update_msr() affects the entire core (both CPUs), we will consider 2 CPUs from different cores. Let the 2 threads of this application schedule to CPU0 (core 0) and to CPU 2 (core 1), then: | || | | CPU 0 (core 0) || CPU 2 (core 1) | |_________________________________||___________________________________| | || | | 1) SPLIT LOCK occured || | | || | | 2) split_lock_warn() || | | || | | 3) sysctl_sld_mitigate =3D=3D 0 || | | (work =3D &sl_reenable) || | | || | | 4) schedule_delayed_work_on() || | | (reenable will be called || | | after 2 jiffies on CPU 0) || | | || | | 5) disable SLD for core 0 || | | || | | ------------------------- || | | || | | || 6) SPLIT LOCK occured | | || | | || 7) split_lock_warn() | | || | | || 8) sysctl_sld_mitigate =3D=3D 0 | | || (work =3D &sl_reenable, | | || the same address as in 3) ) | | || | | 2 jiffies || 9) schedule_delayed_work_on() | | || fials because the work is in | | || the pending state since 4). | | || The work wasn't placed to the | | || workqueue. reenable won't be | | || called on CPU 2 | | || | | || 10) disable SLD for core 0 | | || | | || From now on SLD will | | || never be reenabled on core 1 | | || | | ------------------------- || | | || | | 11) enable SLD for core 0 by || | | __split_lock_reenable || | | || | If the application threads can be scheduled to all processor cores, then over time there will be only one core left, on which SLD will be enabled and split lock will be able to be detected; and on all other cores SLD will be disabled all the time. Most likely, this bug has not been noticed for so long because sysctl_sld_mitigate default value is 1, and in this case a semaphore is used that does not allow 2 different cores to have SLD disabled at the same time, that is, strictly only one work is placed in the workqueue. In order to fix the warning mode with disabled mitigation mode, delayed work has to be per-CPU. Implement it. Fixes: 727209376f49 ("x86/split_lock: Add sysctl to control the misery mode= ") Signed-off-by: Maksim Davydov Signed-off-by: Ingo Molnar Tested-by: Guilherme G. Piccoli Cc: Thomas Gleixner Cc: Ravi Bangoria Cc: Tom Lendacky Link: https://lore.kernel.org/r/20250115131704.132609-1-davydov-max@yandex-= team.ru --- arch/x86/kernel/cpu/bus_lock.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/bus_lock.c b/arch/x86/kernel/cpu/bus_lock.c index 6cba85c..97222ef 100644 --- a/arch/x86/kernel/cpu/bus_lock.c +++ b/arch/x86/kernel/cpu/bus_lock.c @@ -192,7 +192,13 @@ static void __split_lock_reenable(struct work_struct *= work) { sld_update_msr(true); } -static DECLARE_DELAYED_WORK(sl_reenable, __split_lock_reenable); +/* + * In order for each CPU to schedule its delayed work independently of the + * others, delayed work struct must be per-CPU. This is not required when + * sysctl_sld_mitigate is enabled because of the semaphore that limits + * the number of simultaneously scheduled delayed works to 1. + */ +static DEFINE_PER_CPU(struct delayed_work, sl_reenable); =20 /* * If a CPU goes offline with pending delayed work to re-enable split lock @@ -213,7 +219,7 @@ static int splitlock_cpu_offline(unsigned int cpu) =20 static void split_lock_warn(unsigned long ip) { - struct delayed_work *work; + struct delayed_work *work =3D NULL; int cpu; =20 if (!current->reported_split_lock) @@ -235,11 +241,17 @@ static void split_lock_warn(unsigned long ip) if (down_interruptible(&buslock_sem) =3D=3D -EINTR) return; work =3D &sl_reenable_unlock; - } else { - work =3D &sl_reenable; } =20 cpu =3D get_cpu(); + + if (!work) { + work =3D this_cpu_ptr(&sl_reenable); + /* Deferred initialization of per-CPU struct */ + if (!work->work.func) + INIT_DELAYED_WORK(work, __split_lock_reenable); + } + schedule_delayed_work_on(cpu, work, 2); =20 /* Disable split lock detection on this CPU to make progress */