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" { |
| 12 | #include "hf/mpool.h" |
| 13 | #include "hf/vm.h" |
| 14 | } |
| 15 | |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 16 | #include <list> |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 17 | #include <memory> |
| 18 | #include <span> |
| 19 | #include <vector> |
| 20 | |
| 21 | #include "mm_test.hh" |
| 22 | |
| 23 | namespace |
| 24 | { |
| 25 | using namespace ::std::placeholders; |
| 26 | |
| 27 | using ::testing::AllOf; |
| 28 | using ::testing::Each; |
| 29 | using ::testing::SizeIs; |
| 30 | |
| 31 | using struct_vm = struct vm; |
| 32 | |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 33 | constexpr size_t TEST_HEAP_SIZE = PAGE_SIZE * 32; |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 34 | const int TOP_LEVEL = arch_mm_stage2_max_level(); |
| 35 | |
| 36 | class vm : public ::testing::Test |
| 37 | { |
| 38 | void SetUp() override |
| 39 | { |
| 40 | /* |
| 41 | * TODO: replace with direct use of stdlib allocator so |
| 42 | * sanitizers are more effective. |
| 43 | */ |
| 44 | test_heap = std::make_unique<uint8_t[]>(TEST_HEAP_SIZE); |
| 45 | mpool_init(&ppool, sizeof(struct mm_page_table)); |
| 46 | mpool_add_chunk(&ppool, test_heap.get(), TEST_HEAP_SIZE); |
| 47 | } |
| 48 | |
| 49 | std::unique_ptr<uint8_t[]> test_heap; |
| 50 | |
| 51 | protected: |
| 52 | struct mpool ppool; |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 53 | |
| 54 | public: |
| 55 | static bool BootOrderBiggerThan(struct_vm *vm1, struct_vm *vm2) |
| 56 | { |
| 57 | return vm1->boot_order > vm2->boot_order; |
| 58 | } |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | /** |
| 62 | * If nothing is mapped, unmapping the hypervisor has no effect. |
| 63 | */ |
| 64 | TEST_F(vm, vm_unmap_hypervisor_not_mapped) |
| 65 | { |
| 66 | struct_vm *vm; |
| 67 | struct vm_locked vm_locked; |
| 68 | |
Raghu Krishnamurthy | cd1eceb | 2021-01-04 12:20:48 -0800 | [diff] [blame] | 69 | EXPECT_TRUE(vm_init_next(1, &ppool, &vm, false)); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 70 | vm_locked = vm_lock(vm); |
Raghu Krishnamurthy | 0132b51 | 2021-02-03 14:13:26 -0800 | [diff] [blame] | 71 | ASSERT_TRUE(mm_vm_init(&vm->ptable, vm->id, &ppool)); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 72 | EXPECT_TRUE(vm_unmap_hypervisor(vm_locked, &ppool)); |
| 73 | EXPECT_THAT( |
| 74 | mm_test::get_ptable(vm->ptable), |
| 75 | AllOf(SizeIs(4), Each(Each(arch_mm_absent_pte(TOP_LEVEL))))); |
| 76 | mm_vm_fini(&vm->ptable, &ppool); |
| 77 | vm_unlock(&vm_locked); |
| 78 | } |
| 79 | |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 80 | /** |
| 81 | * Validate the "boot_list" is created properly, according to vm's "boot_order" |
| 82 | * field. |
| 83 | */ |
| 84 | TEST_F(vm, vm_boot_order) |
| 85 | { |
| 86 | struct_vm *vm_cur; |
| 87 | std::list<struct_vm *> expected_final_order; |
| 88 | |
| 89 | EXPECT_FALSE(vm_get_first_boot()); |
| 90 | |
| 91 | /* |
| 92 | * Insertion when no call to "vm_update_boot" has been made yet. |
| 93 | * The "boot_list" is expected to be empty. |
| 94 | */ |
Raghu Krishnamurthy | cd1eceb | 2021-01-04 12:20:48 -0800 | [diff] [blame] | 95 | EXPECT_TRUE(vm_init_next(1, &ppool, &vm_cur, false)); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 96 | vm_cur->boot_order = 1; |
| 97 | vm_update_boot(vm_cur); |
| 98 | expected_final_order.push_back(vm_cur); |
| 99 | |
| 100 | EXPECT_EQ(vm_get_first_boot()->id, vm_cur->id); |
| 101 | |
| 102 | /* Insertion at the head of the boot list */ |
Raghu Krishnamurthy | cd1eceb | 2021-01-04 12:20:48 -0800 | [diff] [blame] | 103 | EXPECT_TRUE(vm_init_next(1, &ppool, &vm_cur, false)); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 104 | vm_cur->boot_order = 3; |
| 105 | vm_update_boot(vm_cur); |
| 106 | expected_final_order.push_back(vm_cur); |
| 107 | |
| 108 | EXPECT_EQ(vm_get_first_boot()->id, vm_cur->id); |
| 109 | |
| 110 | /* Insertion of two in the middle of the boot list */ |
| 111 | for (int i = 0; i < 2; i++) { |
Raghu Krishnamurthy | cd1eceb | 2021-01-04 12:20:48 -0800 | [diff] [blame] | 112 | EXPECT_TRUE(vm_init_next(1, &ppool, &vm_cur, false)); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 113 | vm_cur->boot_order = 2; |
| 114 | vm_update_boot(vm_cur); |
| 115 | expected_final_order.push_back(vm_cur); |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * Insertion in the end of the list. |
| 120 | * This tests shares the data with "vm_unmap_hypervisor_not_mapped". |
| 121 | * As such, a VM is expected to have been initialized before this |
| 122 | * test, with ID 1 and boot_order 0. |
| 123 | */ |
| 124 | vm_cur = vm_find(1); |
| 125 | EXPECT_FALSE(vm_cur == NULL); |
| 126 | vm_update_boot(vm_cur); |
| 127 | expected_final_order.push_back(vm_cur); |
| 128 | |
| 129 | /* |
| 130 | * Number of VMs initialized should be the same as in the |
| 131 | * "expected_final_order", before the final verification. |
| 132 | */ |
| 133 | EXPECT_EQ(expected_final_order.size(), vm_get_count()) |
| 134 | << "Something went wrong with the test itself...\n"; |
| 135 | |
| 136 | /* Sort "expected_final_order" by "boot_order" field */ |
| 137 | expected_final_order.sort(vm::BootOrderBiggerThan); |
| 138 | |
| 139 | std::list<struct_vm *>::iterator it; |
| 140 | for (it = expected_final_order.begin(), vm_cur = vm_get_first_boot(); |
| 141 | it != expected_final_order.end() && vm_cur != NULL; |
| 142 | it++, vm_cur = vm_cur->next_boot) { |
| 143 | EXPECT_EQ((*it)->id, vm_cur->id); |
| 144 | } |
| 145 | } |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * Validates updates and check functions for binding notifications to endpoints. |
| 149 | */ |
| 150 | TEST_F(vm, vm_notifications_bind_diff_senders) |
| 151 | { |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 152 | struct_vm *current_vm = nullptr; |
| 153 | struct vm_locked current_vm_locked; |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 154 | std::vector<struct_vm *> dummy_senders; |
| 155 | ffa_notifications_bitmap_t bitmaps[] = { |
| 156 | 0x00000000FFFFFFFFU, 0xFFFFFFFF00000000U, 0x0000FFFFFFFF0000U}; |
| 157 | bool is_from_vm = true; |
| 158 | |
| 159 | /* For the subsequent tests three VMs are used. */ |
| 160 | CHECK(vm_get_count() >= 3); |
| 161 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 162 | current_vm = vm_find_index(0); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 163 | |
| 164 | dummy_senders.push_back(vm_find_index(1)); |
| 165 | dummy_senders.push_back(vm_find_index(2)); |
| 166 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 167 | current_vm_locked = vm_lock(current_vm); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 168 | |
| 169 | for (unsigned int i = 0; i < 2; i++) { |
| 170 | /* Validate bindings condition after initialization. */ |
| 171 | EXPECT_TRUE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 172 | current_vm_locked, is_from_vm, HF_INVALID_VM_ID, |
| 173 | bitmaps[i], false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 174 | |
| 175 | /* |
| 176 | * Validate bind related operations. For this test considering |
| 177 | * only global notifications. |
| 178 | */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 179 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 180 | dummy_senders[i]->id, |
| 181 | bitmaps[i], false); |
| 182 | |
| 183 | EXPECT_TRUE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 184 | current_vm_locked, is_from_vm, dummy_senders[i]->id, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 185 | bitmaps[i], false)); |
| 186 | |
| 187 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 188 | current_vm_locked, is_from_vm, dummy_senders[1 - i]->id, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 189 | bitmaps[i], false)); |
| 190 | |
| 191 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 192 | current_vm_locked, is_from_vm, dummy_senders[i]->id, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 193 | bitmaps[1 - i], false)); |
| 194 | |
| 195 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 196 | current_vm_locked, is_from_vm, dummy_senders[i]->id, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 197 | bitmaps[2], false)); |
| 198 | } |
| 199 | |
| 200 | /** Clean up bind for other tests. */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 201 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 202 | bitmaps[0], false); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 203 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 204 | bitmaps[1], false); |
| 205 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 206 | vm_unlock(¤t_vm_locked); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Validates updates and check functions for binding notifications, namely the |
| 211 | * configuration of bindings of global and per VCPU notifications. |
| 212 | */ |
| 213 | TEST_F(vm, vm_notification_bind_per_vcpu_vs_global) |
| 214 | { |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 215 | struct_vm *current_vm; |
| 216 | struct vm_locked current_vm_locked; |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 217 | struct_vm *dummy_sender; |
| 218 | ffa_notifications_bitmap_t global = 0x00000000FFFFFFFFU; |
| 219 | ffa_notifications_bitmap_t per_vcpu = ~global; |
| 220 | bool is_from_vm = true; |
| 221 | |
| 222 | CHECK(vm_get_count() >= 2); |
| 223 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 224 | current_vm = vm_find_index(0); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 225 | |
| 226 | dummy_sender = vm_find_index(1); |
| 227 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 228 | current_vm_locked = vm_lock(current_vm); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 229 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 230 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 231 | dummy_sender->id, global, false); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 232 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 233 | dummy_sender->id, per_vcpu, true); |
| 234 | |
| 235 | /* Check validation of global notifications bindings. */ |
| 236 | EXPECT_TRUE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 237 | current_vm_locked, is_from_vm, dummy_sender->id, global, |
| 238 | false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 239 | |
| 240 | /* Check validation of per vcpu notifications bindings. */ |
| 241 | EXPECT_TRUE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 242 | current_vm_locked, is_from_vm, dummy_sender->id, per_vcpu, |
| 243 | true)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 244 | |
| 245 | /** |
| 246 | * Check that global notifications are not validated as per VCPU, and |
| 247 | * vice-versa. |
| 248 | */ |
| 249 | EXPECT_FALSE(vm_notifications_validate_binding( |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 250 | current_vm_locked, is_from_vm, dummy_sender->id, global, true)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 251 | EXPECT_FALSE(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, per_vcpu, |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 253 | false)); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 254 | EXPECT_FALSE(vm_notifications_validate_binding( |
| 255 | current_vm_locked, is_from_vm, dummy_sender->id, |
| 256 | global | per_vcpu, true)); |
| 257 | EXPECT_FALSE(vm_notifications_validate_binding( |
| 258 | current_vm_locked, is_from_vm, dummy_sender->id, |
| 259 | global | per_vcpu, false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 260 | |
| 261 | /** Undo the bindings */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 262 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0, |
| 263 | global, false); |
| 264 | EXPECT_TRUE(vm_notifications_validate_binding( |
| 265 | current_vm_locked, is_from_vm, 0, global, false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 266 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 267 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0, |
| 268 | per_vcpu, false); |
| 269 | EXPECT_TRUE(vm_notifications_validate_binding( |
| 270 | current_vm_locked, is_from_vm, 0, per_vcpu, false)); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 271 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 272 | vm_unlock(¤t_vm_locked); |
J-Alves | 60eaff9 | 2021-05-27 14:54:41 +0100 | [diff] [blame] | 273 | } |
| 274 | |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 275 | /** |
| 276 | * Validates accesses to notifications bitmaps. |
| 277 | */ |
| 278 | TEST_F(vm, vm_notifications_set_and_get) |
| 279 | { |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 280 | struct_vm *current_vm; |
| 281 | struct vm_locked current_vm_locked; |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 282 | struct_vm *dummy_sender; |
| 283 | ffa_notifications_bitmap_t global = 0x00000000FFFFFFFFU; |
| 284 | ffa_notifications_bitmap_t per_vcpu = ~global; |
| 285 | ffa_notifications_bitmap_t ret; |
| 286 | const unsigned int vcpu_idx = 1; |
| 287 | struct notifications *notifications; |
| 288 | const bool is_from_vm = true; |
| 289 | |
| 290 | CHECK(vm_get_count() >= 2); |
| 291 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 292 | current_vm = vm_find_index(0); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 293 | dummy_sender = vm_find_index(1); |
| 294 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 295 | notifications = ¤t_vm->notifications.from_vm; |
| 296 | current_vm_locked = vm_lock(current_vm); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 297 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 298 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 299 | dummy_sender->id, global, false); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 300 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 301 | dummy_sender->id, per_vcpu, true); |
| 302 | |
| 303 | /* |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 304 | * Validate get notifications bitmap for global notifications. |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 305 | */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 306 | vm_notifications_set(current_vm_locked, is_from_vm, global, 0ull, |
| 307 | false); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 308 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 309 | ret = vm_notifications_get_pending_and_clear(current_vm_locked, |
| 310 | is_from_vm, 0ull); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 311 | EXPECT_EQ(ret, global); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 312 | EXPECT_EQ(notifications->global.pending, 0ull); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 313 | |
| 314 | /* |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 315 | * Validate get notifications bitmap for per-vCPU notifications. |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 316 | */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 317 | vm_notifications_set(current_vm_locked, is_from_vm, per_vcpu, vcpu_idx, |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 318 | true); |
| 319 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 320 | ret = vm_notifications_get_pending_and_clear(current_vm_locked, |
| 321 | is_from_vm, vcpu_idx); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 322 | EXPECT_EQ(ret, per_vcpu); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 323 | EXPECT_EQ(notifications->per_vcpu[vcpu_idx].pending, 0ull); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 324 | |
| 325 | /* |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 326 | * Validate that getting notifications for a specific vCPU also returns |
| 327 | * global notifications. |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 328 | */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 329 | vm_notifications_set(current_vm_locked, is_from_vm, per_vcpu, vcpu_idx, |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 330 | true); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 331 | vm_notifications_set(current_vm_locked, is_from_vm, global, 0ull, |
| 332 | false); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 333 | |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 334 | ret = vm_notifications_get_pending_and_clear(current_vm_locked, |
| 335 | is_from_vm, vcpu_idx); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 336 | EXPECT_EQ(ret, per_vcpu | global); |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 337 | EXPECT_EQ(notifications->per_vcpu[vcpu_idx].pending, 0ull); |
| 338 | EXPECT_EQ(notifications->global.pending, 0ull); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 339 | |
| 340 | /** Undo the binding */ |
J-Alves | d3e8162 | 2021-10-05 14:55:57 +0100 | [diff] [blame^] | 341 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0ull, |
| 342 | global, false); |
| 343 | vm_notifications_update_bindings(current_vm_locked, is_from_vm, 0ull, |
| 344 | per_vcpu, true); |
| 345 | vm_unlock(¤t_vm_locked); |
J-Alves | ce2f8d3 | 2021-06-10 18:30:21 +0100 | [diff] [blame] | 346 | } |
| 347 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 348 | } /* namespace */ |