arm: add GICv2 MMIO tests
Subsystems (3)
v2 cover arm: add GICv2 MMIO tests
I found this in one my branches: this is an updated version of what I sent end of 2016 [1]. I tried to address all comments that Drew and Eric had at the time.
Please have a look whether this makes sense.
Changelog v1..v2:
- made many functions void
- use symbolic name for first SPI being number 32
- add test runs with one and three vCPUs
- use gic_version() directly
- factor out test_byte_access()
- drop redundant "filling priorities" test
- dropped GICv3 test
[1] https://lists.cs.columbia.edu/pipermail/kvmarm/2016-November/022352.html
Original cover letter:
======================
The GIC spec mandates certain constraints on how to acccess the MMIO mapped registers, both in terms of which registers are available and also in terms of which bits within a register should be masked, for instance. Since we went through some lengths in the KVM emulation to implement this, it's about time to give this actually a test beyond what the kernel as a GIC user actually implements - for instance we ignore priorities in Linux.
This series tries to attack some constraints, on a low-hanging-fruit base. It focusses on some generic registers and the PRIORITY and TARGETS registers of GICv2. GICv3 is not covered yet.
This actually revealed genuine bugs in the KVM emulation in the past. KVM passes these tests now, but QEMU fails some UP and 3-way-SMP tests.
Cheers,
Andre.
Andre Przywara (4):
mark exit() and abort() as non-returning functions arm/arm64: GIC: basic GICv2 MMIO tests arm/arm64: GICv2: add GICD_IPRIORITYR testing arm/arm64: GICv2: add GICD_ITARGETSR testing
arm/gic.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 18 +++++ lib/arm/asm/gic.h | 5 ++ lib/arm/io.c | 1 + lib/libcflat.h | 7 +- lib/powerpc/io.c | 1 + lib/x86/io.c | 1 + 7 files changed, 243 insertions(+), 3 deletions(-)
Signature · 1 line
2.14.4
PATCH v2 1/4 mark exit() and abort() as non-returning functions
exit() and abort() are functions that never return, and (at least) GCC has an attribute to flag those functions accordingly. This allows the compiler to do further optimizations and to omit various warnings about uninitialized variables, for instance.
Since the actual "play-dead" function is in (inline) assembly, the compiler does not recognize its fatal nature, so help it with the __builtin_unreachable() hint.
Flag the prototypes of our fatal functions accordingly.
--- lib/arm/io.c | 1 + lib/libcflat.h | 7 ++++--- lib/powerpc/io.c | 1 + lib/x86/io.c | 1 + 4 files changed, 7 insertions(+), 3 deletions(-)
lib/arm/io.c +1 -0
@@ -83,4 +83,5 @@ void exit(int code) {chr_testdev_exit (code);halt (code); +__builtin_unreachable (); }
lib/libcflat.h +4 -3
@@ -84,8 +84,8 @@ typedef u64 phys_addr_t;extern void puts (const char *s);extern int __getchar (void );extern int getchar (void ); -extern void exit (int code); -extern void abort (void ); +extern void exit (int code) __attribute__((noreturn)); +extern void abort (void ) __attribute__((noreturn));extern long atol (const char *ptr);extern char *getenv (const char *name);
@@ -107,7 +107,8 @@ extern void report(const char *msg_fmt, bool pass, ...)extern void report_xfail (const char *msg_fmt,bool xfail,bool pass, ...) __attribute__((format (printf,1 ,4 )));extern void report_abort (const char *msg_fmt, ...) - __attribute__((format (printf,1 ,2 ))); + __attribute__((format (printf,1 ,2 ))) + __attribute__((noreturn));extern void report_skip (const char *msg_fmt, ...) __attribute__((format (printf,1 ,2 )));extern void report_info (const char *msg_fmt, ...)
lib/powerpc/io.c +1 -0
@@ -35,4 +35,5 @@ void exit(int code)printf ("\nEXIT: STATUS=%d\n" , ((code) <<1 ) |1 );rtas_power_off ();halt (code); +__builtin_unreachable (); }
lib/x86/io.c +1 -0
@@ -82,6 +82,7 @@ void exit(int code)#else asmvolatile ("out %0, %1" : :"a" (code),"d" ((short )0xf4 ));#endif +__builtin_unreachable (); }void __iomem *ioremap (phys_addr_t phys_addr,size_t size)
Signature · 1 line
2.14.4
Re: [Qemu-devel] [kvm-unit-tests PATCH v2 1/4] mark exit() and abort() as non-returning functions
Quoted 9 lines · Andre Przywara
exit()andabort()are functions that never return, and (at least) GCC has an attribute to flag those functions accordingly. This allows the compiler to do further optimizations and to omit various warnings about uninitialized variables, for instance.
Since the actual "play-dead" function is in (inline) assembly, the compiler does not recognize its fatal nature, so help it with the__builtin_unreachable()hint.
Flag the prototypes of our fatal functions accordingly.
Quoted 8 lines
Signed-off-by Andre Przywara <[email protected]>--- lib/arm/io.c | 1 + lib/libcflat.h | 7 ++++--- lib/powerpc/io.c | 1 + lib/x86/io.c | 1 + 4 files changed, 7 insertions(+), 3 deletions(-)
PATCH v2 2/4 arm/arm64: GIC: basic GICv2 MMIO tests
In reply to Andre PrzywaraThis adds an MMIO subtest to the GIC test.
It accesses some generic GICv2 registers and does some sanity tests, like checking for some of them being read-only.
--- arm/gic.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 18 +++++++++++ lib/arm/asm/gic.h | 4 +++ 3 files changed, 113 insertions(+)
arm/gic.c +91 -0
@@ -3,6 +3,7 @@* * GICv2 * + test sending/receiving IPIs +* + MMIO access tests * GICv3 * + test sending/receiving IPIs *
@@ -303,6 +304,92 @@ static void run_active_clear_test(void)report_prefix_pop (); } +static bool test_ro_pattern_32 (void *address,u32 pattern,u32 orig) +{ +u32 reg; + +writel (pattern, address); + reg =readl (address); + +if (reg != orig) +writel (orig, address); + +return reg == orig; +} + +static bool test_readonly_32 (void *address,bool razwi) +{ +u32 orig, pattern; + + orig =readl (address); +if (razwi && orig) +return false; + + pattern =0xffffffff ; +if (orig != pattern) { +if (!test_ro_pattern_32 (address, pattern, orig)) +return false; + } + + pattern =0xa5a55a5a ; +if (orig != pattern) { +if (!test_ro_pattern_32 (address, pattern, orig)) +return false; + } + + pattern =0 ; +if (orig != pattern) { +if (!test_ro_pattern_32 (address, pattern, orig)) +return false; + } + +return true; +} + +static void test_typer_v2 (uint32_t reg) +{ +int nr_gic_cpus = ((reg >>5 ) &0x7 ) +1 ; + +report ("all %d CPUs have interrupts" , nr_cpus == nr_gic_cpus, + nr_gic_cpus); +} + +static void gic_test_mmio (void ) +{ +u32 reg; +int nr_irqs; +void *gic_dist_base, *idreg; + +switch (gic_version ()) { +case 0x2 : + gic_dist_base =gicv2_dist_base (); + idreg = gic_dist_base +GICD_ICPIDR2 ; +break ; +case 0x3 : +report_abort ("GICv3 MMIO tests NYI" ); +default : +report_abort ("GIC version %d not supported" ,gic_version ()); + } + + reg =readl (gic_dist_base +GICD_TYPER ); + nr_irqs =GICD_TYPER_IRQS (reg); +report_info ("number of implemented SPIs: %d" , nr_irqs -GIC_FIRST_SPI ); + +test_typer_v2 (reg); + +report_info ("IIDR: 0x%08x" ,readl (gic_dist_base +GICD_IIDR )); + +report ("GICD_TYPER is read-only" , +test_readonly_32 (gic_dist_base +GICD_TYPER , false)); +report ("GICD_IIDR is read-only" , +test_readonly_32 (gic_dist_base +GICD_IIDR , false)); + + reg =readl (idreg); +report ("ICPIDR2 is read-only (0x%08x)" , +test_readonly_32 (idreg, false), + reg); +} +int main (int argc,char **argv) {if (!gic_init ()) {
@@ -330,6 +417,10 @@ int main(int argc, char **argv)on_cpus (ipi_test,NULL ); }else if (strcmp (argv[1 ],"active" ) ==0 ) {run_active_clear_test (); + }else if (strcmp (argv[1 ],"mmio" ) ==0 ) { +report_prefix_push (argv[1 ]); +gic_test_mmio (); +report_prefix_pop (); }else {report_abort ("Unknown subtest '%s'" , argv[1 ]); }
arm/unittests.cfg +18 -0
@@ -86,6 +86,24 @@ smp = $((($MAX_SMP < 8)?$MAX_SMP:8)) extra_params = -machine gic-version=2 -append 'ipi' groups = gic +[gicv2-mmio] +file = gic.flat +smp = $((($MAX_SMP < 8)?$MAX_SMP:8)) +extra_params = -machine gic-version=2 -append 'mmio' +groups = gic + +[gicv2-mmio-up] +file = gic.flat +smp = 1 +extra_params = -machine gic-version=2 -append 'mmio' +groups = gic + +[gicv2-mmio-3p] +file = gic.flat +smp = $((($MAX_SMP < 3)?$MAX_SMP:3)) +extra_params = -machine gic-version=2 -append 'mmio' +groups = gic + [gicv3-ipi] file = gic.flat smp = $MAX_SMP
lib/arm/asm/gic.h +4 -0
@@ -6,10 +6,13 @@#ifndef _ASMARM_GIC_H_#define _ASMARM_GIC_H_ +#define GIC_NR_PRIVATE_IRQS 32 +#define GIC_FIRST_SPI GIC_NR_PRIVATE_IRQS/* Distributor registers */ #define GICD_CTLR 0x0000#define GICD_TYPER 0x0004 +#define GICD_IIDR 0x0008#define GICD_IGROUPR 0x0080#define GICD_ISENABLER 0x0100#define GICD_ISPENDR 0x0200
@@ -18,6 +21,7 @@#define GICD_ICACTIVER 0x0380#define GICD_IPRIORITYR 0x0400#define GICD_SGIR 0x0f00 +#define GICD_ICPIDR2 0x0fe8#define GICD_TYPER_IRQS (typer) ((((typer) & 0x1f) + 1) * 32)#define GICD_INT_EN_SET_SGI 0x0000ffff
Signature · 1 line
2.14.4
Re: [kvm-unit-tests PATCH v2 2/4] arm/arm64: GIC: basic GICv2 MMIO tests
Quoted 140 lines · Andre Przywara
This adds an MMIO subtest to the GIC test.
It accesses some generic GICv2 registers and does some sanity tests, like checking for some of them being read-only.Signed-off-by Andre Przywara <[email protected]>--- arm/gic.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 18 +++++++++++ lib/arm/asm/gic.h | 4 +++ 3 files changed, 113 insertions(+)arm/gic.c +91
-0@@ -3,6 +3,7 @@* * GICv2 * + test sending/receiving IPIs +* + MMIO access tests * GICv3 * + test sending/receiving IPIs * @@ -303,6 +304,92 @@ static void run_active_clear_test(void)report_prefix_pop (); } +static bool test_ro_pattern_32 (void *address,u32 pattern,u32 orig) +{ +u32 reg; + +writel (pattern, address); + reg =readl (address); + +if (reg != orig) +writel (orig, address); + +return reg == orig; +} + +static bool test_readonly_32 (void *address,bool razwi) +{ +u32 orig, pattern; + + orig =readl (address); +if (razwi && orig) +return false; + + pattern =0xffffffff ; +if (orig != pattern) { +if (!test_ro_pattern_32 (address, pattern, orig)) +return false; + } + + pattern =0xa5a55a5a ; +if (orig != pattern) { +if (!test_ro_pattern_32 (address, pattern, orig)) +return false; + } + + pattern =0 ; +if (orig != pattern) { +if (!test_ro_pattern_32 (address, pattern, orig)) +return false; + } + +return true; +} + +static void test_typer_v2 (uint32_t reg) +{ +int nr_gic_cpus = ((reg >>5 ) &0x7 ) +1 ; + +report ("all %d CPUs have interrupts" , nr_cpus == nr_gic_cpus, + nr_gic_cpus); +} + +static void gic_test_mmio (void ) +{ +u32 reg; +int nr_irqs; +void *gic_dist_base, *idreg; + +switch (gic_version ()) { +case 0x2 : + gic_dist_base =gicv2_dist_base (); + idreg = gic_dist_base +GICD_ICPIDR2 ; +break ; +case 0x3 : +report_abort ("GICv3 MMIO tests NYI" ); +default : +report_abort ("GIC version %d not supported" ,gic_version ()); + } + + reg =readl (gic_dist_base +GICD_TYPER ); + nr_irqs =GICD_TYPER_IRQS (reg); +report_info ("number of implemented SPIs: %d" , nr_irqs -GIC_FIRST_SPI ); + +test_typer_v2 (reg); + +report_info ("IIDR: 0x%08x" ,readl (gic_dist_base +GICD_IIDR )); + +report ("GICD_TYPER is read-only" , +test_readonly_32 (gic_dist_base +GICD_TYPER , false)); +report ("GICD_IIDR is read-only" , +test_readonly_32 (gic_dist_base +GICD_IIDR , false)); + + reg =readl (idreg); +report ("ICPIDR2 is read-only (0x%08x)" , +test_readonly_32 (idreg, false), + reg); +} +int main (int argc,char **argv) {if (!gic_init ()) {@@ -330,6 +417,10 @@ int main(int argc, char **argv)on_cpus (ipi_test,NULL ); }else if (strcmp (argv[1 ],"active" ) ==0 ) {run_active_clear_test (); + }else if (strcmp (argv[1 ],"mmio" ) ==0 ) { +report_prefix_push (argv[1 ]); +gic_test_mmio (); +report_prefix_pop (); }else {report_abort ("Unknown subtest '%s'" , argv[1 ]); }arm/unittests.cfg +5
-0@@ -86,6 +86,24 @@ smp = $((($MAX_SMP < 8)?$MAX_SMP:8)) extra_params = -machine gic-version=2 -append 'ipi' groups = gic +[gicv2-mmio] +file = gic.flat +smp = $((($MAX_SMP < 8)?$MAX_SMP:8)) +extra_params = -machine gic-version=2 -append 'mmio' +groups = gic
arm/unittests.cfg smp = $((($MAX_SMP < 8)?$MAX_SMP:8)) · line 103
Quoted 10 lines
arm/unittests.cfg +10
-0+ +[gicv2-mmio-up] +file = gic.flat +smp = 1 +extra_params = -machine gic-version=2 -append 'mmio' +groups = gic + +[gicv2-mmio-3p] +file = gic.flat +smp = $((($MAX_SMP < 3)?$MAX_SMP:3))
If MAX_SMP is less than 3, then we'll still run the test with whatever it is, possibly 1, which probably isn't want the test intends. Maybe we should put a
if (nr_cpus < 3) {
report_skip("host doesn't support guests with at least 3 vcpus");
return report_summary();}
in the test case as well?
That said, I'm not overly worried about that ever happening, so we could just fail the test less gracefully in that case by setting 'smp = 3' here in the unittests.cfg file instead. And, that said, I won't worry about this enough for a respin at all, so
Thanks,
drew
Quoted 35 lines
arm/unittests.cfg +3
-0+extra_params = -machine gic-version=2 -append 'mmio' +groups = gic + [gicv3-ipi] file = gic.flat smp = $MAX_SMPlib/arm/asm/gic.h +4
-0@@ -6,10 +6,13 @@#ifndef _ASMARM_GIC_H_#define _ASMARM_GIC_H_ +#define GIC_NR_PRIVATE_IRQS 32 +#define GIC_FIRST_SPI GIC_NR_PRIVATE_IRQS/* Distributor registers */ #define GICD_CTLR 0x0000#define GICD_TYPER 0x0004 +#define GICD_IIDR 0x0008#define GICD_IGROUPR 0x0080#define GICD_ISENABLER 0x0100#define GICD_ISPENDR 0x0200@@ -18,6 +21,7 @@#define GICD_ICACTIVER 0x0380#define GICD_IPRIORITYR 0x0400#define GICD_SGIR 0x0f00 +#define GICD_ICPIDR2 0x0fe8#define GICD_TYPER_IRQS (typer) ((((typer) & 0x1f) + 1) * 32)#define GICD_INT_EN_SET_SGI 0x0000ffffSignature · 1 line
2.14.4
PATCH v2 3/4 arm/arm64: GICv2: add GICD_IPRIORITYR testing
In reply to Andre PrzywaraSome tests for the IPRIORITY registers. The significant number of bits is IMPLEMENTATION DEFINED, but should be the same for every IRQ. Also these registers must be byte-accessible.
Check that accesses beyond the implemented IRQ limit are actually read-as-zero/write-ignore.
--- arm/gic.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)
arm/gic.c +79 -0
@@ -354,6 +354,83 @@ static void test_typer_v2(uint32_t reg) nr_gic_cpus); } +#define BYTE (reg32, byte) (((reg32) >> ((byte) * 8)) & 0xff) +#define REPLACE_BYTE (reg32, byte, new) (((reg32) & ~(0xff << ((byte) * 8))) |\ + ((new) << ((byte) * 8))) + +/* +* Some registers are byte accessible, do a byte-wide read and write of known +* content to check for this. +* Apply a @mask to cater for special register properties. +* @pattern contains the value already in the register. +*/ +static void test_byte_access (void *base_addr,u32 pattern,u32 mask) +{ +u32 reg =readb (base_addr +1 ); + +report ("byte reads successful (0x%08x => 0x%02x)" , + reg == (BYTE (pattern,1 ) & (mask >>8 )), + pattern & mask, reg); + + pattern =REPLACE_BYTE (pattern,2 ,0x1f ); +writeb (BYTE (pattern,2 ), base_addr +2 ); + reg =readl (base_addr); +report ("byte writes successful (0x%02x => 0x%08x)" , + reg == (pattern & mask),BYTE (pattern,2 ), reg); +} + +static void test_priorities (int nr_irqs,void *priptr) +{ +u32 orig_prio, reg, pri_bits; +u32 pri_mask, pattern; +void *first_spi = priptr +GIC_FIRST_SPI ; + + orig_prio =readl (first_spi); +report_prefix_push ("IPRIORITYR" ); + +/* +* Determine implemented number of priority bits by writing all 1's +* and checking the number of cleared bits in the value read back. +*/ +writel (0xffffffff , first_spi); + pri_mask =readl (first_spi); + + reg = ~pri_mask; +report ("consistent priority masking (0x%08x)" , + (((reg >>16 ) == (reg &0xffff )) && + ((reg &0xff ) == ((reg >>8 ) &0xff ))), pri_mask); + + reg = reg &0xff ; +for (pri_bits =8 ; reg &1 ; reg >>=1 , pri_bits--) + ; +report ("implements at least 4 priority bits (%d)" , + pri_bits >=4 , pri_bits); + + pattern =0 ; +writel (pattern, first_spi); +report ("clearing priorities" ,readl (first_spi) == pattern); + +/* setting all priorities to their max valus was tested above */ + +report ("accesses beyond limit RAZ/WI" , +test_readonly_32 (priptr + nr_irqs, true)); + +writel (pattern, priptr + nr_irqs -4 ); +report ("accessing last SPIs" , +readl (priptr + nr_irqs -4 ) == (pattern & pri_mask)); + + pattern =0xff7fbf3f ; +writel (pattern, first_spi); +report ("priorities are preserved" , +readl (first_spi) == (pattern & pri_mask)); + +/* The PRIORITY registers are byte accessible. */ +test_byte_access (first_spi, pattern, pri_mask); + +report_prefix_pop (); +writel (orig_prio, first_spi); +} +static void gic_test_mmio (void ) {u32 reg;
@@ -388,6 +465,8 @@ static void gic_test_mmio(void)report ("ICPIDR2 is read-only (0x%08x)" ,test_readonly_32 (idreg, false), reg); + +test_priorities (nr_irqs, gic_dist_base +GICD_IPRIORITYR ); }int main (int argc,char **argv)
Signature · 1 line
2.14.4
Re: [kvm-unit-tests PATCH v2 3/4] arm/arm64: GICv2: add GICD_IPRIORITYR testing
Quoted 11 lines · Andre Przywara
Some tests for the IPRIORITY registers. The significant number of bits is IMPLEMENTATION DEFINED, but should be the same for every IRQ. Also these registers must be byte-accessible.
Check that accesses beyond the implemented IRQ limit are actually read-as-zero/write-ignore.Signed-off-by Andre Przywara <[email protected]>--- arm/gic.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)
Re: [kvm-unit-tests PATCH v2 3/4] arm/arm64: GICv2: add GICD_IPRIORITYR testing
In reply to Andre PrzywaraQuoted 33 lines · Andre Przywara
Some tests for the IPRIORITY registers. The significant number of bits is IMPLEMENTATION DEFINED, but should be the same for every IRQ. Also these registers must be byte-accessible.
Check that accesses beyond the implemented IRQ limit are actually read-as-zero/write-ignore.Signed-off-by Andre Przywara <[email protected]>--- arm/gic.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)arm/gic.c +14
-0@@ -354,6 +354,83 @@ static void test_typer_v2(uint32_t reg) nr_gic_cpus); } +#define BYTE (reg32, byte) (((reg32) >> ((byte) * 8)) & 0xff) +#define REPLACE_BYTE (reg32, byte, new) (((reg32) & ~(0xff << ((byte) * 8))) |\ + ((new) << ((byte) * 8))) + +/* +* Some registers are byte accessible, do a byte-wide read and write of known +* content to check for this. +* Apply a @mask to cater for special register properties. +* @pattern contains the value already in the register. +*/ +static void test_byte_access (void *base_addr,u32 pattern,u32 mask) +{ +u32 reg =readb (base_addr +1 ); +
arm/gic.c static void test_typer_v2(uint32_t reg) · line 380
Quoted 10 lines
arm/gic.c +10
-0+report ("byte reads successful (0x%08x => 0x%02x)" , + reg == (BYTE (pattern,1 ) & (mask >>8 )), + pattern & mask, reg); + + pattern =REPLACE_BYTE (pattern,2 ,0x1f ); +writeb (BYTE (pattern,2 ), base_addr +2 ); + reg =readl (base_addr); +report ("byte writes successful (0x%02x => 0x%08x)" , + reg == (pattern & mask),BYTE (pattern,2 ), reg); +}
Hmm, should the above test prepare itself for a potential alignment fault?
Thanks,
drew
PATCH v2 4/4 arm/arm64: GICv2: add GICD_ITARGETSR testing
In reply to Andre PrzywaraSome tests for the ITARGETS registers.
Bits corresponding to non-existent CPUs must be RAZ/WI. These registers must be byte-accessible, also check that accesses beyond the implemented IRQ limit are actually read-as-zero/write-ignore.
--- arm/gic.c | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/arm/asm/gic.h | 1 + 2 files changed, 44 insertions(+)
arm/gic.c +43 -0
@@ -431,6 +431,46 @@ static void test_priorities(int nr_irqs, void *priptr)writel (orig_prio, first_spi); } +/* GICD_ITARGETSR is only used by GICv2. */ +static void test_targets (int nr_irqs) +{ +void *targetsptr =gicv2_dist_base () +GICD_ITARGETSR ; +u32 orig_targets; +u32 cpu_mask; +u32 pattern, reg; + + orig_targets =readl (targetsptr +GIC_FIRST_SPI ); +report_prefix_push ("ITARGETSR" ); + + cpu_mask = (1 << nr_cpus) -1 ; + cpu_mask |= cpu_mask <<8 ; + cpu_mask |= cpu_mask <<16 ; + +/* Check that bits for non implemented CPUs are RAZ/WI. */ +if (nr_cpus <8 ) { +writel (0xffffffff , targetsptr +GIC_FIRST_SPI ); +report ("bits for %d non-existent CPUs masked" , + !(readl (targetsptr +GIC_FIRST_SPI ) & ~cpu_mask), +8 - nr_cpus); + }else { +report_skip ("CPU masking (all CPUs implemented)" ); + } + +report ("accesses beyond limit RAZ/WI" , +test_readonly_32 (targetsptr + nr_irqs, true)); + + pattern =0x0103020f ; +writel (pattern, targetsptr +GIC_FIRST_SPI ); + reg =readl (targetsptr +GIC_FIRST_SPI ); +report ("register content preserved (%08x => %08x)" , + reg == (pattern & cpu_mask), pattern & cpu_mask, reg); + +/* The TARGETS registers are byte accessible. */ +test_byte_access (targetsptr +GIC_FIRST_SPI , pattern, cpu_mask); + +writel (orig_targets, targetsptr +GIC_FIRST_SPI ); +} +static void gic_test_mmio (void ) {u32 reg;
@@ -467,6 +507,9 @@ static void gic_test_mmio(void) reg);test_priorities (nr_irqs, gic_dist_base +GICD_IPRIORITYR ); + +if (gic_version () ==2 ) +test_targets (nr_irqs); }int main (int argc,char **argv)
lib/arm/asm/gic.h +1 -0
@@ -20,6 +20,7 @@#define GICD_ISACTIVER 0x0300#define GICD_ICACTIVER 0x0380#define GICD_IPRIORITYR 0x0400 +#define GICD_ITARGETSR 0x0800#define GICD_SGIR 0x0f00#define GICD_ICPIDR2 0x0fe8
Signature · 1 line
2.14.4
Re: [Qemu-devel] [kvm-unit-tests PATCH v2 4/4] arm/arm64: GICv2: add GICD_ITARGETSR testing
Quoted 11 lines · Andre Przywara
Some tests for the ITARGETS registers.
Bits corresponding to non-existent CPUs must be RAZ/WI. These registers must be byte-accessible, also check that accesses beyond the implemented IRQ limit are actually read-as-zero/write-ignore.Signed-off-by Andre Przywara <[email protected]>--- arm/gic.c | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/arm/asm/gic.h | 1 + 2 files changed, 44 insertions(+)
Quoted 25 lines · Andre Przywara
I found this in one my branches: this is an updated version of what I sent end of 2016 [1]. I tried to address all comments that Drew and Eric had at the time.
Please have a look whether this makes sense.Changelog v1..v2:
- made many functions void
- use symbolic name for first SPI being number 32
- add test runs with one and three vCPUs
- usegic_version()directly
- factor outtest_byte_access()
- drop redundant "filling priorities" test
- dropped GICv3 test[1] https://lists.cs.columbia.edu/pipermail/kvmarm/2016-November/022352.html
Original cover letter:
======================
The GIC spec mandates certain constraints on how to acccess the MMIO mapped registers, both in terms of which registers are available and also in terms of which bits within a register should be masked, for instance. Since we went through some lengths in the KVM emulation to implement this, it's about time to give this actually a test beyond what the kernel as a GIC user actually implements - for instance we ignore priorities in Linux.
Quoted 6 lines
This series tries to attack some constraints, on a low-hanging-fruit base. It focusses on some generic registers and the PRIORITY and TARGETS registers of GICv2. GICv3 is not covered yet.
This actually revealed genuine bugs in the KVM emulation in the past. KVM passes these tests now, but QEMU fails some UP and 3-way-SMP tests.
Would be interesting to see if we've fixed some of the QEMU emulation bugs, either already in master or in Luc's on-list patchset that adds support for emulation of the GICv2 virt extensions...
thanks
-- PMM