Skip to contentSkip to conversation

x86/mm: Drop {HAP,SHADOW}_ERROR() wrappers

PATCH In review Andrew Cooper 4 participants 6 messages Aug 28, 2018 – Aug 30, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mm: Drop {HAP,SHADOW}_ERROR() wrappers

Unlike the PRINTK/DEBUG wrappers, these go straight out to the console, rather than ending up in the debugtrace buffer.

A number of these users are followed by domain_crash(), and future changes will want to combine the printk() into the domain_crash() call. Expand these wrappers in place, using XENLOG_ERR before a BUG(), and XENLOG_G_ERR before a domain_crash().

Perfom some %pv/PRI_mfn/etc cleanup while modifying the invocations, and explicitly drop some calls which are unnecessary (bad shadow op, and the empty stubs for incorrect sh_map_and_validate_gl?e() calls).

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Tim Deegan <[email protected]>
CC: George Dunlap <[email protected]>

---
 xen/arch/x86/mm/hap/hap.c        |  13 ++--
 xen/arch/x86/mm/shadow/common.c  | 126 ++++++++++++++++++++-------------------
 xen/arch/x86/mm/shadow/multi.c   |  23 +++----
 xen/arch/x86/mm/shadow/private.h |   6 +-
 xen/include/asm-x86/hap.h        |   2 -
 5 files changed, 82 insertions(+), 88 deletions(-)
xen/arch/x86/mm/hap/hap.c +7 -6
index d6449e6..946e301 100644
@@ -304,10 +304,11 @@ static void hap_free_p2m_page(struct domain *d, struct page_info *pg)
     /* Should still have no owner and count zero. */
     if ( owner || (pg->count_info & PGC_count_mask) )
     {
-        HAP_ERROR("d%d: Odd p2m page %"PRI_mfn" d=%d c=%lx t=%"PRtype_info"\n",
-                  d->domain_id, mfn_x(page_to_mfn(pg)),
-                  owner ? owner->domain_id : DOMID_INVALID,
-                  pg->count_info, pg->u.inuse.type_info);
+        printk(XENLOG_ERR
+               "d%d: Odd p2m page %"PRI_mfn" d=%d c=%lx t=%"PRtype_info"\n",
+               d->domain_id, mfn_x(page_to_mfn(pg)),
+               owner ? owner->domain_id : DOMID_INVALID,
+               pg->count_info, pg->u.inuse.type_info);
         WARN();
         pg->count_info &= ~PGC_count_mask;
         page_set_owner(pg, NULL);
@@ -407,7 +408,7 @@ static mfn_t hap_make_monitor_table(struct vcpu *v)
     return m4mfn;
 
  oom:
-    HAP_ERROR("out of memory building monitor pagetable\n");
+    printk(XENLOG_G_ERR "out of memory building monitor pagetable\n");
     domain_crash(d);
     return INVALID_MFN;
 }
@@ -640,7 +641,7 @@ static int hap_page_fault(struct vcpu *v, unsigned long va,
 {
     struct domain *d = v->domain;
 
-    HAP_ERROR("Intercepted a guest #PF (%pv) with HAP enabled\n", v);
+    printk(XENLOG_G_ERR "Intercepted #PF from %pv with HAP enabled\n", v);
     domain_crash(d);
     return 0;
 }
xen/arch/x86/mm/shadow/common.c +64 -62

264 lines not on this page · raw message

xen/arch/x86/mm/shadow/multi.c +9 -14
index f979dca..dd86aa1 100644
@@ -2155,7 +2155,7 @@ static int validate_gl4e(struct vcpu *v, void *new_ge, mfn_t sl4mfn, void *se)
                           mfn_x(sl4mfn), shadow_index, new_sl4e.l4);
             if ( shadow_l4e_get_flags(new_sl4e) & _PAGE_PRESENT )
             {
-                SHADOW_ERROR("out-of-range l4e update\n");
+                printk(XENLOG_G_ERR "out-of-range l4e update\n");
                 result |= SHADOW_SET_ERROR;
             }
 
@@ -2478,9 +2478,7 @@ sh_map_and_validate_gl4e(struct vcpu *v, mfn_t gl4mfn,
                                 shadow_l4_index,
                                 validate_gl4e);
 #else // ! GUEST_PAGING_LEVELS >= 4
-    SHADOW_ERROR("called in wrong paging mode!\n");
-    BUG();
-    return 0;
+    BUG(); /* Called in wrong paging mode! */
 #endif
 }
 
@@ -2494,9 +2492,7 @@ sh_map_and_validate_gl3e(struct vcpu *v, mfn_t gl3mfn,
                                 shadow_l3_index,
                                 validate_gl3e);
 #else // ! GUEST_PAGING_LEVELS >= 4
-    SHADOW_ERROR("called in wrong paging mode!\n");
-    BUG();
-    return 0;
+    BUG(); /* Called in wrong paging mode! */
 #endif
 }
 
@@ -2520,9 +2516,7 @@ sh_map_and_validate_gl2he(struct vcpu *v, mfn_t gl2mfn,
                                 shadow_l2_index,
                                 validate_gl2e);
 #else /* Non-PAE guests don't have different kinds of l2 table */
-    SHADOW_ERROR("called in wrong paging mode!\n");
-    BUG();
-    return 0;
+    BUG(); /* Called in wrong paging mode! */
 #endif
 }
 
