Re: [PATCH 19/24] kvm: x86/mmu: Protect tdp_mmu_pages with a lock

Paolo Bonzini
2021-01-27T12:45:16Z

On 26/01/21 23:02, Sean Christopherson wrote:
>> You can do the deferred freeing with a short write-side critical section to
>> ensure all readers have terminated.
>
> Hmm, the most obvious downside I see is that the zap_collapsible_sptes() case
> will not scale as well as the RCU approach. E.g. the lock may be heavily
> contested when refaulting all of guest memory to (re)install huge pages after a
> failed migration.

The simplest solution is to use a write_trylock on the read_unlock()
path; if it fails, schedule a delayed work item 1 second in the future
so that it's possible to do some batching.

(The work item would also have to re-check the llist after each iteration.)

Paolo