[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: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Henry Wang <Henry.Wang@xxxxxxx>
  • Date: Thu, 13 Oct 2022 09:40:36 +0000
  • Accept-language: zh-CN, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=oC0meC2W1Kz8dB5+yrDcSqlJtevWH88cFRtHoxbjs1s=; b=fOTR5VgRa+at2noXeq4Fsx19eO/lBA/jjjYJaduf2X6OosbBD/nZSlRxg29XxqKPDTkkU4xNVZ30PPavhrOvhnlFhmsVQ+hOddn8GGJkoWhigc9+YgDhkc5KySfrPZt5Ry4Rklx1DqQnzTB5feDXdQ9IdIlUgxlvEGYJ9i+Xuj0sm0PJwB1kIny5aYsrLwdR6PKc/ON+XC7dxYU2cu/f/izR4jZOCEAU4VKuu78SDv11DZHc557FNBkYOgJulM4h4BDalqndWJyFvZ8FIFiEL4zxJp/hs+9nIOgbNS82i+cHklyZugUJMIpVFTSY97qe/q22Et0ViViOCg9/w4FPAw==
  • 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=oC0meC2W1Kz8dB5+yrDcSqlJtevWH88cFRtHoxbjs1s=; b=LiPY6TMKmH3ewUL1CMVbS3NAtYqdGPtedrdR7l9YCdkD4uRYjZbNKKTgvz/LrfRaDz8wtvCvES9WMOeWIBKt74wSb3ctfDQqJiQ3ehspZBp+rh1zO8PUIwlPKUZRcKGx66SlYC7pgMJkCJ5WeRXkjTuUEK76UKSCTooyL5A75oMrudaUeZpQ8/d9A2bw63X7sLxYwwTYbYzFJ9xQulNo2yfki/lA1oTpZRHWz7X+7sCLf9pd3LS/ZO1G/zdDD09gulP+RX2wLAL4p+L508oYE5+j+lspxtldyqe+NfAmc5S36Uq9bSPQJI0VaDABTUSEzsk0bhuITJGJEXi0I2q69A==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=ntOsT/G/hcZE5mywaIN84jOR4ncBZnv4mo8ByfV5U0E6K5ViDC2e+0oedFClz6uFL0LQnC/Zbt5SrVj25frVCT/Qu8oB7DMZ7wOoir0ED9Kp0aKBLB7A5TrToKLy3MoJJHviszEwtaQ9fr2v591ndLFG595/x2Z3BuwuYND9nBUqhiXr/uTpButPgmCyQDkRGWHkByfBEa1DaMCBw6KbZrZD6szC4AYyUU2ec7Y9sk2E73IQxbPLD0i63OE2iU2ci1bAjKBWwVobER2rV4sbC+BQjCX7JQE2gND+b+k/f/m762U7JtA1zvkOoepC08OKDuL6F2p6+EeXbOtS8ZYGLw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QVEIwOdxEoKIMz5KWhZHlL2jL6t3dGX0bWHrQjCuo9vwLwhSdHGiYW6NlbMdVc+5ma0e16Vsz24wND87gZ0rlKaSMgNJIz6JvCnix452qk8vSbyBgjQN1hT34n3T1Ne0RDMLbEYYQlMO2r0TSrCbEfeflh208lW+2/aFKGhnASwjvpVgYJzDF4/7qJsvBK9JfvihWSS+LVRIkozxSQB4FLZOQwexwtIc3d3MdIgkEoXaERKG5hnzPrghgqCCVmx/EoswThk41vxvSf6XhTcrX0oywyYttFQl3HVxuQAE8D5+Si3QlfWiOf1j20OR7Brn5/4fj2MxY7RpQG0SAsiXLg==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.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:40:54 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHY3t81xdeRddBbSEGLoF20gErPe64MD6gAgAAAmHA=
  • Thread-topic: [PATCH] xen/arm: p2m: Populate pages for GICv2 mapping in arch_domain_create()

Hi Andrew,

> -----Original Message-----
> From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
> Subject: Re: [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...

I think in Arm's arch_domain_create(), all the error handling are the
same style using:

if ( (rc = <function>) !=0 )
    goto fail;

and we need to keep them the same? But I think I will drop the
p2m_set_allocation(d, 0, NULL); as the arch_domain_destroy(d) in

fail:
    d->is_dying = DOMDYING_dead;
    arch_domain_destroy(d);

will clean-up the pool.

Kind regards,
Henry

> 
> > +
> >      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®.