KVM Archive on lore.kernel.org
 help / color / Atom feed
From: Tao Xu <tao3.xu@intel.com>
To: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: pbonzini@redhat.com, rkrcmar@redhat.com, corbet@lwn.net,
	tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	hpa@zytor.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	fenghua.yu@intel.com, xiaoyao.li@linux.intel.com,
	jingqi.liu@intel.com
Subject: Re: [PATCH v7 3/3] KVM: vmx: handle vm-exit for UMWAIT and TPAUSE
Date: Sat, 13 Jul 2019 22:22:59 +0800
Message-ID: <babf6abf-3e03-1e33-8dd9-ee847957be6f@intel.com> (raw)
In-Reply-To: <20190712160352.GD29659@linux.intel.com>

On 7/13/2019 12:03 AM, Sean Christopherson wrote:
> On Fri, Jul 12, 2019 at 04:29:07PM +0800, Tao Xu wrote:
>> --- a/arch/x86/kvm/vmx/nested.c
>> +++ b/arch/x86/kvm/vmx/nested.c
>> @@ -5213,6 +5213,9 @@ bool nested_vmx_exit_reflected(struct kvm_vcpu *vcpu, u32 exit_reason)
>>   	case EXIT_REASON_ENCLS:
>>   		/* SGX is never exposed to L1 */
>>   		return false;
>> +	case EXIT_REASON_UMWAIT: case EXIT_REASON_TPAUSE:
> 
> Grouped case statements are usually stacked vertically, e.g.:
> 
> 	case EXIT_REASON_UMWAIT:
> 	case EXIT_REASON_TPAUSE:
>Ok, thank you for your suggestion.

>> +		return nested_cpu_has2(vmcs12,
>> +			SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE);
>>   	default:
>>   		return true;
>>   	}
>> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
>> index 0787f140d155..e026b1313dc3 100644
>> --- a/arch/x86/kvm/vmx/vmx.c
>> +++ b/arch/x86/kvm/vmx/vmx.c
>> @@ -5349,6 +5349,20 @@ static int handle_monitor(struct kvm_vcpu *vcpu)
>>   	return handle_nop(vcpu);
>>   }
>>   
>> +static int handle_umwait(struct kvm_vcpu *vcpu)
>> +{
>> +	kvm_skip_emulated_instruction(vcpu);
>> +	WARN(1, "this should never happen\n");
> 
> Blech.  I'm guessing this code was copy-pasted from handle_xsaves() and
> handle_xrstors().  The blurb of "this should never happen" isn't very
> helpful, e.g. the WARN itself makes it pretty obvious that we don't expect
> to reach this point.  WARN_ONCE would also be preferable, no need to spam
> the log in the event things go completely haywire.
> 
> Rather than propagate ugly code, what about defining a common helper, e.g.
> 
> static int handle_unexpected_vmexit(struct kvm_vcpu *vcpu)
> {
> 	kvm_skip_emulated_instruction(vcpu);
> 	WARN_ONCE(1, "Unexpected VM-Exit = 0x%x", vmcs_read32(VM_EXIT_REASON));
> 	return 1;
> }
> 
> ...
> {
> 	[EXIT_REASON_XSAVES]                  = handle_unexpected_vmexit,
> 	[EXIT_REASON_XRSTORS]                 = handle_unexpected_vmexit,
> 
> 	[EXIT_REASON_UMWAIT]                  = handle_unexpected_vmexit,
> 	[EXIT_REASON_TPAUSE]                  = handle_unexpected_vmexit,
> 
> }
> 
Thank you Sean, I will do this in next version of patch.

>> +	return 1;
>> +}
>> +
>> +static int handle_tpause(struct kvm_vcpu *vcpu)
>> +{
>> +	kvm_skip_emulated_instruction(vcpu);
>> +	WARN(1, "this should never happen\n");
>> +	return 1;
>> +}
>> +
>>   static int handle_invpcid(struct kvm_vcpu *vcpu)
>>   {
>>   	u32 vmx_instruction_info;
>> @@ -5559,6 +5573,8 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {
>>   	[EXIT_REASON_VMFUNC]		      = handle_vmx_instruction,
>>   	[EXIT_REASON_PREEMPTION_TIMER]	      = handle_preemption_timer,
>>   	[EXIT_REASON_ENCLS]		      = handle_encls,
>> +	[EXIT_REASON_UMWAIT]                  = handle_umwait,
>> +	[EXIT_REASON_TPAUSE]                  = handle_tpause,
>>   };
>>   
>>   static const int kvm_vmx_max_exit_handlers =
>> -- 
>> 2.20.1
>>


      reply index

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-12  8:29 [PATCH v7 0/3] KVM: x86: Enable user wait instructions Tao Xu
2019-07-12  8:29 ` [PATCH v7 1/3] KVM: x86: add support for " Tao Xu
2019-07-12 15:13   ` Sean Christopherson
2019-07-15  1:11     ` Tao Xu
2019-07-12  8:29 ` [PATCH v7 2/3] KVM: vmx: Emulate MSR IA32_UMWAIT_CONTROL Tao Xu
2019-07-12 15:52   ` Sean Christopherson
2019-07-15  1:22     ` Tao Xu
2019-07-15 14:16       ` Sean Christopherson
2019-07-16 16:03   ` Eduardo Habkost
2019-07-17  1:17     ` Tao Xu
2019-07-17  2:03       ` Tao Xu
2019-07-12  8:29 ` [PATCH v7 3/3] KVM: vmx: handle vm-exit for UMWAIT and TPAUSE Tao Xu
2019-07-12 16:03   ` Sean Christopherson
2019-07-13 14:22     ` Tao Xu [this message]

Reply instructions:

You may reply publically 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=babf6abf-3e03-1e33-8dd9-ee847957be6f@intel.com \
    --to=tao3.xu@intel.com \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=jingqi.liu@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=tglx@linutronix.de \
    --cc=xiaoyao.li@linux.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

KVM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kvm/0 kvm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kvm kvm/ https://lore.kernel.org/kvm \
		kvm@vger.kernel.org kvm@archiver.kernel.org
	public-inbox-index kvm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.kvm


AGPL code for this site: git clone https://public-inbox.org/ public-inbox