xen: gic-v3: Introduce CONFIG_GICV3_NR_LRS
PATCH v2 1/1 xen: gic-v3: Introduce CONFIG_GICV3_NR_LRS
One key requirement of Xen functional safety is to reduce the number of lines of code to be safety certified. Besides, a safety certified Xen requires a static hardware configuration to be defined. This static hardware configuration is described as per the test hardware/emulator hardware configuration against which Xen is verified.
Introduce GICV3_NR_LRS with the two aims in mind:
1. User should set the number of GICV3 list registers as per the test hardware so that the unwanted code can be removed using GCC's dead code elimination or preprocessor's config.
2. By doing #1, one can ensure that there is no untested code due to unsupported hardware platform and thus there is no safety impact due to untested code.
However if the user does not set GICV3_NR_LRS, then it is set to 0. Thus Xen will fallback to the default scenario (i.e. read the hardware register to determine the number of LRS).
1. In gicv3_save_lrs()/gicv3_restore_lrs(), use the number of list registers from GICV3_NR_LRS (if defined) instead of gicv3_info.nr_lrs. This ensures that if the hardware does not support more than 4 LRs (for example), the code accessing LR 4-15 is never reached. The compiler can eliminate the unsupported cases as the switch case uses a constant conditional.
2. RAZ/WI for the unsupported LRs.
---
Changelog:
v1 - 1. s/lrs/LRS
2. Implement RAZ/WI instead of panic
Few comments which were not addressed
1. Do "gicv3_info.nr_lrs to LRS" in gicv3_hyp_init() and keep the code unchanged in gicv3_save_lrs()/gicv3_restore_lrs() -- This prevents the compiler from doing dead code elimination as the switch condition cannot be evaluated at compile time.
I am not sure how to get around this issue.
xen/arch/arm/Kconfig | 9 +++++++++ xen/arch/arm/gic-v3.c | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
xen/arch/arm/Kconfig +9 -0
@@ -276,6 +276,15 @@ config PCI_PASSTHROUGH endmenu +config GICV3_NR_LRS + int "Number of GICv3 Link Registers supported" if EXPERT + depends on GICV3 + range 0 16 + default 0 + help + Controls the number of Link registers to be accessed. + Keep it set to 0 to use a value obtained from a hardware register. + menu "ARM errata workaround via the alternative framework" depends on HAS_ALTERNATIVE
xen/arch/arm/gic-v3.c +12 -2
@@ -51,6 +51,8 @@ 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) +#define LRS (CONFIG_GICV3_NR_LRS ?: \ + gicv3_info.nr_lrs)/* * Saves all 16(Max) LR registers. Though number of LRs implemented
@@ -59,7 +61,7 @@ static DEFINE_PER_CPU(void __iomem*, rbase);static inline void gicv3_save_lrs (struct vcpu *v) {/* Fall through for all the cases */ -switch ( gicv3_info.nr_lrs ) +switch (LRS ) {case 16 : v->arch.gic.v3.lr[15 ] =READ_SYSREG_LR (15 );
@@ -121,7 +123,7 @@ static inline void gicv3_save_lrs(struct vcpu *v)static inline void gicv3_restore_lrs (const struct vcpu *v) {/* Fall through for all the cases */ -switch ( gicv3_info.nr_lrs ) +switch (LRS ) {case 16 :WRITE_SYSREG_LR (v->arch.gic.v3.lr[15 ],15 );
@@ -178,6 +180,10 @@ static inline void gicv3_restore_lrs(const struct vcpu *v)static uint64_t gicv3_ich_read_lr (int lr) { +/* RAZ for unsupported LR */ +if ( lr >=LRS ) +return 0 ; +switch ( lr ) {case 0 :return READ_SYSREG_LR (0 );
@@ -203,6 +209,10 @@ static uint64_t gicv3_ich_read_lr(int lr)static void gicv3_ich_write_lr (int lr,uint64_t val) { +/* WI for unsupported LR */ +if ( lr >=LRS ) +return ; +switch ( lr ) {case 0 :
Signature · 1 line
2.25.1
Hi Ayan,
Quoted 56 lines · Ayan Kumar Halder
One key requirement of Xen functional safety is to reduce the number of lines of code to be safety certified. Besides, a safety certified Xen requires a static hardware configuration to be defined. This static hardware configuration is described as per the test hardware/emulator hardware configuration against which Xen is verified.
Introduce
GICV3_NR_LRSwith the two aims in mind:
1. User should set the number of GICV3 list registers as per the test hardware so that the unwanted code can be removed using GCC's dead code elimination or preprocessor's config.
2. By doing #1, one can ensure that there is no untested code due to unsupported hardware platform and thus there is no safety impact due to untested code.However if the user does not set
GICV3_NR_LRS, then it is set to 0. Thus Xen will fallback to the default scenario (i.e. read the hardware register to determine the number of LRS).1. In gicv3_save_lrs()/gicv3_restore_lrs(), use the number of list registers from
GICV3_NR_LRS(if defined) instead of gicv3_info.nr_lrs. This ensures that if the hardware does not support more than 4 LRs (for example), the code accessing LR 4-15 is never reached. The compiler can eliminate the unsupported cases as the switch case uses a constant conditional.2. RAZ/WI for the unsupported LRs.
Signed-off-by Ayan Kumar Halder <[email protected]>Signed-off-by Michal Orzel <[email protected]>---
Changelog:v1 - 1. s/lrs/LRS
2. Implement RAZ/WI instead of panicFew comments which were not addressed
1. Do "gicv3_info.nr_lrs to LRS" ingicv3_hyp_init()and keep the code unchanged in gicv3_save_lrs()/gicv3_restore_lrs() -- This prevents the compiler from doing dead code elimination as the switch condition cannot be evaluated at compile time.
I am not sure how to get around this issue.xen/arch/arm/Kconfig | 9 +++++++++
xen/arch/arm/gic-v3.c| 14 ++++++++++++--2 files changed, 21 insertions(+), 2 deletions(-)xen/arch/arm/Kconfig +0
-0@@ -276,6 +276,15 @@ config PCI_PASSTHROUGHendmenu
Quoted 4 lines
+config
GICV3_NR_LRS
+ int "Number of GICv3 Link Registers supported" if EXPERT
+ depends on GICV3
+ range 0 16
16 is the maximum supported since ICH_VTR_EL2.ListRegs is 4 bits [1], however how are we handling the case when GICV3_NR_LRS is greater than the supported number of LR registers?
Shall we check that in gicv3_hyp_init()?
Quoted 51 lines
+ default 0
+ helpxen/arch/arm/Kconfig +3
-0+ Controls the number of Link registers to be accessed. + Keep it set to 0 to use a value obtained from a hardware register. +menu "ARM errata workaround via the alternative framework" depends on
HAS_ALTERNATIVExen/arch/arm/gic-v3.c +8
-2@@ -51,6 +51,8 @@ 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) +#define LRS (CONFIG_GICV3_NR_LRS ?: \ + gicv3_info.nr_lrs)/* * Saves all 16(Max) LR registers. Though number of LRs implemented @@ -59,7 +61,7 @@ static DEFINE_PER_CPU(void __iomem*, rbase);static inline void gicv3_save_lrs (struct vcpu *v) {/* Fall through for all the cases */ -switch ( gicv3_info.nr_lrs ) +switch (LRS ) {case 16 : v->arch.gic.v3.lr[15 ] =READ_SYSREG_LR (15 );@@ -121,7 +123,7 @@ static inline void gicv3_save_lrs(struct vcpu *v)static inline void gicv3_restore_lrs (const struct vcpu *v) {/* Fall through for all the cases */ -switch ( gicv3_info.nr_lrs ) +switch (LRS ) {case 16 :WRITE_SYSREG_LR (v->arch.gic.v3.lr[15 ],15 );@@ -178,6 +180,10 @@ static inline void gicv3_restore_lrs(const struct vcpu *v)static uint64_t gicv3_ich_read_lr (int lr) { +/* RAZ for unsupported LR */ +if ( lr >=LRS ) +return 0 ; +switch ( lr ) {case 0 :return READ_SYSREG_LR (0 );
xen/arch/arm/gic-v3.c static uint64_t gicv3_ich_read_lr(int lr) · line 218
Quoted 10 lines
xen/arch/arm/gic-v3.c +4
-0@@ -203,6 +209,10 @@ static uint64_t gicv3_ich_read_lr(int lr)static void gicv3_ich_write_lr (int lr,uint64_t val) { +/* WI for unsupported LR */ +if ( lr >=LRS ) +return ; +switch ( lr ) {case 0 :
Now, since we are using CONFIG_GICV3_NR_LRS or gicv3_info.nr_lrs in gicv3_save_lrs/gicv3_restore_lrs, there are other part of the codebase using nr_lrs (gic_get_nr_lrs() is one of them), but all the callers of that function will use the HW nr_lrs and not the CONFIG_GICV3_NR_LRS, so I think some work needs to be done to align them or there will be mismatches at runtime with possible loss of information.
Cheers,
Luca
😊
Julien Grall reacted via Gmail
<https://www.google.com/gmail/about/?utm_source=gmail-in-product&utm_medium=et&utm_campaign=emojireactionemail#app>
{
"emoji": "😊",
"version": 1
}
Hi,
Quoted 16 lines · Luca Fancellu
xen/arch/arm/gic-v3.c static uint64_t gicv3_ich_read_lr(int lr) · line 218
Quoted 11 lines
xen/arch/arm/gic-v3.c +4
-0@@ -203,6 +209,10 @@ static uint64_t gicv3_ich_read_lr(int lr)static void gicv3_ich_write_lr (int lr,uint64_t val) { +/* WI for unsupported LR */ +if ( lr >=LRS ) +return ; +switch ( lr ) {case 0 :Now, since we are using
CONFIG_GICV3_NR_LRSor gicv3_info.nr_lrs in gicv3_save_lrs/gicv3_restore_lrs, there are other part of the codebase usingnr_lrs(gic_get_nr_lrs()is one of them), but all the callers of that function will use the HWnr_lrsand not theCONFIG_GICV3_NR_LRS, so I think some work needs to be done to align them or there will be mismatches at runtime with possible loss of information.
+1. We need a consistent view for the number of LRs. I could also see a use case where the integrator wants to support less LRs than what the HW supports (this doesn't seem to be prevented with this patch).
Note, during Xen boot, we may need to zero the LRs which are unused as they may potentially contain active interrupts.
Cheers,
Signature · 1 line
Julien Grall
Quoted 1 line · Julien Grall
Hi,
Hi Julien,
Quoted 19 lines · Luca Fancellu
Quoted 16 lines
Quoted 11 lines
xen/arch/arm/gic-v3.c +4
-0@@ -203,6 +209,10 @@ static uint64_t gicv3_ich_read_lr(int lr)static void gicv3_ich_write_lr (int lr,uint64_t val) { + /* WI for unsupported LR */ + if ( lr >= LRS ) + return; + switch ( lr ) {case 0:
Now, since we are using
CONFIG_GICV3_NR_LRSor gicv3_info.nr_lrs in gicv3_save_lrs/gicv3_restore_lrs, there are other part of the codebase usingnr_lrs(gic_get_nr_lrs()is one of them), but all the callers of that function will use the HWnr_lrsand not theCONFIG_GICV3_NR_LRS, so I think some work needs to be done to align them or there will be mismatches at runtime with possible loss of information.
Quoted 2 lines
+1. We need a consistent view for the number of LRs. I could also see
a use case where the integrator wants to support less LRs than what the HW supports (this doesn't seem to be prevented with this patch).
This scenario is ok. In this case, we should use the value provided by the GICV3_NR_LRS. I don't think this should be something we want to prevent. Or I might be missing something ?
The issue is with the opposite situation. If GICV3_NR_LRS is greater than what the hardware supports, we should print a warning. And let Xen use the value GICV3_NR_LRS.
Quoted 2 lines
Note, during Xen boot, we may need to zero the LRs which are unused as they may potentially contain active interrupts.
Ack.
- Ayan
Quoted 3 lines
Cheers,
Quoted 1 line · Luca Fancellu
Hi Ayan,
Hi Luca,
Quoted 65 lines
Quoted 57 lines · Ayan Kumar Halder
One key requirement of Xen functional safety is to reduce the number of lines of code to be safety certified. Besides, a safety certified Xen requires a static hardware configuration to be defined. This static hardware configuration is described as per the test hardware/emulator hardware configuration against which Xen is verified.
Introduce
GICV3_NR_LRSwith the two aims in mind:
1. User should set the number of GICV3 list registers as per the test hardware so that the unwanted code can be removed using GCC's dead code elimination or preprocessor's config.
2. By doing #1, one can ensure that there is no untested code due to unsupported hardware platform and thus there is no safety impact due to untested code.However if the user does not set
GICV3_NR_LRS, then it is set to 0. Thus Xen will fallback to the default scenario (i.e. read the hardware register to determine the number of LRS).1. In gicv3_save_lrs()/gicv3_restore_lrs(), use the number of list registers from
GICV3_NR_LRS(if defined) instead of gicv3_info.nr_lrs. This ensures that if the hardware does not support more than 4 LRs (for example), the code accessing LR 4-15 is never reached. The compiler can eliminate the unsupported cases as the switch case uses a constant conditional.2. RAZ/WI for the unsupported LRs.
Signed-off-by Ayan Kumar Halder <[email protected]>Signed-off-by Michal Orzel <[email protected]>---
Changelog:v1 - 1. s/lrs/LRS
2. Implement RAZ/WI instead of panicFew comments which were not addressed
1. Do "gicv3_info.nr_lrs to LRS" ingicv3_hyp_init()and keep the code unchanged in gicv3_save_lrs()/gicv3_restore_lrs() -- This prevents the compiler from doing dead code elimination as the switch condition cannot be evaluated at compile time.
I am not sure how to get around this issue.xen/arch/arm/Kconfig | 9 +++++++++
xen/arch/arm/gic-v3.c| 14 ++++++++++++--2 files changed, 21 insertions(+), 2 deletions(-)xen/arch/arm/Kconfig +0
-0@@ -276,6 +276,15 @@ config PCI_PASSTHROUGHendmenu
Quoted 4 lines
+config
GICV3_NR_LRS
+ int "Number of GICv3 Link Registers supported" if EXPERT
+ depends on GICV3
+ range 0 1616 is the maximum supported since ICH_VTR_EL2.ListRegs is 4 bits [1], however how are we handling the case when
GICV3_NR_LRSis greater than the supported number of LR registers?
Quoted 1 line
Shall we check that in
gicv3_hyp_init()?
My intention is that when user sets GICV3_NR_LRS , it overwrites the value obtained from reading the hardware. IOW, I was thinking of something like
gicv3_info.nr_lrs = GICV3_NR_LRS
But you have a valid point that what will happen if the user sets GICV3_NR_LRS to value greater than that supported by the hardware. I think we should print a warning in that case. This was suggested by Julien in v1, but I missed that.
Quoted 53 lines
Quoted 53 lines
+ default 0
+ helpxen/arch/arm/Kconfig +3
-0+ Controls the number of Link registers to be accessed. + Keep it set to 0 to use a value obtained from a hardware register. +menu "ARM errata workaround via the alternative framework" depends on
HAS_ALTERNATIVExen/arch/arm/gic-v3.c +8
-2@@ -51,6 +51,8 @@ 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) +#define LRS (CONFIG_GICV3_NR_LRS ?: \ + gicv3_info.nr_lrs)/* * Saves all 16(Max) LR registers. Though number of LRs implemented @@ -59,7 +61,7 @@ static DEFINE_PER_CPU(void __iomem*, rbase);static inline void gicv3_save_lrs (struct vcpu *v) {/* Fall through for all the cases */ -switch ( gicv3_info.nr_lrs ) +switch (LRS ) {case 16 : v->arch.gic.v3.lr[15 ] =READ_SYSREG_LR (15 );@@ -121,7 +123,7 @@ static inline void gicv3_save_lrs(struct vcpu *v)static inline void gicv3_restore_lrs (const struct vcpu *v) {/* Fall through for all the cases */ -switch ( gicv3_info.nr_lrs ) +switch (LRS ) {case 16 :WRITE_SYSREG_LR (v->arch.gic.v3.lr[15 ],15 );@@ -178,6 +180,10 @@ static inline void gicv3_restore_lrs(const struct vcpu *v)static uint64_t gicv3_ich_read_lr (int lr) { +/* RAZ for unsupported LR */ +if ( lr >=LRS ) +return 0 ; +switch ( lr ) {case 0 :return READ_SYSREG_LR (0 );@@ -203,6 +209,10 @@ static uint64_t gicv3_ich_read_lr(int lr)
Quoted 13 lines
xen/arch/arm/gic-v3.c static uint64_t gicv3_ich_read_lr(int lr) · line 218
Quoted 9 lines
xen/arch/arm/gic-v3.c +4
-0static void gicv3_ich_write_lr (int lr,uint64_t val) { +/* WI for unsupported LR */ +if ( lr >=LRS ) +return ; +switch ( lr ) {case 0 :Now, since we are using
CONFIG_GICV3_NR_LRSor gicv3_info.nr_lrs in gicv3_save_lrs/gicv3_restore_lrs, there are other part of the codebase usingnr_lrs(gic_get_nr_lrs()is one of them), but all the callers of that function will use the HWnr_lrsand not theCONFIG_GICV3_NR_LRS, so I think some work needs to be done to align them or there will be mismatches at runtime with possible loss of information.
I will fix that.
- Ayan
Hi Ayan,
Quoted 7 lines · Ayan Kumar Halder
One key requirement of Xen functional safety is to reduce the number of lines of code to be safety certified. Besides, a safety certified Xen requires a static hardware configuration to be defined. This static hardware configuration is described as per the test hardware/emulator hardware configuration against which Xen is verified.
Introduce
GICV3_NR_LRSwith the two aims in mind:
Out of interest, why is this limited to GICv3?
Quoted 3 lines
1. User should set the number of GICV3 list registers as per the test hardware so that the unwanted code can be removed using GCC's dead code elimination or preprocessor's config.
We discussed this offline, I am not fully convinced you can rely on dead code elimination to always remove the BUG() in gicv3_ich_read_lr(). If you want to rely on dead code eliminitation, then you will want to call a function which have a prototype defined but not implemented (similar to what we do for bitops with __bad_atomic_read()) which would fail a link time if the compiler didn't remove the code.
Quoted 41 lines
2. By doing #1, one can ensure that there is no untested code due to unsupported hardware platform and thus there is no safety impact due to untested code.
However if the user does not set
GICV3_NR_LRS, then it is set to 0. Thus Xen will fallback to the default scenario (i.e. read the hardware register to determine the number of LRS).1. In gicv3_save_lrs()/gicv3_restore_lrs(), use the number of list registers from
GICV3_NR_LRS(if defined) instead of gicv3_info.nr_lrs. This ensures that if the hardware does not support more than 4 LRs (for example), the code accessing LR 4-15 is never reached. The compiler can eliminate the unsupported cases as the switch case uses a constant conditional.2. RAZ/WI for the unsupported LRs.
Signed-off-by Ayan Kumar Halder <[email protected]>Signed-off-by Michal Orzel <[email protected]>---
Changelog:v1 - 1. s/lrs/LRS
2. Implement RAZ/WI instead of panicFew comments which were not addressed
1. Do "gicv3_info.nr_lrs to LRS" ingicv3_hyp_init()and keep the code unchanged in gicv3_save_lrs()/gicv3_restore_lrs() -- This prevents the compiler from doing dead code elimination as the switch condition cannot be evaluated at compile time.
I am not sure how to get around this issue.xen/arch/arm/Kconfig | 9 +++++++++ xen/arch/arm/gic-v3.c | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)xen/arch/arm/Kconfig +0
-0
xen/arch/arm/Kconfig config PCI_PASSTHROUGH · line 280
Quoted 5 lines
xen/arch/arm/Kconfig +2
-0@@ -276,6 +276,15 @@ config PCI_PASSTHROUGH endmenu +config GICV3_NR_LRS + int "Number of GICv3 Link Registers supported" if EXPERT
Supported by who? The hardware? Xen? Asking, because I could forsee an integrator wanted to limit the number of LRs to something smaller than what the HW supports (in a lot of cases, 2 LRs is sufficient).
xen/arch/arm/Kconfig config PCI_PASSTHROUGH · line 286
Quoted 6 lines
xen/arch/arm/Kconfig +6
-0+ depends on GICV3 + range 0 16 + default 0 + help + Controls the number of Link registers to be accessed. + Keep it set to 0 to use a value obtained from a hardware register.
I still strongly think that if GICV3_NR_LRS is set, then it needs to be checked against the value read by the hardware
Quoted 9 lines
xen/arch/arm/Kconfig +1
-0+ menu "ARM errata workaround via the alternative framework" depends on HAS_ALTERNATIVExen/arch/arm/gic-v3.c +0
-0
xen/arch/arm/gic-v3.c static DEFINE_PER_CPU(void __iomem*, rbase); · line 55
Quoted 5 lines
xen/arch/arm/gic-v3.c +2
-0@@ -51,6 +51,8 @@ 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) +#define LRS (CONFIG_GICV3_NR_LRS ?: \ + gicv3_info.nr_lrs)
IMHO, LRS is a little bit vague. What about MAX_LRS? Or maybe NR_LRS?
Quoted 33 lines
xen/arch/arm/gic-v3.c +6
-2/* * Saves all 16(Max) LR registers. Though number of LRs implemented @@ -59,7 +61,7 @@ static DEFINE_PER_CPU(void __iomem*, rbase);static inline void gicv3_save_lrs (struct vcpu *v) {/* Fall through for all the cases */ -switch ( gicv3_info.nr_lrs ) +switch (LRS ) {case 16 : v->arch.gic.v3.lr[15 ] =READ_SYSREG_LR (15 );@@ -121,7 +123,7 @@ static inline void gicv3_save_lrs(struct vcpu *v)static inline void gicv3_restore_lrs (const struct vcpu *v) {/* Fall through for all the cases */ -switch ( gicv3_info.nr_lrs ) +switch (LRS ) {case 16 :WRITE_SYSREG_LR (v->arch.gic.v3.lr[15 ],15 );@@ -178,6 +180,10 @@ static inline void gicv3_restore_lrs(const struct vcpu *v)static uint64_t gicv3_ich_read_lr (int lr) { +/* RAZ for unsupported LR */ +if ( lr >=LRS ) +return 0 ; +switch ( lr ) {case 0 :return READ_SYSREG_LR (0 );
xen/arch/arm/gic-v3.c static uint64_t gicv3_ich_read_lr(int lr) · line 212
Quoted 4 lines
xen/arch/arm/gic-v3.c +1
-0@@ -203,6 +209,10 @@ static uint64_t gicv3_ich_read_lr(int lr)static void gicv3_ich_write_lr (int lr,uint64_t val) { +/* WI for unsupported LR */
AFAIU, this path is really not meant to happen. So I don't think we want to silently ignore the write as it would mean an interrupt is missing. I think in debug build, we probably want to use ASSERT_UNREACHABLE(). If we want something for production as well, then we could instead use WARN().
Cheers,
Signature · 1 line
Julien Grall
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
Quoted 11 lines · Ayan Kumar Halder
Quoted 7 lines
One key requirement of Xen functional safety is to reduce the number of lines of code to be safety certified. Besides, a safety certified Xen requires a static hardware configuration to be defined. This static hardware configuration is described as per the test hardware/emulator hardware configuration against which Xen is verified.
Introduce
GICV3_NR_LRSwith the two aims in mind:Out of interest, why is this limited to GICv3?
This was just my starting point of investigation. My intention is to have as much as a static defined hardware configuration, so that the code that cannot be tested on the hardware can be eliminated by one of the many ways (DCE, Kconfig or actual code removal).
The advantage of having a static defined configuration is that the system integrator will have the full control on how to configure Xen for a specific hardware platform. And we try to reduce as much as possible any code that cannot be used due to hardware limitations.
Quoted 6 lines
Quoted 4 lines
1. User should set the number of GICV3 list registers as per the test hardware so that the unwanted code can be removed using GCC's dead code elimination or preprocessor's config.
We discussed this offline, I am not fully convinced you can rely on dead code elimination to always remove the
BUG()ingicv3_ich_read_lr(). If you want to rely on dead code eliminitation, then you will want to call a function which have a prototype defined but not implemented (similar to what we do for bitops with__bad_atomic_read()) which would fail a link time if the compiler didn't remove the code.
If you are ok, we can break this into 2 patches
1. Introduce GICV3_NR_LRS and make sure it is used consistently in the code. IOW, it should address the comments that Luca and you provided.
2. Implement a way for compiler to do DCE based on GICV3_NR_LRS.
Quoted 37 lines
Quoted 37 lines
2. By doing #1, one can ensure that there is no untested code due to unsupported hardware platform and thus there is no safety impact due to untested code.
However if the user does not set
GICV3_NR_LRS, then it is set to 0. Thus Xen will fallback to the default scenario (i.e. read the hardware register to determine the number of LRS).1. In gicv3_save_lrs()/gicv3_restore_lrs(), use the number of list registers from
GICV3_NR_LRS(if defined) instead of gicv3_info.nr_lrs. This ensures that if the hardware does not support more than 4 LRs (for example), the code accessing LR 4-15 is never reached. The compiler can eliminate the unsupported cases as the switch case uses a constant conditional.2. RAZ/WI for the unsupported LRs.
Signed-off-by Ayan Kumar Halder <[email protected]>Signed-off-by Michal Orzel <[email protected]>---
Changelog:v1 - 1. s/lrs/LRS
2. Implement RAZ/WI instead of panicFew comments which were not addressed
1. Do "gicv3_info.nr_lrs to LRS" ingicv3_hyp_init()and keep the code unchanged in gicv3_save_lrs()/gicv3_restore_lrs() -- This prevents the compiler from doing dead code elimination as the switch condition cannot be evaluated at compile time.
I am not sure how to get around this issue.xen/arch/arm/Kconfig | 9 +++++++++
xen/arch/arm/gic-v3.c| 14 ++++++++++++--2 files changed, 21 insertions(+), 2 deletions(-)
Quoted 10 lines
Quoted 8 lines
xen/arch/arm/Kconfig +0
-0@@ -276,6 +276,15 @@ config PCI_PASSTHROUGHendmenu
+configGICV3_NR_LRS
+ int "Number of GICv3 Link Registers supported" if EXPERTSupported by who? The hardware? Xen? Asking, because I could forsee an integrator wanted to limit the number of LRs to something smaller than what the HW supports (in a lot of cases, 2 LRs is sufficient).
Ack
... "Number of GICv3 Link Registers used" if EXPERT
So it implies a decision to be taken by the system integrator. Does it sound ok ?
Quoted 10 lines
Quoted 8 lines
+ depends on GICV3
+ range 0 16
+ default 0
+ help
+ Controls the number of Link registers to be accessed. + Keep it set to 0 to use a value obtained from a hardware register.I still strongly think that if
GICV3_NR_LRSis set, then it needs to be checked against the value read by the hardware
Ack.
Quoted 16 lines
Quoted 9 lines
+
menu "ARM errata workaround via the alternative framework" depends onHAS_ALTERNATIVE
diff --gita/xen/arch/arm/gic-v3.cb/xen/arch/arm/gic-v3.cindexbc07f97c16..eaae95eb4d100644xen/arch/arm/gic-v3.c static DEFINE_PER_CPU(void __iomem*, rbase); · line 55
Quoted 5 lines
xen/arch/arm/gic-v3.c +2
-0@@ -51,6 +51,8 @@ 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) +#define LRS (CONFIG_GICV3_NR_LRS ?: \ + gicv3_info.nr_lrs)IMHO, LRS is a little bit vague. What about
MAX_LRS? Or maybeNR_LRS?
NR_LRS .
Quoted 30 lines
Quoted 30 lines
xen/arch/arm/gic-v3.c +1
-1/** Saves all 16(Max) LR registers. Though number of LRs implemented @@ -59,7 +61,7 @@ static DEFINE_PER_CPU(void __iomem*, rbase); static inline void gicv3_save_lrs(struct vcpu *v) { /* Fall through for all the cases */ - switch ( gicv3_info.nr_lrs ) + switch ( LRS ) {case 16:
v->arch.gic.v3.lr[15] =READ_SYSREG_LR(15);xen/arch/arm/gic-v3.c +1
-1@@ -121,7 +123,7 @@ static inline void gicv3_save_lrs(struct vcpu *v) static inline void gicv3_restore_lrs(const struct vcpu *v) { /* Fall through for all the cases */ - switch ( gicv3_info.nr_lrs ) + switch ( LRS ) {case 16:
WRITE_SYSREG_LR(v->arch.gic.v3.lr[15], 15);xen/arch/arm/gic-v3.c +4
-0@@ -178,6 +180,10 @@ static inline void gicv3_restore_lrs(const struct vcpu *v) static uint64_t gicv3_ich_read_lr(int lr) { + /* RAZ for unsupported LR */ + if ( lr >= LRS ) + return 0; + switch ( lr )
Quoted 8 lines
xen/arch/arm/gic-v3.c static uint64_t gicv3_ich_read_lr(int lr) · line 211
Quoted 6 lines
xen/arch/arm/gic-v3.c +1
-0{ case 0: return READ_SYSREG_LR(0);@@ -203,6 +209,10 @@ static uint64_t gicv3_ich_read_lr(int lr) static void gicv3_ich_write_lr(int lr, uint64_t val) { + /* WI for unsupported LR */AFAIU, this path is really not meant to happen. So I don't think we want to silently ignore the write as it would mean an interrupt is missing. I think in debug build, we probably want to use
ASSERT_UNREACHABLE(). If we want something for production as well, then we could instead useWARN().
Ack. I will use WARN().
- Ayan
Quoted 3 lines
Cheers,
Hi Ayan,
Quoted 12 lines · Ayan Kumar
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
Quoted 8 lines · Ayan Kumar Halder
Quoted 6 lines
One key requirement of Xen functional safety is to reduce the number of lines of code to be safety certified. Besides, a safety certified Xen requires a static hardware configuration to be defined. This static hardware configuration is described as per the test hardware/emulator hardware configuration against which Xen is verified.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Introduce
GICV3_NR_LRSwith the two aims in mind:Out of interest, why is this limited to GICv3?
This was just my starting point of investigation. My intention is to have as much as a static defined hardware configuration, so that the code that cannot be tested on the hardware can be eliminated by one of the many ways (DCE,
Kconfigor actual code removal).The advantage of having a static defined configuration is that the system integrator will have the full control on how to configure Xen for a specific hardware platform. And we try to reduce as much as possible any code that cannot be used due to hardware limitations.
Thanks for the answer. I was asking because I wonder whether the name of config should be more generic so it can be used for GICV2. But I guess we can rename it afterwards.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
1. User should set the number of GICV3 list registers as per the test hardware so that the unwanted code can be removed using GCC's dead code elimination or preprocessor's config.
Quoted 7 lines
Quoted 1 line
We discussed this offline, I am not fully convinced you can rely on dead code elimination to always remove the
BUG()ingicv3_ich_read_lr(). If you want to rely on dead code eliminitation, then you will want to call a function which have a prototype defined but not implemented (similar to what we do for bitops with__bad_atomic_read()) which would fail a link time if the compiler didn't remove the code.If you are ok, we can break this into 2 patches
1. Introduce
GICV3_NR_LRSand make sure it is used consistently in the code. IOW, it should address the comments that Luca and you provided.2. Implement a way for compiler to do DCE based on
GICV3_NR_LRS.
Yes please, so we can merge patch #1 earlier.
Quoted 49 lines
Quoted 38 lines
Quoted 38 lines
2. By doing #1, one can ensure that there is no untested code due to unsupported hardware platform and thus there is no safety impact due to untested code.
However if the user does not set
GICV3_NR_LRS, then it is set to 0. Thus Xen will fallback to the default scenario (i.e. read the hardware register to determine the number of LRS).1. In gicv3_save_lrs()/gicv3_restore_lrs(), use the number of list registers from
GICV3_NR_LRS(if defined) instead of gicv3_info.nr_lrs. This ensures that if the hardware does not support more than 4 LRs (for example), the code accessing LR 4-15 is never reached. The compiler can eliminate the unsupported cases as the switch case uses a constant conditional.2. RAZ/WI for the unsupported LRs.
Signed-off-by Ayan Kumar Halder <[email protected]>Signed-off-by Michal Orzel <[email protected]>---
Changelog:v1 - 1. s/lrs/LRS
2. Implement RAZ/WI instead of panicFew comments which were not addressed
1. Do "gicv3_info.nr_lrs to LRS" ingicv3_hyp_init()and keep the code unchanged in gicv3_save_lrs()/gicv3_restore_lrs() -- This prevents the compiler from doing dead code elimination as the switch condition cannot be evaluated at compile time.
I am not sure how to get around this issue.xen/arch/arm/Kconfig | 9 +++++++++
xen/arch/arm/gic-v3.c| 14 ++++++++++++--2 files changed, 21 insertions(+), 2 deletions(-)Quoted 10 lines
Quoted 8 lines
xen/arch/arm/Kconfig +0
-0@@ -276,6 +276,15 @@ config PCI_PASSTHROUGHendmenu
+configGICV3_NR_LRS
+ int "Number of GICv3 Link Registers supported" if EXPERTSupported by who? The hardware? Xen? Asking, because I could forsee an integrator wanted to limit the number of LRs to something smaller than what the HW supports (in a lot of cases, 2 LRs is sufficient).
Quoted 5 lines
Ack
... "Number of GICv3 Link Registers used" if EXPERT
So it implies a decision to be taken by the system integrator. Does it sound ok ?
Either "used" or "allowed" would be fine.
Cheers,
Signature · 1 line
Julien Grall