Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1372136rwl; Fri, 24 Mar 2023 09:38:13 -0700 (PDT) X-Google-Smtp-Source: AKy350b8KSqVZucgyC2ty6RroDqNITwqdj8L27gwCjBZ3TxTOtkPUUXPsf21gPsa/9jDJZ1ZajFW X-Received: by 2002:a17:907:6e17:b0:92f:c6b5:de08 with SMTP id sd23-20020a1709076e1700b0092fc6b5de08mr3650084ejc.76.1679675893253; Fri, 24 Mar 2023 09:38:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679675893; cv=none; d=google.com; s=arc-20160816; b=YY7+FhYCaqQ5bbAXB/HHIyLn1YjeXb3juiHszqnfD354Ygow9vjIaWntObjEjYqGb2 mp3v0M8zZS2Vr1IIFAHlEtQGU22RO7MzQ3jdMf2LmQurVzBbmJzjqoTrtmYwUajdTuDx BxJ5SxHrL8VgRuYM698/e98HI0hxMNh6t5vJ5I6m2yGJLecZcmgDFIzXxvfsLU8+MRmM huQpfxNM6e8yV4iodFm1mCNu+aqr+Lq0iPCjEVHzzTeHIXl3bSE6GdRStTs4nZX5jhmd u68VtjmK7mR7yU0alC2/LrBsdzy67rPApYspMoGduieGz6jbmQzcNP6zM1PFKydYyK1O d8YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=kCjDWCLrXTdXjFb83G6rN/tUS/hKNe0TB/3jyzTrmBk=; b=m1VLjBNHiipTvD0DfuP/Sls6B8PzTVNqo2fv8mQjPDNk4s0lYD0elEGcWAb9LhEYzz FL6eYJo0vfPL+BW509HtuSpaqWsTAPyfWrip51GxJyMttoJbjLg6PnxPIg+Pa28Rr58Z 6SDtkQVCwDgPi+WeCc3Ufj/xrofT7AIb2OVdzKjVTbTqUox9XY1Yp73Aw5fmHBoWZuWM O7dfegBBvVhMkH4UQLuOEfmuJxJBZ6dPyE4w8tF78xd0sYFrYBrRWKggiP0abf04RXK1 bA131p/LkeADvcv6TVzaQGyv8RsfmMr21iMe0ToOPnJAnHOMaeBcGIECuRI1TIeD7baH JNGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp33-20020a1709073e2100b00934e2ca8548si16618661ejc.210.2023.03.24.09.37.48; Fri, 24 Mar 2023 09:38:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229919AbjCXQd6 (ORCPT + 99 others); Fri, 24 Mar 2023 12:33:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbjCXQd4 (ORCPT ); Fri, 24 Mar 2023 12:33:56 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 13DFCC65E; Fri, 24 Mar 2023 09:33:55 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E2C3A113E; Fri, 24 Mar 2023 09:34:38 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.56.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 17CBD3F6C4; Fri, 24 Mar 2023 09:33:52 -0700 (PDT) Date: Fri, 24 Mar 2023 16:32:52 +0000 From: Mark Rutland To: Uros Bizjak Cc: linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org, linux-perf-users@vger.kernel.org, Will Deacon , Peter Zijlstra , Boqun Feng Subject: Re: [PATCH 01/10] locking/atomic: Add missing cast to try_cmpxchg() fallbacks Message-ID: References: <20230305205628.27385-1-ubizjak@gmail.com> <20230305205628.27385-2-ubizjak@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 24, 2023 at 04:14:22PM +0000, Mark Rutland wrote: > On Fri, Mar 24, 2023 at 04:43:32PM +0100, Uros Bizjak wrote: > > On Fri, Mar 24, 2023 at 3:13 PM Mark Rutland wrote: > > > > > > On Sun, Mar 05, 2023 at 09:56:19PM +0100, Uros Bizjak wrote: > > > > Cast _oldp to the type of _ptr to avoid incompatible-pointer-types warning. > > > > > > Can you give an example of where we are passing an incompatible pointer? > > > > An example is patch 10/10 from the series, which will fail without > > this fix when fallback code is used. We have: > > > > - } while (local_cmpxchg(&rb->head, offset, head) != offset); > > + } while (!local_try_cmpxchg(&rb->head, &offset, head)); > > > > where rb->head is defined as: > > > > typedef struct { > > atomic_long_t a; > > } local_t; > > > > while offset is defined as 'unsigned long'. > > Ok, but that's because we're doing the wrong thing to start with. > > Since local_t is defined in terms of atomic_long_t, we should define the > generic local_try_cmpxchg() in terms of atomic_long_try_cmpxchg(). We'll still > have a mismatch between 'long *' and 'unsigned long *', but then we can fix > that in the callsite: > > while (!local_try_cmpxchg(&rb->head, &(long *)offset, head)) Sorry, that should be: while (!local_try_cmpxchg(&rb->head, (long *)&offset, head)) The fundamenalthing I'm trying to say is that the atomic/atomic64/atomic_long/local/local64 APIs should be type-safe, and for their try_cmpxchg() implementations, the type signature should be: ${atomictype}_try_cmpxchg(${atomictype} *ptr, ${inttype} *old, ${inttype} new) Thanks, Mark.