Skip to contentSkip to conversation

pvh: dom0 add rw mapping for dom0_iommu_rwmem boot opt

RFC PATCH In review Elena Ufimtseva 3 participants 6 messages Feb 13, 2015 – Feb 19, 2015

lore
Share & tools
lore
#0 lore raw

RFC PATCH 4/5 pvh: dom0 add rw mapping for dom0_iommu_rwmem boot opt

Patch adds mapping for memory regions specified by dom0_iommu_rwmem regions. These special regions are not described by ACPI as RMRRs and have special memory type.
Condition need_modify_vtd_table to perform iommu mapping is changed in order to take into account pte permission changes applied for this regions.
Make set_typed_p2m_entry available for using in mapping routine.

See other patches in this series for details and discovery history.

---
 xen/arch/x86/mm/p2m-ept.c           |    6 ++--
 xen/arch/x86/mm/p2m.c               |    2 +-
 xen/drivers/passthrough/iommu.c     |   55 ++++++++++++++++++++++++++++++++++-
 xen/drivers/passthrough/vtd/iommu.c |    7 +++++
 xen/include/asm-x86/p2m.h           |    3 +-
 5 files changed, 67 insertions(+), 6 deletions(-)
xen/arch/x86/mm/p2m-ept.c +3 -3
index d7d8ad1..9643183 100644
@@ -730,7 +730,7 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     }
 
     if ( mfn_valid(mfn_x(mfn)) || direct_mmio || p2m_is_paged(p2mt) ||
-         (p2mt == p2m_ram_paging_in) )
+         (p2mt == p2m_ram_paging_in) || (p2mt == p2m_sys_rw) )
     {
         int emt = epte_get_entry_emt(p2m->domain, gfn, mfn,
                                      i * EPT_TABLE_ORDER, &ipat, direct_mmio);
@@ -750,8 +750,8 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
         new_entry.mfn = mfn_x(mfn);
 
         /* Safe to read-then-write because we hold the p2m lock */
-        if ( ept_entry->mfn == new_entry.mfn )
-             need_modify_vtd_table = 0;
+        if ( ept_entry->mfn == new_entry.mfn && ept_entry->sa_p2mt == new_entry.sa_p2mt )
+            need_modify_vtd_table = 0;
 
         ept_p2m_type_to_flags(&new_entry, p2mt, p2ma);
     }
xen/arch/x86/mm/p2m.c +1 -1
index 6a06e9f..f9e55da 100644
@@ -811,7 +811,7 @@ void p2m_change_type_range(struct domain *d,
 }
 
 /* Returns: 0 for success, -errno for failure */
-static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
+int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
                                p2m_type_t gfn_p2mt, p2m_access_t access)
 {
     int rc = 0;
xen/drivers/passthrough/iommu.c +54 -1

67 lines not on this page · raw message

xen/drivers/passthrough/vtd/iommu.c +7 -0
index 2e113d7..2d0546e 100644
@@ -1655,6 +1655,7 @@ static void iommu_domain_teardown(struct domain *d)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct mapped_rmrr *mrmrr, *tmp;
+    struct rwmem_range *rwrange, *rwtmp;
 
     if ( list_empty(&acpi_drhd_units) )
         return;
@@ -1665,6 +1666,12 @@ static void iommu_domain_teardown(struct domain *d)
         xfree(mrmrr);
     }
 
+    list_for_each_entry_safe ( rwrange, rwtmp, &hd->arch.rwmem_ranges, list )
+    {
+        list_del(&rwrange->list);
+        xfree(rwrange);
+    }
+
     if ( iommu_use_hap_pt(d) )
         return;
 
xen/include/asm-x86/p2m.h +2 -1
index a95521d..5872d0a 100644
@@ -527,7 +527,8 @@ void p2m_memory_type_changed(struct domain *d);
 
 int p2m_is_logdirty_range(struct p2m_domain *, unsigned long start,
                           unsigned long end);
-
+int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
+                               p2m_type_t gfn_p2mt, p2m_access_t access);
 /* Set mmio addresses in the p2m table (for pass-through) */
 int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
                        p2m_access_t access);
Signature · 1 line
1.7.10.4
#1 lore raw

xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, · line 733

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.02.15 at 19:52, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +1 -1
@@ -730,7 +730,7 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     }
 
     if ( mfn_valid(mfn_x(mfn)) || direct_mmio || p2m_is_paged(p2mt) ||
-         (p2mt == p2m_ram_paging_in) )
+         (p2mt == p2m_ram_paging_in) || (p2mt == p2m_sys_rw) )

This looks pretty arbitrary and hence would at least need brief mentioning in the patch description. I'm not convinced of the need for a new P2M type anyway (after all we don't need such for RMRRs either, and iirc you really want extra RMRR-like regions here).

xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, · line 754

Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +2 -2
@@ -750,8 +750,8 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
         new_entry.mfn = mfn_x(mfn);
 
         /* Safe to read-then-write because we hold the p2m lock */
-        if ( ept_entry->mfn == new_entry.mfn )
-             need_modify_vtd_table = 0;
+        if ( ept_entry->mfn == new_entry.mfn && ept_entry->sa_p2mt == new_entry.sa_p2mt )
+            need_modify_vtd_table = 0;

This added conditions deserves explanation too.

