All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: xen: remove the use of VLAIS
@ 2017-12-24 18:02 Nick Desaulniers
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Desaulniers @ 2017-12-24 18:02 UTC (permalink / raw)
  Cc: Juergen Gross, x86, H. Peter Anvin, Nick Desaulniers, ghackmann,
	linux-kernel, mka, Ingo Molnar, srhines, kees, xen-devel,
	Boris Ostrovsky, Thomas Gleixner

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).

Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
---
 arch/x86/xen/mmu_pv.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
index 4d62c07..966976c 100644
--- a/arch/x86/xen/mmu_pv.c
+++ b/arch/x86/xen/mmu_pv.c
@@ -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.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86: xen: remove the use of VLAIS
  2017-12-24 18:02 Nick Desaulniers
@ 2018-01-02  8:18 ` Juergen Gross
  2018-01-02  8:18 ` Juergen Gross
  1 sibling, 0 replies; 4+ messages in thread
From: Juergen Gross @ 2018-01-02  8:18 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: ghackmann, mka, kees, srhines, Boris Ostrovsky, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin, x86, xen-devel, linux-kernel

On 24/12/17 19:02, Nick Desaulniers wrote:
> 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).

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

> 
> Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
> ---
>  arch/x86/xen/mmu_pv.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
> index 4d62c07..966976c 100644
> --- a/arch/x86/xen/mmu_pv.c
> +++ b/arch/x86/xen/mmu_pv.c
> @@ -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);
>  
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86: xen: remove the use of VLAIS
  2017-12-24 18:02 Nick Desaulniers
  2018-01-02  8:18 ` Juergen Gross
@ 2018-01-02  8:18 ` Juergen Gross
  1 sibling, 0 replies; 4+ messages in thread
From: Juergen Gross @ 2018-01-02  8:18 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: x86, H. Peter Anvin, linux-kernel, ghackmann, mka, Ingo Molnar,
	srhines, kees, xen-devel, Boris Ostrovsky, Thomas Gleixner

On 24/12/17 19:02, Nick Desaulniers wrote:
> 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).

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

> 
> Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
> ---
>  arch/x86/xen/mmu_pv.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
> index 4d62c07..966976c 100644
> --- a/arch/x86/xen/mmu_pv.c
> +++ b/arch/x86/xen/mmu_pv.c
> @@ -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);
>  
> 


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] x86: xen: remove the use of VLAIS
@ 2017-12-24 18:02 Nick Desaulniers
  2018-01-02  8:18 ` Juergen Gross
  2018-01-02  8:18 ` Juergen Gross
  0 siblings, 2 replies; 4+ messages in thread
From: Nick Desaulniers @ 2017-12-24 18:02 UTC (permalink / raw)
  Cc: ghackmann, mka, kees, srhines, Nick Desaulniers, Boris Ostrovsky,
	Juergen Gross, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	xen-devel, linux-kernel

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).

Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
---
 arch/x86/xen/mmu_pv.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
index 4d62c07..966976c 100644
--- a/arch/x86/xen/mmu_pv.c
+++ b/arch/x86/xen/mmu_pv.c
@@ -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.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-01-02  8:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-24 18:02 [PATCH] x86: xen: remove the use of VLAIS Nick Desaulniers
2017-12-24 18:02 Nick Desaulniers
2018-01-02  8:18 ` Juergen Gross
2018-01-02  8:18 ` Juergen Gross

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.