Skip to contentSkip to conversation

x86: xen: remove the use of VLAIS

PATCH In review Nick Desaulniers 5 participants 23 messages Dec 24, 2017 – Jan 9, 2018

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

PATCH 1/1 x86: xen: remove the use of VLAIS

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we can define the variable length array (mask) to be a pointer, and calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
 arch/x86/xen/mmu_pv.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
arch/x86/xen/mmu_pv.c +4 -6
index 4d62c07..966976c 100644
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
-		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
+		unsigned long *mask;
 	} *args;
 	struct multicall_space mcs;
+	const size_t mc_entry_size = sizeof(args->op) +
+		sizeof(*args->mask) * BITS_TO_LONGS(num_possible_cpus());
 
 	trace_xen_mmu_flush_tlb_others(cpus, info->mm, info->start, info->end);
 
 	if (cpumask_empty(cpus))
 		return;		/* nothing to do */
 
-	mcs = xen_mc_entry(sizeof(*args));
+	mcs = xen_mc_entry(mc_entry_size);
 	args = mcs.args;
 	args->op.arg2.vcpumask = to_cpumask(args->mask);
 
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 5 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Quoted 7 lines

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we can define the variable length array (mask) to be a pointer, and calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

Using a pointer for mask seems to be wrong, as it is never initialized.

Why don't you just use:

DECLARE_BITMAP(mask, NR_CPUS);

and drop the #ifdef, while keeping the manual length calculation?

Juergen

Quoted 36 lines
---
 arch/x86/xen/mmu_pv.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
arch/x86/xen/mmu_pv.c +4 -6
index 4d62c07..966976c 100644
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
-		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
+		unsigned long *mask;
 	} *args;
 	struct multicall_space mcs;
+	const size_t mc_entry_size = sizeof(args->op) +
+		sizeof(*args->mask) * BITS_TO_LONGS(num_possible_cpus());
 
 	trace_xen_mmu_flush_tlb_others(cpus, info->mm, info->start, info->end);
 
 	if (cpumask_empty(cpus))
 		return;		/* nothing to do */
 
-	mcs = xen_mc_entry(sizeof(*args));
+	mcs = xen_mc_entry(mc_entry_size);
 	args = mcs.args;
 	args->op.arg2.vcpumask = to_cpumask(args->mask);
 
#2 lore raw

PATCH v2 1/1 x86: xen: remove the use of VLAIS

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/xen/mmu_pv.c +3 -5
index 4d62c07..d850762 100644
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;
 	struct multicall_space mcs;
+	const size_t mc_entry_size = sizeof(args->op) +
+		sizeof(args->mask[0]) * BITS_TO_LONGS(num_possible_cpus());
 
 	trace_xen_mmu_flush_tlb_others(cpus, info->mm, info->start, info->end);
 
 	if (cpumask_empty(cpus))
 		return;		/* nothing to do */
 
-	mcs = xen_mc_entry(sizeof(*args));
+	mcs = xen_mc_entry(mc_entry_size);
 	args = mcs.args;
 	args->op.arg2.vcpumask = to_cpumask(args->mask);
 
Signature · 1 line
2.7.4
maintainer Reviewed-by on v2 1/1
#3 lore raw
Quoted 13 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

Quoted 2 lines

Juergen

maintainer Reviewed-by on v2 1/1
#4 lore raw
In reply to Nick Desaulniers
Quoted 13 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

Quoted 2 lines

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

reviewer Applied
#5 lore raw
In reply to Nick Desaulniers
Quoted 13 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

Quoted 2 lines

Applied to for-linus-4.15.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

reviewer Applied
#6 lore raw
In reply to Nick Desaulniers
Quoted 13 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

Quoted 2 lines

Applied to for-linus-4.15.

-boris

#7 lore raw
In reply to Nick Desaulniers
Quoted 29 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/xen/mmu_pv.c +0 -0
index 4d62c07..d850762 100644

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 9 lines
arch/x86/xen/mmu_pv.c +0 -4
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

#8 lore raw
Quoted 25 lines · Peter Zijlstra
Quoted 24 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
Quoted 16 lines
Quoted 5 lines
arch/x86/xen/mmu_pv.c +0 -0
index 4d62c07..d850762 100644

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 9 lines
arch/x86/xen/mmu_pv.c +0 -4
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

Err... right. Now it's even worse than it was before, when the array was potentially smaller. I'll drop this.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#9 lore raw
In reply to Peter Zijlstra
Quoted 25 lines · Peter Zijlstra
Quoted 24 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
Quoted 16 lines
Quoted 5 lines
arch/x86/xen/mmu_pv.c +0 -0
index 4d62c07..d850762 100644

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 9 lines
arch/x86/xen/mmu_pv.c +0 -4
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

