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" { |
Daniel Boulby | 8435071 | 2021-11-26 11:13:20 +0000 | [diff] [blame] | 12 | #include "hf/check.h" |
J-Alves | 67f5ba3 | 2024-09-27 18:07:11 +0100 | [diff] [blame] | 13 | #include "hf/list.h" |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 14 | #include "hf/mpool.h" |
| 15 | #include "hf/vm.h" |
| 16 | } |
| 17 | |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 18 | #include <list> |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 19 | #include <memory> |
| 20 | #include <span> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include "mm_test.hh" |
| 24 | |
| 25 | namespace |
| 26 | { |
| 27 | using namespace ::std::placeholders; |
| 28 | |
| 29 | using ::testing::AllOf; |
| 30 | using ::testing::Each; |
| 31 | using ::testing::SizeIs; |
| 32 | |
| 33 | using struct_vm = struct vm; |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 34 | using struct_vcpu = struct vcpu; |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 35 | using struct_vm_locked = struct vm_locked; |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 36 | |
Olivier Deprez | d5a5489 | 2023-02-02 16:45:59 +0100 | [diff] [blame] | 37 | constexpr size_t TEST_HEAP_SIZE = PAGE_SIZE * 64; |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 38 | const int TOP_LEVEL = arch_mm_stage2_max_level(); |
| 39 | |
| 40 | class vm : public ::testing::Test |
| 41 | { |
Olivier Deprez | d5a5489 | 2023-02-02 16:45:59 +0100 | [diff] [blame] | 42 | protected: |
| 43 | static std::unique_ptr<uint8_t[]> test_heap; |
| 44 | |
| 45 | struct mpool ppool; |
| 46 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 47 | void SetUp() override |
| 48 | { |
Olivier Deprez | d5a5489 | 2023-02-02 16:45:59 +0100 | [diff] [blame] | 49 | if (!test_heap) { |
| 50 | /* |
| 51 | * TODO: replace with direct use of stdlib allocator so |
| 52 | * sanitizers are more effective. |
| 53 | */ |
| 54 | test_heap = std::make_unique<uint8_t[]>(TEST_HEAP_SIZE); |
| 55 | mpool_init(&ppool, sizeof(struct mm_page_table)); |
| 56 | mpool_add_chunk(&ppool, test_heap.get(), |
| 57 | TEST_HEAP_SIZE); |
| 58 | } |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 59 | } |
| 60 | |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 61 | public: |
J-Alves | beeb6dc | 2021-12-08 18:21:32 +0000 | [diff] [blame] | 62 | static bool BootOrderSmallerThan(struct_vm *vm1, struct_vm *vm2) |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 63 | { |
J-Alves | beeb6dc | 2021-12-08 18:21:32 +0000 | [diff] [blame] | 64 | return vm1->boot_order < vm2->boot_order; |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 65 | } |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
Olivier Deprez | d5a5489 | 2023-02-02 16:45:59 +0100 | [diff] [blame] | 68 | std::unique_ptr<uint8_t[]> vm::test_heap; |
| 69 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 70 | /** |
| 71 | * If nothing is mapped, unmapping the hypervisor has no effect. |
| 72 | */ |
| 73 | TEST_F(vm, vm_unmap_hypervisor_not_mapped) |
| 74 | { |
| 75 | struct_vm *vm; |
| 76 | struct vm_locked vm_locked; |
| 77 | |
Olivier Deprez | 878bd5b | 2021-04-15 19:05:10 +0200 | [diff] [blame] | 78 | /* TODO: check ptable usage (security state?) */ |
Madhukar Pappireddy | 070f49e | 2024-01-12 13:02:27 -0600 | [diff] [blame] | 79 | EXPECT_TRUE(vm_init_next(1, &ppool, &vm, false, 0)); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 80 | vm_locked = vm_lock(vm); |
Raghu Krishnamurthy | 0132b51 | 2021-02-03 14:13:26 -0800 | [diff] [blame] | 81 | ASSERT_TRUE(mm_vm_init(&vm->ptable, vm->id, &ppool)); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 82 | EXPECT_TRUE(vm_unmap_hypervisor(vm_locked, &ppool)); |
| 83 | EXPECT_THAT( |
| 84 | mm_test::get_ptable(vm->ptable), |
| 85 | AllOf(SizeIs(4), Each(Each(arch_mm_absent_pte(TOP_LEVEL))))); |
| 86 | mm_vm_fini(&vm->ptable, &ppool); |
| 87 | vm_unlock(&vm_locked); |
| 88 | } |
| 89 | |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 90 | /** |
| 91 | * Validate the "boot_list" is created properly, according to vm's "boot_order" |
| 92 | * field. |
| 93 | */ |
| 94 | TEST_F(vm, vm_boot_order) |
| 95 | { |
| 96 | struct_vm *vm_cur; |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 97 | struct_vcpu *vcpu; |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 98 | std::list<struct_vm *> expected_final_order; |
| 99 | |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 100 | /* |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 101 | * Insertion when no call to "vcpu_update_boot" has been made yet. |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 102 | * The "boot_list" is expected to be empty. |
| 103 | */ |
Madhukar Pappireddy | 070f49e | 2024-01-12 13:02:27 -0600 | [diff] [blame] | 104 | EXPECT_TRUE(vm_init_next(1, &ppool, &vm_cur, false, 0)); |
J-Alves | beeb6dc | 2021-12-08 18:21:32 +0000 | [diff] [blame] | 105 | vm_cur->boot_order = 3; |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 106 | vcpu = vm_get_vcpu(vm_cur, 0); |
| 107 | vcpu_update_boot(vcpu); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 108 | expected_final_order.push_back(vm_cur); |
| 109 | |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 110 | EXPECT_EQ(vcpu_get_boot_vcpu()->vm->id, vm_cur->id); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 111 | |
| 112 | /* Insertion at the head of the boot list */ |
Madhukar Pappireddy | 070f49e | 2024-01-12 13:02:27 -0600 | [diff] [blame] | 113 | EXPECT_TRUE(vm_init_next(1, &ppool, &vm_cur, false, 0)); |
J-Alves | beeb6dc | 2021-12-08 18:21:32 +0000 | [diff] [blame] | 114 | vm_cur->boot_order = 1; |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 115 | vcpu = vm_get_vcpu(vm_cur, 0); |
| 116 | vcpu_update_boot(vcpu); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 117 | expected_final_order.push_back(vm_cur); |
| 118 | |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 119 | EXPECT_EQ(vcpu_get_boot_vcpu()->vm->id, vm_cur->id); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 120 | |
| 121 | /* Insertion of two in the middle of the boot list */ |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 122 | for (uint32_t i = 0; i < 2; i++) { |
Madhukar Pappireddy | 070f49e | 2024-01-12 13:02:27 -0600 | [diff] [blame] | 123 | EXPECT_TRUE(vm_init_next(1, &ppool, &vm_cur, false, 0)); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 124 | vm_cur->boot_order = 2; |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 125 | vcpu = vm_get_vcpu(vm_cur, 0); |
| 126 | vcpu_update_boot(vcpu); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 127 | expected_final_order.push_back(vm_cur); |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Insertion in the end of the list. |
| 132 | * This tests shares the data with "vm_unmap_hypervisor_not_mapped". |
| 133 | * As such, a VM is expected to have been initialized before this |
| 134 | * test, with ID 1 and boot_order 0. |
| 135 | */ |
| 136 | vm_cur = vm_find(1); |
| 137 | EXPECT_FALSE(vm_cur == NULL); |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 138 | vcpu = vm_get_vcpu(vm_cur, 0); |
| 139 | vcpu_update_boot(vcpu); |
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; |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 153 | vcpu = vcpu_get_boot_vcpu(); |
| 154 | for (it = expected_final_order.begin(); |
| 155 | it != expected_final_order.end(); it++) { |
| 156 | EXPECT_TRUE(vcpu != NULL); |
| 157 | EXPECT_EQ((*it)->id, vcpu->vm->id); |
J-Alves | 67f5ba3 | 2024-09-27 18:07:11 +0100 | [diff] [blame] | 158 | vcpu = vcpu_get_next_boot(vcpu); |
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 | |
| 162 | /** |
| 163 | * Validates updates and check functions for binding notifications to endpoints. |
| 164 | */ |
| 165 | TEST_F(vm, vm_notifications_bind_diff_senders) |
| 166 | { |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 167 | struct_vm *current_vm = nullptr; |
| 168 | struct vm_locked current_vm_locked; |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 169 | std::vector<struct_vm *> dummy_senders; |
| 170 | ffa_notifications_bitmap_t bitmaps[] = { |
| 171 | 0x00000000FFFFFFFFU, 0xFFFFFFFF00000000U, 0x0000FFFFFFFF0000U}; |
| 172 | bool is_from_vm = true; |
| 173 | |
| 174 | /* For the subsequent tests three VMs are used. */ |
| 175 | CHECK(vm_get_count() >= 3); |
| 176 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 177 | current_vm = vm_find_index(0); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 178 | |
| 179 | dummy_senders.push_back(vm_find_index(1)); |
| 180 | dummy_senders.push_back(vm_find_index(2)); |
| 181 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 182 | current_vm_locked = vm_lock(current_vm); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 183 | |
| 184 | for (unsigned int i = 0; i < 2; i++) { |
| 185 | /* Validate bindings condition after initialization. */ |
| 186 | EXPECT_TRUE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 187 | current_vm_locked, is_from_vm, HF_INVALID_VM_ID, |
| 188 | bitmaps[i], false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 189 | |
| 190 | /* |
| 191 | * Validate bind related operations. For this test considering |
| 192 | * only global notifications. |
| 193 | */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 194 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 195 | dummy_senders[i]->id, |
| 196 | bitmaps[i], false); |
| 197 | |
| 198 | EXPECT_TRUE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 199 | current_vm_locked, is_from_vm, dummy_senders[i]->id, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 200 | bitmaps[i], false)); |
| 201 | |
| 202 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 203 | current_vm_locked, is_from_vm, dummy_senders[1 - i]->id, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 204 | bitmaps[i], false)); |
| 205 | |
| 206 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 207 | current_vm_locked, is_from_vm, dummy_senders[i]->id, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 208 | bitmaps[1 - i], false)); |
| 209 | |
| 210 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 211 | current_vm_locked, is_from_vm, dummy_senders[i]->id, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 212 | bitmaps[2], false)); |
| 213 | } |
| 214 | |
| 215 | /** Clean up bind for other tests. */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 216 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 217 | bitmaps[0], false); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 218 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 219 | bitmaps[1], false); |
| 220 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 221 | vm_unlock(¤t_vm_locked); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Validates updates and check functions for binding notifications, namely the |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 226 | * configuration of bindings of global and per-vCPU notifications. |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 227 | */ |
| 228 | TEST_F(vm, vm_notification_bind_per_vcpu_vs_global) |
| 229 | { |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 230 | struct_vm *current_vm; |
| 231 | struct vm_locked current_vm_locked; |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 232 | struct_vm *dummy_sender; |
| 233 | ffa_notifications_bitmap_t global = 0x00000000FFFFFFFFU; |
| 234 | ffa_notifications_bitmap_t per_vcpu = ~global; |
| 235 | bool is_from_vm = true; |
| 236 | |
| 237 | CHECK(vm_get_count() >= 2); |
| 238 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 239 | current_vm = vm_find_index(0); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 240 | |
| 241 | dummy_sender = vm_find_index(1); |
| 242 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 243 | current_vm_locked = vm_lock(current_vm); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 244 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 245 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 246 | dummy_sender->id, global, false); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 247 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 248 | dummy_sender->id, per_vcpu, true); |
| 249 | |
| 250 | /* Check validation of global notifications bindings. */ |
| 251 | EXPECT_TRUE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 252 | current_vm_locked, is_from_vm, dummy_sender->id, global, |
| 253 | false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 254 | |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 255 | /* Check validation of per-vCPU notifications bindings. */ |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 256 | EXPECT_TRUE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 257 | current_vm_locked, is_from_vm, dummy_sender->id, per_vcpu, |
| 258 | true)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 259 | |
| 260 | /** |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 261 | * Check that global notifications are not validated as per-vCPU, and |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 262 | * vice-versa. |
| 263 | */ |
| 264 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 265 | current_vm_locked, is_from_vm, dummy_sender->id, global, true)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 266 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 267 | current_vm_locked, is_from_vm, dummy_sender->id, per_vcpu, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 268 | false)); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 269 | EXPECT_FALSE(vm_notifications_validate_binding( |
| 270 | current_vm_locked, is_from_vm, dummy_sender->id, |
| 271 | global | per_vcpu, true)); |
| 272 | EXPECT_FALSE(vm_notifications_validate_binding( |
| 273 | current_vm_locked, is_from_vm, dummy_sender->id, |
| 274 | global | per_vcpu, false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 275 | |
| 276 | /** Undo the bindings */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 277 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0, |
| 278 | global, false); |
| 279 | EXPECT_TRUE(vm_notifications_validate_binding( |
| 280 | current_vm_locked, is_from_vm, 0, global, false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 281 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 282 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0, |
| 283 | per_vcpu, false); |
| 284 | EXPECT_TRUE(vm_notifications_validate_binding( |
| 285 | current_vm_locked, is_from_vm, 0, per_vcpu, false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 286 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 287 | vm_unlock(¤t_vm_locked); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 288 | } |
| 289 | |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 290 | /** |
| 291 | * Validates accesses to notifications bitmaps. |
| 292 | */ |
| 293 | TEST_F(vm, vm_notifications_set_and_get) |
| 294 | { |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 295 | struct_vm *current_vm; |
| 296 | struct vm_locked current_vm_locked; |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 297 | struct_vm *dummy_sender; |
| 298 | ffa_notifications_bitmap_t global = 0x00000000FFFFFFFFU; |
| 299 | ffa_notifications_bitmap_t per_vcpu = ~global; |
| 300 | ffa_notifications_bitmap_t ret; |
Raghu Krishnamurthy | 30aabd6 | 2022-09-17 21:41:00 -0700 | [diff] [blame] | 301 | const unsigned int vcpu_idx = 0; |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 302 | struct notifications *notifications; |
| 303 | const bool is_from_vm = true; |
| 304 | |
| 305 | CHECK(vm_get_count() >= 2); |
| 306 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 307 | current_vm = vm_find_index(0); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 308 | dummy_sender = vm_find_index(1); |
| 309 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 310 | notifications = ¤t_vm->notifications.from_vm; |
| 311 | current_vm_locked = vm_lock(current_vm); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 312 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 313 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 314 | dummy_sender->id, global, false); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 315 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 316 | dummy_sender->id, per_vcpu, true); |
| 317 | |
| 318 | /* |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 319 | * Validate get notifications bitmap for global notifications. |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 320 | */ |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 321 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 322 | global, 0ull, false); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 323 | |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 324 | ret = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 325 | is_from_vm, 0ull); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 326 | EXPECT_EQ(ret, global); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 327 | EXPECT_EQ(notifications->global.pending, 0ull); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 328 | |
| 329 | /* |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 330 | * Validate get notifications bitmap for per-vCPU notifications. |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 331 | */ |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 332 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 333 | per_vcpu, vcpu_idx, true); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 334 | |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 335 | ret = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 336 | is_from_vm, vcpu_idx); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 337 | EXPECT_EQ(ret, per_vcpu); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 338 | EXPECT_EQ(notifications->per_vcpu[vcpu_idx].pending, 0ull); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 339 | |
| 340 | /* |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 341 | * Validate that getting notifications for a specific vCPU also returns |
| 342 | * global notifications. |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 343 | */ |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 344 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 345 | per_vcpu, vcpu_idx, true); |
| 346 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 347 | global, 0ull, false); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 348 | |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 349 | ret = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 350 | is_from_vm, vcpu_idx); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 351 | EXPECT_EQ(ret, per_vcpu | global); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 352 | EXPECT_EQ(notifications->per_vcpu[vcpu_idx].pending, 0ull); |
| 353 | EXPECT_EQ(notifications->global.pending, 0ull); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 354 | |
| 355 | /** Undo the binding */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame] | 356 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0ull, |
| 357 | global, false); |
| 358 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0ull, |
| 359 | per_vcpu, true); |
| 360 | vm_unlock(¤t_vm_locked); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 361 | } |
| 362 | |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 363 | /** |
| 364 | * Validates simple getting of notifications info for global notifications. |
| 365 | */ |
| 366 | TEST_F(vm, vm_notifications_info_get_global) |
| 367 | { |
| 368 | ffa_notifications_bitmap_t to_set = 0xFU; |
| 369 | ffa_notifications_bitmap_t got; |
| 370 | |
| 371 | /** |
| 372 | * Following set of variables that are also expected to be used when |
| 373 | * handling FFA_NOTIFICATION_INFO_GET. |
| 374 | */ |
| 375 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 376 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 377 | uint32_t ids_count = 0; |
| 378 | uint32_t lists_count = 0; |
| 379 | enum notifications_info_get_state current_state = INIT; |
| 380 | |
| 381 | CHECK(vm_get_count() >= 2); |
| 382 | |
| 383 | for (unsigned int i = 0; i < 2; i++) { |
| 384 | struct_vm *current_vm = vm_find_index(0); |
| 385 | struct vm_locked current_vm_locked = vm_lock(current_vm); |
| 386 | struct notifications *notifications = |
| 387 | ¤t_vm->notifications.from_sp; |
| 388 | const bool is_from_vm = false; |
| 389 | |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 390 | vm_notifications_partition_set_pending( |
| 391 | current_vm_locked, is_from_vm, to_set, 0, false); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 392 | |
| 393 | vm_notifications_info_get_pending( |
| 394 | current_vm_locked, is_from_vm, ids, &ids_count, |
| 395 | lists_sizes, &lists_count, |
| 396 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, ¤t_state); |
| 397 | |
| 398 | /* |
| 399 | * Here the number of IDs and list count should be the same. |
| 400 | * As we are testing with Global notifications, this is |
| 401 | * expected. |
| 402 | */ |
| 403 | EXPECT_EQ(ids_count, i + 1); |
| 404 | EXPECT_EQ(lists_count, i + 1); |
| 405 | EXPECT_EQ(lists_sizes[i], 0); |
| 406 | EXPECT_EQ(to_set, notifications->global.info_get_retrieved); |
| 407 | |
| 408 | /* Action must be reset to initial state for each VM. */ |
| 409 | current_state = INIT; |
| 410 | |
| 411 | /* |
| 412 | * Check that getting pending notifications gives the expected |
| 413 | * return and cleans the 'pending' and 'info_get_retrieved' |
| 414 | * bitmaps. |
| 415 | */ |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 416 | got = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 417 | is_from_vm, 0); |
| 418 | EXPECT_EQ(got, to_set); |
| 419 | |
| 420 | EXPECT_EQ(notifications->global.info_get_retrieved, 0U); |
| 421 | EXPECT_EQ(notifications->global.pending, 0U); |
| 422 | |
| 423 | vm_unlock(¤t_vm_locked); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * Validates simple getting of notifications info for per-vCPU notifications. |
| 429 | */ |
| 430 | TEST_F(vm, vm_notifications_info_get_per_vcpu) |
| 431 | { |
| 432 | const ffa_notifications_bitmap_t per_vcpu = 0xFU; |
| 433 | ffa_notifications_bitmap_t got; |
| 434 | |
| 435 | /* |
| 436 | * Following set of variables that are also expected to be used when |
| 437 | * handling ffa_notification_info_get. |
| 438 | */ |
| 439 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 440 | uint32_t ids_count = 0; |
| 441 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 442 | uint32_t lists_count = 0; |
| 443 | enum notifications_info_get_state current_state = INIT; |
| 444 | |
| 445 | CHECK(vm_get_count() >= 2); |
| 446 | |
| 447 | for (unsigned int i = 0; i < 2; i++) { |
| 448 | struct_vm *current_vm = vm_find_index(0); |
| 449 | struct vm_locked current_vm_locked = vm_lock(current_vm); |
| 450 | struct notifications *notifications = |
| 451 | ¤t_vm->notifications.from_sp; |
| 452 | const bool is_from_vm = false; |
| 453 | |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 454 | vm_notifications_partition_set_pending( |
| 455 | current_vm_locked, is_from_vm, per_vcpu, 0, true); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 456 | |
| 457 | vm_notifications_info_get_pending( |
| 458 | current_vm_locked, is_from_vm, ids, &ids_count, |
| 459 | lists_sizes, &lists_count, |
| 460 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, ¤t_state); |
| 461 | |
| 462 | /* |
| 463 | * Here the number of IDs and list count should be the same. |
| 464 | * As we are testing with Global notifications, this is |
| 465 | * expected. |
| 466 | */ |
| 467 | EXPECT_EQ(ids_count, (i + 1) * 2); |
| 468 | EXPECT_EQ(lists_count, i + 1); |
| 469 | EXPECT_EQ(lists_sizes[i], 1); |
| 470 | EXPECT_EQ(per_vcpu, |
| 471 | notifications->per_vcpu[0].info_get_retrieved); |
| 472 | |
| 473 | /* Action must be reset to initial state for each VM. */ |
| 474 | current_state = INIT; |
| 475 | |
| 476 | /* |
| 477 | * Check that getting pending notifications gives the expected |
| 478 | * return and cleans the 'pending' and 'info_get_retrieved' |
| 479 | * bitmaps. |
| 480 | */ |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 481 | got = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 482 | is_from_vm, 0); |
| 483 | EXPECT_EQ(got, per_vcpu); |
| 484 | |
| 485 | EXPECT_EQ(notifications->per_vcpu[0].info_get_retrieved, 0U); |
| 486 | EXPECT_EQ(notifications->per_vcpu[0].pending, 0U); |
| 487 | |
| 488 | vm_unlock(¤t_vm_locked); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Validate getting of notifications information if all VCPUs have notifications |
| 494 | * pending. |
| 495 | */ |
| 496 | TEST_F(vm, vm_notifications_info_get_per_vcpu_all_vcpus) |
| 497 | { |
| 498 | struct_vm *current_vm = nullptr; |
| 499 | struct vm_locked current_vm_locked; |
| 500 | const ffa_vcpu_count_t vcpu_count = MAX_CPUS; |
| 501 | ffa_notifications_bitmap_t got; |
| 502 | const ffa_notifications_bitmap_t global = 0xF0000; |
| 503 | |
| 504 | /* |
| 505 | * Following set of variables that are also expected to be used when |
| 506 | * handling ffa_notification_info_get. |
| 507 | */ |
| 508 | struct notifications *notifications; |
| 509 | const bool is_from_sp = false; |
| 510 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 511 | uint32_t ids_count = 0; |
| 512 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 513 | uint32_t lists_count = 0; |
| 514 | enum notifications_info_get_state current_state = INIT; |
| 515 | |
Madhukar Pappireddy | 070f49e | 2024-01-12 13:02:27 -0600 | [diff] [blame] | 516 | EXPECT_TRUE(vm_init_next(vcpu_count, &ppool, ¤t_vm, false, 0)); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 517 | current_vm_locked = vm_lock(current_vm); |
| 518 | notifications = ¤t_vm->notifications.from_sp; |
| 519 | |
| 520 | for (unsigned int i = 0; i < vcpu_count; i++) { |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 521 | vm_notifications_partition_set_pending( |
| 522 | current_vm_locked, is_from_sp, FFA_NOTIFICATION_MASK(i), |
| 523 | i, true); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | /* |
| 527 | * Adding a global notification should not change the list of IDs, |
| 528 | * because global notifications only require the VM ID to be included in |
| 529 | * the list, at least once. |
| 530 | */ |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 531 | vm_notifications_partition_set_pending(current_vm_locked, is_from_sp, |
| 532 | global, 0, false); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 533 | |
| 534 | vm_notifications_info_get_pending(current_vm_locked, is_from_sp, ids, |
| 535 | &ids_count, lists_sizes, &lists_count, |
| 536 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 537 | ¤t_state); |
| 538 | |
| 539 | /* |
| 540 | * This test has been conceived for the expected MAX_CPUS 4. |
| 541 | * All VCPUs have notifications of the same VM, to be broken down in 2 |
| 542 | * lists with 3 VCPU IDs, and 1 VCPU ID respectively. |
| 543 | * The list of IDs should look like: {<vm_id>, 0, 1, 2, <vm_id>, 3}. |
| 544 | */ |
| 545 | CHECK(MAX_CPUS == 4); |
| 546 | EXPECT_EQ(ids_count, 6U); |
| 547 | EXPECT_EQ(lists_count, 2U); |
| 548 | EXPECT_EQ(lists_sizes[0], 3); |
| 549 | EXPECT_EQ(lists_sizes[1], 1); |
| 550 | |
| 551 | for (unsigned int i = 0; i < vcpu_count; i++) { |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 552 | got = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 553 | is_from_sp, i); |
| 554 | |
| 555 | /* |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 556 | * The first call to |
| 557 | * vm_notifications_partition_get_pending should also |
| 558 | * include the global notifications on the return. |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 559 | */ |
| 560 | ffa_notifications_bitmap_t to_check = |
| 561 | (i != 0) ? FFA_NOTIFICATION_MASK(i) |
| 562 | : FFA_NOTIFICATION_MASK(i) | global; |
| 563 | |
| 564 | EXPECT_EQ(got, to_check); |
| 565 | |
| 566 | EXPECT_EQ(notifications->per_vcpu[i].pending, 0); |
| 567 | EXPECT_EQ(notifications->per_vcpu[i].info_get_retrieved, 0); |
| 568 | } |
| 569 | |
| 570 | vm_unlock(¤t_vm_locked); |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * Validate change of state from 'vm_notifications_info_get_pending', when the |
| 575 | * list of IDs is full. |
| 576 | */ |
| 577 | TEST_F(vm, vm_notifications_info_get_full_per_vcpu) |
| 578 | { |
| 579 | struct_vm *current_vm = vm_find_index(0); |
| 580 | struct vm_locked current_vm_locked = vm_lock(current_vm); |
| 581 | struct notifications *notifications = |
| 582 | ¤t_vm->notifications.from_sp; |
| 583 | const bool is_from_vm = false; |
| 584 | ffa_notifications_bitmap_t got = 0; |
| 585 | |
| 586 | /* |
| 587 | * Following set of variables that are also expected to be used when |
| 588 | * handling ffa_notification_info_get. |
| 589 | * For this 'ids_count' has been initialized such that it indicates |
| 590 | * there is no space in the list for a per-vCPU notification (VM ID and |
| 591 | * VCPU ID). |
| 592 | */ |
| 593 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 594 | uint32_t ids_count = FFA_NOTIFICATIONS_INFO_GET_MAX_IDS - 1; |
| 595 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 596 | uint32_t lists_count = 10; |
| 597 | enum notifications_info_get_state current_state = INIT; |
| 598 | CHECK(vm_get_count() >= 2); |
| 599 | |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 600 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 601 | FFA_NOTIFICATION_MASK(1), 0, |
| 602 | true); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 603 | |
| 604 | /* Call function to get notifications info, with only per-vCPU set. */ |
| 605 | vm_notifications_info_get_pending(current_vm_locked, is_from_vm, ids, |
| 606 | &ids_count, lists_sizes, &lists_count, |
| 607 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 608 | ¤t_state); |
| 609 | |
| 610 | /* |
| 611 | * 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] | 612 | * insertion in the list, the |
| 613 | * 'vm_notifications_partition_get_pending' returns and changes |
| 614 | * list state to FULL. In this case returning, because it would need to |
| 615 | * add two IDs (VM ID and VCPU ID). |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 616 | */ |
| 617 | EXPECT_EQ(current_state, FULL); |
| 618 | EXPECT_EQ(ids_count, FFA_NOTIFICATIONS_INFO_GET_MAX_IDS - 1); |
| 619 | EXPECT_EQ(notifications->per_vcpu[0].info_get_retrieved, 0U); |
| 620 | |
| 621 | /* |
| 622 | * At this point there is still room for the information of a global |
| 623 | * notification (only VM ID to be added). Reset 'current_state' |
| 624 | * for the insertion to happen at the last position of the array. |
| 625 | */ |
| 626 | current_state = INIT; |
| 627 | |
| 628 | /* Setting global notification */ |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 629 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 630 | FFA_NOTIFICATION_MASK(2), 0, |
| 631 | false); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 632 | |
| 633 | vm_notifications_info_get_pending(current_vm_locked, is_from_vm, ids, |
| 634 | &ids_count, lists_sizes, &lists_count, |
| 635 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 636 | ¤t_state); |
| 637 | |
| 638 | /* |
| 639 | * Now List must be full, the set global notification must be part of |
| 640 | * 'info_get_retrieved', and the 'current_state' should be set to FULL |
| 641 | * due to the pending per-vCPU notification in VCPU 0. |
| 642 | */ |
| 643 | EXPECT_EQ(ids_count, FFA_NOTIFICATIONS_INFO_GET_MAX_IDS); |
| 644 | EXPECT_EQ(current_state, FULL); |
| 645 | EXPECT_EQ(notifications->global.info_get_retrieved, |
| 646 | FFA_NOTIFICATION_MASK(2)); |
| 647 | |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 648 | got = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 649 | is_from_vm, 0); |
| 650 | EXPECT_EQ(got, FFA_NOTIFICATION_MASK(1) | FFA_NOTIFICATION_MASK(2)); |
| 651 | |
| 652 | vm_unlock(¤t_vm_locked); |
| 653 | } |
| 654 | |
| 655 | TEST_F(vm, vm_notifications_info_get_full_global) |
| 656 | { |
| 657 | struct_vm *current_vm = vm_find_index(0); |
| 658 | struct vm_locked current_vm_locked = vm_lock(current_vm); |
| 659 | ffa_notifications_bitmap_t got; |
| 660 | struct notifications *notifications; |
| 661 | const bool is_from_vm = false; |
| 662 | /* |
| 663 | * Following set of variables that are also expected to be used when |
| 664 | * handling ffa_notification_info_get. |
| 665 | * For this 'ids_count' has been initialized such that it indicates |
| 666 | * there is no space in the list for a global notification (VM ID only). |
| 667 | */ |
| 668 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 669 | uint32_t ids_count = FFA_NOTIFICATIONS_INFO_GET_MAX_IDS; |
| 670 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 671 | uint32_t lists_count = 10; |
| 672 | enum notifications_info_get_state current_state = INIT; |
| 673 | |
| 674 | CHECK(vm_get_count() >= 1); |
| 675 | |
| 676 | current_vm = vm_find_index(0); |
| 677 | |
| 678 | notifications = ¤t_vm->notifications.from_sp; |
| 679 | |
| 680 | /* Set global notification. */ |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 681 | vm_notifications_partition_set_pending(current_vm_locked, is_from_vm, |
| 682 | FFA_NOTIFICATION_MASK(10), 0, |
| 683 | false); |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 684 | |
| 685 | /* Get notifications info for the given notifications. */ |
| 686 | vm_notifications_info_get_pending(current_vm_locked, is_from_vm, ids, |
| 687 | &ids_count, lists_sizes, &lists_count, |
| 688 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS, |
| 689 | ¤t_state); |
| 690 | |
| 691 | /* Expect 'info_get_retrieved' bitmap to be 0. */ |
| 692 | EXPECT_EQ(notifications->global.info_get_retrieved, 0U); |
| 693 | EXPECT_EQ(notifications->global.pending, FFA_NOTIFICATION_MASK(10)); |
| 694 | EXPECT_EQ(ids_count, FFA_NOTIFICATIONS_INFO_GET_MAX_IDS); |
| 695 | EXPECT_EQ(current_state, FULL); |
| 696 | |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 697 | got = vm_notifications_partition_get_pending(current_vm_locked, |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 698 | is_from_vm, 0); |
J-Alves | 9f74b93 | 2021-10-11 14:20:05 +0100 | [diff] [blame] | 699 | EXPECT_EQ(got, FFA_NOTIFICATION_MASK(10)); |
| 700 | |
J-Alves | 96f6e29 | 2021-06-08 17:32:40 +0100 | [diff] [blame] | 701 | vm_unlock(¤t_vm_locked); |
| 702 | } |
| 703 | |
J-Alves | f31940e | 2022-03-25 17:24:00 +0000 | [diff] [blame] | 704 | TEST_F(vm, vm_notifications_info_get_from_framework) |
| 705 | { |
| 706 | struct vm_locked vm_locked = vm_lock(vm_find_index(0)); |
| 707 | uint16_t ids[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 708 | uint32_t ids_count = 0; |
| 709 | uint32_t lists_sizes[FFA_NOTIFICATIONS_INFO_GET_MAX_IDS] = {0}; |
| 710 | uint32_t lists_count = 0; |
| 711 | |
| 712 | vm_notifications_framework_set_pending(vm_locked, 0x1U); |
| 713 | |
| 714 | /* Get notifications info for the given notifications. */ |
| 715 | vm_notifications_info_get(vm_locked, ids, &ids_count, lists_sizes, |
| 716 | &lists_count, |
| 717 | FFA_NOTIFICATIONS_INFO_GET_MAX_IDS); |
| 718 | |
| 719 | EXPECT_EQ(ids[0], vm_locked.vm->id); |
| 720 | EXPECT_EQ(ids_count, 1); |
| 721 | EXPECT_EQ(lists_sizes[0], 0); |
| 722 | EXPECT_EQ(lists_count, 1); |
| 723 | |
| 724 | EXPECT_EQ(vm_notifications_framework_get_pending(vm_locked), 0x1U); |
| 725 | |
| 726 | vm_unlock(&vm_locked); |
| 727 | } |
| 728 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 729 | } /* namespace */ |