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

Re: [PATCH v3] 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: Mon, 17 Oct 2022 15:21:21 +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=0IcUiJORuMDR/agsdZ1gz2t5aO2YlUAO+ABXp8idr2g=; b=LFc04CgiWX6KhauzfRDBhByPfxYyoOxrkImxZTRd3OPXsZiTrMQTuUe8piIPL6Y7J7AsxDGOreH1XyqCt1Yn3Kedzi2ZUhGq/P8Pu4OMTIJsLSJ0LdCFqtAT+kUWLlJ7wVtQ2w94VUR443sfMtCCFHgKlvufMknEX/VFMmnI1FJrmTsg2Nfy8c4W2dcFhgn2uUEQitWeIRzyfkO5FB67nE39jbHha4cjzNkUqXuVFBbMivpUxkivaIuupedCqddlQzKbjEqNNhXTXjTCffJQTdTFy8lOINa8/QzRbIoiYewSFC6ugHzxaYdIi6XInhqY6HdhAe6ADoEye1wEiBUEQg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CbLKSRKFY1FEJvA4IM1rPrNDZ44MRWUe0ibr0Tyn9IkZXZ8o1jxW0VNxZzYBeSaB1+cb5R2uPwvrPRdJX+RVqeooiMcqikoUB7OEM5JQVJzWyLb18A6Exn+XaiZDiCnUkuiuutxdCog4Mtj9p37KfRHM3C5TIzcSGSgN+CsgSHqXaDX8OZ8hyvyG3pyS7fsZtyRo7k0rsY2k+s+QoM5Krt1SFNe0Ex6ItZlA2tIDCegP4dCs2wWu1rTiei/4yDC2KEI1A4KuvWZAglEVWhF/2nQiFdaI34QzjmKQPnHPMIJg8vHnrPU4O2KOQsVF9Q8KQ3GehGYwyKr+LlRpLNq3eQ==
  • 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: Mon, 17 Oct 2022 15:22:01 +0000
  • Ironport-data: A9a23:GDaHWaCYlbsbBRVW/6Tiw5YqxClBgxIJ4kV8jS/XYbTApDMn0jAEx 2QeXWGOa67YYjHwc4gjPIm/9R4F6J+ExoJnQQY4rX1jcSlH+JHPbTi7wuUcHAvJd5GeExg3h yk6QoOdRCzhZiaE/n9BCpC48T8mk/ngqoPUUIbsIjp2SRJvVBAvgBdin/9RqoNziJ2yDhjlV ena+qUzA3f4nW8pWo4ow/jb8kk25K2t4GpwUmEWPpingnePzxH5M7pHTU2BByOQapVZGOe8W 9HCwNmRlo8O105wYj8Nuu+TnnwiGtY+DyDX4pZlc/HKbix5jj4zys4G2M80Mi+7vdkrc+dZk 72hvbToIesg0zaldO41C3G0GAkmVUFKFSOuzdFSfqV/wmWfG0YAzcmCA2kONKkV2rgpBFhFt t4dJGFKSQ+7u7KPlefTpulE3qzPLeHNFaZG4jRF8mucCvwrB5feX6/N+NlUmi8qgdxDFurfY MxfbidzaBPHYFtEPVJ/5JAWxb/0wCWgNWAF7gvN/cLb4ECKpOB1+JHrPMDYZZqhQsJNk1zDj mnH4374ElcRM9n3JT+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k6y5Qqb3OiueT11rm9e8opwkc7/mZ8 o=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHY4fyisutH9MvwK0CzzXPj4djvUK4StD+A
  • Thread-topic: [PATCH v3] xen/arm: p2m: Populate pages for GICv2 mapping in arch_domain_create()

On 17/10/2022 08:46, Henry Wang wrote:
> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
> index f17500ddf3..8c9ddf58e1 100644
> --- a/xen/arch/arm/p2m.c
> +++ b/xen/arch/arm/p2m.c
> @@ -1736,7 +1739,20 @@ void p2m_final_teardown(struct domain *d)
>      if ( !p2m->domain )
>          return;
>  

Everything below here is "dead" code, because...


> +    /*
> +     * No need to call relinquish_p2m_mapping() here because
> +     * p2m_final_teardown() is called either after 
> domain_relinquish_resources()
> +     * where relinquish_p2m_mapping() has been called, or from failure path 
> of
> +     * domain_create()/arch_domain_create() where mappings that require
> +     * p2m_put_l3_page() should never be created. For the latter case, also 
> see
> +     * comment on top of the p2m_set_entry() for more info.
> +     */
> +
> +    BUG_ON(p2m_teardown(d, false));
>      ASSERT(page_list_empty(&p2m->pages));
> +
> +    while ( p2m_teardown_allocation(d) == -ERESTART )
> +        continue; /* No preemption support here */
>      ASSERT(page_list_empty(&d->arch.paging.p2m_freelist));
>  
>      if ( p2m->root )
> @@ -1762,6 +1778,20 @@ int p2m_init(struct domain *d)
>      INIT_PAGE_LIST_HEAD(&p2m->pages);
>      INIT_PAGE_LIST_HEAD(&d->arch.paging.p2m_freelist);
>  
> +    /*
> +     * 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.
> +     * For GICv3, the above-mentioned P2M mapping is not necessary, but since
> +     * the allocated 16 pages here would not be lost, hence populate these
> +     * pages unconditionally.
> +     */
> +    spin_lock(&d->arch.paging.lock);
> +    rc = p2m_set_allocation(d, 16, NULL);
> +    spin_unlock(&d->arch.paging.lock);
> +    if ( rc != 0 )
> +        return rc;

... this early exit is ahead of p2m_init() settings p2m->domain = d.

In particular, you introduce a bug whereby ...

> +
>      p2m->vmid = INVALID_VMID;
>  
>      rc = p2m_alloc_vmid(d);

... this error path now leaks the 16 page p2m allocation.


This change is overly complex.  You add a set_allocation(16) path in
p2m_init(), so should only be adding a single set_allocation(0) to
compensate.

The `while ( p2m_teardown_allocation(d) == -ERESTART ) continue;` is
especially silly because you're specifically wasting time ignoring the
preemption wrapper around the non-preemptible function that you actually
want to use.

Looking at between 4.13 and staging, you want to be calling
set_allocation(0) in p2m_final_teardown() ahead of of the p->domain
check.  Except idempotency which is going to be irritating here.

It will be a no-op from the normal domain destroy path (as relinquish
resource will have emptied the whole pool), while in domain_create error
path, it has a maximum of 16 pages to release.

I'll draft a patch.

~Andrew

 


Rackspace

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