From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (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 61F0D3EF670 for ; Thu, 30 Jul 2026 09:11:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.71 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785402713; cv=none; b=ieQfeIb23lqSxAi+WNQ27WEYE5OP+m3VYQrJTrOpFaqAK8Sao9IxpjFwJ2ZDL89w9Fh3LjXr63S1UAsc/rubBPqLA4+DXiBO78kT39+zM/HjSDFzM4FXyfhWSMsDhMOO2FtGEMqxCdxhBevamkitnTIgQeOFYVm5tWCZ0RLVl90= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785402713; c=relaxed/simple; bh=k8MrRN1zHzHirQ+riz3nZa56KdQtvZYEXwt1G83rtDE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dE/6+cLWZolfJP3CBpKPAbZuP0gdWr+6tm5m6cUw1q/lxEezaXX+JuliXcG1XqwMz55ZGkrdet5zzckSK0D6zoBDK60PV1JOhKGoen6GuZYnnlZ9vPtPs023yA7MIq/ftqjrjvqtnozIiXY9QbMarficy2/0wPlJvmn5mckusEg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=IHIeMxyF; arc=none smtp.client-ip=209.85.128.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IHIeMxyF" Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-493fa6e28a7so20387255e9.1 for ; Thu, 30 Jul 2026 02:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785402710; x=1786007510; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=rzY0lsTJjXWVanRyLSlFEy2hFBQ+8J2ffhaSCqEExvg=; b=IHIeMxyF5u1AZE2s8jUE+Ln1kKL7i7rkbTGIXhN6g/NFUfs2w7eADI9F/5Yk7d4dKn VAUsmDXal1lUsA3RdwLN8HeYYtW2T8YPPEDfagZdwNm4GyoTfbkkldzed24tDxFyRIsF QkN4GLs5lLqnMtxybXSd0W5RNqUkY6rEuPOIR4I+2IwuWl6aUNXm9gqd2ip1qmm2jANE rZDymTMhmpFEyZW7b07hkS95xjRHnQ3ab4PMtd2ZGaqGucR8I5qHykdSSf8SGfMq/QjV 6N0NYPv6JbZMs7ax/aDBrxfpShBBZBcL6ypdbD7k/5izQpCYatR9q6KpDyCdVxLz++SI Tp9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785402710; x=1786007510; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=rzY0lsTJjXWVanRyLSlFEy2hFBQ+8J2ffhaSCqEExvg=; b=f2eGFsTiwjq26XWFAzWPSs8minXeHGcVouo0fAjgWlMut0CJuzfmuckMHnWmMw0K6y HerKVDBNWUlZOiOLvioaXMV/cKY7bzJOs9kooX094aNt+5a7KGp8e32O3O6pH+l2l4Er +uwA4yf5sWr2XmAoXPeEUhYKmeU4NHITOr73eaiSJPnRbptyAeqCJdenJOs2RABiU2WT IOODefsPodUR0o1WOQlbr6ySBD+fAZUwFg1N+oopB6n7iZakO4Ak1MuAACp1GYi8k6p0 gbz/Em8ekKIpoh1Hvw8r8FLEYfsnuuOdCkCJG1Zo7pHEgbP4uNl9pNbJQfBIeMFV2ZIE 8WAA== X-Forwarded-Encrypted: i=1; AHgh+RqFMREauDe6+8cTKOpg8HU/5FeUnzl13Yj1wlWxXU6DjSjC3Oo04o4agBBvsP2XVCd4wtj6yyAtnVWYe3g=@vger.kernel.org X-Gm-Message-State: AOJu0YyU8W0cCxzRRT/HuqIQlwN+XmGfbUB4z7CX9qKhSNb30uYojhzD CGR4AkzusHnRrcO2tiZYQOGMN2g+8/e6YgMepv6lJRUk8KCd3VENaeUYBmK5rh5OSU0Hlw7/OMF H0jXfaInbvDV+dz5+6A== X-Received: from wmbhn27.prod.google.com ([2002:a05:600c:a39b:b0:495:5edc:795b]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1505:b0:495:4df2:b8c1 with SMTP id 5b1f17b1804b1-49800ebbf5dmr13261205e9.35.1785402709283; Thu, 30 Jul 2026 02:11:49 -0700 (PDT) Date: Thu, 30 Jul 2026 09:11:47 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260722-setonce-populate-v1-0-fa7455c26c42@google.com> <20260722-setonce-populate-v1-2-fa7455c26c42@google.com> Message-ID: Subject: Re: [PATCH 2/3] rust: sync: add SetOnce::try_get_or_populate() From: Alice Ryhl To: Alexandre Courbot Cc: Boqun Feng , Gary Guo , Lyude Paul , Daniel Almeida , "Onur =?utf-8?B?w5Z6a2Fu?=" , Greg Kroah-Hartman , Carlos Llamas , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Miguel Ojeda , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Tamir Duberstein , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="utf-8" On Wed, Jul 29, 2026 at 11:05:55PM +0900, Alexandre Courbot wrote: > On Wed Jul 22, 2026 at 6:16 PM JST, Alice Ryhl wrote: > > + where > > + B: lock::Backend, > > + F: FnOnce() -> Result, > > + { > > + if let Some(value) = self.as_ref() { > > + return Ok(value); > > + } > > + > > + let mut to_insert = f()?; > > This means that `f` can run more than once for a given `SetOnce`, which > can lead to problems depending on `f`'s' side-effects. > > In the GEM shmem case, we would create a second `SGTableMap`, and since > `SGTableMap` assumes it is the sole owner, the last instance to drop > would create a use-after-free. > > Now this sounds more like a problem with `SGTableMap`, but if we cannot > avoid calling `f` at least twice then I think it would help if this was > documented. Hmm ... this is the behavior I want in Binder. Actually creating the value is an allocation, but my lock is a spinlock so I cannot invoke f() under the lock. This means that each caller will make their own allocation, and then we throw away any extras if there are concurrent callers. If GEM shmem wants f() invoked under the lock, then that's just a different operation than the one Binder wants. Do you think we should add both? Alice