Skip to contentSkip to conversation

xen/arm: fix guest builder cache cohenrency (again, again)

PATCH Superseded Ian Campbell 5 participants 19 messages Jan 29, 2014 – Jan 30, 2014

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover xen/arm: fix guest builder cache cohenrency (again, again)

Jan/Ian/Keir -- the final patch involves tools changes and a new domctl, which is why you are copied (although the domctl is marked as arm specific you might have opinions on it).

On ARM we need to take care of cache coherency for guests which we have just built because they start with their caches disabled.

Our current strategy for dealing with this, which is to make guest memory default to cacheable regardless of the in guest configuration (the HCR.DC bit), is flawed because it doesn't handle guests which enable their MMU before enabling their caches, which at least FreeBSD does. (NB: Setting HCR.DC while the guest MMU is enabled is UNPREDICTABLE, hence we must disable it when the guest turns its MMU one).

There is also a security aspect here since the current strategy means that a guest which enables its MMU before its caches can potentially see unscrubbed data in RAM (because the scrubbed bytes are still held in the cache).

As well as the new stuff this series removes the HCR.DC support and performs two purely cosmetic renames.

This has survived 20000 bootloops on arm32 and 9700 (on going) on arm64. (I've been seeing a sporadic issue on arm64 but I believe it is unrelated, although I also cannot reproduce at the moment).

As well as being more correct (and secure!) this strategy is IMHO simpler than the existing HCR.DC based thing and I'd like to push it to 4.4.

I'm aware that this is the third attempt to get this right and the second one requiring a freeze exception :-(

Ian.

#1 lore raw

PATCH 1/4 Revert "xen: arm: force guest memory accesses to cacheable when MMU is disabled"

This reverts commit 89eb02c2204a0b42a0aa169f107bc346a3fef802.

This approach has a short coming in that it breaks when a guest enables its MMU (SCTLR.M, disabling HCR.DC) without enabling caches (SCTLR.C) first/at the same time. It turns out that FreeBSD does this.

A follow up patch which fix this (yet) another way (third time is the charm!)

---
 xen/arch/arm/domain.c           |    7 --
 xen/arch/arm/traps.c            |  163 +--------------------------------------
 xen/arch/arm/vtimer.c           |    6 +-
 xen/include/asm-arm/cpregs.h    |    4 -
 xen/include/asm-arm/domain.h    |    2 -
 xen/include/asm-arm/processor.h |    2 +-
 xen/include/asm-arm/sysregs.h   |   19 +----
 7 files changed, 9 insertions(+), 194 deletions(-)
xen/arch/arm/domain.c +0 -7
index 635a9a4..124cccf 100644
@@ -19,7 +19,6 @@
 #include <xen/errno.h>
 #include <xen/bitops.h>
 #include <xen/grant_table.h>
-#include <xen/stdbool.h>
 
 #include <asm/current.h>
 #include <asm/event.h>
@@ -220,11 +219,6 @@ static void ctxt_switch_to(struct vcpu *n)
     else
         hcr |= HCR_RW;
 
-    if ( n->arch.default_cache )
-        hcr |= (HCR_TVM|HCR_DC);
-    else
-        hcr &= ~(HCR_TVM|HCR_DC);
-
     WRITE_SYSREG(hcr, HCR_EL2);
     isb();
 
@@ -475,7 +469,6 @@ int vcpu_initialise(struct vcpu *v)
         return rc;
 
     v->arch.sctlr = SCTLR_GUEST_INIT;
-    v->arch.default_cache = true;
 
     /*
      * By default exposes an SMP system with AFF0 set to the VCPU ID
xen/arch/arm/traps.c +3 -160

220 lines not on this page · raw message

xen/arch/arm/vtimer.c +3 -3
index e325f78..433ad55 100644
@@ -240,18 +240,18 @@ static int vtimer_emulate_sysreg(struct cpu_user_regs *regs, union hsr hsr)
 
     switch ( hsr.bits & HSR_SYSREG_REGS_MASK )
     {
-    case HSR_SYSREG_CNTP_CTL_EL0:
+    case CNTP_CTL_EL0:
         vtimer_cntp_ctl(regs, &r, sysreg.read);
         if ( sysreg.read )
             *x = r;
         return 1;
-    case HSR_SYSREG_CNTP_TVAL_EL0:
+    case CNTP_TVAL_EL0:
         vtimer_cntp_tval(regs, &r, sysreg.read);
         if ( sysreg.read )
             *x = r;
         return 1;
 
-    case HSR_SYSREG_CNTPCT_EL0:
+    case HSR_CPREG64(CNTPCT):
         return vtimer_cntpct(regs, x, sysreg.read);
 
     default:
xen/include/asm-arm/cpregs.h +0 -4
index 508467a..f0f1d53 100644
@@ -121,8 +121,6 @@
 #define TTBR0           p15,0,c2        /* Translation Table Base Reg. 0 */
 #define TTBR1           p15,1,c2        /* Translation Table Base Reg. 1 */
 #define HTTBR           p15,4,c2        /* Hyp. Translation Table Base Register */
-#define TTBR0_32        p15,0,c2,c0,0   /* 32-bit access to TTBR0 */
-#define TTBR1_32        p15,0,c2,c0,1   /* 32-bit access to TTBR1 */
 #define HTCR            p15,4,c2,c0,2   /* Hyp. Translation Control Register */
 #define VTCR            p15,4,c2,c1,2   /* Virtualization Translation Control Register */
 #define VTTBR           p15,6,c2        /* Virtualization Translation Table Base Register */
@@ -262,9 +260,7 @@
 #define CPACR_EL1               CPACR
 #define CSSELR_EL1              CSSELR
 #define DACR32_EL2              DACR
-#define ESR_EL1                 DFSR
 #define ESR_EL2                 HSR
-#define FAR_EL1                 HIFAR
 #define FAR_EL2                 HIFAR
 #define HCR_EL2                 HCR
 #define HPFAR_EL2               HPFAR
xen/include/asm-arm/domain.h +0 -2
index af8c64b..bc20a15 100644
@@ -257,8 +257,6 @@ struct arch_vcpu
     uint64_t event_mask;
     uint64_t lr_mask;
 
-    bool_t default_cache;
-
     struct {
         /*
          * SGIs and PPIs are per-VCPU, SPIs are domain global and in
xen/include/asm-arm/processor.h +1 -1
index 06e638f..dfe807d 100644
@@ -342,7 +342,7 @@ union hsr {
 #define HSR_SYSREG_OP0_SHIFT (20)
 #define HSR_SYSREG_OP1_MASK (0x0001c000)
 #define HSR_SYSREG_OP1_SHIFT (14)
-#define HSR_SYSREG_CRN_MASK (0x00003c00)
+#define HSR_SYSREG_CRN_MASK (0x00003800)
 #define HSR_SYSREG_CRN_SHIFT (10)
 #define HSR_SYSREG_CRM_MASK (0x0000001e)
 #define HSR_SYSREG_CRM_SHIFT (1)
xen/include/asm-arm/sysregs.h +2 -17
index 0cee0e9..48ad07e 100644
@@ -40,23 +40,8 @@
     ((__HSR_SYSREG_##crm) << HSR_SYSREG_CRM_SHIFT) | \
     ((__HSR_SYSREG_##op2) << HSR_SYSREG_OP2_SHIFT)
 
-#define HSR_SYSREG_SCTLR_EL1      HSR_SYSREG(3,0,c1, c0,0)
-#define HSR_SYSREG_TTBR0_EL1      HSR_SYSREG(3,0,c2, c0,0)
-#define HSR_SYSREG_TTBR1_EL1      HSR_SYSREG(3,0,c2, c0,1)
-#define HSR_SYSREG_TCR_EL1        HSR_SYSREG(3,0,c2, c0,2)
-#define HSR_SYSREG_AFSR0_EL1      HSR_SYSREG(3,0,c5, c1,0)
-#define HSR_SYSREG_AFSR1_EL1      HSR_SYSREG(3,0,c5, c1,1)
-#define HSR_SYSREG_ESR_EL1        HSR_SYSREG(3,0,c5, c2,0)
-#define HSR_SYSREG_FAR_EL1        HSR_SYSREG(3,0,c6, c0,0)
-#define HSR_SYSREG_MAIR_EL1       HSR_SYSREG(3,0,c10,c2,0)
-#define HSR_SYSREG_AMAIR_EL1      HSR_SYSREG(3,0,c10,c3,0)
-#define HSR_SYSREG_CONTEXTIDR_EL1 HSR_SYSREG(3,0,c13,c0,1)
-
-#define HSR_SYSREG_CNTPCT_EL0     HSR_SYSREG(3,3,c14,c0,0)
-#define HSR_SYSREG_CNTP_CTL_EL0   HSR_SYSREG(3,3,c14,c2,1)
-#define HSR_SYSREG_CNTP_TVAL_EL0  HSR_SYSREG(3,3,c14,c2,0)
-
-
+#define CNTP_CTL_EL0  HSR_SYSREG(3,3,c14,c2,1)
+#define CNTP_TVAL_EL0 HSR_SYSREG(3,3,c14,c2,0)
 #endif
 
 #endif
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH 1/4] Revert "xen: arm: force guest memory accesses to cacheable when MMU is disabled"

Quoted 5 lines · Ian Campbell

This reverts commit 89eb02c2204a0b42a0aa169f107bc346a3fef802.

This approach has a short coming in that it breaks when a guest enables its MMU (SCTLR.M, disabling HCR.DC) without enabling caches (SCTLR.C) first/at the same time. It turns out that FreeBSD does this.

By reverting this patch, you also revert some insteresting fix:
- Fixing HSR_SYSREG_CRN_MASK
- Use of HSR_SYSREG_

I think this both changes should be kept.

Otherwise, I would move this patch at the end of the series if we need to bisect the code.

Signature · 1 line
Julien Grall
#3 lore raw

Re: [PATCH 1/4] Revert "xen: arm: force guest memory accesses to cacheable when MMU is disabled"

Quoted 8 lines · Julien Grall
Quoted 5 lines · Ian Campbell

This reverts commit 89eb02c2204a0b42a0aa169f107bc346a3fef802.

This approach has a short coming in that it breaks when a guest enables its MMU (SCTLR.M, disabling HCR.DC) without enabling caches (SCTLR.C) first/at the same time. It turns out that FreeBSD does this.

Quoted 5 lines

By reverting this patch, you also revert some insteresting fix:
- Fixing HSR_SYSREG_CRN_MASK
- Use of HSR_SYSREG_

I think this both changes should be kept.

Good, point. The issues are not actual problems with the main change reverted, but we should keep them anyway since they are correct.

Quoted 2 lines

Otherwise, I would move this patch at the end of the series if we need to bisect the code.

Yes, for some reason I had thought this one needed to come first, but I think I was wrong.

Ian

#4 lore raw

PATCH 2/4 xen: arm: rename create_p2m_entries to apply_p2m_changes

In reply to Ian Campbell

This function hasn't been only about creating for quite a while.

This is purely a rename.

---
 xen/arch/arm/p2m.c |   28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
xen/arch/arm/p2m.c +14 -14
index 85ca330..ace3c54 100644
@@ -230,7 +230,7 @@ enum p2m_operation {
     RELINQUISH,
 };
 
-static int create_p2m_entries(struct domain *d,
+static int apply_p2m_changes(struct domain *d,
                      enum p2m_operation op,
                      paddr_t start_gpaddr,
                      paddr_t end_gpaddr,
@@ -438,8 +438,8 @@ int p2m_populate_ram(struct domain *d,
                      paddr_t start,
                      paddr_t end)
 {
-    return create_p2m_entries(d, ALLOCATE, start, end,
-                              0, MATTR_MEM, p2m_ram_rw);
+    return apply_p2m_changes(d, ALLOCATE, start, end,
+                             0, MATTR_MEM, p2m_ram_rw);
 }
 
 int map_mmio_regions(struct domain *d,
@@ -447,8 +447,8 @@ int map_mmio_regions(struct domain *d,
                      paddr_t end_gaddr,
                      paddr_t maddr)
 {
-    return create_p2m_entries(d, INSERT, start_gaddr, end_gaddr,
-                              maddr, MATTR_DEV, p2m_mmio_direct);
+    return apply_p2m_changes(d, INSERT, start_gaddr, end_gaddr,
+                             maddr, MATTR_DEV, p2m_mmio_direct);
 }
 
 int guest_physmap_add_entry(struct domain *d,
@@ -457,20 +457,20 @@ int guest_physmap_add_entry(struct domain *d,
                             unsigned long page_order,
                             p2m_type_t t)
 {
-    return create_p2m_entries(d, INSERT,
-                              pfn_to_paddr(gpfn),
-                              pfn_to_paddr(gpfn + (1 << page_order)),
-                              pfn_to_paddr(mfn), MATTR_MEM, t);
+    return apply_p2m_changes(d, INSERT,
+                             pfn_to_paddr(gpfn),
+                             pfn_to_paddr(gpfn + (1 << page_order)),
+                             pfn_to_paddr(mfn), MATTR_MEM, t);
 }
 
 void guest_physmap_remove_page(struct domain *d,
                                unsigned long gpfn,
                                unsigned long mfn, unsigned int page_order)
 {
-    create_p2m_entries(d, REMOVE,
-                       pfn_to_paddr(gpfn),
-                       pfn_to_paddr(gpfn + (1<<page_order)),
-                       pfn_to_paddr(mfn), MATTR_MEM, p2m_invalid);
+    apply_p2m_changes(d, REMOVE,
+                      pfn_to_paddr(gpfn),
+                      pfn_to_paddr(gpfn + (1<<page_order)),
+                      pfn_to_paddr(mfn), MATTR_MEM, p2m_invalid);
 }
 
 int p2m_alloc_table(struct domain *d)
@@ -618,7 +618,7 @@ int relinquish_p2m_mapping(struct domain *d)
 {
     struct p2m_domain *p2m = &d->arch.p2m;
 
-    return create_p2m_entries(d, RELINQUISH,
+    return apply_p2m_changes(d, RELINQUISH,
                               pfn_to_paddr(p2m->next_gfn_to_relinquish),
                               pfn_to_paddr(p2m->max_mapped_gfn),
                               pfn_to_paddr(INVALID_MFN),
Signature · 1 line
1.7.10.4
Acked-by on v1 2/4
#5 lore raw

Re: [PATCH 2/4] xen: arm: rename create_p2m_entries to apply_p2m_changes

Quoted 5 lines · Ian Campbell

This function hasn't been only about creating for quite a while.

This is purely a rename.

Quoted 78 lines
---
  xen/arch/arm/p2m.c |   28 ++++++++++++++--------------
  1 file changed, 14 insertions(+), 14 deletions(-)
xen/arch/arm/p2m.c +14 -14
index 85ca330..ace3c54 100644
@@ -230,7 +230,7 @@ enum p2m_operation {
      RELINQUISH,
  };
 
-static int create_p2m_entries(struct domain *d,
+static int apply_p2m_changes(struct domain *d,
                       enum p2m_operation op,
                       paddr_t start_gpaddr,
                       paddr_t end_gpaddr,
@@ -438,8 +438,8 @@ int p2m_populate_ram(struct domain *d,
                       paddr_t start,
                       paddr_t end)
  {
-    return create_p2m_entries(d, ALLOCATE, start, end,
-                              0, MATTR_MEM, p2m_ram_rw);
+    return apply_p2m_changes(d, ALLOCATE, start, end,
+                             0, MATTR_MEM, p2m_ram_rw);
  }
 
  int map_mmio_regions(struct domain *d,
@@ -447,8 +447,8 @@ int map_mmio_regions(struct domain *d,
                       paddr_t end_gaddr,
                       paddr_t maddr)
  {
-    return create_p2m_entries(d, INSERT, start_gaddr, end_gaddr,
-                              maddr, MATTR_DEV, p2m_mmio_direct);
+    return apply_p2m_changes(d, INSERT, start_gaddr, end_gaddr,
+                             maddr, MATTR_DEV, p2m_mmio_direct);
  }
 
  int guest_physmap_add_entry(struct domain *d,
@@ -457,20 +457,20 @@ int guest_physmap_add_entry(struct domain *d,
                              unsigned long page_order,
                              p2m_type_t t)
  {
-    return create_p2m_entries(d, INSERT,
-                              pfn_to_paddr(gpfn),
-                              pfn_to_paddr(gpfn + (1 << page_order)),
-                              pfn_to_paddr(mfn), MATTR_MEM, t);
+    return apply_p2m_changes(d, INSERT,
+                             pfn_to_paddr(gpfn),
+                             pfn_to_paddr(gpfn + (1 << page_order)),
+                             pfn_to_paddr(mfn), MATTR_MEM, t);
  }
 
  void guest_physmap_remove_page(struct domain *d,
                                 unsigned long gpfn,
                                 unsigned long mfn, unsigned int page_order)
  {
-    create_p2m_entries(d, REMOVE,
-                       pfn_to_paddr(gpfn),
-                       pfn_to_paddr(gpfn + (1<<page_order)),
-                       pfn_to_paddr(mfn), MATTR_MEM, p2m_invalid);
+    apply_p2m_changes(d, REMOVE,
+                      pfn_to_paddr(gpfn),
+                      pfn_to_paddr(gpfn + (1<<page_order)),
+                      pfn_to_paddr(mfn), MATTR_MEM, p2m_invalid);
  }
 
  int p2m_alloc_table(struct domain *d)
@@ -618,7 +618,7 @@ int relinquish_p2m_mapping(struct domain *d)
  {
      struct p2m_domain *p2m = &d->arch.p2m;
 
-    return create_p2m_entries(d, RELINQUISH,
+    return apply_p2m_changes(d, RELINQUISH,
                                pfn_to_paddr(p2m->next_gfn_to_relinquish),
                                pfn_to_paddr(p2m->max_mapped_gfn),
                                pfn_to_paddr(INVALID_MFN),
Signature · 1 line
Julien Grall
#6 lore raw

PATCH 3/4 xen: arm: rename p2m next_gfn_to_relinquish to lowest_mapped_gfn

In reply to Ian Campbell

This has other uses other than during relinquish, so rename it for clarity.

This is a pure rename.

---
 xen/arch/arm/p2m.c        |    9 ++++-----
 xen/include/asm-arm/p2m.h |    8 +++++---
 2 files changed, 9 insertions(+), 8 deletions(-)
xen/arch/arm/p2m.c +4 -5
index ace3c54..a61edeb 100644
@@ -388,7 +388,7 @@ static int apply_p2m_changes(struct domain *d,
         {
             if ( hypercall_preempt_check() )
             {
-                p2m->next_gfn_to_relinquish = addr >> PAGE_SHIFT;
+                p2m->lowest_mapped_gfn = addr >> PAGE_SHIFT;
                 rc = -EAGAIN;
                 goto out;
             }
@@ -415,8 +415,7 @@ static int apply_p2m_changes(struct domain *d,
         unsigned long egfn = paddr_to_pfn(end_gpaddr);
 
         p2m->max_mapped_gfn = MAX(p2m->max_mapped_gfn, egfn);
-        /* Use next_gfn_to_relinquish to store the lowest gfn mapped */
-        p2m->next_gfn_to_relinquish = MIN(p2m->next_gfn_to_relinquish, sgfn);
+        p2m->lowest_mapped_gfn = MIN(p2m->lowest_mapped_gfn, sgfn);
     }
 
     rc = 0;
@@ -606,7 +605,7 @@ int p2m_init(struct domain *d)
     p2m->first_level = NULL;
 
     p2m->max_mapped_gfn = 0;
-    p2m->next_gfn_to_relinquish = ULONG_MAX;
+    p2m->lowest_mapped_gfn = ULONG_MAX;
 
 err:
     spin_unlock(&p2m->lock);
@@ -619,7 +618,7 @@ int relinquish_p2m_mapping(struct domain *d)
     struct p2m_domain *p2m = &d->arch.p2m;
 
     return apply_p2m_changes(d, RELINQUISH,
-                              pfn_to_paddr(p2m->next_gfn_to_relinquish),
+                              pfn_to_paddr(p2m->lowest_mapped_gfn),
                               pfn_to_paddr(p2m->max_mapped_gfn),
                               pfn_to_paddr(INVALID_MFN),
                               MATTR_MEM, p2m_invalid);
xen/include/asm-arm/p2m.h +5 -3
index 53b3266..e9c884a 100644
@@ -24,9 +24,11 @@ struct p2m_domain {
      */
     unsigned long max_mapped_gfn;
 
-    /* When releasing mapped gfn's in a preemptible manner, recall where
-     * to resume the search */
-    unsigned long next_gfn_to_relinquish;
+    /* Lowest mapped gfn in the p2m. When releasing mapped gfn's in a
+     * preemptible manner this is update to track recall where to
+     * resume the search. Apart from during teardown this can only
+     * decrease. */
+    unsigned long lowest_mapped_gfn;
 };
 
 /* List of possible type for each page in the p2m entry.
Signature · 1 line
1.7.10.4
Acked-by on v1 3/4
#7 lore raw

Re: [PATCH 3/4] xen: arm: rename p2m next_gfn_to_relinquish to lowest_mapped_gfn

Quoted 5 lines · Ian Campbell

This has other uses other than during relinquish, so rename it for clarity.

This is a pure rename.

Quoted 66 lines
---
  xen/arch/arm/p2m.c        |    9 ++++-----
  xen/include/asm-arm/p2m.h |    8 +++++---
  2 files changed, 9 insertions(+), 8 deletions(-)
xen/arch/arm/p2m.c +4 -5
index ace3c54..a61edeb 100644
@@ -388,7 +388,7 @@ static int apply_p2m_changes(struct domain *d,
          {
              if ( hypercall_preempt_check() )
              {
-                p2m->next_gfn_to_relinquish = addr >> PAGE_SHIFT;
+                p2m->lowest_mapped_gfn = addr >> PAGE_SHIFT;
                  rc = -EAGAIN;
                  goto out;
              }
@@ -415,8 +415,7 @@ static int apply_p2m_changes(struct domain *d,
          unsigned long egfn = paddr_to_pfn(end_gpaddr);
 
          p2m->max_mapped_gfn = MAX(p2m->max_mapped_gfn, egfn);
-        /* Use next_gfn_to_relinquish to store the lowest gfn mapped */
-        p2m->next_gfn_to_relinquish = MIN(p2m->next_gfn_to_relinquish, sgfn);
+        p2m->lowest_mapped_gfn = MIN(p2m->lowest_mapped_gfn, sgfn);
      }
 
      rc = 0;
