Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp24434lql; Fri, 12 Apr 2024 02:24:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWxWQXH9O/uOkr+tseFsYmCr1ZkXNujt+sYG5jGChN3uZD6I3MDIntO96l2d+8rWWHEt9YfZFRaAdJjdg94JMH7mpoV4RPeW8EyEBZXHw== X-Google-Smtp-Source: AGHT+IGVcsfEbQtL1bZUReUdoSd+CzMoTzxOYWbBeTYNVFsXKWGzNAIQ5TDdg4bJkk0wJQE18rR7 X-Received: by 2002:a05:622a:10c:b0:434:f39f:ef83 with SMTP id u12-20020a05622a010c00b00434f39fef83mr3120078qtw.44.1712913848646; Fri, 12 Apr 2024 02:24:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712913848; cv=pass; d=google.com; s=arc-20160816; b=Mf1FdwYxzT+vtyeth67Q3H6UeVG1w3jUh9FhXLy+FBqdb5fJWGX3VJhfXMv9ho1pjH c2P+wlw6IRzXtl/XFPi32i+bd8CqaT69TvKss8mClfNnhTOPJCIzh8Yvm3Sk4iZd6hli HjihvRI5uJ+PG97i0g0US9Pqzootw9DR377/ookpEQz15rOtQQj/BdneZwZhU3KpnSQz MIqAujSi+n0e2VLPVAeVlJ6OvjSCqpECUgtKFUpAhfEiqAhgEq/aczXbw8AlPWszk44I e3hAxG496wStr67WBw7mbXPT/f2kaBDWWsPvycH1yI2FUN9M8+GlP9Qob5FO5XHjWMZm yvmw== 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=lgmYgwwZi90eXTj5n/Q0qCknlWcNGDmvUBJwpSGubBQ=; fh=Ud94Q6dWpSSu3/GJgsQezWkHqhtq6g8OS0jJFkPGhUA=; b=tRCQdnOsmBZ/FVf497ldkhXlQ6Gj+ei+ZugHxHL1Fw2nfLkTrXvXjRPFj5+GMOqzNt bK2pocpTSDSyvyEz0RqC/xzZIEfKw9EKF9TiQLy3sDV1+b42/FyZudEjIjQjKw7EGl5x nH3o2CLB/aFI8gRCDp1bHsZwnQkqRLiMVeI5qHtIVXsAySljFPbqVjifaJ/qlFsX7kpC nBxc9ZB/rWe+2h4nNkcl9XatF0hmk6/fWH+30M8PvofS0bncYwikvrXzh3oIE5s3CoR1 WgzQffJJoXGptw55a4lZXzkGMIitOoH9CKusnYcphfQqGnGvYMJI9ZKpwU55K+GzsnZe QEyw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="h/kYj3Cl"; 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-142397-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142397-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id k9-20020a05622a03c900b00434e54824e5si3166902qtx.648.2024.04.12.02.24.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 02:24:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142397-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="h/kYj3Cl"; 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-142397-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142397-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 621501C227DA for ; Fri, 12 Apr 2024 09:24:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 148C058106; Fri, 12 Apr 2024 09:21:18 +0000 (UTC) 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" 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 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: 7bit The following commit has been merged into the locking/core branch of tip: Commit-ID: e361be1ff2621493f5c638719d706e9789f7ab4c Gitweb: https://git.kernel.org/tip/e361be1ff2621493f5c638719d706e9789f7ab4c 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) == 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);