diff mbox series

[v3,10/42] arm64/sve: Make sysctl interface for SVE reusable by SME

Message ID 20211019172247.3045838-11-broonie@kernel.org (mailing list archive)
State New, archived
Headers show
Series arm64/sme: Initial support for the Scalable Matrix Extension | expand

Commit Message

Mark Brown Oct. 19, 2021, 5:22 p.m. UTC
The vector length configuration for SME is very similar to that for SVE
so in order to allow reuse refactor the SVE configuration so that it takes
the vector type from the struct ctl_table. Since there's no dedicated space
for this we repurpose the extra1 field to store the vector type, this is
otherwise unused for integer sysctls.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 arch/arm64/kernel/fpsimd.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

Comments

Will Deacon Oct. 21, 2021, 9:55 a.m. UTC | #1
On Tue, Oct 19, 2021 at 06:22:15PM +0100, Mark Brown wrote:
> The vector length configuration for SME is very similar to that for SVE
> so in order to allow reuse refactor the SVE configuration so that it takes
> the vector type from the struct ctl_table. Since there's no dedicated space
> for this we repurpose the extra1 field to store the vector type, this is
> otherwise unused for integer sysctls.
> 
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
>  arch/arm64/kernel/fpsimd.c | 28 +++++++++++++++++-----------
>  1 file changed, 17 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
> index 3474122f9207..53462636b5cf 100644
> --- a/arch/arm64/kernel/fpsimd.c
> +++ b/arch/arm64/kernel/fpsimd.c
> @@ -15,6 +15,7 @@
>  #include <linux/compiler.h>
>  #include <linux/cpu.h>
>  #include <linux/cpu_pm.h>
> +#include <linux/ctype.h>
>  #include <linux/kernel.h>
>  #include <linux/linkage.h>
>  #include <linux/irqflags.h>
> @@ -155,11 +156,6 @@ static int get_default_vl(enum vec_type type)
>  	return READ_ONCE(vl_config[type].__default_vl);
>  }
>  
> -static int get_sve_default_vl(void)
> -{
> -	return get_default_vl(ARM64_VEC_SVE);
> -}
> -
>  #ifdef CONFIG_ARM64_SVE
>  
>  static void set_default_vl(enum vec_type type, int val)
> @@ -172,6 +168,11 @@ static void set_sve_default_vl(int val)
>  	set_default_vl(ARM64_VEC_SVE, val);
>  }
>  
> +static int get_sve_default_vl(void)
> +{
> +	return get_default_vl(ARM64_VEC_SVE);
> +}
> +
>  static void __percpu *efi_sve_state;
>  
>  #else /* ! CONFIG_ARM64_SVE */
> @@ -406,17 +407,21 @@ static unsigned int find_supported_vector_length(enum vec_type type,
>  
>  #if defined(CONFIG_ARM64_SVE) && defined(CONFIG_SYSCTL)
>  
> -static int sve_proc_do_default_vl(struct ctl_table *table, int write,
> +static int vec_proc_do_default_vl(struct ctl_table *table, int write,
>  				  void *buffer, size_t *lenp, loff_t *ppos)
>  {
> -	struct vl_info *info = &vl_info[ARM64_VEC_SVE];
> +	struct vl_info *info = table->extra1;
> +	enum vec_type type = info->type;
>  	int ret;
> -	int vl = get_sve_default_vl();
> +	int vl = get_default_vl(type);
>  	struct ctl_table tmp_table = {
>  		.data = &vl,
>  		.maxlen = sizeof(vl),
>  	};
>  
> +	if (!info)
> +		return -EINVAL;

Is this check actually needed? If so, you've already dereferenced the
pointer.

Will
Mark Brown Oct. 21, 2021, 12:15 p.m. UTC | #2
On Thu, Oct 21, 2021 at 10:55:51AM +0100, Will Deacon wrote:
> On Tue, Oct 19, 2021 at 06:22:15PM +0100, Mark Brown wrote:

> > +	if (!info)
> > +		return -EINVAL;

> Is this check actually needed? If so, you've already dereferenced the
> pointer.

It's redundant, just defensiveness.
diff mbox series

Patch

diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
index 3474122f9207..53462636b5cf 100644
--- a/arch/arm64/kernel/fpsimd.c
+++ b/arch/arm64/kernel/fpsimd.c
@@ -15,6 +15,7 @@ 
 #include <linux/compiler.h>
 #include <linux/cpu.h>
 #include <linux/cpu_pm.h>
+#include <linux/ctype.h>
 #include <linux/kernel.h>
 #include <linux/linkage.h>
 #include <linux/irqflags.h>
@@ -155,11 +156,6 @@  static int get_default_vl(enum vec_type type)
 	return READ_ONCE(vl_config[type].__default_vl);
 }
 
-static int get_sve_default_vl(void)
-{
-	return get_default_vl(ARM64_VEC_SVE);
-}
-
 #ifdef CONFIG_ARM64_SVE
 
 static void set_default_vl(enum vec_type type, int val)
@@ -172,6 +168,11 @@  static void set_sve_default_vl(int val)
 	set_default_vl(ARM64_VEC_SVE, val);
 }
 
+static int get_sve_default_vl(void)
+{
+	return get_default_vl(ARM64_VEC_SVE);
+}
+
 static void __percpu *efi_sve_state;
 
 #else /* ! CONFIG_ARM64_SVE */
@@ -406,17 +407,21 @@  static unsigned int find_supported_vector_length(enum vec_type type,
 
 #if defined(CONFIG_ARM64_SVE) && defined(CONFIG_SYSCTL)
 
-static int sve_proc_do_default_vl(struct ctl_table *table, int write,
+static int vec_proc_do_default_vl(struct ctl_table *table, int write,
 				  void *buffer, size_t *lenp, loff_t *ppos)
 {
-	struct vl_info *info = &vl_info[ARM64_VEC_SVE];
+	struct vl_info *info = table->extra1;
+	enum vec_type type = info->type;
 	int ret;
-	int vl = get_sve_default_vl();
+	int vl = get_default_vl(type);
 	struct ctl_table tmp_table = {
 		.data = &vl,
 		.maxlen = sizeof(vl),
 	};
 
+	if (!info)
+		return -EINVAL;
+
 	ret = proc_dointvec(&tmp_table, write, buffer, lenp, ppos);
 	if (ret || !write)
 		return ret;
@@ -428,7 +433,7 @@  static int sve_proc_do_default_vl(struct ctl_table *table, int write,
 	if (!sve_vl_valid(vl))
 		return -EINVAL;
 
-	set_sve_default_vl(find_supported_vector_length(ARM64_VEC_SVE, vl));
+	set_default_vl(type, find_supported_vector_length(type, vl));
 	return 0;
 }
 
@@ -436,7 +441,8 @@  static struct ctl_table sve_default_vl_table[] = {
 	{
 		.procname	= "sve_default_vector_length",
 		.mode		= 0644,
-		.proc_handler	= sve_proc_do_default_vl,
+		.proc_handler	= vec_proc_do_default_vl,
+		.extra1		= &vl_info[ARM64_VEC_SVE],
 	},
 	{ }
 };
@@ -1107,7 +1113,7 @@  static void fpsimd_flush_thread_vl(enum vec_type type)
 		vl = get_default_vl(type);
 
 	if (WARN_ON(!sve_vl_valid(vl)))
-		vl = SVE_VL_MIN;
+		vl = vl_info[type].min_vl;
 
 	supported_vl = find_supported_vector_length(type, vl);
 	if (WARN_ON(supported_vl != vl))