Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3344183rwd; Mon, 22 May 2023 12:14:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ73fhtwGjQ5BR9z3/TaYbI99G4RWCLh98m1mpgWRWBABvt+DhywMyP9zHsy1MvC09QFC7o0 X-Received: by 2002:a17:902:ce81:b0:1ac:61ad:d6f2 with SMTP id f1-20020a170902ce8100b001ac61add6f2mr12745943plg.5.1684782864364; Mon, 22 May 2023 12:14:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684782864; cv=none; d=google.com; s=arc-20160816; b=oHNEyzhHQt/Adoy2eH6hm0L7SDf72/+Lp56mMENpqy1C2SxNFeoyGEzL3rAu+aimnN lLRDElnhgsb8mA2QewUSkciZX9NW2xvsGEQN7UG9A2xfcvN/Pxqemo5pkeWi7DTHpfho dyQGa72pgg7BsGqESCWxdQZPiJYokMs429AkuEPFzyMO/6SbjRD92d9ugJQuAD6noF+D Q3fG8Ng08NPowKCd7Dp/0aAGBLwwBR8cIQVtVjzckIOL+0YSGT4XU7nYgjwNT3qMlaTx f+Qz+QERIkbFCnKdDCB7uowK+SurFvnSKaCwhwfrF9xkL98JLinaki8ppuFMambZyYfI DqOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=vr44La27+mz8n+82Zo9X1oKc2Ak0g3wj0ym86181XGQ=; b=fMrFg5qVlkPtAZbpe7PU2sjcSCOvPWcWgTc4pXhTj2wamuyvcCbarLcXfRpw5zuyzy d0aSiShZKPeb7RSr/QGKIbRZORuf6c1IE5ug6KZc+vB+bR0j82AujXd/vGzEQoOVPttC YotifGIciOi8e7QrrsvLhNCNQk1DOsj/vhC5y8oKt5HlWTzC3vzbfA2SD8YeHfnaVRG7 fCL/oonElESSN0El3h+cZkypZ5YMM5b+Xx7EE1v5TF2KjFh9MYR1Y+z9SyTyPm9wlrBH iHtgs4FwwwoJPycH8ZA3Tfp1wgOJmMx06O9zA61xIH/mWaVpoFSU0gweMAhC/+k94AiN Q8rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="d6wu2CS/"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n13-20020a170903110d00b001ab16128039si5343180plh.213.2023.05.22.12.14.08; Mon, 22 May 2023 12:14:24 -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; dkim=pass header.i=@linux-foundation.org header.s=google header.b="d6wu2CS/"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233445AbjEVS64 (ORCPT + 99 others); Mon, 22 May 2023 14:58:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229714AbjEVS6y (ORCPT ); Mon, 22 May 2023 14:58:54 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08175DB for ; Mon, 22 May 2023 11:58:53 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-51190fd46c3so5844017a12.1 for ; Mon, 22 May 2023 11:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1684781931; x=1687373931; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vr44La27+mz8n+82Zo9X1oKc2Ak0g3wj0ym86181XGQ=; b=d6wu2CS/ecLYXBnJBfDH1lUT5tTEOEzfCr5tOvBDmpNQsOkpSvI70tpEjPz8LkymtN hljLXHExNHKPt5q95akj52UpRDs45iwOy/KmLHZvAN5EeVJNsxXHopj5zAW6y9nclMuP 53cSo3rM1RThCAQqDfsp101httIx/DUYg71Vg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684781931; x=1687373931; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vr44La27+mz8n+82Zo9X1oKc2Ak0g3wj0ym86181XGQ=; b=ggdYWvetO8cHLM3/R+PHoOKg42Xvufsl2ThRoxc9CGIF/jEZCXo1CZ2qcYlq/X63Gj Ci7oXNSyopnpeL59KHYuWExA9r/SVCaSpgPGnGtkhtv87Eniu6qTkM126Av/F0E2orFQ PTpzVfMCz0yPmETBjyRtNoiUuiz+cMRzagXqIMAWis5stI6uD/oBRBMSVmkXtqMEghEw xm2kQSeeYieioKPCVehr26JiLjBN9K8IjGb+ed5g1UcFeDnsKHfYOZz78N+/q6C98sCn QASM6mOTd2MAfY8o6BIA1Ej2V9foI4XOLKusK9tCtCsYEG4K9G9hkp5SOSje5oYRD2qm 2SdQ== X-Gm-Message-State: AC+VfDzRRbAZrTX3mTiF1UB2pZXBBYLj4jwuTwxSolK6WtbIPvyYdJMx yCDWfr8Q+7sUQ2uhIcOup28e00w/odaV9dXq7j3SxeAy X-Received: by 2002:aa7:d4c3:0:b0:50b:c584:527b with SMTP id t3-20020aa7d4c3000000b0050bc584527bmr8516425edr.29.1684781931200; Mon, 22 May 2023 11:58:51 -0700 (PDT) Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com. [209.85.218.52]) by smtp.gmail.com with ESMTPSA id l4-20020a50d6c4000000b00510de087302sm3398248edj.47.2023.05.22.11.58.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 May 2023 11:58:50 -0700 (PDT) Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-970056276acso161051166b.2 for ; Mon, 22 May 2023 11:58:50 -0700 (PDT) X-Received: by 2002:a17:907:628c:b0:96a:6e42:712b with SMTP id nd12-20020a170907628c00b0096a6e42712bmr11877487ejc.18.1684781929922; Mon, 22 May 2023 11:58:49 -0700 (PDT) MIME-Version: 1.0 References: <20230522171314.1953699-1-kent.overstreet@linux.dev> In-Reply-To: <20230522171314.1953699-1-kent.overstreet@linux.dev> From: Linus Torvalds Date: Mon, 22 May 2023 11:58:33 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] locking: SIX locks (shared/intent/exclusive) To: Kent Overstreet Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , Brian Foster , Dave Chinner Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Mon, May 22, 2023 at 10:13=E2=80=AFAM Kent Overstreet wrote: > > +static inline unsigned u32_mask_to_ulong_bitnr(u32 mask) > +{ > + union ulong_u32 { > + u32 v32; > + ulong vlong; > + } v =3D { .v32 =3D mask }; > + > + return ilog2(v.vlong); No, this is still wrong. The above is actively undefined - the high bits of 'vlong' can contain random garbage. And you can't even fix it anyway, because even if you add a second 32-bit word and zero it, on big-endian architectures you'll get a result that is bigger than 32, and then when you do this:L > +static inline void six_set_bitmask(struct six_lock *lock, u32 mask) > +{ > + unsigned bitnr =3D u32_mask_to_ulong_bitnr(mask); > + > + if (!test_bit(bitnr, (unsigned long *) &lock->state)) > + set_bit(bitnr, (unsigned long *) &lock->state); you're back to basically just undefined behaviour. You *cannot* do "set_bit()" on a u32. It's that simple. Stop trying to do it with these wrappers that happen to work on x86 but are fundamentally broken. We don't do locking by playing games like this. It's wrong. You clearly don't even want the return value, so you're actually much better off just using an atomic_t and "atomic_or()", I suspect. But these broken games with casting pointers to invalid types MUST END. Locking is subtle enough without doing clearly bogus things that depend on byte order and word size, and that aren't defined for the type you want to use. Linus