diff mbox series

arm64: Expose SVE2 features for userspace

Message ID 1555609298-10498-1-git-send-email-Dave.Martin@arm.com (mailing list archive)
State New, archived
Headers show
Series arm64: Expose SVE2 features for userspace | expand

Commit Message

Dave Martin April 18, 2019, 5:41 p.m. UTC
This patch provides support for reporting the presence of SVE2 and
its optional features to userspace.

This will also enable visibility of SVE2 for guests, when KVM
support for SVE-enabled guests is available.

Signed-off-by: Dave Martin <Dave.Martin@arm.com>
---

This patch is based on

git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
f645d37e281f ("Merge remote-tracking branch 'arm64/for-next/mmiowb' into for-next/core")

(for Andrew Murray's HWCAP2 support).


Tested with the Arm Fast Model SVE2 plugin.

For KVM, tested with:

git://linux-arm.org/linux-dm.git sve-kvm-fixes/v2/head
http://linux-arm.org/git?p=linux-dm.git;a=shortlog;h=refs/heads/sve-kvm-fixes/v2/head

(which is also now merged to kvmarm/next).

 Documentation/arm64/cpu-feature-registers.txt | 16 ++++++++++++++++
 Documentation/arm64/elf_hwcaps.txt            | 24 ++++++++++++++++++++++++
 Documentation/arm64/sve.txt                   | 17 +++++++++++++++++
 arch/arm64/Kconfig                            |  3 +++
 arch/arm64/include/asm/hwcap.h                |  6 ++++++
 arch/arm64/include/asm/sysreg.h               | 14 ++++++++++++++
 arch/arm64/include/uapi/asm/hwcap.h           |  6 ++++++
 arch/arm64/kernel/cpufeature.c                | 17 ++++++++++++++++-
 arch/arm64/kernel/cpuinfo.c                   |  6 ++++++
 9 files changed, 108 insertions(+), 1 deletion(-)

Comments

Will Deacon April 23, 2019, 3:32 p.m. UTC | #1
On Thu, Apr 18, 2019 at 06:41:38PM +0100, Dave Martin wrote:
> This patch provides support for reporting the presence of SVE2 and
> its optional features to userspace.
> 
> This will also enable visibility of SVE2 for guests, when KVM
> support for SVE-enabled guests is available.
> 
> Signed-off-by: Dave Martin <Dave.Martin@arm.com>

Cheers, I'll pick this up for 5.2.

Will
Dave Martin April 23, 2019, 3:48 p.m. UTC | #2
On Tue, Apr 23, 2019 at 04:32:18PM +0100, Will Deacon wrote:
> On Thu, Apr 18, 2019 at 06:41:38PM +0100, Dave Martin wrote:
> > This patch provides support for reporting the presence of SVE2 and
> > its optional features to userspace.
> > 
> > This will also enable visibility of SVE2 for guests, when KVM
> > support for SVE-enabled guests is available.
> > 
> > Signed-off-by: Dave Martin <Dave.Martin@arm.com>
> 
> Cheers, I'll pick this up for 5.2.

Thanks (assuming no objection from anyone else)

---Dave
Mark Rutland April 23, 2019, 4:28 p.m. UTC | #3
On Thu, Apr 18, 2019 at 06:41:38PM +0100, Dave Martin wrote:
> This patch provides support for reporting the presence of SVE2 and
> its optional features to userspace.
> 
> This will also enable visibility of SVE2 for guests, when KVM
> support for SVE-enabled guests is available.
> 
> Signed-off-by: Dave Martin <Dave.Martin@arm.com>
> ---
> 
> This patch is based on
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
> f645d37e281f ("Merge remote-tracking branch 'arm64/for-next/mmiowb' into for-next/core")
> 
> (for Andrew Murray's HWCAP2 support).
> 
> 
> Tested with the Arm Fast Model SVE2 plugin.
> 
> For KVM, tested with:
> 
> git://linux-arm.org/linux-dm.git sve-kvm-fixes/v2/head
> http://linux-arm.org/git?p=linux-dm.git;a=shortlog;h=refs/heads/sve-kvm-fixes/v2/head
> 
> (which is also now merged to kvmarm/next).
> 
>  Documentation/arm64/cpu-feature-registers.txt | 16 ++++++++++++++++
>  Documentation/arm64/elf_hwcaps.txt            | 24 ++++++++++++++++++++++++
>  Documentation/arm64/sve.txt                   | 17 +++++++++++++++++
>  arch/arm64/Kconfig                            |  3 +++
>  arch/arm64/include/asm/hwcap.h                |  6 ++++++
>  arch/arm64/include/asm/sysreg.h               | 14 ++++++++++++++
>  arch/arm64/include/uapi/asm/hwcap.h           |  6 ++++++
>  arch/arm64/kernel/cpufeature.c                | 17 ++++++++++++++++-
>  arch/arm64/kernel/cpuinfo.c                   |  6 ++++++
>  9 files changed, 108 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/arm64/cpu-feature-registers.txt b/Documentation/arm64/cpu-feature-registers.txt
> index d4b4dd1f..4e47a01 100644
> --- a/Documentation/arm64/cpu-feature-registers.txt
> +++ b/Documentation/arm64/cpu-feature-registers.txt
> @@ -209,6 +209,22 @@ infrastructure:
>       | AT                           | [35-32] |    y    |
>       x--------------------------------------------------x
>  
> +  6) ID_AA64ZFR0_EL1 - SVE feature ID register 0
> +
> +     x--------------------------------------------------x
> +     | Name                         |  bits   | visible |
> +     |--------------------------------------------------|
> +     | SM4                          | [43-40] |    y    |
> +     x--------------------------------------------------x
> +     | SHA3                         | [35-32] |    y    |
> +     x--------------------------------------------------x
> +     | BitPerm                      | [19-16] |    y    |
> +     x--------------------------------------------------x
> +     | AES                          | [7-4]   |    y    |
> +     x--------------------------------------------------x
> +     | SVEVer                       | [3-0]   |    y    |
> +     x--------------------------------------------------x

Trivial nit: for consistency with all the other tables, please only use
'x' at the corners, and use '|' at the edges.

Otherwise, this looks good to me; sorry for the late style nit!

Thanks,
Mark.
Will Deacon April 23, 2019, 4:30 p.m. UTC | #4
On Tue, Apr 23, 2019 at 05:28:52PM +0100, Mark Rutland wrote:
> On Thu, Apr 18, 2019 at 06:41:38PM +0100, Dave Martin wrote:
> > diff --git a/Documentation/arm64/cpu-feature-registers.txt b/Documentation/arm64/cpu-feature-registers.txt
> > index d4b4dd1f..4e47a01 100644
> > --- a/Documentation/arm64/cpu-feature-registers.txt
> > +++ b/Documentation/arm64/cpu-feature-registers.txt
> > @@ -209,6 +209,22 @@ infrastructure:
> >       | AT                           | [35-32] |    y    |
> >       x--------------------------------------------------x
> >  
> > +  6) ID_AA64ZFR0_EL1 - SVE feature ID register 0
> > +
> > +     x--------------------------------------------------x
> > +     | Name                         |  bits   | visible |
> > +     |--------------------------------------------------|
> > +     | SM4                          | [43-40] |    y    |
> > +     x--------------------------------------------------x
> > +     | SHA3                         | [35-32] |    y    |
> > +     x--------------------------------------------------x
> > +     | BitPerm                      | [19-16] |    y    |
> > +     x--------------------------------------------------x
> > +     | AES                          | [7-4]   |    y    |
> > +     x--------------------------------------------------x
> > +     | SVEVer                       | [3-0]   |    y    |
> > +     x--------------------------------------------------x
> 
> Trivial nit: for consistency with all the other tables, please only use
> 'x' at the corners, and use '|' at the edges.
> 
> Otherwise, this looks good to me; sorry for the late style nit!

