From: Sean Christopherson <seanjc@google.com>
To: Zhao Liu <zhao1.liu@linux.intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Ira Weiny <ira.weiny@intel.com>,
"Fabio M . De Francesco" <fmdefrancesco@gmail.com>,
Zhenyu Wang <zhenyu.z.wang@intel.com>,
Zhao Liu <zhao1.liu@intel.com>
Subject: Re: [PATCH] KVM: SVM: Replace kmap_atomic() with kmap_local_page()
Date: Fri, 2 Sep 2022 15:15:09 +0000 [thread overview]
Message-ID: <YxId/V1qZcie9eyp@google.com> (raw)
In-Reply-To: <20220902090811.2430228-1-zhao1.liu@linux.intel.com>
On Fri, Sep 02, 2022, Zhao Liu wrote:
> From: Zhao Liu <zhao1.liu@intel.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@intel.com>
> Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> Signed-off-by: Zhao Liu <zhao1.liu@intel.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
>
next prev parent reply other threads:[~2022-09-02 15:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-02 9:08 [PATCH] KVM: SVM: Replace kmap_atomic() with kmap_local_page() Zhao Liu
2022-09-02 15:09 ` Dave Hansen
2022-09-04 15:54 ` Zhao Liu
2022-09-02 15:15 ` Sean Christopherson [this message]
2022-09-02 15:25 ` Dave Hansen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YxId/V1qZcie9eyp@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=fmdefrancesco@gmail.com \
--cc=hpa@zytor.com \
--cc=ira.weiny@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=zhao1.liu@intel.com \
--cc=zhao1.liu@linux.intel.com \
--cc=zhenyu.z.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox