Skip to contentSkip to conversation

x86/mm: address Misra C:2012 rule 16.2

PATCH In review Jan Beulich 2 participants 4 messages May 13 – May 22 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/2 x86/mm: address Misra C:2012 rule 16.2

... ("A switch label shall only be used when the most closely-enclosing compound statement is the body of a `switch' statement"). Use a form of fall-through instead. No difference in generated code, except for some line number changes.

xen/arch/x86/mm.c +9 -7
@@ -2663,15 +2663,17 @@ static int validate_page(struct page_inf
                  get_gpfn_from_mfn(mfn_x(page_to_mfn(page))),
                  type, page->count_info, page->u.inuse.type_info);
         if ( page != current->arch.old_guest_table )
-            page->u.inuse.type_info = 0;
-        else
         {
-            ASSERT((page->u.inuse.type_info &
-                    (PGT_count_mask | PGT_validated)) == 1);
-    case -ERESTART:
-            get_page_light(page);
-            page->u.inuse.type_info |= PGT_partial;
+            page->u.inuse.type_info = 0;
+            break;
         }
+
+        ASSERT((page->u.inuse.type_info &
+                (PGT_count_mask | PGT_validated)) == 1);
+        fallthrough;
+    case -ERESTART:
+        get_page_light(page);
+        page->u.inuse.type_info |= PGT_partial;
         break;
     }
 

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Re: [PATCH 2/2] x86/PV: address Misra C:2012 rule 16.2

Quoted 6 lines · Jan Beulich

... ("A switch label shall only be used when the most closely-enclosing compound statement is the body of a `switch' statement"). While I don't really like doing so, use a few "goto" instead. No change in generated code (somewhat to my surprise).

With one alternative below if you would like to remove one of the introduced labels.

