From nobody Fri Feb 13 05:47:35 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 C059B51C34; Fri, 12 Apr 2024 09:21:15 +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=1712913677; cv=none; b=siA9Og4qzbXm2TceH2VoEbsQi5al81/BvTrff4VwE2vH9leHTDC2cdhbu58ARm0TnL5sipkZrT5rQaRmzVniXiZzqaERT6isP82ACUyWA/NszEwU0OtuPcWBpTNNTYMg3dQYNhIBcmirNKDMRGgIU5MokQr4XlZTipohQNJ+TtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712913677; c=relaxed/simple; bh=3vqlV7nuJVIxwLtggOR4FA9iApy/iGXT3+WyhuVqGEg=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=YpCGVnCEPNn9tEEAAh6PeAsO4dlrB9EpkAYwNoWnMLsGzebzf35RY/M8iNUfyiebeK8P0kmVxR62tgMAYHnkI0GpkPqntaiwTw60vbrRQuhUXubWIm/gd+1HiY7U+UiUmOUO4Nk5O9qVNqzNdTYhYPC6dINlNUQjhXfZMIorbP0= 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=h/kYj3Cl; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=kGN2Be4y; 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="h/kYj3Cl"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kGN2Be4y" Date: Fri, 12 Apr 2024 09:21:07 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712913668; 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=lgmYgwwZi90eXTj5n/Q0qCknlWcNGDmvUBJwpSGubBQ=; b=h/kYj3ClLR5jFiDnChq4SNf4pNsDSeM8VV8prauwT6e0zvEy6C5mBSd/xfXPvmjFURiv4d MROtUhgGET0doDGIg59agxmEY3WRxDEPJBOQsf3C46+BFmKV+UkEbKrUtvrS9NIXPgTODk nielhAMwSxx5fne9QxLO8bE93//ruydLCK1s3IXeVf7qJXEaC5YXrTwRN7oE4a+dAhjLC8 NjXIw5Idh58uvG8a9xmY/ISRMDylUn1NfusDXy0X9g6mpDIvTE4iLVX5iZCBvgiteh107q aQXF8uWF8r1BpKCNd3M2GH4gHra6blxnFOqmb2Mb51FTLlD23LL1ArudI8RKhA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712913668; 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=lgmYgwwZi90eXTj5n/Q0qCknlWcNGDmvUBJwpSGubBQ=; b=kGN2Be4y1KdK6fYDatpqFgVyKrN7giJzQ9cX2N5vk6om1fSDudetRNSTc+KwHOTZ+TsEOa Cn6gY/e8UBH9FODQ== From: "tip-bot2 for Uros Bizjak" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/pvqspinlock: Use try_cmpxchg() in qspinlock_paravirt.h Cc: Uros Bizjak , Ingo Molnar , Waiman Long , Linus Torvalds , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240411192317.25432-2-ubizjak@gmail.com> References: <20240411192317.25432-2-ubizjak@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171291366703.10875.3042491829353534171.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: e361be1ff2621493f5c638719d706e9789f7ab4c Gitweb: https://git.kernel.org/tip/e361be1ff2621493f5c638719d706e978= 9f7ab4c Author: Uros Bizjak AuthorDate: Thu, 11 Apr 2024 21:22:55 +02:00 Committer: Ingo Molnar CommitterDate: Fri, 12 Apr 2024 10:56:45 +02:00 locking/pvqspinlock: Use try_cmpxchg() in qspinlock_paravirt.h Use try_cmpxchg(*ptr, &old, new) instead of cmpxchg(*ptr, old, new) =3D=3D old in qspinlock_paravirt.h x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg. No functional change intended. Signed-off-by: Uros Bizjak Signed-off-by: Ingo Molnar Reviewed-by: Waiman Long Cc: Linus Torvalds Link: https://lore.kernel.org/r/20240411192317.25432-2-ubizjak@gmail.com --- kernel/locking/qspinlock_paravirt.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock= _paravirt.h index 77ba80b..f5a36e6 100644 --- a/kernel/locking/qspinlock_paravirt.h +++ b/kernel/locking/qspinlock_paravirt.h @@ -86,9 +86,10 @@ static inline bool pv_hybrid_queued_unfair_trylock(struc= t qspinlock *lock) */ for (;;) { int val =3D atomic_read(&lock->val); + u8 old =3D 0; =20 if (!(val & _Q_LOCKED_PENDING_MASK) && - (cmpxchg_acquire(&lock->locked, 0, _Q_LOCKED_VAL) =3D=3D 0)) { + try_cmpxchg_acquire(&lock->locked, &old, _Q_LOCKED_VAL)) { lockevent_inc(pv_lock_stealing); return true; } @@ -211,8 +212,9 @@ static struct qspinlock **pv_hash(struct qspinlock *loc= k, struct pv_node *node) int hopcnt =3D 0; =20 for_each_hash_entry(he, offset, hash) { + struct qspinlock *old =3D NULL; hopcnt++; - if (!cmpxchg(&he->lock, NULL, lock)) { + if (try_cmpxchg(&he->lock, &old, lock)) { WRITE_ONCE(he->node, node); lockevent_pv_hop(hopcnt); return &he->lock; @@ -355,7 +357,7 @@ static void pv_wait_node(struct mcs_spinlock *node, str= uct mcs_spinlock *prev) static void pv_kick_node(struct qspinlock *lock, struct mcs_spinlock *node) { struct pv_node *pn =3D (struct pv_node *)node; - + enum vcpu_state old =3D vcpu_halted; /* * If the vCPU is indeed halted, advance its state to match that of * pv_wait_node(). If OTOH this fails, the vCPU was running and will @@ -372,8 +374,7 @@ static void pv_kick_node(struct qspinlock *lock, struct= mcs_spinlock *node) * subsequent writes. */ smp_mb__before_atomic(); - if (cmpxchg_relaxed(&pn->state, vcpu_halted, vcpu_hashed) - !=3D vcpu_halted) + if (!try_cmpxchg_relaxed(&pn->state, &old, vcpu_hashed)) return; =20 /* @@ -541,15 +542,14 @@ __pv_queued_spin_unlock_slowpath(struct qspinlock *lo= ck, u8 locked) #ifndef __pv_queued_spin_unlock __visible __lockfunc void __pv_queued_spin_unlock(struct qspinlock *lock) { - u8 locked; + u8 locked =3D _Q_LOCKED_VAL; =20 /* * We must not unlock if SLOW, because in that case we must first * unhash. Otherwise it would be possible to have multiple @lock * entries, which would be BAD. */ - locked =3D cmpxchg_release(&lock->locked, _Q_LOCKED_VAL, 0); - if (likely(locked =3D=3D _Q_LOCKED_VAL)) + if (try_cmpxchg_release(&lock->locked, &locked, 0)) return; =20 __pv_queued_spin_unlock_slowpath(lock, locked);