lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 2 Sep 2022 15:15:09 +0000
From:   Sean Christopherson <seanjc@...gle.com>
To:     Zhao Liu <zhao1.liu@...ux.intel.com>
Cc:     Paolo Bonzini <pbonzini@...hat.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
        "H . Peter Anvin" <hpa@...or.com>, kvm@...r.kernel.org,
        linux-kernel@...r.kernel.org, Ira Weiny <ira.weiny@...el.com>,
        "Fabio M . De Francesco" <fmdefrancesco@...il.com>,
        Zhenyu Wang <zhenyu.z.wang@...el.com>,
        Zhao Liu <zhao1.liu@...el.com>
Subject: Re: [PATCH] KVM: SVM: Replace kmap_atomic() with kmap_local_page()

On Fri, Sep 02, 2022, Zhao Liu wrote:
> From: Zhao Liu <zhao1.liu@...el.com>
> 
> The use of kmap_atomic() is being deprecated in favor of
> kmap_local_page()[1].
> 
> In arch/x86/kvm/svm/sev.c, the function sev_clflush_pages() doesn't
> need to disable pagefaults and preemption in kmap_atomic(). It can
> simply use kmap_local_page() / kunmap_local() that can instead do the
> mapping / unmapping regardless of the context.
> 
> With kmap_local_page(), the mapping is per thread, CPU local and not
> globally visible. Therefore, sev_clflush_pages() is a function where
> the use of kmap_local_page() in place of kmap_atomic() is correctly
> suited.
> 
> Convert the calls of kmap_atomic() / kunmap_atomic() to
> kmap_local_page() / kunmap_local().
> 
> [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com
> 
> Suggested-by: Ira Weiny <ira.weiny@...el.com>
> Suggested-by: Fabio M. De Francesco <fmdefrancesco@...il.com>
> Signed-off-by: Zhao Liu <zhao1.liu@...el.com>
> ---
> Suggested by credits.
>         Ira: Referred to his task document and review comments.
>         Fabio: Referred to his boiler plate commit message.
> ---
>  arch/x86/kvm/svm/sev.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 28064060413a..12747c7bda4e 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -465,9 +465,9 @@ static void sev_clflush_pages(struct page *pages[], unsigned long npages)
>  		return;
>  
>  	for (i = 0; i < npages; i++) {
> -		page_virtual = kmap_atomic(pages[i]);
> +		page_virtual = kmap_local_page(pages[i]);
>  		clflush_cache_range(page_virtual, PAGE_SIZE);

SEV is 64-bit only, any reason not to go straight to page_address()?

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 28064060413a..aaf39e3c7bb5 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -457,7 +457,6 @@ static void sev_unpin_memory(struct kvm *kvm, struct page **pages,
 
 static void sev_clflush_pages(struct page *pages[], unsigned long npages)
 {
-       uint8_t *page_virtual;
        unsigned long i;
 
        if (this_cpu_has(X86_FEATURE_SME_COHERENT) || npages == 0 ||
@@ -465,9 +464,7 @@ static void sev_clflush_pages(struct page *pages[], unsigned long npages)
                return;
 
        for (i = 0; i < npages; i++) {
-               page_virtual = kmap_atomic(pages[i]);
-               clflush_cache_range(page_virtual, PAGE_SIZE);
-               kunmap_atomic(page_virtual);
+               clflush_cache_range(page_address(pages[i]), PAGE_SIZE);
                cond_resched();
        }
 }


config KVM_AMD_SEV
	def_bool y
	bool "AMD Secure Encrypted Virtualization (SEV) support"
	depends on KVM_AMD && X86_64 <==================================

> -		kunmap_atomic(page_virtual);
> +		kunmap_local(page_virtual);
>  		cond_resched();
>  	}
>  }
> -- 
> 2.34.1
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