From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23B41E65D34 for ; Fri, 22 Nov 2024 08:50:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AACE98D0008; Fri, 22 Nov 2024 03:50:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A37ED8D0007; Fri, 22 Nov 2024 03:50:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B51B8D0008; Fri, 22 Nov 2024 03:50:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 43DEA8D0007 for ; Fri, 22 Nov 2024 03:50:26 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D77D2121503 for ; Fri, 22 Nov 2024 08:50:25 +0000 (UTC) X-FDA: 82813108098.12.0C26450 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf18.hostedemail.com (Postfix) with ESMTP id 067171C0004 for ; Fri, 22 Nov 2024 08:49:59 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=b8xfoGVf; spf=pass (imf18.hostedemail.com: domain of aliceryhl@google.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=aliceryhl@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732265361; h=from:from:sender: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:dkim-signature; bh=w8+9nnoYbf1UxcWWZ8IBCVQZ3ux5jExiFpmdjlIQbp0=; b=q63X2g09+EIszkgcm65RhDegE7DNlZeFc7nqPUcArA+WPAZR89d1Hf3VnayuwfkZDN8zPj fybySHN8GZ1MehFRzQO9WUCMPf7Bu0AS7VaFpOyBXYOaQ76eHS0ODEYwHvCeijf52JysM4 ovFphQ94THpUFIjo/XSD2+iZ3qVlUTg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732265361; a=rsa-sha256; cv=none; b=VE7Q02oU67GY44PharX6/zIMTx+L0BWhoqjV+iheTA3MRq0p05FrnCmS5XaAOomt2u8K9d XiugfuqOPuPqCm3g8C9BD6rR6ocMokNrmNE8OjXtWVmg2l4GjQJ/LUdeqYtpG3H47O+a/V 4tvltBaYTkGCnnji69HW3FRa5zwf43M= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=b8xfoGVf; spf=pass (imf18.hostedemail.com: domain of aliceryhl@google.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=aliceryhl@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2ea568d8216so1576854a91.1 for ; Fri, 22 Nov 2024 00:50:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732265422; x=1732870222; darn=kvack.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=w8+9nnoYbf1UxcWWZ8IBCVQZ3ux5jExiFpmdjlIQbp0=; b=b8xfoGVfNc/k+ETJvhiEvbQq6UyeB7wGjmi1X2n+G7fnVxdxxfLoiixZZ1XELVj9pt Gh5ZIDgo/u6pVKgk37ABJO6d+uktntGHucRJRO+80RKBYPM7b8qN2vuntSZOnRFJ3r7G SKIwmrbZgn0gqvBVc7cImaK3W4El/NaMRtOfQfmXxPR37SaRgOiP4Ktsq63QPOJ2vIgc XRwqXVksOAddEPzrXDXm74q+viiBrGD5SesGXwm+5ezuNQKsMLkIMQDGEYr/CABP96fT bbEWK3tUe2MbQWv4U75/xZQI5u+RMWTzclWNOpNYy73CA/L18oTRZnJKITzoHIGiSLG6 BlYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732265422; x=1732870222; 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=w8+9nnoYbf1UxcWWZ8IBCVQZ3ux5jExiFpmdjlIQbp0=; b=X1UxSIEVmjioCXAiOzvylnF2ExcZIcLX+3mo8m/QktY3pIjMtqoSUC5UDAWgnKxh7t b4RjpBqusn82mxgm20sAfuR8OuHGsGIgBmJ8FeDSW4e9l9Qtmk4NCZZVWjxq0gtAbeHs 97J7U7lDzyxispT2oyuD4fr/HkQSG8Y4sI0S42XnuZRpI7aPs6zh7nctQa3Jel2WTxNb tSU66allV/I7dcCStHlQytGm6joCD/nc6LNOAvnIX/j7Ao579jfr3cV3m3ADEiplR8Gt /3MTu2Ku+3q3DBM52rhdEvQLQj1gfW4Ww/XyNsPqBdFjjklcTsbWkiWx3M7y5UP+yRjd EFKQ== X-Forwarded-Encrypted: i=1; AJvYcCUv/LueTA2Owk99VP4+GPGZQLsa0K1xt6ZFBwwCvrLtjq09UIl255E4ap1KotEXIwSSHq4BbrVytw==@kvack.org X-Gm-Message-State: AOJu0YymntEO9xkiVXsLaLrVQ4OhnDbH+HLp3enHEZHJZJpfiQ88hd9V B5MFA/e1QGvZTHQ9rbcKfcc8r768NoLfPl1VHUM06tlfGHZiFmWZnPerPfa/O7/sDLWqsPwiLnE 9fQperImnN2cDQIa/hVm+jXKRQN8qPTZkt8vL X-Gm-Gg: ASbGncs/drcbXVWmtZ3/5zNoDeNmzlBibq6R1Rb52Lu1P6l9pAQ7msTLROBaBExEexR eHK3j9/XHjuXhrtzU1qe5VIB2fMKliBB7 X-Google-Smtp-Source: AGHT+IERZ9lNFuDAeT7H4I2JX5gC9cNIWkhL8/VD4BkcdPi2aQdqVypnRfvRtA9Uv8ewZgtJ3R72MEjmWswSyzndUqI= X-Received: by 2002:a17:90a:d40b:b0:2ea:5dcf:6f5d with SMTP id 98e67ed59e1d1-2eb0e528054mr2472713a91.16.1732265422368; Fri, 22 Nov 2024 00:50:22 -0800 (PST) MIME-Version: 1.0 References: <20241119112408.779243-1-abdiel.janulgue@gmail.com> <20241119112408.779243-3-abdiel.janulgue@gmail.com> <43a07c04-2985-4999-b6d6-732794906a36@gmail.com> In-Reply-To: From: Alice Ryhl Date: Fri, 22 Nov 2024 09:50:09 +0100 Message-ID: Subject: Re: [PATCH v3 2/2] rust: page: Extend support to existing struct page mappings To: Abdiel Janulgue Cc: Jann Horn , rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Wedson Almeida Filho , Valentin Obst , open list , Andrew Morton , "open list:MEMORY MANAGEMENT" , airlied@redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: cyzawt3bqfq5j4xpthy8qkbiwj8y6myk X-Rspam-User: X-Rspamd-Queue-Id: 067171C0004 X-Rspamd-Server: rspam02 X-HE-Tag: 1732265399-991038 X-HE-Meta: U2FsdGVkX193tXVsJWg8RFf5bkrGx8kI8bwRE1oYiLjAIJ3yZuXLEVBfgKvUCxcmCqxidro+RM4srgpsKF62xVFb8cSpH1o4ccKj45WIZMsV1K01DATaUVeot2sD3eFLIO1bfNOfnkkmmjpDpK8Mydiz/bjqrwLIkpefZ/E5vUOCyYCgtHfxNKkpV2yBey4zUc1hVWI7WRgrRtfSI1yRJ9X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Dw+rcwKeV1OjtmAGaqs2Df/gtcdprCHPqGEiDR8zbw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.002970, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Nov 22, 2024 at 9:36=E2=80=AFAM Abdiel Janulgue wrote: > > On 22/11/2024 09:55, Alice Ryhl wrote: > > On Thu, Nov 21, 2024 at 9:18=E2=80=AFPM Jann Horn wr= ote: > >> > >> On Wed, Nov 20, 2024 at 11:56=E2=80=AFPM Abdiel Janulgue > >> wrote: > >>> On 19/11/2024 19:07, Jann Horn wrote: > >>>>> + pub fn page_slice_to_page<'a>(page: &PageSlice) -> Result<&'a = Self> > >>>> > >>>> Sorry, can you explain to me what the semantics of this are? Does th= is > >>>> create a Page reference that is not lifetime-bound to the PageSlice? > >>> > >>> This creates a Page reference that is tied to the lifetime of the `C > >>> struct page` behind the PageSlice buffer. Basically, it's just a cast > >>> from the struct page pointer and does not own that resource. > >> > >> How is the Page reference tied to the lifetime of the C "struct page"? > >> > >> I asked some Rust experts to explain to me what this method signature > >> expands to, and they added the following to the Rust docs: > >> > >> https://github.com/rust-lang/reference/blob/master/src/lifetime-elisio= n.md > >> ``` > >> fn other_args1<'a>(arg: &str) -> &'a str; // elided > >> fn other_args2<'a, 'b>(arg: &'b str) -> &'a str; // expanded > >> ``` > >> > >> Basically, my understanding is that since you are explicitly > >> specifying that the result should have lifetime 'a, but you are not > >> specifying the lifetime of the parameter, the parameter is given a > >> separate, unrelated lifetime by the compiler? Am I misunderstanding > >> how this works, or is that a typo in the method signature? > > > > No, you are correct. The signature is wrong and lets the caller pick > > any lifetime they want, with no relation to the lifetime of the > > underlying `struct page`. > > But that could be put in the invariant that the PageSlice buffer must > last at least the lifetime `'a`? > > > > > From a C perspective, what are the lifetime requirements of vmalloc_to= _page? > > > > If I'm not mistaken, that should be the lifetime of the vmalloc'd buffer > right? It seems to me that the signature should look like this: fn vmalloc_to_page(vec: &VVec, i: usize) -> &Page This way, by providing the VVec, you can only use it with memory that really comes from a vmalloc call. Alice