From patchwork Tue Oct 15 14:28:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13836565 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 DBE4DD216B3 for ; Tue, 15 Oct 2024 14:28:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E5BE6B007B; Tue, 15 Oct 2024 10:28:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 096546B0082; Tue, 15 Oct 2024 10:28:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA0616B0083; Tue, 15 Oct 2024 10:28:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CBD066B007B for ; Tue, 15 Oct 2024 10:28:49 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B7E94C16A0 for ; Tue, 15 Oct 2024 14:28:39 +0000 (UTC) X-FDA: 82676067642.01.1631AB4 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf18.hostedemail.com (Postfix) with ESMTP id 57E591C000F for ; Tue, 15 Oct 2024 14:28:44 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=i88pICzZ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3HnwOZwkKCI8t41vxAH04z77z4x.v75416DG-553Etv3.7Az@flex--aliceryhl.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3HnwOZwkKCI8t41vxAH04z77z4x.v75416DG-553Etv3.7Az@flex--aliceryhl.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729002370; 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:in-reply-to: references:dkim-signature; bh=XNJeKzAtPjp45SIJ3/kfvuUMRNzvKyffpnVSTmM2Fh0=; b=Svi4GMtMmqWvvH+wW78atgvMi336aHYMcGsR+7wrI91GctmIG59R31c72wLRSIcA+a9uqr 9sNvjYM3yK7VoucJHAEmKgierfVD5I7WJMOO6iMnXmSoBVy/RRdwctZA9lQADcopjnt7m0 WzBiQn/B5jR7JjYkiqs3VhK/BckCOc8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729002370; a=rsa-sha256; cv=none; b=W5Hwo10gOlDQUqaP8iALcPoYJ8akIipqT/2XM2H26K2ouyl/poSl/15iTgYTpq07hKfWBs arx77cWxJERgR4wE8vSwHhr8WnUKnO1mP90tG7+SJzaQWsUaM7PJGpiFcz9glhuouAd0pt 6ng907/DQUs2fm5lSP9P2T+KGydOFFw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=i88pICzZ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3HnwOZwkKCI8t41vxAH04z77z4x.v75416DG-553Etv3.7Az@flex--aliceryhl.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3HnwOZwkKCI8t41vxAH04z77z4x.v75416DG-553Etv3.7Az@flex--aliceryhl.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e290947f6f8so8214575276.2 for ; Tue, 15 Oct 2024 07:28:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729002526; x=1729607326; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=XNJeKzAtPjp45SIJ3/kfvuUMRNzvKyffpnVSTmM2Fh0=; b=i88pICzZUg5MkMqIJvwcY0N8oEoEtOQM1s6eoq7OwrivX6kSUxsfRIZYLruh3IgdwX qWsaxhAZng9TklkowWnnoXooQuw27YZSGd3IdR/Oeg0zzLR8+O8sbpcBVBmml1TNkOp7 kIT48VsODTe7Qc9wXGHEluJkri7dbyoOMBbJg3upHUVOSesBz/bB+UmGQVE1xv/W4JeR BNJ2MkZbps8NizoTb+M5TIxXBh1KHhVGxNrGqMtHwXV7FGgCLzkAAlPhDBfOFb/VkxDg 4IX9CsXmuA5ufGjqXjvKNMJVQlf7pkhaoiOdE4XkObsgBUMGWlcltKvezC/fA866Sopd Gz/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729002526; x=1729607326; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=XNJeKzAtPjp45SIJ3/kfvuUMRNzvKyffpnVSTmM2Fh0=; b=A2JUNK5gYGubh4eSCmr2TwJ4hEzOFVqBQBreKem7H8lKmT9HJ8WAGYzy5MetuOHU91 1lYo4RNqAL5naWXyOv12T2rR/uN31uLiDN1uEsjW+Jmkh/XulcP2JO0F9gcYGV0Se7od LWX4hFwXCS3cYZPgZr9N8uC8iNXMRT4ClNV9XDvfCiq7SDwbTT7brutTJYKzksiCXo8f qo3Rjl2xAXA5Xw3W6Z7qmiJZ/3wFcwjr1T9i2syyUk9MQSuqb7ME7VxVYiUFq0CutzmB e3Cs/jIr0MMMr4oSbSKtcdM/uKgqx0rvjaguuttLTyKnWTJTEWMRYo1dbgsEW2GE7e+n EKUw== X-Forwarded-Encrypted: i=1; AJvYcCU/YFd6tIpSYlLc+ThUgBJKEK9N40/E+wOkgsXranf2hoKQI0IWqjUV+w0oO/wKhSiMPJ9jxXYh9w==@kvack.org X-Gm-Message-State: AOJu0Yw3Pz7rGjBu5Ks+V0fDQmoD8WAitfFoJ5Z05eqBwU5nDF63Zbyb 0E3QwMVs6P/rpzKADfMoC2CMl1kSXXZQphJyI1qSEXEFwZAC1UXchK16A+H894uRwaYyU+vWOlA iH6oe2M8tBvwVMg== X-Google-Smtp-Source: AGHT+IEJsZCQdJgQDK83UiVeL8PodNSP1mZnK7L/+YXxdoFRVd72bLcQ3Ll9Bb0b3OGyiUHdTm+vltTMRxpnJ8A= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:35bd]) (user=aliceryhl job=sendgmr) by 2002:a05:6902:2d08:b0:e28:f6b3:3666 with SMTP id 3f1490d57ef6-e2978567367mr346276.7.1729002526293; Tue, 15 Oct 2024 07:28:46 -0700 (PDT) Date: Tue, 15 Oct 2024 14:28:28 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAAt8DmcC/x2MQQqAIBAAvxJ7TlBRhL4SHcxWWwgThQjEv7d0n IGZDg0rYYNl6lDxoUZ3ZlDzBOH0OaGggxm01EZJZUXx7PxFKQuHNnoTnFU7AgelYqT3n63bGB8 omyDhXAAAAA== X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=1064; i=aliceryhl@google.com; h=from:subject:message-id; bh=t8U1gyWwNSEhj9d9K6BaPBQ0ctfmm7LA5efgRVulxro=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnDnwMVnOv25ulL3mEcQA0kNsek3R1xTz5taYha 5Y1rpWY31+JAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZw58DAAKCRAEWL7uWMY5 RlXgD/4939MppK4B/TGTf4FZZfeJydTXzv8UMnCIqv8aPgKYfnApFk+PbRKDUXzGxTGrpdw5fKG zxA2rh3tCYAMTXueMSZdEFoE8lagpvilyS5Z/cvPQZB3xmh3yTvIjCTlbPG6LPZzHptiGW1RqJC vo54L4y3uiCl4HYLNKGUB3lkzHJHAytQeILBRRWgPtQpZFgQyiNa/cGE3EHPbTqTAOqZXDwo+aF GRql97MJ/xS5HOV4V1miU/Hv0jFDdRphecPH4nDwQ0Ja/d6roUDfpp9MSJwr9MjGfaACh8Nzu8e Rnr4rPSCpdZwokcA7ZbI/NjI/9JMuYg3kqVvt9pTt/g8a1X3HX++F1i9XYfUgkpxcuH6zseKWNc sXl+RmfNUDWsyr48LDF/MKbhlYDtBunbJkcXsUBobeCy66UvP1Ae+zqe+9a6xUypdz8f+bz8ujh FaxQB6i+VwUpCE8BtJ+Q41aI9N3+1PCjA98PmY1EG3MkX2IK+SCpgFFBIWIICa25NIg49cKfDRE TfqYM/LRME+ON8Hxebo1R5stTn/eT4226Qi09e2sEr7N0ov+ZidylEj+XlfmvlLNsbUizpo+D2T qC+TkH6et19oK1qsE2ynkRNeiBojAAiHeSNgr8I0Yw7PyautHKZP0hxLafIwKcIyjP5QeB+k3KK mzG1gXcw+kOfGug== X-Mailer: b4 0.13.0 Message-ID: <20241015-page-align-v1-1-68fbd8b6d10c@google.com> Subject: [PATCH] rust: page: add Rust version of PAGE_ALIGN From: Alice Ryhl To: Miguel Ojeda , Andrew Morton , "Matthew Wilcox (Oracle)" Cc: Alex Gaynor , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Trevor Gross , linux-mm@kvack.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alice Ryhl X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 57E591C000F X-Stat-Signature: oo5ig8jejrimmrcmh9ormhfsc4c6pbs5 X-Rspam-User: X-HE-Tag: 1729002524-384750 X-HE-Meta: U2FsdGVkX198bxmrnKn3VvtanMxRDyPRBu2nAbSECQqU1lSVkMdoeq+oaxbjLsCNsMRPU0TY1ymYqeEq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z09ObFcW/rI3NrjnZaX7k+PM1o2SE7nRLmlhDrxi47RjCinK+XeF85xxNyyUkaCo/ojc48JQcEiPpOKSKTnT7EaEmvx9f/0VbpxwvceJfJ5ihMbE2Ms0PXLa3EpAXp6pKkhs8ece8G+HOwKm3YsUGpQcsoOk74EjWhP9rYnbrkVW/McdHNY4iEGPCRKv/R1djEjKoCP2Azm1WicY0tkdlI6WJYEXLS9h+qRN9VpG/JCkgh7yqXZV9NGYijGpBq2BmZbTxWJN7IgzW1TIKIpB4lTjJYcTQPrsQnCdclfFLziXPvk+nB76Yw05IhvlvlWcd/8yRN0QufiZgki9u9RDoHsm/xLJHHsSabq65ZlNzSaONN9UHWf03Hfr3sedsaL9i4n5K4TeM56SQcPqbgz0hQgapRg1X/wPHvZj/MVf1cSwRqM4GU6j8raiG14wC5Har4U1D441r6UG6peCBVQJ9FGhT0rCdraI57k1hmNkBMkW/QPj4dDaW5SY30y9sP4IJcU55xGGzw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.045220, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This is a useful for helper for working with indices into buffers that consist of several pages. I forgot to include it when I added PAGE_SIZE and PAGE_MASK for the same purpose in commit fc6e66f4696b ("rust: add abstraction for `struct page`"). Signed-off-by: Alice Ryhl Reviewed-by: Boqun Feng --- rust/kernel/page.rs | 5 +++++ 1 file changed, 5 insertions(+) --- base-commit: 8d8f785ceb21b9a0de11e05b811cc52d6fa79318 change-id: 20241015-page-align-7e5fa4c751be Best regards, diff --git a/rust/kernel/page.rs b/rust/kernel/page.rs index 208a006d587c..90846e3fe829 100644 --- a/rust/kernel/page.rs +++ b/rust/kernel/page.rs @@ -20,6 +20,11 @@ /// A bitmask that gives the page containing a given address. pub const PAGE_MASK: usize = !(PAGE_SIZE - 1); +/// Round up the given number to a multiple of `PAGE_SIZE`. +pub fn page_align(addr: usize) -> usize { + (addr + (PAGE_SIZE - 1)) & PAGE_MASK +} + /// A pointer to a page that owns the page allocation. /// /// # Invariants