On Thu, Dec 12, 2024, Maxim Levitsky wrote: > On Wed, 2024-12-11 at 16:44 -0800, Sean Christopherson wrote: > > But, I can't help but wonder why KVM bothers emulating PML. I can appreciate > > that avoiding exits to L1 would be beneficial, but what use case actually cares > > about dirty logging performance in L1? > > It does help with performance by a lot and the implementation is emulated and simple. Yeah, it's not a lot of complexity, but it's architecturally flawed. And I get that it helps with performance, I'm just stumped as to the use case for dirty logging in a nested VM in the first place. > Do you have any comments for the rest of the patch series? If not then I'll send > v2 of the patch series. *sigh* I do. Through no fault of your own. I was trying to figure out a way to ensure the vCPU made meaningful progress, versus just guaranteeing at least one write, and stumbled onto a plethora of flaws and unnecessary complexity in the test. Can you post this patch as a standalone v2? I'd like to do a more agressive cleanup of the selftest, but I don't want to hold this up, and there's no hard dependency. As for the issues I encountered with the selftest: 1. Tracing how many pages have been written for the current iteration with a guest side counter doesn't work without more fixes, because the test doesn't collect all dirty entries for the current iterations. For the dirty ring, this results in a vCPU *starting* an iteration with a full dirty ring, and the test hangs because the guest can't make forward progress until log_mode_collect_dirty_pages() is called. 2. The test presumably doesn't collect all dirty entries because of the weird and unnecessary kick in dirty_ring_collect_dirty_pages(), and all the synchronization that comes with it. The kick is "justified" with a comment saying "This makes sure that hardware PML cache flushed", but there's no reason to do *if* pages that the test collects dirty pages *after* stopping the vCPU. Which is easy to do while also collecting while the vCPU is running, if the kick+synchronization is eliminated (i.e. it's a self-inflicted wound of sorts). 3. dirty_ring_after_vcpu_run() doesn't honor vcpu_sync_stop_requested, and so every other iteration runs until the ring is full. Testing the "soft full" logic is interesting, but not _that_ interesting, and filling the dirty ring basically ignores the "interval". Fixing this reduces the runtime by a significant amount, especially on nested, at the cost of providing less coverage for the dirty ring with default interval in a nested VM (but if someone cares about testing the dirty ring soft full in a nested VM, they can darn well bump the interval). 4. Fixing the test to collect all dirty entries for the current iteration exposes another flaw. The bitmaps (not dirty ring) start with all bits set. And so the first iteration can see "dirty" pages that have never been written, but only when applying your fix to limit the hack to s390. 5. "iteration" is synched to the guest *after* the vCPU is restarted, i.e. the guest could see a stale iteration if the main thread is delayed. 6. host_bmap_track and all of the weird exemptions for writes from previous iterations goes away if all entries are collected for the current iteration (though a second bitmap is needed to handle the second collection; KVM's "get" of the bitmap clobbers the previous value). I have everything more or less coded up, but I need to split it into patches, write changelogs, and interleave it with your fixes. Hopefully I'll get to that tomorrow.