Skip to contentSkip to conversation

x86/p2m: some code simplification

PATCH Superseded Jan Beulich 2 participants 9 messages Jul 5, 2017 – Aug 11, 2017

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/3 x86/p2m-pt: simplify p2m_next_level()

Calculate entry PFN and flags just once. Convert the two successive main if()-s to and if/elf-if chain. Restrict variable scope where reasonable. Take the opportunity and also make the induction variable unsigned.

---
v2: Re-do mostly from scratch following review feedback.
Note: I have trouble seeing how the old code worked, when the 2M page
shattering path specified neither read nor write permission for the IOMMU. Am I overlooking a reason why this was (and should remain) so?

xen/arch/x86/mm/p2m-pt.c +43 -52
@@ -191,18 +191,18 @@ p2m_next_level(struct p2m_domain *p2m, v
                unsigned long *gfn_remainder, unsigned long gfn, u32 shift,
                u32 max, unsigned long type, bool_t unmap)
 {
-    l1_pgentry_t *l1_entry;
-    l1_pgentry_t *p2m_entry;
-    l1_pgentry_t new_entry;
+    l1_pgentry_t *p2m_entry, new_entry;
     void *next;
-    int i;
+    unsigned int flags;
 
     if ( !(p2m_entry = p2m_find_entry(*table, gfn_remainder, gfn,
                                       shift, max)) )
         return -ENOENT;
 
+    flags = l1e_get_flags(*p2m_entry);
+
     /* PoD/paging: Not present doesn't imply empty. */
-    if ( !l1e_get_flags(*p2m_entry) )
+    if ( !flags )
     {
         struct page_info *pg;
 
@@ -231,70 +231,61 @@ p2m_next_level(struct p2m_domain *p2m, v
             break;
         }
     }
-
-    ASSERT(l1e_get_flags(*p2m_entry) & (_PAGE_PRESENT|_PAGE_PSE));
-
-    /* split 1GB pages into 2MB pages */
-    if ( type == PGT_l2_page_table && (l1e_get_flags(*p2m_entry) & _PAGE_PSE) )
+    else if ( flags & _PAGE_PSE )
     {
-        unsigned long flags, pfn;
+        /* Split superpages pages into smaller ones. */
+        unsigned long pfn = l1e_get_pfn(*p2m_entry);
         struct page_info *pg;
+        l1_pgentry_t *l1_entry;
+        unsigned int i, level;
 
-        pg = p2m_alloc_ptp(p2m, PGT_l2_page_table);
-        if ( pg == NULL )
-            return -ENOMEM;
-
-        flags = l1e_get_flags(*p2m_entry);
-        pfn = l1e_get_pfn(*p2m_entry);
-
-        l1_entry = __map_domain_page(pg);
-        for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ )
+        switch ( type )
         {
-            new_entry = l1e_from_pfn(pfn | (i * L1_PAGETABLE_ENTRIES), flags);
-            p2m_add_iommu_flags(&new_entry, 1, IOMMUF_readable|IOMMUF_writable);
-            p2m->write_p2m_entry(p2m, gfn, l1_entry + i, new_entry, 2);
-        }
-        unmap_domain_page(l1_entry);
-        new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)),
-                                 P2M_BASE_FLAGS | _PAGE_RW); /* disable PSE */
-        p2m_add_iommu_flags(&new_entry, 2, IOMMUF_readable|IOMMUF_writable);
-        p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 3);
-    }
+        case PGT_l2_page_table:
+            level = 2;
+            break;
 
+        case PGT_l1_page_table:
+            /*
+             * New splintered mappings inherit the flags of the old superpage,
+             * with a little reorganisation for the _PAGE_PSE_PAT bit.
+             */
+            if ( pfn & 1 )           /* ==> _PAGE_PSE_PAT was set */
+                pfn -= 1;            /* Clear it; _PAGE_PSE becomes _PAGE_PAT */
+            else
+                flags &= ~_PAGE_PSE; /* Clear _PAGE_PSE (== _PAGE_PAT) */
 
