From: Wei Chen <wei.chen@arm.com>
To: Julien Grall <julien.grall@arm.com>, xen-devel@lists.xen.org
Cc: sstabellini@kernel.org, wei.liu2@citrix.com
Subject: Re: [for-4.7 2/2] xen/arm: p2m: Release the p2m lock before undoing the mappings
Date: Tue, 17 May 2016 14:21:42 +0800 [thread overview]
Message-ID: <adf863c7-7add-d750-726f-c5b995ae9b6a@arm.com> (raw)
In-Reply-To: <45f975ea-e916-4066-03b7-8fac4225bda7@arm.com>
Hi Julien,
I have some concern about this patch. Because we released the spinlock
before remove the mapped memory. If somebody acquires the spinlock
before we remove the mapped memory, this mapped memory region can be
accessed by guest.
The apply_p2m_changes is no longer atomic. Is it a security risk?
On 2016/5/17 13:45, Wei Chen wrote:
> Hi Julien,
>
> This code looks good to me, and I have tested that
> the deadlock is fixed by this patch.
>
> Reviewed-and-Tested-by: Wei Chen <Wei.Chen@arm.com>
>
> Original:
> (XEN) smmu: /smb/smmu@e0800000: P2M IPA size not supported (P2M=44
> SMMU=40)!
> (XEN) I/O virtualisation disabled
> (XEN) Request p2m Spinlock...
> (XEN) Request p2m Spinlock...OK
> (XEN) apply_p2m_changes failed! rollback! call apply_p2m_changes
> recursively!
> (XEN) Request p2m Spinlock...
>
> Patched:
> (XEN) smmu: /smb/smmu@e0800000: P2M IPA size not supported (P2M=44
> SMMU=40)!
> (XEN) I/O virtualisation disabled
> (XEN) Request p2m Spinlock...
> (XEN) Request p2m Spinlock...OK
> (XEN) apply_p2m_changes failed! rollback! call apply_p2m_changes
> recursively!
> (XEN) Request p2m Spinlock...
> (XEN) Request p2m Spinlock...OK
>
>
> On 2016/5/16 22:08, Julien Grall wrote:
>> Since commit 4b25423a "arch/arm: unmap partially-mapped memory regions",
>> Xen has been undoing the P2M mappings when an error occurred during
>> insertion or memory allocation.
>>
>> This is done by calling recursively apply_p2m_changes, however the
>> second call is done with the p2m lock taken which will result in a
>> deadlock for the current processor.
>>
>> Fix it by moving the recursive call after the lock has been released.
>>
>> Signed-off-by: Julien Grall <julien.grall@arm.com>
>>
>> ---
>> I think we could unlock the p2m lock before freeing the temporary
>> mapping. Although, I played safe as this is a bug fix for Xen 4.7
>> and to be backported up to Xen 4.5.
>> ---
>> xen/arch/arm/p2m.c | 16 ++++++++--------
>> 1 file changed, 8 insertions(+), 8 deletions(-)
>>
>> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
>> index 68c67b0..838d004 100644
>> --- a/xen/arch/arm/p2m.c
>> +++ b/xen/arch/arm/p2m.c
>> @@ -1184,6 +1184,14 @@ out:
>> while ( (pg = page_list_remove_head(&free_pages)) )
>> free_domheap_page(pg);
>>
>> + for ( level = P2M_ROOT_LEVEL; level < 4; level ++ )
>> + {
>> + if ( mappings[level] )
>> + unmap_domain_page(mappings[level]);
>> + }
>> +
>> + spin_unlock(&p2m->lock);
>> +
>> if ( rc < 0 && ( op == INSERT || op == ALLOCATE ) &&
>> addr != start_gpaddr )
>> {
>> @@ -1196,14 +1204,6 @@ out:
>> mattr, 0, p2m_invalid,
>> d->arch.p2m.default_access);
>> }
>>
>> - for ( level = P2M_ROOT_LEVEL; level < 4; level ++ )
>> - {
>> - if ( mappings[level] )
>> - unmap_domain_page(mappings[level]);
>> - }
>> -
>> - spin_unlock(&p2m->lock);
>> -
>> return rc;
>> }
>>
>>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-05-17 6:21 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-16 14:08 [for-4.7 0/2] xen/arm: Bug fixes in the P2M code Julien Grall
2016-05-16 14:08 ` [for-4.7 1/2] xen/arm: p2m: apply_p2m_changes: Do not undo more than necessary Julien Grall
2016-05-17 6:40 ` Wei Chen
2016-05-17 7:29 ` Julien Grall
2016-05-17 11:18 ` Stefano Stabellini
2016-05-16 14:08 ` [for-4.7 2/2] xen/arm: p2m: Release the p2m lock before undoing the mappings Julien Grall
2016-05-17 5:45 ` Wei Chen
2016-05-17 6:21 ` Wei Chen [this message]
2016-05-17 11:24 ` Stefano Stabellini
2016-05-17 11:35 ` Julien Grall
2016-05-17 12:27 ` Stefano Stabellini
2016-05-17 12:48 ` Julien Grall
2016-05-18 10:10 ` Stefano Stabellini
2016-05-18 10:31 ` Julien Grall
2016-05-18 10:45 ` Julien Grall
2016-05-18 10:39 ` [for-4.7 0/2] xen/arm: Bug fixes in the P2M code Stefano Stabellini
2016-05-18 10:46 ` Wei Liu
2016-05-18 10:58 ` Julien Grall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=adf863c7-7add-d750-726f-c5b995ae9b6a@arm.com \
--to=wei.chen@arm.com \
--cc=julien.grall@arm.com \
--cc=sstabellini@kernel.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).