Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp580171rdb; Thu, 15 Feb 2024 08:51:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWVXLNQ2h5hYbc0g608KtkxVXcGzP/54CVt7Jc4XengdVjHGff1HNKoEmdpIHb9eQoW2mjx4V+q4QdQzjfsEvMJitOqP89/ziFOKUGfZw== X-Google-Smtp-Source: AGHT+IGV2aIAsOTcvdxY+aRA+nOqhYo0qj6eCOnZZOs7I8FVjeeJqRz2mJ6XDpjRuufdoSS0KjIw X-Received: by 2002:a17:902:dac7:b0:1db:499c:9b9e with SMTP id q7-20020a170902dac700b001db499c9b9emr2673852plx.9.1708015884986; Thu, 15 Feb 2024 08:51:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708015884; cv=pass; d=google.com; s=arc-20160816; b=onH5RuqiSOF1H5JRAaFUVPF1dWkQ7QnlIFhpHYra4QPKlvvDki9Q/6ZlYXZdbAbt4E XdXAzsh27rVGRE1t1G/k+YO7aqx8yDCO0FFprXAGLBU5o81mPPdrXcfHYkxfHLHvfOk/ KUCSM60lakI36gArMyxo+1lSQzmcA61i5O6bHdkjStVk0uNbaS5TdTtLEpHXdzFcbaH9 geWqLSYU/zshyl9TXBdh2z6kRAjALwVYRwtlEilZAEe582VWWsjhS2unBop33kGp9K7o GJwSU0AkynWFNBrzqhriVOL8pCAOep0pi2RpGBKU4/oyIimn/ioxhOxCEIga66M/d97t lvig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=PWbTPSA/om6zR+aNxMvSfqC1qzBEfL0EEjQgcRv0csU=; fh=zV8pk2nl5FleHBXd73Un9aRkMfHGIOkFbzUvpzC2JLU=; b=M7HddvghTMrpcR6mqOGJacVnbrPm/tq/2D8Gjm+3d2kljyjp3pEuJ1Zhe+1ifdk9Us 3uUHBF1tFilOuB3XAdG97vaaUdxbV8M7OALRa2oJTNCelm9wYRVHnwKzudl9sMjyuxW7 p0620CA5Ht9cWaRA/oVOCOQnVvBSrjTsOtSgQW7F/29uOiES4IW9QtsbsbY2bN09WL95 Xq+wmLePEe+LikkD1UidxAfmqqTBtXVaE/dJOio2UXIaUOo62HDcOWzlwndckhIGzLQt VIuJslX6SJxnrbZdAw2Iae/ENnv2vn6Z7raSDXic332PkiM3J2UM1mK1zXV0/g8fDLhi ybMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nsCArCfC; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-67328-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67328-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h2-20020a170902f54200b001db78534cbcsi1427022plf.297.2024.02.15.08.51.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 08:51:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67328-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nsCArCfC; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-67328-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67328-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E4FB4285722 for ; Thu, 15 Feb 2024 16:51:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C45813665F; Thu, 15 Feb 2024 16:51:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nsCArCfC" Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) (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 08D8E132C10; Thu, 15 Feb 2024 16:51:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708015869; cv=none; b=k/gjCKjy0xzWu1PMdm0cBkKpnn37kOyjVrhiHmnuXJvRzTRGl3O6wp2NGvYxnve1NFMM2kZlcth1K8zxcp5/B0svAJOaHKB7EthK85lQzXXWv3WXQ5m9rzZ7jX3HddiOp9XT9IvVudox7HsdnRGKckHKvEzWShtPKZJewJrryE0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708015869; c=relaxed/simple; bh=ZTNKs342W8J0RINeS6cyL6H9EKrFTjDnEdCGDzi2b7U=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=fRcIqNPMPVuN+7uJWzPAEIm5sQZypEIDT7eFxplU38T9TUqUyS1JaP2bqlWdBA90bJdOCINapg8WKi8KdCzHE3lspHWOa4F44/D7n8kg1qeDXIxgLRAvqTGSCoNfqmhTA1MJWcapHDDRvRItWvcLsdShs2yBcWYNReJePPOBg2U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nsCArCfC; arc=none smtp.client-ip=209.85.219.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-dcd94fb9e4dso992953276.2; Thu, 15 Feb 2024 08:51:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708015867; x=1708620667; darn=vger.kernel.org; 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=PWbTPSA/om6zR+aNxMvSfqC1qzBEfL0EEjQgcRv0csU=; b=nsCArCfCRBz+o4+rn4OPXKLm7jcGqg+/826nZArCIJ6iUELpUUbf1y4spBn77qK9FO /UMVqedawu9yz0IEafsuVR5jeOdlTcQOgWbqGfL2R7013F+szjFIOtgxS9kXY2462mjb ro1RtJhU9TA63g09HrPm1UN/nlMYsWVHcs0S/kEUTeXUzaXBF3mFiR7Rb7Jco2vY0DIi yDQ/Oi140Wx0hAHu+W9erY4gveEH9HNGoReRX49VlEgze7bdReByDr6resbv0Jwewhrd +dHkQyGvHg5SgjCIvIEZHPYwNfrhtt7VZ2GBTQL3B+o6EDl84HdS6I/v/7e4B8UQ6eie 7TzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708015867; x=1708620667; 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=PWbTPSA/om6zR+aNxMvSfqC1qzBEfL0EEjQgcRv0csU=; b=GQPCK9XM6tZYq/6GAYEcYmvexaR+H+M5FXzJikyx6b3sUSuCXU7+X8crH1Qq4Xuof/ p1YUqhy3odBpkvoN59077F5OjWk2pTo+a+irWdTuKywPRthhmJA9RJikXf7G8bRW8ROm MZde+cAgDqsNAjh2t4/bA3u8ZXzpvPw5lqorRkzcNTppocyLSKEWoK70qGZVZlzdKTAA UBJm7ogjRRLkqJ5BoTvH6mDNHIes1EQEPmLOoy7JGpzZ0pIhto+wYzuby9mMRLb9FVaN t3KkYgm54laJaBrGGh0aS7bPBYJroIxyTge6lBeIyg9lOn0RYcrZcysKnlNOR/6faeNA vCfQ== X-Forwarded-Encrypted: i=1; AJvYcCXg2uQq4XOjppCtN8DCaG1Xhx6YAdzjd+eLY/VWEkUkazNt4VhHfdAgwI5wDYS9DOo23e1dayxxjgrWXUrUEk3Al6IFrKTIKq67MzBI6Z4yCZYRds4cAbPIBOuqORNJ5GeMbx7OqT5Qcq75gI0= X-Gm-Message-State: AOJu0Yy5xcJhSPIQoCYOsb6Tleq9H77J7NqzaIaDmSCogT1QS3oHn7rT Zuf5d0Po9FnwDRNRccsMCIWdViT6XkC55VoriJLv7vDsI2R6HpBeQgBlMhaGPmOtxr5oBGgk3Vp AV5Ixj9LVpDhe815als6HsjaxyW4= X-Received: by 2002:a0d:cc48:0:b0:607:855f:599d with SMTP id o69-20020a0dcc48000000b00607855f599dmr2296378ywd.14.1708015866785; Thu, 15 Feb 2024 08:51:06 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240212-rust-locks-get-mut-v2-1-5ccd34c2b70b@gmail.com> In-Reply-To: From: Wedson Almeida Filho Date: Thu, 15 Feb 2024 13:50:58 -0300 Message-ID: Subject: Re: [PATCH v2] rust: locks: Add `get_mut` method to `Lock` To: Alice Ryhl Cc: mathys35.gasnier@gmail.com, Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Martin Rodriguez Reboredo Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 12 Feb 2024 at 11:22, Alice Ryhl wrote: > > On Mon, Feb 12, 2024 at 3:13=E2=80=AFPM Mathys-Gasnier via B4 Relay > wrote: > > + /// Gets the data contained in the lock > > + /// Having a mutable reference to the lock guarantees that no othe= r threads have access to the lock. > > + /// Making it safe to get a mutable reference to the lock content. > > + pub fn get_mut(&mut self) -> &mut T { > > + self.data.get_mut() > > + } > > It's impossible to call this method. You can never have a mutable > reference to a Linux mutex because we pin our locks. At most, you can > have a Pin<&mut Self>. Perhaps you meant to say that it's impossible to call this method without unsafe blocks? From a `Pin<&mut T>`, we can call `get_unchecked_mut` to get an `&mut T`. This is addressing issue 924 opened by Bj=C3=B6rn some time back. The idea here is that if there's a path where avoiding the lock/unlock calls (which are expensive because of the memory barriers) is performance critical, we can do it as long as we use an unsafe block.