Err... right. Now it's even worse than it was before, when the array was potentially smaller. I'll drop this.

-boris

maintainer
#10 lore raw
Quoted 43 lines · Boris Ostrovsky
Quoted 25 lines · Peter Zijlstra
Quoted 24 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
Quoted 16 lines
Quoted 5 lines
arch/x86/xen/mmu_pv.c +0 -0
index 4d62c07..d850762 100644

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 9 lines
arch/x86/xen/mmu_pv.c +0 -4
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

Quoted 2 lines

Err... right. Now it's even worse than it was before, when the array was potentially smaller. I'll drop this.

No, its only the pointer to the struct, not the struct itself.

Juergen

#11 lore raw
Quoted 43 lines · Juergen Gross
Quoted 42 lines · Boris Ostrovsky
Quoted 41 lines · Peter Zijlstra
Quoted 29 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/xen/mmu_pv.c +0 -0
index 4d62c07..d850762 100644

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 9 lines
arch/x86/xen/mmu_pv.c +0 -4
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

Quoted 4 lines
Quoted 2 lines

Err... right. Now it's even worse than it was before, when the array was potentially smaller. I'll drop this.

No, its only the pointer to the struct, not the struct itself.

It's the full array, isn't it?

#define DECLARE_BITMAP(name,bits) \
unsigned long name[BITS_TO_LONGS(bits)]

<pause>

OK, it *is* a pointer. Sigh...

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#12 lore raw
In reply to Juergen Gross
Quoted 43 lines · Juergen Gross
Quoted 42 lines · Boris Ostrovsky
Quoted 41 lines · Peter Zijlstra
Quoted 29 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/xen/mmu_pv.c +0 -0
index 4d62c07..d850762 100644

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 9 lines
arch/x86/xen/mmu_pv.c +0 -4
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

Quoted 4 lines
Quoted 2 lines

Err... right. Now it's even worse than it was before, when the array was potentially smaller. I'll drop this.

No, its only the pointer to the struct, not the struct itself.

It's the full array, isn't it?

#define DECLARE_BITMAP(name,bits) \
unsigned long name[BITS_TO_LONGS(bits)]

<pause>

OK, it *is* a pointer. Sigh...

-boris

maintainer
#13 lore raw
In reply to Boris Ostrovsky
Quoted 43 lines · Boris Ostrovsky
Quoted 25 lines · Peter Zijlstra
Quoted 24 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
Quoted 16 lines
Quoted 5 lines
arch/x86/xen/mmu_pv.c +0 -0
index 4d62c07..d850762 100644

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 9 lines
arch/x86/xen/mmu_pv.c +0 -4
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

Quoted 2 lines

Err... right. Now it's even worse than it was before, when the array was potentially smaller. I'll drop this.

No, its only the pointer to the struct, not the struct itself.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

maintainer
#14 lore raw
In reply to Peter Zijlstra
Quoted 34 lines · Peter Zijlstra
Quoted 33 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/xen/mmu_pv.c +0 -1
index 4d62c07..d850762 100644
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
Quoted 8 lines

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 5 lines
arch/x86/xen/mmu_pv.c +0 -3
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

This only a pointer to the bitmap.

Juergen

#15 lore raw
Quoted 44 lines · Juergen Gross
Quoted 34 lines · Peter Zijlstra
Quoted 33 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/xen/mmu_pv.c +0 -1
index 4d62c07..d850762 100644
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
Quoted 8 lines

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 5 lines
arch/x86/xen/mmu_pv.c +0 -3
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

Quoted 1 line

This only a pointer to the bitmap.

What's the maximum NR_CPUs for configs that can run this code, times 8?

Thanks,

Ingo

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#16 lore raw
In reply to Juergen Gross
Quoted 44 lines · Juergen Gross
Quoted 34 lines · Peter Zijlstra
Quoted 33 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/xen/mmu_pv.c +0 -1
index 4d62c07..d850762 100644
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
Quoted 8 lines

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 5 lines
arch/x86/xen/mmu_pv.c +0 -3
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

Quoted 1 line

This only a pointer to the bitmap.

What's the maximum NR_CPUs for configs that can run this code, times 8?

Thanks,

Ingo

maintainer
#17 lore raw
Quoted 47 lines · Ingo Molnar
Quoted 44 lines · Juergen Gross
Quoted 42 lines · Peter Zijlstra
Quoted 29 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/xen/mmu_pv.c +0 -0
index 4d62c07..d850762 100644

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 9 lines
arch/x86/xen/mmu_pv.c +0 -4
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

Quoted 3 lines
Quoted 1 line

This only a pointer to the bitmap.

What's the maximum NR_CPUs for configs that can run this code, times 8?

