[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] xen/arm: p2m: Populate pages for GICv2 mapping in arch_domain_create()


  • To: Henry Wang <Henry.Wang@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • Date: Thu, 13 Oct 2022 09:32:24 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XAdWOeXMSA1UBIKB6IzgW4koz5qL75/zBBx/4sjKJgo=; b=e8A+Mes9Xq8q7SGB7t7Foc51AFRUlqi0DelDj2FG9LMcDS/cKiuGP54WThqGDAusOYMMTaHoZ25QKuETSQJEWtw0kUrqiPtvfynYafyqMxxc4EkOhYeVl0kKw/TLKbnp3fyxDjoUQ5rkF1fO9hpQGpGys1vihSKCRc2/6ZskKM70QYT2iGWi2Ds5gIVnCA1CxTCs9tEOqmyAOZnZvZoOIgR06P/YMo6gTNPYCZWgOiwgLzIqu0+gVqhzQpAMK+Q56wI+IZD6tKXgMpauF7QOBunbNhvnosI3ufKv6XiGCLKEXSvSzs+NSpdFUJADwMsdf7MAR6HP3GuooyAhw3coQw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=boyfHlLbSUkNLlJdww5HbcVJ0p+35U9TteTTw6+Oym/clcQI4Rb3sCBTE1IJnTEPtTzqhxX64DHe63N6KJ33GELarpJr/VMoby74uT2uTEmVD8B5ItwNQeIPdz61ktMj5TEmQfP5vSDvq06caT6bNgrcKGFHE3+LKo2sk+rUPOJghamISDaj9Rc92D8Zr0GafUeMT067+RzZ5yrBa2lyaXorxQ8KkYGRAGtYIjdVACWZeBl3zFvA3//EW8lMDbQj0Qi6ktleMQwUEAQ8Gp6DtkM9qv6+iv325THx/eFpBXmeYq/y08IWTQRxP5erGoPdafZ+OvcA9IX5b8NeKY7W5Q==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Wei Chen <wei.chen@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 13 Oct 2022 09:32:59 +0000
  • Ironport-data: A9a23:+FVOOKxvZ/yR67CKq3F6t+e7xyrEfRIJ4+MujC+fZmUNrF6WrkUAm DBNCm+BaKmDM2D2ctB1O9zkoU0P7JSBztE3TgY4+SAxQypGp/SeCIXCJC8cHc8wwu7rFxs7s ppEOrEsCOhuExcwcz/0auCJQUFUjP3OHPykYAL9EngZbRd+Tys8gg5Ulec8g4p56fC0GArIs t7pyyHlEAbNNwVcbyRFtspvlDs15K6o4WtB5QRnDRx2lAS2e0c9Xcp3yZ6ZdxMUcqEMdsamS uDKyq2O/2+x13/B3fv8z94X2mVTKlLjFVDmZkh+AsBOsTAbzsAG6Y4pNeJ0VKtio27hc+ada jl6ncfYpQ8BZsUgkQmGOvVSO3kW0aZuoNcrLZUj2CA6IoKvn3bEmp1T4E8K0YIw+ftOUFESz OUkbx9WXzaZ2rLrn5uKc7w57igjBJGD0II3nFhFlGicIdN4BJfJTuPN+MNS2yo2ioZWB/HCa sEFaD1pKhPdfxlIPVRRA5U79AuqriCnL3sE9xTI+uxuvDO7IA9ZidABNPL8fNCQSNoTtUGfv m/cpEzyAw0ANczZwj2Amp6prr+Vx32k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F/NLggFkPsulqSRkoeMNIbDIGmEVE0kldemrrEWHtDbMs zDSq5rPw==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHY3t89iKUDKPVqKkqXHrrxwpoahK4MD6gA
  • Thread-topic: [PATCH] xen/arm: p2m: Populate pages for GICv2 mapping in arch_domain_create()

On 13/10/2022 09:38, Henry Wang wrote:
> Hardware using GICv2 needs to create a P2M mapping of 8KB GICv2 area
> when the domain is created. Considering the worst case of page tables
> and keep a buffer, populate 16 pages as the default value to the P2M
> pages pool in arch_domain_create() at the domain creation stage to
> satisfy the GICv2 requirement.
>
> Fixes: cbea5a1149ca ("xen/arm: Allocate and free P2M pages from the P2M pool")
> Suggested-by: Julien Grall <jgrall@xxxxxxxxxx>
> Signed-off-by: Henry Wang <Henry.Wang@xxxxxxx>
> ---
> This should also be backported to 4.13, 4.14, 4.15 and 4.16.
> ---
>  xen/arch/arm/domain.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
> index 2c84e6dbbb..e40e2bcba1 100644
> --- a/xen/arch/arm/domain.c
> +++ b/xen/arch/arm/domain.c
> @@ -740,6 +740,20 @@ int arch_domain_create(struct domain *d,
>          BUG();
>      }
>  
> +    spin_lock(&d->arch.paging.lock);
> +    /*
> +     * Hardware using GICv2 needs to create a P2M mapping of 8KB GICv2 area
> +     * when the domain is created. Considering the worst case for page
> +     * tables and keep a buffer, populate 16 pages to the P2M pages pool 
> here.
> +     */
> +    if ( (rc = p2m_set_allocation(d, 16, NULL)) != 0 )
> +    {
> +        p2m_set_allocation(d, 0, NULL);
> +        spin_unlock(&d->arch.paging.lock);
> +        goto fail;
> +    }
> +    spin_unlock(&d->arch.paging.lock);

Generally, this would be better written as

spin_lock();
if ( rc = p2m_set_allocation(16) )
    p2m_set_allocation(0)
spin_unlock();

if ( rc )
    goto fail;

to reduce the number of spin_unlock() calls and make the error paths
more clear.  However...

> +
>      if ( (rc = domain_vgic_register(d, &count)) != 0 )
>          goto fail;
>  

... you've got a problem on this error path, so the set allocation to 0
needs to be in the fail: path with suitable locking.

There are perhaps better ways of doing it in 4.15(?) and later, but not
in earlier versions.  As this is a fix to a bug in a security patch,
simplicity is generally the better approach.

~Andrew

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.