arm64: Mediate access to GICv3 sysregs at EL2
cover arm64: Mediate access to GICv3 sysregs at EL2
From: Manish Jaggi <[email protected]>
This patchset is a Xen port of Marc's patchset.
arm64: KVM: Mediate access to GICv3 sysregs at EL2 [1]
The current RFC patchset is a subset of [1], as it handleing only Group1 traps as a PoC. Most of the trap code is added in vsysreg.c. Trap handler function is kept independent of the usual guest trap handling code.
Looking for feedback on this approach.
The errata has been validated on Cavium ThunderX platform.
Steps to reporduce the errata
- Boot Xen with 2 cores.
- Disable group1 interrupts in domU kernel
- start domU, the kill and start again.
One of the Xen core would hang.
Code in this patchset fixes this issue.
[1] https://lists.cs.columbia.edu/pipermail/kvmarm/2017-June/026029.html
Manish Jaggi (10):
arm64: Add CONFIG_VGIC_ERRATA
arm64: Add hook to handle guest GICv3 sysreg accesses
arm64: Add ICV_BPR1_EL1 handler
arm64: Add ICV_IGRPEN1_EL1 handler
arm64: Add accessors for the ICH_APxRn_EL2 registers
arm64: Expose gicv3_ich_read/write_lr
arm64: Add ICV_IAR1_EL1 handler
arm64: Add ICV_EOIR1_EL1 handler
arm64: Add a handler for ICV_HPPIR1_EL1
arm64: Enable Trapping of Group1 registers which is controlled by
command line
xen/arch/arm/Kconfig | 9 + xen/arch/arm/arm64/vsysreg.c | 564 ++++++++++++++++++++++++++++++++++++ xen/arch/arm/gic-v3.c | 21 +- xen/arch/arm/traps.c | 11 + xen/include/asm-arm/arm64/sysregs.h | 5 + xen/include/asm-arm/arm64/traps.h | 2 + xen/include/asm-arm/gic.h | 1 + xen/include/asm-arm/gic_v3.h | 7 + xen/include/asm-arm/gic_v3_defs.h | 30 ++ 9 files changed, 649 insertions(+), 1 deletion(-) create mode 100644 xen/include/asm-arm/gic_v3.h
Signature · 7 lines
2.14.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 1/10 Add CONFIG_VGIC_ERRATA
From: Manish Jaggi <[email protected]>
Add a config option to enable VGIC Errata Code in Xen. Platforms which do not have this errta can compile out this feature.
--- xen/arch/arm/Kconfig | 9 +++++++++ 1 file changed, 9 insertions(+)
xen/arch/arm/Kconfig +9 -0
@@ -59,6 +59,15 @@ config SBSA_VUART_CONSOLE endmenu +menu "Errata Workarounds" + depends on ARM_64 + +config VGIC_ERRATA + bool "Handler code for emulation of Group0/1 vGIC registers for VGC Errata" + depends on ARM_64 + +endmenu + menu "ARM errata workaround via the alternative framework" depends on HAS_ALTERNATIVE
Signature · 7 lines
2.14.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [RFC PATCH 01/10] Add CONFIG_VGIC_ERRATA
Hi Manish,
Quoted 4 lines · On 16/01/18 15:42, [email protected] wrote:
From: Manish Jaggi <[email protected]>
Add a config option to enable VGIC Errata Code in Xen. Platforms which do not have this errta can compile out this feature.
s/errta/errata/
Quoted 11 lines
Signed-off-by Manish Jaggi <[email protected]>--- xen/arch/arm/Kconfig | 9 +++++++++ 1 file changed, 9 insertions(+)xen/arch/arm/Kconfig +0
-0
xen/arch/arm/Kconfig config SBSA_VUART_CONSOLE · line 63
Quoted 5 lines
xen/arch/arm/Kconfig +2
-0@@ -59,6 +59,15 @@ config SBSA_VUART_CONSOLE endmenu +menu "Errata Workarounds" + depends on ARM_64
I would much prefer to see the memu "ARM errata workaround via..." renamed to "Errata Workarounds". So we have only one menu with all workarounds.
xen/arch/arm/Kconfig config SBSA_VUART_CONSOLE · line 66
Quoted 3 lines
xen/arch/arm/Kconfig +3
-0+ +config VGIC_ERRATA + bool "Handler code for emulation of Group0/1 vGIC registers for VGC Errata"
The title does not help the user to know when to select this option or not.
It looks like to me you want to do something similar to commit 690a341577f9 "arm64: Add workaround for Cavium Thunder erratum 30115" in Linux where the config is called CAVIUM_ERRATA_30115 and a proper description explaining the platform affected.
xen/arch/arm/Kconfig config SBSA_VUART_CONSOLE · line 67
Quoted 1 line
xen/arch/arm/Kconfig +1
-0+ depends on ARM_64
I think this should depend on HAS_GICV3.
xen/arch/arm/Kconfig config SBSA_VUART_CONSOLE · line 73
Quoted 7 lines
xen/arch/arm/Kconfig +3
-0+ +endmenu + menu "ARM errata workaround via the alternative framework" depends on HAS_ALTERNATIVE
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [RFC PATCH 01/10] Add CONFIG_VGIC_ERRATA
Hi Julien,
Quoted 16 lines · Julien Grall
Hi Manish,
Quoted 4 lines · On 16/01/18 15:42, [email protected] wrote:
From: Manish Jaggi <[email protected]>
Add a config option to enable VGIC Errata Code in Xen. Platforms which do not have this errta can compile out this feature.
s/errta/errata/
Quoted 6 lines
Signed-off-by Manish Jaggi <[email protected]>---
xen/arch/arm/Kconfig | 9 +++++++++1 file changed, 9 insertions(+)
Quoted 10 lines
Quoted 8 lines
xen/arch/arm/Kconfig +0
-0@@ -59,6 +59,15 @@ config SBSA_VUART_CONSOLEendmenu
+menu "Errata Workarounds"
+ depends onARM_64I would much prefer to see the memu "ARM errata workaround via..." renamed to "Errata Workarounds". So we have only one menu with all workarounds.
I am not sure it would work as
menu "ARM errata workaround via the alternative framework" depends on HAS_ALTERNATIVE
which may not be correct for vGIC errata.
Quoted 10 lines
Quoted 5 lines
xen/arch/arm/Kconfig +3
-0+ +config VGIC_ERRATA + bool "Handler code for emulation of Group0/1 vGIC registersfor VGC Errata"
The title does not help the user to know when to select this option or not.
It looks like to me you want to do something similar to commit
690a341577f9"arm64: Add workaround for Cavium Thunder erratum 30115" in Linux where the config is calledCAVIUM_ERRATA_30115and a proper description explaining the platform affected.
ok
Quoted 4 lines
Quoted 1 line
+ depends on
ARM_64I think this should depend on
HAS_GICV3.
ok
Quoted 9 lines
Quoted 6 lines
xen/arch/arm/Kconfig +3
-0+ +endmenu +menu "ARM errata workaround via the alternative framework" depends on
HAS_ALTERNATIVECheers,
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [RFC PATCH 01/10] Add CONFIG_VGIC_ERRATA
Quoted 30 lines · Manish Jaggi
Hi Julien,
Quoted 16 lines · Julien Grall
Hi Manish,
Quoted 4 lines · On 16/01/18 15:42, [email protected] wrote:
From: Manish Jaggi <[email protected]>
Add a config option to enable VGIC Errata Code in Xen. Platforms which do not have this errta can compile out this feature.
s/errta/errata/
Quoted 6 lines
Signed-off-by Manish Jaggi <[email protected]>---
xen/arch/arm/Kconfig | 9 +++++++++1 file changed, 9 insertions(+)Quoted 10 lines
Quoted 8 lines
xen/arch/arm/Kconfig +0
-0@@ -59,6 +59,15 @@ config SBSA_VUART_CONSOLEendmenu
+menu "Errata Workarounds"
+ depends onARM_64I would much prefer to see the memu "ARM errata workaround via..." renamed to "Errata Workarounds". So we have only one menu with all workarounds.
Quoted 5 lines
I am not sure it would work as
menu "ARM errata workaround via the alternative framework"
depends onHAS_ALTERNATIVEwhich may not be correct for vGIC errata.
vGIC errata are likely going to be based on alternative. So the call to the function could be avoided on non-affected platform.
But as alternative is supported unconditionally by both Arm64 and Arm32, this depends could just be dropped.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 2/10 arm64: Add hook to handle guest GICv3 sysreg accesses
In reply to [email protected]From: Manish Jaggi <[email protected]>
In order to start handling guest access to GICv3 system registers, let's add a hook that will get called when we trap a system register access.
This handling code is kept independent of other traps. Set CONFIG_VGIC_ERRATA to enable this code.
--- xen/arch/arm/arm64/vsysreg.c | 17 +++++++++++++++++ xen/arch/arm/traps.c | 11 +++++++++++ xen/include/asm-arm/arm64/traps.h | 2 ++ 3 files changed, 30 insertions(+)
xen/arch/arm/arm64/vsysreg.c +17 -0
@@ -219,6 +219,23 @@ void do_sysreg(struct cpu_user_regs *regs, regs->pc +=4 ; } +#ifdef CONFIG_VGIC_ERRATA +int do_fixup_vgic_errata (struct cpu_user_regs *regs,const union hsr hsr) +{ +int ret =0 ; + +local_irq_disable (); +switch ( hsr.bits &HSR_SYSREG_REGS_MASK ) + { +default : + ret =-1 ; +break ; + } +local_irq_enable (); + +return ret; +} +#endif /* * Local variables: * mode: C
xen/arch/arm/traps.c +11 -0
@@ -2103,6 +2103,17 @@ void do_trap_guest_sync(struct cpu_user_regs *regs) {const union hsr hsr = { .bits = regs->hsr }; +#ifdef CONFIG_VGIC_ERRATA +int ret; + + ret =do_fixup_vgic_errata (regs,hsr); +if ( !ret ) + { +advance_pc (regs, hsr); +return ; + } +#endif +enter_hypervisor_head (regs);switch (hsr.ec) {
xen/include/asm-arm/arm64/traps.h +2 -0
@@ -5,6 +5,8 @@ void inject_undef64_exception(struct cpu_user_regs *regs, int instr_len);void do_sysreg (struct cpu_user_regs *regs,const union hsr hsr); +int do_fixup_vgic_errata (struct cpu_user_regs *regs, +const union hsr hsr);#endif /* __ASM_ARM64_TRAPS__ */ /*
Signature · 7 lines
2.14.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [RFC PATCH 02/10] arm64: Add hook to handle guest GICv3 sysreg accesses
Hi Manish,
Quoted 7 lines · On 16/01/18 15:42, [email protected] wrote:
From: Manish Jaggi <[email protected]>
In order to start handling guest access to GICv3 system registers, let's add a hook that will get called when we trap a system register access.
This handling code is kept independent of other traps. SetCONFIG_VGIC_ERRATAto enable this code.
The commit message should explain the rationale behind calling do_fixup_vgic_errata from do_trap_guest_sync.
Quoted 13 lines
Signed-off-by Manish Jaggi <[email protected]>--- xen/arch/arm/arm64/vsysreg.c | 17 +++++++++++++++++ xen/arch/arm/traps.c | 11 +++++++++++ xen/include/asm-arm/arm64/traps.h | 2 ++ 3 files changed, 30 insertions(+)xen/arch/arm/arm64/vsysreg.c +0
-0
xen/arch/arm/arm64/vsysreg.c void do_sysreg(struct cpu_user_regs *regs, · line 223
Quoted 5 lines
xen/arch/arm/arm64/vsysreg.c +2
-0@@ -219,6 +219,23 @@ void do_sysreg(struct cpu_user_regs *regs, regs->pc +=4 ; } +#ifdef CONFIG_VGIC_ERRATA +int do_fixup_vgic_errata (struct cpu_user_regs *regs,const union hsr hsr)
Can we have a separate file to emulate vgic system registers? We might want to re-use some of the code for 32-bit guests in the future. Also as far as I can tell, this will only cover GICv3 system registers. To be more specific it will only be cpu interface register.
So I think you should name vgic_v3_handle_cpuif_access(...).
xen/arch/arm/arm64/vsysreg.c void do_sysreg(struct cpu_user_regs *regs, · line 225
Quoted 2 lines
xen/arch/arm/arm64/vsysreg.c +2
-0+{ +int ret =0 ;
You are returning either -1 or 0. Can we please use bool in that case?
xen/arch/arm/arm64/vsysreg.c void do_sysreg(struct cpu_user_regs *regs, · line 228
Quoted 3 lines
xen/arch/arm/arm64/vsysreg.c +3
-0+ +local_irq_disable (); + switch ( hsr.bits & HSR_SYSREG_REGS_MASK )
You will enter in do_trap_guest_sync for various reasons. So you should check that exception class correspond to a trapped of system instructions (e.g HSR_EC_SYSREG). Otherwise you will emulate sysreg on other encoding by mistake.
Quoted 18 lines
xen/arch/arm/arm64/vsysreg.c +10
-0+ { +default : + ret =-1 ; +break ; + } +local_irq_enable (); + + return ret; +} +#endif /* * Local variables: * mode: C xen/arch/arm/traps.c +0
-0
xen/arch/arm/traps.c void do_trap_guest_sync(struct cpu_user_regs *regs) · line 2109
Quoted 7 lines
xen/arch/arm/traps.c +4
-0@@ -2103,6 +2103,17 @@ void do_trap_guest_sync(struct cpu_user_regs *regs) {const union hsr hsr = { .bits = regs->hsr }; +#ifdef CONFIG_VGIC_ERRATA +int ret; + + ret =do_fixup_vgic_errata (regs,hsr);
Most likely distros will have the errata built in Xen because they want the hypervisor to run on many platforms. And we don't want to affect the
on platform that are not affected by the errata.
So we want to skip the call. Have a look at CHECK_WORKAROUND_HELPER.
Quoted 16 lines
xen/arch/arm/traps.c +7
-0+if ( !ret ) + { +advance_pc (regs, hsr); +return ; + } +#endif +enter_hypervisor_head (regs);switch (hsr.ec) {xen/include/asm-arm/arm64/traps.h +0
-0
xen/include/asm-arm/arm64/traps.h void inject_undef64_exception(struct cpu_user_regs *regs, int instr_len); · line 12
Quoted 8 lines
xen/include/asm-arm/arm64/traps.h +2
-0@@ -5,6 +5,8 @@ void inject_undef64_exception(struct cpu_user_regs *regs, int instr_len);void do_sysreg (struct cpu_user_regs *regs,const union hsr hsr); +int do_fixup_vgic_errata (struct cpu_user_regs *regs, +const union hsr hsr);#endif /* __ASM_ARM64_TRAPS__ */ /*
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [RFC PATCH 02/10] arm64: Add hook to handle guest GICv3 sysreg accesses
In reply to [email protected]Hi,
I forgot to mention one thing about the placement of do_fixup_vgic_errata.
Quoted 6 lines · On 16/01/18 15:42, [email protected] wrote:
xen/arch/arm/traps.c +0
-0@@ -2103,6 +2103,17 @@ void do_trap_guest_sync(struct cpu_user_regs *regs) {
xen/arch/arm/traps.c void do_trap_guest_sync(struct cpu_user_regs *regs) · line 2113
Quoted 10 lines
xen/arch/arm/traps.c +8
-0const union hsr hsr = { .bits = regs->hsr }; +#ifdef CONFIG_VGIC_ERRATA +int ret; + + ret =do_fixup_vgic_errata (regs,hsr); +if ( !ret ) + { +advance_pc (regs, hsr); +return ;
I am fully aware that I suggested this solution and still support that the vGIC errata should be fully separated. After all, it deals with hardware bug and the errata will just update the LRs as the hardware would do.
enter_hypervisor_head() will sync the LRs state to the internal vGIC state. leave_hypervisor_head() will process pending softirq and write/update the LRs based on the internal vGIC state.
As you rightfully did, the do_fixup_vgic_errata should be called before syncing the LRs. However, even if you return early here, you will still execute leave_hypervisor_tail(). This mean that pending softirqs will be processed and potentially the vCPU rescheduled. Because the LRs were not synced (enter_hypervisor_head()) was not called, then the vGIC state will not out-of-date and would lead to all sort of potential issues.
As the vGIC errata implies trapping the register such as IAR1 (reading interrupt), we want to get a fastpath for it (e.g not trying to execute softirq...). So I think we should bypass leave_hypervisor_tail(). I am not entirely sure how to do it nicely thought.
Cheers,
Quoted 20 lines
xen/arch/arm/traps.c +3
-0+ } +#endif +enter_hypervisor_head (regs);switch (hsr.ec) {xen/include/asm-arm/arm64/traps.h +2
-0@@ -5,6 +5,8 @@ void inject_undef64_exception(struct cpu_user_regs *regs, int instr_len);void do_sysreg (struct cpu_user_regs *regs,const union hsr hsr); +int do_fixup_vgic_errata (struct cpu_user_regs *regs, +const union hsr hsr);#endif /* __ASM_ARM64_TRAPS__ */ /*
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [RFC PATCH 02/10] arm64: Add hook to handle guest GICv3 sysreg accesses
Quoted 24 lines · Julien Grall
Hi,
I forgot to mention one thing about the placement of
do_fixup_vgic_errata.Quoted 8 lines · On 16/01/18 15:42, [email protected] wrote:
xen/arch/arm/traps.c +0
-0@@ -2103,6 +2103,17 @@ void do_trap_guest_sync(struct cpu_user_regs *regs) { const union hsr hsr = { .bits = regs->hsr };Quoted 8 lines
+#ifdef
CONFIG_VGIC_ERRATA
+ int ret;
+
+ ret =do_fixup_vgic_errata(regs,hsr);
+ if ( !ret )
+ {
+advance_pc(regs, hsr);
+ return;I am fully aware that I suggested this solution and still support that the vGIC errata should be fully separated. After all, it deals with hardware bug and the errata will just update the LRs as the hardware would do.
Quoted 6 lines
enter_hypervisor_head()will sync the LRs state to the internal vGIC state.leave_hypervisor_head()will process pending softirq and write/update the LRs based on the internal vGIC state.As you rightfully did, the
do_fixup_vgic_erratashould be called before syncing the LRs. However, even if you return early here, you will still executeleave_hypervisor_tail(). This mean that pending softirqs will be processed and potentially the vCPU rescheduled. Because the LRs were not synced (enter_hypervisor_head()) was not called, then the vGIC state will not out-of-date and would lead to all sort of potential issues.As the vGIC errata implies trapping the register such as IAR1 (reading interrupt), we want to get a fastpath for it (e.g not trying to execute softirq...). So I think we should bypass
leave_hypervisor_tail(). I am not entirely sure how to do it nicely thought.
How about adding a check for group1_trap enable in leave_hypervisor_tail().
void leave_hypervisor_tail(void)
{
+if (group1_trap)
+ return;
while (1)
Quoted 12 lines
Cheers,
Quoted 10 lines
+ }
xen/arch/arm/traps.c +2
-0+#endif +
enter_hypervisor_head(regs);
switch (hsr.ec) {xen/include/asm-arm/arm64/traps.h +0
-0@@ -5,6 +5,8 @@ void inject_undef64_exception(struct cpu_user_regs
Quoted 9 lines
xen/include/asm-arm/arm64/traps.h void inject_undef64_exception(struct cpu_user_regs *regs, int instr_len);
Quoted 8 lines
xen/include/asm-arm/arm64/traps.h +2
-0*regs, int instr_len); void do_sysreg(struct cpu_user_regs *regs, const union hsr hsr); +int do_fixup_vgic_errata (struct cpu_user_regs *regs, + const union hsr hsr); #endif /* __ASM_ARM64_TRAPS__ */ /*
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [RFC PATCH 02/10] arm64: Add hook to handle guest GICv3 sysreg accesses
Hi Manish,
Quoted 32 lines · Manish Jaggi
Quoted 24 lines · Julien Grall
Hi,
I forgot to mention one thing about the placement of
do_fixup_vgic_errata.Quoted 8 lines · On 16/01/18 15:42, [email protected] wrote:
xen/arch/arm/traps.c +0
-0@@ -2103,6 +2103,17 @@ void do_trap_guest_sync(struct cpu_user_regs *regs) { const union hsr hsr = { .bits = regs->hsr };Quoted 8 lines
+#ifdef
CONFIG_VGIC_ERRATA
+ int ret;
+
+ ret =do_fixup_vgic_errata(regs,hsr);
+ if ( !ret )
+ {
+advance_pc(regs, hsr);
+ return;I am fully aware that I suggested this solution and still support that the vGIC errata should be fully separated. After all, it deals with hardware bug and the errata will just update the LRs as the hardware would do.
Quoted 6 lines
enter_hypervisor_head()will sync the LRs state to the internal vGIC state.leave_hypervisor_head()will process pending softirq and write/update the LRs based on the internal vGIC state.As you rightfully did, the
do_fixup_vgic_erratashould be called before syncing the LRs. However, even if you return early here, you will still executeleave_hypervisor_tail(). This mean that pending softirqs will be processed and potentially the vCPU rescheduled. Because the LRs were not synced (enter_hypervisor_head()) was not called, then the vGIC state will not out-of-date and would lead to all sort of potential issues.As the vGIC errata implies trapping the register such as IAR1 (reading interrupt), we want to get a fastpath for it (e.g not trying to execute softirq...). So I think we should bypass
leave_hypervisor_tail(). I am not entirely sure how to do it nicely thought.
Quoted 6 lines
How about adding a check for
group1_trapenable inleave_hypervisor_tail().void
leave_hypervisor_tail(void)
{
+if (group1_trap)
+ return;
I guess you mean the variable you introduced in patch #10. In that case, this would be totally wrong. You only want to skip leave_hypervisor_tail() when you are handling a ICV_* System registers.
What you want is adding a bool in the structure cpu_info to tell whether leave_hypervisor_tail() should be skipped.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [RFC PATCH 02/10] arm64: Add hook to handle guest GICv3 sysreg accesses
Quoted 37 lines · Julien Grall
Hi Manish,
Quoted 34 lines · Manish Jaggi
Quoted 24 lines · Julien Grall
Hi,
I forgot to mention one thing about the placement of
do_fixup_vgic_errata.Quoted 8 lines · On 16/01/18 15:42, [email protected] wrote:
xen/arch/arm/traps.c +0
-0@@ -2103,6 +2103,17 @@ void do_trap_guest_sync(struct cpu_user_regs *regs) { const union hsr hsr = { .bits = regs->hsr };Quoted 8 lines
+#ifdef
CONFIG_VGIC_ERRATA
+ int ret;
+
+ ret =do_fixup_vgic_errata(regs,hsr);
+ if ( !ret )
+ {
+advance_pc(regs, hsr);
+ return;I am fully aware that I suggested this solution and still support that the vGIC errata should be fully separated. After all, it deals with hardware bug and the errata will just update the LRs as the hardware would do.
Quoted 6 lines
enter_hypervisor_head()will sync the LRs state to the internal vGIC state.leave_hypervisor_head()will process pending softirq and write/update the LRs based on the internal vGIC state.As you rightfully did, the
do_fixup_vgic_erratashould be called before syncing the LRs. However, even if you return early here, you will still executeleave_hypervisor_tail(). This mean that pending softirqs will be processed and potentially the vCPU rescheduled. Because the LRs were not synced (enter_hypervisor_head()) was not called, then the vGIC state will not out-of-date and would lead to all sort of potential issues.As the vGIC errata implies trapping the register such as IAR1 (reading interrupt), we want to get a fastpath for it (e.g not trying to execute softirq...). So I think we should bypass
leave_hypervisor_tail(). I am not entirely sure how to do it nicely thought.How about adding a check for
group1_trapenable inleave_hypervisor_tail().
Quoted 9 lines
Quoted 4 lines
void
leave_hypervisor_tail(void)
{
+if (group1_trap)
+ return;I guess you mean the variable you introduced in patch #10. In that case, this would be totally wrong. You only want to skip
leave_hypervisor_tail()when you are handling a ICV_* System registers.What you want is adding a bool in the structure
cpu_infoto tell whetherleave_hypervisor_tail()should be skipped.
Why would it be wrong? I don't follow our point.
Also adding a flag in cpu_info would be overkill, use of a global variable is simpler. I am planning to remove group1_trap as a command line, and use it as
static void gicv3_hyp_init(void)
{
...
#ifdef CONFIG_CAVIUM_ERRATUM_30115
if (cpus_have_const_cap(ARM64_WORKAROUND_CAVIUM_30115)) group1_trap = 1;
#endif
...
}
Quoted 2 lines
Cheers,
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [RFC PATCH 02/10] arm64: Add hook to handle guest GICv3 sysreg accesses
Quoted 53 lines · Manish Jaggi
Quoted 37 lines · Julien Grall
Hi Manish,
Quoted 34 lines · Manish Jaggi
Quoted 24 lines · Julien Grall
Hi,
I forgot to mention one thing about the placement of
do_fixup_vgic_errata.Quoted 8 lines · On 16/01/18 15:42, [email protected] wrote:
xen/arch/arm/traps.c +0
-0@@ -2103,6 +2103,17 @@ void do_trap_guest_sync(struct cpu_user_regs *regs) { const union hsr hsr = { .bits = regs->hsr };Quoted 8 lines
+#ifdef
CONFIG_VGIC_ERRATA
+ int ret;
+
+ ret =do_fixup_vgic_errata(regs,hsr);
+ if ( !ret )
+ {
+advance_pc(regs, hsr);
+ return;I am fully aware that I suggested this solution and still support that the vGIC errata should be fully separated. After all, it deals with hardware bug and the errata will just update the LRs as the hardware would do.
Quoted 6 lines
enter_hypervisor_head()will sync the LRs state to the internal vGIC state.leave_hypervisor_head()will process pending softirq and write/update the LRs based on the internal vGIC state.As you rightfully did, the
do_fixup_vgic_erratashould be called before syncing the LRs. However, even if you return early here, you will still executeleave_hypervisor_tail(). This mean that pending softirqs will be processed and potentially the vCPU rescheduled. Because the LRs were not synced (enter_hypervisor_head()) was not called, then the vGIC state will not out-of-date and would lead to all sort of potential issues.As the vGIC errata implies trapping the register such as IAR1 (reading interrupt), we want to get a fastpath for it (e.g not trying to execute softirq...). So I think we should bypass
leave_hypervisor_tail(). I am not entirely sure how to do it nicely thought.How about adding a check for
group1_trapenable inleave_hypervisor_tail().Quoted 9 lines
Quoted 4 lines
void
leave_hypervisor_tail(void)
{
+if (group1_trap)
+ return;I guess you mean the variable you introduced in patch #10. In that case, this would be totally wrong. You only want to skip
leave_hypervisor_tail()when you are handling a ICV_* System registers.What you want is adding a bool in the structure
cpu_infoto tell whetherleave_hypervisor_tail()should be skipped.Why would it be wrong? I don't follow our point.
Also adding a flag incpu_infowould be overkill, use of a global variable is simpler. I am planning to removegroup1_trapas a command line, and use it as
Quoted 9 lines
static void
gicv3_hyp_init(void)
{
...
#ifdefCONFIG_CAVIUM_ERRATUM_30115
if (cpus_have_const_cap(ARM64_WORKAROUND_CAVIUM_30115))group1_trap= 1;
#endif
...
}
Attaching test patch
xen/arch/arm/gic-v3.c +0 -0
@@ -64,6 +64,7 @@ static DEFINE_PER_CPU(void __iomem*, rbase);
#define GICD (gicv3.map_dbase) #define GICD_RDIST_BASE (this_cpu(rbase)) #define GICD_RDIST_SGI_BASE (GICD_RDIST_BASE + SZ_64K) +static bool group1_trap = 0;
/*
* Saves all 16(Max) LR registers. Though number of LRs implemented @@ -825,7 +826,7 @@ static void gicv3_cpu_disable(void)
static void gicv3_hyp_init(void)
{
- uint32_t vtr;
+ uint32_t vtr, reg32;
vtr = READ_SYSREG32(ICH_VTR_EL2); gicv3_info.nr_lrs = (vtr & GICH_VTR_NRLRGS) + 1; @@ -837,6 +838,10 @@ static void gicv3_hyp_init(void)
WRITE_SYSREG32(GICH_VMCR_EOI | GICH_VMCR_VENG1, ICH_VMCR_EL2); WRITE_SYSREG32(GICH_HCR_EN, ICH_HCR_EL2);
+
+ reg32 = GICH_HCR_EN;
+ reg32 |= (group1_trap) ? GICH_HCR_TALL1 : 0;
+ WRITE_SYSREG32(reg32, ICH_HCR_EL2);
}
/* Set up the per-CPU parts of the GIC for a secondary CPU */ @@ -1651,6 +1656,11 @@ static int __init gicv3_init(void) return -ENODEV;
}
+#ifdef CONFIG_CAVIUM_ERRATUM_30115
+ if (cpus_have_const_cap(ARM64_WORKAROUND_CAVIUM_30115)) + group1_trap = 1;
+#endif
+
if ( acpi_disabled )
gicv3_dt_init();
else
xen/arch/arm/traps.c +0 -0
@@ -2295,6 +2295,10 @@ void do_trap_fiq(struct cpu_user_regs *regs)
void leave_hypervisor_tail(void)
{
+#ifdef CONFIG_CAVIUM_ERRATUM_30115
+ if (cpus_have_const_cap(ARM64_WORKAROUND_CAVIUM_30115)) + return;
+#endif
while (1)
{
local_irq_disable();
xen/include/asm-arm/gic.h +0 -0
@@ -117,6 +117,7 @@
#define GICH_HCR_VGRP0DIE (1 << 5)
#define GICH_HCR_VGRP1EIE (1 << 6)
#define GICH_HCR_VGRP1DIE (1 << 7)
+#define GICH_HCR_TALL1 (1 << 12)
#define GICH_MISR_EOI (1 << 0)
#define GICH_MISR_U (1 << 1)
Quoted 4 lines
Quoted 3 lines
Cheers,
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [RFC PATCH 02/10] arm64: Add hook to handle guest GICv3 sysreg accesses
In reply to Manish JaggiHi Manish,
Quoted 45 lines · Manish Jaggi
Quoted 42 lines · Julien Grall
Hi Manish,
Quoted 38 lines · Manish Jaggi
Quoted 24 lines · Julien Grall
Hi,
I forgot to mention one thing about the placement of
do_fixup_vgic_errata.Quoted 8 lines · On 16/01/18 15:42, [email protected] wrote:
xen/arch/arm/traps.c +0
-0@@ -2103,6 +2103,17 @@ void do_trap_guest_sync(struct cpu_user_regs *regs) { const union hsr hsr = { .bits = regs->hsr };Quoted 8 lines
+#ifdef
CONFIG_VGIC_ERRATA
+ int ret;
+
+ ret =do_fixup_vgic_errata(regs,hsr);
+ if ( !ret )
+ {
+advance_pc(regs, hsr);
+ return;I am fully aware that I suggested this solution and still support that the vGIC errata should be fully separated. After all, it deals with hardware bug and the errata will just update the LRs as the hardware would do.
Quoted 6 lines
enter_hypervisor_head()will sync the LRs state to the internal vGIC state.leave_hypervisor_head()will process pending softirq and write/update the LRs based on the internal vGIC state.As you rightfully did, the
do_fixup_vgic_erratashould be called before syncing the LRs. However, even if you return early here, you will still executeleave_hypervisor_tail(). This mean that pending softirqs will be processed and potentially the vCPU rescheduled. Because the LRs were not synced (enter_hypervisor_head()) was not called, then the vGIC state will not out-of-date and would lead to all sort of potential issues.As the vGIC errata implies trapping the register such as IAR1 (reading interrupt), we want to get a fastpath for it (e.g not trying to execute softirq...). So I think we should bypass
leave_hypervisor_tail(). I am not entirely sure how to do it nicely thought.How about adding a check for
group1_trapenable inleave_hypervisor_tail().void
leave_hypervisor_tail(void)
{
+if (group1_trap)
+ return;
Quoted 5 lines
Quoted 4 lines
I guess you mean the variable you introduced in patch #10. In that case, this would be totally wrong. You only want to skip
leave_hypervisor_tail()when you are handling a ICV_* System registers.What you want is adding a bool in the structure
cpu_infoto tell whetherleave_hypervisor_tail()should be skipped.Why would it be wrong? I don't follow our point.
As I mentioned in one of my previous e-mail, leave_hypervisor_tail() will process pending softirq and write/update the LRs based on the internal vGIC state. Softirq are used for scheduling, handling timer,...
So unless you want to make Xen unusable on Thunder-X, you really don't want to bypass leave_hypervisor_tail() in all the cases. Hence the suggest of a flag in cpu_info to provide a fastpath in certain cases.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/10 arm64: Add ICV_BPR1_EL1 handler
In reply to [email protected]From: Manish Jaggi <[email protected]>
Add a handler for reading/writing the guest's view of the ICC_BPR1_EL1 register, which is located in the ICH_VMCR_EL2.BPR1 field.
--- xen/arch/arm/arm64/vsysreg.c | 71 +++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/arm64/sysregs.h | 1 + xen/include/asm-arm/gic_v3_defs.h | 6 ++++ 3 files changed, 78 insertions(+)
xen/arch/arm/arm64/vsysreg.c +71 -0
@@ -22,6 +22,7 @@#include <asm/regs.h> #include <asm/traps.h> #include <asm/vtimer.h> +#include <asm/gic_v3_defs.h> void do_sysreg (struct cpu_user_regs *regs,const union hsr hsr)
@@ -220,13 +221,83 @@ void do_sysreg(struct cpu_user_regs *regs, }#ifdef CONFIG_VGIC_ERRATA +#define vtr_to_nr_pre_bits (v) ((((u32)(v) >> 26) & 7) + 1) + +static int __vgic_v3_bpr_min (void ) +{ +/* See Pseudocode for VPriorityGroup */ +return 8 -vtr_to_nr_pre_bits (READ_SYSREG32 (ICH_VTR_EL2 )); +} + +static unsigned int __vgic_v3_get_bpr0 (u32 vmcr) +{ +return (vmcr &ICH_VMCR_BPR0_MASK ) >>ICH_VMCR_BPR0_SHIFT ; +} + +static unsigned int __vgic_v3_get_bpr1 (u32 vmcr) +{ +unsigned int bpr; + +if ( vmcr &ICH_VMCR_CBPR_MASK ) + { + bpr =__vgic_v3_get_bpr0 (vmcr); +if ( bpr <7 ) + bpr++; + } +else + bpr = (vmcr &ICH_VMCR_BPR1_MASK ) >>ICH_VMCR_BPR1_SHIFT ; + +return bpr; +} + +static void __vgic_v3_read_bpr1 (struct cpu_user_regs *regs,int regidx) +{ +u32 vmcr =READ_SYSREG32 (ICH_VMCR_EL2 ); +set_user_reg (regs, regidx,__vgic_v3_get_bpr1 (vmcr)); +} + +static void __vgic_v3_write_bpr1 (struct cpu_user_regs *regs,int regidx) +{ +u64 val =get_user_reg (regs, regidx); +u8 bpr_min =__vgic_v3_bpr_min (); +u32 vmcr =READ_SYSREG32 (ICH_VMCR_EL2 ); + +if ( vmcr &ICH_VMCR_CBPR_MASK ) +return ; + +/* Enforce BPR limiting */ +if ( val < bpr_min ) + val = bpr_min; + + val <<=ICH_VMCR_BPR1_SHIFT ; + val &=ICH_VMCR_BPR1_MASK ; + vmcr &= ~ICH_VMCR_BPR1_MASK ; + vmcr |= val; + +WRITE_SYSREG32 (vmcr,ICH_VMCR_EL2 ); +} + +void handle_bpr1 (struct cpu_user_regs *regs,int regidx,bool read, +const union hsr hsr) +{ +if ( read ) +__vgic_v3_read_bpr1 (regs, regidx); +else +__vgic_v3_write_bpr1 (regs, regidx); +} +int do_fixup_vgic_errata (struct cpu_user_regs *regs,const union hsr hsr) {int ret =0 ; +int regidx = hsr.sysreg.reg;local_irq_disable ();switch ( hsr.bits &HSR_SYSREG_REGS_MASK ) { +case HSR_SYSREG_ICC_BPR1_EL1 : +handle_bpr1 (regs, regidx, hsr.sysreg.read, hsr); +break ; +default : ret =-1 ;break ;
xen/include/asm-arm/arm64/sysregs.h +1 -0
@@ -89,6 +89,7 @@#define HSR_SYSREG_ICC_ASGI1R_EL1 HSR_SYSREG(3,1,c12,c11,6)#define HSR_SYSREG_ICC_SGI0R_EL1 HSR_SYSREG(3,2,c12,c11,7)#define HSR_SYSREG_ICC_SRE_EL1 HSR_SYSREG(3,0,c12,c12,5) +#define HSR_SYSREG_ICC_BPR1_EL1 HSR_SYSREG(3,0,c12,c12,3)#define HSR_SYSREG_CONTEXTIDR_EL1 HSR_SYSREG(3,0,c13,c0,1)#define HSR_SYSREG_PMCR_EL0 HSR_SYSREG(3,3,c9,c12,0)
xen/include/asm-arm/gic_v3_defs.h +6 -0
@@ -157,6 +157,12 @@#define GICH_VMCR_EOI (1 << 9)#define GICH_VMCR_VENG1 (1 << 1) +#define ICH_VMCR_CBPR_SHIFT 4 +#define ICH_VMCR_CBPR_MASK (1 << ICH_VMCR_CBPR_SHIFT) +#define ICH_VMCR_BPR0_SHIFT 21 +#define ICH_VMCR_BPR0_MASK (7 << ICH_VMCR_BPR0_SHIFT) +#define ICH_VMCR_BPR1_SHIFT 18 +#define ICH_VMCR_BPR1_MASK (7 << ICH_VMCR_BPR1_SHIFT)#define GICH_LR_VIRTUAL_MASK 0xffff#define GICH_LR_VIRTUAL_SHIFT 0
Signature · 7 lines
2.14.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 03/10] arm64: Add ICV_BPR1_EL1 handler
Hi Manish,
Quoted 4 lines · On 16/01/18 15:42, [email protected] wrote:
From: Manish Jaggi <[email protected]>
Add a handler for reading/writing the guest's view of the
ICC_BPR1_EL1register, which is located in the ICH_VMCR_EL2.BPR1 field.
This commit (and likely the followings) is coming from Linux, right? If it matches commit from Linux, then you need to keep tags and point to the Linux commit. See commit 7762c2d6f4 in Xen as an example to how to do it.
If you make changes for Xen, then write "Adapted for Xen...".
But looking at the patch the major difference is you use Xen coding style. The rest is pretty much use Xen name for access register and adding missing define.
I think it would be beneficial for Xen to re-use Linux code. The compatibility layer should be very limited. Stefano any opinions?
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 03/10] arm64: Add ICV_BPR1_EL1 handler
Quoted 11 lines · Julien Grall
Hi Manish,
Quoted 4 lines · On 16/01/18 15:42, [email protected] wrote:
From: Manish Jaggi <[email protected]>
Add a handler for reading/writing the guest's view of the
ICC_BPR1_EL1register, which is located in the ICH_VMCR_EL2.BPR1 field.This commit (and likely the followings) is coming from Linux, right? If it matches commit from Linux, then you need to keep tags and point to the Linux commit. See commit
7762c2d6f4in Xen as an example to how to do it.If you make changes for Xen, then write "Adapted for Xen...".
ok
Quoted 4 lines
But looking at the patch the major difference is you use Xen coding style. The rest is pretty much use Xen name for access register and adding missing define.
I think it would be beneficial for Xen to re-use Linux code. The compatibility layer should be very limited. Stefano any opinions?
So when you mean linux code, you refer to a patch or importing the code file from linux ?
Quoted 3 lines
Cheers,
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 03/10] arm64: Add ICV_BPR1_EL1 handler
Hi Manish,
Quoted 11 lines · Manish Jaggi
Quoted 10 lines · Julien Grall
Hi Manish,
Quoted 4 lines · On 16/01/18 15:42, [email protected] wrote:
From: Manish Jaggi <[email protected]>
Add a handler for reading/writing the guest's view of the
ICC_BPR1_EL1register, which is located in the ICH_VMCR_EL2.BPR1 field.This commit (and likely the followings) is coming from Linux, right? If it matches commit from Linux, then you need to keep tags and point to the Linux commit. See commit
7762c2d6f4in Xen as an example to how to do it.
Quoted 7 lines
Quoted 1 line
If you make changes for Xen, then write "Adapted for Xen...".
ok
Quoted 4 lines
But looking at the patch the major difference is you use Xen coding style. The rest is pretty much use Xen name for access register and adding missing define.
I think it would be beneficial for Xen to re-use Linux code. The compatibility layer should be very limited. Stefano any opinions?
So when you mean linux code, you refer to a patch or importing the code file from linux ?
Importing the code from Linux. And then a patch to adapt for Xen (it should be fairly small).
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 4/10 arm64: Add ICV_IGRPEN1_EL1 handler
In reply to [email protected]From: Manish Jaggi <[email protected]>
Add a handler for reading/writing the guest's view of the ICC_IGRPEN1_EL1 register, which is located in the ICH_VMCR_EL2.VENG1 field.
--- xen/arch/arm/arm64/vsysreg.c | 32 ++++++++++++++++++++++++++++++++ xen/include/asm-arm/arm64/sysregs.h | 1 + xen/include/asm-arm/gic_v3_defs.h | 2 ++ 3 files changed, 35 insertions(+)
xen/arch/arm/arm64/vsysreg.c +32 -0
@@ -286,6 +286,34 @@ void handle_bpr1(struct cpu_user_regs *regs, int regidx, bool read,__vgic_v3_write_bpr1 (regs, regidx); } +static void __vgic_v3_read_igrpen1 (struct cpu_user_regs *regs,int regidx) +{ +u32 vmcr =READ_SYSREG32 (ICH_VMCR_EL2 ); +set_user_reg (regs, regidx, !!(vmcr &ICH_VMCR_ENG1_MASK )); +} + +static void __vgic_v3_write_igrpen1 (struct cpu_user_regs *regs,int regidx) +{ +u64 val =get_user_reg (regs, regidx); +u32 vmcr =READ_SYSREG32 (ICH_VMCR_EL2 ); + +if ( val &1 ) + vmcr |=ICH_VMCR_ENG1_MASK ; +else + vmcr &= ~ICH_VMCR_ENG1_MASK ; + +WRITE_SYSREG32 (vmcr,ICH_VMCR_EL2 ); +} + +void handle_igrpen1 (struct cpu_user_regs *regs,int regidx,bool read, +const union hsr hsr) +{ +if ( read ) +__vgic_v3_read_igrpen1 (regs, regidx); +else +__vgic_v3_write_igrpen1 (regs, regidx); +} +int do_fixup_vgic_errata (struct cpu_user_regs *regs,const union hsr hsr) {int ret =0 ;
@@ -298,6 +326,10 @@ int do_fixup_vgic_errata(struct cpu_user_regs *regs, const union hsr hsr)handle_bpr1 (regs, regidx, hsr.sysreg.read, hsr);break ; +case HSR_SYSREG_ICC_IGRPEN1_EL1 : +handle_igrpen1 (regs, regidx, hsr.sysreg.read, hsr); +break ; +default : ret =-1 ;break ;
xen/include/asm-arm/arm64/sysregs.h +1 -0
@@ -90,6 +90,7 @@#define HSR_SYSREG_ICC_SGI0R_EL1 HSR_SYSREG(3,2,c12,c11,7)#define HSR_SYSREG_ICC_SRE_EL1 HSR_SYSREG(3,0,c12,c12,5)#define HSR_SYSREG_ICC_BPR1_EL1 HSR_SYSREG(3,0,c12,c12,3) +#define HSR_SYSREG_ICC_IGRPEN1_EL1 HSR_SYSREG(3,0,c12,c12,7)#define HSR_SYSREG_CONTEXTIDR_EL1 HSR_SYSREG(3,0,c13,c0,1)#define HSR_SYSREG_PMCR_EL0 HSR_SYSREG(3,3,c9,c12,0)
xen/include/asm-arm/gic_v3_defs.h +2 -0
@@ -163,6 +163,8 @@#define ICH_VMCR_BPR0_MASK (7 << ICH_VMCR_BPR0_SHIFT)#define ICH_VMCR_BPR1_SHIFT 18#define ICH_VMCR_BPR1_MASK (7 << ICH_VMCR_BPR1_SHIFT) +#define ICH_VMCR_ENG1_SHIFT 1 +#define ICH_VMCR_ENG1_MASK (1 << ICH_VMCR_ENG1_SHIFT)#define GICH_LR_VIRTUAL_MASK 0xffff#define GICH_LR_VIRTUAL_SHIFT 0
Signature · 7 lines
2.14.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 5/10 arm64: Add accessors for the ICH_APxRn_EL2 registers
In reply to [email protected]From: Manish Jaggi <[email protected]>
define accessors that take the register number as a parameter.
--- xen/arch/arm/arm64/vsysreg.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+)
xen/arch/arm/arm64/vsysreg.c +92 -0
@@ -314,6 +314,98 @@ void handle_igrpen1(struct cpu_user_regs *regs, int regidx, bool read,__vgic_v3_write_igrpen1 (regs, regidx); } +void __vgic_v3_write_ap0rn (u32 val,int n) +{ +switch (n) + { +case 0 : +WRITE_SYSREG32 (val,ICH_AP0R0_EL2 ); +break ; +case 1 : +WRITE_SYSREG32 (val,ICH_AP0R1_EL2 ); +break ; +case 2 : +WRITE_SYSREG32 (val,ICH_AP0R2_EL2 ); +break ; +case 3 : +WRITE_SYSREG32 (val,ICH_AP0R3_EL2 ); +break ; +default : +unreachable (); + } +} + +void __vgic_v3_write_ap1rn (u32 val,int n) +{ +switch (n) + { +case 0 : +WRITE_SYSREG32 (val,ICH_AP1R0_EL2 ); +break ; +case 1 : +WRITE_SYSREG32 (val,ICH_AP1R1_EL2 ); +break ; +case 2 : +WRITE_SYSREG32 (val,ICH_AP1R2_EL2 ); +break ; +case 3 : +WRITE_SYSREG32 (val,ICH_AP1R3_EL2 ); +break ; +default : +unreachable (); + } +} + +u32 __vgic_v3_read_ap0rn (int n) +{ +u32 val; + +switch (n) + { +case 0 : + val =READ_SYSREG32 (ICH_AP0R0_EL2 ); +break ; +case 1 : + val =READ_SYSREG32 (ICH_AP0R1_EL2 ); +break ; +case 2 : + val =READ_SYSREG32 (ICH_AP0R2_EL2 ); +break ; +case 3 : + val =READ_SYSREG32 (ICH_AP0R3_EL2 ); +break ; +default : +unreachable (); + } + +return val; +} + +u32 __vgic_v3_read_ap1rn (int n) +{ +u32 val; + +switch (n) + { +case 0 : + val =READ_SYSREG32 (ICH_AP1R0_EL2 ); +break ; +case 1 : + val =READ_SYSREG32 (ICH_AP1R1_EL2 ); +break ; +case 2 : + val =READ_SYSREG32 (ICH_AP1R2_EL2 ); +break ; +case 3 : + val =READ_SYSREG32 (ICH_AP1R3_EL2 ); +break ; +default : +unreachable (); + } + +return val; +} +int do_fixup_vgic_errata (struct cpu_user_regs *regs,const union hsr hsr) {int ret =0 ;
Signature · 7 lines
2.14.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 6/10 Expose gicv3_ich_read/write_lr
In reply to [email protected]From: Manish Jaggi <[email protected]>
gicv3_ich_read/write_lr functions are static in gic-v3.c
This patch creates wrapper functions which can be used from outside the file.
--- xen/arch/arm/gic-v3.c | 10 ++++++++++ xen/include/asm-arm/gic_v3.h | 7 +++++++ 2 files changed, 17 insertions(+)
xen/arch/arm/gic-v3.c +10 -0
@@ -184,6 +184,11 @@ static uint64_t gicv3_ich_read_lr(int lr) } } +uint64_t __gicv3_ich_read_lr (int lr) +{ +return gicv3_ich_read_lr (lr); +} +static void gicv3_ich_write_lr (int lr,uint64_t val) { switch ( lr )
@@ -242,6 +247,11 @@ static void gicv3_ich_write_lr(int lr, uint64_t val)isb (); } +void __gicv3_ich_write_lr (int lr,uint64_t val) +{ +return gicv3_ich_write_lr (lr, val); +} +/* * System Register Enable (SRE). Enable to access CPU & Virtual * interface registers as system registers in EL2
xen/include/asm-arm/gic_v3.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef GICV3_H +#define GICV3_H + +uint64_t __gicv3_ich_read_lr (int lr); +void __gicv3_ich_write_lr (int lr,uint64_t val); + +#endif
Signature · 7 lines
2.14.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 06/10] Expose gicv3_ich_read/write_lr
Hi,
Quoted 16 lines · On 16/01/18 15:43, [email protected] wrote:
From: Manish Jaggi <[email protected]>
gicv3_ich_read/write_lr functions are static in
gic-v3.c
This patch creates wrapper functions which can be used from outside the file.Signed-off-by Manish Jaggi <[email protected]>--- xen/arch/arm/gic-v3.c | 10 ++++++++++ xen/include/asm-arm/gic_v3.h | 7 +++++++ 2 files changed, 17 insertions(+)xen/arch/arm/gic-v3.c +0
-0
xen/arch/arm/gic-v3.c static uint64_t gicv3_ich_read_lr(int lr) · line 187
Quoted 4 lines
xen/arch/arm/gic-v3.c +1
-0@@ -184,6 +184,11 @@ static uint64_t gicv3_ich_read_lr(int lr) } } +uint64_t __gicv3_ich_read_lr (int lr)
I see no reason to have a wrapper with exactly the same parameters. Just export the current one.
But I think I would prefer the function to be redefined in the cpu if implementation. So we vGIC errata is fully separated from the rest of Xen.
Quoted 26 lines
xen/arch/arm/gic-v3.c +9
-0+{ +return gicv3_ich_read_lr (lr); +} +static void gicv3_ich_write_lr (int lr,uint64_t val) { switch ( lr )@@ -242,6 +247,11 @@ static void gicv3_ich_write_lr(int lr, uint64_t val)isb (); } +void __gicv3_ich_write_lr (int lr,uint64_t val) +{ +return gicv3_ich_write_lr (lr, val); +} +/* * System Register Enable (SRE). Enable to access CPU & Virtual * interface registers as system registers in EL2 xen/include/asm-arm/gic_v3.h new file +0
-0
xen/include/asm-arm/gic_v3.h line 7
Quoted 7 lines
xen/include/asm-arm/gic_v3.h new file +7
-0@@ -0,0 +1,7 @@ +#ifndef GICV3_H +#define GICV3_H + +uint64_t __gicv3_ich_read_lr (int lr); +void __gicv3_ich_write_lr (int lr,uint64_t val); + +#endif
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 06/10] Expose gicv3_ich_read/write_lr
Quoted 25 lines · Julien Grall
Hi,
Quoted 16 lines · On 16/01/18 15:43, [email protected] wrote:
From: Manish Jaggi <[email protected]>
gicv3_ich_read/write_lr functions are static in
gic-v3.c
This patch creates wrapper functions which can be used from outside the file.Signed-off-by Manish Jaggi <[email protected]>---
xen/arch/arm/gic-v3.c | 10 ++++++++++
xen/include/asm-arm/gic_v3.h| 7 +++++++2 files changed, 17 insertions(+)xen/arch/arm/gic-v3.c +0
-0xen/arch/arm/gic-v3.c static uint64_t gicv3_ich_read_lr(int lr) · line 186
Quoted 3 lines
xen/arch/arm/gic-v3.c +0
-0@@ -184,6 +184,11 @@ static uint64_t gicv3_ich_read_lr(int lr) } } +uint64_t __gicv3_ich_read_lr(int lr)I see no reason to have a wrapper with exactly the same parameters. Just export the current one.
Quoted 1 line
But I think I would prefer the function to be redefined in the cpu if implementation. So we vGIC errata is fully separated from the rest of Xen.
ok, will do.
Quoted 28 lines
Quoted 28 lines
xen/arch/arm/gic-v3.c +8
-0+{ + return gicv3_ich_read_lr(lr); +} + static void gicv3_ich_write_lr(int lr, uint64_t val) { switch ( lr )@@ -242,6 +247,11 @@ static void gicv3_ich_write_lr(int lr, uint64_t val) isb(); } +void __gicv3_ich_write_lr(int lr, uint64_t val) +{ + return gicv3_ich_write_lr(lr, val); +} + /** System Register Enable (SRE). Enable to access CPU & Virtual * interface registers as system registers in EL2
xen/include/asm-arm/gic_v3.h new file +2
-0@@ -0,0 +1,7 @@ +#ifndef GICV3_H +#define GICV3_H
Quoted 9 lines
xen/include/asm-arm/gic_v3.h line 7
Quoted 6 lines
xen/include/asm-arm/gic_v3.h new file +5
-0+ +uint64_t __gicv3_ich_read_lr (int lr); +void __gicv3_ich_write_lr (int lr,uint64_t val); + +#endif Cheers,
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 7/10 arm64: Add ICV_IAR1_EL1 handler
In reply to [email protected]From: Manish Jaggi <[email protected]>
Add a handler for reading the guest's view of the ICC_IAR1_EL1 register. This involves finding the highest priority Group-1 interrupt, checking against both PMR and the active group priority, activating the interrupt and setting the group priority as active.
--- xen/arch/arm/arm64/vsysreg.c | 192 ++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/arm64/sysregs.h | 1 + xen/include/asm-arm/gic_v3_defs.h | 18 ++++ 3 files changed, 211 insertions(+)
xen/arch/arm/arm64/vsysreg.c +192 -0
@@ -23,6 +23,7 @@#include <asm/traps.h> #include <asm/vtimer.h> #include <asm/gic_v3_defs.h> +#include <asm/gic_v3.h> void do_sysreg (struct cpu_user_regs *regs,const union hsr hsr)
@@ -222,6 +223,13 @@ void do_sysreg(struct cpu_user_regs *regs,#ifdef CONFIG_VGIC_ERRATA #define vtr_to_nr_pre_bits (v) ((((u32)(v) >> 26) & 7) + 1) +#define vtr_to_nr_apr_regs (v) (1 << (vtr_to_nr_pre_bits(v) - 5)) + +#define ESR_ELx_SYS64_ISS_CRM_SHIFT 1 +#define ESR_ELx_SYS64_ISS_CRM_MASK (0xf << ESR_ELx_SYS64_ISS_CRM_SHIFT) + +#define ICC_IAR1_EL1_SPURIOUS 0x3ff +#define VGIC_MAX_SPI 1019static int __vgic_v3_bpr_min (void ) {
@@ -406,6 +414,186 @@ u32 __vgic_v3_read_ap1rn(int n)return val; } +static int __vgic_v3_get_group (const union hsr hsr) +{ +u8 crm = (hsr.bits & ESR_ELx_SYS64_ISS_CRM_MASK) >> + ESR_ELx_SYS64_ISS_CRM_SHIFT; + +return crm !=8 ; +} + +unsigned int gic_get_num_lrs (void ) +{ +uint32_t vtr; + + vtr =READ_SYSREG32 (ICH_VTR_EL2 ); +return (vtr &GICH_VTR_NRLRGS ) +1 ; +} + +static int __vgic_v3_highest_priority_lr (struct cpu_user_regs *regs, +u32 vmcr,u64 *lr_val) +{ +int i, lr =-1 ; +unsigned int used_lrs =gic_get_num_lrs (); +u8 priority =GICV3_IDLE_PRIORITY ; + +for ( i =0 ; i < used_lrs; i++ ) + { +u64 val =__gicv3_ich_read_lr (i); +u8 lr_prio = (val &ICH_LR_PRIORITY_MASK ) >>ICH_LR_PRIORITY_SHIFT ; + +/* Not pending in the state? */ +if ( (val &ICH_LR_STATE ) !=ICH_LR_PENDING_BIT ) +continue ; + +/* Group-0 interrupt, but Group-0 disabled? */ +if ( !(val &ICH_LR_GROUP ) && !(vmcr &ICH_VMCR_ENG0_MASK ) ) +continue ; + +/* Group-1 interrupt, but Group-1 disabled? */ +if ( (val &ICH_LR_GROUP ) && !(vmcr &ICH_VMCR_ENG1_MASK ) ) +continue ; + +/* Not the highest priority? */ +if ( lr_prio >= priority ) +continue ; + +/* This is a candidate */ + priority = lr_prio; + *lr_val = val; + lr = i; + } + +if ( lr ==-1 ) + *lr_val =ICC_IAR1_EL1_SPURIOUS ; + +return lr; +} + +static int __vgic_v3_get_highest_active_priority (void ) +{ +int i; +u32 hap =0 ; +u8 nr_apr_regs =vtr_to_nr_apr_regs (READ_SYSREG32 (ICH_VTR_EL2 )); + +for ( i =0 ; i < nr_apr_regs; i++ ) + { +u32 val; + +/* +* The ICH_AP0Rn_EL2 and ICH_AP1Rn_EL2 registers +* contain the active priority levels for this VCPU +* for the maximum number of supported priority +* levels, and we return the full priority level only +* if the BPR is programmed to its minimum, otherwise +* we return a combination of the priority level and +* subpriority, as determined by the setting of the +* BPR, but without the full subpriority. +*/ + val =__vgic_v3_read_ap0rn (i); + val |=__vgic_v3_read_ap1rn (i); +if ( !val ) + { + hap +=32 ; +continue ; + } + +return (hap +__ffs (val)) <<__vgic_v3_bpr_min (); + } + +return GICV3_IDLE_PRIORITY ; +} + +/* +* Convert a priority to a preemption level, taking the relevant BPR +* into account by zeroing the sub-priority bits. +*/ +static u8 __vgic_v3_pri_to_pre (u8 pri,u32 vmcr,int grp) +{ +unsigned int bpr; + +if ( !grp ) + bpr =__vgic_v3_get_bpr0 (vmcr) +1 ; +else + bpr =__vgic_v3_get_bpr1 (vmcr); + +return pri & (GENMASK (7 ,0 ) << bpr); +} + +/* +* The priority value is independent of any of the BPR values, so we +* normalize it using the minumal BPR value. This guarantees that no +* matter what the guest does with its BPR, we can always set/get the +* same value of a priority. +*/ +static void __vgic_v3_set_active_priority (u8 pri,u32 vmcr,int grp) +{ +u8 pre, ap; +u32 val; +int apr; + + pre =__vgic_v3_pri_to_pre (pri, vmcr, grp); + ap = pre >>__vgic_v3_bpr_min (); + apr = ap /32 ; + +if ( !grp ) + { + val =__vgic_v3_read_ap0rn (apr); +__vgic_v3_write_ap0rn (val |BIT (ap %32 ), apr); + } +else + { + val =__vgic_v3_read_ap1rn (apr); +__vgic_v3_write_ap1rn (val |BIT (ap %32 ), apr); + } +} + +static void __vgic_v3_read_iar (struct cpu_user_regs *regs,int regidx, +const union hsr hsr) +{ +u64 lr_val; +u8 lr_prio, pmr; +int lr, grp; + +u32 vmcr =READ_SYSREG32 (ICH_VMCR_EL2 ); + grp =__vgic_v3_get_group (hsr); + + lr =__vgic_v3_highest_priority_lr (regs, vmcr, &lr_val); +if ( lr <0 ) + goto spurious; + +if ( grp != !!(lr_val &ICH_LR_GROUP ) ) + goto spurious; + + pmr = (vmcr &ICH_VMCR_PMR_MASK ) >>ICH_VMCR_PMR_SHIFT ; + lr_prio = (lr_val &ICH_LR_PRIORITY_MASK ) >>ICH_LR_PRIORITY_SHIFT ; +if ( pmr <= lr_prio ) + goto spurious; + +if (__vgic_v3_get_highest_active_priority () <= +__vgic_v3_pri_to_pre (lr_prio, vmcr, grp) ) + goto spurious; + + lr_val &= ~ICH_LR_STATE ; +/* No active state for LPIs */ +if ( (lr_val &ICH_LR_VIRTUAL_ID_MASK ) <=VGIC_MAX_SPI ) + lr_val |=ICH_LR_ACTIVE_BIT ; + +__gicv3_ich_write_lr (lr, lr_val); +__vgic_v3_set_active_priority (lr_prio, vmcr, grp); +set_user_reg (regs, regidx, lr_val &ICH_LR_VIRTUAL_ID_MASK ); + +return ; + +spurious: +set_user_reg (regs, regidx,ICC_IAR1_EL1_SPURIOUS ); +} + +void handle_iar (struct cpu_user_regs *regs,int regidx,const union hsr hsr) +{ +__vgic_v3_read_iar (regs, regidx, hsr); +} +int do_fixup_vgic_errata (struct cpu_user_regs *regs,const union hsr hsr) {int ret =0 ;
@@ -422,6 +610,10 @@ int do_fixup_vgic_errata(struct cpu_user_regs *regs, const union hsr hsr)handle_igrpen1 (regs, regidx, hsr.sysreg.read, hsr);break ; +case HSR_SYSREG_ICC_IAR1_EL1 : +handle_iar (regs, regidx, hsr); +break ; +default : ret =-1 ;break ;
xen/include/asm-arm/arm64/sysregs.h +1 -0
@@ -91,6 +91,7 @@#define HSR_SYSREG_ICC_SRE_EL1 HSR_SYSREG(3,0,c12,c12,5)#define HSR_SYSREG_ICC_BPR1_EL1 HSR_SYSREG(3,0,c12,c12,3)#define HSR_SYSREG_ICC_IGRPEN1_EL1 HSR_SYSREG(3,0,c12,c12,7) +#define HSR_SYSREG_ICC_IAR1_EL1 HSR_SYSREG(3,0,c12,c12,0)#define HSR_SYSREG_CONTEXTIDR_EL1 HSR_SYSREG(3,0,c13,c0,1)#define HSR_SYSREG_PMCR_EL0 HSR_SYSREG(3,3,c9,c12,0)
xen/include/asm-arm/gic_v3_defs.h +18 -0
@@ -68,6 +68,8 @@#define GICV3_GICD_IIDR_VAL 0x34c#define GICV3_GICR_IIDR_VAL GICV3_GICD_IIDR_VAL +#define GICV3_IDLE_PRIORITY 0xff +#define GICR_CTLR (0x0000)#define GICR_IIDR (0x0004)#define GICR_TYPER (0x0008)
@@ -165,6 +167,10 @@#define ICH_VMCR_BPR1_MASK (7 << ICH_VMCR_BPR1_SHIFT)#define ICH_VMCR_ENG1_SHIFT 1#define ICH_VMCR_ENG1_MASK (1 << ICH_VMCR_ENG1_SHIFT) +#define ICH_VMCR_ENG0_SHIFT 0 +#define ICH_VMCR_ENG0_MASK (1 << ICH_VMCR_ENG0_SHIFT) +#define ICH_VMCR_PMR_SHIFT 24 +#define ICH_VMCR_PMR_MASK (0xffUL << ICH_VMCR_PMR_SHIFT)#define GICH_LR_VIRTUAL_MASK 0xffff#define GICH_LR_VIRTUAL_SHIFT 0
@@ -182,6 +188,18 @@#define GICH_LR_GRP1 (1UL<<60)#define GICH_LR_HW (1UL<<61) +#define ICH_LR_PRIORITY_SHIFT 48 +#define ICH_LR_PRIORITY_MASK (0xffULL << ICH_LR_PRIORITY_SHIFT) +#define ICH_LR_EOI (1ULL << 41) +#define ICH_LR_GROUP (1ULL << 60) +#define ICH_LR_HW (1ULL << 61) +#define ICH_LR_STATE (3ULL << 62) +#define ICH_LR_PENDING_BIT (1ULL << 62) +#define ICH_LR_ACTIVE_BIT (1ULL << 63) +#define ICH_LR_PHYS_ID_SHIFT 32 +#define ICH_LR_PHYS_ID_MASK (0x3ffULL << ICH_LR_PHYS_ID_SHIFT) +#define ICH_LR_VIRTUAL_ID_MASK ((1ULL << 32) - 1) +#define GICH_VTR_NRLRGS 0x3f#define GICH_VTR_PRIBITS_MASK 0x7#define GICH_VTR_PRIBITS_SHIFT 29
Signature · 7 lines
2.14.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 8/10 Add ICV_EOIR1_EL1 handler
In reply to [email protected]From: Manish Jaggi <[email protected]>
Add a handler for writing the guest's view of the ICC_EOIR1_EL1 register. This involves dropping the priority of the interrupt, and deactivating it if required.
--- xen/arch/arm/arm64/vsysreg.c | 136 ++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/arm64/sysregs.h | 1 + xen/include/asm-arm/gic_v3_defs.h | 4 ++ 3 files changed, 141 insertions(+)
xen/arch/arm/arm64/vsysreg.c +136 -0
@@ -230,6 +230,7 @@ void do_sysreg(struct cpu_user_regs *regs,#define ICC_IAR1_EL1_SPURIOUS 0x3ff#define VGIC_MAX_SPI 1019 +#define VGIC_MIN_LPI 8192static int __vgic_v3_bpr_min (void ) {
@@ -594,6 +595,137 @@ void handle_iar(struct cpu_user_regs *regs, int regidx, const union hsr hsr)__vgic_v3_read_iar (regs, regidx, hsr); } +static int __vgic_v3_find_active_lr (int intid,u64 *lr_val) +{ +int i; +unsigned int used_lrs =gic_get_num_lrs (); + +for ( i =0 ; i < used_lrs; i++ ) + { +u64 val =__gicv3_ich_read_lr (i); + +if ( (val &ICH_LR_VIRTUAL_ID_MASK ) == intid && + (val &ICH_LR_ACTIVE_BIT ) ) + { + *lr_val = val; +return i; + } + } + + *lr_val =ICC_IAR1_EL1_SPURIOUS ; +return -1 ; +} + +static int __vgic_v3_clear_highest_active_priority (void ) +{ +u32 hap =0 ; +int i; +u8 nr_apr_regs =vtr_to_nr_apr_regs (READ_SYSREG32 (ICH_VTR_EL2 )); + +for ( i =0 ; i < nr_apr_regs; i++ ) + { +u32 ap0, ap1; +int c0, c1; + + ap0 =__vgic_v3_read_ap0rn (i); + ap1 =__vgic_v3_read_ap1rn (i); +if ( !ap0 && !ap1 ) + { + hap +=32 ; +continue ; + } + + c0 = ap0 ?__ffs (ap0) :32 ; + c1 = ap1 ?__ffs (ap1) :32 ; + +/* Always clear the LSB, which is the highest priority */ +if (c0 < c1) + { + ap0 &= ~BIT (c0); +__vgic_v3_write_ap0rn (ap0, i); + hap += c0; + } +else + { + ap1 &= ~BIT (c1); +__vgic_v3_write_ap1rn (ap1, i); + hap += c1; + } + +/* Rescale to 8 bits of priority */ +return hap <<__vgic_v3_bpr_min (); + } + +return GICV3_IDLE_PRIORITY ; +} + +static void __vgic_v3_clear_active_lr (int lr,u64 lr_val) +{ + lr_val &= ~ICH_LR_ACTIVE_BIT ; +if (lr_val &ICH_LR_HW ) + { +u32 pid; + + pid = (lr_val &ICH_LR_PHYS_ID_MASK ) >>ICH_LR_PHYS_ID_SHIFT ; +WRITE_SYSREG32 (pid,ICC_DIR_EL1 ); + } +__gicv3_ich_write_lr (lr, lr_val); +} + +static void __vgic_v3_bump_eoicount (void ) +{ +u32 hcr; + + hcr =READ_SYSREG32 (ICH_HCR_EL2 ); + hcr +=1 << ICH_HCR_EOIcount_SHIFT; +WRITE_SYSREG32 (hcr,ICH_HCR_EL2 ); +} + +static void __vgic_v3_write_eoir (struct cpu_user_regs *regs,int regidx, +const union hsr hsr) +{ +u32 vmcr =READ_SYSREG32 (ICH_VMCR_EL2 ); +u32 vid =get_user_reg (regs, regidx); +u64 lr_val; +u8 lr_prio, act_prio; +int lr, grp; + + grp =__vgic_v3_get_group (hsr); + +/* Drop priority in any case */ + act_prio =__vgic_v3_clear_highest_active_priority (); + +/* If EOIing an LPI, no deactivate to be performed */ +if ( vid >=VGIC_MIN_LPI ) +return ; + +/* EOImode == 1, nothing to be done here */ +if ( vmcr &ICH_VMCR_EOIM_MASK ) +return ; + + lr =__vgic_v3_find_active_lr (vid, &lr_val); +if ( lr ==-1 ) + { +__vgic_v3_bump_eoicount (); +return ; + } + + lr_prio = (lr_val &ICH_LR_PRIORITY_MASK ) >>ICH_LR_PRIORITY_SHIFT ; + +/* If priorities or group do not match, the guest has fscked-up. */ +if ( grp != !!(lr_val &ICH_LR_GROUP ) || +__vgic_v3_pri_to_pre (lr_prio, vmcr, grp) != act_prio ) +return ; + +/* Let's now perform the deactivation */ +__vgic_v3_clear_active_lr (lr, lr_val); +} + +void handle_eoi (struct cpu_user_regs *regs,int regidx,const union hsr hsr) +{ +__vgic_v3_write_eoir (regs, regidx, hsr); +} +int do_fixup_vgic_errata (struct cpu_user_regs *regs,const union hsr hsr) {int ret =0 ;
@@ -614,6 +746,10 @@ int do_fixup_vgic_errata(struct cpu_user_regs *regs, const union hsr hsr)handle_iar (regs, regidx, hsr);break ; +case HSR_SYSREG_ICC_EOIR1_EL1 : +handle_eoi (regs, regidx, hsr); +break ; +default : ret =-1 ;break ;
xen/include/asm-arm/arm64/sysregs.h +1 -0
@@ -92,6 +92,7 @@#define HSR_SYSREG_ICC_BPR1_EL1 HSR_SYSREG(3,0,c12,c12,3)#define HSR_SYSREG_ICC_IGRPEN1_EL1 HSR_SYSREG(3,0,c12,c12,7)#define HSR_SYSREG_ICC_IAR1_EL1 HSR_SYSREG(3,0,c12,c12,0) +#define HSR_SYSREG_ICC_EOIR1_EL1 HSR_SYSREG(3,0,c12,c12,1)#define HSR_SYSREG_CONTEXTIDR_EL1 HSR_SYSREG(3,0,c13,c0,1)#define HSR_SYSREG_PMCR_EL0 HSR_SYSREG(3,3,c9,c12,0)
xen/include/asm-arm/gic_v3_defs.h +4 -0
@@ -171,6 +171,10 @@#define ICH_VMCR_ENG0_MASK (1 << ICH_VMCR_ENG0_SHIFT)#define ICH_VMCR_PMR_SHIFT 24#define ICH_VMCR_PMR_MASK (0xffUL << ICH_VMCR_PMR_SHIFT) +#define ICH_VMCR_EOIM_SHIFT 9 +#define ICH_VMCR_EOIM_MASK (1 << ICH_VMCR_EOIM_SHIFT) +#define ICH_HCR_EOIcount_SHIFT 27 +#define ICH_HCR_EOIcount_MASK (0x1f << ICH_HCR_EOIcount_SHIFT)#define GICH_LR_VIRTUAL_MASK 0xffff#define GICH_LR_VIRTUAL_SHIFT 0
Signature · 7 lines
2.14.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 9/10 arm64: Add a handler for ICV_HPPIR1_EL1
In reply to [email protected]From: Manish Jaggi <[email protected]>
Add a handler for reading the guest's view of the ICV_HPPIR1_EL1 register. This is a simple parsing of the available LRs, extracting the highest available interrupt.
--- xen/arch/arm/arm64/vsysreg.c | 24 ++++++++++++++++++++++++ xen/include/asm-arm/arm64/sysregs.h | 1 + 2 files changed, 25 insertions(+)
xen/arch/arm/arm64/vsysreg.c +24 -0
@@ -726,6 +726,26 @@ void handle_eoi(struct cpu_user_regs *regs, int regidx, const union hsr hsr)__vgic_v3_write_eoir (regs, regidx, hsr); } +void handle_hppir1 (struct cpu_user_regs *regs,int regidx,const union hsr hsr) +{ +u64 lr_val; +int lr, lr_grp, grp; +u32 vmcr =READ_SYSREG32 (ICH_VMCR_EL2 ); + + grp =__vgic_v3_get_group (hsr); + lr =__vgic_v3_highest_priority_lr (regs, vmcr, &lr_val); + +if ( lr ==-1 ) + goto spurious; + + lr_grp = !!(lr_val &ICH_LR_GROUP ); +if ( lr_grp != grp ) + lr_val =ICC_IAR1_EL1_SPURIOUS ; + +spurious: +set_user_reg (regs, regidx, lr_val &ICH_LR_VIRTUAL_ID_MASK ); +} +int do_fixup_vgic_errata (struct cpu_user_regs *regs,const union hsr hsr) {int ret =0 ;
@@ -750,6 +770,10 @@ int do_fixup_vgic_errata(struct cpu_user_regs *regs, const union hsr hsr)handle_eoi (regs, regidx, hsr);break ; +case HSR_SYSREG_ICC_HPPIR1_EL1 : +handle_hppir1 (regs, regidx, hsr); +break ; +default : ret =-1 ;break ;
xen/include/asm-arm/arm64/sysregs.h +1 -0
@@ -93,6 +93,7 @@#define HSR_SYSREG_ICC_IGRPEN1_EL1 HSR_SYSREG(3,0,c12,c12,7)#define HSR_SYSREG_ICC_IAR1_EL1 HSR_SYSREG(3,0,c12,c12,0)#define HSR_SYSREG_ICC_EOIR1_EL1 HSR_SYSREG(3,0,c12,c12,1) +#define HSR_SYSREG_ICC_HPPIR1_EL1 HSR_SYSREG(3,0,c12,c12,2)#define HSR_SYSREG_CONTEXTIDR_EL1 HSR_SYSREG(3,0,c13,c0,1)#define HSR_SYSREG_PMCR_EL0 HSR_SYSREG(3,3,c9,c12,0)
Signature · 7 lines
2.14.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 10/10 Enable Trapping of Group1 registers which is controlled by command line
In reply to [email protected]From: Manish Jaggi <[email protected]>
In order to be able to trap Group-1 GICv3 system registers, we need to set ICH_HCR_EL2.TALL1 before entering the guest. This is controlled by the command line parameter group1_trap.
--- xen/arch/arm/gic-v3.c | 11 ++++++++++- xen/include/asm-arm/gic.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-)
xen/arch/arm/gic-v3.c +10 -1
@@ -833,9 +833,12 @@ static void gicv3_cpu_disable(void)isb (); } +static unsigned int group1_trap =0 ; +integer_param ("group1_trap" , group1_trap); +static void gicv3_hyp_init (void ) { -uint32_t vtr; +uint32_t vtr, reg32; vtr =READ_SYSREG32 (ICH_VTR_EL2 ); gicv3_info.nr_lrs = (vtr &GICH_VTR_NRLRGS ) +1 ;
@@ -847,6 +850,12 @@ static void gicv3_hyp_init(void)WRITE_SYSREG32 (GICH_VMCR_EOI |GICH_VMCR_VENG1 ,ICH_VMCR_EL2 );WRITE_SYSREG32 (GICH_HCR_EN ,ICH_HCR_EL2 ); + + reg32 =READ_SYSREG32 (ICH_HCR_EL2 ); +if ( group1_trap ) + reg32 |=GICH_HCR_TALL1 ; + +WRITE_SYSREG32 (reg32,ICH_HCR_EL2 ); }/* Set up the per-CPU parts of the GIC for a secondary CPU */
xen/include/asm-arm/gic.h +1 -0
@@ -117,6 +117,7 @@#define GICH_HCR_VGRP0DIE (1 << 5)#define GICH_HCR_VGRP1EIE (1 << 6)#define GICH_HCR_VGRP1DIE (1 << 7) +#define GICH_HCR_TALL1 (1 << 12)#define GICH_MISR_EOI (1 << 0)#define GICH_MISR_U (1 << 1)
Signature · 7 lines
2.14.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 10/10] Enable Trapping of Group1 registers which is controlled by command line
Hi Manish,
Quoted 5 lines · On 16/01/18 15:43, [email protected] wrote:
From: Manish Jaggi <[email protected]>
In order to be able to trap Group-1 GICv3 system registers, we need to set ICH_HCR_EL2.TALL1 before entering the guest. This is controlled by the command line parameter
group1_trap.
I was expecting a patch to enable group1_trap by default on affected platform.
Quoted 12 lines
Singed-off-by Manish Jaggi <[email protected]>--- xen/arch/arm/gic-v3.c | 11 ++++++++++- xen/include/asm-arm/gic.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-)xen/arch/arm/gic-v3.c +0
-0
xen/arch/arm/gic-v3.c static void gicv3_cpu_disable(void) · line 837
Quoted 5 lines
xen/arch/arm/gic-v3.c +2
-0@@ -833,9 +833,12 @@ static void gicv3_cpu_disable(void)isb (); } +static unsigned int group1_trap =0 ; +integer_param ("group1_trap" , group1_trap);
New parameter should be describe in docs/misc/xen-command-line.markdown.
Also, you likely want to use a boolean_param here.
Quoted 9 lines
xen/arch/arm/gic-v3.c +2
-1+static void gicv3_hyp_init (void ) { -uint32_t vtr; +uint32_t vtr, reg32; vtr =READ_SYSREG32 (ICH_VTR_EL2 ); gicv3_info.nr_lrs = (vtr &GICH_VTR_NRLRGS ) +1 ;
xen/arch/arm/gic-v3.c static void gicv3_hyp_init(void) · line 854
Quoted 5 lines
xen/arch/arm/gic-v3.c +2
-0@@ -847,6 +850,12 @@ static void gicv3_hyp_init(void)WRITE_SYSREG32 (GICH_VMCR_EOI |GICH_VMCR_VENG1 ,ICH_VMCR_EL2 );WRITE_SYSREG32 (GICH_HCR_EN ,ICH_HCR_EL2 ); + + reg32 =READ_SYSREG32 (ICH_HCR_EL2 );
There are no point to read ICH_HCR_EL2. You know the value (see the line above).
So this code could simplified as:
reg32 = GICH_HCR_EN;
reg32 |= (group1_trap) ? GICH_HCR_TALL1 : 0;
WRITE_SYSREG32(reg32, ICH_HCR_EL2);
Quoted 12 lines
xen/arch/arm/gic-v3.c +4
-0+if ( group1_trap ) + reg32 |=GICH_HCR_TALL1 ; + +WRITE_SYSREG32 (reg32,ICH_HCR_EL2 ); }/* Set up the per-CPU parts of the GIC for a secondary CPU */ xen/include/asm-arm/gic.h +0
-0
xen/include/asm-arm/gic.h line 123
Quoted 7 lines
xen/include/asm-arm/gic.h +1
-0@@ -117,6 +117,7 @@#define GICH_HCR_VGRP0DIE (1 << 5)#define GICH_HCR_VGRP1EIE (1 << 6)#define GICH_HCR_VGRP1DIE (1 << 7) +#define GICH_HCR_TALL1 (1 << 12)#define GICH_MISR_EOI (1 << 0)#define GICH_MISR_U (1 << 1) >
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 10/10] Enable Trapping of Group1 registers which is controlled by command line
Quoted 10 lines · Julien Grall
Hi Manish,
Quoted 5 lines · On 16/01/18 15:43, [email protected] wrote:
From: Manish Jaggi <[email protected]>
In order to be able to trap Group-1 GICv3 system registers, we need to set ICH_HCR_EL2.TALL1 before entering the guest. This is controlled by the command line parameter
group1_trap.I was expecting a patch to enable
group1_trapby default on affected platform.
ok I will add another patch for that.
Quoted 1 line
[...]
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel