Arm: Enable GICv3 for AArch32
cover Arm: Enable GICv3 for AArch32
Hi All,
Please find the following patches to enable GICv3 for AArch32. This is a pre-requisite to support Xen on Cortex-R52 (AArch32-v8R system)
Let me know your thoughts.
Ayan Kumar Halder (12):
Arm: GICv3: Sysreg emulation is applicable for Aarch64 only
Arm: GICv3: Move the macros to compute the affnity level to
arm64/arm32
Arm: GICv3: Enable vreg_reg64_* macros for AArch32
Arm: GICv3: Emulate GICR_TYPER on AArch32
Arm: GICv3: Emulate GICR_PENDBASER and GICR_PROPBASER on AArch32
Arm: GICv3: Emulate of ICC_SGI1R on AArch32
Arm: GICv3: Emulate ICH_LR<n>_EL2 on AArch32
Arm: GICv3: Define ICH_AP0R<n> and ICH_AP1R<n> for AArch32
Arm: GICv3: Define GIC registers for AArch32
Arm: GICv3: Use ULL instead of UL for 64bits
Arm: GICv3: Define macros to read/write 64 bit
Arm: GICv3: Enable GICv3 for AArch32
xen/arch/arm/Kconfig | 2 +- xen/arch/arm/gic-v3-its.c | 20 ++-- xen/arch/arm/gic-v3-lpi.c | 8 +- xen/arch/arm/gic-v3.c | 132 ++++++++++----------- xen/arch/arm/include/asm/arm32/io.h | 4 + xen/arch/arm/include/asm/arm32/processor.h | 10 ++ xen/arch/arm/include/asm/arm32/sysregs.h | 80 +++++++++++++ xen/arch/arm/include/asm/arm64/processor.h | 13 ++ xen/arch/arm/include/asm/arm64/sysregs.h | 7 +- xen/arch/arm/include/asm/cpufeature.h | 1 + xen/arch/arm/include/asm/gic_v3_defs.h | 24 ++-- xen/arch/arm/include/asm/gic_v3_its.h | 2 +- xen/arch/arm/include/asm/processor.h | 14 --- xen/arch/arm/include/asm/vreg.h | 23 ++-- xen/arch/arm/vgic-v3-its.c | 17 +-- xen/arch/arm/vgic-v3.c | 26 ++-- 16 files changed, 242 insertions(+), 141 deletions(-)
Signature · 1 line
2.17.1
RFC PATCH 1/12 Arm: GICv3: Sysreg emulation is applicable for Aarch64 only
Refer ARM DDI 0487G.b ID072021, EC==0b011000 is supported for Aarch64 state only. This is when MSR, MRS, System instruction execution in AArch64 state is trapped, that is not reported using EC 0b000000, 0b000001 or 0b000111.
--- xen/arch/arm/vgic-v3.c | 4 ++++ 1 file changed, 4 insertions(+)
xen/arch/arm/vgic-v3.c +4 -0
@@ -1520,6 +1520,7 @@ static bool vgic_v3_emulate_sgi1r(struct cpu_user_regs *regs, uint64_t *r, } } +#ifdef CONFIG_ARM_64 static bool vgic_v3_emulate_sysreg (struct cpu_user_regs *regs,union hsr hsr) {struct hsr_sysreg sysreg = hsr.sysreg;
@@ -1540,6 +1541,7 @@ static bool vgic_v3_emulate_sysreg(struct cpu_user_regs *regs, union hsr hsr) return false; } } +#endif static bool vgic_v3_emulate_cp64 (struct cpu_user_regs *regs,union hsr hsr) {
@@ -1563,8 +1565,10 @@ static bool vgic_v3_emulate_reg(struct cpu_user_regs *regs, union hsr hsr) {switch (hsr.ec) { +#ifdef CONFIG_ARM_64 case HSR_EC_SYSREG :return vgic_v3_emulate_sysreg (regs, hsr); +#endif case HSR_EC_CP15_64 :return vgic_v3_emulate_cp64 (regs, hsr);default :
Signature · 1 line
2.17.1
Re: [RFC PATCH v1 01/12] Arm: GICv3: Sysreg emulation is applicable for Aarch64 only
Hi Ayan,
Quoted 3 lines · Ayan Kumar Halder
Refer ARM DDI 0487G.b ID072021, EC==0b011000 is supported for Aarch64 state only. This is when MSR, MRS, System instruction execution in AArch64 state is trapped, that is not reported using EC
0b000000,0b000001or0b000111.
I don't understand the second sentence. However, what matter here is the fact the system registers are 64-bit only.
The change itself, looks ok to me.
Cheers,
Signature · 1 line
Julien Grall
RFC PATCH 2/12 Arm: GICv3: Move the macros to compute the affnity level to arm64/arm32
In reply to Ayan Kumar HalderRefer https://elixir.bootlin.com/linux/v6.1-rc1/source/arch/arm64/ \
include/asm/cputype.h#L14 , these macros are specific for arm64.
When one computes MPIDR_LEVEL_SHIFT(3), it crosses the width of a 32 bit register.
Refer https://elixir.bootlin.com/linux/v6.1-rc1/source/arch/arm/include/ \
asm/cputype.h#L54 , these macros are specific for arm32.
--- xen/arch/arm/include/asm/arm32/processor.h | 10 ++++++++++ xen/arch/arm/include/asm/arm64/processor.h | 13 +++++++++++++ xen/arch/arm/include/asm/processor.h | 14 -------------- 3 files changed, 23 insertions(+), 14 deletions(-)
xen/arch/arm/include/asm/arm32/processor.h +10 -0
@@ -56,6 +56,16 @@ struct cpu_user_regsuint32_t pad1;/* Doubleword-align the user half of the frame */ }; +/* +* Macros to extract affinity level. Picked from kernel +*/ + +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) +#define MPIDR_LEVEL_SHIFT (level) (MPIDR_LEVEL_BITS * level) + +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> (MPIDR_LEVEL_BITS * level)) & MPIDR_LEVEL_MASK) +#endif #endif /* __ASM_ARM_ARM32_PROCESSOR_H */
xen/arch/arm/include/asm/arm64/processor.h +13 -0
@@ -84,6 +84,19 @@ struct cpu_user_regs uint64_t sp_el1, elr_el1; }; +/* +* Macros to extract affinity level. picked from kernel +*/ + +#define MPIDR_LEVEL_BITS_SHIFT 3 +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) + +#define MPIDR_LEVEL_SHIFT (level) \ + (((1 << level) >> 1) << MPIDR_LEVEL_BITS_SHIFT) + +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) +#undef __DECL_REG#endif /* __ASSEMBLY__ */
xen/arch/arm/include/asm/processor.h +0 -14
@@ -118,20 +118,6 @@#define MPIDR_INVALID (~MPIDR_HWID_MASK)#define MPIDR_LEVEL_BITS (8) - -/* -* Macros to extract affinity level. picked from kernel -*/ - -#define MPIDR_LEVEL_BITS_SHIFT 3 -#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) - -#define MPIDR_LEVEL_SHIFT (level) \ - (((1 << (level)) >> 1) << MPIDR_LEVEL_BITS_SHIFT) - -#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ - (((mpidr) >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) -#define AFFINITY_MASK (level) ~((_AC(0x1,UL) << MPIDR_LEVEL_SHIFT(level)) - 1)/* TTBCR Translation Table Base Control Register */
Signature · 1 line
2.17.1
Re: [RFC PATCH v1 02/12] Arm: GICv3: Move the macros to compute the affnity level to arm64/arm32
On 10/21/22 18:31, Ayan Kumar Halder wrote:
Hi Ayan
Quoted 76 lines
Refer https://elixir.bootlin.com/linux/v6.1-rc1/source/arch/arm64/ \
include/asm/cputype.h#L14 , these macros are specific for arm64.When one computes
MPIDR_LEVEL_SHIFT(3), it crosses the width of a 32 bit register.Refer https://elixir.bootlin.com/linux/v6.1-rc1/source/arch/arm/include/ \
asm/cputype.h#L54 , these macros are specific for arm32.Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/include/asm/arm32/processor.h | 10 ++++++++++ xen/arch/arm/include/asm/arm64/processor.h | 13 +++++++++++++ xen/arch/arm/include/asm/processor.h | 14 -------------- 3 files changed, 23 insertions(+), 14 deletions(-)xen/arch/arm/include/asm/arm32/processor.h +10
-0@@ -56,6 +56,16 @@ struct cpu_user_regsuint32_t pad1;/* Doubleword-align the user half of the frame */ }; +/* +* Macros to extract affinity level. Picked from kernel +*/ + +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) +#define MPIDR_LEVEL_SHIFT (level) (MPIDR_LEVEL_BITS * level) + +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> (MPIDR_LEVEL_BITS * level)) & MPIDR_LEVEL_MASK) +#endif #endif /* __ASM_ARM_ARM32_PROCESSOR_H */ xen/arch/arm/include/asm/arm64/processor.h +13
-0@@ -84,6 +84,19 @@ struct cpu_user_regs uint64_t sp_el1, elr_el1; }; +/* +* Macros to extract affinity level. picked from kernel +*/ + +#define MPIDR_LEVEL_BITS_SHIFT 3 +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) + +#define MPIDR_LEVEL_SHIFT (level) \ + (((1 << level) >> 1) << MPIDR_LEVEL_BITS_SHIFT) + +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) +#undef __DECL_REG#endif /* __ASSEMBLY__ */ xen/arch/arm/include/asm/processor.h +0
-7@@ -118,20 +118,6 @@#define MPIDR_INVALID (~MPIDR_HWID_MASK)#define MPIDR_LEVEL_BITS (8) - -/* -* Macros to extract affinity level. picked from kernel -*/ - -#define MPIDR_LEVEL_BITS_SHIFT 3 -#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1)
xen/arch/arm/include/asm/processor.h line 123
Quoted 10 lines
xen/arch/arm/include/asm/processor.h +0
-7- -#define MPIDR_LEVEL_SHIFT (level) \ - (((1 << (level)) >> 1) << MPIDR_LEVEL_BITS_SHIFT) - -#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ - (((mpidr) >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) -#define AFFINITY_MASK (level) ~((_AC(0x1,UL) << MPIDR_LEVEL_SHIFT(level)) - 1)/* TTBCR Translation Table Base Control Register */
Since only the definition of the MPIDR_AFFINITY_LEVEL() differs, maybe you could add only this one to the arch specific headers e.g for arm64:
#define MPIDR_LEVEL_SHIFT(level) \
(((1 << (level)) >> 1) << MPIDR_LEVEL_BITS_SHIFT)
for arm32:
#define MPIDR_LEVEL_SHIFT(level) \
((level) << MPIDR_LEVEL_BITS_SHIFT)But in any case don't forget to add parentheses around the macro parameters when an operator acts on them to avoid trouble with operator precedence (MISRA-C Rule 20.7 :))
Signature · 1 line
Xenia
Re: [RFC PATCH v1 02/12] Arm: GICv3: Move the macros to compute the affnity level to arm64/arm32
Quoted 2 lines · Xenia Ragiadakou
On 10/21/22 18:31, Ayan Kumar Halder wrote:
Hi Ayan
Hi Xenia,
Quoted 82 lines
Quoted 79 lines
Refer https://elixir.bootlin.com/linux/v6.1-rc1/source/arch/arm64/ \
include/asm/cputype.h#L14 , these macros are specific for arm64.When one computes
MPIDR_LEVEL_SHIFT(3), it crosses the width of a 32 bit register.Refer https://elixir.bootlin.com/linux/v6.1-rc1/source/arch/arm/include/ \
asm/cputype.h#L54 , these macros are specific for arm32.Signed-off-by Ayan Kumar Halder <[email protected]>---
xen/arch/arm/include/asm/arm32/processor.h| 10 ++++++++++xen/arch/arm/include/asm/arm64/processor.h| 13 +++++++++++++ xen/arch/arm/include/asm/processor.h | 14 --------------3 files changed, 23 insertions(+), 14 deletions(-)xen/arch/arm/include/asm/arm32/processor.h +0
-0@@ -56,6 +56,16 @@ struct cpu_user_regs
uint32_tpad1; /* Doubleword-align the user half of the frame */ };
+/*
+ * Macros to extract affinity level. Picked from kernel
+ */xen/arch/arm/include/asm/arm32/processor.h +7
-0+ +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) +#define MPIDR_LEVEL_SHIFT (level) (MPIDR_LEVEL_BITS * level) + +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> (MPIDR_LEVEL_BITS * level)) & MPIDR_LEVEL_MASK) +#endif
#endif /*__ASM_ARM_ARM32_PROCESSOR_H*/xen/arch/arm/include/asm/arm64/processor.h +0
-0@@ -84,6 +84,19 @@ struct cpu_user_regs uint64_t sp_el1, elr_el1; };+/*
+ * Macros to extract affinity level. picked from kernel
+ */xen/arch/arm/include/asm/arm64/processor.h +10
-0+ +#define MPIDR_LEVEL_BITS_SHIFT 3 +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) + +#define MPIDR_LEVEL_SHIFT (level) \ + (((1 << level) >> 1) << MPIDR_LEVEL_BITS_SHIFT) + +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) +#undef
__DECL_REG
#endif /*__ASSEMBLY__*/xen/arch/arm/include/asm/processor.h +0
-0@@ -118,20 +118,6 @@ #define MPIDR_INVALID (~MPIDR_HWID_MASK) #define MPIDR_LEVEL_BITS (8)-
xen/arch/arm/include/asm/processor.h +0
-13-/* -* Macros to extract affinity level. picked from kernel -*/ - -#define MPIDR_LEVEL_BITS_SHIFT 3 -#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) - -#define MPIDR_LEVEL_SHIFT (level) \ - (((1 << (level)) >> 1) << MPIDR_LEVEL_BITS_SHIFT) - -#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ - (((mpidr) >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) -Quoted 2 lines
#define AFFINITY_MASK(level) ~((_AC(0x1,UL) <<
MPIDR_LEVEL_SHIFT(level)) - 1) /* TTBCR Translation Table Base Control Register */
Quoted 7 lines
Since only the definition of the
MPIDR_AFFINITY_LEVEL()differs, maybe you could add only this one to the arch specific headers e.g for arm64:
#defineMPIDR_LEVEL_SHIFT(level)\
(((1 << (level)) >> 1) <<MPIDR_LEVEL_BITS_SHIFT)
for arm32:
#defineMPIDR_LEVEL_SHIFT(level)\
((level) <<MPIDR_LEVEL_BITS_SHIFT)
Also, MPIDR_AFFINITY_LEVEL needs to be defined in arch specific headers as it differs between arm32 and arm64.
However, MPIDR_LEVEL_MASK can be defined in the common header (as it is same for arm32 and arm64).
Please let me know if it makes sense.
Quoted 2 lines
But in any case don't forget to add parentheses around the macro parameters when an operator acts on them to avoid trouble with operator precedence (MISRA-C Rule 20.7 :))
Thanks for pointing it out. Yes, this is a mistake in my patches.
- Ayan
Re: [RFC PATCH v1 02/12] Arm: GICv3: Move the macros to compute the affnity level to arm64/arm32
Hi Ayan,
Quoted 31 lines · Ayan Kumar Halder
Quoted 2 lines · Xenia Ragiadakou
On 10/21/22 18:31, Ayan Kumar Halder wrote:
Hi AyanHi Xenia,
Quoted 26 lines
Quoted 26 lines
Refer https://elixir.bootlin.com/linux/v6.1-rc1/source/arch/arm64/ \
include/asm/cputype.h#L14 , these macros are specific for arm64.When one computes
MPIDR_LEVEL_SHIFT(3), it crosses the width of a 32 bit register.Refer https://elixir.bootlin.com/linux/v6.1-rc1/source/arch/arm/include/ \
asm/cputype.h#L54 , these macros are specific for arm32.Signed-off-by Ayan Kumar Halder <[email protected]>---
xen/arch/arm/include/asm/arm32/processor.h| 10 ++++++++++xen/arch/arm/include/asm/arm64/processor.h| 13 +++++++++++++ xen/arch/arm/include/asm/processor.h | 14 --------------3 files changed, 23 insertions(+), 14 deletions(-)xen/arch/arm/include/asm/arm32/processor.h +0
-0@@ -56,6 +56,16 @@ struct cpu_user_regs
uint32_tpad1; /* Doubleword-align the user half of the frame */ };
+/*
+ * Macros to extract affinity level. Picked from kernel
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/include/asm/arm32/processor.h struct cpu_user_regs · line 68
Quoted 8 lines
+ */
xen/arch/arm/include/asm/arm32/processor.h +7
-0+ +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) +#define MPIDR_LEVEL_SHIFT (level) (MPIDR_LEVEL_BITS * level) + +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> (MPIDR_LEVEL_BITS * level)) & MPIDR_LEVEL_MASK) +
Above, since
#define MPIDR_LEVEL_SHIFT(level) (MPIDR_LEVEL_BITS * level)
you can replace (MPIDR_LEVEL_BITS * level) with MPIDR_LEVEL_SHIFT(level) in the definition of MPIDR_AFFINITY_LEVEL. You will see that it is identical to the arm64 definition
#define MPIDR_AFFINITY_LEVEL(mpidr, level) \
((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK)
Quoted 56 lines
Quoted 48 lines
Quoted 45 lines
#endif
#endif /*__ASM_ARM_ARM32_PROCESSOR_H*/xen/arch/arm/include/asm/arm64/processor.h +0
-0@@ -84,6 +84,19 @@ struct cpu_user_regs uint64_t sp_el1, elr_el1; };+/*
+ * Macros to extract affinity level. picked from kernel
+ */xen/arch/arm/include/asm/arm64/processor.h +10
-0+ +#define MPIDR_LEVEL_BITS_SHIFT 3 +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) + +#define MPIDR_LEVEL_SHIFT (level) \ + (((1 << level) >> 1) << MPIDR_LEVEL_BITS_SHIFT) + +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) +#undef
__DECL_REG
#endif /*__ASSEMBLY__*/xen/arch/arm/include/asm/processor.h +0
-0@@ -118,20 +118,6 @@ #define MPIDR_INVALID (~MPIDR_HWID_MASK) #define MPIDR_LEVEL_BITS (8)-
xen/arch/arm/include/asm/processor.h +0
-13-/* -* Macros to extract affinity level. picked from kernel -*/ - -#define MPIDR_LEVEL_BITS_SHIFT 3 -#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) - -#define MPIDR_LEVEL_SHIFT (level) \ - (((1 << (level)) >> 1) << MPIDR_LEVEL_BITS_SHIFT) - -#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ - (((mpidr) >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) -Quoted 2 lines
#define AFFINITY_MASK(level) ~((_AC(0x1,UL) <<
MPIDR_LEVEL_SHIFT(level)) - 1) /* TTBCR Translation Table Base Control Register */Quoted 7 lines
Since only the definition of the
MPIDR_AFFINITY_LEVEL()differs, maybe you could add only this one to the arch specific headers e.g for arm64:
#defineMPIDR_LEVEL_SHIFT(level)\
(((1 << (level)) >> 1) <<MPIDR_LEVEL_BITS_SHIFT)
for arm32:
#defineMPIDR_LEVEL_SHIFT(level)\
((level) <<MPIDR_LEVEL_BITS_SHIFT)
Quoted 1 line
Also,
MPIDR_AFFINITY_LEVELneeds to be defined in arch specific headers as it differs between arm32 and arm64.
As I point out above, there is no difference between arm32 and arm64 regarding the definition of MPIDR_AFFINITY_LEVEL(level).
Quoted 12 lines
However,
MPIDR_LEVEL_MASKcan be defined in the common header (as it is same for arm32 and arm64).Please let me know if it makes sense.
Quoted 2 lines
But in any case don't forget to add parentheses around the macro parameters when an operator acts on them to avoid trouble with operator precedence (MISRA-C Rule 20.7 :))
Thanks for pointing it out. Yes, this is a mistake in my patches.
- Ayan
Signature · 1 line
Xenia
Re: [RFC PATCH v1 02/12] Arm: GICv3: Move the macros to compute the affnity level to arm64/arm32
Quoted 1 line · Xenia Ragiadakou
Hi Ayan,
Hi Xenia,
Quoted 40 lines · Ayan Kumar Halder
Quoted 38 lines · Xenia Ragiadakou
Quoted 2 lines · Ayan Kumar Halder
Hi Ayan
Hi Xenia,
Quoted 33 lines
Quoted 33 lines
Refer https://elixir.bootlin.com/linux/v6.1-rc1/source/arch/arm64/ \
include/asm/cputype.h#L14 , these macros are specific for arm64.When one computes
MPIDR_LEVEL_SHIFT(3), it crosses the width of a 32 bit register.Refer https://elixir.bootlin.com/linux/v6.1-rc1/source/arch/arm/include/ \
asm/cputype.h#L54 , these macros are specific for arm32.Signed-off-by Ayan Kumar Halder <[email protected]>---
xen/arch/arm/include/asm/arm32/processor.h| 10 ++++++++++xen/arch/arm/include/asm/arm64/processor.h| 13 +++++++++++++ xen/arch/arm/include/asm/processor.h | 14 --------------3 files changed, 23 insertions(+), 14 deletions(-)xen/arch/arm/include/asm/arm32/processor.h +0
-0@@ -56,6 +56,16 @@ struct cpu_user_regs
uint32_tpad1; /* Doubleword-align the user half of the frame */ };
+/*
+ * Macros to extract affinity level. Picked from kernel
+ */xen/arch/arm/include/asm/arm32/processor.h +6
-0+ +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) +#define MPIDR_LEVEL_SHIFT (level) (MPIDR_LEVEL_BITS * level) + +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> (MPIDR_LEVEL_BITS * level)) & MPIDR_LEVEL_MASK)
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
Above, since
#defineMPIDR_LEVEL_SHIFT(level)(MPIDR_LEVEL_BITS* level)
you can replace (MPIDR_LEVEL_BITS* level) withMPIDR_LEVEL_SHIFT(level)in the definition ofMPIDR_AFFINITY_LEVEL. You will see that it is identical to the arm64 definition
#defineMPIDR_AFFINITY_LEVEL(mpidr, level)\
((mpidr >>MPIDR_LEVEL_SHIFT(level)) &MPIDR_LEVEL_MASK)
Currently, MPIDR_AFFINITY_LEVEL(mpidr, 3) differs between arm32 and arm64:-
In arm32 :- (mpidr >> 24) & 0xff
In arm64 :- (mpidr >> 32) & 0xff
I think this is what is expected. See xen/arch/arm/gic-v3.c ,
static inline uint64_t gicv3_mpidr_to_affinity(int cpu) {
uint64_t mpidr = cpu_logical_map(cpu); return (MPIDR_AFFINITY_LEVEL(mpidr, 3) << 32 | MPIDR_AFFINITY_LEVEL(mpidr, 2) << 16 | MPIDR_AFFINITY_LEVEL(mpidr, 1) << 8 | MPIDR_AFFINITY_LEVEL(mpidr, 0)); }
Quoted 57 lines
Quoted 57 lines
Quoted 56 lines
Quoted 46 lines
#endif
#endif /*__ASM_ARM_ARM32_PROCESSOR_H*/xen/arch/arm/include/asm/arm64/processor.h +0
-0@@ -84,6 +84,19 @@ struct cpu_user_regs uint64_t sp_el1, elr_el1; };+/*
+ * Macros to extract affinity level. picked from kernel
+ */xen/arch/arm/include/asm/arm64/processor.h +10
-0+ +#define MPIDR_LEVEL_BITS_SHIFT 3 +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) + +#define MPIDR_LEVEL_SHIFT (level) \ + (((1 << level) >> 1) << MPIDR_LEVEL_BITS_SHIFT) + +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) +#undef
__DECL_REG
#endif /*__ASSEMBLY__*/xen/arch/arm/include/asm/processor.h +0
-0@@ -118,20 +118,6 @@ #define MPIDR_INVALID (~MPIDR_HWID_MASK) #define MPIDR_LEVEL_BITS (8)-
xen/arch/arm/include/asm/processor.h +0
-13-/* -* Macros to extract affinity level. picked from kernel -*/ - -#define MPIDR_LEVEL_BITS_SHIFT 3 -#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) - -#define MPIDR_LEVEL_SHIFT (level) \ - (((1 << (level)) >> 1) << MPIDR_LEVEL_BITS_SHIFT) - -#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ - (((mpidr) >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) -Quoted 2 lines
#define AFFINITY_MASK(level) ~((_AC(0x1,UL) <<
MPIDR_LEVEL_SHIFT(level)) - 1) /* TTBCR Translation Table Base Control Register */Since only the definition of the
MPIDR_AFFINITY_LEVEL()differs, maybe you could add only this one to the arch specific headers e.g for arm64:
#defineMPIDR_LEVEL_SHIFT(level)\
(((1 << (level)) >> 1) <<MPIDR_LEVEL_BITS_SHIFT)
for arm32:
#defineMPIDR_LEVEL_SHIFT(level)\
((level) <<MPIDR_LEVEL_BITS_SHIFT)
Quoted 3 lines
Quoted 1 line
Also,
MPIDR_AFFINITY_LEVELneeds to be defined in arch specific headers as it differs between arm32 and arm64.As I point out above, there is no difference between arm32 and arm64 regarding the definition of
MPIDR_AFFINITY_LEVEL(level).
Please see above and let me know if it makes sense.
- Ayan
Quoted 14 lines
Quoted 13 lines
However,
MPIDR_LEVEL_MASKcan be defined in the common header (as it is same for arm32 and arm64).Please let me know if it makes sense.
Quoted 2 lines
But in any case don't forget to add parentheses around the macro parameters when an operator acts on them to avoid trouble with operator precedence (MISRA-C Rule 20.7 :))
Thanks for pointing it out. Yes, this is a mistake in my patches.
- Ayan
Re: [RFC PATCH v1 02/12] Arm: GICv3: Move the macros to compute the affnity level to arm64/arm32
Quoted 53 lines · Ayan Kumar Halder
Quoted 1 line · Xenia Ragiadakou
Hi Ayan,
Hi Xenia,
Quoted 40 lines · Ayan Kumar Halder
Quoted 38 lines · Xenia Ragiadakou
Quoted 2 lines · Ayan Kumar Halder
Hi Ayan
Hi Xenia,
Quoted 33 lines
Quoted 33 lines
Refer https://elixir.bootlin.com/linux/v6.1-rc1/source/arch/arm64/ \
include/asm/cputype.h#L14 , these macros are specific for arm64.When one computes
MPIDR_LEVEL_SHIFT(3), it crosses the width of a 32 bit register.Refer https://elixir.bootlin.com/linux/v6.1-rc1/source/arch/arm/include/ \
asm/cputype.h#L54 , these macros are specific for arm32.Signed-off-by Ayan Kumar Halder <[email protected]>---
xen/arch/arm/include/asm/arm32/processor.h| 10 ++++++++++xen/arch/arm/include/asm/arm64/processor.h| 13 +++++++++++++ xen/arch/arm/include/asm/processor.h | 14 --------------3 files changed, 23 insertions(+), 14 deletions(-)xen/arch/arm/include/asm/arm32/processor.h +0
-0@@ -56,6 +56,16 @@ struct cpu_user_regs
uint32_tpad1; /* Doubleword-align the user half of the frame */ };
+/*
+ * Macros to extract affinity level. Picked from kernel
+ */xen/arch/arm/include/asm/arm32/processor.h +6
-0+ +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) +#define MPIDR_LEVEL_SHIFT (level) (MPIDR_LEVEL_BITS * level) + +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> (MPIDR_LEVEL_BITS * level)) & MPIDR_LEVEL_MASK)Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
Above, since
#defineMPIDR_LEVEL_SHIFT(level)(MPIDR_LEVEL_BITS* level)
you can replace (MPIDR_LEVEL_BITS* level) withMPIDR_LEVEL_SHIFT(level)in the definition ofMPIDR_AFFINITY_LEVEL. You will see that it is identical to the arm64 definition
#defineMPIDR_AFFINITY_LEVEL(mpidr, level)\
((mpidr >>MPIDR_LEVEL_SHIFT(level)) &MPIDR_LEVEL_MASK)
Quoted 5 lines
Currently,
MPIDR_AFFINITY_LEVEL(mpidr, 3)differs between arm32 and arm64:-In arm32 :- (mpidr >> 24) &
0xffIn arm64 :- (mpidr >> 32) &
0xff
Correct. This is the case because the MPIDR_LEVEL_SHIFT(level) differs between arm32 and arm64. The definition of MPIDR_AFFINITY_LEVEL is common in both.
More specifically, for level 3,
#define MPIDR_LEVEL_SHIFT(level) \
((level) << MPIDR_LEVEL_BITS_SHIFT)#define MPIDR_AFFINITY_LEVEL(mpidr, level) \
(((mpidr) >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK)
gives (mpidr >> 24) & 0xff
While
#define MPIDR_LEVEL_SHIFT(level) \
(((1 << (level)) >> 1) << MPIDR_LEVEL_BITS_SHIFT)
#define MPIDR_AFFINITY_LEVEL(mpidr, level) \
(((mpidr) >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK)gives (mpidr >> 32) & 0xff
Quoted 91 lines
I think this is what is expected. See
xen/arch/arm/gic-v3.c,static inline
uint64_tgicv3_mpidr_to_affinity(int cpu){
uint64_tmpidr =cpu_logical_map(cpu); return (MPIDR_AFFINITY_LEVEL(mpidr, 3)<< 32 |MPIDR_AFFINITY_LEVEL(mpidr, 2)<< 16 |MPIDR_AFFINITY_LEVEL(mpidr, 1)<< 8 |MPIDR_AFFINITY_LEVEL(mpidr, 0));
}Quoted 57 lines
Quoted 57 lines
Quoted 56 lines
Quoted 46 lines
#endif
#endif /*__ASM_ARM_ARM32_PROCESSOR_H*/xen/arch/arm/include/asm/arm64/processor.h +0
-0@@ -84,6 +84,19 @@ struct cpu_user_regs uint64_t sp_el1, elr_el1; };+/*
+ * Macros to extract affinity level. picked from kernel
+ */xen/arch/arm/include/asm/arm64/processor.h +10
-0+ +#define MPIDR_LEVEL_BITS_SHIFT 3 +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) + +#define MPIDR_LEVEL_SHIFT (level) \ + (((1 << level) >> 1) << MPIDR_LEVEL_BITS_SHIFT) + +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) +#undef
__DECL_REG
#endif /*__ASSEMBLY__*/xen/arch/arm/include/asm/processor.h +0
-0@@ -118,20 +118,6 @@ #define MPIDR_INVALID (~MPIDR_HWID_MASK) #define MPIDR_LEVEL_BITS (8)-
xen/arch/arm/include/asm/processor.h +0
-13-/* -* Macros to extract affinity level. picked from kernel -*/ - -#define MPIDR_LEVEL_BITS_SHIFT 3 -#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) - -#define MPIDR_LEVEL_SHIFT (level) \ - (((1 << (level)) >> 1) << MPIDR_LEVEL_BITS_SHIFT) - -#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ - (((mpidr) >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) -Quoted 2 lines
#define AFFINITY_MASK(level) ~((_AC(0x1,UL) <<
MPIDR_LEVEL_SHIFT(level)) - 1) /* TTBCR Translation Table Base Control Register */Since only the definition of the
MPIDR_AFFINITY_LEVEL()differs, maybe you could add only this one to the arch specific headers e.g for arm64:
#defineMPIDR_LEVEL_SHIFT(level)\
(((1 << (level)) >> 1) <<MPIDR_LEVEL_BITS_SHIFT)
for arm32:
#defineMPIDR_LEVEL_SHIFT(level)\
((level) <<MPIDR_LEVEL_BITS_SHIFT)Quoted 3 lines
Quoted 1 line
Also,
MPIDR_AFFINITY_LEVELneeds to be defined in arch specific headers as it differs between arm32 and arm64.As I point out above, there is no difference between arm32 and arm64 regarding the definition of
MPIDR_AFFINITY_LEVEL(level).Please see above and let me know if it makes sense.
- Ayan
Quoted 14 lines
Quoted 13 lines
However,
MPIDR_LEVEL_MASKcan be defined in the common header (as it is same for arm32 and arm64).Please let me know if it makes sense.
Quoted 2 lines
But in any case don't forget to add parentheses around the macro parameters when an operator acts on them to avoid trouble with operator precedence (MISRA-C Rule 20.7 :))
Thanks for pointing it out. Yes, this is a mistake in my patches.
- Ayan
Signature · 1 line
Xenia
RFC PATCH 3/12 Arm: GICv3: Enable vreg_reg64_* macros for AArch32
In reply to Ayan Kumar HalderIn some situations (eg GICR_TYPER), the hypervior may need to emulate 64bit registers in aarch32 mode. In such situations, the hypervisor may need to read/modify the lower or upper 32 bits of the 64 bit register.
In aarch32, 64 bit is represented by unsigned long long. Thus, we need to change the prototype accordingly.
--- xen/arch/arm/include/asm/vreg.h | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
xen/arch/arm/include/asm/vreg.h +8 -15
@@ -95,7 +95,7 @@ static inline bool vreg_emulate_sysreg(struct cpu_user_regs *regs, union hsr hsr* Note that the alignment fault will always be taken in the guest * (see B3.12.7 DDI0406.b). */ -static inline register_t vreg_reg_extract (unsigned long reg, +static inline register_t vreg_reg_extract (unsigned long long reg,unsigned int offset,enum dabt_size size) {
@@ -105,7 +105,7 @@ static inline register_t vreg_reg_extract(unsigned long reg,return reg; } -static inline void vreg_reg_update (unsigned long *reg,register_t val, +static inline void vreg_reg_update (unsigned long long *reg,register_t val,unsigned int offset,enum dabt_size size) {
@@ -116,7 +116,7 @@ static inline void vreg_reg_update(unsigned long *reg, register_t val, *reg |= ((unsigned long )val & mask) << shift; } -static inline void vreg_reg_setbits (unsigned long *reg,register_t bits, +static inline void vreg_reg_setbits (unsigned long long *reg,register_t bits,unsigned int offset,enum dabt_size size) {
@@ -126,7 +126,7 @@ static inline void vreg_reg_setbits(unsigned long *reg, register_t bits, *reg |= ((unsigned long )bits & mask) << shift; } -static inline void vreg_reg_clearbits (unsigned long *reg,register_t bits, +static inline void vreg_reg_clearbits (unsigned long long *reg,register_t bits,unsigned int offset,enum dabt_size size) {
@@ -149,7 +149,7 @@ static inline void vreg_reg##sz##_update(uint##sz##_t *reg, \ register_t val, \ const mmio_info_t *info) \ { \ -unsigned long tmp = *reg; \ +unsigned long long tmp = *reg; \ \vreg_reg_update (&tmp, val, info->gpa & (offmask), \ info->dabt.size); \
@@ -161,7 +161,7 @@ static inline void vreg_reg##sz##_setbits(uint##sz##_t *reg, \ register_t bits, \ const mmio_info_t *info) \ { \ -unsigned long tmp = *reg; \ +unsigned long long tmp = *reg; \ \vreg_reg_setbits (&tmp, bits, info->gpa & (offmask), \ info->dabt.size); \
@@ -173,7 +173,7 @@ static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ register_t bits, \ const mmio_info_t *info) \ { \ -unsigned long tmp = *reg; \ +unsigned long long tmp = *reg; \ \vreg_reg_clearbits (&tmp, bits, info->gpa & (offmask), \ info->dabt.size); \
@@ -181,15 +181,8 @@ static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ *reg = tmp; \ } -/* -* 64 bits registers are only supported on platform with 64-bit long. -* This is also allow us to optimize the 32 bit case by using -* unsigned long rather than uint64_t -*/ -#if BITS_PER_LONG ==64 -VREG_REG_HELPERS (64 ,0x7 ); -#endif VREG_REG_HELPERS (32 ,0x3 ); +VREG_REG_HELPERS (64 ,0x7 );#undef VREG_REG_HELPERS
Signature · 1 line
2.17.1
Re: [RFC PATCH v1 03/12] Arm: GICv3: Enable vreg_reg64_* macros for AArch32
Hi Ayan,
Title: The code you are modifying below is not GICv3 specific. I would suggest the following title:
xen/arm: vreg: Support vreg_reg64_* helpers on Aarch32
Quoted 80 lines · Ayan Kumar Halder
In some situations (eg
GICR_TYPER), the hypervior may need to emulate 64bit registers in aarch32 mode. In such situations, the hypervisor may need to read/modify the lower or upper 32 bits of the 64 bit register.In aarch32, 64 bit is represented by unsigned long long. Thus, we need to change the prototype accordingly.
Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/include/asm/vreg.h | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)xen/arch/arm/include/asm/vreg.h +7
-7@@ -95,7 +95,7 @@ static inline bool vreg_emulate_sysreg(struct cpu_user_regs *regs, union hsr hsr* Note that the alignment fault will always be taken in the guest * (see B3.12.7 DDI0406.b). */ -static inline register_t vreg_reg_extract (unsigned long reg, +static inline register_t vreg_reg_extract (unsigned long long reg,unsigned int offset,enum dabt_size size) {@@ -105,7 +105,7 @@ static inline register_t vreg_reg_extract(unsigned long reg,return reg; } -static inline void vreg_reg_update (unsigned long *reg,register_t val, +static inline void vreg_reg_update (unsigned long long *reg,register_t val,unsigned int offset,enum dabt_size size) {@@ -116,7 +116,7 @@ static inline void vreg_reg_update(unsigned long *reg, register_t val, *reg |= ((unsigned long )val & mask) << shift; } -static inline void vreg_reg_setbits (unsigned long *reg,register_t bits, +static inline void vreg_reg_setbits (unsigned long long *reg,register_t bits,unsigned int offset,enum dabt_size size) {@@ -126,7 +126,7 @@ static inline void vreg_reg_setbits(unsigned long *reg, register_t bits, *reg |= ((unsigned long )bits & mask) << shift; } -static inline void vreg_reg_clearbits (unsigned long *reg,register_t bits, +static inline void vreg_reg_clearbits (unsigned long long *reg,register_t bits,unsigned int offset,enum dabt_size size) {@@ -149,7 +149,7 @@ static inline void vreg_reg##sz##_update(uint##sz##_t *reg, \ register_t val, \ const mmio_info_t *info) \ { \ -unsigned long tmp = *reg; \ +unsigned long long tmp = *reg; \ \vreg_reg_update (&tmp, val, info->gpa & (offmask), \ info->dabt.size); \@@ -161,7 +161,7 @@ static inline void vreg_reg##sz##_setbits(uint##sz##_t *reg, \ register_t bits, \ const mmio_info_t *info) \ { \ -unsigned long tmp = *reg; \ +unsigned long long tmp = *reg; \ \vreg_reg_setbits (&tmp, bits, info->gpa & (offmask), \ info->dabt.size); \@@ -173,7 +173,7 @@ static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ register_t bits, \ const mmio_info_t *info) \ { \ -unsigned long tmp = *reg; \ +unsigned long long tmp = *reg; \ \vreg_reg_clearbits (&tmp, bits, info->gpa & (offmask), \ info->dabt.size); \
xen/arch/arm/include/asm/vreg.h static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ · line 188
Quoted 8 lines
xen/arch/arm/include/asm/vreg.h +0
-5@@ -181,15 +181,8 @@ static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ *reg = tmp; \ } -/* -* 64 bits registers are only supported on platform with 64-bit long. -* This is also allow us to optimize the 32 bit case by using -* unsigned long rather than uint64_t -*/
The comment above explain why we never use uint64_t in the helpers above. IIRC, the compiler would end up to use 2 registers on AArch32 even for the vreg_reg32_* helpers. I wanted to avoid that and would like like to today. Can you check the code generated?
For other options, I would consider to either:
1) Fold vreg_reg_* in the macros.
2) Write a separate vreg_reg64_*
My preference would be 1).
If we are planning to keep the code with "unsigned long long", then I think this should be addressed in the commit message.
xen/arch/arm/include/asm/vreg.h static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ · line 185
Quoted 5 lines
xen/arch/arm/include/asm/vreg.h +1
-3-#if BITS_PER_LONG ==64 -VREG_REG_HELPERS (64 ,0x7 ); -#endif VREG_REG_HELPERS (32 ,0x3 ); +VREG_REG_HELPERS (64 ,0x7 );
Regardless what I wrote above, the code movement seems to be unwarranted.
xen/arch/arm/include/asm/vreg.h static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ · line 188
Quoted 3 lines
xen/arch/arm/include/asm/vreg.h +0
-0#undef VREG_REG_HELPERS
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC PATCH v1 03/12] Arm: GICv3: Enable vreg_reg64_* macros for AArch32
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
I need some clarification.
Quoted 101 lines
Title: The code you are modifying below is not GICv3 specific. I would suggest the following title:
xen/arm: vreg: Support vreg_reg64_* helpers on Aarch32
Quoted 95 lines · Ayan Kumar Halder
In some situations (eg
GICR_TYPER), the hypervior may need to emulate 64bit registers in aarch32 mode. In such situations, the hypervisor may need to read/modify the lower or upper 32 bits of the 64 bit register.In aarch32, 64 bit is represented by unsigned long long. Thus, we need to change the prototype accordingly.
Signed-off-by Ayan Kumar Halder <[email protected]>---
xen/arch/arm/include/asm/vreg.h| 23 ++++++++---------------1 file changed, 8 insertions(+), 15 deletions(-)xen/arch/arm/include/asm/vreg.h +0
-0@@ -95,7 +95,7 @@ static inline bool vreg_emulate_sysreg(struct
cpu_user_regs*regs, union hsr hsr
* Note that the alignment fault will always be taken in the guest
* (see B3.12.7 DDI0406.b).
*/xen/arch/arm/include/asm/vreg.h +1
-1-static inline register_t vreg_reg_extract(unsigned long reg, +static inline register_t vreg_reg_extract(unsigned long long reg,unsigned int offset, enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-0@@ -105,7 +105,7 @@ static inline register_t vreg_reg_extract(unsigned long reg, return reg; } -static inline void vreg_reg_update(unsigned long *reg, register_t val, +static inline void vreg_reg_update(unsigned long long *reg, register_t val, unsigned int offset,enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-0@@ -116,7 +116,7 @@ static inline void vreg_reg_update(unsigned long *reg, register_t val, *reg |= ((unsigned long)val & mask) << shift; } -static inline void vreg_reg_setbits(unsigned long *reg, register_t bits, +static inline void vreg_reg_setbits(unsigned long long *reg, register_t bits, unsigned int offset,enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-0@@ -126,7 +126,7 @@ static inline void vreg_reg_setbits(unsigned long *reg, register_t bits, *reg |= ((unsigned long)bits & mask) << shift; } -static inline void vreg_reg_clearbits(unsigned long *reg, register_t bits, +static inline void vreg_reg_clearbits(unsigned long long *reg, register_t bits, unsigned int offset,enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-1@@ -149,7 +149,7 @@ static inline void vreg_reg##sz##_update(uint##sz##_t *reg, \ register_t val, \ const mmio_info_t *info) \ { \ - unsigned long tmp = *reg; \ + unsigned long long tmp = *reg; \\
vreg_reg_update(&tmp, val,info->gpa& (offmask), \
info->dabt.size); \xen/arch/arm/include/asm/vreg.h +1
-1@@ -161,7 +161,7 @@ static inline void vreg_reg##sz##_setbits(uint##sz##_t *reg, \ register_t bits, \ const mmio_info_t *info) \ { \ - unsigned long tmp = *reg; \ + unsigned long long tmp = *reg; \\
vreg_reg_setbits(&tmp, bits,info->gpa& (offmask), \
info->dabt.size); \xen/arch/arm/include/asm/vreg.h +1
-1@@ -173,7 +173,7 @@ static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ register_t bits, \ const mmio_info_t *info) \ { \ - unsigned long tmp = *reg; \ + unsigned long long tmp = *reg; \\
vreg_reg_clearbits(&tmp, bits,info->gpa& (offmask), \
info->dabt.size); \xen/arch/arm/include/asm/vreg.h +0
-0@@ -181,15 +181,8 @@ static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ *reg = tmp; \
Quoted 8 lines
Quoted 6 lines
xen/arch/arm/include/asm/vreg.h +0
-0}-/*
- * 64 bits registers are only supported on platform with 64-bit long.
- * This is also allow us to optimize the 32 bit case by using
- * unsigned long rather thanuint64_t
- */The comment above explain why we never use
uint64_tin the helpers above. IIRC, the compiler would end up to use 2 registers on AArch32 even for the vreg_reg32_* helpers. I wanted to avoid that and would like like to today. Can you check the code generated?
I am not sure I understood the comment very well.
With this patch, the disassembly is as follows :-
vreg_reg32_update(&v->domain->arch.vgic.ctlr, r, info); 28124c: e597000c ldr r0, [r7, #12] VREG_REG_HELPERS(32, 0x3);
281250: e5d52002 ldrb r2, [r5, #2]
281254: e1a02322 lsr r2, r2, #6
unsigned long mask = VREG_REG_MASK(size);
281258: e3a03008 mov r3, #8
28125c: e1a03213 lsl r3, r3, r2
281260: e2633020 rsb r3, r3, #32
281264: e3e02000 mvn r2, #0
281268: e1a02332 lsr r2, r2, r3 VREG_REG_HELPERS(32, 0x3);
28126c: e5953010 ldr r3, [r5, #16]
281270: e2033003 and r3, r3, #3
int shift = offset * 8;
281274: e1a03183 lsl r3, r3, #3 VREG_REG_HELPERS(32, 0x3);
281278: e59013f0 ldr r1, [r0, #1008] ; 0x3f0 28127c: e1c11312 bic r1, r1, r2, lsl r3
*reg |= ((unsigned long)val & mask) << shift; 281280: e0022009 and r2, r2, r9 VREG_REG_HELPERS(32, 0x3);
281284: e1813312 orr r3, r1, r2, lsl r3 281288: e58033f0 str r3, [r0, #1008] ; 0x3f0 v->domain->arch.vgic.ctlr &= GICD_CTL_ENABLE; 28128c: e597200c ldr r2, [r7, #12]
281290: e59233f0 ldr r3, [r2, #1008] ; 0x3f0 281294: e2033001 and r3, r3, #1
281298: e58233f0 str r3, [r2, #1008] ; 0x3f0
Without the patch (ie original code) , the disassembly is :-
vreg_reg32_update(&v->domain->arch.vgic.ctlr, r, info); 27f8f4: e597000c ldr r0, [r7, #12] VREG_REG_HELPERS(32, 0x3);
27f8f8: e5d52002 ldrb r2, [r5, #2]
27f8fc: e1a02322 lsr r2, r2, #6
unsigned long mask = VREG_REG_MASK(size);
27f900: e3a03008 mov r3, #8
27f904: e1a03213 lsl r3, r3, r2
27f908: e2633020 rsb r3, r3, #32
27f90c: e3e02000 mvn r2, #0
27f910: e1a02332 lsr r2, r2, r3 VREG_REG_HELPERS(32, 0x3);
27f914: e5953010 ldr r3, [r5, #16]
27f918: e2033003 and r3, r3, #3
int shift = offset * 8;
27f91c: e1a03183 lsl r3, r3, #3
*reg &= ~(mask << shift);
27f920: e5901400 ldr r1, [r0, #1024] ; 0x400 27f924: e1c11312 bic r1, r1, r2, lsl r3
*reg |= ((unsigned long)val & mask) << shift; 27f928: e0022009 and r2, r2, r9
27f92c: e1813312 orr r3, r1, r2, lsl r3 VREG_REG_HELPERS(32, 0x3);
27f930: e5803400 str r3, [r0, #1024] ; 0x400 v->domain->arch.vgic.ctlr &= GICD_CTL_ENABLE; 27f934: e597200c ldr r2, [r7, #12]
27f938: e5923400 ldr r3, [r2, #1024] ; 0x400 27f93c: e2033001 and r3, r3, #1
27f940: e5823400 str r3, [r2, #1024] ; 0x400
Sorry, I can't spot the difference. :(
I had a look at commit 423e9ecdc26c4b40c8db1fcc63b3655463c29976 which introduced this. But I could not make out the reason from the commit message.
Quoted 3 lines
For other options, I would consider to either:
1) Fold vreg_reg_* in the macros.
Can you explain this option a bit ?
- Ayan
Quoted 17 lines
2) Write a separate vreg_reg64_*
My preference would be 1).
If we are planning to keep the code with "unsigned long long", then I think this should be addressed in the commit message.
Quoted 5 lines
xen/arch/arm/include/asm/vreg.h +0
-3-#if BITS_PER_LONG ==64 -VREG_REG_HELPERS (64 ,0x7 ); -#endif
VREG_REG_HELPERS(32, 0x3);
+VREG_REG_HELPERS(64,0x7);Regardless what I wrote above, the code movement seems to be unwarranted.
Quoted 1 line
#undef
VREG_REG_HELPERSCheers,
Re: [RFC PATCH v1 03/12] Arm: GICv3: Enable vreg_reg64_* macros for AArch32
Quoted 120 lines · Ayan Kumar Halder
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
I need some clarification.
Quoted 101 lines
Title: The code you are modifying below is not GICv3 specific. I would suggest the following title:
xen/arm: vreg: Support vreg_reg64_* helpers on Aarch32
Quoted 95 lines · Ayan Kumar Halder
In some situations (eg
GICR_TYPER), the hypervior may need to emulate 64bit registers in aarch32 mode. In such situations, the hypervisor may need to read/modify the lower or upper 32 bits of the 64 bit register.In aarch32, 64 bit is represented by unsigned long long. Thus, we need to change the prototype accordingly.
Signed-off-by Ayan Kumar Halder <[email protected]>---
xen/arch/arm/include/asm/vreg.h| 23 ++++++++---------------1 file changed, 8 insertions(+), 15 deletions(-)xen/arch/arm/include/asm/vreg.h +0
-0@@ -95,7 +95,7 @@ static inline bool vreg_emulate_sysreg(struct
cpu_user_regs*regs, union hsr hsr
* Note that the alignment fault will always be taken in the guest
* (see B3.12.7 DDI0406.b).
*/xen/arch/arm/include/asm/vreg.h +1
-1-static inline register_t vreg_reg_extract(unsigned long reg, +static inline register_t vreg_reg_extract(unsigned long long reg,unsigned int offset, enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-0@@ -105,7 +105,7 @@ static inline register_t vreg_reg_extract(unsigned long reg, return reg; } -static inline void vreg_reg_update(unsigned long *reg, register_t val, +static inline void vreg_reg_update(unsigned long long *reg, register_t val, unsigned int offset,enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-0@@ -116,7 +116,7 @@ static inline void vreg_reg_update(unsigned long *reg, register_t val, *reg |= ((unsigned long)val & mask) << shift; } -static inline void vreg_reg_setbits(unsigned long *reg, register_t bits, +static inline void vreg_reg_setbits(unsigned long long *reg, register_t bits, unsigned int offset,enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-0@@ -126,7 +126,7 @@ static inline void vreg_reg_setbits(unsigned long *reg, register_t bits, *reg |= ((unsigned long)bits & mask) << shift; } -static inline void vreg_reg_clearbits(unsigned long *reg, register_t bits, +static inline void vreg_reg_clearbits(unsigned long long *reg, register_t bits, unsigned int offset,enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-1@@ -149,7 +149,7 @@ static inline void vreg_reg##sz##_update(uint##sz##_t *reg, \ register_t val, \ const mmio_info_t *info) \ { \ - unsigned long tmp = *reg; \ + unsigned long long tmp = *reg; \\
vreg_reg_update(&tmp, val,info->gpa& (offmask), \
info->dabt.size); \xen/arch/arm/include/asm/vreg.h +1
-1@@ -161,7 +161,7 @@ static inline void vreg_reg##sz##_setbits(uint##sz##_t *reg, \ register_t bits, \ const mmio_info_t *info) \ { \ - unsigned long tmp = *reg; \ + unsigned long long tmp = *reg; \\
vreg_reg_setbits(&tmp, bits,info->gpa& (offmask), \
info->dabt.size); \xen/arch/arm/include/asm/vreg.h +1
-1@@ -173,7 +173,7 @@ static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ register_t bits, \ const mmio_info_t *info) \ { \ - unsigned long tmp = *reg; \ + unsigned long long tmp = *reg; \\
vreg_reg_clearbits(&tmp, bits,info->gpa& (offmask), \
info->dabt.size); \xen/arch/arm/include/asm/vreg.h +0
-0@@ -181,15 +181,8 @@ static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ *reg = tmp; \Quoted 8 lines
Quoted 6 lines
xen/arch/arm/include/asm/vreg.h +0
-0}-/*
- * 64 bits registers are only supported on platform with 64-bit long.
- * This is also allow us to optimize the 32 bit case by using
- * unsigned long rather thanuint64_t
- */The comment above explain why we never use
uint64_tin the helpers above. IIRC, the compiler would end up to use 2 registers on AArch32 even for the vreg_reg32_* helpers. I wanted to avoid that and would like like to today. Can you check the code generated?I am not sure I understood the comment very well.
Quoted 8 lines
With this patch, the disassembly is as follows :-
vreg_reg32_update(&v->domain->arch.vgic.ctlr, r, info); 28124c: e597000c ldr r0, [r7, #12]VREG_REG_HELPERS(32, 0x3);
281250: e5d52002 ldrb r2, [r5, #2]
281254: e1a02322 lsr r2, r2, #6
unsigned long mask =VREG_REG_MASK(size);
Hmmm... Shouldn't this be "unsigned long long"?
Quoted 56 lines
281258: e3a03008 mov r3, #8
28125c: e1a03213 lsl r3, r3, r2 281260: e2633020 rsb r3, r3, #32 281264: e3e02000 mvn r2, #0
281268: e1a02332 lsr r2, r2, r3VREG_REG_HELPERS(32, 0x3);
28126c: e5953010 ldr r3, [r5, #16] 281270: e2033003 and r3, r3, #3
int shift = offset * 8;
281274: e1a03183 lsl r3, r3, #3VREG_REG_HELPERS(32, 0x3);
281278: e59013f0 ldr r1, [r0, #1008] ;0x3f028127c: e1c11312 bic r1, r1, r2, lsl r3 *reg |= ((unsigned long)val & mask) << shift; 281280: e0022009 and r2, r2, r9VREG_REG_HELPERS(32, 0x3);
281284: e1813312 orr r3, r1, r2, lsl r3 281288: e58033f0 str r3, [r0, #1008] ;0x3f0v->domain->arch.vgic.ctlr&=GICD_CTL_ENABLE; 28128c: e597200c ldr r2, [r7, #12] 281290: e59233f0 ldr r3, [r2, #1008] ;0x3f0281294: e2033001 and r3, r3, #1 281298: e58233f0 str r3, [r2, #1008] ;0x3f0Without the patch (ie original code) , the disassembly is :-
vreg_reg32_update(&v->domain->arch.vgic.ctlr, r, info); 27f8f4: e597000c ldr r0, [r7, #12]VREG_REG_HELPERS(32, 0x3);
27f8f8: e5d52002 ldrb r2, [r5, #2]
27f8fc: e1a02322 lsr r2, r2, #6
unsigned long mask =VREG_REG_MASK(size);
27f900: e3a03008 mov r3, #8
27f904: e1a03213 lsl r3, r3, r2
27f908: e2633020 rsb r3, r3, #32
27f90c: e3e02000 mvn r2, #0
27f910: e1a02332 lsr r2, r2, r3VREG_REG_HELPERS(32, 0x3);
27f914: e5953010 ldr r3, [r5, #16]
27f918: e2033003 and r3, r3, #3
int shift = offset * 8;
27f91c: e1a03183 lsl r3, r3, #3
*reg &= ~(mask << shift);
27f920: e5901400 ldr r1, [r0, #1024] ;0x40027f924: e1c11312 bic r1, r1, r2, lsl r3
*reg |= ((unsigned long)val & mask) << shift; 27f928: e0022009 and r2, r2, r9
27f92c: e1813312 orr r3, r1, r2, lsl r3VREG_REG_HELPERS(32, 0x3);
27f930: e5803400 str r3, [r0, #1024] ;0x400v->domain->arch.vgic.ctlr&=GICD_CTL_ENABLE; 27f934: e597200c ldr r2, [r7, #12]
27f938: e5923400 ldr r3, [r2, #1024] ;0x40027f93c: e2033001 and r3, r3, #1
27f940: e5823400 str r3, [r2, #1024] ;0x400
Quoted 1 line
Sorry, I can't spot the difference. :(
If there is no difference, then it is a good sign. I was worried that the compiler would end up to use "strd/ldrd" which would result to more register allocations and therefore inefficient code.
But see above.
Quoted 2 lines
I had a look at commit
423e9ecdc26c4b40c8db1fcc63b3655463c29976which introduced this. But I could not make out the reason from the commit message.
The reasoning would be to show that the assembly is either the same or no worse that then existing one with a few compilers.
Quoted 6 lines
Quoted 4 lines
For other options, I would consider to either:
1) Fold vreg_reg_* in the macros.Can you explain this option a bit ?
At the moment, we have generic helpers for vreg_reg_*. They are only called within the helper generated by VREG_REG_HELPERS().
If we make those helpers size specific, then the only the 64-bit helpers would use uint64_t local variables.
As they are only called in one place, we could fold them in the existing helpers.
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC PATCH v1 03/12] Arm: GICv3: Enable vreg_reg64_* macros for AArch32
Quoted 125 lines · Julien Grall
Quoted 122 lines · Ayan Kumar Halder
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
I need some clarification.
Quoted 101 lines
Title: The code you are modifying below is not GICv3 specific. I would suggest the following title:
xen/arm: vreg: Support vreg_reg64_* helpers on Aarch32
Quoted 95 lines · Ayan Kumar Halder
In some situations (eg
GICR_TYPER), the hypervior may need to emulate 64bit registers in aarch32 mode. In such situations, the hypervisor may need to read/modify the lower or upper 32 bits of the 64 bit register.In aarch32, 64 bit is represented by unsigned long long. Thus, we need to change the prototype accordingly.
Signed-off-by Ayan Kumar Halder <[email protected]>---
xen/arch/arm/include/asm/vreg.h| 23 ++++++++---------------1 file changed, 8 insertions(+), 15 deletions(-)xen/arch/arm/include/asm/vreg.h +0
-0@@ -95,7 +95,7 @@ static inline bool vreg_emulate_sysreg(struct
cpu_user_regs*regs, union hsr hsr
* Note that the alignment fault will always be taken in the guest
* (see B3.12.7 DDI0406.b).
*/xen/arch/arm/include/asm/vreg.h +1
-1-static inline register_t vreg_reg_extract(unsigned long reg, +static inline register_t vreg_reg_extract(unsigned long long reg,unsigned int offset, enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-0@@ -105,7 +105,7 @@ static inline register_t vreg_reg_extract(unsigned long reg, return reg; } -static inline void vreg_reg_update(unsigned long *reg, register_t val, +static inline void vreg_reg_update(unsigned long long *reg, register_t val, unsigned int offset,enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-0@@ -116,7 +116,7 @@ static inline void vreg_reg_update(unsigned long *reg, register_t val, *reg |= ((unsigned long)val & mask) << shift; } -static inline void vreg_reg_setbits(unsigned long *reg, register_t bits, +static inline void vreg_reg_setbits(unsigned long long *reg, register_t bits, unsigned int offset,enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-0@@ -126,7 +126,7 @@ static inline void vreg_reg_setbits(unsigned long *reg, register_t bits, *reg |= ((unsigned long)bits & mask) << shift; } -static inline void vreg_reg_clearbits(unsigned long *reg, register_t bits, +static inline void vreg_reg_clearbits(unsigned long long *reg, register_t bits, unsigned int offset,enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-1@@ -149,7 +149,7 @@ static inline void vreg_reg##sz##_update(uint##sz##_t *reg, \ register_t val, \ const mmio_info_t *info) \ { \ - unsigned long tmp = *reg; \ + unsigned long long tmp = *reg; \\
vreg_reg_update(&tmp, val,info->gpa& (offmask), \
info->dabt.size); \xen/arch/arm/include/asm/vreg.h +1
-1@@ -161,7 +161,7 @@ static inline void vreg_reg##sz##_setbits(uint##sz##_t *reg, \ register_t bits, \ const mmio_info_t *info) \ { \ - unsigned long tmp = *reg; \ + unsigned long long tmp = *reg; \\
vreg_reg_setbits(&tmp, bits,info->gpa& (offmask), \
info->dabt.size); \xen/arch/arm/include/asm/vreg.h +1
-1@@ -173,7 +173,7 @@ static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ register_t bits, \ const mmio_info_t *info) \ { \ - unsigned long tmp = *reg; \ + unsigned long long tmp = *reg; \\
vreg_reg_clearbits(&tmp, bits,info->gpa& (offmask), \
info->dabt.size); \xen/arch/arm/include/asm/vreg.h +0
-0@@ -181,15 +181,8 @@ static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ *reg = tmp; \Quoted 8 lines
Quoted 6 lines
xen/arch/arm/include/asm/vreg.h +0
-0}-/*
- * 64 bits registers are only supported on platform with 64-bit long.
- * This is also allow us to optimize the 32 bit case by using
- * unsigned long rather thanuint64_t
- */The comment above explain why we never use
uint64_tin the helpers above. IIRC, the compiler would end up to use 2 registers on AArch32 even for the vreg_reg32_* helpers. I wanted to avoid that and would like like to today. Can you check the code generated?I am not sure I understood the comment very well.
With this patch, the disassembly is as follows :-
Quoted 8 lines
Quoted 6 lines
vreg_reg32_update(&v->domain->arch.vgic.ctlr, r, info); 28124c: e597000c ldr r0, [r7, #12]VREG_REG_HELPERS(32, 0x3);
281250: e5d52002 ldrb r2, [r5, #2]
281254: e1a02322 lsr r2, r2, #6
unsigned long mask =VREG_REG_MASK(size);Hmmm... Shouldn't this be "unsigned long long"?
The function looks like
static inline void vreg_reg_update(unsigned long long *reg, register_t val, unsigned int offset,
enum dabt_size size)
{
unsigned long mask = VREG_REG_MASK(size);
int shift = offset * 8;
*reg &= ~(mask << shift);
*reg |= ((unsigned long)val & mask) << shift;
}
Quoted 73 lines
Quoted 57 lines
281258: e3a03008 mov r3, #8
28125c: e1a03213 lsl r3, r3, r2 281260: e2633020 rsb r3, r3, #32 281264: e3e02000 mvn r2, #0
281268: e1a02332 lsr r2, r2, r3VREG_REG_HELPERS(32, 0x3);
28126c: e5953010 ldr r3, [r5, #16] 281270: e2033003 and r3, r3, #3
int shift = offset * 8;
281274: e1a03183 lsl r3, r3, #3VREG_REG_HELPERS(32, 0x3);
281278: e59013f0 ldr r1, [r0, #1008] ;0x3f028127c: e1c11312 bic r1, r1, r2, lsl r3 *reg |= ((unsigned long)val & mask) << shift; 281280: e0022009 and r2, r2, r9VREG_REG_HELPERS(32, 0x3);
281284: e1813312 orr r3, r1, r2, lsl r3 281288: e58033f0 str r3, [r0, #1008] ;0x3f0v->domain->arch.vgic.ctlr&=GICD_CTL_ENABLE; 28128c: e597200c ldr r2, [r7, #12] 281290: e59233f0 ldr r3, [r2, #1008] ;0x3f0281294: e2033001 and r3, r3, #1 281298: e58233f0 str r3, [r2, #1008] ;0x3f0Without the patch (ie original code) , the disassembly is :-
vreg_reg32_update(&v->domain->arch.vgic.ctlr, r, info); 27f8f4: e597000c ldr r0, [r7, #12]VREG_REG_HELPERS(32, 0x3);
27f8f8: e5d52002 ldrb r2, [r5, #2]
27f8fc: e1a02322 lsr r2, r2, #6
unsigned long mask =VREG_REG_MASK(size);
27f900: e3a03008 mov r3, #8
27f904: e1a03213 lsl r3, r3, r2
27f908: e2633020 rsb r3, r3, #32
27f90c: e3e02000 mvn r2, #0
27f910: e1a02332 lsr r2, r2, r3VREG_REG_HELPERS(32, 0x3);
27f914: e5953010 ldr r3, [r5, #16]
27f918: e2033003 and r3, r3, #3
int shift = offset * 8;
27f91c: e1a03183 lsl r3, r3, #3
*reg &= ~(mask << shift);
27f920: e5901400 ldr r1, [r0, #1024] ;0x40027f924: e1c11312 bic r1, r1, r2, lsl r3
*reg |= ((unsigned long)val & mask) << shift; 27f928: e0022009 and r2, r2, r9
27f92c: e1813312 orr r3, r1, r2, lsl r3VREG_REG_HELPERS(32, 0x3);
27f930: e5803400 str r3, [r0, #1024] ;0x400v->domain->arch.vgic.ctlr&=GICD_CTL_ENABLE; 27f934: e597200c ldr r2, [r7, #12]
27f938: e5923400 ldr r3, [r2, #1024] ;0x40027f93c: e2033001 and r3, r3, #1
27f940: e5823400 str r3, [r2, #1024] ;0x400Quoted 1 line
Sorry, I can't spot the difference. :(
If there is no difference, then it is a good sign. I was worried that the compiler would end up to use "strd/ldrd" which would result to more register allocations and therefore inefficient code.
But see above.
Quoted 2 lines
I had a look at commit
423e9ecdc26c4b40c8db1fcc63b3655463c29976which introduced this. But I could not make out the reason from the commit message.The reasoning would be to show that the assembly is either the same or no worse that then existing one with a few compilers.
Quoted 5 lines
Quoted 4 lines
For other options, I would consider to either:
1) Fold vreg_reg_* in the macros.
Quoted 7 lines
Quoted 1 line
Can you explain this option a bit ?
At the moment, we have generic helpers for vreg_reg_*. They are only called within the helper generated by
VREG_REG_HELPERS().If we make those helpers size specific, then the only the 64-bit helpers would use
uint64_tlocal variables.As they are only called in one place, we could fold them in the existing helpers.
Just to make sure, I understand this. The code would look like below
#define VREG_REG_HELPERS(type, offmask) \
static inline void vreg_reg_##type##_update(type *reg, register_t val, \
const mmio_info_t *info) \
{ \
unsigned long mask = VREG_REG_MASK(size); \
unsigned int offset = info->gpa & (offmask); \
int shift = offset * 8; \
*reg &= ~(mask << shift); \
*reg |= ((unsigned long)val & mask) << shift; \
}
#define vreg_reg_update(reg, val, info) \
do { \
if (sizeof(reg) == 4) \
vreg_reg_uint32_t_update(reg, val, info); \
else if (sizeof(reg) == 8) \
vreg_reg_uint64_t_update(reg, val, info); \
else \
BUG(); \
} while(0); \
Similar implementation will be for vreg_reg_clearbits(), vreg_reg_setbits() and vreg_reg_extract()
VREG_REG_HELPERS(uint32_t, 0x3);
VREG_REG_HELPERS(uint64_t, 0x7);
And the functions would be invoked as follows :-
vreg_update(&priority, r, info);
Is this the correct understanding ?
Quoted 3 lines
Cheers,
Re: [RFC PATCH v1 03/12] Arm: GICv3: Enable vreg_reg64_* macros for AArch32
Quoted 134 lines · Ayan Kumar Halder
Quoted 132 lines · Julien Grall
Quoted 128 lines · Ayan Kumar Halder
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
I need some clarification.
Quoted 101 lines
Title: The code you are modifying below is not GICv3 specific. I would suggest the following title:
xen/arm: vreg: Support vreg_reg64_* helpers on Aarch32
Quoted 95 lines · Ayan Kumar Halder
In some situations (eg
GICR_TYPER), the hypervior may need to emulate 64bit registers in aarch32 mode. In such situations, the hypervisor may need to read/modify the lower or upper 32 bits of the 64 bit register.In aarch32, 64 bit is represented by unsigned long long. Thus, we need to change the prototype accordingly.
Signed-off-by Ayan Kumar Halder <[email protected]>---
xen/arch/arm/include/asm/vreg.h| 23 ++++++++---------------1 file changed, 8 insertions(+), 15 deletions(-)xen/arch/arm/include/asm/vreg.h +0
-0@@ -95,7 +95,7 @@ static inline bool vreg_emulate_sysreg(struct
cpu_user_regs*regs, union hsr hsr
* Note that the alignment fault will always be taken in the guest
* (see B3.12.7 DDI0406.b).
*/xen/arch/arm/include/asm/vreg.h +1
-1-static inline register_t vreg_reg_extract(unsigned long reg, +static inline register_t vreg_reg_extract(unsigned long long reg,unsigned int offset, enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-0@@ -105,7 +105,7 @@ static inline register_t vreg_reg_extract(unsigned long reg, return reg; } -static inline void vreg_reg_update(unsigned long *reg, register_t val, +static inline void vreg_reg_update(unsigned long long *reg, register_t val, unsigned int offset,enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-0@@ -116,7 +116,7 @@ static inline void vreg_reg_update(unsigned long *reg, register_t val, *reg |= ((unsigned long)val & mask) << shift; } -static inline void vreg_reg_setbits(unsigned long *reg, register_t bits, +static inline void vreg_reg_setbits(unsigned long long *reg, register_t bits, unsigned int offset,enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-0@@ -126,7 +126,7 @@ static inline void vreg_reg_setbits(unsigned long *reg, register_t bits, *reg |= ((unsigned long)bits & mask) << shift; } -static inline void vreg_reg_clearbits(unsigned long *reg, register_t bits, +static inline void vreg_reg_clearbits(unsigned long long *reg, register_t bits, unsigned int offset,enum
dabt_sizesize) {xen/arch/arm/include/asm/vreg.h +1
-1@@ -149,7 +149,7 @@ static inline void vreg_reg##sz##_update(uint##sz##_t *reg, \ register_t val, \ const mmio_info_t *info) \ { \ - unsigned long tmp = *reg; \ + unsigned long long tmp = *reg; \\
vreg_reg_update(&tmp, val,info->gpa& (offmask), \
info->dabt.size); \xen/arch/arm/include/asm/vreg.h +1
-1@@ -161,7 +161,7 @@ static inline void vreg_reg##sz##_setbits(uint##sz##_t *reg, \ register_t bits, \ const mmio_info_t *info) \ { \ - unsigned long tmp = *reg; \ + unsigned long long tmp = *reg; \\
vreg_reg_setbits(&tmp, bits,info->gpa& (offmask), \
info->dabt.size); \xen/arch/arm/include/asm/vreg.h +1
-1@@ -173,7 +173,7 @@ static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ register_t bits, \ const mmio_info_t *info) \ { \ - unsigned long tmp = *reg; \ + unsigned long long tmp = *reg; \\
vreg_reg_clearbits(&tmp, bits,info->gpa& (offmask), \
info->dabt.size); \xen/arch/arm/include/asm/vreg.h +0
-0@@ -181,15 +181,8 @@ static inline void vreg_reg##sz##_clearbits(uint##sz##_t *reg, \ *reg = tmp; \Quoted 8 lines
Quoted 6 lines
xen/arch/arm/include/asm/vreg.h +0
-0}-/*
- * 64 bits registers are only supported on platform with 64-bit long.
- * This is also allow us to optimize the 32 bit case by using
- * unsigned long rather thanuint64_t
- */The comment above explain why we never use
uint64_tin the helpers above. IIRC, the compiler would end up to use 2 registers on AArch32 even for the vreg_reg32_* helpers. I wanted to avoid that and would like like to today. Can you check the code generated?I am not sure I understood the comment very well.
With this patch, the disassembly is as follows :-
vreg_reg32_update(&v->domain->arch.vgic.ctlr, r, info); 28124c: e597000c ldr r0, [r7, #12]VREG_REG_HELPERS(32, 0x3);
281250: e5d52002 ldrb r2, [r5, #2]
281254: e1a02322 lsr r2, r2, #6
unsigned long mask =VREG_REG_MASK(size);
Quoted 3 lines
Quoted 1 line
Hmmm... Shouldn't this be "unsigned long long"?
The function looks like
Right. My question was why is this still a "unsigned long" with your patch? If the caller wanted to access the top 32-bit of a 64-bit value...
Quoted 9 lines
static inline void vreg_reg_update(unsigned long long *reg,
register_tval,
unsigned int offset,
enumdabt_sizesize)
{
unsigned long mask =VREG_REG_MASK(size);
int shift = offset * 8;*reg &= ~(mask << shift);
... we would have 'mask << 32' which is AFAIU "undefined" because 'mask' is 'unsigned long'. Same...
Quoted 1 line
*reg |= ((unsigned long)val & mask) << shift;
... here. The operation would need to be done on 64-bit rather than 32-bit.
Quoted 26 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
For other options, I would consider to either:
1) Fold vreg_reg_* in the macros.Quoted 7 lines
Quoted 1 line
Can you explain this option a bit ?
At the moment, we have generic helpers for vreg_reg_*. They are only called within the helper generated by
VREG_REG_HELPERS().If we make those helpers size specific, then the only the 64-bit helpers would use
uint64_tlocal variables.As they are only called in one place, we could fold them in the existing helpers.
Just to make sure, I understand this. The code would look like below
#define
VREG_REG_HELPERS(type, offmask)\static inline void vreg_reg_##type##_update(type *reg,
register_tval,
\const
mmio_info_t*info) \{ \
unsigned long mask =
VREG_REG_MASK(size); \
Quoted 8 lines
unsigned int offset =
info->gpa& (offmask); \int shift = offset * 8; \
*reg &= ~(mask << shift); \
*reg |= ((unsigned long)val & mask) << shift; \}
This implementation is not correct for 64-bit register. It would need to look like (untested):
static inline void vreg_reg##sz##_update(uint##sz##_t *reg,
register_t val, const mmio_info_t *info)
{
uint##sz##_t tmp = *reg;
uint##sz##_t mask = VREG_REG_MASK(info->dabt.size);
unsigned int offset = info->gap & (offsetmask);
*reg &= ~(mask << shift);
*reg |= ((uint##sz##_t)val & mask) << shift;
}Quoted 12 lines
#define
vreg_reg_update(reg, val, info)\do { \
if (sizeof(reg) == 4) \
vreg_reg_uint32_t_update(reg, val, info); \else if (sizeof(reg) == 8) \
Quoted 7 lines
vreg_reg_uint64_t_update(reg, val, info); \else \
BUG(); \} while(0); \
After your change above, nobody will call vreg_reg_update(). So no need to re-implement the function. You can simply drop it.
Quoted 5 lines
Similar implementation will be for
vreg_reg_clearbits(),vreg_reg_setbits()andvreg_reg_extract()
Quoted 8 lines
VREG_REG_HELPERS(uint32_t, 0x3);
VREG_REG_HELPERS(uint64_t, 0x7);And the functions would be invoked as follows :-
vreg_update(&priority, r, info);
The code should use vreg_reg<sz>_update() rather than the generic one. At least it will be clear from the caller which size is expected.
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC PATCH v1 03/12] Arm: GICv3: Enable vreg_reg64_* macros for AArch32
Hi Julien,
Quoted 5 lines
static inline void vreg_reg##sz##_update(uint##sz##_t *reg,
register_tval, constmmio_info_t*info) {
uint##sz##_t tmp = *reg;
Drop this as we don't use tmp.
Quoted 2 lines
uint##sz##_t mask =
VREG_REG_MASK(info->dabt.size); unsigned int offset =info->gap& (offsetmask);
int shift = offset * 8;
Quoted 4 lines
*reg &= ~(mask << shift);
*reg |= ((uint##sz##_t)val & mask) << shift;
}
I think this is correct. Except for an improvement (as above).
Also, we will always keep this defined for both Arm32 and Arm64
VREG_REG_HELPERS(32, 0x3);VREG_REG_HELPERS(64, 0x7);
- Ayan
RFC PATCH 4/12 Arm: GICv3: Emulate GICR_TYPER on AArch32
In reply to Ayan Kumar HalderRefer Arm IHI 0069H ID020922,
The upper 32 bits of GICR_TYPER represent the affinity whereas the lower 32 bits represent the other bits (eg processor number, etc).MPIDR_AFFINITY_LEVEL() returns a 32 bit number on aarch32. Thus, this is appended to return GICR_TYPER register.
--- xen/arch/arm/vgic-v3.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
xen/arch/arm/vgic-v3.c +9 -5
@@ -190,14 +190,18 @@ static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info,case VREG64 (GICR_TYPER ): { -uint64_t typer, aff; +uint64_t typer; +uint32_t aff;if ( !vgic_reg64_check_access (dabt) ) goto bad_width; - aff = (MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,3 ) <<56 | -MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,2 ) <<48 | -MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,1 ) <<40 | -MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,0 ) <<32 ); + aff = (MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,3 ) <<24 | +MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,2 ) <<16 | +MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,1 ) <<8 | +MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,0 )); typer = aff; + + typer = typer <<32 ; +/* We use the VCPU ID as the redistributor ID in bits[23:8] */ typer |= v->vcpu_id <<GICR_TYPER_PROC_NUM_SHIFT ;
Signature · 1 line
2.17.1
Re: [RFC PATCH v1 04/12] Arm: GICv3: Emulate GICR_TYPER on AArch32
On 10/21/22 18:31, Ayan Kumar Halder wrote:
Hi Ayan
Quoted 30 lines
Refer Arm IHI 0069H ID020922,
The upper 32 bits ofGICR_TYPERrepresent the affinity whereas the lower 32 bits represent the other bits (eg processor number, etc).MPIDR_AFFINITY_LEVEL()returns a 32 bit number on aarch32. Thus, this is appended to returnGICR_TYPERregister.Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/vgic-v3.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)xen/arch/arm/vgic-v3.c +3
-5@@ -190,14 +190,18 @@ static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info,case VREG64 (GICR_TYPER ): { -uint64_t typer, aff; +uint64_t typer; +uint32_t aff;if ( !vgic_reg64_check_access (dabt) ) goto bad_width; - aff = (MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,3 ) <<56 | -MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,2 ) <<48 | -MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,1 ) <<40 | -MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,0 ) <<32 ); + aff = (MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 3) << 24 |
xen/arch/arm/vgic-v3.c static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info, · line 207
Quoted 10 lines
xen/arch/arm/vgic-v3.c +6
-0+MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,2 ) <<16 | +MPIDR_AFFINITY_LEVEL (v->arch.vmpidr,1 ) <<8 | + MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 0)); typer = aff; + + typer = typer <<32 ; +/* We use the VCPU ID as the redistributor ID in bits[23:8] */ typer |= v->vcpu_id <<GICR_TYPER_PROC_NUM_SHIFT ;
I don't see an issue I just want to propose alternatives that I think would reduce the changes, hopefully without breaking it.
So, other ways would be either to assign v->arch.vmpidr to a new variable uint64_t vmpidr and operate on this (without changing the shifts), or to leave the type of aff uint64_t, adjust the shifts and do typer = aff << 32.
Signature · 1 line
Xenia
Re: [RFC PATCH v1 04/12] Arm: GICv3: Emulate GICR_TYPER on AArch32
Hi,
Quoted 9 lines · Xenia Ragiadakou
On 10/21/22 18:31, Ayan Kumar Halder wrote:
Hi AyanQuoted 6 lines
Refer Arm IHI 0069H ID020922,
The upper 32 bits ofGICR_TYPERrepresent the affinity whereas the lower 32 bits represent the other bits (eg processor number, etc).MPIDR_AFFINITY_LEVEL()returns a 32 bit number on aarch32. Thus, this is appended to returnGICR_TYPERregister.
The last sentence doesn't seem to match your modification below.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Ayan Kumar Halder <[email protected]>---
xen/arch/arm/vgic-v3.c| 14 +++++++++-----1 file changed, 9 insertions(+), 5 deletions(-)xen/arch/arm/vgic-v3.c +0
-0@@ -190,14 +190,18 @@ static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info,case
VREG64(GICR_TYPER):
{
-uint64_ttyper, aff;
+uint64_ttyper;
+uint32_taff;
if ( !vgic_reg64_check_access(dabt) ) gotobad_width; - aff = (MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 3)<< 56 | -MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 2)<< 48 | -MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 1)<< 40 |
Quoted 8 lines
Quoted 8 lines
-
MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 0)<< 32); + aff = (MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 3)<< 24 | +MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 2)<< 16 | +MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 1)<< 8 | +MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 0)); typer = aff;
+
+ typer = typer << 32;
I find the "typer = aff; typer = typer << 32" quite confusing to read. In fact, my first instinct would be to combine the two but this would do the wrong thing. So I would prefer if we use a different approach (see below).
Quoted 6 lines
Quoted 3 lines
+
/* We use the VCPU ID as the redistributor ID in bits[23:8] */ typer |=v->vcpu_id<<GICR_TYPER_PROC_NUM_SHIFT;I don't see an issue I just want to propose alternatives that I think would reduce the changes, hopefully without breaking it.
So, other ways would be either to assignv->arch.vmpidrto a new variableuint64_tvmpidr and operate on this (without changing the shifts), or to leave the type of affuint64_t, adjust the shifts and do typer = aff << 32.
How about making MPIDR_AFFINITY_LEVEL returning a 64-bit value? The other option would be to use what Xenia's last option. I.e:
" to level the type of aff uint64_t, adjust the shifts and do typer = aff << 32". This would need a suitable comment though explain why the shift can't be fold.
Cheers,
Signature · 1 line
Julien Grall
RFC PATCH 5/12 Arm: GICv3: Emulate GICR_PENDBASER and GICR_PROPBASER on AArch32
In reply to Ayan Kumar Halder'unsigned long long' is defined as 64 bit across both aarch32 and aarch64. So, use 'ULL' for 64 bit word instead of UL which is 32 bits for aarch32. GICR_PENDBASER and GICR_PROPBASER both are 64 bit registers.
--- xen/arch/arm/include/asm/gic_v3_defs.h | 16 ++++++++-------- xen/arch/arm/vgic-v3.c | 6 ++++-- 2 files changed, 12 insertions(+), 10 deletions(-)
xen/arch/arm/include/asm/gic_v3_defs.h +8 -8
@@ -134,15 +134,15 @@#define GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT 56#define GICR_PROPBASER_OUTER_CACHEABILITY_MASK \ - (7UL << GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT) + (7ULL << GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT)#define GICR_PROPBASER_SHAREABILITY_SHIFT 10#define GICR_PROPBASER_SHAREABILITY_MASK \ - (3UL << GICR_PROPBASER_SHAREABILITY_SHIFT) + (3ULL << GICR_PROPBASER_SHAREABILITY_SHIFT)#define GICR_PROPBASER_INNER_CACHEABILITY_SHIFT 7#define GICR_PROPBASER_INNER_CACHEABILITY_MASK \ - (7UL << GICR_PROPBASER_INNER_CACHEABILITY_SHIFT) + (7ULL << GICR_PROPBASER_INNER_CACHEABILITY_SHIFT)#define GICR_PROPBASER_RES0_MASK \ - (GENMASK(63, 59) | GENMASK(55, 52) | GENMASK(6, 5)) + (GENMASK_ULL(63, 59) | GENMASK_ULL(55, 52) | GENMASK_ULL(6, 5))#define GICR_PENDBASER_SHAREABILITY_SHIFT 10#define GICR_PENDBASER_INNER_CACHEABILITY_SHIFT 7
@@ -152,11 +152,11 @@#define GICR_PENDBASER_INNER_CACHEABILITY_MASK \ (7UL << GICR_PENDBASER_INNER_CACHEABILITY_SHIFT)#define GICR_PENDBASER_OUTER_CACHEABILITY_MASK \ - (7UL << GICR_PENDBASER_OUTER_CACHEABILITY_SHIFT) -#define GICR_PENDBASER_PTZ BIT(62, UL) + (7ULL << GICR_PENDBASER_OUTER_CACHEABILITY_SHIFT) +#define GICR_PENDBASER_PTZ BIT(62, ULL)#define GICR_PENDBASER_RES0_MASK \ - (BIT(63, UL) | GENMASK(61, 59) | GENMASK(55, 52) | \ - GENMASK(15, 12) | GENMASK(6, 0)) + (BIT(63, ULL) | GENMASK_ULL(61, 59) | GENMASK_ULL(55, 52) | \ + GENMASK_ULL(15, 12) | GENMASK_ULL(6, 0))#define DEFAULT_PMR_VALUE 0xff
xen/arch/arm/vgic-v3.c +4 -2
@@ -254,14 +254,16 @@ static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info,case VREG64 (GICR_PENDBASER ): {unsigned long flags; +uint64_t value;if ( !v->domain->arch.vgic.has_its ) goto read_as_zero_64;if ( !vgic_reg64_check_access (dabt) ) goto bad_width;spin_lock_irqsave (&v->arch.vgic.lock, flags); - *r =vreg_reg64_extract (v->arch.vgic.rdist_pendbase, info); - *r &= ~GICR_PENDBASER_PTZ ;/* WO, reads as 0 */ + value = v->arch.vgic.rdist_pendbase; + value &= ~GICR_PENDBASER_PTZ ;/* WO, reads as 0 */ + *r =vreg_reg64_extract (value, info);spin_unlock_irqrestore (&v->arch.vgic.lock, flags);return 1 ; }
Signature · 1 line
2.17.1
Re: [RFC PATCH v1 05/12] Arm: GICv3: Emulate GICR_PENDBASER and GICR_PROPBASER on AArch32
Hi Ayan,
Title: To me, it reads as if you provide a brand new code for emulating the registers. However, below, you are only fixing the code. So how about:
"xen/arm: gicv3: Fix GICR_{PENDBASER, PROPBASER} emulation on 32-bit host"
Quoted 60 lines · Ayan Kumar Halder
'unsigned long long' is defined as 64 bit across both aarch32 and aarch64. So, use 'ULL' for 64 bit word instead of UL which is 32 bits for aarch32.
GICR_PENDBASERandGICR_PROPBASERboth are 64 bit registers.Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/include/asm/gic_v3_defs.h | 16 ++++++++-------- xen/arch/arm/vgic-v3.c | 6 ++++-- 2 files changed, 12 insertions(+), 10 deletions(-)xen/arch/arm/include/asm/gic_v3_defs.h +8
-8@@ -134,15 +134,15 @@#define GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT 56#define GICR_PROPBASER_OUTER_CACHEABILITY_MASK \ - (7UL << GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT) + (7ULL << GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT)#define GICR_PROPBASER_SHAREABILITY_SHIFT 10#define GICR_PROPBASER_SHAREABILITY_MASK \ - (3UL << GICR_PROPBASER_SHAREABILITY_SHIFT) + (3ULL << GICR_PROPBASER_SHAREABILITY_SHIFT)#define GICR_PROPBASER_INNER_CACHEABILITY_SHIFT 7#define GICR_PROPBASER_INNER_CACHEABILITY_MASK \ - (7UL << GICR_PROPBASER_INNER_CACHEABILITY_SHIFT) + (7ULL << GICR_PROPBASER_INNER_CACHEABILITY_SHIFT)#define GICR_PROPBASER_RES0_MASK \ - (GENMASK(63, 59) | GENMASK(55, 52) | GENMASK(6, 5)) + (GENMASK_ULL(63, 59) | GENMASK_ULL(55, 52) | GENMASK_ULL(6, 5))#define GICR_PENDBASER_SHAREABILITY_SHIFT 10#define GICR_PENDBASER_INNER_CACHEABILITY_SHIFT 7@@ -152,11 +152,11 @@#define GICR_PENDBASER_INNER_CACHEABILITY_MASK \ (7UL << GICR_PENDBASER_INNER_CACHEABILITY_SHIFT)#define GICR_PENDBASER_OUTER_CACHEABILITY_MASK \ - (7UL << GICR_PENDBASER_OUTER_CACHEABILITY_SHIFT) -#define GICR_PENDBASER_PTZ BIT(62, UL) + (7ULL << GICR_PENDBASER_OUTER_CACHEABILITY_SHIFT) +#define GICR_PENDBASER_PTZ BIT(62, ULL)#define GICR_PENDBASER_RES0_MASK \ - (BIT(63, UL) | GENMASK(61, 59) | GENMASK(55, 52) | \ - GENMASK(15, 12) | GENMASK(6, 0)) + (BIT(63, ULL) | GENMASK_ULL(61, 59) | GENMASK_ULL(55, 52) | \ + GENMASK_ULL(15, 12) | GENMASK_ULL(6, 0))rer#define DEFAULT_PMR_VALUE 0xffxen/arch/arm/vgic-v3.c +1
-0@@ -254,14 +254,16 @@ static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info,case VREG64 (GICR_PENDBASER ): {unsigned long flags; +uint64_t value;
xen/arch/arm/vgic-v3.c static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info, · line 266
Quoted 10 lines
xen/arch/arm/vgic-v3.c +3
-2if ( !v->domain->arch.vgic.has_its ) goto read_as_zero_64;if ( !vgic_reg64_check_access (dabt) ) goto bad_width;spin_lock_irqsave (&v->arch.vgic.lock, flags); - *r =vreg_reg64_extract (v->arch.vgic.rdist_pendbase, info); - *r &= ~GICR_PENDBASER_PTZ ;/* WO, reads as 0 */ + value = v->arch.vgic.rdist_pendbase; + value &= ~GICR_PENDBASER_PTZ ;/* WO, reads as 0 */ + *r =vreg_reg64_extract (value, info);
The commit message suggests the code would only be replacing "UL" with "ULL". But here, you are doing more than that. The code is re-order so PTZ is cleared before extracting the value.
I agree the existing code was wrong if the guest was using 32-bit access and your new approach is correct. Can you split the change in a separate patch? (Please add a Fixes tag as well).
xen/arch/arm/vgic-v3.c static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info, · line 269
Quoted 3 lines
xen/arch/arm/vgic-v3.c +0
-0spin_unlock_irqrestore (&v->arch.vgic.lock, flags);return 1 ; }
Cheers,
Signature · 1 line
Julien Grall
RFC PATCH 6/12 Arm: GICv3: Emulate of ICC_SGI1R on AArch32
In reply to Ayan Kumar HalderRefer Arm IHI 0069H ID020922, 12.5.23, ICC_SGI1R is a 64 bit register on Aarch32 systems. Thus, the prototype needs to change to reflect this.
--- xen/arch/arm/vgic-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/vgic-v3.c +1 -1
@@ -1482,7 +1482,7 @@ write_reserved:return 1 ; } -static bool vgic_v3_to_sgi (struct vcpu *v,register_t sgir) +static bool vgic_v3_to_sgi (struct vcpu *v,uint64_t sgir) {int virq;int irqmode;
Signature · 1 line
2.17.1
Re: [RFC PATCH v1 06/12] Arm: GICv3: Emulate of ICC_SGI1R on AArch32
Title: Similar to the previous patch, you are fixing the existing emulation.
Quoted 2 lines · Ayan Kumar Halder
Refer Arm IHI 0069H ID020922, 12.5.23,
ICC_SGI1Ris a 64 bit register on Aarch32 systems. Thus, the prototype needs to change to reflect this.
At first, it wasn't obvious why changing the prototype is enough. So it would be good to explain it in the commit message.
Quoted 11 lines
Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/vgic-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/arm/vgic-v3.c +0
-0
xen/arch/arm/vgic-v3.c write_reserved: · line 1488
Quoted 8 lines
xen/arch/arm/vgic-v3.c +1
-1@@ -1482,7 +1482,7 @@ write_reserved:return 1 ; } -static bool vgic_v3_to_sgi (struct vcpu *v,register_t sgir) +static bool vgic_v3_to_sgi (struct vcpu *v,uint64_t sgir) {int virq;int irqmode;
Cheers,
Signature · 1 line
Julien Grall
RFC PATCH 7/12 Arm: GICv3: Emulate ICH_LR<n>_EL2 on AArch32
In reply to Ayan Kumar HalderRefer "Arm IHI 0069H ID020922", 12.4.6, Interrupt Controller List Registers
AArch64 System register ICH_LR<n>_EL2 bits [31:0] are architecturally mapped to AArch32 System register ICH_LR<n>[31:0].
AArch64 System register ICH_LR<n>_EL2 bits [63:32] are architecturally mapped to AArch32 System register ICH_LRC<n>[31:0].
Defined ICH_LR<0...15>_EL2 and ICH_LRC<0...15>_EL2 for Aarch32. For AArch32, the link register is stored as :- (((uint64_t) ICH_LRC<0...15>_EL2) << 32) | ICH_LR<0...15>_EL2
Also, ICR_LR macros need to be modified as ULL is 64 bits for AArch32 and AArch64.
--- xen/arch/arm/gic-v3.c | 132 +++++++++++------------ xen/arch/arm/include/asm/arm32/sysregs.h | 52 +++++++++ xen/arch/arm/include/asm/arm64/sysregs.h | 7 +- xen/arch/arm/include/asm/gic_v3_defs.h | 6 +- 4 files changed, 126 insertions(+), 71 deletions(-)
xen/arch/arm/gic-v3.c +66 -66
@@ -73,37 +73,37 @@ static inline void gicv3_save_lrs(struct vcpu *v)switch ( gicv3_info.nr_lrs ) {case 16 : - v->arch.gic.v3.lr[15 ] =READ_SYSREG (ICH_LR15_EL2 ); + v->arch.gic.v3.lr[15 ] =READ_SYSREG_LR (15 );case 15 : - v->arch.gic.v3.lr[14 ] =READ_SYSREG (ICH_LR14_EL2 ); + v->arch.gic.v3.lr[14 ] =READ_SYSREG_LR (14 );case 14 : - v->arch.gic.v3.lr[13 ] =READ_SYSREG (ICH_LR13_EL2 ); + v->arch.gic.v3.lr[13 ] =READ_SYSREG_LR (13 );case 13 : - v->arch.gic.v3.lr[12 ] =READ_SYSREG (ICH_LR12_EL2 ); + v->arch.gic.v3.lr[12 ] =READ_SYSREG_LR (12 );case 12 : - v->arch.gic.v3.lr[11 ] =READ_SYSREG (ICH_LR11_EL2 ); + v->arch.gic.v3.lr[11 ] =READ_SYSREG_LR (11 );case 11 : - v->arch.gic.v3.lr[10 ] =READ_SYSREG (ICH_LR10_EL2 ); + v->arch.gic.v3.lr[10 ] =READ_SYSREG_LR (10 );case 10 : - v->arch.gic.v3.lr[9 ] =READ_SYSREG (ICH_LR9_EL2 ); + v->arch.gic.v3.lr[9 ] =READ_SYSREG_LR (9 );case 9 : - v->arch.gic.v3.lr[8 ] =READ_SYSREG (ICH_LR8_EL2 ); + v->arch.gic.v3.lr[8 ] =READ_SYSREG_LR (8 );case 8 : - v->arch.gic.v3.lr[7 ] =READ_SYSREG (ICH_LR7_EL2 ); + v->arch.gic.v3.lr[7 ] =READ_SYSREG_LR (7 );case 7 : - v->arch.gic.v3.lr[6 ] =READ_SYSREG (ICH_LR6_EL2 ); + v->arch.gic.v3.lr[6 ] =READ_SYSREG_LR (6 );case 6 : - v->arch.gic.v3.lr[5 ] =READ_SYSREG (ICH_LR5_EL2 ); + v->arch.gic.v3.lr[5 ] =READ_SYSREG_LR (5 );case 5 : - v->arch.gic.v3.lr[4 ] =READ_SYSREG (ICH_LR4_EL2 ); + v->arch.gic.v3.lr[4 ] =READ_SYSREG_LR (4 );case 4 : - v->arch.gic.v3.lr[3 ] =READ_SYSREG (ICH_LR3_EL2 ); + v->arch.gic.v3.lr[3 ] =READ_SYSREG_LR (3 );case 3 : - v->arch.gic.v3.lr[2 ] =READ_SYSREG (ICH_LR2_EL2 ); + v->arch.gic.v3.lr[2 ] =READ_SYSREG_LR (2 );case 2 : - v->arch.gic.v3.lr[1 ] =READ_SYSREG (ICH_LR1_EL2 ); + v->arch.gic.v3.lr[1 ] =READ_SYSREG_LR (1 );case 1 : - v->arch.gic.v3.lr[0 ] =READ_SYSREG (ICH_LR0_EL2 ); + v->arch.gic.v3.lr[0 ] =READ_SYSREG_LR (0 );break ;default :BUG ();
@@ -120,37 +120,37 @@ static inline void gicv3_restore_lrs(const struct vcpu *v)switch ( gicv3_info.nr_lrs ) {case 16 : -WRITE_SYSREG (v->arch.gic.v3.lr[15 ],ICH_LR15_EL2 ); +WRITE_SYSREG_LR (15 , v->arch.gic.v3.lr[15 ]);case 15 : -WRITE_SYSREG (v->arch.gic.v3.lr[14 ],ICH_LR14_EL2 ); +WRITE_SYSREG_LR (14 , v->arch.gic.v3.lr[14 ]);case 14 : -WRITE_SYSREG (v->arch.gic.v3.lr[13 ],ICH_LR13_EL2 ); +WRITE_SYSREG_LR (13 , v->arch.gic.v3.lr[13 ]);case 13 : -WRITE_SYSREG (v->arch.gic.v3.lr[12 ],ICH_LR12_EL2 ); +WRITE_SYSREG_LR (12 , v->arch.gic.v3.lr[12 ]);case 12 : -WRITE_SYSREG (v->arch.gic.v3.lr[11 ],ICH_LR11_EL2 ); +WRITE_SYSREG_LR (11 , v->arch.gic.v3.lr[11 ]);case 11 : -WRITE_SYSREG (v->arch.gic.v3.lr[10 ],ICH_LR10_EL2 ); +WRITE_SYSREG_LR (10 , v->arch.gic.v3.lr[10 ]);case 10 : -WRITE_SYSREG (v->arch.gic.v3.lr[9 ],ICH_LR9_EL2 ); +WRITE_SYSREG_LR (9 , v->arch.gic.v3.lr[9 ]);case 9 : -WRITE_SYSREG (v->arch.gic.v3.lr[8 ],ICH_LR8_EL2 ); +WRITE_SYSREG_LR (8 , v->arch.gic.v3.lr[8 ]);case 8 : -WRITE_SYSREG (v->arch.gic.v3.lr[7 ],ICH_LR7_EL2 ); +WRITE_SYSREG_LR (7 , v->arch.gic.v3.lr[7 ]);case 7 : -WRITE_SYSREG (v->arch.gic.v3.lr[6 ],ICH_LR6_EL2 ); +WRITE_SYSREG_LR (6 , v->arch.gic.v3.lr[6 ]);case 6 : -WRITE_SYSREG (v->arch.gic.v3.lr[5 ],ICH_LR5_EL2 ); +WRITE_SYSREG_LR (5 , v->arch.gic.v3.lr[5 ]);case 5 : -WRITE_SYSREG (v->arch.gic.v3.lr[4 ],ICH_LR4_EL2 ); +WRITE_SYSREG_LR (4 , v->arch.gic.v3.lr[4 ]);case 4 : -WRITE_SYSREG (v->arch.gic.v3.lr[3 ],ICH_LR3_EL2 ); +WRITE_SYSREG_LR (3 , v->arch.gic.v3.lr[3 ]);case 3 : -WRITE_SYSREG (v->arch.gic.v3.lr[2 ],ICH_LR2_EL2 ); +WRITE_SYSREG_LR (2 , v->arch.gic.v3.lr[2 ]);case 2 : -WRITE_SYSREG (v->arch.gic.v3.lr[1 ],ICH_LR1_EL2 ); +WRITE_SYSREG_LR (1 , v->arch.gic.v3.lr[1 ]);case 1 : -WRITE_SYSREG (v->arch.gic.v3.lr[0 ],ICH_LR0_EL2 ); +WRITE_SYSREG_LR (0 , v->arch.gic.v3.lr[0 ]);break ;default :BUG ();
@@ -161,22 +161,22 @@ static uint64_t gicv3_ich_read_lr(int lr) {switch ( lr ) { -case 0 :return READ_SYSREG (ICH_LR0_EL2 ); -case 1 :return READ_SYSREG (ICH_LR1_EL2 ); -case 2 :return READ_SYSREG (ICH_LR2_EL2 ); -case 3 :return READ_SYSREG (ICH_LR3_EL2 ); -case 4 :return READ_SYSREG (ICH_LR4_EL2 ); -case 5 :return READ_SYSREG (ICH_LR5_EL2 ); -case 6 :return READ_SYSREG (ICH_LR6_EL2 ); -case 7 :return READ_SYSREG (ICH_LR7_EL2 ); -case 8 :return READ_SYSREG (ICH_LR8_EL2 ); -case 9 :return READ_SYSREG (ICH_LR9_EL2 ); -case 10 :return READ_SYSREG (ICH_LR10_EL2 ); -case 11 :return READ_SYSREG (ICH_LR11_EL2 ); -case 12 :return READ_SYSREG (ICH_LR12_EL2 ); -case 13 :return READ_SYSREG (ICH_LR13_EL2 ); -case 14 :return READ_SYSREG (ICH_LR14_EL2 ); -case 15 :return READ_SYSREG (ICH_LR15_EL2 ); +case 0 :return READ_SYSREG_LR (0 ); +case 1 :return READ_SYSREG_LR (1 ); +case 2 :return READ_SYSREG_LR (2 ); +case 3 :return READ_SYSREG_LR (3 ); +case 4 :return READ_SYSREG_LR (4 ); +case 5 :return READ_SYSREG_LR (5 ); +case 6 :return READ_SYSREG_LR (6 ); +case 7 :return READ_SYSREG_LR (7 ); +case 8 :return READ_SYSREG_LR (8 ); +case 9 :return READ_SYSREG_LR (9 ); +case 10 :return READ_SYSREG_LR (10 ); +case 11 :return READ_SYSREG_LR (11 ); +case 12 :return READ_SYSREG_LR (12 ); +case 13 :return READ_SYSREG_LR (13 ); +case 14 :return READ_SYSREG_LR (14 ); +case 15 :return READ_SYSREG_LR (15 );default :BUG (); }
@@ -187,52 +187,52 @@ static void gicv3_ich_write_lr(int lr, uint64_t val)switch ( lr ) {case 0 : -WRITE_SYSREG (val,ICH_LR0_EL2 ); +WRITE_SYSREG_LR (0 , val);break ;case 1 : -WRITE_SYSREG (val,ICH_LR1_EL2 ); +WRITE_SYSREG_LR (1 , val);break ;case 2 : -WRITE_SYSREG (val,ICH_LR2_EL2 ); +WRITE_SYSREG_LR (2 , val);break ;case 3 : -WRITE_SYSREG (val,ICH_LR3_EL2 ); +WRITE_SYSREG_LR (3 , val);break ;case 4 : -WRITE_SYSREG (val,ICH_LR4_EL2 ); +WRITE_SYSREG_LR (4 , val);break ;case 5 : -WRITE_SYSREG (val,ICH_LR5_EL2 ); +WRITE_SYSREG_LR (5 , val);break ;case 6 : -WRITE_SYSREG (val,ICH_LR6_EL2 ); +WRITE_SYSREG_LR (6 , val);break ;case 7 : -WRITE_SYSREG (val,ICH_LR7_EL2 ); +WRITE_SYSREG_LR (7 , val);break ;case 8 : -WRITE_SYSREG (val,ICH_LR8_EL2 ); +WRITE_SYSREG_LR (8 , val);break ;case 9 : -WRITE_SYSREG (val,ICH_LR9_EL2 ); +WRITE_SYSREG_LR (9 , val);break ;case 10 : -WRITE_SYSREG (val,ICH_LR10_EL2 ); +WRITE_SYSREG_LR (10 , val);break ;case 11 : -WRITE_SYSREG (val,ICH_LR11_EL2 ); +WRITE_SYSREG_LR (11 , val);break ;case 12 : -WRITE_SYSREG (val,ICH_LR12_EL2 ); +WRITE_SYSREG_LR (12 , val);break ;case 13 : -WRITE_SYSREG (val,ICH_LR13_EL2 ); +WRITE_SYSREG_LR (13 , val);break ;case 14 : -WRITE_SYSREG (val,ICH_LR14_EL2 ); +WRITE_SYSREG_LR (14 , val);break ;case 15 : -WRITE_SYSREG (val,ICH_LR15_EL2 ); +WRITE_SYSREG_LR (15 , val);break ;default :return ;
@@ -417,12 +417,12 @@ static void gicv3_dump_state(const struct vcpu *v)if ( v == current ) {for ( i =0 ; i < gicv3_info.nr_lrs; i++ ) -printk (" HW_LR[%d]=%lx\n" , i,gicv3_ich_read_lr (i)); +printk (" HW_LR[%d]=%llx\n" , i,gicv3_ich_read_lr (i)); }else {for ( i =0 ; i < gicv3_info.nr_lrs; i++ ) -printk (" VCPU_LR[%d]=%lx\n" , i, v->arch.gic.v3.lr[i]); +printk (" VCPU_LR[%d]=%llx\n" , i, v->arch.gic.v3.lr[i]); } }
xen/arch/arm/include/asm/arm32/sysregs.h +52 -0
61 lines not on this page · raw message
xen/arch/arm/include/asm/arm64/sysregs.h +5 -2
@@ -469,8 +469,11 @@ asm volatile("mrs %0, "__stringify(name) : "=r" (_r)); \ _r; }) -#define READ_SYSREG (name) READ_SYSREG64(name) -#define WRITE_SYSREG (v, name) WRITE_SYSREG64(v, name) +#define READ_SYSREG (name) READ_SYSREG64(name) +#define WRITE_SYSREG (v, name) WRITE_SYSREG64(v, name) +#define ICH_LR_REG (index) ICH_LR ## index ## _EL2 +#define WRITE_SYSREG_LR (index, v) WRITE_SYSREG(v, ICH_LR_REG(index)) +#define READ_SYSREG_LR (index) READ_SYSREG(ICH_LR_REG(index))#endif /* _ASM_ARM_ARM64_SYSREGS_H */
xen/arch/arm/include/asm/gic_v3_defs.h +3 -3
@@ -185,9 +185,9 @@#define ICH_LR_HW_SHIFT 61#define ICH_LR_GRP_MASK 0x1#define ICH_LR_GRP_SHIFT 60 -#define ICH_LR_MAINTENANCE_IRQ (1UL<<41) -#define ICH_LR_GRP1 (1UL<<60) -#define ICH_LR_HW (1UL<<61) +#define ICH_LR_MAINTENANCE_IRQ (1ULL<<41) +#define ICH_LR_GRP1 (1ULL<<60) +#define ICH_LR_HW (1ULL<<61)#define ICH_VTR_NRLRGS 0x3f#define ICH_VTR_PRIBITS_MASK 0x7
Signature · 1 line
2.17.1
Re: [RFC PATCH v1 07/12] Arm: GICv3: Emulate ICH_LR<n>_EL2 on AArch32
Hi Ayan,
Title: Xen doesn't emulate ICH_LR* (we don't expose them to the guest). Instead Xen will use the registers and your patch provides wrappers to use access the registers on 32-bit host.
Quoted 5 lines · Ayan Kumar Halder
xen/arch/arm/include/asm/arm32/sysregs.h +0
-0
xen/arch/arm/include/asm/arm32/sysregs.h line 70
Quoted 9 lines
xen/arch/arm/include/asm/arm32/sysregs.h +6
-0@@ -62,9 +62,61 @@ #define READ_SYSREG(R...) READ_SYSREG32(R) #define WRITE_SYSREG(V, R...) WRITE_SYSREG32(V, R) +#define ICH_LR_REG (INDEX ) ICH_LR ## INDEX ## _EL2 +#define ICH_LRC_REG (INDEX ) ICH_LRC ## INDEX ## _EL2 + +#define READ_SYSREG_LR (INDEX ) ((((uint64_t) \ + (READ_SYSREG(ICH_LRC_REG(INDEX)))) << 32) | \ + (READ_SYSREG(ICH_LR_REG(INDEX))))
This is a bit dense to read. Also, we should use READ_CP64() when dealing with arm32 only code. So how about (formatting will need to be done):
#define READ_SYSREG_LR(INDEX) ({ \
uint32_t lrc_ = READ_CP64(ICH_LRC_REG(INDEX)); \
uint32_t lr_ = READ_CP64(ICH_LR_REG(INDEX)); \
\
(uint64_t)(lrc_ << 32) | lr_;
})xen/arch/arm/include/asm/arm32/sysregs.h line 74
Quoted 4 lines
xen/arch/arm/include/asm/arm32/sysregs.h +4
-0+ +#define WRITE_SYSREG_LR (INDEX ,V ) WRITE_SYSREG \ + (V&0xFFFFFFFF, ICH_LR_REG(INDEX)); \ + WRITE_SYSREG(V>>32, ICH_LRC_REG(INDEX));
This code is fragile. If V is a function call, then you will call it twice. You want something like:
do {
uint64_t v_ = (V);
WRITE_SYSREG(v_ & 0xFFFFFFFF, ICH_LR_REG(INDEX)); WRITE_SYSREG(v_ >> 32, ICH_LRC_REG(INDEX));
} while(0);
And maybe replacing the opencoding Fs with GENMASK.
xen/arch/arm/include/asm/arm32/sysregs.h line 79
Quoted 5 lines
xen/arch/arm/include/asm/arm32/sysregs.h +2
-0+/* MVFR2 is not defined on ARMv7 */ #define MVFR2_MAYBE_UNDEFINED +#define ___CP32 (a,b,c,d,e) a,b,c,d,e
I am not entirely sure why you need to define __CP32() here. However, co-processors registers should be defined in asm/cpregs.h rather than arm32/sysregs.h.
Quoted 48 lines
xen/arch/arm/include/asm/arm32/sysregs.h +40
-0+#define __LR0_EL2 (x) ___CP32(p15,4,c12,c12,x) +#define __LR8_EL2 (x) ___CP32(p15,4,c12,c13,x) + +#define __LRC0_EL2 (x) ___CP32(p15,4,c12,c14,x) +#define __LRC8_EL2 (x) ___CP32(p15,4,c12,c15,x) + +#define ICH_LR0_EL2 __LR0_EL2(0) +#define ICH_LR1_EL2 __LR0_EL2(1) +#define ICH_LR2_EL2 __LR0_EL2(2) +#define ICH_LR3_EL2 __LR0_EL2(3) +#define ICH_LR4_EL2 __LR0_EL2(4) +#define ICH_LR5_EL2 __LR0_EL2(5) +#define ICH_LR6_EL2 __LR0_EL2(6) +#define ICH_LR7_EL2 __LR0_EL2(7) +#define ICH_LR8_EL2 __LR8_EL2(0) +#define ICH_LR9_EL2 __LR8_EL2(1) +#define ICH_LR10_EL2 __LR8_EL2(2) +#define ICH_LR11_EL2 __LR8_EL2(3) +#define ICH_LR12_EL2 __LR8_EL2(4) +#define ICH_LR13_EL2 __LR8_EL2(5) +#define ICH_LR14_EL2 __LR8_EL2(6) +#define ICH_LR15_EL2 __LR8_EL2(7) + +#define ICH_LRC0_EL2 __LRC0_EL2(0) +#define ICH_LRC1_EL2 __LRC0_EL2(1) +#define ICH_LRC2_EL2 __LRC0_EL2(2) +#define ICH_LRC3_EL2 __LRC0_EL2(3) +#define ICH_LRC4_EL2 __LRC0_EL2(4) +#define ICH_LRC5_EL2 __LRC0_EL2(5) +#define ICH_LRC6_EL2 __LRC0_EL2(6) +#define ICH_LRC7_EL2 __LRC0_EL2(7) +#define ICH_LRC8_EL2 __LRC8_EL2(0) +#define ICH_LRC9_EL2 __LRC8_EL2(1) +#define ICH_LRC10_EL2 __LRC8_EL2(2) +#define ICH_LRC11_EL2 __LRC8_EL2(3) +#define ICH_LRC12_EL2 __LRC8_EL2(4) +#define ICH_LRC13_EL2 __LRC8_EL2(5) +#define ICH_LRC14_EL2 __LRC8_EL2(6) +#define ICH_LRC15_EL2 __LRC8_EL2(7) +#endif /* __ASSEMBLY__ */ #endif /* __ASM_ARM_ARM32_SYSREGS_H */ xen/arch/arm/include/asm/arm64/sysregs.h +0
-0
xen/arch/arm/include/asm/arm64/sysregs.h line 473
Quoted 7 lines
xen/arch/arm/include/asm/arm64/sysregs.h +2
-2@@ -469,8 +469,11 @@ asm volatile("mrs %0, "__stringify(name) : "=r" (_r)); \ _r; }) -#define READ_SYSREG (name) READ_SYSREG64(name) -#define WRITE_SYSREG (v, name) WRITE_SYSREG64(v, name) +#define READ_SYSREG (name) READ_SYSREG64(name) +#define WRITE_SYSREG (v, name) WRITE_SYSREG64(v, name)
Please don't re-indent existing macro. This is only introducing unnecessary extra churn.
Quoted 13 lines
xen/arch/arm/include/asm/arm64/sysregs.h +3
-0+#define ICH_LR_REG (index) ICH_LR ## index ## _EL2 +#define WRITE_SYSREG_LR (index, v) WRITE_SYSREG(v, ICH_LR_REG(index)) +#define READ_SYSREG_LR (index) READ_SYSREG(ICH_LR_REG(index))#endif /* _ASM_ARM_ARM64_SYSREGS_H */ xen/arch/arm/include/asm/gic_v3_defs.h +0
-0@@ -185,9 +185,9 @@#define ICH_LR_HW_SHIFT 61#define ICH_LR_GRP_MASK 0x1
xen/arch/arm/include/asm/gic_v3_defs.h line 193
Quoted 10 lines
xen/arch/arm/include/asm/gic_v3_defs.h +3
-3#define ICH_LR_GRP_SHIFT 60 -#define ICH_LR_MAINTENANCE_IRQ (1UL<<41) -#define ICH_LR_GRP1 (1UL<<60) -#define ICH_LR_HW (1UL<<61) +#define ICH_LR_MAINTENANCE_IRQ (1ULL<<41) +#define ICH_LR_GRP1 (1ULL<<60) +#define ICH_LR_HW (1ULL<<61)#define ICH_VTR_NRLRGS 0x3f#define ICH_VTR_PRIBITS_MASK 0x7
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC PATCH v1 07/12] Arm: GICv3: Emulate ICH_LR<n>_EL2 on AArch32
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
I need a clarification.
Quoted 20 lines
Title: Xen doesn't emulate ICH_LR* (we don't expose them to the guest). Instead Xen will use the registers and your patch provides wrappers to use access the registers on 32-bit host.
xen/arch/arm/include/asm/arm32/sysregs.h line 70
Quoted 13 lines · Ayan Kumar Halder
xen/arch/arm/include/asm/arm32/sysregs.h +0
-0@@ -62,9 +62,61 @@ #define READ_SYSREG(R...) READ_SYSREG32(R) #define WRITE_SYSREG(V, R...) WRITE_SYSREG32(V, R)+#define ICH_LR_REG(INDEX)
ICH_LR## INDEX ##_EL2xen/arch/arm/include/asm/arm32/sysregs.h +5
-0+#define ICH_LRC_REG (INDEX ) ICH_LRC ## INDEX ## _EL2 + +#define READ_SYSREG_LR (INDEX ) ((((uint64_t) \ + (READ_SYSREG(ICH_LRC_REG(INDEX)))) << 32) | \ + (READ_SYSREG(ICH_LR_REG(INDEX))))This is a bit dense to read. Also, we should use
READ_CP64()when dealing with arm32 only code. So how about (formatting will need to be done):
Quoted 4 lines
#define
READ_SYSREG_LR(INDEX)({ \
uint32_tlrc_= READ_CP64(ICH_LRC_REG(INDEX)); \
uint32_tlr_= READ_CP64(ICH_LR_REG(INDEX)); \
\
I think this looks incorrect. These are read using 'mrc' so they should be READ_CP32(). They are 32 bit registers.
However, READ_SYSREG is defined as READ_CP32(), so should we use READ_CP32() or READ_SYSREG() ?
- Ayan
Quoted 105 lines
(uint64_t)(lrc_ << 32) |
lr_;
})Quoted 5 lines
xen/arch/arm/include/asm/arm32/sysregs.h +4
-0+ +#define WRITE_SYSREG_LR (INDEX ,V ) WRITE_SYSREG \ + (V&0xFFFFFFFF, ICH_LR_REG(INDEX)); \ + WRITE_SYSREG(V>>32,
ICH_LRC_REG(INDEX));This code is fragile. If V is a function call, then you will call it twice. You want something like:
do {
uint64_tv_ = (V);
WRITE_SYSREG(v_ & 0xFFFFFFFF, ICH_LR_REG(INDEX));WRITE_SYSREG(v_ >> 32, ICH_LRC_REG(INDEX)); } while(0);And maybe replacing the opencoding Fs with GENMASK.
Quoted 4 lines
+
/* MVFR2 is not defined on ARMv7 */
#defineMVFR2_MAYBE_UNDEFINED
+#define ___CP32(a,b,c,d,e) a,b,c,d,eI am not entirely sure why you need to define
__CP32()here. However, co-processors registers should be defined inasm/cpregs.hrather thanarm32/sysregs.h.Quoted 47 lines
xen/arch/arm/include/asm/arm32/sysregs.h +40
-0+#define __LR0_EL2 (x) ___CP32(p15,4,c12,c12,x) +#define __LR8_EL2 (x) ___CP32(p15,4,c12,c13,x) + +#define __LRC0_EL2 (x) ___CP32(p15,4,c12,c14,x) +#define __LRC8_EL2 (x) ___CP32(p15,4,c12,c15,x) + +#define ICH_LR0_EL2 __LR0_EL2(0) +#define ICH_LR1_EL2 __LR0_EL2(1) +#define ICH_LR2_EL2 __LR0_EL2(2) +#define ICH_LR3_EL2 __LR0_EL2(3) +#define ICH_LR4_EL2 __LR0_EL2(4) +#define ICH_LR5_EL2 __LR0_EL2(5) +#define ICH_LR6_EL2 __LR0_EL2(6) +#define ICH_LR7_EL2 __LR0_EL2(7) +#define ICH_LR8_EL2 __LR8_EL2(0) +#define ICH_LR9_EL2 __LR8_EL2(1) +#define ICH_LR10_EL2 __LR8_EL2(2) +#define ICH_LR11_EL2 __LR8_EL2(3) +#define ICH_LR12_EL2 __LR8_EL2(4) +#define ICH_LR13_EL2 __LR8_EL2(5) +#define ICH_LR14_EL2 __LR8_EL2(6) +#define ICH_LR15_EL2 __LR8_EL2(7) + +#define ICH_LRC0_EL2 __LRC0_EL2(0) +#define ICH_LRC1_EL2 __LRC0_EL2(1) +#define ICH_LRC2_EL2 __LRC0_EL2(2) +#define ICH_LRC3_EL2 __LRC0_EL2(3) +#define ICH_LRC4_EL2 __LRC0_EL2(4) +#define ICH_LRC5_EL2 __LRC0_EL2(5) +#define ICH_LRC6_EL2 __LRC0_EL2(6) +#define ICH_LRC7_EL2 __LRC0_EL2(7) +#define ICH_LRC8_EL2 __LRC8_EL2(0) +#define ICH_LRC9_EL2 __LRC8_EL2(1) +#define ICH_LRC10_EL2 __LRC8_EL2(2) +#define ICH_LRC11_EL2 __LRC8_EL2(3) +#define ICH_LRC12_EL2 __LRC8_EL2(4) +#define ICH_LRC13_EL2 __LRC8_EL2(5) +#define ICH_LRC14_EL2 __LRC8_EL2(6) +#define ICH_LRC15_EL2 __LRC8_EL2(7) +#endif /*
__ASSEMBLY__*/
#endif /*__ASM_ARM_ARM32_SYSREGS_H*/xen/arch/arm/include/asm/arm64/sysregs.h +0
-0xen/arch/arm/include/asm/arm64/sysregs.h line 473
Quoted 6 lines
xen/arch/arm/include/asm/arm64/sysregs.h +2
-1@@ -469,8 +469,11 @@ asm volatile("mrs %0, "__stringify(name) : "=r" (_r)); \ _r; }) -#define READ_SYSREG(name) READ_SYSREG64(name) -#define WRITE_SYSREG (v, name) WRITE_SYSREG64(v, name) +#define READ_SYSREG (name) READ_SYSREG64(name) +#define WRITE_SYSREG (v, name) WRITE_SYSREG64(v, name)Please don't re-indent existing macro. This is only introducing unnecessary extra churn.
Quoted 10 lines
xen/arch/arm/include/asm/arm64/sysregs.h +3
-0+#define ICH_LR_REG (index) ICH_LR ## index ## _EL2 +#define WRITE_SYSREG_LR (index, v) WRITE_SYSREG(v, ICH_LR_REG(index)) +#define READ_SYSREG_LR (index) READ_SYSREG(ICH_LR_REG(index)) #endif /* _ASM_ARM_ARM64_SYSREGS_H */diff --git
a/xen/arch/arm/include/asm/gic_v3_defs.hb/xen/arch/arm/include/asm/gic_v3_defs.hindex48a1bc401e..87115f8b25100644xen/arch/arm/include/asm/gic_v3_defs.h +0
-0@@ -185,9 +185,9 @@ #define ICH_LR_HW_SHIFT 61xen/arch/arm/include/asm/gic_v3_defs.h line 192
Quoted 10 lines
xen/arch/arm/include/asm/gic_v3_defs.h +3
-3#define ICH_LR_GRP_MASK 0x1 #define ICH_LR_GRP_SHIFT 60 -#define ICH_LR_MAINTENANCE_IRQ (1UL<<41) -#define ICH_LR_GRP1 (1UL<<60) -#define ICH_LR_HW (1UL<<61) +#define ICH_LR_MAINTENANCE_IRQ (1ULL<<41) +#define ICH_LR_GRP1 (1ULL<<60) +#define ICH_LR_HW (1ULL<<61) #define ICH_VTR_NRLRGS 0x3f #define ICH_VTR_PRIBITS_MASK 0x7Cheers,
Re: [RFC PATCH v1 07/12] Arm: GICv3: Emulate ICH_LR<n>_EL2 on AArch32
Quoted 28 lines · Ayan Kumar Halder
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
I need a clarification.
Quoted 20 lines
Title: Xen doesn't emulate ICH_LR* (we don't expose them to the guest). Instead Xen will use the registers and your patch provides wrappers to use access the registers on 32-bit host.
xen/arch/arm/include/asm/arm32/sysregs.h line 70
Quoted 13 lines · Ayan Kumar Halder
xen/arch/arm/include/asm/arm32/sysregs.h +0
-0@@ -62,9 +62,61 @@ #define READ_SYSREG(R...) READ_SYSREG32(R) #define WRITE_SYSREG(V, R...) WRITE_SYSREG32(V, R)+#define ICH_LR_REG(INDEX)
ICH_LR## INDEX ##_EL2xen/arch/arm/include/asm/arm32/sysregs.h +5
-0+#define ICH_LRC_REG (INDEX ) ICH_LRC ## INDEX ## _EL2 + +#define READ_SYSREG_LR (INDEX ) ((((uint64_t) \ + (READ_SYSREG(ICH_LRC_REG(INDEX)))) << 32) | \ + (READ_SYSREG(ICH_LR_REG(INDEX))))This is a bit dense to read. Also, we should use
READ_CP64()when dealing with arm32 only code. So how about (formatting will need to be done):
Quoted 6 lines
Quoted 4 lines
#define
READ_SYSREG_LR(INDEX)({ \
uint32_tlrc_= READ_CP64(ICH_LRC_REG(INDEX)); \
uint32_tlr_= READ_CP64(ICH_LR_REG(INDEX)); \
\I think this looks incorrect. These are read using 'mrc' so they should be
READ_CP32(). They are 32 bit registers.
That's my mistake. We should use...
Quoted 2 lines
However,
READ_SYSREGis defined asREAD_CP32(), so should we useREAD_CP32()orREAD_SYSREG()?
READ_CP32() instead of READ_SYSREG() for arm32 specific code. The latter is only provided to avoid #ifdef in the common code.
Cheers,
Signature · 1 line
Julien Grall
RFC PATCH 8/12 Arm: GICv3: Define ICH_AP0R<n> and ICH_AP1R<n> for AArch32
In reply to Ayan Kumar HalderRefer "Arm IHI 0069H ID020922",
12.7.1 - Interrupt Controller Hyp Active Priorities Group0 Registers 0-3 12.7.2 - Interrupt Controller Hyp Active Priorities Group1 Registers 0-3
--- xen/arch/arm/include/asm/arm32/sysregs.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
xen/arch/arm/include/asm/arm32/sysregs.h +12 -0
@@ -117,6 +117,18 @@#define ICH_LRC14_EL2 __LRC8_EL2(6)#define ICH_LRC15_EL2 __LRC8_EL2(7) +#define __AP0Rx_EL2 (x) ___CP32(p15,4,c12,c8,x) +#define ICH_AP0R0_EL2 __AP0Rx_EL2(0) +#define ICH_AP0R1_EL2 __AP0Rx_EL2(1) +#define ICH_AP0R2_EL2 __AP0Rx_EL2(2) +#define ICH_AP0R3_EL2 __AP0Rx_EL2(3) + +#define __AP1Rx_EL2 (x) ___CP32(p15,4,c12,c9,x) +#define ICH_AP1R0_EL2 __AP1Rx_EL2(0) +#define ICH_AP1R1_EL2 __AP1Rx_EL2(1) +#define ICH_AP1R2_EL2 __AP1Rx_EL2(2) +#define ICH_AP1R3_EL2 __AP1Rx_EL2(3) +#endif /* __ASSEMBLY__ */ #endif /* __ASM_ARM_ARM32_SYSREGS_H */
Signature · 1 line
2.17.1
Re: [RFC PATCH v1 08/12] Arm: GICv3: Define ICH_AP0R<n> and ICH_AP1R<n> for AArch32
Hi Ayan,
xen/arch/arm/include/asm/arm32/sysregs.h
Quoted 13 lines · Ayan Kumar Halder
Refer "Arm IHI 0069H ID020922",
12.7.1 - Interrupt Controller Hyp Active Priorities Group0 Registers 0-3 12.7.2 - Interrupt Controller Hyp Active Priorities Group1 Registers 0-3Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/include/asm/arm32/sysregs.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)xen/arch/arm/include/asm/arm32/sysregs.h +0
-0
As the previous patch, the define should be declared in cpregs.h.
Quoted 9 lines
xen/arch/arm/include/asm/arm32/sysregs.h +5
-0@@ -117,6 +117,18 @@#define ICH_LRC14_EL2 __LRC8_EL2(6)#define ICH_LRC15_EL2 __LRC8_EL2(7) +#define __AP0Rx_EL2 (x) ___CP32(p15,4,c12,c8,x) +#define ICH_AP0R0_EL2 __AP0Rx_EL2(0) +#define ICH_AP0R1_EL2 __AP0Rx_EL2(1) +#define ICH_AP0R2_EL2 __AP0Rx_EL2(2) +#define ICH_AP0R3_EL2 __AP0Rx_EL2(3)
xen/arch/arm/include/asm/arm32/sysregs.h line 134
Quoted 10 lines
xen/arch/arm/include/asm/arm32/sysregs.h +7
-0+ +#define __AP1Rx_EL2 (x) ___CP32(p15,4,c12,c9,x) +#define ICH_AP1R0_EL2 __AP1Rx_EL2(0) +#define ICH_AP1R1_EL2 __AP1Rx_EL2(1) +#define ICH_AP1R2_EL2 __AP1Rx_EL2(2) +#define ICH_AP1R3_EL2 __AP1Rx_EL2(3) +#endif /* __ASSEMBLY__ */ #endif /* __ASM_ARM_ARM32_SYSREGS_H */
Cheers,
Signature · 1 line
Julien Grall
RFC PATCH 9/12 Arm: GICv3: Define GIC registers for AArch32
In reply to Ayan Kumar HalderRefer "Arm IHI 0069H ID020922"
12.5.23 ICC_SGI1R, Interrupt Controller Software Generated Interrupt Group 1 Register
12.5.12 ICC_HSRE, Interrupt Controller Hyp System Register Enable register 12.7.10 ICH_VTR, Interrupt Controller VGIC Type Register
12.7.5 ICH_HCR, Interrupt Controller Hyp Control Register 12.5.20 ICC_PMR, Interrupt Controller Interrupt Priority Mask Register 12.5.24 ICC_SRE, Interrupt Controller System Register Enable register 12.5.7 ICC_DIR, Interrupt Controller Deactivate Interrupt Register 12.5.9 ICC_EOIR1, Interrupt Controller End Of Interrupt Register 1 12.5.14 ICC_IAR1, Interrupt Controller Interrupt Acknowledge Register 1 12.5.5 ICC_BPR1, Interrupt Controller Binary Point Register 1 12.5.6 ICC_CTLR, Interrupt Controller Control Register
12.5.16 ICC_IGRPEN1, Interrupt Controller Interrupt Group 1 Enable register 12.7.9 ICH_VMCR, Interrupt Controller Virtual Machine Control Register
--- xen/arch/arm/include/asm/arm32/sysregs.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
xen/arch/arm/include/asm/arm32/sysregs.h +16 -0
@@ -129,6 +129,22 @@#define ICH_AP1R2_EL2 __AP1Rx_EL2(2)#define ICH_AP1R3_EL2 __AP1Rx_EL2(3) +#define ICC_SGI1R_EL1 p15,0,c12 + +#define ICC_SRE_EL2 p15,4,c12,c9,5 +#define ICH_VTR_EL2 p15,4,c12,c11,1 +#define ICH_HCR_EL2 p15,4,c12,c11,0 + +#define ICC_PMR_EL1 p15,0,c4,c6,0 +#define ICC_SRE_EL1 p15,0,c12,c12,5 +#define ICC_DIR_EL1 p15,0,c12,c11,1 +#define ICC_EOIR1_EL1 p15,0,c12,c12,1 +#define ICC_IAR1_EL1 p15,0,c12,c12,0 +#define ICC_BPR1_EL1 p15,0,c12,c12,3 +#define ICC_CTLR_EL1 p15,0,c12,c12,4 +#define ICC_IGRPEN1_EL1 p15,0,c12,c12,7 +#define ICH_VMCR_EL2 p15,4,c12,c11,7 +#endif /* __ASSEMBLY__ */ #endif /* __ASM_ARM_ARM32_SYSREGS_H */
Signature · 1 line
2.17.1
Re: [RFC PATCH v1 09/12] Arm: GICv3: Define GIC registers for AArch32
Hi Ayan,
xen/arch/arm/include/asm/arm32/sysregs.h
Quoted 25 lines · Ayan Kumar Halder
Refer "Arm IHI 0069H ID020922"
12.5.23ICC_SGI1R, Interrupt Controller Software Generated Interrupt Group 1 Register
12.5.12ICC_HSRE, Interrupt Controller Hyp System Register Enable register 12.7.10ICH_VTR, Interrupt Controller VGIC Type Register
12.7.5ICH_HCR, Interrupt Controller Hyp Control Register 12.5.20ICC_PMR, Interrupt Controller Interrupt Priority Mask Register 12.5.24ICC_SRE, Interrupt Controller System Register Enable register 12.5.7ICC_DIR, Interrupt Controller Deactivate Interrupt Register 12.5.9ICC_EOIR1, Interrupt Controller End Of Interrupt Register 1 12.5.14ICC_IAR1, Interrupt Controller Interrupt Acknowledge Register 1 12.5.5ICC_BPR1, Interrupt Controller Binary Point Register 1 12.5.6ICC_CTLR, Interrupt Controller Control Register
12.5.16ICC_IGRPEN1, Interrupt Controller Interrupt Group 1 Enable register 12.7.9ICH_VMCR, Interrupt Controller Virtual Machine Control RegisterSigned-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/include/asm/arm32/sysregs.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)xen/arch/arm/include/asm/arm32/sysregs.h +0
-0
Same as the previous two patches. This should be defined in cpregs.h
Quoted 13 lines
xen/arch/arm/include/asm/arm32/sysregs.h +9
-0@@ -129,6 +129,22 @@#define ICH_AP1R2_EL2 __AP1Rx_EL2(2)#define ICH_AP1R3_EL2 __AP1Rx_EL2(3) +#define ICC_SGI1R_EL1 p15,0,c12 + +#define ICC_SRE_EL2 p15,4,c12,c9,5 +#define ICH_VTR_EL2 p15,4,c12,c11,1 +#define ICH_HCR_EL2 p15,4,c12,c11,0 + +#define ICC_PMR_EL1 p15,0,c4,c6,0 +#define ICC_SRE_EL1 p15,0,c12,c12,5 +#define ICC_DIR_EL1 p15,0,c12,c11,1
xen/arch/arm/include/asm/arm32/sysregs.h line 150
Quoted 10 lines
xen/arch/arm/include/asm/arm32/sysregs.h +7
-0+#define ICC_EOIR1_EL1 p15,0,c12,c12,1 +#define ICC_IAR1_EL1 p15,0,c12,c12,0 +#define ICC_BPR1_EL1 p15,0,c12,c12,3 +#define ICC_CTLR_EL1 p15,0,c12,c12,4 +#define ICC_IGRPEN1_EL1 p15,0,c12,c12,7 +#define ICH_VMCR_EL2 p15,4,c12,c11,7 +#endif /* __ASSEMBLY__ */ #endif /* __ASM_ARM_ARM32_SYSREGS_H */
Cheers,
Signature · 1 line
Julien Grall
RFC PATCH 10/12 Arm: GICv3: Use ULL instead of UL for 64bits
In reply to Ayan Kumar Halder"unsigned long long" is defined as 64 bits on AArch64 and AArch32 Thus, one should this instead of "unsigned long" which is 32 bits on AArch32.
Also use 'PRIu64' instead of 'lx' to print uint64_t.
--- xen/arch/arm/gic-v3-its.c | 20 ++++++++++---------- xen/arch/arm/gic-v3-lpi.c | 8 ++++---- xen/arch/arm/gic-v3.c | 4 ++-- xen/arch/arm/include/asm/gic_v3_defs.h | 2 +- xen/arch/arm/include/asm/gic_v3_its.h | 2 +- xen/arch/arm/vgic-v3-its.c | 17 +++++++++-------- 6 files changed, 27 insertions(+), 26 deletions(-)
xen/arch/arm/gic-v3-its.c +10 -10
@@ -163,7 +163,7 @@ static int gicv3_its_wait_commands(struct host_its *hw_its)static uint64_t encode_rdbase (struct host_its *hw_its,unsigned int cpu,uint64_t reg) { - reg &= ~GENMASK (51 ,16 ); + reg &= ~GENMASK_ULL (51 ,16 ); reg |=gicv3_get_redist_address (cpu, hw_its->flags &HOST_ITS_USES_PTA );
@@ -219,7 +219,7 @@ static int its_send_cmd_mapd(struct host_its *its, uint32_t deviceid, {ASSERT (size_bits <= its->evid_bits);ASSERT (size_bits >0 ); -ASSERT (!(itt_addr & ~GENMASK (51 ,8 ))); +ASSERT (!(itt_addr & ~GENMASK_ULL (51 ,8 )));/* The number of events is encoded as "number of bits minus one". */ size_bits--;
@@ -273,9 +273,9 @@ int gicv3_its_setup_collection(unsigned int cpu)#define BASER_ATTR_MASK \ ((0x3UL << GITS_BASER_SHAREABILITY_SHIFT) | \ - (0x7UL << GITS_BASER_OUTER_CACHEABILITY_SHIFT) | \ - (0x7UL << GITS_BASER_INNER_CACHEABILITY_SHIFT)) -#define BASER_RO_MASK (GENMASK(58, 56) | GENMASK(52, 48)) + (0x7ULL << GITS_BASER_OUTER_CACHEABILITY_SHIFT) | \ + (0x7ULL << GITS_BASER_INNER_CACHEABILITY_SHIFT)) +#define BASER_RO_MASK (GENMASK_ULL(58, 56) | GENMASK_ULL(52, 48))/* Check that the physical address can be encoded in the PROPBASER register. */ static bool check_baser_phys_addr (void *vaddr,unsigned int page_bits)
@@ -287,13 +287,13 @@ static bool check_baser_phys_addr(void *vaddr, unsigned int page_bits)static uint64_t encode_baser_phys_addr (paddr_t addr,unsigned int page_bits) { -uint64_t ret = addr &GENMASK (47 , page_bits); +uint64_t ret = addr &GENMASK_ULL (47 , page_bits);if ( page_bits <16 )return ret;/* For 64K pages address bits 51-48 are encoded in bits 15-12. */ -return ret | ((addr &GENMASK (51 ,48 )) >> (48 -12 )); +return ret | ((addr &GENMASK_ULL (51 ,48 )) >> (48 -12 )); }static void *its_map_cbaser (struct host_its *its)
@@ -310,7 +310,7 @@ static void *its_map_cbaser(struct host_its *its)if ( !buffer )return NULL ; -if (virt_to_maddr (buffer) & ~GENMASK (51 ,12 ) ) +if (virt_to_maddr (buffer) & ~GENMASK_ULL (51 ,12 ) ) {xfree (buffer);return NULL ;
@@ -446,7 +446,7 @@ static int gicv3_disable_its(struct host_its *hw_its)udelay (1 ); }while (NOW () <= deadline ); -printk (XENLOG_ERR "ITS@%lx not quiescent.\n" , hw_its->addr); +printk (XENLOG_ERR "ITS@%" PRIu64" not quiescent.\n" , hw_its->addr);return -ETIMEDOUT ; }
@@ -999,7 +999,7 @@ static void add_to_host_its_list(paddr_t addr, paddr_t size, its_data->size = size; its_data->dt_node = node; -printk ("GICv3: Found ITS @0x%lx\n" , addr); +printk ("GICv3: Found ITS 0x%" PRIu64"\n" , addr);list_add_tail (&its_data->entry, &host_its_list); }
xen/arch/arm/gic-v3-lpi.c +4 -4
@@ -134,7 +134,7 @@ void gicv3_set_redist_address(paddr_t address, unsigned int redist_id)uint64_t gicv3_get_redist_address (unsigned int cpu,bool use_pta) {if ( use_pta ) -return per_cpu (lpi_redist, cpu).redist_addr &GENMASK (51 ,16 ); +return per_cpu (lpi_redist, cpu).redist_addr &GENMASK_ULL (51 ,16 );else return per_cpu (lpi_redist, cpu).redist_id <<16 ; }
@@ -253,7 +253,7 @@ static int gicv3_lpi_allocate_pendtable(unsigned int cpu)return -ENOMEM ;/* Make sure the physical address can be encoded in the register. */ -if (virt_to_maddr (pendtable) & ~GENMASK (51 ,16 ) ) +if (virt_to_maddr (pendtable) & ~GENMASK_ULL (51 ,16 ) ) {xfree (pendtable);return -ERANGE ;
@@ -281,7 +281,7 @@ static int gicv3_lpi_set_pendtable(void __iomem *rdist_base)return -ENOMEM ; } -ASSERT (!(virt_to_maddr (pendtable) & ~GENMASK (51 ,16 ))); +ASSERT (!(virt_to_maddr (pendtable) & ~GENMASK_ULL (51 ,16 ))); val = GIC_BASER_CACHE_RaWaWb <<GICR_PENDBASER_INNER_CACHEABILITY_SHIFT ; val |= GIC_BASER_CACHE_SameAsInner <<GICR_PENDBASER_OUTER_CACHEABILITY_SHIFT ;
@@ -329,7 +329,7 @@ static int gicv3_lpi_set_proptable(void __iomem * rdist_base)return -ENOMEM ;/* Make sure the physical address can be encoded in the register. */ -if ( (virt_to_maddr (table) & ~GENMASK (51 ,12 )) ) +if ( (virt_to_maddr (table) & ~GENMASK_ULL (51 ,12 )) ) {xfree (table);return -ERANGE ;
xen/arch/arm/gic-v3.c +2 -2
@@ -417,12 +417,12 @@ static void gicv3_dump_state(const struct vcpu *v)if ( v == current ) {for ( i =0 ; i < gicv3_info.nr_lrs; i++ ) -printk (" HW_LR[%d]=%llx\n" , i,gicv3_ich_read_lr (i)); +printk (" HW_LR[%d]=%" PRIu64"\n" , i,gicv3_ich_read_lr (i)); }else {for ( i =0 ; i < gicv3_info.nr_lrs; i++ ) -printk (" VCPU_LR[%d]=%llx\n" , i, v->arch.gic.v3.lr[i]); +printk (" VCPU_LR[%d]=%" PRIu64"\n" , i, v->arch.gic.v3.lr[i]); } }
xen/arch/arm/include/asm/gic_v3_defs.h +1 -1
@@ -195,7 +195,7 @@#define ICH_SGI_IRQMODE_SHIFT 40#define ICH_SGI_IRQMODE_MASK 0x1 -#define ICH_SGI_TARGET_OTHERS 1UL +#define ICH_SGI_TARGET_OTHERS 1ULL#define ICH_SGI_TARGET_LIST 0#define ICH_SGI_IRQ_SHIFT 24#define ICH_SGI_IRQ_MASK 0xf
xen/arch/arm/include/asm/gic_v3_its.h +1 -1
@@ -38,7 +38,7 @@#define GITS_PIDR2 GICR_PIDR2/* Register bits */ -#define GITS_VALID_BIT BIT(63, UL) +#define GITS_VALID_BIT BIT(63, ULL)#define GITS_CTLR_QUIESCENT BIT(31, UL)#define GITS_CTLR_ENABLE BIT(0, UL)
xen/arch/arm/vgic-v3-its.c +9 -8
@@ -96,13 +96,13 @@ typedef uint16_t coll_table_entry_t;* in the lowest 5 bits of the word. */ typedef uint64_t dev_table_entry_t ; -#define DEV_TABLE_ITT_ADDR (x) ((x) & GENMASK(51, 8)) +#define DEV_TABLE_ITT_ADDR (x) ((x) & GENMASK_ULL(51, 8))#define DEV_TABLE_ITT_SIZE (x) (BIT(((x) & GENMASK(4, 0)) + 1, UL))#define DEV_TABLE_ENTRY (addr, bits) \ (((addr) & GENMASK(51, 8)) | (((bits) - 1) & GENMASK(4, 0)))#define GITS_BASER_RO_MASK (GITS_BASER_TYPE_MASK | \ - (0x1fL << GITS_BASER_ENTRY_SIZE_SHIFT)) + (0x1fLL << GITS_BASER_ENTRY_SIZE_SHIFT))/* * The physical address is encoded slightly differently depending on
@@ -112,10 +112,10 @@ typedef uint64_t dev_table_entry_t;static paddr_t get_baser_phys_addr (uint64_t reg) {if ( reg &BIT (9 ,UL ) ) -return (reg &GENMASK (47 ,16 )) | +return (reg &GENMASK_ULL (47 ,16 )) | ((reg &GENMASK (15 ,12 )) <<36 );else -return reg &GENMASK (47 ,12 ); +return reg &GENMASK_ULL (47 ,12 ); }/* Must be called with the ITS lock held. */
@@ -414,7 +414,7 @@ static int update_lpi_property(struct domain *d, struct pending_irq *p)if ( !d->arch.vgic.rdists_enabled )return 0 ; - addr = d->arch.vgic.rdist_propbase &GENMASK (51 ,12 ); + addr = d->arch.vgic.rdist_propbase &GENMASK_ULL (51 ,12 ); ret =access_guest_memory_by_ipa (d, addr + p->irq -LPI_OFFSET , &property,sizeof (property), false);
@@ -897,7 +897,8 @@ out_unlock:static void dump_its_command (uint64_t *command) { -gdprintk (XENLOG_WARNING ," cmd 0x%02lx: %016lx %016lx %016lx %016lx\n" , +gdprintk (XENLOG_WARNING ," cmd 0x%" PRIu64": %" PRIu64 +"%" PRIu64"%" PRIu64"%" PRIu64"\n" ,its_cmd_get_command (command), command[0 ], command[1 ], command[2 ], command[3 ]); }
@@ -909,7 +910,7 @@ static void dump_its_command(uint64_t *command)*/ static int vgic_its_handle_cmds (struct domain *d,struct virt_its *its) { -paddr_t addr = its->cbaser &GENMASK (51 ,12 ); +paddr_t addr = its->cbaser &GENMASK_ULL (51 ,12 );uint64_t command[4 ];ASSERT (spin_is_locked (&its->vcmd_lock));
@@ -1122,7 +1123,7 @@ read_as_zero_64: read_impl_defined:printk (XENLOG_G_DEBUG -"%pv: vGITS: RAZ on implementation defined register offset %#04lx\n" , +"%pv: vGITS: RAZ on implementation defined register offset %" PRIx64"#04llx\n" , v, info->gpa &0xffff ); *r =0 ;return 1 ;
Signature · 1 line
2.17.1
Re: [RFC PATCH v1 10/12] Arm: GICv3: Use ULL instead of UL for 64bits
Hi Ayan,
Quoted 5 lines · Ayan Kumar Halder
"unsigned long long" is defined as 64 bits on AArch64 and AArch32 Thus, one should this instead of "unsigned long" which is 32 bits on AArch32.
Also use 'PRIu64' instead of 'lx' to print
uint64_t.
This is not quite a simple change of type. Now, the values will be printed in decimal rather than hexadecimal. Any particular reason why you didn't go with PRIx64?
[...]
Quoted 33 lines
xen/arch/arm/include/asm/gic_v3_defs.h +1
-1@@ -195,7 +195,7 @@#define ICH_SGI_IRQMODE_SHIFT 40#define ICH_SGI_IRQMODE_MASK 0x1 -#define ICH_SGI_TARGET_OTHERS 1UL +#define ICH_SGI_TARGET_OTHERS 1ULL#define ICH_SGI_TARGET_LIST 0#define ICH_SGI_IRQ_SHIFT 24#define ICH_SGI_IRQ_MASK 0xfxen/arch/arm/include/asm/gic_v3_its.h +1
-1@@ -38,7 +38,7 @@#define GITS_PIDR2 GICR_PIDR2/* Register bits */ -#define GITS_VALID_BIT BIT(63, UL) +#define GITS_VALID_BIT BIT(63, ULL)#define GITS_CTLR_QUIESCENT BIT(31, UL)#define GITS_CTLR_ENABLE BIT(0, UL)xen/arch/arm/vgic-v3-its.c +0
-0@@ -96,13 +96,13 @@ typedef uint16_t coll_table_entry_t;* in the lowest 5 bits of the word. */
xen/arch/arm/vgic-v3-its.c typedef uint16_t coll_table_entry_t; · line 105
Quoted 10 lines
xen/arch/arm/vgic-v3-its.c +2
-2typedef uint64_t dev_table_entry_t ; -#define DEV_TABLE_ITT_ADDR (x) ((x) & GENMASK(51, 8)) +#define DEV_TABLE_ITT_ADDR (x) ((x) & GENMASK_ULL(51, 8))#define DEV_TABLE_ITT_SIZE (x) (BIT(((x) & GENMASK(4, 0)) + 1, UL))#define DEV_TABLE_ENTRY (addr, bits) \ (((addr) & GENMASK(51, 8)) | (((bits) - 1) & GENMASK(4, 0)))#define GITS_BASER_RO_MASK (GITS_BASER_TYPE_MASK | \ - (0x1fL << GITS_BASER_ENTRY_SIZE_SHIFT)) + (0x1fLL << GITS_BASER_ENTRY_SIZE_SHIFT))
While you are modifying it, shouldn't this be ULL?
Cheers,
Signature · 1 line
Julien Grall
RFC PATCH 11/12 Arm: GICv3: Define macros to read/write 64 bit
In reply to Ayan Kumar HalderDefined readq_relaxed()/writeq_relaxed() to read and write 64 bit regs. This in turn calls readl_relaxed()/writel_relaxed() twice for the lower and upper 32 bits.
--- xen/arch/arm/include/asm/arm32/io.h | 4 ++++ 1 file changed, 4 insertions(+)
xen/arch/arm/include/asm/arm32/io.h +4 -0
@@ -80,10 +80,14 @@ static inline u32 __raw_readl(const volatile void __iomem *addr) __raw_readw(c)); __r; })#define readl_relaxed (c) ({ u32 __r = le32_to_cpu((__force __le32) \ __raw_readl(c)); __r; }) +#define readq_relaxed (c) ({ u64 __r = (le64_to_cpu(readl_relaxed(c+4)) << 32) | \ + readl_relaxed(c); __r; })#define writeb_relaxed (v,c) __raw_writeb(v,c)#define writew_relaxed (v,c) __raw_writew((__force u16) cpu_to_le16(v),c)#define writel_relaxed (v,c) __raw_writel((__force u32) cpu_to_le32(v),c) +#define writeq_relaxed (v,c) writel_relaxed(((uint64_t)v&0xffffffff), c); \ + writel_relaxed((((uint64_t)v)>>32), (c+4));#define readb (c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; })#define readw (c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
Signature · 1 line
2.17.1
Re: [RFC PATCH v1 11/12] Arm: GICv3: Define macros to read/write 64 bit
On 10/21/22 18:31, Ayan Kumar Halder wrote:
Hi Ayan
Quoted 14 lines
Defined readq_relaxed()/writeq_relaxed() to read and write 64 bit regs. This in turn calls readl_relaxed()/writel_relaxed() twice for the lower and upper 32 bits.
Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/include/asm/arm32/io.h | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/arm/include/asm/arm32/io.h +0
-0
xen/arch/arm/include/asm/arm32/io.h static inline u32 __raw_readl(const volatile void __iomem *addr) · line 84
Quoted 5 lines
xen/arch/arm/include/asm/arm32/io.h +2
-0@@ -80,10 +80,14 @@ static inline u32 __raw_readl(const volatile void __iomem *addr) __raw_readw(c)); __r; })#define readl_relaxed (c) ({ u32 __r = le32_to_cpu((__force __le32) \ __raw_readl(c)); __r; }) +#define readq_relaxed (c) ({ u64 __r = (le64_to_cpu(readl_relaxed(c+4)) << 32) | \ + readl_relaxed(c); __r; })
Maybe you wanted to write sth like
(((u64)readl_relaxed((c) + 4) << 32) | readl_relaxed(c))
readl_relaxed returns a u32 value so no byteorder conversions are needed at this stage. Also, you need to add parentheses around macro parameter c because an operator performs on it.
xen/arch/arm/include/asm/arm32/io.h static inline u32 __raw_readl(const volatile void __iomem *addr) · line 93
Quoted 9 lines
xen/arch/arm/include/asm/arm32/io.h +2
-0#define writeb_relaxed (v,c) __raw_writeb(v,c)#define writew_relaxed (v,c) __raw_writew((__force u16) cpu_to_le16(v),c)#define writel_relaxed (v,c) __raw_writel((__force u32) cpu_to_le32(v),c) +#define writeq_relaxed (v,c) writel_relaxed(((uint64_t)v&0xffffffff), c); \ + writel_relaxed((((uint64_t)v)>>32), (c+4));#define readb (c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; })#define readw (c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
And
writel_relaxed((u32)v, c); writel_relaxed((u32)((v) >> 32), (c) + 4);
v is already u64 and writel_relaxed() expects a u32. Here as well, you need to add parentheses around macro parameter c because an operator performs on it.
I am wondering if the parts of the register need to be accessed in a specific order.
Signature · 1 line
Xenia
Re: [RFC PATCH v1 11/12] Arm: GICv3: Define macros to read/write 64 bit
In reply to Ayan Kumar HalderHi Ayan,
Quoted 3 lines · Ayan Kumar Halder
Defined readq_relaxed()/writeq_relaxed() to read and write 64 bit regs. This in turn calls readl_relaxed()/writel_relaxed() twice for the lower and upper 32 bits.
This needs an explanation why we can't use "strd/ldrd". And the same would have to be duplicated in the code below.
Quoted 11 lines
Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/include/asm/arm32/io.h | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/arm/include/asm/arm32/io.h +0
-0
xen/arch/arm/include/asm/arm32/io.h static inline u32 __raw_readl(const volatile void __iomem *addr) · line 84
Quoted 5 lines
xen/arch/arm/include/asm/arm32/io.h +2
-0@@ -80,10 +80,14 @@ static inline u32 __raw_readl(const volatile void __iomem *addr) __raw_readw(c)); __r; })#define readl_relaxed (c) ({ u32 __r = le32_to_cpu((__force __le32) \ __raw_readl(c)); __r; }) +#define readq_relaxed (c) ({ u64 __r = (le64_to_cpu(readl_relaxed(c+4)) << 32) | \ + readl_relaxed(c); __r; })
All the read*_relaxed are provide atomic read. This is not guaranteed by your new helper. The name should be different (maybe readq_relaxed_non_atomic()) to make clear of the difference.
I also don't quite understand the implementation. The value returned by readl_relaxed() is already in the CPU endianess. So why do you call le64_to_cpu() on top?
xen/arch/arm/include/asm/arm32/io.h static inline u32 __raw_readl(const volatile void __iomem *addr) · line 90
Quoted 6 lines
xen/arch/arm/include/asm/arm32/io.h +2
-0#define writeb_relaxed (v,c) __raw_writeb(v,c)#define writew_relaxed (v,c) __raw_writew((__force u16) cpu_to_le16(v),c)#define writel_relaxed (v,c) __raw_writel((__force u32) cpu_to_le32(v),c) +#define writeq_relaxed (v,c) writel_relaxed(((uint64_t)v&0xffffffff), c); \ + writel_relaxed((((uint64_t)v)>>32), (c+4));
This needs to be surrounded with do { } while (0), otherwise the following would not properly work:
if ( foo )
writeq_relaxed(v, c);
Similarly, if 'v' is a call, then it will end up to be called twice.
xen/arch/arm/include/asm/arm32/io.h static inline u32 __raw_readl(const volatile void __iomem *addr) · line 93
Quoted 3 lines
xen/arch/arm/include/asm/arm32/io.h +0
-0#define readb (c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; })#define readw (c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
Cheers,
Signature · 1 line
Julien Grall
RFC PATCH 12/12 Arm: GICv3: Enable GICv3 for AArch32
In reply to Ayan Kumar HalderRefer ARM DDI 0487G.b ID072021,
D13.2.86 -ID_PFR1_EL1, AArch32 Processor Feature Register 1
GIC, bits[31:28] == 0b0001 for GIC3.0 on Aarch32
One can now enable GICv3 on AArch32 systems.
--- xen/arch/arm/Kconfig | 2 +- xen/arch/arm/include/asm/cpufeature.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
xen/arch/arm/Kconfig +1 -1
@@ -41,7 +41,7 @@ config ARM_EFI config GICV3 bool "GICv3 driver" - depends on ARM_64 && !NEW_VGIC + depends on (ARM_64 || ARM_32) && !NEW_VGIC default y ---help---
xen/arch/arm/include/asm/cpufeature.h +1 -0
@@ -31,6 +31,7 @@#define cpu_has_jazelle (boot_cpu_feature32(jazelle) > 0)#define cpu_has_thumbee (boot_cpu_feature32(thumbee) == 1)#define cpu_has_aarch32 (cpu_has_arm || cpu_has_thumb) +#define cpu_has_gicv3 (boot_cpu_feature32(gic) >= 1)#ifdef CONFIG_ARM_32 #define cpu_has_gentimer (boot_cpu_feature32(gentimer) == 1)
Signature · 1 line
2.17.1
Re: [RFC PATCH v1 12/12] Arm: GICv3: Enable GICv3 for AArch32
Hi,
Quoted 19 lines · Ayan Kumar Halder
Refer ARM DDI 0487G.b ID072021,
D13.2.86 -ID_PFR1_EL1, AArch32 Processor Feature Register 1GIC, bits[31:28] == 0b0001 for GIC3.0 on Aarch32
One can now enable GICv3 on AArch32 systems.
Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/Kconfig | 2 +- xen/arch/arm/include/asm/cpufeature.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)xen/arch/arm/Kconfig +0
-0
xen/arch/arm/Kconfig config ARM_EFI · line 44
Quoted 5 lines
xen/arch/arm/Kconfig +1
-1@@ -41,7 +41,7 @@ config ARM_EFI config GICV3 bool "GICv3 driver" - depends on ARM_64 && !NEW_VGIC + depends on (ARM_64 || ARM_32) && !NEW_VGIC
(ARM_64 || ARM_32) will always be true. So this can be dropped.
Furthermore, I wonder whether we should update SUPPORT.md with the support state for GICv3 on 32-bit. I would be fine if we already mark it as "supported, not security supported". But I am not sure about security supported until further testing.
Any opinions?
Cheers,
Signature · 1 line
Julien Grall