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 11/18] arm/altp2m: Make flush_tlb_domain ready for altp2m.
Date: Tue, 5 Jul 2016 16:48:24 +0200	[thread overview]
Message-ID: <52cc0542-6e8c-d4e1-7372-3fd001ba2b9e@sec.in.tum.de> (raw)
In-Reply-To: <823fcd21-52bc-53d2-c6dc-64b89b695811@arm.com>

Hi Julien,


On 07/04/2016 10:32 PM, Julien Grall wrote:
> Hello Sergej,
>
> On 04/07/2016 12:45, Sergej Proskurin wrote:
>> This commit makes sure that the TLB of a domain considers flushing all
>> of the associated altp2m views. Therefore, in case a different domain
>> (not the currently active domain) shall flush its TLBs, the current
>> implementation loops over all VTTBRs of the different altp2m mappings
>> per vCPU and flushes the TLBs. This way, a change of one of the altp2m
>> mapping is considered.  At this point, it must be considered that the
>> domain --whose TLBs are to be flushed-- is not locked.
>>
>> Signed-off-by: Sergej Proskurin <proskurin@sec.in.tum.de>
>> ---
>> Cc: Stefano Stabellini <sstabellini@kernel.org>
>> Cc: Julien Grall <julien.grall@arm.com>
>> ---
>>  xen/arch/arm/p2m.c | 71
>> ++++++++++++++++++++++++++++++++++++++++++++++++------
>>  1 file changed, 63 insertions(+), 8 deletions(-)
>>
>> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
>> index 7e721f9..019f10e 100644
>> --- a/xen/arch/arm/p2m.c
>> +++ b/xen/arch/arm/p2m.c
>> @@ -15,6 +15,8 @@
>>  #include <asm/hardirq.h>
>>  #include <asm/page.h>
>>
>> +#include <asm/altp2m.h>
>> +
>>  #ifdef CONFIG_ARM_64
>>  static unsigned int __read_mostly p2m_root_order;
>>  static unsigned int __read_mostly p2m_root_level;
>> @@ -79,12 +81,41 @@ void dump_p2m_lookup(struct domain *d, paddr_t addr)
>>                   P2M_ROOT_LEVEL, P2M_ROOT_PAGES);
>>  }
>>
>> +static uint64_t p2m_get_altp2m_vttbr(struct vcpu *v)
>> +{
>> +    struct domain *d = v->domain;
>> +    uint16_t index = vcpu_altp2m(v).p2midx;
>> +
>> +    if ( index == INVALID_ALTP2M )
>> +        return INVALID_MFN;
>> +
>> +    BUG_ON(index >= MAX_ALTP2M);
>> +
>> +    return d->arch.altp2m_vttbr[index];
>> +}
>> +
>> +static void p2m_load_altp2m_VTTBR(struct vcpu *v)
>
> Please try to share code when it is possible. For instance, a big part
> of this helper is similar to p2m_load_VTTBR. Assuming you get the p2m
> rather than the VTTBR directly.
>

I will combine these two functions, thank you.

>> +{
>> +    struct domain *d = v->domain;
>> +    uint64_t vttbr = p2m_get_altp2m_vttbr(v);
>> +
>> +    if ( is_idle_domain(d) )
>> +        return;
>> +
>> +    BUG_ON(vttbr == INVALID_MFN);
>> +    WRITE_SYSREG64(vttbr, VTTBR_EL2);
>> +
>> +    isb(); /* Ensure update is visible */
>> +}
>> +
>>  static void p2m_load_VTTBR(struct domain *d)
>>  {
>>      if ( is_idle_domain(d) )
>>          return;
>> +
>>      BUG_ON(!d->arch.vttbr);
>>      WRITE_SYSREG64(d->arch.vttbr, VTTBR_EL2);
>> +
>
> Spurious changes.
>

I will revert these, thank you.

>>      isb(); /* Ensure update is visible */
>>  }
>>
>> @@ -101,7 +132,11 @@ void p2m_restore_state(struct vcpu *n)
>>      WRITE_SYSREG(hcr & ~HCR_VM, HCR_EL2);
>>      isb();
>>
>> -    p2m_load_VTTBR(n->domain);
>> +    if ( altp2m_active(n->domain) )
>
> This would benefit of an unlikely (maybe within altp2m_active).
>

Fair enough. I will insert an unlikely macro into altp2m_active.

>> +        p2m_load_altp2m_VTTBR(n);
>> +    else
>> +        p2m_load_VTTBR(n->domain);
>> +
>>      isb();
>>
>>      if ( is_32bit_domain(n->domain) )
>> @@ -119,22 +154,42 @@ void p2m_restore_state(struct vcpu *n)
>>  void flush_tlb_domain(struct domain *d)
>>  {
>>      unsigned long flags = 0;
>> +    struct vcpu *v = NULL;
>>
>> -    /* Update the VTTBR if necessary with the domain d. In this case,
>> -     * it's only necessary to flush TLBs on every CPUs with the
>> current VMID
>> -     * (our domain).
>> +    /*
>> +     * Update the VTTBR if necessary with the domain d. In this
>> case, it is only
>> +     * necessary to flush TLBs on every CPUs with the current VMID (our
>> +     * domain).
>>       */
>>      if ( d != current->domain )
>>      {
>>          local_irq_save(flags);
>> -        p2m_load_VTTBR(d);
>> -    }
>>
>> -    flush_tlb();
>> +        /* If altp2m is active, update VTTBR and flush TLBs of every
>> VCPU */
>> +        if ( altp2m_active(d) )
>> +        {
>> +            for_each_vcpu( d, v )
>> +            {
>> +                p2m_load_altp2m_VTTBR(v);
>> +                flush_tlb();
>> +            }
>> +        }
>> +        else
>> +        {
>> +            p2m_load_VTTBR(d);
>> +            flush_tlb();
>> +        }
>
> Why do you need to do a such things? If the VMID is the same, a single
> call to flush_tlb() will nuke all the entries for the given TLBs.
>
> If the VMID is not shared, then I am not even sure why you would need
> to flush the TLBs for all the altp2ms.
>

If the VMID is shared between multiple views and we would change one
entry in one specific view, we might reuse an entry that is not part of
the currently active altp2m view of the domain. And even if we assign
unique VMIDs to the individual altp2m views (as discussed in patch #04),
as far as I understand, we will still need to flush the mappings of all
altp2ms at this point because (AFAIK) changes in individual altp2m views
will still need to be propagated to the TLBs. Please correct me, if I am
wrong at this point.

> I have looked to Xen with this series applied and noticed that when
> you remove a page from the hostp2m, the mapping in the altp2m is not
> removed. So the guest may use a page that would have been freed
> previously. Did I miss something?
>

When altp2m is active, the hostp2m is not used. All changes are applied
directly to the individual altp2m views. As far as I know, the only
situations, where a mapping is removed from a specific p2m view is in
the functions unmap_regions_rw_cache, unmap_mmio_regions, and
guest_physmap_remove_page. Each one of these functions provide, however
the hostp2m to the function apply_p2m_changes, where the mapping is
eventually removed. So, we definitely remove mappings from the hostp2m.
However, these would not be removed from the associated altp2m views.

Can you state a scenario, when and why pages might need to be removed at
run time from the hostp2m? In that case, maybe it would make sense to
extend the three functions (unmap_regions_rw_cache, unmap_mmio_regions,
and guest_physmap_remove_page) to additionally remove the mappings from
all available altp2m views?

Cheers,
~Sergej


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

  reply	other threads:[~2016-07-05 14:48 UTC|newest]

Thread overview: 126+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-04 11:45 [PATCH 00/18] arm/altp2m: Introducing altp2m to ARM Sergej Proskurin
2016-07-04 11:45 ` [PATCH 01/18] arm/altp2m: Add cmd-line support for altp2m on ARM Sergej Proskurin
2016-07-04 12:15   ` Andrew Cooper
2016-07-04 13:02     ` Sergej Proskurin
2016-07-04 13:25   ` Julien Grall
2016-07-04 13:43     ` Sergej Proskurin
2016-07-04 17:42   ` Julien Grall
2016-07-04 17:56     ` Tamas K Lengyel
2016-07-04 21:08       ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 02/18] arm/altp2m: Add first altp2m HVMOP stubs Sergej Proskurin
2016-07-04 13:36   ` Julien Grall
2016-07-04 13:51     ` Sergej Proskurin
2016-07-05 10:19   ` Julien Grall
2016-07-06  9:14     ` Sergej Proskurin
2016-07-06 13:43       ` Julien Grall
2016-07-06 15:23         ` Tamas K Lengyel
2016-07-06 15:54           ` Julien Grall
2016-07-06 16:05             ` Tamas K Lengyel
2016-07-06 16:29               ` Julien Grall
2016-07-06 16:35                 ` Tamas K Lengyel
2016-07-06 18:35                   ` Julien Grall
2016-07-07  9:14                     ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 03/18] arm/altp2m: Add HVMOP_altp2m_get_domain_state Sergej Proskurin
2016-07-04 11:45 ` [PATCH 04/18] arm/altp2m: Add altp2m init/teardown routines Sergej Proskurin
2016-07-04 15:17   ` Julien Grall
2016-07-04 16:40     ` Sergej Proskurin
2016-07-04 16:43       ` Andrew Cooper
2016-07-04 16:56         ` Sergej Proskurin
2016-07-04 17:44           ` Julien Grall
2016-07-04 21:19             ` Sergej Proskurin
2016-07-04 21:35               ` Julien Grall
2016-07-04 21:46               ` Sergej Proskurin
2016-07-04 18:18         ` Julien Grall
2016-07-04 21:37           ` Sergej Proskurin
2016-07-04 18:30       ` Julien Grall
2016-07-04 21:56         ` Sergej Proskurin
2016-07-04 16:15   ` Julien Grall
2016-07-04 16:51     ` Sergej Proskurin
2016-07-04 18:34       ` Julien Grall
2016-07-05  7:45         ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 05/18] arm/altp2m: Add HVMOP_altp2m_set_domain_state Sergej Proskurin
2016-07-04 15:39   ` Julien Grall
2016-07-05  8:45     ` Sergej Proskurin
2016-07-05 10:11       ` Julien Grall
2016-07-05 12:05         ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 06/18] arm/altp2m: Add a(p2m) table flushing routines Sergej Proskurin
2016-07-04 12:12   ` Sergej Proskurin
2016-07-04 15:42     ` Julien Grall
2016-07-05  8:52       ` Sergej Proskurin
2016-07-04 15:55   ` Julien Grall
2016-07-05  9:51     ` Sergej Proskurin
2016-07-04 16:20   ` Julien Grall
2016-07-05  9:57     ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 07/18] arm/altp2m: Add HVMOP_altp2m_create_p2m Sergej Proskurin
2016-07-04 11:45 ` [PATCH 08/18] arm/altp2m: Add HVMOP_altp2m_destroy_p2m Sergej Proskurin
2016-07-04 16:32   ` Julien Grall
2016-07-05 11:37     ` Sergej Proskurin
2016-07-05 11:48       ` Julien Grall
2016-07-05 12:18         ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 09/18] arm/altp2m: Add HVMOP_altp2m_switch_p2m Sergej Proskurin
2016-07-04 11:45 ` [PATCH 10/18] arm/altp2m: Renamed and extended p2m_alloc_table Sergej Proskurin
2016-07-04 18:43   ` Julien Grall
2016-07-05 13:56     ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 11/18] arm/altp2m: Make flush_tlb_domain ready for altp2m Sergej Proskurin
2016-07-04 12:30   ` Sergej Proskurin
2016-07-04 20:32   ` Julien Grall
2016-07-05 14:48     ` Sergej Proskurin [this message]
2016-07-05 15:37       ` Julien Grall
2016-07-05 20:21         ` Sergej Proskurin
2016-07-06 14:28           ` Julien Grall
2016-07-06 14:39             ` Sergej Proskurin
2016-07-07 17:24           ` Julien Grall
2016-07-04 11:45 ` [PATCH 12/18] arm/altp2m: Cosmetic fixes - function prototypes Sergej Proskurin
2016-07-15 13:45   ` Julien Grall
2016-07-16 15:18     ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 13/18] arm/altp2m: Make get_page_from_gva ready for altp2m Sergej Proskurin
2016-07-04 20:34   ` Julien Grall
2016-07-05 20:31     ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 14/18] arm/altp2m: Add HVMOP_altp2m_set_mem_access Sergej Proskurin
2016-07-05 12:49   ` Julien Grall
2016-07-05 21:55     ` Sergej Proskurin
2016-07-06 14:32       ` Julien Grall
2016-07-06 16:12         ` Tamas K Lengyel
2016-07-06 16:59           ` Julien Grall
2016-07-06 17:03           ` Sergej Proskurin
2016-07-06 17:08   ` Julien Grall
2016-07-07  9:16     ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 15/18] arm/altp2m: Add altp2m paging mechanism Sergej Proskurin
2016-07-04 20:53   ` Julien Grall
2016-07-06  8:33     ` Sergej Proskurin
2016-07-06 14:26       ` Julien Grall
2016-07-04 11:45 ` [PATCH 16/18] arm/altp2m: Extended libxl to activate altp2m on ARM Sergej Proskurin
2016-07-07 16:27   ` Wei Liu
2016-07-24 16:06     ` Sergej Proskurin
2016-07-25  8:32       ` Wei Liu
2016-07-25  9:04         ` Sergej Proskurin
2016-07-25  9:49           ` Julien Grall
2016-07-25 10:08             ` Wei Liu
2016-07-25 11:26               ` Sergej Proskurin
2016-07-25 11:37                 ` Wei Liu
2016-07-04 11:45 ` [PATCH 17/18] arm/altp2m: Adjust debug information to altp2m Sergej Proskurin
2016-07-04 20:58   ` Julien Grall
2016-07-06  8:41     ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 18/18] arm/altp2m: Extend xen-access for altp2m on ARM Sergej Proskurin
2016-07-04 13:38   ` Razvan Cojocaru
2016-07-06  8:44     ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 01/18] arm/altp2m: Add cmd-line support " Sergej Proskurin
2016-07-04 11:45 ` [PATCH 02/18] arm/altp2m: Add first altp2m HVMOP stubs Sergej Proskurin
2016-07-04 11:45 ` [PATCH 03/18] arm/altp2m: Add HVMOP_altp2m_get_domain_state Sergej Proskurin
2016-07-04 11:45 ` [PATCH 04/18] arm/altp2m: Add altp2m init/teardown routines Sergej Proskurin
2016-07-04 11:45 ` [PATCH 05/18] arm/altp2m: Add HVMOP_altp2m_set_domain_state Sergej Proskurin
2016-07-04 11:45 ` [PATCH 06/18] arm/altp2m: Add a(p2m) table flushing routines Sergej Proskurin
2016-07-04 11:45 ` [PATCH 07/18] arm/altp2m: Add HVMOP_altp2m_create_p2m Sergej Proskurin
2016-07-04 11:45 ` [PATCH 08/18] arm/altp2m: Add HVMOP_altp2m_destroy_p2m Sergej Proskurin
2016-07-04 11:45 ` [PATCH 09/18] arm/altp2m: Add HVMOP_altp2m_switch_p2m Sergej Proskurin
2016-07-04 11:45 ` [PATCH 10/18] arm/altp2m: Renamed and extended p2m_alloc_table Sergej Proskurin
2016-07-04 11:45 ` [PATCH 11/18] arm/altp2m: Make flush_tlb_domain ready for altp2m Sergej Proskurin
2016-07-04 11:45 ` [PATCH 12/18] arm/altp2m: Cosmetic fixes - function prototypes Sergej Proskurin
2016-07-04 11:46 ` [PATCH 13/18] arm/altp2m: Make get_page_from_gva ready for altp2m Sergej Proskurin
2016-07-04 11:46 ` [PATCH 14/18] arm/altp2m: Add HVMOP_altp2m_set_mem_access Sergej Proskurin
2016-07-04 11:46 ` [PATCH 15/18] arm/altp2m: Add altp2m paging mechanism Sergej Proskurin
2016-07-04 11:46 ` [PATCH 16/18] arm/altp2m: Extended libxl to activate altp2m on ARM Sergej Proskurin
2016-07-04 11:46 ` [PATCH 17/18] arm/altp2m: Adjust debug information to altp2m Sergej Proskurin
2016-07-04 11:46 ` [PATCH 18/18] arm/altp2m: Extend xen-access for altp2m on ARM Sergej Proskurin
2016-07-04 12:52 ` [PATCH 00/18] arm/altp2m: Introducing altp2m to ARM Andrew Cooper
2016-07-04 13:05   ` 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=52cc0542-6e8c-d4e1-7372-3fd001ba2b9e@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).