Skip to contentSkip to conversation

AMD/IOMMU: Clean up the allocation helpers

PATCH In review Andrew Cooper 3 participants 3 messages Feb 11, 2020 – Feb 12, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 AMD/IOMMU: Clean up the allocation helpers

Conform to style, drop unnecessary local variables, and avoid opencoding clear_domain_page().

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

Avoiding opencoding clear_domain_page() drops a surprising quantity of code.

add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-269 (-269)

  Function                                     old     new   delta
  amd_iommu_alloc_root.part                    167     116     -51
  iommu_pde_from_dfn                          1061     955    -106
  amd_iommu_quarantine_init                    694     582    -112
  Total: Before=3019031, After=3018762, chg -0.01%
---
 xen/drivers/passthrough/amd/iommu.h | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)
xen/drivers/passthrough/amd/iommu.h +10 -16
index 1abfdc685a..16af40b8cd 100644
@@ -341,34 +341,28 @@ static inline unsigned long region_to_pages(unsigned long addr, unsigned long si
     return (PAGE_ALIGN(addr + size) - (addr & PAGE_MASK)) >> PAGE_SHIFT;
 }
 
-static inline struct page_info* alloc_amd_iommu_pgtable(void)
+static inline struct page_info *alloc_amd_iommu_pgtable(void)
 {
-    struct page_info *pg;
-    void *vaddr;
-
-    pg = alloc_domheap_page(NULL, 0);
-    if ( pg == NULL )
-        return 0;
-    vaddr = __map_domain_page(pg);
-    memset(vaddr, 0, PAGE_SIZE);
-    unmap_domain_page(vaddr);
+    struct page_info *pg = alloc_domheap_page(NULL, 0);
+
+    if ( pg )
+        clear_domain_page(page_to_mfn(pg));
+
     return pg;
 }
 
 static inline void free_amd_iommu_pgtable(struct page_info *pg)
 {
-    if ( pg != 0 )
+    if ( pg )
         free_domheap_page(pg);
 }
 
-static inline void* __alloc_amd_iommu_tables(int order)
+static inline void *__alloc_amd_iommu_tables(unsigned int order)
 {
-    void *buf;
-    buf = alloc_xenheap_pages(order, 0);
-    return buf;
+    return alloc_xenheap_pages(order, 0);
 }
 
-static inline void __free_amd_iommu_tables(void *table, int order)
+static inline void __free_amd_iommu_tables(void *table, unsigned int order)
 {
     free_xenheap_pages(table, order);
 }
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by Paul Durrant on v1 1/1
#1 lore raw
Quoted 9 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Andrew Cooper
Sent: 11 February 2020 12:27
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [Xen-devel] [PATCH] AMD/IOMMU: Clean up the allocation helpers

Quoted 4 lines

Conform to style, drop unnecessary local variables, and avoid opencoding clear_domain_page().

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