Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp32198lql; Fri, 12 Apr 2024 02:46:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVIMaxAgqAhbH5wP+V7Pu5Qacuo4HUsAjR9Wxf4tFrDd0F0aSHRlOis8FwSFAuRjd6snWMZlGVTgExf9N/6l4c7OF7gm2f13O5TAjS7sA== X-Google-Smtp-Source: AGHT+IEE/HNAgmIVEn344wdgCWc3R7PeRO/tNVA40HYYaA62fl3/PhIqgT0eY7S341LY7SdjP8Ks X-Received: by 2002:a05:6a00:9aa:b0:6ed:435f:ec9b with SMTP id u42-20020a056a0009aa00b006ed435fec9bmr2566925pfg.20.1712915192801; Fri, 12 Apr 2024 02:46:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712915192; cv=pass; d=google.com; s=arc-20160816; b=vr0f3jpEHXxr/TglnacuImEqYtoSl7rqZkTYbLq6mNqEQi0PW2wA49Jp83K8+cPr9O LN7r5XEL8yXUPw/yoCJ1kewFQrjpo2+kbVPDWJ1GbqBj/xtMoujGGBQ1Hz63c1OxdG0S bq78Ptd5fBDC4OJ/RiwQEWrATYaMKW3yhQelXYkVXy3D20He2SZSm+Kq5EBEAbfLSROj Z2IQi7z8YiI0QPXJqu5braxC2e73PKYF2a3bErEV6H1svISXteZ3Jylw+3CA8J0mTz8l KvRygRSYVjK0TpRkEpYyFPFgRCk65VidgfskIbm+eg6gQC8xJaZLLALIGisImzQoSmUF VRxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=P6XRvPI1tYLBSmNwTmwjjmv92sbhGwJHc4BFKYQy6xA=; fh=Ud94Q6dWpSSu3/GJgsQezWkHqhtq6g8OS0jJFkPGhUA=; b=Wr12jBkgSdhwET7kCvDXPsVdIIwkQ90sHsfeexVqM58kGoidBQUih5/q7C15fCaHmO Ud7bkoIceyvItkvHtzqorJvZvIdC781XwXSAPE5LM9fbCM2xyINK6o9QyoPUO7VZ2Q0x Kf3NHF04lnUntST+Cs1PFV+9wlWgS3DjKN3DfOp0mtOkUuUTMA7hP+WRRKyHyQRUxusW mZzy+nVeYQU0a925FF+wAJ98fwiokFCzIQGVlHKywJTRz3JkezLH3UNj5FjKWNrPtDYB lX9ljdTUrH1GRZVvKEAU1dmBPZqlyUVX9Vkwo+f8H+q3AiGN4gcCW15oYsH+7cRvlrH9 KBgg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yo0bSjLE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-142433-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142433-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c3-20020a056a000ac300b006ee007f15f7si2604747pfl.284.2024.04.12.02.46.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 02:46:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142433-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yo0bSjLE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-142433-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142433-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7217E2846C4 for ; Fri, 12 Apr 2024 09:46:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F0B853388; Fri, 12 Apr 2024 09:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yo0bSjLE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="b1mgBzsd" 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 5DE7A51C34; Fri, 12 Apr 2024 09:46:18 +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=1712915180; cv=none; b=iBsqHvnNGDehqCM8o/eqeB8f2Jhagn96VPsuaVrJ6rQ37HlzNY/OyU5rWx+ReJz/VPkNwyE11F0dRN4h3RkyeEDFnASMFRZUTmjdWipsDum0gWU/qhT9Z/Q7Czm1Q2kk9hnW+Z68AdFGjdTkTyWUekis69qvocf3ROPGLdwrCHo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712915180; c=relaxed/simple; bh=/Us3vhKdB2/ROVstVTV5U/SGyd83c1WO34+U6z6ZpKk=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=YFlRVsMWo27A1UdpP4s5Nbhb2ZC+vDvZcikKzKSouiFZAod8y53BeI8Tgl8R5aSNyWp+GvWKnD7GGkHBOKQd7j2aQak1Mj3zQFKw0ane5BzG90BEydsEduFtu7vIOOMAouOl7sNx3o8oCEwF208ecbLJlyCoURpy6NEgq0H/1sw= 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=yo0bSjLE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=b1mgBzsd; 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 Date: Fri, 12 Apr 2024 09:46:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712915177; 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=P6XRvPI1tYLBSmNwTmwjjmv92sbhGwJHc4BFKYQy6xA=; b=yo0bSjLEhCokMcnku9+1qy4nqzmV+u27aM8Au4K8KgD0jcryCmgkRDMLypHZIdDA7wxeSs lY141dgHsSALcBCNTEcfCs8GGVG5L+04CFBK/8qcQV7tDFLbDHp7wYrZnRupduomx0IhJo vodkyQKzm/RCHkc+LTJOGLGe1Pp9PbkJWofZv8etTuV3ySUUFZjGkeGRfAoa0F3QCDWfIu bXOkXj92EUU8w6kFkQVBzNol8ctlKlkPHgComo7sghljQNi7GiEDoA5dzqkkGiMceeexH1 UwStvtdFahWo88eAyyILD1RQGuRqWw/2V7NtM7EVHZQafftGg8RI49tjS5kodw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712915177; 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=P6XRvPI1tYLBSmNwTmwjjmv92sbhGwJHc4BFKYQy6xA=; b=b1mgBzsdDVXtp20y76OYzL7k6USQx6ufsC0P6NVBro8Bs2mf/uGd8cxpuRVJeVhcVQB1/K eltbiwEcp7+ph4Ag== 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: <171291517671.10875.5289616784830783285.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: 7bit The following commit has been merged into the locking/core branch of tip: Commit-ID: fea0e1820b51fff95c85518eb9cf3386f367908d Gitweb: https://git.kernel.org/tip/fea0e1820b51fff95c85518eb9cf3386f367908d Author: Uros Bizjak AuthorDate: Thu, 11 Apr 2024 21:22:55 +02:00 Committer: Ingo Molnar CommitterDate: Fri, 12 Apr 2024 11:42:39 +02:00 locking/pvqspinlock: Use try_cmpxchg() in qspinlock_paravirt.h Use try_cmpxchg(*ptr, &old, new) instead of cmpxchg(*ptr, old, new) == 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(struct qspinlock *lock) */ for (;;) { int val = atomic_read(&lock->val); + u8 old = 0; if (!(val & _Q_LOCKED_PENDING_MASK) && - (cmpxchg_acquire(&lock->locked, 0, _Q_LOCKED_VAL) == 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 *lock, struct pv_node *node) int hopcnt = 0; for_each_hash_entry(he, offset, hash) { + struct qspinlock *old = 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, struct mcs_spinlock *prev) static void pv_kick_node(struct qspinlock *lock, struct mcs_spinlock *node) { struct pv_node *pn = (struct pv_node *)node; - + enum vcpu_state old = 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) - != vcpu_halted) + if (!try_cmpxchg_relaxed(&pn->state, &old, vcpu_hashed)) return; /* @@ -541,15 +542,14 @@ __pv_queued_spin_unlock_slowpath(struct qspinlock *lock, u8 locked) #ifndef __pv_queued_spin_unlock __visible __lockfunc void __pv_queued_spin_unlock(struct qspinlock *lock) { - u8 locked; + u8 locked = _Q_LOCKED_VAL; /* * 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 = cmpxchg_release(&lock->locked, _Q_LOCKED_VAL, 0); - if (likely(locked == _Q_LOCKED_VAL)) + if (try_cmpxchg_release(&lock->locked, &locked, 0)) return; __pv_queued_spin_unlock_slowpath(lock, locked);