@@ -598,6 +598,47 @@ static void test_v3_redist_ipa_range_check_at_vcpu_run(void)
598
598
vm_gic_destroy (& v );
599
599
}
600
600
601
+ static void test_v3_its_region (void )
602
+ {
603
+ struct vm_gic v ;
604
+ uint64_t addr ;
605
+ int its_fd , ret ;
606
+
607
+ v = vm_gic_create_with_vcpus (KVM_DEV_TYPE_ARM_VGIC_V3 , NR_VCPUS );
608
+ its_fd = kvm_create_device (v .vm , KVM_DEV_TYPE_ARM_VGIC_ITS , false);
609
+
610
+ addr = 0x401000 ;
611
+ ret = _kvm_device_access (its_fd , KVM_DEV_ARM_VGIC_GRP_ADDR ,
612
+ KVM_VGIC_ITS_ADDR_TYPE , & addr , true);
613
+ TEST_ASSERT (ret && errno == EINVAL ,
614
+ "ITS region with misaligned address" );
615
+
616
+ addr = max_phys_size ;
617
+ ret = _kvm_device_access (its_fd , KVM_DEV_ARM_VGIC_GRP_ADDR ,
618
+ KVM_VGIC_ITS_ADDR_TYPE , & addr , true);
619
+ TEST_ASSERT (ret && errno == E2BIG ,
620
+ "register ITS region with base address beyond IPA range" );
621
+
622
+ addr = max_phys_size - 0x10000 ;
623
+ ret = _kvm_device_access (its_fd , KVM_DEV_ARM_VGIC_GRP_ADDR ,
624
+ KVM_VGIC_ITS_ADDR_TYPE , & addr , true);
625
+ TEST_ASSERT (ret && errno == E2BIG ,
626
+ "Half of ITS region is beyond IPA range" );
627
+
628
+ /* This one succeeds setting the ITS base */
629
+ addr = 0x400000 ;
630
+ kvm_device_access (its_fd , KVM_DEV_ARM_VGIC_GRP_ADDR ,
631
+ KVM_VGIC_ITS_ADDR_TYPE , & addr , true);
632
+
633
+ addr = 0x300000 ;
634
+ ret = _kvm_device_access (its_fd , KVM_DEV_ARM_VGIC_GRP_ADDR ,
635
+ KVM_VGIC_ITS_ADDR_TYPE , & addr , true);
636
+ TEST_ASSERT (ret && errno == EEXIST , "ITS base set again" );
637
+
638
+ close (its_fd );
639
+ vm_gic_destroy (& v );
640
+ }
641
+
601
642
/*
602
643
* Returns 0 if it's possible to create GIC device of a given type (V2 or V3).
603
644
*/
@@ -650,6 +691,7 @@ void run_tests(uint32_t gic_dev_type)
650
691
test_v3_last_bit_redist_regions ();
651
692
test_v3_last_bit_single_rdist ();
652
693
test_v3_redist_ipa_range_check_at_vcpu_run ();
694
+ test_v3_its_region ();
653
695
}
654
696
}
655
697
0 commit comments