This is a resend the module cleanup fixes but this time without the
HV/PR merge.
Fabiano Rosas (1):
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
arch/powerpc/kvm/book3s_hv.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
--
2.33.1
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>
---
arch/powerpc/kvm/book3s_hv.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
@@ -6065,7 +6065,7 @@ static int kvmppc_book3s_init_hv(void)r=kvm_init_subcore_bitmap();if(r)-returnr;+gotoerr;/**WeneedawayofaccessingtheXICSinterruptcontroller,
@@ -6080,7 +6080,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);
@@ -6093,12 +6094,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();
@@ -6111,6 +6112,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)
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>
---
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(-)
From: Nicholas Piggin <npiggin@gmail.com> Date: 2021-12-25 10:20:31
Excerpts from Fabiano Rosas's message of December 24, 2021 7:19 am:
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>
Also looks okay to me but KVM init has lots of details. IIRC Alexey may
have run into a related issue with ops being set too early (or was it
cleared too late?)
Thanks,
Nick
From: Nicholas Piggin <npiggin@gmail.com> Date: 2021-12-25 10:23:27
Excerpts from Fabiano Rosas's message of December 24, 2021 7:19 am:
quoted hunk
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>
---
arch/powerpc/kvm/book3s_hv.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
@@ -6065,7 +6065,7 @@ static int kvmppc_book3s_init_hv(void)r=kvm_init_subcore_bitmap();if(r)-returnr;+gotoerr;/**WeneedawayofaccessingtheXICSinterruptcontroller,
@@ -6080,7 +6080,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);
@@ -6093,12 +6094,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();
@@ -6111,6 +6112,12 @@ static int kvmppc_book3s_init_hv(void)kvmppc_hv_ops=&kvm_ops_hv;return0;++err:+kvmhv_nested_exit();+kvmppc_radix_exit();
These should both be callable without init functions succeeding
so this looks right to me.
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Thanks,
Nick
Excerpts from Fabiano Rosas's message of December 24, 2021 7:19 am:
quoted
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(-)
@@ -6087,9 +6087,6 @@ static int kvmppc_book3s_init_hv(void)}#endif-kvm_ops_hv.owner=THIS_MODULE;-kvmppc_hv_ops=&kvm_ops_hv;-init_default_hcalls();init_vcore_lists();
@@ -6105,10 +6102,15 @@ static int kvmppc_book3s_init_hv(void)}r=kvmppc_uvmem_init();-if(r<0)+if(r<0){pr_err("KVM-HV: kvmppc_uvmem_init failed %d\n",r);+returnr;+}-returnr;+kvm_ops_hv.owner=THIS_MODULE;+kvmppc_hv_ops=&kvm_ops_hv;++return0;}staticvoidkvmppc_book3s_exit_hv(void)
--
2.33.1
Also looks okay to me but KVM init has lots of details. IIRC Alexey may
have run into a related issue with ops being set too early (or was it
cleared too late?)
Thanks,
Nick
From: Michael Ellerman <hidden> Date: 2022-02-18 02:11:02
On Thu, 23 Dec 2021 18:19:28 -0300, Fabiano Rosas wrote:
This is a resend the module cleanup fixes but this time without the
HV/PR merge.
Fabiano Rosas (1):
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
[...]
From: Michael Ellerman <mpe@ellerman.id.au> Date: 2022-03-12 10:43:00
Michael Ellerman [off-list ref] writes:
On Thu, 23 Dec 2021 18:19:28 -0300, Fabiano Rosas wrote:
quoted
This is a resend the module cleanup fixes but this time without the
HV/PR merge.
Fabiano Rosas (1):
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
[...]