I'll fix that up in my tree.

Will
Dave Martin April 23, 2019, 4:45 p.m. UTC | #5
On Tue, Apr 23, 2019 at 05:30:17PM +0100, Will Deacon wrote:
> On Tue, Apr 23, 2019 at 05:28:52PM +0100, Mark Rutland wrote:
> > On Thu, Apr 18, 2019 at 06:41:38PM +0100, Dave Martin wrote:
> > > diff --git a/Documentation/arm64/cpu-feature-registers.txt b/Documentation/arm64/cpu-feature-registers.txt
> > > index d4b4dd1f..4e47a01 100644
> > > --- a/Documentation/arm64/cpu-feature-registers.txt
> > > +++ b/Documentation/arm64/cpu-feature-registers.txt
> > > @@ -209,6 +209,22 @@ infrastructure:
> > >       | AT                           | [35-32] |    y    |
> > >       x--------------------------------------------------x
> > >  
> > > +  6) ID_AA64ZFR0_EL1 - SVE feature ID register 0
> > > +
> > > +     x--------------------------------------------------x
> > > +     | Name                         |  bits   | visible |
> > > +     |--------------------------------------------------|
> > > +     | SM4                          | [43-40] |    y    |
> > > +     x--------------------------------------------------x
> > > +     | SHA3                         | [35-32] |    y    |
> > > +     x--------------------------------------------------x
> > > +     | BitPerm                      | [19-16] |    y    |
> > > +     x--------------------------------------------------x
> > > +     | AES                          | [7-4]   |    y    |
> > > +     x--------------------------------------------------x
> > > +     | SVEVer                       | [3-0]   |    y    |
> > > +     x--------------------------------------------------x
> > 
> > Trivial nit: for consistency with all the other tables, please only use
> > 'x' at the corners, and use '|' at the edges.
> > 
> > Otherwise, this looks good to me; sorry for the late style nit!
> 
> I'll fix that up in my tree.

Thanks.  I didn't even spot the difference...

Cheers
---Dave
diff mbox series

Patch

diff --git a/Documentation/arm64/cpu-feature-registers.txt b/Documentation/arm64/cpu-feature-registers.txt
index d4b4dd1f..4e47a01 100644
--- a/Documentation/arm64/cpu-feature-registers.txt
+++ b/Documentation/arm64/cpu-feature-registers.txt
@@ -209,6 +209,22 @@  infrastructure:
      | AT                           | [35-32] |    y    |
      x--------------------------------------------------x
 
+  6) ID_AA64ZFR0_EL1 - SVE feature ID register 0
+
+     x--------------------------------------------------x
+     | Name                         |  bits   | visible |
+     |--------------------------------------------------|
+     | SM4                          | [43-40] |    y    |
+     x--------------------------------------------------x
+     | SHA3                         | [35-32] |    y    |
+     x--------------------------------------------------x
+     | BitPerm                      | [19-16] |    y    |
+     x--------------------------------------------------x
+     | AES                          | [7-4]   |    y    |
+     x--------------------------------------------------x
+     | SVEVer                       | [3-0]   |    y    |
+     x--------------------------------------------------x
+
 Appendix I: Example
 ---------------------------
 
diff --git a/Documentation/arm64/elf_hwcaps.txt b/Documentation/arm64/elf_hwcaps.txt
index 55431fd..b73a251 100644
--- a/Documentation/arm64/elf_hwcaps.txt
+++ b/Documentation/arm64/elf_hwcaps.txt
@@ -163,6 +163,30 @@  HWCAP_SVE
 
     Functionality implied by ID_AA64PFR0_EL1.SVE == 0b0001.
 
+HWCAP2_SVE2
+
+    Functionality implied by ID_AA64ZFR0_EL1.SVEVer == 0b0001.
+
+HWCAP2_SVEAES
+
+    Functionality implied by ID_AA64ZFR0_EL1.AES == 0b0001.
+
+HWCAP2_SVEPMULL
+
+    Functionality implied by ID_AA64ZFR0_EL1.AES == 0b0010.
+
+HWCAP2_SVEBITPERM
+
+    Functionality implied by ID_AA64ZFR0_EL1.BitPerm == 0b0001.
+
+HWCAP2_SVESHA3
+
+    Functionality implied by ID_AA64ZFR0_EL1.SHA3 == 0b0001.
+
+HWCAP2_SVESM4
+
+    Functionality implied by ID_AA64ZFR0_EL1.SM4 == 0b0001.
+
 HWCAP_ASIMDFHM
 
    Functionality implied by ID_AA64ISAR0_EL1.FHM == 0b0001.
diff --git a/Documentation/arm64/sve.txt b/Documentation/arm64/sve.txt
index 7169a0e..9940e92 100644
--- a/Documentation/arm64/sve.txt
+++ b/Documentation/arm64/sve.txt
@@ -34,6 +34,23 @@  model features for SVE is included in Appendix A.
   following sections: software that needs to verify that those interfaces are
   present must check for HWCAP_SVE instead.
 
+* On hardware that supports the SVE2 extensions, HWCAP2_SVE2 will also
+  be reported in the AT_HWCAP2 aux vector entry.  In addition to this,
+  optional extensions to SVE2 may be reported by the presence of:
+
+	HWCAP2_SVE2
+	HWCAP2_SVEAES
+	HWCAP2_SVEPMULL
+	HWCAP2_SVEBITPERM
+	HWCAP2_SVESHA3
+	HWCAP2_SVESM4
+
+  This list may be extended over time as the SVE architecture evolves.
+
+  These extensions are also reported via the CPU ID register ID_AA64ZFR0_EL1,
+  which userspace can read using an MRS instruction.  See elf_hwcaps.txt and
+  cpu-feature-registers.txt for details.
+
 * Debuggers should restrict themselves to interacting with the target via the
   NT_ARM_SVE regset.  The recommended way of detecting support for this regset
   is to connect to a target process first and then attempt a
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index c383625..4d79446 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -1322,6 +1322,9 @@  config ARM64_SVE
 
 	  To enable use of this extension on CPUs that implement it, say Y.
 
+	  On CPUs that support the SVE2 extensions, this option will enable
+	  those too.
+
 	  Note that for architectural reasons, firmware _must_ implement SVE
 	  support when running on SVE capable hardware.  The required support
 	  is present in:
diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h
index f78c86c..b4bfb66 100644
--- a/arch/arm64/include/asm/hwcap.h
+++ b/arch/arm64/include/asm/hwcap.h
@@ -89,6 +89,12 @@ 
 
 #define __khwcap2_feature(x)		(const_ilog2(HWCAP2_ ## x) + 32)
 #define KERNEL_HWCAP_DCPODP		__khwcap2_feature(DCPODP)
+#define KERNEL_HWCAP_SVE2		__khwcap2_feature(SVE2)
+#define KERNEL_HWCAP_SVEAES		__khwcap2_feature(SVEAES)
+#define KERNEL_HWCAP_SVEPMULL		__khwcap2_feature(SVEPMULL)
+#define KERNEL_HWCAP_SVEBITPERM		__khwcap2_feature(SVEBITPERM)
+#define KERNEL_HWCAP_SVESHA3		__khwcap2_feature(SVESHA3)
+#define KERNEL_HWCAP_SVESM4		__khwcap2_feature(SVESM4)
 
 /*
  * This yields a mask that user programs can use to figure out what
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 5b267de..29c6559 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -606,6 +606,20 @@ 
 #define ID_AA64PFR1_SSBS_PSTATE_ONLY	1
 #define ID_AA64PFR1_SSBS_PSTATE_INSNS	2
 
+/* id_aa64zfr0 */
+#define ID_AA64ZFR0_SM4_SHIFT		40
+#define ID_AA64ZFR0_SHA3_SHIFT		32
+#define ID_AA64ZFR0_BITPERM_SHIFT	16
+#define ID_AA64ZFR0_AES_SHIFT		4
+#define ID_AA64ZFR0_SVEVER_SHIFT	0
+
+#define ID_AA64ZFR0_SM4			0x1
+#define ID_AA64ZFR0_SHA3		0x1
+#define ID_AA64ZFR0_BITPERM		0x1
+#define ID_AA64ZFR0_AES			0x1
+#define ID_AA64ZFR0_AES_PMULL		0x2
+#define ID_AA64ZFR0_SVEVER_SVE2		0x1
+
 /* id_aa64mmfr0 */
 #define ID_AA64MMFR0_TGRAN4_SHIFT	28
 #define ID_AA64MMFR0_TGRAN64_SHIFT	24
diff --git a/arch/arm64/include/uapi/asm/hwcap.h b/arch/arm64/include/uapi/asm/hwcap.h
index d64af39..1a772b1 100644
--- a/arch/arm64/include/uapi/asm/hwcap.h
+++ b/arch/arm64/include/uapi/asm/hwcap.h
@@ -57,5 +57,11 @@ 
  * HWCAP2 flags - for AT_HWCAP2
  */
 #define HWCAP2_DCPODP		(1 << 0)
+#define HWCAP2_SVE2		(1 << 1)
+#define HWCAP2_SVEAES		(1 << 2)
+#define HWCAP2_SVEPMULL		(1 << 3)
+#define HWCAP2_SVEBITPERM	(1 << 4)
+#define HWCAP2_SVESHA3		(1 << 5)
+#define HWCAP2_SVESM4		(1 << 6)
 
 #endif /* _UAPI__ASM_HWCAP_H */
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 9d18e45..d856c55 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -184,6 +184,15 @@  static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {
 	ARM64_FTR_END,
 };
 
+static const struct arm64_ftr_bits ftr_id_aa64zfr0[] = {
+	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0),
+	ARM64_FTR_END,
+};
+
 static const struct arm64_ftr_bits ftr_id_aa64mmfr0[] = {
 	S_ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_TGRAN4_SHIFT, 4, ID_AA64MMFR0_TGRAN4_NI),
 	S_ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_TGRAN64_SHIFT, 4, ID_AA64MMFR0_TGRAN64_NI),
@@ -392,7 +401,7 @@  static const struct __ftr_reg_entry {
 	/* Op1 = 0, CRn = 0, CRm = 4 */
 	ARM64_FTR_REG(SYS_ID_AA64PFR0_EL1, ftr_id_aa64pfr0),
 	ARM64_FTR_REG(SYS_ID_AA64PFR1_EL1, ftr_id_aa64pfr1),
-	ARM64_FTR_REG(SYS_ID_AA64ZFR0_EL1, ftr_raz),
+	ARM64_FTR_REG(SYS_ID_AA64ZFR0_EL1, ftr_id_aa64zfr0),
 
 	/* Op1 = 0, CRn = 0, CRm = 5 */
 	ARM64_FTR_REG(SYS_ID_AA64DFR0_EL1, ftr_id_aa64dfr0),
@@ -1610,6 +1619,12 @@  static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = {
 	HWCAP_CAP(SYS_ID_AA64MMFR2_EL1, ID_AA64MMFR2_AT_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_USCAT),
 #ifdef CONFIG_ARM64_SVE
 	HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_SVE_SHIFT, FTR_UNSIGNED, ID_AA64PFR0_SVE, CAP_HWCAP, KERNEL_HWCAP_SVE),
+	HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_SVEVER_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_SVEVER_SVE2, CAP_HWCAP, KERNEL_HWCAP_SVE2),
+	HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_AES_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_AES, CAP_HWCAP, KERNEL_HWCAP_SVEAES),
+	HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_AES_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_AES_PMULL, CAP_HWCAP, KERNEL_HWCAP_SVEPMULL),
+	HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_BITPERM_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_BITPERM, CAP_HWCAP, KERNEL_HWCAP_SVEBITPERM),
+	HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_SHA3_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_SHA3, CAP_HWCAP, KERNEL_HWCAP_SVESHA3),
+	HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_SM4_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_SM4, CAP_HWCAP, KERNEL_HWCAP_SVESM4),
 #endif
 	HWCAP_CAP(SYS_ID_AA64PFR1_EL1, ID_AA64PFR1_SSBS_SHIFT, FTR_UNSIGNED, ID_AA64PFR1_SSBS_PSTATE_INSNS, CAP_HWCAP, KERNEL_HWCAP_SSBS),
 #ifdef CONFIG_ARM64_PTR_AUTH
diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
index 093ca53..f6f7936 100644
--- a/arch/arm64/kernel/cpuinfo.c
+++ b/arch/arm64/kernel/cpuinfo.c
@@ -86,6 +86,12 @@  static const char *const hwcap_str[] = {
 	"paca",
 	"pacg",
 	"dcpodp",
+	"sve2",
+	"sveaes",
+	"svepmull",
+	"svebitperm",
+	"svesha3",
+	"svesm4",
 	NULL
 };