From 54bf8268a9c3ab786b262e92b8d574c021a714e0 Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Fri, 4 Dec 2026 21:08:05 -0500 Subject: [PATCH] fex: keep aio keys, cancels and reaped events native for copied control blocks Guest aio_key is no longer cleared before dispatch: the slot is probed with a same-value write and only the first n accepted copies get key 0 after the host io_submit returns n. io_cancel redirects to a copy only when the guest block is readable and its key is 0, so unreadable blocks fault in the kernel as before. io_getevents and io_pgetevents reap into emulator storage, translate and release copies there, then copy the events out, returning -EFAULT if that fails. A successful io_setup clears the ring header magic so userspace ring reapers fall back to io_getevents, where copies are translated and released. --- ...uest-memory-above-host-address-limit.patch | 100 ++++++++++++----- tools/tests/test_fex_guest_high_memory.py | 106 ++++++++++++++++-- 2 files changed, 170 insertions(+), 36 deletions(-) diff --git a/tools/fex/patches/0027-fixed-guest-memory-above-host-address-limit.patch b/tools/fex/patches/0027-fixed-guest-memory-above-host-address-limit.patch index 31b4aafa8d..544f10ab19 100644 --- a/tools/fex/patches/0027-fixed-guest-memory-above-host-address-limit.patch +++ b/tools/fex/patches/0027-fixed-guest-memory-above-host-address-limit.patch @@ -13,15 +13,15 @@ writes to code in them invalidate translated blocks. Builds on StonkGuy's anti-cheat emulation from https://github.com/StonkGuy/FEX (eac-2611, MIT). --- Source/Tools/LinuxEmulation/CMakeLists.txt | 1 + - .../LinuxSyscalls/GuestHighMemory.cpp | 2464 +++++++++++++++++ - .../LinuxSyscalls/GuestHighMemory.h | 57 + + .../LinuxSyscalls/GuestHighMemory.cpp | 2503 +++++++++++++++++ + .../LinuxSyscalls/GuestHighMemory.h | 60 + .../LinuxSyscalls/SignalDelegator.cpp | 5 + .../LinuxEmulation/LinuxSyscalls/Syscalls.cpp | 53 +- .../LinuxSyscalls/Syscalls/Memory.cpp | 30 + .../LinuxSyscalls/SyscallsSMCTracking.cpp | 61 +- .../LinuxSyscalls/ThreadManager.cpp | 2 + .../LinuxSyscalls/ThreadManager.h | 34 + - 9 files changed, 2677 insertions(+), 30 deletions(-) + 9 files changed, 2719 insertions(+), 30 deletions(-) create mode 100644 Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.cpp create mode 100644 Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.h @@ -39,10 +39,10 @@ index 3f02104..acf4c4c 100644 LinuxSyscalls/SyscallsVMATracking.cpp diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.cpp new file mode 100644 -index 0000000..df71a2e +index 0000000..414f6e7 --- /dev/null +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.cpp -@@ -0,0 +1,2464 @@ +@@ -0,0 +1,2503 @@ +#include "LinuxSyscalls/GuestHighMemory.h" +#include "LinuxSyscalls/Syscalls.h" +#include "LinuxSyscalls/SignalDelegator.h" @@ -1577,11 +1577,6 @@ index 0000000..df71a2e + return 0; + } + -+ bool CopyFromGuest(void* Value, uint64_t Address, uint64_t Size) { -+ uint64_t Host {}; -+ return TranslateRange(Address, Size, &Host) && FaultSafeUserMemAccess::CopyFromUser(Value, reinterpret_cast(Host), Size) == 0; -+ } -+ + bool CopyToGuest(uint64_t Address, const void* Value, uint64_t Size) { + uint64_t Host {}; + return TranslateRange(Address, Size, &Host) && FaultSafeUserMemAccess::CopyToUser(reinterpret_cast(Host), Value, Size) == 0; @@ -1861,7 +1856,10 @@ index 0000000..df71a2e + } + + uint64_t CancelTarget(uint64_t Context, uint64_t Guest, uint64_t Host) { -+ if (IoCopyCount.load(std::memory_order_acquire) == 0) { ++ uint32_t Key {}; ++ if (IoCopyCount.load(std::memory_order_acquire) == 0 || ++ FaultSafeUserMemAccess::CopyFromUser(&Key, reinterpret_cast(Host + offsetof(IoControlBlock, Key)), sizeof(Key)) != 0 || ++ Key != 0) { + return Host; + } + auto lk = FEXCore::MaskSignalsAndLockMutex(IoCopyMutex, ~HeldSignalMask()); @@ -1873,10 +1871,44 @@ index 0000000..df71a2e + return Host; + } + ++ constexpr uint64_t MaxIoEvents = 65536; ++ constexpr uint64_t IoEventWords = IoEventSize / sizeof(uint64_t); ++ constexpr uint64_t AioRingMagicOffset = 16; ++ constexpr uint32_t AioRingMagic = 0xa10a10a1; ++ ++ void ClearRingMagic(uint64_t ContextPointer) { ++ uint64_t Ring {}; ++ uint32_t Magic {}; ++ if (FaultSafeUserMemAccess::CopyFromUser(&Ring, reinterpret_cast(ContextPointer), sizeof(Ring)) != 0 || Ring == 0 || ++ FaultSafeUserMemAccess::CopyFromUser(&Magic, reinterpret_cast(Ring + AioRingMagicOffset), sizeof(Magic)) != 0 || ++ Magic != AioRingMagic) { ++ return; ++ } ++ Magic = 0; ++ static_cast(FaultSafeUserMemAccess::CopyToUser(reinterpret_cast(Ring + AioRingMagicOffset), &Magic, sizeof(Magic))); ++ } ++ + void TrackIoCopies(uint64_t Syscall, const uint64_t* Guest, uint64_t* Args, ArgumentStorage* Storage) { + switch (Syscall) { ++ case x64::SYSCALL_x64_io_setup: Storage->SetupContext = Args[1]; break; + case x64::SYSCALL_x64_io_getevents: -+ case x64::SYSCALL_x64_io_pgetevents: Storage->Events = Guest[3]; break; ++ case x64::SYSCALL_x64_io_pgetevents: { ++ const auto Wanted = static_cast(Args[2]); ++ if (Wanted <= 0 || Guest[3] == 0) { ++ break; ++ } ++ const auto Events = std::min(Wanted, MaxIoEvents); ++ if (static_cast(Wanted) > Events) { ++ if (static_cast(Args[1]) > static_cast(Events) && static_cast(Args[1]) <= Wanted) { ++ Args[1] = Events; ++ } ++ Args[2] = Events; ++ } ++ Storage->EventBuffer.resize(Events * IoEventWords); ++ Storage->Events = Guest[3]; ++ Args[3] = reinterpret_cast(Storage->EventBuffer.data()); ++ break; ++ } + case x64::SYSCALL_x64_io_cancel: Args[1] = CancelTarget(Args[0], Guest[1], Args[1]); break; + case x64::SYSCALL_x64_io_destroy: + Storage->DestroyedContext = Args[0]; @@ -1898,6 +1930,7 @@ index 0000000..df71a2e + return 0; + } + Storage->IoCopies.reserve(Blocks); ++ Storage->IoKeys.reserve(Blocks); + bool Refused = false; + bool Changed = false; + uint64_t Vectors = 0; @@ -1922,22 +1955,21 @@ index 0000000..df71a2e + } + uint64_t Submitted = Host; + if (Buffer != Block.Buffer) { -+ Block.Key = 0; ++ if (FaultSafeUserMemAccess::CopyToUser(reinterpret_cast(Host + offsetof(IoControlBlock, Key)), &Block.Key, sizeof(Block.Key)) != 0) { ++ break; ++ } + Block.Buffer = Buffer; + Submitted = ClaimIoCopy(Block, Context, List[Usable]); + if (Submitted == 0) { + Refused = true; + break; + } -+ if (FaultSafeUserMemAccess::CopyToUser(reinterpret_cast(Host + offsetof(IoControlBlock, Key)), &Block.Key, sizeof(Block.Key)) != 0) { -+ ReleaseIoCopies(&Submitted, 1); -+ break; -+ } + } + if (Vectored) { + Vectors += Block.Bytes; + } + Storage->IoCopies.push_back(Submitted != Host ? Submitted : 0); ++ Storage->IoKeys.push_back(Submitted != Host ? Host + offsetof(IoControlBlock, Key) : 0); + Changed = Changed || Submitted != List[Usable]; + List[Usable] = Submitted; + } @@ -2266,8 +2298,17 @@ index 0000000..df71a2e + } Socket {std::exchange(Storage->Socket, -1)}; + if (!Storage->IoCopies.empty()) { + const auto Submitted = FEX::HLE::HasSyscallError(Result) ? 0 : std::min(Result, Storage->IoCopies.size()); ++ const uint32_t Accepted {}; ++ for (uint64_t i = 0; i < Submitted; ++i) { ++ if (Storage->IoKeys[i] != 0) { ++ static_cast(FaultSafeUserMemAccess::CopyToUser(reinterpret_cast(Storage->IoKeys[i]), &Accepted, sizeof(Accepted))); ++ } ++ } + ReleaseIoCopies(Storage->IoCopies.data() + Submitted, Storage->IoCopies.size() - Submitted); + } ++ if (Storage->SetupContext != 0 && Result == 0) { ++ ClearRingMagic(Storage->SetupContext); ++ } + if (Storage->Destroying && Result == 0) { + ReleaseContext(Storage->DestroyedContext); + } @@ -2278,16 +2319,14 @@ index 0000000..df71a2e + if (FEX::HLE::HasSyscallError(Result)) { + return Result; + } -+ if (Storage->Events != 0 && (Count.load(std::memory_order_acquire) != 0 || IoCopyCount.load(std::memory_order_acquire) != 0)) { -+ for (uint64_t i = 0; i < Result; ++i) { -+ const auto Field = Storage->Events + i * IoEventSize + IoEventObjectOffset; -+ uint64_t Object {}; -+ if (!CopyFromGuest(&Object, Field, sizeof(Object))) { -+ break; -+ } -+ if (const auto Guest = ReportedObject(Object); Guest != Object) { -+ static_cast(CopyToGuest(Field, &Guest, sizeof(Guest))); -+ } ++ if (Storage->Events != 0) { ++ const auto Reaped = std::min(Result, Storage->EventBuffer.size() / IoEventWords); ++ for (uint64_t i = 0; i < Reaped; ++i) { ++ auto& Object = Storage->EventBuffer[i * IoEventWords + IoEventObjectOffset / sizeof(uint64_t)]; ++ Object = ReportedObject(Object); ++ } ++ if (Reaped != 0 && !CopyToGuest(Storage->Events, Storage->EventBuffer.data(), Reaped * IoEventSize)) { ++ return -EFAULT; + } + } + if (Storage->GuestMessages != 0) { @@ -2509,10 +2548,10 @@ index 0000000..df71a2e +} // namespace FEX::HLE::GuestHighMemory diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.h new file mode 100644 -index 0000000..9091b27 +index 0000000..b5a8ee3 --- /dev/null +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.h -@@ -0,0 +1,57 @@ +@@ -0,0 +1,60 @@ +#pragma once + +#include @@ -2547,7 +2586,10 @@ index 0000000..9091b27 + uint64_t GuestCapabilityHeader {}; + fextl::vector Words; + fextl::vector IoCopies; ++ fextl::vector IoKeys; ++ fextl::vector EventBuffer; + uint64_t Events {}; ++ uint64_t SetupContext {}; + uint64_t DestroyedContext {}; + bool Destroying {}; +}; diff --git a/tools/tests/test_fex_guest_high_memory.py b/tools/tests/test_fex_guest_high_memory.py index cb3801d380..418d416d4a 100644 --- a/tools/tests/test_fex_guest_high_memory.py +++ b/tools/tests/test_fex_guest_high_memory.py @@ -685,7 +685,6 @@ int main() { Vectored.Buffer = reinterpret_cast(Scatter); Vectored.Bytes = 2; TestIocb ReadExpected = ReadBlock; - ReadExpected.Key = 0; const TestIocb VectoredExpected = Vectored; auto GuestBlocksUntouched = [&] { return std::memcmp(&ReadBlock, &ReadExpected, sizeof(TestIocb)) == 0 && std::memcmp(&Vectored, &VectoredExpected, sizeof(TestIocb)) == 0; @@ -696,6 +695,9 @@ int main() { int64_t Result; int64_t Result2; }; + auto Deliver = [](const uint64_t* Args, const void* Events, size_t Size) { + static_cast(FEX::HLE::FaultSafeUserMemAccess::CopyToUser(reinterpret_cast(Args[3]), Events, Size)); + }; uint64_t Submitted[2] = {reinterpret_cast(&ReadBlock), reinterpret_cast(&Vectored)}; ArgumentStorage Submit; uint64_t SubmitArgs[6] = {1, 2, reinterpret_cast(Submitted), 0, 0, 0}; @@ -709,7 +711,7 @@ int main() { const auto* SentVector = reinterpret_cast(Sent[1]); Show("io_submit_private_blocks", SentRead != &ReadBlock && SentVector != &Vectored); Show("io_submit_buffer", SentRead->Buffer - Base); - Show("io_submit_fields_kept", SentRead->Data == 0x77 && SentRead->Bytes == 64 && SentRead->Key == 0); + Show("io_submit_fields_kept", SentRead->Data == 0x77 && SentRead->Bytes == 64 && SentRead->Key == 5); const auto* HostScatter = reinterpret_cast(SentVector->Buffer); Show("io_submit_vector_copied", HostScatter != Scatter); Show("io_submit_vector_base", reinterpret_cast(HostScatter[0].iov_base) - Base); @@ -718,6 +720,8 @@ int main() { Show("io_submit_guest_untouched", GuestBlocksUntouched()); Show("io_submit_copies", IoCopyCount.load() - CopiesBefore); FinishSyscallArguments(2, &Submit); + Show("io_submit_accepted_key", ReadBlock.Key); + ReadExpected.Key = 0; Show("io_submit_copies_kept", IoCopyCount.load() - CopiesBefore); Show("io_submit_finished_untouched", GuestBlocksUntouched()); @@ -735,6 +739,8 @@ int main() { ArgumentStorage ReapCopies; uint64_t ReapCopiesArgs[6] = {1, 1, 3, reinterpret_cast(Reaped), 0, 0}; Call(Sys::SYSCALL_x64_io_getevents, ReapCopiesArgs, &ReapCopies); + Show("io_getevents_host_buffer", ReapCopiesArgs[3] == reinterpret_cast(ReapCopies.EventBuffer.data())); + Deliver(ReapCopiesArgs, Reaped, sizeof(Reaped)); FinishSyscallArguments(3, &ReapCopies); Show("io_getevents_copy_object", Reaped[0].Object == reinterpret_cast(&ReadBlock)); Show("io_getevents_vector_object", Reaped[1].Object == reinterpret_cast(&Vectored)); @@ -802,11 +808,59 @@ int main() { Show("io_submit_first_bad_result", Call(Sys::SYSCALL_x64_io_submit, FirstBadArgs, &FirstBad)); FinishSyscallArguments(static_cast(-EFAULT), &FirstBad); Show("io_submit_first_bad_copies", IoCopyCount.load() - CopiesBefore); + TestIocb KeyFirst = ReadBlock; + KeyFirst.Key = 5; + TestIocb KeySecond = ReadBlock; + KeySecond.Key = 6; + uint64_t KeyList[2] = {reinterpret_cast(&KeyFirst), reinterpret_cast(&KeySecond)}; + ArgumentStorage KeySubmit; + uint64_t KeySubmitArgs[6] = {4, 2, reinterpret_cast(KeyList), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_submit, KeySubmitArgs, &KeySubmit); + const uint64_t KeyFirstSent = reinterpret_cast(KeySubmitArgs[2])[0]; + Show("io_submit_keys_prepared", KeyFirst.Key == 5 && KeySecond.Key == 6); + TestEvent KeyCancelEvent {}; + ArgumentStorage EarlyCancel; + uint64_t EarlyCancelArgs[6] = {4, reinterpret_cast(&KeyFirst), reinterpret_cast(&KeyCancelEvent), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_cancel, EarlyCancelArgs, &EarlyCancel); + Show("io_cancel_keyed_native", EarlyCancelArgs[1] == reinterpret_cast(&KeyFirst)); + FinishSyscallArguments(1, &KeySubmit); + Show("io_submit_key_accepted", KeyFirst.Key); + Show("io_submit_key_after_rejected", KeySecond.Key); + Show("io_submit_key_rejected_released", IoCopyCount.load() - CopiesBefore); + ArgumentStorage LateCancel; + uint64_t LateCancelArgs[6] = {4, reinterpret_cast(&KeyFirst), reinterpret_cast(&KeyCancelEvent), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_cancel, LateCancelArgs, &LateCancel); + Show("io_cancel_accepted_private", LateCancelArgs[1] == KeyFirstSent); + auto* SealedEvents = static_cast(mmap(nullptr, Page, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + ArgumentStorage SealedReap; + uint64_t SealedReapArgs[6] = {4, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, SealedReapArgs, &SealedReap); + const TestEvent SealedEvent {0x77, KeyFirstSent, 64, 0}; + Deliver(SealedReapArgs, &SealedEvent, sizeof(SealedEvent)); + Show("io_getevents_sealed_result", FinishSyscallArguments(1, &SealedReap)); + Show("io_getevents_sealed_released", IoCopyCount.load() - CopiesBefore); + munmap(SealedEvents, Page); + uint32_t Ring[8] = {0, 128, 0, 0, 0xa10a10a1, 1, 0, 32}; + uint64_t RingContext = reinterpret_cast(Ring); + ArgumentStorage Setup; + uint64_t SetupArgs[6] = {128, reinterpret_cast(&RingContext), 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_setup, SetupArgs, &Setup); + FinishSyscallArguments(0, &Setup); + Show("io_setup_magic", Ring[4]); + Show("io_setup_header_kept", Ring[0] == 0 && Ring[1] == 128 && Ring[2] == 0 && Ring[3] == 0 && Ring[5] == 1 && Ring[6] == 0 && Ring[7] == 32); + uint32_t KeptRing[8] = {0, 128, 0, 0, 0xa10a10a1, 1, 0, 32}; + uint64_t KeptContext = reinterpret_cast(KeptRing); + ArgumentStorage FailedSetup; + uint64_t FailedSetupArgs[6] = {128, reinterpret_cast(&KeptContext), 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_setup, FailedSetupArgs, &FailedSetup); + FinishSyscallArguments(static_cast(-EINVAL), &FailedSetup); + Show("io_setup_failed_magic", KeptRing[4]); TestEvent Completions[2] = {{7, Base + 1536, 16, 0}, {8, Base + 1536, 16, 0}}; ArgumentStorage Reap; uint64_t ReapArgs[6] = {1, 1, 2, reinterpret_cast(Completions), 0, 0}; Show("io_getevents_result", Call(Sys::SYSCALL_x64_io_getevents, ReapArgs, &Reap)); + Deliver(ReapArgs, Completions, sizeof(Completions)); FinishSyscallArguments(1, &Reap); Show("io_getevents_object", Completions[0].Object - Single); Show("io_getevents_unreported", Completions[1].Object - Base); @@ -1121,6 +1175,10 @@ int main() { Show("io_submit_high_copy_private", HighSent != BlocksHost && FindIoCopyLocked(HighSent) != nullptr); Show("io_submit_high_copy_vector", reinterpret_cast(reinterpret_cast(HighSent)->Buffer)[0].iov_base == reinterpret_cast(Base + 800)); Show("io_submit_high_copy_untouched", std::memcmp(HighIocb, &HighExpected, sizeof(TestIocb)) == 0); + ArgumentStorage HighCancel; + uint64_t HighCancelArgs[6] = {1, Blocks, reinterpret_cast(&CancelEvent), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_cancel, HighCancelArgs, &HighCancel); + Show("io_cancel_high_private", HighCancelArgs[1] == HighSent); Show("io_submit_high_copy_hidden", Protect(Blocks, Page, PROT_NONE)); uint64_t SealedProbe = 0; auto HiddenRead = [&] { return FEX::HLE::FaultSafeUserMemAccess::CopyFromUser(&SealedProbe, &HighIocb->Buffer, sizeof(SealedProbe)) != 0; }; @@ -1128,14 +1186,15 @@ int main() { ProtectCalls = 0; FinishSyscallArguments(1, &HighCopy); Show("io_submit_high_copy_sealed", HiddenRead() && HiddenWrite()); - ArgumentStorage HighCancel; - uint64_t HighCancelArgs[6] = {1, Blocks, reinterpret_cast(&CancelEvent), 0, 0, 0}; - Call(Sys::SYSCALL_x64_io_cancel, HighCancelArgs, &HighCancel); - Show("io_cancel_high_private", HighCancelArgs[1] == HighSent); + ArgumentStorage HiddenCancel; + uint64_t HiddenCancelArgs[6] = {1, Blocks, reinterpret_cast(&CancelEvent), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_cancel, HiddenCancelArgs, &HiddenCancel); + Show("io_cancel_hidden_native", HiddenCancelArgs[1] == BlocksHost); TestEvent HighReaped[1] = {{0x99, HighSent, 16, 0}}; ArgumentStorage HighReap; uint64_t HighReapArgs[6] = {1, 1, 1, reinterpret_cast(HighReaped), 0, 0}; Call(Sys::SYSCALL_x64_io_getevents, HighReapArgs, &HighReap); + Deliver(HighReapArgs, HighReaped, sizeof(HighReaped)); FinishSyscallArguments(1, &HighReap); Show("io_getevents_high_object", HighReaped[0].Object - Blocks); Show("io_getevents_high_sealed", HiddenRead() && HiddenWrite()); @@ -1189,7 +1248,16 @@ int main() { ArgumentStorage QuietReap; uint64_t QuietReapArgs[6] = {1, 1, 1, reinterpret_cast(QuietReaped), 0, 0}; Call(Sys::SYSCALL_x64_io_getevents, QuietReapArgs, &QuietReap); + Show("low_iocb_quiet_host_buffer", QuietReapArgs[3] == reinterpret_cast(QuietReap.EventBuffer.data())); + Deliver(QuietReapArgs, QuietReaped, sizeof(QuietReaped)); FinishSyscallArguments(1, &QuietReap); + uint32_t QuietRing[8] = {0, 64, 0, 0, 0xa10a10a1, 1, 0, 32}; + uint64_t QuietRingContext = reinterpret_cast(QuietRing); + ArgumentStorage QuietSetup; + uint64_t QuietSetupArgs[6] = {64, reinterpret_cast(&QuietRingContext), 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_setup, QuietSetupArgs, &QuietSetup); + FinishSyscallArguments(0, &QuietSetup); + Show("low_quiet_setup_magic", QuietRing[4]); Count.store(Regions); Show("low_iocb_quiet_object", QuietReaped[0].Object == reinterpret_cast(LowBlock)); Show("low_iocb_quiet_freed", IoCopyCount.load() - CopiesBefore); @@ -1921,7 +1989,8 @@ class GuestHighMemoryTest(unittest.TestCase): self.assertEqual(self.value("io_submit_vector_copied"), 1) self.assertEqual(self.value("io_submit_vector_base"), 800) self.assertEqual(self.value("io_submit_vector_low"), 1) - self.assertEqual(self.value("io_submit_guest_key"), 0) + self.assertEqual(self.value("io_submit_guest_key"), 5) + self.assertEqual(self.value("io_submit_accepted_key"), 0) self.assertEqual(self.value("io_submit_copies"), 2) self.assertEqual(self.value("io_submit_copies_kept"), 2) self.assertEqual(self.value("io_submit_high_result"), 0) @@ -1971,6 +2040,29 @@ class GuestHighMemoryTest(unittest.TestCase): self.assertEqual(self.value("io_cancel_private"), 1) self.assertEqual(self.value("io_cancel_other_context"), 1) self.assertEqual(self.value("io_cancel_high_private"), 1) + self.assertEqual(self.value("io_cancel_accepted_private"), 1) + + def test_aio_cancel_on_unreadable_or_unkeyed_blocks_stays_native(self): + self.assertEqual(self.value("io_cancel_hidden_native"), 1) + self.assertEqual(self.value("io_cancel_keyed_native"), 1) + + def test_aio_keys_clear_only_for_accepted_submissions(self): + self.assertEqual(self.value("io_submit_keys_prepared"), 1) + self.assertEqual(self.value("io_submit_key_accepted"), 0) + self.assertEqual(self.value("io_submit_key_after_rejected"), 6) + self.assertEqual(self.value("io_submit_key_rejected_released"), 1) + + def test_aio_completions_are_reaped_into_emulator_storage(self): + self.assertEqual(self.value("io_getevents_host_buffer"), 1) + self.assertEqual(self.value("low_iocb_quiet_host_buffer"), 1) + self.assertEqual(self.value("io_getevents_sealed_result"), self.efault()) + self.assertEqual(self.value("io_getevents_sealed_released"), 0) + + def test_aio_rings_send_userspace_reapers_to_the_kernel(self): + self.assertEqual(self.value("io_setup_magic"), 0) + self.assertEqual(self.value("io_setup_header_kept"), 1) + self.assertEqual(self.value("io_setup_failed_magic"), 0xa10a10a1) + self.assertEqual(self.value("low_quiet_setup_magic"), 0) def test_aio_copies_follow_completions_without_relocated_mappings(self): self.assertEqual(self.value("low_iocb_quiet_cancel"), 1)