From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66F8F303A26 for ; Fri, 6 Mar 2026 23:01:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772838111; cv=none; b=ovobSmRMCfehJ1uKiOLc6hy9mVMMGCwTyG99Zv2Rb6NrsSNUSw80CQtXwMUklm/IXP9+dEASlHxB8PeyKcpB9jXmsw4Y+tdjQ8UQGbcX9TZkd+TBGIwxGUMpXfDbT1CwblZNR0GosQR28xuBrqoJuZJJja93K9N8UICd71HfZ0w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772838111; c=relaxed/simple; bh=U9KNVACx7LcUNec72rTJF5WAYZP6Tm3RU0SP8avBzFw=; h=Date:From:To:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kmY9WtCOhnsu2qVInB0TNHETIZ5WigGunp9fmqYr0fWKFg6t3s8LqBIXVtckIGV9LrxtFR/9uzvTDEL3taqF7TgAfCEhRkdzBYsGPiroYSxU1hrgLDRkIefbtvRw3Wz0K+VbMKSBnoE3fltGq49b5JqTrtbKDkzEKcFv7TDZmFg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Sn0kGylT; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Sn0kGylT" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-b886fc047d5so1604725466b.3 for ; Fri, 06 Mar 2026 15:01:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772838109; x=1773442909; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:to:from:date:from:to:cc:subject:date:message-id :reply-to; bh=csq6UnkG3rFF/Au2dqYAL62oGuzagATvVAFu0wgNA9E=; b=Sn0kGylThXZufICrvAA2cKO/a/xwncrRPnLP5pjRVGbVXggWxzAThwd5qylE/HRn/E 9mXhmB7T4z+Gkk6JNGDuc73LLo7b3YKNhsUo9GwjkyF33I9SyUcz+I7Jx76sOILDpVah meIRUJ7cGcqO2sayrI0omf5aVV9Zl3JpX4sxZUrWuW3hVm1buQbdTa+qhArOlpSN2tJ5 wdl2dLyTXYhohafdvHx429hudY/Y166c6PBzxK7lHtHX8+MfhwTfhIcjnPFaC0JSrKsu AgK+e43VIcJvSh3TsPLthU0p+2AIfjDnVLe6SuGGujXhM1p2JYTTQbSSvgIyyByNzKka Z9VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772838109; x=1773442909; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:to:from:date:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=csq6UnkG3rFF/Au2dqYAL62oGuzagATvVAFu0wgNA9E=; b=n5lST5sMpnAO6ZNQDD3u5GtlqqdRgoRK1Vmr0s01Uj/D+wgv7himGTMkWCqaKnfpF5 Cfa4SdAldFjlfYfbgkd2Uiig3hApsvldupcLY5eRjim8ItUxtVnnSjrpl+/DghKfpEfb lKeP+rn4UOpA2hULtlBLCiLcBZBZWj96MqvBVg8iLU8TA9+nkuATu19l8nA2lHXjpvup uGVstLGPd5JYy4ZHDJfTe4bCzXBKei2Q0HAmGVlxxdNXOkk8ONFhWi0I9/yXkX+Wfxm+ HMfPQ8/sQug2cDv+vXNzSJH3nltABv2zPbr0FOWC4bUqZ01r5W7EtYd4dehzyEFWoFfz priA== X-Forwarded-Encrypted: i=1; AJvYcCXcA3L/KoveF9FDVjm6WR5maWu5AEred0T/Ojn/JHe9+WoBxijtAQWF+g8gYbubngfUegDAeZSZetZQKUI=@vger.kernel.org X-Gm-Message-State: AOJu0YzDgy8kdkAyd9ogcpBoLcmC3GQUSBHhQOfG4rHn5RP+Uq+0LSbh rmka34oWBJDoJeUfgq3mh8i14ppspNTEgRnqzh3DzIFs7BSWtXBzbzzx X-Gm-Gg: ATEYQzxYp8Q6ZHILRPbe/8VXKiucl70piZy85dZ/MHGYoAlsuTV4JANhhfvS4i+ik30 ywwZKtEI3Eff7w+Z06BXDrFtBB6Mbcj/VsTpzO0yPxUxhser6nQaNl2iojubUtgMCjoP9i5wHQb 20kIksOA7rLBpUTR8PR39FZ30qfcgWC47yf8pFdzb48SubbwXbqfqaFrxE78OJox2zI/XJrldxH xGeIsmxKcOah3ph+SHs/mH6Xp9TpBgDrx/FtJYFW8fVAyj6r+2iY1RmQQD6ZSaPPf47r9tDdKWL cCXgJjKmqcH2dPC9VoOxMCFBuwnxmZO+U0ReyuuJLK8OuE3Dnh/Qwb3SA+iN+vHETygJcrYPsRN uC4R6COgt8TXcMOE00aFJwQGcYjQ3O6a2f1iMxNFLH94tdFc9KVdLRq7fpezDZ8WjGP6tgqbr53 OjSq+R92gPrcdkvlUuq9nqJUO2pqSp/oRVHTBFE3XmEVBx4nZOoUw5tnrFTrHf0LUi X-Received: by 2002:a17:907:94c2:b0:b93:8460:4ac with SMTP id a640c23a62f3a-b942e05c8admr221014466b.53.1772838108344; Fri, 06 Mar 2026 15:01:48 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-661a55a205asm787708a12.30.2026.03.06.15.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2026 15:01:48 -0800 (PST) Date: Fri, 6 Mar 2026 23:01:46 +0000 From: David Laight To: Waiman Long , Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , linux-kernel@vger.kernel.org, Linus Torvalds , Yafang Shao , Steven Rostedt Subject: Re: [PATCH v3 next 3/5] Use node->prev_cpu instead of saving node->prev Message-ID: <20260306230146.5d8606f5@pumpkin> In-Reply-To: <20260306225150.93178-4-david.laight.linux@gmail.com> References: <20260306225150.93178-1-david.laight.linux@gmail.com> <20260306225150.93178-4-david.laight.linux@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 6 Mar 2026 22:51:48 +0000 david.laight.linux@gmail.com wrote: Apologies to Yafang for mistyping his address... > From: David Laight > > node->prev is only used to update 'prev' in the unlikely case > of concurrent unqueues. > The new 'prev' pointer can be obtained from prev_cpu. > > node->cpu (or more particularly) prev->cpu is only used for the > osq_wait_next() call in the unqueue path. > Normally this is exactly the value that the initial xchg() read > from lock->tail (used to obtain 'prev'), but can get updated > by concurrent unqueues. > > Both the 'prev' and 'cpu' members of optimistic_spin_node are > now unused and can be deleted. > > Signed-off-by: David Laight > --- > kernel/locking/osq_lock.c | 31 ++++++++++++++----------------- > 1 file changed, 14 insertions(+), 17 deletions(-) > > diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c > index 0e1c7d11b6c0..5dd7e08d4fda 100644 > --- a/kernel/locking/osq_lock.c > +++ b/kernel/locking/osq_lock.c > @@ -13,9 +13,8 @@ > */ > > struct optimistic_spin_node { > - struct optimistic_spin_node *next, *prev; > + struct optimistic_spin_node *next; > int locked; /* 1 if lock acquired */ > - int cpu; /* encoded CPU # + 1 value */ > int prev_cpu; /* encoded CPU # + 1 value */ > }; > > @@ -96,10 +95,9 @@ bool osq_lock(struct optimistic_spin_queue *lock) > struct optimistic_spin_node *node = this_cpu_ptr(&osq_node); > struct optimistic_spin_node *prev, *next; > int curr = encode_cpu(smp_processor_id()); > - int old; > + int prev_cpu; > > node->next = NULL; > - node->cpu = curr; > > /* > * We need both ACQUIRE (pairs with corresponding RELEASE in > @@ -107,23 +105,22 @@ bool osq_lock(struct optimistic_spin_queue *lock) > * the node fields we just initialised) semantics when updating > * the lock tail. > */ > - old = atomic_xchg(&lock->tail, curr); > - if (old == OSQ_UNLOCKED_VAL) > + prev_cpu = atomic_xchg(&lock->tail, curr); > + if (prev_cpu == OSQ_UNLOCKED_VAL) > return true; > > - WRITE_ONCE(node->prev_cpu, old); > - prev = decode_cpu(old); > - node->prev = prev; > + WRITE_ONCE(node->prev_cpu, prev_cpu); > + prev = decode_cpu(prev_cpu); > node->locked = 0; > > /* > * osq_lock() unqueue > * > - * node->prev = prev osq_wait_next() > + * node->prev_cpu = prev_cpu osq_wait_next() > * WMB MB > - * prev->next = node next->prev = prev // unqueue-C > + * prev->next = node next->prev_cpu = prev_cpu // unqueue-C > * > - * Here 'node->prev' and 'next->prev' are the same variable and we need > + * Here 'node->prev_cpu' and 'next->prev_cpu' are the same variable and we need > * to ensure these stores happen in-order to avoid corrupting the list. > */ > smp_wmb(); > @@ -179,9 +176,10 @@ bool osq_lock(struct optimistic_spin_queue *lock) > > /* > * Or we race against a concurrent unqueue()'s step-B, in which > - * case its step-C will write us a new @node->prev pointer. > + * case its step-C will write us a new @node->prev_cpu value. > */ > - prev = READ_ONCE(node->prev); > + prev_cpu = READ_ONCE(node->prev_cpu); > + prev = decode_cpu(prev_cpu); > } > > /* > @@ -191,7 +189,7 @@ bool osq_lock(struct optimistic_spin_queue *lock) > * back to @prev. > */ > > - next = osq_wait_next(lock, node, prev->cpu); > + next = osq_wait_next(lock, node, prev_cpu); > if (!next) > return false; > > @@ -203,8 +201,7 @@ bool osq_lock(struct optimistic_spin_queue *lock) > * it will wait in Step-A. > */ > > - WRITE_ONCE(next->prev_cpu, prev->cpu); > - WRITE_ONCE(next->prev, prev); > + WRITE_ONCE(next->prev_cpu, prev_cpu); > WRITE_ONCE(prev->next, next); > > return false;