From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 5A8C437F006 for ; Mon, 1 Jun 2026 22:26:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780352769; cv=none; b=Rh7j/514zRGvYMLW6gkXrJkCK8530eL6icbj3Flm8WKj3mRraUU8XiMHPuHhjVppWcOQTKVfqTFDKlEI3izWuZNFvawCL9ZMUXeeEC9fehGyL0AcsoMzf4Gsg9x9GsJQ9OMoscQOBu/cQ8hTJoiGx9/F7eutOMdTGy3TlMS4xQQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780352769; c=relaxed/simple; bh=KEKGZD7wPG4K2tO6rX2z5E8F6yamjZqlTqEu1Uo9K0c=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=rw3KzWxh7zRA9PVijdo+Fw9h1Hfp/tCGyQGjJL4tT5PHLssgOyLBEgKnE8w87Sqet9dpNvNudYZA2+Olc86i3XWwP6b7zpu2cbGXv/WJTL6t1ncZ+cOIf3dadKFJwW4dXrAdniyS5Hm2PZ1QIK6xudUJ9GrAjSrhk74DFbK1o3c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MBDFhlJa; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=lzV2ON4J; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MBDFhlJa"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="lzV2ON4J" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780352767; h=from:from: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=KEKGZD7wPG4K2tO6rX2z5E8F6yamjZqlTqEu1Uo9K0c=; b=MBDFhlJairdnFQBgaZjG6uc5tH6o5QozZW0NZ7fEG9LzxOjpARmLIPlAioPM6gINyemHx6 jSgdFTPYbedr8yVNl9fouXGWa8lgz2OfYu5AXqs39fuP9208nMKMngcbIDKQXxn2nb4GbS FsI8qrOe+fkyelTjwL6+edMCF+RJCpQ= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-COIeM5mFNdaqgg2kp2RE9A-1; Mon, 01 Jun 2026 18:26:06 -0400 X-MC-Unique: COIeM5mFNdaqgg2kp2RE9A-1 X-Mimecast-MFC-AGG-ID: COIeM5mFNdaqgg2kp2RE9A_1780352766 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-8ccdcc89495so99192706d6.0 for ; Mon, 01 Jun 2026 15:26:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780352766; x=1780957566; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=KEKGZD7wPG4K2tO6rX2z5E8F6yamjZqlTqEu1Uo9K0c=; b=lzV2ON4JUCe1xPz8mKcCGx/rm3yvbye9lfc61W8YLEuTebJGL8nWc9dsOFjO4OBDGS MqcES3tytEfUW6LijfkGQ5B695CErVDpxnoNy9bGs+EVdcsMLUZLE9TQI9ld1NQJzXZs lqihoRFiwKDXDJMaWNlwj/mx2LtQR5Pxgts+LtKqaSm53v0oli5R8EEum132RbnerGYV 5LWnuUAfWUxX1pCMOy7IKzGgcgmRfWZkjfS3p35TIW3QZSOPAUJ44e7mq7N9XPozZAoe i1SUHGaZl4IdpbgAtjkqqXZntFNYJUxPNVCp08+d3TQREhVyTnociCKo61Bz4KCZxhDY 5dkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780352766; x=1780957566; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KEKGZD7wPG4K2tO6rX2z5E8F6yamjZqlTqEu1Uo9K0c=; b=V0T5ZCeIPiiNmCKZ+o308Gd/lBHzVxRIJo5SX+I7a3YMhHJ3wv44w5k3VPsQ2O9Mh2 17Thw5jPw5FkZpmECyc1mR8EIG/pNDJn5OpIZ8ttlVvjXG2U9MwNtM6wh1WOzeOIP687 k7lduidaq/ew8bLdjdvV1ZBb+nWy5wJ4ihxqyM8vFzRh0t0NQ3v6FXxwOxkd0QRSddfU ePW9u7+F/sIiPdplbxbrJ77jRH+mokk9K+gsbVqHesJaidpSnoAHx5VZpuWj9PCDZzVi a8IbqCUnW9+y/TNO//K1PRrr6kc1xcFzo30TqwFTSyi9cgC9rCQXov1ZLYYzCXMRL3v8 ZFeQ== X-Forwarded-Encrypted: i=1; AFNElJ94CNrpOTA+uO1oKYkgzqAUJ1fvtKr/CIAyzZDBMtc4tyvVqXZncnGkCIiZ5+RJjChkyXnsEptgUYMfgzI=@vger.kernel.org X-Gm-Message-State: AOJu0Ywiw2LVGnjBdh1Qlc/wM/CSoFd6zlc42jiAkiZ+x0EnDt4Mz0/K t33dmog2B2iiIUPWfGVCpafbpymo7A8vcR+NjkxWZPSZVWJXuwkJHwBv7sjJfmlhAkavpVvjgHm rPTVyg6DPnGP1qsWPMxwVPqDT7rX84vG01774xW8+hzOdDr134xey5PNWeCwx51gK5g== X-Gm-Gg: Acq92OENegDuj/fKPbS89Egzopr0Z8NkxPem6O9ga8xTxP3lu/QhdwEqWg1OD10tpS4 0zxvirZNhoMvs6I3PLrHq4dEctQ3qugLbaKLjmyixwsf/CkWd4L8oz0ffXlJz1Y1LGccREQJb1P 6uFiPIw68euMA3X+yCbXv5lC8LrrkvS6Ex6zUP7QRf5gfaxd6EnZKlDgTCDc1BzKQlqE7PZ2Tie 4xh8Bja+/5mhEXLJXEb/FH0YZf6lIFMyUnG80iYxjnowOFpCMS+4znNbVa0uzNkUO7017Zmg5Ii oxbUguhsc/9DVDShUZQv4mB4aT1LxPe/2wVTcWzZTN6pGgL2rf3Jz3Q7rzdanv+JZU5POG5wXbO 0x2fNSKhPFcTilqFUEuu0/abkCSpk X-Received: by 2002:ad4:5947:0:b0:8cc:f5b7:4e13 with SMTP id 6a1803df08f44-8cebf53afdbmr26107476d6.24.1780352765759; Mon, 01 Jun 2026 15:26:05 -0700 (PDT) X-Received: by 2002:ad4:5947:0:b0:8cc:f5b7:4e13 with SMTP id 6a1803df08f44-8cebf53afdbmr26107066d6.24.1780352765346; Mon, 01 Jun 2026 15:26:05 -0700 (PDT) Received: from [192.168.8.4] ([100.0.180.93]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ccebb681f6sm99921236d6.4.2026.06.01.15.26.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2026 15:26:04 -0700 (PDT) Message-ID: Subject: Re: [PATCH v2 2/2] rust: sync: Introduce LazyInit From: lyude@redhat.com To: Alice Ryhl Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Gary Guo , Ingo Molnar , Miguel Ojeda , Tamir Duberstein , Boqun Feng , Peter Zijlstra , Viresh Kumar , Benno Lossin , Will Deacon Date: Mon, 01 Jun 2026 18:26:04 -0400 In-Reply-To: References: <20260529173137.303717-1-lyude@redhat.com> <20260529173137.303717-3-lyude@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.3 (3.58.3-1.fc43) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Mon, 2026-06-01 at 08:27 +0000, Alice Ryhl wrote: > I'm not a big fan of using these kinds of tricks to access the > contents > of a mutex after unlocking it. Could we instead use a struct like > this: >=20 > struct LazyInit { > =C2=A0=C2=A0=C2=A0 data: UnsafeCell>, > =C2=A0=C2=A0=C2=A0 set: AtomicBool, > =C2=A0=C2=A0=C2=A0 lock: Mutex<()>, > } >=20 > or even: >=20 > struct LazyInit { > =C2=A0=C2=A0=C2=A0 data: SetOnce, > =C2=A0=C2=A0=C2=A0 lock: Mutex<()>, > } >=20 > I think this logic will be simpler for everyone. > By the way, another option is to use a similar strategy to > https://lore.kernel.org/rust-for-linux/20260523-upgrade-poll-v4-2-f5b4c74= 7eac2@google.com/ > where you just use SetOnce and protect calls to `populate` by another > mutex in the structure. Then you don't need a separate LazyInit. ooo - yeah, that definitely works for me and would be preferable. I still will like to make one change to SetOnce that I think isn't too crazy: writing up a `reset()` function for SetOnce that works through a &mut like what I had here for LazyInit, since that would be quite helpful to have in the gem shmem free_callback() function. >=20 > Alice