From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 C773A2C6B7 for ; Mon, 15 Apr 2024 08:11:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713168665; cv=none; b=Hmc/bd7R+ZYR6zMj6mrncHzSYxmj3xVThatKz6lad8GVQlCZaapt2Zy5JKFDXb8uZwrPEdQqmFgU6VBzL9zWE6AWkPyCn0Ut12nK81a1tnOQCokXaVxI8Fz2qVhbaLNCA02jn091FQMVYgr3HQh801seSXhlsUh+KmUr+6x31DU= 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.42 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 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: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a5200202c1bso355849966b.0 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=nHyuw3MLejBIGWoOfueIeQUjXgi0hPEn9bugJH65YMKxKug4N78447m8C+lDAk3xez JYCRXpQ7isGDj1yIJPIY2TiPL6EPpLPSlGnuLed+NAYk1AWe0mqpTafRA7YV/+Asx1vT 3xsU8W+WJpnHHF89Z3mzcShWjqjh1Mec07fIMcw21iWboJpORN3dbtto0IxYxrOCbuct PQsYZ6lve7jruBUoGxGd87m6sTNlv+9wbCoZHMK0g5w/MoVoWIIOBUvYrRGhPw4cC31+ UEJOialATM+k5w+EAl+U5P6M8YiZ/wP2ZMqbhVNCiuNNAoILAQl4OpOpSMzL6fBsRZDm 4ZWg== X-Forwarded-Encrypted: i=1; AJvYcCUo8SFV0nW9E1qzGTAwuj2+5i1Y+s5ixH4K9vd7OSmfc4BuLoBcqg6YKN/vxnK1igtR6OV71+prfAiwtpBL+vSPtp7UBpIf8vUXf7+bN54= X-Gm-Message-State: AOJu0Ywn8QPfpnIxWsdCBAYrs2bKebJy15ww5NbAHYJAXmhNVAnsVhJH wRtevpVHqBMK1Wz3Q2AIRgGuDvaSYHyo56F4GUgfm/z9Wyu24Tl62/PCiFzni2M= X-Google-Smtp-Source: AGHT+IEmro/z4RIN6GSVHudfugd2GkdsT2hNxezDpNHADO1XqkCrWaYgEi/s3syKd6RfY4DayBQjlA== 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: rust-for-linux@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