Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1282277lqp; Mon, 15 Apr 2024 01:11:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUuqCWpgvjhbVWjDCq7fS1E2H819WQ5CvylrR1QatKi5MQ2z6KaTAeF1dI44uReibvn1UIIy/XH7ycnNM46YFwCiqM9MPZ1gTob9LTsog== X-Google-Smtp-Source: AGHT+IFqh/0IpOEnbipdmpLQShJQw9KiGb0mBVSH+gasvZiNVT6QcyCbRh5eGTYqwwfHPZ+UIVOh X-Received: by 2002:a05:6122:308a:b0:4c7:7407:e8ab with SMTP id cd10-20020a056122308a00b004c77407e8abmr5543862vkb.12.1713168680573; Mon, 15 Apr 2024 01:11:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713168680; cv=pass; d=google.com; s=arc-20160816; b=tGeMYNtyM9MoPk/QQQoObODbuR6Dtv30/drmgSXf4hb3uAcT3JShNUsTtVJ48CC5S1 Km/Nh0riWABbz05xpQk9gXbM6pq1xcrOo5rwLS27HTu4Il+jg24qT2+c8OpDWAr2hA2q E169NRMUAkUDjUcVFi27tqH+8To4elSkyb5QuDBzfQuV4U5FLhx+Mzk7+oDY+ybhTIYb AK3oNUau4mpsD33e/JPDux/H43DHZUD0UsmBKuWeZXJnCs4Als5s07BOrPnKG/syaJ5m B2S7TBCYaVEKlIVN8LH6dQjvoax67J3UH3QH+7jn5nkRJghc8VH4gxG4fnPiksyFoU71 7gCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:user-agent:references:in-reply-to:subject:cc:to :from:dkim-signature; bh=zv5YTVuVpK0uEb+PQ488dEDxv7U+R1SjCDPDwfMdrbU=; fh=u7StqPAtFcuvqL5TvB0qvHrpIyieHCPrUYT/qhQ6yoA=; b=pi0LDAAnpSl+uFUqqD2jvmqZ/Las58BTXY76oh+EOuJ67YPzl5k0L6Mi5Oj3U31xX3 GLxxygGANmnOfAzsmJE8ZsEZb8pJ5xMEXTViOLpPL03FkFETqmIucptV9jbth2eZtoaU hm2nBlfp3CnljIPXPI+d2rcmNRURn7R6xpydwal7cbgK11NFo0P3zRUPqDr2JFRv8Jpp e4Cn/RWXPhoa5qyV7kXiewFMad3pdEPhR1w+1unFk8HNwDb8JbC0s7SO88a8eNycURWi QK8YFZ3u7ii2rQGbw4yo/Omvv3DcFD+SbBfTOPBW+y0dA3uSgdq+IJTFTTzDJbScTnVS jNRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@metaspace-dk.20230601.gappssmtp.com header.s=20230601 header.b=b+yWIR7q; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-144730-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144730-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v8-20020a05622a130800b00432f64d44fcsi9946160qtk.137.2024.04.15.01.11.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 01:11:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144730-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20230601.gappssmtp.com header.s=20230601 header.b=b+yWIR7q; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-144730-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144730-linux.lists.archive=gmail.com@vger.kernel.org" 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id CCA591C237F4 for ; Mon, 15 Apr 2024 08:11:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B26172C6B7; Mon, 15 Apr 2024 08:11:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=metaspace-dk.20230601.gappssmtp.com header.i=@metaspace-dk.20230601.gappssmtp.com header.b="b+yWIR7q" Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 D01B72E636 for ; Mon, 15 Apr 2024 08:11:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713168665; cv=none; b=i7x6+s2JR2JqEhrKQ5tllC6heqbalUIlKYhWPH1oO4CVDphLslBvVnkyA/Cqo8f3++/uR+/Qhs3RZV9CXZ/F8+J09V588dDdM47HlZ7EZ1FGvE8TxN6HOz7XjccAstNtXmmpyRqEnzgw8jq351uHWi97RD4OxPC+zHeg7VUbLxc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713168665; c=relaxed/simple; bh=zv5YTVuVpK0uEb+PQ488dEDxv7U+R1SjCDPDwfMdrbU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=m30QnEmEVp4wBspukxaxmtQdhOR/QNwCi7chIK0Ixuvx6aaxBeCqMMPZjKHJ+S1xZQ4Nl1J9PKg/GBIaJAH00F9FQ6Ci/NkDXhplv8xMqBB+5n2qkscvKLR4/6JejnffDmkOC+nKAyx9330ZRDES/9MaIaAgtaQkaV9y1Ku5D/g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=metaspace.dk; spf=none smtp.mailfrom=metaspace.dk; dkim=pass (2048-bit key) header.d=metaspace-dk.20230601.gappssmtp.com header.i=@metaspace-dk.20230601.gappssmtp.com header.b=b+yWIR7q; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=metaspace.dk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=metaspace.dk Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a523524e5baso328932266b.3 for ; Mon, 15 Apr 2024 01:11:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20230601.gappssmtp.com; s=20230601; t=1713168662; x=1713773462; darn=vger.kernel.org; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=zv5YTVuVpK0uEb+PQ488dEDxv7U+R1SjCDPDwfMdrbU=; b=b+yWIR7qrhztk9PDFeg4HD0WDU8cpOkhXfWO2X+7AW+IgjUBmLXYTm/RwDZIo6K781 gkkpr+YclzYNsspFgE+ySapVkstXCcdvr3FScTjdapvNroko9huhSy8qeekJ0GtCa0b/ F5pRiXN9jwNeQZWcK4LrMegomBVa1VGXfSPTawx6P/8nOS5fTTyp+FFSjNx7bL4TRAG2 WJzrVzBUnc8Ogy2zJgyI+Hsj/BnfBJ7Vd4tYebmjSkSn28yP6pPZMzwup28JgqP96sRZ 4nipp1bGEIL+VjU4PTMu0q/4cZq7g3xC5kTDD5GIwCQ6KGkbmkdM6HXOUgURHSbfLCkB BCJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713168662; x=1713773462; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zv5YTVuVpK0uEb+PQ488dEDxv7U+R1SjCDPDwfMdrbU=; b=qCTseQwM8Wu+B6xqseBOGMMNZrDcE3mDa6SXo3K8n+wNKg88l6V2dWenYx92+2dhKz TDXwFHKdtaPZjyeW7lRNzt4sr0QShjkCYpbmXpjP9EWXaLaij1+PmKwMvPqLOO6aIsPh RsQd+WBuMLHt2v+y40NCLlJIWsPs7PD2WifdY2F9PiU+adzzk2yjSlDcGzO3luwCeNTa WbVG40tdPtNhJ/4CpzkQeiwwjPTetlZk76do/F+8zZ2rzi+q8SIiqHo+5RGTDKnR3V2K 0fKkgiSFtfjgelkJtcdTKUUtE7QY7VigvRpAF8ht3z7IK1X6TrjB9Li6eie5uTWrSVIE 0EjQ== X-Forwarded-Encrypted: i=1; AJvYcCWhLycODZsq6PM+oyzsg7KbDFSNm8t5/U91aeiu4DCj0Y0JmbnsF4wcujcOWyL/z5/a8UEQfsFKLcIO/oI3HumELQ7ZPDXuS/r7zMB7 X-Gm-Message-State: AOJu0YzXDOv5JP59H1IVkNTpHWnoeqk24fJw8DKr8mItqh7BrhAoNe8v e/CT1nRAqOBNnpITA6NmZtEVgVUvnHxP4z5m0xa6NWZakCMZyBON4PeUYFPGMsw= X-Received: by 2002:a17:906:590b:b0:a52:42ee:4e10 with SMTP id h11-20020a170906590b00b00a5242ee4e10mr5567894ejq.8.1713168661716; Mon, 15 Apr 2024 01:11:01 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id 15-20020a170906300f00b00a521e5856f6sm5122991ejz.51.2024.04.15.01.11.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 01:11:01 -0700 (PDT) From: Andreas Hindborg To: Alice Ryhl Cc: Miguel Ojeda , Matthew Wilcox , Al Viro , Andrew Morton , Kees Cook , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , 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 Subject: Re: [PATCH v5 4/4] rust: add abstraction for `struct page` In-Reply-To: <20240415-alice-mm-v5-4-6f55e4d8ef51@google.com> (Alice Ryhl's message of "Mon, 15 Apr 2024 07:13:56 +0000") References: <20240415-alice-mm-v5-0-6f55e4d8ef51@google.com> <20240415-alice-mm-v5-4-6f55e4d8ef51@google.com> User-Agent: mu4e 1.12.2; emacs 29.3 Date: Mon, 15 Apr 2024 10:10:48 +0200 Message-ID: <87il0jm4fr.fsf@metaspace.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Alice Ryhl writes: > Adds a new struct called `Page` that wraps a pointer to `struct page`. > This struct is assumed to hold ownership over the page, so that Rust > code can allocate and manage pages directly. > > The page type has various methods for reading and writing into the page. > These methods will temporarily map the page to allow the operation. All > of these methods use a helper that takes an offset and length, performs > bounds checks, and returns a pointer to the given offset in the page. > > This patch only adds support for pages of order zero, as that is all > Rust Binder needs. However, it is written to make it easy to add support > for higher-order pages in the future. To do that, you would add a const > generic parameter to `Page` that specifies the order. Most of the > methods do not need to be adjusted, as the logic for dealing with > mapping multiple pages at once can be isolated to just the > `with_pointer_into_page` method. > > Rust Binder needs to manage pages directly as that is how transactions > are delivered: Each process has an mmap'd region for incoming > transactions. When an incoming transaction arrives, the Binder driver > will choose a region in the mmap, allocate and map the relevant pages > manually, and copy the incoming transaction directly into the page. This > architecture allows the driver to copy transactions directly from the > address space of one process to another, without an intermediate copy > to a kernel buffer. > > This code is based on Wedson's page abstractions from the old rust > branch, but it has been modified by Alice by removing the incomplete > support for higher-order pages, by introducing the `with_*` helpers > to consolidate the bounds checking logic into a single place, and by > introducing gfp flags. > > Co-developed-by: Wedson Almeida Filho > Signed-off-by: Wedson Almeida Filho > Signed-off-by: Alice Ryhl > --- Reviewed-by: Andreas Hindborg