All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Teddy Astie <teddy.astie@vates.tech>
Subject: Re: [PATCH 2/2] x86/PV: address Misra C:2012 rule 16.2
Date: Fri, 22 May 2026 12:49:13 +0200	[thread overview]
Message-ID: <ahA0qSC9w61Kx_4P@macbook.local> (raw)
In-Reply-To: <d04afa56-1197-4f5c-b158-b4b7eb7fc6b9@suse.com>

On Wed, May 13, 2026 at 04:06:20PM +0200, Jan Beulich wrote:
> ... ("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).
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Roger Pau Monné <roger.pau@citrix.com>

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

> 
> --- a/xen/arch/x86/pv/emul-priv-op.c
> +++ b/xen/arch/x86/pv/emul-priv-op.c
> @@ -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;
> -            }
> +        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.


  parent reply	other threads:[~2026-05-22 10:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <e3cdf68f-122a-4a41-a72c-8e6ed857b282@suse.com>
2026-05-13 14:05 ` [PATCH 1/2] x86/mm: address Misra C:2012 rule 16.2 Jan Beulich
2026-05-22 10:34   ` Roger Pau Monné
     [not found] ` <d04afa56-1197-4f5c-b158-b4b7eb7fc6b9@suse.com>
2026-05-22 10:49   ` Roger Pau Monné [this message]
2026-05-22 11:00     ` [PATCH 2/2] x86/PV: " Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ahA0qSC9w61Kx_4P@macbook.local \
    --to=roger.pau@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=teddy.astie@vates.tech \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.