diff mbox series

[v2,1/2] mm: Add PAGE_ALIGN_DOWN macro

Message ID 20220527185600.1236769-1-davidgow@google.com (mailing list archive)
State New
Headers show
Series [v2,1/2] mm: Add PAGE_ALIGN_DOWN macro | expand

Commit Message

David Gow May 27, 2022, 6:55 p.m. UTC
This is just the same as PAGE_ALIGN(), but rounds the address down, not
up.

Suggested-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: David Gow <davidgow@google.com>
---

Note: there is no v1 of this patch, it's just 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(+)

Comments

Andrew Morton May 30, 2022, 12:06 a.m. UTC | #1
On Fri, 27 May 2022 11:55:59 -0700 David Gow <davidgow@google.com> wrote:

> This is just the same as PAGE_ALIGN(), but rounds the address down, not
> up.

Acked-by: Andrew Morton <akpm@linux-foundation.org>

Please include this in the UML tree alongside [2/2].
diff mbox series

Patch

diff --git a/include/linux/mm.h b/include/linux/mm.h
index e34edb775334..e68731f0ef20 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)