@@ -2966,8 +2960,8 @@ static int sh_page_fault(struct vcpu *v,
      * a BUG() when we try to take the lock again. */
     if ( unlikely(paging_locked_by_me(d)) )
     {
-        SHADOW_ERROR("Recursive shadow fault: lock was taken by %s\n",
-                     d->arch.paging.lock.locker_function);
+        printk(XENLOG_G_ERR "Recursive shadow fault: lock taken by %s\n",
+               d->arch.paging.lock.locker_function);
         return 0;
     }
 
@@ -3952,7 +3946,8 @@ sh_set_toplevel_shadow(struct vcpu *v,
     }
     else
     {
-        SHADOW_ERROR("can't install %#lx as toplevel shadow\n", mfn_x(smfn));
+        printk(XENLOG_G_ERR "can't install %"PRI_mfn" as toplevel shadow\n",
+               mfn_x(smfn));
         domain_crash(d);
         new_entry = pagetable_null();
     }
@@ -3972,7 +3967,7 @@ sh_set_toplevel_shadow(struct vcpu *v,
          * shadow and it's not safe to free it yet. */
         if ( !mfn_to_page(old_smfn)->u.sh.pinned && !sh_pin(d, old_smfn) )
         {
-            SHADOW_ERROR("can't re-pin %#lx\n", mfn_x(old_smfn));
+            printk(XENLOG_G_ERR "can't re-pin %"PRI_mfn"\n", mfn_x(old_smfn));
             domain_crash(d);
         }
         sh_put_ref(d, old_smfn, 0);
xen/arch/x86/mm/shadow/private.h +2 -4
index 691bcf6..a1fae50 100644
@@ -75,8 +75,6 @@ extern int shadow_audit_enable;
 
 #define SHADOW_PRINTK(_f, _a...)                                     \
     debugtrace_printk("sh: %s(): " _f, __func__, ##_a)
-#define SHADOW_ERROR(_f, _a...)                                      \
-    printk("sh error: %s(): " _f, __func__, ##_a)
 #define SHADOW_DEBUG(flag, _f, _a...)                                \
     do {                                                              \
         if (SHADOW_DEBUG_ ## flag)                                   \
@@ -549,8 +547,8 @@ static inline void sh_put_ref(struct domain *d, mfn_t smfn, paddr_t entry_pa)
 
     if ( unlikely(x == 0) )
     {
-        SHADOW_ERROR("shadow ref underflow, smfn=%lx oc=%#lx t=%#x\n",
-                     mfn_x(smfn), sp->u.sh.count + 0UL, sp->u.sh.type);
+        printk(XENLOG_ERR "shadow ref underflow, smfn=%"PRI_mfn" oc=%#lx t=%#x\n",
+               mfn_x(smfn), sp->u.sh.count + 0UL, sp->u.sh.type);
         BUG();
     }
 
xen/include/asm-x86/hap.h +0 -2
index c5d6038..b94bfb4 100644
@@ -27,8 +27,6 @@
 
 #define HAP_PRINTK(_f, _a...)                                         \
     debugtrace_printk("hap: %s(): " _f, __func__, ##_a)
-#define HAP_ERROR(_f, _a...)                                          \
-    printk("hap error: %s(): " _f, __func__, ##_a)
 
 /************************************************/
 /*        hap domain level functions            */
Signature · 7 lines
2.1.4


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

Unlike the PRINTK/DEBUG wrappers, these go straight out to the console, rather than ending up in the debugtrace buffer.

A number of these users are followed by domain_crash(), and future changes will want to combine the printk() into the domain_crash() call. Expand these wrappers in place, using XENLOG_ERR before a BUG(), and XENLOG_G_ERR before a domain_crash().

Perfom some %pv/PRI_mfn/etc cleanup while modifying the invocations, and explicitly drop some calls which are unnecessary (bad shadow op, and the empty stubs for incorrect sh_map_and_validate_gl?e() calls).

Do you not want to retain the respective prefixes (hap error / sh error)? I think they are useful to a degree. But then you can already tell which subsystem goes wrong by grepping the error message in code.

In any case, code-wise:

Wei.

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

Acked-by on v1 1/1
#2 lore raw
In reply to Andrew Cooper
Quoted 8 lines · Andrew Cooper

Unlike the PRINTK/DEBUG wrappers, these go straight out to the console, rather than ending up in the debugtrace buffer.

A number of these users are followed by domain_crash(), and future changes will want to combine the printk() into the domain_crash() call. Expand these wrappers in place, using XENLOG_ERR before a BUG(), and XENLOG_G_ERR before a domain_crash().

Quoted 5 lines

Perfom some %pv/PRI_mfn/etc cleanup while modifying the invocations, and explicitly drop some calls which are unnecessary (bad shadow op, and the empty stubs for incorrect sh_map_and_validate_gl?e() calls).

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

#3 lore raw
In reply to Andrew Cooper
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 28.08.18 at 20:11, <[email protected]> wrote:
xen/arch/x86/mm/hap/hap.c +0 -0
@@ -304,10 +304,11 @@ static void hap_free_p2m_page(struct domain *d, struct page_info *pg)
     /* Should still have no owner and count zero. */
     if ( owner || (pg->count_info & PGC_count_mask) )
     {

xen/arch/x86/mm/hap/hap.c static void hap_free_p2m_page(struct domain *d, struct page_info *pg) · line 312

Quoted 10 lines
xen/arch/x86/mm/hap/hap.c +5 -4
-        HAP_ERROR("d%d: Odd p2m page %"PRI_mfn" d=%d c=%lx t=%"PRtype_info"\n",
-                  d->domain_id, mfn_x(page_to_mfn(pg)),
-                  owner ? owner->domain_id : DOMID_INVALID,
-                  pg->count_info, pg->u.inuse.type_info);
+        printk(XENLOG_ERR
+               "d%d: Odd p2m page %"PRI_mfn" d=%d c=%lx t=%"PRtype_info"\n",
+               d->domain_id, mfn_x(page_to_mfn(pg)),
+               owner ? owner->domain_id : DOMID_INVALID,
+               pg->count_info, pg->u.inuse.type_info);
         WARN();

This being WARN(), perhaps then also XENLOG_WARNING?

xen/arch/x86/mm/hap/hap.c sh_map_and_validate_gl4e(struct vcpu *v, mfn_t gl4mfn, · line 2483

Quoted 10 lines
xen/arch/x86/mm/hap/hap.c +1 -3
@@ -2478,9 +2478,7 @@ sh_map_and_validate_gl4e(struct vcpu *v, mfn_t gl4mfn,
                                 shadow_l4_index,
                                 validate_gl4e);
 #else // ! GUEST_PAGING_LEVELS >= 4
-    SHADOW_ERROR("called in wrong paging mode!\n");
-    BUG();
-    return 0;
+    BUG(); /* Called in wrong paging mode! */
 #endif
 }

Isn't this going to break the build for certain older gcc versions? ISTR some similar problems in the past.

Jan

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

#4 lore raw
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 28.08.18 at 20:11, <[email protected]> wrote:
xen/arch/x86/mm/hap/hap.c +0 -3
@@ -304,10 +304,11 @@ static void hap_free_p2m_page(struct domain *d, struct page_info *pg)
     /* Should still have no owner and count zero. */
     if ( owner || (pg->count_info & PGC_count_mask) )
     {
-        HAP_ERROR("d%d: Odd p2m page %"PRI_mfn" d=%d c=%lx t=%"PRtype_info"\n",
-                  d->domain_id, mfn_x(page_to_mfn(pg)),
-                  owner ? owner->domain_id : DOMID_INVALID,
Quoted 8 lines

xen/arch/x86/mm/hap/hap.c static void hap_free_p2m_page(struct domain *d, struct page_info *pg) · line 312

Quoted 7 lines
xen/arch/x86/mm/hap/hap.c +5 -1
-                  pg->count_info, pg->u.inuse.type_info);
+        printk(XENLOG_ERR
+               "d%d: Odd p2m page %"PRI_mfn" d=%d c=%lx t=%"PRtype_info"\n",
+               d->domain_id, mfn_x(page_to_mfn(pg)),
+               owner ? owner->domain_id : DOMID_INVALID,
+               pg->count_info, pg->u.inuse.type_info);
         WARN();

This being WARN(), perhaps then also XENLOG_WARNING?

Oh - absolutely.

Quoted 13 lines

xen/arch/x86/mm/hap/hap.c sh_map_and_validate_gl4e(struct vcpu *v, mfn_t gl4mfn, · line 2483

Quoted 11 lines
xen/arch/x86/mm/hap/hap.c +1 -3
@@ -2478,9 +2478,7 @@ sh_map_and_validate_gl4e(struct vcpu *v, mfn_t gl4mfn,
                                 shadow_l4_index,
                                 validate_gl4e);
 #else // ! GUEST_PAGING_LEVELS >= 4
-    SHADOW_ERROR("called in wrong paging mode!\n");
-    BUG();
-    return 0;
+    BUG(); /* Called in wrong paging mode! */
 #endif
 }

Isn't this going to break the build for certain older gcc versions? ISTR some similar problems in the past.

Perhaps, but since this code was written, BUG() has gained an unreachable() hint.  As other examples of this code like this compile, I don't think this is going to be a problem.

~Andrew

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

#5 lore raw
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 30.08.18 at 17:20, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich

xen/arch/x86/mm/shadow/multi.c sh_map_and_validate_gl4e(struct vcpu *v, mfn_t gl4mfn, · line 2483

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 28.08.18 at 20:11, <[email protected]> wrote:
xen/arch/x86/mm/shadow/multi.c +1 -3
@@ -2478,9 +2478,7 @@ sh_map_and_validate_gl4e(struct vcpu *v, mfn_t gl4mfn,
                                 shadow_l4_index,
                                 validate_gl4e);
 #else // ! GUEST_PAGING_LEVELS >= 4
-    SHADOW_ERROR("called in wrong paging mode!\n");
-    BUG();
-    return 0;
+    BUG(); /* Called in wrong paging mode! */
 #endif
 }

Isn't this going to break the build for certain older gcc versions? ISTR some similar problems in the past.

Quoted 3 lines

Perhaps, but since this code was written, BUG() has gained an unreachable() hint. As other examples of this code like this compile, I don't think this is going to be a problem.

The problem(s) I think I recall certainly post-date the introduction of unreachable(). Perhaps whether a compiler would produce a diagnostic depends on other factors as well. I'm not objecting to this going in unchanged; in the worst case we'll have to re-introduce the "return" later on.

Jan

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