From: Nicholas Piggin <npiggin@gmail.com>
To: Fabiano Rosas <farosas@linux.ibm.com>, kvm-ppc@vger.kernel.org
Cc: aik@ozlabs.ru, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v2 4/4] KVM: PPC: Decrement module refcount if init_vm fails
Date: Tue, 25 Jan 2022 03:46:42 +0000 [thread overview]
Message-ID: <1643082153.tb99kluqtm.astroid@bobo.none> (raw)
In-Reply-To: <20220124220803.1011673-5-farosas@linux.ibm.com>
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 <farosas@linux.ibm.com>
> ---
> 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
> ---
> arch/powerpc/kvm/powerpc.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
> index 2ad0ccd202d5..4285d0eac900 100644
> --- a/arch/powerpc/kvm/powerpc.c
> +++ b/arch/powerpc/kvm/powerpc.c
> @@ -431,6 +431,8 @@ int kvm_arch_check_processor_compat(void *opaque)
> int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
> {
> struct kvmppc_ops *kvm_ops = NULL;
> + int r;
> +
> /*
> * if we have both HV and PR enabled, default is HV
> */
> @@ -456,7 +458,10 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
> return -ENOENT;
>
> kvm->arch.kvm_ops = kvm_ops;
> - return kvmppc_core_init_vm(kvm);
> + r = kvmppc_core_init_vm(kvm);
> + if (r)
> + module_put(kvm->arch.kvm_ops->owner);
> + return r;
> err_out:
> return -EINVAL;
> }
> --
> 2.34.1
>
>
next prev parent reply other threads:[~2022-01-25 3:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 22:07 [PATCH v2 0/4] KVM: PPC: KVM module exit fixes Fabiano Rosas
2022-01-24 22:08 ` [PATCH v2 1/4] KVM: PPC: Book3S HV: Check return value of kvmppc_radix_init Fabiano Rosas
2022-01-24 22:08 ` [PATCH v2 2/4] KVM: PPC: Book3S HV: Delay setting of kvm ops Fabiano Rosas
2022-01-24 22:08 ` [PATCH v2 3/4] KVM: PPC: Book3S HV: Free allocated memory if module init fails Fabiano Rosas
2022-01-24 22:08 ` [PATCH v2 4/4] KVM: PPC: Decrement module refcount if init_vm fails Fabiano Rosas
2022-01-25 3:46 ` Nicholas Piggin [this message]
2022-01-25 15:08 ` Fabiano Rosas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1643082153.tb99kluqtm.astroid@bobo.none \
--to=npiggin@gmail.com \
--cc=aik@ozlabs.ru \
--cc=farosas@linux.ibm.com \
--cc=kvm-ppc@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox