On Fri, Mar 20, 2020 at 10:17:13AM +1100, Paul Mackerras wrote: > On Thu, Mar 19, 2020 at 12:41:08PM -0700, Ram Pai wrote: > > On Thu, Mar 19, 2020 at 03:33:01PM +1100, Paul Mackerras wrote: > [snip] > > > --- a/arch/powerpc/kvm/powerpc.c > > > +++ b/arch/powerpc/kvm/powerpc.c > > > @@ -670,6 +670,11 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) > > > (hv_enabled && cpu_has_feature(CPU_FTR_P9_TM_HV_ASSIST)); > > > break; > > > #endif > > > +#if defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE) && defined(CONFIG_PPC_UV) > > > + case KVM_CAP_PPC_SECURE_GUEST: > > > + r = hv_enabled && !!firmware_has_feature(FW_FEATURE_ULTRAVISOR); > > > > We also need to check if the kvmppc_uvmem_init() has been successfully > > called and initialized. > > > > r = hv_enabled && !!firmware_has_feature(FW_FEATURE_ULTRAVISOR) > > && kvmppc_uvmem_bitmap; > > Well I can't do that exactly because kvmppc_uvmem_bitmap is in a > different module (the kvm_hv module, whereas this code is in the kvm > module), and I wouldn't want to depend on kvmppc_uvmem_bitmap, since > that's an internal implementation detail. yes. checking for kvmppc_uvmem_bitmap depends on internal implementation detail. Its also a loose approximation. There has to be something better which can tell, if everything needed to support secure guests, is available and initialized. > > The firmware_has_feature(FW_FEATURE_ULTRAVISOR) test ultimately > depends on there being a device tree node with "ibm,ultravisor" in its > compatible property (see early_init_dt_scan_ultravisor()). So that > means there is an ultravisor there. The cases where that test would > pass but kvmppc_uvmem_bitmap == NULL would be those where the device > tree nodes are present but not right, or where the host is so short of > memory that it couldn't allocate the kvmppc_uvmem_bitmap. If you > think those cases are worth worrying about then I will have to devise > a way to do the test without depending on any symbols from the kvm-hv > module. the cases, where incorrect behavior can happen; if we do not have this additional check, are -- a) zero secure memory in the system. b) "kvmppc_uvmem" memory region is not defined. c) the memory region fails to map. d) kvmppc_uvmem_bitmap allocation failed. All these are possible to varying level of certainity. I do not know we should be concerned about these possibilities. But if we do, than will a patch like this help? compile tested. ------------------ diff --git a/arch/powerpc/include/asm/kvm_book3s_uvmem.h b/arch/powerpc/include/asm/kvm_book3s_uvmem.h index 5a9834e..643c497 100644 --- a/arch/powerpc/include/asm/kvm_book3s_uvmem.h +++ b/arch/powerpc/include/asm/kvm_book3s_uvmem.h @@ -4,6 +4,7 @@ #ifdef CONFIG_PPC_UV int kvmppc_uvmem_init(void); +int kvmppc_uv_enabled(void); void kvmppc_uvmem_free(void); int kvmppc_uvmem_slot_init(struct kvm *kvm, const struct kvm_memory_slot *slot); void kvmppc_uvmem_slot_free(struct kvm *kvm, @@ -28,6 +29,11 @@ static inline int kvmppc_uvmem_init(void) return 0; } +static inline int kvmppc_uv_enabled(void) +{ + return 0; +} + static inline void kvmppc_uvmem_free(void) { } static inline int diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c b/arch/powerpc/kvm/book3s_hv_uvmem.c index 79b1202..3331ac5 100644 --- a/arch/powerpc/kvm/book3s_hv_uvmem.c +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c @@ -804,6 +804,11 @@ int kvmppc_uvmem_init(void) return ret; } +int kvmppc_uv_enabled(void) +{ + return !kvmppc_uvmem_bitmap; +} + void kvmppc_uvmem_free(void) { memunmap_pages(&kvmppc_uvmem_pgmap); ------------------ > > Paul. -- Ram Pai