kvmppc: HMM driver to manage pages of secure guest
Subsystems (4)
v4 cover kvmppc: HMM driver to manage pages of secure guest
Hi,
A pseries guest can be run as a secure guest on Ultravisor-enabled POWER platforms. On such platforms, this driver will be used to manage the movement of guest pages between the normal memory managed by hypervisor (HV) and secure memory managed by Ultravisor (UV).
Private ZONE_DEVICE memory equal to the amount of secure memory available in the platform for running secure guests is created via a HMM device. The movement of pages between normal and secure memory is done by ->alloc_and_copy() callback routine of migrate_vma().
The page-in or page-out requests from UV will come to HV as hcalls and HV will call back into UV via uvcalls to satisfy these page requests.
These patches apply and work on top of the base Ultravisor patches posted by Claudio Carvalho at:
https://lists.ozlabs.org/pipermail/linuxppc-dev/2019-May/190694.html
In this version, the last two patches are the new additions.
Changes in v4
=============
- Handling HV side page invalidations by issuing UV_PAGE_INVAL ucall
- Handling HV side radix page faults by sending the page to UV
- Support for rebooting a secure guest
- Some cleanups and code reorgs
v3: https://lists.ozlabs.org/pipermail/linuxppc-dev/2019-January/184731.html
Bharata B Rao (6):
kvmppc: HMM backend driver to manage pages of secure guest
kvmppc: Shared pages support for secure guests
kvmppc: H_SVM_INIT_START and H_SVM_INIT_DONE hcalls
kvmppc: Handle memory plug/unplug to secure VM
kvmppc: Radix changes for secure guest
kvmppc: Support reset of secure guest
arch/powerpc/include/asm/hvcall.h | 9 + arch/powerpc/include/asm/kvm_book3s_hmm.h | 41 ++ arch/powerpc/include/asm/kvm_host.h | 37 ++ arch/powerpc/include/asm/kvm_ppc.h | 4 + arch/powerpc/include/asm/ultravisor-api.h | 6 + arch/powerpc/include/asm/ultravisor.h | 47 ++ arch/powerpc/kvm/Makefile | 3 + arch/powerpc/kvm/book3s_64_mmu_radix.c | 19 + arch/powerpc/kvm/book3s_hv.c | 69 +++ arch/powerpc/kvm/book3s_hv_hmm.c | 666 ++++++++++++++++++++++ arch/powerpc/kvm/powerpc.c | 12 + include/uapi/linux/kvm.h | 1 + tools/include/uapi/linux/kvm.h | 1 + 13 files changed, 915 insertions(+) create mode 100644 arch/powerpc/include/asm/kvm_book3s_hmm.h create mode 100644 arch/powerpc/kvm/book3s_hv_hmm.c
Signature · 1 line
2.17.1
PATCH v4 1/6 kvmppc: HMM backend driver to manage pages of secure guest
HMM driver for KVM PPC to manage page transitions of secure guest via H_SVM_PAGE_IN and H_SVM_PAGE_OUT hcalls.
H_SVM_PAGE_IN: Move the content of a normal page to secure pageH_SVM_PAGE_OUT: Move the content of a secure page to normal page
--- arch/powerpc/include/asm/hvcall.h | 4 + arch/powerpc/include/asm/kvm_book3s_hmm.h | 29 ++ arch/powerpc/include/asm/kvm_host.h | 14 + arch/powerpc/include/asm/ultravisor-api.h | 2 + arch/powerpc/include/asm/ultravisor.h | 17 + arch/powerpc/kvm/Makefile | 3 + arch/powerpc/kvm/book3s_hv.c | 20 + arch/powerpc/kvm/book3s_hv_hmm.c | 474 ++++++++++++++++++++++ 8 files changed, 563 insertions(+) create mode 100644 arch/powerpc/include/asm/kvm_book3s_hmm.h create mode 100644 arch/powerpc/kvm/book3s_hv_hmm.c
arch/powerpc/include/asm/hvcall.h +4 -0
@@ -337,6 +337,10 @@#define H_TLB_INVALIDATE 0xF808#define H_COPY_TOFROM_GUEST 0xF80C +/* Platform-specific hcalls used by the Ultravisor */ +#define H_SVM_PAGE_IN 0xEF00 +#define H_SVM_PAGE_OUT 0xEF04 +/* Values for 2nd argument to H_SET_MODE */ #define H_SET_MODE_RESOURCE_SET_CIABR 1#define H_SET_MODE_RESOURCE_SET_DAWR 2
arch/powerpc/include/asm/kvm_book3s_hmm.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __POWERPC_KVM_PPC_HMM_H__ +#define __POWERPC_KVM_PPC_HMM_H__ + +#ifdef CONFIG_PPC_UV +extern unsigned long kvmppc_h_svm_page_in (struct kvm *kvm, +unsigned long gra, +unsigned long flags, +unsigned long page_shift); +extern unsigned long kvmppc_h_svm_page_out (struct kvm *kvm, +unsigned long gra, +unsigned long flags, +unsigned long page_shift); +#else +static inline unsigned long +kvmppc_h_svm_page_in (struct kvm *kvm,unsigned long gra, +unsigned long flags,unsigned long page_shift) +{ +return H_UNSUPPORTED ; +} + +static inline unsigned long +kvmppc_h_svm_page_out (struct kvm *kvm,unsigned long gra, +unsigned long flags,unsigned long page_shift) +{ +return H_UNSUPPORTED ; +} +#endif /* CONFIG_PPC_UV */ +#endif /* __POWERPC_KVM_PPC_HMM_H__ */
arch/powerpc/include/asm/kvm_host.h +14 -0
@@ -858,4 +858,18 @@ static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}static inline void kvm_arch_vcpu_unblocking (struct kvm_vcpu *vcpu) {}static inline void kvm_arch_vcpu_block_finish (struct kvm_vcpu *vcpu) {} +#ifdef CONFIG_PPC_UV +extern int kvmppc_hmm_init (void ); +extern void kvmppc_hmm_free (void ); +extern void kvmppc_hmm_release_pfns (struct kvm_memory_slot *free); +#else +static inline int kvmppc_hmm_init (void ) +{ +return 0 ; +} + +static inline void kvmppc_hmm_free (void ) {} +static inline void kvmppc_hmm_release_pfns (struct kvm_memory_slot *free) {} +#endif /* CONFIG_PPC_UV */ +#endif /* __POWERPC_KVM_HOST_H__ */
arch/powerpc/include/asm/ultravisor-api.h +2 -0
@@ -20,5 +20,7 @@/* opcodes */ #define UV_WRITE_PATE 0xF104#define UV_RETURN 0xF11C +#define UV_PAGE_IN 0xF128 +#define UV_PAGE_OUT 0xF12C#endif /* _ASM_POWERPC_ULTRAVISOR_API_H */
arch/powerpc/include/asm/ultravisor.h +17 -0
@@ -44,6 +44,23 @@ static inline int uv_register_pate(u64 lpid, u64 dw0, u64 dw1)return ucall (UV_WRITE_PATE , retbuf, lpid, dw0, dw1); } +static inline int uv_page_in (u64 lpid,u64 src_ra,u64 dst_gpa,u64 flags, +u64 page_shift) +{ +unsigned long retbuf[UCALL_BUFSIZE ]; + +return ucall (UV_PAGE_IN , retbuf, lpid, src_ra, dst_gpa, flags, + page_shift); +} + +static inline int uv_page_out (u64 lpid,u64 dst_ra,u64 src_gpa,u64 flags, +u64 page_shift) +{ +unsigned long retbuf[UCALL_BUFSIZE ]; + +return ucall (UV_PAGE_OUT , retbuf, lpid, dst_ra, src_gpa, flags, + page_shift); +}#endif /* !__ASSEMBLY__ */ #endif /* _ASM_POWERPC_ULTRAVISOR_H */
arch/powerpc/kvm/Makefile +3 -0
@@ -71,6 +71,9 @@ kvm-hv-y += \ book3s_64_mmu_radix.o \ book3s_hv_nested.o +kvm-hv-$(CONFIG_PPC_UV) += \ + book3s_hv_hmm.o + kvm-hv-$(CONFIG_PPC_TRANSACTIONAL_MEM) += \ book3s_hv_tm.o
arch/powerpc/kvm/book3s_hv.c +20 -0
@@ -76,6 +76,8 @@#include <asm/xive.h> #include <asm/hw_breakpoint.h> #include <asm/firmware.h> +#include <asm/kvm_host.h> +#include <asm/kvm_book3s_hmm.h> #include "book3s.h"
@@ -1084,6 +1086,18 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)kvmppc_get_gpr (vcpu,5 ), kvmppc_get_gpr(vcpu, 6));break ; +case H_SVM_PAGE_IN : + ret =kvmppc_h_svm_page_in (vcpu->kvm, +kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 )); +break ; +case H_SVM_PAGE_OUT : + ret =kvmppc_h_svm_page_out (vcpu->kvm, +kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 )); +break ;default :return RESUME_HOST ; }
@@ -4421,6 +4435,7 @@ static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {if (!dont || free->arch.rmap != dont->arch.rmap) { +kvmppc_hmm_release_pfns (free);vfree (free->arch.rmap); free->arch.rmap =NULL ; }
@@ -5494,11 +5509,16 @@ static int kvmppc_book3s_init_hv(void) no_mixing_hpt_and_radix = true; } + r =kvmppc_hmm_init (); +if (r <0 ) +pr_err ("KVM-HV: kvmppc_hmm_init failed %d\n" , r); +return r; }static void kvmppc_book3s_exit_hv (void ) { +kvmppc_hmm_free ();kvmppc_free_host_rm_ops ();if (kvmppc_radix_possible ())kvmppc_radix_exit ();
arch/powerpc/kvm/book3s_hv_hmm.c new file +474 -0
474 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 2/6 kvmppc: Shared pages support for secure guests
In reply to Bharata B RaoA secure guest will share some of its pages with hypervisor (Eg. virtio bounce buffers etc). Support shared pages in HMM driver.
--- arch/powerpc/include/asm/hvcall.h | 3 ++ arch/powerpc/kvm/book3s_hv_hmm.c | 58 +++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/hvcall.h +3 -0
@@ -337,6 +337,9 @@#define H_TLB_INVALIDATE 0xF808#define H_COPY_TOFROM_GUEST 0xF80C +/* Flags for H_SVM_PAGE_IN */ +#define H_PAGE_IN_SHARED 0x1 +/* Platform-specific hcalls used by the Ultravisor */ #define H_SVM_PAGE_IN 0xEF00#define H_SVM_PAGE_OUT 0xEF04
arch/powerpc/kvm/book3s_hv_hmm.c +55 -3
84 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 3/6 kvmppc: H_SVM_INIT_START and H_SVM_INIT_DONE hcalls
In reply to Bharata B RaoH_SVM_INIT_START: Initiate securing a VMH_SVM_INIT_DONE: Conclude securing a VM
As part of H_SVM_INIT_START register all existing memslots with the UV. H_SVM_INIT_DONE call by UV informs HV that transition of the guest to secure mode is complete.
--- arch/powerpc/include/asm/hvcall.h | 2 ++ arch/powerpc/include/asm/kvm_book3s_hmm.h | 12 ++++++++ arch/powerpc/include/asm/kvm_host.h | 4 +++ arch/powerpc/include/asm/ultravisor-api.h | 1 + arch/powerpc/include/asm/ultravisor.h | 9 ++++++ arch/powerpc/kvm/book3s_hv.c | 7 +++++ arch/powerpc/kvm/book3s_hv_hmm.c | 34 +++++++++++++++++++++++ 7 files changed, 69 insertions(+)
arch/powerpc/include/asm/hvcall.h +2 -0
@@ -343,6 +343,8 @@/* Platform-specific hcalls used by the Ultravisor */ #define H_SVM_PAGE_IN 0xEF00#define H_SVM_PAGE_OUT 0xEF04 +#define H_SVM_INIT_START 0xEF08 +#define H_SVM_INIT_DONE 0xEF0C/* Values for 2nd argument to H_SET_MODE */ #define H_SET_MODE_RESOURCE_SET_CIABR 1
arch/powerpc/include/asm/kvm_book3s_hmm.h +12 -0
@@ -11,6 +11,8 @@ extern unsigned long kvmppc_h_svm_page_out(struct kvm *kvm,unsigned long gra, unsigned long flags, unsigned long page_shift); +extern unsigned long kvmppc_h_svm_init_start (struct kvm *kvm); +extern unsigned long kvmppc_h_svm_init_done (struct kvm *kvm);#else static inline unsigned long kvmppc_h_svm_page_in(struct kvm *kvm, unsigned long gra,
@@ -25,5 +27,15 @@ kvmppc_h_svm_page_out(struct kvm *kvm, unsigned long gra, {return H_UNSUPPORTED ; } + +static inine unsigned long kvmppc_h_svm_init_start (struct kvm *kvm) +{ +return H_UNSUPPORTED ; +} + +static inine unsigned long kvmppc_h_svm_init_done (struct kvm *kvm); +{ +return H_UNSUPPORTED ; +}#endif /* CONFIG_PPC_UV */ #endif /* __POWERPC_KVM_PPC_HMM_H__ */
arch/powerpc/include/asm/kvm_host.h +4 -0
@@ -272,6 +272,10 @@ struct kvm_hpt_info {struct kvm_resize_hpt ; +/* Flag values for kvm_arch.secure_guest */ +#define KVMPPC_SECURE_INIT_START 0x1/* H_SVM_INIT_START has been called */ +#define KVMPPC_SECURE_INIT_DONE 0x2/* H_SVM_INIT_DONE completed */ +struct kvm_arch {unsigned int lpid;unsigned int smt_mode;/* # vcpus per virtual core */
arch/powerpc/include/asm/ultravisor-api.h +1 -0
@@ -20,6 +20,7 @@/* opcodes */ #define UV_WRITE_PATE 0xF104#define UV_RETURN 0xF11C +#define UV_REGISTER_MEM_SLOT 0xF120#define UV_PAGE_IN 0xF128#define UV_PAGE_OUT 0xF12C
arch/powerpc/include/asm/ultravisor.h +9 -0
@@ -61,6 +61,15 @@ static inline int uv_page_out(u64 lpid, u64 dst_ra, u64 src_gpa, u64 flags,return ucall (UV_PAGE_OUT , retbuf, lpid, dst_ra, src_gpa, flags, page_shift); } + +static inline int uv_register_mem_slot (u64 lpid,u64 start_gpa,u64 size, +u64 flags,u64 slotid) +{ +unsigned long retbuf[UCALL_BUFSIZE ]; + +return ucall (UV_REGISTER_MEM_SLOT , retbuf, lpid, start_gpa, + size, flags, slotid); +}#endif /* !__ASSEMBLY__ */ #endif /* _ASM_POWERPC_ULTRAVISOR_H */
arch/powerpc/kvm/book3s_hv.c +7 -0
@@ -1098,6 +1098,13 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)kvmppc_get_gpr (vcpu,5 ), kvmppc_get_gpr(vcpu, 6));break ; +case H_SVM_INIT_START : + ret =kvmppc_h_svm_init_start (vcpu->kvm); +break ; +case H_SVM_INIT_DONE : + ret =kvmppc_h_svm_init_done (vcpu->kvm); +break ; +default :return RESUME_HOST ; }
arch/powerpc/kvm/book3s_hv_hmm.c +34 -0
@@ -55,6 +55,40 @@ struct kvmppc_hmm_migrate_args {unsigned long page_shift; }; +unsigned long kvmppc_h_svm_init_start (struct kvm *kvm) +{ +struct kvm_memslots *slots; +struct kvm_memory_slot *memslot; +int ret =H_SUCCESS ; +int srcu_idx; + + srcu_idx =srcu_read_lock (&kvm->srcu); + slots =kvm_memslots (kvm); +kvm_for_each_memslot (memslot, slots) { + ret =uv_register_mem_slot (kvm->arch.lpid, + memslot->base_gfn <<PAGE_SHIFT , + memslot->npages *PAGE_SIZE , +0 , memslot->id); +if (ret <0 ) { + ret =H_PARAMETER ; + goto out; + } + } + kvm->arch.secure_guest |=KVMPPC_SECURE_INIT_START ; +out: +srcu_read_unlock (&kvm->srcu, srcu_idx); +return ret; +} + +unsigned long kvmppc_h_svm_init_done (struct kvm *kvm) +{ +if (!(kvm->arch.secure_guest &KVMPPC_SECURE_INIT_START )) +return H_UNSUPPORTED ; + + kvm->arch.secure_guest |=KVMPPC_SECURE_INIT_DONE ; +return H_SUCCESS ; +} +#define KVMPPC_PFN_HMM (0x1ULL << 61)static inline bool kvmppc_is_hmm_pfn (unsigned long pfn)
Signature · 1 line
2.17.1
PATCH v4 4/6 kvmppc: Handle memory plug/unplug to secure VM
In reply to Bharata B RaoRegister the new memslot with UV during plug and unregister the memslot during unplug.
--- arch/powerpc/include/asm/ultravisor-api.h | 1 + arch/powerpc/include/asm/ultravisor.h | 7 +++++++ arch/powerpc/kvm/book3s_hv.c | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+)
arch/powerpc/include/asm/ultravisor-api.h +1 -0
@@ -21,6 +21,7 @@#define UV_WRITE_PATE 0xF104#define UV_RETURN 0xF11C#define UV_REGISTER_MEM_SLOT 0xF120 +#define UV_UNREGISTER_MEM_SLOT 0xF124#define UV_PAGE_IN 0xF128#define UV_PAGE_OUT 0xF12C
arch/powerpc/include/asm/ultravisor.h +7 -0
@@ -70,6 +70,13 @@ static inline int uv_register_mem_slot(u64 lpid, u64 start_gpa, u64 size,return ucall (UV_REGISTER_MEM_SLOT , retbuf, lpid, start_gpa, size, flags, slotid); } + +static inline int uv_unregister_mem_slot (u64 lpid,u64 slotid) +{ +unsigned long retbuf[UCALL_BUFSIZE ]; + +return ucall (UV_UNREGISTER_MEM_SLOT , retbuf, lpid, slotid); +}#endif /* !__ASSEMBLY__ */ #endif /* _ASM_POWERPC_ULTRAVISOR_H */
arch/powerpc/kvm/book3s_hv.c +19 -0
@@ -78,6 +78,7 @@#include <asm/firmware.h> #include <asm/kvm_host.h> #include <asm/kvm_book3s_hmm.h> +#include <asm/ultravisor.h> #include "book3s.h"
@@ -4498,6 +4499,24 @@ static void kvmppc_core_commit_memory_region_hv(struct kvm *kvm,if (change =KVM_MR_FLAGS_ONLY &&kvm_is_radix (kvm) && ((new->flags ^ old->flags) &KVM_MEM_LOG_DIRTY_PAGES ))kvmppc_radix_flush_memslot (kvm, old); +/* +* If UV hasn't yet called H_SVM_INIT_START, don't register memslots. +*/ +if (!kvm->arch.secure_guest) +return ; + +/* +* TODO: Handle KVM_MR_MOVE +*/ +if (change =KVM_MR_CREATE ) { +uv_register_mem_slot (kvm->arch.lpid, + new->base_gfn <<PAGE_SHIFT , + new->npages *PAGE_SIZE , +0 , + new->id); + }else if (change =KVM_MR_DELETE ) { +uv_unregister_mem_slot (kvm->arch.lpid, old->id); + } }/*
Signature · 1 line
2.17.1
RFC PATCH v4 5/6 kvmppc: Radix changes for secure guest
In reply to Bharata B Rao- After the guest becomes secure, when we handle a page fault of a page belonging to SVM in HV, send that page to UV via UV_PAGE_IN.
- Whenever a page is unmapped on the HV side, inform UV via UV_PAGE_INVAL.
--- arch/powerpc/include/asm/kvm_host.h | 13 +++++++++++++ arch/powerpc/include/asm/ultravisor-api.h | 1 + arch/powerpc/include/asm/ultravisor.h | 7 +++++++ arch/powerpc/kvm/book3s_64_mmu_radix.c | 19 +++++++++++++++++++ arch/powerpc/kvm/book3s_hv_hmm.c | 23 +++++++++++++++++++++++ 5 files changed, 63 insertions(+)
arch/powerpc/include/asm/kvm_host.h +13 -0
@@ -866,6 +866,8 @@ static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {}extern int kvmppc_hmm_init (void );extern void kvmppc_hmm_free (void );extern void kvmppc_hmm_release_pfns (struct kvm_memory_slot *free); +extern bool kvmppc_is_guest_secure (struct kvm *kvm); +extern int kvmppc_send_page_to_uv (struct kvm *kvm,unsigned long gpa);#else static inline int kvmppc_hmm_init (void ) {
@@ -874,6 +876,17 @@ static inline int kvmppc_hmm_init(void)static inline void kvmppc_hmm_free (void ) {}static inline void kvmppc_hmm_release_pfns (struct kvm_memory_slot *free) {} + + +static inline bool kvmppc_is_guest_secure (struct kvm *kvm) +{ +return false; +} + +static inline int kvmppc_send_page_to_uv (struct kvm *kvm,unsigned long gpa) +{ +return -EFAULT ; +}#endif /* CONFIG_PPC_UV */ #endif /* __POWERPC_KVM_HOST_H__ */
arch/powerpc/include/asm/ultravisor-api.h +1 -0
@@ -24,5 +24,6 @@#define UV_UNREGISTER_MEM_SLOT 0xF124#define UV_PAGE_IN 0xF128#define UV_PAGE_OUT 0xF12C +#define UV_PAGE_INVAL 0xF138#endif /* _ASM_POWERPC_ULTRAVISOR_API_H */
arch/powerpc/include/asm/ultravisor.h +7 -0
@@ -77,6 +77,13 @@ static inline int uv_unregister_mem_slot(u64 lpid, u64 slotid)return ucall (UV_UNREGISTER_MEM_SLOT , retbuf, lpid, slotid); } + +static inline int uv_page_inval (u64 lpid,u64 gpa,u64 page_shift) +{ +unsigned long retbuf[UCALL_BUFSIZE ]; + +return ucall (UV_PAGE_INVAL , retbuf, lpid, gpa, page_shift); +}#endif /* !__ASSEMBLY__ */ #endif /* _ASM_POWERPC_ULTRAVISOR_H */
arch/powerpc/kvm/book3s_64_mmu_radix.c +19 -0
@@ -21,6 +21,8 @@#include <asm/pgtable.h> #include <asm/pgalloc.h> #include <asm/pte-walk.h> +#include <asm/ultravisor.h> +#include <asm/kvm_host.h> /* * Supported radix tree geometry.
@@ -923,6 +925,9 @@ int kvmppc_book3s_radix_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,if (!(dsisr &DSISR_PRTABLE_FAULT )) gpa |= ea &0xfff ; +if (kvmppc_is_guest_secure (kvm)) +return kvmppc_send_page_to_uv (kvm, gpa &PAGE_MASK ); +/* Get the corresponding memslot */ memslot =gfn_to_memslot (kvm, gfn);
@@ -980,6 +985,11 @@ int kvm_unmap_radix(struct kvm *kvm, struct kvm_memory_slot *memslot,unsigned long gpa = gfn <<PAGE_SHIFT ;unsigned int shift; +if (kvmppc_is_guest_secure (kvm)) { +uv_page_inval (kvm->arch.lpid, gpa,PAGE_SIZE ); +return 0 ; + } + ptep =__find_linux_pte (kvm->arch.pgtable, gpa,NULL , &shift);if (ptep &&pte_present (*ptep)) kvmppc_unmap_pte(kvm, ptep, gpa, shift, memslot,
@@ -997,6 +1007,9 @@ int kvm_age_radix(struct kvm *kvm, struct kvm_memory_slot *memslot,int ref =0 ;unsigned long old, *rmapp; +if (kvmppc_is_guest_secure (kvm)) +return ref; + ptep =__find_linux_pte (kvm->arch.pgtable, gpa,NULL , &shift);if (ptep &&pte_present (*ptep) &&pte_young (*ptep)) { old = kvmppc_radix_update_pte(kvm, ptep, _PAGE_ACCESSED, 0,
@@ -1021,6 +1034,9 @@ int kvm_test_age_radix(struct kvm *kvm, struct kvm_memory_slot *memslot,unsigned int shift;int ref =0 ; +if (kvmppc_is_guest_secure (kvm)) +return ref; + ptep =__find_linux_pte (kvm->arch.pgtable, gpa,NULL , &shift);if (ptep &&pte_present (*ptep) &&pte_young (*ptep)) ref =1 ;
@@ -1038,6 +1054,9 @@ static int kvm_radix_test_clear_dirty(struct kvm *kvm,int ret =0 ;unsigned long old, *rmapp; +if (kvmppc_is_guest_secure (kvm)) +return ret; + ptep =__find_linux_pte (kvm->arch.pgtable, gpa,NULL , &shift);if (ptep &&pte_present (*ptep) &&pte_dirty (*ptep)) { ret =1 ;
arch/powerpc/kvm/book3s_hv_hmm.c +23 -0
@@ -55,6 +55,11 @@ struct kvmppc_hmm_migrate_args {unsigned long page_shift; }; +bool kvmppc_is_guest_secure (struct kvm *kvm) +{ +return !!(kvm->arch.secure_guest &KVMPPC_SECURE_INIT_DONE ); +} +unsigned long kvmppc_h_svm_init_start (struct kvm *kvm) {struct kvm_memslots *slots;
@@ -478,6 +483,24 @@ kvmppc_h_svm_page_out(struct kvm *kvm, unsigned long gpa,return ret; } +int kvmppc_send_page_to_uv (struct kvm *kvm,unsigned long gpa) +{ +int srcu_idx; +unsigned long pfn; +int ret; + + srcu_idx =srcu_read_lock (&kvm->srcu); + pfn =gfn_to_pfn (kvm, gpa >>PAGE_SHIFT ); +srcu_read_unlock (&kvm->srcu, srcu_idx); +if (is_error_noslot_pfn (pfn)) +return -EFAULT ; + + ret =uv_page_in (kvm->arch.lpid, pfn <<PAGE_SHIFT , gpa,0 ,PAGE_SHIFT ); +kvm_release_pfn_clean (pfn); + +return (ret =U_SUCCESS ) ?RESUME_GUEST : -EFAULT ; +} +static u64 kvmppc_get_secmem_size (void ) {struct device_node *np;
Signature · 1 line
2.17.1
RFC PATCH v4 6/6 kvmppc: Support reset of secure guest
In reply to Bharata B RaoAdd support for reset of secure guest via a new ioctl KVM_PPC_SVM_OFF. This ioctl will be issued by QEMU during reset and in this ioctl, we ask UV to terminate the guest via UV_SVM_TERMINATE ucall, reinitialize guest's partitioned scoped page tables and release all HMM pages of the secure guest.
After these steps, guest is ready to issue UV_ESM call once again to switch to secure mode.
[Implementation of uv_svm_terminate() and its call from guest shutdown path]
--- arch/powerpc/include/asm/kvm_host.h | 6 ++ arch/powerpc/include/asm/kvm_ppc.h | 4 ++ arch/powerpc/include/asm/ultravisor-api.h | 1 + arch/powerpc/include/asm/ultravisor.h | 7 ++ arch/powerpc/kvm/book3s_hv.c | 23 +++++++ arch/powerpc/kvm/book3s_hv_hmm.c | 83 +++++++++++++++++++++++ arch/powerpc/kvm/powerpc.c | 12 ++++ include/uapi/linux/kvm.h | 1 + tools/include/uapi/linux/kvm.h | 1 + 9 files changed, 138 insertions(+)
arch/powerpc/include/asm/kvm_host.h +6 -0
@@ -868,6 +868,7 @@ extern void kvmppc_hmm_free(void);extern void kvmppc_hmm_release_pfns (struct kvm_memory_slot *free);extern bool kvmppc_is_guest_secure (struct kvm *kvm);extern int kvmppc_send_page_to_uv (struct kvm *kvm,unsigned long gpa); +extern int kvmppc_hmm_svm_off (struct kvm *kvm);#else static inline int kvmppc_hmm_init (void ) {
@@ -887,6 +888,11 @@ static inline int kvmppc_send_page_to_uv(struct kvm *kvm, unsigned long gpa) {return -EFAULT ; } + +static inline int kvmppc_hmm_svm_off (struct kvm *kvm) +{ +return 0 ; +}#endif /* CONFIG_PPC_UV */ #endif /* __POWERPC_KVM_HOST_H__ */
arch/powerpc/include/asm/kvm_ppc.h +4 -0
@@ -188,6 +188,7 @@ extern void kvm_spapr_tce_release_iommu_group(struct kvm *kvm,extern int kvmppc_switch_mmu_to_hpt (struct kvm *kvm);extern int kvmppc_switch_mmu_to_radix (struct kvm *kvm);extern void kvmppc_setup_partition_table (struct kvm *kvm); +extern int kvmppc_reinit_partition_table (struct kvm *kvm);extern long kvm_vm_ioctl_create_spapr_tce (struct kvm *kvm,struct kvm_create_spapr_tce_64 *args);
@@ -332,6 +333,7 @@ struct kvmppc_ops { int size);int (*store_to_eaddr)(struct kvm_vcpu *vcpu,ulong *eaddr,void *ptr,int size); +int (*svm_off)(struct kvm *kvm); };extern struct kvmppc_ops *kvmppc_hv_ops;
@@ -961,5 +963,7 @@ static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb) }extern void xics_wake_cpu (int cpu); +extern void kvmppc_hmm_free_memslot_pfns (struct kvm *kvm, +struct kvm_memslots *slots);#endif /* __POWERPC_KVM_PPC_H__ */
arch/powerpc/include/asm/ultravisor-api.h +1 -0
@@ -25,5 +25,6 @@#define UV_PAGE_IN 0xF128#define UV_PAGE_OUT 0xF12C#define UV_PAGE_INVAL 0xF138 +#define UV_SVM_TERMINATE 0xF13C#endif /* _ASM_POWERPC_ULTRAVISOR_API_H */
arch/powerpc/include/asm/ultravisor.h +7 -0
@@ -84,6 +84,13 @@ static inline int uv_page_inval(u64 lpid, u64 gpa, u64 page_shift)return ucall (UV_PAGE_INVAL , retbuf, lpid, gpa, page_shift); } + +static inline int uv_svm_terminate (u64 lpid) +{ +unsigned long retbuf[UCALL_BUFSIZE ]; + +return ucall (UV_SVM_TERMINATE , retbuf, lpid); +}#endif /* !__ASSEMBLY__ */ #endif /* _ASM_POWERPC_ULTRAVISOR_H */
arch/powerpc/kvm/book3s_hv.c +23 -0
@@ -4571,6 +4571,22 @@ void kvmppc_setup_partition_table(struct kvm *kvm)kvmhv_set_ptbl_entry (kvm->arch.lpid, dw0, dw1); } +/* +* Called from KVM_PPC_SVM_OFF ioctl at guest reset time when secure +* guest is converted back to normal guest. +*/ +int kvmppc_reinit_partition_table (struct kvm *kvm) +{ +int ret; + + ret =kvmppc_init_vm_radix (kvm); +if (ret) +return ret; + +kvmppc_setup_partition_table (kvm); +return 0 ; +} +/* * Set up HPT (hashed page table) and RMA (real-mode area). * Must be called with kvm->lock held.
@@ -4950,6 +4966,7 @@ static void kvmppc_core_destroy_vm_hv(struct kvm *kvm)if (nesting_enabled (kvm))kvmhv_release_all_nested (kvm); kvm->arch.process_table =0 ; +uv_svm_terminate (kvm->arch.lpid);kvmhv_set_ptbl_entry (kvm->arch.lpid,0 ,0 ); }kvmppc_free_lpid (kvm->arch.lpid);
@@ -5391,6 +5408,11 @@ static int kvmhv_store_to_eaddr(struct kvm_vcpu *vcpu, ulong *eaddr, void *ptr,return rc; } +static int kvmhv_svm_off (struct kvm *kvm) +{ +return kvmppc_hmm_svm_off (kvm); +} +static struct kvmppc_ops kvm_ops_hv = { .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv,
@@ -5433,6 +5455,7 @@ static struct kvmppc_ops kvm_ops_hv = { .enable_nested = kvmhv_enable_nested, .load_from_eaddr = kvmhv_load_from_eaddr, .store_to_eaddr = kvmhv_store_to_eaddr, + .svm_off = kvmhv_svm_off, };static int kvm_init_subcore_bitmap (void )
arch/powerpc/kvm/book3s_hv_hmm.c +83 -0
107 lines not on this page · raw message
arch/powerpc/kvm/powerpc.c +12 -0
@@ -42,6 +42,8 @@#include <asm/hvcall.h> #include <asm/plpar_wrappers.h> #endif +#include <asm/ultravisor.h> +#include <asm/kvm_host.h> #include "timing.h" #include "irq.h"
@@ -2423,6 +2425,16 @@ long kvm_arch_vm_ioctl(struct file *filp, r = -EFAULT ;break ; } +case KVM_PPC_SVM_OFF : { +struct kvm *kvm = filp->private_data; + + r =0 ; +if (!kvm->arch.kvm_ops->svm_off) + goto out; + + r = kvm->arch.kvm_ops->svm_off (kvm); +break ; + }default : {struct kvm *kvm = filp->private_data; r = kvm->arch.kvm_ops->arch_vm_ioctl (filp, ioctl, arg);
include/uapi/linux/kvm.h +1 -0
@@ -1327,6 +1327,7 @@ struct kvm_s390_ucas_mapping {#define KVM_PPC_GET_RMMU_INFO _IOW(KVMIO, 0xb0, struct kvm_ppc_rmmu_info)/* Available with KVM_CAP_PPC_GET_CPU_CHAR */ #define KVM_PPC_GET_CPU_CHAR _IOR(KVMIO, 0xb1, struct kvm_ppc_cpu_char) +#define KVM_PPC_SVM_OFF _IO(KVMIO, 0xb2)/* ioctl for vm fd */ #define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device)
tools/include/uapi/linux/kvm.h +1 -0
@@ -1319,6 +1319,7 @@ struct kvm_s390_ucas_mapping {#define KVM_PPC_GET_RMMU_INFO _IOW(KVMIO, 0xb0, struct kvm_ppc_rmmu_info)/* Available with KVM_CAP_PPC_GET_CPU_CHAR */ #define KVM_PPC_GET_CPU_CHAR _IOR(KVMIO, 0xb1, struct kvm_ppc_cpu_char) +#define KVM_PPC_SVM_OFF _IO(KVMIO, 0xb2)/* ioctl for vm fd */ #define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device)
Signature · 1 line
2.17.1
Re: [RFC PATCH v4 6/6] kvmppc: Support reset of secure guest
Quoted 8 lines · Bharata B Rao
Add support for reset of secure guest via a new ioctl
KVM_PPC_SVM_OFF. This ioctl will be issued by QEMU during reset and in this ioctl, we ask UV to terminate the guest viaUV_SVM_TERMINATEucall, reinitialize guest's partitioned scoped page tables and release all HMM pages of the secure guest.After these steps, guest is ready to issue
UV_ESMcall once again to switch to secure mode.
Since you are adding a new KVM ioctl, you need to add a description of it to Documentation/virtual/kvm/api.txt.
Paul.
Re: [PATCH v4 1/6] kvmppc: HMM backend driver to manage pages of secure guest
In reply to Bharata B RaoQuoted 5 lines · Bharata B Rao
HMM driver for KVM PPC to manage page transitions of secure guest via
H_SVM_PAGE_INandH_SVM_PAGE_OUThcalls.
H_SVM_PAGE_IN: Move the content of a normal page to secure pageH_SVM_PAGE_OUT: Move the content of a secure page to normal page
Comments below...
arch/powerpc/kvm/book3s_hv.c static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *free, · line 4438
Quoted 5 lines
arch/powerpc/kvm/book3s_hv.c +1
-0@@ -4421,6 +4435,7 @@ static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {if (!dont || free->arch.rmap != dont->arch.rmap) { +kvmppc_hmm_release_pfns (free);
I don't think this is the right place to do this. The memslot will have no pages mapped by this time, because higher levels of code will have called kvmppc_core_flush_memslot_hv() before calling this. Releasing the pfns should be done in that function.
Quoted 3 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +0
-0
...
arch/powerpc/kvm/book3s_hv_hmm.c line 62
Quoted 6 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +6
-0+#define KVMPPC_PFN_HMM (0x1ULL << 61) + +static inline bool kvmppc_is_hmm_pfn (unsigned long pfn) +{ +return !!(pfn &KVMPPC_PFN_HMM ); +}
Since you are putting in these values in the rmap entries, you need to be careful about overlaps between these values and the other uses of rmap entries. The value you have chosen would be in the middle of the LPID field for an rmap entry for a guest that has nested guests, and in fact kvmhv_remove_nest_rmap_range() effectively assumes that a non-zero rmap entry must be a list of L2 guest mappings. (This is for radix guests; HPT guests use the rmap entry differently, but I am assuming that we will enforce that only radix guests can be secure guests.)
Maybe it is true that the rmap entry will be non-zero only for those guest pages which are not mapped on the host side, that is, kvmppc_radix_flush_memslot() will see !pte_present(*ptep) for any page of a secure guest where the rmap entry contains a HMM pfn. If that is so and is a deliberate part of the design, then I would like to see it written down in comments and commit messages so it's clear to others working on the code in future.
Suraj is working on support for nested HPT guests, which will involve changing the rmap format to indicate more explicitly what sort of entry each rmap entry is. Please work with him to define a format for your rmap entries that is clearly distinguishable from the others.
I think it is reasonable to say that a secure guest can't have nested guests, at least for now, but then we should make sure to kill all nested guests when a guest goes secure.
...
Quoted 15 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +15
-0+/* +* Move page from normal memory to secure memory. +*/ +unsigned long +kvmppc_h_svm_page_in (struct kvm *kvm,unsigned long gpa, +unsigned long flags,unsigned long page_shift) +{ +unsigned long addr, end; +unsigned long src_pfn, dst_pfn; +struct kvmppc_hmm_migrate_args args; +struct vm_area_struct *vma; +int srcu_idx; +unsigned long gfn = gpa >> page_shift; +struct kvm_memory_slot *slot; +unsigned long *rmap;
arch/powerpc/kvm/book3s_hv_hmm.c line 239
Quoted 10 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +10
-0+int ret =H_SUCCESS ; + +if (page_shift !=PAGE_SHIFT ) +return H_P3 ; + + srcu_idx =srcu_read_lock (&kvm->srcu); + slot =gfn_to_memslot (kvm, gfn); + rmap = &slot->arch.rmap[gfn - slot->base_gfn]; + addr =gfn_to_hva (kvm, gpa >> page_shift); +srcu_read_unlock (&kvm->srcu, srcu_idx);
Shouldn't we keep the srcu read lock until we have finished working on the page?
Quoted 27 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +27
-0+if (kvm_is_error_hva (addr)) +return H_PARAMETER ; + + end = addr + (1UL << page_shift); + +if (flags) +return H_P2 ; + + args.rmap = rmap; + args.lpid = kvm->arch.lpid; + args.gpa = gpa; + args.page_shift = page_shift; + +down_read (&kvm->mm->mmap_sem); + vma =find_vma_intersection (kvm->mm, addr, end); +if (!vma || vma->vm_start > addr || vma->vm_end < end) { + ret =H_PARAMETER ; + goto out; + } + ret =migrate_vma (&kvmppc_hmm_migrate_ops, vma, addr, end, + &src_pfn, &dst_pfn, &args); +if (ret <0 ) + ret =H_PARAMETER ; +out: +up_read (&kvm->mm->mmap_sem); +return ret; +}
...
Quoted 12 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +12
-0+/* +* Move page from secure memory to normal memory. +*/ +unsigned long +kvmppc_h_svm_page_out (struct kvm *kvm,unsigned long gpa, +unsigned long flags,unsigned long page_shift) +{ +unsigned long addr, end; +struct vm_area_struct *vma; +unsigned long src_pfn, dst_pfn =0 ; +int srcu_idx; +int ret =H_SUCCESS ;
arch/powerpc/kvm/book3s_hv_hmm.c line 374
Quoted 10 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +10
-0+ +if (page_shift !=PAGE_SHIFT ) +return H_P3 ; + +if (flags) +return H_P2 ; + + srcu_idx =srcu_read_lock (&kvm->srcu); + addr =gfn_to_hva (kvm, gpa >> page_shift); +srcu_read_unlock (&kvm->srcu, srcu_idx);
and likewise here, shouldn't we unlock later, after the migrate_vma() call perhaps?
Quoted 10 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +10
-0+if (kvm_is_error_hva (addr)) +return H_PARAMETER ; + + end = addr + (1UL << page_shift); + +down_read (&kvm->mm->mmap_sem); + vma =find_vma_intersection (kvm->mm, addr, end); +if (!vma || vma->vm_start > addr || vma->vm_end < end) { + ret =H_PARAMETER ; + goto out;
arch/powerpc/kvm/book3s_hv_hmm.c line 394
Quoted 10 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +10
-0+ } + ret =migrate_vma (&kvmppc_hmm_fault_migrate_ops, vma, addr, end, + &src_pfn, &dst_pfn,NULL ); +if (ret <0 ) + ret =H_PARAMETER ; +out: +up_read (&kvm->mm->mmap_sem); +return ret; +} +
Paul.
Re: [PATCH v4 3/6] kvmppc: H_SVM_INIT_START and H_SVM_INIT_DONE hcalls
In reply to Bharata B RaoQuoted 6 lines · Bharata B Rao
H_SVM_INIT_START: Initiate securing a VMH_SVM_INIT_DONE: Conclude securing a VMAs part of
H_SVM_INIT_STARTregister all existing memslots with the UV.H_SVM_INIT_DONEcall by UV informs HV that transition of the guest to secure mode is complete.
It is worth mentioning here that setting any of the flag bits in kvm->arch.secure_guest will cause the assembly code that enters the guest to call the UV_RETURN ucall instead of trying to enter the guest directly. That's not necessarily obvious to the reader as this patch doesn't touch that assembly code.
Apart from that this patch looks fine.
Quoted 1 line
Signed-off-by Bharata B Rao <[email protected]>
Re: [PATCH v4 4/6] kvmppc: Handle memory plug/unplug to secure VM
In reply to Bharata B RaoQuoted 4 lines · Bharata B Rao
Register the new memslot with UV during plug and unregister the memslot during unplug.
Signed-off-by Bharata B Rao <[email protected]>
Re: [PATCH v4 3/6] kvmppc: H_SVM_INIT_START and H_SVM_INIT_DONE hcalls
In reply to Bharata B RaoHello Bharata,
Quoted 19 lines · Bharata B Rao
arch/powerpc/include/asm/kvm_book3s_hmm.h +4
-0@@ -11,6 +11,8 @@ extern unsigned long kvmppc_h_svm_page_out(struct kvm *kvm,unsigned long gra, unsigned long flags, unsigned long page_shift); +extern unsigned long kvmppc_h_svm_init_start (struct kvm *kvm); +extern unsigned long kvmppc_h_svm_init_done (struct kvm *kvm);#else static inline unsigned long kvmppc_h_svm_page_in(struct kvm *kvm, unsigned long gra,@@ -25,5 +27,15 @@ kvmppc_h_svm_page_out(struct kvm *kvm, unsigned long gra, {return H_UNSUPPORTED ; } + +static inine unsigned long kvmppc_h_svm_init_start (struct kvm *kvm)
arch/powerpc/include/asm/kvm_book3s_hmm.h kvmppc_h_svm_page_out(struct kvm *kvm, unsigned long gra, · line 41
Quoted 10 lines
arch/powerpc/include/asm/kvm_book3s_hmm.h +8
-0+{ +return H_UNSUPPORTED ; +} + +static inine unsigned long kvmppc_h_svm_init_done (struct kvm *kvm); +{ +return H_UNSUPPORTED ; +}#endif /* CONFIG_PPC_UV */ #endif /* __POWERPC_KVM_PPC_HMM_H__ */
This patch won't build when CONFIG_PPC_UV isn't set because of two
typos: "inine" and the ';' at the end of kvmppc_h_svm_init_done() function prototype.
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
Re: [PATCH v4 1/6] kvmppc: HMM backend driver to manage pages of secure guest
In reply to Paul MackerrasQuoted 9 lines · Paul Mackerras
Quoted 5 lines · Bharata B Rao
HMM driver for KVM PPC to manage page transitions of secure guest via
H_SVM_PAGE_INandH_SVM_PAGE_OUThcalls.
H_SVM_PAGE_IN: Move the content of a normal page to secure pageH_SVM_PAGE_OUT: Move the content of a secure page to normal pageComments below...
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *free, · line 4438
Quoted 5 lines
arch/powerpc/kvm/book3s_hv.c +1
-0@@ -4421,6 +4435,7 @@ static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {if (!dont || free->arch.rmap != dont->arch.rmap) { +kvmppc_hmm_release_pfns (free);I don't think this is the right place to do this. The memslot will have no pages mapped by this time, because higher levels of code will have called
kvmppc_core_flush_memslot_hv()before calling this. Releasing the pfns should be done in that function.
In fact I can get rid of kvmppc_hmm_release_pfns() totally as we don't have to do free the HMM pages like this explicitly. During guest shutdown all these pages are dropped when unmap_vmas() is called.
Quoted 7 lines
Quoted 4 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +0
-0...
Quoted 16 lines
arch/powerpc/kvm/book3s_hv_hmm.c line 62
Quoted 6 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +6
-0+#define KVMPPC_PFN_HMM (0x1ULL << 61) + +static inline bool kvmppc_is_hmm_pfn (unsigned long pfn) +{ +return !!(pfn &KVMPPC_PFN_HMM ); +}Since you are putting in these values in the rmap entries, you need to be careful about overlaps between these values and the other uses of rmap entries. The value you have chosen would be in the middle of the LPID field for an rmap entry for a guest that has nested guests, and in fact
kvmhv_remove_nest_rmap_range()effectively assumes that a non-zero rmap entry must be a list of L2 guest mappings. (This is for radix guests; HPT guests use the rmap entry differently, but I am assuming that we will enforce that only radix guests can be secure guests.)
Worked out with Suraj on sharing the rmap and got a well defined bit slot for HMM PFNs in rmap.
Quoted 8 lines
Maybe it is true that the rmap entry will be non-zero only for those guest pages which are not mapped on the host side, that is,
kvmppc_radix_flush_memslot()will see !pte_present(*ptep) for any page of a secure guest where the rmap entry contains a HMM pfn. If that is so and is a deliberate part of the design, then I would like to see it written down in comments and commit messages so it's clear to others working on the code in future.
Yes, rmap entry will be non-zero only for those guest pages which are not mapped on the host side. However as soon as guest becomes secure we free the HV side partition scoped page tables and hence kvmppc_radix_flush_memslot() and other such routines which lookup kvm->arch.pgtable will no longer touch it.
Quoted 9 lines
Suraj is working on support for nested HPT guests, which will involve changing the rmap format to indicate more explicitly what sort of entry each rmap entry is. Please work with him to define a format for your rmap entries that is clearly distinguishable from the others.
I think it is reasonable to say that a secure guest can't have nested guests, at least for now, but then we should make sure to kill all nested guests when a guest goes secure.
Ok. Yet to figure this part out.
Quoted 23 lines
...
Quoted 20 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +20
-0+/* +* Move page from normal memory to secure memory. +*/ +unsigned long +kvmppc_h_svm_page_in (struct kvm *kvm,unsigned long gpa, +unsigned long flags,unsigned long page_shift) +{ +unsigned long addr, end; +unsigned long src_pfn, dst_pfn; +struct kvmppc_hmm_migrate_args args; +struct vm_area_struct *vma; +int srcu_idx; +unsigned long gfn = gpa >> page_shift; +struct kvm_memory_slot *slot; +unsigned long *rmap; +int ret =H_SUCCESS ; + +if (page_shift !=PAGE_SHIFT ) +return H_P3 ; +
Quoted 8 lines
arch/powerpc/kvm/book3s_hv_hmm.c line 239
Quoted 5 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +5
-0+ srcu_idx =srcu_read_lock (&kvm->srcu); + slot =gfn_to_memslot (kvm, gfn); + rmap = &slot->arch.rmap[gfn - slot->base_gfn]; + addr =gfn_to_hva (kvm, gpa >> page_shift); +srcu_read_unlock (&kvm->srcu, srcu_idx);Shouldn't we keep the srcu read lock until we have finished working on the page?
I wasn't sure, so keeping it locked till the end in the next version.
Quoted 48 lines
Quoted 28 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +27
-0+if (kvm_is_error_hva (addr)) +return H_PARAMETER ; + + end = addr + (1UL << page_shift); + +if (flags) +return H_P2 ; + + args.rmap = rmap; + args.lpid = kvm->arch.lpid; + args.gpa = gpa; + args.page_shift = page_shift; + +down_read (&kvm->mm->mmap_sem); + vma =find_vma_intersection (kvm->mm, addr, end); +if (!vma || vma->vm_start > addr || vma->vm_end < end) { + ret =H_PARAMETER ; + goto out; + } + ret =migrate_vma (&kvmppc_hmm_migrate_ops, vma, addr, end, + &src_pfn, &dst_pfn, &args); +if (ret <0 ) + ret =H_PARAMETER ; +out: +up_read (&kvm->mm->mmap_sem); +return ret; +}...
Quoted 17 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +17
-0+/* +* Move page from secure memory to normal memory. +*/ +unsigned long +kvmppc_h_svm_page_out (struct kvm *kvm,unsigned long gpa, +unsigned long flags,unsigned long page_shift) +{ +unsigned long addr, end; +struct vm_area_struct *vma; +unsigned long src_pfn, dst_pfn =0 ; +int srcu_idx; +int ret =H_SUCCESS ; + +if (page_shift !=PAGE_SHIFT ) +return H_P3 ; + +if (flags)
Quoted 8 lines
arch/powerpc/kvm/book3s_hv_hmm.c line 374
Quoted 5 lines
arch/powerpc/kvm/book3s_hv_hmm.c new file +5
-0+return H_P2 ; + + srcu_idx =srcu_read_lock (&kvm->srcu); + addr =gfn_to_hva (kvm, gpa >> page_shift); +srcu_read_unlock (&kvm->srcu, srcu_idx);and likewise here, shouldn't we unlock later, after the
migrate_vma()call perhaps?
Sure.
Regards,
Bharata.
Re: [PATCH v4 3/6] kvmppc: H_SVM_INIT_START and H_SVM_INIT_DONE hcalls
In reply to Paul MackerrasQuoted 8 lines · Paul Mackerras
Quoted 6 lines · Bharata B Rao
H_SVM_INIT_START: Initiate securing a VMH_SVM_INIT_DONE: Conclude securing a VMAs part of
H_SVM_INIT_STARTregister all existing memslots with the UV.H_SVM_INIT_DONEcall by UV informs HV that transition of the guest to secure mode is complete.
Quoted 5 lines
It is worth mentioning here that setting any of the flag bits in
kvm->arch.secure_guestwill cause the assembly code that enters the guest to call theUV_RETURNucall instead of trying to enter the guest directly. That's not necessarily obvious to the reader as this patch doesn't touch that assembly code.
Documented this in the commit message.
Quoted 6 lines
Apart from that this patch looks fine.
Quoted 1 line
Signed-off-by Bharata B Rao <[email protected]>Acked-by Paul Mackerras <[email protected]>
Thanks,
Bharata.
Re: [PATCH v4 3/6] kvmppc: H_SVM_INIT_START and H_SVM_INIT_DONE hcalls
In reply to Thiago Jung BauermannQuoted 30 lines · Thiago Jung Bauermann
Hello Bharata,
Quoted 25 lines · Bharata B Rao
arch/powerpc/include/asm/kvm_book3s_hmm.h +10
-0@@ -11,6 +11,8 @@ extern unsigned long kvmppc_h_svm_page_out(struct kvm *kvm,unsigned long gra, unsigned long flags, unsigned long page_shift); +extern unsigned long kvmppc_h_svm_init_start (struct kvm *kvm); +extern unsigned long kvmppc_h_svm_init_done (struct kvm *kvm);#else static inline unsigned long kvmppc_h_svm_page_in(struct kvm *kvm, unsigned long gra,@@ -25,5 +27,15 @@ kvmppc_h_svm_page_out(struct kvm *kvm, unsigned long gra, {return H_UNSUPPORTED ; } + +static inine unsigned long kvmppc_h_svm_init_start (struct kvm *kvm) +{ +return H_UNSUPPORTED ; +} + +static inine unsigned long kvmppc_h_svm_init_done (struct kvm *kvm); +{
Quoted 8 lines
arch/powerpc/include/asm/kvm_book3s_hmm.h kvmppc_h_svm_page_out(struct kvm *kvm, unsigned long gra, · line 41
Quoted 4 lines
arch/powerpc/include/asm/kvm_book3s_hmm.h +2
-0+return H_UNSUPPORTED ; +}#endif /* CONFIG_PPC_UV */ #endif /* __POWERPC_KVM_PPC_HMM_H__ */ This patch won't build when
CONFIG_PPC_UVisn't set because of two
typos: "inine" and the ';' at the end ofkvmppc_h_svm_init_done()function prototype.
Thanks. Fixed this.
Regards,
Bharata.
Re: [RFC PATCH v4 6/6] kvmppc: Support reset of secure guest
In reply to Paul MackerrasQuoted 7 lines · Paul Mackerras
Quoted 6 lines · Bharata B Rao
Add support for reset of secure guest via a new ioctl
KVM_PPC_SVM_OFF. This ioctl will be issued by QEMU during reset and in this ioctl, we ask UV to terminate the guest viaUV_SVM_TERMINATEucall, reinitialize guest's partitioned scoped page tables and release all HMM pages of the secure guest.
Quoted 5 lines
Quoted 2 lines
After these steps, guest is ready to issue
UV_ESMcall once again to switch to secure mode.Since you are adding a new KVM ioctl, you need to add a description of it to
Documentation/virtual/kvm/api.txt.
Adding in the next version.
Regards,
Bharata.