aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKirill A. Shutemov <kirill@shutemov.name>2020-05-22 15:52:01 +0300
committerMarc Zyngier <maz@kernel.org>2020-09-15 19:24:21 +0100
commitdbd4c551b3d34cb3e06e575eb205e2056f4a6e76 (patch)
tree33e68acc0003bb940cc2d29635e813af88920015
parent307c5ec1a2a79368b7277d1b1b205cb0c8ff44ca (diff)
downloadarm-platforms-dbd4c551b3d34cb3e06e575eb205e2056f4a6e76.tar.gz
x86/kvm: Make DMA pages shared
Make force_dma_unencrypted() return true for KVM to get DMA pages mapped as shared. __set_memory_enc_dec() now informs the host via hypercall if the state of the page has changed from shared to private or back. Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Marc Zyngier <maz@kernel.org>
-rw-r--r--arch/x86/Kconfig1
-rw-r--r--arch/x86/mm/mem_encrypt_common.c5
-rw-r--r--arch/x86/mm/pat/set_memory.c7
-rw-r--r--include/uapi/linux/kvm_para.h2
4 files changed, 13 insertions, 2 deletions
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 619ebf40e457d..cd272e3babbc9 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -805,6 +805,7 @@ config KVM_GUEST
select PARAVIRT_CLOCK
select ARCH_CPUIDLE_HALTPOLL
select X86_HV_CALLBACK_VECTOR
+ select X86_MEM_ENCRYPT_COMMON
default y
help
This option enables various optimizations for running under the KVM
diff --git a/arch/x86/mm/mem_encrypt_common.c b/arch/x86/mm/mem_encrypt_common.c
index 964e04152417c..a878e7f246d58 100644
--- a/arch/x86/mm/mem_encrypt_common.c
+++ b/arch/x86/mm/mem_encrypt_common.c
@@ -10,14 +10,15 @@
#include <linux/mm.h>
#include <linux/mem_encrypt.h>
#include <linux/dma-mapping.h>
+#include <asm/kvm_para.h>
/* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPTED */
bool force_dma_unencrypted(struct device *dev)
{
/*
- * For SEV, all DMA must be to unencrypted/shared addresses.
+ * For SEV and KVM, all DMA must be to unencrypted/shared addresses.
*/
- if (sev_active())
+ if (sev_active() || kvm_mem_protected())
return true;
/*
diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index d1b2a889f035d..4c49303126c9d 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -16,6 +16,7 @@
#include <linux/pci.h>
#include <linux/vmalloc.h>
#include <linux/libnvdimm.h>
+#include <linux/kvm_para.h>
#include <asm/e820/api.h>
#include <asm/processor.h>
@@ -1977,6 +1978,12 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc)
struct cpa_data cpa;
int ret;
+ if (kvm_mem_protected()) {
+ unsigned long gfn = __pa(addr) >> PAGE_SHIFT;
+ int call = enc ? KVM_HC_MEM_UNSHARE : KVM_HC_MEM_SHARE;
+ return kvm_hypercall2(call, gfn, numpages);
+ }
+
/* Nothing to do if memory encryption is not active */
if (!mem_encrypt_active())
return 0;
diff --git a/include/uapi/linux/kvm_para.h b/include/uapi/linux/kvm_para.h
index 1a216f32e5729..c6d8c988e3306 100644
--- a/include/uapi/linux/kvm_para.h
+++ b/include/uapi/linux/kvm_para.h
@@ -30,6 +30,8 @@
#define KVM_HC_SEND_IPI 10
#define KVM_HC_SCHED_YIELD 11
#define KVM_HC_ENABLE_MEM_PROTECTED 12
+#define KVM_HC_MEM_SHARE 13
+#define KVM_HC_MEM_UNSHARE 14
/*
* hypercalls use architecture specific