Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2350561rdb; Mon, 12 Feb 2024 01:37:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHue8xMA1gwwiVIa8Alqep2n7rmDXFay9FEtMDLbDabZS1OGUdS8toFkhLS0Za4SM24oe0Q X-Received: by 2002:a17:907:1183:b0:a3c:5e3:ad19 with SMTP id uz3-20020a170907118300b00a3c05e3ad19mr3980861ejb.57.1707730659567; Mon, 12 Feb 2024 01:37:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707730659; cv=pass; d=google.com; s=arc-20160816; b=IzhmwRg6UPUNMH7w1mzXxdHdicBphTCxWd8O5S/kyHk3R0eVSVr7ixmCW59bi95aMj WBsxaj7JhXOYPnfG8oeFKfe9c0Bw0aX4TZQwJHjLE2JgdMMFWp9/b9mWfQmydapPbx4I QfCrcqN9xvGg5SsVBRRaKHFqny1lwjFBUFkdXao6zgcR6zew9jnqxPYKRyI5M2Q5tKWc ltCWrFyQciYNRnKoNeE8LaMqfKke4JOTp+8vWdc6mLPqvcMAOoovZWeOGUqyxFwfpqzs Ooe8BpG8WoDQVervBQy6MzI/8PQwEJz20KE1xsV2LUYCrhq9IepR3UhL94RYojVP1eBb XWUQ== 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=H/E+m/HmOf8NYGXW5jPmBKlZJMmDwZLc9BuYGu83i6s=; fh=L6QXnGWOF/GRiunFXFZdJxgs/14Qx+m4wR3py7t6h9I=; b=r0McBc3v/1aTMQtfE2XpV721+GwwP7MI9smpmkOAPlxA4eIL+Dmalj8V4Es1WEj1iK 9v5lkgF1grQIgORoXfsCmQDp0ND96cwxE23HQgL/ALuvzhfgNQbVuBDDMckWd9mhJseo QhPyah+61rDowZTqC5nefTLezMIzqMXUDUuGWnqasKrsFK6YwtF027RivF7igImtDgOx YiHc7tfv3lIQDpWUmG2PgKZZ2ewp+q5ulndn3kiQ0Xic1f1l/FsxRCvwHB5btF5P2BiZ jZEIJ+onodNDJUueYOZwpK9P0lataRdKvD9nGZAD/cnRv1p5GiJuHrYL8lxMr7tAaSQ2 z2Yg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=u1XttLTI; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-61251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61251-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCW3Ihh7dgJVDLP3cLE8gXL56lHzn1VRgOxBrx6WiTFr6L0GJIFqYrYiY79x7LKbOh4TTTOkvYuQhJOPwEeHRzLeqXKDxf2StECCkdp7Kw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id k6-20020a170906578600b00a3be3b27d0dsi14791ejq.499.2024.02.12.01.37.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 01:37:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=u1XttLTI; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-61251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61251-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1FA8B1F234BB for ; Mon, 12 Feb 2024 09:37:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33A5317BAB; Mon, 12 Feb 2024 09:37:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="u1XttLTI" Received: from mail-ua1-f50.google.com (mail-ua1-f50.google.com [209.85.222.50]) (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 E7A5312B7E for ; Mon, 12 Feb 2024 09:37:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707730622; cv=none; b=CsAmwJTbXuXpovw15Z210rnd80JuOdU4xZFH+Ke3rrNfQKsdfKxpgXLz1l5W0X7G/THmJ8L4t/t6NdaEjUvCBPPCZn/sDir7lKVgCya5HDpD7CaqvJGKJ9vPmeLg56CsWdSUhNw/6Voy6MOSZcU8SCLaZmI9aSOkM+a4jSaQe5Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707730622; c=relaxed/simple; bh=hNoYuhS9gQug/OX6MY7ORS8ZrUYMnh2ZQxIi4q+85ds=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=MHr7Yo9FQBSN5tqG3grcIPhQJFUKGXwAprErCTN2v3og/lWtR1fPfDnSkGEKvySA1sIyHJMAOHyM8MD7Lp31L9uf3x3+O38kLk98ZESQgNOS/yVCNlvesZA6LxUoXhVvEaRjJFrodj4JyGHlvr2CVK7JrT4//P4gHNu7QrTXQsQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=u1XttLTI; arc=none smtp.client-ip=209.85.222.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ua1-f50.google.com with SMTP id a1e0cc1a2514c-7d2a78c49d1so1527021241.0 for ; Mon, 12 Feb 2024 01:37:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707730620; x=1708335420; 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=H/E+m/HmOf8NYGXW5jPmBKlZJMmDwZLc9BuYGu83i6s=; b=u1XttLTIEHxldQlNaA6c7dcUkf2Fg9YWwYMqQJoG9jOFvYyt7DsbwgzAWdGBIhRY6M LgPdaIg69WxumnBcSYJgaYHhMftnrJr6YlNq0MARyoT/7JohlOBnBk+p5niWYBhOJcrq 9W2e3FoQqqWGOHfdvpf4ASZssQb8z4XmS8lztVv6FRUNNWQT4uTvOWOfC/JPBMtVnba0 XKTNUWGtWACUBPQITgd/VhOUK2YMwuisXNK6QAmjmkZPEHtqMW3zKsXCYst1BAqXa5VB cpQiFmr3tiCNReIYGBNBc5o7mHjv+8FTyPgGvXNlbD0YGiO5AwvtwDsD+iOFiY4oMwKC Ik/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707730620; x=1708335420; 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=H/E+m/HmOf8NYGXW5jPmBKlZJMmDwZLc9BuYGu83i6s=; b=NI8mEb4+I0D2vHYzrgfl7RND01qU8kysFdd7nsM/t08RfBf55UFk5VQ4cRBN8MziIc Ic0TXElfD8JtTZVJIwDZ7gmxe16vGdKw7FALxuCTV5g5Ot+rrcqtWx1h06NiPCNdXpCt Yj9iFeP3GTtMrIzNXubWsaHzeZdGx5AZgM3nqixWLVvKowU+/3j3rep3WwLmQCUq3IA9 UjrkLNm/dGx7GVwX14oDjFwtnWyIZFoTz3eo5Ye7qU+fM7hKagdr3F8y3hWq4qYb41EG no7RTZZhrt7YtYhNYA4KjGcp9eZwqxnTrka/9S8L+fNpNY893v3FNXmIm7G7fEcbvwY2 /eaQ== X-Gm-Message-State: AOJu0YxKHYEh5NMzEgbLspH2qhjmXaMn1tXswxSZZ4++U3DCVGJ014ra SDViRgwcDZat8XwjIrtWj06Jl+Ajsa+uUc7e1veJI/cmQ8+pmoP57i0MLk3vf4K8GTvdGVHwwcC vPw/pD4jpFtKPEZ/y0heW+HEaBStwPTYD9NMI X-Received: by 2002:a05:6102:3709:b0:46d:2b14:db7 with SMTP id s9-20020a056102370900b0046d2b140db7mr4717432vst.4.1707730619799; Mon, 12 Feb 2024 01:36:59 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240208-alice-mm-v2-0-d821250204a6@google.com> <20240208-alice-mm-v2-4-d821250204a6@google.com> In-Reply-To: From: Alice Ryhl Date: Mon, 12 Feb 2024 10:36:48 +0100 Message-ID: Subject: Re: [PATCH v2 4/4] rust: add abstraction for `struct page` To: Martin Rodriguez Reboredo Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Kees Cook , Al Viro , Andrew Morton , Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Arnd Bergmann , linux-mm@kvack.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Christian Brauner Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Feb 10, 2024 at 5:23=E2=80=AFAM Martin Rodriguez Reboredo wrote: > > On 2/8/24 12:47, Alice Ryhl wrote: > > [...] > > + /// Maps the page and reads from it into the given buffer. > > + /// > > + /// This method will perform bounds checks on the page offset. If = `offset .. > > + /// offset+len` goes outside ot the page, then this call returns `= EINVAL`. > > + /// > > + /// # Safety > > + /// > > + /// * Callers must ensure that `dst` is valid for writing `len` by= tes. > > + /// * Callers must ensure that this call does not race with a writ= e to the > > + /// same page that overlaps with this read. > > This safety section says that a call mustn't race with a page that > overlaps this read, hmmmmm. Is there a question here? > > + pub unsafe fn read_raw(&self, dst: *mut u8, offset: usize, len: us= ize) -> Result { > > + self.with_pointer_into_page(offset, len, move |src| { > > + // SAFETY: If `with_pointer_into_page` calls into this clo= sure, then > > + // it has performed a bounds check and guarantees that `sr= c` is > > + // valid for `len` bytes. > > + // > > + // There caller guarantees that there is no data race. > > + unsafe { ptr::copy(src, dst, len) }; > > If `src` and `dst` overlap then wouldn't that be a bad idea? If so then > how about mentioning that callers have to ensure that `dst` does not > overlap with the page that's being read and use > `core::ptr::copy_nonoverlapping` instead, otherwise the doc comment > could mention that `dst` can overlap. I'll use copy_nonoverlapping. Thanks for the suggestion. Alice