Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp475916lql; Mon, 11 Mar 2024 08:10:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU/SxNLpkei0XyZ+K8nQsTKnN/EKzTt2ToVIGgabDRhWkTpRHrgijMxm7P7hwlBs/QjboawfhYTD/uCQbl1Bvh43rnHX6uWhi2Qgchk6Q== X-Google-Smtp-Source: AGHT+IFa0w4MPDfa0LfTippjXzxwSVr8jcBXDEtm/JHYryLadAbSvlv0xytYJyrQLOQsZHc0hKBq X-Received: by 2002:a17:902:eccc:b0:1dd:96c1:6ff0 with SMTP id a12-20020a170902eccc00b001dd96c16ff0mr5419560plh.18.1710169834044; Mon, 11 Mar 2024 08:10:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710169834; cv=pass; d=google.com; s=arc-20160816; b=kRi/ubQWCwfXbg6SKmYqehieBo0heVvnnkWRmp9pKXSt7Arz3S/7qZYzJeI/A376mU +3u9UEdl4FuJ5ZcLNlqIb1jNJg7Oq6t4mjSttA3wTig0HkpqcyUTokKAuy+UTmeTQD3O 2iksbCh09h6OHv+IkYM8IVT+1IPc7jRjHmrx/nsW0chA55TlvmVCyZucuR2m5A8Ppth3 G1Uxj5r5VuXxRciVTG5HTyRlDx/siOB/QyzBCxQPDlOgvqNE+Yn+gBqBx5qUWrKP01xG 91wLKNkirZ3CRpPOzxZ8/1uDIlbfG2tbjCbKB7svVHvBWWYsenAHWUjzPbATJ3cdCRai NNDA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=zjHIIFeLLaVTxCN34fAudxAbK5EtaRui6gv1zvCRSVE=; fh=sUkmEM0f4r3oKclGKZ33P8W7UrrFlDDKJcB1gXqwwfI=; b=OOB8BmKmW/H03GUGmEP4ePLaQjxzVVhg0+B3hRSFIEkZZ0oGewWrZeuLy0em7BpXLA lrIa9sMaLBSTk9k2F9rrd1GxGhSCBoCGlp0drgLqg3qeMxY5W0KK1450wSoyw8iVqT0W WRh5Y4uixGiI4CYAmwMyZVnk+/LAbOhQGFFi0Ce5a9M71nQKglaFHB0sNVZvDs+tbPr8 JnSsBNlSROHwgewWflYpCLvrNrsfpGmZWp+MkFA4K7asYDJvr5KVdZdgG/0rjnBHqMwu q603QoNTIpjVUo2c8xk/lqayIeM9qzGJ7mibjUkNwZmn7Lx8A9AFnJOFE0UcK9KcXlKF S5OQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b="ASD/9UEH"; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-99044-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99044-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q3-20020a170902eb8300b001dc30f26867si5005052plg.27.2024.03.11.08.10.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 08:10:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99044-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b="ASD/9UEH"; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-99044-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99044-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 69569B234EE for ; Mon, 11 Mar 2024 15:05:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7367F446D1; Mon, 11 Mar 2024 15:04:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="ASD/9UEH" Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) (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 C08D743ADC; Mon, 11 Mar 2024 15:04:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.77.79.158 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710169493; cv=none; b=TI28fP1zwh2WyJL8DL6sRLB/k2hGNVJZBzby71xGbR/qhVvrcKu3FMFJ+DmyPiVYGhrFX7Pntmm0+qOtxpv3KYb94YM0KLfjqQlaVkPB5HSjh80L56IxokIEqDiqQ281C11guOPfG1kSYwswxeOT6FrJ5a0GDIMBUwb7GC11FUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710169493; c=relaxed/simple; bh=rPsgfa/jUXlF5r6wmYl3H5nz8wyQaYnNMQgu78ADxjY=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=X2ZHBsRdQKr/go3n2EeCz2fMaXebqElBDm2VOKL3ruiqQjDsQAePBLwIPAmb04v905wlY3VievaZw2NEVS6MwWQo4rMXTJzLktPCI8YAGKkJNnp6NQ41691774bsjW8SKhvtYCJ89m9MzymsQQ3w/R6Wws08a4Z0WFMjTLqMcF4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=ASD/9UEH; arc=none smtp.client-ip=51.77.79.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1710169474; x=1710428674; bh=zjHIIFeLLaVTxCN34fAudxAbK5EtaRui6gv1zvCRSVE=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=ASD/9UEHSWfJcYBolLhibajFVC0F4Uk5qIEsPLr3kEt2RCOrn0Dsw4+i4tRef80C6 7lHJ5QvzmZ5MpEpCYcysss5Y5gkTFTSaOiWnBnw9h2J12pQzED1VHD9uqElt4UqJnz R39eB//CrgwG6rtC9ioQBCYV7btwXkenDmM7+TgBSjQZKdQsCNQ4xYeSaPKy4mhvrQ dgJbrARDXxaL5OHGCTYFlPgwQZj7Bal+TUkod6LphVpgkXHAxTDTYC4IZCkb1XzkyE 5XG3WrwsHZPe3Br3W45KJ/rJn2nKLr9e+wh5D4QaZGF1i2RBepxwU7hP1rrUGktWM7 YS7l2ZJ1vpPPQ== Date: Mon, 11 Mar 2024 15:04:27 +0000 To: Alice Ryhl From: Benno Lossin Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] rust: sync: add `ArcBorrow::from_raw` Message-ID: <4aef25d7-5135-4444-a461-fdef02f969e0@proton.me> In-Reply-To: References: <20240228-arc-for-list-v2-0-ae93201426b4@google.com> <20240228-arc-for-list-v2-1-ae93201426b4@google.com> Feedback-ID: 71780778:user:proton 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=utf-8 Content-Transfer-Encoding: quoted-printable On 3/11/24 09:58, Alice Ryhl wrote: > On Sat, Mar 9, 2024 at 1:56=E2=80=AFPM Benno Lossin wrote: >>> + /// Creates an [`ArcBorrow`] to an [`Arc`] that has previously bee= n deconstructed with >>> + /// [`Arc::into_raw`]. >>> + /// >>> + /// # Safety >>> + /// >>> + /// * The provided pointer must originate from a call to [`Arc::in= to_raw`]. >>> + /// * For the duration of the lifetime annotated on this `ArcBorro= w`, the reference count must >>> + /// not hit zero. >>> + /// * For the duration of the lifetime annotated on this `ArcBorro= w`, there must not be a >>> + /// [`UniqueArc`] reference to this value. >> >> I am a bit confused, this feels to me like it should be guaranteed by >> `UniqueArc` and not by this function. Currently there is not even a way >> of getting a `*const T` from a `UniqueArc`. >> So I think we can remove this requirement and instead have the >> requirement for creating `UniqueArc` that not only the refcount is >> exactly 1, but also that no `ArcBorrow` exists. >=20 > If you combine this with `into_unique_or_drop` that is introduced in > the next patch of this series, then you could perform these > operations: >=20 > * Arc::into_raw > * ArcBorrow::from_raw > * Arc::from_raw > * Arc::into_unique_or_drop > * And then use the ArcBorrow >=20 > If we drop the final safety requirement from `ArcBorrow::from_raw`, > then the above would be allowed. The refcount does not hit zero at any > point during these operations. The only unsafe functions are > Arc::into_raw, Arc::from_raw, and ArcBorrow::from_raw, so this safety > requirement must go on one of them. It seems to me that, out of these, > ArcBorrow::from_raw is the most appropriate choice. >=20 > Thoughts? I see, it is a bit unfortunate that we have to put the constraint onto `ArcBorrow::from_raw`, but I also do not see a better place. Thus: Reviewed-by: Benno Lossin --=20 Cheers, Benno