Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2004705rwl; Thu, 30 Mar 2023 04:52:27 -0700 (PDT) X-Google-Smtp-Source: AKy350a1BVXA0pK5LlLQmhDV2zwsJkR0a5bQeFNqVrMDnuL2FjS5bpBxnbi9VrGZK1R0exPLBjlf X-Received: by 2002:a17:902:868b:b0:1a2:8f6d:8a14 with SMTP id g11-20020a170902868b00b001a28f6d8a14mr1380778plo.5.1680177147389; Thu, 30 Mar 2023 04:52:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680177147; cv=none; d=google.com; s=arc-20160816; b=1Cj1PODUvNzjap9uBqmM961WiXUV5HWMHXmadWOVFeEVhlImKI85NMWGxGHP4yFIRW 1ok3o4Uky6G44FhYvBL7VwnGec5cx8uFWuAXsdU4LP/JQyNIP+P8ustCq/0brf6bl99X cyB6tm4reze9URJ1nTigfoWK4YqslecwbroYHRD0piQFeicmkViQ8GAjJsqlDbhyOV2L SVrLL7KIi+bd9hqTJfJZrD24h4xHbEERezGZx7weCDbe3vZbw4TjpKrYM62rBSPjqOST erO1W+PrWpz648B4yyZ4K+FL0Re5j/fXAVXIZh1vhokqOO9aWrQZQRajkIaWvUX5Ihpa IMXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :dkim-signature:date; bh=dgiu3xs0UtWg8N/CQ9KvytVckw5AYUEZ2ZLbaBlSqBw=; b=HDrFUxEncbGWkDalz8i3fWiW8WS+A9pYfUvxYYPLSw/EH7HLZg9BK2p814ikEcLDCa sTGamlCaJKbZFfPqfS5dtzdOpdDAC8ZnjawBA4Nq1x2fGnFnLbnqBqroqlGWL3SQVyzE 8YwJzyNr7D8z4QjDLpasVUAaENbj59to7l7ahHBkh9wHNIqxIosCLHEXNRVdf4Y/jC64 VWkgEskVl/QQgugwRiiMkCk/OF95Eqmb9wPCgYplX0SanYObOFCm3qMeLdkJiWfPZuiS EmPQ8lxOUf4Ri/2MccEvASZhkcx8qckFJX0IHXLBqhqZLmqHWLXkc1yxHyC9gfducoJw t0ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=YLbF9EOL; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m18-20020a17090b069200b0023cfda36390si3740272pjz.121.2023.03.30.04.52.13; Thu, 30 Mar 2023 04:52:27 -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=@protonmail.com header.s=protonmail3 header.b=YLbF9EOL; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231759AbjC3Lqk (ORCPT + 99 others); Thu, 30 Mar 2023 07:46:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231583AbjC3LqZ (ORCPT ); Thu, 30 Mar 2023 07:46:25 -0400 Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66349B743 for ; Thu, 30 Mar 2023 04:46:00 -0700 (PDT) Date: Thu, 30 Mar 2023 11:45:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680176732; x=1680435932; bh=dgiu3xs0UtWg8N/CQ9KvytVckw5AYUEZ2ZLbaBlSqBw=; 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=YLbF9EOLEIaYnAxBxL9QfwYcOrYZTZBVFjernRYSfgCjRNQIDLkXjUwl5z0TDG7Cp h9x4S33xR597WhxHeWQO2B57KIbpp9lwljVpYixnkrAm6k6I7r1ob7V9oitq7xHF4U cOnjAWZqBwJ/SzOuFViI6ZYTUfU4As5onY4WJGo0tnQUNTWFIJjpamjpfMm6mecSmz pzNJsQmYPR4HlWm8PAjH0N5rSkIDLScgi+5TJb+4g3ZyDREG62WJGW/FQ/uHHGyft1 pGS1u0Us5y4meuxtsj4pfm92P67EIKWwkhmtstmUbBAEQbjM88xJSuTgx1omYaeVK6 cuJni9q0tEUEw== To: Wedson Almeida Filho , rust-for-linux@vger.kernel.org From: Benno Lossin Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , linux-kernel@vger.kernel.org, Wedson Almeida Filho Subject: Re: [PATCH 13/13] rust: sync: introduce `LockedBy` Message-ID: <06a7c5e7-fc5f-3860-7f17-7f3609de669a@protonmail.com> In-Reply-To: <04034640-2d89-dd63-07e5-29fa612aa458@protonmail.com> References: <20230330043954.562237-1-wedsonaf@gmail.com> <20230330043954.562237-13-wedsonaf@gmail.com> <04034640-2d89-dd63-07e5-29fa612aa458@protonmail.com> Feedback-ID: 40624463:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS 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 30.03.23 13:28, Benno Lossin wrote: > What happens if the the protected data `U` is a ZST? Then the address > comparing will not work, since all ZST references have the same address. > For example: > > struct Outer { > mtx: Mutex<()>, > inners: Vec, > } > > struct Inner { > count: LockedBy, > } > > fn evil(inner: &Inner) { > // can create two mutable references at the same time: > let a =3D inner.count.access_mut(&mut ()); > let b =3D inner.count.access_mut(&mut ()); > core::mem::swap(a, b); > } Sorry the example I provided does not actually work, since `&mut ()` refers to a place on the stack. I found a new example that shows ZSTs are still problematic: struct Outer { mtx1: Mutex<()>, mtx2: Mutex<()>, inners: Vec, } struct Inner { count: LockedBy, } fn new_inner(outer: &Outer) -> Inner { Inner { count: LockedBy::new(&outer.mtx1, 0) } } fn evil(outer: &Outer) { let inner =3D outer.inners.get(0).unwrap(); let mut guard1 =3D outer.mtx1.lock(); let mut guard2 =3D outer.mtx2.lock(); =09// The pointee of `guard1` and `guard2` have the same address. let ref1 =3D inner.count.access_mut(&mut *guard1); let ref2 =3D inner.count.access_mut(&mut *guard2); mem::swap(ref1, ref2); } -- Cheers, Benno