kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] svm: Add mutex_lock to protect apic_access_page_done on AMD systems
@ 2018-11-12 12:23 Suthikulpanit, Suravee
  2018-11-12 13:37 ` joro
  0 siblings, 1 reply; 3+ messages in thread
From: Suthikulpanit, Suravee @ 2018-11-12 12:23 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: joro, pbonzini, rkrcmar, Wei Wang, Amadeusz Juskowiak,
	Julian Stecklina, Suthikulpanit, Suravee

From: Wei Wang <wawei@amazon.de>

There is a race condition when accessing kvm->arch.apic_access_page_done.
Due to it, x86_set_memory_region will fail when creating the second vcpu
for a svm guest.

Add a mutex_lock to serialize the accesses to apic_access_page_done.
This lock is also used by vmx for the same purpose.

Signed-off-by: Wei Wang <wawei@amazon.de>
Signed-off-by: Amadeusz Juskowiak <ajusk@amazon.de>
Signed-off-by: Julian Stecklina <jsteckli@amazon.de>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
 arch/x86/kvm/svm.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index d96092b35936..8be1718fed1d 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1658,20 +1658,23 @@ static u64 *avic_get_physical_id_entry(struct kvm_vcpu *vcpu,
 static int avic_init_access_page(struct kvm_vcpu *vcpu)
 {
 	struct kvm *kvm = vcpu->kvm;
-	int ret;
+	int ret = 0;
 
+	mutex_lock(&kvm->slots_lock);
 	if (kvm->arch.apic_access_page_done)
-		return 0;
+		goto out;
 
-	ret = x86_set_memory_region(kvm,
-				    APIC_ACCESS_PAGE_PRIVATE_MEMSLOT,
-				    APIC_DEFAULT_PHYS_BASE,
-				    PAGE_SIZE);
+	ret = __x86_set_memory_region(kvm,
+				      APIC_ACCESS_PAGE_PRIVATE_MEMSLOT,
+				      APIC_DEFAULT_PHYS_BASE,
+				      PAGE_SIZE);
 	if (ret)
-		return ret;
+		goto out;
 
 	kvm->arch.apic_access_page_done = true;
-	return 0;
+out:
+	mutex_unlock(&kvm->slots_lock);
+	return ret;
 }
 
 static int avic_init_backing_page(struct kvm_vcpu *vcpu)
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] svm: Add mutex_lock to protect apic_access_page_done on AMD systems
  2018-11-12 12:23 [PATCH] svm: Add mutex_lock to protect apic_access_page_done on AMD systems Suthikulpanit, Suravee
@ 2018-11-12 13:37 ` joro
  2018-11-25 17:34   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: joro @ 2018-11-12 13:37 UTC (permalink / raw)
  To: Suthikulpanit, Suravee
  Cc: linux-kernel, kvm, pbonzini, rkrcmar, Wei Wang,
	Amadeusz Juskowiak, Julian Stecklina

On Mon, Nov 12, 2018 at 12:23:14PM +0000, Suthikulpanit, Suravee wrote:
> From: Wei Wang <wawei@amazon.de>
> 
> There is a race condition when accessing kvm->arch.apic_access_page_done.
> Due to it, x86_set_memory_region will fail when creating the second vcpu
> for a svm guest.
> 
> Add a mutex_lock to serialize the accesses to apic_access_page_done.
> This lock is also used by vmx for the same purpose.
> 
> Signed-off-by: Wei Wang <wawei@amazon.de>
> Signed-off-by: Amadeusz Juskowiak <ajusk@amazon.de>
> Signed-off-by: Julian Stecklina <jsteckli@amazon.de>
> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>

Reviewed-by: Joerg Roedel <jroedel@suse.de>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] svm: Add mutex_lock to protect apic_access_page_done on AMD systems
  2018-11-12 13:37 ` joro
@ 2018-11-25 17:34   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2018-11-25 17:34 UTC (permalink / raw)
  To: joro, Suthikulpanit, Suravee
  Cc: linux-kernel, kvm, rkrcmar, Wei Wang, Amadeusz Juskowiak,
	Julian Stecklina

On 12/11/18 14:37, joro@8bytes.org wrote:
> On Mon, Nov 12, 2018 at 12:23:14PM +0000, Suthikulpanit, Suravee wrote:
>> From: Wei Wang <wawei@amazon.de>
>>
>> There is a race condition when accessing kvm->arch.apic_access_page_done.
>> Due to it, x86_set_memory_region will fail when creating the second vcpu
>> for a svm guest.
>>
>> Add a mutex_lock to serialize the accesses to apic_access_page_done.
>> This lock is also used by vmx for the same purpose.
>>
>> Signed-off-by: Wei Wang <wawei@amazon.de>
>> Signed-off-by: Amadeusz Juskowiak <ajusk@amazon.de>
>> Signed-off-by: Julian Stecklina <jsteckli@amazon.de>
>> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> Reviewed-by: Joerg Roedel <jroedel@suse.de>

Queued, thanks.

Paolo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-25 17:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-12 12:23 [PATCH] svm: Add mutex_lock to protect apic_access_page_done on AMD systems Suthikulpanit, Suravee
2018-11-12 13:37 ` joro
2018-11-25 17:34   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).