@@ -606,7 +605,7 @@ int p2m_init(struct domain *d)
      p2m->first_level = NULL;
 
      p2m->max_mapped_gfn = 0;
-    p2m->next_gfn_to_relinquish = ULONG_MAX;
+    p2m->lowest_mapped_gfn = ULONG_MAX;
 
  err:
      spin_unlock(&p2m->lock);
@@ -619,7 +618,7 @@ int relinquish_p2m_mapping(struct domain *d)
      struct p2m_domain *p2m = &d->arch.p2m;
 
      return apply_p2m_changes(d, RELINQUISH,
-                              pfn_to_paddr(p2m->next_gfn_to_relinquish),
+                              pfn_to_paddr(p2m->lowest_mapped_gfn),
                                pfn_to_paddr(p2m->max_mapped_gfn),
                                pfn_to_paddr(INVALID_MFN),
                                MATTR_MEM, p2m_invalid);
xen/include/asm-arm/p2m.h +5 -3
index 53b3266..e9c884a 100644
@@ -24,9 +24,11 @@ struct p2m_domain {
       */
      unsigned long max_mapped_gfn;
 
-    /* When releasing mapped gfn's in a preemptible manner, recall where
-     * to resume the search */
-    unsigned long next_gfn_to_relinquish;
+    /* Lowest mapped gfn in the p2m. When releasing mapped gfn's in a
+     * preemptible manner this is update to track recall where to
+     * resume the search. Apart from during teardown this can only
+     * decrease. */
+    unsigned long lowest_mapped_gfn;
  };
 
  /* List of possible type for each page in the p2m entry.
Signature · 1 line
Julien Grall
#8 lore raw

PATCH 4/4 xen/arm: clean and invalidate all guest caches by VMID after domain build.

In reply to Ian Campbell

Guests are initially started with caches disabled and so we need to make sure they see consistent data in RAM (requiring a cache clean) but also that they do not have old stale data suddenly appear in the caches when they enable their caches (requiring the invalidate).

We need to clean all caches in order to catch both pages dirtied by the domain builder and those which have been scrubbed but not yet flushed. Separating the two and flushing scrubbed pages at scrub time and only builder-dirtied pages here would require tracking the dirtiness state in the guest's p2m, perhaps via a new p2m type.

---
 tools/libxc/xc_domain.c     |    8 ++++++
 tools/libxc/xenctrl.h       |    1 +
 tools/libxl/libxl_create.c  |    3 ++
 xen/arch/arm/domctl.c       |   12 ++++++++
 xen/arch/arm/p2m.c          |   64 +++++++++++++++++++++++++++++++++++++------
 xen/include/public/domctl.h |    9 ++++++
 6 files changed, 89 insertions(+), 8 deletions(-)
tools/libxc/xc_domain.c +8 -0
index c2fdd74..e6fa4ff 100644
@@ -48,6 +48,14 @@ int xc_domain_create(xc_interface *xch,
     return 0;
 }
 
+int xc_domain_cacheflush(xc_interface *xch, uint32_t domid)
+{
+    DECLARE_DOMCTL;
+    domctl.cmd = XEN_DOMCTL_cacheflush;
+    domctl.domain = (domid_t)domid;
+    domctl.u.cacheflush.start_mfn = 0;
+    return do_domctl(xch, &domctl);
+}
 
 int xc_domain_pause(xc_interface *xch,
                     uint32_t domid)
tools/libxc/xenctrl.h +1 -0
index 13f816b..43dae5c 100644
@@ -453,6 +453,7 @@ int xc_domain_create(xc_interface *xch,
                      xen_domain_handle_t handle,
                      uint32_t flags,
                      uint32_t *pdomid);
+int xc_domain_cacheflush(xc_interface *xch, uint32_t domid);
 
 
 /* Functions to produce a dump of a given domain
tools/libxl/libxl_create.c +3 -0
index a604cd8..55c86f0 100644
@@ -1364,7 +1364,10 @@ static void domain_create_cb(libxl__egc *egc,
     STATE_AO_GC(cdcs->dcs.ao);
 
     if (!rc)
+    {
         *cdcs->domid_out = domid;
+        xc_domain_cacheflush(CTX->xch, domid);
+    }
 
     libxl__ao_complete(egc, ao, rc);
 }
xen/arch/arm/domctl.c +12 -0
index 546e86b..9e3b37d 100644
@@ -11,12 +11,24 @@
 #include <xen/sched.h>
 #include <xen/hypercall.h>
 #include <public/domctl.h>
+#include <xen/guest_access.h>
+
+extern long p2m_cache_flush(struct domain *d, xen_pfn_t *start_mfn);
 
 long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
                     XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 {
     switch ( domctl->cmd )
     {
+    case XEN_DOMCTL_cacheflush:
+    {
+        long rc = p2m_cache_flush(d, &domctl->u.cacheflush.start_mfn);
+        if ( __copy_to_guest(u_domctl, domctl, 1) )
+            rc = -EFAULT;
+
+        return rc;
+    }
+
     default:
         return subarch_do_domctl(domctl, d, u_domctl);
     }
xen/arch/arm/p2m.c +56 -8

124 lines not on this page · raw message

xen/include/public/domctl.h +9 -0
index 91f01fa..d7b22c3 100644
@@ -885,6 +885,13 @@ struct xen_domctl_set_max_evtchn {
 typedef struct xen_domctl_set_max_evtchn xen_domctl_set_max_evtchn_t;
 DEFINE_XEN_GUEST_HANDLE(xen_domctl_set_max_evtchn_t);
 
+struct xen_domctl_cacheflush {
+    /* Updated for progress */
+    xen_pfn_t start_mfn;
+};
+typedef struct xen_domctl_cacheflush xen_domctl_cacheflush_t;
+DEFINE_XEN_GUEST_HANDLE(xen_domctl_cacheflush_t);
+
 struct xen_domctl {
     uint32_t cmd;
 #define XEN_DOMCTL_createdomain                   1
@@ -954,6 +961,7 @@ struct xen_domctl {
 #define XEN_DOMCTL_setnodeaffinity               68
 #define XEN_DOMCTL_getnodeaffinity               69
 #define XEN_DOMCTL_set_max_evtchn                70
+#define XEN_DOMCTL_cacheflush                    71
 #define XEN_DOMCTL_gdbsx_guestmemio            1000
 #define XEN_DOMCTL_gdbsx_pausevcpu             1001
 #define XEN_DOMCTL_gdbsx_unpausevcpu           1002
@@ -1012,6 +1020,7 @@ struct xen_domctl {
         struct xen_domctl_set_max_evtchn    set_max_evtchn;
         struct xen_domctl_gdbsx_memio       gdbsx_guest_memio;
         struct xen_domctl_set_broken_page_p2m set_broken_page_p2m;
+        struct xen_domctl_cacheflush        cacheflush;
         struct xen_domctl_gdbsx_pauseunp_vcpu gdbsx_pauseunp_vcpu;
         struct xen_domctl_gdbsx_domstatus   gdbsx_domstatus;
         uint8_t                             pad[128];
Signature · 1 line
1.7.10.4
#9 lore raw

Re: [PATCH 4/4] xen/arm: clean and invalidate all guest caches by VMID after domain build.

tools/libxc/xc_domain.c int xc_domain_create(xc_interface *xch, · line 55

Quoted 12 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
tools/libxc/xc_domain.c +5 -0
@@ -48,6 +48,14 @@ int xc_domain_create(xc_interface *xch,
     return 0;
 }
 
+int xc_domain_cacheflush(xc_interface *xch, uint32_t domid)
+{
+    DECLARE_DOMCTL;
+    domctl.cmd = XEN_DOMCTL_cacheflush;
+    domctl.domain = (domid_t)domid;

Why can't the function parameter be domid_t right away?

tools/libxc/xc_domain.c int xc_domain_create(xc_interface *xch, · line 59

Quoted 4 lines
tools/libxc/xc_domain.c +4 -0
+    case XEN_DOMCTL_cacheflush:
+    {
+        long rc = p2m_cache_flush(d, &domctl->u.cacheflush.start_mfn);
+        if ( __copy_to_guest(u_domctl, domctl, 1) )

While you certainly say so in the public header change, I think you recall that we pretty recently changed another hypercall to not be the only inconsistent one modifying the input structure in order to handle hypercall preemption.

Further - who's responsible for initiating the resume after a preemption? p2m_cache_flush() returning -EAGAIN isn't being handled here, and also not in libxc (which would be awkward anyway).

tools/libxc/xc_domain.c int xc_domain_create(xc_interface *xch,

Quoted 8 lines
tools/libxc/xc_domain.c +8 -0
+static void do_one_cacheflush(paddr_t mfn)
+{
+    void *v = map_domain_page(mfn);
+
+    flush_xen_dcache_va_range(v, PAGE_SIZE);
+
+    unmap_domain_page(v);
+}

Sort of odd that you have to map a page in order to flush cache (which I very much hope is physically indexed, or else this operation wouldn't have the intended effect anyway). Can this not be done based on the machine address?

Quoted 11 lines
         /* Preempt every 2MiB (mapped) or 32 MiB (unmapped) - arbitrary */
tools/libxc/xc_domain.c +4 -2
-        if ( op == RELINQUISH && count >= 0x2000 )
+        switch ( op )
         {
-            if ( hypercall_preempt_check() )
+        case RELINQUISH:
+        case CACHEFLUSH:
+            if (count >= 0x2000 && hypercall_preempt_check() )
             {
                 p2m->lowest_mapped_gfn = addr >> PAGE_SHIFT;
                 rc = -EAGAIN;

tools/libxc/xc_domain.c

Quoted 10 lines
tools/libxc/xc_domain.c +6 -0
                 goto out;
             }
             count = 0;
+            break;
+        case INSERT:
+        case ALLOCATE:
+        case REMOVE:
+            /* No preemption */
+            break;
         }

Unrelated to the patch here, but don't you have a problem if you don't preempt _at all_ here for certain operation types? Or is a limit on the number of iterations being enforced elsewhere for those?

Jan

#10 lore raw

Re: [PATCH 4/4] xen/arm: clean and invalidate all guest caches by VMID after domain build.

Quoted 5 lines · Jan Beulich
Quoted 5 lines
xen/arch/arm/p2m.c +5 -0
+static void do_one_cacheflush(paddr_t mfn)
+{
+    void *v = map_domain_page(mfn);
+
+    flush_xen_dcache_va_range(v, PAGE_SIZE);
Quoted 8 lines

xen/arch/arm/p2m.c enum p2m_operation { · line 241

Quoted 3 lines
xen/arch/arm/p2m.c +3 -0
+
+    unmap_domain_page(v);
+}

Sort of odd that you have to map a page in order to flush cache (which I very much hope is physically indexed, or else this operation wouldn't have the intended effect anyway). Can this not be done based on the machine address?

Unfortunately no. I asked for a similar change when Ian sent the RFC because I was concerned about performances, but it turns out is not possible. A pity.

#11 lore raw

Re: [PATCH 4/4] xen/arm: clean and invalidate all guest caches by VMID after domain build.

In reply to Jan Beulich
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
tools/libxc/xc_domain.c +0 -0
@@ -48,6 +48,14 @@ int xc_domain_create(xc_interface *xch,
     return 0;
 }
 
Quoted 7 lines

tools/libxc/xc_domain.c int xc_domain_create(xc_interface *xch, · line 55

Quoted 5 lines
tools/libxc/xc_domain.c +5 -0
+int xc_domain_cacheflush(xc_interface *xch, uint32_t domid)
+{
+    DECLARE_DOMCTL;
+    domctl.cmd = XEN_DOMCTL_cacheflush;
+    domctl.domain = (domid_t)domid;

Why can't the function parameter be domid_t right away?

It seemed that the vast majority of the current libxc functions were using uint32_t for whatever reason.

Quoted 10 lines

tools/libxc/xc_domain.c int xc_domain_create(xc_interface *xch, · line 59

Quoted 5 lines
tools/libxc/xc_domain.c +4 -0
+    case XEN_DOMCTL_cacheflush:
+    {
+        long rc = p2m_cache_flush(d, &domctl->u.cacheflush.start_mfn);
+        if ( __copy_to_guest(u_domctl, domctl, 1) )

While you certainly say so in the public header change, I think you recall that we pretty recently changed another hypercall to not be the only inconsistent one modifying the input structure in order to handle hypercall preemption.

That was a XNEMEM though IIRC -- is the same requirement also true of domctl's?

How/where would you recommend saving the progress here?

Quoted 5 lines

Further - who's responsible for initiating the resume after a preemption? p2m_cache_flush() returning -EAGAIN isn't being handled here, and also not in libxc (which would be awkward anyway).

I've once again fallen into the trap of thinking the common domctl code would do it for me.

Quoted 14 lines

tools/libxc/xc_domain.c int xc_domain_create(xc_interface *xch,

Quoted 9 lines
tools/libxc/xc_domain.c +8 -0
+static void do_one_cacheflush(paddr_t mfn)
+{
+    void *v = map_domain_page(mfn);
+
+    flush_xen_dcache_va_range(v, PAGE_SIZE);
+
+    unmap_domain_page(v);
+}

Sort of odd that you have to map a page in order to flush cache (which I very much hope is physically indexed, or else this operation wouldn't have the intended effect anyway). Can this not be done based on the machine address?

Sadly not, yes it is very annoying.

Yes, the cache is required to be physically indexed from armv7 onwards.

Quoted 23 lines
Quoted 12 lines
         /* Preempt every 2MiB (mapped) or 32 MiB (unmapped) - arbitrary */
tools/libxc/xc_domain.c +4 -2
-        if ( op == RELINQUISH && count >= 0x2000 )
+        switch ( op )
         {
-            if ( hypercall_preempt_check() )
+        case RELINQUISH:
+        case CACHEFLUSH:
+            if (count >= 0x2000 && hypercall_preempt_check() )
             {
                 p2m->lowest_mapped_gfn = addr >> PAGE_SHIFT;
                 rc = -EAGAIN;

tools/libxc/xc_domain.c

Quoted 10 lines
tools/libxc/xc_domain.c +6 -0
                 goto out;
             }
             count = 0;
+            break;
+        case INSERT:
+        case ALLOCATE:
+        case REMOVE:
+            /* No preemption */
+            break;
         }
Quoted 4 lines

Unrelated to the patch here, but don't you have a problem if you don't preempt _at all_ here for certain operation types? Or is a limit on the number of iterations being enforced elsewhere for those?

Good question.

The tools/guest accessible paths here are through guest_physmap_add/remove_page. I think the only paths which are exposed that pass a non-zero order are XENMEM_populate_physmap and XENMEM_exchange, bot of which restrict the maximum order.

I don't think those guest_physmap_* are preemptible on x86 either?

It's possible that we should nevertheless handle preemption on those code paths as well, but I don't think it is critical right now (*or at least not critical enough to warrant an freeze exception for 4.4).

Ian.

#12 lore raw

Re: [PATCH 4/4] xen/arm: clean and invalidate all guest caches by VMID after domain build.

Quoted 8 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
xen/arch/arm/domctl.c +4 -0
+    case XEN_DOMCTL_cacheflush:
+    {
+        long rc = p2m_cache_flush(d, &domctl->u.cacheflush.start_mfn);
+        if ( __copy_to_guest(u_domctl, domctl, 1) )
Quoted 7 lines
Quoted 4 lines

While you certainly say so in the public header change, I think you recall that we pretty recently changed another hypercall to not be the only inconsistent one modifying the input structure in order to handle hypercall preemption.

That was a XNEMEM though IIRC -- is the same requirement also true of domctl's?

Not necessarily - I was just trying to point out the issue to avoid needing to fix it later on.

Quoted 1 line

How/where would you recommend saving the progress here?

Depending on the nature, a per-domain or per-vCPU field that gets acted upon before issuing any new, similar operation. I.e. something along the lines of x86's old_guest_table. It's ugly, I know. But with exposing domctls to semi-trusted guests in mind, you may use state modifiable by the caller here only if tampering with that state isn't going to harm the whole system (if the guest being started is affected in the case here that obviously wouldn't be a problem).

Quoted 27 lines
Quoted 22 lines
Quoted 11 lines
         /* Preempt every 2MiB (mapped) or 32 MiB (unmapped) - arbitrary */
xen/arch/arm/p2m.c +4 -2
-        if ( op == RELINQUISH && count >= 0x2000 )
+        switch ( op )
         {
-            if ( hypercall_preempt_check() )
+        case RELINQUISH:
+        case CACHEFLUSH:
+            if (count >= 0x2000 && hypercall_preempt_check() )
             {
                 p2m->lowest_mapped_gfn = addr >> PAGE_SHIFT;
                 rc = -EAGAIN;

xen/arch/arm/p2m.c static int apply_p2m_changes(struct domain *d, · line 431

Quoted 10 lines
xen/arch/arm/p2m.c +6 -0
                 goto out;
             }
             count = 0;
+            break;
+        case INSERT:
+        case ALLOCATE:
+        case REMOVE:
+            /* No preemption */
+            break;
         }
Quoted 4 lines

Unrelated to the patch here, but don't you have a problem if you don't preempt _at all_ here for certain operation types? Or is a limit on the number of iterations being enforced elsewhere for those?

Quoted 8 lines

Good question.

The tools/guest accessible paths here are through guest_physmap_add/remove_page. I think the only paths which are exposed that pass a non-zero order are XENMEM_populate_physmap and XENMEM_exchange, bot of which restrict the maximum order.

I don't think those guest_physmap_* are preemptible on x86 either?

They aren't, but they have a strict upper limit of at most dealing with a 1Gb page at a time. If that's similar for ARM, I don't see an immediate issue.

Quoted 3 lines

It's possible that we should nevertheless handle preemption on those code paths as well, but I don't think it is critical right now (*or at least not critical enough to warrant an freeze exception for 4.4).

Indeed. Of course the 1Gb limit mentioned above, while perhaps acceptable to process without preemption right now, is still pretty high for achieving really good responsiveness, so we may need to do something about that going forward.

Jan

#13 lore raw

Re: [PATCH 4/4] xen/arm: clean and invalidate all guest caches by VMID after domain build.

Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 10 lines · Jan Beulich

xen/arch/arm/domctl.c line 26

Quoted 5 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
xen/arch/arm/domctl.c +4 -0
+    case XEN_DOMCTL_cacheflush:
+    {
+        long rc = p2m_cache_flush(d, &domctl->u.cacheflush.start_mfn);
+        if ( __copy_to_guest(u_domctl, domctl, 1) )

While you certainly say so in the public header change, I think you recall that we pretty recently changed another hypercall to not be the only inconsistent one modifying the input structure in order to handle hypercall preemption.

Quoted 5 lines
Quoted 2 lines

That was a XNEMEM though IIRC -- is the same requirement also true of domctl's?

Not necessarily - I was just trying to point out the issue to avoid needing to fix it later on.

OK, but you do think it should be fixed "transparently" rather than made an explicit part of the API?

Quoted 10 lines
Quoted 1 line

How/where would you recommend saving the progress here?

Depending on the nature, a per-domain or per-vCPU field that gets acted upon before issuing any new, similar operation. I.e. something along the lines of x86's old_guest_table. It's ugly, I know. But with exposing domctls to semi-trusted guests in mind, you may use state modifiable by the caller here only if tampering with that state isn't going to harm the whole system (if the guest being started is affected in the case here that obviously wouldn't be a problem).

Hrm, thanks for raising this -- it made me realise that we cannot necessarily rely on the disaggregated domain builder to even issue this call at all.

That would be OK from the point of view of not flushing the things which the builder touched (as you say, it can only harm the domain it is building). But it is not ok from the PoV of flushing scrubbed data from the cache, ensuring that the scrubbed bytes reach RAM (i.e. it can leak old data).

So I think I need an approach which flushes the scrubbed pages as it does the scrubbing (this makes a certain logical sense anyway) and have the toolstack issue hypercalls to flush the stuff it has written. (the first approach to this issue tried to do this but used a system call provided by Linux which didn't have the quite correct semantics, but using a version of this hypercall with a range should work).

Before I get too deep into that, do you think that

        struct xen_domctl_cacheflush {
            /* start_mfn is updated for progress over preemption. */
            xen_pfn_t start_mfn;
            xen_pfn_t end_mfn;
        };

is acceptable or do you want me to try and find a way to do preemption without the write back?

The blobs written by the toolstack aren't likely to be >1GB in size, so rejecting over large ranges would be a potential option, but it's not totally satisfactory.

Quoted 34 lines
Quoted 34 lines
Quoted 22 lines
Quoted 11 lines
         /* Preempt every 2MiB (mapped) or 32 MiB (unmapped) - arbitrary */
xen/arch/arm/p2m.c +4 -2
-        if ( op == RELINQUISH && count >= 0x2000 )
+        switch ( op )
         {
-            if ( hypercall_preempt_check() )
+        case RELINQUISH:
+        case CACHEFLUSH:
+            if (count >= 0x2000 && hypercall_preempt_check() )
             {
                 p2m->lowest_mapped_gfn = addr >> PAGE_SHIFT;
                 rc = -EAGAIN;

xen/arch/arm/p2m.c static int apply_p2m_changes(struct domain *d, · line 431

Quoted 10 lines
xen/arch/arm/p2m.c +6 -0
                 goto out;
             }
             count = 0;
+            break;
+        case INSERT:
+        case ALLOCATE:
+        case REMOVE:
+            /* No preemption */
+            break;
         }
Quoted 4 lines

Unrelated to the patch here, but don't you have a problem if you don't preempt _at all_ here for certain operation types? Or is a limit on the number of iterations being enforced elsewhere for those?

Good question.

The tools/guest accessible paths here are through guest_physmap_add/remove_page. I think the only paths which are exposed that pass a non-zero order are XENMEM_populate_physmap and XENMEM_exchange, bot of which restrict the maximum order.

Quoted 5 lines
Quoted 1 line

I don't think those guest_physmap_* are preemptible on x86 either?

They aren't, but they have a strict upper limit of at most dealing with a 1Gb page at a time. If that's similar for ARM, I don't see an immediate issue.

Same on ARM (through common code using MAX_ORDER == 20)

Quoted 8 lines
Quoted 3 lines

It's possible that we should nevertheless handle preemption on those code paths as well, but I don't think it is critical right now (*or at least not critical enough to warrant an freeze exception for 4.4).

Indeed. Of course the 1Gb limit mentioned above, while perhaps acceptable to process without preemption right now, is still pretty high for achieving really good responsiveness, so we may need to do something about that going forward.

Right. I won't worry about it now though.

Quoted 3 lines

Jan

#14 lore raw

Re: [PATCH 4/4] xen/arm: clean and invalidate all guest caches by VMID after domain build.

Quoted 15 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 10 lines · Jan Beulich

xen/arch/arm/domctl.c line 26

Quoted 5 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
xen/arch/arm/domctl.c +4 -0
+    case XEN_DOMCTL_cacheflush:
+    {
+        long rc = p2m_cache_flush(d, &domctl->u.cacheflush.start_mfn);
+        if ( __copy_to_guest(u_domctl, domctl, 1) )

While you certainly say so in the public header change, I think you recall that we pretty recently changed another hypercall to not be the only inconsistent one modifying the input structure in order to handle hypercall preemption.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

That was a XNEMEM though IIRC -- is the same requirement also true of domctl's?

Not necessarily - I was just trying to point out the issue to avoid needing to fix it later on.

OK, but you do think it should be fixed "transparently" rather than made an explicit part of the API?

I'd prefer if it would be done that way. Otherwise we'd need to mentally store that we're allowing exceptions for domctls, but not for other hypercalls.

Quoted 9 lines

Before I get too deep into that, do you think that

        struct xen_domctl_cacheflush {
            /* start_mfn is updated for progress over preemption. */
            xen_pfn_t start_mfn;
            xen_pfn_t end_mfn;
        };

is acceptable or do you want me to try and find a way to do preemption without the write back?

As per above - if possible, I'd prefer you avoiding the write back.

Quoted 3 lines

The blobs written by the toolstack aren't likely to be >1GB in size, so rejecting over large ranges would be a potential option, but it's not totally satisfactory.

Agreed, but good enough for now (considering the various other cases that already have similar "issues").

Jan

#15 lore raw

Re: [PATCH 4/4] xen/arm: clean and invalidate all guest caches by VMID after domain build.

In reply to Ian Campbell

Ian Campbell writes ("Re: [PATCH 4/4] xen/arm: clean and invalidate all guest caches by VMID after domain build."):

Quoted 9 lines · Jan Beulich
Quoted 5 lines

tools/libxc/xc_domain.c int xc_domain_create(xc_interface *xch, · line 55

Quoted 3 lines · Ian Campbell
tools/libxc/xc_domain.c +2 -0
+int xc_domain_cacheflush(xc_interface *xch, uint32_t domid)
+    domctl.domain = (domid_t)domid;

Why can't the function parameter be domid_t right away?

It seemed that the vast majority of the current libxc functions were using uint32_t for whatever reason.

What's the point of the cast, though ?

Ian.

#16 lore raw

Re: [PATCH 4/4] xen/arm: clean and invalidate all guest caches by VMID after domain build.

Quoted 6 lines · Ian Jackson

Ian Campbell writes ("Re: [PATCH 4/4] xen/arm: clean and invalidate all guest caches by VMID after domain build."):

Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 3 lines · Ian Campbell
tools/libxc/xc_domain.c +2 -0
+int xc_domain_cacheflush(xc_interface *xch, uint32_t domid)
+    domctl.domain = (domid_t)domid;
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Why can't the function parameter be domid_t right away?

It seemed that the vast majority of the current libxc functions were using uint32_t for whatever reason.

What's the point of the cast, though ?

Apparently all the cool kids in this file are doing it and I followed suite ;-)

domid_t is a uint16_t, I kind of expect gcc to warn about an assignment of a uint32_t to a uint16_t to generate some sort of warning, but apparently not...

Ian.

#17 lore raw

Re: [PATCH 4/4] xen/arm: clean and invalidate all guest caches by VMID after domain build.

Quoted 12 lines · Ian Campbell
Quoted 11 lines · Ian Jackson

Ian Campbell writes ("Re: [PATCH 4/4] xen/arm: clean and invalidate all guest caches by VMID after domain build."):

Quoted 9 lines · Jan Beulich
Quoted 5 lines

tools/libxc/xc_domain.c int xc_domain_create(xc_interface *xch, · line 55

Quoted 3 lines · Ian Campbell
tools/libxc/xc_domain.c +2 -0
+int xc_domain_cacheflush(xc_interface *xch, uint32_t domid)
+    domctl.domain = (domid_t)domid;

Why can't the function parameter be domid_t right away?

It seemed that the vast majority of the current libxc functions were using uint32_t for whatever reason.

Quoted 8 lines
Quoted 1 line

What's the point of the cast, though ?

Apparently all the cool kids in this file are doing it and I followed suite ;-)

domid_t is a uint16_t, I kind of expect gcc to warn about an assignment of a uint32_t to a uint16_t to generate some sort of warning, but apparently not...

Just for completeness: -Wconversion is the option to make it do this.

#18 lore raw
In reply to Ian Campbell

Hi Ian,

Thanks for the patch series.

Quoted 7 lines · Ian Campbell

Jan/Ian/Keir -- the final patch involves tools changes and a new domctl, which is why you are copied (although the domctl is marked as arm specific you might have opinions on it).

On ARM we need to take care of cache coherency for guests which we have just built because they start with their caches disabled.

Quoted 7 lines

Our current strategy for dealing with this, which is to make guest memory default to cacheable regardless of the in guest configuration (the HCR.DC bit), is flawed because it doesn't handle guests which enable their MMU before enabling their caches, which at least FreeBSD does. (NB: Setting HCR.DC while the guest MMU is enabled is UNPREDICTABLE, hence we must disable it when the guest turns its MMU one).

Enabling the cache earlier wouldn't change the issue :). The main problem is the page table attributes. Using Write-Through (with cached enabled/disabled) can randomly crash guest.

Signature · 1 line
Julien Grall