Why does this matter? args is a pointer only, so it occupies 8 bytes of the stack. The structure is only for type correctness.

Juergen

maintainer
#18 lore raw
In reply to Ingo Molnar
Quoted 47 lines · Ingo Molnar
Quoted 44 lines · Juergen Gross
Quoted 42 lines · Peter Zijlstra
Quoted 29 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/xen/mmu_pv.c +0 -0
index 4d62c07..d850762 100644

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 9 lines
arch/x86/xen/mmu_pv.c +0 -4
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

Quoted 3 lines
Quoted 1 line

This only a pointer to the bitmap.

What's the maximum NR_CPUs for configs that can run this code, times 8?

Why does this matter? args is a pointer only, so it occupies 8 bytes of the stack. The structure is only for type correctness.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

maintainer
#19 lore raw
In reply to Peter Zijlstra
Quoted 34 lines · Peter Zijlstra
Quoted 33 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/xen/mmu_pv.c +0 -1
index 4d62c07..d850762 100644
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
Quoted 8 lines

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 5 lines
arch/x86/xen/mmu_pv.c +0 -3
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

This only a pointer to the bitmap.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#20 lore raw
In reply to Nick Desaulniers
Quoted 29 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/xen/mmu_pv.c +0 -0
index 4d62c07..d850762 100644

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1329

Quoted 9 lines
arch/x86/xen/mmu_pv.c +0 -4
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;

Why is it OK for Xen to place this bitmap on-stack in the first place? That NR_CPUS thing can be fairly huge.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#21 lore raw

PATCH v2 1/1 x86: xen: remove the use of VLAIS

In reply to Juergen Gross

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

---
Changes in v2:
* Change mask to us DECLARE_BITMAP instead of pointer, as suggested.
* Update commit message to remove mention of pointer.
* Update sizeof calculation to work with array rather than pointer.

 arch/x86/xen/mmu_pv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/xen/mmu_pv.c +3 -5
index 4d62c07..d850762 100644
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
 		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
 	} *args;
 	struct multicall_space mcs;
+	const size_t mc_entry_size = sizeof(args->op) +
+		sizeof(args->mask[0]) * BITS_TO_LONGS(num_possible_cpus());
 
 	trace_xen_mmu_flush_tlb_others(cpus, info->mm, info->start, info->end);
 
 	if (cpumask_empty(cpus))
 		return;		/* nothing to do */
 
-	mcs = xen_mc_entry(sizeof(*args));
+	mcs = xen_mc_entry(mc_entry_size);
 	args = mcs.args;
 	args->op.arg2.vcpumask = to_cpumask(args->mask);
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
maintainer
#22 lore raw
In reply to Nick Desaulniers
Quoted 5 lines · Nick Desaulniers

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Quoted 7 lines

Here, the VLAIS was used because the size of the bitmap returned from xen_mc_entry() depended on possibly (based on kernel configuration) runtime sized data. Rather than declaring args as a VLAIS then calling sizeof on *args, we can define the variable length array (mask) to be a pointer, and calculate the appropriate sizeof args manually. Further, we can get rid of the #ifdef's and rely on num_possible_cpus() (thanks to a helpful checkpatch warning from an earlier version of this patch).

Using a pointer for mask seems to be wrong, as it is never initialized.

Why don't you just use:

DECLARE_BITMAP(mask, NR_CPUS);

and drop the #ifdef, while keeping the manual length calculation?

Juergen

Quoted 26 lines
---
 arch/x86/xen/mmu_pv.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
arch/x86/xen/mmu_pv.c +3 -5
index 4d62c07..966976c 100644
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 {
 	struct {
 		struct mmuext_op op;
-#ifdef CONFIG_SMP
-		DECLARE_BITMAP(mask, num_processors);
-#else
-		DECLARE_BITMAP(mask, NR_CPUS);
-#endif
+		unsigned long *mask;
 	} *args;
 	struct multicall_space mcs;
+	const size_t mc_entry_size = sizeof(args->op) +
+		sizeof(*args->mask) * BITS_TO_LONGS(num_possible_cpus());
 

arch/x86/xen/mmu_pv.c static void xen_flush_tlb_others(const struct cpumask *cpus, · line 1342

Quoted 10 lines
arch/x86/xen/mmu_pv.c +1 -1
 	trace_xen_mmu_flush_tlb_others(cpus, info->mm, info->start, info->end);
 
 	if (cpumask_empty(cpus))
 		return;		/* nothing to do */
 
-	mcs = xen_mc_entry(sizeof(*args));
+	mcs = xen_mc_entry(mc_entry_size);
 	args = mcs.args;
 	args->op.arg2.vcpumask = to_cpumask(args->mask);
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel