xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Tim Deegan <tim@xen.org>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: xen-devel@lists.xensource.com, Ian.Campbell@citrix.com
Subject: Re: [PATCH 6/7] xen/arm: flush D-cache and I-cache when appropriate
Date: Wed, 24 Oct 2012 16:59:45 +0100	[thread overview]
Message-ID: <20121024155945.GD39126@ocelot.phlegethon.org> (raw)
In-Reply-To: <1351091027-20740-6-git-send-email-stefano.stabellini@eu.citrix.com>

At 16:03 +0100 on 24 Oct (1351094626), Stefano Stabellini wrote:
> - invalidate tlb after setting WXN;
> - flush D-cache and I-cache after relocation;
> - flush D-cache after writing to smp_up_cpu;
> - flush TLB before changing HTTBR;
> - flush I-cache after changing HTTBR;
> - flush I-cache and branch predictor after writing Xen text ptes.
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

> @@ -244,10 +245,18 @@ void __init setup_pagetables(unsigned long boot_phys_offset, paddr_t xen_paddr)
>  
>      /* Change pagetables to the copy in the relocated Xen */
>      boot_httbr = (unsigned long) xen_pgtable + phys_offset;
> +    flush_xen_dcache_va((unsigned long)&boot_httbr);
> +    for ( i = 0; i < _end - _start; i += cacheline_size )
> +        flush_xen_dcache_va(dest_va + i);
> +    flush_xen_text_tlb();
> +
>      asm volatile (
> +        "dsb;"                        /* Ensure visibility of HTTBR update */

That comment should be changed -- this dsb is to make sure all the PT
changes are completed, right?

>          STORE_CP64(0, HTTBR)          /* Change translation base */
>          "dsb;"                        /* Ensure visibility of HTTBR update */
> +        "isb;"
>          STORE_CP32(0, TLBIALLH)       /* Flush hypervisor TLB */
> +        STORE_CP32(0, ICIALLU)        /* Flush I-cache */
>          STORE_CP32(0, BPIALL)         /* Flush branch predictor */
>          "dsb;"                        /* Ensure completion of TLB+BP flush */
>          "isb;"

> diff --git a/xen/include/asm-arm/page.h b/xen/include/asm-arm/page.h
> index 9511c45..7d70d8c 100644
> --- a/xen/include/asm-arm/page.h
> +++ b/xen/include/asm-arm/page.h
> @@ -232,13 +232,26 @@ static inline lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr)
>  static inline void write_pte(lpae_t *p, lpae_t pte)
>  {
>      asm volatile (
> +        "dsb;"

I guess this is to make sure all writes that used the old mapping have
completed?  Can you add a comment?

>          /* Safely write the entry (STRD is atomic on CPUs that support LPAE) */
>          "strd %0, %H0, [%1];"
> +        "dsb;"
>          /* Push this cacheline to the PoC so the rest of the system sees it. */
>          STORE_CP32(1, DCCMVAC)
> +        "isb;"

This is for code modifications, right?  I think we can drop it, and have
all the paths that modify text mappings do explicit isb()s there -- the
vast majority of PTE writes don't need it. 

>          : : "r" (pte.bits), "r" (p) : "memory");
>  }
>  
> +static inline void flush_xen_dcache_va(unsigned long va)

Three of the four users of this function cast their arguments from
pointer types - maybe it should take a void * instead?.

> +{
> +    register unsigned long r0 asm ("r0") = va;

I don't think this is necessary - why not just pass va directly to the
inline asm?  We don't care what register it's in (and if we did I'm not
convinced this would guarantee it was r0).

> +    asm volatile (
> +        "dsb;"
> +        STORE_CP32(0, DCCMVAC)
> +        "isb;"
> +        : : "r" (r0) : "memory");

Does this need a 'memory' clobber?  Can we get away with just saying it
consumes *va as an input?  All we need to be sure of is that the
particular thing we're flushing has been written out; no need to stop
any other optimizations.

I guess it might need to be re-cast as a macro so the compiler knows how
big *va is?

Tim.

> +}
> +
>  /*
>   * Flush all hypervisor mappings from the TLB and branch predictor.
>   * This is needed after changing Xen code mappings. 
> @@ -249,6 +262,7 @@ static inline void flush_xen_text_tlb(void)
>      asm volatile (
>          "dsb;"                        /* Ensure visibility of PTE writes */
>          STORE_CP32(0, TLBIALLH)       /* Flush hypervisor TLB */
> +        STORE_CP32(0, ICIALLU)        /* Flush I-cache */
>          STORE_CP32(0, BPIALL)         /* Flush branch predictor */
>          "dsb;"                        /* Ensure completion of TLB+BP flush */
>          "isb;"
> -- 
> 1.7.2.5
> 

  reply	other threads:[~2012-10-24 15:59 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-24 15:03 [PATCH 0/7] xen/arm: run on real hardware Stefano Stabellini
2012-10-24 15:03 ` [PATCH 1/7] xen/arm: fix rank calculation in vgic_vcpu_inject_irq Stefano Stabellini
2012-10-25  9:27   ` Ian Campbell
2012-10-26 16:33     ` Stefano Stabellini
2012-10-26 16:40       ` Ian Campbell
2012-10-26 18:42         ` Stefano Stabellini
2012-10-26 20:47           ` Ian Campbell
2012-10-27 10:09             ` Tim Deegan
2012-10-27 10:44               ` Ian Campbell
2012-11-13 11:57               ` Stefano Stabellini
2012-11-13 12:00                 ` Ian Campbell
2012-11-13 12:23                   ` Stefano Stabellini
2012-10-24 15:03 ` [PATCH 2/7] xen/arm: setup the fixmap in head.S Stefano Stabellini
2012-10-24 15:27   ` Tim Deegan
2012-10-24 15:37     ` Stefano Stabellini
2012-10-25  9:33   ` Ian Campbell
2012-10-25 11:00     ` Stefano Stabellini
2012-10-24 15:03 ` [PATCH 3/7] pl011: set baud and clock_hz to the right defaults for Versatile Express Stefano Stabellini
2012-10-25  9:37   ` Ian Campbell
2012-10-25 10:57     ` Stefano Stabellini
2012-10-25 11:00       ` Ian Campbell
2012-10-24 15:03 ` [PATCH 4/7] xen/arm: set the SMP bit in the ACTLR register Stefano Stabellini
2012-10-25  9:52   ` Ian Campbell
2012-10-25 11:57     ` Stefano Stabellini
2012-10-25 12:04       ` Ian Campbell
2012-10-26  8:56         ` Tim Deegan
2012-10-26  8:59           ` Ian Campbell
2012-10-24 15:03 ` [PATCH 5/7] xen/arm: wake up secondary cpus Stefano Stabellini
2012-10-24 15:38   ` Tim Deegan
2012-10-24 15:59     ` Stefano Stabellini
2012-10-24 16:05       ` Tim Deegan
2012-10-25  9:59   ` Ian Campbell
2012-10-25 17:45     ` Stefano Stabellini
2012-10-26  7:30       ` Ian Campbell
2012-10-26 11:18         ` Stefano Stabellini
2012-10-26 12:16           ` Ian Campbell
2012-10-26 15:24             ` Stefano Stabellini
2012-10-26 15:32               ` Ian Campbell
2012-10-24 15:03 ` [PATCH 6/7] xen/arm: flush D-cache and I-cache when appropriate Stefano Stabellini
2012-10-24 15:59   ` Tim Deegan [this message]
2012-10-24 16:05     ` Ian Campbell
2012-10-24 16:17       ` Tim Deegan
2012-10-24 17:35     ` Stefano Stabellini
2012-10-26  9:01       ` Tim Deegan
2012-10-26 15:53         ` Stefano Stabellini
2012-10-26 15:55           ` Stefano Stabellini
2012-10-26 16:03             ` Stefano Stabellini
2012-10-26 16:55               ` Tim Deegan
2012-10-26 18:40                 ` Stefano Stabellini
2012-10-27 10:44                   ` Tim Deegan
2012-10-27 11:54                     ` Tim Deegan
2012-10-29  9:53                       ` Stefano Stabellini
2012-10-29  9:52                     ` Stefano Stabellini
2012-11-13 12:01                     ` Stefano Stabellini
2012-11-13 12:15                       ` Tim Deegan
2012-10-26 16:45           ` Tim Deegan
2012-10-24 15:03 ` [PATCH 7/7] xen/arm: get the number of cpus from device tree Stefano Stabellini
2012-10-25 10:02   ` Ian Campbell
2012-10-24 16:02 ` [PATCH 0/7] xen/arm: run on real hardware Tim Deegan
  -- strict thread matches above, loose matches on Subject: below --
2012-11-13 15:40 [PATCH v2 " Stefano Stabellini
2012-11-13 15:42 ` [PATCH 6/7] xen/arm: flush D-cache and I-cache when appropriate Stefano Stabellini
2012-11-15 10:02   ` Ian Campbell
2012-11-16 15:36     ` Stefano Stabellini

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=20121024155945.GD39126@ocelot.phlegethon.org \
    --to=tim@xen.org \
    --cc=Ian.Campbell@citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /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).