xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Sergej Proskurin <proskurin@sec.in.tum.de>
To: Julien Grall <julien.grall@arm.com>, xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>
Subject: Re: [PATCH v3 10/38] arm/p2m: Move hostp2m init/teardown to individual functions
Date: Mon, 5 Sep 2016 12:23:09 +0200	[thread overview]
Message-ID: <22f029f4-05d0-a6dc-b5d2-a19dcaa649f9@sec.in.tum.de> (raw)
In-Reply-To: <79831fe1-622a-70e9-bb2b-517a5f7855b5@arm.com>

Hi Julien,


On 09/02/2016 12:51 PM, Julien Grall wrote:
>
>
> On 02/09/16 10:09, Sergej Proskurin wrote:
>> Hi Julien,
>>
>> On 09/01/2016 07:36 PM, Julien Grall wrote:
>>> Hello Sergej,
>>>
>>> On 16/08/16 23:16, Sergej Proskurin wrote:
>>>> ---
>>>>  xen/arch/arm/p2m.c        | 71
>>>> +++++++++++++++++++++++++++++++++++++++++------
>>>>  xen/include/asm-arm/p2m.h | 11 ++++++++
>>>>  2 files changed, 73 insertions(+), 9 deletions(-)
>>>>
>>>> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
>>>> index e859fca..9ef19d4 100644
>>>> --- a/xen/arch/arm/p2m.c
>>>> +++ b/xen/arch/arm/p2m.c
>>>> @@ -1245,27 +1245,53 @@ static void p2m_free_vmid(struct domain *d)
>>>>      spin_unlock(&vmid_alloc_lock);
>>>>  }
>>>>
>>>> -void p2m_teardown(struct domain *d)
>>>> +/* Reset this p2m table to be empty. */
>>>> +void p2m_flush_table(struct p2m_domain *p2m)
>>>>  {
>>>> -    struct p2m_domain *p2m = p2m_get_hostp2m(d);
>>>> -    struct page_info *pg;
>>>> +    struct page_info *page, *pg;
>>>> +    unsigned int i;
>>>> +
>>>> +    if ( p2m->root )
>>>> +    {
>>>> +        page = p2m->root;
>>>> +
>>>> +        /* Clear all concatenated first level pages. */
>>>
>>> s/first/root/
>>>
>>
>> Ok.
>>
>>>> +        for ( i = 0; i < P2M_ROOT_PAGES; i++ )
>>>> +            clear_and_clean_page(page + i);
>>>
>>> Clearing live page table like that is not safe. Each entry (64-bit)
>>> should be written atomically to avoid breaking coherency (e.g if the
>>> MMU
>>> is walking the page table at the same time). However you don't know the
>>> implementation of clear_and_clean_page.
>>
>> The function p2m_flush_table gets called by the altp2m subsystem
>> indrectly through the function p2m_teardown_one when the associated view
>> gets destroyed. In this case we should not worry about crashing the
>> domain, as the altp2m views are not active anyway.
>>
>> The function altp2m_reset calls the function p2m_flush_table directly
>> (with active altp2m views), however, locks the p2m before flushing the
>> table. I did not find any locks on page-granularity, so please provide
>> me with further information about the solution you had in mind.
>
> I never mentioned any locking problem. As said in my previous mail,
> the altp2m may still be in use by another vCPU. So the MMU (i.e the
> hardware) may want do a table walk whilst you modify the entry.
>
> The MMU is reading the entry (64-bit) at once so it also expects the
> entry to be modified atomically. However, you don't know the
> implementation of clean_and_clean_page. The function might write
> 32-bit at the time, which means that the MMU will see bogus entry. At
> best it will lead to a crash, at worst open a security issue.
>

I see your point. Not sure how to fix this, though. I believe that the
described issue would remain if we would use free_domheap_pages.
Instead, maybe we should manually set the value in the translation tables?

Or, what if we flush the TLBs immediately before unmapping the root
pages? This would cause the system to load the mappings from memory and
delay a MMU table walk so that it would potentially resolve the
atomicity issue.

Do you have another suggestion?

>>>
>>> Also, this adds a small overhead when tearing down a p2m because the
>>> clear is not necessary.
>>>
>>
>> The p2m views are cleared very rarely so the overhead is really minimal
>> as it affects clearing the root tables.
>
> You seem to forget the p2m teardown is also called during domain
> destruction.
>
>> Besides the function
>> altp2m_reset calls the function p2m_flush_table and assumes that the
>> root tables are cleared as well. If the root tables would not be cleared
>> at this point, stalled entries in the altp2m views that got wiped out in
>> the hostp2m would make the system unstable.
>
> As I already mentioned in the previous version, this code was not
> present before and based of the description of this commit the patch
> is supposed to only move code around. This is not the case here.
>

I will move the part with the clear_and_clean_page invocation into a
separate patch.

>
>>>>
>>>>      radix_tree_destroy(&p2m->mem_access_settings, NULL);
>>>>  }
>>>>
>>>> -int p2m_init(struct domain *d)
>>>> +int p2m_init_one(struct domain *d, struct p2m_domain *p2m)
>>>>  {
>>>> -    struct p2m_domain *p2m = p2m_get_hostp2m(d);
>>>>      int rc = 0;
>>>>
>>>>      rwlock_init(&p2m->lock);
>>>> @@ -1278,11 +1304,14 @@ int p2m_init(struct domain *d)
>>>>          return rc;
>>>>
>>>>      p2m->max_mapped_gfn = _gfn(0);
>>>> -    p2m->lowest_mapped_gfn = _gfn(ULONG_MAX);
>>>> +    p2m->lowest_mapped_gfn = INVALID_GFN;
>>>
>>> Why this change?
>>>
>>
>> Since we compare the gfn's with INVALID_GFN throughout the code it makes
>> sense to use the macro instead of a hardcoded value.
>
> Please don't do unnecessary change. This patch is complex enough to
> review.

Ok.

Cheers,
~Sergej


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2016-09-05 10:23 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-16 22:16 [PATCH v3 00/38] arm/altp2m: Introducing altp2m to ARM Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 01/38] arm/p2m: Cosmetic fixes - apply p2m_get_hostp2m Sergej Proskurin
2016-09-01 15:46   ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 02/38] arm/p2m: Expose p2m_*lock helpers Sergej Proskurin
2016-09-01 15:48   ` Julien Grall
2016-09-02 10:12     ` Sergej Proskurin
2016-09-02 10:15       ` Julien Grall
2016-09-02 10:29         ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 03/38] arm/p2m: Introduce p2m_(switch|restore)_vttbr_and_(g|s)et_flags Sergej Proskurin
2016-09-01 15:51   ` Julien Grall
2016-09-02  8:40     ` Sergej Proskurin
2016-09-02  9:57       ` Julien Grall
2016-09-02 10:15         ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 04/38] arm/p2m: Add first altp2m HVMOP stubs Sergej Proskurin
2016-09-01 16:09   ` Julien Grall
2016-09-02  9:26     ` Sergej Proskurin
2016-09-02 10:12       ` Julien Grall
2016-09-02 10:24         ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 05/38] arm/p2m: Add hvm_allow_(set|get)_param Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 06/38] arm/p2m: Add HVMOP_altp2m_get_domain_state Sergej Proskurin
2016-09-01 17:06   ` Julien Grall
2016-09-02  8:45     ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 07/38] arm/p2m: Introduce p2m_is_(hostp2m|altp2m) Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 08/38] arm/p2m: Free p2m entries only in the hostp2m Sergej Proskurin
2016-09-01 17:08   ` Julien Grall
2016-09-02  9:38     ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 09/38] arm/p2m: Add backpointer to the domain in p2m_domain Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 10/38] arm/p2m: Move hostp2m init/teardown to individual functions Sergej Proskurin
2016-09-01 17:36   ` Julien Grall
2016-09-02  9:09     ` Sergej Proskurin
2016-09-02 10:51       ` Julien Grall
2016-09-05 10:23         ` Sergej Proskurin [this message]
2016-09-09 16:44           ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 11/38] arm/p2m: Cosmetic fix - function prototype of p2m_alloc_table Sergej Proskurin
2016-09-09 16:45   ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 12/38] arm/p2m: Rename parameter in p2m_alloc_vmid Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 13/38] arm/p2m: Change func prototype and impl of p2m_(alloc|free)_vmid Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 14/38] arm/p2m: Add altp2m init/teardown routines Sergej Proskurin
2016-09-09 16:56   ` Julien Grall
2016-09-13 19:35     ` Sergej Proskurin
2016-09-14  6:28       ` Sergej Proskurin
2016-09-14 10:53         ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 15/38] arm/p2m: Add altp2m table flushing routine Sergej Proskurin
2016-09-09 17:02   ` Julien Grall
2016-09-13  9:13     ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 16/38] arm/p2m: Add HVMOP_altp2m_set_domain_state Sergej Proskurin
2016-09-09 17:14   ` Julien Grall
2016-09-13  9:22     ` Sergej Proskurin
2016-09-14 11:07   ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 17/38] arm/p2m: Add HVMOP_altp2m_create_p2m Sergej Proskurin
2016-09-12  8:38   ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 18/38] arm/p2m: Add HVMOP_altp2m_destroy_p2m Sergej Proskurin
2016-09-12  8:41   ` Julien Grall
2016-09-13 12:43     ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 19/38] arm/p2m: Add HVMOP_altp2m_switch_p2m Sergej Proskurin
2016-09-12  8:47   ` Julien Grall
2016-09-13 13:00     ` Sergej Proskurin
2016-09-14 10:57       ` Julien Grall
2016-09-14 15:28         ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 20/38] arm/p2m: Add p2m_get_active_p2m macro Sergej Proskurin
2016-09-12  8:50   ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 21/38] arm/p2m: Make p2m_restore_state ready for altp2m Sergej Proskurin
2016-09-12  8:51   ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 22/38] arm/p2m: Make get_page_from_gva " Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 23/38] arm/p2m: Cosmetic fixes -- __p2m_get_mem_access Sergej Proskurin
2016-09-12  8:53   ` Julien Grall
2016-09-13 13:27     ` Sergej Proskurin
2016-09-13 13:30       ` Julien Grall
2016-09-13 13:42         ` Sergej Proskurin
2016-09-13 13:45           ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 24/38] arm/p2m: Make p2m_mem_access_check ready for altp2m Sergej Proskurin
2016-09-12  9:02   ` Julien Grall
2016-09-13 14:00     ` Sergej Proskurin
2016-09-13 14:20       ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 25/38] arm/p2m: Cosmetic fixes - function prototypes Sergej Proskurin
2016-08-16 22:17 ` [PATCH v3 26/38] arm/p2m: Introduce helpers managing altp2m entries Sergej Proskurin
2016-09-12  9:04   ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 27/38] arm/p2m: Introduce p2m_lookup_attr Sergej Proskurin
2016-09-12  9:15   ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 28/38] arm/p2m: Modify reference count only if hostp2m active Sergej Proskurin
2016-09-12  9:17   ` Julien Grall
2016-09-13 14:16     ` Sergej Proskurin
2016-08-16 22:17 ` [PATCH v3 29/38] arm/p2m: Add HVMOP_altp2m_set_mem_access Sergej Proskurin
2016-09-12 12:08   ` Julien Grall
2016-09-14 15:20     ` Sergej Proskurin
2016-08-16 22:17 ` [PATCH v3 30/38] arm/p2m: Add altp2m_propagate_change Sergej Proskurin
2016-08-16 22:17 ` [PATCH v3 31/38] altp2m: Introduce altp2m_switch_vcpu_altp2m_by_id Sergej Proskurin
2016-08-17 10:05   ` Jan Beulich
2016-08-17 12:37     ` Sergej Proskurin
2016-08-17 12:48       ` Julien Grall
2016-08-17 12:08   ` Razvan Cojocaru
2016-08-18 10:35   ` George Dunlap
2016-08-16 22:17 ` [PATCH v3 32/38] arm/p2m: Code movement in instr/data abort handlers Sergej Proskurin
2016-09-12 13:54   ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 33/38] arm/p2m: Add altp2m paging mechanism Sergej Proskurin
2016-09-12 14:18   ` Julien Grall
2016-09-13 15:06     ` Sergej Proskurin
2016-09-13 15:08       ` Julien Grall
2016-09-13 15:53         ` Sergej Proskurin
2016-09-14  7:53       ` Sergej Proskurin
2016-09-14 11:15         ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 34/38] arm/p2m: Add HVMOP_altp2m_change_gfn Sergej Proskurin
2016-09-12 14:27   ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 35/38] arm/p2m: Adjust debug information to altp2m Sergej Proskurin
2016-09-12 14:29   ` Julien Grall
2016-09-13 15:13     ` Sergej Proskurin
2016-08-16 22:17 ` [PATCH v3 36/38] altp2m: Allow specifying external-only use-case Sergej Proskurin
2016-08-17 10:08   ` Jan Beulich
2016-08-17 14:47   ` Daniel De Graaf
2016-08-24 12:18   ` Wei Liu
2016-08-16 22:17 ` [PATCH v3 37/38] arm/p2m: Extend xen-access for altp2m on ARM Sergej Proskurin
2016-08-17 11:26   ` Razvan Cojocaru
2016-08-16 22:17 ` [PATCH v3 38/38] arm/p2m: Add test of xc_altp2m_change_gfn Sergej Proskurin
2016-08-17 12:06   ` Razvan Cojocaru
2016-08-24 12:27   ` Wei Liu
2016-09-13 15:45     ` Sergej Proskurin

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=22f029f4-05d0-a6dc-b5d2-a19dcaa649f9@sec.in.tum.de \
    --to=proskurin@sec.in.tum.de \
    --cc=julien.grall@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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).