Skip to contentSkip to conversation

mm: kfence: Use PAGE_ALIGNED helper

PATCH Applied Kefeng Wang 3 participants 6 messages May 20, 2022 – May 23, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: kfence: Use PAGE_ALIGNED helper

Use PAGE_ALIGNED macro instead of IS_ALIGNED and passing PAGE_SIZE.

---
 mm/kfence/kfence_test.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/kfence/kfence_test.c +2 -3
index 96206a4ee9ab..a97bffe0cc3e 100644
@@ -296,10 +296,9 @@ static void *test_alloc(struct kunit *test, size_t size, gfp_t gfp, enum allocat
 
 			if (policy == ALLOCATE_ANY)
 				return alloc;
-			if (policy == ALLOCATE_LEFT && IS_ALIGNED((unsigned long)alloc, PAGE_SIZE))
+			if (policy == ALLOCATE_LEFT && PAGE_ALIGNED(alloc))
 				return alloc;
-			if (policy == ALLOCATE_RIGHT &&
-			    !IS_ALIGNED((unsigned long)alloc, PAGE_SIZE))
+			if (policy == ALLOCATE_RIGHT && !PAGE_ALIGNED(alloc))
 				return alloc;
 		} else if (policy == ALLOCATE_NONE)
 			return alloc;
Signature · 1 line
2.35.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Kefeng Wang' via kasan-dev

Use PAGE_ALIGNED macro instead of IS_ALIGNED and passing PAGE_SIZE.

Quoted 23 lines
---
 mm/kfence/kfence_test.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/kfence/kfence_test.c +2 -3
index 96206a4ee9ab..a97bffe0cc3e 100644
@@ -296,10 +296,9 @@ static void *test_alloc(struct kunit *test, size_t size, gfp_t gfp, enum allocat
 
 			if (policy == ALLOCATE_ANY)
 				return alloc;
-			if (policy == ALLOCATE_LEFT && IS_ALIGNED((unsigned long)alloc, PAGE_SIZE))
+			if (policy == ALLOCATE_LEFT && PAGE_ALIGNED(alloc))
 				return alloc;
-			if (policy == ALLOCATE_RIGHT &&
-			    !IS_ALIGNED((unsigned long)alloc, PAGE_SIZE))
+			if (policy == ALLOCATE_RIGHT && !PAGE_ALIGNED(alloc))
 				return alloc;
 		} else if (policy == ALLOCATE_NONE)
 			return alloc;
Signature · 1 line
2.35.3
#3 lore raw
Quoted 5 lines · Muchun Song
Quoted 3 lines · Kefeng Wang

Use PAGE_ALIGNED macro instead of IS_ALIGNED and passing PAGE_SIZE.

Thanks,

Quoted 3 lines

BTW, there is a similar case in page_fixed_fake_head(), woule you like to improve that as well?

IS_ALIGNED is defined in include/linux/align.h, but PAGE_ALIGNED is in include/linux/mm.h, so better to keep unchanged in include/linux/page-flags.h.

Quoted 4 lines

Thanks.

.

#4 lore raw
Quoted 6 lines · Kefeng Wang
Quoted 4 lines · Muchun Song
Quoted 3 lines · Kefeng Wang

Use PAGE_ALIGNED macro instead of IS_ALIGNED and passing PAGE_SIZE.

Quoted 9 lines
Quoted 1 line

Thanks,

Quoted 3 lines

BTW, there is a similar case in page_fixed_fake_head(), woule you like to improve that as well?

IS_ALIGNED is defined in include/linux/align.h, but PAGE_ALIGNED is in include/linux/mm.h, so better to keep unchanged in include/linux/page-flags.h.

Maybe we could move this macro to page-flags.h or align.h so that we could reuse it?

Thanks.

#5 lore raw
Quoted 7 lines · Muchun Song
Quoted 6 lines · Kefeng Wang
Quoted 5 lines · Muchun Song
Quoted 3 lines · Kefeng Wang

Use PAGE_ALIGNED macro instead of IS_ALIGNED and passing PAGE_SIZE.

Quoted 8 lines
Quoted 6 lines

Thanks,

Quoted 2 lines

BTW, there is a similar case in page_fixed_fake_head(), woule you like to improve that as well?

IS_ALIGNED is defined in include/linux/align.h, but PAGE_ALIGNED is in include/linux/mm.h, so better to keep unchanged in include/linux/page-flags.h.

Maybe we could move this macro to page-flags.h or align.h so that we could reuse it?

align.h is inappropriate, could be page-flags.h,  but this could affect the include of 'mm.h',so I think it is unnecessary to move the PAGE_ALIGNED(and there is a PAGE_ALIGN too, no need to move both of them).

Quoted 2 lines

Thanks.
.