On 31/03/2021 11:32, Roger Pau Monne wrote:
> @@ -1620,9 +1666,22 @@ int vlapic_init(struct vcpu *v)
>  
>      clear_page(vlapic->regs);
>  
> +    vlapic->callbacks = xmalloc_array(typeof(*vlapic->callbacks),
> +                                      X86_NR_VECTORS - 16);
> +    if ( !vlapic->callbacks )
> +    {
> +        dprintk(XENLOG_ERR, "%pv: alloc vlapic callbacks error\n", v);
> +        unmap_domain_page_global(vlapic->regs);
> +        free_domheap_page(vlapic->regs_page);
> +        return -ENOMEM;
> +    }
> +    memset(vlapic->callbacks, 0,
> +           sizeof(*vlapic->callbacks) * (X86_NR_VECTORS - 16));

xzalloc_array() instead of memset().  Also, we shouldn't be printing for
-ENOMEM cases.

As for the construction/teardown logic, vlapic_init()'s caller already
vlapic_destory().  Therefore, the existing error path you've copied is
buggy because it will cause a double-free if __map_domain_page_global()
fails.

I'll do a cleanup patch to fix the idempotency, which needs backporting too.

~Andrew


Reply via email to