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 EB43ED78777 for ; Thu, 21 Nov 2024 14:40:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F47D6B0089; Thu, 21 Nov 2024 09:40:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 77D056B008A; Thu, 21 Nov 2024 09:40:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F6D96B008C; Thu, 21 Nov 2024 09:40:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 391716B0089 for ; Thu, 21 Nov 2024 09:40:01 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E9B7CA1386 for ; Thu, 21 Nov 2024 14:40:00 +0000 (UTC) X-FDA: 82810361298.14.36853FE Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by imf14.hostedemail.com (Postfix) with ESMTP id 31659100012 for ; Thu, 21 Nov 2024 14:38:59 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="dAgBe/Yi"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of aliceryhl@google.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=aliceryhl@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732199931; a=rsa-sha256; cv=none; b=zk8pEZZ0jpTgIGccOXnqTBtY+jIOZwcYxi9/6dLHY4Zs8ha6EHv9M+XlBHVTOWufQXuxsK IKqlldVFs0ImdaWg2nv0lb8mdAdP9gxBktO7c0OW3ICj47l9mDoQvNwlNvDjQe0iQNPNoF dXS8lkhjq44SWM3dPNS1nhvV3MuEw0s= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="dAgBe/Yi"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of aliceryhl@google.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=aliceryhl@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732199931; 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=fRJx2WZ5u5Th7dWmrrUrE1cesu1hkjYpX0gzcJWX5Y4=; b=5ab+GXgiQ6vJ+Q2rFzxBqPkprze9DtZTkbu2dzf2aFUSP02PovGGjfX7t710v49mebK9pe 2LwIVEY7Lc45deGX8i1PyDINqmvzg6dhsAzAZC5ABwqeUYruSwrHXH22+nAlbLulxdVNpc fgT+dQTgHOk4dwI85ybrO+exiTD6lt8= Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3823cf963f1so582800f8f.1 for ; Thu, 21 Nov 2024 06:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732199997; x=1732804797; 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=fRJx2WZ5u5Th7dWmrrUrE1cesu1hkjYpX0gzcJWX5Y4=; b=dAgBe/YiRpBrmzzSOlPwIIPpId3AzJ1h0URhrEmiFBUm3xwnZA4Of1Lyf01aD7iYLj e8uXeNMN8SPvCC6VKV3rG9Nk8UX8aKlemUYu2wpD6Ux+SRlfliizQ5VtRGMjHj+c/Mzg qz5N5qoA6O0IqIzfJe+ziwBnUOk+QiloMeWXJ9W1nPAVFUI3p5EvyFXwAMCqtFMPsC2O ywf8ZOmt/AxbzEZ2wYAkwYz2yZ+jBFnCMpa4pDr8gWl3v0L5F9cJ3PVbT1nUSGQTIFpE htzTtKmEyfLoU6MXCvCHuHaj0UVTkib6XEF62RlqUxWOOvazkBl9d9rZc0dKv08QwzJj WLKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732199997; x=1732804797; 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=fRJx2WZ5u5Th7dWmrrUrE1cesu1hkjYpX0gzcJWX5Y4=; b=bObJkCChmATOCrCoNtfm7YFfid27MhezVaDDzJ3t0C2z2QA5m++ZmM69vi5hr+nfqU Dlbu0UVv7Pxtm+yGDHsPRjwabEJ7HfGhhVE3jfczN0AGn/I15oqyxaDdXbIauCEMFfkV MMH0kpJgKXjOg/RhpLPQbztn61MNivYVEfOs6cOyScnfIlXHChx927qU7uMjrTd0NvPp fsC7iAnVFg6ZDQWqW/3NTCkidREmHpk7tEq8kqZLVYV/uEhb49BNlTqPp0U8KuctDCWP HBUDB4/pkecKiVhww/E9onfLLvqZ/Quir0tER2lU24nqJSFU3Lerpgmt1+J15doaOYhv /bLg== X-Forwarded-Encrypted: i=1; AJvYcCVLqCj320IJsfXNqa7pACMRkXqrGTnLku14y1Uleh0B/+VSCBcNMB1LjjKEzBdh4SFzB4iG0VjSLQ==@kvack.org X-Gm-Message-State: AOJu0Yy/qOyTIdVLMLRfiek5UzVz/OATR5lASC4oCRIyn8h/kjZdRnnx 3KmvvDdycy6q7WO4Tt46b9JYcvxaUfiRRMzpewteGqfWQBcpbPZViQISNzXaanx/wBmLYLWj21c w/UFXciKVrZJ5SEVb467Q025a6YtCPbe3ka4K X-Gm-Gg: ASbGncs9ClelmodahPT96m3kuMTnqOZ6aEh33D/bbyQYhDu3DLSIAvYZzJosw7jUBmH kDz9n1LDHK+GPqSx3EdISafONT0Te+VhpWna8qO4sMEydgwhT4FDUjEEJRbGtXw== X-Google-Smtp-Source: AGHT+IEovcTS4X7zk9GHA36taO4imLGGYuJ2IpetSRs95zNJpNYqDqE1eWMgvsHvtxUKoS5Hl2pXCf075S4vMEjTkXU= X-Received: by 2002:a05:6000:4410:b0:37c:d244:bdb1 with SMTP id ffacd0b85a97d-38254afcb4emr3878408f8f.26.1732199997420; Thu, 21 Nov 2024 06:39:57 -0800 (PST) MIME-Version: 1.0 References: <20241120-vma-v8-0-eb31425da66b@google.com> <20241120-vma-v8-2-eb31425da66b@google.com> In-Reply-To: From: Alice Ryhl Date: Thu, 21 Nov 2024 15:39:45 +0100 Message-ID: Subject: Re: [PATCH v8 2/7] mm: rust: add vm_area_struct methods that require read access To: Lorenzo Stoakes Cc: Miguel Ojeda , Matthew Wilcox , Vlastimil Babka , John Hubbard , "Liam R. Howlett" , Andrew Morton , Greg Kroah-Hartman , Arnd Bergmann , Christian Brauner , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , linux-kernel@vger.kernel.org, linux-mm@kvack.org, rust-for-linux@vger.kernel.org, Andreas Hindborg Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Queue-Id: 31659100012 X-Rspamd-Server: rspam01 X-Stat-Signature: shsytz71drjdmjjhr9m8a4acfzqe6i13 X-HE-Tag: 1732199939-769357 X-HE-Meta: U2FsdGVkX1/+j76Vh0mWyJ3AcilIIPNZ0kt1zJxKkwJ23k7DoCJejwuvjQ7NCWHaTCm1zb8ohGupEjv0fFxpR+xqt5s4ep+veOQehtCHdmdL84hG03nuSA2BQ0boxg1hfyMI9ZlIBuabDdzBeocJE3idMZ39GSRYlDH8TxApkm4hm+yv74oYAlVfh4Sled1I/x/10M3pzYVHk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TU/+gL8Ko93g3gsAS7YRptE/MQfqa++6kKInEKN4jnynleO/+dArXPvPvzm6TanbTridIKzQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000102, 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 Thu, Nov 21, 2024 at 1:50=E2=80=AFPM Lorenzo Stoakes wrote: > > On Thu, Nov 21, 2024 at 11:23:39AM +0100, Alice Ryhl wrote: > > On Wed, Nov 20, 2024 at 8:07=E2=80=AFPM Lorenzo Stoakes > > wrote: > > > > > > On Wed, Nov 20, 2024 at 02:49:56PM +0000, Alice Ryhl wrote: > > > > + #[inline] > > > > + pub fn end(&self) -> usize { > > > > + // SAFETY: By the type invariants, the caller holds at lea= st the mmap read lock, so this > > > > + // access is not a data race. > > > > + unsafe { (*self.as_ptr()).__bindgen_anon_1.__bindgen_anon_= 1.vm_end as _ } > > > > + } > > > > + > > > > + /// Unmap pages in the given page range. > > > > > > This needs some more description, as 'unmapping' pages is unfortunate= ly an > > > overloaded term in the kernel and this very much might confuse people= as > > > opposed to e.g. munmap()'ing a range. > > > > > > I'd say something like 'clear page table mappings for the range at th= e leaf > > > level, leaving all other page tables intact, freeing any memory refer= enced > > > by the VMA in this range (anonymous memory is completely freed, file-= backed > > > memory has its reference count on page cache folio's dropped, any dir= ty > > > data will still be written back to disk as usual)'. > > > > Sure, will add that to the docs. > > Thanks, I assume you mean this comment, which will form part of the docs?= As > here we should at least replace the 'unmap' with 'zap' to avoid confusion > vs. munmap(). Yes. Comments with three slashes are rendered in the html documentation. > > > > + #[inline] > > > > + pub fn zap_page_range_single(&self, address: usize, size: usiz= e) { > > > > + // SAFETY: By the type invariants, the caller has read acc= ess to this VMA, which is > > > > + // sufficient for this method call. This method has no req= uirements on the vma flags. Any > > > > + // value of `address` and `size` is allowed. > > > > + unsafe { > > > > + bindings::zap_page_range_single( > > > > > > Hm weirdly I see this in rust/bindings/bindings_generated.rs but not = in > > > rust/helpers/mm.c is this intended? > > > > > > Is this meant to be generated _from_ somewhere? Is something missing = for > > > that? > > > > The bindings_generated.rs file is generated at built-time from C > > headers. The zap_page_range_single is a real function, not a fake > > static inline header-only function, so bindgen is able to generate it > > without anything in rust/helpers. > > > > > > + self.as_ptr(), > > > > + address as _, > > > > + size as _, > > > > + core::ptr::null_mut(), > > > > + ) > > > > + }; > > > > + } > > > > +} > > > > + > > > > +/// The integer type used for vma flags. > > > > +#[doc(inline)] > > > > +pub use bindings::vm_flags_t; > > > > > > Where do you declare this type? > > > > It's declared in include/linux/mm_types.h > > I meant from a rust perspective, but I guess bindgen handles this? Yes, anything in `bindings::` is output from bindgen based on C headers. Alice