Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Hafnium Authors. |
| 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://opensource.org/licenses/BSD-3-Clause. |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <gmock/gmock.h> |
| 10 | |
| 11 | extern "C" { |
Karl Meakin | 07a69ab | 2025-02-07 14:53:19 +0000 | [diff] [blame^] | 12 | #include "hf/arch/mm.h" |
| 13 | |
Daniel Boulby | 8435071 | 2021-11-26 11:13:20 +0000 | [diff] [blame] | 14 | #include "hf/check.h" |
J-Alves | 67f5ba3 | 2024-09-27 18:07:11 +0100 | [diff] [blame] | 15 | #include "hf/list.h" |
Karl Meakin | 07a69ab | 2025-02-07 14:53:19 +0000 | [diff] [blame^] | 16 | #include "hf/mm.h" |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 17 | #include "hf/mpool.h" |
Madhukar Pappireddy | a067dc1 | 2024-10-16 22:20:44 -0500 | [diff] [blame] | 18 | #include "hf/timer_mgmt.h" |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 19 | #include "hf/vm.h" |
| 20 | } |
| 21 | |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 22 | #include <list> |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 23 | #include <memory> |
| 24 | #include <span> |
| 25 | #include <vector> |
| 26 | |
| 27 | #include "mm_test.hh" |
| 28 | |
| 29 | namespace |
| 30 | { |
| 31 | using namespace ::std::placeholders; |
| 32 | |
| 33 | using ::testing::AllOf; |
| 34 | using ::testing::Each; |
| 35 | using ::testing::SizeIs; |
| 36 | |
| 37 | using struct_vm = struct vm; |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 38 | using struct_vcpu = struct vcpu; |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 39 | using struct_vm_locked = struct vm_locked; |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 40 | |
Olivier Deprez | d5a5489 | 2023-02-02 16:45:59 +0100 | [diff] [blame] | 41 | constexpr size_t TEST_HEAP_SIZE = PAGE_SIZE * 64; |
Karl Meakin | 07a69ab | 2025-02-07 14:53:19 +0000 | [diff] [blame^] | 42 | const mm_level_t TOP_LEVEL = arch_mm_stage2_max_level(); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 43 | |
| 44 | class vm : public ::testing::Test |
| 45 | { |
Olivier Deprez | d5a5489 | 2023-02-02 16:45:59 +0100 | [diff] [blame] | 46 | protected: |
| 47 | static std::unique_ptr<uint8_t[]> test_heap; |
| 48 | |
| 49 | struct mpool ppool; |
| 50 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 51 | void SetUp() override |
| 52 | { |
Olivier Deprez | d5a5489 | 2023-02-02 16:45:59 +0100 | [diff] [blame] | 53 | if (!test_heap) { |
| 54 | /* |
| 55 | * TODO: replace with direct use of stdlib allocator so |
| 56 | * sanitizers are more effective. |
| 57 | */ |
| 58 | test_heap = std::make_unique<uint8_t[]>(TEST_HEAP_SIZE); |
| 59 | mpool_init(&ppool, sizeof(struct mm_page_table)); |
| 60 | mpool_add_chunk(&ppool, test_heap.get(), |
| 61 | TEST_HEAP_SIZE); |
| 62 | } |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 63 | } |
| 64 | |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 65 | public: |
J-Alves | beeb6dc | 2021-12-08 18:21:32 +0000 | [diff] [blame] | 66 | static bool BootOrderSmallerThan(struct_vm *vm1, struct_vm *vm2) |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 67 | { |
J-Alves | beeb6dc | 2021-12-08 18:21:32 +0000 | [diff] [blame] | 68 | return vm1->boot_order < vm2->boot_order; |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 69 | } |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
Olivier Deprez | d5a5489 | 2023-02-02 16:45:59 +0100 | [diff] [blame] | 72 | std::unique_ptr<uint8_t[]> vm::test_heap; |
| 73 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 74 | /** |
| 75 | * If nothing is mapped, unmapping the hypervisor has no effect. |
| 76 | */ |
| 77 | TEST_F(vm, vm_unmap_hypervisor_not_mapped) |
| 78 | { |
| 79 | struct_vm *vm; |
| 80 | struct vm_locked vm_locked; |
| 81 | |
Olivier Deprez | 878bd5b | 2021-04-15 19:05:10 +0200 | [diff] [blame] | 82 | /* TODO: check ptable usage (security state?) */ |
Madhukar Pappireddy | 070f49e | 2024-01-12 13:02:27 -0600 | [diff] [blame] | 83 | EXPECT_TRUE(vm_init_next(1, &ppool, &vm, false, 0)); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 84 | vm_locked = vm_lock(vm); |
Raghu Krishnamurthy | 0132b51 | 2021-02-03 14:13:26 -0800 | [diff] [blame] | 85 | ASSERT_TRUE(mm_vm_init(&vm->ptable, vm->id, &ppool)); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 86 | EXPECT_TRUE(vm_unmap_hypervisor(vm_locked, &ppool)); |
| 87 | EXPECT_THAT( |
| 88 | mm_test::get_ptable(vm->ptable), |
| 89 | AllOf(SizeIs(4), Each(Each(arch_mm_absent_pte(TOP_LEVEL))))); |
| 90 | mm_vm_fini(&vm->ptable, &ppool); |
| 91 | vm_unlock(&vm_locked); |
| 92 | } |
| 93 | |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 94 | /** |
| 95 | * Validate the "boot_list" is created properly, according to vm's "boot_order" |
| 96 | * field. |
| 97 | */ |
| 98 | TEST_F(vm, vm_boot_order) |
| 99 | { |
| 100 | struct_vm *vm_cur; |
Madhukar Pappireddy | a49ba16 | 2024-11-25 09:40:45 -0600 | [diff] [blame] | 101 | struct_vm *vm; |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 102 | std::list<struct_vm *> expected_final_order; |
| 103 | |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 104 | /* |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 105 | * Insertion when no call to "vcpu_update_boot" has been made yet. |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 106 | * The "boot_list" is expected to be empty. |
| 107 | */ |
Madhukar Pappireddy | 070f49e | 2024-01-12 13:02:27 -0600 | [diff] [blame] | 108 | EXPECT_TRUE(vm_init_next(1, &ppool, &vm_cur, false, 0)); |
J-Alves | beeb6dc | 2021-12-08 18:21:32 +0000 | [diff] [blame] | 109 | vm_cur->boot_order = 3; |
Madhukar Pappireddy | a49ba16 | 2024-11-25 09:40:45 -0600 | [diff] [blame] | 110 | vm_update_boot(vm_cur); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 111 | expected_final_order.push_back(vm_cur); |
| 112 | |
Madhukar Pappireddy | a49ba16 | 2024-11-25 09:40:45 -0600 | [diff] [blame] | 113 | EXPECT_EQ(vm_get_boot_vm()->id, vm_cur->id); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 114 | |
| 115 | /* Insertion at the head of the boot list */ |
Madhukar Pappireddy | 070f49e | 2024-01-12 13:02:27 -0600 | [diff] [blame] | 116 | EXPECT_TRUE(vm_init_next(1, &ppool, &vm_cur, false, 0)); |
J-Alves | beeb6dc | 2021-12-08 18:21:32 +0000 | [diff] [blame] | 117 | vm_cur->boot_order = 1; |
Madhukar Pappireddy | a49ba16 | 2024-11-25 09:40:45 -0600 | [diff] [blame] | 118 | vm_update_boot(vm_cur); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 119 | expected_final_order.push_back(vm_cur); |
| 120 | |
Madhukar Pappireddy | a49ba16 | 2024-11-25 09:40:45 -0600 | [diff] [blame] | 121 | EXPECT_EQ(vm_get_boot_vm()->id, vm_cur->id); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 122 | |
| 123 | /* Insertion of two in the middle of the boot list */ |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 124 | for (uint32_t i = 0; i < 2; i++) { |
Daniel Boulby | 6c2aa33 | 2024-11-13 13:54:08 +0000 | [diff] [blame] | 125 | EXPECT_TRUE(vm_init_next(MAX_CPUS, &ppool, &vm_cur, false, 0)); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 126 | vm_cur->boot_order = 2; |
Madhukar Pappireddy | a49ba16 | 2024-11-25 09:40:45 -0600 | [diff] [blame] | 127 | vm_update_boot(vm_cur); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 128 | expected_final_order.push_back(vm_cur); |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * Insertion in the end of the list. |
| 133 | * This tests shares the data with "vm_unmap_hypervisor_not_mapped". |
| 134 | * As such, a VM is expected to have been initialized before this |
| 135 | * test, with ID 1 and boot_order 0. |
| 136 | */ |
| 137 | vm_cur = vm_find(1); |
| 138 | EXPECT_FALSE(vm_cur == NULL); |
Madhukar Pappireddy | a49ba16 | 2024-11-25 09:40:45 -0600 | [diff] [blame] | 139 | vm_update_boot(vm_cur); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 140 | expected_final_order.push_back(vm_cur); |
| 141 | |
| 142 | /* |
| 143 | * Number of VMs initialized should be the same as in the |
| 144 | * "expected_final_order", before the final verification. |
| 145 | */ |
| 146 | EXPECT_EQ(expected_final_order.size(), vm_get_count()) |
| 147 | << "Something went wrong with the test itself...\n"; |
| 148 | |
J-Alves | beeb6dc | 2021-12-08 18:21:32 +0000 | [diff] [blame] | 149 | /* Sort VMs from lower to higher "boot_order" field.*/ |
| 150 | expected_final_order.sort(vm::BootOrderSmallerThan); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 151 | |
| 152 | std::list<struct_vm *>::iterator it; |
Madhukar Pappireddy | a49ba16 | 2024-11-25 09:40:45 -0600 | [diff] [blame] | 153 | vm = vm_get_boot_vm(); |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 154 | for (it = expected_final_order.begin(); |
| 155 | it != expected_final_order.end(); it++) { |
Madhukar Pappireddy | a49ba16 | 2024-11-25 09:40:45 -0600 | [diff] [blame] | 156 | EXPECT_TRUE(vm != NULL); |
| 157 | EXPECT_EQ((*it)->id, vm->id); |
| 158 | vm = vm_get_next_boot(vm); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 159 | } |
| 160 | } |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 161 | |
Madhukar Pappireddy | a067dc1 | 2024-10-16 22:20:44 -0500 | [diff] [blame] | 162 | TEST_F(vm, vcpu_arch_timer) |
| 163 | { |
| 164 | const cpu_id_t cpu_ids[2] = {0, 1}; |
| 165 | struct_vcpu *vm0_vcpu; |
| 166 | struct_vcpu *vm1_vcpu; |
| 167 | struct_vcpu *deadline_vcpu; |
| 168 | struct_vcpu *target_vcpu; |
| 169 | struct vcpu_locked vcpu_locked; |
| 170 | struct cpu *cpu0; |
| 171 | struct cpu *cpu1; |
| 172 | |
| 173 | /* Initialie CPU module with two physical CPUs. */ |
| 174 | cpu_module_init(cpu_ids, 2); |
| 175 | cpu0 = cpu_find_index(0); |
| 176 | cpu1 = cpu_find_index(1); |
| 177 | |
| 178 | /* Two UP endpoints are deployed for this test. */ |
| 179 | CHECK(vm_get_count() >= 2); |
| 180 | vm0_vcpu = vm_get_vcpu(vm_find_index(0), 0); |
| 181 | vm1_vcpu = vm_get_vcpu(vm_find_index(1), 0); |
| 182 | |
| 183 | /* The execution context of each VM is scheduled on CPU0. */ |
| 184 | vm0_vcpu->cpu = cpu0; |
| 185 | vm1_vcpu->cpu = cpu0; |
| 186 | |
| 187 | /* |
| 188 | * Enable the timer peripheral for each vCPU and setup an arbitraty |
| 189 | * countdown value. |
| 190 | */ |
| 191 | vm0_vcpu->regs.arch_timer.cval = 555555; |
| 192 | vm1_vcpu->regs.arch_timer.cval = 999999; |
| 193 | vm0_vcpu->regs.arch_timer.ctl = 1; |
| 194 | vm1_vcpu->regs.arch_timer.ctl = 1; |
| 195 | |
| 196 | /* No vCPU is being tracked through either timer list. */ |
| 197 | deadline_vcpu = timer_find_vcpu_nearest_deadline(cpu0); |
| 198 | EXPECT_TRUE(deadline_vcpu == NULL); |
| 199 | deadline_vcpu = timer_find_vcpu_nearest_deadline(cpu1); |
| 200 | EXPECT_TRUE(deadline_vcpu == NULL); |
| 201 | |
| 202 | /* vCPU of VM0 and VM1 are being added to the list. */ |
| 203 | timer_vcpu_manage(vm0_vcpu); |
| 204 | timer_vcpu_manage(vm1_vcpu); |
| 205 | |
| 206 | deadline_vcpu = timer_find_vcpu_nearest_deadline(cpu0); |
| 207 | EXPECT_EQ(deadline_vcpu, vm0_vcpu); |
| 208 | |
| 209 | /* Remove one of the vCPUs from the CPU0 list. */ |
| 210 | vm0_vcpu->regs.arch_timer.cval = 0; |
| 211 | vm0_vcpu->regs.arch_timer.ctl = 0; |
| 212 | timer_vcpu_manage(vm0_vcpu); |
| 213 | |
| 214 | /* This leaves one vCPU entry on CPU0 list. */ |
| 215 | deadline_vcpu = timer_find_vcpu_nearest_deadline(cpu0); |
| 216 | EXPECT_EQ(deadline_vcpu, vm1_vcpu); |
| 217 | |
| 218 | /* Attempt to migrate VM1 vCPU from CPU0 to CPU1. */ |
| 219 | vcpu_locked = vcpu_lock(vm1_vcpu); |
| 220 | timer_migrate_to_other_cpu(cpu1, vcpu_locked); |
| 221 | vcpu_unlock(&vcpu_locked); |
| 222 | |
| 223 | /* |
| 224 | * After migration, ensure the list is empty on CPU0 but non-empty on |
| 225 | * CPU1. |
| 226 | */ |
| 227 | deadline_vcpu = timer_find_vcpu_nearest_deadline(cpu0); |
| 228 | EXPECT_TRUE(deadline_vcpu == NULL); |
| 229 | |
| 230 | /* |
| 231 | * vCPU of VM1 is now running on CPU1. It must be the target vCPU when |
| 232 | * the timer has expired. |
| 233 | */ |
| 234 | target_vcpu = timer_find_target_vcpu(vm1_vcpu); |
| 235 | EXPECT_EQ(target_vcpu, vm1_vcpu); |
| 236 | } |
| 237 | |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 238 | /** |
| 239 | * Validates updates and check functions for binding notifications to endpoints. |
| 240 | */ |
| 241 | TEST_F(vm, vm_notifications_bind_diff_senders) |
| 242 | { |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 243 | struct_vm *current_vm = nullptr; |
| 244 | struct vm_locked current_vm_locked; |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 245 | std::vector<struct_vm *> dummy_senders; |
| 246 | ffa_notifications_bitmap_t bitmaps[] = { |
| 247 | 0x00000000FFFFFFFFU, 0xFFFFFFFF00000000U, 0x0000FFFFFFFF0000U}; |
| 248 | bool is_from_vm = true; |
| 249 | |
| 250 | /* For the subsequent tests three VMs are used. */ |
| 251 | CHECK(vm_get_count() >= 3); |
| 252 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 253 | current_vm = vm_find_index(0); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 254 | |
| 255 | dummy_senders.push_back(vm_find_index(1)); |
| 256 | dummy_senders.push_back(vm_find_index(2)); |
| 257 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 258 | current_vm_locked = vm_lock(current_vm); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 259 | |
| 260 | for (unsigned int i = 0; i < 2; i++) { |
| 261 | /* Validate bindings condition after initialization. */ |
| 262 | EXPECT_TRUE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 263 | current_vm_locked, is_from_vm, HF_INVALID_VM_ID, |
| 264 | bitmaps[i], false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 265 | |
| 266 | /* |
| 267 | * Validate bind related operations. For this test considering |
| 268 | * only global notifications. |
| 269 | */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 270 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 271 | dummy_senders[i]->id, |
| 272 | bitmaps[i], false); |
| 273 | |
| 274 | EXPECT_TRUE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 275 | current_vm_locked, is_from_vm, dummy_senders[i]->id, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 276 | bitmaps[i], false)); |
| 277 | |
| 278 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 279 | current_vm_locked, is_from_vm, dummy_senders[1 - i]->id, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 280 | bitmaps[i], false)); |
| 281 | |
| 282 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 283 | current_vm_locked, is_from_vm, dummy_senders[i]->id, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 284 | bitmaps[1 - i], false)); |
| 285 | |
| 286 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 287 | current_vm_locked, is_from_vm, dummy_senders[i]->id, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 288 | bitmaps[2], false)); |
| 289 | } |
| 290 | |
| 291 | /** Clean up bind for other tests. */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 292 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 293 | bitmaps[0], false); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 294 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 295 | bitmaps[1], false); |
| 296 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 297 | vm_unlock(¤t_vm_locked); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Validates updates and check functions for binding notifications, namely the |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 302 | * configuration of bindings of global and per-vCPU notifications. |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 303 | */ |
| 304 | TEST_F(vm, vm_notification_bind_per_vcpu_vs_global) |
| 305 | { |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 306 | struct_vm *current_vm; |
| 307 | struct vm_locked current_vm_locked; |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 308 | struct_vm *dummy_sender; |
| 309 | ffa_notifications_bitmap_t global = 0x00000000FFFFFFFFU; |
| 310 | ffa_notifications_bitmap_t per_vcpu = ~global; |
| 311 | bool is_from_vm = true; |
| 312 | |
| 313 | CHECK(vm_get_count() >= 2); |
| 314 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 315 | current_vm = vm_find_index(0); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 316 | |
| 317 | dummy_sender = vm_find_index(1); |
| 318 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 319 | current_vm_locked = vm_lock(current_vm); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 320 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 321 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 322 | dummy_sender->id, global, false); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 323 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 324 | dummy_sender->id, per_vcpu, true); |
| 325 | |
| 326 | /* Check validation of global notifications bindings. */ |
| 327 | EXPECT_TRUE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 328 | current_vm_locked, is_from_vm, dummy_sender->id, global, |
| 329 | false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 330 | |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 331 | /* Check validation of per-vCPU notifications bindings. */ |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 332 | EXPECT_TRUE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 333 | current_vm_locked, is_from_vm, dummy_sender->id, per_vcpu, |
| 334 | true)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 335 | |
| 336 | /** |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 337 | * Check that global notifications are not validated as per-vCPU, and |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 338 | * vice-versa. |
| 339 | */ |
| 340 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 341 | current_vm_locked, is_from_vm, dummy_sender->id, global, true)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 342 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 343 | current_vm_locked, is_from_vm, dummy_sender->id, per_vcpu, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 344 | false)); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 345 | EXPECT_FALSE(vm_notifications_validate_binding( |
| 346 | current_vm_locked, is_from_vm, dummy_sender->id, |
| 347 | global | per_vcpu, true)); |
| 348 | EXPECT_FALSE(vm_notifications_validate_binding( |
| 349 | current_vm_locked, is_from_vm, dummy_sender->id, |
| 350 | global | per_vcpu, false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 351 | |
| 352 | /** Undo the bindings */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 353 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0, |
| 354 | global, false); |
| 355 | EXPECT_TRUE(vm_notifications_validate_binding( |
| 356 | current_vm_locked, is_from_vm, 0, global, false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 357 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 358 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0, |
| 359 | per_vcpu, false); |
| 360 | EXPECT_TRUE(vm_notifications_validate_binding( |
| 361 | current_vm_locked, is_from_vm, 0, per_vcpu, false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 362 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 363 | vm_unlock(¤t_vm_locked); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 364 | } |
| 365 | |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 366 | /** |
| 367 | * Validates accesses to notifications bitmaps. |
| 368 | */ |
| 369 | TEST_F(vm, vm_notifications_set_and_get) |
| 370 | { |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 371 | struct_vm *current_vm; |
| 372 | struct vm_locked current_vm_locked; |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 373 | struct_vm *dummy_sender; |
| 374 | ffa_notifications_bitmap_t global = 0x00000000FFFFFFFFU; |
| 375 | ffa_notifications_bitmap_t per_vcpu = ~global; |
| 376 | ffa_notifications_bitmap_t ret; |
Raghu Krishnamurthy | 30aabd6 | 2022-09-17 21:41:00 -0700 | [diff] [blame] | 377 | const unsigned int vcpu_idx = 0; |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 378 | struct notifications *notifications; |
| 379 | const bool is_from_vm = true; |
| 380 | |
| 381 | CHECK(vm_get_count() >= 2); |
| 382 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 383 | current_vm = vm_find_index(0); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 384 | dummy_sender = vm_find_index(1); |
| 385 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 386 | notifications = ¤t_vm->notifications.from_vm; |
| 387 | current_vm_locked = vm_lock(current_vm); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 388 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 389 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 390 | dummy_sender->id, global, false); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 391 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 392 | dummy_sender->id, per_vcpu, true); |
| 393 | |
| 394 | /* |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 395 | * Validate get notifications bitmap for global notifications. |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 396 | */ |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 397 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 398 | global, 0ull, false); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 399 | |
J-Alves | 8450ecb | 2025-02-03 11:51:39 +0000 | [diff] [blame] | 400 | EXPECT_EQ(notifications->global.pending, global); |
| 401 | |
| 402 | /* Counter should track pending notifications. */ |
| 403 | EXPECT_FALSE(vm_is_notifications_pending_count_zero()); |
| 404 | |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 405 | ret = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 406 | is_from_vm, 0ull); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 407 | EXPECT_EQ(ret, global); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 408 | EXPECT_EQ(notifications->global.pending, 0ull); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 409 | |
| 410 | /* |
J-Alves | 8450ecb | 2025-02-03 11:51:39 +0000 | [diff] [blame] | 411 | * After getting the pending notifications, the pending count should |
| 412 | * be zeroed. |
| 413 | */ |
| 414 | EXPECT_TRUE(vm_is_notifications_pending_count_zero()); |
| 415 | |
| 416 | /* |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 417 | * Validate get notifications bitmap for per-vCPU notifications. |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 418 | */ |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 419 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 420 | per_vcpu, vcpu_idx, true); |
J-Alves | fc50ef7 | 2025-02-03 11:57:51 +0000 | [diff] [blame] | 421 | |
| 422 | /* |
| 423 | * Duplicate call to check that the state of the counters doesn't alter |
| 424 | * because of it. |
| 425 | */ |
| 426 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 427 | per_vcpu, vcpu_idx, true); |
| 428 | |
J-Alves | 8450ecb | 2025-02-03 11:51:39 +0000 | [diff] [blame] | 429 | EXPECT_FALSE(vm_is_notifications_pending_count_zero()); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 430 | |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 431 | ret = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 432 | is_from_vm, vcpu_idx); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 433 | EXPECT_EQ(ret, per_vcpu); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 434 | EXPECT_EQ(notifications->per_vcpu[vcpu_idx].pending, 0ull); |
J-Alves | 8450ecb | 2025-02-03 11:51:39 +0000 | [diff] [blame] | 435 | EXPECT_TRUE(vm_is_notifications_pending_count_zero()); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 436 | |
| 437 | /* |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 438 | * Validate that getting notifications for a specific vCPU also returns |
| 439 | * global notifications. |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 440 | */ |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 441 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 442 | per_vcpu, vcpu_idx, true); |
J-Alves | 8450ecb | 2025-02-03 11:51:39 +0000 | [diff] [blame] | 443 | |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 444 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 445 | global, 0ull, false); |
J-Alves | 8450ecb | 2025-02-03 11:51:39 +0000 | [diff] [blame] | 446 | EXPECT_FALSE(vm_is_notifications_pending_count_zero()); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 447 | |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 448 | ret = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 449 | is_from_vm, vcpu_idx); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 450 | EXPECT_EQ(ret, per_vcpu | global); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 451 | EXPECT_EQ(notifications->per_vcpu[vcpu_idx].pending, 0ull); |
| 452 | EXPECT_EQ(notifications->global.pending, 0ull); |
J-Alves | 8450ecb | 2025-02-03 11:51:39 +0000 | [diff] [blame] | 453 | EXPECT_TRUE(vm_is_notifications_pending_count_zero()); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 454 | |
| 455 | /** Undo the binding */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 456 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0ull, |
| 457 | global, false); |
| 458 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0ull, |
| 459 | per_vcpu, true); |
| 460 | vm_unlock(¤t_vm_locked); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 461 | } |
| 462 | |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 463 | /** |
| 464 | * Validates simple getting of notifications info for global notifications. |
| 465 | */ |
| 466 | TEST_F(vm, vm_notifications_info_get_global) |
| 467 | { |
| 468 | ffa_notifications_bitmap_t to_set = 0xFU; |
| 469 | ffa_notifications_bitmap_t got; |
| 470 | |
| 471 | /** |
| 472 | * Following set of variables that are also expected to be used when |
| 473 | * handling FFA_NOTIFICATION_INFO_GET. |
| 474 | */ |
| 475 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 476 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 477 | uint32_t ids_count = 0; |
| 478 | uint32_t lists_count = 0; |
| 479 | enum notifications_info_get_state current_state = INIT; |
| 480 | |
| 481 | CHECK(vm_get_count() >= 2); |
| 482 | |
| 483 | for (unsigned int i = 0; i < 2; i++) { |
| 484 | struct_vm *current_vm = vm_find_index(0); |
| 485 | struct vm_locked current_vm_locked = vm_lock(current_vm); |
| 486 | struct notifications *notifications = |
| 487 | ¤t_vm->notifications.from_sp; |
| 488 | const bool is_from_vm = false; |
| 489 | |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 490 | vm_notifications_partition_set_pending( |
| 491 | current_vm_locked, is_from_vm, to_set, 0, false); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 492 | |
| 493 | vm_notifications_info_get_pending( |
| 494 | current_vm_locked, is_from_vm, ids, &ids_count, |
| 495 | lists_sizes, &lists_count, |
| 496 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, ¤t_state); |
| 497 | |
| 498 | /* |
| 499 | * Here the number of IDs and list count should be the same. |
| 500 | * As we are testing with Global notifications, this is |
| 501 | * expected. |
| 502 | */ |
| 503 | EXPECT_EQ(ids_count, i + 1); |
| 504 | EXPECT_EQ(lists_count, i + 1); |
| 505 | EXPECT_EQ(lists_sizes[i], 0); |
| 506 | EXPECT_EQ(to_set, notifications->global.info_get_retrieved); |
| 507 | |
| 508 | /* Action must be reset to initial state for each VM. */ |
| 509 | current_state = INIT; |
| 510 | |
| 511 | /* |
| 512 | * Check that getting pending notifications gives the expected |
| 513 | * return and cleans the 'pending' and 'info_get_retrieved' |
| 514 | * bitmaps. |
| 515 | */ |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 516 | got = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 517 | is_from_vm, 0); |
| 518 | EXPECT_EQ(got, to_set); |
| 519 | |
| 520 | EXPECT_EQ(notifications->global.info_get_retrieved, 0U); |
| 521 | EXPECT_EQ(notifications->global.pending, 0U); |
| 522 | |
| 523 | vm_unlock(¤t_vm_locked); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * Validates simple getting of notifications info for per-vCPU notifications. |
| 529 | */ |
| 530 | TEST_F(vm, vm_notifications_info_get_per_vcpu) |
| 531 | { |
| 532 | const ffa_notifications_bitmap_t per_vcpu = 0xFU; |
| 533 | ffa_notifications_bitmap_t got; |
| 534 | |
| 535 | /* |
| 536 | * Following set of variables that are also expected to be used when |
| 537 | * handling ffa_notification_info_get. |
| 538 | */ |
| 539 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 540 | uint32_t ids_count = 0; |
| 541 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 542 | uint32_t lists_count = 0; |
| 543 | enum notifications_info_get_state current_state = INIT; |
| 544 | |
| 545 | CHECK(vm_get_count() >= 2); |
| 546 | |
| 547 | for (unsigned int i = 0; i < 2; i++) { |
| 548 | struct_vm *current_vm = vm_find_index(0); |
| 549 | struct vm_locked current_vm_locked = vm_lock(current_vm); |
| 550 | struct notifications *notifications = |
| 551 | ¤t_vm->notifications.from_sp; |
| 552 | const bool is_from_vm = false; |
| 553 | |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 554 | vm_notifications_partition_set_pending( |
| 555 | current_vm_locked, is_from_vm, per_vcpu, 0, true); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 556 | |
| 557 | vm_notifications_info_get_pending( |
| 558 | current_vm_locked, is_from_vm, ids, &ids_count, |
| 559 | lists_sizes, &lists_count, |
| 560 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, ¤t_state); |
| 561 | |
| 562 | /* |
| 563 | * Here the number of IDs and list count should be the same. |
| 564 | * As we are testing with Global notifications, this is |
| 565 | * expected. |
| 566 | */ |
| 567 | EXPECT_EQ(ids_count, (i + 1) * 2); |
| 568 | EXPECT_EQ(lists_count, i + 1); |
| 569 | EXPECT_EQ(lists_sizes[i], 1); |
| 570 | EXPECT_EQ(per_vcpu, |
| 571 | notifications->per_vcpu[0].info_get_retrieved); |
| 572 | |
| 573 | /* Action must be reset to initial state for each VM. */ |
| 574 | current_state = INIT; |
| 575 | |
| 576 | /* |
| 577 | * Check that getting pending notifications gives the expected |
| 578 | * return and cleans the 'pending' and 'info_get_retrieved' |
| 579 | * bitmaps. |
| 580 | */ |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 581 | got = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 582 | is_from_vm, 0); |
| 583 | EXPECT_EQ(got, per_vcpu); |
| 584 | |
| 585 | EXPECT_EQ(notifications->per_vcpu[0].info_get_retrieved, 0U); |
| 586 | EXPECT_EQ(notifications->per_vcpu[0].pending, 0U); |
| 587 | |
| 588 | vm_unlock(¤t_vm_locked); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * Validate getting of notifications information if all VCPUs have notifications |
| 594 | * pending. |
| 595 | */ |
| 596 | TEST_F(vm, vm_notifications_info_get_per_vcpu_all_vcpus) |
| 597 | { |
| 598 | struct_vm *current_vm = nullptr; |
| 599 | struct vm_locked current_vm_locked; |
| 600 | const ffa_vcpu_count_t vcpu_count = MAX_CPUS; |
| 601 | ffa_notifications_bitmap_t got; |
| 602 | const ffa_notifications_bitmap_t global = 0xF0000; |
| 603 | |
| 604 | /* |
| 605 | * Following set of variables that are also expected to be used when |
| 606 | * handling ffa_notification_info_get. |
| 607 | */ |
| 608 | struct notifications *notifications; |
| 609 | const bool is_from_sp = false; |
| 610 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 611 | uint32_t ids_count = 0; |
| 612 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 613 | uint32_t lists_count = 0; |
| 614 | enum notifications_info_get_state current_state = INIT; |
| 615 | |
Madhukar Pappireddy | 070f49e | 2024-01-12 13:02:27 -0600 | [diff] [blame] | 616 | EXPECT_TRUE(vm_init_next(vcpu_count, &ppool, ¤t_vm, false, 0)); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 617 | current_vm_locked = vm_lock(current_vm); |
| 618 | notifications = ¤t_vm->notifications.from_sp; |
| 619 | |
| 620 | for (unsigned int i = 0; i < vcpu_count; i++) { |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 621 | vm_notifications_partition_set_pending( |
| 622 | current_vm_locked, is_from_sp, FFA_NOTIFICATION_MASK(i), |
| 623 | i, true); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | /* |
| 627 | * Adding a global notification should not change the list of IDs, |
| 628 | * because global notifications only require the VM ID to be included in |
| 629 | * the list, at least once. |
| 630 | */ |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 631 | vm_notifications_partition_set_pending(current_vm_locked, is_from_sp, |
| 632 | global, 0, false); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 633 | |
| 634 | vm_notifications_info_get_pending(current_vm_locked, is_from_sp, ids, |
| 635 | &ids_count, lists_sizes, &lists_count, |
| 636 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 637 | ¤t_state); |
| 638 | |
| 639 | /* |
| 640 | * This test has been conceived for the expected MAX_CPUS 4. |
| 641 | * All VCPUs have notifications of the same VM, to be broken down in 2 |
| 642 | * lists with 3 VCPU IDs, and 1 VCPU ID respectively. |
| 643 | * The list of IDs should look like: {<vm_id>, 0, 1, 2, <vm_id>, 3}. |
| 644 | */ |
| 645 | CHECK(MAX_CPUS == 4); |
| 646 | EXPECT_EQ(ids_count, 6U); |
| 647 | EXPECT_EQ(lists_count, 2U); |
| 648 | EXPECT_EQ(lists_sizes[0], 3); |
| 649 | EXPECT_EQ(lists_sizes[1], 1); |
| 650 | |
| 651 | for (unsigned int i = 0; i < vcpu_count; i++) { |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 652 | got = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 653 | is_from_sp, i); |
| 654 | |
| 655 | /* |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 656 | * The first call to |
| 657 | * vm_notifications_partition_get_pending should also |
| 658 | * include the global notifications on the return. |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 659 | */ |
| 660 | ffa_notifications_bitmap_t to_check = |
| 661 | (i != 0) ? FFA_NOTIFICATION_MASK(i) |
| 662 | : FFA_NOTIFICATION_MASK(i) | global; |
| 663 | |
| 664 | EXPECT_EQ(got, to_check); |
| 665 | |
| 666 | EXPECT_EQ(notifications->per_vcpu[i].pending, 0); |
| 667 | EXPECT_EQ(notifications->per_vcpu[i].info_get_retrieved, 0); |
| 668 | } |
| 669 | |
| 670 | vm_unlock(¤t_vm_locked); |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * Validate change of state from 'vm_notifications_info_get_pending', when the |
| 675 | * list of IDs is full. |
| 676 | */ |
| 677 | TEST_F(vm, vm_notifications_info_get_full_per_vcpu) |
| 678 | { |
| 679 | struct_vm *current_vm = vm_find_index(0); |
| 680 | struct vm_locked current_vm_locked = vm_lock(current_vm); |
| 681 | struct notifications *notifications = |
| 682 | ¤t_vm->notifications.from_sp; |
| 683 | const bool is_from_vm = false; |
| 684 | ffa_notifications_bitmap_t got = 0; |
| 685 | |
| 686 | /* |
| 687 | * Following set of variables that are also expected to be used when |
| 688 | * handling ffa_notification_info_get. |
| 689 | * For this 'ids_count' has been initialized such that it indicates |
| 690 | * there is no space in the list for a per-vCPU notification (VM ID and |
| 691 | * VCPU ID). |
| 692 | */ |
| 693 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 694 | uint32_t ids_count = FFA_NOTIFICATIONS_INFO_GET_MAX_IDS - 1; |
| 695 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 696 | uint32_t lists_count = 10; |
| 697 | enum notifications_info_get_state current_state = INIT; |
| 698 | CHECK(vm_get_count() >= 2); |
| 699 | |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 700 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 701 | FFA_NOTIFICATION_MASK(1), 0, |
| 702 | true); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 703 | |
| 704 | /* Call function to get notifications info, with only per-vCPU set. */ |
| 705 | vm_notifications_info_get_pending(current_vm_locked, is_from_vm, ids, |
| 706 | &ids_count, lists_sizes, &lists_count, |
| 707 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 708 | ¤t_state); |
| 709 | |
| 710 | /* |
| 711 | * Verify that as soon as there isn't space to do the required |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 712 | * insertion in the list, the |
| 713 | * 'vm_notifications_partition_get_pending' returns and changes |
| 714 | * list state to FULL. In this case returning, because it would need to |
| 715 | * add two IDs (VM ID and VCPU ID). |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 716 | */ |
| 717 | EXPECT_EQ(current_state, FULL); |
| 718 | EXPECT_EQ(ids_count, FFA_NOTIFICATIONS_INFO_GET_MAX_IDS - 1); |
| 719 | EXPECT_EQ(notifications->per_vcpu[0].info_get_retrieved, 0U); |
| 720 | |
| 721 | /* |
| 722 | * At this point there is still room for the information of a global |
| 723 | * notification (only VM ID to be added). Reset 'current_state' |
| 724 | * for the insertion to happen at the last position of the array. |
| 725 | */ |
| 726 | current_state = INIT; |
| 727 | |
| 728 | /* Setting global notification */ |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 729 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 730 | FFA_NOTIFICATION_MASK(2), 0, |
| 731 | false); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 732 | |
| 733 | vm_notifications_info_get_pending(current_vm_locked, is_from_vm, ids, |
| 734 | &ids_count, lists_sizes, &lists_count, |
| 735 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 736 | ¤t_state); |
| 737 | |
| 738 | /* |
| 739 | * Now List must be full, the set global notification must be part of |
| 740 | * 'info_get_retrieved', and the 'current_state' should be set to FULL |
| 741 | * due to the pending per-vCPU notification in VCPU 0. |
| 742 | */ |
| 743 | EXPECT_EQ(ids_count, FFA_NOTIFICATIONS_INFO_GET_MAX_IDS); |
| 744 | EXPECT_EQ(current_state, FULL); |
| 745 | EXPECT_EQ(notifications->global.info_get_retrieved, |
| 746 | FFA_NOTIFICATION_MASK(2)); |
| 747 | |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 748 | got = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 749 | is_from_vm, 0); |
| 750 | EXPECT_EQ(got, FFA_NOTIFICATION_MASK(1) | FFA_NOTIFICATION_MASK(2)); |
| 751 | |
| 752 | vm_unlock(¤t_vm_locked); |
| 753 | } |
| 754 | |
| 755 | TEST_F(vm, vm_notifications_info_get_full_global) |
| 756 | { |
| 757 | struct_vm *current_vm = vm_find_index(0); |
| 758 | struct vm_locked current_vm_locked = vm_lock(current_vm); |
| 759 | ffa_notifications_bitmap_t got; |
| 760 | struct notifications *notifications; |
| 761 | const bool is_from_vm = false; |
| 762 | /* |
| 763 | * Following set of variables that are also expected to be used when |
| 764 | * handling ffa_notification_info_get. |
| 765 | * For this 'ids_count' has been initialized such that it indicates |
| 766 | * there is no space in the list for a global notification (VM ID only). |
| 767 | */ |
| 768 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 769 | uint32_t ids_count = FFA_NOTIFICATIONS_INFO_GET_MAX_IDS; |
| 770 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 771 | uint32_t lists_count = 10; |
| 772 | enum notifications_info_get_state current_state = INIT; |
| 773 | |
| 774 | CHECK(vm_get_count() >= 1); |
| 775 | |
| 776 | current_vm = vm_find_index(0); |
| 777 | |
| 778 | notifications = ¤t_vm->notifications.from_sp; |
| 779 | |
| 780 | /* Set global notification. */ |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 781 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 782 | FFA_NOTIFICATION_MASK(10), 0, |
| 783 | false); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 784 | |
| 785 | /* Get notifications info for the given notifications. */ |
| 786 | vm_notifications_info_get_pending(current_vm_locked, is_from_vm, ids, |
| 787 | &ids_count, lists_sizes, &lists_count, |
| 788 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 789 | ¤t_state); |
| 790 | |
| 791 | /* Expect 'info_get_retrieved' bitmap to be 0. */ |
| 792 | EXPECT_EQ(notifications->global.info_get_retrieved, 0U); |
| 793 | EXPECT_EQ(notifications->global.pending, FFA_NOTIFICATION_MASK(10)); |
| 794 | EXPECT_EQ(ids_count, FFA_NOTIFICATIONS_INFO_GET_MAX_IDS); |
| 795 | EXPECT_EQ(current_state, FULL); |
| 796 | |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 797 | got = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 798 | is_from_vm, 0); |
J-Alves | 9f74b93 | 2021-10-11 14:20:05 +0100 | [diff] [blame] | 799 | EXPECT_EQ(got, FFA_NOTIFICATION_MASK(10)); |
| 800 | |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 801 | vm_unlock(¤t_vm_locked); |
| 802 | } |
| 803 | |
J-Alves | f31940e | 2022-03-25 17:24:00 +0000 | [diff] [blame] | 804 | TEST_F(vm, vm_notifications_info_get_from_framework) |
| 805 | { |
| 806 | struct vm_locked vm_locked = vm_lock(vm_find_index(0)); |
| 807 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 808 | uint32_t ids_count = 0; |
| 809 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 810 | uint32_t lists_count = 0; |
| 811 | |
| 812 | vm_notifications_framework_set_pending(vm_locked, 0x1U); |
| 813 | |
| 814 | /* Get notifications info for the given notifications. */ |
| 815 | vm_notifications_info_get(vm_locked, ids, &ids_count, lists_sizes, |
| 816 | &lists_count, |
| 817 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS); |
| 818 | |
| 819 | EXPECT_EQ(ids[0], vm_locked.vm->id); |
| 820 | EXPECT_EQ(ids_count, 1); |
| 821 | EXPECT_EQ(lists_sizes[0], 0); |
| 822 | EXPECT_EQ(lists_count, 1); |
| 823 | |
| 824 | EXPECT_EQ(vm_notifications_framework_get_pending(vm_locked), 0x1U); |
| 825 | |
| 826 | vm_unlock(&vm_locked); |
| 827 | } |
| 828 | |
Daniel Boulby | 8be2651 | 2024-09-03 19:41:11 +0100 | [diff] [blame] | 829 | /** |
| 830 | * Validates simple getting of notifications info for pending IPI. |
Daniel Boulby | 6c2aa33 | 2024-11-13 13:54:08 +0000 | [diff] [blame] | 831 | * Also checks that vCPUs with pending IPIs are only reported if the |
| 832 | * vCPU is in the waiting state. |
Daniel Boulby | 8be2651 | 2024-09-03 19:41:11 +0100 | [diff] [blame] | 833 | */ |
| 834 | TEST_F(vm, vm_notifications_info_get_ipi) |
| 835 | { |
| 836 | /* |
| 837 | * Following set of variables that are also expected to be used when |
| 838 | * handling ffa_notification_info_get. |
| 839 | */ |
| 840 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 841 | uint32_t ids_count = 0; |
| 842 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 843 | uint32_t lists_count = 0; |
| 844 | enum notifications_info_get_state current_state = INIT; |
Daniel Boulby | 6c2aa33 | 2024-11-13 13:54:08 +0000 | [diff] [blame] | 845 | struct_vm *current_vm = vm_find_index(4); |
Daniel Boulby | 8be2651 | 2024-09-03 19:41:11 +0100 | [diff] [blame] | 846 | struct vcpu *target_vcpu = vm_get_vcpu(current_vm, 1); |
Daniel Boulby | 3c1506b | 2025-02-25 10:49:51 +0000 | [diff] [blame] | 847 | struct vcpu_locked vcpu_locked; |
Daniel Boulby | 8be2651 | 2024-09-03 19:41:11 +0100 | [diff] [blame] | 848 | const bool is_from_vm = false; |
| 849 | struct vm_locked current_vm_locked = vm_lock(current_vm); |
| 850 | |
| 851 | EXPECT_TRUE(current_vm->vcpu_count >= 2); |
| 852 | |
Daniel Boulby | 3c1506b | 2025-02-25 10:49:51 +0000 | [diff] [blame] | 853 | vcpu_locked = vcpu_lock(target_vcpu); |
| 854 | vcpu_virt_interrupt_inject(vcpu_locked, HF_IPI_INTID); |
| 855 | vcpu_unlock(&vcpu_locked); |
Daniel Boulby | 8be2651 | 2024-09-03 19:41:11 +0100 | [diff] [blame] | 856 | |
| 857 | vm_notifications_info_get_pending(current_vm_locked, is_from_vm, ids, |
| 858 | &ids_count, lists_sizes, &lists_count, |
| 859 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 860 | ¤t_state); |
| 861 | |
Daniel Boulby | 6c2aa33 | 2024-11-13 13:54:08 +0000 | [diff] [blame] | 862 | EXPECT_EQ(ids_count, 0); |
| 863 | EXPECT_EQ(lists_count, 0); |
| 864 | |
| 865 | target_vcpu->state = VCPU_STATE_WAITING; |
| 866 | |
| 867 | vm_notifications_info_get_pending(current_vm_locked, is_from_vm, ids, |
| 868 | &ids_count, lists_sizes, &lists_count, |
| 869 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 870 | ¤t_state); |
| 871 | |
Daniel Boulby | 8be2651 | 2024-09-03 19:41:11 +0100 | [diff] [blame] | 872 | EXPECT_EQ(ids_count, 2); |
| 873 | EXPECT_EQ(lists_count, 1); |
| 874 | EXPECT_EQ(lists_sizes[0], 1); |
| 875 | EXPECT_EQ(ids[0], current_vm->id); |
| 876 | EXPECT_EQ(ids[1], 1); |
| 877 | EXPECT_EQ(target_vcpu->ipi_info_get_retrieved, true); |
| 878 | |
| 879 | /* Check it is not retrieved multiple times. */ |
| 880 | current_state = INIT; |
| 881 | ids[0] = 0; |
| 882 | ids[1] = 0; |
| 883 | ids_count = 0; |
| 884 | lists_sizes[0] = 0; |
| 885 | lists_count = 0; |
| 886 | |
| 887 | vm_notifications_info_get_pending(current_vm_locked, is_from_vm, ids, |
| 888 | &ids_count, lists_sizes, &lists_count, |
| 889 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 890 | ¤t_state); |
| 891 | EXPECT_EQ(ids_count, 0); |
| 892 | EXPECT_EQ(lists_count, 0); |
| 893 | EXPECT_EQ(lists_sizes[0], 0); |
| 894 | |
| 895 | vm_unlock(¤t_vm_locked); |
| 896 | } |
| 897 | |
| 898 | /** |
| 899 | * Validates simple getting of notifications info for pending with IPI when |
| 900 | * notification for the same vcpu is also pending. |
| 901 | */ |
| 902 | TEST_F(vm, vm_notifications_info_get_ipi_with_per_vcpu) |
| 903 | { |
| 904 | /* |
| 905 | * Following set of variables that are also expected to be used when |
| 906 | * handling ffa_notification_info_get. |
| 907 | */ |
| 908 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 909 | uint32_t ids_count = 0; |
| 910 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 911 | uint32_t lists_count = 0; |
| 912 | enum notifications_info_get_state current_state = INIT; |
Daniel Boulby | 6c2aa33 | 2024-11-13 13:54:08 +0000 | [diff] [blame] | 913 | struct_vm *current_vm = vm_find_index(4); |
Daniel Boulby | 8be2651 | 2024-09-03 19:41:11 +0100 | [diff] [blame] | 914 | struct vcpu *target_vcpu = vm_get_vcpu(current_vm, 1); |
Daniel Boulby | 3c1506b | 2025-02-25 10:49:51 +0000 | [diff] [blame] | 915 | struct vcpu_locked vcpu_locked; |
Daniel Boulby | 8be2651 | 2024-09-03 19:41:11 +0100 | [diff] [blame] | 916 | const bool is_from_vm = false; |
| 917 | struct vm_locked current_vm_locked = vm_lock(current_vm); |
| 918 | |
| 919 | EXPECT_TRUE(current_vm->vcpu_count >= 2); |
| 920 | |
Daniel Boulby | 3c1506b | 2025-02-25 10:49:51 +0000 | [diff] [blame] | 921 | vcpu_locked = vcpu_lock(target_vcpu); |
| 922 | vcpu_virt_interrupt_inject(vcpu_locked, HF_IPI_INTID); |
| 923 | vcpu_unlock(&vcpu_locked); |
Daniel Boulby | 8be2651 | 2024-09-03 19:41:11 +0100 | [diff] [blame] | 924 | |
| 925 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 926 | true, 1, true); |
| 927 | vm_notifications_info_get_pending(current_vm_locked, is_from_vm, ids, |
| 928 | &ids_count, lists_sizes, &lists_count, |
| 929 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 930 | ¤t_state); |
| 931 | |
| 932 | EXPECT_EQ(ids_count, 2); |
| 933 | EXPECT_EQ(lists_count, 1); |
| 934 | EXPECT_EQ(lists_sizes[0], 1); |
| 935 | EXPECT_EQ(ids[0], current_vm->id); |
| 936 | EXPECT_EQ(ids[1], 1); |
| 937 | EXPECT_EQ(target_vcpu->ipi_info_get_retrieved, true); |
| 938 | |
| 939 | /* Reset the state and values. */ |
| 940 | current_state = INIT; |
| 941 | ids[0] = 0; |
| 942 | ids[1] = 0; |
| 943 | ids_count = 0; |
| 944 | lists_sizes[0] = 0; |
| 945 | lists_count = 0; |
| 946 | |
| 947 | vm_notifications_info_get_pending(current_vm_locked, is_from_vm, ids, |
| 948 | &ids_count, lists_sizes, &lists_count, |
| 949 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 950 | ¤t_state); |
| 951 | EXPECT_EQ(ids_count, 0); |
| 952 | EXPECT_EQ(lists_count, 0); |
| 953 | EXPECT_EQ(lists_sizes[0], 0); |
| 954 | |
| 955 | vm_unlock(¤t_vm_locked); |
| 956 | } |
| 957 | |
| 958 | /** |
| 959 | * Validate that a mix of a pending IPI and notifcations are correctly |
| 960 | * reported across vcpus. |
| 961 | */ |
| 962 | TEST_F(vm, vm_notifications_info_get_per_vcpu_all_vcpus_and_ipi) |
| 963 | { |
Daniel Boulby | 6c2aa33 | 2024-11-13 13:54:08 +0000 | [diff] [blame] | 964 | struct_vm *current_vm = vm_find_index(4); |
Daniel Boulby | 8be2651 | 2024-09-03 19:41:11 +0100 | [diff] [blame] | 965 | ffa_vcpu_count_t vcpu_count = current_vm->vcpu_count; |
| 966 | CHECK(vcpu_count > 1); |
| 967 | |
| 968 | struct vm_locked current_vm_locked = vm_lock(current_vm); |
| 969 | |
| 970 | /* |
| 971 | * Following set of variables that are also expected to be used when |
| 972 | * handling ffa_notification_info_get. |
| 973 | */ |
| 974 | const bool is_from_vm = false; |
| 975 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 976 | uint32_t ids_count = 0; |
| 977 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 978 | uint32_t lists_count = 0; |
| 979 | enum notifications_info_get_state current_state = INIT; |
| 980 | struct vcpu *target_vcpu = vm_get_vcpu(current_vm, 0); |
Daniel Boulby | 3c1506b | 2025-02-25 10:49:51 +0000 | [diff] [blame] | 981 | struct vcpu_locked vcpu_locked; |
Daniel Boulby | 8be2651 | 2024-09-03 19:41:11 +0100 | [diff] [blame] | 982 | |
Daniel Boulby | 6c2aa33 | 2024-11-13 13:54:08 +0000 | [diff] [blame] | 983 | target_vcpu->state = VCPU_STATE_WAITING; |
| 984 | |
Daniel Boulby | 3c1506b | 2025-02-25 10:49:51 +0000 | [diff] [blame] | 985 | vcpu_locked = vcpu_lock(target_vcpu); |
| 986 | vcpu_virt_interrupt_inject(vcpu_locked, HF_IPI_INTID); |
| 987 | vcpu_unlock(&vcpu_locked); |
Daniel Boulby | 8be2651 | 2024-09-03 19:41:11 +0100 | [diff] [blame] | 988 | |
| 989 | for (unsigned int i = 1; i < vcpu_count; i++) { |
| 990 | vm_notifications_partition_set_pending( |
| 991 | current_vm_locked, is_from_vm, FFA_NOTIFICATION_MASK(i), |
| 992 | i, true); |
| 993 | } |
| 994 | |
| 995 | vm_notifications_info_get_pending(current_vm_locked, is_from_vm, ids, |
| 996 | &ids_count, lists_sizes, &lists_count, |
| 997 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 998 | ¤t_state); |
| 999 | |
| 1000 | /* |
| 1001 | * This test has been conceived for the expected MAX_CPUS 4. |
| 1002 | * All VCPUs have notifications of the same VM, to be broken down in 2 |
| 1003 | * lists with 3 VCPU IDs, and 1 VCPU ID respectively. |
| 1004 | * The list of IDs should look like: {<vm_id>, 0, 1, 2, <vm_id>, 3}. |
| 1005 | */ |
| 1006 | EXPECT_EQ(ids_count, 6U); |
| 1007 | EXPECT_EQ(lists_count, 2U); |
| 1008 | EXPECT_EQ(lists_sizes[0], 3); |
| 1009 | EXPECT_EQ(lists_sizes[1], 1); |
| 1010 | EXPECT_EQ(ids[0], current_vm->id); |
| 1011 | EXPECT_EQ(ids[1], 0); |
| 1012 | EXPECT_EQ(ids[2], 1); |
| 1013 | EXPECT_EQ(ids[3], 2); |
| 1014 | EXPECT_EQ(ids[4], current_vm->id); |
| 1015 | EXPECT_EQ(ids[5], 3); |
| 1016 | |
| 1017 | vm_unlock(¤t_vm_locked); |
| 1018 | } |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 1019 | } /* namespace */ |