Skip to contentSkip to conversation

bootmem: add alloc_bootmem_align()

PATCH In review Suresh Siddha 2 participants 6 messages Nov 16, 2010 – Dec 14, 2010 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 bootmem: add alloc_bootmem_align()

---
 include/linux/bootmem.h |    2 ++
 1 file changed, 2 insertions(+)
include/linux/bootmem.h +2 -0
Index: tree/include/linux/bootmem.h
===================================================================
@@ -105,6 +105,8 @@ extern void *__alloc_bootmem_low_node(pg
 
 #define alloc_bootmem(x) \
 	__alloc_bootmem(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
+#define alloc_bootmem_align(x, align) \
+	__alloc_bootmem(x, align, __pa(MAX_DMA_ADDRESS))
 #define alloc_bootmem_nopanic(x) \
 	__alloc_bootmem_nopanic(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
 #define alloc_bootmem_pages(x) \
#1 lore raw

PATCH 2/2 xsave: use alloc_bootmem_align() instead of alloc_bootmem()

Alignment of alloc_bootmem() depends on the value of L1_CACHE_SHIFT. What we need here is 64byte alignment. Use alloc_bootmem_align() instead.

This fixes a kernel boot crash reported by Jody when the cpu in .config is set to MPENTIUMII

---
 arch/x86/kernel/xsave.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/xsave.c +2 -1
Index: tree/arch/x86/kernel/xsave.c
===================================================================
@@ -394,7 +394,8 @@ static void __init setup_xstate_init(voi
 	 * Setup init_xstate_buf to represent the init state of
 	 * all the features managed by the xsave
 	 */
-	init_xstate_buf = alloc_bootmem(xstate_size);
+	init_xstate_buf = alloc_bootmem_align(xstate_size,
+					      __alignof__(struct xsave_struct));
 	init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT;
 
 	clts();
#2 lore raw

[tip:x86/urgent] x86, xsave: Use alloc_bootmem_align() instead of alloc_bootmem()

Commit-ID:  10340ae130fb70352eae1ae8a00b7906d91bf166
Gitweb:     http://git.kernel.org/tip/10340ae130fb70352eae1ae8a00b7906d91bf166
Author:     Suresh Siddha <[email protected]>
AuthorDate: Tue, 16 Nov 2010 13:23:51 -0800
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Mon, 13 Dec 2010 16:13:11 -0800

x86, xsave: Use alloc_bootmem_align() instead of alloc_bootmem()

Alignment of alloc_bootmem() depends on the value of L1_CACHE_SHIFT. What we need here, however, is 64 byte alignment. Use alloc_bootmem_align() and explicitly specify the alignment instead.

This fixes a kernel boot crash reported by Jody when the cpu in .config is set to MPENTIUMII but the kernel is booted on a xsave-capable CPU.

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/xsave.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/xsave.c +2 -1
index 9c253bd..5471285 100644
@@ -394,7 +394,8 @@ static void __init setup_xstate_init(void)
 	 * Setup init_xstate_buf to represent the init state of
 	 * all the features managed by the xsave
 	 */
-	init_xstate_buf = alloc_bootmem(xstate_size);
+	init_xstate_buf = alloc_bootmem_align(xstate_size,
+					      __alignof__(struct xsave_struct));
 	init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT;
 
 	clts();
#3 lore raw
In reply to Suresh Siddha
Quoted 13 lines · Suresh Siddha

Index: tree/include/linux/bootmem.h
===================================================================

include/linux/bootmem.h +2 -0
@@ -105,6 +105,8 @@ extern void *__alloc_bootmem_low_node(pg
 
 #define alloc_bootmem(x) \
 	__alloc_bootmem(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
+#define alloc_bootmem_align(x, align) \
+	__alloc_bootmem(x, align, __pa(MAX_DMA_ADDRESS))
 #define alloc_bootmem_nopanic(x) \
 	__alloc_bootmem_nopanic(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
 #define alloc_bootmem_pages(x) \

[...]

include/linux/bootmem.h

Quoted 5 lines
include/linux/bootmem.h +2 -1
 	 */
-	init_xstate_buf = alloc_bootmem(xstate_size);
+	init_xstate_buf = alloc_bootmem_align(xstate_size,
+					      __alignof__(struct xsave_struct));
 	init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT;

Perhaps it would make even more sense to have:

#define alloc_bootmem_alignof(x, type) \
	__alloc_bootmem(x, __alignof__(type), __pa(MAX_DMA_ADDRESS))

?

-hpa

#4 lore raw
Quoted 25 lines · H. Peter Anvin
Quoted 13 lines · Suresh Siddha

Index: tree/include/linux/bootmem.h
===================================================================

include/linux/bootmem.h +2 -0
@@ -105,6 +105,8 @@ extern void *__alloc_bootmem_low_node(pg
 
 #define alloc_bootmem(x) \
 	__alloc_bootmem(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
+#define alloc_bootmem_align(x, align) \
+	__alloc_bootmem(x, align, __pa(MAX_DMA_ADDRESS))
 #define alloc_bootmem_nopanic(x) \
 	__alloc_bootmem_nopanic(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
 #define alloc_bootmem_pages(x) \

[...]

include/linux/bootmem.h

Quoted 5 lines
include/linux/bootmem.h +2 -1
 	 */
-	init_xstate_buf = alloc_bootmem(xstate_size);
+	init_xstate_buf = alloc_bootmem_align(xstate_size,
+					      __alignof__(struct xsave_struct));
 	init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT;

Perhaps it would make even more sense to have:

Quoted 3 lines
#define alloc_bootmem_alignof(x, type) \
	__alloc_bootmem(x, __alignof__(type), __pa(MAX_DMA_ADDRESS))

Wanted to keep it broad so that more people can start using it.

For example, most of the current x86 uses of alloc_bootmem_pages() (or the __alloc_bootmem() calls in other architectures) can be replaced with alloc_bootmem_align() and most of them don't have a relevant type to describe the alignment.

thanks,
suresh

#5 lore raw

[tip:x86/urgent] bootmem: Add alloc_bootmem_align()

In reply to Suresh Siddha
Commit-ID:  53dde5f385bc56e312f78b7cb25ffaf8efd4735d
Gitweb:     http://git.kernel.org/tip/53dde5f385bc56e312f78b7cb25ffaf8efd4735d
Author:     Suresh Siddha <[email protected]>
AuthorDate: Tue, 16 Nov 2010 13:23:50 -0800
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Mon, 13 Dec 2010 16:11:13 -0800

bootmem: Add alloc_bootmem_align()

Add an alloc_bootmem_align() interface to allocate bootmem with specified alignment. This is necessary to be able to allocate the xsave area in a subsequent patch.

LKML-Reference: <[email protected]>

---
 include/linux/bootmem.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
include/linux/bootmem.h +2 -0
index 266ab92..499dfe9 100644
@@ -105,6 +105,8 @@ extern void *__alloc_bootmem_low_node(pg_data_t *pgdat,
 
 #define alloc_bootmem(x) \
 	__alloc_bootmem(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
+#define alloc_bootmem_align(x, align) \
+	__alloc_bootmem(x, align, __pa(MAX_DMA_ADDRESS))
 #define alloc_bootmem_nopanic(x) \
 	__alloc_bootmem_nopanic(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
 #define alloc_bootmem_pages(x) \