-    /* split single 2MB large page into 4KB page in P2M table */
-    if ( type == PGT_l1_page_table && (l1e_get_flags(*p2m_entry) & _PAGE_PSE) )
-    {
-        unsigned long flags, pfn;
-        struct page_info *pg;
+            level = 1;
+            break;
 
-        pg = p2m_alloc_ptp(p2m, PGT_l1_page_table);
+        default:
+            ASSERT_UNREACHABLE();
+            return -EINVAL;
+        }
+
+        pg = p2m_alloc_ptp(p2m, type);
         if ( pg == NULL )
             return -ENOMEM;
 
-        /* New splintered mappings inherit the flags of the old superpage, 
-         * with a little reorganisation for the _PAGE_PSE_PAT bit. */
-        flags = l1e_get_flags(*p2m_entry);
-        pfn = l1e_get_pfn(*p2m_entry);
-        if ( pfn & 1 )           /* ==> _PAGE_PSE_PAT was set */
-            pfn -= 1;            /* Clear it; _PAGE_PSE becomes _PAGE_PAT */
-        else
-            flags &= ~_PAGE_PSE; /* Clear _PAGE_PSE (== _PAGE_PAT) */
-        
         l1_entry = __map_domain_page(pg);
-        for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ )
+
+        for ( i = 0; i < (1u << PAGETABLE_ORDER); i++ )
         {
-            new_entry = l1e_from_pfn(pfn | i, flags);
-            p2m_add_iommu_flags(&new_entry, 0, 0);
-            p2m->write_p2m_entry(p2m, gfn, l1_entry + i, new_entry, 1);
+            new_entry = l1e_from_pfn(pfn | (i << ((level - 1) * PAGETABLE_ORDER)),
+                                     flags);
+            p2m_add_iommu_flags(&new_entry, level - 1,
+                                IOMMUF_readable|IOMMUF_writable);
+            p2m->write_p2m_entry(p2m, gfn, l1_entry + i, new_entry, level);
         }
+
         unmap_domain_page(l1_entry);
-        
         new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)),
                                  P2M_BASE_FLAGS | _PAGE_RW);
-        p2m_add_iommu_flags(&new_entry, 1, IOMMUF_readable|IOMMUF_writable);
-        p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 2);
+        p2m_add_iommu_flags(&new_entry, level, IOMMUF_readable|IOMMUF_writable);
+        p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, level + 1);
     }
+    else
+        ASSERT(flags & _PAGE_PRESENT);
 
     next = map_domain_page(_mfn(l1e_get_pfn(*p2m_entry)));
     if ( unmap )

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw

Re: [PATCH v2 1/3] x86/p2m-pt: simplify p2m_next_level()

Quoted 5 lines · Jan Beulich

Calculate entry PFN and flags just once. Convert the two successive main if()-s to and if/elf-if chain. Restrict variable scope where reasonable. Take the opportunity and also make the induction variable unsigned.

Quoted 7 lines

---
v2: Re-do mostly from scratch following review feedback.
Note: I have trouble seeing how the old code worked, when the 2M page
shattering path specified neither read nor write permission for the IOMMU. Am I overlooking a reason why this was (and should remain) so?

Hmm -- given that in all other circumstances, a 4k page which is ram_rw gets RW, then I think the old code must certainly be buggy.

But is your code correct? It looks like you unconditionally give it RW, when for ram_ro, for example it should be R (not W). It seems like we should either call p2m_get_iommu_flags(), or ASSERT() that the resulting flags would be RW.

Everything else looks good, thanks.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH v2 1/3] x86/p2m-pt: simplify p2m_next_level()

Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 27.07.17 at 18:19, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich

Calculate entry PFN and flags just once. Convert the two successive main if()-s to and if/elf-if chain. Restrict variable scope where reasonable. Take the opportunity and also make the induction variable unsigned.

