diff mbox

[v5,4/5] KVM: irqfd: use kvm_arch_is_virtual_intc_initialized

Message ID 1417622832-5460-5-git-send-email-eric.auger@linaro.org
State New
Headers show

Commit Message

Auger Eric Dec. 3, 2014, 4:07 p.m. UTC
On arm/arm64, the interrupt controller is dynamically instantiated.
There is a risk the user-space assigns an irqfd before this latter
is initialized and ready to accept virtual irq injection. On such
attempt, the IRQFD setup is rejected and -EAGAIN is returned.

Signed-off-by: Eric Auger <eric.auger@linaro.org>
---
 virt/kvm/eventfd.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Christoffer Dall Jan. 11, 2015, 9:17 p.m. UTC | #1
On Wed, Dec 03, 2014 at 05:07:11PM +0100, Eric Auger wrote:
> On arm/arm64, the interrupt controller is dynamically instantiated.
> There is a risk the user-space assigns an irqfd before this latter
> is initialized and ready to accept virtual irq injection. On such
> attempt, the IRQFD setup is rejected and -EAGAIN is returned.
> 
> Signed-off-by: Eric Auger <eric.auger@linaro.org>
> ---
>  virt/kvm/eventfd.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
> index b0fb390..f837c83 100644
> --- a/virt/kvm/eventfd.c
> +++ b/virt/kvm/eventfd.c
> @@ -314,6 +314,9 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
>  	unsigned int events;
>  	int idx;
>  
> +	if (!kvm_arch_is_virtual_intc_initialized(kvm))
> +		return -EAGAIN;
> +

You can fold this into the patch that defines the static inline since
nothing defines the KVM_HAVE_ARCH_... yet.

>  	irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL);
>  	if (!irqfd)
>  		return -ENOMEM;
> -- 
> 1.9.1
>
Auger Eric Jan. 12, 2015, 1:40 p.m. UTC | #2
On 01/11/2015 10:17 PM, Christoffer Dall wrote:
> On Wed, Dec 03, 2014 at 05:07:11PM +0100, Eric Auger wrote:
>> On arm/arm64, the interrupt controller is dynamically instantiated.
>> There is a risk the user-space assigns an irqfd before this latter
>> is initialized and ready to accept virtual irq injection. On such
>> attempt, the IRQFD setup is rejected and -EAGAIN is returned.
>>
>> Signed-off-by: Eric Auger <eric.auger@linaro.org>
>> ---
>>  virt/kvm/eventfd.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
>> index b0fb390..f837c83 100644
>> --- a/virt/kvm/eventfd.c
>> +++ b/virt/kvm/eventfd.c
>> @@ -314,6 +314,9 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
>>  	unsigned int events;
>>  	int idx;
>>  
>> +	if (!kvm_arch_is_virtual_intc_initialized(kvm))
>> +		return -EAGAIN;
>> +
> 
> You can fold this into the patch that defines the static inline since
> nothing defines the KVM_HAVE_ARCH_... yet.
Not sure to understand what you mean:
__KVM_HAVE_ARCH_VIRTUAL_INTC_INITIALIZED was defined in previous patch
file (3/5). Nethertheless I can drop that patch file.

Thanks

Eric
> 
>>  	irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL);
>>  	if (!irqfd)
>>  		return -ENOMEM;
>> -- 
>> 1.9.1
>>
Christoffer Dall Jan. 12, 2015, 4:55 p.m. UTC | #3
On Mon, Jan 12, 2015 at 02:40:03PM +0100, Eric Auger wrote:
> On 01/11/2015 10:17 PM, Christoffer Dall wrote:
> > On Wed, Dec 03, 2014 at 05:07:11PM +0100, Eric Auger wrote:
> >> On arm/arm64, the interrupt controller is dynamically instantiated.
> >> There is a risk the user-space assigns an irqfd before this latter
> >> is initialized and ready to accept virtual irq injection. On such
> >> attempt, the IRQFD setup is rejected and -EAGAIN is returned.
> >>
> >> Signed-off-by: Eric Auger <eric.auger@linaro.org>
> >> ---
> >>  virt/kvm/eventfd.c | 3 +++
> >>  1 file changed, 3 insertions(+)
> >>
> >> diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
> >> index b0fb390..f837c83 100644
> >> --- a/virt/kvm/eventfd.c
> >> +++ b/virt/kvm/eventfd.c
> >> @@ -314,6 +314,9 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
> >>  	unsigned int events;
> >>  	int idx;
> >>  
> >> +	if (!kvm_arch_is_virtual_intc_initialized(kvm))
> >> +		return -EAGAIN;
> >> +
> > 
> > You can fold this into the patch that defines the static inline since
> > nothing defines the KVM_HAVE_ARCH_... yet.
> Not sure to understand what you mean:
> __KVM_HAVE_ARCH_VIRTUAL_INTC_INITIALIZED was defined in previous patch
> file (3/5). Nethertheless I can drop that patch file.
> 
I'm just saying that you don't need to split this into multiple patches.

-Christoffer
diff mbox

Patch

diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index b0fb390..f837c83 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -314,6 +314,9 @@  kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
 	unsigned int events;
 	int idx;
 
+	if (!kvm_arch_is_virtual_intc_initialized(kvm))
+		return -EAGAIN;
+
 	irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL);
 	if (!irqfd)
 		return -ENOMEM;