public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Borislav Petkov <bp@alien8.de>
Cc: KVM <kvm@vger.kernel.org>, lkml <linux-kernel@vger.kernel.org>,
	"Jim Mattson" <jmattson@google.com>,
	"Joerg Roedel" <joro@8bytes.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Tom Lendacky" <thomas.lendacky@amd.com>,
	"Tony Luck" <tony.luck@intel.com>,
	"Yazen Ghannam" <Yazen.Ghannam@amd.com>
Subject: Re: [PATCH -v5.1] x86/kvm: Implement HWCR support
Date: Thu, 18 Apr 2019 07:38:47 -0700	[thread overview]
Message-ID: <20190418143847.GC17218@linux.intel.com> (raw)
In-Reply-To: <20190418141949.GK27160@zn.tnic>

On Thu, Apr 18, 2019 at 04:19:49PM +0200, Borislav Petkov wrote:
> On Thu, Apr 18, 2019 at 06:56:06AM -0700, Sean Christopherson wrote:
> > This doesn't allow writing '0' regardless of msr_hwcr.BIT(18), which was
> > previously supported.
> 
> Restored the old conditional:
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 10f6acc6494c..f74f1280745b 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2318,7 +2318,8 @@ static int set_msr_mce(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>  				return -1;
>  
>  			/* MCi_STATUS */
> -			if ((offset & 0x3) == 1 && !msr_info->host_initiated) {
> +			if (!msr_info->host_initiated &&
> +			    (offset & 0x3) == 1 && data != 0) {
>  				if (!can_set_mci_status(vcpu))
>  					return -1;
>  			}
> 
> > And there's no need for multiple if statements.
> 
> It is a bit more readable this way.
> 
> Actually, I'd break that if above into smaller if-statements with
> flipped logic to make it even more readable:
> 
> 	if (msr_info->host_initiated)
> 		goto set_msr;
> 
> 	if (!(offset & 0x3))
> 		goto set_msr;
> 
> 	if (!data)
> 		goto set_msr;
> 
> 	if (!can_set_mci_status(vcpu))
> 		return -1;

At that point it probably makes sense to rework the whole block as there
are existing issues in both the CTL and STATUS flows:

  - Fault cases should return '1', not '-1'.

  - host_initiated should be checked for the CTL case


My personal preference would be to combine the host_initiated and !data
checks for brevity, so something like:

	if (msr_info->host_initiated || !data)
		goto set_msr;

	offset = msr - MSR_IA32_MC0_CTL;
	if ((offset & 0x3) == 0 && (data | (1 << 10)) != ~(u64)0)
		return 1;
	if ((offset & 0x3) == 1 && !can_set_mci_status(vcpu))
		return 1;

set_msr:

> 
> set_msr:
> 	...
> 
> 
> Anything else? Can I send v5.2 now?
> 
> -- 
> Regards/Gruss,
>     Boris.
> 
> Good mailing practices for 400: avoid top-posting and trim the reply.

  reply	other threads:[~2019-04-18 14:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-08  9:09 [PATCH -v5] x86/kvm: Implement HWCR support Borislav Petkov
2019-04-08 14:41 ` Sean Christopherson
2019-04-08 14:57   ` Borislav Petkov
2019-04-18 12:28     ` [PATCH -v5.1] " Borislav Petkov
2019-04-18 13:56       ` Sean Christopherson
2019-04-18 14:19         ` Borislav Petkov
2019-04-18 14:38           ` Sean Christopherson [this message]
2019-04-18 16:36           ` Paolo Bonzini
2019-04-18 16:34       ` Paolo Bonzini

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=20190418143847.GC17218@linux.intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=Yazen.Ghannam@amd.com \
    --cc=bp@alien8.de \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=thomas.lendacky@amd.com \
    --cc=tony.luck@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox