All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/19] Permission Indirection Extension
@ 2023-04-13 11:04 Joey Gouly
  2023-04-13 11:04 ` [PATCH v2 01/19] arm64/sysreg: Add ID register ID_AA64MMFR3 Joey Gouly
                   ` (18 more replies)
  0 siblings, 19 replies; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:04 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Hi all,

This series implements the Permission Indirection Extension introduced in 2022
VMSA enhancements [1].

Changes since v1 [2]:
	- Renamed PIRx_ELx_PERMIDX and reversed the arguments
	- Added new registers to get-reg-list selftest
	- Added booting requirements
	- Add TCR2_EL2 and PIR_EL2 registers
	- Collected review tags
	- Rebased onto arm64/for-next/core (b2ad9d4e249), to get Mark Brown's
	  HFG* register commit.

The Permission Indirection Extension is a new way to set memory permissions.
Instead of directly encoding the permission in the Page Table Entry (PTE),
fields in the PTEs are used to index into an array of permissions specified in
a register. This indirection provides greater flexibility, greater encoding
density and enables the representation of new permissions.

The PTEs bit that are repurposed for use with permission indirection are:
	54 PTE_UXN
	53 PTE_PXN
	51 PTE_DBM
	6 PTE_USER

The way that PIE is implemented in this patchset is that the encodings are
picked such that they match how Linux currently sets the bits in the PTEs, so
none of the page table handling has changed. This means this patchset keeps the
same functionality as currently implemented, but allows for future expansion.

Enabling PIE is also a prerequisite for implementing the Guarded Control Stack
Extension (GCS).

Another related extension is the Permission Overlay Extension, which is not
covered by this patch set, but is mentioned in patch 5 as half of PIE encoding
values apply an overlay. However, since overlays are not currently enabled, they
act as all the other permissions do.

This first few patches are adding the new system registers, and cpufeature
capabilities. Then KVM support for save/restore of the new registers is added.
Finally the new Permission Indirection registers are set and the new feature is
enabled.

Kristina's series [3] changes how HCRX_EL2 is handled, so there will be need to be
some minor changes, depending on which series goes in first.

Thanks,
Joey

Joey Gouly (19):
  arm64/sysreg: Add ID register ID_AA64MMFR3
  arm64/sysreg: add system registers TCR2_ELx
  arm64/sysreg: update HCRX_EL2 register
  arm64/sysreg: add PIR*_ELx registers
  arm64: cpufeature: add system register ID_AA64MMFR3
  arm64: cpufeature: add TCR2 cpucap
  arm64: cpufeature: add Permission Indirection Extension cpucap
  KVM: arm64: Save/restore TCR2_EL1
  KVM: arm64: Save/restore PIE registers
  KVM: arm64: expose ID_AA64MMFR3_EL1 to guests
  arm64: add PTE_UXN/PTE_WRITE to SWAPPER_*_FLAGS
  arm64: add PTE_WRITE to PROT_SECT_NORMAL
  arm64: reorganise PAGE_/PROT_ macros
  arm64: disable EL2 traps for PIE
  arm64: add encodings of PIRx_ELx registers
  arm64: enable Permission Indirection Extension (PIE)
  arm64: transfer permission indirection settings to EL2
  arm64: Document boot requirements for PIE
  KVM: selftests: get-reg-list: add Permission Indirection registers

 Documentation/arm64/booting.rst               |  26 +++
 arch/arm64/include/asm/cpu.h                  |   1 +
 arch/arm64/include/asm/el2_setup.h            |  23 ++-
 arch/arm64/include/asm/kernel-pgtable.h       |   4 +-
 arch/arm64/include/asm/kvm_host.h             |   5 +
 arch/arm64/include/asm/pgtable-hwdef.h        |   8 +
 arch/arm64/include/asm/pgtable-prot.h         |  96 ++++++++---
 arch/arm64/include/asm/sysreg.h               |  19 +++
 arch/arm64/kernel/cpufeature.c                |  32 ++++
 arch/arm64/kernel/cpuinfo.c                   |   1 +
 arch/arm64/kernel/head.S                      |   8 +-
 arch/arm64/kernel/hyp-stub.S                  |  18 ++
 arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h    |  12 ++
 arch/arm64/kvm/sys_regs.c                     |   5 +-
 arch/arm64/mm/proc.S                          |  17 +-
 arch/arm64/tools/cpucaps                      |   2 +
 arch/arm64/tools/sysreg                       | 159 +++++++++++++++++-
 .../selftests/kvm/aarch64/get-reg-list.c      |   5 +-
 18 files changed, 402 insertions(+), 39 deletions(-)

-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 01/19] arm64/sysreg: Add ID register ID_AA64MMFR3
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
@ 2023-04-13 11:04 ` Joey Gouly
  2023-04-13 11:14   ` Mark Brown
  2023-04-13 16:13   ` Catalin Marinas
  2023-04-13 11:04 ` [PATCH v2 02/19] arm64/sysreg: add system registers TCR2_ELx Joey Gouly
                   ` (17 subsequent siblings)
  18 siblings, 2 replies; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:04 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Add the new ID register ID_AA64MMFR3.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
---
 arch/arm64/tools/sysreg | 66 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/arch/arm64/tools/sysreg b/arch/arm64/tools/sysreg
index 2af92b4f4fe4..0acbc2112f1e 100644
--- a/arch/arm64/tools/sysreg
+++ b/arch/arm64/tools/sysreg
@@ -1538,6 +1538,72 @@ UnsignedEnum	3:0	CnP
 EndEnum
 EndSysreg
 
+Sysreg	ID_AA64MMFR3_EL1	3	0	0	7	3
+Enum	63:60	Spec_FPACC
+	0b0000	NI
+	0b0001	IMP
+EndEnum
+Enum	59:56	ADERR
+	0b0000	NI
+	0b0001	DEV_ASYNC
+	0b0010	FEAT_ADERR
+EndEnum
+Enum	55:52	SDERR
+	0b0000	NI
+	0b0001	DEV_SYNC
+	0b0001	FEAT_SDERR
+EndEnum
+Res0	51:48
+Enum	47:44	ANERR
+	0b0000	ASYNC
+	0b0001	FEAT_ANERR
+EndEnum
+Enum	43:40	SNERR
+	0b0000	SYNC
+	0b0001	FEAT_SNERR
+EndEnum
+Enum	39:36	D128_2
+	0b0000	NI
+	0b0001	IMP
+EndEnum
+Enum	35:32	D128
+	0b0000	NI
+	0b0001	IMP
+EndEnum
+Enum	31:28	MEC
+	0b0000	NI
+	0b0001	IMP
+EndEnum
+Enum	27:24	AIE
+	0b0000	NI
+	0b0001	IMP
+EndEnum
+Enum	23:20	S2POE
+	0b0000	NI
+	0b0001	IMP
+EndEnum
+Enum	19:16	S1POE
+	0b0000	NI
+	0b0001	IMP
+EndEnum
+Enum	15:12	S2PIE
+	0b0000	NI
+	0b0001	IMP
+EndEnum
+Enum	11:8	S1PIE
+	0b0000	NI
+	0b0001	IMP
+EndEnum
+Enum	7:4	SCTLRX
+	0b0000	NI
+	0b0001	IMP
+EndEnum
+Enum	3:0	TCRX
+	0b0000	NI
+	0b0001	IMP
+EndEnum
+EndSysreg
+
 Sysreg	SCTLR_EL1	3	0	1	0	0
 Field	63	TIDCP
 Field	62	SPINTMASK
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 02/19] arm64/sysreg: add system registers TCR2_ELx
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
  2023-04-13 11:04 ` [PATCH v2 01/19] arm64/sysreg: Add ID register ID_AA64MMFR3 Joey Gouly
@ 2023-04-13 11:04 ` Joey Gouly
  2023-04-13 16:14   ` Catalin Marinas
  2023-04-13 11:04 ` [PATCH v2 03/19] arm64/sysreg: update HCRX_EL2 register Joey Gouly
                   ` (16 subsequent siblings)
  18 siblings, 1 reply; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:04 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Add definitions of TCR2_EL1, TCR2_EL12 and TCR_EL2 registers.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
Reviewed-by: Mark Brown <broonie@kernel.org>
---
 arch/arm64/tools/sysreg | 42 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/arch/arm64/tools/sysreg b/arch/arm64/tools/sysreg
index 0acbc2112f1e..a63f25261f74 100644
--- a/arch/arm64/tools/sysreg
+++ b/arch/arm64/tools/sysreg
@@ -2150,6 +2150,48 @@ Sysreg	TTBR1_EL1	3	0	2	0	1
 Fields	TTBRx_EL1
 EndSysreg
 
+SysregFields	TCR2_EL1x
+Res0	63:16
+Field	15	DisCH1
+Field	14	DisCH0
+Res0	13:12
+Field	11	HAFT
+Field	10	PTTWI
+Res0	9:6
+Field	5	D128
+Field	4	AIE
+Field	3	POE
+Field	2	E0POE
+Field	1	PIE
+Field	0	PnCH
+EndSysregFields
+
+Sysreg	TCR2_EL1	3	0	2	0	3
+Fields	TCR2_EL1x
+EndSysreg
+
+Sysreg	TCR2_EL12	3	5	2	0	3
+Fields	TCR2_EL1x
+EndSysreg
+
+Sysreg	TCR2_EL2	3	4	2	0	3
+Res0	63:16
+Field	15	DisCH1
+Field	14	DisCH0
+Field	13	AMEC1
+Field	12	AMEC0
+Field	11	HAFT
+Field	10	PTTWI
+Field	9:8	SKL1
+Field	7:6	SKL0
+Field	5	D128
+Field	4	AIE
+Field	3	POE
+Field	2	E0POE
+Field	1	PIE
+Field	0	PnCH
+EndSysreg
+
 Sysreg	LORSA_EL1	3	0	10	4	0
 Res0	63:52
 Field	51:16	SA
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 03/19] arm64/sysreg: update HCRX_EL2 register
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
  2023-04-13 11:04 ` [PATCH v2 01/19] arm64/sysreg: Add ID register ID_AA64MMFR3 Joey Gouly
  2023-04-13 11:04 ` [PATCH v2 02/19] arm64/sysreg: add system registers TCR2_ELx Joey Gouly
@ 2023-04-13 11:04 ` Joey Gouly
  2023-04-13 11:20   ` Mark Brown
  2023-04-13 16:14   ` Catalin Marinas
  2023-04-13 11:04 ` [PATCH v2 04/19] arm64/sysreg: add PIR*_ELx registers Joey Gouly
                   ` (15 subsequent siblings)
  18 siblings, 2 replies; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:04 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Update the HCRX_EL2 register with new bit definitions.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
---
 arch/arm64/tools/sysreg | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/tools/sysreg b/arch/arm64/tools/sysreg
index a63f25261f74..6e8aa9070513 100644
--- a/arch/arm64/tools/sysreg
+++ b/arch/arm64/tools/sysreg
@@ -2035,7 +2035,17 @@ Fields	ZCR_ELx
 EndSysreg
 
 Sysreg	HCRX_EL2	3	4	1	2	2
-Res0	63:12
+Res0	63:23
+Field	22	GCSEn
+Field	21	EnIDCP128
+Field	20	EnSDERR
+Field	19	TMEA
+Field	18	EnSNERR
+Field	17	D128En
+Field	16	PTTWI
+Field	15	SCTLR2En
+Field	14	TCR2En
+Res0	13:12
 Field	11	MSCEn
 Field	10	MCE2
 Field	9	CMOW
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 04/19] arm64/sysreg: add PIR*_ELx registers
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (2 preceding siblings ...)
  2023-04-13 11:04 ` [PATCH v2 03/19] arm64/sysreg: update HCRX_EL2 register Joey Gouly
@ 2023-04-13 11:04 ` Joey Gouly
  2023-04-13 16:15   ` Catalin Marinas
  2023-04-13 11:04 ` [PATCH v2 05/19] arm64: cpufeature: add system register ID_AA64MMFR3 Joey Gouly
                   ` (14 subsequent siblings)
  18 siblings, 1 reply; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:04 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Add definitions of PIR_EL1, PIR_EL12, PIRE0_EL1, PIRE0_EL12, and
PIR_EL2 registers.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
Reviewed-by: Mark Brown <broonie@kernel.org>
---
 arch/arm64/include/asm/sysreg.h | 19 ++++++++++++++++
 arch/arm64/tools/sysreg         | 39 +++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index e5ca9ece1606..2b317a24734c 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -756,6 +756,25 @@
 #define ICH_VTR_TDS_SHIFT	19
 #define ICH_VTR_TDS_MASK	(1 << ICH_VTR_TDS_SHIFT)
 
+/*
+ * Permission Indirection Extension (PIE) permission encodings.
+ * Encodings with the _O suffix, have overlays applied (Permission Overlay Extension).
+ */
+#define PIE_NONE_O	0x0
+#define PIE_R_O		0x1
+#define PIE_X_O		0x2
+#define PIE_RX_O	0x3
+#define PIE_RW_O	0x5
+#define PIE_RWnX_O	0x6
+#define PIE_RWX_O	0x7
+#define PIE_R		0x8
+#define PIE_GCS		0x9
+#define PIE_RX		0xa
+#define PIE_RW		0xc
+#define PIE_RWX		0xe
+
+#define PIRx_ELx_PERM(idx, perm)	((perm) << ((idx) * 4))
+
 #define ARM64_FEATURE_FIELD_BITS	4
 
 /* Defined for compatibility only, do not add new users. */
diff --git a/arch/arm64/tools/sysreg b/arch/arm64/tools/sysreg
index 6e8aa9070513..dd2b333334a1 100644
--- a/arch/arm64/tools/sysreg
+++ b/arch/arm64/tools/sysreg
@@ -2202,6 +2202,45 @@ Field	1	PIE
 Field	0	PnCH
 EndSysreg
 
+SysregFields PIRx_ELx
+Field	63:60	Perm15
+Field	59:56	Perm14
+Field	55:52	Perm13
+Field	51:48	Perm12
+Field	47:44	Perm11
+Field	43:40	Perm10
+Field	39:36	Perm9
+Field	35:32	Perm8
+Field	31:28	Perm7
+Field	27:24	Perm6
+Field	23:20	Perm5
+Field	19:16	Perm4
+Field	15:12	Perm3
+Field	11:8	Perm2
+Field	7:4	Perm1
+Field	3:0	Perm0
+EndSysregFields
+
+Sysreg	PIRE0_EL1	3	0	10	2	2
+Fields	PIRx_ELx
+EndSysreg
+
+Sysreg	PIRE0_EL12	3	5	10	2	2
+Fields	PIRx_ELx
+EndSysreg
+
+Sysreg	PIR_EL1		3	0	10	2	3
+Fields	PIRx_ELx
+EndSysreg
+
+Sysreg	PIR_EL12	3	5	10	2	3
+Fields	PIRx_ELx
+EndSysreg
+
+Sysreg	PIR_EL2		3	4	10	2	3
+Fields	PIRx_ELx
+EndSysreg
+
 Sysreg	LORSA_EL1	3	0	10	4	0
 Res0	63:52
 Field	51:16	SA
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 05/19] arm64: cpufeature: add system register ID_AA64MMFR3
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (3 preceding siblings ...)
  2023-04-13 11:04 ` [PATCH v2 04/19] arm64/sysreg: add PIR*_ELx registers Joey Gouly
@ 2023-04-13 11:04 ` Joey Gouly
  2023-04-13 11:05 ` [PATCH v2 06/19] arm64: cpufeature: add TCR2 cpucap Joey Gouly
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:04 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Add new system register ID_AA64MMFR3 to the cpufeature infrastructure.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/include/asm/cpu.h   |  1 +
 arch/arm64/kernel/cpufeature.c | 11 +++++++++++
 arch/arm64/kernel/cpuinfo.c    |  1 +
 3 files changed, 13 insertions(+)

diff --git a/arch/arm64/include/asm/cpu.h b/arch/arm64/include/asm/cpu.h
index fd7a92219eea..e749838b9c5d 100644
--- a/arch/arm64/include/asm/cpu.h
+++ b/arch/arm64/include/asm/cpu.h
@@ -56,6 +56,7 @@ struct cpuinfo_arm64 {
 	u64		reg_id_aa64mmfr0;
 	u64		reg_id_aa64mmfr1;
 	u64		reg_id_aa64mmfr2;
+	u64		reg_id_aa64mmfr3;
 	u64		reg_id_aa64pfr0;
 	u64		reg_id_aa64pfr1;
 	u64		reg_id_aa64zfr0;
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 2e3e55139777..9590335b2ce0 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -389,6 +389,12 @@ static const struct arm64_ftr_bits ftr_id_aa64mmfr2[] = {
 	ARM64_FTR_END,
 };
 
+static const struct arm64_ftr_bits ftr_id_aa64mmfr3[] = {
+	ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR3_EL1_S1PIE_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR3_EL1_TCRX_SHIFT, 4, 0),
+	ARM64_FTR_END,
+};
+
 static const struct arm64_ftr_bits ftr_ctr[] = {
 	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_EXACT, 31, 1, 1), /* RES1 */
 	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, CTR_EL0_DIC_SHIFT, 1, 1),
@@ -715,6 +721,7 @@ static const struct __ftr_reg_entry {
 	ARM64_FTR_REG_OVERRIDE(SYS_ID_AA64MMFR1_EL1, ftr_id_aa64mmfr1,
 			       &id_aa64mmfr1_override),
 	ARM64_FTR_REG(SYS_ID_AA64MMFR2_EL1, ftr_id_aa64mmfr2),
+	ARM64_FTR_REG(SYS_ID_AA64MMFR3_EL1, ftr_id_aa64mmfr3),
 
 	/* Op1 = 0, CRn = 1, CRm = 2 */
 	ARM64_FTR_REG(SYS_ZCR_EL1, ftr_zcr),
@@ -1010,6 +1017,7 @@ void __init init_cpu_features(struct cpuinfo_arm64 *info)
 	init_cpu_ftr_reg(SYS_ID_AA64MMFR0_EL1, info->reg_id_aa64mmfr0);
 	init_cpu_ftr_reg(SYS_ID_AA64MMFR1_EL1, info->reg_id_aa64mmfr1);
 	init_cpu_ftr_reg(SYS_ID_AA64MMFR2_EL1, info->reg_id_aa64mmfr2);
+	init_cpu_ftr_reg(SYS_ID_AA64MMFR3_EL1, info->reg_id_aa64mmfr3);
 	init_cpu_ftr_reg(SYS_ID_AA64PFR0_EL1, info->reg_id_aa64pfr0);
 	init_cpu_ftr_reg(SYS_ID_AA64PFR1_EL1, info->reg_id_aa64pfr1);
 	init_cpu_ftr_reg(SYS_ID_AA64ZFR0_EL1, info->reg_id_aa64zfr0);
@@ -1255,6 +1263,8 @@ void update_cpu_features(int cpu,
 				      info->reg_id_aa64mmfr1, boot->reg_id_aa64mmfr1);
 	taint |= check_update_ftr_reg(SYS_ID_AA64MMFR2_EL1, cpu,
 				      info->reg_id_aa64mmfr2, boot->reg_id_aa64mmfr2);
+	taint |= check_update_ftr_reg(SYS_ID_AA64MMFR3_EL1, cpu,
+				      info->reg_id_aa64mmfr3, boot->reg_id_aa64mmfr3);
 
 	taint |= check_update_ftr_reg(SYS_ID_AA64PFR0_EL1, cpu,
 				      info->reg_id_aa64pfr0, boot->reg_id_aa64pfr0);
@@ -1384,6 +1394,7 @@ u64 __read_sysreg_by_encoding(u32 sys_id)
 	read_sysreg_case(SYS_ID_AA64MMFR0_EL1);
 	read_sysreg_case(SYS_ID_AA64MMFR1_EL1);
 	read_sysreg_case(SYS_ID_AA64MMFR2_EL1);
+	read_sysreg_case(SYS_ID_AA64MMFR3_EL1);
 	read_sysreg_case(SYS_ID_AA64ISAR0_EL1);
 	read_sysreg_case(SYS_ID_AA64ISAR1_EL1);
 	read_sysreg_case(SYS_ID_AA64ISAR2_EL1);
diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
index eb4378c23b3c..9937614c3deb 100644
--- a/arch/arm64/kernel/cpuinfo.c
+++ b/arch/arm64/kernel/cpuinfo.c
@@ -446,6 +446,7 @@ static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info)
 	info->reg_id_aa64mmfr0 = read_cpuid(ID_AA64MMFR0_EL1);
 	info->reg_id_aa64mmfr1 = read_cpuid(ID_AA64MMFR1_EL1);
 	info->reg_id_aa64mmfr2 = read_cpuid(ID_AA64MMFR2_EL1);
+	info->reg_id_aa64mmfr3 = read_cpuid(ID_AA64MMFR3_EL1);
 	info->reg_id_aa64pfr0 = read_cpuid(ID_AA64PFR0_EL1);
 	info->reg_id_aa64pfr1 = read_cpuid(ID_AA64PFR1_EL1);
 	info->reg_id_aa64zfr0 = read_cpuid(ID_AA64ZFR0_EL1);
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 06/19] arm64: cpufeature: add TCR2 cpucap
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (4 preceding siblings ...)
  2023-04-13 11:04 ` [PATCH v2 05/19] arm64: cpufeature: add system register ID_AA64MMFR3 Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-13 11:25   ` Mark Brown
  2023-04-13 11:05 ` [PATCH v2 07/19] arm64: cpufeature: add Permission Indirection Extension cpucap Joey Gouly
                   ` (12 subsequent siblings)
  18 siblings, 1 reply; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

This capability indicates if the system supports the TCR2_ELx system register.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/kernel/cpufeature.c | 10 ++++++++++
 arch/arm64/tools/cpucaps       |  1 +
 2 files changed, 11 insertions(+)

diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 9590335b2ce0..6944d8bbb17c 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -2783,6 +2783,16 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
 		.matches = has_cpuid_feature,
 		.cpu_enable = cpu_enable_dit,
 	},
+	{
+		.capability = ARM64_HAS_TCR2,
+		.type = ARM64_CPUCAP_SYSTEM_FEATURE,
+		.sys_reg = SYS_ID_AA64MMFR3_EL1,
+		.sign = FTR_UNSIGNED,
+		.field_pos = ID_AA64MMFR3_EL1_TCRX_SHIFT,
+		.field_width = 4,
+		.min_field_value = ID_AA64MMFR3_EL1_TCRX_IMP,
+		.matches = has_cpuid_feature,
+	},
 	{},
 };
 
diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps
index 37b1340e9646..5859b9ee7444 100644
--- a/arch/arm64/tools/cpucaps
+++ b/arch/arm64/tools/cpucaps
@@ -41,6 +41,7 @@ HAS_RAS_EXTN
 HAS_RNG
 HAS_SB
 HAS_STAGE2_FWB
+HAS_TCR2
 HAS_TIDCP1
 HAS_TLB_RANGE
 HAS_VIRT_HOST_EXTN
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 07/19] arm64: cpufeature: add Permission Indirection Extension cpucap
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (5 preceding siblings ...)
  2023-04-13 11:05 ` [PATCH v2 06/19] arm64: cpufeature: add TCR2 cpucap Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-13 11:30   ` Mark Brown
  2023-04-13 11:05 ` [PATCH v2 08/19] KVM: arm64: Save/restore TCR2_EL1 Joey Gouly
                   ` (11 subsequent siblings)
  18 siblings, 1 reply; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

This indicates if the system supports PIE. This is a CPUCAP_BOOT_CPU_FEATURE
as the boot CPU will enable PIE if it has it, so secondary CPUs must also
have this feature.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/kernel/cpufeature.c | 11 +++++++++++
 arch/arm64/tools/cpucaps       |  1 +
 2 files changed, 12 insertions(+)

diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 6944d8bbb17c..acbc21963128 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -2793,6 +2793,17 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
 		.min_field_value = ID_AA64MMFR3_EL1_TCRX_IMP,
 		.matches = has_cpuid_feature,
 	},
+	{
+		.desc = "Permission Indirection Extension (PIE)",
+		.capability = ARM64_HAS_PIE,
+		.type = ARM64_CPUCAP_BOOT_CPU_FEATURE,
+		.sys_reg = SYS_ID_AA64MMFR3_EL1,
+		.sign = FTR_UNSIGNED,
+		.field_pos = ID_AA64MMFR3_EL1_S1PIE_SHIFT,
+		.field_width = 4,
+		.min_field_value = ID_AA64MMFR3_EL1_S1PIE_IMP,
+		.matches = has_cpuid_feature,
+	},
 	{},
 };
 
diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps
index 5859b9ee7444..c4c4c59882b8 100644
--- a/arch/arm64/tools/cpucaps
+++ b/arch/arm64/tools/cpucaps
@@ -37,6 +37,7 @@ HAS_NESTED_VIRT
 HAS_NO_FPSIMD
 HAS_NO_HW_PREFETCH
 HAS_PAN
+HAS_PIE
 HAS_RAS_EXTN
 HAS_RNG
 HAS_SB
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 08/19] KVM: arm64: Save/restore TCR2_EL1
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (6 preceding siblings ...)
  2023-04-13 11:05 ` [PATCH v2 07/19] arm64: cpufeature: add Permission Indirection Extension cpucap Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-20  9:13   ` Marc Zyngier
  2023-04-13 11:05 ` [PATCH v2 09/19] KVM: arm64: Save/restore PIE registers Joey Gouly
                   ` (10 subsequent siblings)
  18 siblings, 1 reply; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Define the new system register TCR2_EL1 and context switch it.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Oliver Upton <oliver.upton@linux.dev>
Cc: James Morse <james.morse@arm.com>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Zenghui Yu <yuzenghui@huawei.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/include/asm/kvm_host.h          | 1 +
 arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 4 ++++
 arch/arm64/kvm/sys_regs.c                  | 1 +
 3 files changed, 6 insertions(+)

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index bcd774d74f34..e1137832a01f 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -269,6 +269,7 @@ enum vcpu_sysreg {
 	TTBR0_EL1,	/* Translation Table Base Register 0 */
 	TTBR1_EL1,	/* Translation Table Base Register 1 */
 	TCR_EL1,	/* Translation Control Register */
+	TCR2_EL1,	/* Extended Translation Control Register */
 	ESR_EL1,	/* Exception Syndrome Register */
 	AFSR0_EL1,	/* Auxiliary Fault Status Register 0 */
 	AFSR1_EL1,	/* Auxiliary Fault Status Register 1 */
diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
index 699ea1f8d409..16199a107a47 100644
--- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
+++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
@@ -44,6 +44,8 @@ static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)
 	ctxt_sys_reg(ctxt, TTBR0_EL1)	= read_sysreg_el1(SYS_TTBR0);
 	ctxt_sys_reg(ctxt, TTBR1_EL1)	= read_sysreg_el1(SYS_TTBR1);
 	ctxt_sys_reg(ctxt, TCR_EL1)	= read_sysreg_el1(SYS_TCR);
+	if (cpus_have_final_cap(ARM64_HAS_TCR2))
+		ctxt_sys_reg(ctxt, TCR2_EL1)	= read_sysreg_el1(SYS_TCR2);
 	ctxt_sys_reg(ctxt, ESR_EL1)	= read_sysreg_el1(SYS_ESR);
 	ctxt_sys_reg(ctxt, AFSR0_EL1)	= read_sysreg_el1(SYS_AFSR0);
 	ctxt_sys_reg(ctxt, AFSR1_EL1)	= read_sysreg_el1(SYS_AFSR1);
@@ -114,6 +116,8 @@ static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt)
 	write_sysreg_el1(ctxt_sys_reg(ctxt, CPACR_EL1),	SYS_CPACR);
 	write_sysreg_el1(ctxt_sys_reg(ctxt, TTBR0_EL1),	SYS_TTBR0);
 	write_sysreg_el1(ctxt_sys_reg(ctxt, TTBR1_EL1),	SYS_TTBR1);
+	if (cpus_have_final_cap(ARM64_HAS_TCR2))
+		write_sysreg_el1(ctxt_sys_reg(ctxt, TCR2_EL1),	SYS_TCR2);
 	write_sysreg_el1(ctxt_sys_reg(ctxt, ESR_EL1),	SYS_ESR);
 	write_sysreg_el1(ctxt_sys_reg(ctxt, AFSR0_EL1),	SYS_AFSR0);
 	write_sysreg_el1(ctxt_sys_reg(ctxt, AFSR1_EL1),	SYS_AFSR1);
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 53749d3a0996..5e7e4a433035 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1871,6 +1871,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 	{ SYS_DESC(SYS_TTBR0_EL1), access_vm_reg, reset_unknown, TTBR0_EL1 },
 	{ SYS_DESC(SYS_TTBR1_EL1), access_vm_reg, reset_unknown, TTBR1_EL1 },
 	{ SYS_DESC(SYS_TCR_EL1), access_vm_reg, reset_val, TCR_EL1, 0 },
+	{ SYS_DESC(SYS_TCR2_EL1), NULL, reset_unknown, TCR2_EL1 },
 
 	PTRAUTH_KEY(APIA),
 	PTRAUTH_KEY(APIB),
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 09/19] KVM: arm64: Save/restore PIE registers
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (7 preceding siblings ...)
  2023-04-13 11:05 ` [PATCH v2 08/19] KVM: arm64: Save/restore TCR2_EL1 Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-20  8:36   ` Marc Zyngier
  2023-04-13 11:05 ` [PATCH v2 10/19] KVM: arm64: expose ID_AA64MMFR3_EL1 to guests Joey Gouly
                   ` (9 subsequent siblings)
  18 siblings, 1 reply; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Define the new system registers that PIE introduces and context switch them.
The PIE feature is still hidden from the ID register, and not exposed to a VM.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Oliver Upton <oliver.upton@linux.dev>
Cc: James Morse <james.morse@arm.com>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Zenghui Yu <yuzenghui@huawei.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/include/asm/kvm_host.h          | 4 ++++
 arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 8 ++++++++
 arch/arm64/kvm/sys_regs.c                  | 2 ++
 3 files changed, 14 insertions(+)

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index e1137832a01f..381bd0763abf 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -367,6 +367,10 @@ enum vcpu_sysreg {
 	CNTHCTL_EL2,	/* Counter-timer Hypervisor Control register */
 	SP_EL2,		/* EL2 Stack Pointer */
 
+	/* Permission Indirection Extension registers */
+	PIR_EL1,       /* Permission Indirection Register 1 (EL1) */
+	PIRE0_EL1,     /*  Permission Indirection Register 0 (EL1) */
+
 	NR_SYS_REGS	/* Nothing after this line! */
 };
 
diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
index 16199a107a47..99566bca19a9 100644
--- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
+++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
@@ -55,6 +55,10 @@ static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)
 	ctxt_sys_reg(ctxt, CONTEXTIDR_EL1) = read_sysreg_el1(SYS_CONTEXTIDR);
 	ctxt_sys_reg(ctxt, AMAIR_EL1)	= read_sysreg_el1(SYS_AMAIR);
 	ctxt_sys_reg(ctxt, CNTKCTL_EL1)	= read_sysreg_el1(SYS_CNTKCTL);
+	if (cpus_have_final_cap(ARM64_HAS_PIE)) {
+		ctxt_sys_reg(ctxt, PIR_EL1)	= read_sysreg_el1(SYS_PIR);
+		ctxt_sys_reg(ctxt, PIRE0_EL1)	= read_sysreg_el1(SYS_PIRE0);
+	}
 	ctxt_sys_reg(ctxt, PAR_EL1)	= read_sysreg_par();
 	ctxt_sys_reg(ctxt, TPIDR_EL1)	= read_sysreg(tpidr_el1);
 
@@ -127,6 +131,10 @@ static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt)
 	write_sysreg_el1(ctxt_sys_reg(ctxt, CONTEXTIDR_EL1), SYS_CONTEXTIDR);
 	write_sysreg_el1(ctxt_sys_reg(ctxt, AMAIR_EL1),	SYS_AMAIR);
 	write_sysreg_el1(ctxt_sys_reg(ctxt, CNTKCTL_EL1), SYS_CNTKCTL);
+	if (cpus_have_final_cap(ARM64_HAS_PIE)) {
+		write_sysreg_el1(ctxt_sys_reg(ctxt, PIR_EL1),	SYS_PIR);
+		write_sysreg_el1(ctxt_sys_reg(ctxt, PIRE0_EL1),	SYS_PIRE0);
+	}
 	write_sysreg(ctxt_sys_reg(ctxt, PAR_EL1),	par_el1);
 	write_sysreg(ctxt_sys_reg(ctxt, TPIDR_EL1),	tpidr_el1);
 
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 5e7e4a433035..6e92821b0bea 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1921,6 +1921,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 	{ SYS_DESC(SYS_PMMIR_EL1), trap_raz_wi },
 
 	{ SYS_DESC(SYS_MAIR_EL1), access_vm_reg, reset_unknown, MAIR_EL1 },
+	{ SYS_DESC(SYS_PIRE0_EL1), NULL, reset_unknown, PIRE0_EL1 },
+	{ SYS_DESC(SYS_PIR_EL1), NULL, reset_unknown, PIR_EL1 },
 	{ SYS_DESC(SYS_AMAIR_EL1), access_vm_reg, reset_amair_el1, AMAIR_EL1 },
 
 	{ SYS_DESC(SYS_LORSA_EL1), trap_loregion },
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 10/19] KVM: arm64: expose ID_AA64MMFR3_EL1 to guests
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (8 preceding siblings ...)
  2023-04-13 11:05 ` [PATCH v2 09/19] KVM: arm64: Save/restore PIE registers Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-13 16:15   ` Catalin Marinas
  2023-04-13 11:05 ` [PATCH v2 11/19] arm64: add PTE_UXN/PTE_WRITE to SWAPPER_*_FLAGS Joey Gouly
                   ` (8 subsequent siblings)
  18 siblings, 1 reply; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Now that KVM context switches the appropriate registers, expose ID_AA64MMFR3_EL1
to guests to allow them to use the new features.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Oliver Upton <oliver.upton@linux.dev>
Cc: James Morse <james.morse@arm.com>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Zenghui Yu <yuzenghui@huawei.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 arch/arm64/kvm/sys_regs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 6e92821b0bea..e98d8daa95de 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1851,7 +1851,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 	ID_SANITISED(ID_AA64MMFR0_EL1),
 	ID_SANITISED(ID_AA64MMFR1_EL1),
 	ID_SANITISED(ID_AA64MMFR2_EL1),
-	ID_UNALLOCATED(7,3),
+	ID_SANITISED(ID_AA64MMFR3_EL1),
 	ID_UNALLOCATED(7,4),
 	ID_UNALLOCATED(7,5),
 	ID_UNALLOCATED(7,6),
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 11/19] arm64: add PTE_UXN/PTE_WRITE to SWAPPER_*_FLAGS
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (9 preceding siblings ...)
  2023-04-13 11:05 ` [PATCH v2 10/19] KVM: arm64: expose ID_AA64MMFR3_EL1 to guests Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-13 16:35   ` Catalin Marinas
  2023-04-13 11:05 ` [PATCH v2 12/19] arm64: add PTE_WRITE to PROT_SECT_NORMAL Joey Gouly
                   ` (7 subsequent siblings)
  18 siblings, 1 reply; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

With PIE enabled, the swapper PTEs would have a Permission Indirection Index
(PIIndex) of 0. A PIIndex of 0 is not currently used by any other PTEs.

To avoid using index 0 specifically for the swapper PTEs, mark them as
PTE_UXN and PTE_WRITE, so that they map to a PAGE_KERNEL_EXEC equivalent.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
---
 arch/arm64/include/asm/kernel-pgtable.h | 4 ++--
 arch/arm64/kernel/head.S                | 8 ++++----
 arch/arm64/mm/proc.S                    | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h
index fcd14197756f..daf1909116f6 100644
--- a/arch/arm64/include/asm/kernel-pgtable.h
+++ b/arch/arm64/include/asm/kernel-pgtable.h
@@ -104,8 +104,8 @@
 /*
  * Initial memory map attributes.
  */
-#define SWAPPER_PTE_FLAGS	(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
-#define SWAPPER_PMD_FLAGS	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
+#define SWAPPER_PTE_FLAGS	(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED | PTE_UXN | PTE_WRITE)
+#define SWAPPER_PMD_FLAGS	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S | PTE_UXN | PTE_WRITE)
 
 #ifdef CONFIG_ARM64_4K_PAGES
 #define SWAPPER_RW_MMUFLAGS	(PMD_ATTRINDX(MT_NORMAL) | SWAPPER_PMD_FLAGS)
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index b98970907226..989e2132af14 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -382,7 +382,7 @@ SYM_FUNC_START_LOCAL(create_idmap)
 	adrp	x0, init_idmap_pg_dir
 	adrp	x3, _text
 	adrp	x6, _end + MAX_FDT_SIZE + SWAPPER_BLOCK_SIZE
-	mov	x7, SWAPPER_RX_MMUFLAGS
+	mov_q	x7, SWAPPER_RX_MMUFLAGS
 
 	map_memory x0, x1, x3, x6, x7, x3, IDMAP_PGD_ORDER, x10, x11, x12, x13, x14, EXTRA_SHIFT
 
@@ -391,7 +391,7 @@ SYM_FUNC_START_LOCAL(create_idmap)
 	adrp	x2, init_pg_dir
 	adrp	x3, init_pg_end
 	bic	x4, x2, #SWAPPER_BLOCK_SIZE - 1
-	mov	x5, SWAPPER_RW_MMUFLAGS
+	mov_q	x5, SWAPPER_RW_MMUFLAGS
 	mov	x6, #SWAPPER_BLOCK_SHIFT
 	bl	remap_region
 
@@ -402,7 +402,7 @@ SYM_FUNC_START_LOCAL(create_idmap)
 	bfi	x22, x21, #0, #SWAPPER_BLOCK_SHIFT		// remapped FDT address
 	add	x3, x2, #MAX_FDT_SIZE + SWAPPER_BLOCK_SIZE
 	bic	x4, x21, #SWAPPER_BLOCK_SIZE - 1
-	mov	x5, SWAPPER_RW_MMUFLAGS
+	mov_q	x5, SWAPPER_RW_MMUFLAGS
 	mov	x6, #SWAPPER_BLOCK_SHIFT
 	bl	remap_region
 
@@ -430,7 +430,7 @@ SYM_FUNC_START_LOCAL(create_kernel_mapping)
 	adrp	x3, _text			// runtime __pa(_text)
 	sub	x6, x6, x3			// _end - _text
 	add	x6, x6, x5			// runtime __va(_end)
-	mov	x7, SWAPPER_RW_MMUFLAGS
+	mov_q	x7, SWAPPER_RW_MMUFLAGS
 
 	map_memory x0, x1, x5, x6, x7, x3, (VA_BITS - PGDIR_SHIFT), x10, x11, x12, x13, x14
 
diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index 91410f488090..644e8daa25df 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -290,7 +290,7 @@ SYM_TYPED_FUNC_START(idmap_kpti_install_ng_mappings)
 	isb
 
 	mov	temp_pte, x5
-	mov	pte_flags, #KPTI_NG_PTE_FLAGS
+	mov_q	pte_flags, KPTI_NG_PTE_FLAGS
 
 	/* Everybody is enjoying the idmap, so we can rewrite swapper. */
 	/* PGD */
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 12/19] arm64: add PTE_WRITE to PROT_SECT_NORMAL
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (10 preceding siblings ...)
  2023-04-13 11:05 ` [PATCH v2 11/19] arm64: add PTE_UXN/PTE_WRITE to SWAPPER_*_FLAGS Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-13 11:05 ` [PATCH v2 13/19] arm64: reorganise PAGE_/PROT_ macros Joey Gouly
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

With PIE enabled, PROT_SECT_NORMAL would map onto PAGE_KERNEL_RO.
Add PTE_WRITE so that this maps onto PAGE_KERNEL, so that it is writable.

Without PIE, this should enable DBM for PROT_SECT_NORMAL. However PTE_RDONLY
is already cleared, so the DBM mechanism is not used, and it is always writable,
so this is functionally equivalent.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/include/asm/pgtable-prot.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h
index 9b165117a454..d26d0b427c0a 100644
--- a/arch/arm64/include/asm/pgtable-prot.h
+++ b/arch/arm64/include/asm/pgtable-prot.h
@@ -60,7 +60,7 @@ extern bool arm64_use_ng_mappings;
 #define PROT_NORMAL_TAGGED	(PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_TAGGED))
 
 #define PROT_SECT_DEVICE_nGnRE	(PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_DEVICE_nGnRE))
-#define PROT_SECT_NORMAL	(PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL))
+#define PROT_SECT_NORMAL	(PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PTE_WRITE | PMD_ATTRINDX(MT_NORMAL))
 #define PROT_SECT_NORMAL_EXEC	(PROT_SECT_DEFAULT | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL))
 
 #define _PAGE_DEFAULT		(_PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL))
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 13/19] arm64: reorganise PAGE_/PROT_ macros
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (11 preceding siblings ...)
  2023-04-13 11:05 ` [PATCH v2 12/19] arm64: add PTE_WRITE to PROT_SECT_NORMAL Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-13 11:05 ` [PATCH v2 14/19] arm64: disable EL2 traps for PIE Joey Gouly
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Make these macros available to assembly code, so they can be re-used by the
PIE initialisation code.

This involves adding some extra macros, prepended with _ that are the raw
values not `pgprot` values.

A dummy value for PTE_MAYBE_NG is also provided, for use in assembly.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/include/asm/pgtable-prot.h | 72 ++++++++++++++++-----------
 1 file changed, 44 insertions(+), 28 deletions(-)

diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h
index d26d0b427c0a..a45af0a22b25 100644
--- a/arch/arm64/include/asm/pgtable-prot.h
+++ b/arch/arm64/include/asm/pgtable-prot.h
@@ -27,6 +27,40 @@
  */
 #define PMD_PRESENT_INVALID	(_AT(pteval_t, 1) << 59) /* only when !PMD_SECT_VALID */
 
+#define _PROT_DEFAULT		(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
+#define _PROT_SECT_DEFAULT	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
+
+#define PROT_DEFAULT		(_PROT_DEFAULT | PTE_MAYBE_NG)
+#define PROT_SECT_DEFAULT	(_PROT_SECT_DEFAULT | PMD_MAYBE_NG)
+
+#define PROT_DEVICE_nGnRnE	(PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRnE))
+#define PROT_DEVICE_nGnRE	(PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRE))
+#define PROT_NORMAL_NC		(PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_NC))
+#define PROT_NORMAL		(PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL))
+#define PROT_NORMAL_TAGGED	(PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_TAGGED))
+
+#define PROT_SECT_DEVICE_nGnRE	(PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_DEVICE_nGnRE))
+#define PROT_SECT_NORMAL	(PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PTE_WRITE | PMD_ATTRINDX(MT_NORMAL))
+#define PROT_SECT_NORMAL_EXEC	(PROT_SECT_DEFAULT | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL))
+
+#define _PAGE_DEFAULT		(_PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL))
+
+#define _PAGE_KERNEL		(PROT_NORMAL)
+#define _PAGE_KERNEL_RO		((PROT_NORMAL & ~PTE_WRITE) | PTE_RDONLY)
+#define _PAGE_KERNEL_ROX	((PROT_NORMAL & ~(PTE_WRITE | PTE_PXN)) | PTE_RDONLY)
+#define _PAGE_KERNEL_EXEC	(PROT_NORMAL & ~PTE_PXN)
+#define _PAGE_KERNEL_EXEC_CONT	((PROT_NORMAL & ~PTE_PXN) | PTE_CONT)
+
+#define _PAGE_SHARED		(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN | PTE_WRITE)
+#define _PAGE_SHARED_EXEC	(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_WRITE)
+#define _PAGE_READONLY		(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN)
+#define _PAGE_READONLY_EXEC	(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN)
+#define _PAGE_EXECONLY		(_PAGE_DEFAULT | PTE_RDONLY | PTE_NG | PTE_PXN)
+
+#ifdef __ASSEMBLY__
+#define PTE_MAYBE_NG	0
+#endif
+
 #ifndef __ASSEMBLY__
 
 #include <asm/cpufeature.h>
@@ -34,9 +68,6 @@
 
 extern bool arm64_use_ng_mappings;
 
-#define _PROT_DEFAULT		(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
-#define _PROT_SECT_DEFAULT	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
-
 #define PTE_MAYBE_NG		(arm64_use_ng_mappings ? PTE_NG : 0)
 #define PMD_MAYBE_NG		(arm64_use_ng_mappings ? PMD_SECT_NG : 0)
 
@@ -50,26 +81,11 @@ extern bool arm64_use_ng_mappings;
 #define PTE_MAYBE_GP		0
 #endif
 
-#define PROT_DEFAULT		(_PROT_DEFAULT | PTE_MAYBE_NG)
-#define PROT_SECT_DEFAULT	(_PROT_SECT_DEFAULT | PMD_MAYBE_NG)
-
-#define PROT_DEVICE_nGnRnE	(PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRnE))
-#define PROT_DEVICE_nGnRE	(PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRE))
-#define PROT_NORMAL_NC		(PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_NC))
-#define PROT_NORMAL		(PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL))
-#define PROT_NORMAL_TAGGED	(PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_TAGGED))
-
-#define PROT_SECT_DEVICE_nGnRE	(PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_DEVICE_nGnRE))
-#define PROT_SECT_NORMAL	(PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PTE_WRITE | PMD_ATTRINDX(MT_NORMAL))
-#define PROT_SECT_NORMAL_EXEC	(PROT_SECT_DEFAULT | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL))
-
-#define _PAGE_DEFAULT		(_PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL))
-
-#define PAGE_KERNEL		__pgprot(PROT_NORMAL)
-#define PAGE_KERNEL_RO		__pgprot((PROT_NORMAL & ~PTE_WRITE) | PTE_RDONLY)
-#define PAGE_KERNEL_ROX		__pgprot((PROT_NORMAL & ~(PTE_WRITE | PTE_PXN)) | PTE_RDONLY)
-#define PAGE_KERNEL_EXEC	__pgprot(PROT_NORMAL & ~PTE_PXN)
-#define PAGE_KERNEL_EXEC_CONT	__pgprot((PROT_NORMAL & ~PTE_PXN) | PTE_CONT)
+#define PAGE_KERNEL		__pgprot(_PAGE_KERNEL)
+#define PAGE_KERNEL_RO		__pgprot(_PAGE_KERNEL_RO)
+#define PAGE_KERNEL_ROX		__pgprot(_PAGE_KERNEL_ROX)
+#define PAGE_KERNEL_EXEC	__pgprot(_PAGE_KERNEL_EXEC)
+#define PAGE_KERNEL_EXEC_CONT	__pgprot(_PAGE_KERNEL_EXEC_CONT)
 
 #define PAGE_S2_MEMATTR(attr, has_fwb)					\
 	({								\
@@ -83,11 +99,11 @@ extern bool arm64_use_ng_mappings;
 
 #define PAGE_NONE		__pgprot(((_PAGE_DEFAULT) & ~PTE_VALID) | PTE_PROT_NONE | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN)
 /* shared+writable pages are clean by default, hence PTE_RDONLY|PTE_WRITE */
-#define PAGE_SHARED		__pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN | PTE_WRITE)
-#define PAGE_SHARED_EXEC	__pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_WRITE)
-#define PAGE_READONLY		__pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN)
-#define PAGE_READONLY_EXEC	__pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN)
-#define PAGE_EXECONLY		__pgprot(_PAGE_DEFAULT | PTE_RDONLY | PTE_NG | PTE_PXN)
+#define PAGE_SHARED		__pgprot(_PAGE_SHARED)
+#define PAGE_SHARED_EXEC	__pgprot(_PAGE_SHARED_EXEC)
+#define PAGE_READONLY		__pgprot(_PAGE_READONLY)
+#define PAGE_READONLY_EXEC	__pgprot(_PAGE_READONLY_EXEC)
+#define PAGE_EXECONLY		__pgprot(_PAGE_EXECONLY)
 
 #endif /* __ASSEMBLY__ */
 
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 14/19] arm64: disable EL2 traps for PIE
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (12 preceding siblings ...)
  2023-04-13 11:05 ` [PATCH v2 13/19] arm64: reorganise PAGE_/PROT_ macros Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-13 16:42   ` Catalin Marinas
  2023-04-13 11:05 ` [PATCH v2 15/19] arm64: add encodings of PIRx_ELx registers Joey Gouly
                   ` (4 subsequent siblings)
  18 siblings, 1 reply; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Disable trapping of TCR2_EL1 and PIRx_EL1 registers, so they can be
accessed from by EL1.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Reviewed-by: Mark Brown <broonie@kernel.org>
---
 arch/arm64/include/asm/el2_setup.h | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h
index 037724b19c5c..67a967647628 100644
--- a/arch/arm64/include/asm/el2_setup.h
+++ b/arch/arm64/include/asm/el2_setup.h
@@ -22,6 +22,17 @@
 	isb
 .endm
 
+.macro __init_el2_hcrx
+	mrs	x1, id_aa64mmfr1_el1
+	ubfx	x0, x1, #ID_AA64MMFR1_EL1_HCX_SHIFT, 4
+	cbz	x0, .Lskip_hcrx_\@
+
+	mrs_s	x0, SYS_HCRX_EL2
+	orr	x0, x0, #HCRX_EL2_TCR2En
+	msr_s	SYS_HCRX_EL2, x0
+.Lskip_hcrx_\@:
+.endm
+
 /*
  * Allow Non-secure EL1 and EL0 to access physical timer and counter.
  * This is not necessary for VHE, since the host kernel runs in EL2,
@@ -150,12 +161,21 @@
 	mov	x0, xzr
 	mrs	x1, id_aa64pfr1_el1
 	ubfx	x1, x1, #ID_AA64PFR1_EL1_SME_SHIFT, #4
-	cbz	x1, .Lset_fgt_\@
+	cbz	x1, .Lset_pie_fgt_\@
 
 	/* Disable nVHE traps of TPIDR2 and SMPRI */
 	orr	x0, x0, #HFGxTR_EL2_nSMPRI_EL1_MASK
 	orr	x0, x0, #HFGxTR_EL2_nTPIDR2_EL0_MASK
 
+.Lset_pie_fgt_\@:
+	mrs_s	x1, SYS_ID_AA64MMFR3_EL1
+	ubfx	x1, x1, #ID_AA64MMFR3_EL1_S1PIE_SHIFT, #4
+	cbz	x1, .Lset_fgt_\@
+
+	/* Disable trapping of PIR_EL1 / PIRE0_EL1 */
+	orr	x0, x0, #HFGxTR_EL2_nPIR_EL1
+	orr	x0, x0, #HFGxTR_EL2_nPIRE0_EL1
+
 .Lset_fgt_\@:
 	msr_s	SYS_HFGRTR_EL2, x0
 	msr_s	SYS_HFGWTR_EL2, x0
@@ -184,6 +204,7 @@
  */
 .macro init_el2_state
 	__init_el2_sctlr
+	__init_el2_hcrx
 	__init_el2_timers
 	__init_el2_debug
 	__init_el2_lor
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 15/19] arm64: add encodings of PIRx_ELx registers
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (13 preceding siblings ...)
  2023-04-13 11:05 ` [PATCH v2 14/19] arm64: disable EL2 traps for PIE Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-18 14:02   ` Mark Brown
  2023-04-13 11:05 ` [PATCH v2 16/19] arm64: enable Permission Indirection Extension (PIE) Joey Gouly
                   ` (3 subsequent siblings)
  18 siblings, 1 reply; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

The encodings used in the permission indirection registers means that the
values that Linux puts in the PTEs do not need to be changed.

The E0 values are replicated in E1, with the execute permissions removed.
This is needed as the futex operations access user mappings with privileged
loads/stores.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/include/asm/pgtable-hwdef.h |  8 ++++++++
 arch/arm64/include/asm/pgtable-prot.h  | 24 ++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h
index f658aafc47df..11c81e700335 100644
--- a/arch/arm64/include/asm/pgtable-hwdef.h
+++ b/arch/arm64/include/asm/pgtable-hwdef.h
@@ -170,6 +170,14 @@
 #define PTE_ATTRINDX(t)		(_AT(pteval_t, (t)) << 2)
 #define PTE_ATTRINDX_MASK	(_AT(pteval_t, 7) << 2)
 
+/*
+ * PIIndex[3:0] encoding (Permission Indirection Extension)
+ */
+#define PTE_PI_IDX_0	6
+#define PTE_PI_IDX_1	51
+#define PTE_PI_IDX_2	53
+#define PTE_PI_IDX_3	54
+
 /*
  * Memory Attribute override for Stage-2 (MemAttr[3:0])
  */
diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h
index a45af0a22b25..f5a6de8588b2 100644
--- a/arch/arm64/include/asm/pgtable-prot.h
+++ b/arch/arm64/include/asm/pgtable-prot.h
@@ -107,4 +107,28 @@ extern bool arm64_use_ng_mappings;
 
 #endif /* __ASSEMBLY__ */
 
+#define pte_pi_index(pte) ( \
+	((pte & BIT(PTE_PI_IDX_3)) >> (PTE_PI_IDX_3 - 3)) | \
+	((pte & BIT(PTE_PI_IDX_2)) >> (PTE_PI_IDX_2 - 2)) | \
+	((pte & BIT(PTE_PI_IDX_1)) >> (PTE_PI_IDX_1 - 1)) | \
+	((pte & BIT(PTE_PI_IDX_0)) >> (PTE_PI_IDX_0 - 0)))
+
+#define PIE_E0	( \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY),      PIE_X_O) | \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_RX)  | \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC),   PIE_RWX) | \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY),      PIE_R)   | \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED),        PIE_RW))
+
+#define PIE_E1	( \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY),      PIE_NONE_O) | \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_R)      | \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC),   PIE_RW)     | \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY),      PIE_R)      | \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED),        PIE_RW)     | \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL_ROX),    PIE_RX)     | \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL_EXEC),   PIE_RWX)    | \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL_RO),     PIE_R)      | \
+	PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL),        PIE_RW))
+
 #endif /* __ASM_PGTABLE_PROT_H */
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 16/19] arm64: enable Permission Indirection Extension (PIE)
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (14 preceding siblings ...)
  2023-04-13 11:05 ` [PATCH v2 15/19] arm64: add encodings of PIRx_ELx registers Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-13 11:05 ` [PATCH v2 17/19] arm64: transfer permission indirection settings to EL2 Joey Gouly
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Now that the necessary changes have been made, set the Permission Indirection
registers and enable the Permission Indirection Extension.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/mm/proc.S | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index 644e8daa25df..c2695e3ffc96 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -454,6 +454,21 @@ SYM_FUNC_START(__cpu_setup)
 #endif	/* CONFIG_ARM64_HW_AFDBM */
 	msr	mair_el1, mair
 	msr	tcr_el1, tcr
+
+	mrs_s	x1, SYS_ID_AA64MMFR3_EL1
+	ubfx	x1, x1, #ID_AA64MMFR3_EL1_S1PIE_SHIFT, #4
+	cbz	x1, .Lskip_indirection
+
+	mov_q	x0, PIE_E0
+	msr	REG_PIRE0_EL1, x0
+	mov_q	x0, PIE_E1
+	msr	REG_PIR_EL1, x0
+
+	mov	x0, TCR2_EL1x_PIE
+	msr	REG_TCR2_EL1, x0
+
+.Lskip_indirection:
+
 	/*
 	 * Prepare SCTLR
 	 */
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 17/19] arm64: transfer permission indirection settings to EL2
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (15 preceding siblings ...)
  2023-04-13 11:05 ` [PATCH v2 16/19] arm64: enable Permission Indirection Extension (PIE) Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-13 11:05 ` [PATCH v2 18/19] arm64: Document boot requirements for PIE Joey Gouly
  2023-04-13 11:05 ` [PATCH v2 19/19] KVM: selftests: get-reg-list: add Permission Indirection registers Joey Gouly
  18 siblings, 0 replies; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Copy the EL1 registers: TCR2_EL1, PIR_EL1, PIRE0_EL1, such that PIE
is also enabled for EL2.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Oliver Upton <oliver.upton@linux.dev>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/kernel/hyp-stub.S | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm64/kernel/hyp-stub.S b/arch/arm64/kernel/hyp-stub.S
index 9439240c3fcf..d63de1973ddb 100644
--- a/arch/arm64/kernel/hyp-stub.S
+++ b/arch/arm64/kernel/hyp-stub.S
@@ -119,6 +119,24 @@ SYM_CODE_START_LOCAL(__finalise_el2)
 	msr	ttbr1_el1, x0
 	mrs_s	x0, SYS_MAIR_EL12
 	msr	mair_el1, x0
+	mrs	x1, REG_ID_AA64MMFR3_EL1
+	ubfx	x1, x1, #ID_AA64MMFR3_EL1_TCRX_SHIFT, #4
+	cbz	x1, .Lskip_tcr2
+	mrs	x0, REG_TCR2_EL12
+	msr	REG_TCR2_EL1, x0
+
+	// Transfer permission indirection state
+	mrs	x1, REG_ID_AA64MMFR3_EL1
+	ubfx	x1, x1, #ID_AA64MMFR3_EL1_S1PIE_SHIFT, #4
+	cbz	x1, .Lskip_indirection
+	mrs	x0, REG_PIRE0_EL12
+	msr	REG_PIRE0_EL1, x0
+	mrs	x0, REG_PIR_EL12
+	msr	REG_PIR_EL1, x0
+
+.Lskip_indirection:
+.Lskip_tcr2:
+
 	isb
 
 	// Hack the exception return to stay at EL2
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 18/19] arm64: Document boot requirements for PIE
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (16 preceding siblings ...)
  2023-04-13 11:05 ` [PATCH v2 17/19] arm64: transfer permission indirection settings to EL2 Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-13 11:45   ` Mark Brown
  2023-04-13 16:45   ` Catalin Marinas
  2023-04-13 11:05 ` [PATCH v2 19/19] KVM: selftests: get-reg-list: add Permission Indirection registers Joey Gouly
  18 siblings, 2 replies; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Features PIE and TCR2 introduce new registers, update the trap requirements
for these features.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
---
 Documentation/arm64/booting.rst | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/Documentation/arm64/booting.rst b/Documentation/arm64/booting.rst
index ffeccdd6bdac..babbf36f0ce2 100644
--- a/Documentation/arm64/booting.rst
+++ b/Documentation/arm64/booting.rst
@@ -379,6 +379,32 @@ Before jumping into the kernel, the following conditions must be met:
 
     - SMCR_EL2.EZT0 (bit 30) must be initialised to 0b1.
 
+  For CPUs with the Extended Translation Control Register feature (FEAT_TCR2):
+
+  - If EL3 is present:
+
+    - SCR_EL3.TCR2En (bit 43) must be initialised to 0b1.
+
+ - If the kernel is entered at EL1 and EL2 is present:
+
+    - HCRX_EL2.TCR2En (bit 14) must be initialised to 0b1.
+
+  For CPUs with the Stage 1 Permission Indirection Extension feature (FEAT_S1PIE):
+
+  - If EL3 is present:
+
+    - SCR_EL3.PIEn (bit 45) must be initialised to 0b1.
+
+  - If the kernel is entered at EL1 and EL2 is present:
+
+    - HFGRTR_EL2.nPIR_EL1 (bit 58) must be initialised to 0b1.
+
+    - HFGWTR_EL2.nPIR_EL1 (bit 58) must be initialised to 0b1.
+
+    - HFGRTR_EL2.nPIRE0_EL1 (bit 57) must be initialised to 0b1.
+
+    - HFGRWR_EL2.nPIRE0_EL1 (bit 57) must be initialised to 0b1.
+
 The requirements described above for CPU mode, caches, MMUs, architected
 timers, coherency and system registers apply to all CPUs.  All CPUs must
 enter the kernel in the same exception level.  Where the values documented
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 19/19] KVM: selftests: get-reg-list: add Permission Indirection registers
  2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
                   ` (17 preceding siblings ...)
  2023-04-13 11:05 ` [PATCH v2 18/19] arm64: Document boot requirements for PIE Joey Gouly
@ 2023-04-13 11:05 ` Joey Gouly
  2023-04-13 16:43   ` Catalin Marinas
  2023-04-13 18:04   ` Mark Brown
  18 siblings, 2 replies; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:05 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: nd, broonie, catalin.marinas, james.morse, joey.gouly,
	mark.rutland, maz, oliver.upton, suzuki.poulose, will, yuzenghui

Add new system registers:
  - ID_AA64MMFR3_EL1
  - TCR2_EL1
  - PIRE0_EL1
  - PIR_EL1

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Oliver Upton <oliver.upton@linux.dev>
Cc: Mark Brown <broonie@kernel.org>
---
 tools/testing/selftests/kvm/aarch64/get-reg-list.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/aarch64/get-reg-list.c b/tools/testing/selftests/kvm/aarch64/get-reg-list.c
index d287dd2cac0a..3731b8183b40 100644
--- a/tools/testing/selftests/kvm/aarch64/get-reg-list.c
+++ b/tools/testing/selftests/kvm/aarch64/get-reg-list.c
@@ -832,7 +832,7 @@ static __u64 base_regs[] = {
 	ARM64_SYS_REG(3, 0, 0, 7, 0),	/* ID_AA64MMFR0_EL1 */
 	ARM64_SYS_REG(3, 0, 0, 7, 1),	/* ID_AA64MMFR1_EL1 */
 	ARM64_SYS_REG(3, 0, 0, 7, 2),	/* ID_AA64MMFR2_EL1 */
-	ARM64_SYS_REG(3, 0, 0, 7, 3),
+	ARM64_SYS_REG(3, 0, 0, 7, 3),	/* ID_AA64MMFR3_EL1 */
 	ARM64_SYS_REG(3, 0, 0, 7, 4),
 	ARM64_SYS_REG(3, 0, 0, 7, 5),
 	ARM64_SYS_REG(3, 0, 0, 7, 6),
@@ -843,12 +843,15 @@ static __u64 base_regs[] = {
 	ARM64_SYS_REG(3, 0, 2, 0, 0),	/* TTBR0_EL1 */
 	ARM64_SYS_REG(3, 0, 2, 0, 1),	/* TTBR1_EL1 */
 	ARM64_SYS_REG(3, 0, 2, 0, 2),	/* TCR_EL1 */
+	ARM64_SYS_REG(3, 0, 2, 0, 3),	/* TCR2_EL1 */
 	ARM64_SYS_REG(3, 0, 5, 1, 0),	/* AFSR0_EL1 */
 	ARM64_SYS_REG(3, 0, 5, 1, 1),	/* AFSR1_EL1 */
 	ARM64_SYS_REG(3, 0, 5, 2, 0),	/* ESR_EL1 */
 	ARM64_SYS_REG(3, 0, 6, 0, 0),	/* FAR_EL1 */
 	ARM64_SYS_REG(3, 0, 7, 4, 0),	/* PAR_EL1 */
 	ARM64_SYS_REG(3, 0, 10, 2, 0),	/* MAIR_EL1 */
+	ARM64_SYS_REG(3, 0, 10, 2, 2),	/* PIRE0_EL1 */
+	ARM64_SYS_REG(3, 0, 10, 2, 3),	/* PIR_EL1 */
 	ARM64_SYS_REG(3, 0, 10, 3, 0),	/* AMAIR_EL1 */
 	ARM64_SYS_REG(3, 0, 12, 0, 0),	/* VBAR_EL1 */
 	ARM64_SYS_REG(3, 0, 12, 1, 1),	/* DISR_EL1 */
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 01/19] arm64/sysreg: Add ID register ID_AA64MMFR3
  2023-04-13 11:04 ` [PATCH v2 01/19] arm64/sysreg: Add ID register ID_AA64MMFR3 Joey Gouly
@ 2023-04-13 11:14   ` Mark Brown
  2023-04-13 11:25     ` Joey Gouly
  2023-04-13 16:13   ` Catalin Marinas
  1 sibling, 1 reply; 42+ messages in thread
From: Mark Brown @ 2023-04-13 11:14 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, catalin.marinas, james.morse, mark.rutland,
	maz, oliver.upton, suzuki.poulose, will, yuzenghui


[-- Attachment #1.1: Type: text/plain, Size: 926 bytes --]

On Thu, Apr 13, 2023 at 12:04:55PM +0100, Joey Gouly wrote:
> Add the new ID register ID_AA64MMFR3.

DDI0601 2023-03 has a few more values which this misses, it looks like
this might have been done against DDO0601 2022-12?  Ideally we'd update
to the new version but it's not urgent so:

Reviewed-by: Mark Brown <broonie@kernel.org>

It's good to note what version of the architecture you're syncing with.

> +Enum	59:56	ADERR
> +	0b0000	NI
> +	0b0001	DEV_ASYNC
> +	0b0010	FEAT_ADERR
> +EndEnum

There's also 0b0011 which on a quick scan I'm not sure what a clear name
for is.

> +Enum	55:52	SDERR
> +	0b0000	NI
> +	0b0001	DEV_SYNC
> +	0b0001	FEAT_SDERR
> +EndEnum

Similar pattern to ADERR here.

> +Res0	51:48
> +Enum	47:44	ANERR
> +	0b0000	ASYNC
> +	0b0001	FEAT_ANERR
> +EndEnum

There's also 0b0010 and 0b0011 for this.

> +Enum	43:40	SNERR
> +	0b0000	SYNC
> +	0b0001	FEAT_SNERR
> +EndEnum

Similar pattern to ANERR here.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 03/19] arm64/sysreg: update HCRX_EL2 register
  2023-04-13 11:04 ` [PATCH v2 03/19] arm64/sysreg: update HCRX_EL2 register Joey Gouly
@ 2023-04-13 11:20   ` Mark Brown
  2023-04-13 16:14   ` Catalin Marinas
  1 sibling, 0 replies; 42+ messages in thread
From: Mark Brown @ 2023-04-13 11:20 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, catalin.marinas, james.morse, mark.rutland,
	maz, oliver.upton, suzuki.poulose, will, yuzenghui


[-- Attachment #1.1: Type: text/plain, Size: 380 bytes --]

On Thu, Apr 13, 2023 at 12:04:57PM +0100, Joey Gouly wrote:
> Update the HCRX_EL2 register with new bit definitions.

Checking against DDI0601 2023-03 this looks OK.

Reviewed-by: Mark Brown <broonie@kernel.org>

>  Sysreg	HCRX_EL2	3	4	1	2	2
> -Res0	63:12
> +Res0	63:23

It would be better to align the bitfield spec for this and the other
Res0, though this is an existing issue.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 06/19] arm64: cpufeature: add TCR2 cpucap
  2023-04-13 11:05 ` [PATCH v2 06/19] arm64: cpufeature: add TCR2 cpucap Joey Gouly
@ 2023-04-13 11:25   ` Mark Brown
  0 siblings, 0 replies; 42+ messages in thread
From: Mark Brown @ 2023-04-13 11:25 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, catalin.marinas, james.morse, mark.rutland,
	maz, oliver.upton, suzuki.poulose, will, yuzenghui


[-- Attachment #1.1: Type: text/plain, Size: 187 bytes --]

On Thu, Apr 13, 2023 at 12:05:00PM +0100, Joey Gouly wrote:
> This capability indicates if the system supports the TCR2_ELx system register.

Reviewed-by: Mark Brown <broonie@kernel.org>

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 01/19] arm64/sysreg: Add ID register ID_AA64MMFR3
  2023-04-13 11:14   ` Mark Brown
@ 2023-04-13 11:25     ` Joey Gouly
  0 siblings, 0 replies; 42+ messages in thread
From: Joey Gouly @ 2023-04-13 11:25 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-arm-kernel, nd, catalin.marinas, james.morse, mark.rutland,
	maz, oliver.upton, suzuki.poulose, will, yuzenghui

On Thu, Apr 13, 2023 at 12:14:59PM +0100, Mark Brown wrote:
> On Thu, Apr 13, 2023 at 12:04:55PM +0100, Joey Gouly wrote:
> > Add the new ID register ID_AA64MMFR3.
> 
> DDI0601 2023-03 has a few more values which this misses, it looks like
> this might have been done against DDO0601 2022-12?  Ideally we'd update
> to the new version but it's not urgent so:
> 
> Reviewed-by: Mark Brown <broonie@kernel.org>
> 
> It's good to note what version of the architecture you're syncing with.
> 
> > +Enum	59:56	ADERR
> > +	0b0000	NI
> > +	0b0001	DEV_ASYNC
> > +	0b0010	FEAT_ADERR
> > +EndEnum
> 
> There's also 0b0011 which on a quick scan I'm not sure what a clear name
> for is.
> 
> > +Enum	55:52	SDERR
> > +	0b0000	NI
> > +	0b0001	DEV_SYNC
> > +	0b0001	FEAT_SDERR
> > +EndEnum
> 
> Similar pattern to ADERR here.
> 
> > +Res0	51:48
> > +Enum	47:44	ANERR
> > +	0b0000	ASYNC
> > +	0b0001	FEAT_ANERR
> > +EndEnum
> 
> There's also 0b0010 and 0b0011 for this.
> 
> > +Enum	43:40	SNERR
> > +	0b0000	SYNC
> > +	0b0001	FEAT_SNERR
> > +EndEnum
> 
> Similar pattern to ANERR here.

Yes I was doing this against a 2022-12 version.

I completely messed up this section though, looks like I accidentaly got rid of
all the `0b0000 NI` values. Will redo this part.

Thanks,
Joey

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 07/19] arm64: cpufeature: add Permission Indirection Extension cpucap
  2023-04-13 11:05 ` [PATCH v2 07/19] arm64: cpufeature: add Permission Indirection Extension cpucap Joey Gouly
@ 2023-04-13 11:30   ` Mark Brown
  0 siblings, 0 replies; 42+ messages in thread
From: Mark Brown @ 2023-04-13 11:30 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, catalin.marinas, james.morse, mark.rutland,
	maz, oliver.upton, suzuki.poulose, will, yuzenghui


[-- Attachment #1.1: Type: text/plain, Size: 752 bytes --]

On Thu, Apr 13, 2023 at 12:05:01PM +0100, Joey Gouly wrote:
> This indicates if the system supports PIE. This is a CPUCAP_BOOT_CPU_FEATURE
> as the boot CPU will enable PIE if it has it, so secondary CPUs must also
> have this feature.

Reviewed-by: Mark Brown <broonie@kernel.org>

> +	{
> +		.desc = "Permission Indirection Extension (PIE)",
> +		.capability = ARM64_HAS_PIE,
> +		.type = ARM64_CPUCAP_BOOT_CPU_FEATURE,
> +		.sys_reg = SYS_ID_AA64MMFR3_EL1,
> +		.sign = FTR_UNSIGNED,
> +		.field_pos = ID_AA64MMFR3_EL1_S1PIE_SHIFT,
> +		.field_width = 4,
> +		.min_field_value = ID_AA64MMFR3_EL1_S1PIE_IMP,
> +		.matches = has_cpuid_feature,
> +	},

It might avoid some future confusion to label this as being stage 1, but
that's just bikeshedding.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 18/19] arm64: Document boot requirements for PIE
  2023-04-13 11:05 ` [PATCH v2 18/19] arm64: Document boot requirements for PIE Joey Gouly
@ 2023-04-13 11:45   ` Mark Brown
  2023-04-13 16:45   ` Catalin Marinas
  1 sibling, 0 replies; 42+ messages in thread
From: Mark Brown @ 2023-04-13 11:45 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, catalin.marinas, james.morse, mark.rutland,
	maz, oliver.upton, suzuki.poulose, will, yuzenghui


[-- Attachment #1.1: Type: text/plain, Size: 329 bytes --]

On Thu, Apr 13, 2023 at 12:05:12PM +0100, Joey Gouly wrote:

> Features PIE and TCR2 introduce new registers, update the trap requirements
> for these features.

Reviewed-by: Mark Brown <broonie@kernel.org>

We could also do S2 and SxPOR while we're at it, but you could say the
same for any feature so it shoudn't be a blocker.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 01/19] arm64/sysreg: Add ID register ID_AA64MMFR3
  2023-04-13 11:04 ` [PATCH v2 01/19] arm64/sysreg: Add ID register ID_AA64MMFR3 Joey Gouly
  2023-04-13 11:14   ` Mark Brown
@ 2023-04-13 16:13   ` Catalin Marinas
  1 sibling, 0 replies; 42+ messages in thread
From: Catalin Marinas @ 2023-04-13 16:13 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, broonie, james.morse, mark.rutland, maz,
	oliver.upton, suzuki.poulose, will, yuzenghui

On Thu, Apr 13, 2023 at 12:04:55PM +0100, Joey Gouly wrote:
> Add the new ID register ID_AA64MMFR3.
> 
> Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Mark Brown <broonie@kernel.org>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 02/19] arm64/sysreg: add system registers TCR2_ELx
  2023-04-13 11:04 ` [PATCH v2 02/19] arm64/sysreg: add system registers TCR2_ELx Joey Gouly
@ 2023-04-13 16:14   ` Catalin Marinas
  0 siblings, 0 replies; 42+ messages in thread
From: Catalin Marinas @ 2023-04-13 16:14 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, broonie, james.morse, mark.rutland, maz,
	oliver.upton, suzuki.poulose, will, yuzenghui

On Thu, Apr 13, 2023 at 12:04:56PM +0100, Joey Gouly wrote:
> Add definitions of TCR2_EL1, TCR2_EL12 and TCR_EL2 registers.
> 
> Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Mark Brown <broonie@kernel.org>
> Reviewed-by: Mark Brown <broonie@kernel.org>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 03/19] arm64/sysreg: update HCRX_EL2 register
  2023-04-13 11:04 ` [PATCH v2 03/19] arm64/sysreg: update HCRX_EL2 register Joey Gouly
  2023-04-13 11:20   ` Mark Brown
@ 2023-04-13 16:14   ` Catalin Marinas
  1 sibling, 0 replies; 42+ messages in thread
From: Catalin Marinas @ 2023-04-13 16:14 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, broonie, james.morse, mark.rutland, maz,
	oliver.upton, suzuki.poulose, will, yuzenghui

On Thu, Apr 13, 2023 at 12:04:57PM +0100, Joey Gouly wrote:
> Update the HCRX_EL2 register with new bit definitions.
> 
> Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Mark Brown <broonie@kernel.org>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 04/19] arm64/sysreg: add PIR*_ELx registers
  2023-04-13 11:04 ` [PATCH v2 04/19] arm64/sysreg: add PIR*_ELx registers Joey Gouly
@ 2023-04-13 16:15   ` Catalin Marinas
  0 siblings, 0 replies; 42+ messages in thread
From: Catalin Marinas @ 2023-04-13 16:15 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, broonie, james.morse, mark.rutland, maz,
	oliver.upton, suzuki.poulose, will, yuzenghui

On Thu, Apr 13, 2023 at 12:04:58PM +0100, Joey Gouly wrote:
> Add definitions of PIR_EL1, PIR_EL12, PIRE0_EL1, PIRE0_EL12, and
> PIR_EL2 registers.
> 
> Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Mark Brown <broonie@kernel.org>
> Reviewed-by: Mark Brown <broonie@kernel.org>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 10/19] KVM: arm64: expose ID_AA64MMFR3_EL1 to guests
  2023-04-13 11:05 ` [PATCH v2 10/19] KVM: arm64: expose ID_AA64MMFR3_EL1 to guests Joey Gouly
@ 2023-04-13 16:15   ` Catalin Marinas
  0 siblings, 0 replies; 42+ messages in thread
From: Catalin Marinas @ 2023-04-13 16:15 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, broonie, james.morse, mark.rutland, maz,
	oliver.upton, suzuki.poulose, will, yuzenghui

On Thu, Apr 13, 2023 at 12:05:04PM +0100, Joey Gouly wrote:
> Now that KVM context switches the appropriate registers, expose ID_AA64MMFR3_EL1
> to guests to allow them to use the new features.
> 
> Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: Oliver Upton <oliver.upton@linux.dev>
> Cc: James Morse <james.morse@arm.com>
> Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
> Cc: Zenghui Yu <yuzenghui@huawei.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 11/19] arm64: add PTE_UXN/PTE_WRITE to SWAPPER_*_FLAGS
  2023-04-13 11:05 ` [PATCH v2 11/19] arm64: add PTE_UXN/PTE_WRITE to SWAPPER_*_FLAGS Joey Gouly
@ 2023-04-13 16:35   ` Catalin Marinas
  2023-04-20 15:29     ` Joey Gouly
  0 siblings, 1 reply; 42+ messages in thread
From: Catalin Marinas @ 2023-04-13 16:35 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, broonie, james.morse, mark.rutland, maz,
	oliver.upton, suzuki.poulose, will, yuzenghui

On Thu, Apr 13, 2023 at 12:05:05PM +0100, Joey Gouly wrote:
> With PIE enabled, the swapper PTEs would have a Permission Indirection Index
> (PIIndex) of 0. A PIIndex of 0 is not currently used by any other PTEs.
> 
> To avoid using index 0 specifically for the swapper PTEs, mark them as
> PTE_UXN and PTE_WRITE, so that they map to a PAGE_KERNEL_EXEC equivalent.
> 
> Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> ---
>  arch/arm64/include/asm/kernel-pgtable.h | 4 ++--
>  arch/arm64/kernel/head.S                | 8 ++++----
>  arch/arm64/mm/proc.S                    | 2 +-
>  3 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h
> index fcd14197756f..daf1909116f6 100644
> --- a/arch/arm64/include/asm/kernel-pgtable.h
> +++ b/arch/arm64/include/asm/kernel-pgtable.h
> @@ -104,8 +104,8 @@
>  /*
>   * Initial memory map attributes.
>   */
> -#define SWAPPER_PTE_FLAGS	(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
> -#define SWAPPER_PMD_FLAGS	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
> +#define SWAPPER_PTE_FLAGS	(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED | PTE_UXN | PTE_WRITE)
> +#define SWAPPER_PMD_FLAGS	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S | PTE_UXN | PTE_WRITE)

I mentioned on the previous version, I think it's better not to add the
PTE_WRITE here but in the users of these macros where writeable is
required (e.g. SWAPPER_RX_MMUFLAGS doesn't need PTE_WRITE as it has
PTE_RDONLY).

-- 
Catalin

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 14/19] arm64: disable EL2 traps for PIE
  2023-04-13 11:05 ` [PATCH v2 14/19] arm64: disable EL2 traps for PIE Joey Gouly
@ 2023-04-13 16:42   ` Catalin Marinas
  0 siblings, 0 replies; 42+ messages in thread
From: Catalin Marinas @ 2023-04-13 16:42 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, broonie, james.morse, mark.rutland, maz,
	oliver.upton, suzuki.poulose, will, yuzenghui

On Thu, Apr 13, 2023 at 12:05:08PM +0100, Joey Gouly wrote:
> Disable trapping of TCR2_EL1 and PIRx_EL1 registers, so they can be
> accessed from by EL1.
> 
> Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Reviewed-by: Mark Brown <broonie@kernel.org>

Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 19/19] KVM: selftests: get-reg-list: add Permission Indirection registers
  2023-04-13 11:05 ` [PATCH v2 19/19] KVM: selftests: get-reg-list: add Permission Indirection registers Joey Gouly
@ 2023-04-13 16:43   ` Catalin Marinas
  2023-04-13 18:04   ` Mark Brown
  1 sibling, 0 replies; 42+ messages in thread
From: Catalin Marinas @ 2023-04-13 16:43 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, broonie, james.morse, mark.rutland, maz,
	oliver.upton, suzuki.poulose, will, yuzenghui

On Thu, Apr 13, 2023 at 12:05:13PM +0100, Joey Gouly wrote:
> Add new system registers:
>   - ID_AA64MMFR3_EL1
>   - TCR2_EL1
>   - PIRE0_EL1
>   - PIR_EL1
> 
> Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: Oliver Upton <oliver.upton@linux.dev>
> Cc: Mark Brown <broonie@kernel.org>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 18/19] arm64: Document boot requirements for PIE
  2023-04-13 11:05 ` [PATCH v2 18/19] arm64: Document boot requirements for PIE Joey Gouly
  2023-04-13 11:45   ` Mark Brown
@ 2023-04-13 16:45   ` Catalin Marinas
  1 sibling, 0 replies; 42+ messages in thread
From: Catalin Marinas @ 2023-04-13 16:45 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, broonie, james.morse, mark.rutland, maz,
	oliver.upton, suzuki.poulose, will, yuzenghui