Quoted 7 lines

---
v2: Re-do mostly from scratch following review feedback.
Note: I have trouble seeing how the old code worked, when the 2M page
shattering path specified neither read nor write permission for the IOMMU. Am I overlooking a reason why this was (and should remain) so?

Quoted 7 lines

Hmm -- given that in all other circumstances, a 4k page which is ram_rw gets RW, then I think the old code must certainly be buggy.

But is your code correct? It looks like you unconditionally give it RW, when for ram_ro, for example it should be R (not W). It seems like we should either call p2m_get_iommu_flags(), or ASSERT() that the resulting flags would be RW.

Hmm, good point, but that means the original code had the same issue when splitting 1G into 2M pages. I'd prefer to not call p2m_get_iommu_flags() though, but instead simply inherit the IOMMU flags from the original large page.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw

Re: [PATCH v2 1/3] x86/p2m-pt: simplify p2m_next_level()

In reply to George Dunlap
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 27.07.17 at 18:19, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich

Calculate entry PFN and flags just once. Convert the two successive main if()-s to and if/elf-if chain. Restrict variable scope where reasonable. Take the opportunity and also make the induction variable unsigned.

Quoted 7 lines

---
v2: Re-do mostly from scratch following review feedback.
Note: I have trouble seeing how the old code worked, when the 2M page
shattering path specified neither read nor write permission for the IOMMU. Am I overlooking a reason why this was (and should remain) so?

Quoted 2 lines

Hmm -- given that in all other circumstances, a 4k page which is ram_rw gets RW, then I think the old code must certainly be buggy.

Oh, I think this is buggy in another way than I first thought: It looks like it's meant to inherit the original flags (as they're not being cleared from "flags"), but afaict that breaks the next level field - that one is also being inherited, and then being OR-ed into with the new next level field. I suppose all of this has not caused issues simply because we've not allowed shared page tables on AMD for quite a while (and both fields are of no interest in the shadow mode case).

I'll drop the use of p2m_add_iommu_flags() in that particular case altogether.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw

PATCH v2 2/3 x86/p2m: make p2m_alloc_ptp() return an MFN

In reply to Jan Beulich

None of the callers really needs the struct page_info pointer.

---
v2: Re-base over changes to patch 1.

xen/arch/x86/mm/p2m.c +8 -8
@@ -569,7 +569,7 @@ int p2m_set_entry(struct p2m_domain *p2m
     return rc;
 }
 
