All of lore.kernel.org
 help / color / mirror / Atom feed
From: marc.zyngier@arm.com (Marc Zyngier)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] virt: kvm: arm: vgic: Process the failure case when kvm_register_device_ops() fails
Date: Fri, 14 Nov 2014 14:09:55 +0000	[thread overview]
Message-ID: <54660D33.5090309@arm.com> (raw)
In-Reply-To: <54660C32.6090602@gmail.com>

On 14/11/14 14:05, Chen Gang wrote:
> On 11/13/2014 11:30 PM, Marc Zyngier wrote:
>> On 13/11/14 15:04, Chen Gang wrote:
>>> When kvm_register_device_ops() fails, also need call free_percpu_irq()
>>> just like others have down within kvm_vgic_hyp_init().
>>>
>>> Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
>>> ---
>>>  virt/kvm/arm/vgic.c | 10 ++++++++--
>>>  1 file changed, 8 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
>>> index 3aaca49..b799f17 100644
>>> --- a/virt/kvm/arm/vgic.c
>>> +++ b/virt/kvm/arm/vgic.c
>>> @@ -2470,8 +2470,14 @@ int kvm_vgic_hyp_init(void)
>>>  
>>>  	on_each_cpu(vgic_init_maintenance_interrupt, NULL, 1);
>>>  
>>> -	return kvm_register_device_ops(&kvm_arm_vgic_v2_ops,
>>> -				       KVM_DEV_TYPE_ARM_VGIC_V2);
>>> +	ret = kvm_register_device_ops(&kvm_arm_vgic_v2_ops,
>>> +				      KVM_DEV_TYPE_ARM_VGIC_V2);
>>> +	if (ret) {
>>> +		kvm_err("Cannot register device ops\n");
>>> +		goto out_free_irq;
>>> +	}
>>> +
>>> +	return 0;
>>>  
>>>  out_free_irq:
>>>  	free_percpu_irq(vgic->maint_irq, kvm_get_running_vcpus());
>>>
>>
>> Awesome. You're now freeing a per-cpu interrupt after just after having
>> enabled it on all CPUs. What could possibly go wrong?
>>
> 
> OK, thanks. What you said sound reasonable to me. Need call on_each_cpu
> for disable_percpu_irq(). Also need call __unregister_cpu_notifier(),
> and need a new function vgic_arch_unsetup() for arm64.

No. Just look at the code. Why don't you just move the
kvm_register_device_ops call *before* enabling the interrupt?

	M.
-- 
Jazz is not dead. It just smells funny...

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <marc.zyngier@arm.com>
To: Chen Gang <gang.chen.5i5j@gmail.com>
Cc: "christoffer.dall@linaro.org" <christoffer.dall@linaro.org>,
	"gleb@kernel.org" <gleb@kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] virt: kvm: arm: vgic: Process the failure case when kvm_register_device_ops() fails
Date: Fri, 14 Nov 2014 14:09:55 +0000	[thread overview]
Message-ID: <54660D33.5090309@arm.com> (raw)
In-Reply-To: <54660C32.6090602@gmail.com>

On 14/11/14 14:05, Chen Gang wrote:
> On 11/13/2014 11:30 PM, Marc Zyngier wrote:
>> On 13/11/14 15:04, Chen Gang wrote:
>>> When kvm_register_device_ops() fails, also need call free_percpu_irq()
>>> just like others have down within kvm_vgic_hyp_init().
>>>
>>> Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
>>> ---
>>>  virt/kvm/arm/vgic.c | 10 ++++++++--
>>>  1 file changed, 8 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
>>> index 3aaca49..b799f17 100644
>>> --- a/virt/kvm/arm/vgic.c
>>> +++ b/virt/kvm/arm/vgic.c
>>> @@ -2470,8 +2470,14 @@ int kvm_vgic_hyp_init(void)
>>>  
>>>  	on_each_cpu(vgic_init_maintenance_interrupt, NULL, 1);
>>>  
>>> -	return kvm_register_device_ops(&kvm_arm_vgic_v2_ops,
>>> -				       KVM_DEV_TYPE_ARM_VGIC_V2);
>>> +	ret = kvm_register_device_ops(&kvm_arm_vgic_v2_ops,
>>> +				      KVM_DEV_TYPE_ARM_VGIC_V2);
>>> +	if (ret) {
>>> +		kvm_err("Cannot register device ops\n");
>>> +		goto out_free_irq;
>>> +	}
>>> +
>>> +	return 0;
>>>  
>>>  out_free_irq:
>>>  	free_percpu_irq(vgic->maint_irq, kvm_get_running_vcpus());
>>>
>>
>> Awesome. You're now freeing a per-cpu interrupt after just after having
>> enabled it on all CPUs. What could possibly go wrong?
>>
> 
> OK, thanks. What you said sound reasonable to me. Need call on_each_cpu
> for disable_percpu_irq(). Also need call __unregister_cpu_notifier(),
> and need a new function vgic_arch_unsetup() for arm64.

No. Just look at the code. Why don't you just move the
kvm_register_device_ops call *before* enabling the interrupt?

	M.
-- 
Jazz is not dead. It just smells funny...

  reply	other threads:[~2014-11-14 14:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-13 15:04 [PATCH] virt: kvm: arm: vgic: Process the failure case when kvm_register_device_ops() fails Chen Gang
2014-11-13 15:04 ` Chen Gang
2014-11-13 15:04 ` Chen Gang
2014-11-13 15:30 ` Marc Zyngier
2014-11-13 15:30   ` Marc Zyngier
2014-11-14 14:05   ` Chen Gang
2014-11-14 14:05     ` Chen Gang
2014-11-14 14:05   ` Chen Gang
2014-11-14 14:05     ` Chen Gang
2014-11-14 14:09     ` Marc Zyngier [this message]
2014-11-14 14:09       ` Marc Zyngier
2014-11-14 14:27       ` Chen Gang
2014-11-14 14:27         ` Chen Gang
2014-11-14 14:53         ` Marc Zyngier
2014-11-14 14:53           ` Marc Zyngier
2014-11-14 15:18           ` Chen Gang
2014-11-14 15:18             ` Chen Gang

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=54660D33.5090309@arm.com \
    --to=marc.zyngier@arm.com \
    --cc=linux-arm-kernel@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.