Quoted 31 lines
xen/arch/x86/pv/emul-priv-op.c +4 -11
@@ -897,7 +897,7 @@ static int cf_check read_msr(
     struct vcpu *curr = current;
     const struct domain *currd = curr->domain;
     const struct cpu_policy *cp = currd->arch.cpu_policy;
-    bool vpmu_msr = false, warn = false;
+    bool warn = false;
     uint64_t tmp;
     int ret;
 
@@ -996,21 +996,21 @@ static int cf_check read_msr(
     case MSR_CORE_PERF_FIXED_CTR0 ... MSR_CORE_PERF_FIXED_CTR2:
     case MSR_CORE_PERF_FIXED_CTR_CTRL ... MSR_CORE_PERF_GLOBAL_OVF_CTRL:
         if ( boot_cpu_data.vendor == X86_VENDOR_INTEL )
-        {
-            vpmu_msr = true;
-            /* fall through */
+            goto vpmu;
+        goto check_relaxed;
+
     case MSR_AMD_FAM15H_EVNTSEL0 ... MSR_AMD_FAM15H_PERFCTR5:
     case MSR_K7_EVNTSEL0 ... MSR_K7_PERFCTR3:
-            if ( vpmu_msr || (boot_cpu_data.vendor &
-                              (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )
-            {
-                if ( vpmu_do_rdmsr(reg, val) )
-                    break;
-                return X86EMUL_OKAY;
-            }

xen/arch/x86/pv/emul-priv-op.c static int cf_check read_msr( · line 1013

Quoted 10 lines
xen/arch/x86/pv/emul-priv-op.c +7 -0
+        if ( boot_cpu_data.vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON) )
+        {
+    vpmu:
+            if ( vpmu_do_rdmsr(reg, val) )
+                break;
+            return X86EMUL_OKAY;
         }
         /* fall through */
     default:
+    check_relaxed:

Not sure it's much better, but I think you could avoid the vpmu label at the cost of keeping the vpmu_msr local variable:

    case MSR_CORE_PERF_FIXED_CTR0 ... MSR_CORE_PERF_FIXED_CTR2:
    case MSR_CORE_PERF_FIXED_CTR_CTRL ... MSR_CORE_PERF_GLOBAL_OVF_CTRL:
        if ( boot_cpu_data.vendor != X86_VENDOR_INTEL )
            goto check_relaxed;
        vpmu_msr = true;
        fallthrough;

    case MSR_AMD_FAM15H_EVNTSEL0 ... MSR_AMD_FAM15H_PERFCTR5:
    case MSR_K7_EVNTSEL0 ... MSR_K7_PERFCTR3:
       if ( vpmu_msr || (boot_cpu_data.vendor &
                         (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )

Thanks, Roger.

#5 lore raw

Re: [PATCH 2/2] x86/PV: address Misra C:2012 rule 16.2

Quoted 9 lines · Roger Pau Monné
Quoted 6 lines · Jan Beulich

... ("A switch label shall only be used when the most closely-enclosing compound statement is the body of a `switch' statement"). While I don't really like doing so, use a few "goto" instead. No change in generated code (somewhat to my surprise).

Thanks.

Quoted 48 lines

With one alternative below if you would like to remove one of the introduced labels.

Quoted 31 lines
xen/arch/x86/pv/emul-priv-op.c +4 -11
@@ -897,7 +897,7 @@ static int cf_check read_msr(
     struct vcpu *curr = current;
     const struct domain *currd = curr->domain;
     const struct cpu_policy *cp = currd->arch.cpu_policy;
-    bool vpmu_msr = false, warn = false;
+    bool warn = false;
     uint64_t tmp;
     int ret;
 
@@ -996,21 +996,21 @@ static int cf_check read_msr(
     case MSR_CORE_PERF_FIXED_CTR0 ... MSR_CORE_PERF_FIXED_CTR2:
     case MSR_CORE_PERF_FIXED_CTR_CTRL ... MSR_CORE_PERF_GLOBAL_OVF_CTRL:
         if ( boot_cpu_data.vendor == X86_VENDOR_INTEL )
-        {
-            vpmu_msr = true;
-            /* fall through */
+            goto vpmu;
+        goto check_relaxed;
+
     case MSR_AMD_FAM15H_EVNTSEL0 ... MSR_AMD_FAM15H_PERFCTR5:
     case MSR_K7_EVNTSEL0 ... MSR_K7_PERFCTR3:
-            if ( vpmu_msr || (boot_cpu_data.vendor &
-                              (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )
-            {
-                if ( vpmu_do_rdmsr(reg, val) )
-                    break;
-                return X86EMUL_OKAY;
-            }

xen/arch/x86/pv/emul-priv-op.c static int cf_check read_msr( · line 1013

Quoted 10 lines
xen/arch/x86/pv/emul-priv-op.c +7 -0
+        if ( boot_cpu_data.vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON) )
+        {
+    vpmu:
+            if ( vpmu_do_rdmsr(reg, val) )
+                break;
+            return X86EMUL_OKAY;
         }
         /* fall through */
     default:
+    check_relaxed:

Not sure it's much better, but I think you could avoid the vpmu label at the cost of keeping the vpmu_msr local variable:

Quoted 11 lines
    case MSR_CORE_PERF_FIXED_CTR0 ... MSR_CORE_PERF_FIXED_CTR2:
    case MSR_CORE_PERF_FIXED_CTR_CTRL ... MSR_CORE_PERF_GLOBAL_OVF_CTRL:
        if ( boot_cpu_data.vendor != X86_VENDOR_INTEL )
            goto check_relaxed;
        vpmu_msr = true;
        fallthrough;

    case MSR_AMD_FAM15H_EVNTSEL0 ... MSR_AMD_FAM15H_PERFCTR5:
    case MSR_K7_EVNTSEL0 ... MSR_K7_PERFCTR3:
       if ( vpmu_msr || (boot_cpu_data.vendor &
                         (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )

I was actually happy to see this last construct go away, which your variant would retain.

Jan