On Thu, Apr 13, 2023 at 12:05:12PM +0100, Joey Gouly wrote:
> Features PIE and TCR2 introduce new registers, update the trap requirements
> for these features.
> 
> Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Mark Brown <broonie@kernel.org>

Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 19/19] KVM: selftests: get-reg-list: add Permission Indirection registers
  2023-04-13 11:05 ` [PATCH v2 19/19] KVM: selftests: get-reg-list: add Permission Indirection registers Joey Gouly
  2023-04-13 16:43   ` Catalin Marinas
@ 2023-04-13 18:04   ` Mark Brown
  1 sibling, 0 replies; 42+ messages in thread
From: Mark Brown @ 2023-04-13 18:04 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, catalin.marinas, james.morse, mark.rutland,
	maz, oliver.upton, suzuki.poulose, will, yuzenghui


[-- Attachment #1.1: Type: text/plain, Size: 566 bytes --]

On Thu, Apr 13, 2023 at 12:05:13PM +0100, Joey Gouly wrote:
> Add new system registers:
>   - ID_AA64MMFR3_EL1
>   - TCR2_EL1
>   - PIRE0_EL1
>   - PIR_EL1

This generates a test failure for the non-ID registers when run on
anything that doesn't have PIE:

vregs: There are 3 missing registers.
The following lines are missing registers:

	ARM64_SYS_REG(3, 0, 2, 0, 3),
	ARM64_SYS_REG(3, 0, 10, 2, 2),
	ARM64_SYS_REG(3, 0, 10, 2, 3),

...

==== Test Assertion Failure ====
  aarch64/get-reg-list.c:558: !missing_regs && !failed_get && !failed_set && !failed_reject


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 15/19] arm64: add encodings of PIRx_ELx registers
  2023-04-13 11:05 ` [PATCH v2 15/19] arm64: add encodings of PIRx_ELx registers Joey Gouly
@ 2023-04-18 14:02   ` Mark Brown
  0 siblings, 0 replies; 42+ messages in thread
From: Mark Brown @ 2023-04-18 14:02 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, catalin.marinas, james.morse, mark.rutland,
	maz, oliver.upton, suzuki.poulose, will, yuzenghui


[-- Attachment #1.1: Type: text/plain, Size: 3253 bytes --]

On Thu, Apr 13, 2023 at 12:05:09PM +0100, Joey Gouly wrote:

> +/*
> + * PIIndex[3:0] encoding (Permission Indirection Extension)
> + */
> +#define PTE_PI_IDX_0	6
> +#define PTE_PI_IDX_1	51
> +#define PTE_PI_IDX_2	53
> +#define PTE_PI_IDX_3	54

FWIW I locally updated this to:

-#define PTE_PI_IDX_0   6
-#define PTE_PI_IDX_1   51
-#define PTE_PI_IDX_2   53
-#define PTE_PI_IDX_3   54
+#define PTE_PI_IDX_0   6       /* AP[1], USER */
+#define PTE_PI_IDX_1   51      /* DBM */
+#define PTE_PI_IDX_2   53      /* PXN */
+#define PTE_PI_IDX_3   54      /* UXN */

for ease of reference, it is in your cover letter and of course the
architecture but it's handy to have to hand in the code.

> +#define PIE_E0	( \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY),      PIE_X_O) | \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_RX)  | \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC),   PIE_RWX) | \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY),      PIE_R)   | \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED),        PIE_RW))
> +
> +#define PIE_E1	( \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY),      PIE_NONE_O) | \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_R)      | \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC),   PIE_RW)     | \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY),      PIE_R)      | \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED),        PIE_RW)     | \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL_ROX),    PIE_RX)     | \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL_EXEC),   PIE_RWX)    | \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL_RO),     PIE_R)      | \
> +	PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL),        PIE_RW))

I also added this for future reference:

+/*
+ * Page types used via Page Table Indirection (PTI).  PTE uses the
+ * USER, DBM, PXN and UXN bits to to generate an index which is used
+ * to look up the actual permission in PIR_ELx and PIRE0_EL1.  We
+ * define combinations we use on non-PTI systems with the same
+ * encoding, for convenience these are listed here as comments as are
+ * the unallocated encodings.
+ */
+
+/* 0: PAGE_DEFAULT                                                  */
+/* 1:                      PTE_USER                                 */
+/* 2:                      PTE_WRITE                                */
+/* 3:                      PTE_WRITE | PTE_USER                     */
+/* 4: PAGE_EXECONLY        PTE_PXN                                  */
+/* 5: PAGE_READONLY_EXEC   PTE_PXN | PTE_USER                       */
+/* 6:                      PTE_PXN | PTE_WRITE                      */
+/* 7:                      PTE_PXN | PTE_WRITE | PTE_USER           */
+/* 8: PAGE_KERNEL_ROX      PTE_UXN                                  */
+/* 9:                      PTE_UXN | PTE_USER                       */
+/* a: PAGE_KERNEL_EXEC     PTE_UXN | PTE_WRITE                      */
+/* b:                      PTE_UXN | PTE_WRITE | PTE_USER           */
+/* c: PAGE_KERNEL_RO       PTE_UXN | PTE_PXN                        */
+/* d: PAGE_READONLY        PTE_UXN | PTE_PXN | PTE_USER             */
+/* e: PAGE_KERNEL          PTE_UXN | PTE_PXN | PTE_WRITE            */
+/* f: PAGE_SHARED          PTE_UXN | PTE_PXN | PTE_WRITE | PTE_USER */


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 09/19] KVM: arm64: Save/restore PIE registers
  2023-04-13 11:05 ` [PATCH v2 09/19] KVM: arm64: Save/restore PIE registers Joey Gouly
@ 2023-04-20  8:36   ` Marc Zyngier
  0 siblings, 0 replies; 42+ messages in thread
From: Marc Zyngier @ 2023-04-20  8:36 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, broonie, catalin.marinas, james.morse,
	mark.rutland, oliver.upton, suzuki.poulose, will, yuzenghui

On Thu, 13 Apr 2023 12:05:03 +0100,
Joey Gouly <joey.gouly@arm.com> wrote:
> 
> Define the new system registers that PIE introduces and context switch them.
> The PIE feature is still hidden from the ID register, and not exposed to a VM.
> 
> Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: Oliver Upton <oliver.upton@linux.dev>
> Cc: James Morse <james.morse@arm.com>
> Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
> Cc: Zenghui Yu <yuzenghui@huawei.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
> ---
>  arch/arm64/include/asm/kvm_host.h          | 4 ++++
>  arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 8 ++++++++
>  arch/arm64/kvm/sys_regs.c                  | 2 ++
>  3 files changed, 14 insertions(+)
> 
> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> index e1137832a01f..381bd0763abf 100644
> --- a/arch/arm64/include/asm/kvm_host.h
> +++ b/arch/arm64/include/asm/kvm_host.h
> @@ -367,6 +367,10 @@ enum vcpu_sysreg {
>  	CNTHCTL_EL2,	/* Counter-timer Hypervisor Control register */
>  	SP_EL2,		/* EL2 Stack Pointer */
>  
> +	/* Permission Indirection Extension registers */
> +	PIR_EL1,       /* Permission Indirection Register 1 (EL1) */
> +	PIRE0_EL1,     /*  Permission Indirection Register 0 (EL1) */
> +

nit: please move these EL1 register outside of the EL2 range, as it
becomes significant with NV. Next to the MTE register is as good a
place as any.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 08/19] KVM: arm64: Save/restore TCR2_EL1
  2023-04-13 11:05 ` [PATCH v2 08/19] KVM: arm64: Save/restore TCR2_EL1 Joey Gouly
@ 2023-04-20  9:13   ` Marc Zyngier
  2023-04-20 14:11     ` Joey Gouly
  0 siblings, 1 reply; 42+ messages in thread
From: Marc Zyngier @ 2023-04-20  9:13 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, broonie, catalin.marinas, james.morse,
	mark.rutland, oliver.upton, suzuki.poulose, will, yuzenghui

On Thu, 13 Apr 2023 12:05:02 +0100,
Joey Gouly <joey.gouly@arm.com> wrote:
> 
> Define the new system register TCR2_EL1 and context switch it.
> 
> Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: Oliver Upton <oliver.upton@linux.dev>
> Cc: James Morse <james.morse@arm.com>
> Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
> Cc: Zenghui Yu <yuzenghui@huawei.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
> ---
>  arch/arm64/include/asm/kvm_host.h          | 1 +
>  arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 4 ++++
>  arch/arm64/kvm/sys_regs.c                  | 1 +
>  3 files changed, 6 insertions(+)
> 
> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> index bcd774d74f34..e1137832a01f 100644
> --- a/arch/arm64/include/asm/kvm_host.h
> +++ b/arch/arm64/include/asm/kvm_host.h
> @@ -269,6 +269,7 @@ enum vcpu_sysreg {
>  	TTBR0_EL1,	/* Translation Table Base Register 0 */
>  	TTBR1_EL1,	/* Translation Table Base Register 1 */
>  	TCR_EL1,	/* Translation Control Register */
> +	TCR2_EL1,	/* Extended Translation Control Register */
>  	ESR_EL1,	/* Exception Syndrome Register */
>  	AFSR0_EL1,	/* Auxiliary Fault Status Register 0 */
>  	AFSR1_EL1,	/* Auxiliary Fault Status Register 1 */
> diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
> index 699ea1f8d409..16199a107a47 100644
> --- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
> +++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
> @@ -44,6 +44,8 @@ static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)
>  	ctxt_sys_reg(ctxt, TTBR0_EL1)	= read_sysreg_el1(SYS_TTBR0);
>  	ctxt_sys_reg(ctxt, TTBR1_EL1)	= read_sysreg_el1(SYS_TTBR1);
>  	ctxt_sys_reg(ctxt, TCR_EL1)	= read_sysreg_el1(SYS_TCR);
> +	if (cpus_have_final_cap(ARM64_HAS_TCR2))
> +		ctxt_sys_reg(ctxt, TCR2_EL1)	= read_sysreg_el1(SYS_TCR2);
>  	ctxt_sys_reg(ctxt, ESR_EL1)	= read_sysreg_el1(SYS_ESR);
>  	ctxt_sys_reg(ctxt, AFSR0_EL1)	= read_sysreg_el1(SYS_AFSR0);
>  	ctxt_sys_reg(ctxt, AFSR1_EL1)	= read_sysreg_el1(SYS_AFSR1);
> @@ -114,6 +116,8 @@ static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt)
>  	write_sysreg_el1(ctxt_sys_reg(ctxt, CPACR_EL1),	SYS_CPACR);
>  	write_sysreg_el1(ctxt_sys_reg(ctxt, TTBR0_EL1),	SYS_TTBR0);
>  	write_sysreg_el1(ctxt_sys_reg(ctxt, TTBR1_EL1),	SYS_TTBR1);
> +	if (cpus_have_final_cap(ARM64_HAS_TCR2))
> +		write_sysreg_el1(ctxt_sys_reg(ctxt, TCR2_EL1),	SYS_TCR2);
>  	write_sysreg_el1(ctxt_sys_reg(ctxt, ESR_EL1),	SYS_ESR);
>  	write_sysreg_el1(ctxt_sys_reg(ctxt, AFSR0_EL1),	SYS_AFSR0);
>  	write_sysreg_el1(ctxt_sys_reg(ctxt, AFSR1_EL1),	SYS_AFSR1);
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index 53749d3a0996..5e7e4a433035 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -1871,6 +1871,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {
>  	{ SYS_DESC(SYS_TTBR0_EL1), access_vm_reg, reset_unknown, TTBR0_EL1 },
>  	{ SYS_DESC(SYS_TTBR1_EL1), access_vm_reg, reset_unknown, TTBR1_EL1 },
>  	{ SYS_DESC(SYS_TCR_EL1), access_vm_reg, reset_val, TCR_EL1, 0 },
> +	{ SYS_DESC(SYS_TCR2_EL1), NULL, reset_unknown, TCR2_EL1 },

I'm not convinced reset_unknown is the right thing, at least for the
bits that are defined as "If EL2 and EL3 is not implemented, this bit
resets to 0b0 on a reset."

Given that an EL1 guest isn't in control of EL2, I'm a bit wary that
we start execution of the guest in a context that isn't well defined.
My strong preference would be to reset TCR2 just like TCR, unless you
can provide a explanation of why UNKNOWN is actually more correct.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 08/19] KVM: arm64: Save/restore TCR2_EL1
  2023-04-20  9:13   ` Marc Zyngier
@ 2023-04-20 14:11     ` Joey Gouly
  0 siblings, 0 replies; 42+ messages in thread
From: Joey Gouly @ 2023-04-20 14:11 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: linux-arm-kernel, nd, broonie, catalin.marinas, james.morse,
	mark.rutland, oliver.upton, suzuki.poulose, will, yuzenghui

Hi,

On Thu, Apr 20, 2023 at 10:13:38AM +0100, Marc Zyngier wrote:
> On Thu, 13 Apr 2023 12:05:02 +0100,
> Joey Gouly <joey.gouly@arm.com> wrote:
> > 
> > Define the new system register TCR2_EL1 and context switch it.
> > 
> > Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> > Cc: Marc Zyngier <maz@kernel.org>
> > Cc: Oliver Upton <oliver.upton@linux.dev>
> > Cc: James Morse <james.morse@arm.com>
> > Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
> > Cc: Zenghui Yu <yuzenghui@huawei.com>
> > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > Cc: Will Deacon <will@kernel.org>
> > Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
> > ---
> >  arch/arm64/include/asm/kvm_host.h          | 1 +
> >  arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 4 ++++
> >  arch/arm64/kvm/sys_regs.c                  | 1 +
> >  3 files changed, 6 insertions(+)
> > 
> > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> > index bcd774d74f34..e1137832a01f 100644
> > --- a/arch/arm64/include/asm/kvm_host.h
> > +++ b/arch/arm64/include/asm/kvm_host.h
> > @@ -269,6 +269,7 @@ enum vcpu_sysreg {
> >  	TTBR0_EL1,	/* Translation Table Base Register 0 */
> >  	TTBR1_EL1,	/* Translation Table Base Register 1 */
> >  	TCR_EL1,	/* Translation Control Register */
> > +	TCR2_EL1,	/* Extended Translation Control Register */
> >  	ESR_EL1,	/* Exception Syndrome Register */
> >  	AFSR0_EL1,	/* Auxiliary Fault Status Register 0 */
> >  	AFSR1_EL1,	/* Auxiliary Fault Status Register 1 */
> > diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
> > index 699ea1f8d409..16199a107a47 100644
> > --- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
> > +++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
> > @@ -44,6 +44,8 @@ static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)
> >  	ctxt_sys_reg(ctxt, TTBR0_EL1)	= read_sysreg_el1(SYS_TTBR0);
> >  	ctxt_sys_reg(ctxt, TTBR1_EL1)	= read_sysreg_el1(SYS_TTBR1);
> >  	ctxt_sys_reg(ctxt, TCR_EL1)	= read_sysreg_el1(SYS_TCR);
> > +	if (cpus_have_final_cap(ARM64_HAS_TCR2))
> > +		ctxt_sys_reg(ctxt, TCR2_EL1)	= read_sysreg_el1(SYS_TCR2);
> >  	ctxt_sys_reg(ctxt, ESR_EL1)	= read_sysreg_el1(SYS_ESR);
> >  	ctxt_sys_reg(ctxt, AFSR0_EL1)	= read_sysreg_el1(SYS_AFSR0);
> >  	ctxt_sys_reg(ctxt, AFSR1_EL1)	= read_sysreg_el1(SYS_AFSR1);
> > @@ -114,6 +116,8 @@ static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt)
> >  	write_sysreg_el1(ctxt_sys_reg(ctxt, CPACR_EL1),	SYS_CPACR);
> >  	write_sysreg_el1(ctxt_sys_reg(ctxt, TTBR0_EL1),	SYS_TTBR0);
> >  	write_sysreg_el1(ctxt_sys_reg(ctxt, TTBR1_EL1),	SYS_TTBR1);
> > +	if (cpus_have_final_cap(ARM64_HAS_TCR2))
> > +		write_sysreg_el1(ctxt_sys_reg(ctxt, TCR2_EL1),	SYS_TCR2);
> >  	write_sysreg_el1(ctxt_sys_reg(ctxt, ESR_EL1),	SYS_ESR);
> >  	write_sysreg_el1(ctxt_sys_reg(ctxt, AFSR0_EL1),	SYS_AFSR0);
> >  	write_sysreg_el1(ctxt_sys_reg(ctxt, AFSR1_EL1),	SYS_AFSR1);
> > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> > index 53749d3a0996..5e7e4a433035 100644
> > --- a/arch/arm64/kvm/sys_regs.c
> > +++ b/arch/arm64/kvm/sys_regs.c
> > @@ -1871,6 +1871,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {
> >  	{ SYS_DESC(SYS_TTBR0_EL1), access_vm_reg, reset_unknown, TTBR0_EL1 },
> >  	{ SYS_DESC(SYS_TTBR1_EL1), access_vm_reg, reset_unknown, TTBR1_EL1 },
> >  	{ SYS_DESC(SYS_TCR_EL1), access_vm_reg, reset_val, TCR_EL1, 0 },
> > +	{ SYS_DESC(SYS_TCR2_EL1), NULL, reset_unknown, TCR2_EL1 },
> 
> I'm not convinced reset_unknown is the right thing, at least for the
> bits that are defined as "If EL2 and EL3 is not implemented, this bit
> resets to 0b0 on a reset."
> 
> Given that an EL1 guest isn't in control of EL2, I'm a bit wary that
> we start execution of the guest in a context that isn't well defined.
> My strong preference would be to reset TCR2 just like TCR, unless you
> can provide a explanation of why UNKNOWN is actually more correct.


You're right, I have changed this to reset to 0 like TCR_EL1.

Thanks,
Joey

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 11/19] arm64: add PTE_UXN/PTE_WRITE to SWAPPER_*_FLAGS
  2023-04-13 16:35   ` Catalin Marinas
@ 2023-04-20 15:29     ` Joey Gouly
  2023-04-21  7:52       ` Catalin Marinas
  0 siblings, 1 reply; 42+ messages in thread
From: Joey Gouly @ 2023-04-20 15:29 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: linux-arm-kernel, nd, broonie, james.morse, mark.rutland, maz,
	oliver.upton, suzuki.poulose, will, yuzenghui

Hi,

On Thu, Apr 13, 2023 at 05:35:15PM +0100, Catalin Marinas wrote:
> On Thu, Apr 13, 2023 at 12:05:05PM +0100, Joey Gouly wrote:
> > With PIE enabled, the swapper PTEs would have a Permission Indirection Index
> > (PIIndex) of 0. A PIIndex of 0 is not currently used by any other PTEs.
> > 
> > To avoid using index 0 specifically for the swapper PTEs, mark them as
> > PTE_UXN and PTE_WRITE, so that they map to a PAGE_KERNEL_EXEC equivalent.
> > 
> > Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > Cc: Will Deacon <will@kernel.org>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > ---
> >  arch/arm64/include/asm/kernel-pgtable.h | 4 ++--
> >  arch/arm64/kernel/head.S                | 8 ++++----
> >  arch/arm64/mm/proc.S                    | 2 +-
> >  3 files changed, 7 insertions(+), 7 deletions(-)
> > 
> > diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h
> > index fcd14197756f..daf1909116f6 100644
> > --- a/arch/arm64/include/asm/kernel-pgtable.h
> > +++ b/arch/arm64/include/asm/kernel-pgtable.h
> > @@ -104,8 +104,8 @@
> >  /*
> >   * Initial memory map attributes.
> >   */
> > -#define SWAPPER_PTE_FLAGS	(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
> > -#define SWAPPER_PMD_FLAGS	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
> > +#define SWAPPER_PTE_FLAGS	(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED | PTE_UXN | PTE_WRITE)
> > +#define SWAPPER_PMD_FLAGS	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S | PTE_UXN | PTE_WRITE)
> 
> I mentioned on the previous version, I think it's better not to add the
> PTE_WRITE here but in the users of these macros where writeable is
> required (e.g. SWAPPER_RX_MMUFLAGS doesn't need PTE_WRITE as it has
> PTE_RDONLY).

I didn't ignore the previous comment, I just misunderstood it and thought I
should leave it as is. I've made the change now!

Thanks,
Joey

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 11/19] arm64: add PTE_UXN/PTE_WRITE to SWAPPER_*_FLAGS
  2023-04-20 15:29     ` Joey Gouly
@ 2023-04-21  7:52       ` Catalin Marinas
  0 siblings, 0 replies; 42+ messages in thread
From: Catalin Marinas @ 2023-04-21  7:52 UTC (permalink / raw)
  To: Joey Gouly
  Cc: linux-arm-kernel, nd, broonie, james.morse, mark.rutland, maz,
	oliver.upton, suzuki.poulose, will, yuzenghui

On Thu, Apr 20, 2023 at 04:29:17PM +0100, Joey Gouly wrote:
> On Thu, Apr 13, 2023 at 05:35:15PM +0100, Catalin Marinas wrote:
> > On Thu, Apr 13, 2023 at 12:05:05PM +0100, Joey Gouly wrote:
> > > With PIE enabled, the swapper PTEs would have a Permission Indirection Index
> > > (PIIndex) of 0. A PIIndex of 0 is not currently used by any other PTEs.
> > > 
> > > To avoid using index 0 specifically for the swapper PTEs, mark them as
> > > PTE_UXN and PTE_WRITE, so that they map to a PAGE_KERNEL_EXEC equivalent.
> > > 
> > > Signed-off-by: Joey Gouly <joey.gouly@arm.com>
> > > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > > Cc: Will Deacon <will@kernel.org>
> > > Cc: Mark Rutland <mark.rutland@arm.com>
> > > ---
> > >  arch/arm64/include/asm/kernel-pgtable.h | 4 ++--
> > >  arch/arm64/kernel/head.S                | 8 ++++----
> > >  arch/arm64/mm/proc.S                    | 2 +-
> > >  3 files changed, 7 insertions(+), 7 deletions(-)
> > > 
> > > diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h
> > > index fcd14197756f..daf1909116f6 100644
> > > --- a/arch/arm64/include/asm/kernel-pgtable.h
> > > +++ b/arch/arm64/include/asm/kernel-pgtable.h
> > > @@ -104,8 +104,8 @@
> > >  /*
> > >   * Initial memory map attributes.
> > >   */
> > > -#define SWAPPER_PTE_FLAGS	(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
> > > -#define SWAPPER_PMD_FLAGS	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
> > > +#define SWAPPER_PTE_FLAGS	(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED | PTE_UXN | PTE_WRITE)
> > > +#define SWAPPER_PMD_FLAGS	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S | PTE_UXN | PTE_WRITE)
> > 
> > I mentioned on the previous version, I think it's better not to add the
> > PTE_WRITE here but in the users of these macros where writeable is
> > required (e.g. SWAPPER_RX_MMUFLAGS doesn't need PTE_WRITE as it has
> > PTE_RDONLY).
> 
> I didn't ignore the previous comment, I just misunderstood it and thought I
> should leave it as is.

Yeah, sorry, my comment was confusing.

> I've made the change now!

Thanks.

-- 
Catalin

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-04-21  7:53 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-13 11:04 [PATCH v2 00/19] Permission Indirection Extension Joey Gouly
2023-04-13 11:04 ` [PATCH v2 01/19] arm64/sysreg: Add ID register ID_AA64MMFR3 Joey Gouly
2023-04-13 11:14   ` Mark Brown
2023-04-13 11:25     ` Joey Gouly
2023-04-13 16:13   ` Catalin Marinas
2023-04-13 11:04 ` [PATCH v2 02/19] arm64/sysreg: add system registers TCR2_ELx Joey Gouly
2023-04-13 16:14   ` Catalin Marinas
2023-04-13 11:04 ` [PATCH v2 03/19] arm64/sysreg: update HCRX_EL2 register Joey Gouly
2023-04-13 11:20   ` Mark Brown
2023-04-13 16:14   ` Catalin Marinas
2023-04-13 11:04 ` [PATCH v2 04/19] arm64/sysreg: add PIR*_ELx registers Joey Gouly
2023-04-13 16:15   ` Catalin Marinas
2023-04-13 11:04 ` [PATCH v2 05/19] arm64: cpufeature: add system register ID_AA64MMFR3 Joey Gouly
2023-04-13 11:05 ` [PATCH v2 06/19] arm64: cpufeature: add TCR2 cpucap Joey Gouly
2023-04-13 11:25   ` Mark Brown
2023-04-13 11:05 ` [PATCH v2 07/19] arm64: cpufeature: add Permission Indirection Extension cpucap Joey Gouly
2023-04-13 11:30   ` Mark Brown
2023-04-13 11:05 ` [PATCH v2 08/19] KVM: arm64: Save/restore TCR2_EL1 Joey Gouly
2023-04-20  9:13   ` Marc Zyngier
2023-04-20 14:11     ` Joey Gouly
2023-04-13 11:05 ` [PATCH v2 09/19] KVM: arm64: Save/restore PIE registers Joey Gouly
2023-04-20  8:36   ` Marc Zyngier
2023-04-13 11:05 ` [PATCH v2 10/19] KVM: arm64: expose ID_AA64MMFR3_EL1 to guests Joey Gouly
2023-04-13 16:15   ` Catalin Marinas
2023-04-13 11:05 ` [PATCH v2 11/19] arm64: add PTE_UXN/PTE_WRITE to SWAPPER_*_FLAGS Joey Gouly
2023-04-13 16:35   ` Catalin Marinas
2023-04-20 15:29     ` Joey Gouly
2023-04-21  7:52       ` Catalin Marinas
2023-04-13 11:05 ` [PATCH v2 12/19] arm64: add PTE_WRITE to PROT_SECT_NORMAL Joey Gouly
2023-04-13 11:05 ` [PATCH v2 13/19] arm64: reorganise PAGE_/PROT_ macros Joey Gouly
2023-04-13 11:05 ` [PATCH v2 14/19] arm64: disable EL2 traps for PIE Joey Gouly
2023-04-13 16:42   ` Catalin Marinas
2023-04-13 11:05 ` [PATCH v2 15/19] arm64: add encodings of PIRx_ELx registers Joey Gouly
2023-04-18 14:02   ` Mark Brown
2023-04-13 11:05 ` [PATCH v2 16/19] arm64: enable Permission Indirection Extension (PIE) Joey Gouly
2023-04-13 11:05 ` [PATCH v2 17/19] arm64: transfer permission indirection settings to EL2 Joey Gouly
2023-04-13 11:05 ` [PATCH v2 18/19] arm64: Document boot requirements for PIE Joey Gouly
2023-04-13 11:45   ` Mark Brown
2023-04-13 16:45   ` Catalin Marinas
2023-04-13 11:05 ` [PATCH v2 19/19] KVM: selftests: get-reg-list: add Permission Indirection registers Joey Gouly
2023-04-13 16:43   ` Catalin Marinas
2023-04-13 18:04   ` Mark Brown

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.