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 263B8C48260 for ; Sat, 10 Feb 2024 04:23:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB93D6B0072; Fri, 9 Feb 2024 23:23:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E68226B0074; Fri, 9 Feb 2024 23:23:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE1EC6B0075; Fri, 9 Feb 2024 23:23:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BA5286B0072 for ; Fri, 9 Feb 2024 23:23:48 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 23236C1164 for ; Sat, 10 Feb 2024 04:23:48 +0000 (UTC) X-FDA: 81774600936.16.DF00300 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf29.hostedemail.com (Postfix) with ESMTP id 2E0BD12000E for ; Sat, 10 Feb 2024 04:23:45 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IVENVm8G; spf=pass (imf29.hostedemail.com: domain of yakoyoku@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=yakoyoku@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707539026; a=rsa-sha256; cv=none; b=IG+o85ICgofY997bQaDsgKSR3+VT27JXcd2s87yq3rjD//I5XpRhKDVucBZn5Nz6G3GkaQ oZyDpH6d+V6lwkNHUQPHqLM9vOs+PYDMeho+Mj98q5IMBwyngEqlTvLAK8XXT+ydEXbeBE qsqb9dy9gh9FdrN7qrn4h7RanDD8tSc= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IVENVm8G; spf=pass (imf29.hostedemail.com: domain of yakoyoku@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=yakoyoku@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707539026; 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=+R0OcFh8QuVvnUOr/SAUhq/IMAFvrwIfBwIQpXf9tlQ=; b=AzZppaIbmRUPn9vMW9KgSxnrit7dYec2uJ4NiKMppNzglrxXdJCCFQcTyWt5Gt6PhmgKrV AeZY0IPqqUyg+FkFfsY/87Q5bHG/GCtrwCRT1PgVoykxv7ZNeJ1OqmW6gHjxhV5AaQq6fc QRTcOESoZp3sneg8FuuJK2iA8l11jII= Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6da4a923b1bso1393040b3a.2 for ; Fri, 09 Feb 2024 20:23:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707539025; x=1708143825; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=+R0OcFh8QuVvnUOr/SAUhq/IMAFvrwIfBwIQpXf9tlQ=; b=IVENVm8GTLlyHQECWC4OX4TOiRn+SPCky/Te36aq8U6dhrzndNBk9P+B5qxKlVjxiV xJx9hOPrvHz2jqTQZnOaczJzRTJvb8P4/88KMMbskbg0ljJZWHy8RGlge91Ks/mP8rj9 NjHOAWGEU9spFeQV0MlAbV1l6NOHtCq2Wuxe3qBsHp/yEoWILcZgcdSmts/cTiaBLEjU f5e4Zt47wWSzTjFWI1J0gkC/Fduu2Xuc0HlfgvewPTkcU/ehRhgEZMCBRMCx9aJIv5rO mfkWyroaM7TxA/h/6Yl4nxJGE1jxN2o4Xzti7833k1uO+ELZU5S4vRE/JSHQwmBSlSiH 8reQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707539025; x=1708143825; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+R0OcFh8QuVvnUOr/SAUhq/IMAFvrwIfBwIQpXf9tlQ=; b=VxgNPQS9eF2W9rDZla3wjJADxOjMCOww8/WGe6KZhUCLVrgP+uVUe6kuJ/Z2xholpE /jdyXwNSVEu5jgXUKaE8oAMEV402RXTTXOZpTe+tvEMmo+zTfKbZ5WTEElqvpOm/I+rV o+Qlqdm9PMkZq0rULFFQC8C6fcrtnCy9cIrBiGoQjgzotybQWbSioXNG/2tX0a+mdftH 7NaMvF5mrzt/Dpv2erLLZw0mi0kY+l1MVgNV63FJsQ8ywRYxBpiVY5mStCo2L2qrq6RH NRsSgyrWtiLULDPqhB1fR0WHVjV+RemInUSw4SpKTv3mpOfHhyhaDd4QI8ZQDuh9P0+I Zfeg== X-Forwarded-Encrypted: i=1; AJvYcCVANOr+IzcWo4HcnW/J2Pp8I+5Z1XVRdSoRiEf+5mvx/tvXQh+btqOb+mDMVbiYyVB39BLmMBYknQhDvOwC1fZw9+8= X-Gm-Message-State: AOJu0YxbDc/JqvST2G8tUkPJAwT4vK4YpOnFQF8OwPNHYc544wysZ6mL DBXw0gAVrgZes7gRGyaXLa9fsrM1psgg+ulBRcHHZYdjrAYY9YYa X-Google-Smtp-Source: AGHT+IHd1Lcc5MMpQyHrDTrH5tqwCgZsd0+wYJ2vs9KNP8mEmdgqizlw3H4odw2sax6sPK1jRbQVMQ== X-Received: by 2002:aa7:86d4:0:b0:6dd:c3fd:45fb with SMTP id h20-20020aa786d4000000b006ddc3fd45fbmr1203330pfo.24.1707539024775; Fri, 09 Feb 2024 20:23:44 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVeHjFnDx6mul6waQi7Lp/LgSfsbqfN5PG95avU746wKv7PVDKFjFtsukaX+mRiLqYgTXbmvOvJFwsjO4i+IMBaKemdCX3ST8dNK8eHW4pQvbYJBBqDVpueN0vQV6s6NbeyiBwCn2Z8gwB4iFOpzNRTIe1HYBmlOVGqRz6pRa6/x9oSEW/RNqn7Nn2hQuk6BKfPCfKSRElcRBaeMgzG2CL7RJnATszXS0sPHIrJqRzS2FDbLfQyKoK9i4AswVpXlCnYDW/6euxGC5hMY+lOb3WFad7wW1u5Q7i3p6G2qOOTP6zcH0mvYLy13w9VHllPhIeO5LrJ0QUTm7SURQpmrLcSyxiBHdKTmDoD6/opgtpTFkuLU2f2K75XBSSJS/qtv8Zti7bkROSf6Duz+yjSm2Vz8cLjbpjCkWfDrrPSPpVd6PiWV6+yEPYPdTtACOfnYKegl5k9rTr9USnNM4BfEI9SXeiRyh+bqqpeeNvvAMxlTse2qTlrui/Vl8yMMPRsFLO9oeFh2ppXV8GJktZ/xEvTnZmh5X1ozaQ53nzZmdGwUHK64+hVjTqhgTBAb+NCiDHctB3937CkEAoTweFrCtMSjAPsN35UFdA2MXgVwbkfwsc069WdLIz0lqrjB3rJEz+1TVQhSc6ILk+bLYC2B3RUNSOCRTZLGNUaZcO7Xsv+MVYVBxpEpCXokGyOsawOoWYp6UBj Received: from [192.168.54.105] (static.220.238.itcsa.net. [190.15.220.238]) by smtp.gmail.com with ESMTPSA id j19-20020a056a00175300b006e0436e08edsm1419682pfc.11.2024.02.09.20.23.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 20:23:44 -0800 (PST) Message-ID: Date: Sat, 10 Feb 2024 01:23:38 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 4/4] rust: add abstraction for `struct page` Content-Language: en-US To: Alice Ryhl , 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 Cc: Greg Kroah-Hartman , =?UTF-8?Q?Arve_Hj=C3=B8nnev=C3=A5g?= , 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 References: <20240208-alice-mm-v2-0-d821250204a6@google.com> <20240208-alice-mm-v2-4-d821250204a6@google.com> From: Martin Rodriguez Reboredo In-Reply-To: <20240208-alice-mm-v2-4-d821250204a6@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2E0BD12000E X-Stat-Signature: 4k5tcrtzo3prakujjeryzhgfeg8oa11r X-Rspam-User: X-HE-Tag: 1707539025-671002 X-HE-Meta: U2FsdGVkX182qUbVQ5uUgaKhKT8VJDWA2+9+dQMPmGvyUwLGxont9gaZKDYQx7maK/GShydaztzDKLO8LossPel11ydKDFdMFWz+JYwoZxX2fEKfie7UO9gru912mLVrz+40ppqjlIeInZj1likxfpGFshHlZxSgbc6cCH32aCAB2zzpHUH9duT++hTnvYXlv5juXdbLQSKEkeXhf36CJIdaVudeB9lBYu/pja5kjaVFq+MUc1opt7tBO3mmYORXXcLCnhVQ+FWOsC3UQd1Cre9ZU+CjNHlCm0DmJ3aMzj0wLl1EXaXQxe87oaiVC1Mi4n9JVC4yagspbeBhXAD2Q0EI7lYa80uey62FdBLrWVFdVFdG/8oCJRrRsuIikrGnJM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ZeYMDsWp+TgY20Y0s1G7wRpNJyYZ2GUZ7f4zPxZjuH5zdoKTxmJnGr3Sr0U527tnQCXT5FnZgvhCyKKZARN12dpSjv1U4H//SLnms4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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 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` bytes. > + /// * Callers must ensure that this call does not race with a write 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. > + pub unsafe fn read_raw(&self, dst: *mut u8, offset: usize, len: usize) -> Result { > + self.with_pointer_into_page(offset, len, move |src| { > + // SAFETY: If `with_pointer_into_page` calls into this closure, then > + // it has performed a bounds check and guarantees that `src` 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. > + Ok(()) > + }) > + } > + > + /// Maps the page and writes into it from 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 `src` is valid for reading `len` bytes. > + /// * Callers must ensure that this call does not race with a read or write > + /// to the same page that overlaps with this write. > + pub unsafe fn write_raw(&self, src: *const u8, offset: usize, len: usize) -> Result { > + self.with_pointer_into_page(offset, len, move |dst| { > + // SAFETY: If `with_pointer_into_page` calls into this closure, then > + // it has performed a bounds check and guarantees that `dst` is > + // valid for `len` bytes. > + // > + // There caller guarantees that there is no data race. > + unsafe { ptr::copy(src, dst, len) }; Same as above > + Ok(()) > + }) > + } > [...]