[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1557758315-12667-19-git-send-email-alexandre.chartre@oracle.com>
Date: Mon, 13 May 2019 16:38:26 +0200
From: Alexandre Chartre <alexandre.chartre@...cle.com>
To: pbonzini@...hat.com, rkrcmar@...hat.com, tglx@...utronix.de,
mingo@...hat.com, bp@...en8.de, hpa@...or.com,
dave.hansen@...ux.intel.com, luto@...nel.org, peterz@...radead.org,
kvm@...r.kernel.org, x86@...nel.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Cc: konrad.wilk@...cle.com, jan.setjeeilers@...cle.com,
liran.alon@...cle.com, jwadams@...gle.com,
alexandre.chartre@...cle.com
Subject: [RFC KVM 18/27] kvm/isolation: function to copy page table entries for percpu buffer
pcpu_base_addr is already mapped to the KVM address space, but this
represents the first percpu chunk. To access a per-cpu buffer not
allocated in the first chunk, add a function which maps all cpu
buffers corresponding to that per-cpu buffer.
Also add function to clear page table entries for a percpu buffer.
Signed-off-by: Alexandre Chartre <alexandre.chartre@...cle.com>
---
arch/x86/kvm/isolation.c | 34 ++++++++++++++++++++++++++++++++++
arch/x86/kvm/isolation.h | 2 ++
2 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kvm/isolation.c b/arch/x86/kvm/isolation.c
index 539e287..2052abf 100644
--- a/arch/x86/kvm/isolation.c
+++ b/arch/x86/kvm/isolation.c
@@ -990,6 +990,40 @@ void kvm_clear_range_mapping(void *ptr)
EXPORT_SYMBOL(kvm_clear_range_mapping);
+void kvm_clear_percpu_mapping(void *percpu_ptr)
+{
+ void *ptr;
+ int cpu;
+
+ pr_debug("PERCPU CLEAR percpu=%px\n", percpu_ptr);
+ for_each_possible_cpu(cpu) {
+ ptr = per_cpu_ptr(percpu_ptr, cpu);
+ kvm_clear_range_mapping(ptr);
+ }
+}
+EXPORT_SYMBOL(kvm_clear_percpu_mapping);
+
+int kvm_copy_percpu_mapping(void *percpu_ptr, size_t size)
+{
+ void *ptr;
+ int cpu, err;
+
+ pr_debug("PERCPU COPY percpu=%px size=%lx\n", percpu_ptr, size);
+ for_each_possible_cpu(cpu) {
+ ptr = per_cpu_ptr(percpu_ptr, cpu);
+ pr_debug("PERCPU COPY cpu%d addr=%px\n", cpu, ptr);
+ err = kvm_copy_ptes(ptr, size);
+ if (err) {
+ kvm_clear_range_mapping(percpu_ptr);
+ return err;
+ }
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(kvm_copy_percpu_mapping);
+
+
static int kvm_isolation_init_mm(void)
{
pgd_t *kvm_pgd;
diff --git a/arch/x86/kvm/isolation.h b/arch/x86/kvm/isolation.h
index 7d3c985..3ef2060 100644
--- a/arch/x86/kvm/isolation.h
+++ b/arch/x86/kvm/isolation.h
@@ -18,5 +18,7 @@ static inline bool kvm_isolation(void)
extern void kvm_may_access_sensitive_data(struct kvm_vcpu *vcpu);
extern int kvm_copy_ptes(void *ptr, unsigned long size);
extern void kvm_clear_range_mapping(void *ptr);
+extern int kvm_copy_percpu_mapping(void *percpu_ptr, size_t size);
+extern void kvm_clear_percpu_mapping(void *percpu_ptr);
#endif
--
1.7.1
Powered by blists - more mailing lists