2019-10-03 21:20:53

by Tom Lendacky

[permalink] [raw]
Subject: [PATCH 0/5] SEV fixes and performance enhancements

From: Tom Lendacky <[email protected]>

This patch series provides fixes in the area of ASID assignment and VM
deactivation.

Additionally, it provides some performance enhancements by reducing the
number of WBINVD/DF_FLUSH invocations that are made.

Note: The third patch in the series modifies a file that is outside of
the arch/x86/kvm directory.

---

Patches based on https://git.kernel.org/pub/scm/virt/kvm/kvm.git next
and commit:
fd3edd4a9066 ("KVM: nVMX: cleanup and fix host 64-bit mode checks")

Tom Lendacky (5):
KVM: SVM: Serialize access to the SEV ASID bitmap
KVM: SVM: Guard against DEACTIVATE when performing WBINVD/DF_FLUSH
KVM: SVM: Remove unneeded WBINVD and DF_FLUSH when starting SEV guests
KVM: SVM: Convert DEACTIVATE mutex to read/write semaphore
KVM: SVM: Reduce WBINVD/DF_FLUSH invocations

arch/x86/kvm/svm.c | 105 +++++++++++++++++++++++++++--------
drivers/crypto/ccp/psp-dev.c | 9 +++
2 files changed, 92 insertions(+), 22 deletions(-)

--
2.17.1


2019-10-03 21:22:45

by Tom Lendacky

[permalink] [raw]
Subject: [PATCH 4/5] KVM: SVM: Convert DEACTIVATE mutex to read/write semaphore

From: Tom Lendacky <[email protected]>

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 <[email protected]>
Signed-off-by: Tom Lendacky <[email protected]>
---
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

2019-10-09 10:10:36

by Paolo Bonzini

[permalink] [raw]
Subject: Re: [PATCH 0/5] SEV fixes and performance enhancements

On 03/10/19 23:17, Lendacky, Thomas wrote:
> From: Tom Lendacky <[email protected]>
>
> This patch series provides fixes in the area of ASID assignment and VM
> deactivation.
>
> Additionally, it provides some performance enhancements by reducing the
> number of WBINVD/DF_FLUSH invocations that are made.
>
> Note: The third patch in the series modifies a file that is outside of
> the arch/x86/kvm directory.
>
> ---
>
> Patches based on https://git.kernel.org/pub/scm/virt/kvm/kvm.git next
> and commit:
> fd3edd4a9066 ("KVM: nVMX: cleanup and fix host 64-bit mode checks")
>
> Tom Lendacky (5):
> KVM: SVM: Serialize access to the SEV ASID bitmap
> KVM: SVM: Guard against DEACTIVATE when performing WBINVD/DF_FLUSH
> KVM: SVM: Remove unneeded WBINVD and DF_FLUSH when starting SEV guests
> KVM: SVM: Convert DEACTIVATE mutex to read/write semaphore
> KVM: SVM: Reduce WBINVD/DF_FLUSH invocations
>
> arch/x86/kvm/svm.c | 105 +++++++++++++++++++++++++++--------
> drivers/crypto/ccp/psp-dev.c | 9 +++
> 2 files changed, 92 insertions(+), 22 deletions(-)
>

Queued, thanks. I squashed 4/5 and 5/5 since there's not much that
survives of patch 4 after the next one.

Paolo