From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr2-f12.google.com (mail-wr2-f12.google.com [74.125.225.76]) (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 70E0B435EFA for ; Wed, 23 Sep 2026 09:30:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.76 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790155833; cv=none; b=Eah7/T7sfufVaBKwVqi3sEn2j7CGFlnQxSa4PfSLWlWvkS7eSg0VCmdVwqNmFXV+TJMZWzdXpVovh3HWeFOqVrO13xKMKPV2knV/0yvbMIam1fsi2hUVZDS0bf2GSeSoVbkZYFyRDVAFkjUQjFdA9CxzeoJDLmBimUGE2TphPUs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790155833; c=relaxed/simple; bh=vBPUuNMXa0dgJzwuDSTU7kuQyYIoV4Ak7Pjwd9e1PnY=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Bo90dL8znJTmLoX5H+H3AcauBWsZu1Yjxl5l/L0lZYsgVLGugtOAlq7D7YKC1TxLX58q4cKWzGgjGTXpZ9EnsF2M/1AFL9EllWvUS7aeQy0vnLObNE9l/Q/s2kZ1H5DQ3VDP0gOvlPSaxAwBX7MNUp8chOojHikBx2NCoSJtFmc= 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=mZo1aBS9; arc=none smtp.client-ip=74.125.225.76 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="mZo1aBS9" Received: by mail-wr2-f12.google.com with SMTP id ffacd0b85a97d-485984ebf5cso634203f8f.0 for ; Wed, 23 Sep 2026 02:30:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790155830; x=1790760630; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=XpdOD7b7tZjf2YLODbEeqXbESzHRLhCJCCPyiQAoQpI=; b=mZo1aBS9p45hjZPXMYgAS/IwXUHKZYyeBLuhZnxYXk+iTyUzi6lGbXjY/Ue+x7UU1R rO4YpGbpylZLDW4711fn9YqCw7Z0K2KdiUHd5TJvGAtRXjWGapkkkKgidoZfG9f1qUOa TKI5Ug6rcT1ryqpD7HEv/ea7F02wMs6YYo5TuOvml2V4AHktJm2smSKi54jsVWpV6q+5 dva+Ajd9TpId7R6x1Zf2ndPth5uWaU4+waRFwSHxKfmpGNDGIj8TOv0KQIrNfp5i6BxZ t25ff0Tms2fy7nPSv8K7fW1cu6nqx9QHSE3BXWUuRPXhxN3hbY8rK042iIb/QGvSvoF+ t4Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790155830; x=1790760630; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=XpdOD7b7tZjf2YLODbEeqXbESzHRLhCJCCPyiQAoQpI=; b=MgHRke3YX1OVFyaGd/8y7BsO7FzmoID/qm5wt66ziRB512zku5wT3/v9aF0dVUxMIB Gb1laSlj/tnB+RHsORFtH6tdSa8LafPro5iNOwLO5HavbM0+WfjN9quPYIVYZgn+uWfs i/vY+rwScVF4zbFZYIqhvrHB4PSULWf5dMvjtxN1QGfk4MOok2us6pheZY782rE7cXI2 kI+8yW4usvGrZnMWRNQb9DCp8iU79cAyCAC23/zRYrxQH4qww0Yj87i1f0W4PHlsSjgt 4WvSpEmHsjEgKoIznjVkM39efHgGhG/dUYm0Q92gw8Q05OqiHHP9Zo9fTSUpg5czIlFa 3czw== X-Forwarded-Encrypted: i=1; AKwUvBxYvLFqWmL77mXm33kvKjalQvhN2WsRR0LO/ls6FB2eJahlk1YHkN3WPnNbZDDGQSQAJ1+StKqGcET3MG4=@vger.kernel.org X-Gm-Message-State: AFuF++lljr47VrjKME/XKdXSzURJI4JGOv4cLSg36nn79AOPzNC8kyQ6 TubqSf+7Ld+34t3FKPWaFSA7SGFZrPE6k0Z4oB+F7qzKfmCk5zDn7UfL X-Gm-Gg: AYBFou3GPbCIh49z+R7dXJfScwZAw/BKl3+zvE+yXARl7hRoDdrKNx26u6Q5TPT3QGr i+YW7sa3siyo6wzXE1ox+X9vC1juScG9YG/8dPF13mwWyY9RB0dqHyCbfhzijr7CVgMe+TJc1/G 5TnkrtYymZn0kpuFNdBLW9Ptx/hv/900/BnWHCCZtW1skr4tYthiGOYTPYT+v8ZmmK+O0J9fSxG JisJDOcLKs/p8jOX1PaDesujniKl1YmmCcyTkmyVJgyVPRUHrNTKCMtSr6YLm4Z1lVI5mph+a1t S6euNfgDKGjKCAaimHfRN5VV9CJvzd9cqT5NNL9aJpc4kuYIQBwkeQgQtmx/Des8/ZzXCzXbdYX fMPhKB5NzL0OOe0C+oLML0FVlZtBJzWkaWyCRb7LOQX9JixsDy5mKcGDKYQ5Xj8W+AukCm69IgS w55KoTE7P8rFB70o59sGO8DScstBTu4uI1XM3wzhaDLyRdD+EyZYahT8gHNF7hCOQCOU0oOTCmp /2ETkr3CbN24B/O1kbIXKI06rc0qYQizHqZTn0ZI9dC+eAsNSXwQRLu X-Received: by 2002:a05:6000:22c4:b0:487:35c:6e6b with SMTP id ffacd0b85a97d-4886704aa19mr3430312f8f.12.1790155829433; Wed, 23 Sep 2026 02:30:29 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-488684863d9sm5350009f8f.12.2026.09.23.02.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2026 02:30:28 -0700 (PDT) Date: Wed, 23 Sep 2026 10:30:27 +0100 From: David Laight To: Bradley Morgan Cc: Andrew Morton , Vineet Gupta , Guo Ren , Yoshinori Sato , Rich Felker , Chris Zankel , Max Filippov , Arnd Bergmann , "Paul E . McKenney" , John Paul Adrian Glaubitz , linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/5] ARC: Emulate two-byte cmpxchg Message-ID: <20260923103027.22bd9ef4@pumpkin> In-Reply-To: <20260922173354.14404-3-brads@mainlining.org> References: <20260922173354.14404-1-brads@mainlining.org> <20260922173354.14404-3-brads@mainlining.org> 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 Tue, 22 Sep 2026 17:33:51 +0000 Bradley Morgan wrote: > ARC has no two-byte atomic compare and swap, so the arch_cmpxchg_relaxed() > macro switch lets case 2 fall through to BUILD_BUG() via default. Route case > 2 through the new cmpxchg_emu_u16(), which takes the old and new > values as unsigned long and narrows them itself, so the (uintptr_t) > casts on _o_ and _n_ are no longer needed and the case 2 call passes > them straight. > > The switch also now tests sizeof(*(_p_)) instead of sizeof((_p_)), > which switched on the pointer and made the size 1 and size 2 cases > dead code, routing every sub-word cmpxchg() through the 32-bit > llock/scond pair and comparing whole words against sub-word values, > so the compare almost never succeeded. Hmmm... that looks like it warrants a 'Fixes' tag. Clearly no one uses 'arc'. David > The old and new values are > now declared as unsigned long through (unsigned long)(0 ? *(_p_) : > (old)), the idiom David Laight suggested, which type checks the > arguments against the pointee, so cmpxchg(&p, 4, 5) no longer > compiles silently. > > Signed-off-by: Bradley Morgan > --- > arch/arc/include/asm/cmpxchg.h | 19 +++++++++++-------- > 1 file changed, 11 insertions(+), 8 deletions(-) > > diff --git a/arch/arc/include/asm/cmpxchg.h b/arch/arc/include/asm/cmpxchg.h > index 76f43db0890f..4596edfefa95 100644 > --- a/arch/arc/include/asm/cmpxchg.h > +++ b/arch/arc/include/asm/cmpxchg.h > @@ -42,16 +42,19 @@ > #define arch_cmpxchg_relaxed(ptr, old, new) \ > ({ \ > __typeof__(ptr) _p_ = (ptr); \ > - __typeof__(*(ptr)) _o_ = (old); \ > - __typeof__(*(ptr)) _n_ = (new); \ > + unsigned long _old_ = (unsigned long)(0 ? *(_p_) : (old)); \ > + unsigned long _new_ = (unsigned long)(0 ? *(_p_) : (new)); \ > __typeof__(*(ptr)) _prev_; \ > \ > - switch(sizeof((_p_))) { \ > + switch (sizeof(*(_p_))) { \ > case 1: \ > - _prev_ = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *__force)_p_, (uintptr_t)_o_, (uintptr_t)_n_); \ > + _prev_ = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *__force)_p_, _old_, _new_); \ > + break; \ > + case 2: \ > + _prev_ = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *__force)_p_, _old_, _new_); \ > break; \ > case 4: \ > - _prev_ = __cmpxchg(_p_, _o_, _n_); \ > + _prev_ = (__typeof__(*(ptr)))__cmpxchg(_p_, _old_, _new_); \ > break; \ > default: \ > BUILD_BUG(); \ > @@ -64,8 +67,8 @@ > #define arch_cmpxchg(ptr, old, new) \ > ({ \ > volatile __typeof__(ptr) _p_ = (ptr); \ > - __typeof__(*(ptr)) _o_ = (old); \ > - __typeof__(*(ptr)) _n_ = (new); \ > + unsigned long _old_ = (unsigned long)(0 ? *(_p_) : (old)); \ > + unsigned long _new_ = (unsigned long)(0 ? *(_p_) : (new)); \ > __typeof__(*(ptr)) _prev_; \ > unsigned long __flags; \ > \ > @@ -102,7 +105,7 @@ > __typeof__(ptr) _p_ = (ptr); \ > __typeof__(*(ptr)) _val_ = (val); \ > \ > - switch(sizeof(*(_p_))) { \ > + switch (sizeof(*(_p_))) { \ > case 4: \ > _val_ = __arch_xchg(_p_, _val_); \ > break; \