I stumbled upon another issue with our module exit so I'm sending
another version to add a fix for it.
- patches 1 and 3 are already reviewed;
- patch 2 lacks a Reviewed-by. Nick asked about an issue Alexey might
have encountered. I haven't heard of any issues with the module exit
aside from the ones that this series fixes;
- patch 4 is new. It fixes an issue with module refcounting.
v1:
https://lore.kernel.org/r/20211223211931.3560887-1-farosas@linux.ibm.com
Fabiano Rosas (4):
KVM: PPC: Book3S HV: Check return value of kvmppc_radix_init
KVM: PPC: Book3S HV: Delay setting of kvm ops
KVM: PPC: Book3S HV: Free allocated memory if module init fails
KVM: PPC: Decrement module refcount if init_vm fails
arch/powerpc/kvm/book3s_hv.c | 28 ++++++++++++++++++++--------
arch/powerpc/kvm/powerpc.c | 7 ++++++-
2 files changed, 26 insertions(+), 9 deletions(-)
--
2.34.1
The return of the function is being shadowed by the call to
kvmppc_uvmem_init.
Fixes: ca9f4942670c ("KVM: PPC: Book3S HV: Support for running secure guests")
Signed-off-by: Fabiano Rosas <redacted>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/kvm/book3s_hv.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Delay the setting of kvm_hv_ops until after all init code has
completed. This avoids leaving the ops still accessible if the init
fails.
Signed-off-by: Fabiano Rosas <redacted>
---
arch/powerpc/kvm/book3s_hv.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
The module's exit function is not called when the init fails, we need
to do cleanup before returning.
Signed-off-by: Fabiano Rosas <redacted>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/kvm/book3s_hv.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
@@ -6104,7 +6104,7 @@ static int kvmppc_book3s_init_hv(void)if(!cpu_has_feature(CPU_FTR_ARCH_300)){r=kvm_init_subcore_bitmap();if(r)-returnr;+gotoerr;}/*
@@ -6120,7 +6120,8 @@ static int kvmppc_book3s_init_hv(void)np=of_find_compatible_node(NULL,NULL,"ibm,opal-intc");if(!np){pr_err("KVM-HV: Cannot determine method for accessing XICS\n");-return-ENODEV;+r=-ENODEV;+gotoerr;}/* presence of intc confirmed - node can be dropped again */of_node_put(np);
@@ -6133,12 +6134,12 @@ static int kvmppc_book3s_init_hv(void)r=kvmppc_mmu_hv_init();if(r)-returnr;+gotoerr;if(kvmppc_radix_possible()){r=kvmppc_radix_init();if(r)-returnr;+gotoerr;}r=kvmppc_uvmem_init();
@@ -6151,6 +6152,12 @@ static int kvmppc_book3s_init_hv(void)kvmppc_hv_ops=&kvm_ops_hv;return0;++err:+kvmhv_nested_exit();+kvmppc_radix_exit();++returnr;}staticvoidkvmppc_book3s_exit_hv(void)
We increment the reference count for KVM-HV/PR before the call to
kvmppc_core_init_vm. If that function fails we need to decrement the
refcount.
Signed-off-by: Fabiano Rosas <redacted>
---
Caught this while testing Nick's LPID patches by looking at
/sys/module/kvm_hv/refcnt
---
arch/powerpc/kvm/powerpc.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
From: Nicholas Piggin <npiggin@gmail.com> Date: 2022-01-25 03:47:33
Excerpts from Fabiano Rosas's message of January 25, 2022 8:08 am:
We increment the reference count for KVM-HV/PR before the call to
kvmppc_core_init_vm. If that function fails we need to decrement the
refcount.
Signed-off-by: Fabiano Rosas <redacted>
---
Caught this while testing Nick's LPID patches by looking at
/sys/module/kvm_hv/refcnt
Nice catch. Is this the only change in the series?
You can just use kvm_ops->owner like try_module_get() does I think? Also
try_module_get works on a NULL module same as module_put by the looks,
so you could adjust that in this patch to remove the NULL check so it
is consistent with the put.
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Thanks,
Nick
Excerpts from Fabiano Rosas's message of January 25, 2022 8:08 am:
quoted
We increment the reference count for KVM-HV/PR before the call to
kvmppc_core_init_vm. If that function fails we need to decrement the
refcount.
Signed-off-by: Fabiano Rosas <redacted>
---
Caught this while testing Nick's LPID patches by looking at
/sys/module/kvm_hv/refcnt
Nice catch. Is this the only change in the series?
Yes.
You can just use kvm_ops->owner like try_module_get() does I think? Also
try_module_get works on a NULL module same as module_put by the looks,
so you could adjust that in this patch to remove the NULL check so it
is consistent with the put.