kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Bandan Das <bsd@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, kvm <kvm@vger.kernel.org>,
	Wanpeng Li <wanpeng.li@linux.intel.com>,
	Jailhouse <jailhouse-dev@googlegroups.com>
Subject: Re: [PATCH] KVM: nVMX: Disable preemption while reading from shadow VMCS
Date: Wed, 08 Oct 2014 21:19:12 +0200	[thread overview]
Message-ID: <54358E30.1070201@siemens.com> (raw)
In-Reply-To: <jpgsiiyjs7p.fsf@nelium.bos.redhat.com>

On 2014-10-08 21:07, Bandan Das wrote:
> Jan Kiszka <jan.kiszka@siemens.com> writes:
> 
>> In order to access the shadow VMCS, we need to load it. At this point,
>> vmx->loaded_vmcs->vmcs and the actually loaded one start to differ. If
>> we now get preempted by Linux, vmx_vcpu_put and, on return, the
>> vmx_vcpu_load will work against the wrong vmcs. That can cause
>> copy_shadow_to_vmcs12 to corrupt the vmcs12 state.
> 
> Ouch! I apologize if I missed this in the previous discussion but why do
> we never get into this condition while running a Linux guest ?

Well, you need high load on the host, preemption at the "wrong" time,
and some relevant difference between the still to-be-copied shadow vmcs
fields between the proper vmcs and the real one that was used by KVM at
that point. I don't think it is a Jailhouse-only issue, but other
hypervisors may be less sensitive.

> 
> Will there be a performance impact of this change ? I hope it's 
> negligible though..

The preemption counter is cheap, the only impact should be on scheduling
latency. But that is irrelevant as long as we have the counterpart under
the same preemption lock.

Jan

> 
>> Fix the issue by disabling preemption during the copy operation.
>>
>> copy_vmcs12_to_shadow is safe from this issue as it is executed by
>> vmx_vcpu_run when preemption is already disabled before vmentry.
>>
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>> ---
>>
>> This fixes specifically Jailhouse in KVM on CPUs with shadow VMCS
>> support.
>>
>>  arch/x86/kvm/vmx.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index 04fa1b8..f3de106 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -6417,6 +6417,8 @@ static void copy_shadow_to_vmcs12(struct vcpu_vmx *vmx)
>>  	const unsigned long *fields = shadow_read_write_fields;
>>  	const int num_fields = max_shadow_read_write_fields;
>>  
>> +	preempt_disable();
>> +
>>  	vmcs_load(shadow_vmcs);
>>  
>>  	for (i = 0; i < num_fields; i++) {
>> @@ -6440,6 +6442,8 @@ static void copy_shadow_to_vmcs12(struct vcpu_vmx *vmx)
>>  
>>  	vmcs_clear(shadow_vmcs);
>>  	vmcs_load(vmx->loaded_vmcs->vmcs);
>> +
>> +	preempt_enable();
>>  }
>>  
>>  static void copy_vmcs12_to_shadow(struct vcpu_vmx *vmx)

-- 
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux

-- 
You received this message because you are subscribed to the Google Groups "Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jailhouse-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  reply	other threads:[~2014-10-08 19:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-08 16:05 [PATCH] KVM: nVMX: Disable preemption while reading from shadow VMCS Jan Kiszka
2014-10-08 19:07 ` Bandan Das
2014-10-08 19:19   ` Jan Kiszka [this message]
2014-10-08 20:21     ` Paolo Bonzini
2014-10-08 20:03 ` Paolo Bonzini
2014-10-09  0:00 ` Wanpeng Li

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=54358E30.1070201@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=bsd@redhat.com \
    --cc=jailhouse-dev@googlegroups.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=wanpeng.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
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;
as well as URLs for NNTP newsgroup(s).