From: Marco Elver <elver@google.com>
To: Muchun Song <songmuchun@bytedance.com>
Cc: glider@google.com, dvyukov@google.com, akpm@linux-foundation.org,
jannh@google.com, sjpark@amazon.de, muchun.song@linux.dev,
kasan-dev@googlegroups.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 6/6] mm: kfence: replace ALIGN_DOWN(x, PAGE_SIZE) with PAGE_ALIGN_DOWN(x)
Date: Tue, 28 Mar 2023 13:55:38 +0200 [thread overview]
Message-ID: <CANpmjNPeQBcV7qnpXJOoLYjonsjPnOW-cerYm=_U3ptNZrXu0Q@mail.gmail.com> (raw)
In-Reply-To: <20230328095807.7014-7-songmuchun@bytedance.com>
On Tue, 28 Mar 2023 at 11:59, 'Muchun Song' via kasan-dev
<kasan-dev@googlegroups.com> wrote:
>
> Replace ALIGN_DOWN(x, PAGE_SIZE) with PAGE_ALIGN_DOWN(x) to simplify
> the code a bit.
>
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Reviewed-by: Marco Elver <elver@google.com>
> ---
> mm/kfence/core.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/mm/kfence/core.c b/mm/kfence/core.c
> index f205b860f460..dbfb79a4d624 100644
> --- a/mm/kfence/core.c
> +++ b/mm/kfence/core.c
> @@ -230,17 +230,17 @@ static bool alloc_covered_contains(u32 alloc_stack_hash)
>
> static inline void kfence_protect(unsigned long addr)
> {
> - kfence_protect_page(ALIGN_DOWN(addr, PAGE_SIZE), true);
> + kfence_protect_page(PAGE_ALIGN_DOWN(addr), true);
> }
>
> static inline void kfence_unprotect(unsigned long addr)
> {
> - kfence_protect_page(ALIGN_DOWN(addr, PAGE_SIZE), false);
> + kfence_protect_page(PAGE_ALIGN_DOWN(addr), false);
> }
>
> static inline unsigned long metadata_to_pageaddr(const struct kfence_metadata *meta)
> {
> - return ALIGN_DOWN(meta->addr, PAGE_SIZE);
> + return PAGE_ALIGN_DOWN(meta->addr);
> }
>
> /*
> @@ -308,7 +308,7 @@ static inline bool check_canary_byte(u8 *addr)
> /* __always_inline this to ensure we won't do an indirect call to fn. */
> static __always_inline void for_each_canary(const struct kfence_metadata *meta, bool (*fn)(u8 *))
> {
> - const unsigned long pageaddr = ALIGN_DOWN(meta->addr, PAGE_SIZE);
> + const unsigned long pageaddr = PAGE_ALIGN_DOWN(meta->addr);
> unsigned long addr;
>
> /*
> @@ -455,7 +455,7 @@ static void kfence_guarded_free(void *addr, struct kfence_metadata *meta, bool z
> }
>
> /* Detect racy use-after-free, or incorrect reallocation of this page by KFENCE. */
> - kcsan_begin_scoped_access((void *)ALIGN_DOWN((unsigned long)addr, PAGE_SIZE), PAGE_SIZE,
> + kcsan_begin_scoped_access((void *)PAGE_ALIGN_DOWN((unsigned long)addr), PAGE_SIZE,
> KCSAN_ACCESS_SCOPED | KCSAN_ACCESS_WRITE | KCSAN_ACCESS_ASSERT,
> &assert_page_exclusive);
>
> @@ -464,7 +464,7 @@ static void kfence_guarded_free(void *addr, struct kfence_metadata *meta, bool z
>
> /* Restore page protection if there was an OOB access. */
> if (meta->unprotected_page) {
> - memzero_explicit((void *)ALIGN_DOWN(meta->unprotected_page, PAGE_SIZE), PAGE_SIZE);
> + memzero_explicit((void *)PAGE_ALIGN_DOWN(meta->unprotected_page), PAGE_SIZE);
> kfence_protect(meta->unprotected_page);
> meta->unprotected_page = 0;
> }
> --
> 2.11.0
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20230328095807.7014-7-songmuchun%40bytedance.com.
prev parent reply other threads:[~2023-03-28 11:56 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-28 9:58 [PATCH 0/6] Simplify kfence code Muchun Song
2023-03-28 9:58 ` [PATCH 1/6] mm: kfence: simplify kfence pool initialization Muchun Song
2023-03-28 11:55 ` Marco Elver
2023-03-28 12:05 ` Marco Elver
2023-03-28 12:53 ` Muchun Song
2023-03-28 9:58 ` [PATCH 2/6] mm: kfence: check kfence pool size at building time Muchun Song
2023-03-28 10:14 ` Marco Elver
2023-03-28 13:03 ` Muchun Song
2023-03-28 9:58 ` [PATCH 3/6] mm: kfence: make kfence_protect_page() void Muchun Song
2023-03-28 10:32 ` Marco Elver
2023-03-28 13:04 ` Muchun Song
2023-03-28 9:58 ` [PATCH 4/6] mm: kfence: remove useless check for CONFIG_KFENCE_NUM_OBJECTS Muchun Song
2023-04-03 8:59 ` Alexander Potapenko
2023-03-28 9:58 ` [PATCH 5/6] mm: kfence: change kfence pool page layout Muchun Song
2023-03-28 12:59 ` Marco Elver
2023-03-28 13:32 ` Muchun Song
2023-03-28 14:12 ` Marco Elver
2023-03-28 9:58 ` [PATCH 6/6] mm: kfence: replace ALIGN_DOWN(x, PAGE_SIZE) with PAGE_ALIGN_DOWN(x) Muchun Song
2023-03-28 11:55 ` Marco Elver [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CANpmjNPeQBcV7qnpXJOoLYjonsjPnOW-cerYm=_U3ptNZrXu0Q@mail.gmail.com' \
--to=elver@google.com \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=jannh@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=sjpark@amazon.de \
--cc=songmuchun@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox