From patchwork Thu Jun 30 08:08:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12901355 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 D8848CCA47E for ; Thu, 30 Jun 2022 08:08:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 354508E0001; Thu, 30 Jun 2022 04:08:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 302216B0073; Thu, 30 Jun 2022 04:08:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F0D48E0001; Thu, 30 Jun 2022 04:08:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0FBBC6B0072 for ; Thu, 30 Jun 2022 04:08:41 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D0649348D4 for ; Thu, 30 Jun 2022 08:08:40 +0000 (UTC) X-FDA: 79634175600.11.E6FE9E2 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf03.hostedemail.com (Postfix) with ESMTP id 0BB3E20033 for ; Thu, 30 Jun 2022 08:08:39 +0000 (UTC) Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-31bf3674d86so66301427b3.5 for ; Thu, 30 Jun 2022 01:08:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=GYiA9a77cHEq6HAaCDmf6SI0OmewmuXNtKGENJPyeDQ=; b=C1EfKr+StywKgVJq/OBLvMLrK8heQvFtjIGCGGyT7rZ69b5pEQPGxTEhFvO2BYcjEy g8ZS17+7JsRQ95zhsgiOMkfTwS3li5dwnG7XEpm57ZkE1rhwFbw0sQfTIqFSMUe2FWXd FDmNZSkIIaXOQDIpKCFOm8ja+Hhl0uhdA6myzfve5xULGXTW204yGkTZydfQL5EDnouO 5mNv99T+S/mp7gh/QW+Tf9ygT+H6W91jY9O0kOG9pLpcPMqSAa0h1mvt06NFXSrElzJ5 iOkJIEe1i08IEujUg3ijvej4K+LucoNqEI8Lae5M+VGTkRfr/Zq7rVM6Iaek+b/85BH9 eCYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=GYiA9a77cHEq6HAaCDmf6SI0OmewmuXNtKGENJPyeDQ=; b=f31v3DwQFbA0OV2wdQODAOaiez/b0x3+oAoq2i562r7k/hz26VAOyS90TCA86nyxDD fO/WzCa/RHJqu3o42JERx5m+WAYCCwxPFATWeiYBloW7Bn0LqsbyaM+untXZmWaHkaUT yA4ZtRYVuWBj9/YVKWXLo3VovxnyCV9Hyc7aOulX7Yy3Tuy8He2t2/WQIiKy+XJz8djW /j3swZemvaNC2OFTl6+ds1tyZUa3SCsZRG443G8yuIFEclie9fL7RdzlkIMvgtODG+4S IqiBocTMeLpHFCtyEswxFTGSdoCHmeDOGtRGmx+ZfO7h6f1uHtOKcYHZGz7xSHz6y6jJ 07cA== X-Gm-Message-State: AJIora+xBBWMBMu65u/I3UOylBECYtsHaJ9vIIXooJluM66xDV0P6tc9 kDcPVEaRcRL8SDFSnDkF8/XiIjP0v31DhQ== X-Google-Smtp-Source: AGRyM1vm38iy2eLMKhhFXCCu+SfPwrcidn0k3qk7MdnQqnMvfwdUj/TRVk/LjaEK39jKP3KXpV4aVpj1UMke7g== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a05:6902:1d0:b0:668:b5ea:10ec with SMTP id u16-20020a05690201d000b00668b5ea10ecmr8084737ybh.419.1656576519392; Thu, 30 Jun 2022 01:08:39 -0700 (PDT) Date: Thu, 30 Jun 2022 16:08:33 +0800 Message-Id: <20220630080834.2742777-1-davidgow@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 1/2] mm: Add PAGE_ALIGN_DOWN macro From: David Gow To: Vincent Whitchurch , Johannes Berg , Patricia Alfonso , Jeff Dike , Richard Weinberger , anton.ivanov@cambridgegreys.com, Dmitry Vyukov , Brendan Higgins , Andrew Morton , Andrey Konovalov , Andrey Ryabinin Cc: David Gow , kasan-dev , linux-um@lists.infradead.org, LKML , Daniel Latypov , linux-mm@kvack.org, kunit-dev@googlegroups.com ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=C1EfKr+S; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 3B1q9YggKCMwvsD0vy6Ey66y3w.u64305CF-442Dsu2.69y@flex--davidgow.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3B1q9YggKCMwvsD0vy6Ey66y3w.u64305CF-442Dsu2.69y@flex--davidgow.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656576520; a=rsa-sha256; cv=none; b=7+7lFiF9FeDd4AmingrZZEc+rqpl0WP/ShxA4LZFnVoJtYWBLIBTfbNfApQ4cVNeOk+VdU WPmBNi+HFLK4PisGRzLw3Ba9paiDSrsjTW5MzZC+c8zbIidVy5Ub4lbnCpD6uTXkA5pYi5 PFq8CuIo3sbpcJ9L8wF/L4irBoO25Lc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656576520; 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=GYiA9a77cHEq6HAaCDmf6SI0OmewmuXNtKGENJPyeDQ=; b=11c/Acfnx7JAuXJgKPGBTfRLwZL/2RzRY42LG6FJrIhWdW7Ff/Ape2ahMOooalRVc2bie4 pDtqQJcjVnPSx3dSgyQVf5J6CexHKekpHk2gUF/R6k2oxZeIQR78h6vXvRUN/7AnAvjZcJ wyzNPMB91YahQbrEiBibF98ebw301mQ= X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=C1EfKr+S; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 3B1q9YggKCMwvsD0vy6Ey66y3w.u64305CF-442Dsu2.69y@flex--davidgow.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3B1q9YggKCMwvsD0vy6Ey66y3w.u64305CF-442Dsu2.69y@flex--davidgow.bounces.google.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 0BB3E20033 X-Stat-Signature: y7e1z8nse4i7s3gc9hwpo3wbqud34s1k X-HE-Tag: 1656576519-365752 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: This is just the same as PAGE_ALIGN(), but rounds the address down, not up. Suggested-by: Dmitry Vyukov Signed-off-by: David Gow Acked-by: Andrew Morton --- Please take this patch as part of the UML tree, along with patch #2, thanks! No changes to this patch since v3 (just a minor issue with patch #2): https://lore.kernel.org/lkml/20220630074757.2739000-1-davidgow@google.com/ Changes since v2: https://lore.kernel.org/lkml/20220527185600.1236769-1-davidgow@google.com/ - Add Andrew's Acked-by tag. v2 was the first version of this patch (it having been introduced as part of v2 of the UML/KASAN series). There are almost certainly lots of places where this macro should be used: just look for ALIGN_DOWN(..., PAGE_SIZE). I haven't gone through to try to replace them all. --- include/linux/mm.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 9f44254af8ce..9abe5975ad11 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -221,6 +221,9 @@ int overcommit_policy_handler(struct ctl_table *, int, void *, size_t *, /* to align the pointer to the (next) page boundary */ #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) +/* to align the pointer to the (prev) page boundary */ +#define PAGE_ALIGN_DOWN(addr) ALIGN_DOWN(addr, PAGE_SIZE) + /* test whether an address (unsigned long or pointer) is aligned to PAGE_SIZE */ #define PAGE_ALIGNED(addr) IS_ALIGNED((unsigned long)(addr), PAGE_SIZE)