For all further changes done here, I'd really like to first understand why you don't simply add extra RMRRs based on the command line option introduced in the next patch, as that would appear to make most of what you do here unnecessary.

Jan

#2 lore raw
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 13.02.15 at 19:52, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +0 -0
@@ -730,7 +730,7 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     }
 
Quoted 8 lines

xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, · line 733

Quoted 3 lines
xen/arch/x86/mm/p2m-ept.c +1 -1
     if ( mfn_valid(mfn_x(mfn)) || direct_mmio || p2m_is_paged(p2mt) ||
-         (p2mt == p2m_ram_paging_in) )
+         (p2mt == p2m_ram_paging_in) || (p2mt == p2m_sys_rw) )

This looks pretty arbitrary and hence would at least need brief mentioning in the patch description. I'm not convinced of the need for a new P2M type anyway (after all we don't need such for RMRRs either, and iirc you really want extra RMRR-like regions here).

Agree.

Quoted 12 lines

xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, · line 754

Quoted 9 lines
xen/arch/x86/mm/p2m-ept.c +2 -2
@@ -750,8 +750,8 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
         new_entry.mfn = mfn_x(mfn);
 
         /* Safe to read-then-write because we hold the p2m lock */
-        if ( ept_entry->mfn == new_entry.mfn )
-             need_modify_vtd_table = 0;
+        if ( ept_entry->mfn == new_entry.mfn && ept_entry->sa_p2mt == new_entry.sa_p2mt )
+            need_modify_vtd_table = 0;

This added conditions deserves explanation too.

Quoted 4 lines

For all further changes done here, I'd really like to first understand why you don't simply add extra RMRRs based on the command line option introduced in the next patch, as that would appear to make most of what you do here unnecessary.

I discussed it with Konrad and it was an option, but I used that approach. Now looks like everyone is agree with adding extra RMRRs derived from command-line to existing list of RMRRs, I will post next version and will do it this way.
I am not sure though if there is need to distinguish between these extra RMRRs regions and the ones derived from ACPI.

Quoted 3 lines

Jan

#3 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 17.02.15 at 19:25, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

For all further changes done here, I'd really like to first understand why you don't simply add extra RMRRs based on the command line option introduced in the next patch, as that would appear to make most of what you do here unnecessary.

Quoted 6 lines

I discussed it with Konrad and it was an option, but I used that approach. Now looks like everyone is agree with adding extra RMRRs derived from command-line to existing list of RMRRs, I will post next version and will do it this way.
I am not sure though if there is need to distinguish between these extra RMRRs regions and the ones derived from ACPI.

Did anyone suggest you'd need to make a distinction?

Jan

#4 lore raw
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 17.02.15 at 19:25, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

For all further changes done here, I'd really like to first understand why you don't simply add extra RMRRs based on the command line option introduced in the next patch, as that would appear to make most of what you do here unnecessary.

Quoted 8 lines
Quoted 6 lines

I discussed it with Konrad and it was an option, but I used that approach. Now looks like everyone is agree with adding extra RMRRs derived from command-line to existing list of RMRRs, I will post next version and will do it this way.
I am not sure though if there is need to distinguish between these extra RMRRs regions and the ones derived from ACPI.

Did anyone suggest you'd need to make a distinction?

Yes me. We were thinking in terms of the blacklist of RMRR regions to a guest that Intel is looking at. And that these command-driven blacklist needn't be blacklisted in the guest RMRR region.. The theory was that:
1). The system admin might just want the real RMRR regions blacklisted. 2). The other regions that are blacklisted could be blacklisted or not
depending on the desires of the system admin. As in, we would want the system admin to make this choice and by defualt blacklist it. That would require either keeping those two RMRR regions in two seperate buckets or perhaps have the RMRR list have an extra bit (cmd_line:yes).

But all of that is a bit of hand-waving because the RMRR patches aren't yet ready and we thought it might be just easier to address this once those patches are in (or being posted as non-RFC).

Um, but if this comes up - then the code can be redone to address it when the RMRR patches are ready.

Quoted 3 lines

Jan

#5 lore raw
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 18.02.15 at 19:06, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 17.02.15 at 19:25, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

For all further changes done here, I'd really like to first understand why you don't simply add extra RMRRs based on the command line option introduced in the next patch, as that would appear to make most of what you do here unnecessary.

Quoted 8 lines
Quoted 6 lines

I discussed it with Konrad and it was an option, but I used that approach. Now looks like everyone is agree with adding extra RMRRs derived from command-line to existing list of RMRRs, I will post next version and will do it this way.
I am not sure though if there is need to distinguish between these extra RMRRs regions and the ones derived from ACPI.

Did anyone suggest you'd need to make a distinction?

Quoted 10 lines

Yes me. We were thinking in terms of the blacklist of RMRR regions to a guest
that Intel is looking at. And that these command-driven blacklist needn't be blacklisted in the guest RMRR region.. The theory was that:
1). The system admin might just want the real RMRR regions blacklisted. 2). The other regions that are blacklisted could be blacklisted or not
depending on the desires of the system admin. As in, we would want the system admin to make this choice and by defualt blacklist it. That would require either keeping those two RMRR regions in two seperate buckets or perhaps have the RMRR list have an extra bit (cmd_line:yes).

I don't see why hand-specified regions should be treated any different from what ACPI tells us: After all the sole purpose is to work around the firmware not properly specifying these regions in the first place.

Jan