-struct page_info *p2m_alloc_ptp(struct p2m_domain *p2m, unsigned long type)
+mfn_t p2m_alloc_ptp(struct p2m_domain *p2m, unsigned long type)
 {
     struct page_info *pg;
 
@@ -577,13 +577,13 @@ struct page_info *p2m_alloc_ptp(struct p
     ASSERT(p2m->domain);
     ASSERT(p2m->domain->arch.paging.alloc_page);
     pg = p2m->domain->arch.paging.alloc_page(p2m->domain);
-    if (pg == NULL)
-        return NULL;
+    if ( !pg )
+        return INVALID_MFN;
 
     page_list_add_tail(pg, &p2m->pages);
     pg->u.inuse.type_info = type | 1 | PGT_validated;
 
-    return pg;
+    return page_to_mfn(pg);
 }
 
 void p2m_free_ptp(struct p2m_domain *p2m, struct page_info *pg)
@@ -609,7 +609,7 @@ void p2m_free_ptp(struct p2m_domain *p2m
  */
 int p2m_alloc_table(struct p2m_domain *p2m)
 {
-    struct page_info *p2m_top;
+    mfn_t top_mfn;
     struct domain *d = p2m->domain;
     int rc = 0;
 
@@ -632,14 +632,14 @@ int p2m_alloc_table(struct p2m_domain *p
 
     P2M_PRINTK("allocating p2m table\n");
 
-    p2m_top = p2m_alloc_ptp(p2m, PGT_l4_page_table);
-    if ( p2m_top == NULL )
+    top_mfn = p2m_alloc_ptp(p2m, PGT_l4_page_table);
+    if ( mfn_eq(top_mfn, INVALID_MFN) )
     {
         p2m_unlock(p2m);
         return -ENOMEM;
     }
 
-    p2m->phys_table = pagetable_from_mfn(page_to_mfn(p2m_top));
+    p2m->phys_table = pagetable_from_mfn(top_mfn);
 
     if ( hap_enabled(d) )
         iommu_share_p2m_table(d);
xen/arch/x86/mm/p2m-ept.c +5 -5
@@ -225,16 +225,16 @@ static void ept_p2m_type_to_flags(struct
 /* Fill in middle levels of ept table */
 static int ept_set_middle_entry(struct p2m_domain *p2m, ept_entry_t *ept_entry)
 {
-    struct page_info *pg;
+    mfn_t mfn;
     ept_entry_t *table;
     unsigned int i;
 
-    pg = p2m_alloc_ptp(p2m, 0);
-    if ( pg == NULL )
+    mfn = p2m_alloc_ptp(p2m, 0);
+    if ( mfn_eq(mfn, INVALID_MFN) )
         return 0;
 
     ept_entry->epte = 0;
-    ept_entry->mfn = page_to_mfn(pg);
+    ept_entry->mfn = mfn_x(mfn);
     ept_entry->access = p2m->default_access;
 
     ept_entry->r = ept_entry->w = ept_entry->x = 1;
@@ -243,7 +243,7 @@ static int ept_set_middle_entry(struct p
 
     ept_entry->suppress_ve = 1;
 
-    table = __map_domain_page(pg);
+    table = map_domain_page(mfn);
 
     for ( i = 0; i < EPT_PAGETABLE_ENTRIES; i++ )
         table[i].suppress_ve = 1;
xen/arch/x86/mm/p2m-pt.c +8 -11
@@ -204,14 +204,12 @@ p2m_next_level(struct p2m_domain *p2m, v
     /* PoD/paging: Not present doesn't imply empty. */
     if ( !flags )
     {
-        struct page_info *pg;
+        mfn_t mfn = p2m_alloc_ptp(p2m, type);
 
-        pg = p2m_alloc_ptp(p2m, type);
-        if ( pg == NULL )
+        if ( mfn_eq(mfn, INVALID_MFN) )
             return -ENOMEM;
 
-        new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)),
-                                 P2M_BASE_FLAGS | _PAGE_RW);
+        new_entry = l1e_from_pfn(mfn_x(mfn), P2M_BASE_FLAGS | _PAGE_RW);
 
         switch ( type ) {
         case PGT_l3_page_table:
@@ -235,7 +233,7 @@ p2m_next_level(struct p2m_domain *p2m, v
     {
         /* Split superpages pages into smaller ones. */
         unsigned long pfn = l1e_get_pfn(*p2m_entry);
-        struct page_info *pg;
+        mfn_t mfn;
         l1_pgentry_t *l1_entry;
         unsigned int i, level;
 
@@ -263,11 +261,11 @@ p2m_next_level(struct p2m_domain *p2m, v
             return -EINVAL;
         }
 
-        pg = p2m_alloc_ptp(p2m, type);
-        if ( pg == NULL )
+        mfn = p2m_alloc_ptp(p2m, type);
+        if ( mfn_eq(mfn, INVALID_MFN) )
             return -ENOMEM;
 
-        l1_entry = __map_domain_page(pg);
+        l1_entry = map_domain_page(mfn);
 
         for ( i = 0; i < (1u << PAGETABLE_ORDER); i++ )
         {
@@ -279,8 +277,7 @@ p2m_next_level(struct p2m_domain *p2m, v
         }
 
         unmap_domain_page(l1_entry);
-        new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)),
-                                 P2M_BASE_FLAGS | _PAGE_RW);
+        new_entry = l1e_from_pfn(mfn_x(mfn), P2M_BASE_FLAGS | _PAGE_RW);
         p2m_add_iommu_flags(&new_entry, level, IOMMUF_readable|IOMMUF_writable);
         p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, level + 1);
     }
xen/include/asm-x86/p2m.h +1 -1
@@ -684,7 +684,7 @@ void p2m_mem_paging_resume(struct domain
  * Internal functions, only called by other p2m code
  */
 
-struct page_info *p2m_alloc_ptp(struct p2m_domain *p2m, unsigned long type);
+mfn_t p2m_alloc_ptp(struct p2m_domain *p2m, unsigned long type);
 void p2m_free_ptp(struct p2m_domain *p2m, struct page_info *pg);
 
 /* Directly set a p2m entry: only for use by p2m code. Does not need

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw

PATCH v2 3/3 x86/p2m-pt: pass level instead of page type to p2m_next_level()

In reply to Jan Beulich

This in turn calls for p2m_alloc_ptp() also being passed the numeric level.

---
v2: New.
---
Question is whether passing the level to p2m_alloc_ptp() is really all that useful: p2m-ept.c's only use passes zero anyway, and p2m.c's uniform passing of 4 doesn't necessarily match reality afaict.

xen/arch/x86/mm/p2m.c +6 -3
@@ -569,7 +569,7 @@ int p2m_set_entry(struct p2m_domain *p2m
     return rc;
 }
 
-mfn_t p2m_alloc_ptp(struct p2m_domain *p2m, unsigned long type)
+mfn_t p2m_alloc_ptp(struct p2m_domain *p2m, unsigned int level)
 {
     struct page_info *pg;
 
@@ -581,7 +581,10 @@ mfn_t p2m_alloc_ptp(struct p2m_domain *p
         return INVALID_MFN;
 
     page_list_add_tail(pg, &p2m->pages);
-    pg->u.inuse.type_info = type | 1 | PGT_validated;
+    BUILD_BUG_ON(PGT_l1_page_table * 2 != PGT_l2_page_table);
+    BUILD_BUG_ON(PGT_l1_page_table * 3 != PGT_l3_page_table);
+    BUILD_BUG_ON(PGT_l1_page_table * 4 != PGT_l4_page_table);
+    pg->u.inuse.type_info = (PGT_l1_page_table * level) | 1 | PGT_validated;
 
     return page_to_mfn(pg);
 }
@@ -632,7 +635,7 @@ int p2m_alloc_table(struct p2m_domain *p
 
     P2M_PRINTK("allocating p2m table\n");
 
-    top_mfn = p2m_alloc_ptp(p2m, PGT_l4_page_table);
+    top_mfn = p2m_alloc_ptp(p2m, 4);
     if ( mfn_eq(top_mfn, INVALID_MFN) )
     {
         p2m_unlock(p2m);
xen/arch/x86/mm/p2m-pt.c +14 -38

128 lines not on this page · raw message

xen/include/asm-x86/p2m.h +1 -1
@@ -684,7 +684,7 @@ void p2m_mem_paging_resume(struct domain
  * Internal functions, only called by other p2m code
  */
 
-mfn_t p2m_alloc_ptp(struct p2m_domain *p2m, unsigned long type);
+mfn_t p2m_alloc_ptp(struct p2m_domain *p2m, unsigned int level);
 void p2m_free_ptp(struct p2m_domain *p2m, struct page_info *pg);
 
 /* Directly set a p2m entry: only for use by p2m code. Does not need

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v2 3/3
#7 lore raw

Re: [PATCH v2 3/3] x86/p2m-pt: pass level instead of page type to p2m_next_level()

Quoted 10 lines · Jan Beulich

This in turn calls for p2m_alloc_ptp() also being passed the numeric level.

---
v2: New.
---
Question is whether passing the level to p2m_alloc_ptp() is really all that useful: p2m-ept.c's only use passes zero anyway, and p2m.c's uniform passing of 4 doesn't necessarily match reality afaict.

I agree that we should either fix it properly (so that it reflects reality), or make it always be the same value.

Well the original reason for keeping track of the different paging levels in type_info was for PV pagetables, right? I can't off the top of my head think of a reason that it's important to keep track of the different levels for p2m tables.

It probably *is* good to prevent such a page from winding up in a writeable entry of a PV guest; so maybe following p2m.c's lead and always setting it to PGT_l4_page_table?

Other than that...

Quoted 11 lines
         new_entry = l1e_from_pfn(mfn_x(mfn), P2M_BASE_FLAGS | _PAGE_RW);
xen/arch/x86/mm/p2m-pt.c +0 -9
-        switch ( type ) {
-        case PGT_l3_page_table:
-            p2m_add_iommu_flags(&new_entry, 3, IOMMUF_readable|IOMMUF_writable);
-            p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 4);
-            break;
-        case PGT_l2_page_table:
-            p2m_add_iommu_flags(&new_entry, 2, IOMMUF_readable|IOMMUF_writable);
-            p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 3);
-            break;

xen/arch/x86/mm/p2m-pt.c p2m_next_level(struct p2m_domain *p2m, v · line 209

Quoted 10 lines
xen/arch/x86/mm/p2m-pt.c +2 -8
-        case PGT_l1_page_table:
-            p2m_add_iommu_flags(&new_entry, 1, IOMMUF_readable|IOMMUF_writable);
-            p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 2);
-            break;
-        default:
-            BUG();
-            break;
-        }
+        p2m_add_iommu_flags(&new_entry, level, IOMMUF_readable|IOMMUF_writable);
+        p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, level + 1);

...this looks *much better*, thanks!

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw

Re: [PATCH v2 3/3] x86/p2m-pt: pass level instead of page type to p2m_next_level()

Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 27.07.17 at 18:50, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich

This in turn calls for p2m_alloc_ptp() also being passed the numeric level.

---
v2: New.
---
Question is whether passing the level to p2m_alloc_ptp() is really all that useful: p2m-ept.c's only use passes zero anyway, and p2m.c's uniform passing of 4 doesn't necessarily match reality afaict.

I agree that we should either fix it properly (so that it reflects reality), or make it always be the same value.

Quoted 8 lines

Well the original reason for keeping track of the different paging levels in type_info was for PV pagetables, right? I can't off the top of my head think of a reason that it's important to keep track of the different levels for p2m tables.

It probably *is* good to prevent such a page from winding up in a writeable entry of a PV guest; so maybe following p2m.c's lead and always setting it to PGT_l4_page_table?

Yeah, probably that's the safest we can do.

Quoted 25 lines

Other than that...

Quoted 11 lines
         new_entry = l1e_from_pfn(mfn_x(mfn), P2M_BASE_FLAGS | _PAGE_RW);
xen/arch/x86/mm/p2m-pt.c +0 -9
-        switch ( type ) {
-        case PGT_l3_page_table:
-            p2m_add_iommu_flags(&new_entry, 3, IOMMUF_readable|IOMMUF_writable);
-            p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 4);
-            break;
-        case PGT_l2_page_table:
-            p2m_add_iommu_flags(&new_entry, 2, IOMMUF_readable|IOMMUF_writable);
-            p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 3);
-            break;

xen/arch/x86/mm/p2m-pt.c p2m_next_level(struct p2m_domain *p2m, v · line 209

Quoted 10 lines
xen/arch/x86/mm/p2m-pt.c +2 -8
-        case PGT_l1_page_table:
-            p2m_add_iommu_flags(&new_entry, 1, IOMMUF_readable|IOMMUF_writable);
-            p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 2);
-            break;
-        default:
-            BUG();
-            break;
-        }
+        p2m_add_iommu_flags(&new_entry, level, IOMMUF_readable|IOMMUF_writable);
+        p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, level + 1);
Quoted 3 lines

...this looks *much better*, thanks!

Thanks!

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel