[3/4] x86/mm: avoid IOMMU operations in more cases in _get_page_type()
diff mbox series

Message ID c93259a3-5f68-bcca-aeee-f264234cadf4@suse.com
State New
Headers show
Series
  • x86/mm: XSA-299 / 309 / 310 follow-up
Related show

Commit Message

Jan Beulich Dec. 20, 2019, 2:19 p.m. UTC
All that really matters is whether writability of a page changes; in
paticular e.g. page table -> page table (but different levels)
transitions do not require unmapping the page from the IOMMU again.

Note that the XSA-288 fix did arrange for PGT_none pages not needing
special consideration here.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

Comments

Andrew Cooper Dec. 20, 2019, 2:47 p.m. UTC | #1
On 20/12/2019 14:19, Jan Beulich wrote:
> All that really matters is whether writability of a page changes; in
> paticular e.g. page table -> page table (but different levels)
> transitions do not require unmapping the page from the IOMMU again.
>
> Note that the XSA-288 fix did arrange for PGT_none pages not needing
> special consideration here.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>

Patch
diff mbox series

--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -2968,17 +2968,19 @@  static int _get_page_type(struct page_in
             return -EINTR;
     }
 
-    if ( unlikely((x & PGT_type_mask) != type) )
+    if ( unlikely(((x & PGT_type_mask) == PGT_writable_page) !=
+                  (type == PGT_writable_page)) )
     {
         /* Special pages should not be accessible from devices. */
         struct domain *d = page_get_owner(page);
+
         if ( d && is_pv_domain(d) && unlikely(need_iommu_pt_sync(d)) )
         {
             mfn_t mfn = page_to_mfn(page);
 
             if ( (x & PGT_type_mask) == PGT_writable_page )
                 rc = iommu_legacy_unmap(d, _dfn(mfn_x(mfn)), PAGE_ORDER_4K);
-            else if ( type == PGT_writable_page )
+            else
                 rc = iommu_legacy_map(d, _dfn(mfn_x(mfn)), mfn, PAGE_ORDER_4K,
                                       IOMMUF_readable | IOMMUF_writable);