From patchwork Fri Jul 1 09:16:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12903033 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 02816C43334 for ; Fri, 1 Jul 2022 09:16:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E6A76B0071; Fri, 1 Jul 2022 05:16:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 86FA66B0073; Fri, 1 Jul 2022 05:16:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70FB86B0074; Fri, 1 Jul 2022 05:16:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 606706B0071 for ; Fri, 1 Jul 2022 05:16:28 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 3146780D66 for ; Fri, 1 Jul 2022 09:16:28 +0000 (UTC) X-FDA: 79637975256.21.F6E06E6 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf18.hostedemail.com (Postfix) with ESMTP id AFDB51C002F for ; Fri, 1 Jul 2022 09:16:27 +0000 (UTC) Received: by mail-pj1-f74.google.com with SMTP id u1-20020a17090a450100b001ef1c4c2844so1157711pjg.4 for ; Fri, 01 Jul 2022 02:16:27 -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=Gzf9MNYfzuExJ4letAUuWlfZz/ymERxaYUyT/EuC1fc=; b=Ziw2qAXAlzhNlbhTjbP0JE77DsFllvjUC3AvzRFw4OJ8KKLOHiNYxCskVSDnjCrbmk dRi/Tm4oQcCNrIY5p5Ziht1qS27pnUQatjR262bXMIcKV9YxIj2b/0029BocKRRLJlYU HP6zwkl7J2Icx8KXYVj+zvrUrOD58dKKWVnJye31y9E4/J2F4wUXrxoAQ4WcoSR7evCz ZSbWZjPy6gy16w95t0NfHgdbfNUgudhTVrD7nIgjoc8Kl8jNzBjvQSMW/2/0mC5xaqQu Wao9C47Jn/85zScpvweq1xtOni7nOQTixCgarYqulfUgkf2NQQ33BTBk593QPAqQQhv9 cLYQ== 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=Gzf9MNYfzuExJ4letAUuWlfZz/ymERxaYUyT/EuC1fc=; b=4o9PdDy+Dp9bEHbPDMmXsRaK4qN7rVEg5vn45hhbvQsRBZgv2lGID9Q62mFgmLl2+g TsnkvSjZ5uZpzAPAPmiDjOQda8KUSH4iYM1miMi0nNXz0q7GRfCx9cfC8XbklhGdwv1T Tj178DbU2qfbeMrU4L65vzY4W/msgSjwcV1WwOK5idLkig71JcSOb4Xi/vFQayiGBVX/ 1E26gp5yjm43KTApuAJHwVtmuzQauyR3JSYdzLH7hsguTp6dmJRibt1+eSLqFFstdZXX c2eVRVw31OMStG4uoKxg2ahctcWPJh0YkEZnk8mxm2EXv+g/j2sbzR0A5Qz/QP8wdTuN 4Gdg== X-Gm-Message-State: AJIora/7ca2O/puoaDOmgq5AgY8xZ0q3ztCee5OAkY+JV4mJq1YeJErD zWuDPVgvJpVmdMXPQutqbwd9jvH2nWvJMQ== X-Google-Smtp-Source: AGRyM1tlgeuz2bKn2ETD5JL0peIvZI8MizDxt/mQxTKM/Btl6ArdfthuN5ner3m8FquTDc5cMpJaiqaGXiCE8g== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a17:90b:4a42:b0:1ec:adee:e298 with SMTP id lb2-20020a17090b4a4200b001ecadeee298mr17874949pjb.161.1656666986727; Fri, 01 Jul 2022 02:16:26 -0700 (PDT) Date: Fri, 1 Jul 2022 17:16:19 +0800 Message-Id: <20220701091621.3022368-1-davidgow@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v5 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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656666987; 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=Gzf9MNYfzuExJ4letAUuWlfZz/ymERxaYUyT/EuC1fc=; b=7dzJ3GC4XXXgGKVBfjWG+87aNg5QUbkBz7CVAaHsG36Wf1m77ooIVaFunjVJiMPz5GvyAK xfCfVA0OhIe/g8Iz9V4AuBXMHYsXd5oKbSWHjK5EtJCguYtt/zhDXefGibGGBC0NqsagZY NL8SsbNJvCzB6H8vpPJwoWCGPFFSjJQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656666987; a=rsa-sha256; cv=none; b=t/updq8dxeymgQ02Ox5b0wxYFd605smbJteGJwRfD3P5nzV4vEm66W58lNlJftDNXlI86L Jjbh4T4kTmDuUGSCZrreYr/uhEr5DXs/h2azSej/7aypU1+nena0PhQAFVry5rIYeUqP6d rj/QrRUNbq3QIE82a8oUZL5Wq6VjKQc= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Ziw2qAXA; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3aru-YggKCPccZuhcfnvfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--davidgow.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3aru-YggKCPccZuhcfnvfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--davidgow.bounces.google.com X-Stat-Signature: ux6fbzm6sagzj7tu666se9opm6nig6wf X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Ziw2qAXA; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3aru-YggKCPccZuhcfnvfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--davidgow.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3aru-YggKCPccZuhcfnvfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--davidgow.bounces.google.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AFDB51C002F X-HE-Tag: 1656666987-94511 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 v4: https://lore.kernel.org/lkml/20220630080834.2742777-1-davidgow@google.com/ 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)