From: Tom Lendacky <thomas.lendacky@xxxxxxx> In preparation for an upcoming patch, convert the mutex that guards the DEACTIVATE/WBINVD/DF_FLUSH sequence into a read/write semaphore. The conversion will convert the mutex lock and unlock into down_write and up_write so that the mutex behavior is maintained. Tested-by: David Rientjes <rientjes@xxxxxxxxxx> Signed-off-by: Tom Lendacky <thomas.lendacky@xxxxxxx> --- arch/x86/kvm/svm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 389dfd7594eb..b995d7ac1516 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -38,6 +38,7 @@ #include <linux/file.h> #include <linux/pagemap.h> #include <linux/swap.h> +#include <linux/rwsem.h> #include <asm/apic.h> #include <asm/perf_event.h> @@ -418,7 +419,7 @@ enum { #define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL -static DEFINE_MUTEX(sev_deactivate_lock); +static DECLARE_RWSEM(sev_deactivate_lock); static DEFINE_MUTEX(sev_bitmap_lock); static unsigned int max_sev_asid; static unsigned int min_sev_asid; @@ -1762,14 +1763,14 @@ static void sev_unbind_asid(struct kvm *kvm, unsigned int handle) * Guard against a parallel DEACTIVATE command before the DF_FLUSH * command has completed. */ - mutex_lock(&sev_deactivate_lock); + down_write(&sev_deactivate_lock); sev_guest_deactivate(data, NULL); wbinvd_on_all_cpus(); sev_guest_df_flush(NULL); - mutex_unlock(&sev_deactivate_lock); + up_write(&sev_deactivate_lock); kfree(data); -- 2.17.1