[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7ba2f3a7-2e8e-39fa-dbf6-b2781f244486@amd.com>
Date: Fri, 22 Jan 2021 15:16:37 -0600
From: Tom Lendacky <thomas.lendacky@....com>
To: Sean Christopherson <seanjc@...gle.com>,
Paolo Bonzini <pbonzini@...hat.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Andy Lutomirski <luto@...nel.org>,
Peter Zijlstra <peterz@...radead.org>
Cc: Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, Borislav Petkov <bp@...e.de>,
Brijesh Singh <brijesh.singh@....com>
Subject: Re: [PATCH v3 13/13] KVM: SVM: Skip SEV cache flush if no ASIDs have
been used
On 1/22/21 2:21 PM, Sean Christopherson wrote:
> Skip SEV's expensive WBINVD and DF_FLUSH if there are no SEV ASIDs
> waiting to be reclaimed, e.g. if SEV was never used. This "fixes" an
> issue where the DF_FLUSH fails during hardware teardown if the original
> SEV_INIT failed. Ideally, SEV wouldn't be marked as enabled in KVM if
> SEV_INIT fails, but that's a problem for another day.
>
> Signed-off-by: Sean Christopherson <seanjc@...gle.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@....com>
> ---
> arch/x86/kvm/svm/sev.c | 23 +++++++++++------------
> 1 file changed, 11 insertions(+), 12 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 73da2af1e25d..0a4715e60b88 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -56,9 +56,14 @@ struct enc_region {
> unsigned long size;
> };
>
> -static int sev_flush_asids(void)
> +static int sev_flush_asids(int min_asid, int max_asid)
> {
> - int ret, error = 0;
> + int ret, pos, error = 0;
> +
> + /* Check if there are any ASIDs to reclaim before performing a flush */
> + pos = find_next_bit(sev_reclaim_asid_bitmap, max_sev_asid, min_asid);
> + if (pos >= max_asid)
> + return -EBUSY;
>
> /*
> * DEACTIVATE will clear the WBINVD indicator causing DF_FLUSH to fail,
> @@ -80,14 +85,7 @@ static int sev_flush_asids(void)
> /* Must be called with the sev_bitmap_lock held */
> static bool __sev_recycle_asids(int min_asid, int max_asid)
> {
> - int pos;
> -
> - /* Check if there are any ASIDs to reclaim before performing a flush */
> - pos = find_next_bit(sev_reclaim_asid_bitmap, max_sev_asid, min_asid);
> - if (pos >= max_asid)
> - return false;
> -
> - if (sev_flush_asids())
> + if (sev_flush_asids(min_asid, max_asid))
> return false;
>
> /* The flush process will flush all reclaimable SEV and SEV-ES ASIDs */
> @@ -1324,10 +1322,11 @@ void sev_hardware_teardown(void)
> if (!sev_enabled)
> return;
>
> + /* No need to take sev_bitmap_lock, all VMs have been destroyed. */
> + sev_flush_asids(0, max_sev_asid);
> +
> bitmap_free(sev_asid_bitmap);
> bitmap_free(sev_reclaim_asid_bitmap);
> -
> - sev_flush_asids();
> }
>
> int sev_cpu_init(struct svm_cpu_data *sd)
>
Powered by blists - more mailing lists